summaryrefslogtreecommitdiff
path: root/src/combined/ffmpeg/ff_audio_decoder.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/combined/ffmpeg/ff_audio_decoder.c')
-rw-r--r--src/combined/ffmpeg/ff_audio_decoder.c81
1 files changed, 69 insertions, 12 deletions
diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c
index b7f966325..27fe18d9c 100644
--- a/src/combined/ffmpeg/ff_audio_decoder.c
+++ b/src/combined/ffmpeg/ff_audio_decoder.c
@@ -78,6 +78,7 @@ static const ff_codec_t ff_audio_lookup[] = {
{BUF_AUDIO_14_4, CODEC_ID_RA_144, "Real 14.4 (ffmpeg)"},
{BUF_AUDIO_28_8, CODEC_ID_RA_288, "Real 28.8 (ffmpeg)"},
{BUF_AUDIO_MPEG, CODEC_ID_MP3, "MP3 (ffmpeg)"},
+ {BUF_AUDIO_MP3ADU, CODEC_ID_MP3ADU, "MPEG-3 adu (ffmpeg)"},
{BUF_AUDIO_MSADPCM, CODEC_ID_ADPCM_MS, "MS ADPCM (ffmpeg)"},
{BUF_AUDIO_QTIMAADPCM, CODEC_ID_ADPCM_IMA_QT, "QT IMA ADPCM (ffmpeg)"},
{BUF_AUDIO_MSIMAADPCM, CODEC_ID_ADPCM_IMA_WAV, "MS IMA ADPCM (ffmpeg)"},
@@ -198,8 +199,8 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf)
this->audio_channels = this->buf[0x37];
/* this->audio_bits = buf->content[0x35] */
- this->context->block_align = _X_BE_16(&this->buf[0x2A]);
-
+ this->context->block_align = _X_BE_32(&this->buf[0x18]);
+
this->context->extradata_size = 5*sizeof(short);
this->context->extradata = xine_xmalloc(this->context->extradata_size);
@@ -210,7 +211,49 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf)
ptr[2] = _X_BE_16(&this->buf[0x16]); /* subpacket flavour */
ptr[3] = _X_BE_32(&this->buf[0x18]); /* coded frame size */
ptr[4] = 0; /* codec's data length */
+
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ "ffmpeg_audio_dec: 28_8 audio channels %d bits %d sample rate %d block align %d\n",
+ this->audio_channels, this->audio_bits, this->audio_sample_rate,
+ this->context->block_align);
break;
+ case BUF_AUDIO_COOK:
+ {
+ int version;
+ int data_len;
+ int extradata;
+
+ version = _X_BE_16 (this->buf+4);
+ if (version == 4) {
+ this->audio_sample_rate = _X_BE_16 (this->buf+48);
+ this->audio_bits = _X_BE_16 (this->buf+52);
+ this->audio_channels = _X_BE_16 (this->buf+54);
+ data_len = _X_BE_32 (this->buf+67);
+ extradata = 71;
+ } else {
+ this->audio_sample_rate = _X_BE_16 (this->buf+54);
+ this->audio_bits = _X_BE_16 (this->buf+58);
+ this->audio_channels = _X_BE_16 (this->buf+60);
+ data_len = _X_BE_32 (this->buf+74);
+ extradata = 78;
+ }
+ this->context->block_align = _X_BE_16 (this->buf+44);
+
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ "ffmpeg_audio_dec: cook audio channels %d bits %d sample rate %d block align %d\n",
+ this->audio_channels, this->audio_bits, this->audio_sample_rate,
+ this->context->block_align);
+
+ if (extradata + data_len > this->size)
+ break; /* abort early - extradata length is bad */
+
+ this->context->extradata_size = data_len;
+ this->context->extradata = xine_xmalloc(this->context->extradata_size +
+ FF_INPUT_BUFFER_PADDING_SIZE);
+ xine_fast_memcpy (this->context->extradata, this->buf + extradata,
+ this->context->extradata_size);
+ break;
+ }
default:
xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
"ffmpeg_audio_dec: unknown header with buf type 0x%X\n", codec_type);
@@ -227,6 +270,7 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf)
this->context->sample_rate = this->audio_sample_rate;
this->context->channels = this->audio_channels;
this->context->codec_id = this->codec->id;
+ this->context->codec_type = this->codec->type;
this->context->codec_tag = _x_stream_info_get(this->stream, XINE_STREAM_INFO_AUDIO_FOURCC);
this->size = 0;
@@ -266,7 +310,26 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf)
this->decoder_ok = 1;
}
+ if( buf->decoder_flags & BUF_FLAG_PREVIEW )
+ return;
+
+ ff_audio_ensure_buffer_size(this, this->size + buf->size);
+ xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size);
+ this->size += buf->size;
+
if (!this->output_open) {
+ if (!this->audio_bits || !this->audio_sample_rate || !this->audio_channels) {
+ avcodec_decode_audio (this->context,
+ (int16_t *)this->decode_buffer,
+ &decode_buffer_size,
+ &this->buf[0],
+ this->size);
+ this->audio_bits = this->context->bits_per_sample;
+ this->audio_sample_rate = this->context->sample_rate;
+ this->audio_channels = this->context->channels;
+ if (!this->audio_bits || !this->audio_sample_rate || !this->audio_channels)
+ return;
+ }
this->output_open = (this->stream->audio_out->open) (this->stream->audio_out,
this->stream, this->audio_bits, this->audio_sample_rate,
_x_ao_channels2mode(this->audio_channels));
@@ -276,13 +339,6 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf)
if (!this->output_open)
return;
- if( buf->decoder_flags & BUF_FLAG_PREVIEW )
- return;
-
- ff_audio_ensure_buffer_size(this, this->size + buf->size);
- xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size);
- this->size += buf->size;
-
if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* time to decode a frame */
offset = 0;
@@ -323,7 +379,7 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf)
/* fill up this buffer */
xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[out],
- bytes_to_send);
+ bytes_to_send);
/* byte count / 2 (bytes / sample) / channels */
audio_buffer->num_frames = bytes_to_send / 2 / this->audio_channels;
@@ -354,7 +410,8 @@ static void ff_audio_reset (audio_decoder_t *this_gen) {
if( this->context && this->decoder_ok ) {
pthread_mutex_lock (&ffmpeg_lock);
avcodec_close (this->context);
- avcodec_open (this->context, this->codec);
+ if (avcodec_open (this->context, this->codec) < 0)
+ this->decoder_ok = 0;
pthread_mutex_unlock (&ffmpeg_lock);
}
}
@@ -468,5 +525,5 @@ static const uint32_t supported_audio_types[] = {
decoder_info_t dec_info_ffmpeg_audio = {
supported_audio_types, /* supported types */
- 6 /* priority */
+ 7 /* priority */
};