1use ffi::*;
2
3#[derive(Copy, Clone, Debug)]
4pub enum Mode {
5 Input,
6 Output,
7}
8
9pub struct Destructor {
10 ptr: *mut AVFormatContext,
11 mode: Mode,
12}
13
14impl Destructor {
15 pub unsafe fn new(ptr: *mut AVFormatContext, mode: Mode) -> Self {
16 Destructor { ptr, mode }
17 }
18}
19
20impl Drop for Destructor {
21 fn drop(&mut self) {
22 unsafe {
23 match self.mode {
24 Mode::Input => avformat_close_input(&mut self.ptr),
25
26 Mode::Output => {
27 avio_close((*self.ptr).pb);
28 avformat_free_context(self.ptr);
29 }
30 }
31 }
32 }
33}
34