Skip to content

Commit

Permalink
media_utils: fix segfault when stopping a recording
Browse files Browse the repository at this point in the history
  • Loading branch information
Megamouse committed Jan 12, 2024
1 parent 17aeefe commit f7fa5aa
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 19 deletions.
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

0 comments on commit f7fa5aa

Please sign in to comment.