* input_ext-dec.h: structures exported to the VideoLAN decoders
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
- * $Id: input_ext-dec.h,v 1.12 2001/01/12 11:36:49 massiot Exp $
+ * $Id: input_ext-dec.h,v 1.13 2001/01/12 17:33:18 massiot Exp $
*
* Authors:
*
*/
/*****************************************************************************
- * GetByte : reads the next byte in the input stream
+ * GetByte : reads the next byte in the input stream (PRIVATE)
*****************************************************************************/
-static __inline__ byte_t GetByte( bit_stream_t * p_bit_stream )
+static __inline__ byte_t _GetByte( bit_stream_t * p_bit_stream )
{
/* Are there some bytes left in the current data packet ? */
/* could change this test to have a if (! (bytes--)) instead */
{
while ( p_bit_stream->fifo.i_available < i_bits )
{
- p_bit_stream->fifo.buffer |= ((WORD_TYPE)GetByte( p_bit_stream ))
+ p_bit_stream->fifo.buffer |= ((WORD_TYPE)_GetByte( p_bit_stream ))
<< (sizeof(WORD_TYPE) - 8
- p_bit_stream->fifo.i_available);
p_bit_stream->fifo.i_available += 8;
/*****************************************************************************
* ShowBits : return i_bits bits from the bit stream
*****************************************************************************/
-static __inline__ WORD_TYPE ShowWord( bit_stream_t * p_bit_stream )
+static __inline__ WORD_TYPE _ShowWord( bit_stream_t * p_bit_stream )
{
if( p_bit_stream->p_byte <= p_bit_stream->p_end - sizeof(WORD_TYPE) )
{
}
return( (p_bit_stream->fifo.buffer |
- (ShowWord( p_bit_stream ) >> p_bit_stream->fifo.i_available))
+ (_ShowWord( p_bit_stream ) >> p_bit_stream->fifo.i_available))
>> (8 * sizeof(WORD_TYPE) - i_bits) );
}
/*****************************************************************************
- * GetWord : returns the next word to be read
+ * GetWord : returns the next word to be read (PRIVATE)
*****************************************************************************/
-static __inline__ WORD_TYPE GetWord( bit_stream_t * p_bit_stream )
+static __inline__ WORD_TYPE _GetWord( bit_stream_t * p_bit_stream )
{
if( p_bit_stream->p_byte <= p_bit_stream->p_end - sizeof(WORD_TYPE) )
{
p_bit_stream->fifo.buffer <<= i_bits;
return;
}
- p_bit_stream->fifo.buffer = GetWord( p_bit_stream )
+ p_bit_stream->fifo.buffer = _GetWord( p_bit_stream )
<< ( -p_bit_stream->fifo.i_available );
p_bit_stream->fifo.i_available += sizeof(WORD_TYPE) * 8;
}
{
if( p_bit_stream->fifo.i_available )
{
- p_bit_stream->fifo.buffer = GetWord( p_bit_stream )
+ p_bit_stream->fifo.buffer = _GetWord( p_bit_stream )
<< (32 - p_bit_stream->fifo.i_available);
}
else
{
- p_bit_stream->fifo.buffer = GetWord( p_bit_stream );
+ _GetWord( p_bit_stream );
}
}
}
i_result = p_bit_stream->fifo.buffer >> (8 * sizeof(WORD_TYPE) - i_bits);
- p_bit_stream->fifo.buffer = GetWord( p_bit_stream );
+ p_bit_stream->fifo.buffer = _GetWord( p_bit_stream );
i_result |= p_bit_stream->fifo.buffer
>> (8 * sizeof(WORD_TYPE)
+ p_bit_stream->fifo.i_available);
{
WORD_TYPE i_result;
- i_result = p_bit_stream->fifo.buffer;
- p_bit_stream->fifo.buffer = GetWord( p_bit_stream );
-
- i_result |= p_bit_stream->fifo.buffer
- >> (p_bit_stream->fifo.i_available);
if( p_bit_stream->fifo.i_available )
{
+ i_result = p_bit_stream->fifo.buffer;
+ p_bit_stream->fifo.buffer = _GetWord( p_bit_stream );
+
+ i_result |= p_bit_stream->fifo.buffer
+ >> (p_bit_stream->fifo.i_available);
p_bit_stream->fifo.buffer <<= (8 * sizeof(WORD_TYPE)
- p_bit_stream->fifo.i_available);
+ return( i_result );
+ }
+ else
+ {
+ return( _GetWord( p_bit_stream ) );
}
-
- return( i_result );
}
/*****************************************************************************
p_bit_stream->pf_next_data_packet( p_bit_stream );
}
while( (i_available = p_bit_stream->p_end - p_bit_stream->p_byte)
- <= i_buf_len );
+ <= i_buf_len && !p_bit_stream->p_decoder_fifo->b_die );
if( i_buf_len )
{
* input_programs.c: es_descriptor_t, pgrm_descriptor_t management
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
- * $Id: input_programs.c,v 1.24 2001/01/12 14:49:55 sam Exp $
+ * $Id: input_programs.c,v 1.25 2001/01/12 17:33:18 massiot Exp $
*
* Authors:
*
*****************************************************************************/
void input_EndStream( input_thread_t * p_input )
{
- int i;
-
/* Free all programs and associated ES, and associated decoders. */
- for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
+ while( p_input->stream.i_pgrm_number )
{
- /* Don't put i instead of 0 !! */
input_DelProgram( p_input, p_input->stream.pp_programs[0] );
}
/* Free standalone ES */
- for( i = 0; i < p_input->stream.i_es_number; i++ )
+ while( p_input->stream.i_es_number )
{
- /* Don't put i instead of 0 !! */
input_DelES( p_input, p_input->stream.pp_es[0] );
}
}
*****************************************************************************/
void input_DelProgram( input_thread_t * p_input, pgrm_descriptor_t * p_pgrm )
{
- int i_index, i_pgrm_index;
+ int i_pgrm_index;
ASSERT( p_pgrm );
intf_DbgMsg("Deleting description for pgrm %d", p_pgrm->i_number);
/* Free the structures that describe the es that belongs to that program */
- for( i_index = 0; i_index < p_pgrm->i_es_number; i_index++ )
+ while( p_pgrm->i_es_number )
{
- /* Don't put i_index instead of 0 !! */
input_DelES( p_input, p_pgrm->pp_es[0] );
}
if( p_es->p_decoder_fifo != NULL )
{
input_EndDecoder( p_input, p_es );
-
- /* Destroy the lock and cond */
- vlc_cond_destroy( &p_es->p_decoder_fifo->data_wait );
- vlc_mutex_destroy( &p_es->p_decoder_fifo->data_lock );
-
- free( p_es->p_decoder_fifo );
}
/* Remove this ES from the description of the program if it is associated to
boolean_t b_valid;
subpicture_t * p_spu = NULL;
- while( !DECODER_FIFO_ISEMPTY(*p_spudec->p_fifo) )
+ /* wait for the next SPU ID.
+ * XXX: We trash 0xff bytes since they probably come from
+ * an incomplete previous packet */
+ do
{
- /* wait for the next SPU ID.
- * XXX: We trash 0xff bytes since they probably come from
- * an incomplete previous packet */
- do
- {
- i_packet_size = GetByte( &p_spudec->bit_stream );
- }
- while( i_packet_size == 0xff );
+ i_packet_size = GetBits( &p_spudec->bit_stream, 8 );
+ }
+ while( i_packet_size == 0xff );
+
+ if( p_spudec->p_fifo->b_die )
+ {
+ break;
+ }
+
+ /* the total size - should equal the sum of the
+ * PES packet size that form the SPU packet */
+ i_packet_size = i_packet_size << 8
+ | GetBits( &p_spudec->bit_stream, 8 );
+
+ /* the RLE stuff size */
+ i_rle_size = GetBits( &p_spudec->bit_stream, 16 );
+
+ /* if the values we got aren't too strange, decode the data */
+ if( i_rle_size < i_packet_size )
+ {
+ /* allocate the subpicture.
+ * FIXME: we should check if the allocation failed */
+ p_spu = vout_CreateSubPicture( p_spudec->p_vout,
+ DVD_SUBPICTURE, i_rle_size );
+ /* get display time */
+ p_spu->begin_date = p_spu->end_date
+ = DECODER_FIFO_START(*p_spudec->p_fifo)->i_pts;
+
+ /* get RLE data, skip 4 bytes for the first two read offsets */
+ GetChunk( &p_spudec->bit_stream, p_spu->p_data,
+ i_rle_size - 4 );
if( p_spudec->p_fifo->b_die )
{
- goto bad_packet;
+ break;
}
- /* the total size - should equal the sum of the
- * PES packet size that form the SPU packet */
- i_packet_size = i_packet_size << 8
- | GetByte( &p_spudec->bit_stream );
+ /* continue parsing after the RLE part */
+ i_index = i_rle_size;
- /* the RLE stuff size */
- i_rle_size = GetByte( &p_spudec->bit_stream ) << 8
- | GetByte( &p_spudec->bit_stream );
+ /* assume packet is valid */
+ b_valid = 1;
- /* if the values we got aren't too strange, decode the data */
- if( i_rle_size < i_packet_size )
+ /* getting the control part */
+ do
{
- /* allocate the subpicture.
- * FIXME: we should check if the allocation failed */
- p_spu = vout_CreateSubPicture( p_spudec->p_vout,
- DVD_SUBPICTURE, i_rle_size );
- /* get display time */
- p_spu->begin_date = p_spu->end_date
- = DECODER_FIFO_START(*p_spudec->p_fifo)->i_pts;
-
- /* get RLE data, skip 4 bytes for the first two read offsets */
- GetChunk( &p_spudec->bit_stream, p_spu->p_data,
- i_rle_size - 4 );
-
- if( p_spudec->p_fifo->b_die )
- {
- goto bad_packet;
- }
+ unsigned char i_cmd;
+ u16 i_date;
- /* continue parsing after the RLE part */
- i_index = i_rle_size;
+ /* Get the sequence date */
+ i_date = GetBits( &p_spudec->bit_stream, 16 );
- /* assume packet is valid */
- b_valid = 1;
+ /* Next offset */
+ i_next = GetBits( &p_spudec->bit_stream, 16 );
+
+ i_index += 4;
- /* getting the control part */
do
{
- unsigned char i_cmd;
- unsigned int i_word, i_date;
-
- /* Get the sequence date */
- i_date = GetByte( &p_spudec->bit_stream ) << 8
- | GetByte( &p_spudec->bit_stream );
-
- /* Next offset */
- i_next = GetByte( &p_spudec->bit_stream ) << 8
- | GetByte( &p_spudec->bit_stream );
-
- i_index += 4;
+ i_cmd = GetBits( &p_spudec->bit_stream, 8 );
+ i_index++;
- do
+ switch( i_cmd )
{
- i_cmd = GetByte( &p_spudec->bit_stream );
- i_index++;
-
- switch( i_cmd )
- {
- case SPU_CMD_FORCE_DISPLAY:
- /* 00 (force displaying) */
- break;
- /* FIXME: here we have to calculate dates. It's
- * around i_date * 12000 but I don't know
- * how much exactly.
- */
- case SPU_CMD_START_DISPLAY:
- /* 01 (start displaying) */
- p_spu->begin_date += ( i_date * 12000 );
- break;
- case SPU_CMD_STOP_DISPLAY:
- /* 02 (stop displaying) */
- p_spu->end_date += ( i_date * 12000 );
- break;
- case SPU_CMD_SET_PALETTE:
- /* 03xxxx (palette) */
- i_word = GetByte( &p_spudec->bit_stream ) << 8
- | GetByte( &p_spudec->bit_stream );
- i_index += 2;
- break;
- case SPU_CMD_SET_ALPHACHANNEL:
- /* 04xxxx (alpha channel) */
- i_word = GetByte( &p_spudec->bit_stream ) << 8
- | GetByte( &p_spudec->bit_stream );
- i_index += 2;
- break;
- case SPU_CMD_SET_COORDINATES:
- /* 05xxxyyyxxxyyy (coordinates) */
- i_word = GetByte( &p_spudec->bit_stream );
- p_spu->i_x = (i_word << 4)
- | GetBits( &p_spudec->bit_stream, 4 );
-
- i_word = GetBits( &p_spudec->bit_stream, 4 );
- p_spu->i_width = p_spu->i_x - ( (i_word << 8)
- | GetBits( &p_spudec->bit_stream, 8 ) ) + 1;
-
- i_word = GetBits( &p_spudec->bit_stream, 8 );
- p_spu->i_y = (i_word << 4)
- | GetBits( &p_spudec->bit_stream, 4 );
-
- i_word = GetBits( &p_spudec->bit_stream, 4 );
- p_spu->i_height = p_spu->i_y - ( (i_word << 8)
- | GetByte( &p_spudec->bit_stream ) ) + 1;
-
- i_index += 6;
- break;
- case SPU_CMD_SET_OFFSETS:
- /* 06xxxxyyyy (byte offsets) */
- p_spu->type.spu.i_offset[0] =
- ( GetByte( &p_spudec->bit_stream ) << 8
- | GetByte( &p_spudec->bit_stream ) ) - 4;
- p_spu->type.spu.i_offset[1] =
- ( GetByte( &p_spudec->bit_stream ) << 8
- | GetByte( &p_spudec->bit_stream ) ) - 4;
- i_index += 4;
- break;
- case SPU_CMD_END:
- /* ff (end) */
- break;
- default:
- /* ?? (unknown command) */
- intf_ErrMsg( "spudec: unknown command 0x%.2x",
- i_cmd );
- b_valid = 0;
- break;
- }
+ case SPU_CMD_FORCE_DISPLAY:
+ /* 00 (force displaying) */
+ break;
+ /* FIXME: here we have to calculate dates. It's
+ * around i_date * 12000 but I don't know
+ * how much exactly.
+ */
+ case SPU_CMD_START_DISPLAY:
+ /* 01 (start displaying) */
+ p_spu->begin_date += ( i_date * 12000 );
+ break;
+ case SPU_CMD_STOP_DISPLAY:
+ /* 02 (stop displaying) */
+ p_spu->end_date += ( i_date * 12000 );
+ break;
+ case SPU_CMD_SET_PALETTE:
+ /* 03xxxx (palette) - trashed */
+ RemoveBits( &p_spudec->bit_stream, 16 );
+ i_index += 2;
+ break;
+ case SPU_CMD_SET_ALPHACHANNEL:
+ /* 04xxxx (alpha channel) - trashed */
+ RemoveBits( &p_spudec->bit_stream, 16 );
+ i_index += 2;
+ break;
+ case SPU_CMD_SET_COORDINATES:
+ /* 05xxxyyyxxxyyy (coordinates) */
+ p_spu->i_x =
+ GetBits( &p_spudec->bit_stream, 12 );
+
+ p_spu->i_width = p_spu->i_x -
+ GetBits( &p_spudec->bit_stream, 12 ) + 1;
+
+ p_spu->i_y =
+ GetBits( &p_spudec->bit_stream, 12 );
+
+ p_spu->i_height = p_spu->i_y -
+ GetBits( &p_spudec->bit_stream, 12 ) + 1;
+
+ i_index += 6;
+ break;
+ case SPU_CMD_SET_OFFSETS:
+ /* 06xxxxyyyy (byte offsets) */
+ p_spu->type.spu.i_offset[0] =
+ GetBits( &p_spudec->bit_stream, 16 ) - 4;
+ p_spu->type.spu.i_offset[1] =
+ GetBits( &p_spudec->bit_stream, 16 ) - 4;
+ i_index += 4;
+ break;
+ case SPU_CMD_END:
+ /* ff (end) */
+ break;
+ default:
+ /* ?? (unknown command) */
+ intf_ErrMsg( "spudec: unknown command 0x%.2x",
+ i_cmd );
+ b_valid = 0;
+ break;
}
- while( b_valid && ( i_cmd != SPU_CMD_END ) );
}
- while( b_valid && ( i_index == i_next ) );
+ while( b_valid && ( i_cmd != SPU_CMD_END ) );
+ }
+ while( b_valid && ( i_index == i_next ) );
- if( b_valid )
- {
- /* SPU is finished - we can tell the video output
- * to display it */
- vout_DisplaySubPicture( p_spudec->p_vout, p_spu );
- }
- else
- {
- vout_DestroySubPicture( p_spudec->p_vout, p_spu );
- }
+ if( b_valid )
+ {
+ /* SPU is finished - we can tell the video output
+ * to display it */
+ vout_DisplaySubPicture( p_spudec->p_vout, p_spu );
}
- else
+ else
{
- /* Unexpected PES packet - trash it */
- intf_ErrMsg( "spudec: trying to recover from bad packet" );
- vlc_mutex_lock( &p_spudec->p_fifo->data_lock );
- p_spudec->p_fifo->pf_delete_pes( p_spudec->p_fifo->p_packets_mgt,
- DECODER_FIFO_START(*p_spudec->p_fifo) );
- DECODER_FIFO_INCSTART( *p_spudec->p_fifo );
- vlc_mutex_unlock( &p_spudec->p_fifo->data_lock );
+ vout_DestroySubPicture( p_spudec->p_vout, p_spu );
}
-bad_packet:
+ }
+ else
+ {
+ /* Unexpected PES packet - trash it */
+ intf_ErrMsg( "spudec: trying to recover from bad packet" );
+ vlc_mutex_lock( &p_spudec->p_fifo->data_lock );
+ p_spudec->p_fifo->pf_delete_pes( p_spudec->p_fifo->p_packets_mgt,
+ DECODER_FIFO_START(*p_spudec->p_fifo) );
+ DECODER_FIFO_INCSTART( *p_spudec->p_fifo );
+ vlc_mutex_unlock( &p_spudec->p_fifo->data_lock );
}
}