Commit 47e65c0f authored by Christophe Massiot's avatar Christophe Massiot

* Fixed a major bug in the LPCM codec.

* Moved input_ExtractPES to where it belongs, input_ext-dec.c.
parent 75426e20
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* input_ext-dec.h: structures exported to the VideoLAN decoders * input_ext-dec.h: structures exported to the VideoLAN decoders
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2001 VideoLAN * Copyright (C) 1999-2001 VideoLAN
* $Id: input_ext-dec.h,v 1.78 2003/01/07 21:49:01 fenrir Exp $ * $Id: input_ext-dec.h,v 1.79 2003/03/04 13:21:19 massiot Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* Michel Kaempf <maxx@via.ecp.fr> * Michel Kaempf <maxx@via.ecp.fr>
...@@ -211,6 +211,8 @@ struct bit_stream_t ...@@ -211,6 +211,8 @@ struct bit_stream_t
/***************************************************************************** /*****************************************************************************
* Prototypes from input_ext-dec.c * Prototypes from input_ext-dec.c
*****************************************************************************/ *****************************************************************************/
VLC_EXPORT( void, input_ExtractPES, ( decoder_fifo_t *, pes_packet_t ** ) );
VLC_EXPORT( void, input_DeletePES, ( input_buffers_t *, pes_packet_t * ) );
VLC_EXPORT( int, InitBitstream, ( bit_stream_t *, decoder_fifo_t *, void ( * )( bit_stream_t *, vlc_bool_t ), void * p_callback_arg ) ); VLC_EXPORT( int, InitBitstream, ( bit_stream_t *, decoder_fifo_t *, void ( * )( bit_stream_t *, vlc_bool_t ), void * p_callback_arg ) );
VLC_EXPORT( vlc_bool_t, NextDataPacket, ( decoder_fifo_t *, bit_stream_t * ) ); VLC_EXPORT( vlc_bool_t, NextDataPacket, ( decoder_fifo_t *, bit_stream_t * ) );
VLC_EXPORT( void, BitstreamNextDataPacket, ( bit_stream_t * ) ); VLC_EXPORT( void, BitstreamNextDataPacket, ( bit_stream_t * ) );
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* but exported to plug-ins * but exported to plug-ins
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2002 VideoLAN * Copyright (C) 1999-2002 VideoLAN
* $Id: input_ext-plugins.h,v 1.39 2003/01/25 03:12:20 fenrir Exp $ * $Id: input_ext-plugins.h,v 1.40 2003/03/04 13:21:19 massiot Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -58,8 +58,6 @@ VLC_EXPORT( int, input_UnselectES,( input_thread_t *, es_descriptor_t * ) ); ...@@ -58,8 +58,6 @@ VLC_EXPORT( int, input_UnselectES,( input_thread_t *, es_descriptor_t * ) );
decoder_fifo_t * input_RunDecoder( input_thread_t *, es_descriptor_t * ); decoder_fifo_t * input_RunDecoder( input_thread_t *, es_descriptor_t * );
void input_EndDecoder( input_thread_t *, es_descriptor_t * ); void input_EndDecoder( input_thread_t *, es_descriptor_t * );
VLC_EXPORT( void, input_DecodePES, ( decoder_fifo_t *, pes_packet_t * ) ); VLC_EXPORT( void, input_DecodePES, ( decoder_fifo_t *, pes_packet_t * ) );
VLC_EXPORT( void, input_ExtractPES, ( decoder_fifo_t *, pes_packet_t ** ) );
VLC_EXPORT( void, input_FlushPESFifo, ( decoder_fifo_t * ) );
void input_EscapeDiscontinuity( input_thread_t * ); void input_EscapeDiscontinuity( input_thread_t * );
void input_EscapeAudioDiscontinuity( input_thread_t * ); void input_EscapeAudioDiscontinuity( input_thread_t * );
VLC_EXPORT( void, input_NullPacket, ( input_thread_t *, es_descriptor_t * ) ); VLC_EXPORT( void, input_NullPacket, ( input_thread_t *, es_descriptor_t * ) );
...@@ -91,7 +89,6 @@ VLC_EXPORT( data_packet_t *, input_ShareBuffer, ( input_buffers_t *, data_buffer ...@@ -91,7 +89,6 @@ VLC_EXPORT( data_packet_t *, input_ShareBuffer, ( input_buffers_t *, data_buffer
VLC_EXPORT( data_packet_t *, input_NewPacket, ( input_buffers_t *, size_t ) ); VLC_EXPORT( data_packet_t *, input_NewPacket, ( input_buffers_t *, size_t ) );
VLC_EXPORT( void, input_DeletePacket, ( input_buffers_t *, data_packet_t * ) ); VLC_EXPORT( void, input_DeletePacket, ( input_buffers_t *, data_packet_t * ) );
VLC_EXPORT( pes_packet_t *, input_NewPES, ( input_buffers_t * ) ); VLC_EXPORT( pes_packet_t *, input_NewPES, ( input_buffers_t * ) );
VLC_EXPORT( void, input_DeletePES, ( input_buffers_t *, pes_packet_t * ) );
VLC_EXPORT( ssize_t, input_FillBuffer, ( input_thread_t * ) ); VLC_EXPORT( ssize_t, input_FillBuffer, ( input_thread_t * ) );
VLC_EXPORT( ssize_t, input_Peek, ( input_thread_t *, byte_t **, size_t ) ); VLC_EXPORT( ssize_t, input_Peek, ( input_thread_t *, byte_t **, size_t ) );
VLC_EXPORT( ssize_t, input_SplitBuffer, ( input_thread_t *, data_packet_t **, size_t ) ); VLC_EXPORT( ssize_t, input_SplitBuffer, ( input_thread_t *, data_packet_t **, size_t ) );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* lpcm.c: lpcm decoder module * lpcm.c: lpcm decoder module
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2001 VideoLAN * Copyright (C) 1999-2001 VideoLAN
* $Id: lpcm.c,v 1.12 2003/03/03 14:19:09 massiot Exp $ * $Id: lpcm.c,v 1.13 2003/03/04 13:21:19 massiot Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* Henri Fallon <henri@videolan.org> * Henri Fallon <henri@videolan.org>
...@@ -38,25 +38,15 @@ ...@@ -38,25 +38,15 @@
# include <unistd.h> /* getpid() */ # include <unistd.h> /* getpid() */
#endif #endif
/* DVD PES size (2048) - 40 bytes (headers) */
#define LPCM_FRAME_LENGTH 2008
/***************************************************************************** /*****************************************************************************
* dec_thread_t : lpcm decoder thread descriptor * dec_thread_t : lpcm decoder thread descriptor
*****************************************************************************/ *****************************************************************************/
typedef struct dec_thread_t typedef struct dec_thread_t
{ {
/*
* Thread properties
*/
vlc_thread_t thread_id; /* id for thread functions */
/* /*
* Input properties * Input properties
*/ */
decoder_fifo_t * p_fifo; /* stores the PES stream data */ decoder_fifo_t * p_fifo; /* stores the PES stream data */
bit_stream_t bit_stream;
int sync_ptr; /* sync ptr from lpcm magic header */
/* /*
* Output properties * Output properties
...@@ -82,6 +72,8 @@ typedef struct dec_thread_t ...@@ -82,6 +72,8 @@ typedef struct dec_thread_t
* - start code (8 bits) == 0x80 * - start code (8 bits) == 0x80
*/ */
#define LPCM_HEADER_LEN 6
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
...@@ -125,7 +117,7 @@ static int RunDecoder( decoder_fifo_t * p_fifo ) ...@@ -125,7 +117,7 @@ static int RunDecoder( decoder_fifo_t * p_fifo )
dec_thread_t * p_dec; dec_thread_t * p_dec;
/* Allocate the memory needed to store the thread's structure */ /* Allocate the memory needed to store the thread's structure */
if( (p_dec = (dec_thread_t *)malloc (sizeof(dec_thread_t)) ) if( (p_dec = (dec_thread_t *)malloc( sizeof(dec_thread_t)) )
== NULL) == NULL)
{ {
msg_Err( p_fifo, "out of memory" ); msg_Err( p_fifo, "out of memory" );
...@@ -136,16 +128,6 @@ static int RunDecoder( decoder_fifo_t * p_fifo ) ...@@ -136,16 +128,6 @@ static int RunDecoder( decoder_fifo_t * p_fifo )
/* Initialize the thread properties */ /* Initialize the thread properties */
p_dec->p_fifo = p_fifo; p_dec->p_fifo = p_fifo;
/* Init the bitstream */
if( InitBitstream( &p_dec->bit_stream, p_dec->p_fifo,
NULL, NULL ) != VLC_SUCCESS )
{
msg_Err( p_fifo, "cannot initialize bitstream" );
DecoderError( p_fifo );
EndThread( p_dec );
return -1;
}
p_dec->output_format.i_format = VLC_FOURCC('s','1','6','b'); p_dec->output_format.i_format = VLC_FOURCC('s','1','6','b');
p_dec->p_aout = NULL; p_dec->p_aout = NULL;
p_dec->p_aout_input = NULL; p_dec->p_aout_input = NULL;
...@@ -173,30 +155,61 @@ static int RunDecoder( decoder_fifo_t * p_fifo ) ...@@ -173,30 +155,61 @@ static int RunDecoder( decoder_fifo_t * p_fifo )
*****************************************************************************/ *****************************************************************************/
static void DecodeFrame( dec_thread_t * p_dec ) static void DecodeFrame( dec_thread_t * p_dec )
{ {
pes_packet_t * p_pes;
data_packet_t * p_data;
aout_buffer_t * p_buffer; aout_buffer_t * p_buffer;
void * p_dest;
mtime_t i_pts; mtime_t i_pts;
uint8_t i_header; uint8_t i_header;
unsigned int i_rate, i_original_channels; unsigned int i_rate, i_original_channels, i_size;
int i;
/* Look for sync word - should be 0xXX80 */ input_ExtractPES( p_dec->p_fifo, &p_pes );
RealignBits( &p_dec->bit_stream ); if ( !p_pes )
while ( (ShowBits( &p_dec->bit_stream, 16 ) & 0xc8ff) != 0x0080 &&
(!p_dec->p_fifo->b_die) && (!p_dec->p_fifo->b_error) )
{ {
RemoveBits( &p_dec->bit_stream, 8 ); p_dec->p_fifo->b_error = 1;
return;
}
/* Compute the size of the PES - i_pes_size includes the PES header. */
p_data = p_pes->p_first;
i_size = 0;
while ( p_data != NULL )
{
i_size += p_data->p_payload_end - p_data->p_payload_start;
p_data = p_data->p_next;
}
if ( i_size < LPCM_HEADER_LEN )
{
msg_Err(p_dec->p_fifo, "PES packet is too short");
input_DeletePES( p_dec->p_fifo->p_packets_mgt, p_pes );
return;
} }
if ( p_dec->p_fifo->b_die || p_dec->p_fifo->b_error ) return;
NextPTS( &p_dec->bit_stream, &i_pts, NULL ); i_pts = p_pes->i_pts;
if( i_pts != 0 && i_pts != aout_DateGet( &p_dec->end_date ) ) if( i_pts != 0 && i_pts != aout_DateGet( &p_dec->end_date ) )
{ {
aout_DateSet( &p_dec->end_date, i_pts ); aout_DateSet( &p_dec->end_date, i_pts );
} }
p_data = p_pes->p_first;
/* It necessarily contains one byte. */
/* Get LPCM header. */ /* Get LPCM header. */
i_header = GetBits( &p_dec->bit_stream, 16 ) >> 8;
switch ( i_header >> 4 ) /* Drop the first four bytes. */
for ( i = 0; i < 4; i++ )
{
if ( p_data->p_payload_end == p_data->p_payload_start )
{
p_data = p_data->p_next;
}
p_data->p_payload_start++;
}
i_header = p_data->p_payload_start[0];
p_data->p_payload_start++;
switch ( (i_header >> 4) & 0x3 )
{ {
case 0: case 0:
i_rate = 48000; i_rate = 48000;
...@@ -253,6 +266,19 @@ static void DecodeFrame( dec_thread_t * p_dec ) ...@@ -253,6 +266,19 @@ static void DecodeFrame( dec_thread_t * p_dec )
break; break;
} }
/* Check frame sync and drop it. */
if ( p_data->p_payload_end == p_data->p_payload_start )
{
p_data = p_data->p_next;
}
if ( p_data->p_payload_start[0] != 0x80 )
{
msg_Warn(p_dec->p_fifo, "no frame sync");
input_DeletePES( p_dec->p_fifo->p_packets_mgt, p_pes );
return;
}
p_data->p_payload_start++;
if( (p_dec->p_aout_input != NULL) && if( (p_dec->p_aout_input != NULL) &&
( (p_dec->output_format.i_rate != i_rate) ( (p_dec->output_format.i_rate != i_rate)
|| (p_dec->output_format.i_original_channels || (p_dec->output_format.i_original_channels
...@@ -278,41 +304,44 @@ static void DecodeFrame( dec_thread_t * p_dec ) ...@@ -278,41 +304,44 @@ static void DecodeFrame( dec_thread_t * p_dec )
if ( p_dec->p_aout_input == NULL ) if ( p_dec->p_aout_input == NULL )
{ {
p_dec->p_fifo->b_error = 1; p_dec->p_fifo->b_error = 1;
input_DeletePES( p_dec->p_fifo->p_packets_mgt, p_pes );
return; return;
} }
} }
if ( !aout_DateGet( &p_dec->end_date ) ) if ( !aout_DateGet( &p_dec->end_date ) )
{ {
byte_t p_junk[LPCM_FRAME_LENGTH];
/* We've just started the stream, wait for the first PTS. */ /* We've just started the stream, wait for the first PTS. */
GetChunk( &p_dec->bit_stream, p_junk, LPCM_FRAME_LENGTH ); input_DeletePES( p_dec->p_fifo->p_packets_mgt, p_pes );
return; return;
} }
p_buffer = aout_DecNewBuffer( p_dec->p_aout, p_dec->p_aout_input, p_buffer = aout_DecNewBuffer( p_dec->p_aout, p_dec->p_aout_input,
LPCM_FRAME_LENGTH / p_dec->output_format.i_bytes_per_frame ); (i_size - LPCM_HEADER_LEN)
/ p_dec->output_format.i_bytes_per_frame );
if( p_buffer == NULL ) if( p_buffer == NULL )
{ {
msg_Err( p_dec->p_fifo, "cannot get aout buffer" ); msg_Err( p_dec->p_fifo, "cannot get aout buffer" );
p_dec->p_fifo->b_error = 1; p_dec->p_fifo->b_error = 1;
input_DeletePES( p_dec->p_fifo->p_packets_mgt, p_pes );
return; return;
} }
p_buffer->start_date = aout_DateGet( &p_dec->end_date ); p_buffer->start_date = aout_DateGet( &p_dec->end_date );
p_buffer->end_date = aout_DateIncrement( &p_dec->end_date, p_buffer->end_date = aout_DateIncrement( &p_dec->end_date,
LPCM_FRAME_LENGTH / p_dec->output_format.i_bytes_per_frame ); (i_size - LPCM_HEADER_LEN)
/ p_dec->output_format.i_bytes_per_frame );
/* Get the whole frame. */ /* Get the whole frame. */
GetChunk( &p_dec->bit_stream, p_buffer->p_buffer, p_dest = p_buffer->p_buffer;
LPCM_FRAME_LENGTH); while ( p_data != NULL )
if( p_dec->p_fifo->b_die )
{ {
aout_DecDeleteBuffer( p_dec->p_aout, p_dec->p_aout_input, p_dec->p_fifo->p_vlc->pf_memcpy( p_dest, p_data->p_payload_start,
p_buffer ); p_data->p_payload_end - p_data->p_payload_start );
return; p_dest += p_data->p_payload_end - p_data->p_payload_start;
p_data = p_data->p_next;
} }
input_DeletePES( p_dec->p_fifo->p_packets_mgt, p_pes );
/* Send the buffer to the aout core. */ /* Send the buffer to the aout core. */
aout_DecPlay( p_dec->p_aout, p_dec->p_aout_input, p_buffer ); aout_DecPlay( p_dec->p_aout, p_dec->p_aout_input, p_buffer );
...@@ -328,6 +357,5 @@ static void EndThread( dec_thread_t * p_dec ) ...@@ -328,6 +357,5 @@ static void EndThread( dec_thread_t * p_dec )
aout_DecDelete( p_dec->p_aout, p_dec->p_aout_input ); aout_DecDelete( p_dec->p_aout, p_dec->p_aout_input );
} }
CloseBitstream( &p_dec->bit_stream );
free( p_dec ); free( p_dec );
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* input_dec.c: Functions for the management of decoders * input_dec.c: Functions for the management of decoders
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2001 VideoLAN * Copyright (C) 1999-2001 VideoLAN
* $Id: input_dec.c,v 1.58 2003/02/18 00:20:01 hartman Exp $ * $Id: input_dec.c,v 1.59 2003/03/04 13:21:19 massiot Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -214,77 +214,6 @@ void input_DecodePES( decoder_fifo_t * p_decoder_fifo, pes_packet_t * p_pes ) ...@@ -214,77 +214,6 @@ void input_DecodePES( decoder_fifo_t * p_decoder_fifo, pes_packet_t * p_pes )
vlc_mutex_unlock( &p_decoder_fifo->data_lock ); vlc_mutex_unlock( &p_decoder_fifo->data_lock );
} }
/****************************************************************************
* input_ExtractPES
*****************************************************************************
* Extract a PES from the fifo. If pp_pes is NULL then the PES is just
* deleted, otherwise *pp_pes will point to this PES.
****************************************************************************/
void input_ExtractPES( decoder_fifo_t *p_fifo, pes_packet_t **pp_pes )
{
pes_packet_t *p_pes;
vlc_mutex_lock( &p_fifo->data_lock );
if( p_fifo->p_first == NULL )
{
if( p_fifo->b_die )
{
vlc_mutex_unlock( &p_fifo->data_lock );
if( pp_pes ) *pp_pes = NULL;
return;
}
/* Signal the input thread we're waiting. This is only
* needed in case of slave clock (ES plug-in) but it won't
* harm. */
vlc_cond_signal( &p_fifo->data_wait );
/* Wait for the input to tell us when we received a packet. */
vlc_cond_wait( &p_fifo->data_wait, &p_fifo->data_lock );
}
p_pes = p_fifo->p_first;
p_fifo->p_first = p_pes->p_next;
p_pes->p_next = NULL;
p_fifo->i_depth--;
if( !p_fifo->p_first )
{
/* No PES in the FIFO. p_last is no longer valid. */
p_fifo->pp_last = &p_fifo->p_first;
}
vlc_mutex_unlock( &p_fifo->data_lock );
if( pp_pes )
*pp_pes = p_pes;
else
input_DeletePES( p_fifo->p_packets_mgt, p_pes );
}
/****************************************************************************
* input_FlushPESFifo
*****************************************************************************
* Empties the PES fifo of the decoder.
****************************************************************************/
void input_FlushPESFifo( decoder_fifo_t *p_fifo )
{
pes_packet_t * p_pes;
vlc_mutex_lock( &p_fifo->data_lock );
while( p_fifo->p_first )
{
p_pes = p_fifo->p_first;
p_fifo->p_first = p_fifo->p_first->p_next;
input_DeletePES( p_fifo->p_packets_mgt, p_pes );
}
/* No PES in the FIFO. p_last is no longer valid. */
p_fifo->pp_last = &p_fifo->p_first;
vlc_mutex_unlock( &p_fifo->data_lock );
}
/***************************************************************************** /*****************************************************************************
* Create a NULL packet for padding in case of a data loss * Create a NULL packet for padding in case of a data loss
*****************************************************************************/ *****************************************************************************/
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* input_ext-dec.c: services to the decoders * input_ext-dec.c: services to the decoders
***************************************************************************** *****************************************************************************
* Copyright (C) 1998-2001 VideoLAN * Copyright (C) 1998-2001 VideoLAN
* $Id: input_ext-dec.c,v 1.44 2003/02/26 13:51:36 gbazin Exp $ * $Id: input_ext-dec.c,v 1.45 2003/03/04 13:21:19 massiot Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -33,6 +33,55 @@ ...@@ -33,6 +33,55 @@
#include "input_ext-intf.h" #include "input_ext-intf.h"
#include "input_ext-plugins.h" #include "input_ext-plugins.h"
/****************************************************************************
* input_ExtractPES
*****************************************************************************
* Extract a PES from the fifo. If pp_pes is NULL then the PES is just
* deleted, otherwise *pp_pes will point to this PES.
****************************************************************************/
void input_ExtractPES( decoder_fifo_t *p_fifo, pes_packet_t **pp_pes )
{
pes_packet_t *p_pes;
vlc_mutex_lock( &p_fifo->data_lock );
if( p_fifo->p_first == NULL )
{
if( p_fifo->b_die )
{
vlc_mutex_unlock( &p_fifo->data_lock );
if( pp_pes ) *pp_pes = NULL;
return;
}
/* Signal the input thread we're waiting. This is only
* needed in case of slave clock (ES plug-in) but it won't
* harm. */
vlc_cond_signal( &p_fifo->data_wait );
/* Wait for the input to tell us when we received a packet. */
vlc_cond_wait( &p_fifo->data_wait, &p_fifo->data_lock );
}
p_pes = p_fifo->p_first;
p_fifo->p_first = p_pes->p_next;
p_pes->p_next = NULL;
p_fifo->i_depth--;
if( !p_fifo->p_first )
{
/* No PES in the FIFO. p_last is no longer valid. */
p_fifo->pp_last = &p_fifo->p_first;
}
vlc_mutex_unlock( &p_fifo->data_lock );
if( pp_pes )
*pp_pes = p_pes;
else
input_DeletePES( p_fifo->p_packets_mgt, p_pes );
}
/***************************************************************************** /*****************************************************************************
* InitBitstream: initialize a bit_stream_t structure and returns VLC_SUCCESS * InitBitstream: initialize a bit_stream_t structure and returns VLC_SUCCESS
* on success. * on success.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment