util/frame: split it up in files
This commit is contained in:
parent
9666310abf
commit
73accc66b5
106
src/util/frame/audio.rs
Normal file
106
src/util/frame/audio.rs
Normal file
@ -0,0 +1,106 @@
|
||||
use libc::c_int;
|
||||
use std::mem;
|
||||
use std::ops::Deref;
|
||||
|
||||
use ffi::*;
|
||||
use ::util::format;
|
||||
use super::Frame;
|
||||
|
||||
pub struct Audio(Frame);
|
||||
|
||||
impl Audio {
|
||||
pub fn new() -> Self {
|
||||
Audio(Frame::new())
|
||||
}
|
||||
|
||||
pub fn format(&self) -> format::Sample {
|
||||
unsafe {
|
||||
if (*self.ptr).format == -1 {
|
||||
format::Sample::None
|
||||
}
|
||||
else {
|
||||
format::Sample::from(mem::transmute::<_, AVSampleFormat>(((*self.ptr).format)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn channel_layout(&self) -> i64 {
|
||||
unsafe {
|
||||
av_frame_get_channel_layout(self.ptr)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_channel_layout(&mut self, value: i64) {
|
||||
unsafe {
|
||||
av_frame_set_channel_layout(self.ptr, value);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn channels(&self) -> usize {
|
||||
unsafe {
|
||||
av_frame_get_channels(self.ptr) as usize
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_channels(&mut self, value: usize) {
|
||||
unsafe {
|
||||
av_frame_set_channels(self.ptr, value as c_int);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rate(&self) -> i32 {
|
||||
unsafe {
|
||||
av_frame_get_sample_rate(self.ptr)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_rate(&mut self, value: i32) {
|
||||
unsafe {
|
||||
av_frame_set_sample_rate(self.ptr, value);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn samples(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.ptr).nb_samples as usize
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_samples(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.ptr).nb_samples = value as c_int;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for Audio { }
|
||||
|
||||
impl Deref for Audio {
|
||||
type Target = Frame;
|
||||
|
||||
fn deref(&self) -> &Frame {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Audio {
|
||||
fn clone(&self) -> Self {
|
||||
Audio(self.0.clone())
|
||||
}
|
||||
|
||||
fn clone_from(&mut self, source: &Self) {
|
||||
self.0.clone_from(&source.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Frame> for Audio {
|
||||
fn into(self) -> Frame {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Audio> for Frame {
|
||||
fn into(self) -> Audio {
|
||||
Audio(self)
|
||||
}
|
||||
}
|
@ -1,17 +1,17 @@
|
||||
pub mod side_data;
|
||||
pub use self::side_data::SideData;
|
||||
|
||||
pub mod video;
|
||||
pub use self::video::Video;
|
||||
|
||||
pub mod audio;
|
||||
pub use self::audio::Audio;
|
||||
|
||||
use libc::c_int;
|
||||
use std::ptr;
|
||||
use std::mem;
|
||||
use std::ops::Deref;
|
||||
|
||||
use ffi::*;
|
||||
use ::{Dictionary, Rational, Picture};
|
||||
use ::util::format;
|
||||
use ::util::chroma;
|
||||
use ::picture;
|
||||
use ::color;
|
||||
use ::Dictionary;
|
||||
|
||||
bitflags! {
|
||||
flags Flags: c_int {
|
||||
@ -171,257 +171,3 @@ impl Drop for Frame {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Audio(Frame);
|
||||
|
||||
impl Audio {
|
||||
pub fn new() -> Self {
|
||||
Audio(Frame::new())
|
||||
}
|
||||
|
||||
pub fn format(&self) -> format::Sample {
|
||||
unsafe {
|
||||
if (*self.ptr).format == -1 {
|
||||
format::Sample::None
|
||||
}
|
||||
else {
|
||||
format::Sample::from(mem::transmute::<_, AVSampleFormat>(((*self.ptr).format)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn channel_layout(&self) -> i64 {
|
||||
unsafe {
|
||||
av_frame_get_channel_layout(self.ptr)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_channel_layout(&mut self, value: i64) {
|
||||
unsafe {
|
||||
av_frame_set_channel_layout(self.ptr, value);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn channels(&self) -> usize {
|
||||
unsafe {
|
||||
av_frame_get_channels(self.ptr) as usize
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_channels(&mut self, value: usize) {
|
||||
unsafe {
|
||||
av_frame_set_channels(self.ptr, value as c_int);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rate(&self) -> i32 {
|
||||
unsafe {
|
||||
av_frame_get_sample_rate(self.ptr)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_rate(&mut self, value: i32) {
|
||||
unsafe {
|
||||
av_frame_set_sample_rate(self.ptr, value);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn samples(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.ptr).nb_samples as usize
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_samples(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.ptr).nb_samples = value as c_int;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for Audio { }
|
||||
|
||||
impl Deref for Audio {
|
||||
type Target = Frame;
|
||||
|
||||
fn deref(&self) -> &Frame {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Frame> for Audio {
|
||||
fn into(self) -> Frame {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Audio> for Frame {
|
||||
fn into(self) -> Audio {
|
||||
Audio(self)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Video(Frame);
|
||||
|
||||
impl Video {
|
||||
pub fn new() -> Self {
|
||||
Video(Frame::new())
|
||||
}
|
||||
|
||||
pub fn picture(&self) -> Picture {
|
||||
Picture::wrap(self.ptr as *mut AVPicture, self.format(), self.width(), self.height())
|
||||
}
|
||||
|
||||
pub fn format(&self) -> format::Pixel {
|
||||
unsafe {
|
||||
if (*self.ptr).format == -1 {
|
||||
format::Pixel::None
|
||||
}
|
||||
else {
|
||||
format::Pixel::from(mem::transmute::<_, AVPixelFormat>(((*self.ptr).format)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn kind(&self) -> picture::Type {
|
||||
unsafe {
|
||||
picture::Type::from((*self.ptr).pict_type)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_interlaced(&self) -> bool {
|
||||
unsafe {
|
||||
(*self.ptr).interlaced_frame != 0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_top_first(&self) -> bool {
|
||||
unsafe {
|
||||
(*self.ptr).top_field_first != 0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_palette_changed(&self) -> bool {
|
||||
unsafe {
|
||||
(*self.ptr).palette_has_changed != 0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn width(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.ptr).width as u32
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_width(&mut self, value: u32) {
|
||||
unsafe {
|
||||
(*self.ptr).width = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn height(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.ptr).height as u32
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_height(&mut self, value: u32) {
|
||||
unsafe {
|
||||
(*self.ptr).height = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn color_space(&self) -> color::Space {
|
||||
unsafe {
|
||||
color::Space::from(av_frame_get_colorspace(self.ptr))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_color_space(&mut self, value: color::Space) {
|
||||
unsafe {
|
||||
av_frame_set_colorspace(self.ptr, value.into());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn color_range(&self) -> color::Range {
|
||||
unsafe {
|
||||
color::Range::from(av_frame_get_color_range(self.ptr))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_color_range(&mut self, value: color::Range) {
|
||||
unsafe {
|
||||
av_frame_set_color_range(self.ptr, value.into());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn color_primaries(&self) -> color::Primaries {
|
||||
unsafe {
|
||||
color::Primaries::from((*self.ptr).color_primaries)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_color_primaries(&mut self, value: color::Primaries) {
|
||||
unsafe {
|
||||
(*self.ptr).color_primaries = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn color_transfer_characteristic(&self) -> color::TransferCharacteristic {
|
||||
unsafe {
|
||||
color::TransferCharacteristic::from((*self.ptr).color_trc)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_color_transfer_characteristic(&mut self, value: color::TransferCharacteristic) {
|
||||
unsafe {
|
||||
(*self.ptr).color_trc = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chroma_location(&self) -> chroma::Location {
|
||||
unsafe {
|
||||
chroma::Location::from((*self.ptr).chroma_location)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn aspect_ratio(&self) -> Rational {
|
||||
unsafe {
|
||||
Rational((*self.ptr).sample_aspect_ratio)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn coded_number(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.ptr).coded_picture_number as usize
|
||||
}
|
||||
}
|
||||
|
||||
pub fn display_number(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.ptr).display_picture_number as usize
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for Video { }
|
||||
|
||||
impl Deref for Video {
|
||||
type Target = Frame;
|
||||
|
||||
fn deref(&self) -> &Frame {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Video> for Frame {
|
||||
fn into(self) -> Video {
|
||||
Video(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Frame> for Video {
|
||||
fn into(self) -> Frame {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
186
src/util/frame/video.rs
Normal file
186
src/util/frame/video.rs
Normal file
@ -0,0 +1,186 @@
|
||||
use libc::c_int;
|
||||
use std::mem;
|
||||
use std::ops::Deref;
|
||||
|
||||
use ffi::*;
|
||||
use ::{Rational, Picture};
|
||||
use ::util::format;
|
||||
use ::util::chroma;
|
||||
use ::picture;
|
||||
use ::color;
|
||||
use super::Frame;
|
||||
|
||||
pub struct Video(Frame);
|
||||
|
||||
impl Video {
|
||||
pub fn new() -> Self {
|
||||
Video(Frame::new())
|
||||
}
|
||||
|
||||
pub fn picture(&self) -> Picture {
|
||||
Picture::wrap(self.ptr as *mut AVPicture, self.format(), self.width(), self.height())
|
||||
}
|
||||
|
||||
pub fn format(&self) -> format::Pixel {
|
||||
unsafe {
|
||||
if (*self.ptr).format == -1 {
|
||||
format::Pixel::None
|
||||
}
|
||||
else {
|
||||
format::Pixel::from(mem::transmute::<_, AVPixelFormat>(((*self.ptr).format)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn kind(&self) -> picture::Type {
|
||||
unsafe {
|
||||
picture::Type::from((*self.ptr).pict_type)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_interlaced(&self) -> bool {
|
||||
unsafe {
|
||||
(*self.ptr).interlaced_frame != 0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_top_first(&self) -> bool {
|
||||
unsafe {
|
||||
(*self.ptr).top_field_first != 0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_palette_changed(&self) -> bool {
|
||||
unsafe {
|
||||
(*self.ptr).palette_has_changed != 0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn width(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.ptr).width as u32
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_width(&mut self, value: u32) {
|
||||
unsafe {
|
||||
(*self.ptr).width = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn height(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.ptr).height as u32
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_height(&mut self, value: u32) {
|
||||
unsafe {
|
||||
(*self.ptr).height = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn color_space(&self) -> color::Space {
|
||||
unsafe {
|
||||
color::Space::from(av_frame_get_colorspace(self.ptr))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_color_space(&mut self, value: color::Space) {
|
||||
unsafe {
|
||||
av_frame_set_colorspace(self.ptr, value.into());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn color_range(&self) -> color::Range {
|
||||
unsafe {
|
||||
color::Range::from(av_frame_get_color_range(self.ptr))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_color_range(&mut self, value: color::Range) {
|
||||
unsafe {
|
||||
av_frame_set_color_range(self.ptr, value.into());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn color_primaries(&self) -> color::Primaries {
|
||||
unsafe {
|
||||
color::Primaries::from((*self.ptr).color_primaries)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_color_primaries(&mut self, value: color::Primaries) {
|
||||
unsafe {
|
||||
(*self.ptr).color_primaries = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn color_transfer_characteristic(&self) -> color::TransferCharacteristic {
|
||||
unsafe {
|
||||
color::TransferCharacteristic::from((*self.ptr).color_trc)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_color_transfer_characteristic(&mut self, value: color::TransferCharacteristic) {
|
||||
unsafe {
|
||||
(*self.ptr).color_trc = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chroma_location(&self) -> chroma::Location {
|
||||
unsafe {
|
||||
chroma::Location::from((*self.ptr).chroma_location)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn aspect_ratio(&self) -> Rational {
|
||||
unsafe {
|
||||
Rational((*self.ptr).sample_aspect_ratio)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn coded_number(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.ptr).coded_picture_number as usize
|
||||
}
|
||||
}
|
||||
|
||||
pub fn display_number(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.ptr).display_picture_number as usize
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for Video { }
|
||||
|
||||
impl Deref for Video {
|
||||
type Target = Frame;
|
||||
|
||||
fn deref(&self) -> &Frame {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Video {
|
||||
fn clone(&self) -> Self {
|
||||
Video(self.0.clone())
|
||||
}
|
||||
|
||||
fn clone_from(&mut self, source: &Self) {
|
||||
self.0.clone_from(&source.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Video> for Frame {
|
||||
fn into(self) -> Video {
|
||||
Video(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Frame> for Video {
|
||||
fn into(self) -> Frame {
|
||||
self.0
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user