From 0591a1d3fec932940bd7d1bf46b792acf7eea702 Mon Sep 17 00:00:00 2001 From: Gildas Bazin Date: Sat, 10 Dec 2005 11:15:19 +0000 Subject: [PATCH] * modules/demux/real.c: improved cook support. We now try to send audio subpackets as soon as they are available instead of waiting for the full re-ordering to be finished. Added some sanity checks as well and gave a try to 28_8 support (not tested). --- modules/demux/real.c | 86 ++++++++++++++++++++++++++++++++------------ 1 file changed, 64 insertions(+), 22 deletions(-) diff --git a/modules/demux/real.c b/modules/demux/real.c index 5433111321..fd02983825 100644 --- a/modules/demux/real.c +++ b/modules/demux/real.c @@ -67,6 +67,7 @@ typedef struct int i_subpacket; int i_subpackets; block_t **p_subpackets; + int i_out_subpacket; } real_track_t; @@ -180,10 +181,8 @@ static int Demux( demux_t *p_demux ) { demux_sys_t *p_sys = p_demux->p_sys; uint8_t header[18]; - int i_size; - int i_id; + int i_size, i_id, i_flags, i; int64_t i_pts; - int i; real_track_t *tk = NULL; vlc_bool_t b_selected; @@ -215,8 +214,7 @@ static int Demux( demux_t *p_demux ) i_id = GetWBE( &header[4] ); i_pts = 1000 * GetDWBE( &header[6] ); i_pts += 1000; /* Avoid 0 pts */ - - /* header[11] -> flags 0x02 -> keyframe */ + i_flags= header[11]; /* flags 0x02 -> keyframe */ #if 0 msg_Dbg( p_demux, "packet %d size=%d id=%d pts=%u", @@ -490,36 +488,69 @@ static int Demux( demux_t *p_demux ) } } } - else if( tk->fmt.i_codec == VLC_FOURCC( 'c', 'o', 'o', 'k' ) ) + else if( tk->fmt.i_codec == VLC_FOURCC( 'c', 'o', 'o', 'k' ) || + tk->fmt.i_codec == VLC_FOURCC('2','8','_','8') ) { uint8_t *p_buf = p_sys->buffer; - int h = tk->i_subpacket_h; int y = tk->i_subpacket / (tk->i_frame_size /tk->i_subpacket_size); - int i; + int i_index, i; + /* Sanity check */ + if( i_flags & 2 ) y = tk->i_subpacket = 0; + if( tk->fmt.i_codec == VLC_FOURCC( 'c', 'o', 'o', 'k' ) ) for( i = 0; i < tk->i_frame_size / tk->i_subpacket_size; i++ ) { block_t *p_block = block_New( p_demux, tk->i_subpacket_size ); memcpy( p_block->p_buffer, p_buf, tk->i_subpacket_size ); p_buf += tk->i_subpacket_size; + i_index = tk->i_subpacket_h * i + + ((tk->i_subpacket_h + 1) / 2) * (y&1) + (y>>1); + p_block->i_dts = p_block->i_pts = i_pts; - tk->p_subpackets[(h*i+((h+1)/2)*(y&1)+(y>>1))] = p_block; + tk->p_subpackets[i_index] = p_block; tk->i_subpacket++; } - if( tk->i_subpacket == tk->i_subpackets ) + if( tk->fmt.i_codec == VLC_FOURCC('2','8','_','8') ) + for( i = 0; i < tk->i_subpacket_h / 2; i++ ) { - for( i = 0; i < tk->i_subpackets; i++ ) - { - block_t *p_block = tk->p_subpackets[i]; - tk->p_subpackets[i] = 0; + block_t *p_block = block_New( p_demux, tk->i_coded_frame_size); + memcpy( p_block->p_buffer, p_buf, tk->i_coded_frame_size ); + p_buf += tk->i_coded_frame_size; - if( i ) p_block->i_dts = p_block->i_pts = 0; - es_out_Send( p_demux->out, tk->p_es, p_block ); - } + i_index = (i * 2 * tk->i_frame_size) / + tk->i_coded_frame_size + y; + + p_block->i_dts = p_block->i_pts = i_pts; + tk->p_subpackets[i_index] = p_block; + tk->i_subpacket++; + } + + while( tk->i_out_subpacket != tk->i_subpackets && + tk->p_subpackets[tk->i_out_subpacket] ) + { + block_t *p_block = tk->p_subpackets[tk->i_out_subpacket]; + tk->p_subpackets[tk->i_out_subpacket] = 0; + + if( tk->i_out_subpacket ) p_block->i_dts = p_block->i_pts = 0; + es_out_Send( p_demux->out, tk->p_es, p_block ); + + tk->i_out_subpacket++; + } + + if( tk->i_subpacket == tk->i_subpackets && + tk->i_out_subpacket != tk->i_subpackets ) + { + msg_Warn( p_demux, "i_subpacket != i_out_subpacket, " + "this shouldn't happen" ); + } + + if( tk->i_subpacket == tk->i_subpackets ) + { tk->i_subpacket = 0; + tk->i_out_subpacket = 0; } } else @@ -965,6 +996,10 @@ static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num ) memcpy( fmt.p_extra, p_peek + 4, fmt.i_extra ); break; + case VLC_FOURCC('2','8','_','8'): + fmt.audio.i_blockalign = i_coded_frame_size; + break; + default: msg_Dbg( p_demux, " - unknown audio codec=%4.4s", (char*)&fmt.i_codec ); @@ -973,6 +1008,8 @@ static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num ) if( fmt.i_codec != 0 ) { + int i; + msg_Dbg( p_demux, " - extra data=%d", fmt.i_extra ); tk = malloc( sizeof( real_track_t ) ); @@ -986,21 +1023,26 @@ static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num ) tk->i_coded_frame_size = i_coded_frame_size; tk->i_frame_size = i_frame_size; + tk->i_out_subpacket = 0; tk->i_subpacket = 0; tk->i_subpackets = 0; tk->p_subpackets = NULL; if( fmt.i_codec == VLC_FOURCC('c','o','o','k') ) { - int i; - tk->i_subpackets = i_subpacket_h * i_frame_size / tk->i_subpacket_size; tk->p_subpackets = malloc( tk->i_subpackets * sizeof(block_t *) ); - - for( i = 0; i < tk->i_subpackets; i++ ) - tk->p_subpackets[i] = NULL; } + else if( fmt.i_codec == VLC_FOURCC('2','8','_','8') ) + { + tk->i_subpackets = + i_subpacket_h * i_frame_size / tk->i_coded_frame_size; + tk->p_subpackets = + malloc( tk->i_subpackets * sizeof(block_t *) ); + } + + for( i = 0; i < tk->i_subpackets; i++ ) tk->p_subpackets[i] = NULL; tk->p_es = es_out_Add( p_demux->out, &fmt ); -- 2.39.2