Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

media_utils: fix segfault when stopping a recording #15040

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions rpcs3/Emu/Cell/Modules/cellAdec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ class AudioDecoder : public ppu_thread
}
if (ctx)
{
avcodec_close(ctx);
avcodec_free_context(&ctx);
}
if (io_buf)
Expand All @@ -382,7 +381,6 @@ class AudioDecoder : public ppu_thread
{
if (fmt->pb) av_freep(&fmt->pb);
avformat_close_input(&fmt);
avformat_free_context(fmt);
}
}

Expand Down
1 change: 0 additions & 1 deletion rpcs3/Emu/Cell/Modules/cellVdec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ struct vdec_context final

~vdec_context()
{
avcodec_close(ctx);
avcodec_free_context(&ctx);
sws_freeContext(sws);
}
Expand Down
20 changes: 4 additions & 16 deletions rpcs3/util/media_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ namespace utils
{
// Failed to load stream information
avformat_close_input(&av_format_ctx);
avformat_free_context(av_format_ctx);
media_log.notice("get_media_info: avformat_find_stream_info: could not load stream information. error=%d='%s' file='%s'", err, av_error_to_string(err), path);
return { false, std::move(info) };
}
Expand Down Expand Up @@ -227,7 +226,6 @@ namespace utils
{
// Failed to find a stream
avformat_close_input(&av_format_ctx);
avformat_free_context(av_format_ctx);
media_log.notice("get_media_info: Failed to match stream of type %d in file='%s'", av_media_type, path);
return { false, std::move(info) };
}
Expand Down Expand Up @@ -258,7 +256,6 @@ namespace utils
}

avformat_close_input(&av_format_ctx);
avformat_free_context(av_format_ctx);

return { true, std::move(info) };
}
Expand Down Expand Up @@ -302,22 +299,13 @@ namespace utils
if (sws)
sws_freeContext(sws);
if (audio.context)
{
avcodec_close(audio.context);
avcodec_free_context(&audio.context);
}
if (video.context)
{
avcodec_close(video.context);
avcodec_free_context(&video.context);
}
// AVCodec is managed by libavformat, no need to free it
// see: https://stackoverflow.com/a/18047320
if (format_context)
{
avformat_close_input(&format_context);
avformat_free_context(format_context);
}
//if (stream)
// av_free(stream);
if (kill_callback)
Expand Down Expand Up @@ -1266,9 +1254,9 @@ namespace utils
{
media_log.error("video_encoder: avformat_write_header failed. Error: %d='%s'", err, av_error_to_string(err));

if (int err = avio_close(av.format_context->pb); err != 0)
if (int err = avio_closep(&av.format_context->pb); err != 0)
{
media_log.error("video_encoder: avio_close failed. Error: %d='%s'", err, av_error_to_string(err));
media_log.error("video_encoder: avio_closep failed. Error: %d='%s'", err, av_error_to_string(err));
}

has_error = true;
Expand Down Expand Up @@ -1645,9 +1633,9 @@ namespace utils
media_log.error("video_encoder: av_write_trailer failed. Error: %d='%s'", err, av_error_to_string(err));
}

if (int err = avio_close(av.format_context->pb); err != 0)
if (int err = avio_closep(&av.format_context->pb); err != 0)
{
media_log.error("video_encoder: avio_close failed. Error: %d='%s'", err, av_error_to_string(err));
media_log.error("video_encoder: avio_closep failed. Error: %d='%s'", err, av_error_to_string(err));
}
});
}
Expand Down