Skip to content

Commit 2ad4046

Browse files
fix: add patch for ffmpeg mediacodec
1 parent df6a923 commit 2ad4046

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
From 9aa111c400cc3245edf870c431a5e271432ef5f2 Mon Sep 17 00:00:00 2001
2+
From: sfan5 <[email protected]>
3+
Date: Wed, 7 Aug 2024 17:48:06 +0200
4+
Subject: [PATCH v2] avcodec/mediacodecdec: call MediaCodec.stop on close
5+
6+
Usually the MediaCodec context will be released immediately, or it needs to stay
7+
alive due to existing hardware buffers.
8+
9+
However we can free resources early in the case of
10+
hw_buffer_count == 0 && refcount > 1, which can be reproduced by keeping frames
11+
referenced after flushing and closing. mpv currently behaves like this.
12+
13+
Signed-off-by: sfan5 <[email protected]>
14+
---
15+
libavcodec/mediacodecdec_common.c | 12 ++++++++++++
16+
1 file changed, 12 insertions(+)
17+
18+
diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c
19+
index d6f91e6e89..c888dea8cf 100644
20+
--- a/libavcodec/mediacodecdec_common.c
21+
+++ b/libavcodec/mediacodecdec_common.c
22+
@@ -841,6 +841,18 @@ int ff_mediacodec_dec_flush(AVCodecContext *avctx, MediaCodecDecContext *s)
23+
24+
int ff_mediacodec_dec_close(AVCodecContext *avctx, MediaCodecDecContext *s)
25+
{
26+
+ if (!s)
27+
+ return 0;
28+
+
29+
+ if (s->codec) {
30+
+ if (atomic_load(&s->hw_buffer_count) == 0) {
31+
+ ff_AMediaCodec_stop(s->codec);
32+
+ av_log(avctx, AV_LOG_DEBUG, "MediaCodec %p stopped\n", s->codec);
33+
+ } else {
34+
+ av_log(avctx, AV_LOG_DEBUG, "Not stopping MediaCodec (there are buffers pending)\n");
35+
+ }
36+
+ }
37+
+
38+
ff_mediacodec_dec_unref(s);
39+
40+
return 0;
41+
--
42+
2.46.0
43+

0 commit comments

Comments
 (0)