[FFmpeg-devel] [PATCH v2] avcodec/h264_parser: Try to avoid (un)referencing

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Fri May 29 19:31:57 EEST 2020


When a slice is encountered, the H.264 parser up until now always
unreferenced and reset the currently active PPS; immediately
afterwards, the currently active PPS is set again which includes
referencing it. Given that it is typical for the active parameter
sets to change only seldomly, most of the time the new active PPS will
be the old one. Therefore this commit checks for this and only
unreferences the PPS if it changed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
New and much simplified version of [1]. This has been made possible by
5e316096fa9ba4493d9dbb48847ad8e0b0e188c3.

[1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2019-August/248374.html

 libavcodec/h264_parser.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index d988484660..c6fd049f46 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -363,6 +363,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
                 goto fail;
             }
 
+            if (p->ps.pps != (const PPS*)p->ps.pps_list[pps_id]->data) {
             av_buffer_unref(&p->ps.pps_ref);
             p->ps.pps = NULL;
             p->ps.sps = NULL;
@@ -371,6 +372,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
                 goto fail;
             p->ps.pps = (const PPS*)p->ps.pps_ref->data;
             p->ps.sps = p->ps.pps->sps;
+            }
             sps       = p->ps.sps;
 
             // heuristic to detect non marked keyframes
-- 
2.20.1



More information about the ffmpeg-devel mailing list