diff mbox series

[FFmpeg-devel,v2,05/12] avutil/frame: add helper for adding side data to set

Message ID 20230411212052.159889-6-jeebjp@gmail.com
State New
Headers show
Series encoder AVCodecContext configuration side data | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Jan Ekström April 11, 2023, 9:20 p.m. UTC
---
 libavutil/frame.c | 12 ++++++++++++
 libavutil/frame.h | 13 +++++++++++++
 2 files changed, 25 insertions(+)

Comments

Anton Khirnov April 12, 2023, 8:41 a.m. UTC | #1
Quoting Jan Ekström (2023-04-11 23:20:45)
> ---
>  libavutil/frame.c | 12 ++++++++++++
>  libavutil/frame.h | 13 +++++++++++++
>  2 files changed, 25 insertions(+)
> 
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index ab1a4e7f6a..29e9b631f8 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -708,6 +708,18 @@ AVFrameSideData *av_frame_new_side_data(AVFrame *frame,
>      return ret;
>  }
>  
> +
> +AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set,
> +                                         enum AVFrameSideDataType type,
> +                                         size_t size)
> +{
> +    AVBufferRef     *buf = av_buffer_alloc(size);

unchecked allocation

> +    AVFrameSideData *ret = add_side_data_to_set_from_buf(set, type, buf);
> +    if (!ret)
> +        av_buffer_unref(&buf);
> +    return ret;
> +}
> +
>  AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
>                                          enum AVFrameSideDataType type)
>  {
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index 734ac3fe75..167a8f0ff6 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -998,6 +998,19 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type);
>   */
>  void av_side_data_set_wipe(AVFrameSideDataSet *set);
>  
> +/**
> + * Add a new side data entry to a set.
> + *
> + * @param set a set to which the side data should be added
> + * @param type type of the added side data
> + * @param size size of the side data
> + *
> + * @return newly added side data on success, NULL on error
> + */
> +AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set,

av_side_data_set_add()?

Or possibly _new or _create, because 'add' suggests you're passing in
the thing to be added, while in fact it creates a new uninitialized
entry.
diff mbox series

Patch

diff --git a/libavutil/frame.c b/libavutil/frame.c
index ab1a4e7f6a..29e9b631f8 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -708,6 +708,18 @@  AVFrameSideData *av_frame_new_side_data(AVFrame *frame,
     return ret;
 }
 
+
+AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set,
+                                         enum AVFrameSideDataType type,
+                                         size_t size)
+{
+    AVBufferRef     *buf = av_buffer_alloc(size);
+    AVFrameSideData *ret = add_side_data_to_set_from_buf(set, type, buf);
+    if (!ret)
+        av_buffer_unref(&buf);
+    return ret;
+}
+
 AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
                                         enum AVFrameSideDataType type)
 {
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 734ac3fe75..167a8f0ff6 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -998,6 +998,19 @@  const char *av_frame_side_data_name(enum AVFrameSideDataType type);
  */
 void av_side_data_set_wipe(AVFrameSideDataSet *set);
 
+/**
+ * Add a new side data entry to a set.
+ *
+ * @param set a set to which the side data should be added
+ * @param type type of the added side data
+ * @param size size of the side data
+ *
+ * @return newly added side data on success, NULL on error
+ */
+AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set,
+                                         enum AVFrameSideDataType type,
+                                         size_t size);
+
 /**
  * @}
  */