comparison ac3dec.c @ 7028:4ef389a71e03 libavcodec

split up header parsing function
author jbr
date Sat, 07 Jun 2008 22:30:51 +0000
parents 1edec36c02c5
children f90b89217cc9
comparison
equal deleted inserted replaced
7027:1edec36c02c5 7028:4ef389a71e03
234 * GetBitContext within AC3DecodeContext must point to 234 * GetBitContext within AC3DecodeContext must point to
235 * start of the synchronized ac3 bitstream. 235 * start of the synchronized ac3 bitstream.
236 */ 236 */
237 static int ac3_parse_header(AC3DecodeContext *s) 237 static int ac3_parse_header(AC3DecodeContext *s)
238 { 238 {
239 GetBitContext *gbc = &s->gbc;
240 int i;
241
242 /* read the rest of the bsi. read twice for dual mono mode. */
243 i = !(s->channel_mode);
244 do {
245 skip_bits(gbc, 5); // skip dialog normalization
246 if (get_bits1(gbc))
247 skip_bits(gbc, 8); //skip compression
248 if (get_bits1(gbc))
249 skip_bits(gbc, 8); //skip language code
250 if (get_bits1(gbc))
251 skip_bits(gbc, 7); //skip audio production information
252 } while (i--);
253
254 skip_bits(gbc, 2); //skip copyright bit and original bitstream bit
255
256 /* skip the timecodes (or extra bitstream information for Alternate Syntax)
257 TODO: read & use the xbsi1 downmix levels */
258 if (get_bits1(gbc))
259 skip_bits(gbc, 14); //skip timecode1 / xbsi1
260 if (get_bits1(gbc))
261 skip_bits(gbc, 14); //skip timecode2 / xbsi2
262
263 /* skip additional bitstream info */
264 if (get_bits1(gbc)) {
265 i = get_bits(gbc, 6);
266 do {
267 skip_bits(gbc, 8);
268 } while(i--);
269 }
270
271 return 0;
272 }
273
274 /**
275 * Common function to parse AC3 or E-AC3 frame header
276 */
277 static int parse_frame_header(AC3DecodeContext *s)
278 {
239 AC3HeaderInfo hdr; 279 AC3HeaderInfo hdr;
240 GetBitContext *gbc = &s->gbc; 280 GetBitContext *gbc = &s->gbc;
241 int err, i; 281 int err;
242 282
243 err = ff_ac3_parse_header(gbc, &hdr); 283 err = ff_ac3_parse_header(gbc, &hdr);
244 if(err) 284 if(err)
245 return err; 285 return err;
246 286
269 s->end_freq[s->lfe_ch] = 7; 309 s->end_freq[s->lfe_ch] = 7;
270 s->num_exp_groups[s->lfe_ch] = 2; 310 s->num_exp_groups[s->lfe_ch] = 2;
271 s->channel_in_cpl[s->lfe_ch] = 0; 311 s->channel_in_cpl[s->lfe_ch] = 0;
272 } 312 }
273 313
274 /* read the rest of the bsi. read twice for dual mono mode. */ 314 return ac3_parse_header(s);
275 i = !(s->channel_mode);
276 do {
277 skip_bits(gbc, 5); // skip dialog normalization
278 if (get_bits1(gbc))
279 skip_bits(gbc, 8); //skip compression
280 if (get_bits1(gbc))
281 skip_bits(gbc, 8); //skip language code
282 if (get_bits1(gbc))
283 skip_bits(gbc, 7); //skip audio production information
284 } while (i--);
285
286 skip_bits(gbc, 2); //skip copyright bit and original bitstream bit
287
288 /* skip the timecodes (or extra bitstream information for Alternate Syntax)
289 TODO: read & use the xbsi1 downmix levels */
290 if (get_bits1(gbc))
291 skip_bits(gbc, 14); //skip timecode1 / xbsi1
292 if (get_bits1(gbc))
293 skip_bits(gbc, 14); //skip timecode2 / xbsi2
294
295 /* skip additional bitstream info */
296 if (get_bits1(gbc)) {
297 i = get_bits(gbc, 6);
298 do {
299 skip_bits(gbc, 8);
300 } while(i--);
301 }
302
303 return 0;
304 } 315 }
305 316
306 /** 317 /**
307 * Set stereo downmixing coefficients based on frame header info. 318 * Set stereo downmixing coefficients based on frame header info.
308 * reference: Section 7.8.2 Downmixing Into Two Channels 319 * reference: Section 7.8.2 Downmixing Into Two Channels
1079 init_get_bits(&s->gbc, buf, buf_size * 8); 1090 init_get_bits(&s->gbc, buf, buf_size * 8);
1080 } 1091 }
1081 1092
1082 /* parse the syncinfo */ 1093 /* parse the syncinfo */
1083 *data_size = 0; 1094 *data_size = 0;
1084 err = ac3_parse_header(s); 1095 err = parse_frame_header(s);
1085 1096
1086 /* check that reported frame size fits in input buffer */ 1097 /* check that reported frame size fits in input buffer */
1087 if(s->frame_size > buf_size) { 1098 if(s->frame_size > buf_size) {
1088 av_log(avctx, AV_LOG_ERROR, "incomplete frame\n"); 1099 av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
1089 err = AC3_PARSE_ERROR_FRAME_SIZE; 1100 err = AC3_PARSE_ERROR_FRAME_SIZE;