History

avcodec/ac3_parser: handle more header bits in ff_ac3_parse_header()

Based on a patch by nyanmisaka.

James Almer committed 1 year ago

Commit 117343c1 parent efbcd317 files · +282 −221Browse files

Unified · Split

7 files
  1. libavcodec/ac3_parser.c +219 −0
  2. libavcodec/ac3_parser_internal.h +19 −0
  3. libavcodec/ac3dec.c +20 −68
  4. libavcodec/ac3dec.h +3 −1
  5. libavcodec/ac3defs.h +2 −0
  6. libavcodec/eac3dec.c +17 −137
  7. libavformat/movenc.c +2 −15
libavcodec/ac3_parser.c+219−0
@@ -73,6 +73,217 @@ int ff_ac3_find_syncword(const uint8_t *buf, int buf_size) · 72 unmodified lines
7373 return i;
7474 }
7575
76+/**
77+ * Parse the 'sync info' and 'bit stream info' from the AC-3 bitstream.
78+ * GetBitContext within AC3DecodeContext must point to
79+ * the start of the synchronized AC-3 bitstream.
80+ */
81+static int ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
82+{
83+ /* read the rest of the bsi. read twice for dual mono mode. */
84+ for (int i = 0; i < (hdr->channel_mode ? 1 : 2); i++) {
85+ hdr->dialog_normalization[i] = -get_bits(gbc, 5);
86+ hdr->compression_exists[i] = get_bits1(gbc);
87+ if (hdr->compression_exists[i])
88+ hdr->heavy_dynamic_range[i] = get_bits(gbc, 8);
89+ if (get_bits1(gbc))
90+ skip_bits(gbc, 8); //skip language code
91+ if (get_bits1(gbc))
92+ skip_bits(gbc, 7); //skip audio production information
93+ }
94+
95+ skip_bits(gbc, 2); //skip copyright bit and original bitstream bit
96+
97+ /* skip the timecodes or parse the Alternate Bit Stream Syntax */
98+ if (hdr->bitstream_id != 6) {
99+ if (get_bits1(gbc))
100+ skip_bits(gbc, 14); //skip timecode1
101+ if (get_bits1(gbc))
102+ skip_bits(gbc, 14); //skip timecode2
103+ } else {
104+ if (get_bits1(gbc)) {
105+ hdr->preferred_downmix = get_bits(gbc, 2);
106+ hdr->center_mix_level_ltrt = get_bits(gbc, 3);
107+ hdr->surround_mix_level_ltrt = av_clip(get_bits(gbc, 3), 3, 7);
108+ hdr->center_mix_level = get_bits(gbc, 3);
109+ hdr->surround_mix_level = av_clip(get_bits(gbc, 3), 3, 7);
110+ }
111+ if (get_bits1(gbc)) {
112+ hdr->dolby_surround_ex_mode = get_bits(gbc, 2);
113+ hdr->dolby_headphone_mode = get_bits(gbc, 2);
114+ skip_bits(gbc, 10); // skip adconvtyp (1), xbsi2 (8), encinfo (1)
115+ }
116+ }
117+
118+ /* skip additional bitstream info */
119+ if (get_bits1(gbc)) {
120+ int i = get_bits(gbc, 6);
121+ do {
122+ skip_bits(gbc, 8);
123+ } while (i--);
124+ }
125+
126+ return 0;
127+}
128+
129+static int eac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
130+{
131+ if (hdr->frame_type == EAC3_FRAME_TYPE_RESERVED)
132+ return AC3_PARSE_ERROR_FRAME_TYPE;
133+ if (hdr->substreamid)
134+ return AC3_PARSE_ERROR_FRAME_TYPE;
135+
136+ skip_bits(gbc, 5); // skip bitstream id
137+
138+ /* volume control params */
139+ for (int i = 0; i < (hdr->channel_mode ? 1 : 2); i++) {
140+ hdr->dialog_normalization[i] = -get_bits(gbc, 5);
141+ hdr->compression_exists[i] = get_bits1(gbc);
142+ if (hdr->compression_exists[i])
143+ hdr->heavy_dynamic_range[i] = get_bits(gbc, 8);
144+ }
145+
146+ /* dependent stream channel map */
147+ if (hdr->frame_type == EAC3_FRAME_TYPE_DEPENDENT) {
148+ hdr->channel_map_present = get_bits1(gbc);
149+ if (hdr->channel_map_present) {
150+ int64_t channel_layout = 0;
151+ int channel_map = get_bits(gbc, 16);
152+
153+ for (int i = 0; i < 16; i++)
154+ if (channel_map & (1 << (EAC3_MAX_CHANNELS - i - 1)))
155+ channel_layout |= ff_eac3_custom_channel_map_locations[i][1];
156+
157+ if (av_popcount64(channel_layout) > EAC3_MAX_CHANNELS) {
158+ return AC3_PARSE_ERROR_CHANNEL_MAP;
159+ }
160+ hdr->channel_map = channel_map;
161+ }
162+ }
163+
164+ /* mixing metadata */
165+ if (get_bits1(gbc)) {
166+ /* center and surround mix levels */
167+ if (hdr->channel_mode > AC3_CHMODE_STEREO) {
168+ hdr->preferred_downmix = get_bits(gbc, 2);
169+ if (hdr->channel_mode & 1) {
170+ /* if three front channels exist */
171+ hdr->center_mix_level_ltrt = get_bits(gbc, 3);
172+ hdr->center_mix_level = get_bits(gbc, 3);
173+ }
174+ if (hdr->channel_mode & 4) {
175+ /* if a surround channel exists */
176+ hdr->surround_mix_level_ltrt = av_clip(get_bits(gbc, 3), 3, 7);
177+ hdr->surround_mix_level = av_clip(get_bits(gbc, 3), 3, 7);
178+ }
179+ }
180+
181+ /* lfe mix level */
182+ if (hdr->lfe_on && (hdr->lfe_mix_level_exists = get_bits1(gbc))) {
183+ hdr->lfe_mix_level = get_bits(gbc, 5);
184+ }
185+
186+ /* info for mixing with other streams and substreams */
187+ if (hdr->frame_type == EAC3_FRAME_TYPE_INDEPENDENT) {
188+ for (int i = 0; i < (hdr->channel_mode ? 1 : 2); i++) {
189+ // TODO: apply program scale factor
190+ if (get_bits1(gbc)) {
191+ skip_bits(gbc, 6); // skip program scale factor
192+ }
193+ }
194+ if (get_bits1(gbc)) {
195+ skip_bits(gbc, 6); // skip external program scale factor
196+ }
197+ /* skip mixing parameter data */
198+ switch(get_bits(gbc, 2)) {
199+ case 1: skip_bits(gbc, 5); break;
200+ case 2: skip_bits(gbc, 12); break;
201+ case 3: {
202+ int mix_data_size = (get_bits(gbc, 5) + 2) << 3;
203+ skip_bits_long(gbc, mix_data_size);
204+ break;
205+ }
206+ }
207+ /* skip pan information for mono or dual mono source */
208+ if (hdr->channel_mode < AC3_CHMODE_STEREO) {
209+ for (int i = 0; i < (hdr->channel_mode ? 1 : 2); i++) {
210+ if (get_bits1(gbc)) {
211+ /* note: this is not in the ATSC A/52B specification
212+ reference: ETSI TS 102 366 V1.1.1
213+ section: E.1.3.1.25 */
214+ skip_bits(gbc, 8); // skip pan mean direction index
215+ skip_bits(gbc, 6); // skip reserved paninfo bits
216+ }
217+ }
218+ }
219+ /* skip mixing configuration information */
220+ if (get_bits1(gbc)) {
221+ for (int i = 0; i < hdr->num_blocks; i++) {
222+ if (hdr->num_blocks == 1 || get_bits1(gbc)) {
223+ skip_bits(gbc, 5);
224+ }
225+ }
226+ }
227+ }
228+ }
229+
230+ /* informational metadata */
231+ if (get_bits1(gbc)) {
232+ hdr->bitstream_mode = get_bits(gbc, 3);
233+ skip_bits(gbc, 2); // skip copyright bit and original bitstream bit
234+ if (hdr->channel_mode == AC3_CHMODE_STEREO) {
235+ hdr->dolby_surround_mode = get_bits(gbc, 2);
236+ hdr->dolby_headphone_mode = get_bits(gbc, 2);
237+ }
238+ if (hdr->channel_mode >= AC3_CHMODE_2F2R) {
239+ hdr->dolby_surround_ex_mode = get_bits(gbc, 2);
240+ }
241+ for (int i = 0; i < (hdr->channel_mode ? 1 : 2); i++) {
242+ if (get_bits1(gbc)) {
243+ skip_bits(gbc, 8); // skip mix level, room type, and A/D converter type
244+ }
245+ }
246+ if (hdr->sr_code != EAC3_SR_CODE_REDUCED) {
247+ skip_bits1(gbc); // skip source sample rate code
248+ }
249+ }
250+
251+ /* converter synchronization flag
252+ If frames are less than six blocks, this bit should be turned on
253+ once every 6 blocks to indicate the start of a frame set.
254+ reference: RFC 4598, Section 2.1.3 Frame Sets */
255+ if (hdr->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && hdr->num_blocks != 6) {
256+ skip_bits1(gbc); // skip converter synchronization flag
257+ }
258+
259+ /* original frame size code if this stream was converted from AC-3 */
260+ if (hdr->frame_type == EAC3_FRAME_TYPE_AC3_CONVERT &&
261+ (hdr->num_blocks == 6 || get_bits1(gbc))) {
262+ skip_bits(gbc, 6); // skip frame size code
263+ }
264+
265+ /* additional bitstream info */
266+ if (get_bits1(gbc)) {
267+ int addbsil = get_bits(gbc, 6);
268+ for (int i = 0; i < addbsil + 1; i++) {
269+ if (i == 0) {
270+ /* In this 8 bit chunk, the LSB is equal to flag_ec3_extension_type_a
271+ which can be used to detect Atmos presence */
272+ skip_bits(gbc, 7);
273+ hdr->eac3_extension_type_a = get_bits1(gbc);
274+ if (hdr->eac3_extension_type_a) {
275+ hdr->complexity_index_type_a = get_bits(gbc, 8);
276+ i++;
277+ }
278+ } else {
279+ skip_bits(gbc, 8); // skip additional bit stream info
280+ }
281+ }
282+ }
283+
284+ return 0;
285+}
286+
76287 int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
77288 {
78289 int frame_size_code;
@@ -133,6 +344,10 @@ int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr) · 54 unmodified lines
133344 hdr->frame_size = ff_ac3_frame_size_tab[frame_size_code][hdr->sr_code] * 2;
134345 hdr->frame_type = EAC3_FRAME_TYPE_AC3_CONVERT; //EAC3_FRAME_TYPE_INDEPENDENT;
135346 hdr->substreamid = 0;
347+
348+ int ret = ac3_parse_header(gbc, hdr);
349+ if (ret < 0)
350+ return ret;
136351 } else {
137352 /* Enhanced AC-3 */
138353 hdr->crc1 = 0;
@@ -165,6 +380,10 @@ int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr) · 26 unmodified lines
165380 hdr->bit_rate = 8LL * hdr->frame_size * hdr->sample_rate /
166381 (hdr->num_blocks * 256);
167382 hdr->channels = ff_ac3_channels_tab[hdr->channel_mode] + hdr->lfe_on;
383+
384+ int ret = eac3_parse_header(gbc, hdr);
385+ if (ret < 0)
386+ return ret;
168387 }
169388 hdr->channel_layout = ff_ac3_channel_layout_tab[hdr->channel_mode];
170389 if (hdr->lfe_on)
libavcodec/ac3_parser_internal.h+19−0
@@ -46,6 +46,7 @@ typedef struct AC3HeaderInfo { · 45 unmodified lines
4646 int substreamid; ///< substream identification
4747 int center_mix_level; ///< Center mix level index
4848 int surround_mix_level; ///< Surround mix level index
49+ uint8_t channel_map_present;
4950 uint16_t channel_map;
5051 int num_blocks; ///< number of audio blocks
5152 int dolby_surround_mode;
@@ -62,6 +63,23 @@ typedef struct AC3HeaderInfo { · 10 unmodified lines
6263 uint64_t channel_layout;
6364 int8_t ac3_bit_rate_code;
6465 /** @} */
66+
67+ /** @name enhanced eac3 extension coded elements
68+ * @{
69+ */
70+ int8_t dialog_normalization[2];
71+ uint8_t compression_exists[2];
72+ uint8_t heavy_dynamic_range[2];
73+ uint8_t center_mix_level_ltrt; ///< Center mix level index
74+ uint8_t surround_mix_level_ltrt; ///< Surround mix level index
75+ uint8_t dolby_headphone_mode;
76+ uint8_t dolby_surround_ex_mode;
77+ uint8_t lfe_mix_level_exists;
78+ uint8_t lfe_mix_level;
79+ uint8_t preferred_downmix;
80+ uint8_t eac3_extension_type_a;
81+ uint8_t complexity_index_type_a;
82+ /** @} */
6583 } AC3HeaderInfo;
6684
6785 typedef enum {
@@ -71,6 +89,7 @@ typedef enum { · 3 unmodified lines
7189 AC3_PARSE_ERROR_FRAME_SIZE = -0x4030c0a,
7290 AC3_PARSE_ERROR_FRAME_TYPE = -0x5030c0a,
7391 AC3_PARSE_ERROR_CRC = -0x6030c0a,
92+ AC3_PARSE_ERROR_CHANNEL_MAP = -0x7030c0a,
7493 } AC3ParseError;
7594
7695 /**
libavcodec/ac3dec.c+20−68
@@ -156,72 +156,6 @@ static av_cold void ac3_decode_flush(AVCodecContext *avctx) · 155 unmodified lines
156156 av_lfg_init(&s->dith_state, 0);
157157 }
158158
159−/**
160− * Parse the 'sync info' and 'bit stream info' from the AC-3 bitstream.
161− * GetBitContext within AC3DecodeContext must point to
162− * the start of the synchronized AC-3 bitstream.
163− */
164−static int ac3_parse_header(AC3DecodeContext *s)
165−{
166− GetBitContext *gbc = &s->gbc;
167− int i;
168−
169− /* read the rest of the bsi. read twice for dual mono mode. */
170− i = !s->channel_mode;
171− do {
172− s->dialog_normalization[(!s->channel_mode)-i] = -get_bits(gbc, 5);
173− if (s->dialog_normalization[(!s->channel_mode)-i] == 0) {
174− s->dialog_normalization[(!s->channel_mode)-i] = -31;
175− }
176− if (s->target_level != 0) {
177− s->level_gain[(!s->channel_mode)-i] = powf(2.0f,
178− (float)(s->target_level -
179− s->dialog_normalization[(!s->channel_mode)-i])/6.0f);
180− }
181− if (s->compression_exists[(!s->channel_mode)-i] = get_bits1(gbc)) {
182− s->heavy_dynamic_range[(!s->channel_mode)-i] =
183− AC3_HEAVY_RANGE(get_bits(gbc, 8));
184− }
185− if (get_bits1(gbc))
186− skip_bits(gbc, 8); //skip language code
187− if (get_bits1(gbc))
188− skip_bits(gbc, 7); //skip audio production information
189− } while (i--);
190−
191− skip_bits(gbc, 2); //skip copyright bit and original bitstream bit
192−
193− /* skip the timecodes or parse the Alternate Bit Stream Syntax */
194− if (s->bitstream_id != 6) {
195− if (get_bits1(gbc))
196− skip_bits(gbc, 14); //skip timecode1
197− if (get_bits1(gbc))
198− skip_bits(gbc, 14); //skip timecode2
199− } else {
200− if (get_bits1(gbc)) {
201− s->preferred_downmix = get_bits(gbc, 2);
202− s->center_mix_level_ltrt = get_bits(gbc, 3);
203− s->surround_mix_level_ltrt = av_clip(get_bits(gbc, 3), 3, 7);
204− s->center_mix_level = get_bits(gbc, 3);
205− s->surround_mix_level = av_clip(get_bits(gbc, 3), 3, 7);
206− }
207− if (get_bits1(gbc)) {
208− s->dolby_surround_ex_mode = get_bits(gbc, 2);
209− s->dolby_headphone_mode = get_bits(gbc, 2);
210− skip_bits(gbc, 10); // skip adconvtyp (1), xbsi2 (8), encinfo (1)
211− }
212− }
213−
214− /* skip additional bitstream info */
215− if (get_bits1(gbc)) {
216− i = get_bits(gbc, 6);
217− do {
218− skip_bits(gbc, 8);
219− } while (i--);
220− }
221−
222− return 0;
223−}
224−
225159 /**
226160 * Common function to parse AC-3 or E-AC-3 frame header
227161 */
@@ -281,10 +215,25 @@ static int parse_frame_header(AC3DecodeContext *s) · 53 unmodified lines
281215 s->dba_syntax = 1;
282216 s->skip_syntax = 1;
283217 memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
284− return ac3_parse_header(s);
218+ /* volume control params */
219+ for (int i = 0; i < (s->channel_mode ? 1 : 2); i++) {
220+ s->dialog_normalization[i] = hdr.dialog_normalization[i];
221+ if (s->dialog_normalization[i] == 0) {
222+ s->dialog_normalization[i] = -31;
223+ }
224+ if (s->target_level != 0) {
225+ s->level_gain[i] = powf(2.0f,
226+ (float)(s->target_level - s->dialog_normalization[i])/6.0f);
227+ }
228+ s->compression_exists[i] = hdr.compression_exists[i];
229+ if (s->compression_exists[i]) {
230+ s->heavy_dynamic_range[i] = AC3_HEAVY_RANGE(hdr.heavy_dynamic_range[i]);
231+ }
232+ }
233+ return 0;
285234 } else if (CONFIG_EAC3_DECODER) {
286235 s->eac3 = 1;
287− return ff_eac3_parse_header(s);
236+ return ff_eac3_parse_header(s, &hdr);
288237 } else {
289238 av_log(s->avctx, AV_LOG_ERROR, "E-AC-3 support not compiled in\n");
290239 return AVERROR(ENOSYS);
@@ -1469,6 +1418,9 @@ dependent_frame: · 1178 unmodified lines
14691418 av_log(avctx, AV_LOG_ERROR, "invalid frame type\n");
14701419 }
14711420 break;
1421+ case AC3_PARSE_ERROR_CHANNEL_MAP:
1422+ av_log(avctx, AV_LOG_ERROR, "invalid channel map\n");
1423+ return AVERROR_INVALIDDATA;
14721424 case AC3_PARSE_ERROR_CRC:
14731425 break;
14741426 default: // Normal AVERROR do not try to recover.
libavcodec/ac3dec.h+3−1
@@ -260,11 +260,13 @@ typedef struct AC3DecodeContext { · 259 unmodified lines
260260 ///@}
261261 } AC3DecodeContext;
262262
263+struct AC3HeaderInfo;
264+
263265 /**
264266 * Parse the E-AC-3 frame header.
265267 * This parses both the bit stream info and audio frame header.
266268 */
267−static int ff_eac3_parse_header(AC3DecodeContext *s);
269+static int ff_eac3_parse_header(AC3DecodeContext *s, const struct AC3HeaderInfo *hdr);
268270
269271 /**
270272 * Decode mantissas in a single channel for the entire frame.
libavcodec/ac3defs.h+2−0
@@ -34,6 +34,8 @@ · 33 unmodified lines
3434 #define AC3_CRITICAL_BANDS 50
3535 #define AC3_MAX_CPL_BANDS 18
3636
37+#define EAC3_SR_CODE_REDUCED 3
38+
3739 /* pre-defined gain values */
3840 #define LEVEL_PLUS_3DB M_SQRT2
3941 #define LEVEL_PLUS_1POINT5DB 1.1892071150027209
libavcodec/eac3dec.c+17−137
@@ -53,8 +53,6 @@ typedef enum { · 52 unmodified lines
5353 EAC3_GAQ_124
5454 } EAC3GaqMode;
5555
56−#define EAC3_SR_CODE_REDUCED 3
57−
5856 static void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
5957 {
6058 int bin, bnd, ch, i;
@@ -287,7 +285,7 @@ static void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch) · 226 unmodified lines
287285 }
288286 }
289287
290−static int ff_eac3_parse_header(AC3DecodeContext *s)
288+static int ff_eac3_parse_header(AC3DecodeContext *s, const AC3HeaderInfo *hdr)
291289 {
292290 int i, blk, ch;
293291 int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
@@ -323,11 +321,10 @@ static int ff_eac3_parse_header(AC3DecodeContext *s) · 29 unmodified lines
323321 avpriv_request_sample(s->avctx, "Reduced sampling rate");
324322 return AVERROR_PATCHWELCOME;
325323 }
326− skip_bits(gbc, 5); // skip bitstream id
327324
328325 /* volume control params */
329326 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
330− s->dialog_normalization[i] = -get_bits(gbc, 5);
327+ s->dialog_normalization[i] = hdr->dialog_normalization[i];
331328 if (s->dialog_normalization[i] == 0) {
332329 s->dialog_normalization[i] = -31;
333330 }
@@ -335,147 +332,30 @@ static int ff_eac3_parse_header(AC3DecodeContext *s) · 1 unmodified line
335332 s->level_gain[i] = powf(2.0f,
336333 (float)(s->target_level - s->dialog_normalization[i])/6.0f);
337334 }
338− s->compression_exists[i] = get_bits1(gbc);
339− if (s->compression_exists[i]) {
340− s->heavy_dynamic_range[i] = AC3_HEAVY_RANGE(get_bits(gbc, 8));
335+ if (hdr->compression_exists[i]) {
336+ s->heavy_dynamic_range[i] = AC3_HEAVY_RANGE(hdr->heavy_dynamic_range[i]);
341337 }
342338 }
343339
344− /* dependent stream channel map */
345− if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) {
346− if (get_bits1(gbc)) {
347− int64_t channel_layout = 0;
348− int channel_map = get_bits(gbc, 16);
349− av_log(s->avctx, AV_LOG_DEBUG, "channel_map: %0X\n", channel_map);
350−
351− for (i = 0; i < 16; i++)
352− if (channel_map & (1 << (EAC3_MAX_CHANNELS - i - 1)))
353− channel_layout |= ff_eac3_custom_channel_map_locations[i][1];
354−
355− if (av_popcount64(channel_layout) > EAC3_MAX_CHANNELS) {
356− return AVERROR_INVALIDDATA;
357− }
358− s->channel_map = channel_map;
359− }
360− }
340+ s->channel_map = hdr->channel_map;
361341
362342 /* mixing metadata */
363− if (get_bits1(gbc)) {
364− /* center and surround mix levels */
365− if (s->channel_mode > AC3_CHMODE_STEREO) {
366− s->preferred_downmix = get_bits(gbc, 2);
367− if (s->channel_mode & 1) {
368− /* if three front channels exist */
369− s->center_mix_level_ltrt = get_bits(gbc, 3);
370− s->center_mix_level = get_bits(gbc, 3);
371− }
372− if (s->channel_mode & 4) {
373− /* if a surround channel exists */
374− s->surround_mix_level_ltrt = av_clip(get_bits(gbc, 3), 3, 7);
375− s->surround_mix_level = av_clip(get_bits(gbc, 3), 3, 7);
376− }
377− }
378−
379− /* lfe mix level */
380− if (s->lfe_on && (s->lfe_mix_level_exists = get_bits1(gbc))) {
381− s->lfe_mix_level = get_bits(gbc, 5);
382− }
383−
384− /* info for mixing with other streams and substreams */
385− if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT) {
386− for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
387− // TODO: apply program scale factor
388− if (get_bits1(gbc)) {
389− skip_bits(gbc, 6); // skip program scale factor
390− }
391− }
392− if (get_bits1(gbc)) {
393− skip_bits(gbc, 6); // skip external program scale factor
394− }
395− /* skip mixing parameter data */
396− switch(get_bits(gbc, 2)) {
397− case 1: skip_bits(gbc, 5); break;
398− case 2: skip_bits(gbc, 12); break;
399− case 3: {
400− int mix_data_size = (get_bits(gbc, 5) + 2) << 3;
401− skip_bits_long(gbc, mix_data_size);
402− break;
403− }
404− }
405− /* skip pan information for mono or dual mono source */
406− if (s->channel_mode < AC3_CHMODE_STEREO) {
407− for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
408− if (get_bits1(gbc)) {
409− /* note: this is not in the ATSC A/52B specification
410− reference: ETSI TS 102 366 V1.1.1
411− section: E.1.3.1.25 */
412− skip_bits(gbc, 8); // skip pan mean direction index
413− skip_bits(gbc, 6); // skip reserved paninfo bits
414− }
415− }
416− }
417− /* skip mixing configuration information */
418− if (get_bits1(gbc)) {
419− for (blk = 0; blk < s->num_blocks; blk++) {
420− if (s->num_blocks == 1 || get_bits1(gbc)) {
421− skip_bits(gbc, 5);
422− }
423− }
424− }
425− }
426− }
343+ s->preferred_downmix = hdr->preferred_downmix;
344+ s->center_mix_level_ltrt = hdr->center_mix_level_ltrt;
345+ s->center_mix_level = hdr->center_mix_level;
346+ s->surround_mix_level_ltrt = hdr->surround_mix_level_ltrt;
347+ s->surround_mix_level = hdr->surround_mix_level;
348+ s->lfe_mix_level_exists = hdr->lfe_mix_level_exists;
349+ s->lfe_mix_level = hdr->lfe_mix_level;
350+ s->dolby_surround_mode = hdr->dolby_surround_mode;
351+ s->dolby_headphone_mode = hdr->dolby_headphone_mode;
352+ s->dolby_surround_ex_mode = hdr->dolby_surround_ex_mode;
427353
428354 /* informational metadata */
429− if (get_bits1(gbc)) {
430− s->bitstream_mode = get_bits(gbc, 3);
431− skip_bits(gbc, 2); // skip copyright bit and original bitstream bit
432− if (s->channel_mode == AC3_CHMODE_STEREO) {
433− s->dolby_surround_mode = get_bits(gbc, 2);
434− s->dolby_headphone_mode = get_bits(gbc, 2);
435− }
436− if (s->channel_mode >= AC3_CHMODE_2F2R) {
437− s->dolby_surround_ex_mode = get_bits(gbc, 2);
438− }
439− for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
440− if (get_bits1(gbc)) {
441− skip_bits(gbc, 8); // skip mix level, room type, and A/D converter type
442− }
443− }
444− if (s->bit_alloc_params.sr_code != EAC3_SR_CODE_REDUCED) {
445− skip_bits1(gbc); // skip source sample rate code
446− }
447− }
448−
449− /* converter synchronization flag
450− If frames are less than six blocks, this bit should be turned on
451− once every 6 blocks to indicate the start of a frame set.
452− reference: RFC 4598, Section 2.1.3 Frame Sets */
453− if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && s->num_blocks != 6) {
454− skip_bits1(gbc); // skip converter synchronization flag
455− }
456−
457− /* original frame size code if this stream was converted from AC-3 */
458− if (s->frame_type == EAC3_FRAME_TYPE_AC3_CONVERT &&
459− (s->num_blocks == 6 || get_bits1(gbc))) {
460− skip_bits(gbc, 6); // skip frame size code
461− }
355+ s->bitstream_mode = hdr->bitstream_mode;
462356
463357 /* additional bitstream info */
464− if (get_bits1(gbc)) {
465− int addbsil = get_bits(gbc, 6);
466− for (i = 0; i < addbsil + 1; i++) {
467− if (i == 0) {
468− /* In this 8 bit chunk, the LSB is equal to flag_ec3_extension_type_a
469− which can be used to detect Atmos presence */
470− skip_bits(gbc, 7);
471− if (get_bits1(gbc)) {
472− s->eac3_extension_type_a = 1;
473− }
474− } else {
475− skip_bits(gbc, 8); // skip additional bit stream info
476− }
477− }
478− }
358+ s->eac3_extension_type_a = hdr->eac3_extension_type_a;
479359
480360 /* audio frame syntax flags, strategy data, and per-frame data */
481361
libavformat/movenc.c+2−15
@@ -532,8 +532,6 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track) · 531 unmodified lines
532532 int parent = hdr->substreamid;
533533
534534 while (cumul_size != pkt->size) {
535− GetBitContext gbc;
536− int i;
537535 ret = avpriv_ac3_parse_header(&hdr, pkt->data + cumul_size, pkt->size - cumul_size);
538536 if (ret < 0)
539537 goto end;
@@ -544,20 +542,9 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track) · 4 unmodified lines
544542 info->substream[parent].num_dep_sub++;
545543 ret /= 8;
546544
547− /* header is parsed up to lfeon, but custom channel map may be needed */
548− init_get_bits8(&gbc, pkt->data + cumul_size + ret, pkt->size - cumul_size - ret);
549− /* skip bsid */
550− skip_bits(&gbc, 5);
551− /* skip volume control params */
552− for (i = 0; i < (hdr->channel_mode ? 1 : 2); i++) {
553− skip_bits(&gbc, 5); // skip dialog normalization
554− if (get_bits1(&gbc)) {
555− skip_bits(&gbc, 8); // skip compression gain word
556− }
557− }
558545 /* get the dependent stream channel map, if exists */
559− if (get_bits1(&gbc))
560− info->substream[parent].chan_loc |= (get_bits(&gbc, 16) >> 5) & 0x1f;
546+ if (hdr->channel_map_present)
547+ info->substream[parent].chan_loc |= (hdr->channel_map >> 5) & 0x1f;
561548 else
562549 info->substream[parent].chan_loc |= hdr->channel_mode;
563550 cumul_size += hdr->frame_size;

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