Commit e97f189c authored by Michel Kaempf's avatar Michel Kaempf

* GoldenEye rewlz :

- explications du commit au prochain commit :-)
parent 07f2392f
......@@ -176,12 +176,11 @@ typedef struct aout_thread_s
/* The size of the audio output buffer is kept in audio units, as this is
* the only unit that is common with every audio decoder and audio fifo */
long l_units;
long l_msleep;
mtime_t date;
/* date is the moment where the first audio unit of the output buffer
* should be played and is kept up-to-date with the following incremental
* structure */
aout_increment_t date_increment;
* will be played */
mtime_t date;
} aout_thread_t;
......
......@@ -277,6 +277,7 @@ static void RunThread( ac3dec_thread_t * p_ac3dec )
downmix( p_ac3dec, ((ac3dec_frame_t *)p_ac3dec->p_aout_fifo->buffer)[ p_ac3dec->p_aout_fifo->l_end_frame ] );
vlc_mutex_lock( &p_ac3dec->p_aout_fifo->data_lock );
p_ac3dec->p_aout_fifo->l_end_frame = (p_ac3dec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
vlc_cond_signal( &p_ac3dec->p_aout_fifo->data_wait );
vlc_mutex_unlock( &p_ac3dec->p_aout_fifo->data_lock );
/* frame 2 */
......@@ -297,6 +298,7 @@ static void RunThread( ac3dec_thread_t * p_ac3dec )
p_ac3dec->p_aout_fifo->date[p_ac3dec->p_aout_fifo->l_end_frame] = LAST_MDATE;
vlc_mutex_lock( &p_ac3dec->p_aout_fifo->data_lock );
p_ac3dec->p_aout_fifo->l_end_frame = (p_ac3dec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
vlc_cond_signal( &p_ac3dec->p_aout_fifo->data_wait );
vlc_mutex_unlock( &p_ac3dec->p_aout_fifo->data_lock );
/* frame 3 */
......@@ -317,6 +319,7 @@ static void RunThread( ac3dec_thread_t * p_ac3dec )
p_ac3dec->p_aout_fifo->date[p_ac3dec->p_aout_fifo->l_end_frame] = LAST_MDATE;
vlc_mutex_lock( &p_ac3dec->p_aout_fifo->data_lock );
p_ac3dec->p_aout_fifo->l_end_frame = (p_ac3dec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
vlc_cond_signal( &p_ac3dec->p_aout_fifo->data_wait );
vlc_mutex_unlock( &p_ac3dec->p_aout_fifo->data_lock );
/* frame 4 */
......@@ -337,6 +340,7 @@ static void RunThread( ac3dec_thread_t * p_ac3dec )
p_ac3dec->p_aout_fifo->date[p_ac3dec->p_aout_fifo->l_end_frame] = LAST_MDATE;
vlc_mutex_lock( &p_ac3dec->p_aout_fifo->data_lock );
p_ac3dec->p_aout_fifo->l_end_frame = (p_ac3dec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
vlc_cond_signal( &p_ac3dec->p_aout_fifo->data_wait );
vlc_mutex_unlock( &p_ac3dec->p_aout_fifo->data_lock );
/* frame 5 */
......@@ -357,6 +361,7 @@ static void RunThread( ac3dec_thread_t * p_ac3dec )
p_ac3dec->p_aout_fifo->date[p_ac3dec->p_aout_fifo->l_end_frame] = LAST_MDATE;
vlc_mutex_lock( &p_ac3dec->p_aout_fifo->data_lock );
p_ac3dec->p_aout_fifo->l_end_frame = (p_ac3dec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
vlc_cond_signal( &p_ac3dec->p_aout_fifo->data_wait );
vlc_mutex_unlock( &p_ac3dec->p_aout_fifo->data_lock );
/* frame 6 */
......@@ -377,6 +382,7 @@ static void RunThread( ac3dec_thread_t * p_ac3dec )
p_ac3dec->p_aout_fifo->date[p_ac3dec->p_aout_fifo->l_end_frame] = LAST_MDATE;
vlc_mutex_lock( &p_ac3dec->p_aout_fifo->data_lock );
p_ac3dec->p_aout_fifo->l_end_frame = (p_ac3dec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
vlc_cond_signal( &p_ac3dec->p_aout_fifo->data_wait );
vlc_mutex_unlock( &p_ac3dec->p_aout_fifo->data_lock );
parse_auxdata( p_ac3dec );
......
......@@ -40,7 +40,6 @@
* Local prototypes
******************************************************************************/
static int aout_SpawnThread( aout_thread_t * p_aout );
/* Creating as much aout_Thread functions as configurations is one solution,
......@@ -56,7 +55,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/*, mtime_t aout_date*/ );
static __inline__ int NextFrame( aout_thread_t * p_aout, aout_fifo_t * p_fifo, mtime_t aout_date );
/******************************************************************************
* aout_CreateThread: initialize audio thread
......@@ -138,7 +137,6 @@ static int aout_SpawnThread( aout_thread_t * p_aout )
{
int i_fifo;
long l_bytes;
s64 s64_numerator, s64_denominator;
void * aout_thread = NULL;
intf_DbgMsg("aout debug: spawning audio output thread (%p)\n", p_aout);
......@@ -160,6 +158,7 @@ static int aout_SpawnThread( aout_thread_t * p_aout )
* AOUT_BUFFER_DURATION is given in microseconds, the output rate is given
* in Hz, that's why we need to divide by 10^6 microseconds (1 second) */
p_aout->l_units = (long)( ((s64)p_aout->dsp.l_rate * AOUT_BUFFER_DURATION) / 1000000 );
p_aout->l_msleep = ((s64)p_aout->l_units * 1000000) / (s64)p_aout->dsp.l_rate;
/* Make aout_thread point to the right thread function, and compute the
* byte size of the audio output buffer */
......@@ -251,24 +250,6 @@ static int aout_SpawnThread( aout_thread_t * p_aout )
return( -1 );
}
/* Initialize the incremental structure that is used to work out the date
* of the first audio unit in the output buffer */
s64_numerator = (s64)p_aout->l_units * 1000000;
s64_denominator = (s64)p_aout->dsp.l_rate;
p_aout->date_increment.l_remainder = -(long)s64_denominator;
p_aout->date_increment.l_euclidean_integer = 0;
while ( s64_numerator >= s64_denominator )
{
p_aout->date_increment.l_euclidean_integer++;
s64_numerator -= s64_denominator;
}
p_aout->date_increment.l_euclidean_remainder = (long)s64_numerator;
p_aout->date_increment.l_euclidean_denominator = (long)s64_denominator;
/* Before launching the thread, we try to predict the date of the first
* audio unit in the first output buffer */
p_aout->date = mdate();
......@@ -391,7 +372,6 @@ aout_fifo_t * aout_CreateFifo( aout_thread_t * p_aout, aout_fifo_t * p_fifo )
* out the fifo's current rate (as soon as the decoder has decoded
* enough frames, the members of the fifo structure that are not
* initialized now will be calculated) */
p_aout->fifo[i_fifo].l_unit = 0; /* !! */
p_aout->fifo[i_fifo].b_start_frame = 0;
p_aout->fifo[i_fifo].b_next_frame = 0;
break;
......@@ -457,7 +437,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/*, mtime_t aout_date*/ )
static __inline__ int NextFrame( aout_thread_t * p_aout, aout_fifo_t * p_fifo, mtime_t aout_date )
{
long l_units, l_rate;
......@@ -473,6 +453,7 @@ static __inline__ int NextFrame( aout_thread_t * p_aout, aout_fifo_t * p_fifo/*,
{
p_fifo->b_start_frame = 1;
p_fifo->l_next_frame = (p_fifo->l_start_frame + 1) & AOUT_FIFO_SIZE;
p_fifo->l_unit = p_fifo->l_start_frame * (p_fifo->l_frame_size >> p_fifo->b_stereo);
break;
}
p_fifo->l_start_frame = (p_fifo->l_start_frame + 1) & AOUT_FIFO_SIZE;
......@@ -483,24 +464,25 @@ static __inline__ int NextFrame( aout_thread_t * p_aout, aout_fifo_t * p_fifo/*,
return( -1 );
}
}
/*
if ( aout_date < p_fifo->date[p_fifo->l_start_frame] )
#if 0
if ( aout_date < p_fifo->date[p_fifo->l_start_frame] - 100000 )
{
fprintf(stderr, "+");
fprintf( stderr, "-" );
p_fifo->l_dr = 0;
vlc_mutex_unlock( &p_fifo->data_lock );
return( -1 );
}
*/
#endif
/* We are looking for the next dated frame */
while ( 1 )
{
while ( p_fifo->l_next_frame != p_fifo->l_end_frame )
{
if ( p_fifo->date[p_fifo->l_next_frame] != LAST_MDATE )
{
/*
if ( aout_date < p_fifo->date[p_fifo->l_next_frame] )
{
*/
#if 0
if ( p_fifo->date[p_fifo->l_start_frame] >= p_fifo->date[p_fifo->l_next_frame] )
{
fprintf( stderr, "aout debug: %lli >= %lli\n", p_fifo->date[p_fifo->l_start_frame], p_fifo->date[p_fifo->l_next_frame] );
......@@ -512,23 +494,55 @@ static __inline__ int NextFrame( aout_thread_t * p_aout, aout_fifo_t * p_fifo/*,
fprintf( stderr, "aout debug: (%lli - %lli) > 1000000\n", p_fifo->date[p_fifo->l_next_frame], p_fifo->date[p_fifo->l_start_frame] );
p_fifo->date[p_fifo->l_start_frame] = p_fifo->date[p_fifo->l_next_frame] - ((1000000 * ((mtime_t)(p_fifo->l_frame_size * ((p_fifo->l_next_frame - p_fifo->l_start_frame) & AOUT_FIFO_SIZE))) >> p_fifo->b_stereo) / ((mtime_t)p_fifo->l_rate));
}
p_fifo->b_next_frame = 1;
break;
/*
#endif
#if 0
if ( aout_date < p_fifo->date[p_fifo->l_next_frame] + 100000 )
{
#endif
p_fifo->b_next_frame = 1;
break;
#if 0
}
else
{
fprintf(stderr, "-");
fprintf( stderr, "+" );
// p_fifo->b_next_frame = 1;
// break;
p_fifo->l_start_frame = p_fifo->l_next_frame;
p_fifo->l_unit = p_fifo->l_start_frame * (p_fifo->l_frame_size >> p_fifo->b_stereo);
p_fifo->l_dr = 0;
}
*/
#endif
}
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 )
{
if ( (((p_fifo->l_end_frame + 1) - p_fifo->l_start_frame) & AOUT_FIFO_SIZE) == 0 )
{
fprintf( stderr, "aout debug: synkro suxx rocks;\n" );
p_fifo->l_start_frame = 0;
p_fifo->b_start_frame = 0;
/* p_fifo->l_next_frame = 0; */
/* p_fifo->b_next_frame = 0; */
p_fifo->l_end_frame = 0;
vlc_mutex_unlock( &p_fifo->data_lock );
return( -1 );
}
while ( p_fifo->l_next_frame == p_fifo->l_end_frame )
{
vlc_cond_wait(&p_fifo->data_wait, &p_fifo->data_lock);
}
}
else
{
break;
}
}
#if 0
if ( p_fifo->l_next_frame == p_fifo->l_end_frame )
{
fprintf( stderr, "aout debug: synkro suxx rocks (%li);\n", p_fifo->l_dr );
if ( (((p_fifo->l_end_frame + 1) - p_fifo->l_start_frame) & AOUT_FIFO_SIZE) == 0 )
{
p_fifo->l_start_frame = 0;
......@@ -540,12 +554,45 @@ static __inline__ int NextFrame( aout_thread_t * p_aout, aout_fifo_t * p_fifo/*,
vlc_mutex_unlock( &p_fifo->data_lock );
return( -1 );
}
#endif
l_units = ((p_fifo->l_next_frame - p_fifo->l_start_frame) & AOUT_FIFO_SIZE) * (p_fifo->l_frame_size >> p_fifo->b_stereo);
// fprintf( stderr, "%li", p_fifo->l_unit - (p_fifo->l_start_frame * (p_fifo->l_frame_size >> p_fifo->b_stereo)) );
#if 0
// fprintf( stderr, "aout debug: %lli;\n", aout_date - p_fifo->date[p_fifo->l_start_frame] );
if ( /*(p_fifo->date[p_fifo->l_start_frame] < aout_date) &&*/ (aout_date < p_fifo->date[p_fifo->l_next_frame]) )
{
fprintf( stderr, "*" );
l_rate = (long)(((mtime_t)l_units * 1000000) / (p_fifo->date[p_fifo->l_next_frame] - aout_date));
}
else
{
l_rate = (long)(((mtime_t)l_units * 1000000) / (p_fifo->date[p_fifo->l_next_frame] - p_fifo->date[p_fifo->l_start_frame]));
}
#endif
// l_rate = (long)( ((mtime_t)l_units * 1000000) / (p_fifo->date[p_fifo->l_next_frame] - ((p_fifo->date[p_fifo->l_start_frame] + aout_date) / 2)) );
// fprintf( stderr, "aout debug: l_rate == %li;\n", l_rate );
// fprintf( stderr, "aout debug: %li;\n", l_rate );
// fprintf( stderr, "aout debug: %lli, %li, %lli;\n", aout_date - p_fifo->date[p_fifo->l_start_frame], p_fifo->l_unit - (p_fifo->l_start_frame * (p_fifo->l_frame_size >> p_fifo->b_stereo)), p_fifo->date[p_fifo->l_next_frame] - aout_date );
/*
if ( aout_date < p_fifo->date[p_fifo->l_start_frame] )
{
p_fifo->l_dr -= 1;
}
else if ( p_fifo->date[p_fifo->l_start_frame] < aout_date )
{
p_fifo->l_dr += 1;
}
*/
l_rate = p_fifo->l_rate + ((aout_date - p_fifo->date[p_fifo->l_start_frame]) / 8);
// l_rate = (long)(((mtime_t)l_units * 1000000) / (p_fifo->date[p_fifo->l_next_frame] - p_fifo->date[p_fifo->l_start_frame])) + p_fifo->l_dr;
// fprintf( stderr, "aout debug: l_rate == %li (%lli);\n", l_rate /*+ p_fifo->l_dr*/, aout_date - p_fifo->date[p_fifo->l_start_frame] );
l_rate = (long)( ((mtime_t)l_units * 1000000)
/ (p_fifo->date[p_fifo->l_next_frame] - p_fifo->date[p_fifo->l_start_frame]) );
// fprintf( stderr, "aout debug: l_rate == %li\n", l_rate );
// p_fifo->delta += aout_date - p_fifo->date[p_fifo->l_start_frame];
// p_fifo->n += 1;
// fprintf( stderr, "aout debug: %lli, %lli, %li;\n", aout_date - p_fifo->date[p_fifo->l_start_frame], p_fifo->delta/p_fifo->n, l_rate );
InitializeIncrement( &p_fifo->unit_increment, l_rate, p_aout->dsp.l_rate );
......@@ -581,8 +628,8 @@ void aout_Thread_S16_Mono( aout_thread_t * p_aout )
void aout_Thread_S16_Stereo( aout_thread_t * p_aout )
{
int i_fifo;
long l_units;
long l_buffer, l_buffer_limit;
long l_units, l_bytes;
intf_DbgMsg("adec debug: running audio output thread (%p) (pid == %i)\n", p_aout, getpid());
......@@ -599,14 +646,6 @@ void aout_Thread_S16_Stereo( aout_thread_t * p_aout )
break;
case AOUT_INTF_MONO_FIFO:
if ( p_aout->fifo[i_fifo].b_die )
{
free( p_aout->fifo[i_fifo].buffer ); /* !! */
p_aout->fifo[i_fifo].i_type = AOUT_EMPTY_FIFO; /* !! */
intf_DbgMsg("aout debug: audio output fifo (%p) destroyed\n", &p_aout->fifo[i_fifo]);
continue;
}
if ( p_aout->fifo[i_fifo].l_units > p_aout->l_units )
{
l_buffer = 0;
......@@ -638,14 +677,6 @@ void aout_Thread_S16_Stereo( aout_thread_t * p_aout )
break;
case AOUT_INTF_STEREO_FIFO:
if ( p_aout->fifo[i_fifo].b_die )
{
free( p_aout->fifo[i_fifo].buffer ); /* !! */
p_aout->fifo[i_fifo].i_type = AOUT_EMPTY_FIFO; /* !! */
intf_DbgMsg("aout debug: audio output fifo (%p) destroyed\n", &p_aout->fifo[i_fifo]);
continue;
}
if ( p_aout->fifo[i_fifo].l_units > p_aout->l_units )
{
l_buffer = 0;
......@@ -692,7 +723,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]/*, p_aout->date + (mtime_t)((l_buffer >> p_aout->dsp.b_stereo) / p_aout->dsp.l_rate)*/) )
if ( NextFrame(p_aout, &p_aout->fifo[i_fifo], p_aout->date + ((((mtime_t)(l_buffer >> 1)) * 1000000) / ((mtime_t)p_aout->dsp.l_rate))) )
{
break;
}
......@@ -769,7 +800,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]/*, p_aout->date + (mtime_t)((l_buffer >> p_aout->dsp.b_stereo) / p_aout->dsp.l_rate)*/) )
if ( NextFrame(p_aout, &p_aout->fifo[i_fifo], p_aout->date + ((((mtime_t)(l_buffer >> 1)) * 1000000) / ((mtime_t)p_aout->dsp.l_rate))) )
{
break;
}
......@@ -846,10 +877,18 @@ void aout_Thread_S16_Stereo( aout_thread_t * p_aout )
}
aout_dspGetBufInfo( &p_aout->dsp );
l_bytes = (p_aout->dsp.buf_info.fragstotal * p_aout->dsp.buf_info.fragsize) - p_aout->dsp.buf_info.bytes;
p_aout->date = mdate() + ((((mtime_t)(l_bytes / 4)) * 1000000) / ((mtime_t)p_aout->dsp.l_rate)); /* sizeof(s16) << p_aout->dsp.b_stereo == 4 */
aout_dspPlaySamples( &p_aout->dsp, (byte_t *)p_aout->buffer, l_buffer_limit * sizeof(s16) );
if ( l_bytes > (l_buffer_limit * sizeof(s16)) )
{
msleep( p_aout->l_msleep );
}
#if 0
if ( p_aout->dsp.buf_info.fragments == p_aout->dsp.buf_info.fragstotal ) /* ?? */
{
aout_dspPlaySamples( &p_aout->dsp, (byte_t *)p_aout->buffer, sizeof(s16) * l_buffer_limit );
p_aout->date = mdate();
aout_dspPlaySamples( &p_aout->dsp, (byte_t *)p_aout->buffer, sizeof(s16) * l_buffer_limit );
}
else if ( p_aout->dsp.buf_info.bytes >=
((p_aout->dsp.buf_info.fragsize * p_aout->dsp.buf_info.fragstotal) -
......@@ -859,10 +898,14 @@ void aout_Thread_S16_Stereo( aout_thread_t * p_aout )
}
else
{
fprintf( stderr, "%lli\n", mdate() - date );
date = mdate();
aout_dspPlaySamples( &p_aout->dsp, (byte_t *)p_aout->buffer, sizeof(s16) * l_buffer_limit );
// fprintf( stderr, "%lli\n", (date + ((((mtime_t)((p_aout->dsp.buf_info.fragstotal * p_aout->dsp.buf_info.fragsize - p_aout->dsp.buf_info.bytes) / 4)) * 1000000)/((mtime_t)p_aout->dsp.l_rate))) - p_aout->date );
msleep( p_aout->date_increment.l_euclidean_integer );
}
UPDATE_INCREMENT( p_aout->date_increment, p_aout->date )
#endif
}
vlc_mutex_lock( &p_aout->fifos_lock );
......
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