Commit 87b5a350 authored by Laurent Aimar's avatar Laurent Aimar

Moved a few aout tests+statistics to decoder.

It allows removing an ugly input dependency in aout as well as finer control
at decoder side.
parent 647d418b
......@@ -251,9 +251,6 @@ struct aout_input_t
* third-party. */
vlc_mutex_t lock;
/* The input thread that spawned this input */
input_thread_t *p_input_thread;
audio_sample_format_t input;
aout_alloc_t input_alloc;
......@@ -288,9 +285,10 @@ struct aout_input_t
/* last rate from input */
int i_last_input_rate;
/* internal caching delay from input */
int i_pts_delay;
};
/* */
int i_buffer_lost;
};
/** an output stream for the audio output */
typedef struct aout_output_t
......
......@@ -139,6 +139,7 @@ int aout_DecDelete ( aout_instance_t *, aout_input_t * );
aout_buffer_t * aout_DecNewBuffer( aout_input_t *, size_t );
void aout_DecDeleteBuffer( aout_instance_t *, aout_input_t *, aout_buffer_t * );
int aout_DecPlay( aout_instance_t *, aout_input_t *, aout_buffer_t *, int i_input_rate );
int aout_DecGetResetLost( aout_instance_t *, aout_input_t * );
/* Helpers */
......
......@@ -39,9 +39,6 @@
#include "aout_internal.h"
/** FIXME: Ugly but needed to access the counters */
#include "input/input_internal.h"
/*****************************************************************************
* aout_DecNew : create a decoder
*****************************************************************************/
......@@ -50,7 +47,6 @@ static aout_input_t * DecNew( vlc_object_t * p_this, aout_instance_t * p_aout,
audio_replay_gain_t *p_replay_gain )
{
aout_input_t * p_input;
input_thread_t * p_input_thread;
/* Sanitize audio format */
if( p_format->i_channels > 32 )
......@@ -156,20 +152,6 @@ static aout_input_t * DecNew( vlc_object_t * p_this, aout_instance_t * p_aout,
aout_unlock_mixer( p_aout );
p_input_thread = (input_thread_t *)vlc_object_find( p_this,
VLC_OBJECT_INPUT, FIND_PARENT );
if( p_input_thread )
{
p_input->i_pts_delay = p_input_thread->i_pts_delay;
p_input->p_input_thread = p_input_thread;
vlc_object_release( p_input_thread );
}
else
{
p_input->i_pts_delay = DEFAULT_PTS_DELAY;
p_input->p_input_thread = NULL;
}
return p_input;
error:
......@@ -313,41 +295,10 @@ void aout_DecDeleteBuffer( aout_instance_t * p_aout, aout_input_t * p_input,
int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input,
aout_buffer_t * p_buffer, int i_input_rate )
{
if ( p_buffer->start_date == 0 )
{
msg_Warn( p_aout, "non-dated buffer received" );
aout_BufferFree( p_buffer );
return -1;
}
assert( i_input_rate >= INPUT_RATE_DEFAULT / AOUT_MAX_INPUT_RATE &&
i_input_rate <= INPUT_RATE_DEFAULT * AOUT_MAX_INPUT_RATE );
#ifndef FIXME
/* This hack for #transcode{acodec=...}:display to work -- Courmisch */
if( i_input_rate == 0 )
i_input_rate = INPUT_RATE_DEFAULT;
#endif
if( i_input_rate > INPUT_RATE_DEFAULT * AOUT_MAX_INPUT_RATE ||
i_input_rate < INPUT_RATE_DEFAULT / AOUT_MAX_INPUT_RATE )
{
aout_BufferFree( p_buffer );
return 0;
}
if ( p_buffer->start_date > mdate() + p_input->i_pts_delay +
AOUT_MAX_ADVANCE_TIME )
{
msg_Warn( p_aout, "received buffer in the future (%"PRId64")",
p_buffer->start_date - mdate());
if( p_input->p_input_thread )
{
vlc_mutex_lock( &p_input->p_input_thread->p->counters.counters_lock);
stats_UpdateInteger( p_aout,
p_input->p_input_thread->p->counters.p_lost_abuffers,
1, NULL );
vlc_mutex_unlock( &p_input->p_input_thread->p->counters.counters_lock);
}
aout_BufferFree( p_buffer );
return -1;
}
assert( p_buffer->start_date > 0 );
p_buffer->end_date = p_buffer->start_date
+ (mtime_t)p_buffer->i_nb_samples * 1000000
......@@ -355,14 +306,14 @@ int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input,
aout_lock_input( p_aout, p_input );
if ( p_input->b_error )
if( p_input->b_error )
{
aout_unlock_input( p_aout, p_input );
aout_BufferFree( p_buffer );
return -1;
}
if ( p_input->b_changed )
if( p_input->b_changed )
{
/* Maybe the allocation size has changed. Re-allocate a buffer. */
aout_buffer_t * p_new_buffer;
......@@ -381,27 +332,30 @@ int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input,
p_input->b_changed = 0;
}
/* If the buffer is too early, wait a while. */
mwait( p_buffer->start_date - AOUT_MAX_PREPARE_TIME );
int ret = aout_InputPlay( p_aout, p_input, p_buffer, i_input_rate );
int i_ret = aout_InputPlay( p_aout, p_input, p_buffer, i_input_rate );
aout_unlock_input( p_aout, p_input );
if ( ret == -1 ) return -1;
if( i_ret == -1 )
return -1;
/* Run the mixer if it is able to run. */
aout_lock_mixer( p_aout );
aout_MixerRun( p_aout );
if( p_input->p_input_thread )
{
vlc_mutex_lock( &p_input->p_input_thread->p->counters.counters_lock);
stats_UpdateInteger( p_aout,
p_input->p_input_thread->p->counters.p_played_abuffers,
1, NULL );
vlc_mutex_unlock( &p_input->p_input_thread->p->counters.counters_lock);
}
aout_unlock_mixer( p_aout );
return 0;
}
int aout_DecGetResetLost( aout_instance_t *p_aout, aout_input_t *p_input )
{
aout_lock_input( p_aout, p_input );
int i_value = p_input->i_buffer_lost;
p_input->i_buffer_lost = 0;
aout_unlock_input( p_aout, p_input );
return i_value;
}
......@@ -42,12 +42,10 @@
# include <alloca.h>
#endif
#include <vlc_aout.h>
#include <libvlc.h>
#include "aout_internal.h"
/** FIXME: Ugly but needed to access the counters */
#include "input/input_internal.h"
#define AOUT_ASSERT_MIXER_LOCKED vlc_assert_locked( &p_aout->mixer_lock )
#define AOUT_ASSERT_INPUT_LOCKED vlc_assert_locked( &p_input->lock )
......@@ -759,12 +757,7 @@ static void inputDrop( aout_instance_t *p_aout, aout_input_t *p_input, aout_buff
{
aout_BufferFree( p_buffer );
if( !p_input->p_input_thread )
return;
vlc_mutex_lock( &p_input->p_input_thread->p->counters.counters_lock);
stats_UpdateInteger( p_aout, p_input->p_input_thread->p->counters.p_lost_abuffers, 1, NULL );
vlc_mutex_unlock( &p_input->p_input_thread->p->counters.counters_lock);
p_input->i_buffer_lost++;
}
static void inputResamplingStop( aout_input_t *p_input )
......
......@@ -140,11 +140,6 @@ static int MixBuffer( aout_instance_t * p_aout )
"trashing", mdate() - p_buffer->start_date );
p_buffer = aout_FifoPop( p_aout, p_fifo );
aout_BufferFree( p_buffer );
if( p_input->p_input_thread )
{
// stats_UpdateInteger( p_input->p_input_thread,
// "lost_abuffers", 1 );
}
p_buffer = p_fifo->p_first;
p_input->p_first_byte_to_mix = NULL;
}
......@@ -202,11 +197,6 @@ static int MixBuffer( aout_instance_t * p_aout )
msg_Warn( p_aout, "the mixer got a packet in the past (%"PRId64")",
start_date - p_buffer->end_date );
aout_BufferFree( p_buffer );
if( p_input->p_input_thread )
{
// stats_UpdateInteger( p_input->p_input_thread,
// "lost_abuffers", 1 );
}
p_fifo->p_first = p_buffer = p_next;
p_input->p_first_byte_to_mix = NULL;
}
......
......@@ -808,11 +808,17 @@ static void DecoderDecodeAudio( decoder_t *p_dec, block_t *p_block )
input_thread_t *p_input = p_owner->p_input;
input_clock_t *p_clock = p_owner->p_clock;
aout_buffer_t *p_aout_buf;
int i_decoded = 0;
int i_lost = 0;
int i_played = 0;
while( (p_aout_buf = p_dec->pf_decode_audio( p_dec, &p_block )) )
{
aout_instance_t *p_aout = p_owner->p_aout;
aout_input_t *p_aout_input = p_owner->p_aout_input;
int i_rate;
int i_lost;
int i_played;
if( p_dec->b_die )
{
......@@ -822,9 +828,7 @@ static void DecoderDecodeAudio( decoder_t *p_dec, block_t *p_block )
block_Release( p_block );
break;
}
vlc_mutex_lock( &p_input->p->counters.counters_lock );
stats_UpdateInteger( p_dec, p_input->p->counters.p_decoded_audio, 1, NULL );
vlc_mutex_unlock( &p_input->p->counters.counters_lock );
i_decoded++;
if( p_aout_buf->start_date < p_owner->i_preroll_end )
{
......@@ -841,14 +845,59 @@ static void DecoderDecodeAudio( decoder_t *p_dec, block_t *p_block )
DecoderWaitUnpause( p_dec );
const int i_rate = p_clock ? input_clock_GetRate( p_clock ) : p_block->i_rate;
DecoderAoutBufferFixTs( p_aout_buf, p_clock, p_input->i_pts_delay );
if( i_rate >= INPUT_RATE_DEFAULT/AOUT_MAX_INPUT_RATE &&
if( p_clock )
i_rate = input_clock_GetRate( p_clock );
else if( p_block && p_block->i_rate > 0 )
i_rate = p_block->i_rate;
else
i_rate = INPUT_RATE_DEFAULT;
/* FIXME TODO take care of audio-delay for mdate check */
const mtime_t i_max_date = mdate() + p_input->i_pts_delay + AOUT_MAX_ADVANCE_TIME;
if( p_aout_buf->start_date > 0 &&
p_aout_buf->start_date <= i_max_date &&
i_rate >= INPUT_RATE_DEFAULT/AOUT_MAX_INPUT_RATE &&
i_rate <= INPUT_RATE_DEFAULT*AOUT_MAX_INPUT_RATE )
aout_DecPlay( p_aout, p_aout_input, p_aout_buf, i_rate );
{
/* Wait if we are too early
* FIXME that's plain ugly to do it here */
mwait( p_aout_buf->start_date - AOUT_MAX_PREPARE_TIME );
if( !aout_DecPlay( p_aout, p_aout_input, p_aout_buf, i_rate ) )
i_played++;
i_lost += aout_DecGetResetLost( p_aout, p_aout_input );
}
else
{
if( p_aout_buf->start_date <= 0 )
{
msg_Warn( p_dec, "non-dated audio buffer received" );
}
else if( p_aout_buf->start_date > i_max_date )
{
msg_Warn( p_aout, "received buffer in the future (%"PRId64")",
p_aout_buf->start_date - mdate() );
i_lost++;
}
aout_DecDeleteBuffer( p_aout, p_aout_input, p_aout_buf );
}
}
/* Update ugly stat */
if( i_decoded > 0 || i_lost > 0 || i_played > 0 )
{
vlc_mutex_lock( &p_input->p->counters.counters_lock);
stats_UpdateInteger( p_dec, p_input->p->counters.p_lost_abuffers,
i_lost, NULL );
stats_UpdateInteger( p_dec, p_input->p->counters.p_played_abuffers,
i_played, NULL );
stats_UpdateInteger( p_dec, p_input->p->counters.p_decoded_audio,
i_decoded, NULL );
vlc_mutex_unlock( &p_input->p->counters.counters_lock);
}
}
static void DecoderGetCc( decoder_t *p_dec, decoder_t *p_dec_cc )
......
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