Commit eb5f3c54 authored by Justin Ruggles's avatar Justin Ruggles

Modify the Ogg/Speex demuxer and the libspeex decoder so that they always treat

a packet of Speex frames as a single frame.

Originally committed as revision 19734 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent dd0e43e4
...@@ -53,6 +53,8 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx) ...@@ -53,6 +53,8 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
avctx->sample_rate = s->header->rate; avctx->sample_rate = s->header->rate;
avctx->channels = s->header->nb_channels; avctx->channels = s->header->nb_channels;
avctx->frame_size = s->header->frame_size; avctx->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); mode = speex_lib_get_mode(s->header->mode);
if (!mode) { if (!mode) {
...@@ -98,7 +100,7 @@ static int libspeex_decode_frame(AVCodecContext *avctx, ...@@ -98,7 +100,7 @@ static int libspeex_decode_frame(AVCodecContext *avctx,
int16_t *output = data, *end; int16_t *output = data, *end;
int i, num_samples; int i, num_samples;
num_samples = avctx->frame_size * avctx->channels; num_samples = s->header->frame_size * avctx->channels;
end = output + *data_size/2; end = output + *data_size/2;
speex_bits_read_from(&s->bits, buf, buf_size); speex_bits_read_from(&s->bits, buf, buf_size);
...@@ -113,12 +115,13 @@ static int libspeex_decode_frame(AVCodecContext *avctx, ...@@ -113,12 +115,13 @@ static int libspeex_decode_frame(AVCodecContext *avctx,
break; break;
if (avctx->channels == 2) if (avctx->channels == 2)
speex_decode_stereo_int(output, avctx->frame_size, &s->stereo); speex_decode_stereo_int(output, s->header->frame_size, &s->stereo);
output += num_samples; output += num_samples;
} }
*data_size = i * avctx->channels * avctx->frame_size * 2; avctx->frame_size = s->header->frame_size * i;
*data_size = avctx->channels * avctx->frame_size * sizeof(*output);
return buf_size; return buf_size;
} }
......
...@@ -40,12 +40,22 @@ static int speex_header(AVFormatContext *s, int idx) { ...@@ -40,12 +40,22 @@ static int speex_header(AVFormatContext *s, int idx) {
return 0; return 0;
if (os->seq == 0) { if (os->seq == 0) {
int frames_per_packet;
st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_type = CODEC_TYPE_AUDIO;
st->codec->codec_id = CODEC_ID_SPEEX; st->codec->codec_id = CODEC_ID_SPEEX;
st->codec->sample_rate = AV_RL32(p + 36); st->codec->sample_rate = AV_RL32(p + 36);
st->codec->channels = AV_RL32(p + 48); st->codec->channels = AV_RL32(p + 48);
/* We treat the whole Speex packet as a single frame everywhere Speex
is handled in FFmpeg. This avoids the complexities of splitting
and joining individual Speex frames, which are not always
byte-aligned. */
st->codec->frame_size = AV_RL32(p + 56); st->codec->frame_size = AV_RL32(p + 56);
frames_per_packet = AV_RL32(p + 64);
if (frames_per_packet)
st->codec->frame_size *= frames_per_packet;
st->codec->extradata_size = os->psize; st->codec->extradata_size = os->psize;
st->codec->extradata = av_malloc(st->codec->extradata_size st->codec->extradata = av_malloc(st->codec->extradata_size
+ FF_INPUT_BUFFER_PADDING_SIZE); + FF_INPUT_BUFFER_PADDING_SIZE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment