[FFmpeg-devel] [PATCH 3/8] avcodec/cbs_h2645: implement CodedBitstreamType.flush() callbacks

James Almer jamrial at gmail.com
Fri Sep 25 17:43:13 EEST 2020


Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/cbs_h2645.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index b9233f4df7..b6d77dd17f 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1296,6 +1296,24 @@ static int cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx,
     return 0;
 }
 
+static void cbs_h264_flush(CodedBitstreamContext *ctx)
+{
+    CodedBitstreamH264Context *h264 = ctx->priv_data;
+
+    for (int i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++) {
+        av_buffer_unref(&h264->sps_ref[i]);
+        h264->sps[i] = NULL;
+    }
+    for (int i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++) {
+        av_buffer_unref(&h264->pps_ref[i]);
+        h264->pps[i] = NULL;
+    }
+
+    h264->active_sps = NULL;
+    h264->active_pps = NULL;
+    h264->last_slice_nal_unit_type = 0;
+}
+
 static void cbs_h264_close(CodedBitstreamContext *ctx)
 {
     CodedBitstreamH264Context *h264 = ctx->priv_data;
@@ -1309,6 +1327,28 @@ static void cbs_h264_close(CodedBitstreamContext *ctx)
         av_buffer_unref(&h264->pps_ref[i]);
 }
 
+static void cbs_h265_flush(CodedBitstreamContext *ctx)
+{
+    CodedBitstreamH265Context *h265 = ctx->priv_data;
+
+    for (int i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++) {
+        av_buffer_unref(&h265->vps_ref[i]);
+        h265->vps[i] = NULL;
+    }
+    for (int i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++) {
+        av_buffer_unref(&h265->sps_ref[i]);
+        h265->sps[i] = NULL;
+    }
+    for (int i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++) {
+        av_buffer_unref(&h265->pps_ref[i]);
+        h265->pps[i] = NULL;
+    }
+
+    h265->active_vps = NULL;
+    h265->active_sps = NULL;
+    h265->active_pps = NULL;
+}
+
 static void cbs_h265_close(CodedBitstreamContext *ctx)
 {
     CodedBitstreamH265Context *h265 = ctx->priv_data;
@@ -1480,6 +1520,7 @@ const CodedBitstreamType ff_cbs_type_h264 = {
     .write_unit        = &cbs_h264_write_nal_unit,
     .assemble_fragment = &cbs_h2645_assemble_fragment,
 
+    .flush             = &cbs_h264_flush,
     .close             = &cbs_h264_close,
 };
 
@@ -1495,6 +1536,7 @@ const CodedBitstreamType ff_cbs_type_h265 = {
     .write_unit        = &cbs_h265_write_nal_unit,
     .assemble_fragment = &cbs_h2645_assemble_fragment,
 
+    .flush             = &cbs_h265_flush,
     .close             = &cbs_h265_close,
 };
 
-- 
2.27.0



More information about the ffmpeg-devel mailing list