ffmpeg_the_third/format/context/
destructor.rs

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