Skip to content

Commit 828e941

Browse files
committed
Compatibility with older FFmpeg versions
1 parent 72e3038 commit 828e941

File tree

4 files changed

+70
-13
lines changed

4 files changed

+70
-13
lines changed

funcs.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@
135135
["AVPacketSideData_size", "number", ["number", "number"]],
136136
["AVPacketSideData_type", "number", ["number", "number"]],
137137
["av_packet_unref", null, ["number"]],
138-
["av_shrink_packet", null, ["number", "number"]]
138+
["av_shrink_packet", null, ["number", "number"]],
139+
["ff_codecpar_new_side_data", "number", ["number", "number", "number"]]
139140
],
140141

141142
"meta": [
@@ -163,6 +164,7 @@
163164
"codec_id",
164165
"codec_tag",
165166
"codec_type",
167+
"coded_side_data",
166168
"color_primaries",
167169
"color_range",
168170
"color_space",
@@ -173,6 +175,7 @@
173175
{"name": "framerate", "rational": true},
174176
"height",
175177
"level",
178+
"nb_coded_side_data",
176179
"profile",
177180
"sample_rate",
178181
"width"
@@ -378,6 +381,7 @@
378381
"channels",
379382
"channel_layoutmask",
380383
"ch_layout_nb_channels",
384+
"coded_side_data",
381385
"compression_level",
382386
"extradata",
383387
"extradata_size",
@@ -388,6 +392,7 @@
388392
"keyint_min",
389393
"level",
390394
"max_b_frames",
395+
"nb_coded_side_data",
391396
"pix_fmt",
392397
"profile",
393398
"rc_max_rate",

src/b-avcodec.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@ B(enum AVMediaType, type)
3333
B(enum AVCodecID, codec_id)
3434
B(enum AVMediaType, codec_type)
3535
BL(int64_t, bit_rate)
36+
B(AVPacketSideData *, coded_side_data)
37+
B(int, compression_level)
3638
B(uint8_t *, extradata)
3739
B(int, extradata_size)
38-
B(int, compression_level)
3940
B(int, frame_size)
4041
B(int, gop_size)
4142
B(int, height)
4243
B(int, keyint_min)
4344
B(int, level)
4445
B(int, max_b_frames)
46+
B(int, nb_coded_side_data)
4547
B(int, pix_fmt)
4648
B(int, profile)
4749
BL(int64_t, rc_max_rate)
@@ -93,6 +95,16 @@ B(enum AVColorTransferCharacteristic, color_trc)
9395
B(enum AVColorSpace, color_space)
9496
B(enum AVChromaLocation, chroma_location)
9597
B(int, sample_rate)
98+
99+
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(60, 30, 100)
100+
B(AVPacketSideData *, coded_side_data)
101+
B(int, nb_coded_side_data)
102+
#else
103+
AVPacketSideData *AVCodecParameters_coded_side_data(AVCodecParameters *a) { return NULL; }
104+
void AVCodecParameters_coded_side_data_s(AVCodecParameters *a, AVPacketSideData *b) {}
105+
int AVCodecParameters_nb_coded_side_data(AVCodecParameters *a) { return 0; }
106+
void AVCodecParameters_nb_coded_side_data_s(AVCodecParameters *a, AVPacketSideData *b) {}
107+
#endif
96108
#undef B
97109

98110
#if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(60, 10, 100)
@@ -103,6 +115,20 @@ RAT_FAKE(AVCodecParameters, framerate, 60, 1)
103115

104116
CHL(AVCodecParameters)
105117

118+
uint8_t *ff_codecpar_new_side_data(
119+
AVCodecParameters *codecpar, enum AVPacketSideDataType type, size_t size
120+
) {
121+
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(60, 30, 100)
122+
AVPacketSideData *sd = av_packet_side_data_new(
123+
&codecpar->coded_side_data, &codecpar->nb_coded_side_data, type, size,
124+
0
125+
);
126+
return sd ? sd->data : NULL;
127+
#else
128+
return NULL;
129+
#endif
130+
}
131+
106132

107133
/* AVPacket */
108134
#define B(type, field) A(AVPacket, type, field)

src/libav.types.in.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ declare namespace LibAV {
277277
*/
278278
channel_layoutmask?: number;
279279
channels?: number;
280+
281+
/**
282+
* Side data. Codec-specific.
283+
*/
284+
coded_side_data?: any;
280285
}
281286

282287
/**

src/p-avfcbridge.in.js

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@ var ff_copyout_packet = Module.ff_copyout_packet = function(pkt) {
5252
flags: AVPacket_flags(pkt),
5353
duration: AVPacket_duration(pkt),
5454
durationhi: AVPacket_durationhi(pkt),
55-
side_data: ff_copyout_side_data(pkt)
55+
side_data: ff_copyout_side_data(
56+
AVPacket_side_data(pkt),
57+
AVPacket_side_data_elems(pkt)
58+
)
5659
};
5760
};
5861

5962
// Copy out a packet's side data. Used internally by ff_copyout_packet.
60-
var ff_copyout_side_data = Module.ff_copyout_side_data = function(pkt) {
61-
var side_data = AVPacket_side_data(pkt);
62-
var side_data_elems = AVPacket_side_data_elems(pkt);
63+
var ff_copyout_side_data = Module.ff_copyout_side_data = function(side_data, side_data_elems) {
6364
if (!side_data) return null;
6465

6566
var ret = [];
@@ -114,9 +115,8 @@ var ff_copyin_packet = Module.ff_copyin_packet = function(pktPtr, packet) {
114115
ff_set_packet(pktPtr, packet.data);
115116

116117
[
117-
"dts", "dtshi", "duration", "durationhi", "flags", "side_data",
118-
"side_data_elems", "stream_index", "pts", "ptshi", "time_base_num",
119-
"time_base_den"
118+
"dts", "dtshi", "duration", "durationhi", "flags", "stream_index",
119+
"pts", "ptshi", "time_base_num", "time_base_den"
120120
].forEach(function(key) {
121121
if (key in packet)
122122
CAccessors["AVPacket_" + key + "_s"](pktPtr, packet[key]);
@@ -128,6 +128,8 @@ var ff_copyin_packet = Module.ff_copyin_packet = function(pktPtr, packet) {
128128

129129
// Copy in a packet's side data. Used internally by ff_copyin_packet.
130130
var ff_copyin_side_data = Module.ff_copyin_side_data = function(pktPtr, side_data) {
131+
AVPacket_side_data_s(pktPtr, 0);
132+
AVPacket_side_data_elems_s(pktPtr, 0);
131133
side_data.forEach(function(elem) {
132134
var data = av_packet_new_side_data(pktPtr, elem.type, elem.data.length);
133135
if (data === 0)
@@ -160,7 +162,11 @@ var ff_copyout_codecpar = Module.ff_copyout_codecpar = function(codecpar) {
160162
profile: AVCodecParameters_profile(codecpar),
161163
sample_rate: AVCodecParameters_sample_rate(codecpar),
162164
width: AVCodecParameters_width(codecpar),
163-
extradata: ff_copyout_codecpar_extradata(codecpar)
165+
extradata: ff_copyout_codecpar_extradata(codecpar),
166+
coded_side_data: ff_copyout_side_data(
167+
AVCodecParameters_coded_side_data(codecpar),
168+
AVCodecParameters_nb_coded_side_data(codecpar)
169+
)
164170
};
165171
};
166172

@@ -181,16 +187,19 @@ var ff_copyout_codecpar_extradata = Module.ff_copyout_codecpar_extradata = funct
181187
var ff_copyin_codecpar = Module.ff_copyin_codecpar = function(codecparPtr, codecpar) {
182188
[
183189
"bit_rate", "channel_layoutmask", "channels", "chroma_location",
184-
"codec_id", "codec_tag", "codec_type", "color_primaries", "color_range",
185-
"color_space", "color_trc", "format", "height", "level", "profile",
186-
"sample_rate", "width"
190+
"codec_id", "codec_tag", "codec_type", "coded_side_data",
191+
"color_primaries", "color_range", "color_space", "color_trc", "format",
192+
"height", "level", "nb_coded_side_data", "profile", "sample_rate",
193+
"width"
187194
].forEach(function(key) {
188195
if (key in codecpar)
189196
CAccessors["AVCodecParameters_" + key + "_s"](codecparPtr, codecpar[key]);
190197
});
191198

192199
if (codecpar.extradata)
193200
ff_copyin_codecpar_extradata(codecparPtr, codecpar.extradata);
201+
if (codecpar.coded_side_data)
202+
ff_copyin_codecpar_side_data(codecparPtr, codecpar.side_data);
194203
};
195204

196205
// Copy in codec parameter extradata. Used internally by ff_copyin_codecpar.
@@ -200,3 +209,15 @@ var ff_copyin_codecpar_extradata = Module.ff_copyin_codecpar_extradata = functio
200209
AVCodecParameters_extradata_s(codecparPtr, extradataPtr);
201210
AVCodecParameters_extradata_size_s(codecparPtr, extradata.length);
202211
};
212+
213+
// Copy in a codecpar's side data. Used internally by ff_copyin_codecpar.
214+
var ff_copyin_codecpar_side_data = Module.ff_copyin_codecpar_side_data = function(codecpar, side_data) {
215+
AVCodecParameters_coded_side_data_s(codecpar, 0);
216+
AVCodecParameters_nb_coded_side_data_s(codecpar, 0);
217+
side_data.forEach(function(elem) {
218+
var data = ff_codecpar_new_side_data(codecpar, elem.type, elem.data.length);
219+
if (data === 0)
220+
throw new Error("Failed to allocate side data!");
221+
copyin_u8(data, elem.data);
222+
});
223+
};

0 commit comments

Comments
 (0)