summaryrefslogtreecommitdiff
path: root/cras/src/server/audio_thread.c
diff options
context:
space:
mode:
authorCheng-Yi Chiang <cychiang@chromium.org>2021-02-17 23:21:24 +0800
committerCommit Bot <commit-bot@chromium.org>2021-03-03 18:15:40 +0000
commit86e1a560610cb3a8dfbf6cedb7984c85830d6855 (patch)
treece84cd20c034528dff607fd9e16f3b5a6f82cbf4 /cras/src/server/audio_thread.c
parent75f9a6f3f931e8ab5dd0964ce1a0724953b7a4dd (diff)
downloadadhd-86e1a560610cb3a8dfbf6cedb7984c85830d6855.tar.gz
CRAS: Align new output stream callback time to existing input stream
We want to align the input stream POST and output stream FETCH schedule in order to reduce number of wake up time. Optimize for the case where an input stream is created first, then an output stream is created later. If input and output stream are both using the same block size and rate, align output stream initial callback time with input stream next_cb_ts, also use the sleep interval of input stream as the initial sleep interval of the output stream. The above actions align the output stream to the existing input stream in the beginning. To keep the alignment as much as we can, we assume the input and output devices on the same card have the same estimated rate. The estimated rate changes sleep interval. To avoid any fluctuation on the estimated rate breaks the alignemtn, we use output device estimated rate for the input device if they are both on internal sound card, and are using the same rate. The tricky part is that we need to update estimated rate in every wake up cycle in order to get the latest estimated rate and hence sleep interval from output device to input device. Note that to bring back alignment from underrun or overrun would be in the future work. BUG=b:163511204 TEST=check 480 block size input and output streams are aligned in WebRTC case. TEST=check audio.CrasPerf.playback_capture test CPU cycle count is reduced by about 33%. Change-Id: I31c000609255193b0971adcb438abc0e343ae4ad Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/2703368 Reviewed-by: Yu-Hsuan Hsu <yuhsuan@chromium.org> Commit-Queue: Cheng-Yi Chiang <cychiang@chromium.org> Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
Diffstat (limited to 'cras/src/server/audio_thread.c')
-rw-r--r--cras/src/server/audio_thread.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/cras/src/server/audio_thread.c b/cras/src/server/audio_thread.c
index cd155e82..48bb0dc2 100644
--- a/cras/src/server/audio_thread.c
+++ b/cras/src/server/audio_thread.c
@@ -443,7 +443,8 @@ static int thread_add_stream(struct audio_thread *thread,
{
int rc;
- rc = dev_io_append_stream(&thread->open_devs[stream->direction], stream,
+ rc = dev_io_append_stream(&thread->open_devs[CRAS_STREAM_OUTPUT],
+ &thread->open_devs[CRAS_STREAM_INPUT], stream,
iodevs, num_iodevs);
if (rc < 0)
return rc;