Browse code

decoder works fine now, when fed properly-sized chunks by the demuxer; cleaned up some cruft for this commit

Originally committed as revision 4010 to svn://svn.ffmpeg.org/ffmpeg/trunk

Mike Melanson authored on 2005/03/06 16:00:24
Showing 3 changed files
... ...
@@ -11,6 +11,7 @@ version <next>
11 11
 - Nullsoft Video (NSV) file demuxer
12 12
 - Shorten audio decoder
13 13
 - LOCO video decoder
14
+- Apple Lossless Audio Codec (ALAC) decoder 
14 15
 
15 16
 version 0.4.9-pre1:
16 17
 
... ...
@@ -837,6 +837,8 @@ solutions.
837 837
 @item Apple MACE 6           @tab      @tab X
838 838
 @item FLAC lossless audio    @tab      @tab X
839 839
 @item Shorten lossless audio @tab      @tab X
840
+@item Apple lossless audio   @tab      @tab X
841
+@tab QuickTime fourcc 'alac'
840 842
 @item FFmpeg Sonic           @tab X    @tab X
841 843
 @tab Experimental lossy/lossless codec
842 844
 @end multitable
... ...
@@ -132,7 +132,7 @@ static uint32_t readbits_16(alac_file *alac, int bits)
132 132
     int new_accumulator;
133 133
 
134 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 136
             alac->input_buffer_index + 2, alac->input_buffer_size);
137 137
 //        exit (0);
138 138
     }
... ...
@@ -184,9 +184,9 @@ static int readbit(alac_file *alac)
184 184
     int new_accumulator;
185 185
 
186 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 188
             alac->input_buffer_index + 2, alac->input_buffer_size);
189
-//        exit (0);
189
+        exit (0);
190 190
     }
191 191
 
192 192
     result = alac->input_buffer[alac->input_buffer_index];
... ...
@@ -508,14 +508,6 @@ void deinterlace_16(int32_t *buffer_a, int32_t *buffer_b,
508 508
             left = (midright - ((difference * interlacing_leftweight) >> interlacing_shift))
509 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 511
             buffer_out[i*numchannels] = left;
520 512
             buffer_out[i*numchannels + 1] = right;
521 513
         }
... ...
@@ -530,27 +522,25 @@ void deinterlace_16(int32_t *buffer_a, int32_t *buffer_b,
530 530
         left = buffer_a[i];
531 531
         right = buffer_b[i];
532 532
 
533
-        /* output is always little endian */
534
-/*
535
-        if (host_bigendian) {
536
-            be2me_16(left);
537
-            be2me_16(right);
538
-        }
539
-*/
540
-
541 533
         buffer_out[i*numchannels] = left;
542 534
         buffer_out[i*numchannels + 1] = right;
543 535
     }
544 536
 }
545 537
 
546
-int decode_frame(ALACContext *s, alac_file *alac,
547
-                  unsigned char *inbuffer,
548
-                  int input_buffer_size,
549
-                  void *outbuffer, int *outputsize)
538
+static int alac_decode_frame(AVCodecContext *avctx,
539
+                             void *outbuffer, int *outputsize,
540
+                             uint8_t *inbuffer, int input_buffer_size)
550 541
 {
542
+    ALACContext *s = avctx->priv_data;
543
+    alac_file *alac = s->alac;
544
+
551 545
     int channels;
552 546
     int32_t outputsamples;
553 547
 
548
+    /* short-circuit null buffers */
549
+    if (!inbuffer || !input_buffer_size)
550
+        return input_buffer_size;
551
+
554 552
     /* initialize from the extradata */
555 553
     if (!s->context_initialized) {
556 554
         if (s->avctx->extradata_size != ALAC_EXTRADATA_SIZE) {
... ...
@@ -906,15 +896,7 @@ int decode_frame(ALACContext *s, alac_file *alac,
906 906
     }
907 907
     }
908 908
 
909
-av_log(NULL, AV_LOG_INFO, "buf size = %d, consumed %d\n",
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;
909
+    return input_buffer_size;
918 910
 }
919 911
 
920 912
 static int alac_decode_init(AVCodecContext * avctx)
... ...
@@ -932,20 +914,6 @@ static int alac_decode_init(AVCodecContext * avctx)
932 932
     return 0;
933 933
 }
934 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
-}
948
-
949 935
 static int alac_decode_close(AVCodecContext *avctx)
950 936
 {
951 937
     ALACContext *s = avctx->priv_data;