From 9889bb6352966f869ccbc682858f2f3a98f8422a Mon Sep 17 00:00:00 2001 From: Kyle Repinski Date: Tue, 24 Mar 2015 18:05:08 -0500 Subject: audio: Decide use_long_periods on start_output_stream. Previously this was corrected on the first write, however that was causing a buffer underrun sometimes when a stream was started. This avoids that. --- audio/audio_hw.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/audio/audio_hw.c b/audio/audio_hw.c index 5e36799..24f507f 100644 --- a/audio/audio_hw.c +++ b/audio/audio_hw.c @@ -1505,8 +1505,13 @@ static int start_output_stream_deep_buffer(struct tuna_stream_out *out) select_output_device(adev); } - out->write_threshold = PLAYBACK_DEEP_BUFFER_LONG_PERIOD_COUNT * DEEP_BUFFER_LONG_PERIOD_SIZE; - out->use_long_periods = true; + out->use_long_periods = adev->screen_off && !adev->active_input; + /* TODO: Do we need a pcm_set_avail_min here somehow? */ + if (out->use_long_periods) { + out->write_threshold = PLAYBACK_DEEP_BUFFER_LONG_PERIOD_COUNT * DEEP_BUFFER_LONG_PERIOD_SIZE; + } else { + out->write_threshold = PLAYBACK_DEEP_BUFFER_SHORT_PERIOD_COUNT * DEEP_BUFFER_SHORT_PERIOD_SIZE; + } out->config[PCM_NORMAL] = pcm_config_mm; #ifndef USE_VARIABLE_SAMPLING_RATE -- cgit v1.1