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

Andreas Rheinhardt andreas.rheinhardt at googlemail.com
Mon Nov 26 15:39:12 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 | 65 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 559290bd91..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,6 +1597,7 @@ const CodedBitstreamType ff_cbs_type_h264 = {
 
     .split_fragment    = &cbs_h2645_split_fragment,
     .read_unit         = &cbs_h264_read_nal_unit,
+    .make_writable     = &cbs_h264_make_unit_writable,
     .write_unit        = &cbs_h2645_write_nal_unit,
     .assemble_fragment = &cbs_h2645_assemble_fragment,
 
@@ -1547,6 +1611,7 @@ const CodedBitstreamType ff_cbs_type_h265 = {
 
     .split_fragment    = &cbs_h2645_split_fragment,
     .read_unit         = &cbs_h265_read_nal_unit,
+    .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