Mercurial > libavcodec.hg
comparison aacenc.c @ 9937:3e39dbd2d9eb libavcodec
cosmetics: prettyprinting, K&R style, break overly long lines
author | diego |
---|---|
date | Wed, 08 Jul 2009 21:16:06 +0000 |
parents | 7f42ae22c351 |
children | 6c1ac45b3097 |
comparison
equal
deleted
inserted
replaced
9936:7f42ae22c351 | 9937:3e39dbd2d9eb |
---|---|
179 ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); | 179 ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); |
180 ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); | 180 ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); |
181 ff_sine_window_init(ff_sine_1024, 1024); | 181 ff_sine_window_init(ff_sine_1024, 1024); |
182 ff_sine_window_init(ff_sine_128, 128); | 182 ff_sine_window_init(ff_sine_128, 128); |
183 | 183 |
184 s->samples = av_malloc(2 * 1024 * avctx->channels * sizeof(s->samples[0])); | 184 s->samples = av_malloc(2 * 1024 * avctx->channels * sizeof(s->samples[0])); |
185 s->cpe = av_mallocz(sizeof(ChannelElement) * aac_chan_configs[avctx->channels-1][0]); | 185 s->cpe = av_mallocz(sizeof(ChannelElement) * aac_chan_configs[avctx->channels-1][0]); |
186 avctx->extradata = av_malloc(2); | 186 avctx->extradata = av_malloc(2); |
187 avctx->extradata_size = 2; | 187 avctx->extradata_size = 2; |
188 put_audio_specific_config(avctx); | 188 put_audio_specific_config(avctx); |
189 | 189 |
190 sizes[0] = swb_size_1024[i]; | 190 sizes[0] = swb_size_1024[i]; |
191 sizes[1] = swb_size_128[i]; | 191 sizes[1] = swb_size_128[i]; |
192 lengths[0] = ff_aac_num_swb_1024[i]; | 192 lengths[0] = ff_aac_num_swb_1024[i]; |
193 lengths[1] = ff_aac_num_swb_128[i]; | 193 lengths[1] = ff_aac_num_swb_128[i]; |
194 ff_psy_init(&s->psy, avctx, 2, sizes, lengths); | 194 ff_psy_init(&s->psy, avctx, 2, sizes, lengths); |
195 s->psypp = ff_psy_preprocess_init(avctx); | 195 s->psypp = ff_psy_preprocess_init(avctx); |
196 s->coder = &ff_aac_coders[0]; | 196 s->coder = &ff_aac_coders[0]; |
351 ics0->max_sfb = FFMAX(ics0->max_sfb, ics1->max_sfb); | 351 ics0->max_sfb = FFMAX(ics0->max_sfb, ics1->max_sfb); |
352 ics1->max_sfb = ics0->max_sfb; | 352 ics1->max_sfb = ics0->max_sfb; |
353 for (w = 0; w < ics0->num_windows*16; w += 16) | 353 for (w = 0; w < ics0->num_windows*16; w += 16) |
354 for (i = 0; i < ics0->max_sfb; i++) | 354 for (i = 0; i < ics0->max_sfb; i++) |
355 if (cpe->ms_mask[w+i]) msc++; | 355 if (cpe->ms_mask[w+i]) msc++; |
356 if (msc == 0 || ics0->max_sfb == 0) cpe->ms_mode = 0; | 356 if (msc == 0 || ics0->max_sfb == 0) |
357 else cpe->ms_mode = msc < ics0->max_sfb ? 1 : 2; | 357 cpe->ms_mode = 0; |
358 else | |
359 cpe->ms_mode = msc < ics0->max_sfb ? 1 : 2; | |
358 } | 360 } |
359 } | 361 } |
360 | 362 |
361 /** | 363 /** |
362 * Encode scalefactor band coding type. | 364 * Encode scalefactor band coding type. |
371 } | 373 } |
372 | 374 |
373 /** | 375 /** |
374 * Encode scalefactors. | 376 * Encode scalefactors. |
375 */ | 377 */ |
376 static void encode_scale_factors(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce) | 378 static void encode_scale_factors(AVCodecContext *avctx, AACEncContext *s, |
379 SingleChannelElement *sce) | |
377 { | 380 { |
378 int off = sce->sf_idx[0], diff; | 381 int off = sce->sf_idx[0], diff; |
379 int i, w; | 382 int i, w; |
380 | 383 |
381 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { | 384 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { |
382 for (i = 0; i < sce->ics.max_sfb; i++) { | 385 for (i = 0; i < sce->ics.max_sfb; i++) { |
383 if (!sce->zeroes[w*16 + i]) { | 386 if (!sce->zeroes[w*16 + i]) { |
384 diff = sce->sf_idx[w*16 + i] - off + SCALE_DIFF_ZERO; | 387 diff = sce->sf_idx[w*16 + i] - off + SCALE_DIFF_ZERO; |
385 if (diff < 0 || diff > 120) av_log(avctx, AV_LOG_ERROR, "Scalefactor difference is too big to be coded\n"); | 388 if (diff < 0 || diff > 120) |
389 av_log(avctx, AV_LOG_ERROR, "Scalefactor difference is too big to be coded\n"); | |
386 off = sce->sf_idx[w*16 + i]; | 390 off = sce->sf_idx[w*16 + i]; |
387 put_bits(&s->pb, ff_aac_scalefactor_bits[diff], ff_aac_scalefactor_code[diff]); | 391 put_bits(&s->pb, ff_aac_scalefactor_bits[diff], ff_aac_scalefactor_code[diff]); |
388 } | 392 } |
389 } | 393 } |
390 } | 394 } |
396 static void encode_pulses(AACEncContext *s, Pulse *pulse) | 400 static void encode_pulses(AACEncContext *s, Pulse *pulse) |
397 { | 401 { |
398 int i; | 402 int i; |
399 | 403 |
400 put_bits(&s->pb, 1, !!pulse->num_pulse); | 404 put_bits(&s->pb, 1, !!pulse->num_pulse); |
401 if (!pulse->num_pulse) return; | 405 if (!pulse->num_pulse) |
406 return; | |
402 | 407 |
403 put_bits(&s->pb, 2, pulse->num_pulse - 1); | 408 put_bits(&s->pb, 2, pulse->num_pulse - 1); |
404 put_bits(&s->pb, 6, pulse->start); | 409 put_bits(&s->pb, 6, pulse->start); |
405 for (i = 0; i < pulse->num_pulse; i++) { | 410 for (i = 0; i < pulse->num_pulse; i++) { |
406 put_bits(&s->pb, 5, pulse->pos[i]); | 411 put_bits(&s->pb, 5, pulse->pos[i]); |
422 start += sce->ics.swb_sizes[i]; | 427 start += sce->ics.swb_sizes[i]; |
423 continue; | 428 continue; |
424 } | 429 } |
425 for (w2 = w; w2 < w + sce->ics.group_len[w]; w2++) { | 430 for (w2 = w; w2 < w + sce->ics.group_len[w]; w2++) { |
426 s->coder->quantize_and_encode_band(s, &s->pb, sce->coeffs + start + w2*128, | 431 s->coder->quantize_and_encode_band(s, &s->pb, sce->coeffs + start + w2*128, |
427 sce->ics.swb_sizes[i], | 432 sce->ics.swb_sizes[i], |
428 sce->sf_idx[w*16 + i], | 433 sce->sf_idx[w*16 + i], |
429 sce->band_type[w*16 + i], | 434 sce->band_type[w*16 + i], |
430 s->lambda); | 435 s->lambda); |
431 } | 436 } |
432 start += sce->ics.swb_sizes[i]; | 437 start += sce->ics.swb_sizes[i]; |
433 } | 438 } |
434 } | 439 } |
435 } | 440 } |
436 | 441 |
437 /** | 442 /** |
438 * Encode one channel of audio data. | 443 * Encode one channel of audio data. |
439 */ | 444 */ |
440 static int encode_individual_channel(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, int common_window) | 445 static int encode_individual_channel(AVCodecContext *avctx, AACEncContext *s, |
446 SingleChannelElement *sce, | |
447 int common_window) | |
441 { | 448 { |
442 put_bits(&s->pb, 8, sce->sf_idx[0]); | 449 put_bits(&s->pb, 8, sce->sf_idx[0]); |
443 if (!common_window) put_ics_info(s, &sce->ics); | 450 if (!common_window) |
451 put_ics_info(s, &sce->ics); | |
444 encode_band_info(s, sce); | 452 encode_band_info(s, sce); |
445 encode_scale_factors(avctx, s, sce); | 453 encode_scale_factors(avctx, s, sce); |
446 encode_pulses(s, &sce->pulse); | 454 encode_pulses(s, &sce->pulse); |
447 put_bits(&s->pb, 1, 0); //tns | 455 put_bits(&s->pb, 1, 0); //tns |
448 put_bits(&s->pb, 1, 0); //ssr | 456 put_bits(&s->pb, 1, 0); //ssr |
451 } | 459 } |
452 | 460 |
453 /** | 461 /** |
454 * Write some auxiliary information about the created AAC file. | 462 * Write some auxiliary information about the created AAC file. |
455 */ | 463 */ |
456 static void put_bitstream_info(AVCodecContext *avctx, AACEncContext *s, const char *name) | 464 static void put_bitstream_info(AVCodecContext *avctx, AACEncContext *s, |
465 const char *name) | |
457 { | 466 { |
458 int i, namelen, padbits; | 467 int i, namelen, padbits; |
459 | 468 |
460 namelen = strlen(name) + 2; | 469 namelen = strlen(name) + 2; |
461 put_bits(&s->pb, 3, TYPE_FIL); | 470 put_bits(&s->pb, 3, TYPE_FIL); |
482 | 491 |
483 if (s->last_frame) | 492 if (s->last_frame) |
484 return 0; | 493 return 0; |
485 if (data) { | 494 if (data) { |
486 if (!s->psypp) { | 495 if (!s->psypp) { |
487 memcpy(s->samples + 1024 * avctx->channels, data, 1024 * avctx->channels * sizeof(s->samples[0])); | 496 memcpy(s->samples + 1024 * avctx->channels, data, |
497 1024 * avctx->channels * sizeof(s->samples[0])); | |
488 } else { | 498 } else { |
489 start_ch = 0; | 499 start_ch = 0; |
490 samples2 = s->samples + 1024 * avctx->channels; | 500 samples2 = s->samples + 1024 * avctx->channels; |
491 for (i = 0; i < chan_map[0]; i++) { | 501 for (i = 0; i < chan_map[0]; i++) { |
492 tag = chan_map[i+1]; | 502 tag = chan_map[i+1]; |
493 chans = tag == TYPE_CPE ? 2 : 1; | 503 chans = tag == TYPE_CPE ? 2 : 1; |
494 ff_psy_preprocess(s->psypp, (uint16_t*)data + start_ch, samples2 + start_ch, start_ch, chans); | 504 ff_psy_preprocess(s->psypp, (uint16_t*)data + start_ch, |
505 samples2 + start_ch, start_ch, chans); | |
495 start_ch += chans; | 506 start_ch += chans; |
496 } | 507 } |
497 } | 508 } |
498 } | 509 } |
499 if (!avctx->frame_number) { | 510 if (!avctx->frame_number) { |
500 memcpy(s->samples, s->samples + 1024 * avctx->channels, 1024 * avctx->channels * sizeof(s->samples[0])); | 511 memcpy(s->samples, s->samples + 1024 * avctx->channels, |
512 1024 * avctx->channels * sizeof(s->samples[0])); | |
501 return 0; | 513 return 0; |
502 } | 514 } |
503 | 515 |
504 init_put_bits(&s->pb, frame, buf_size*8); | 516 init_put_bits(&s->pb, frame, buf_size*8); |
505 if ((avctx->frame_number & 0xFF)==1 && !(avctx->flags & CODEC_FLAG_BITEXACT)) { | 517 if ((avctx->frame_number & 0xFF)==1 && !(avctx->flags & CODEC_FLAG_BITEXACT)) { |
507 } | 519 } |
508 start_ch = 0; | 520 start_ch = 0; |
509 memset(chan_el_counter, 0, sizeof(chan_el_counter)); | 521 memset(chan_el_counter, 0, sizeof(chan_el_counter)); |
510 for (i = 0; i < chan_map[0]; i++) { | 522 for (i = 0; i < chan_map[0]; i++) { |
511 FFPsyWindowInfo wi[2]; | 523 FFPsyWindowInfo wi[2]; |
512 tag = chan_map[i+1]; | 524 tag = chan_map[i+1]; |
513 chans = tag == TYPE_CPE ? 2 : 1; | 525 chans = tag == TYPE_CPE ? 2 : 1; |
514 cpe = &s->cpe[i]; | 526 cpe = &s->cpe[i]; |
515 samples2 = samples + start_ch; | 527 samples2 = samples + start_ch; |
516 la = samples2 + 1024 * avctx->channels + start_ch; | 528 la = samples2 + 1024 * avctx->channels + start_ch; |
517 if (!data) la = NULL; | 529 if (!data) la = NULL; |
518 for (j = 0; j < chans; j++) { | 530 for (j = 0; j < chans; j++) { |
519 IndividualChannelStream *ics = &cpe->ch[j].ics; | 531 IndividualChannelStream *ics = &cpe->ch[j].ics; |
520 int k; | 532 int k; |
521 wi[j] = ff_psy_suggest_window(&s->psy, samples2, la, start_ch + j, ics->window_sequence[0]); | 533 wi[j] = ff_psy_suggest_window(&s->psy, samples2, la, start_ch + j, ics->window_sequence[0]); |
575 float ratio = avctx->bit_rate * 1024.0f / avctx->sample_rate / avctx->frame_bits; | 587 float ratio = avctx->bit_rate * 1024.0f / avctx->sample_rate / avctx->frame_bits; |
576 s->lambda *= ratio; | 588 s->lambda *= ratio; |
577 } | 589 } |
578 | 590 |
579 if (avctx->frame_bits > 6144*avctx->channels) { | 591 if (avctx->frame_bits > 6144*avctx->channels) { |
580 av_log(avctx, AV_LOG_ERROR, "input buffer violation %d > %d.\n", avctx->frame_bits, 6144*avctx->channels); | 592 av_log(avctx, AV_LOG_ERROR, "input buffer violation %d > %d.\n", |
593 avctx->frame_bits, 6144*avctx->channels); | |
581 } | 594 } |
582 | 595 |
583 if (!data) | 596 if (!data) |
584 s->last_frame = 1; | 597 s->last_frame = 1; |
585 memcpy(s->samples, s->samples + 1024 * avctx->channels, 1024 * avctx->channels * sizeof(s->samples[0])); | 598 memcpy(s->samples, s->samples + 1024 * avctx->channels, |
599 1024 * avctx->channels * sizeof(s->samples[0])); | |
586 return put_bits_count(&s->pb)>>3; | 600 return put_bits_count(&s->pb)>>3; |
587 } | 601 } |
588 | 602 |
589 static av_cold int aac_encode_end(AVCodecContext *avctx) | 603 static av_cold int aac_encode_end(AVCodecContext *avctx) |
590 { | 604 { |