@@ -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)
+ memcpy(content, &unit->content, sizeof(content));
+ }
+
+ return 0;
+}
@@ -352,5 +352,15 @@ int ff_cbs_delete_unit(CodedBitstreamContext *ctx,
CodedBitstreamFragment *frag,
int position);
+/**
+ * Make the content of a unit writable.
+ *
+ * If content is supplied, it is supposed to be a pointer to a pointer
+ * and *content will point to the content of the unit on success.
+ */
+int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx,
+ CodedBitstreamUnit *unit,
+ void *content);
+
#endif /* AVCODEC_CBS_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);
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> --- Unfortunately I messed up the function parameters and made the content parameter pretty much unusable. This version fixes this. Notice that it supposes that both pointer to void as well as pointer to structures have the same size and object representation. Other functions like several memory-related ones (that use a void * argument for a pointer to a pointer) make the same assumption, so I guess that it is ok. libavcodec/cbs.c | 21 +++++++++++++++++++++ libavcodec/cbs.h | 10 ++++++++++ libavcodec/cbs_internal.h | 4 ++++ 3 files changed, 35 insertions(+)