diff options
-rw-r--r-- | src/demuxers/demux_qt.c | 16 | ||||
-rw-r--r-- | src/libfaad/xine_decoder.c | 52 | ||||
-rw-r--r-- | src/xine-engine/buffer.h | 10 |
3 files changed, 66 insertions, 12 deletions
diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 0becc401c..ba6aaba4a 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -30,7 +30,7 @@ * build_frame_table * free_qt_info * - * $Id: demux_qt.c,v 1.69 2002/07/17 18:49:49 miguelfreitas Exp $ + * $Id: demux_qt.c,v 1.70 2002/07/17 20:29:03 miguelfreitas Exp $ * */ @@ -228,6 +228,7 @@ typedef struct { unsigned int audio_bits; void *audio_decoder_config; int audio_decoder_config_len; + unsigned int *audio_sample_size_table; qt_atom video_codec; unsigned int video_type; @@ -401,6 +402,7 @@ static qt_error parse_trak_atom(qt_sample_table *sample_table, sample_table->sample_to_chunk_table = NULL; sample_table->time_to_sample_table = NULL; sample_table->decoder_config = NULL; + sample_table->sample_size_table = NULL; /* default type */ sample_table->type = MEDIA_OTHER; @@ -903,6 +905,8 @@ static void parse_moov_atom(qt_info *info, unsigned char *moov_atom) { info->audio_decoder_config = sample_tables[i].decoder_config; info->audio_decoder_config_len = sample_tables[i].decoder_config_len; + + info->audio_sample_size_table = sample_tables[i].sample_size_table; } } @@ -1254,9 +1258,17 @@ static void *demux_qt_loop (void *this_gen) { break; } - if (!remaining_sample_bytes) + if (!remaining_sample_bytes) { buf->decoder_flags |= BUF_FLAG_FRAME_END; + if( this->qt->audio_sample_size_table ) { + buf->decoder_flags |= BUF_FLAG_SPECIAL; + buf->decoder_info[1] = BUF_SPECIAL_SAMPLE_SIZE_TABLE; + buf->decoder_info[3] = (uint32_t) + &this->qt->audio_sample_size_table[this->qt->frames[i].official_byte_count]; + } + } + this->audio_fifo->put(this->audio_fifo, buf); } } diff --git a/src/libfaad/xine_decoder.c b/src/libfaad/xine_decoder.c index 3000c128a..1c73b470e 100644 --- a/src/libfaad/xine_decoder.c +++ b/src/libfaad/xine_decoder.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xine_decoder.c,v 1.4 2002/07/17 15:21:46 miguelfreitas Exp $ + * $Id: xine_decoder.c,v 1.5 2002/07/17 20:29:04 miguelfreitas Exp $ * */ @@ -33,7 +33,7 @@ #include "xineutils.h" #include "faad.h" -#define LOG +/* #define LOG */ typedef struct faad_decoder_s { audio_decoder_t audio_decoder; @@ -119,13 +119,24 @@ static int faad_open_dec( faad_decoder_t *this ) { static void faad_decode_audio ( faad_decoder_t *this, int end_frame ) { int used, decoded, outsize; uint8_t *sample_buffer; + uint8_t *inbuf; audio_buffer_t *audio_buffer; - while( this->faac_dec && this->size >= this->rec_audio_src_size) { + if( !this->faac_dec ) + return; + + inbuf = this->buf; + while( (this->mp4_mode && end_frame && this->size >= 10) || + (!this->mp4_mode && this->size >= this->rec_audio_src_size) ) { sample_buffer = faacDecDecode(this->faac_dec, - &this->faac_finfo, this->buf); - used = this->faac_finfo.bytesconsumed; + &this->faac_finfo, inbuf); + + if( this->mp4_mode && this->sample_size_table ) + used = *this->sample_size_table++; + else + used = this->faac_finfo.bytesconsumed; + decoded = this->faac_finfo.samples * 2; /* 1 sample = 2 bytes */ #ifdef LOG @@ -149,7 +160,7 @@ static void faad_decode_audio ( faad_decoder_t *this, int end_frame ) { xine_fast_memcpy( audio_buffer->mem, sample_buffer, outsize ); audio_buffer->num_frames = outsize / (this->num_channels*2); - audio_buffer->vpts = this->pts; + audio_buffer->vpts = this->pts; this->audio_out->put_buffer (this->audio_out, audio_buffer); @@ -163,9 +174,16 @@ static void faad_decode_audio ( faad_decoder_t *this, int end_frame ) { this->size = 0; } else { this->size -= used; - memmove( this->buf, &this->buf[used], this->size); + inbuf += used; } - } + } + + if( this->mp4_mode && this->sample_size_table ) + this->size = 0; + else if( this->size ) + memmove( this->buf, inbuf, this->size); + + this->sample_size_table = NULL; } static void faad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { @@ -176,6 +194,8 @@ static void faad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { if (buf->decoder_flags & BUF_FLAG_PREVIEW) return; + + /* initialize libfaad with with config information from ESDS mp4/qt atom */ if( !this->faac_dec && (buf->decoder_flags & BUF_FLAG_SPECIAL) && buf->decoder_info[1] == BUF_SPECIAL_DECODER_CONFIG ) { @@ -203,7 +223,20 @@ static void faad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { this->rate, this->num_channels ); #endif } - + + /* get sample sizes table. this is needed since sample size + might differ from faac_finfo.bytesconsumed */ + if( (buf->decoder_flags & BUF_FLAG_SPECIAL) && + buf->decoder_info[1] == BUF_SPECIAL_SAMPLE_SIZE_TABLE ) { +#ifdef LOG + printf("libfaad: sample_size_table received\n"); +#endif + this->sample_size_table = (unsigned int *)buf->decoder_info[3]; + } + + + /* get audio parameters from file header + (may be overwritten by libfaad returned parameters) */ if (buf->decoder_flags & BUF_FLAG_HEADER) { this->rate=buf->decoder_info[1]; @@ -269,6 +302,7 @@ static void faad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { } else { + /* open audio device as needed */ if (!this->output_open) { switch( this->num_channels ) { case 1: diff --git a/src/xine-engine/buffer.h b/src/xine-engine/buffer.h index 465aaf4fb..622af913a 100644 --- a/src/xine-engine/buffer.h +++ b/src/xine-engine/buffer.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: buffer.h,v 1.59 2002/07/15 02:15:38 miguelfreitas Exp $ + * $Id: buffer.h,v 1.60 2002/07/17 20:29:04 miguelfreitas Exp $ * * * contents: @@ -251,6 +251,14 @@ struct buf_element_s { */ #define BUF_SPECIAL_DECODER_CONFIG 4 +/* + * In a BUF_SPECIAL_SAMPLE_SIZE_TABLE buffer: + * decoder_info[1] = BUF_SPECIAL_SAMPLE_SIZE_TABLE + * decoder_info[2] = + * decoder_info[3] = pointer to table with sample sizes (within current frame) + */ +#define BUF_SPECIAL_SAMPLE_SIZE_TABLE 5 + typedef struct palette_entry_s palette_entry_t; struct palette_entry_s |