-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add patch for ffmpeg mediacodec
- Loading branch information
1 parent
df6a923
commit 2ad4046
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...s/patches/ffmpeg/FFmpeg-devel-v2-avcodec-mediacodecdec-call-MediaCodec.stop-on-close.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
From 9aa111c400cc3245edf870c431a5e271432ef5f2 Mon Sep 17 00:00:00 2001 | ||
From: sfan5 <[email protected]> | ||
Date: Wed, 7 Aug 2024 17:48:06 +0200 | ||
Subject: [PATCH v2] 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. | ||
|
||
Signed-off-by: sfan5 <[email protected]> | ||
--- | ||
libavcodec/mediacodecdec_common.c | 12 ++++++++++++ | ||
1 file changed, 12 insertions(+) | ||
|
||
diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c | ||
index d6f91e6e89..c888dea8cf 100644 | ||
--- a/libavcodec/mediacodecdec_common.c | ||
+++ b/libavcodec/mediacodecdec_common.c | ||
@@ -841,6 +841,18 @@ int ff_mediacodec_dec_flush(AVCodecContext *avctx, MediaCodecDecContext *s) | ||
|
||
int ff_mediacodec_dec_close(AVCodecContext *avctx, MediaCodecDecContext *s) | ||
{ | ||
+ if (!s) | ||
+ return 0; | ||
+ | ||
+ if (s->codec) { | ||
+ if (atomic_load(&s->hw_buffer_count) == 0) { | ||
+ ff_AMediaCodec_stop(s->codec); | ||
+ av_log(avctx, AV_LOG_DEBUG, "MediaCodec %p stopped\n", s->codec); | ||
+ } else { | ||
+ av_log(avctx, AV_LOG_DEBUG, "Not stopping MediaCodec (there are buffers pending)\n"); | ||
+ } | ||
+ } | ||
+ | ||
ff_mediacodec_dec_unref(s); | ||
|
||
return 0; | ||
-- | ||
2.46.0 | ||
|