From a290eebdfb78539942557beaf9157a3ad9407eb3 Mon Sep 17 00:00:00 2001 From: meh Date: Mon, 8 Jun 2015 15:49:36 +0200 Subject: [PATCH] codec/packet: add read/write support --- src/codec/packet/mod.rs | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/codec/packet/mod.rs b/src/codec/packet/mod.rs index 0c9cc78..36b177e 100644 --- a/src/codec/packet/mod.rs +++ b/src/codec/packet/mod.rs @@ -6,9 +6,10 @@ pub use self::flag::Flags; use std::marker::PhantomData; use std::mem; -use libc::c_int; +use libc::c_int; use ffi::*; +use ::{Error, format}; pub struct Packet(AVPacket); @@ -64,6 +65,14 @@ impl Packet { self.0.flags = value.bits(); } + pub fn stream(&self) -> usize { + self.0.stream_index as usize + } + + pub fn set_stream(&mut self, index: usize) { + self.0.stream_index = index as c_int; + } + pub fn pts(&self) -> i64 { self.0.pts as i64 } @@ -91,6 +100,35 @@ impl Packet { pub fn side_data(&self) -> SideDataIter { SideDataIter::new(&self.0) } + + pub fn read(&mut self, format: &mut format::Context) -> Result<(), Error> { + unsafe { + match av_read_frame(format.as_mut_ptr(), self.as_mut_ptr()) { + 0 => Ok(()), + e => Err(Error::from(e)) + } + } + } + + pub fn write(&self, format: &mut format::Context) -> Result { + unsafe { + match av_write_frame(format.as_mut_ptr(), self.as_ptr()) { + 1 => Ok(true), + 0 => Ok(false), + e => Err(Error::from(e)) + } + } + } + + pub fn write_interleaved(&self, format: &mut format::Context) -> Result { + unsafe { + match av_interleaved_write_frame(format.as_mut_ptr(), self.as_ptr()) { + 1 => Ok(true), + 0 => Ok(false), + e => Err(Error::from(e)) + } + } + } } unsafe impl Send for Packet { }