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

Submitted by Andreas Rheinhardt on Nov. 9, 2018, 5:31 a.m.

Details

Message ID 20181109053138.4572-4-andreas.rheinhardt@googlemail.com
State New
Headers show

Commit Message

Andreas Rheinhardt Nov. 9, 2018, 5:31 a.m.
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@googlemail.com>
---
 libavcodec/cbs_h264.h  |  8 ++++++++
 libavcodec/cbs_h2645.c | 16 ++++++++++++++++
 libavcodec/cbs_h265.h  |  9 +++++++++
 3 files changed, 33 insertions(+)

Comments

Mark Thompson Nov. 18, 2018, 9:09 p.m.
On 09/11/18 05:31, Andreas Rheinhardt wrote:
> 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@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 */
> 

Would it be sensible to instead make the more general ff_cbs_make_unit_writeable(), calling a new function in CodedBitstreamType?  You don't need to implement any additional cases (they can just return AVERROR_PATCHWELCOME if you call it on an unsupported unit), but I think the API would be nicer.

Thanks,

- Mark

Patch hide | download patch | download mbox

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 */