summaryrefslogtreecommitdiff
path: root/audio_alsa.c
diff options
context:
space:
mode:
authorMike Brady <mikebrady@eircom.net>2018-12-10 22:28:52 +0000
committerMike Brady <mikebrady@eircom.net>2018-12-10 22:28:52 +0000
commit9d5ff22f2dc2591301154ade1c9b75adf81b0730 (patch)
treeced208ead07d488f5966e28dcc76a03588443a14 /audio_alsa.c
parent079db2eba885e708eb32dd6121f601365fe553a7 (diff)
Connect up the stall response to the external command calling -- add a single argument to the unfixable error call.
Diffstat (limited to 'audio_alsa.c')
-rw-r--r--audio_alsa.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/audio_alsa.c b/audio_alsa.c
index d1fe42a..71a4e7e 100644
--- a/audio_alsa.c
+++ b/audio_alsa.c
@@ -76,8 +76,8 @@ static pthread_mutex_t alsa_mutex = PTHREAD_MUTEX_INITIALIZER;
// for tracking how long the output device has stalled
uint64_t stall_monitor_start_time; // zero if not initialised / not started / zeroed by flush
-long stall_monitor_frame_count; // set to delay at start of time, incremented by any writes
-int stall_monitor_error_notified;
+long stall_monitor_frame_count; // set to delay at start of time, incremented by any writes
+int stall_monitor_error_notified;
static snd_output_t *output = NULL;
static unsigned int desired_sample_rate;
@@ -940,11 +940,10 @@ static void start(int i_sample_rate, int i_sample_format) {
frame_index = 0;
measurement_data_is_valid = 0;
-
+
stall_monitor_start_time = 0;
stall_monitor_frame_count = 0;
stall_monitor_error_notified = 0;
-
}
// assuming pthread cancellation is disabled
@@ -1062,20 +1061,23 @@ int delay(long *the_delay) {
pthread_setcancelstate(oldState, NULL);
}
debug(3, "Total playing time to get delay of %d frames: %8.2f us.", *the_delay,
- (1000000.0 * (get_absolute_time_in_fp() - overall_time_before) / (uint64_t)0x100000000));
-
+ (1000000.0 * (get_absolute_time_in_fp() - overall_time_before) / (uint64_t)0x100000000));
+
if ((reply == 0) && (*the_delay != 0)) {
uint64_t stall_monitor_time_now = get_absolute_time_in_fp();
if ((stall_monitor_start_time != 0) && (stall_monitor_frame_count == *the_delay)) {
// hasn't outputted anything since the last call to delay()
int64_t time_stalled = stall_monitor_time_now - stall_monitor_start_time;
int64_t stall_monitor_error_threshold = 200000; // microseconds;
- stall_monitor_error_threshold = (stall_monitor_error_threshold << 32) / 1000000; // now in fp form
+ stall_monitor_error_threshold =
+ (stall_monitor_error_threshold << 32) / 1000000; // now in fp form
if (time_stalled > stall_monitor_error_threshold) {
if (stall_monitor_error_notified == 0) {
- debug(1, "alsa output device stalled -- no output in %8.2f us.",(1000000.0 * stall_monitor_error_threshold) / (uint64_t)0x100000000);
+ debug(1, "alsa output device stalled -- no output in %8.2f us.",
+ (1000000.0 * stall_monitor_error_threshold) / (uint64_t)0x100000000);
stall_monitor_error_notified = 1;
}
+ reply = sps_extra_errno_output_stalled;
}
} else {
// is outputting stuff, so restart the monitoring here
@@ -1084,7 +1086,7 @@ int delay(long *the_delay) {
}
} else {
// if there is an error or the delay is zero (from which it is assumed there is no output)
- stall_monitor_start_time = 0; // zero if not initialised / not started / zeroed by flush
+ stall_monitor_start_time = 0; // zero if not initialised / not started / zeroed by flush
stall_monitor_frame_count = 0; // set to delay at start of time, incremented by any writes
}
return reply;
@@ -1114,7 +1116,8 @@ static int play(void *buf, int samples) {
pthread_cleanup_debug_mutex_lock(&alsa_mutex, 10000, 1);
overall_time_before = get_absolute_time_in_fp();
ret = actual_open_alsa_device();
- debug(3, "Opening time: %8.2f us.", (1000000.0 * (get_absolute_time_in_fp() - overall_time_before ) / (uint64_t)0x100000000));
+ debug(3, "Opening time: %8.2f us.",
+ (1000000.0 * (get_absolute_time_in_fp() - overall_time_before) / (uint64_t)0x100000000));
if (ret == 0) {
if (audio_alsa.volume)
do_volume(set_volume);
@@ -1231,8 +1234,8 @@ static int play(void *buf, int samples) {
pthread_cleanup_pop(0); // release the mutex
}
pthread_setcancelstate(oldState, NULL);
- debug(3, "Total playing time to write %d samples: %8.2f us.",
- samples, (1000000.0 * (get_absolute_time_in_fp() - overall_time_before) / (uint64_t)0x100000000));
+ debug(3, "Total playing time to write %d samples: %8.2f us.", samples,
+ (1000000.0 * (get_absolute_time_in_fp() - overall_time_before) / (uint64_t)0x100000000));
return ret;
}
@@ -1265,7 +1268,7 @@ static void flush(void) {
pthread_cleanup_pop(0); // release the mutex
pthread_setcancelstate(oldState, NULL);
debug(3, "Total playing time to flush: %8.2f us.",
- (1000000.0 * (get_absolute_time_in_fp() - overall_time_before) / (uint64_t)0x100000000));
+ (1000000.0 * (get_absolute_time_in_fp() - overall_time_before) / (uint64_t)0x100000000));
}
static void stop(void) {