Skip to main content

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
23unsafe impl Send for Destructor {}
24unsafe impl Sync for Destructor {}
25
26impl Drop for Destructor {
27    fn drop(&mut self) {
28        unsafe {
29            match self.mode {
30                Mode::Input => avformat_close_input(&mut self.ptr),
31
32                Mode::Output => {
33                    avio_close((*self.ptr).pb);
34                    avformat_free_context(self.ptr);
35                }
36            }
37        }
38    }
39}