CRAS: audio_thread - Remove skip_mix flag

skip_mix flag is set only when shm is empty, and it wasn't
taking effect to skip any empty stream.  Before change d1b209c
cras_mix_add_stream() doesn't mix a stream if there's zero
frames in shm, but that logic no longer exists.
Clean up this flag and check the shm frames before mixing.

BUG=None
TEST=play youtube and drum machine webapp, execute 'cras_test_client
--playback_file -' at the same time, verify audio not drop.

Change-Id: Icf2562e668e7f28b22d009ce2e34bc5cc11b2803
Reviewed-on: https://chromium-review.googlesource.com/212270
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
CRAS: cras_iodev - Remove software_volume_scaler in cras_iodev

Removes software_volume_scaler in cras_iodev. The scaler will be looked
up when audio thread writes data to buffer in possibly_fill_audio.
By doing this we do not need to worry which the active node is when the
software_volume_scaler is set. The scaler will be determined by system
volume, active node volume and software_volume_needed flag.

BUG=chrome-os-partner:31101
TEST=make check
TEST=On nyan_big, connect to HDMI. Change volume to around 20%. Reboot.
Listen to HDMI audio and check volume is around 20%.

Change-Id: Idf2c414e87f9271cc7d46dd145d69774aa87391b
Reviewed-on: https://chromium-review.googlesource.com/212002
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
CRAS: iodev_list - select, rm, then select active dev should work

Fix the bug that when a device X is originally selected as active,
then removed from active list for any reason, select it back
will fail.

BUG=None
TEST=Call dbus-send with SetActiveOutputNode, RemoveActiveOutputNode
and then SetActiveOutputNode in order to the same node id, should
see the node selected as active by cras_test_client --dump_s

Change-Id: Ia6b5538f5ab68e774e8f1546d294dd546b686456
Reviewed-on: https://chromium-review.googlesource.com/212473
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
CRAS: unittest - write two streams one empty one full

Add test case to cover that when writing two streams, if
one stream becomes empty for some reason, it should be skipped
and proceed write the streams which have samples.

BUG=None
TEST=make check

Change-Id: If4960b63245cd79940e5e832d94220d9f3deb9a9
Reviewed-on: https://chromium-review.googlesource.com/212289
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Revert "CRAS: unittest - write two streams one empty one full"

This reverts commit c3722294fb9d1775839d753e53c563512847d512.

This unittest was added to test that when two streams added,
should skip mix the empty stream.  This turns out wrong and cause
problem on two output streams of different cb_threshold, the correct
solution is to skip write an empty stream only when it's empty after
fetch. Correct unittest will be added in later change.

BUG=chromium:404885
TEST=make check

Change-Id: I34542cf9c96426719829bd3a12d65eee3b0726b4
Reviewed-on: https://chromium-review.googlesource.com/213043
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Revert "CRAS: audio_thread - Remove skip_mix flag"

This reverts commit 3b9e7e54a4615c82d98f65021fb520df57d5ac66.

skip_mix flag was removed and replace by checking shm frames == zero
to fix bad client bug.  However this is causing a more severe problem
on two output streams of different cb_threshold, revert this commit
since keeping the skip_mix flag still looks like the best way to handle
these cases.

BUG=chromium:404885
TEST=Play html5 video and open local wav file.

Change-Id: Id262af7ac5e81d2363df1adc4dc35ecbd0156c79
Reviewed-on: https://chromium-review.googlesource.com/213044
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
CRAS: audio_thread - Don't mix stream with skip_mix = 1

When two output streams are added and one is held by a bad client
that never fills audio to shm, we should skip mixing it so that
the other streams won't be affected.

Note that this doesn't solve the bad client problem completely, but
makes the other streams have a much better quality.

BUG=chromium:404885
TEST=Play youtube and at the same time execute 'cras_test_client
--playback_file -'

Change-Id: Id3dc4c87f3c68c283406f69bf76f7350849a4f22
Reviewed-on: https://chromium-review.googlesource.com/213045
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Expresso: add eq and volume tuning

BUG=none
TEST=`emerge-expresso adhd` verify files are present

Change-Id: I4ba29c90bbc8603d6b206b473aa60f1fb64b895b
Signed-off-by: Pan Sheng-Liang <Sheng-Liang.Pan@quantatw.com>
Reviewed-on: https://chromium-review.googlesource.com/212235
Tested-by: Lucas Chen <lucas.chen@quantatw.com>
Reviewed-by: Yung Leem <yungleem@chromium.org>
Tested-by: David Wu <david_wu@quantatw.com>
Commit-Queue: David Wu <david_wu@quantatw.com>
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>