diff mbox

[FFmpeg-devel,1/5] cbs: Add function to make content of a unit writable

Message ID 20181126133913.2356-1-andreas.rheinhardt@googlemail.com
State Superseded
Headers show

Commit Message

Andreas Rheinhardt Nov. 26, 2018, 1:39 p.m. UTC
This will enable us to change e.g. the parameter sets of H.2645 in ways
that would change the parsing process of future units. An example of
this is the h264_redundant_pps bsf.
The actual implementation of the underlying codec-dependent
make_writable functions is not contained in this commit.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com>
---

Here is an updated patchset. Sorry for the unnecessary noise.

 libavcodec/cbs.c          | 21 +++++++++++++++++++++
 libavcodec/cbs.h          |  9 +++++++++
 libavcodec/cbs_internal.h |  4 ++++
 3 files changed, 34 insertions(+)
diff mbox

Patch

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index ecbf57c293..cb2ee3a769 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -665,3 +665,24 @@  int ff_cbs_delete_unit(CodedBitstreamContext *ctx,
 
     return 0;
 }
+
+int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx,
+                              CodedBitstreamUnit *unit,
+                              void** content)
+{
+    if (unit->content && (!unit->content_ref ||
+                          !av_buffer_is_writable(unit->content_ref))) {
+        int err;
+        if (!ctx->codec->make_writable)
+            return AVERROR_PATCHWELCOME;
+
+        err = ctx->codec->make_writable(ctx, unit);
+        if (err < 0)
+            return err;
+
+        if (content)
+            *content = unit->content;
+    }
+
+    return 0;
+}
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index 53ac360bb1..9bdc6aa5fd 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -352,5 +352,14 @@  int ff_cbs_delete_unit(CodedBitstreamContext *ctx,
                        CodedBitstreamFragment *frag,
                        int position);
 
+/**
+ * Make the content of a unit writable.
+ *
+ * If content is supplied, *content will point to the unit's content on success.
+ */
+int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx,
+                              CodedBitstreamUnit *unit,
+                              void **content);
+
 
 #endif /* AVCODEC_CBS_H */
diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index 53f2e5d187..62a836af90 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -44,6 +44,10 @@  typedef struct CodedBitstreamType {
     int (*read_unit)(CodedBitstreamContext *ctx,
                      CodedBitstreamUnit *unit);
 
+    // Make a unit's content writable.
+    int (*make_writable)(CodedBitstreamContext *ctx,
+                         CodedBitstreamUnit *unit);
+
     // Write the unit->data bitstream from unit->content.
     int (*write_unit)(CodedBitstreamContext *ctx,
                       CodedBitstreamUnit *unit);