]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/libspeexdec.c
sparc: fix a few pages of cast warnings
[ffmpeg] / libavcodec / libspeexdec.c
index 7ea348901b956c20f1516719c7188ccabb503994..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) {
@@ -60,22 +63,23 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
             return -1;
         }
     } else
-        av_log(avctx, AV_LOG_INFO, "Missing speex header, assuming defaults\n");
+        av_log(avctx, AV_LOG_INFO, "Missing Speex header, assuming defaults.\n");
 
     if (avctx->channels > 2) {
-        av_log(avctx, AV_LOG_ERROR, "Only stereo and mono supported\n");
+        av_log(avctx, AV_LOG_ERROR, "Only stereo and mono are supported.\n");
         return -1;
     }
 
     speex_bits_init(&s->bits);
     s->dec_state = speex_decoder_init(mode);
     if (!s->dec_state) {
-        av_log(avctx, AV_LOG_ERROR, "Error initializing libspeex decoder\n");
+        av_log(avctx, AV_LOG_ERROR, "Error initializing libspeex decoder.\n");
         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;
@@ -90,33 +94,36 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
 
 static int libspeex_decode_frame(AVCodecContext *avctx,
                                  void *data, int *data_size,
-                                 const uint8_t *buf, int buf_size)
+                                 AVPacket *avpkt)
 {
+    const uint8_t *buf = avpkt->data;
+    int buf_size = avpkt->size;
     LibSpeexContext *s = avctx->priv_data;
     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);
 
     for (i = 0; speex_bits_remaining(&s->bits) && output + num_samples < end; i++) {
         int ret = speex_decode_int(s->dec_state, &s->bits, output);
         if (ret <= -2) {
-            av_log(avctx, AV_LOG_ERROR, "Error decoding speex frame\n");
+            av_log(avctx, AV_LOG_ERROR, "Error decoding Speex frame.\n");
             return -1;
         } else if (ret == -1)
             // end of stream
             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;
 }
 
@@ -140,5 +147,5 @@ AVCodec libspeex_decoder = {
     NULL,
     libspeex_decode_close,
     libspeex_decode_frame,
-    .long_name = NULL_IF_CONFIG_SMALL("libspeex"),
+    .long_name = NULL_IF_CONFIG_SMALL("libspeex Speex"),
 };