Mercurial > libavcodec.hg
comparison libspeexdec.c @ 10110:4186efb86933 libavcodec
Modify the Ogg/Speex demuxer and the libspeex decoder so that they always treat
a packet of Speex frames as a single frame.
author | jbr |
---|---|
date | Fri, 28 Aug 2009 00:44:54 +0000 |
parents | 54bc8a2727b0 |
children | ebe5812b39a7 |
comparison
equal
deleted
inserted
replaced
10109:68f824761c1b | 10110:4186efb86933 |
---|---|
51 avctx->sample_fmt = SAMPLE_FMT_S16; | 51 avctx->sample_fmt = SAMPLE_FMT_S16; |
52 if (s->header) { | 52 if (s->header) { |
53 avctx->sample_rate = s->header->rate; | 53 avctx->sample_rate = s->header->rate; |
54 avctx->channels = s->header->nb_channels; | 54 avctx->channels = s->header->nb_channels; |
55 avctx->frame_size = s->header->frame_size; | 55 avctx->frame_size = s->header->frame_size; |
56 if (s->header->frames_per_packet) | |
57 avctx->frame_size *= s->header->frames_per_packet; | |
56 | 58 |
57 mode = speex_lib_get_mode(s->header->mode); | 59 mode = speex_lib_get_mode(s->header->mode); |
58 if (!mode) { | 60 if (!mode) { |
59 av_log(avctx, AV_LOG_ERROR, "Unknown Speex mode %d", s->header->mode); | 61 av_log(avctx, AV_LOG_ERROR, "Unknown Speex mode %d", s->header->mode); |
60 return -1; | 62 return -1; |
96 int buf_size = avpkt->size; | 98 int buf_size = avpkt->size; |
97 LibSpeexContext *s = avctx->priv_data; | 99 LibSpeexContext *s = avctx->priv_data; |
98 int16_t *output = data, *end; | 100 int16_t *output = data, *end; |
99 int i, num_samples; | 101 int i, num_samples; |
100 | 102 |
101 num_samples = avctx->frame_size * avctx->channels; | 103 num_samples = s->header->frame_size * avctx->channels; |
102 end = output + *data_size/2; | 104 end = output + *data_size/2; |
103 | 105 |
104 speex_bits_read_from(&s->bits, buf, buf_size); | 106 speex_bits_read_from(&s->bits, buf, buf_size); |
105 | 107 |
106 for (i = 0; speex_bits_remaining(&s->bits) && output + num_samples < end; i++) { | 108 for (i = 0; speex_bits_remaining(&s->bits) && output + num_samples < end; i++) { |
111 } else if (ret == -1) | 113 } else if (ret == -1) |
112 // end of stream | 114 // end of stream |
113 break; | 115 break; |
114 | 116 |
115 if (avctx->channels == 2) | 117 if (avctx->channels == 2) |
116 speex_decode_stereo_int(output, avctx->frame_size, &s->stereo); | 118 speex_decode_stereo_int(output, s->header->frame_size, &s->stereo); |
117 | 119 |
118 output += num_samples; | 120 output += num_samples; |
119 } | 121 } |
120 | 122 |
121 *data_size = i * avctx->channels * avctx->frame_size * 2; | 123 avctx->frame_size = s->header->frame_size * i; |
124 *data_size = avctx->channels * avctx->frame_size * sizeof(*output); | |
122 return buf_size; | 125 return buf_size; |
123 } | 126 } |
124 | 127 |
125 static av_cold int libspeex_decode_close(AVCodecContext *avctx) | 128 static av_cold int libspeex_decode_close(AVCodecContext *avctx) |
126 { | 129 { |