comparison libspeexdec.c @ 10116:6cade2cdd63b libavcodec

Store the frame size in the LibSpeexContext in case the header does not exist.
author jbr
date Sat, 29 Aug 2009 21:04:18 +0000
parents ebe5812b39a7
children 691a0e5585a0
comparison
equal deleted inserted replaced
10115:0b76ca7e07b5 10116:6cade2cdd63b
27 typedef struct { 27 typedef struct {
28 SpeexBits bits; 28 SpeexBits bits;
29 SpeexStereoState stereo; 29 SpeexStereoState stereo;
30 void *dec_state; 30 void *dec_state;
31 SpeexHeader *header; 31 SpeexHeader *header;
32 int frame_size;
32 } LibSpeexContext; 33 } LibSpeexContext;
33 34
34 35
35 static av_cold int libspeex_decode_init(AVCodecContext *avctx) 36 static av_cold int libspeex_decode_init(AVCodecContext *avctx)
36 { 37 {
50 51
51 avctx->sample_fmt = SAMPLE_FMT_S16; 52 avctx->sample_fmt = SAMPLE_FMT_S16;
52 if (s->header) { 53 if (s->header) {
53 avctx->sample_rate = s->header->rate; 54 avctx->sample_rate = s->header->rate;
54 avctx->channels = s->header->nb_channels; 55 avctx->channels = s->header->nb_channels;
55 avctx->frame_size = s->header->frame_size; 56 avctx->frame_size = s->frame_size = s->header->frame_size;
56 if (s->header->frames_per_packet) 57 if (s->header->frames_per_packet)
57 avctx->frame_size *= s->header->frames_per_packet; 58 avctx->frame_size *= s->header->frames_per_packet;
58 59
59 mode = speex_lib_get_mode(s->header->mode); 60 mode = speex_lib_get_mode(s->header->mode);
60 if (!mode) { 61 if (!mode) {
74 if (!s->dec_state) { 75 if (!s->dec_state) {
75 av_log(avctx, AV_LOG_ERROR, "Error initializing libspeex decoder.\n"); 76 av_log(avctx, AV_LOG_ERROR, "Error initializing libspeex decoder.\n");
76 return -1; 77 return -1;
77 } 78 }
78 79
79 if (!s->header) 80 if (!s->header) {
80 speex_decoder_ctl(s->dec_state, SPEEX_GET_FRAME_SIZE, &avctx->frame_size); 81 speex_decoder_ctl(s->dec_state, SPEEX_GET_FRAME_SIZE, &avctx->frame_size);
82 s->frame_size = avctx->frame_size;
83 }
81 84
82 if (avctx->channels == 2) { 85 if (avctx->channels == 2) {
83 SpeexCallback callback; 86 SpeexCallback callback;
84 callback.callback_id = SPEEX_INBAND_STEREO; 87 callback.callback_id = SPEEX_INBAND_STEREO;
85 callback.func = speex_std_stereo_request_handler; 88 callback.func = speex_std_stereo_request_handler;
98 int buf_size = avpkt->size; 101 int buf_size = avpkt->size;
99 LibSpeexContext *s = avctx->priv_data; 102 LibSpeexContext *s = avctx->priv_data;
100 int16_t *output = data, *end; 103 int16_t *output = data, *end;
101 int i, num_samples; 104 int i, num_samples;
102 105
103 num_samples = s->header->frame_size * avctx->channels; 106 num_samples = s->frame_size * avctx->channels;
104 end = output + *data_size / sizeof(*output); 107 end = output + *data_size / sizeof(*output);
105 108
106 speex_bits_read_from(&s->bits, buf, buf_size); 109 speex_bits_read_from(&s->bits, buf, buf_size);
107 110
108 for (i = 0; speex_bits_remaining(&s->bits) && output + num_samples < end; i++) { 111 for (i = 0; speex_bits_remaining(&s->bits) && output + num_samples < end; i++) {
113 } else if (ret == -1) 116 } else if (ret == -1)
114 // end of stream 117 // end of stream
115 break; 118 break;
116 119
117 if (avctx->channels == 2) 120 if (avctx->channels == 2)
118 speex_decode_stereo_int(output, s->header->frame_size, &s->stereo); 121 speex_decode_stereo_int(output, s->frame_size, &s->stereo);
119 122
120 output += num_samples; 123 output += num_samples;
121 } 124 }
122 125
123 avctx->frame_size = s->header->frame_size * i; 126 avctx->frame_size = s->frame_size * i;
124 *data_size = avctx->channels * avctx->frame_size * sizeof(*output); 127 *data_size = avctx->channels * avctx->frame_size * sizeof(*output);
125 return buf_size; 128 return buf_size;
126 } 129 }
127 130
128 static av_cold int libspeex_decode_close(AVCodecContext *avctx) 131 static av_cold int libspeex_decode_close(AVCodecContext *avctx)