History

avcodec/codec_par: add side data to AVCodecParameters

This will simplify the propagation of side data to decoders and from encoders. Global side data will now reside in the AVCodecContext, thus be available during init(), removing the need to propagate it inside packets. Global and frame specific side data will therefore be distinct.

James Almer committed 3 years ago

Commit 21d7cc61 parent 74279224 files · +65 −1Browse files

Unified · Split

4 files
  1. doc/APIchanges +5 −0
  2. libavcodec/codec_par.c +48 −0
  3. libavcodec/codec_par.h +11 −0
  4. libavcodec/version.h +1 −1
doc/APIchanges+5−0
@@ -2,6 +2,11 @@ The last version increases of all libraries were on 2023-02-09 · 1 unmodified line
22
33 API changes, most recent first:
44
5+2023-10-06 - xxxxxxxxxx - lavc 60.30.100 - codec_par.h
6+ Added {nb_,}coded_side_data to AVCodecParameters.
7+ The AVCodecParameters helpers will copy it to and from its AVCodecContext
8+ namesake.
9+
510 2023-10-06 - xxxxxxxxxx - lavc 60.29.100 - packet.h
611 Added av_packet_side_data_new(), av_packet_side_data_add(),
712 av_packet_side_data_get(), av_packet_side_data_remove, and
libavcodec/codec_par.c+48−0
@@ -27,11 +27,13 @@ · 26 unmodified lines
2727 #include "libavutil/mem.h"
2828 #include "avcodec.h"
2929 #include "codec_par.h"
30+#include "packet.h"
3031
3132 static void codec_parameters_reset(AVCodecParameters *par)
3233 {
3334 av_freep(&par->extradata);
3435 av_channel_layout_uninit(&par->ch_layout);
36+ av_packet_side_data_free(&par->coded_side_data, &par->nb_coded_side_data);
3537
3638 memset(par, 0, sizeof(*par));
3739
@@ -72,6 +74,35 @@ void avcodec_parameters_free(AVCodecParameters **ppar) · 34 unmodified lines
7274 av_freep(ppar);
7375 }
7476
77+static int codec_parameters_copy_side_data(AVPacketSideData **pdst, int *pnb_dst,
78+ const AVPacketSideData *src, int nb_src)
79+{
80+ AVPacketSideData *dst;
81+ int nb_dst = *pnb_dst;
82+
83+ if (!src)
84+ return 0;
85+
86+ *pdst = dst = av_calloc(nb_src, sizeof(*dst));
87+ if (!dst)
88+ return AVERROR(ENOMEM);
89+
90+ for (int i = 0; i < nb_src; i++) {
91+ const AVPacketSideData *src_sd = &src[i];
92+ AVPacketSideData *dst_sd = &dst[i];
93+
94+ dst_sd->data = av_memdup(src_sd->data, src_sd->size);
95+ if (!dst_sd->data)
96+ return AVERROR(ENOMEM);
97+
98+ dst_sd->type = src_sd->type;
99+ dst_sd->size = src_sd->size;
100+ *pnb_dst = ++nb_dst;
101+ }
102+
103+ return 0;
104+}
105+
75106 int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
76107 {
77108 int ret;
@@ -82,6 +113,8 @@ int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src · 4 unmodified lines
82113 dst->ch_layout = (AVChannelLayout){0};
83114 dst->extradata = NULL;
84115 dst->extradata_size = 0;
116+ dst->coded_side_data = NULL;
117+ dst->nb_coded_side_data = 0;
85118 if (src->extradata) {
86119 dst->extradata = av_mallocz(src->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
87120 if (!dst->extradata)
@@ -89,6 +122,10 @@ int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src · 1 unmodified line
89122 memcpy(dst->extradata, src->extradata, src->extradata_size);
90123 dst->extradata_size = src->extradata_size;
91124 }
125+ ret = codec_parameters_copy_side_data(&dst->coded_side_data, &dst->nb_coded_side_data,
126+ src->coded_side_data, src->nb_coded_side_data);
127+ if (ret < 0)
128+ return ret;
92129
93130 ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);
94131 if (ret < 0)
@@ -178,6 +215,11 @@ FF_ENABLE_DEPRECATION_WARNINGS · 83 unmodified lines
178215 par->extradata_size = codec->extradata_size;
179216 }
180217
218+ ret = codec_parameters_copy_side_data(&par->coded_side_data, &par->nb_coded_side_data,
219+ codec->coded_side_data, codec->nb_coded_side_data);
220+ if (ret < 0)
221+ return ret;
222+
181223 return 0;
182224 }
183225
@@ -262,5 +304,11 @@ FF_ENABLE_DEPRECATION_WARNINGS · 78 unmodified lines
262304 codec->extradata_size = par->extradata_size;
263305 }
264306
307+ av_packet_side_data_free(&codec->coded_side_data, &codec->nb_coded_side_data);
308+ ret = codec_parameters_copy_side_data(&codec->coded_side_data, &codec->nb_coded_side_data,
309+ par->coded_side_data, par->nb_coded_side_data);
310+ if (ret < 0)
311+ return ret;
312+
265313 return 0;
266314 }
libavcodec/codec_par.h+11−0
@@ -30,6 +30,7 @@ · 29 unmodified lines
3030
3131 #include "codec_id.h"
3232 #include "defs.h"
33+#include "packet.h"
3334
3435 /**
3536 * @addtogroup lavc_core
@@ -215,6 +216,16 @@ typedef struct AVCodecParameters { · 179 unmodified lines
215216 * when no higher-level timing information is available.
216217 */
217218 AVRational framerate;
219+
220+ /**
221+ * Additional data associated with the entire stream.
222+ */
223+ AVPacketSideData *coded_side_data;
224+
225+ /**
226+ * Amount of entries in @ref coded_side_data.
227+ */
228+ int nb_coded_side_data;
218229 } AVCodecParameters;
219230
220231 /**
libavcodec/version.h+1−1
@@ -29,7 +29,7 @@ · 28 unmodified lines
2929
3030 #include "version_major.h"
3131
32−#define LIBAVCODEC_VERSION_MINOR 29
32+#define LIBAVCODEC_VERSION_MINOR 30
3333 #define LIBAVCODEC_VERSION_MICRO 100
3434
3535 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t