Skip to content

Commit c5939bf

Browse files
author
Rémi Denis-Courmont
committed
aout: fix lost block stats
Do not count dropped blocks as played.
1 parent b758d16 commit c5939bf

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

src/audio_output/aout_internal.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ typedef struct
8181
aout_request_vout_t request_vout;
8282

8383
atomic_uint buffers_lost;
84+
atomic_uint buffers_played;
8485
atomic_uchar restart;
8586
} aout_owner_t;
8687

@@ -136,8 +137,8 @@ bool aout_ChangeFilterString( vlc_object_t *manager, vlc_object_t *aout,
136137
int aout_DecNew(audio_output_t *, const audio_sample_format_t *,
137138
const audio_replay_gain_t *, const aout_request_vout_t *);
138139
void aout_DecDelete(audio_output_t *);
139-
int aout_DecPlay(audio_output_t *, block_t *, int i_input_rate);
140-
unsigned aout_DecGetResetLost(audio_output_t *);
140+
void aout_DecPlay(audio_output_t *, block_t *, int i_input_rate);
141+
void aout_DecGetResetStats(audio_output_t *, unsigned *, unsigned *);
141142
void aout_DecChangePause(audio_output_t *, bool b_paused, mtime_t i_date);
142143
void aout_DecFlush(audio_output_t *, bool wait);
143144
void aout_RequestRestart (audio_output_t *, unsigned);

src/audio_output/dec.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ int aout_DecNew( audio_output_t *p_aout,
108108
aout_OutputUnlock (p_aout);
109109

110110
atomic_init (&owner->buffers_lost, 0);
111+
atomic_init (&owner->buffers_played, 0);
111112
return 0;
112113
}
113114

@@ -338,7 +339,7 @@ static void aout_DecSynchronize (audio_output_t *aout, mtime_t dec_pts,
338339
/*****************************************************************************
339340
* aout_DecPlay : filter & mix the decoded buffer
340341
*****************************************************************************/
341-
int aout_DecPlay (audio_output_t *aout, block_t *block, int input_rate)
342+
void aout_DecPlay (audio_output_t *aout, block_t *block, int input_rate)
342343
{
343344
aout_owner_t *owner = aout_owner (aout);
344345

@@ -384,9 +385,10 @@ int aout_DecPlay (audio_output_t *aout, block_t *block, int input_rate)
384385
owner->sync.end = block->i_pts + block->i_length + 1;
385386
owner->sync.discontinuity = false;
386387
aout_OutputPlay (aout, block);
388+
atomic_fetch_add(&owner->buffers_played, 1);
387389
out:
388390
aout_OutputUnlock (aout);
389-
return 0;
391+
return;
390392
drop:
391393
owner->sync.discontinuity = true;
392394
block_Release (block);
@@ -395,10 +397,13 @@ int aout_DecPlay (audio_output_t *aout, block_t *block, int input_rate)
395397
goto out;
396398
}
397399

398-
unsigned aout_DecGetResetLost (audio_output_t *aout)
400+
void aout_DecGetResetStats(audio_output_t *aout, unsigned *restrict lost,
401+
unsigned *restrict played)
399402
{
400403
aout_owner_t *owner = aout_owner (aout);
401-
return atomic_exchange(&owner->buffers_lost, 0);
404+
405+
*lost = atomic_exchange(&owner->buffers_lost, 0);
406+
*played = atomic_exchange(&owner->buffers_played, 0);
402407
}
403408

404409
void aout_DecChangePause (audio_output_t *aout, bool paused, mtime_t date)

src/input/decoder.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,6 @@ static void DecoderProcessVideo( decoder_t *p_dec, block_t *p_block )
10381038
}
10391039

10401040
static int DecoderPlayAudio( decoder_t *p_dec, block_t *p_audio,
1041-
unsigned *restrict pi_played_sum,
10421041
unsigned *restrict pi_lost_sum )
10431042
{
10441043
decoder_owner_sys_t *p_owner = p_dec->p_owner;
@@ -1093,35 +1092,40 @@ static int DecoderPlayAudio( decoder_t *p_dec, block_t *p_audio,
10931092

10941093
audio_output_t *p_aout = p_owner->p_aout;
10951094

1096-
if( p_aout == NULL || p_audio->i_pts <= VLC_TS_INVALID
1097-
|| i_rate < INPUT_RATE_DEFAULT/AOUT_MAX_INPUT_RATE
1098-
|| i_rate > INPUT_RATE_DEFAULT*AOUT_MAX_INPUT_RATE
1099-
|| DecoderTimedWait( p_dec, p_audio->i_pts - AOUT_MAX_PREPARE_TIME ) )
1095+
if( p_aout != NULL && p_audio->i_pts > VLC_TS_INVALID
1096+
&& i_rate >= INPUT_RATE_DEFAULT/AOUT_MAX_INPUT_RATE
1097+
&& i_rate <= INPUT_RATE_DEFAULT*AOUT_MAX_INPUT_RATE
1098+
&& !DecoderTimedWait( p_dec, p_audio->i_pts - AOUT_MAX_PREPARE_TIME ) )
1099+
{
1100+
aout_DecPlay( p_aout, p_audio, i_rate );
1101+
}
1102+
else
11001103
{
11011104
msg_Dbg( p_dec, "discarded audio buffer" );
11021105
*pi_lost_sum += 1;
11031106
block_Release( p_audio );
1104-
return 0;
11051107
}
1106-
1107-
if( aout_DecPlay( p_aout, p_audio, i_rate ) == 0 )
1108-
*pi_played_sum += 1;
1109-
11101108
return 0;
11111109
}
11121110

11131111
static void DecoderUpdateStatAudio( decoder_t *p_dec, unsigned decoded,
1114-
unsigned lost, unsigned played )
1112+
unsigned lost )
11151113
{
11161114
decoder_owner_sys_t *p_owner = p_dec->p_owner;
11171115
input_thread_t *p_input = p_owner->p_input;
1116+
unsigned played = 0;
11181117

11191118
/* Update ugly stat */
11201119
if( p_input == NULL )
11211120
return;
11221121

11231122
if( p_owner->p_aout != NULL )
1124-
lost += aout_DecGetResetLost( p_owner->p_aout );
1123+
{
1124+
unsigned aout_lost;
1125+
1126+
aout_DecGetResetStats( p_owner->p_aout, &aout_lost, &played );
1127+
lost += aout_lost;
1128+
}
11251129

11261130
vlc_mutex_lock( &p_input->p->counters.counters_lock);
11271131
stats_Update( p_input->p->counters.p_lost_abuffers, lost, NULL );
@@ -1132,11 +1136,11 @@ static void DecoderUpdateStatAudio( decoder_t *p_dec, unsigned decoded,
11321136

11331137
static int DecoderQueueAudio( decoder_t *p_dec, block_t *p_aout_buf )
11341138
{
1135-
unsigned i_lost = 0, i_played = 0;
1139+
unsigned lost = 0;
11361140

1137-
int ret = DecoderPlayAudio( p_dec, p_aout_buf, &i_played, &i_lost );
1141+
int ret = DecoderPlayAudio( p_dec, p_aout_buf, &lost );
11381142

1139-
DecoderUpdateStatAudio( p_dec, 1, i_lost, i_played );
1143+
DecoderUpdateStatAudio( p_dec, 1, lost );
11401144

11411145
return ret;
11421146
}
@@ -1145,16 +1149,16 @@ static void DecoderDecodeAudio( decoder_t *p_dec, block_t *p_block )
11451149
{
11461150
block_t *p_aout_buf;
11471151
block_t **pp_block = p_block ? &p_block : NULL;
1148-
unsigned i_decoded = 0, i_lost = 0, i_played = 0;
1152+
unsigned decoded = 0, lost = 0;
11491153

11501154
while( (p_aout_buf = p_dec->pf_decode_audio( p_dec, pp_block ) ) )
11511155
{
1152-
i_decoded++;
1156+
decoded++;
11531157

1154-
DecoderPlayAudio( p_dec, p_aout_buf, &i_played, &i_lost );
1158+
DecoderPlayAudio( p_dec, p_aout_buf, &lost );
11551159
}
11561160

1157-
DecoderUpdateStatAudio( p_dec, i_decoded, i_lost, i_played );
1161+
DecoderUpdateStatAudio( p_dec, decoded, lost );
11581162
}
11591163

11601164
/* This function process a audio block

0 commit comments

Comments
 (0)