From 3ba84fb7ea4e09a52fb9bc2a597effdb79440a69 Mon Sep 17 00:00:00 2001 From: meh Date: Sun, 27 Sep 2015 20:30:44 +0200 Subject: [PATCH] codec/encoder/video: check the passed frame is in the proper format --- src/codec/encoder/video.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/codec/encoder/video.rs b/src/codec/encoder/video.rs index f8cd4e3..f0eefab 100644 --- a/src/codec/encoder/video.rs +++ b/src/codec/encoder/video.rs @@ -358,6 +358,10 @@ pub struct Encoder(pub Video); impl Encoder { pub fn encode(&mut self, frame: &frame::Video, out: &mut Packet) -> Result { unsafe { + if self.format() != frame.format() { + return Err(Error::InvalidData); + } + let mut got: c_int = 0; match avcodec_encode_video2(self.0.as_mut_ptr(), out.as_mut_ptr(), frame.as_ptr(), &mut got) { @@ -369,7 +373,12 @@ impl Encoder { pub fn flush(&mut self, out: &mut Packet) -> Result { unsafe { - self.encode(&frame::Video::wrap(ptr::null_mut()), out) + let mut got: c_int = 0; + + match avcodec_encode_video2(self.0.as_mut_ptr(), out.as_mut_ptr(), ptr::null(), &mut got) { + e if e < 0 => Err(Error::from(e)), + _ => Ok(got != 0) + } } }