[FFmpeg-devel] [PATCH] lavc/h264_ps: add ff_h264_ps_uninit and use it

Matthieu Bouron matthieu.bouron at gmail.com
Mon Jun 20 16:13:02 CEST 2016


From: Matthieu Bouron <matthieu.bouron at stupeflix.com>

---
 libavcodec/h264.c        | 10 +---------
 libavcodec/h264.h        |  6 ++++++
 libavcodec/h264_parser.c |  8 +-------
 libavcodec/h264_ps.c     | 17 +++++++++++++++++
 4 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index f2dc473..9d2caba 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -377,15 +377,7 @@ static av_cold int h264_decode_end(AVCodecContext *avctx)
     h->nb_slice_ctx = 0;
 
     ff_h264_sei_uninit(&h->sei);
-
-    for (i = 0; i < MAX_SPS_COUNT; i++)
-        av_buffer_unref(&h->ps.sps_list[i]);
-
-    for (i = 0; i < MAX_PPS_COUNT; i++)
-        av_buffer_unref(&h->ps.pps_list[i]);
-
-    av_buffer_unref(&h->ps.sps_ref);
-    av_buffer_unref(&h->ps.pps_ref);
+    ff_h264_ps_uninit(&h->ps);
 
     ff_h2645_packet_uninit(&h->pkt);
 
diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index 61d94cd..8e92f62 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -695,6 +695,12 @@ typedef struct H264Context {
 extern const uint16_t ff_h264_mb_sizes[4];
 
 /**
+ * Uninit H264 param sets structure.
+ */
+
+void ff_h264_ps_uninit(H264ParamSets *ps);
+
+/**
  * Decode SPS
  */
 int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index 3ce049e..42ad932 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -649,17 +649,11 @@ static void h264_close(AVCodecParserContext *s)
 {
     H264ParseContext *p = s->priv_data;
     ParseContext *pc = &p->pc;
-    int i;
 
     av_freep(&pc->buffer);
 
     ff_h264_sei_uninit(&p->sei);
-
-    for (i = 0; i < FF_ARRAY_ELEMS(p->ps.sps_list); i++)
-        av_buffer_unref(&p->ps.sps_list[i]);
-
-    for (i = 0; i < FF_ARRAY_ELEMS(p->ps.pps_list); i++)
-        av_buffer_unref(&p->ps.pps_list[i]);
+    ff_h264_ps_uninit(&p->ps);
 }
 
 static av_cold int init(AVCodecParserContext *s)
diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
index 521f560..fb05b05 100644
--- a/libavcodec/h264_ps.c
+++ b/libavcodec/h264_ps.c
@@ -298,6 +298,23 @@ static void decode_scaling_matrices(GetBitContext *gb, SPS *sps,
     }
 }
 
+void ff_h264_ps_uninit(H264ParamSets *ps)
+{
+    int i;
+
+    for (i = 0; i < MAX_SPS_COUNT; i++)
+        av_buffer_unref(&ps->sps_list[i]);
+
+    for (i = 0; i < MAX_PPS_COUNT; i++)
+        av_buffer_unref(&ps->pps_list[i]);
+
+    av_buffer_unref(&ps->sps_ref);
+    av_buffer_unref(&ps->pps_ref);
+
+    ps->pps = NULL;
+    ps->sps = NULL;
+}
+
 int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
                                      H264ParamSets *ps, int ignore_truncation)
 {
-- 
2.8.3



More information about the ffmpeg-devel mailing list