History

avcodec/mediacodecdec: call MediaCodec.stop on close

Usually the MediaCodec context will be released immediately, or it needs to stay alive due to existing hardware buffers. However we can free resources early in the case of hw_buffer_count == 0 && refcount > 1, which can be reproduced by keeping frames referenced after flushing and closing. mpv currently behaves like this.

sfan5 committed 2 years ago

Commit c7797661 parent 817c6a61 file · +12 −0Browse files

Unified · Split

libavcodec/mediacodecdec_common.c+12−0
@@ -841,6 +841,18 @@ int ff_mediacodec_dec_flush(AVCodecContext *avctx, MediaCodecDecContext *s) · 840 unmodified lines
841 841
842int ff_mediacodec_dec_close(AVCodecContext *avctx, MediaCodecDecContext *s)842int ff_mediacodec_dec_close(AVCodecContext *avctx, MediaCodecDecContext *s)
843{843{
844 if (!s)
845 return 0;
846
847 if (s->codec) {
848 if (atomic_load(&s->hw_buffer_count) == 0) {
849 ff_AMediaCodec_stop(s->codec);
850 av_log(avctx, AV_LOG_DEBUG, "MediaCodec %p stopped\n", s->codec);
851 } else {
852 av_log(avctx, AV_LOG_DEBUG, "Not stopping MediaCodec (there are buffers pending)\n");
853 }
854 }
855
844 ff_mediacodec_dec_unref(s);856 ff_mediacodec_dec_unref(s);
845 857
846 return 0;858 return 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t