CRAS: audio_thread - Don't call dev_stream_mix if not needed

If the current stream has already written write_limit samples, skip
the extra call.  The offset could be greater than the limit if near
the end of the hw ring buffer, this makes sure there is no crash in
that case.

BUG=chromium:420173
TEST=play grooveshark and visualizer

Change-Id: Ib76a72965de75886bd1209f3a3564bd11181d470
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222380
CRAS: dev_stream - limit write frames correctly.

If some frames have already been written, there is now less space to
write to.  Make sure not to overrun the buffer.

BUG=chromium:420137
TEST=play grooveshark and visualizer

Change-Id: I414820e897c32363908b242c278233a2a0598bcb
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222381
CRAS: audio_thread - put back min writeable calculation

Finding the minimum amount a stream will write avoids a large memset
that was using crazy amounts of CPU.

BUG=chromium:420137
TEST=grooveshark and visualizer

Change-Id: I704aad9ecf136830209fef3be7f727bf57ca5cd6
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222374
CRAS: iodev_list - reset active pointer if it is removed.

If an active device is remove remove the reference to it help int
active_input or active_output.

BUG=chromium:421024
TEST=play/record audio suspend/resume with USB devices attached.

Change-Id: Ie372939354e2b4b0a65602be7bd2848e3dc50637
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/221496
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: Fix out-of-source build

common/cras_version.h is generated in builddir, not srcdir:
Add that directory to cras_test_client CPPFLAGS.

BUG=None
TEST=./git_prepare.sh; mkdir build; cd build; ../configure && make

Change-Id: I5d77ac08173df9f6ac3ef5b6c8347dc20c6bc958
Reviewed-on: https://chromium-review.googlesource.com/222181
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
CRAS: audio_thread - close device from rm_active.

The device always wants to be closed when removed from the active
list.  Handle that from within the remove function.  Before this some
places were closing the device before removing it from the active
list, which lead to accessing freed memory.

BUG=chromium:421655
TEST=plug/unplug USB headset and suspend/resume while playing audio.

Change-Id: Ic6be0ca14d6566859295a146fc51a29ee376c50b
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222383
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
UCM config: update Samus configs

Change-Id: I36a9af069ec180a3129d2f497040a7d2a97af701
Signed-off-by: Ben Zhang <benzh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/220590
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
CRAS: dev_stream - offset in capture_avail

When calculates the available frames in stream for capture take into
account the previous capture offset of the active devices.

BUG=chromium:421941
TEST=Test on Pixel, activate keyboard mic and listen to the recorded
audio.

Change-Id: I09329a11cd2fc2675e511f07282f202d50f59968
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: dev_stream - Increase sleep time when captue count is missed.

If there haven't been enough samples captured when it is time to send
data to the stream, sleep for a while longer in hopes that they
arrive.

BUG=chromium:421941
TEST=record from two devices and listen for quality.

Change-Id: I38a10cad3255c8874e5057df17b8dfbe60f230b2
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_area - Limit amount copied if not enough space

Check the amount of frames that fit in the destination buffer as well
as how many are present in the input buffer.

BUG=chromium:421941
TEST=record from multiple devices to multiple streams

Change-Id: I03285fe7d6616727726ebc6869cffdfe7ea96c32
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: dev_stream - track read offset per device.

Similar to how output devices work, track each stream's read offset
into the device.  This will allow streams that need SRC to read less
than the maximum amount of frames.

BUG=chromium:421941
TEST=play and record from multiple devices.

Change-Id: I1a5445bee41e17196557e9cce2795f97ed66f1b8
Signed-off-by: Dylan Reid <dgreid@chromium.org>