codec/context: make destructors safe

This commit is contained in:
meh
2015-09-17 17:33:31 +02:00
parent 19548810dd
commit 9736980b02
10 changed files with 166 additions and 134 deletions

View File

@ -0,0 +1,35 @@
use ffi::*;
#[derive(Copy, Clone, Debug)]
pub enum Mode {
Input,
Output,
}
pub struct Destructor {
ptr: *mut AVFormatContext,
mode: Mode,
}
impl Destructor {
pub unsafe fn new(ptr: *mut AVFormatContext, mode: Mode) -> Self {
Destructor {
ptr: ptr,
mode: mode,
}
}
}
impl Drop for Destructor {
fn drop(&mut self) {
unsafe {
match self.mode {
Mode::Input =>
avformat_close_input(&mut self.ptr),
Mode::Output =>
avformat_free_context(self.ptr),
}
}
}
}