[FFmpeg-devel] [PATCH 3/6] cbs_h2645: Create functions to make parameter sets writeable

Andreas Rheinhardt andreas.rheinhardt at googlemail.com
Fri Nov 9 07:31:35 EET 2018


av_buffer_make_writable can't be used here, because a shallow copy isn't
enough for parameter sets.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at googlemail.com>
---
 libavcodec/cbs_h264.h  |  8 ++++++++
 libavcodec/cbs_h2645.c | 16 ++++++++++++++++
 libavcodec/cbs_h265.h  |  9 +++++++++
 3 files changed, 33 insertions(+)

diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
index 92277e4750..dc6019765b 100644
--- a/libavcodec/cbs_h264.h
+++ b/libavcodec/cbs_h264.h
@@ -479,4 +479,12 @@ int ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx,
                                    CodedBitstreamUnit *nal_unit,
                                    int position);
 
+/**
+ * Create a writeable reference from a reference to a buffer that contains
+ * a parameter set of the kind implied by the function name.
+ */
+int ff_cbs_h264_make_sps_writeable(AVBufferRef **buf);
+int ff_cbs_h264_make_pps_writeable(AVBufferRef **buf);
+
+
 #endif /* AVCODEC_CBS_H264_H */
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index e73706f2e6..a323bb2e8a 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -716,6 +716,22 @@ static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \
         return AVERROR(ENOMEM); \
     priv->ps_var[id] = (H26 ## h26n ## Raw ## ps_name *)priv->ps_var ## _ref[id]->data; \
     return 0; \
+} \
+ \
+int ff_cbs_h26 ## h26n ## _make_ ## ps_var ## _writeable(AVBufferRef **buf) \
+{ \
+    if (av_buffer_is_writable(*buf)) {\
+        return 0; \
+    } else { \
+        AVBufferRef *copy = cbs_h26 ## h26n ## _copy_ ## ps_var \
+                              ((H26 ## h26n ## Raw ## ps_name*)(*buf)->data); \
+        if (copy) { \
+            av_buffer_unref(buf); \
+            *buf = copy; \
+            return 0; \
+        } else \
+            return AVERROR(ENOMEM); \
+    } \
 }
 
 
diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h
index cca1d7590b..9e951cd945 100644
--- a/libavcodec/cbs_h265.h
+++ b/libavcodec/cbs_h265.h
@@ -581,4 +581,13 @@ typedef struct CodedBitstreamH265Context {
 } CodedBitstreamH265Context;
 
 
+/**
+ * Create a writeable reference from a reference to a buffer that contains
+ * a parameter set of the kind implied by the function name.
+ */
+int ff_cbs_h265_make_vps_writeable(AVBufferRef **buf);
+int ff_cbs_h265_make_sps_writeable(AVBufferRef **buf);
+int ff_cbs_h265_make_pps_writeable(AVBufferRef **buf);
+
+
 #endif /* AVCODEC_CBS_H265_H */
-- 
2.19.0



More information about the ffmpeg-devel mailing list