Skip to content

Commit

Permalink
Add a 'stats' function to the audio back ends to replace the 'rate_in…
Browse files Browse the repository at this point in the history
…fo' function. Zero all except the alsa back end.
  • Loading branch information
mikebrady committed Nov 20, 2021
1 parent 5f8e6e3 commit cd9da86
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ typedef struct {
// will change dynamically, so keep watching it. Implemented in ALSA only.
// returns a negative error code if there's a problem
int (*delay)(long *the_delay); // snd_pcm_sframes_t is a signed long
int (*rate_info)(uint64_t *measurement_time, uint64_t *delay,
int (*stats)(uint64_t *measurement_time, uint64_t *delay,
uint64_t *frames_sent_to_dac); // use this to get the true rate of the DAC

// may be NULL, in which case soft volume is applied
Expand Down
6 changes: 3 additions & 3 deletions audio_alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static int play(void *buf, int samples);
static void stop(void);
static void flush(void);
int delay(long *the_delay);
int play_stats(uint64_t *the_time, uint64_t *the_delay, uint64_t *frames_sent_to_dac);
int stats(uint64_t *the_time, uint64_t *the_delay, uint64_t *frames_sent_to_dac);
// int get_rate_information(uint64_t *elapsed_time, uint64_t *frames_played);
void *alsa_buffer_monitor_thread_code(void *arg);

Expand Down Expand Up @@ -89,7 +89,7 @@ audio_output audio_alsa = {
.flush = &flush,
.delay = &delay,
.play = &play,
.rate_info = &play_stats, // will also include frames of silence sent to stop
.stats = &stats, // will also include frames of silence sent to stop
// standby mode
// .rate_info = NULL,
.mute = NULL, // a function will be provided if it can, and is allowed to,
Expand Down Expand Up @@ -1629,7 +1629,7 @@ int delay(long *the_delay) {
return ret;
}

int play_stats(uint64_t *the_time, uint64_t *the_delay, uint64_t *frames_sent_to_dac) {
int stats(uint64_t *the_time, uint64_t *the_delay, uint64_t *frames_sent_to_dac) {
// returns 0 if the device is in a valid state -- SND_PCM_STATE_RUNNING or
// SND_PCM_STATE_PREPARED
// or SND_PCM_STATE_DRAINING
Expand Down
1 change: 1 addition & 0 deletions audio_ao.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ audio_output audio_ao = {.name = "ao",
.is_running = NULL,
.flush = NULL,
.delay = NULL,
.stats = NULL,
.play = &play,
.volume = NULL,
.parameters = NULL,
Expand Down
1 change: 1 addition & 0 deletions audio_dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ audio_output audio_dummy = {.name = "dummy",
.is_running = NULL,
.flush = NULL,
.delay = NULL,
.stats = NULL,
.play = &play,
.volume = NULL,
.parameters = NULL,
Expand Down
1 change: 1 addition & 0 deletions audio_jack.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ audio_output audio_jack = {.name = "jack",
.is_running = NULL,
.flush = &jack_flush,
.delay = &jack_delay,
.stats = NULL,
.play = &play,
.volume = NULL,
.parameters = NULL,
Expand Down
1 change: 1 addition & 0 deletions audio_pa.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ audio_output audio_pa = {.name = "pa",
.is_running = NULL,
.flush = &flush,
.delay = &pa_delay,
.stats = NULL,
.play = &play,
.volume = NULL,
.parameters = NULL,
Expand Down
1 change: 1 addition & 0 deletions audio_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ audio_output audio_pipe = {.name = "pipe",
.is_running = NULL,
.flush = NULL,
.delay = NULL,
.stats = NULL,
.play = &play,
.volume = NULL,
.parameters = NULL,
Expand Down
1 change: 1 addition & 0 deletions audio_pw.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ audio_output audio_pw = {.name = "pw",
.is_running = NULL,
.flush = &flush,
.delay = NULL,
.stats = NULL,
.play = &play,
.volume = NULL,
.parameters = NULL,
Expand Down
1 change: 1 addition & 0 deletions audio_sndio.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ audio_output audio_sndio = {.name = "sndio",
.is_running = NULL,
.flush = &flush,
.delay = &delay,
.stats = NULL,
.play = &play,
.volume = NULL,
.parameters = NULL,
Expand Down
1 change: 1 addition & 0 deletions audio_soundio.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ audio_output audio_soundio = {.name = "soundio",
.is_running = NULL,
.flush = &flush,
.delay = NULL,
.stats = NULL,
.play = &play,
.volume = NULL,
.parameters = &parameters,
Expand Down
1 change: 1 addition & 0 deletions audio_stdout.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ audio_output audio_stdout = {.name = "stdout",
.is_running = NULL,
.flush = NULL,
.delay = NULL,
.stats = NULL,
.play = &play,
.volume = NULL,
.parameters = NULL,
Expand Down
8 changes: 4 additions & 4 deletions player.c
Original file line number Diff line number Diff line change
Expand Up @@ -2019,7 +2019,7 @@ void *player_thread_func(void *arg) {
}
} else {
#endif
if (config.output->delay) {
if (config.output->stats) {
if (config.no_sync == 0)
statistics_print_profile = ap1_synced_statistics_print_profile;
else
Expand Down Expand Up @@ -2311,15 +2311,15 @@ void *player_thread_func(void *arg) {
}

int stats_status = -1;
if ((config.output->delay) && (config.no_sync == 0) && (config.output->rate_info)) {
if ((config.output->delay) && (config.no_sync == 0) && (config.output->stats)) {
uint64_t frames_sent_for_play;
uint64_t measurement_time;
uint64_t actual_delay;
stats_status = config.output->rate_info(&measurement_time, &actual_delay, &frames_sent_for_play);
stats_status = config.output->stats(&measurement_time, &actual_delay, &frames_sent_for_play);
// debug(1,"actual_delay: %" PRIu64 ", frames_sent_for_play: %" PRIu64 ", frames_played: %" PRIu64 ".", actual_delay, frames_sent_for_play, frames_sent_for_play - actual_delay);
uint64_t frames_played = frames_sent_for_play - actual_delay;
// If the status is zero, it means that there were no output problems since the
// last time the rate_info call was made. Thus, the frame rate should be valid.
// last time the stats call was made. Thus, the frame rate should be valid.
if ((stats_status == 0) && (previous_frames_played_valid)) {
uint64_t frames_played_in_this_interval = frames_played - previous_frames_played;
uint64_t interval = measurement_time - previous_frames_played_time;
Expand Down

0 comments on commit cd9da86

Please sign in to comment.