From c0c516e97e06d5d39805469d0eb8f80021ec32da Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Fri, 16 Sep 2011 13:22:57 +0300 Subject: Simplify: check for BUF_FLAG_SPECIAL only once. Splitted special buffer handling to separate function. --- src/combined/ffmpeg/ff_audio_decoder.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'src/combined/ffmpeg') diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index 7fd5af865..f554a8b8f 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -109,7 +109,7 @@ static void *realloc16 (void *m, size_t s) { } - static void ff_audio_ensure_buffer_size(ff_audio_decoder_t *this, int size) { +static void ff_audio_ensure_buffer_size(ff_audio_decoder_t *this, int size) { if (size > this->bufsize) { this->bufsize = size + size / 2; xprintf(this->stream->xine, XINE_VERBOSITY_LOG, @@ -119,6 +119,18 @@ static void *realloc16 (void *m, size_t s) { } } +static void ff_audio_handle_special_buffer(ff_audio_decoder_t *this, buf_element_t *buf) { + + if (buf->decoder_info[1] == BUF_SPECIAL_STSD_ATOM) { + + this->context->extradata_size = buf->decoder_info[2]; + this->context->extradata = malloc(buf->decoder_info[2] + + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(this->context->extradata, buf->decoder_info_ptr[2], + buf->decoder_info[2]); + } +} + static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen; @@ -130,7 +142,12 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) int bytes_to_send; unsigned int codec_type = buf->type & (BUF_MAJOR_MASK | BUF_DECODER_MASK); - if ( (buf->decoder_flags & (BUF_FLAG_HEADER | BUF_FLAG_SPECIAL)) == BUF_FLAG_HEADER ) { + if (buf->decoder_flags & BUF_FLAG_SPECIAL) { + ff_audio_handle_special_buffer(this, buf); + return; + } + + if (buf->decoder_flags & BUF_FLAG_HEADER) { /* accumulate init data */ ff_audio_ensure_buffer_size(this, this->size + buf->size); @@ -275,19 +292,10 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) this->size = 0; this->decode_buffer = malloc16 (AVCODEC_MAX_AUDIO_FRAME_SIZE); - - return; } - } else if ((buf->decoder_flags & BUF_FLAG_SPECIAL) && - (buf->decoder_info[1] == BUF_SPECIAL_STSD_ATOM)) { - this->context->extradata_size = buf->decoder_info[2]; - this->context->extradata = malloc(buf->decoder_info[2] + - FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(this->context->extradata, buf->decoder_info_ptr[2], - buf->decoder_info[2]); + } else { - } else if (!(buf->decoder_flags & BUF_FLAG_SPECIAL)) { #if AVAUDIO > 2 AVPacket avpkt; #endif -- cgit v1.2.3 From 94854aaccd747984e7b6a8414fd253eb23573b8b Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Fri, 16 Sep 2011 13:24:08 +0300 Subject: Fixed "warning: cast from pointer to integer of different size" --- src/combined/ffmpeg/ff_audio_decoder.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/combined/ffmpeg') diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index f554a8b8f..269342ddb 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -85,7 +85,7 @@ typedef struct ff_audio_decoder_s { #define free16(p) realloc16(p,0) static void *realloc16 (void *m, size_t s) { - unsigned int diff, diff2; + unsigned long diff, diff2; unsigned char *p = m, *q; if (p) { diff = p[-1]; @@ -95,13 +95,13 @@ static void *realloc16 (void *m, size_t s) { } q = realloc (p - diff, s + 16); if (!q) return (q); - diff2 = 16 - ((unsigned int)q & 15); + diff2 = 16 - ((unsigned long)q & 15); if (diff2 != diff) memmove (q + diff2, q + diff, s); } else { if (s == 0) return (NULL); q = malloc (s + 16); if (!q) return (q); - diff2 = 16 - ((unsigned int)q & 15); + diff2 = 16 - ((unsigned long)q & 15); } q += diff2; q[-1] = diff2; -- cgit v1.2.3 From 33045f759f0cb124cb8eb15ac317d5340644481e Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Thu, 15 Sep 2011 15:07:02 +0300 Subject: ffmpeg audio: make sure context is allocated only once imported patch 10115.diff --- src/combined/ffmpeg/ff_audio_decoder.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/combined/ffmpeg') diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index 269342ddb..34ccadeee 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -178,8 +178,6 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) return; } - this->context = avcodec_alloc_context(); - if(buf->decoder_flags & BUF_FLAG_STDHEADER) { this->audio_sample_rate = buf->decoder_info[1]; this->audio_channels = buf->decoder_info[3]; @@ -536,6 +534,8 @@ static audio_decoder_t *ff_audio_open_plugin (audio_decoder_class_t *class_gen, ff_audio_ensure_buffer_size(this, AUDIOBUFSIZE); + this->context = avcodec_alloc_context(); + return &this->audio_decoder; } -- cgit v1.2.3 From 97cec62e0abfacdd0f89f211583f018f59a74c69 Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Thu, 15 Sep 2011 15:10:15 +0300 Subject: ffmpeg audio: removed checks that are always true (context is allocated in init) imported patch 10116.diff --- src/combined/ffmpeg/ff_audio_decoder.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/combined/ffmpeg') diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index 34ccadeee..754de45be 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -299,7 +299,7 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) #endif if( !this->decoder_ok ) { - if ( ! this->context || ! this->codec ) { + if ( !this->codec ) { xprintf (this->stream->xine, XINE_VERBOSITY_LOG, _("ffmpeg_audio_dec: trying to open null codec\n")); _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); @@ -475,7 +475,7 @@ static void ff_audio_reset (audio_decoder_t *this_gen) { this->size = 0; /* try to reset the wma decoder */ - if( this->context && this->decoder_ok ) { + if( this->decoder_ok ) { pthread_mutex_lock (&ffmpeg_lock); avcodec_close (this->context); if (avcodec_open (this->context, this->codec) < 0) -- cgit v1.2.3 From a2cc9a19b5e8193426c6626a1544a623f0da7a73 Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Tue, 27 Sep 2011 11:43:44 +0300 Subject: ffmpeg audio: make sure decode_buffer is allocated only once imported patch 10119.diff --- src/combined/ffmpeg/ff_audio_decoder.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/combined/ffmpeg') diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index 754de45be..ec4d01ccd 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -288,8 +288,6 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) this->context->codec_tag = _x_stream_info_get(this->stream, XINE_STREAM_INFO_AUDIO_FOURCC); this->size = 0; - - this->decode_buffer = malloc16 (AVCODEC_MAX_AUDIO_FRAME_SIZE); } } else { @@ -535,6 +533,7 @@ static audio_decoder_t *ff_audio_open_plugin (audio_decoder_class_t *class_gen, ff_audio_ensure_buffer_size(this, AUDIOBUFSIZE); this->context = avcodec_alloc_context(); + this->decode_buffer = malloc16 (AVCODEC_MAX_AUDIO_FRAME_SIZE); return &this->audio_decoder; } -- cgit v1.2.3 From 0b0e25c1c44d1a33d07a41292ad6c341eccce278 Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Tue, 27 Sep 2011 12:01:49 +0300 Subject: Splitted ff_audio_handle_header_buffer() from ff_audio_decode_data() imported patch 10120.diff --- src/combined/ffmpeg/ff_audio_decoder.c | 288 +++++++++++++++++---------------- 1 file changed, 148 insertions(+), 140 deletions(-) (limited to 'src/combined/ffmpeg') diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index ec4d01ccd..5944e714a 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -131,164 +131,172 @@ static void ff_audio_handle_special_buffer(ff_audio_decoder_t *this, buf_element } } -static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - - ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen; - int bytes_consumed; - int decode_buffer_size; - int offset; - int out; - audio_buffer_t *audio_buffer; - int bytes_to_send; +static void ff_handle_header_buffer(ff_audio_decoder_t *this, buf_element_t *buf) +{ unsigned int codec_type = buf->type & (BUF_MAJOR_MASK | BUF_DECODER_MASK); + size_t i; + xine_waveformatex *audio_header; - if (buf->decoder_flags & BUF_FLAG_SPECIAL) { - ff_audio_handle_special_buffer(this, buf); + /* accumulate init data */ + 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)) { return; } - if (buf->decoder_flags & BUF_FLAG_HEADER) { + this->codec = NULL; - /* accumulate init data */ - 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; + for(i = 0; i < sizeof(ff_audio_lookup)/sizeof(ff_codec_t); i++) + if(ff_audio_lookup[i].type == codec_type) { + pthread_mutex_lock (&ffmpeg_lock); + this->codec = avcodec_find_decoder(ff_audio_lookup[i].id); + pthread_mutex_unlock (&ffmpeg_lock); + _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, + ff_audio_lookup[i].name); + break; + } - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - size_t i; - xine_waveformatex *audio_header; + if (!this->codec) { + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"), + codec_type); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); + return; + } - this->codec = NULL; + if(buf->decoder_flags & BUF_FLAG_STDHEADER) { + this->audio_sample_rate = buf->decoder_info[1]; + this->audio_channels = buf->decoder_info[3]; - for(i = 0; i < sizeof(ff_audio_lookup)/sizeof(ff_codec_t); i++) - if(ff_audio_lookup[i].type == codec_type) { - pthread_mutex_lock (&ffmpeg_lock); - this->codec = avcodec_find_decoder(ff_audio_lookup[i].id); - pthread_mutex_unlock (&ffmpeg_lock); - _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, - ff_audio_lookup[i].name); - break; - } + if(this->size) { + audio_header = (xine_waveformatex *)this->buf; - if (!this->codec) { - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"), - codec_type); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); - return; + this->context->block_align = audio_header->nBlockAlign; + this->context->bit_rate = audio_header->nAvgBytesPerSec * 8; + + if(audio_header->cbSize > 0) { + this->context->extradata = malloc(audio_header->cbSize); + this->context->extradata_size = audio_header->cbSize; + memcpy( this->context->extradata, + (uint8_t *)audio_header + sizeof(xine_waveformatex), + audio_header->cbSize ); + } + } + } else { + short *ptr; + + switch(codec_type) { + case BUF_AUDIO_14_4: + this->audio_sample_rate = 8000; + this->audio_channels = 1; + + this->context->block_align = 240; + break; + case BUF_AUDIO_28_8: + this->audio_sample_rate = _X_BE_16(&this->buf[0x30]); + this->audio_channels = this->buf[0x37]; + /* this->audio_bits = buf->content[0x35] */ + + this->context->block_align = _X_BE_32(&this->buf[0x18]); + + this->context->extradata_size = 5*sizeof(short); + this->context->extradata = malloc(this->context->extradata_size); + + ptr = (short *) this->context->extradata; + + ptr[0] = _X_BE_16(&this->buf[0x2C]); /* subpacket size */ + ptr[1] = _X_BE_16(&this->buf[0x28]); /* subpacket height */ + 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 */ + if (extradata > INT_MAX - data_len) + break;/*integer overflow*/ + + this->context->extradata_size = data_len; + this->context->extradata = malloc(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); + break; + } + } - if(buf->decoder_flags & BUF_FLAG_STDHEADER) { - this->audio_sample_rate = buf->decoder_info[1]; - this->audio_channels = buf->decoder_info[3]; + /* Current ffmpeg audio decoders usually use 16 bits/sample + * buf->decoder_info[2] can't be used as it doesn't refer to the output + * bits/sample for some codecs (e.g. MS ADPCM) */ + this->audio_bits = 16; - if(this->size) { - audio_header = (xine_waveformatex *)this->buf; + this->context->bits_per_sample = this->audio_bits; + 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->context->block_align = audio_header->nBlockAlign; - this->context->bit_rate = audio_header->nAvgBytesPerSec * 8; + this->size = 0; +} - if(audio_header->cbSize > 0) { - this->context->extradata = malloc(audio_header->cbSize); - this->context->extradata_size = audio_header->cbSize; - memcpy( this->context->extradata, - (uint8_t *)audio_header + sizeof(xine_waveformatex), - audio_header->cbSize ); - } - } - } else { - short *ptr; - - switch(codec_type) { - case BUF_AUDIO_14_4: - this->audio_sample_rate = 8000; - this->audio_channels = 1; - - this->context->block_align = 240; - break; - case BUF_AUDIO_28_8: - this->audio_sample_rate = _X_BE_16(&this->buf[0x30]); - this->audio_channels = this->buf[0x37]; - /* this->audio_bits = buf->content[0x35] */ - - this->context->block_align = _X_BE_32(&this->buf[0x18]); - - this->context->extradata_size = 5*sizeof(short); - this->context->extradata = malloc(this->context->extradata_size); - - ptr = (short *) this->context->extradata; - - ptr[0] = _X_BE_16(&this->buf[0x2C]); /* subpacket size */ - ptr[1] = _X_BE_16(&this->buf[0x28]); /* subpacket height */ - 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 */ - if (extradata > INT_MAX - data_len) - break;/*integer overflow*/ - - this->context->extradata_size = data_len; - this->context->extradata = malloc(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); - break; - } - } +static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - /* Current ffmpeg audio decoders usually use 16 bits/sample - * buf->decoder_info[2] can't be used as it doesn't refer to the output - * bits/sample for some codecs (e.g. MS ADPCM) */ - this->audio_bits = 16; + ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen; + int bytes_consumed; + int decode_buffer_size; + int offset; + int out; + audio_buffer_t *audio_buffer; + int bytes_to_send; + unsigned int codec_type = buf->type & (BUF_MAJOR_MASK | BUF_DECODER_MASK); - this->context->bits_per_sample = this->audio_bits; - 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); + if (buf->decoder_flags & BUF_FLAG_SPECIAL) { + ff_audio_handle_special_buffer(this, buf); + return; + } - this->size = 0; - } + if (buf->decoder_flags & BUF_FLAG_HEADER) { + ff_handle_header_buffer(this, buf); + return; } else { -- cgit v1.2.3 From a33c720b1ac8e11aaa353d940edb052efb35b561 Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Tue, 27 Sep 2011 12:08:22 +0300 Subject: Splitted ff_audio_init_codec() from ff_audio_handle_header_buffer() imported patch 10121.diff --- src/combined/ffmpeg/ff_audio_decoder.c | 53 +++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'src/combined/ffmpeg') diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index 5944e714a..19cf50648 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -131,20 +131,8 @@ static void ff_audio_handle_special_buffer(ff_audio_decoder_t *this, buf_element } } -static void ff_handle_header_buffer(ff_audio_decoder_t *this, buf_element_t *buf) -{ - unsigned int codec_type = buf->type & (BUF_MAJOR_MASK | BUF_DECODER_MASK); +static void ff_audio_init_codec(ff_audio_decoder_t *this, unsigned int codec_type) { size_t i; - xine_waveformatex *audio_header; - - /* accumulate init data */ - 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)) { - return; - } this->codec = NULL; @@ -166,6 +154,33 @@ static void ff_handle_header_buffer(ff_audio_decoder_t *this, buf_element_t *buf return; } + /* Current ffmpeg audio decoders usually use 16 bits/sample + * buf->decoder_info[2] can't be used as it doesn't refer to the output + * bits/sample for some codecs (e.g. MS ADPCM) */ + this->audio_bits = 16; + + this->context->bits_per_sample = this->audio_bits; + 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); +} + +static void ff_handle_header_buffer(ff_audio_decoder_t *this, buf_element_t *buf) +{ + unsigned int codec_type = buf->type & (BUF_MAJOR_MASK | BUF_DECODER_MASK); + xine_waveformatex *audio_header; + + /* accumulate init data */ + 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)) { + return; + } + if(buf->decoder_flags & BUF_FLAG_STDHEADER) { this->audio_sample_rate = buf->decoder_info[1]; this->audio_channels = buf->decoder_info[3]; @@ -263,17 +278,7 @@ static void ff_handle_header_buffer(ff_audio_decoder_t *this, buf_element_t *buf } } - /* Current ffmpeg audio decoders usually use 16 bits/sample - * buf->decoder_info[2] can't be used as it doesn't refer to the output - * bits/sample for some codecs (e.g. MS ADPCM) */ - this->audio_bits = 16; - - this->context->bits_per_sample = this->audio_bits; - 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); + ff_audio_init_codec(this, codec_type); this->size = 0; } -- cgit v1.2.3 From e6ed5771c5caf6a714f3fa7fa47cec2b55f3fd33 Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Tue, 27 Sep 2011 14:59:30 +0300 Subject: Splitted ff_audio_open_codec() from ff_audio_decode_data() imported patch 10123.diff --- src/combined/ffmpeg/ff_audio_decoder.c | 40 +++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'src/combined/ffmpeg') diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index 19cf50648..0bd947d42 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -167,6 +167,30 @@ static void ff_audio_init_codec(ff_audio_decoder_t *this, unsigned int codec_typ this->context->codec_tag = _x_stream_info_get(this->stream, XINE_STREAM_INFO_AUDIO_FOURCC); } +static int ff_audio_open_codec(ff_audio_decoder_t *this, unsigned int codec_type) { + + if ( !this->codec ) { + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_audio_dec: trying to open null codec\n")); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); + return -1; + } + + pthread_mutex_lock (&ffmpeg_lock); + if (avcodec_open (this->context, this->codec) < 0) { + pthread_mutex_unlock (&ffmpeg_lock); + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_audio_dec: couldn't open decoder\n")); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); + return -1; + } + pthread_mutex_unlock (&ffmpeg_lock); + + this->decoder_ok = 1; + + return 1; +} + static void ff_handle_header_buffer(ff_audio_decoder_t *this, buf_element_t *buf) { unsigned int codec_type = buf->type & (BUF_MAJOR_MASK | BUF_DECODER_MASK); @@ -310,23 +334,9 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) #endif if( !this->decoder_ok ) { - if ( !this->codec ) { - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_audio_dec: trying to open null codec\n")); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); + if (ff_audio_open_codec(this, codec_type) < 0) { return; } - - pthread_mutex_lock (&ffmpeg_lock); - if (avcodec_open (this->context, this->codec) < 0) { - pthread_mutex_unlock (&ffmpeg_lock); - xprintf (this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_audio_dec: couldn't open decoder\n")); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); - return; - } - pthread_mutex_unlock (&ffmpeg_lock); - this->decoder_ok = 1; } if( buf->decoder_flags & BUF_FLAG_PREVIEW ) -- cgit v1.2.3 From 2ae5c07dc74b7771557de4c171d610e9d137da60 Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Tue, 27 Sep 2011 15:02:50 +0300 Subject: ff_audio_open_codec(): initialize codec if it hasn't been initialized. This makes HEADERS optional for codecs that don't require extradata. imported patch 10124.diff --- src/combined/ffmpeg/ff_audio_decoder.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/combined/ffmpeg') diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index 0bd947d42..31287fd3d 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -169,6 +169,10 @@ static void ff_audio_init_codec(ff_audio_decoder_t *this, unsigned int codec_typ static int ff_audio_open_codec(ff_audio_decoder_t *this, unsigned int codec_type) { + if ( !this->codec ) { + ff_audio_init_codec(this, codec_type); + } + if ( !this->codec ) { xprintf (this->stream->xine, XINE_VERBOSITY_LOG, _("ffmpeg_audio_dec: trying to open null codec\n")); -- cgit v1.2.3 From 33cf5de308a841526b2d6f11e83ab590acbc3539 Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Tue, 27 Sep 2011 14:28:12 +0300 Subject: Fixed mpeg2 decoding with ffmpeg. Codec was never opened when using mpeg12 mode. --- src/combined/ffmpeg/ff_video_decoder.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'src/combined/ffmpeg') diff --git a/src/combined/ffmpeg/ff_video_decoder.c b/src/combined/ffmpeg/ff_video_decoder.c index f9822723c..a1d729df4 100644 --- a/src/combined/ffmpeg/ff_video_decoder.c +++ b/src/combined/ffmpeg/ff_video_decoder.c @@ -521,17 +521,6 @@ static void init_postprocess (ff_video_decoder_t *this) { static int ff_handle_mpeg_sequence(ff_video_decoder_t *this, mpeg_parser_t *parser) { - /* - * init codec - */ - if (this->decoder_init_mode) { - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, - "mpeg-1 (ffmpeg)"); - - init_video_codec (this, BUF_VIDEO_MPEG); - this->decoder_init_mode = 0; - } - /* frame format change */ if ((parser->width != this->bih.biWidth) || (parser->height != this->bih.biHeight) || @@ -908,10 +897,18 @@ static int ff_check_extradata(ff_video_decoder_t *this, unsigned int codec_type, static void ff_init_mpeg12_mode(ff_video_decoder_t *this) { this->is_mpeg12 = 1; + + if (this->decoder_init_mode) { + _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, + "mpeg-1 (ffmpeg)"); + + init_video_codec (this, BUF_VIDEO_MPEG); + this->decoder_init_mode = 0; + } + if ( this->mpeg_parser == NULL ) { this->mpeg_parser = calloc(1, sizeof(mpeg_parser_t)); mpeg_parser_init(this->mpeg_parser); - this->decoder_init_mode = 0; } } -- cgit v1.2.3