*: make internal pointer handling safer
This commit is contained in:
@ -3,7 +3,7 @@ use std::mem;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use ffi::*;
|
||||
use ::{Rational, Picture};
|
||||
use ::Rational;
|
||||
use ::util::format;
|
||||
use ::util::chroma;
|
||||
use ::picture;
|
||||
@ -13,10 +13,16 @@ use super::Frame;
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct Video(Frame);
|
||||
|
||||
impl Video {
|
||||
pub unsafe fn wrap(ptr: *mut AVFrame) -> Self {
|
||||
Video(Frame::wrap(ptr))
|
||||
}
|
||||
}
|
||||
|
||||
impl Video {
|
||||
pub fn empty() -> Self {
|
||||
unsafe {
|
||||
Video(Frame { ptr: av_frame_alloc() })
|
||||
Video(Frame::empty())
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,160 +34,152 @@ impl Video {
|
||||
frame.set_width(width);
|
||||
frame.set_height(height);
|
||||
|
||||
av_frame_get_buffer(frame.ptr, 1);
|
||||
av_frame_get_buffer(frame.as_mut_ptr(), 1);
|
||||
|
||||
frame
|
||||
}
|
||||
}
|
||||
|
||||
pub fn picture(&self) -> Picture {
|
||||
Picture::wrap(self.ptr as *mut AVPicture, self.format(), self.width(), self.height())
|
||||
}
|
||||
|
||||
pub fn picture_mut(&mut 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 {
|
||||
if (*self.as_ptr()).format == -1 {
|
||||
format::Pixel::None
|
||||
}
|
||||
else {
|
||||
format::Pixel::from(mem::transmute::<_, AVPixelFormat>(((*self.ptr).format)))
|
||||
format::Pixel::from(mem::transmute::<_, AVPixelFormat>(((*self.as_ptr()).format)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_format(&mut self, value: format::Pixel) {
|
||||
unsafe {
|
||||
(*self.ptr).format = mem::transmute::<AVPixelFormat, c_int>(value.into());
|
||||
(*self.as_mut_ptr()).format = mem::transmute::<AVPixelFormat, c_int>(value.into());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn kind(&self) -> picture::Type {
|
||||
unsafe {
|
||||
picture::Type::from((*self.ptr).pict_type)
|
||||
picture::Type::from((*self.as_ptr()).pict_type)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_interlaced(&self) -> bool {
|
||||
unsafe {
|
||||
(*self.ptr).interlaced_frame != 0
|
||||
(*self.as_ptr()).interlaced_frame != 0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_top_first(&self) -> bool {
|
||||
unsafe {
|
||||
(*self.ptr).top_field_first != 0
|
||||
(*self.as_ptr()).top_field_first != 0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_palette_changed(&self) -> bool {
|
||||
unsafe {
|
||||
(*self.ptr).palette_has_changed != 0
|
||||
(*self.as_ptr()).palette_has_changed != 0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn width(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.ptr).width as u32
|
||||
(*self.as_ptr()).width as u32
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_width(&mut self, value: u32) {
|
||||
unsafe {
|
||||
(*self.ptr).width = value as c_int;
|
||||
(*self.as_mut_ptr()).width = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn height(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.ptr).height as u32
|
||||
(*self.as_ptr()).height as u32
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_height(&mut self, value: u32) {
|
||||
unsafe {
|
||||
(*self.ptr).height = value as c_int;
|
||||
(*self.as_mut_ptr()).height = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn color_space(&self) -> color::Space {
|
||||
unsafe {
|
||||
color::Space::from(av_frame_get_colorspace(self.ptr))
|
||||
color::Space::from(av_frame_get_colorspace(self.as_ptr()))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_color_space(&mut self, value: color::Space) {
|
||||
unsafe {
|
||||
av_frame_set_colorspace(self.ptr, value.into());
|
||||
av_frame_set_colorspace(self.as_mut_ptr(), value.into());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn color_range(&self) -> color::Range {
|
||||
unsafe {
|
||||
color::Range::from(av_frame_get_color_range(self.ptr))
|
||||
color::Range::from(av_frame_get_color_range(self.as_ptr()))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_color_range(&mut self, value: color::Range) {
|
||||
unsafe {
|
||||
av_frame_set_color_range(self.ptr, value.into());
|
||||
av_frame_set_color_range(self.as_mut_ptr(), value.into());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn color_primaries(&self) -> color::Primaries {
|
||||
unsafe {
|
||||
color::Primaries::from((*self.ptr).color_primaries)
|
||||
color::Primaries::from((*self.as_ptr()).color_primaries)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_color_primaries(&mut self, value: color::Primaries) {
|
||||
unsafe {
|
||||
(*self.ptr).color_primaries = value.into();
|
||||
(*self.as_mut_ptr()).color_primaries = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn color_transfer_characteristic(&self) -> color::TransferCharacteristic {
|
||||
unsafe {
|
||||
color::TransferCharacteristic::from((*self.ptr).color_trc)
|
||||
color::TransferCharacteristic::from((*self.as_ptr()).color_trc)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_color_transfer_characteristic(&mut self, value: color::TransferCharacteristic) {
|
||||
unsafe {
|
||||
(*self.ptr).color_trc = value.into();
|
||||
(*self.as_mut_ptr()).color_trc = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chroma_location(&self) -> chroma::Location {
|
||||
unsafe {
|
||||
chroma::Location::from((*self.ptr).chroma_location)
|
||||
chroma::Location::from((*self.as_ptr()).chroma_location)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn aspect_ratio(&self) -> Rational {
|
||||
unsafe {
|
||||
Rational((*self.ptr).sample_aspect_ratio)
|
||||
Rational((*self.as_ptr()).sample_aspect_ratio)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn coded_number(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.ptr).coded_picture_number as usize
|
||||
(*self.as_ptr()).coded_picture_number as usize
|
||||
}
|
||||
}
|
||||
|
||||
pub fn display_number(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.ptr).display_picture_number as usize
|
||||
(*self.as_ptr()).display_picture_number as usize
|
||||
}
|
||||
}
|
||||
|
||||
pub fn repeat(&self) -> f64 {
|
||||
unsafe {
|
||||
(*self.ptr).repeat_pict as f64
|
||||
(*self.as_ptr()).repeat_pict as f64
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -212,8 +210,8 @@ impl Clone for Video {
|
||||
|
||||
fn clone_from(&mut self, source: &Self) {
|
||||
unsafe {
|
||||
av_frame_copy(self.ptr, source.ptr);
|
||||
av_frame_copy_props(self.ptr, source.ptr);
|
||||
av_frame_copy(self.as_mut_ptr(), source.as_ptr());
|
||||
av_frame_copy_props(self.as_mut_ptr(), source.as_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user