comparison libmpcodecs/ad_speex.c @ 18157:2c7219c38e56

bug fixes: left-over mode variable used uninitialized, initialize sh->audio_out_minsize to maximum decoded size
author reimar
date Wed, 19 Apr 2006 22:30:31 +0000
parents 7dac2afa70aa
children cc65a585fdcc
comparison
equal deleted inserted replaced
18156:2898ee5573d9 18157:2c7219c38e56
3 * License: GPL 3 * License: GPL
4 * This code may be be relicensed under the terms of the GNU LGPL when it 4 * This code may be be relicensed under the terms of the GNU LGPL when it
5 * becomes part of the FFmpeg project (ffmpeg.org) 5 * becomes part of the FFmpeg project (ffmpeg.org)
6 */ 6 */
7 #include "config.h" 7 #include "config.h"
8 #include <stdlib.h>
8 #include <speex/speex.h> 9 #include <speex/speex.h>
9 #include <speex/speex_stereo.h> 10 #include <speex/speex_stereo.h>
10 #include <speex/speex_header.h> 11 #include <speex/speex_header.h>
11 #include "ad_internal.h" 12 #include "ad_internal.h"
12 13
25 void *dec_context; 26 void *dec_context;
26 SpeexStereoState stereo; 27 SpeexStereoState stereo;
27 SpeexHeader *hdr; 28 SpeexHeader *hdr;
28 } context_t; 29 } context_t;
29 30
31 #define MAX_FRAMES_PER_PACKET 100
32
30 static int preinit(sh_audio_t *sh) { 33 static int preinit(sh_audio_t *sh) {
34 sh->audio_out_minsize = 2 * 320 * MAX_FRAMES_PER_PACKET * 2 * sizeof(short);
31 return 1; 35 return 1;
32 } 36 }
33 37
34 static int init(sh_audio_t *sh) { 38 static int init(sh_audio_t *sh) {
35 context_t *ctx = (context_t *)calloc(1, sizeof(context_t)); 39 context_t *ctx = (context_t *)calloc(1, sizeof(context_t));
36 const SpeexMode *spx_mode; 40 const SpeexMode *spx_mode;
37 const SpeexStereoState st_st = SPEEX_STEREO_STATE_INIT; // hack 41 const SpeexStereoState st_st = SPEEX_STEREO_STATE_INIT; // hack
38 int mode;
39 if (!sh->wf || sh->wf->cbSize < 80) { 42 if (!sh->wf || sh->wf->cbSize < 80) {
40 mp_msg(MSGT_DECAUDIO, MSGL_FATAL, "Missing extradata!\n"); 43 mp_msg(MSGT_DECAUDIO, MSGL_FATAL, "Missing extradata!\n");
41 return 0; 44 return 0;
42 } 45 }
43 ctx->hdr = speex_packet_to_header((char *)&sh->wf[1], sh->wf->cbSize); 46 ctx->hdr = speex_packet_to_header((char *)&sh->wf[1], sh->wf->cbSize);
44 if (ctx->hdr->nb_channels != 1 && ctx->hdr->nb_channels != 2) { 47 if (ctx->hdr->nb_channels != 1 && ctx->hdr->nb_channels != 2) {
45 mp_msg(MSGT_DECAUDIO, MSGL_WARN, "Invalid number of channels (%i), " 48 mp_msg(MSGT_DECAUDIO, MSGL_WARN, "Invalid number of channels (%i), "
46 "assuming mono\n", ctx->hdr->nb_channels); 49 "assuming mono\n", ctx->hdr->nb_channels);
47 ctx->hdr->nb_channels = 1; 50 ctx->hdr->nb_channels = 1;
48 } 51 }
52 if (ctx->hdr->frames_per_packet > MAX_FRAMES_PER_PACKET) {
53 mp_msg(MSGT_DECAUDIO, MSGL_WARN, "Invalid number of frames per packet (%i), "
54 "assuming 1\n", ctx->hdr->frames_per_packet);
55 ctx->hdr->frames_per_packet = 1;
56 }
49 switch (ctx->hdr->mode) { 57 switch (ctx->hdr->mode) {
50 case 0: 58 case 0:
51 spx_mode = &speex_nb_mode; break; 59 spx_mode = &speex_nb_mode; break;
52 case 1: 60 case 1:
53 spx_mode = &speex_wb_mode; break; 61 spx_mode = &speex_wb_mode; break;
54 case 2: 62 case 2:
55 spx_mode = &speex_uwb_mode; break; 63 spx_mode = &speex_uwb_mode; break;
56 default: 64 default:
57 mp_msg(MSGT_DECAUDIO, MSGL_WARN, "Unknown speex mode (%i)\n", mode); 65 mp_msg(MSGT_DECAUDIO, MSGL_WARN, "Unknown speex mode (%i)\n", ctx->hdr->mode);
58 spx_mode = &speex_nb_mode; 66 spx_mode = &speex_nb_mode;
59 } 67 }
60 ctx->dec_context = speex_decoder_init(spx_mode); 68 ctx->dec_context = speex_decoder_init(spx_mode);
61 speex_bits_init(&ctx->bits); 69 speex_bits_init(&ctx->bits);
62 memcpy(&ctx->stereo, &st_st, sizeof(ctx->stereo)); // hack part 2 70 memcpy(&ctx->stereo, &st_st, sizeof(ctx->stereo)); // hack part 2