codec/encoder/video: check the passed frame is in the proper format
This commit is contained in:
parent
e1e6e8cca7
commit
3ba84fb7ea
@ -358,6 +358,10 @@ pub struct Encoder(pub Video);
|
||||
impl Encoder {
|
||||
pub fn encode(&mut self, frame: &frame::Video, out: &mut Packet) -> Result<bool, Error> {
|
||||
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<bool, Error> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user