Commit b616e265 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

aout: move pre-packetization FIFO handling to output

parent 06e1cd04
......@@ -82,15 +82,12 @@ struct aout_input_t
/* */
int i_buffer_lost;
/* */
mtime_t i_pause_date;
/* */
bool b_recycle_vout;
aout_request_vout_t request_vout;
/* */
aout_fifo_t fifo;
date_t date;
};
typedef struct
......@@ -114,6 +111,9 @@ typedef struct
/* Indicates whether the audio output is currently starving, to avoid
* printing a 1,000 "output is starving" messages. */
bool b_starving;
mtime_t pause_date;
aout_fifo_t partial;
} aout_owner_t;
typedef struct
......
......@@ -62,7 +62,6 @@ audio_output_t *aout_New( vlc_object_t * p_parent )
vlc_mutex_init (&owner->volume.lock);
owner->volume.multiplier = 1.0;
owner->volume.mixer = NULL;
owner->b_starving = true;
vlc_mutex_init (&aout->lock);
......
......@@ -82,7 +82,6 @@ aout_input_t *aout_DecNew( audio_output_t *p_aout,
return NULL;
p_input->b_error = true;
p_input->i_pause_date = VLC_TS_INVALID;
aout_FormatPrepare( p_format );
......@@ -239,27 +238,16 @@ void aout_DecChangePause( audio_output_t *p_aout, aout_input_t *p_input, bool b_
aout_lock( p_aout );
assert (owner->input == p_input);
/* XXX: Should the input date be offset by the pause duration instead? */
date_Set (&p_input->date, VLC_TS_INVALID);
aout_OutputPause( p_aout, b_paused, i_date );
if( b_paused )
{
p_input->i_pause_date = i_date;
}
else
{
assert( p_input->i_pause_date != VLC_TS_INVALID );
mtime_t i_duration = i_date - p_input->i_pause_date;
p_input->i_pause_date = VLC_TS_INVALID;
aout_FifoMoveDates( &p_input->fifo, i_duration );
}
aout_unlock( p_aout );
}
void aout_DecFlush( audio_output_t *p_aout, aout_input_t *p_input )
{
aout_lock( p_aout );
aout_FifoReset( &p_input->fifo );
date_Set (&p_input->date, VLC_TS_INVALID);
aout_OutputFlush( p_aout, false );
aout_unlock( p_aout );
}
......@@ -269,7 +257,8 @@ bool aout_DecIsEmpty( audio_output_t * p_aout, aout_input_t * p_input )
mtime_t end_date;
aout_lock( p_aout );
end_date = aout_FifoNextStart( &p_input->fifo );
/* FIXME: tell output to drain */
end_date = date_Get (&p_input->date);
aout_unlock( p_aout );
return end_date == VLC_TS_INVALID || end_date <= mdate();
}
......@@ -81,8 +81,8 @@ int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_r
p_input->i_nb_resamplers = p_input->i_nb_filters = 0;
/* Prepare FIFO. */
aout_FifoInit (p_aout, &p_input->fifo, owner->mixer_format.i_rate);
date_Init (&p_input->date, owner->mixer_format.i_rate, 1);
date_Set (&p_input->date, VLC_TS_INVALID);
/* */
if( p_request_vout )
......@@ -447,7 +447,6 @@ int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input )
aout_FiltersDestroyPipeline( p_input->pp_resamplers,
p_input->i_nb_resamplers );
p_input->i_nb_resamplers = 0;
aout_FifoDestroy( &p_input->fifo );
return 0;
}
......@@ -459,25 +458,18 @@ int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input )
*****************************************************************************/
void aout_InputCheckAndRestart( audio_output_t * p_aout, aout_input_t * p_input )
{
aout_owner_t *owner = aout_owner (p_aout);
AOUT_ASSERT_LOCKED;
if( !p_input->b_restart )
return;
/* A little trick to avoid loosing our input fifo and properties */
aout_fifo_t fifo = p_input->fifo;
mtime_t i_pause_date = p_input->i_pause_date;
aout_FifoInit (p_aout, &p_input->fifo, owner->mixer_format.i_rate);
/* A little trick to avoid loosing our input properties */
date_t date = p_input->date;
aout_InputDelete( p_aout, p_input );
aout_InputNew( p_aout, p_input, &p_input->request_vout );
p_input->fifo = fifo;
p_input->i_pause_date = i_pause_date;
p_input->date = date;
p_input->b_restart = false;
}
/*****************************************************************************
......@@ -540,7 +532,7 @@ block_t *aout_InputPlay( audio_output_t *p_aout, aout_input_t *p_input,
/* We don't care if someone changes the start date behind our back after
* this. We'll deal with that when pushing the buffer, and compensate
* with the next incoming buffer. */
start_date = aout_FifoNextStart( &p_input->fifo );
start_date = date_Get (&p_input->date);
if ( start_date != VLC_TS_INVALID && start_date < now )
{
......@@ -549,7 +541,6 @@ block_t *aout_InputPlay( audio_output_t *p_aout, aout_input_t *p_input,
* happen :). */
msg_Warn( p_aout, "computed PTS is out of range (%"PRId64"), "
"clearing out", now - start_date );
aout_FifoReset( &p_input->fifo );
aout_OutputFlush( p_aout, false );
if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE )
msg_Warn( p_aout, "timing screwed, stopping resampling" );
......@@ -572,7 +563,10 @@ block_t *aout_InputPlay( audio_output_t *p_aout, aout_input_t *p_input,
/* If the audio drift is too big then it's not worth trying to resample
* the audio. */
if( start_date == VLC_TS_INVALID )
{
start_date = p_buffer->i_pts;
date_Set (&p_input->date, start_date);
}
mtime_t drift = start_date - p_buffer->i_pts;
......@@ -580,13 +574,13 @@ block_t *aout_InputPlay( audio_output_t *p_aout, aout_input_t *p_input,
{
msg_Warn( p_aout, "buffer way too early (%"PRId64"), clearing queue",
drift );
aout_FifoReset( &p_input->fifo );
aout_OutputFlush( p_aout, false );
if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE )
msg_Warn( p_aout, "timing screwed, stopping resampling" );
inputResamplingStop( p_input );
p_buffer->i_flags |= BLOCK_FLAG_DISCONTINUITY;
start_date = p_buffer->i_pts;
date_Set (&p_input->date, start_date);
drift = 0;
}
else
......@@ -692,8 +686,8 @@ block_t *aout_InputPlay( audio_output_t *p_aout, aout_input_t *p_input,
}
#endif
/* Adding the start date will be managed by aout_FifoPush(). */
p_buffer->i_pts = start_date;
date_Increment (&p_input->date, p_buffer->i_nb_samples);
return p_buffer;
}
......@@ -711,7 +705,6 @@ static void inputFailure( audio_output_t * p_aout, aout_input_t * p_input,
aout_FiltersDestroyPipeline( p_input->pp_filters, p_input->i_nb_filters );
aout_FiltersDestroyPipeline( p_input->pp_resamplers,
p_input->i_nb_resamplers );
aout_FifoDestroy( &p_input->fifo );
var_Destroy( p_aout, "visual" );
var_Destroy( p_aout, "equalizer" );
var_Destroy( p_aout, "audio-filter" );
......
......@@ -159,10 +159,13 @@ int aout_OutputNew( audio_output_t *p_aout,
var_TriggerCallback( p_aout, "intf-change" );
aout_FormatPrepare( &p_aout->format );
aout_FormatPrint( p_aout, "output", &p_aout->format );
/* Prepare FIFO. */
aout_FifoInit( p_aout, &p_aout->fifo, p_aout->format.i_rate );
aout_FormatPrint( p_aout, "output", &p_aout->format );
aout_FifoInit (p_aout, &p_aout->fifo, p_aout->format.i_rate);
aout_FifoInit (p_aout, &owner->partial, p_aout->format.i_rate);
owner->pause_date = VLC_TS_INVALID;
owner->b_starving = true;
/* Choose the mixer format. */
owner->mixer_format = p_aout->format;
......@@ -218,7 +221,8 @@ void aout_OutputDelete( audio_output_t * p_aout )
aout_VolumeNoneInit( p_aout ); /* clear volume callback */
owner->module = NULL;
aout_FiltersDestroyPipeline (owner->filters, owner->nb_filters);
aout_FifoDestroy( &p_aout->fifo );
aout_FifoDestroy (&p_aout->fifo);
aout_FifoDestroy (&owner->partial);
}
static block_t *aout_OutputSlice( audio_output_t *, aout_fifo_t * );
......@@ -243,11 +247,9 @@ void aout_OutputPlay( audio_output_t * p_aout, aout_buffer_t * p_buffer )
return;
}
aout_fifo_t *fifo = &owner->input->fifo;
/* XXX: cleanup */
aout_FifoPush( fifo, p_buffer );
aout_FifoPush (&owner->partial, p_buffer );
while( (p_buffer = aout_OutputSlice( p_aout, fifo ) ) != NULL )
while ((p_buffer = aout_OutputSlice (p_aout, &owner->partial)) != NULL)
{
aout_FifoPush( &p_aout->fifo, p_buffer );
p_aout->pf_play( p_aout );
......@@ -261,17 +263,24 @@ void aout_OutputPlay( audio_output_t * p_aout, aout_buffer_t * p_buffer )
*/
void aout_OutputPause( audio_output_t *aout, bool pause, mtime_t date )
{
aout_owner_t *owner = aout_owner (aout);
vlc_assert_locked( &aout->lock );
if( aout->pf_pause != NULL )
aout->pf_pause( aout, pause, date );
if( !pause )
aout_owner_t *owner = aout_owner (aout);
if (pause)
{
mtime_t duration = date - owner->input->i_pause_date;
/* XXX: ^ onk onk! gruik! ^ */
aout_FifoMoveDates( &aout->fifo, duration );
owner->pause_date = date;
}
else
{
assert (owner->pause_date != VLC_TS_INVALID);
mtime_t duration = date - owner->pause_date;
owner->pause_date = VLC_TS_INVALID;
aout_FifoMoveDates (&owner->partial, duration);
aout_FifoMoveDates (&aout->fifo, duration);
}
}
......@@ -287,7 +296,10 @@ void aout_OutputFlush( audio_output_t *aout, bool wait )
if( aout->pf_flush != NULL )
aout->pf_flush( aout, wait );
aout_FifoReset( &aout->fifo );
aout_owner_t *owner = aout_owner (aout);
aout_FifoReset (&aout->fifo);
aout_FifoReset (&owner->partial);
}
......@@ -609,8 +621,8 @@ aout_buffer_t * aout_OutputNextBuffer( audio_output_t * p_aout,
msg_Warn( p_aout, "output date isn't PTS date, requesting "
"resampling (%"PRId64")", delta );
aout_FifoMoveDates (&owner->input->fifo, delta);
aout_FifoMoveDates( p_fifo, delta );
aout_FifoMoveDates (&owner->partial, delta);
aout_FifoMoveDates (p_fifo, delta);
}
out:
aout_unlock( p_aout );
......
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