fix: demuxer cleanup

This commit is contained in:
kieran 2024-11-29 23:40:10 +00:00
parent b1f054d7d1
commit df69b2f05d
No known key found for this signature in database
GPG Key ID: DE71CEB3925BE941
2 changed files with 10 additions and 5 deletions

View File

@ -246,11 +246,12 @@ impl Demuxer {
impl Drop for Demuxer {
fn drop(&mut self) {
if !self.ctx.is_null() {
unsafe {
unsafe {
if !self.ctx.is_null() {
if let DemuxerInput::Reader(_, _) = self.input {
av_free((*(*self.ctx).pb).buffer as *mut _);
drop(SlimBox::<dyn Read>::from_raw((*(*self.ctx).pb).opaque));
avio_context_free(&mut (*self.ctx).pb);
}
avformat_free_context(self.ctx);
}

View File

@ -1,11 +1,11 @@
use crate::{bail_ffmpeg, cstr, set_opts, Encoder, AVIO_BUFFER_SIZE};
use anyhow::{bail, Result};
use ffmpeg_sys_the_third::{
av_interleaved_write_frame, av_mallocz, av_packet_rescale_ts, av_write_trailer,
av_free, av_interleaved_write_frame, av_mallocz, av_packet_rescale_ts, av_write_trailer,
avcodec_parameters_copy, avcodec_parameters_from_context, avformat_alloc_output_context2,
avformat_free_context, avformat_new_stream, avformat_write_header, avio_alloc_context,
avio_close, avio_open, AVFormatContext, AVIOContext, AVPacket, AVStream, AVERROR_EOF,
AVFMT_GLOBALHEADER, AVFMT_NOFILE, AVIO_FLAG_DIRECT, AVIO_FLAG_WRITE,
avio_close, avio_context_free, avio_open, AVFormatContext, AVIOContext, AVPacket, AVStream,
AVERROR_EOF, AVFMT_GLOBALHEADER, AVFMT_NOFILE, AVIO_FLAG_DIRECT, AVIO_FLAG_WRITE,
AV_CODEC_FLAG_GLOBAL_HEADER,
};
use slimbox::{slimbox_unsize, SlimBox, SlimMut};
@ -372,10 +372,14 @@ impl Muxer {
}
}
MuxerOutput::WriterSeeker(_) => {
av_free((*(*self.ctx).pb).buffer as *mut _);
drop(SlimBox::<dyn WriteSeek>::from_raw((*(*self.ctx).pb).opaque));
avio_context_free(&mut (*self.ctx).pb);
}
MuxerOutput::Writer(_) => {
av_free((*(*self.ctx).pb).buffer as *mut _);
drop(SlimBox::<dyn Write>::from_raw((*(*self.ctx).pb).opaque));
avio_context_free(&mut (*self.ctx).pb);
}
}
avformat_free_context(self.ctx);