diff mbox series

[FFmpeg-devel,v0,10/14] avcodec: add function for setting avctx side data

Message ID 20230320233408.134255-11-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 March 20, 2023, 11:34 p.m. UTC
---
 libavcodec/avcodec.c | 30 ++++++++++++++++++++++++++++++
 libavcodec/avcodec.h | 12 ++++++++++++
 2 files changed, 42 insertions(+)

Comments

Anton Khirnov March 24, 2023, 10:49 a.m. UTC | #1
Quoting Jan Ekström (2023-03-21 00:34:04)
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 30f1d312f4..8f535a0cc8 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -3223,6 +3223,18 @@ void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size);
>   */
>  int avcodec_is_open(AVCodecContext *s);
>  
> +/**
> + * Configure a side data set to an encoder AVCodecContext. With multiple
> + * calls new side data gets added in addition to the existing set of side data.

I have no idea what does "configure" mean in this context and what
effect will this actually have.
Jan Ekström March 24, 2023, 5:35 p.m. UTC | #2
On Fri, Mar 24, 2023 at 12:49 PM Anton Khirnov <anton@khirnov.net> wrote:
>
> Quoting Jan Ekström (2023-03-21 00:34:04)
> > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> > index 30f1d312f4..8f535a0cc8 100644
> > --- a/libavcodec/avcodec.h
> > +++ b/libavcodec/avcodec.h
> > @@ -3223,6 +3223,18 @@ void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size);
> >   */
> >  int avcodec_is_open(AVCodecContext *s);
> >
> > +/**
> > + * Configure a side data set to an encoder AVCodecContext. With multiple
> > + * calls new side data gets added in addition to the existing set of side data.
>
> I have no idea what does "configure" mean in this context and what
> effect will this actually have.
>

It becomes available to any encoder which utilizes it for
configuration of itself, basically.

Jan
diff mbox series

Patch

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 3faabe77d1..9ffff28d70 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -29,6 +29,7 @@ 
 #include "libavutil/bprint.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/fifo.h"
+#include "libavutil/frame.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
@@ -719,3 +720,32 @@  int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr
         return ff_decode_receive_frame(avctx, frame);
     return ff_encode_receive_frame(avctx, frame);
 }
+
+int avcodec_configure_side_data(AVCodecContext *avctx,
+                                const AVFrameSideDataSet set)
+{
+    if (!avctx || !avctx->internal || !av_codec_is_encoder(avctx->codec))
+        return AVERROR(EINVAL);
+
+    {
+        AVCodecInternal    *avci = avctx->internal;
+        AVFrameSideDataSet *dst  = &avci->side_data_set;
+
+        for (int i = 0; i < set.nb_side_data; i++) {
+            const AVFrameSideData *sd_src = set.side_data[i];
+            AVFrameSideData *sd_dst =
+                av_new_side_data_to_set(dst, sd_src->type,
+                                        sd_src->size);
+            if (!sd_dst) {
+                av_side_data_set_wipe(dst);
+                return AVERROR(ENOMEM);
+            }
+
+            memcpy(sd_dst->data, sd_src->data, sd_src->size);
+
+            av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
+        }
+
+        return 0;
+    }
+}
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 30f1d312f4..8f535a0cc8 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3223,6 +3223,18 @@  void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size);
  */
 int avcodec_is_open(AVCodecContext *s);
 
+/**
+ * Configure a side data set to an encoder AVCodecContext. With multiple
+ * calls new side data gets added in addition to the existing set of side data.
+ *
+ * @param avctx codec context to which to add side data
+ * @param set   set of side data to add
+ *
+* @return negative error code on failure, >=0 on success.
+ */
+int avcodec_configure_side_data(AVCodecContext *avctx,
+                                const AVFrameSideDataSet set);
+
 /**
  * @}
  */