CRAS: audio_area - Zero buffer from offset.

The buffer needs to be zeroed, starting from the offset at which data
will be written.

BUG=chromium:406213
TEST=updated unittest. Also arecord audio and listen.

Change-Id: I0be4fe2711537da2f3dad9ccac321a3e55a89804
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/213741
CRAS: unittest - Test write two streams with one empty

This commit re-uploads commit c37222, which has been reverted.

In possibly_fill_audio there are two cases which we should handle
empty output stream differently:
1. When we fetch a stream and it returns zero frames, we should skip
and don't mix it.
2. When an empty stream has smaller cb_threshold so hasn't yet meet the
condition to fetch it, should just proceed mix it although there's no
sample in shm.

BUG=None
TEST=make check

Change-Id: Ibb724da6ced2060d9e83307f1ae76b316afaea51
Reviewed-on: https://chromium-review.googlesource.com/213059
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
CRAS: a2dp - TryAquire a transport when it's in pending state

When a playing A2DP headset receives AVDTP suspend command then
a start command, it enters the pending state and will be confirmed
suspend after a short while(by checking the debug log of bluez)
causing a2dp audio stop.  According to bluez media API, in this
state CRAS could send 'TryAquire' method to acquire the transport
again.

Note that this problem can be reproduced on specific headset by
switching back and forth between HFP and A2DP.

BUG=None
TEST=Enable HFP, connect to Jabra EASYCALL headset and play mp3
file. Manual switch between HFP and A2DP and verify audio does
not disappear.

Change-Id: Iebfbd5d86a91da8e6af7b620851784a2a37a4d0b
Reviewed-on: https://chromium-review.googlesource.com/214134
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Candy: Add UCM config for Candy

This is a clone of the Rambi UCM config.

BUG=chrome-os-partner:31706
TEST=`emerge-candy adhd`

Change-Id: I3f5dde56639799ca1ef76d91efa3ce18dcec6129
Reviewed-on: https://chromium-review.googlesource.com/215861
Reviewed-by: Marc Jones <marc.jones@se-eng.com>
Commit-Queue: Huki Huang <huki.huang@intel.com>
Tested-by: Huki Huang <huki.huang@intel.com>
UCM config: Add UCM config for Samus

This contains basic initialization:
AIF1 Playback -> PDM1 (speakers)
AIF1 Playback -> OUT1/OUT2 (headphones)
DMIC1 -> AIF1 Capture
IN1P/IN1N -> AIF1 Capture

Default config:
playback to speakers
capture from DMICs

Headphone plugged in:
playback to headphone; speaker disabled

Analog mic plugged in:
capture from analog mic; DMICs disabled

BUG=chrome-os-partner:29649
TEST=audio playback and recording via headset/speakers/dmics on samus

Change-Id: I373d245bff96f23171cace6fc688d31a6fb253a6
Signed-off-by: Ben Zhang <benzh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/215637
Reviewed-by: Dylan Reid <dgreid@chromium.org>
scripts: initial patch for volume_tuning

This patch includes source code of volume-tuning.appspot.com

BUG=chromium:401328
TEST=open volume.html and generate a config file.

Change-Id: I8b09a27d753ff071b1475292c8e4e4111bdda922
Reviewed-on: https://chromium-review.googlesource.com/215906
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
Commit-Queue: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
scripts: Modify default volume step for headphone

The default volume step of headphone is too low such that sound is too
loud at minimum level.
Modify default volume step for headphone from 50 to 70.

BUG=chromium:401328
TEST=run volume tuning app and generate a config file. Check default
volume step for headphone is changed to 70. Apply this config and check
headphone volume at minimum level is very small.

Change-Id: Ia6e1e0727097c9a2db500bb45a20decfce4a3068
Reviewed-on: https://chromium-review.googlesource.com/215907
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
Commit-Queue: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
Swanky: Adjust volume curve for speaker

BUG=chrome-os-partner:31329
TEST=`emerge-swanky adhd` verify file is modified.

Change-Id: I1ff31ef4761e8e790df3e965a548b411fae8f4dd
Signed-off-by: Pan Sheng-Liang <Sheng-Liang.Pan@quantatw.com>
Reviewed-on: https://chromium-review.googlesource.com/213764
Tested-by: David Wu <david_wu@quantatw.com>
Reviewed-by: Yung Leem <yungleem@chromium.org>
CRAS: byte_buffer - Fix compilation issues.

sys/param.h is needed for the MIN macro.
obviously destory should be static inline.

Change-Id: I5d20984fa3304bde25e5da017e29c174ea6101d5
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/216508
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: Remove min_cb_level.

min_db_level hasn't been used in a very long time, for input it is
totally ignored for output it was always set to cb_threshold anyways.

BUg=none
TEST=make check, and play audio on Blaze

Change-Id: I230c763d1db8e4816fe45e146c6afdc39438f132
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/216509
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: Fill stream_attached message with a pointer.

Pass a pointer to an audio format instead of copying the format.

BUG=none
TEST=make check

Change-Id: Ie1bcaa127b177566622b52aba9d2768e31a3e034
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/216540
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: rclient - Rename remote format variable.

No functional change, just rename the variable from mfmt to
remote_format.  This variable holds the unpacked format from the
remote client.  Using this name will make the code more legible when
doing server-side format conversion.

BUG=none
TEST=none

Change-Id: I8c32311a19be126f1a3145c888e623a1bba3c40b
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/216541
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: rstream - Remove unused flags variable.

After three years we haven't found a use for flags, remove it.

BUG=none
TEST=make check

Change-Id: I4a3e7af0c23a27d5fedac8f3a21bd5d7aa6580da
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/216542
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: rstream - re-order struct

To keep the input/output shm variables together, put the format and
list members at the bottom.  Add a comment describing the members.

BUG=none
TEST=none

Change-Id: If2ea9d1cff4b8dc7bec45aee0dd3b0beb453ac6b
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/216543
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS dbus - Don't select on dbus write watch

Dbus connection is notified by status toggle of two types
of watch: write watch and read watch. CRAS should only listen
on the read watch and ignore the write watch for now.

These two watches has the same file descriptor but of different
direction, this change fixes a tricky bug that CRAS originally
add select the fd of the read watch, but incorrectly remove it later
when sees write watch toggles, so CRAS will fail to dispatch dbus
message.

Note that the write watch toggle is difficult to reproduce in normal
usage, but can happen 100% of the time when runs a test to
continuously switch between HFP and A2DP.

BUG=None
TEST=Enable HFP and test switch between HFP and A2DP, verify by
dbus-send GetNodes can receive result.

Change-Id: Ib5eb9658afe4d663fe40c49da89a33d2b6c383a2
Reviewed-on: https://chromium-review.googlesource.com/216595
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
CRAS: fmt_conv - make input buffer const.

The input buffer to convert frames isn't modified.

Change-Id: Ia39737d40d5e11fa2d6a62fbdd4c322f0fcf21c1
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: fmt_conv - Add accessors for in and out formats.

These will be useful to get sizes and sample rates easily when doing
SRC on the server side.

Change-Id: If39d2f7f7d810cb9eb91548c35f439aba3b249b6
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: fmt_conv - Move creation from client to fmt_conv.

Move the code that configures the format converter from cras_client
into the format conversion core.  This will allow for the server side
to reuse the same set up code when the SRC is added to it.

BUG=none
TEST=unittests, play two different formats of audio.

Change-Id: Ie0277ae66666ba70ae2c2cea7b067b3378f3da3e
Signed-off-by: Dylan Reid <dgreid@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>
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>