*: format code with rustfmt and fix clippy suggestions
* Add avformat_close_input call to clean up AVFormantContext * Format code with rustfmt * Fix clippy lint double_parens * Fix clippy lint deref_addrof * Fix clippy lint identity_conversion * Fix clippy lint match_ref_pats * Fix clippy lint cast_lossless * Fix clippy lint cmp_null * Fix clippy lint clone_on_ref_ptr * Fix clippy lint map_clone * Fix clippy lint needless_borrow * Fix clippy lint needless_pass_by_value * Fix clippy lints for examples * Fix clippy lint unused_io_amount * Fix clippy lint new_without_default * Ignore inline_always clippy lint * Add vim temp files to .gitignore
This commit is contained in:
@ -1,525 +1,515 @@
|
||||
use std::mem;
|
||||
use std::slice;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::slice;
|
||||
|
||||
use libc::{c_int, int64_t, c_ulonglong};
|
||||
use ffi::*;
|
||||
use ::ChannelLayout;
|
||||
use ::util::format;
|
||||
use super::Frame;
|
||||
use ffi::*;
|
||||
use libc::{c_int, c_ulonglong, int64_t};
|
||||
use util::format;
|
||||
use ChannelLayout;
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct Audio(Frame);
|
||||
|
||||
impl Audio {
|
||||
#[inline(always)]
|
||||
pub unsafe fn wrap(ptr: *mut AVFrame) -> Self {
|
||||
Audio(Frame::wrap(ptr))
|
||||
}
|
||||
#[inline(always)]
|
||||
pub unsafe fn wrap(ptr: *mut AVFrame) -> Self {
|
||||
Audio(Frame::wrap(ptr))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn alloc(&mut self, format: format::Sample, samples: usize, layout: ChannelLayout) {
|
||||
self.set_format(format);
|
||||
self.set_samples(samples);
|
||||
self.set_channel_layout(layout);
|
||||
#[inline]
|
||||
pub unsafe fn alloc(&mut self, format: format::Sample, samples: usize, layout: ChannelLayout) {
|
||||
self.set_format(format);
|
||||
self.set_samples(samples);
|
||||
self.set_channel_layout(layout);
|
||||
|
||||
av_frame_get_buffer(self.as_mut_ptr(), 0);
|
||||
}
|
||||
av_frame_get_buffer(self.as_mut_ptr(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
impl Audio {
|
||||
#[inline(always)]
|
||||
pub fn empty() -> Self {
|
||||
unsafe {
|
||||
Audio(Frame::empty())
|
||||
}
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn empty() -> Self {
|
||||
unsafe { Audio(Frame::empty()) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new(format: format::Sample, samples: usize, layout: ChannelLayout) -> Self {
|
||||
unsafe {
|
||||
let mut frame = Audio::empty();
|
||||
frame.alloc(format, samples, layout);
|
||||
#[inline]
|
||||
pub fn new(format: format::Sample, samples: usize, layout: ChannelLayout) -> Self {
|
||||
unsafe {
|
||||
let mut frame = Audio::empty();
|
||||
frame.alloc(format, samples, layout);
|
||||
|
||||
frame
|
||||
}
|
||||
}
|
||||
frame
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn format(&self) -> format::Sample {
|
||||
unsafe {
|
||||
if (*self.as_ptr()).format == -1 {
|
||||
format::Sample::None
|
||||
}
|
||||
else {
|
||||
format::Sample::from(mem::transmute::<_, AVSampleFormat>(((*self.as_ptr()).format)))
|
||||
}
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn format(&self) -> format::Sample {
|
||||
unsafe {
|
||||
if (*self.as_ptr()).format == -1 {
|
||||
format::Sample::None
|
||||
} else {
|
||||
format::Sample::from(mem::transmute::<_, AVSampleFormat>((*self.as_ptr()).format))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_format(&mut self, value: format::Sample) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).format = mem::transmute::<AVSampleFormat, c_int>(value.into());
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_format(&mut self, value: format::Sample) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).format = mem::transmute::<AVSampleFormat, c_int>(value.into());
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn channel_layout(&self) -> ChannelLayout {
|
||||
unsafe {
|
||||
ChannelLayout::from_bits_truncate(av_frame_get_channel_layout(self.as_ptr()) as c_ulonglong)
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn channel_layout(&self) -> ChannelLayout {
|
||||
unsafe {
|
||||
ChannelLayout::from_bits_truncate(av_frame_get_channel_layout(self.as_ptr()) as c_ulonglong)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_channel_layout(&mut self, value: ChannelLayout) {
|
||||
unsafe {
|
||||
av_frame_set_channel_layout(self.as_mut_ptr(), value.bits() as int64_t);
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_channel_layout(&mut self, value: ChannelLayout) {
|
||||
unsafe {
|
||||
av_frame_set_channel_layout(self.as_mut_ptr(), value.bits() as int64_t);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn channels(&self) -> u16 {
|
||||
unsafe {
|
||||
av_frame_get_channels(self.as_ptr()) as u16
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn channels(&self) -> u16 {
|
||||
unsafe { av_frame_get_channels(self.as_ptr()) as u16 }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_channels(&mut self, value: u16) {
|
||||
unsafe {
|
||||
av_frame_set_channels(self.as_mut_ptr(), value as c_int);
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_channels(&mut self, value: u16) {
|
||||
unsafe {
|
||||
av_frame_set_channels(self.as_mut_ptr(), i32::from(value));
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn rate(&self) -> u32 {
|
||||
unsafe {
|
||||
av_frame_get_sample_rate(self.as_ptr()) as u32
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn rate(&self) -> u32 {
|
||||
unsafe { av_frame_get_sample_rate(self.as_ptr()) as u32 }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_rate(&mut self, value: u32) {
|
||||
unsafe {
|
||||
av_frame_set_sample_rate(self.as_mut_ptr(), value as c_int);
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_rate(&mut self, value: u32) {
|
||||
unsafe {
|
||||
av_frame_set_sample_rate(self.as_mut_ptr(), value as c_int);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn samples(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.as_ptr()).nb_samples as usize
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn samples(&self) -> usize {
|
||||
unsafe { (*self.as_ptr()).nb_samples as usize }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_samples(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).nb_samples = value as c_int;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_samples(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).nb_samples = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_planar(&self) -> bool {
|
||||
self.format().is_planar()
|
||||
}
|
||||
#[inline]
|
||||
pub fn is_planar(&self) -> bool {
|
||||
self.format().is_planar()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_packed(&self) -> bool {
|
||||
self.format().is_packed()
|
||||
}
|
||||
#[inline]
|
||||
pub fn is_packed(&self) -> bool {
|
||||
self.format().is_packed()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn planes(&self) -> usize {
|
||||
unsafe {
|
||||
if (*self.as_ptr()).linesize[0] == 0 {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn planes(&self) -> usize {
|
||||
unsafe {
|
||||
if (*self.as_ptr()).linesize[0] == 0 {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if self.is_packed() {
|
||||
1
|
||||
}
|
||||
else {
|
||||
self.channels() as usize
|
||||
}
|
||||
}
|
||||
if self.is_packed() {
|
||||
1
|
||||
} else {
|
||||
self.channels() as usize
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn plane<T: Sample>(&self, index: usize) -> &[T] {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
#[inline]
|
||||
pub fn plane<T: Sample>(&self, index: usize) -> &[T] {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
|
||||
if !<T as Sample>::is_valid(self.format(), self.channels()) {
|
||||
panic!("unsupported type");
|
||||
}
|
||||
if !<T as Sample>::is_valid(self.format(), self.channels()) {
|
||||
panic!("unsupported type");
|
||||
}
|
||||
|
||||
unsafe {
|
||||
slice::from_raw_parts(mem::transmute((*self.as_ptr()).data[index]),
|
||||
self.samples())
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
slice::from_raw_parts(mem::transmute((*self.as_ptr()).data[index]), self.samples())
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn plane_mut<T: Sample>(&mut self, index: usize) -> &mut [T] {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
#[inline]
|
||||
pub fn plane_mut<T: Sample>(&mut self, index: usize) -> &mut [T] {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
|
||||
if !<T as Sample>::is_valid(self.format(), self.channels()) {
|
||||
panic!("unsupported type");
|
||||
}
|
||||
if !<T as Sample>::is_valid(self.format(), self.channels()) {
|
||||
panic!("unsupported type");
|
||||
}
|
||||
|
||||
unsafe {
|
||||
slice::from_raw_parts_mut(mem::transmute((*self.as_mut_ptr()).data[index]),
|
||||
self.samples())
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
slice::from_raw_parts_mut(
|
||||
mem::transmute((*self.as_mut_ptr()).data[index]),
|
||||
self.samples(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn data(&self, index: usize) -> &[u8] {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
#[inline]
|
||||
pub fn data(&self, index: usize) -> &[u8] {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
|
||||
unsafe {
|
||||
slice::from_raw_parts((*self.as_ptr()).data[index],
|
||||
(*self.as_ptr()).linesize[index] as usize)
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
slice::from_raw_parts(
|
||||
(*self.as_ptr()).data[index],
|
||||
(*self.as_ptr()).linesize[index] as usize,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn data_mut(&mut self, index: usize) -> &mut [u8] {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
#[inline]
|
||||
pub fn data_mut(&mut self, index: usize) -> &mut [u8] {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
|
||||
unsafe {
|
||||
slice::from_raw_parts_mut((*self.as_mut_ptr()).data[index],
|
||||
(*self.as_ptr()).linesize[index] as usize)
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
slice::from_raw_parts_mut(
|
||||
(*self.as_mut_ptr()).data[index],
|
||||
(*self.as_ptr()).linesize[index] as usize,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Audio {
|
||||
type Target = Frame;
|
||||
type Target = Frame;
|
||||
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Audio {
|
||||
fn deref_mut(&mut self) -> &mut<Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::fmt::Debug for Audio {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
|
||||
try!(f.write_str("ffmpeg::frame::Audio { "));
|
||||
try!(f.write_str(&format!("format: {:?}, ", self.format())));
|
||||
try!(f.write_str(&format!("channels: {:?}, ", self.channels())));
|
||||
try!(f.write_str(&format!("rate: {:?}, ", self.rate())));
|
||||
try!(f.write_str(&format!("samples: {:?} ", self.samples())));
|
||||
f.write_str("}")
|
||||
}
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
|
||||
f.write_str("ffmpeg::frame::Audio { ")?;
|
||||
f.write_str(&format!("format: {:?}, ", self.format()))?;
|
||||
f.write_str(&format!("channels: {:?}, ", self.channels()))?;
|
||||
f.write_str(&format!("rate: {:?}, ", self.rate()))?;
|
||||
f.write_str(&format!("samples: {:?} ", self.samples()))?;
|
||||
f.write_str("}")
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Audio {
|
||||
fn clone(&self) -> Self {
|
||||
let mut cloned = Audio::new(self.format(), self.samples(), self.channel_layout());
|
||||
cloned.clone_from(self);
|
||||
fn clone(&self) -> Self {
|
||||
let mut cloned = Audio::new(self.format(), self.samples(), self.channel_layout());
|
||||
cloned.clone_from(self);
|
||||
|
||||
cloned
|
||||
}
|
||||
cloned
|
||||
}
|
||||
|
||||
fn clone_from(&mut self, source: &Self) {
|
||||
unsafe {
|
||||
av_frame_copy(self.as_mut_ptr(), source.as_ptr());
|
||||
av_frame_copy_props(self.as_mut_ptr(), source.as_ptr());
|
||||
}
|
||||
}
|
||||
fn clone_from(&mut self, source: &Self) {
|
||||
unsafe {
|
||||
av_frame_copy(self.as_mut_ptr(), source.as_ptr());
|
||||
av_frame_copy_props(self.as_mut_ptr(), source.as_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Frame> for Audio {
|
||||
fn from(frame: Frame) -> Self {
|
||||
Audio(frame)
|
||||
}
|
||||
fn from(frame: Frame) -> Self {
|
||||
Audio(frame)
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe trait Sample {
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool;
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool;
|
||||
}
|
||||
|
||||
unsafe impl Sample for u8 {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, _channels: u16) -> bool {
|
||||
if let format::Sample::U8(..) = format {
|
||||
true
|
||||
}
|
||||
else {
|
||||
false
|
||||
}
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, _channels: u16) -> bool {
|
||||
if let format::Sample::U8(..) = format {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (u8, u8) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 2 && format == format::Sample::U8(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 2 && format == format::Sample::U8(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (u8, u8, u8) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 3 && format == format::Sample::U8(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 3 && format == format::Sample::U8(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (u8, u8, u8, u8) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 4 && format == format::Sample::U8(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 4 && format == format::Sample::U8(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (u8, u8, u8, u8, u8) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 5 && format == format::Sample::U8(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 5 && format == format::Sample::U8(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (u8, u8, u8, u8, u8, u8) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 6 && format == format::Sample::U8(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 6 && format == format::Sample::U8(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (u8, u8, u8, u8, u8, u8, u8) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 7 && format == format::Sample::U8(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 7 && format == format::Sample::U8(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for i16 {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, _channels: u16) -> bool {
|
||||
if let format::Sample::I16(..) = format {
|
||||
true
|
||||
}
|
||||
else {
|
||||
false
|
||||
}
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, _channels: u16) -> bool {
|
||||
if let format::Sample::I16(..) = format {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (i16, i16) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 2 && format == format::Sample::I16(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 2 && format == format::Sample::I16(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (i16, i16, i16) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 3 && format == format::Sample::I16(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 3 && format == format::Sample::I16(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (i16, i16, i16, i16) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 4 && format == format::Sample::I16(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 4 && format == format::Sample::I16(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (i16, i16, i16, i16, i16) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 5 && format == format::Sample::I16(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 5 && format == format::Sample::I16(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (i16, i16, i16, i16, i16, i16) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 6 && format == format::Sample::I16(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 6 && format == format::Sample::I16(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (i16, i16, i16, i16, i16, i16, i16) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 7 && format == format::Sample::I16(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 7 && format == format::Sample::I16(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for i32 {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, _channels: u16) -> bool {
|
||||
if let format::Sample::I32(..) = format {
|
||||
true
|
||||
}
|
||||
else {
|
||||
false
|
||||
}
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, _channels: u16) -> bool {
|
||||
if let format::Sample::I32(..) = format {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (i32, i32) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 2 && format == format::Sample::I32(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 2 && format == format::Sample::I32(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (i32, i32, i32) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 3 && format == format::Sample::I32(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 3 && format == format::Sample::I32(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (i32, i32, i32, i32) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 4 && format == format::Sample::I32(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 4 && format == format::Sample::I32(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (i32, i32, i32, i32, i32) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 5 && format == format::Sample::I32(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 5 && format == format::Sample::I32(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (i32, i32, i32, i32, i32, i32) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 6 && format == format::Sample::I32(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 6 && format == format::Sample::I32(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (i32, i32, i32, i32, i32, i32, i32) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 7 && format == format::Sample::I32(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 7 && format == format::Sample::I32(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for f32 {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, _channels: u16) -> bool {
|
||||
if let format::Sample::F32(..) = format {
|
||||
true
|
||||
}
|
||||
else {
|
||||
false
|
||||
}
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, _channels: u16) -> bool {
|
||||
if let format::Sample::F32(..) = format {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (f32, f32) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 2 && format == format::Sample::F32(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 2 && format == format::Sample::F32(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (f32, f32, f32) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 3 && format == format::Sample::F32(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 3 && format == format::Sample::F32(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (f32, f32, f32, f32) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 4 && format == format::Sample::F32(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 4 && format == format::Sample::F32(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (f32, f32, f32, f32, f32) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 5 && format == format::Sample::F32(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 5 && format == format::Sample::F32(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (f32, f32, f32, f32, f32, f32) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 6 && format == format::Sample::F32(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 6 && format == format::Sample::F32(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (f32, f32, f32, f32, f32, f32, f32) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 7 && format == format::Sample::F32(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 7 && format == format::Sample::F32(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for f64 {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, _channels: u16) -> bool {
|
||||
if let format::Sample::F64(..) = format {
|
||||
true
|
||||
}
|
||||
else {
|
||||
false
|
||||
}
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, _channels: u16) -> bool {
|
||||
if let format::Sample::F64(..) = format {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (f64, f64) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 2 && format == format::Sample::F64(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 2 && format == format::Sample::F64(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (f64, f64, f64) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 3 && format == format::Sample::F64(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 3 && format == format::Sample::F64(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (f64, f64, f64, f64) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 4 && format == format::Sample::F64(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 4 && format == format::Sample::F64(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (f64, f64, f64, f64, f64) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 5 && format == format::Sample::F64(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 5 && format == format::Sample::F64(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (f64, f64, f64, f64, f64, f64) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 6 && format == format::Sample::F64(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 6 && format == format::Sample::F64(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for (f64, f64, f64, f64, f64, f64, f64) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 7 && format == format::Sample::F64(format::sample::Type::Packed)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Sample, channels: u16) -> bool {
|
||||
channels == 7 && format == format::Sample::F64(format::sample::Type::Packed)
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
|
||||
bitflags! {
|
||||
pub struct Flags: c_int {
|
||||
const CORRUPT = AV_FRAME_FLAG_CORRUPT;
|
||||
}
|
||||
pub struct Flags: c_int {
|
||||
const CORRUPT = AV_FRAME_FLAG_CORRUPT;
|
||||
}
|
||||
}
|
||||
|
@ -10,180 +10,176 @@ pub use self::audio::Audio;
|
||||
pub mod flag;
|
||||
pub use self::flag::Flags;
|
||||
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use ::{Dictionary, DictionaryRef};
|
||||
use libc::c_int;
|
||||
use {Dictionary, DictionaryRef};
|
||||
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||
pub struct Packet {
|
||||
pub duration: i64,
|
||||
pub position: i64,
|
||||
pub size: usize,
|
||||
pub duration: i64,
|
||||
pub position: i64,
|
||||
pub size: usize,
|
||||
|
||||
pub pts: i64,
|
||||
pub dts: i64,
|
||||
pub pts: i64,
|
||||
pub dts: i64,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct Frame {
|
||||
ptr: *mut AVFrame,
|
||||
ptr: *mut AVFrame,
|
||||
|
||||
_own: bool,
|
||||
_own: bool,
|
||||
}
|
||||
|
||||
unsafe impl Send for Frame { }
|
||||
unsafe impl Sync for Frame { }
|
||||
unsafe impl Send for Frame {}
|
||||
unsafe impl Sync for Frame {}
|
||||
|
||||
impl Frame {
|
||||
#[inline(always)]
|
||||
pub unsafe fn wrap(ptr: *mut AVFrame) -> Self {
|
||||
Frame { ptr: ptr, _own: false }
|
||||
}
|
||||
#[inline(always)]
|
||||
pub unsafe fn wrap(ptr: *mut AVFrame) -> Self {
|
||||
Frame {
|
||||
ptr: ptr,
|
||||
_own: false,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn empty() -> Self {
|
||||
Frame { ptr: av_frame_alloc(), _own: true }
|
||||
}
|
||||
#[inline(always)]
|
||||
pub unsafe fn empty() -> Self {
|
||||
Frame {
|
||||
ptr: av_frame_alloc(),
|
||||
_own: true,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn as_ptr(&self) -> *const AVFrame {
|
||||
self.ptr as *const _
|
||||
}
|
||||
#[inline(always)]
|
||||
pub unsafe fn as_ptr(&self) -> *const AVFrame {
|
||||
self.ptr as *const _
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFrame {
|
||||
self.ptr
|
||||
}
|
||||
#[inline(always)]
|
||||
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFrame {
|
||||
self.ptr
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn is_empty(&self) -> bool {
|
||||
(*self.as_ptr()).data[0].is_null()
|
||||
}
|
||||
#[inline(always)]
|
||||
pub unsafe fn is_empty(&self) -> bool {
|
||||
(*self.as_ptr()).data[0].is_null()
|
||||
}
|
||||
}
|
||||
|
||||
impl Frame {
|
||||
#[inline]
|
||||
pub fn is_key(&self) -> bool {
|
||||
unsafe {
|
||||
(*self.as_ptr()).key_frame == 1
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn is_key(&self) -> bool {
|
||||
unsafe { (*self.as_ptr()).key_frame == 1 }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_corrupt(&self) -> bool {
|
||||
self.flags().contains(flag::CORRUPT)
|
||||
}
|
||||
#[inline]
|
||||
pub fn is_corrupt(&self) -> bool {
|
||||
self.flags().contains(flag::CORRUPT)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn packet(&self) -> Packet {
|
||||
unsafe {
|
||||
Packet {
|
||||
duration: av_frame_get_pkt_duration(self.as_ptr()) as i64,
|
||||
position: av_frame_get_pkt_pos(self.as_ptr()) as i64,
|
||||
size: av_frame_get_pkt_size(self.as_ptr()) as usize,
|
||||
#[inline]
|
||||
pub fn packet(&self) -> Packet {
|
||||
unsafe {
|
||||
Packet {
|
||||
duration: av_frame_get_pkt_duration(self.as_ptr()) as i64,
|
||||
position: av_frame_get_pkt_pos(self.as_ptr()) as i64,
|
||||
size: av_frame_get_pkt_size(self.as_ptr()) as usize,
|
||||
|
||||
pts: (*self.as_ptr()).pkt_pts,
|
||||
dts: (*self.as_ptr()).pkt_dts,
|
||||
}
|
||||
}
|
||||
}
|
||||
pts: (*self.as_ptr()).pkt_pts,
|
||||
dts: (*self.as_ptr()).pkt_dts,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn pts(&self) -> Option<i64> {
|
||||
unsafe {
|
||||
match (*self.as_ptr()).pts {
|
||||
AV_NOPTS_VALUE => None,
|
||||
pts => Some(pts as i64),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn pts(&self) -> Option<i64> {
|
||||
unsafe {
|
||||
match (*self.as_ptr()).pts {
|
||||
AV_NOPTS_VALUE => None,
|
||||
pts => Some(pts as i64),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_pts(&mut self, value: Option<i64>) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).pts = value.unwrap_or(AV_NOPTS_VALUE);
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_pts(&mut self, value: Option<i64>) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).pts = value.unwrap_or(AV_NOPTS_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn timestamp(&self) -> Option<i64> {
|
||||
unsafe {
|
||||
match av_frame_get_best_effort_timestamp(self.as_ptr()) {
|
||||
AV_NOPTS_VALUE => None,
|
||||
t => Some(t as i64)
|
||||
}
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn timestamp(&self) -> Option<i64> {
|
||||
unsafe {
|
||||
match av_frame_get_best_effort_timestamp(self.as_ptr()) {
|
||||
AV_NOPTS_VALUE => None,
|
||||
t => Some(t as i64),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn quality(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.as_ptr()).quality as usize
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn quality(&self) -> usize {
|
||||
unsafe { (*self.as_ptr()).quality as usize }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn flags(&self) -> Flags {
|
||||
unsafe {
|
||||
Flags::from_bits_truncate((*self.as_ptr()).flags)
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn flags(&self) -> Flags {
|
||||
unsafe { Flags::from_bits_truncate((*self.as_ptr()).flags) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn metadata(&self) -> DictionaryRef {
|
||||
unsafe {
|
||||
DictionaryRef::wrap(av_frame_get_metadata(self.as_ptr()))
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn metadata(&self) -> DictionaryRef {
|
||||
unsafe { DictionaryRef::wrap(av_frame_get_metadata(self.as_ptr())) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_metadata(&mut self, value: Dictionary) {
|
||||
unsafe {
|
||||
av_frame_set_metadata(self.as_mut_ptr(), value.disown());
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_metadata(&mut self, value: Dictionary) {
|
||||
unsafe {
|
||||
av_frame_set_metadata(self.as_mut_ptr(), value.disown());
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn side_data(&self, kind: side_data::Type) -> Option<SideData> {
|
||||
unsafe {
|
||||
let ptr = av_frame_get_side_data(self.as_ptr(), kind.into());
|
||||
#[inline]
|
||||
pub fn side_data(&self, kind: side_data::Type) -> Option<SideData> {
|
||||
unsafe {
|
||||
let ptr = av_frame_get_side_data(self.as_ptr(), kind.into());
|
||||
|
||||
if ptr.is_null() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(SideData::wrap(ptr))
|
||||
}
|
||||
}
|
||||
}
|
||||
if ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(SideData::wrap(ptr))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new_side_data(&mut self, kind: side_data::Type, size: usize) -> Option<SideData> {
|
||||
unsafe {
|
||||
let ptr = av_frame_new_side_data(self.as_mut_ptr(), kind.into(), size as c_int);
|
||||
#[inline]
|
||||
pub fn new_side_data(&mut self, kind: side_data::Type, size: usize) -> Option<SideData> {
|
||||
unsafe {
|
||||
let ptr = av_frame_new_side_data(self.as_mut_ptr(), kind.into(), size as c_int);
|
||||
|
||||
if ptr.is_null() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(SideData::wrap(ptr))
|
||||
}
|
||||
}
|
||||
}
|
||||
if ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(SideData::wrap(ptr))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn remove_side_data(&mut self, kind: side_data::Type) {
|
||||
unsafe {
|
||||
av_frame_remove_side_data(self.as_mut_ptr(), kind.into());
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn remove_side_data(&mut self, kind: side_data::Type) {
|
||||
unsafe {
|
||||
av_frame_remove_side_data(self.as_mut_ptr(), kind.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Frame {
|
||||
#[inline]
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
av_frame_free(&mut self.as_mut_ptr());
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
av_frame_free(&mut self.as_mut_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,135 +1,132 @@
|
||||
use std::ffi::CStr;
|
||||
use std::marker::PhantomData;
|
||||
use std::slice;
|
||||
use std::ffi::CStr;
|
||||
use std::str::from_utf8_unchecked;
|
||||
|
||||
use ffi::*;
|
||||
use ffi::AVFrameSideDataType::*;
|
||||
use super::Frame;
|
||||
use ::DictionaryRef;
|
||||
use ffi::AVFrameSideDataType::*;
|
||||
use ffi::*;
|
||||
use DictionaryRef;
|
||||
|
||||
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
|
||||
pub enum Type {
|
||||
PanScan,
|
||||
A53CC,
|
||||
Stereo3D,
|
||||
MatrixEncoding,
|
||||
DownMixInfo,
|
||||
ReplayGain,
|
||||
DisplayMatrix,
|
||||
AFD,
|
||||
MotionVectors,
|
||||
SkipSamples,
|
||||
AudioServiceType,
|
||||
MasteringDisplayMetadata,
|
||||
GOPTimecode,
|
||||
Spherical,
|
||||
PanScan,
|
||||
A53CC,
|
||||
Stereo3D,
|
||||
MatrixEncoding,
|
||||
DownMixInfo,
|
||||
ReplayGain,
|
||||
DisplayMatrix,
|
||||
AFD,
|
||||
MotionVectors,
|
||||
SkipSamples,
|
||||
AudioServiceType,
|
||||
MasteringDisplayMetadata,
|
||||
GOPTimecode,
|
||||
Spherical,
|
||||
|
||||
ContentLightLevel,
|
||||
IccProfile,
|
||||
ContentLightLevel,
|
||||
IccProfile,
|
||||
}
|
||||
|
||||
impl Type {
|
||||
#[inline]
|
||||
pub fn name(&self) -> &'static str {
|
||||
unsafe {
|
||||
from_utf8_unchecked(CStr::from_ptr(av_frame_side_data_name((*self).into())).to_bytes())
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn name(&self) -> &'static str {
|
||||
unsafe {
|
||||
from_utf8_unchecked(CStr::from_ptr(av_frame_side_data_name((*self).into())).to_bytes())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AVFrameSideDataType> for Type {
|
||||
#[inline(always)]
|
||||
fn from(value: AVFrameSideDataType) -> Self {
|
||||
match value {
|
||||
AV_FRAME_DATA_PANSCAN => Type::PanScan,
|
||||
AV_FRAME_DATA_A53_CC => Type::A53CC,
|
||||
AV_FRAME_DATA_STEREO3D => Type::Stereo3D,
|
||||
AV_FRAME_DATA_MATRIXENCODING => Type::MatrixEncoding,
|
||||
AV_FRAME_DATA_DOWNMIX_INFO => Type::DownMixInfo,
|
||||
AV_FRAME_DATA_REPLAYGAIN => Type::ReplayGain,
|
||||
AV_FRAME_DATA_DISPLAYMATRIX => Type::DisplayMatrix,
|
||||
AV_FRAME_DATA_AFD => Type::AFD,
|
||||
AV_FRAME_DATA_MOTION_VECTORS => Type::MotionVectors,
|
||||
AV_FRAME_DATA_SKIP_SAMPLES => Type::SkipSamples,
|
||||
AV_FRAME_DATA_AUDIO_SERVICE_TYPE => Type::AudioServiceType,
|
||||
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA => Type::MasteringDisplayMetadata,
|
||||
AV_FRAME_DATA_GOP_TIMECODE => Type::GOPTimecode,
|
||||
AV_FRAME_DATA_SPHERICAL => Type::Spherical,
|
||||
#[inline(always)]
|
||||
fn from(value: AVFrameSideDataType) -> Self {
|
||||
match value {
|
||||
AV_FRAME_DATA_PANSCAN => Type::PanScan,
|
||||
AV_FRAME_DATA_A53_CC => Type::A53CC,
|
||||
AV_FRAME_DATA_STEREO3D => Type::Stereo3D,
|
||||
AV_FRAME_DATA_MATRIXENCODING => Type::MatrixEncoding,
|
||||
AV_FRAME_DATA_DOWNMIX_INFO => Type::DownMixInfo,
|
||||
AV_FRAME_DATA_REPLAYGAIN => Type::ReplayGain,
|
||||
AV_FRAME_DATA_DISPLAYMATRIX => Type::DisplayMatrix,
|
||||
AV_FRAME_DATA_AFD => Type::AFD,
|
||||
AV_FRAME_DATA_MOTION_VECTORS => Type::MotionVectors,
|
||||
AV_FRAME_DATA_SKIP_SAMPLES => Type::SkipSamples,
|
||||
AV_FRAME_DATA_AUDIO_SERVICE_TYPE => Type::AudioServiceType,
|
||||
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA => Type::MasteringDisplayMetadata,
|
||||
AV_FRAME_DATA_GOP_TIMECODE => Type::GOPTimecode,
|
||||
AV_FRAME_DATA_SPHERICAL => Type::Spherical,
|
||||
|
||||
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL => Type::ContentLightLevel,
|
||||
AV_FRAME_DATA_ICC_PROFILE => Type::IccProfile,
|
||||
}
|
||||
}
|
||||
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL => Type::ContentLightLevel,
|
||||
AV_FRAME_DATA_ICC_PROFILE => Type::IccProfile,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<AVFrameSideDataType> for Type {
|
||||
#[inline(always)]
|
||||
fn into(self) -> AVFrameSideDataType {
|
||||
match self {
|
||||
Type::PanScan => AV_FRAME_DATA_PANSCAN,
|
||||
Type::A53CC => AV_FRAME_DATA_A53_CC,
|
||||
Type::Stereo3D => AV_FRAME_DATA_STEREO3D,
|
||||
Type::MatrixEncoding => AV_FRAME_DATA_MATRIXENCODING,
|
||||
Type::DownMixInfo => AV_FRAME_DATA_DOWNMIX_INFO,
|
||||
Type::ReplayGain => AV_FRAME_DATA_REPLAYGAIN,
|
||||
Type::DisplayMatrix => AV_FRAME_DATA_DISPLAYMATRIX,
|
||||
Type::AFD => AV_FRAME_DATA_AFD,
|
||||
Type::MotionVectors => AV_FRAME_DATA_MOTION_VECTORS,
|
||||
Type::SkipSamples => AV_FRAME_DATA_SKIP_SAMPLES,
|
||||
Type::AudioServiceType => AV_FRAME_DATA_AUDIO_SERVICE_TYPE,
|
||||
Type::MasteringDisplayMetadata => AV_FRAME_DATA_MASTERING_DISPLAY_METADATA,
|
||||
Type::GOPTimecode => AV_FRAME_DATA_GOP_TIMECODE,
|
||||
Type::Spherical => AV_FRAME_DATA_SPHERICAL,
|
||||
#[inline(always)]
|
||||
fn into(self) -> AVFrameSideDataType {
|
||||
match self {
|
||||
Type::PanScan => AV_FRAME_DATA_PANSCAN,
|
||||
Type::A53CC => AV_FRAME_DATA_A53_CC,
|
||||
Type::Stereo3D => AV_FRAME_DATA_STEREO3D,
|
||||
Type::MatrixEncoding => AV_FRAME_DATA_MATRIXENCODING,
|
||||
Type::DownMixInfo => AV_FRAME_DATA_DOWNMIX_INFO,
|
||||
Type::ReplayGain => AV_FRAME_DATA_REPLAYGAIN,
|
||||
Type::DisplayMatrix => AV_FRAME_DATA_DISPLAYMATRIX,
|
||||
Type::AFD => AV_FRAME_DATA_AFD,
|
||||
Type::MotionVectors => AV_FRAME_DATA_MOTION_VECTORS,
|
||||
Type::SkipSamples => AV_FRAME_DATA_SKIP_SAMPLES,
|
||||
Type::AudioServiceType => AV_FRAME_DATA_AUDIO_SERVICE_TYPE,
|
||||
Type::MasteringDisplayMetadata => AV_FRAME_DATA_MASTERING_DISPLAY_METADATA,
|
||||
Type::GOPTimecode => AV_FRAME_DATA_GOP_TIMECODE,
|
||||
Type::Spherical => AV_FRAME_DATA_SPHERICAL,
|
||||
|
||||
Type::ContentLightLevel => AV_FRAME_DATA_CONTENT_LIGHT_LEVEL,
|
||||
Type::IccProfile => AV_FRAME_DATA_ICC_PROFILE,
|
||||
}
|
||||
}
|
||||
Type::ContentLightLevel => AV_FRAME_DATA_CONTENT_LIGHT_LEVEL,
|
||||
Type::IccProfile => AV_FRAME_DATA_ICC_PROFILE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SideData<'a> {
|
||||
ptr: *mut AVFrameSideData,
|
||||
ptr: *mut AVFrameSideData,
|
||||
|
||||
_marker: PhantomData<&'a Frame>,
|
||||
_marker: PhantomData<&'a Frame>,
|
||||
}
|
||||
|
||||
impl<'a> SideData<'a> {
|
||||
#[inline(always)]
|
||||
pub unsafe fn wrap(ptr: *mut AVFrameSideData) -> Self {
|
||||
SideData { ptr: ptr, _marker: PhantomData }
|
||||
}
|
||||
#[inline(always)]
|
||||
pub unsafe fn wrap(ptr: *mut AVFrameSideData) -> Self {
|
||||
SideData {
|
||||
ptr: ptr,
|
||||
_marker: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn as_ptr(&self) -> *const AVFrameSideData {
|
||||
self.ptr as *const _
|
||||
}
|
||||
#[inline(always)]
|
||||
pub unsafe fn as_ptr(&self) -> *const AVFrameSideData {
|
||||
self.ptr as *const _
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFrameSideData {
|
||||
self.ptr
|
||||
}
|
||||
#[inline(always)]
|
||||
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFrameSideData {
|
||||
self.ptr
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SideData<'a> {
|
||||
#[inline]
|
||||
pub fn kind(&self) -> Type {
|
||||
unsafe {
|
||||
Type::from((*self.as_ptr()).type_)
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn kind(&self) -> Type {
|
||||
unsafe { Type::from((*self.as_ptr()).type_) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn data(&self) -> &[u8] {
|
||||
unsafe {
|
||||
slice::from_raw_parts((*self.as_ptr()).data, (*self.as_ptr()).size as usize)
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn data(&self) -> &[u8] {
|
||||
unsafe { slice::from_raw_parts((*self.as_ptr()).data, (*self.as_ptr()).size as usize) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn metadata(&self) -> DictionaryRef {
|
||||
unsafe {
|
||||
DictionaryRef::wrap((*self.as_ptr()).metadata)
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn metadata(&self) -> DictionaryRef {
|
||||
unsafe { DictionaryRef::wrap((*self.as_ptr()).metadata) }
|
||||
}
|
||||
}
|
||||
|
@ -1,448 +1,417 @@
|
||||
use std::mem;
|
||||
use std::slice;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::slice;
|
||||
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use ::Rational;
|
||||
use ::util::format;
|
||||
use ::util::chroma;
|
||||
use ::picture;
|
||||
use ::color;
|
||||
use super::Frame;
|
||||
use color;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
use picture;
|
||||
use util::chroma;
|
||||
use util::format;
|
||||
use Rational;
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct Video(Frame);
|
||||
|
||||
impl Video {
|
||||
#[inline(always)]
|
||||
pub unsafe fn wrap(ptr: *mut AVFrame) -> Self {
|
||||
Video(Frame::wrap(ptr))
|
||||
}
|
||||
#[inline(always)]
|
||||
pub unsafe fn wrap(ptr: *mut AVFrame) -> Self {
|
||||
Video(Frame::wrap(ptr))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn alloc(&mut self, format: format::Pixel, width: u32, height: u32) {
|
||||
self.set_format(format);
|
||||
self.set_width(width);
|
||||
self.set_height(height);
|
||||
#[inline]
|
||||
pub unsafe fn alloc(&mut self, format: format::Pixel, width: u32, height: u32) {
|
||||
self.set_format(format);
|
||||
self.set_width(width);
|
||||
self.set_height(height);
|
||||
|
||||
av_frame_get_buffer(self.as_mut_ptr(), 32);
|
||||
}
|
||||
av_frame_get_buffer(self.as_mut_ptr(), 32);
|
||||
}
|
||||
}
|
||||
|
||||
impl Video {
|
||||
#[inline(always)]
|
||||
pub fn empty() -> Self {
|
||||
unsafe {
|
||||
Video(Frame::empty())
|
||||
}
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn empty() -> Self {
|
||||
unsafe { Video(Frame::empty()) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new(format: format::Pixel, width: u32, height: u32) -> Self {
|
||||
unsafe {
|
||||
let mut frame = Video::empty();
|
||||
frame.alloc(format, width, height);
|
||||
#[inline]
|
||||
pub fn new(format: format::Pixel, width: u32, height: u32) -> Self {
|
||||
unsafe {
|
||||
let mut frame = Video::empty();
|
||||
frame.alloc(format, width, height);
|
||||
|
||||
frame
|
||||
}
|
||||
}
|
||||
frame
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn format(&self) -> format::Pixel {
|
||||
unsafe {
|
||||
if (*self.as_ptr()).format == -1 {
|
||||
format::Pixel::None
|
||||
}
|
||||
else {
|
||||
format::Pixel::from(mem::transmute::<_, AVPixelFormat>(((*self.as_ptr()).format)))
|
||||
}
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn format(&self) -> format::Pixel {
|
||||
unsafe {
|
||||
if (*self.as_ptr()).format == -1 {
|
||||
format::Pixel::None
|
||||
} else {
|
||||
format::Pixel::from(mem::transmute::<_, AVPixelFormat>((*self.as_ptr()).format))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_format(&mut self, value: format::Pixel) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).format = mem::transmute::<AVPixelFormat, c_int>(value.into());
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_format(&mut self, value: format::Pixel) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).format = mem::transmute::<AVPixelFormat, c_int>(value.into());
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn kind(&self) -> picture::Type {
|
||||
unsafe {
|
||||
picture::Type::from((*self.as_ptr()).pict_type)
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn kind(&self) -> picture::Type {
|
||||
unsafe { picture::Type::from((*self.as_ptr()).pict_type) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_kind(&mut self, value: picture::Type) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).pict_type = value.into();
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_kind(&mut self, value: picture::Type) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).pict_type = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_interlaced(&self) -> bool {
|
||||
unsafe {
|
||||
(*self.as_ptr()).interlaced_frame != 0
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn is_interlaced(&self) -> bool {
|
||||
unsafe { (*self.as_ptr()).interlaced_frame != 0 }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_top_first(&self) -> bool {
|
||||
unsafe {
|
||||
(*self.as_ptr()).top_field_first != 0
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn is_top_first(&self) -> bool {
|
||||
unsafe { (*self.as_ptr()).top_field_first != 0 }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn has_palette_changed(&self) -> bool {
|
||||
unsafe {
|
||||
(*self.as_ptr()).palette_has_changed != 0
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn has_palette_changed(&self) -> bool {
|
||||
unsafe { (*self.as_ptr()).palette_has_changed != 0 }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn width(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).width as u32
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn width(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).width as u32 }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_width(&mut self, value: u32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).width = value as c_int;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_width(&mut self, value: u32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).width = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn height(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).height as u32
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn height(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).height as u32 }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_height(&mut self, value: u32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).height = value as c_int;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_height(&mut self, value: u32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).height = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn color_space(&self) -> color::Space {
|
||||
unsafe {
|
||||
color::Space::from(av_frame_get_colorspace(self.as_ptr()))
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn color_space(&self) -> color::Space {
|
||||
unsafe { color::Space::from(av_frame_get_colorspace(self.as_ptr())) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_color_space(&mut self, value: color::Space) {
|
||||
unsafe {
|
||||
av_frame_set_colorspace(self.as_mut_ptr(), value.into());
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_color_space(&mut self, value: color::Space) {
|
||||
unsafe {
|
||||
av_frame_set_colorspace(self.as_mut_ptr(), value.into());
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn color_range(&self) -> color::Range {
|
||||
unsafe {
|
||||
color::Range::from(av_frame_get_color_range(self.as_ptr()))
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn color_range(&self) -> color::Range {
|
||||
unsafe { color::Range::from(av_frame_get_color_range(self.as_ptr())) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_color_range(&mut self, value: color::Range) {
|
||||
unsafe {
|
||||
av_frame_set_color_range(self.as_mut_ptr(), value.into());
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_color_range(&mut self, value: color::Range) {
|
||||
unsafe {
|
||||
av_frame_set_color_range(self.as_mut_ptr(), value.into());
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn color_primaries(&self) -> color::Primaries {
|
||||
unsafe {
|
||||
color::Primaries::from((*self.as_ptr()).color_primaries)
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn color_primaries(&self) -> color::Primaries {
|
||||
unsafe { color::Primaries::from((*self.as_ptr()).color_primaries) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_color_primaries(&mut self, value: color::Primaries) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).color_primaries = value.into();
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_color_primaries(&mut self, value: color::Primaries) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).color_primaries = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn color_transfer_characteristic(&self) -> color::TransferCharacteristic {
|
||||
unsafe {
|
||||
color::TransferCharacteristic::from((*self.as_ptr()).color_trc)
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn color_transfer_characteristic(&self) -> color::TransferCharacteristic {
|
||||
unsafe { color::TransferCharacteristic::from((*self.as_ptr()).color_trc) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_color_transfer_characteristic(&mut self, value: color::TransferCharacteristic) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).color_trc = value.into();
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_color_transfer_characteristic(&mut self, value: color::TransferCharacteristic) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).color_trc = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn chroma_location(&self) -> chroma::Location {
|
||||
unsafe {
|
||||
chroma::Location::from((*self.as_ptr()).chroma_location)
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn chroma_location(&self) -> chroma::Location {
|
||||
unsafe { chroma::Location::from((*self.as_ptr()).chroma_location) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn aspect_ratio(&self) -> Rational {
|
||||
unsafe {
|
||||
Rational::from((*self.as_ptr()).sample_aspect_ratio)
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn aspect_ratio(&self) -> Rational {
|
||||
unsafe { Rational::from((*self.as_ptr()).sample_aspect_ratio) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn coded_number(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.as_ptr()).coded_picture_number as usize
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn coded_number(&self) -> usize {
|
||||
unsafe { (*self.as_ptr()).coded_picture_number as usize }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn display_number(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.as_ptr()).display_picture_number as usize
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn display_number(&self) -> usize {
|
||||
unsafe { (*self.as_ptr()).display_picture_number as usize }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn repeat(&self) -> f64 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).repeat_pict as f64
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn repeat(&self) -> f64 {
|
||||
unsafe { f64::from((*self.as_ptr()).repeat_pict) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn stride(&self, index: usize) -> usize {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
#[inline]
|
||||
pub fn stride(&self, index: usize) -> usize {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
|
||||
unsafe {
|
||||
(*self.as_ptr()).linesize[index] as usize
|
||||
}
|
||||
}
|
||||
unsafe { (*self.as_ptr()).linesize[index] as usize }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn planes(&self) -> usize {
|
||||
for i in 0 .. 8 {
|
||||
unsafe {
|
||||
if (*self.as_ptr()).linesize[i] == 0 {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn planes(&self) -> usize {
|
||||
for i in 0..8 {
|
||||
unsafe {
|
||||
if (*self.as_ptr()).linesize[i] == 0 {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
8
|
||||
}
|
||||
8
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn plane_width(&self, index: usize) -> u32 {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
#[inline]
|
||||
pub fn plane_width(&self, index: usize) -> u32 {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
|
||||
// Logic taken from image_get_linesize().
|
||||
if index != 1 && index != 2 {
|
||||
return self.width();
|
||||
}
|
||||
// Logic taken from image_get_linesize().
|
||||
if index != 1 && index != 2 {
|
||||
return self.width();
|
||||
}
|
||||
|
||||
if let Some(desc) = self.format().descriptor() {
|
||||
let s = desc.log2_chroma_w();
|
||||
(self.width() + (1 << s) - 1) >> s
|
||||
}
|
||||
else {
|
||||
self.width()
|
||||
}
|
||||
}
|
||||
if let Some(desc) = self.format().descriptor() {
|
||||
let s = desc.log2_chroma_w();
|
||||
(self.width() + (1 << s) - 1) >> s
|
||||
} else {
|
||||
self.width()
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn plane_height(&self, index: usize) -> u32 {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
#[inline]
|
||||
pub fn plane_height(&self, index: usize) -> u32 {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
|
||||
// Logic taken from av_image_fill_pointers().
|
||||
if index != 1 && index != 2 {
|
||||
return self.height();
|
||||
}
|
||||
// Logic taken from av_image_fill_pointers().
|
||||
if index != 1 && index != 2 {
|
||||
return self.height();
|
||||
}
|
||||
|
||||
if let Some(desc) = self.format().descriptor() {
|
||||
let s = desc.log2_chroma_h();
|
||||
(self.height() + (1 << s) - 1) >> s
|
||||
}
|
||||
else {
|
||||
self.height()
|
||||
}
|
||||
}
|
||||
if let Some(desc) = self.format().descriptor() {
|
||||
let s = desc.log2_chroma_h();
|
||||
(self.height() + (1 << s) - 1) >> s
|
||||
} else {
|
||||
self.height()
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn plane<T: Component>(&self, index: usize) -> &[T] {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
#[inline]
|
||||
pub fn plane<T: Component>(&self, index: usize) -> &[T] {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
|
||||
if !<T as Component>::is_valid(self.format()) {
|
||||
panic!("unsupported type");
|
||||
}
|
||||
if !<T as Component>::is_valid(self.format()) {
|
||||
panic!("unsupported type");
|
||||
}
|
||||
|
||||
unsafe {
|
||||
slice::from_raw_parts(
|
||||
mem::transmute((*self.as_ptr()).data[index]),
|
||||
self.stride(index) * self.plane_height(index) as usize / mem::size_of::<T>())
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
slice::from_raw_parts(
|
||||
mem::transmute((*self.as_ptr()).data[index]),
|
||||
self.stride(index) * self.plane_height(index) as usize / mem::size_of::<T>(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn plane_mut<T: Component>(&mut self, index: usize) -> &mut [T] {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
#[inline]
|
||||
pub fn plane_mut<T: Component>(&mut self, index: usize) -> &mut [T] {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
|
||||
if !<T as Component>::is_valid(self.format()) {
|
||||
panic!("unsupported type");
|
||||
}
|
||||
if !<T as Component>::is_valid(self.format()) {
|
||||
panic!("unsupported type");
|
||||
}
|
||||
|
||||
unsafe {
|
||||
slice::from_raw_parts_mut(
|
||||
mem::transmute((*self.as_mut_ptr()).data[index]),
|
||||
self.stride(index) * self.plane_height(index) as usize / mem::size_of::<T>())
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
slice::from_raw_parts_mut(
|
||||
mem::transmute((*self.as_mut_ptr()).data[index]),
|
||||
self.stride(index) * self.plane_height(index) as usize / mem::size_of::<T>(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn data(&self, index: usize) -> &[u8] {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
#[inline]
|
||||
pub fn data(&self, index: usize) -> &[u8] {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
|
||||
unsafe {
|
||||
slice::from_raw_parts((*self.as_ptr()).data[index],
|
||||
self.stride(index) * self.plane_height(index) as usize)
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
slice::from_raw_parts(
|
||||
(*self.as_ptr()).data[index],
|
||||
self.stride(index) * self.plane_height(index) as usize,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn data_mut(&mut self, index: usize) -> &mut [u8] {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
#[inline]
|
||||
pub fn data_mut(&mut self, index: usize) -> &mut [u8] {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
|
||||
unsafe {
|
||||
slice::from_raw_parts_mut((*self.as_mut_ptr()).data[index],
|
||||
self.stride(index) * self.plane_height(index) as usize)
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
slice::from_raw_parts_mut(
|
||||
(*self.as_mut_ptr()).data[index],
|
||||
self.stride(index) * self.plane_height(index) as usize,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Video {
|
||||
type Target = Frame;
|
||||
type Target = Frame;
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &Frame {
|
||||
&self.0
|
||||
}
|
||||
#[inline]
|
||||
fn deref(&self) -> &Frame {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Video {
|
||||
#[inline]
|
||||
fn deref_mut(&mut self) -> &mut Frame {
|
||||
&mut self.0
|
||||
}
|
||||
#[inline]
|
||||
fn deref_mut(&mut self) -> &mut Frame {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Video {
|
||||
#[inline]
|
||||
fn clone(&self) -> Self {
|
||||
let mut cloned = Video::new(self.format(), self.width(), self.height());
|
||||
cloned.clone_from(self);
|
||||
#[inline]
|
||||
fn clone(&self) -> Self {
|
||||
let mut cloned = Video::new(self.format(), self.width(), self.height());
|
||||
cloned.clone_from(self);
|
||||
|
||||
cloned
|
||||
}
|
||||
cloned
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn clone_from(&mut self, source: &Self) {
|
||||
unsafe {
|
||||
av_frame_copy(self.as_mut_ptr(), source.as_ptr());
|
||||
av_frame_copy_props(self.as_mut_ptr(), source.as_ptr());
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn clone_from(&mut self, source: &Self) {
|
||||
unsafe {
|
||||
av_frame_copy(self.as_mut_ptr(), source.as_ptr());
|
||||
av_frame_copy_props(self.as_mut_ptr(), source.as_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Frame> for Video {
|
||||
#[inline]
|
||||
fn from(frame: Frame) -> Self {
|
||||
Video(frame)
|
||||
}
|
||||
#[inline]
|
||||
fn from(frame: Frame) -> Self {
|
||||
Video(frame)
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe trait Component {
|
||||
fn is_valid(format: format::Pixel) -> bool;
|
||||
fn is_valid(format: format::Pixel) -> bool;
|
||||
}
|
||||
|
||||
#[cfg(feature = "image")]
|
||||
unsafe impl Component for ::image::Luma<u8> {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Pixel) -> bool {
|
||||
format == format::Pixel::GRAY8
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Pixel) -> bool {
|
||||
format == format::Pixel::GRAY8
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "image")]
|
||||
unsafe impl Component for ::image::Rgb<u8> {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Pixel) -> bool {
|
||||
format == format::Pixel::RGB24
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Pixel) -> bool {
|
||||
format == format::Pixel::RGB24
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "image")]
|
||||
unsafe impl Component for ::image::Rgba<u8> {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Pixel) -> bool {
|
||||
format == format::Pixel::RGBA
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Pixel) -> bool {
|
||||
format == format::Pixel::RGBA
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Component for [u8; 3] {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Pixel) -> bool {
|
||||
format == format::Pixel::RGB24 || format == format::Pixel::BGR24
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Pixel) -> bool {
|
||||
format == format::Pixel::RGB24 || format == format::Pixel::BGR24
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Component for (u8, u8, u8) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Pixel) -> bool {
|
||||
format == format::Pixel::RGB24 || format == format::Pixel::BGR24
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Pixel) -> bool {
|
||||
format == format::Pixel::RGB24 || format == format::Pixel::BGR24
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Component for [u8; 4] {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Pixel) -> bool {
|
||||
format == format::Pixel::RGBA || format == format::Pixel::BGRA ||
|
||||
format == format::Pixel::ARGB || format == format::Pixel::ABGR ||
|
||||
format == format::Pixel::RGBZ || format == format::Pixel::BGRZ ||
|
||||
format == format::Pixel::ZRGB || format == format::Pixel::ZBGR
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Pixel) -> bool {
|
||||
format == format::Pixel::RGBA || format == format::Pixel::BGRA
|
||||
|| format == format::Pixel::ARGB || format == format::Pixel::ABGR
|
||||
|| format == format::Pixel::RGBZ || format == format::Pixel::BGRZ
|
||||
|| format == format::Pixel::ZRGB || format == format::Pixel::ZBGR
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Component for (u8, u8, u8, u8) {
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Pixel) -> bool {
|
||||
format == format::Pixel::RGBA || format == format::Pixel::BGRA ||
|
||||
format == format::Pixel::ARGB || format == format::Pixel::ABGR ||
|
||||
format == format::Pixel::RGBZ || format == format::Pixel::BGRZ ||
|
||||
format == format::Pixel::ZRGB || format == format::Pixel::ZBGR
|
||||
}
|
||||
#[inline(always)]
|
||||
fn is_valid(format: format::Pixel) -> bool {
|
||||
format == format::Pixel::RGBA || format == format::Pixel::BGRA
|
||||
|| format == format::Pixel::ARGB || format == format::Pixel::ABGR
|
||||
|| format == format::Pixel::RGBZ || format == format::Pixel::BGRZ
|
||||
|| format == format::Pixel::ZRGB || format == format::Pixel::ZBGR
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user