codec/packet: add inline attributes

This commit is contained in:
meh 2015-10-01 20:41:42 +02:00
parent 8570e3a5b4
commit 14c7586030

View File

@ -18,20 +18,24 @@ unsafe impl Send for Packet { }
unsafe impl Sync for Packet { } unsafe impl Sync for Packet { }
impl Packet { impl Packet {
#[inline(always)]
pub unsafe fn as_ptr(&self) -> *const AVPacket { pub unsafe fn as_ptr(&self) -> *const AVPacket {
&self.0 &self.0
} }
#[inline(always)]
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVPacket { pub unsafe fn as_mut_ptr(&mut self) -> *mut AVPacket {
&mut self.0 &mut self.0
} }
#[inline(always)]
pub unsafe fn is_empty(&self) -> bool { pub unsafe fn is_empty(&self) -> bool {
self.0.buf.is_null() self.0.buf.is_null()
} }
} }
impl Packet { impl Packet {
#[inline]
pub fn empty() -> Self { pub fn empty() -> Self {
unsafe { unsafe {
let mut pkt: AVPacket = mem::zeroed(); let mut pkt: AVPacket = mem::zeroed();
@ -42,6 +46,7 @@ impl Packet {
} }
} }
#[inline]
pub fn new(size: usize) -> Self { pub fn new(size: usize) -> Self {
unsafe { unsafe {
let mut pkt: AVPacket = mem::zeroed(); let mut pkt: AVPacket = mem::zeroed();
@ -53,6 +58,7 @@ impl Packet {
} }
} }
#[inline]
pub fn copy(data: &[u8]) -> Self { pub fn copy(data: &[u8]) -> Self {
use std::io::Write; use std::io::Write;
@ -62,18 +68,21 @@ impl Packet {
packet packet
} }
#[inline]
pub fn shrink(&mut self, size: usize) { pub fn shrink(&mut self, size: usize) {
unsafe { unsafe {
av_shrink_packet(&mut self.0, size as c_int); av_shrink_packet(&mut self.0, size as c_int);
} }
} }
#[inline]
pub fn grow(&mut self, size: usize) { pub fn grow(&mut self, size: usize) {
unsafe { unsafe {
av_grow_packet(&mut self.0, size as c_int); av_grow_packet(&mut self.0, size as c_int);
} }
} }
#[inline]
pub fn rescale_ts<S, D>(&mut self, source: S, destination: D) -> &mut Self pub fn rescale_ts<S, D>(&mut self, source: S, destination: D) -> &mut Self
where S: Into<Rational>, where S: Into<Rational>,
D: Into<Rational> D: Into<Rational>
@ -85,34 +94,41 @@ impl Packet {
self self
} }
#[inline]
pub fn flags(&self) -> Flags { pub fn flags(&self) -> Flags {
Flags::from_bits_truncate(self.0.flags) Flags::from_bits_truncate(self.0.flags)
} }
#[inline]
pub fn set_flags(&mut self, value: Flags) -> &mut Self { pub fn set_flags(&mut self, value: Flags) -> &mut Self {
self.0.flags = value.bits(); self.0.flags = value.bits();
self self
} }
#[inline]
pub fn is_key(&self) -> bool { pub fn is_key(&self) -> bool {
self.flags().contains(flag::KEY) self.flags().contains(flag::KEY)
} }
#[inline]
pub fn is_corrupt(&self) -> bool { pub fn is_corrupt(&self) -> bool {
self.flags().contains(flag::CORRUPT) self.flags().contains(flag::CORRUPT)
} }
#[inline]
pub fn stream(&self) -> usize { pub fn stream(&self) -> usize {
self.0.stream_index as usize self.0.stream_index as usize
} }
#[inline]
pub fn set_stream(&mut self, index: usize) -> &mut Self { pub fn set_stream(&mut self, index: usize) -> &mut Self {
self.0.stream_index = index as c_int; self.0.stream_index = index as c_int;
self self
} }
#[inline]
pub fn pts(&self) -> Option<i64> { pub fn pts(&self) -> Option<i64> {
match self.0.pts { match self.0.pts {
AV_NOPTS_VALUE => None, AV_NOPTS_VALUE => None,
@ -120,30 +136,37 @@ impl Packet {
} }
} }
#[inline]
pub fn dts(&self) -> i64 { pub fn dts(&self) -> i64 {
self.0.dts as i64 self.0.dts as i64
} }
#[inline]
pub fn size(&self) -> usize { pub fn size(&self) -> usize {
self.0.size as usize self.0.size as usize
} }
#[inline]
pub fn duration(&self) -> usize { pub fn duration(&self) -> usize {
self.0.duration as usize self.0.duration as usize
} }
#[inline]
pub fn position(&self) -> isize { pub fn position(&self) -> isize {
self.0.pos as isize self.0.pos as isize
} }
#[inline]
pub fn convergence(&self) -> isize { pub fn convergence(&self) -> isize {
self.0.convergence_duration as isize self.0.convergence_duration as isize
} }
#[inline]
pub fn side_data(&self) -> SideDataIter { pub fn side_data(&self) -> SideDataIter {
SideDataIter::new(&self.0) SideDataIter::new(&self.0)
} }
#[inline]
pub fn data(&self) -> Option<&[u8]> { pub fn data(&self) -> Option<&[u8]> {
unsafe { unsafe {
if self.0.data.is_null() { if self.0.data.is_null() {
@ -155,6 +178,7 @@ impl Packet {
} }
} }
#[inline]
pub fn data_mut(&mut self) -> Option<&mut [u8]> { pub fn data_mut(&mut self) -> Option<&mut [u8]> {
unsafe { unsafe {
if self.0.data.is_null() { if self.0.data.is_null() {
@ -166,6 +190,7 @@ impl Packet {
} }
} }
#[inline]
pub fn read(&mut self, format: &mut format::context::Input) -> Result<(), Error> { pub fn read(&mut self, format: &mut format::context::Input) -> Result<(), Error> {
unsafe { unsafe {
match av_read_frame(format.as_mut_ptr(), self.as_mut_ptr()) { match av_read_frame(format.as_mut_ptr(), self.as_mut_ptr()) {
@ -175,6 +200,7 @@ impl Packet {
} }
} }
#[inline]
pub fn write(&self, format: &mut format::context::Output) -> Result<bool, Error> { pub fn write(&self, format: &mut format::context::Output) -> Result<bool, Error> {
unsafe { unsafe {
if self.is_empty() { if self.is_empty() {
@ -189,6 +215,7 @@ impl Packet {
} }
} }
#[inline]
pub fn write_interleaved(&self, format: &mut format::context::Output) -> Result<bool, Error> { pub fn write_interleaved(&self, format: &mut format::context::Output) -> Result<bool, Error> {
unsafe { unsafe {
if self.is_empty() { if self.is_empty() {
@ -205,6 +232,7 @@ impl Packet {
} }
impl Clone for Packet { impl Clone for Packet {
#[inline]
fn clone(&self) -> Self { fn clone(&self) -> Self {
let mut pkt = Packet::empty(); let mut pkt = Packet::empty();
pkt.clone_from(self); pkt.clone_from(self);
@ -212,6 +240,7 @@ impl Clone for Packet {
pkt pkt
} }
#[inline]
fn clone_from(&mut self, source: &Self) { fn clone_from(&mut self, source: &Self) {
unsafe { unsafe {
av_copy_packet(&mut self.0, &source.0); av_copy_packet(&mut self.0, &source.0);