[FFmpeg-devel] [PATCH 4/5] cbs_h2645: Implement functions to make a unit's content writable

Andreas Rheinhardt andreas.rheinhardt at googlemail.com
Sat Nov 24 03:55:37 EET 2018


These functions (which are only implemented for parameter sets) make it
possible to change the contents of the parameter sets as one pleases
without changing/breaking the parsing process of future access units.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at googlemail.com>
---
 libavcodec/cbs_h2645.c | 67 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 65 insertions(+), 2 deletions(-)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index b40cf92a7b..931c7fb2af 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1062,6 +1062,69 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx,
     return 0;
 }
 
+static int cbs_h264_make_unit_writable(CodedBitstreamContext *ctx,
+                                       CodedBitstreamUnit *unit)
+{
+    AVBufferRef *ref;
+
+    switch (unit->type) {
+    case H264_NAL_SPS:
+        {
+            ref = cbs_h264_copy_sps(unit->content);
+            break;
+        }
+    case H264_NAL_PPS:
+        {
+            ref = cbs_h264_copy_pps(unit->content);
+            break;
+        }
+    default:
+        return AVERROR_PATCHWELCOME;
+    }
+    if (!ref)
+        return AVERROR(ENOMEM);
+
+    av_buffer_unref(&unit->content_ref);
+    unit->content     = ref->data;
+    unit->content_ref = ref;
+
+    return 0;
+}
+
+static int cbs_h265_make_unit_writable(CodedBitstreamContext *ctx,
+                                       CodedBitstreamUnit *unit)
+{
+    AVBufferRef *ref;
+
+    switch (unit->type) {
+    case HEVC_NAL_VPS:
+        {
+            ref = cbs_h265_copy_vps(unit->content);
+            break;
+        }
+    case HEVC_NAL_SPS:
+        {
+            ref = cbs_h265_copy_sps(unit->content);
+            break;
+        }
+    case HEVC_NAL_PPS:
+        {
+            ref = cbs_h265_copy_pps(unit->content);
+            break;
+        }
+    default:
+        return AVERROR_PATCHWELCOME;
+    }
+    if (!ref)
+        return AVERROR(ENOMEM);
+
+    av_buffer_unref(&unit->content_ref);
+    unit->content     = ref->data;
+    unit->content_ref = ref;
+
+    return 0;
+}
+
 static int cbs_h2645_write_slice_data(CodedBitstreamContext *ctx,
                                       PutBitContext *pbc, const uint8_t *data,
                                       size_t data_size, int data_bit_start)
@@ -1534,7 +1597,7 @@ const CodedBitstreamType ff_cbs_type_h264 = {
 
     .split_fragment    = &cbs_h2645_split_fragment,
     .read_unit         = &cbs_h264_read_nal_unit,
-    .make_writable     = NULL,
+    .make_writable     = &cbs_h264_make_unit_writable,
     .write_unit        = &cbs_h2645_write_nal_unit,
     .assemble_fragment = &cbs_h2645_assemble_fragment,
 
@@ -1548,7 +1611,7 @@ const CodedBitstreamType ff_cbs_type_h265 = {
 
     .split_fragment    = &cbs_h2645_split_fragment,
     .read_unit         = &cbs_h265_read_nal_unit,
-    .make_writable     = NULL,
+    .make_writable     = &cbs_h265_make_unit_writable,
     .write_unit        = &cbs_h2645_write_nal_unit,
     .assemble_fragment = &cbs_h2645_assemble_fragment,
 
-- 
2.19.1



More information about the ffmpeg-devel mailing list