]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/libspeexdec.c
Lossless jpeg expects and uses BGRA not RGB32 (this probably caused a problem on
[ffmpeg] / libavcodec / libspeexdec.c
index 8c3dc293dfdcc70461d41d125c2e068bfa6f77d6..153e395eb0c62453f28cd307f45bd21b504fe966 100644 (file)
@@ -29,6 +29,7 @@ typedef struct {
     SpeexStereoState stereo;
     void *dec_state;
     SpeexHeader *header;
+    int frame_size;
 } LibSpeexContext;
 
 
@@ -52,7 +53,9 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
     if (s->header) {
         avctx->sample_rate = s->header->rate;
         avctx->channels    = s->header->nb_channels;
-        avctx->frame_size  = s->header->frame_size;
+        avctx->frame_size  = s->frame_size = s->header->frame_size;
+        if (s->header->frames_per_packet)
+            avctx->frame_size *= s->header->frames_per_packet;
 
         mode = speex_lib_get_mode(s->header->mode);
         if (!mode) {
@@ -74,8 +77,9 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
         return -1;
     }
 
-    if (!s->header)
-        speex_decoder_ctl(s->dec_state, SPEEX_GET_FRAME_SIZE, &avctx->frame_size);
+    if (!s->header) {
+        speex_decoder_ctl(s->dec_state, SPEEX_GET_FRAME_SIZE, &s->frame_size);
+    }
 
     if (avctx->channels == 2) {
         SpeexCallback callback;
@@ -98,8 +102,8 @@ static int libspeex_decode_frame(AVCodecContext *avctx,
     int16_t *output = data, *end;
     int i, num_samples;
 
-    num_samples = avctx->frame_size * avctx->channels;
-    end = output + *data_size/2;
+    num_samples = s->frame_size * avctx->channels;
+    end = output + *data_size / sizeof(*output);
 
     speex_bits_read_from(&s->bits, buf, buf_size);
 
@@ -113,12 +117,13 @@ static int libspeex_decode_frame(AVCodecContext *avctx,
             break;
 
         if (avctx->channels == 2)
-            speex_decode_stereo_int(output, avctx->frame_size, &s->stereo);
+            speex_decode_stereo_int(output, s->frame_size, &s->stereo);
 
         output += num_samples;
     }
 
-    *data_size = i * avctx->channels * avctx->frame_size * 2;
+    avctx->frame_size = s->frame_size * i;
+    *data_size = avctx->channels * avctx->frame_size * sizeof(*output);
     return buf_size;
 }