mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-21 10:40:21 +00:00
Print cumulative audio playback stats on exit
* removed that summary from ALSA
This commit is contained in:
@@ -45,21 +45,22 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "debug.h"
|
||||
#include "host.h"
|
||||
|
||||
#include "audio/audio.h"
|
||||
#include "audio/audio_playback.h"
|
||||
#include "audio/playback/sdi.h"
|
||||
|
||||
#include "debug.h"
|
||||
#include "host.h"
|
||||
#include "lib_common.h"
|
||||
|
||||
#include "tv.h"
|
||||
#include "video_display.h" /* flags */
|
||||
|
||||
struct state_audio_playback {
|
||||
char name[128];
|
||||
const struct audio_playback_info *funcs;
|
||||
void *state;
|
||||
|
||||
struct timeval t0;
|
||||
long long int samples_played;
|
||||
};
|
||||
|
||||
void audio_playback_help(bool full)
|
||||
@@ -73,6 +74,7 @@ int audio_playback_init(const char *device, const char *cfg, struct state_audio_
|
||||
struct state_audio_playback *s;
|
||||
|
||||
s = calloc(1, sizeof(struct state_audio_playback));
|
||||
gettimeofday(&s->t0, NULL);
|
||||
s->funcs = load_library(device, LIBRARY_CLASS_AUDIO_PLAYBACK, AUDIO_PLAYBACK_ABI_VERSION);
|
||||
|
||||
if (s->funcs == NULL) {
|
||||
@@ -111,10 +113,21 @@ struct state_audio_playback *audio_playback_init_null_device(void)
|
||||
|
||||
void audio_playback_done(struct state_audio_playback *s)
|
||||
{
|
||||
if(s) {
|
||||
s->funcs->done(s->state);
|
||||
free(s);
|
||||
if (!s) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s->samples_played > 0) {
|
||||
struct timeval t1;
|
||||
gettimeofday(&t1, NULL);
|
||||
|
||||
log_msg(LOG_LEVEL_INFO, "Played %lld audio samples in %f seconds (%f samples per second).\n",
|
||||
s->samples_played, tv_diff(t1, s->t0),
|
||||
s->samples_played / tv_diff(t1, s->t0));
|
||||
}
|
||||
|
||||
s->funcs->done(s->state);
|
||||
free(s);
|
||||
}
|
||||
|
||||
unsigned int audio_playback_get_display_flags(struct state_audio_playback *s)
|
||||
@@ -135,6 +148,7 @@ unsigned int audio_playback_get_display_flags(struct state_audio_playback *s)
|
||||
|
||||
void audio_playback_put_frame(struct state_audio_playback *s, struct audio_frame *frame)
|
||||
{
|
||||
s->samples_played += frame->data_len / frame->ch_count / frame->bps;
|
||||
s->funcs->write(s->state, frame);
|
||||
}
|
||||
|
||||
|
||||
@@ -103,9 +103,6 @@ struct state_alsa_playback {
|
||||
snd_pcm_t *handle;
|
||||
struct audio_desc desc;
|
||||
|
||||
struct timeval start_time;
|
||||
long long int played_samples;
|
||||
|
||||
/* Local configuration with handle_underrun workaround set for PulseAudio
|
||||
ALSA plugin. Will be NULL if the PA ALSA plugin is not in use or the
|
||||
workaround is not required. */
|
||||
@@ -834,8 +831,6 @@ static void * audio_play_alsa_init(const char *cfg)
|
||||
log_msg(LOG_LEVEL_WARNING, MOD_NAME "Async API is experimental, in case of problems use either \"thread\" or \"sync\" API\n");
|
||||
}
|
||||
|
||||
gettimeofday(&s->start_time, NULL);
|
||||
|
||||
if(cfg && strlen(cfg) > 0) {
|
||||
if(strcmp(cfg, "help") == 0) {
|
||||
printf("Usage\n");
|
||||
@@ -964,8 +959,6 @@ static void audio_play_alsa_write_frame(void *state, struct audio_frame *frame)
|
||||
signed2unsigned(frame->data, frame->data, frame->data_len);
|
||||
}
|
||||
|
||||
s->played_samples += frame->data_len / frame->bps / frame->ch_count;
|
||||
|
||||
int frames = frame->data_len / (frame->bps * frame->ch_count);
|
||||
rc = write_samples(s->handle, frame, frames, s->non_interleaved, s->playback_mode);
|
||||
if (rc == -EPIPE) {
|
||||
@@ -1038,8 +1031,6 @@ static void audio_play_alsa_done(void *state)
|
||||
{
|
||||
struct state_alsa_playback *s = (struct state_alsa_playback *) state;
|
||||
|
||||
struct timeval t;
|
||||
|
||||
if (s->playback_mode == THREAD && s->thread_started) {
|
||||
pthread_mutex_lock(&s->lock);
|
||||
s->should_exit_thread = true;
|
||||
@@ -1051,11 +1042,6 @@ static void audio_play_alsa_done(void *state)
|
||||
snd_async_del_handler(s->pcm_callback);
|
||||
}
|
||||
|
||||
gettimeofday(&t, NULL);
|
||||
log_msg(LOG_LEVEL_INFO, MOD_NAME "Played %lld samples in %f seconds (%f samples per second).\n",
|
||||
s->played_samples, tv_diff(t, s->start_time),
|
||||
s->played_samples / tv_diff(t, s->start_time));
|
||||
|
||||
snd_pcm_drain(s->handle);
|
||||
snd_pcm_close(s->handle);
|
||||
if (s->local_config) {
|
||||
|
||||
Reference in New Issue
Block a user