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
2 2
3API changes, most recent first:3API changes, most recent first:
4 4
52023-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
52023-10-06 - xxxxxxxxxx - lavc 60.29.100 - packet.h102023-10-06 - xxxxxxxxxx - lavc 60.29.100 - packet.h
6 Added av_packet_side_data_new(), av_packet_side_data_add(),11 Added av_packet_side_data_new(), av_packet_side_data_add(),
7 av_packet_side_data_get(), av_packet_side_data_remove, and12 av_packet_side_data_get(), av_packet_side_data_remove, and
libavcodec/codec_par.c+48−0
@@ -27,11 +27,13 @@ · 26 unmodified lines
27#include "libavutil/mem.h"27#include "libavutil/mem.h"
28#include "avcodec.h"28#include "avcodec.h"
29#include "codec_par.h"29#include "codec_par.h"
30#include "packet.h"
30 31
31static void codec_parameters_reset(AVCodecParameters *par)32static void codec_parameters_reset(AVCodecParameters *par)
32{33{
33 av_freep(&par->extradata);34 av_freep(&par->extradata);
34 av_channel_layout_uninit(&par->ch_layout);35 av_channel_layout_uninit(&par->ch_layout);
36 av_packet_side_data_free(&par->coded_side_data, &par->nb_coded_side_data);
35 37
36 memset(par, 0, sizeof(*par));38 memset(par, 0, sizeof(*par));
37 39
@@ -72,6 +74,35 @@ void avcodec_parameters_free(AVCodecParameters **ppar) · 34 unmodified lines
72 av_freep(ppar);74 av_freep(ppar);
73}75}
74 76
77static 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
75int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)106int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
76{107{
77 int ret;108 int ret;
@@ -82,6 +113,8 @@ int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src · 4 unmodified lines
82 dst->ch_layout = (AVChannelLayout){0};113 dst->ch_layout = (AVChannelLayout){0};
83 dst->extradata = NULL;114 dst->extradata = NULL;
84 dst->extradata_size = 0;115 dst->extradata_size = 0;
116 dst->coded_side_data = NULL;
117 dst->nb_coded_side_data = 0;
85 if (src->extradata) {118 if (src->extradata) {
86 dst->extradata = av_mallocz(src->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);119 dst->extradata = av_mallocz(src->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
87 if (!dst->extradata)120 if (!dst->extradata)
@@ -89,6 +122,10 @@ int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src · 1 unmodified line
89 memcpy(dst->extradata, src->extradata, src->extradata_size);122 memcpy(dst->extradata, src->extradata, src->extradata_size);
90 dst->extradata_size = src->extradata_size;123 dst->extradata_size = src->extradata_size;
91 }124 }
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;
92 129
93 ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);130 ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);
94 if (ret < 0)131 if (ret < 0)
@@ -178,6 +215,11 @@ FF_ENABLE_DEPRECATION_WARNINGS · 83 unmodified lines
178 par->extradata_size = codec->extradata_size;215 par->extradata_size = codec->extradata_size;
179 }216 }
180 217
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
181 return 0;223 return 0;
182}224}
183 225
@@ -262,5 +304,11 @@ FF_ENABLE_DEPRECATION_WARNINGS · 78 unmodified lines
262 codec->extradata_size = par->extradata_size;304 codec->extradata_size = par->extradata_size;
263 }305 }
264 306
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
265 return 0;313 return 0;
266}314}
libavcodec/codec_par.h+11−0
@@ -30,6 +30,7 @@ · 29 unmodified lines
30 30
31#include "codec_id.h"31#include "codec_id.h"
32#include "defs.h"32#include "defs.h"
33#include "packet.h"
33 34
34/**35/**
35 * @addtogroup lavc_core36 * @addtogroup lavc_core
@@ -215,6 +216,16 @@ typedef struct AVCodecParameters { · 179 unmodified lines
215 * when no higher-level timing information is available.216 * when no higher-level timing information is available.
216 */217 */
217 AVRational framerate;218 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;
218} AVCodecParameters;229} AVCodecParameters;
219 230
220/**231/**
libavcodec/version.h+1−1
@@ -29,7 +29,7 @@ · 28 unmodified lines
29 29
30#include "version_major.h"30#include "version_major.h"
31 31
32#define LIBAVCODEC_VERSION_MINOR 2932#define LIBAVCODEC_VERSION_MINOR 30
33#define LIBAVCODEC_VERSION_MICRO 10033#define LIBAVCODEC_VERSION_MICRO 100
34 34
35#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \35#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