Skip to content

Commit

Permalink
VGMStream: Clean up FFmpeg code somewhat
Browse files Browse the repository at this point in the history
Remove deprecated functions, make use of free functions that clear the
pointers before returning, etc.

Signed-off-by: Christopher Snowhill <[email protected]>
  • Loading branch information
kode54 committed Feb 18, 2025
1 parent 212ef0f commit 0f1be59
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions Frameworks/vgmstream/vgmstream/src/coding/ffmpeg_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -918,35 +918,26 @@ static void free_ffmpeg_config(ffmpeg_codec_data* data) {

if (data->packet) {
av_packet_unref(data->packet);
av_free(data->packet);
data->packet = NULL;
av_freep(&(data->packet));
}
if (data->frame) {
av_frame_unref(data->frame);
av_free(data->frame);
data->frame = NULL;
av_freep(&(data->frame));
}
if (data->codecCtx) {
avcodec_close(data->codecCtx);
avcodec_free_context(&data->codecCtx);
data->codecCtx = NULL;
}
if (data->formatCtx) {
avformat_close_input(&data->formatCtx);
//avformat_free_context(data->formatCtx); /* done in close_input */
data->formatCtx = NULL;
}
if (data->ioCtx) {
/* buffer passed in is occasionally freed and replaced.
* the replacement must be free'd as well (below) */
data->buffer = data->ioCtx->buffer;
avio_context_free(&data->ioCtx);
//av_free(data->ioCtx); /* done in context_free (same thing) */
data->ioCtx = NULL;
}
if (data->buffer) {
av_free(data->buffer);
data->buffer = NULL;
av_freep(&(data->buffer));
}

//todo avformat_find_stream_info may cause some Win Handle leaks? related to certain option
Expand All @@ -959,8 +950,7 @@ void free_ffmpeg(ffmpeg_codec_data* data) {
free_ffmpeg_config(data);

if (data->header_block) {
av_free(data->header_block);
data->header_block = NULL;
av_freep(&(data->header_block));
}

close_streamfile(data->sf);
Expand Down

0 comments on commit 0f1be59

Please sign in to comment.