CRAS: audio_thread - Remove stream on reply error.

The stream should be removed when the attempt to read from the socket
fails.  This means that the other side of the socket has been closed
and the client is no longer there.

BUG=chrome-os-partner:31849
TEST=play audio on Big

Change-Id: I800c2a6badc09a07634f13575ca210d798a8d422
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/217162
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: audio_thread - Add stream list for each device.

In later changes this list will be used instead of a thread-wide list
to track attached streams.

Change-Id: I07aed4dea9d6037c0d2ed0f03f3365adbc4d571e
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/217151
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: audio_thread - Keep list of attached streams per device.

Instead of keeping a list of attached streams in the audio thread
struct, keep a list per device.  This will allow for different streams
to be routed to different or multiple devices in later commits.

Change-Id: I7d3d8437c96f3496375864575c36dab0b7c45c81
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/217152
CRAS: mix - Re-order the checks in mix_add_stream.

Re-order the check for mute to be within the while loop.  This will
make mixing streams that require SRC on the server side simpler in a
later change.

Change-Id: I1b2ea5e542cfdec0e562e31cd70bd17276feb745
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/217153
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: audio_thread - remove fd from io stream

The fd parameter was just used as a cache.  Remove that and instead
get it from the stream when needed.  This is done so that
cras_io_stream can have per-stream details removed.  Eventually
cras_io_stream will be used for a stream to device mapping, and the
same stream could be held by multiple devices.

BUG=none
TEST=unittest

Change-Id: I9f82d3af07c6f29270d3273105213cd652b1ce10
Reviewed-on: https://chromium-review.googlesource.com/217154
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - use mix_mute_buffer helper.

Replace meset with cras_mux_mute_buffer.  No functional change.

Change-Id: I288736eb8141295e6ea01b6fb28324d49fc7570d
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/217155
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: audio_thread - Factor cras_io_stream to its own file.

Rename cras_io_stream to dev_stream and move it to its own source
file.  In later commits this struct will take on additional
responsibilities keeping sample rate converters and tracking how much
of a stream has been written to each device.

BUG=none
TEST=make check

Change-Id: Ifa19e8f1bb3557ca7c7ff4546ad445729bc3ddfb
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/217156
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: move stream mixing to dev_stream.

Move the shm interaction and some decision making to dev_stream as
this is a property of the stream.  cras_mix no longer needs to know
about shm and its unit test is now much cleaner.  This paves the way
to add sample rate conversion logic to dev_stream in a later commit.

BUG=none
TEST=make check, play a few simultaneous streams.

Change-Id: I5fbb3c670e86393a0c8d3454e29c4bf587a5015c
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/217157
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: dev_stream - Add format rate converter.

Add a format rate converted to dev stream.  This adds an argument to
the constructor indicating the format of the device the stream will
play on.  If this format doesn't match the stream a sample rate
converter will be created.

A later change will modify audio_thread and rclient to use this
functionality.  For now rclient ensures that the formats match.

BUG=none
TEST=new unittest, the code doesn't run yet.

Change-Id: Id71e593cbed05abc1771e5232c0e181f862053f4
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/217158
Cranky: add UCM config for Cranky

This is a clone of the Rambi config.

BUG=chrome-os-partner:31875
TEST=None

Change-Id: Ie281f5cfe8ae71984f14c4cfd6bc747bdeec2c8f
Reviewed-on: https://chromium-review.googlesource.com/217420
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Bernie Thompson <bhthompson@chromium.org>
Commit-Queue: Bernie Thompson <bhthompson@chromium.org>
CRAS: audio area - Override channel layout for mono stream

Chrome use CHANNEL_LAYOUT_MONO for mono stream where the only
valid channel position is FC(front center) not FL(front left).

Fix the bug so that when a mono input stream is created, and
hardware only supports stereo recording. CRAS will copy over
the sample from both front left and front right channel instead
of copy nothing.

BUG=chromium:412604
TEST=On Pixel, open a mono input stream by:
cras_test_client --capture_file /tmp/1 --num_channels=1 \
--channel_layout=-1,-1,-1,-1,0,-1,-1,-1,-1,-1,-1
verify that /tmp/1 is not all zero.

Change-Id: I3540b5e3d1cda30efba8933bc4b4e309754da07d
Reviewed-on: https://chromium-review.googlesource.com/217459
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Auron: add Auron ALSA config

BUG=chrome-os-partner:31842
TEST=check that auron_alsa.fw is loaded in dmesg

Change-Id: I9ee53352f96d2780a5627bc8fc35ab50e36e027c
Reviewed-on: https://chromium-review.googlesource.com/217961
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Bernie Thompson <bhthompson@chromium.org>
Commit-Queue: Bernie Thompson <bhthompson@chromium.org>
CRAS: Add --version parameter to cras_test_client

In the context of crouton, it is useful to know the exact commit
id that was used to build cras. And it can be useful for
development purpose as well.

If -DVCIS= is included in CPPFLAGS (Chromium OS build), use
that as version.
If not, generate a header file that defines the symbol from the
output of `git rev-parse`.

BUG=chromium:398796
CQ-DEPEND=CL:217540
TEST=cras_test_client --version outputs the correct git commit id.

Change-Id: I6049cb1e180c3a6cfe43bc33adbd12bd88f6f738
Reviewed-on: https://chromium-review.googlesource.com/217523
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
CRAS: dev_stream - don't convert channel/layout for input stream

For capture CRAS can copy the samples from device to stream
for each channel base on the channel layout specified. So when
creating a dev_stream, no need to create format converter if
the format difference is on channel count or layout.

BUG=None
TEST=cras_test_client --capture_file /tmp/1 --num_channels=3
--channel_layout=0,1,-1,-1,2,-1,-1,-1,-1,-1,-1

Change-Id: Id09a8647729f9f7cd9b6887b887a2a28f73436e8
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/218096
CRAS: audio_thread - set format to active device when append stream

The format of additional active devices stays NULL until it's
initialized. Since now dev_stream is introduced, we need to have
device's format set earlier in append_stream_to_dev() to
configure the format converter when a stream is appended.
Also changes the unittest to reflect the change.

BUG=None
TEST=unittest. Activate keyboard mic on Pixel then capture a
stream won't crash.

Change-Id: I45fde87f1c9bca182bb1bec2fdfaf9feda14e4dd
Reviewed-on: https://chromium-review.googlesource.com/218097
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - don't poll negative fd

When a stream is in the draining state, its file descriptor is set to
-1.  Now that the fd isn't cached locally, this will cause an
exception from libc.  Before we were polling a closed fd, which isn't
good but wasn't catastrophic.

BUG=chromium:413943
TEST=play audio on panther.

Change-Id: I280e23c492bef691b685fa9aae1cb306478b9ad1
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/217995
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Ben Zhang <benzh@chromium.org>
CRAS: libcras - Update function descriptions and fix typos.

BUG=None
TEST=None

Change-Id: I40c0365eba9a11f345f3a1d4bb3de6ee53213eb1
Reviewed-on: https://chromium-review.googlesource.com/217469
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Tested-by: Chinyue Chen <chinyue@chromium.org>
Commit-Queue: Chinyue Chen <chinyue@chromium.org>
CRAS: audio_thread - Handle dev_stream with a format converter.

If a dev_stream has a format converter, update the amount of frames
available and use the format converter when rendering samples.

BUG=none
TEST=none, not used yet.

Change-Id: Id1929b1cf8677a57852c4a873c19373bda3303a4
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: rclient - Accept the remote stream format.

Always accept the remote stream format when a stream is attached.  The
format conversion is now done in the audio thread, allow the client to
send whatever it wants.

This change will cause the client never to do format conversion, and
instead rely on the audio thread to convert to the format of the
device.

BUG=none
TEST=unittest, play record audio on blaze.

Change-Id: Ib6261a640cc237f74e92ee37ce555914d047a43e
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - don't check draining streams

If a stream is draining, don't check if it has replied with more data.

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