Commit 5adf2c05 authored by Michel Kaempf's avatar Michel Kaempf

* input/input.c :

- Correction de deux bugs concernant le calcul de b_has_pts et d'une autre
variable de la structure pes (les masques utilis�s n'�taient pas les bons...
cons�quence imm�diate : la synchro ne voyait jamais de paquet dat�) ;
- Correction d'un bug de la m�thode de calcul de i_pts ;

* audio_decoder/audio_decoder.c :
- Autod�tection des dates en utilisant le champ i_pts fourni par la
synchro... le son � fr�quence variable adapt�e aux pertes de paquets TS et
autres probl�mes est d�sormais une r�alit� :-)

* audio_output/audio_output.c :
+ Rajout de la synchro :
- On attend si on est en avance ;
- On saute des frames si on est en retard ;
+ Ce n'est pas encore tout � fait �a, mais �a commence � prendre forme...
On dirait que le mini-server va trop vite, parce que l'audio est souvent
en retard... Polux ?

* Makefile :
- Modifications cosm�tiques ;

--
MaXX
parent 51bb183d
......@@ -45,7 +45,6 @@ CCFLAGS += -D_GNU_SOURCE
#CCFLAGS += -s -fargument-noalias-global -fexpensive-optimizations -ffast-math -funroll-loops -fomit-frame-pointer #-march=pentiumpro
#(Uncomment -march=pentiumpro if it applies)
#
# C compiler flags: dependancies
#
......
......@@ -770,17 +770,6 @@ static int InitThread( adec_thread_t * p_adec )
return( 0 );
}
#define UPDATE_INCREMENT( increment, integer ) \
if ( ((increment).l_remainder += (increment).l_euclidean_remainder) >= 0 ) \
{ \
(integer) += (increment).l_euclidean_integer + 1; \
(increment).l_remainder -= (increment).l_euclidean_denominator; \
} \
else \
{ \
(integer) += (increment).l_euclidean_integer; \
}
/******************************************************************************
* RunThread : audio decoder thread
******************************************************************************
......@@ -793,11 +782,6 @@ static void RunThread( adec_thread_t * p_adec )
// int i_header;
// int i_framesize;
// int i_dummy;
s64 s64_numerator;
s64 s64_denominator;
/* The synchronization needs date and date_increment for the moment */
mtime_t date = 0;
aout_increment_t date_increment;
intf_DbgMsg("adec debug: running audio decoder thread (%p) (pid == %i)\n", p_adec, getpid());
......@@ -807,30 +791,6 @@ static void RunThread( adec_thread_t * p_adec )
p_adec->b_error = 1;
}
/* Initializing date_increment */
s64_denominator = (s64)p_adec->p_aout_fifo->l_rate;
switch ( (p_adec->bit_stream.fifo.buffer & ADEC_HEADER_LAYER_MASK) >> ADEC_HEADER_LAYER_SHIFT )
{
/* Layer 2 */
case 2:
s64_numerator = 1152 * 1000000;
break;
/* Layer 1 */
case 3:
s64_numerator = 384 * 1000000;
break;
}
date_increment.l_remainder = -(long)s64_denominator;
date_increment.l_euclidean_integer = 0;
while ( s64_numerator >= s64_denominator )
{
date_increment.l_euclidean_integer++;
s64_numerator -= s64_denominator;
}
date_increment.l_euclidean_remainder = (long)s64_numerator;
date_increment.l_euclidean_denominator = (long)s64_denominator;
/* Audio decoder thread's main loop */
while ( (!p_adec->b_die) && (!p_adec->b_error) )
{
......@@ -893,8 +853,15 @@ static void RunThread( adec_thread_t * p_adec )
{
pthread_mutex_lock( &p_adec->p_aout_fifo->data_lock );
/* Frame 1 */
p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] = date; /* DECODER_FIFO_START(p_adec->fifo)->i_pts; */
/* DECODER_FIFO_START(p_adec->fifo)->i_pts = LAST_MDATE; */
if ( DECODER_FIFO_START(p_adec->fifo)->b_has_pts )
{
p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] = DECODER_FIFO_START(p_adec->fifo)->i_pts;
DECODER_FIFO_START(p_adec->fifo)->b_has_pts = 0;
}
else
{
p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] = LAST_MDATE;
}
p_adec->p_aout_fifo->l_end_frame = (p_adec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
/* Frame 2 */
p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] = LAST_MDATE;
......@@ -912,7 +879,6 @@ static void RunThread( adec_thread_t * p_adec )
p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] = LAST_MDATE;
p_adec->p_aout_fifo->l_end_frame = (p_adec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
pthread_mutex_unlock( &p_adec->p_aout_fifo->data_lock );
UPDATE_INCREMENT( date_increment, date )
}
}
break;
......
......@@ -52,7 +52,7 @@ void aout_Thread_S16_Stereo ( aout_thread_t * p_aout );
void aout_Thread_U16_Stereo ( aout_thread_t * p_aout );
static __inline__ void InitializeIncrement( aout_increment_t * p_increment, long l_numerator, long l_denominator );
static __inline__ int NextFrame( aout_thread_t * p_aout, aout_fifo_t * p_fifo );
static __inline__ int NextFrame( aout_thread_t * p_aout, aout_fifo_t * p_fifo, mtime_t aout_date );
/******************************************************************************
* aout_Open
......@@ -426,7 +426,7 @@ static __inline__ void InitializeIncrement( aout_increment_t * p_increment, long
/******************************************************************************
* NextFrame
******************************************************************************/
static __inline__ int NextFrame( aout_thread_t * p_aout, aout_fifo_t * p_fifo )
static __inline__ int NextFrame( aout_thread_t * p_aout, aout_fifo_t * p_fifo, mtime_t aout_date )
{
long l_units, l_rate;
......@@ -453,15 +453,30 @@ static __inline__ int NextFrame( aout_thread_t * p_aout, aout_fifo_t * p_fifo )
}
}
if ( aout_date < p_fifo->date[p_fifo->l_start_frame] )
{
fprintf(stderr, "+");
pthread_mutex_unlock( &p_fifo->data_lock );
return( -1 );
}
/* We are looking for the next dated frame */
while ( p_fifo->l_next_frame != p_fifo->l_end_frame )
{
if ( p_fifo->date[p_fifo->l_next_frame] != LAST_MDATE )
{
p_fifo->b_next_frame = 1;
break;
if ( aout_date < p_fifo->date[p_fifo->l_next_frame] )
{
p_fifo->b_next_frame = 1;
break;
}
else
{
fprintf(stderr, "-");
p_fifo->l_start_frame = p_fifo->l_next_frame;
}
}
p_fifo->l_next_frame = (p_fifo->l_next_frame + 1) & AOUT_FIFO_SIZE;
p_fifo->l_next_frame = (p_fifo->l_next_frame + 1) & AOUT_FIFO_SIZE;
}
if ( p_fifo->l_next_frame == p_fifo->l_end_frame )
{
......@@ -603,7 +618,7 @@ void aout_Thread_S16_Stereo( aout_thread_t * p_aout )
{
if ( !p_aout->fifo[i_fifo].b_next_frame )
{
if ( NextFrame(p_aout, &p_aout->fifo[i_fifo]) )
if ( NextFrame(p_aout, &p_aout->fifo[i_fifo], p_aout->date + (mtime_t)((l_buffer >> p_aout->dsp.b_stereo) / p_aout->dsp.l_rate)) )
{
break;
}
......@@ -671,7 +686,7 @@ void aout_Thread_S16_Stereo( aout_thread_t * p_aout )
{
if ( !p_aout->fifo[i_fifo].b_next_frame )
{
if ( NextFrame(p_aout, &p_aout->fifo[i_fifo]) )
if ( NextFrame(p_aout, &p_aout->fifo[i_fifo], p_aout->date + (mtime_t)((l_buffer >> p_aout->dsp.b_stereo) / p_aout->dsp.l_rate)) )
{
break;
}
......
......@@ -322,7 +322,7 @@ static void ErrorThread( input_thread_t *p_input )
/*******************************************************************************
* EndThread: end the input thread
*******************************************************************************/
static void EndThread( input_thread_t *p_input )
static void EndThread( input_thread_t * p_input )
{
int i_es_loop;
......@@ -889,30 +889,27 @@ static __inline__ void input_DemuxPES( input_thread_t *p_input,
default:
/* The PES header contains at least 3 more bytes: parse them */
p_pes->b_data_alignment = p_pes->p_pes_header[6] & 0x10;
p_pes->b_has_pts = p_pes->p_pes_header[7] & 0x4;
p_pes->b_data_alignment = p_pes->p_pes_header[6] & 0x04;
p_pes->b_has_pts = p_pes->p_pes_header[7] & 0x80;
i_pes_header_size = 9 + p_pes->p_pes_header[8];
/* Now parse the optional header extensions (in the limit of
the 14 bytes */
if( p_pes->b_has_pts )
{
pcr_descriptor_t *p_pcr;
/* The PTS field is split in 3 bit records. We have to add
them, and thereafter we substract the 2 marker_bits */
pcr_descriptor_t * p_pcr;
p_pcr = p_input->p_pcr;
pthread_mutex_lock( &p_pcr->lock );
if( p_pcr->delta_clock == 0 )
{
p_pes->i_pts = 0;
p_pes->b_has_pts = 0;
}
else
{
p_pes->i_pts = ( ((mtime_t)p_pes->p_pes_header[9] << 29) +
((mtime_t)U16_AT(p_pes->p_pes_header + 10) << 14) +
((mtime_t)U16_AT(p_pes->p_pes_header + 12) >> 1) -
(1 << 14) - (1 << 29) );
p_pes->i_pts = ( ((mtime_t)(p_pes->p_pes_header[9] & 0x0E) << 29) |
(((mtime_t)U16_AT(p_pes->p_pes_header + 10) << 14) - (1 << 14)) |
((mtime_t)U16_AT(p_pes->p_pes_header + 12) >> 1) );
p_pes->i_pts *= 300;
p_pes->i_pts /= 27;
p_pes->i_pts += p_pcr->delta_clock;
......@@ -921,8 +918,8 @@ static __inline__ void input_DemuxPES( input_thread_t *p_input,
p_pcr->delta_decode = mdate() - p_pes->i_pts + 500000;
}
p_pes->i_pts += p_pcr->delta_decode;
p_pcr->c_pts += 1;
}
p_pcr->c_pts += 1;
pthread_mutex_unlock( &p_pcr->lock );
}
break;
......
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