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>
Reviewed-on: https://chromium-review.googlesource.com/222947
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@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>
Reviewed-on: https://chromium-review.googlesource.com/222948
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
CRAS: alsa_mixer - UCM can specify an extra main volume control

Samus has a main volume control named DAC1, we don't want to use DAC1
as a main control on all boards, so add the ability to specify an
extra main volume name in the UCM config file.

BUG=chrome-os-partner:29649
TEST=On Samus, slide volume bar on GUI, see DAC1 is used as a fine
control that takes a value between 0dB and -2.63dB.

Change-Id: Ic19c824d27c00314be3a5a4e41f187fbe9a04edb
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222967
Reviewed-by: Ben Zhang <benzh@chromium.org>
Commit-Queue: Ben Zhang <benzh@chromium.org>
Tested-by: Ben Zhang <benzh@chromium.org>
UCM config: Samus: use DAC1 as an extra main volume control

BUG=chrome-os-partner:29649
TEST=On Samus, slide volume bar on GUI, see DAC1 is used as a fine
control that takes a value between 0dB and -2.63dB.

Change-Id: Id475f9e457223dfea558fa73b852b369a0e2fb61
Signed-off-by: Ben Zhang <benzh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222994
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>
Reviewed-on: https://chromium-review.googlesource.com/222498
Commit-Queue: Hsinyu Chao <hychao@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>
Reviewed-on: https://chromium-review.googlesource.com/222643
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
UCM config: Samus: auto channel duplication on external mic

The external mic is mono. The amixer control 'IF1 Slot01 Swap'
allows us to duplicate left channel data to right channel when
recording from an external analog mic.

BUG=chrome-os-partner:29649
TEST=arecord/aplay with a headset, both left and right channel has sound
CQ-DEPEND=CL:222452

Change-Id: Idc06ac38c0a856712ff011703bb85b10a8964595
Signed-off-by: Ben Zhang <benzh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222884
Reviewed-by: Dylan Reid <dgreid@chromium.org>