[FFmpeg-cvslog] avcodec/cbs: Make ff_cbs_insert_unit_data() always append the new unit

Andreas Rheinhardt git at videolan.org
Tue Feb 8 08:25:36 EET 2022


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Fri Feb  4 13:58:36 2022 +0100| [66d7a211329e79ad61316f67726e89d07c21d862] | committer: Andreas Rheinhardt

avcodec/cbs: Make ff_cbs_insert_unit_data() always append the new unit

All split functions (the only users of this function) only
append units.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=66d7a211329e79ad61316f67726e89d07c21d862
---

 libavcodec/cbs.c       | 22 +++++++++++++++-------
 libavcodec/cbs.h       |  5 ++---
 libavcodec/cbs_av1.c   |  2 +-
 libavcodec/cbs_h2645.c |  2 +-
 libavcodec/cbs_jpeg.c  |  2 +-
 libavcodec/cbs_mpeg2.c |  2 +-
 libavcodec/cbs_vp9.c   |  4 ++--
 7 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index d7aa67c3af..e829caa0a0 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -789,18 +789,16 @@ int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag,
     return 0;
 }
 
-int ff_cbs_insert_unit_data(CodedBitstreamFragment *frag,
-                            int position,
-                            CodedBitstreamUnitType type,
-                            uint8_t *data, size_t data_size,
-                            AVBufferRef *data_buf)
+static int cbs_insert_unit_data(CodedBitstreamFragment *frag,
+                                CodedBitstreamUnitType type,
+                                uint8_t *data, size_t data_size,
+                                AVBufferRef *data_buf,
+                                int position)
 {
     CodedBitstreamUnit *unit;
     AVBufferRef *data_ref;
     int err;
 
-    if (position == -1)
-        position = frag->nb_units;
     av_assert0(position >= 0 && position <= frag->nb_units);
 
     if (data_buf)
@@ -828,6 +826,16 @@ int ff_cbs_insert_unit_data(CodedBitstreamFragment *frag,
     return 0;
 }
 
+int ff_cbs_append_unit_data(CodedBitstreamFragment *frag,
+                            CodedBitstreamUnitType type,
+                            uint8_t *data, size_t data_size,
+                            AVBufferRef *data_buf)
+{
+    return cbs_insert_unit_data(frag, type,
+                                data, data_size, data_buf,
+                                frag->nb_units);
+}
+
 void ff_cbs_delete_unit(CodedBitstreamFragment *frag,
                         int position)
 {
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index 87ea14cd07..5583063b5e 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -393,14 +393,13 @@ int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag,
                                AVBufferRef *content_buf);
 
 /**
- * Insert a new unit into a fragment with the given data bitstream.
+ * Add a new unit to a fragment with the given data bitstream.
  *
  * If data_buf is not supplied then data must have been allocated with
  * av_malloc() and will on success become owned by the unit after this
  * call or freed on error.
  */
-int ff_cbs_insert_unit_data(CodedBitstreamFragment *frag,
-                            int position,
+int ff_cbs_append_unit_data(CodedBitstreamFragment *frag,
                             CodedBitstreamUnitType type,
                             uint8_t *data, size_t data_size,
                             AVBufferRef *data_buf);
diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index 302e1f38f5..04314443de 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -828,7 +828,7 @@ static int cbs_av1_split_fragment(CodedBitstreamContext *ctx,
             goto fail;
         }
 
-        err = ff_cbs_insert_unit_data(frag, -1, header.obu_type,
+        err = ff_cbs_append_unit_data(frag, header.obu_type,
                                       data, obu_length, frag->data_ref);
         if (err < 0)
             goto fail;
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 3396c059c9..10b3bcc70b 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -493,7 +493,7 @@ static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
         ref = (nal->data == nal->raw_data) ? frag->data_ref
                                            : packet->rbsp.rbsp_buffer_ref;
 
-        err = ff_cbs_insert_unit_data(frag, -1, nal->type,
+        err = ff_cbs_append_unit_data(frag, nal->type,
                             (uint8_t*)nal->data, size, ref);
         if (err < 0)
             return err;
diff --git a/libavcodec/cbs_jpeg.c b/libavcodec/cbs_jpeg.c
index ae263ba038..da7ee808cf 100644
--- a/libavcodec/cbs_jpeg.c
+++ b/libavcodec/cbs_jpeg.c
@@ -226,7 +226,7 @@ static int cbs_jpeg_split_fragment(CodedBitstreamContext *ctx,
             data_ref  = frag->data_ref;
         }
 
-        err = ff_cbs_insert_unit_data(frag, -1, marker,
+        err = ff_cbs_append_unit_data(frag, marker,
                                       data, data_size, data_ref);
         if (err < 0)
             return err;
diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 4395bbf047..2bf38c6001 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -186,7 +186,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
            final     = 1;
         }
 
-        err = ff_cbs_insert_unit_data(frag, -1, unit_type, (uint8_t*)start,
+        err = ff_cbs_append_unit_data(frag, unit_type, (uint8_t*)start,
                                       unit_size, frag->data_ref);
         if (err < 0)
             return err;
diff --git a/libavcodec/cbs_vp9.c b/libavcodec/cbs_vp9.c
index e0b8c02ac2..333d70ba4e 100644
--- a/libavcodec/cbs_vp9.c
+++ b/libavcodec/cbs_vp9.c
@@ -451,7 +451,7 @@ static int cbs_vp9_split_fragment(CodedBitstreamContext *ctx,
                 return AVERROR_INVALIDDATA;
             }
 
-            err = ff_cbs_insert_unit_data(frag, -1, 0,
+            err = ff_cbs_append_unit_data(frag, 0,
                                           frag->data + pos,
                                           sfi.frame_sizes[i],
                                           frag->data_ref);
@@ -469,7 +469,7 @@ static int cbs_vp9_split_fragment(CodedBitstreamContext *ctx,
         return 0;
 
     } else {
-        err = ff_cbs_insert_unit_data(frag, -1, 0,
+        err = ff_cbs_append_unit_data(frag, 0,
                                       frag->data, frag->data_size,
                                       frag->data_ref);
         if (err < 0)



More information about the ffmpeg-cvslog mailing list