Mercurial > libavcodec.hg
comparison alac.c @ 2544:8c426f5a09ae libavcodec
decoder works fine now, when fed properly-sized chunks by the demuxer;
cleaned up some cruft for this commit
author | melanson |
---|---|
date | Sun, 06 Mar 2005 07:00:24 +0000 |
parents | e8f1f57215ad |
children | 621cc4a94695 |
comparison
equal
deleted
inserted
replaced
2543:e8f1f57215ad | 2544:8c426f5a09ae |
---|---|
130 { | 130 { |
131 uint32_t result; | 131 uint32_t result; |
132 int new_accumulator; | 132 int new_accumulator; |
133 | 133 |
134 if (alac->input_buffer_index + 2 >= alac->input_buffer_size) { | 134 if (alac->input_buffer_index + 2 >= alac->input_buffer_size) { |
135 av_log(NULL, AV_LOG_INFO, "alac: input buffer went out of bounds (%d >= %d)\n", | 135 av_log(NULL, AV_LOG_ERROR, "alac: input buffer went out of bounds (%d >= %d)\n", |
136 alac->input_buffer_index + 2, alac->input_buffer_size); | 136 alac->input_buffer_index + 2, alac->input_buffer_size); |
137 // exit (0); | 137 // exit (0); |
138 } | 138 } |
139 result = (alac->input_buffer[alac->input_buffer_index + 0] << 16) | | 139 result = (alac->input_buffer[alac->input_buffer_index + 0] << 16) | |
140 (alac->input_buffer[alac->input_buffer_index + 1] << 8) | | 140 (alac->input_buffer[alac->input_buffer_index + 1] << 8) | |
182 { | 182 { |
183 int result; | 183 int result; |
184 int new_accumulator; | 184 int new_accumulator; |
185 | 185 |
186 if (alac->input_buffer_index >= alac->input_buffer_size) { | 186 if (alac->input_buffer_index >= alac->input_buffer_size) { |
187 av_log(NULL, AV_LOG_INFO, "alac: input buffer went out of bounds (%d >= %d)\n", | 187 av_log(NULL, AV_LOG_ERROR, "alac: input buffer went out of bounds (%d >= %d)\n", |
188 alac->input_buffer_index + 2, alac->input_buffer_size); | 188 alac->input_buffer_index + 2, alac->input_buffer_size); |
189 // exit (0); | 189 exit (0); |
190 } | 190 } |
191 | 191 |
192 result = alac->input_buffer[alac->input_buffer_index]; | 192 result = alac->input_buffer[alac->input_buffer_index]; |
193 | 193 |
194 result = result << alac->input_buffer_bitaccumulator; | 194 result = result << alac->input_buffer_bitaccumulator; |
506 | 506 |
507 right = midright - ((difference * interlacing_leftweight) >> interlacing_shift); | 507 right = midright - ((difference * interlacing_leftweight) >> interlacing_shift); |
508 left = (midright - ((difference * interlacing_leftweight) >> interlacing_shift)) | 508 left = (midright - ((difference * interlacing_leftweight) >> interlacing_shift)) |
509 + difference; | 509 + difference; |
510 | 510 |
511 /* output is always little endian */ | |
512 /* | |
513 if (host_bigendian) { | |
514 be2me_16(left); | |
515 be2me_16(right); | |
516 } | |
517 */ | |
518 | |
519 buffer_out[i*numchannels] = left; | 511 buffer_out[i*numchannels] = left; |
520 buffer_out[i*numchannels + 1] = right; | 512 buffer_out[i*numchannels + 1] = right; |
521 } | 513 } |
522 | 514 |
523 return; | 515 return; |
528 int16_t left, right; | 520 int16_t left, right; |
529 | 521 |
530 left = buffer_a[i]; | 522 left = buffer_a[i]; |
531 right = buffer_b[i]; | 523 right = buffer_b[i]; |
532 | 524 |
533 /* output is always little endian */ | |
534 /* | |
535 if (host_bigendian) { | |
536 be2me_16(left); | |
537 be2me_16(right); | |
538 } | |
539 */ | |
540 | |
541 buffer_out[i*numchannels] = left; | 525 buffer_out[i*numchannels] = left; |
542 buffer_out[i*numchannels + 1] = right; | 526 buffer_out[i*numchannels + 1] = right; |
543 } | 527 } |
544 } | 528 } |
545 | 529 |
546 int decode_frame(ALACContext *s, alac_file *alac, | 530 static int alac_decode_frame(AVCodecContext *avctx, |
547 unsigned char *inbuffer, | 531 void *outbuffer, int *outputsize, |
548 int input_buffer_size, | 532 uint8_t *inbuffer, int input_buffer_size) |
549 void *outbuffer, int *outputsize) | 533 { |
550 { | 534 ALACContext *s = avctx->priv_data; |
535 alac_file *alac = s->alac; | |
536 | |
551 int channels; | 537 int channels; |
552 int32_t outputsamples; | 538 int32_t outputsamples; |
539 | |
540 /* short-circuit null buffers */ | |
541 if (!inbuffer || !input_buffer_size) | |
542 return input_buffer_size; | |
553 | 543 |
554 /* initialize from the extradata */ | 544 /* initialize from the extradata */ |
555 if (!s->context_initialized) { | 545 if (!s->context_initialized) { |
556 if (s->avctx->extradata_size != ALAC_EXTRADATA_SIZE) { | 546 if (s->avctx->extradata_size != ALAC_EXTRADATA_SIZE) { |
557 av_log(NULL, AV_LOG_ERROR, "alac: expected %d extradata bytes\n", | 547 av_log(NULL, AV_LOG_ERROR, "alac: expected %d extradata bytes\n", |
904 | 894 |
905 break; | 895 break; |
906 } | 896 } |
907 } | 897 } |
908 | 898 |
909 av_log(NULL, AV_LOG_INFO, "buf size = %d, consumed %d\n", | 899 return input_buffer_size; |
910 input_buffer_size, alac->input_buffer_index); | |
911 | |
912 /* avoid infinite loop: if decoder consumed 0 bytes; report all bytes | |
913 * consumed */ | |
914 // if (alac->input_buffer_index) | |
915 // return alac->input_buffer_index; | |
916 // else | |
917 return input_buffer_size; | |
918 } | 900 } |
919 | 901 |
920 static int alac_decode_init(AVCodecContext * avctx) | 902 static int alac_decode_init(AVCodecContext * avctx) |
921 { | 903 { |
922 ALACContext *s = avctx->priv_data; | 904 ALACContext *s = avctx->priv_data; |
928 s->alac->samplesize = s->avctx->bits_per_sample; | 910 s->alac->samplesize = s->avctx->bits_per_sample; |
929 s->alac->numchannels = s->avctx->channels; | 911 s->alac->numchannels = s->avctx->channels; |
930 s->alac->bytespersample = (s->alac->samplesize / 8) * s->alac->numchannels; | 912 s->alac->bytespersample = (s->alac->samplesize / 8) * s->alac->numchannels; |
931 | 913 |
932 return 0; | 914 return 0; |
933 } | |
934 | |
935 static int alac_decode_frame(AVCodecContext *avctx, | |
936 void *data, int *data_size, | |
937 uint8_t *buf, int buf_size) | |
938 { | |
939 ALACContext *s = avctx->priv_data; | |
940 int bytes_consumed = buf_size; | |
941 | |
942 if (buf) | |
943 bytes_consumed = decode_frame(s, s->alac, buf, buf_size, | |
944 data, data_size); | |
945 | |
946 return bytes_consumed; | |
947 } | 915 } |
948 | 916 |
949 static int alac_decode_close(AVCodecContext *avctx) | 917 static int alac_decode_close(AVCodecContext *avctx) |
950 { | 918 { |
951 ALACContext *s = avctx->priv_data; | 919 ALACContext *s = avctx->priv_data; |