diff mbox series

[FFmpeg-devel,v2,06/12] avutil/frame: add helper for getting side data from set

Message ID 20230411212052.159889-7-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 | 22 +++++++++++++++++-----
 libavutil/frame.h | 10 ++++++++++
 2 files changed, 27 insertions(+), 5 deletions(-)

Comments

Anton Khirnov April 12, 2023, 8:43 a.m. UTC | #1
Quoting Jan Ekström (2023-04-11 23:20:46)
> ---
>  libavutil/frame.c | 22 +++++++++++++++++-----
>  libavutil/frame.h | 10 ++++++++++
>  2 files changed, 27 insertions(+), 5 deletions(-)
> 
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index 29e9b631f8..3386cda627 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -720,16 +720,28 @@ AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set,
>      return ret;
>  }
>  
> -AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
> -                                        enum AVFrameSideDataType type)
> +AVFrameSideData *av_get_side_data_from_set(const AVFrameSideDataSet set,

I suppose it does not matter much because it is const, but it seem a bit
strange that you're passing in the struct itself and not a pointer.

Otherwise, the same naming complaint as for the other patches.
diff mbox series

Patch

diff --git a/libavutil/frame.c b/libavutil/frame.c
index 29e9b631f8..3386cda627 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -720,16 +720,28 @@  AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set,
     return ret;
 }
 
-AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
-                                        enum AVFrameSideDataType type)
+AVFrameSideData *av_get_side_data_from_set(const AVFrameSideDataSet set,
+                                           enum AVFrameSideDataType type)
 {
-    for (int i = 0; i < frame->nb_side_data; i++) {
-        if (frame->side_data[i]->type == type)
-            return frame->side_data[i];
+    for (int i = 0; i < set.nb_side_data; i++) {
+        if (set.side_data[i]->type == type)
+            return set.side_data[i];
     }
     return NULL;
 }
 
+AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
+                                        enum AVFrameSideDataType type)
+{
+    return av_get_side_data_from_set(
+        (const AVFrameSideDataSet){
+            .side_data    = frame->side_data,
+            .nb_side_data = frame->nb_side_data
+        },
+        type
+    );
+}
+
 static int frame_copy_video(AVFrame *dst, const AVFrame *src)
 {
     const uint8_t *src_data[4];
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 167a8f0ff6..8aa50e3ad8 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1011,6 +1011,16 @@  AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set,
                                          enum AVFrameSideDataType type,
                                          size_t size);
 
+/**
+ * @param set a set to which the side data should be added
+ * @param type type of the added side data
+ *
+ * @return a pointer to the side data of a given type on success, NULL if there
+ *         is no side data with such type in this set.
+ */
+AVFrameSideData *av_get_side_data_from_set(const AVFrameSideDataSet set,
+                                           enum AVFrameSideDataType type);
+
 /**
  * @}
  */