History log of /external/adhd/cras/src/server/cras_bt_io.c
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
2e14c232763ac89fd9d2fa5e9b3fdcf6581b2db8 23-May-2017 Chinyue Chen <chinyue@chromium.org> Revert "CRAS: Deduplicate snd_pcm_open calls when opening a device."

This reverts commit 70182dd089ce9646f371ce0188ce4423d7f64f6a.

Reason for revert: broke the external mic on cyan and celes

Original change's description:
> CRAS: Deduplicate snd_pcm_open calls when opening a device.
>
> The current open device flow includes several functions like
> cras_alsa_fill_properties and update_channel_layout. They are used only
> once in the flow but each calls snd_pcm_open and then snd_pcm_close the
> device. Since snd_pcm_open is one of the most time-consuming hardware
> operations, the CL extracts the snd_pcm_open calls to the beginning of
> the device open flow to save time.
>
> 1. Update cras_alsa_fill_properties and update_channel_layout to take a
> handle as argument and do not invoke snd_pcm_open.
> 2. Rename existing open_dev functions to configure_dev. open_dev is now
> called at the beginning of the device open flow and invokes the
> snd_pcm_open call.
> 3. Put open_dev, cras_iodev_set_format, and configure_dev inside the
> cras_iodev_open function.
>
> BUG=b:719812
> TEST=make check and tested on reef
> Cuts time to open speakers from 78ms to 42ms
>
> Change-Id: I9b161217def5e87bf892f4ca8148f07bed5e71a5
> Reviewed-on: https://chromium-review.googlesource.com/505974
> Commit-Ready: Chinyue Chen <chinyue@chromium.org>
> Tested-by: Chinyue Chen <chinyue@chromium.org>
> Reviewed-by: Dylan Reid <dgreid@chromium.org>
>

BUG=b:719812

Change-Id: I22eb2fc70b4a5003a861be62d31bc2337b9918c3
Reviewed-on: https://chromium-review.googlesource.com/511982
Commit-Ready: Chinyue Chen <chinyue@chromium.org>
Tested-by: Chinyue Chen <chinyue@chromium.org>
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
70182dd089ce9646f371ce0188ce4423d7f64f6a 12-May-2017 Chinyue Chen <chinyue@google.com> CRAS: Deduplicate snd_pcm_open calls when opening a device.

The current open device flow includes several functions like
cras_alsa_fill_properties and update_channel_layout. They are used only
once in the flow but each calls snd_pcm_open and then snd_pcm_close the
device. Since snd_pcm_open is one of the most time-consuming hardware
operations, the CL extracts the snd_pcm_open calls to the beginning of
the device open flow to save time.

1. Update cras_alsa_fill_properties and update_channel_layout to take a
handle as argument and do not invoke snd_pcm_open.
2. Rename existing open_dev functions to configure_dev. open_dev is now
called at the beginning of the device open flow and invokes the
snd_pcm_open call.
3. Put open_dev, cras_iodev_set_format, and configure_dev inside the
cras_iodev_open function.

BUG=b:719812
TEST=make check and tested on reef
Cuts time to open speakers from 78ms to 42ms

Change-Id: I9b161217def5e87bf892f4ca8148f07bed5e71a5
Reviewed-on: https://chromium-review.googlesource.com/505974
Commit-Ready: Chinyue Chen <chinyue@chromium.org>
Tested-by: Chinyue Chen <chinyue@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
c84eb15a0fbd4a6b336d11438836b644fefc2679 08-Nov-2016 Moja Hsu <mojahsu@google.com> CRAS: dbus_control - Add serial number for USB device for stable id

Get additional sys attribute for "serial" which is serial number in
udev.
Add it into the stable_id_new calcuation and keep stable_id for backward
compitable.

BUG=chromium:661861
TEST=Plug 2 same type USB speakers into chromebook.
execute
"dbus-send --system
--type=method_call
--print-reply
--dest=org.chromium.cras
/org/chromium/cras
org.chromium.cras.Control.GetNodes"

Check if we have the same stable_id but different stable_id_new for the 2
speakers.

pass make check for unit test.

Change-Id: Iefefe383fd6143dd7c28fdba3cf3f3872c2dd726
Reviewed-on: https://chromium-review.googlesource.com/407723
Commit-Ready: Hsu Wei-Cheng <mojahsu@chromium.org>
Tested-by: Hsu Wei-Cheng <mojahsu@chromium.org>
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
fa4cd9766aec6eae544b1078ed835687c4e74617 31-Jul-2016 John Muir <muirj@google.com> CRAS: Use the hardware timestamp with available/used frames.

The ALSA device drivers can provide a timestamp associated with
the buffer read-pointer. This can be use to more accurately guage
the time that the next buffer is required.

Enable this functionality only when supported ALSA in the running
kernel.

BUG=None
TEST=Unit tests pass.
Verified on Samus (on kernel v3.14).
Verified on new device (kernel v3.18 - htimestamp enabled).
Verified a bluetooth device.
Verified a USB device.

Change-Id: I5bca36f7ad9a236e80b2e277ccc62ccc8c39905b
Reviewed-on: https://chromium-review.googlesource.com/366961
Commit-Ready: John Muir <muirj@google.com>
Tested-by: John Muir <muirj@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
50cf4aec95391fb7768d9a98e35e618edc7443f3 26-Jul-2016 Cheng-Yi Chiang <cychiang@chromium.org> CRAS: iodev - Add state variable in cras_iodev

Reland e9e2c8e CRAS: iodev - Add state variable in cras_iodev.

The bug in cras_iodev_open for input device has been fixed.
Since input device start in the end of open, its state should be normal
run. Also fix the unittest that failed to catch this issue.

Use state variable to maintain the state of iodev.
Remove no_stream_state flag in iodev.
Remove is_open ops in iodev.
Remove dev_running ops in iodev.

Now iodev uses start ops to determine if a device can stay in open state.
If start ops is not supported, device should start running right after
opening. Output device will be in no_stream state, while input device
will be in normal state.

This is in preparation for the next patch to move state transition from
write_output_samples in audio_thread into cras_iodev and cleanup iodev
interface.

BUG=chromium:519942
TEST=make check

Signed-off-by: Cheng-Yi Chiang <cychiang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/364432
Change-Id: Ibe857665be46965c52d4b4ff6f0f84dd63574373
Reviewed-on: https://chromium-review.googlesource.com/375581
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
8ebc96cf4135d449b8473e191386e0f896372039 25-Aug-2016 Cheng-Yi Chiang <cychiang@chromium.org> Revert "CRAS: iodev - Add state variable in cras_iodev"

This reverts commit e9e2c8e19fa28a469372bfa3e5fd942dcbb26f90.

The change somehow broke recording path. Revert it now and investigate
it later.

BUG=chromium:640659,chromium:519942
TEST=check recording works fine on chell.

Signed-off-by: Cheng-Yi Chiang <cychiang@chromium.org>
Change-Id: I2f6b17fd158f4063c69154810a14ed1b4e74e1b9
Reviewed-on: https://chromium-review.googlesource.com/375659
/external/adhd/cras/src/server/cras_bt_io.c
e9e2c8e19fa28a469372bfa3e5fd942dcbb26f90 26-Jul-2016 Cheng-Yi Chiang <cychiang@chromium.org> CRAS: iodev - Add state variable in cras_iodev

Use state variable to maintain the state of iodev.
Remove no_stream_state flag in iodev.
Remove is_open ops in iodev.
Remove dev_running ops in iodev.

Now iodev uses start ops to determine if a device can stay in open state.
If start ops is not supported, device should start running right after
opening. Output device will be in no_stream state, while input device
will be in normal state.

This is in preparation for the next patch to move state transition from
write_output_samples in audio_thread into cras_iodev and cleanup iodev
interface.

BUG=chromium:519942
TEST=make check

Change-Id: Ib393a56bfc5d8e49b65cacc6ad862e3bbaccf420
Signed-off-by: Cheng-Yi Chiang <cychiang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/364432
/external/adhd/cras/src/server/cras_bt_io.c
016277914b2ab40298e86145a25f8cb3cd22b790 19-May-2016 Cheng-Yi Chiang <cychiang@chromium.org> CRAS: iodev - Add no_stream and output_should_wake ops

Add no_stream ops with a default implementation in cras_iodev. The
default implementation is to fill some zeros.
Override no_stream ops to optimize no stream playback for alsa_io.
When there is no stream, and there is no valid sample in ALSA buffer
anymore, we can fill whole ALSA buffer with zeros, and let device hw_ptr
keep running while appl_ptr remains the same. This state in alsa_io is
defined as "free run".
When there is a valid sample ready from a new stream, we can move
appl_ptr to some distance ahead of hw_ptr such that the valid sample
written to the position of appl_ptr will be played at low latency.

If OptimizeNoStream flag is set in UCM, we enable no_stream
related ops in alsa_io.
If device has min_buffer_level, it will be taken into account when
resuming from free run.

Before filling whole ALSA buffer with zeros, valid samples must be played.
This is done by filling zeros targeting two times of callback level for
some cycles, until all samples in the device are zeros.
The number of zeros filled is tracked in filled_zeros_for_draining.
When hw_level is less than this value, it means all samples in device are zeros.
Then we can fill whole ALSA buffer with zeros.

Add output_should_wake ops to alsa_io so audio thread does not need to
wake up for alsa_io device when its buffer is filled with zeros.

Device other than alsa_io device can have its own optimization for
no stream playback if it override no_stream ops.

BUG=chromium:519942
TEST=make check
TEST=set OptimizeNoStream "1" in HiFi.conf on samus and run
below tests.
TEST=Check audio playback works for the first time.
TEST=Check audio playback works within 10 seconds after the first stream
ends.
TEST=cras_test_client --playback_f
/usr/local/autotest/cros/audio/fix_440_16.raw --show_latency and see the
latency of the second stream is reduced from 16 ms to 11 ms for speaker on
samus, from 10 ms to 5 ms for headphone.

Signed-off-by: Cheng-Yi Chiang <cychiang@chromium.org>
Change-Id: I953fe24f312942a691c2444132e4269c40ac3f70
Reviewed-on: https://chromium-review.googlesource.com/346084
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
a0bb5828a2f34a4722285a8b23c9418d66d95859 22-Jun-2016 Hsin-Yu Chao <hychao@chromium.org> CRAS: bt_io - Fix empty stable id on bt_io

The active node of bt_io doesn't have its stable_id filled
so it's always 0x00000000. This could cause problem in Chrome
UI to mess up preferences of two different BT headsets.

BUG=None
TEST=Connect BT headset, cras_test_client --dump_s
to verify that all BT nodes has a valid stable_id.

Change-Id: I5979dee87976ae1f6993483c853974675b7c0489
Reviewed-on: https://chromium-review.googlesource.com/354794
Commit-Ready: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
dace0e596c97dfa4b0a2b3baa3004376eb2fd2c0 22-Jun-2016 Hsin-Yu Chao <hychao@chromium.org> CRAS: bt_device - Fix bug in profile switching

cras_bt_device exposes functions for profile switching at iodev
open and at close. The reason is that when bt iodev is about to
open and meets the condition to switch profile, main thread needs
to re-enable this iodev after profile switching is done.
In addion to open/close, when each profile(A2DP or HFP) is connected
profile switch could happen but we should leave the enable/disable
status of bt iodev unchanged, or it could accidentally be enabled
while other device is in use.

This change fixes the bug that BT headset got enabled while internal
speaker is active. Also the profile switching functions are renamed
from
- cras_bt_device_switch_profile_on_open()
- cras_bt_device_switch_profile_on_close()
to
- cras_bt_device_switch_profile_enable_dev()
- cras_bt_device_switch_profile()

so it is more clear in which scenario we need to do the extra task
to enable the dev.

Note that this bug wasn't discovered until latest release because Chrome
always selected BT headset for active output when it is connected. And
now the behavior is changed to auto-select BT headset based on user's
last preference.

BUG=chrome-os-partner:54176
TEST=Connect BT headset, play audio and select output to internal
speaker. Restart system, seeing that internal speaker is the active
output. Play audio and now try connect BT headset, verify that when
BT headset is connected it doesn't play audio.

Change-Id: If30088a7bbe5d2b8caa726bce7feb79f73f44d31
Reviewed-on: https://chromium-review.googlesource.com/354793
Commit-Ready: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
54d7d7c2c921c0e264b1b22d4f5ffe642e3d4f9d 01-Apr-2016 John Muir <muirj@google.com> CRAS: Allow compile without DBUS.

This is required for building on Brillo where DBUS doesn't
exist. When DBUS is not available, use a new UTF8 validation
function.

BUG=None
TEST=Ran all unit tests with DBUS enabled.
Build with DBUS enabled or disabled.
Execution on Brillo with DBUS disabled.
Added unit test for new UTF8 validation function.

Change-Id: I284a41aea258f5d8ffb67edc76ec318363078b31
Reviewed-on: https://chromium-review.googlesource.com/339403
Commit-Ready: John Muir <muirj@google.com>
Tested-by: John Muir <muirj@google.com>
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
f96a10e395815823130ecc9f162b23b4bb4471f9 22-Apr-2016 Hsin-Yu Chao <hychao@chromium.org> CRAS: bt_io - Clean up the use of software_volume_needed flag

Currently for bluetooth audio software volume is used, no matter
what profile(HFP, A2DP) is used. In future when AVRCP is supported
and remote headset supports absolute volume, we'll be able to use
hardware volume on both HFP and A2DP.
This change cleans up related code so that only the parent bt_iodev
cares about the software_volume_needed flag, and can delegate
the volume adjust task to each profile iodev when this flag is
unset.

BUG=chromium:605035
TEST=Playback in A2DP and record in HFP, adjust volume can work.

Change-Id: I662597f8b08c100bfb4ad9539380f9e24e13952d
Reviewed-on: https://chromium-review.googlesource.com/340341
Commit-Ready: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
e91895c69bef2515b60d6e4514a5f8e8c53cb36f 22-Mar-2016 Cheng-Yi Chiang <cychiang@chromium.org> CRAS: iodev - Add start function to cras_iodev

In alsa_io, simplify dev_running to just check if device is running.
In alsa_io, implement start function to start PCM.
In audio thread, start device when sample is ready from stream and is
written to the deivce.

Avoid putting zeros to device when it is still waiting for the first reply
from stream in these two cases:
- If there is no stream on the device, only fills zeros to device when
device is running. Only device in idle stage will get these zeros.
- If there is no sample written, and device buffer is empty, only fills
zeros to device when device is running.

Add dummy start function definition to differnet iodevs.
For bluetooth and loopback devices, the devices start running when they
are opened.
For empty device and test device, devices are always running.

BUG=chromium:519942
TEST=cras_test_client --playback_f
/usr/local/autotest/cros/audio/fix_440_16.raw --show_latency; check the
latency is reduced from 13ms to 4ms on headphone, from 19ms to 10ms on
speaker.

Signed-off-by: Cheng-Yi Chiang <cychiang@chromium.org>
Change-Id: I0b54e8e78d6dd64e0e92d6c140fe644385483c9b
Reviewed-on: https://chromium-review.googlesource.com/333837
/external/adhd/cras/src/server/cras_bt_io.c
194f243f86bc9147967f65a2fa550d506df7930b 16-Mar-2016 Cheng-Yi Chiang <cychiang@chromium.org> CRAS: iodev - Add fields related to software gain in cras_ionode

Reuse flag software_volume_needed to enable/disable software gain on an input
node.
Use max_software_gain to store maximum software gain.
Only enable this flag for input on ALSA ionode where UCM MaxSoftwareGain is
set.
If there are capture gain controls on this alsa_input_node, their
combined gain will be set to 0dB in set_alsa_capture_gain when software
gain is used.

BUG=chrome-os-partner:50139
TEST=make check

Signed-off-by: Cheng-Yi Chiang <cychiang@chromium.org>
Change-Id: Ib6a2ffb5c607220f7539bbbe8c40561d7952689d
Reviewed-on: https://chromium-review.googlesource.com/332915
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Ben Zhang <benzh@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
0def72b968591065f56e88d67e5c83234184811b 16-Dec-2015 Hsin-Yu Chao <hychao@chromium.org> CRAS: iodev_list - add dev_enabled to update active node

Originally in CRAS, assume iodev1 and iodev2 both have only one
node. Selecting between iodev1 and iodev2 will not trigger the
update_active_node callback at all, for both iodev1 and iodev2.
This causes a problem that any mixer settings specified for HDMI
iodev in UCM config never gets set/unset.
Fix this bug by explicitly call update_active_node() when the state
of iodev changed.

BUG=chromium:364414
TEST=unittest

Change-Id: I84d535ced168932f2f91641cc157ef60b9d713d5
Reviewed-on: https://chromium-review.googlesource.com/318612
Commit-Ready: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
10fe628c1fb07d521e21ed5f45ab75fe505b062a 16-Dec-2015 Hsin-Yu Chao <hychao@chromium.org> CRAS: iodev - Add stable id for node

Stable id of iodev isn't enough to distinguish different nodes
on one iodev. Take into account the node name to build stable id
for each node.
This change fixes the issue that Chrome UI messed up preference
of internal speaker and headphone.

BUG=chromium:570570
TEST=dbus-send --system --type=method_call --print-reply \
--dest=org.chromium.cras /org/chromium/cras \
org.chromium.cras.Control.GetNodes | grep -A 2 StableDeviceId
to verify all nodes has different stable id.

Change-Id: I66ea886b9d76152e1adf2bb99aa6d24f2a308cd4
Reviewed-on: https://chromium-review.googlesource.com/318958
Commit-Ready: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
85137d0c83307ebbfa890e8a64446de5957fbbbc 11-Aug-2015 Chinyue Chen <chinyue@chromium.org> CRAS: iodev - Add stable device ID.

The stable device ID is an additional info for devices and does not
change due to plug/unplug. The stable device ID is constructed from
the device name plus

* card index and device index for internal devices
* VID and PID for USB devices
* MAC address for Bluetooth devices

BUG=chromium:466768
TEST=Verified on peppy with "cras_test_client --dump_s"

Change-Id: Ib615dd4bf5db3cc9383c758b8bf435fe947f3a18
Reviewed-on: https://chromium-review.googlesource.com/292326
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Chinyue Chen <chinyue@chromium.org>
Tested-by: Chinyue Chen <chinyue@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
e2a533757cc2ed6b43efec914a662081df7b89d8 29-Jul-2015 Cheng-Yi Chiang <cychiang@chromium.org> CRAS: bt_io - Drop invalid UTF8 node name

Check node name is a valid UTF8 string. If it is not, use default name
instead.

BUG=chromium:390678
TEST=unittest

Change-Id: I778e0cccbbf62ccd2b18b559b92054deaf9cd155
Signed-off-by: Cheng-Yi Chiang <cychiang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/289068
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
4d0d9fdb1457bb23168dbcf69ca247e1d7224baf 23-Jul-2015 Hsin-Yu Chao <hychao@chromium.org> CRAS: bt_io - Prevent reference to destroyed iodev

A crash is observed that a destroyed HFP iodev is still being
used, but there isn't yet a call path discovered can cause this
problem.
Add a safety check to cras_bt_io_remove() to return error if the
profile iodevs are messed up, and in that case log the err and
just destroy the whole bt iodev.

BUG=chromium:503520
TEST=Manual verify HFP and A2DP headset can work.
Use record app and YouTube to verify profile switch
can work.

Change-Id: Ie6d0d6555ada214af368067caf7ed8f4c8e9fc72
Reviewed-on: https://chromium-review.googlesource.com/287644
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
3f787ac37a53be6b3a065ee5d1a47427fae78100 25-Jun-2015 Hsin-Yu Chao <hychao@chromium.org> CRAS: audio_thread - Flush input buffer when 1st stream added

In multiple input devices use case, two mics are opened
sequentially before the first input stream attaches to read
input buffers. If one of the device open call takes too long
it would cause large buffer difference between input devs and
cause echo.
To fix this problem, flush the input buffer to discard all the
buffer already captured when the first input stream is added.

BUG=chromium:460515
TEST=Manual test audio record on two Jabra speakerphones.

Change-Id: I78fbc719b2827ef5b05612c01df8b2fce40041c3
Reviewed-on: https://chromium-review.googlesource.com/281890
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
bb28140f38fdf6627ec26696c943dfa4f9188450 18-May-2015 Hsin-Yu Chao <hychao@chromium.org> CRAS: iodev_list - Remove selected input/ouput

This change removes the selected input/output node from
server state, since now we allow multiple nodes be enalbed
using extension API and it makes less sense to store the
Chrome UI selected node. Note that the selected input/ouput
nodes were looked up when calling update_active_node()
to select different nodes on an iodev. This is changed to
pass in the node index to the callback.

BUG=None
TEST=Plug headphone jack, select between headphone and speaker
on UI, unplug headphone jack. Do the same test for mic jack and
internal mic, verify everthing works as it should be.

Change-Id: I5600ee775980e5bec4b314e259391da810368873
Reviewed-on: https://chromium-review.googlesource.com/272343
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
8401cbaa8d5bf558960d30ea8fc7a521ca92a1fe 23-Mar-2015 Hsin-Yu Chao <hychao@chromium.org> CRAS: bt_device - Fix incorrect active profile

This change fixes a bug that when headset connects while there
are already input and output streams. If A2DP connects first, the
output routes to BT headset and set the active profile flag to
'A2DP'. When HFP/HSP connects a short while later to create the BT
input iodev, the active profile gets incorrectly set to 'HFP/HSP'
and cause the profile switching never happen.

BUG=chromium:461636
TEST=
1. Open YouTube to output audio, manually connect HFP/A2DP
headset, verify audio streams to the headset.
2. Use vocaroo.com to record audio, verify switches to HFP/HSP.
3. Power off headset, and then power it on to trigger reconnect.
Verify audio input/ouput routes to BT headset.

Change-Id: Id5f6dfc4f7e99c4dd7f1646dc6ee75fe7a60693a
Reviewed-on: https://chromium-review.googlesource.com/261881
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
5f01b1beb131b2c1e184970bba53d748a077f7e8 17-Mar-2015 Hsin-Yu Chao <hychao@chromium.org> CRAS: hfp_iodev - Register callback for when SCO packet size changed

Add the ability to hfp_iodev to modify the buffer size after open.
This is important for some BT adapters prefers a smaller SCO packet
size other than the reported MTU to update the accurate buffer size
so that audio thread doesn't confuse with the room to fill buffer but
never get enough buffer from hfp iodev.

BUG=chrome-os-partner:36187
TEST=Test HFP/HSP headset on veyron_minnie
Use 'cras_test_client --dump_a | head -n20' while playing
YouTube to verify the buffer size displayed is slightly
less than the max allowed buffer size.

Change-Id: Iff64b97c4b37a3b539b547274a01a31a1ada1208
Reviewed-on: https://chromium-review.googlesource.com/260519
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
971f1da15d17fe613cf83e59beb84d0b66a1fadd 30-Jan-2015 Hsin-Yu Chao <hychao@chromium.org> CRAS: bt_io - Change detect logic of bt profile

Originally we rely on the profile capability stored in the
cras_bt_device structure to determine if it's ok to switch
to the other profile. However this is not reliable when more
than one headsets are connected, only the 1st headset supporting
A2DP will be enumerated in CRAS, due to that bluetoothd sends
notification to configure only one a2dp device.

This change fixes the issue by checking if a bt_io has a node
attached of certain profile, instead of checking the supported
profiles claimed in cras_bt_device.

BUG=chromium:448594
TEST=unittest. Connect bt headset A, and then connect a second
bt headset B. Open YouTube to test audio output on headset B,
and then use 'cras_test_client --capture_file /tmp/1' to open
an input stream, ctrl+C to stop the recording, verify audio
output is still good.

Change-Id: I1bc51017b7a8cc637c0aeea864794dc5968213f5
Reviewed-on: https://chromium-review.googlesource.com/244636
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
f43ea02b12cb9a694b6e06a41b488b1af641aafb 29-Jan-2015 Hsin-Yu Chao <hychao@chromium.org> CRAS: bt_io - Free old format when open fail

When a bt_io first added to active device list but failed to
be open to stream audio, its ext_format and format members
remains non-null. Later when this bt_io switches profile and
about to open again, the non-null format prevents the
update_supported_format callback be called to configure the
profile specific iodev, and cause crash.

BUG=chromium:451379
TEST=verify in auron_yuna, see no CRAS crash by the steps below:
1. Open Youtube to stream audio
2. connect DUT to a HFP/HSP only headset
3. connect DUT to the other bluetooth headset(A2DP + HFP/HSP)

Change-Id: Ic47b2ff34dfa452b93aaf8566e65f820715a1e6b
Reviewed-on: https://chromium-review.googlesource.com/244254
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
ba771746acf979c111c5f79694258e455d1dae7c 06-Jan-2015 Hsin-Yu Chao <hychao@chromium.org> CRAS: bt_io - check profile by bt_io's active node

The active_profile member of cras_bt_device is used to mark the
target active profile before doing the actual profile transition,
which doesn't reflect in real time the active profile being used
by bt_io.

A few crashes are indirectly caused by it, so add the
cras_bt_io_on_profile() function and use it instead of checking
the 'active_profile' member when BT headset disconnects.

BUG=chromium:446089
TEST=Connect BT headset, use audio visualizer app to test HFP.
Disconnect BT headset from bluetooth UI to verify there's no
crash.

Change-Id: I0a73b79652eb4518c204b586707fe42706bb6bb9
Reviewed-on: https://chromium-review.googlesource.com/238690
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
8a78d9d465774605551f1134c293b5ddd0d251b8 05-Jan-2015 Hsin-Yu Chao <hychao@chromium.org> CRAS: bt_io - Don't remove the dummy node

The first ionode created on a bt_io is a dummy node used to
point to the other node of active profile (A2DP or HFP). Be
careful not to remove this node when we have to need to remove
any other node when BT device disconnects.

BUG=chromium:446089
TEST=Connect BT headset and test HFP using audio visualizer app.

Change-Id: Iebd3fa59371cfc8f907d49b57b7251460461d2ff
Reviewed-on: https://chromium-review.googlesource.com/238319
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
65b542d23eea88f36d2f22e25d15568b53ec611b 11-Dec-2014 Hsin-Yu Chao <hychao@chromium.org> CRAS: bt_io - Handle set_volume when profile switches

A2DP uses software volume while HFP/HSP supports speaker gain
setting. Implement the set_bt_volume callback to delegate the
job to each profile iodev. Also sync the volume settings
when update_active_node.

BUG=chromium:432432
TEST=Connect bluetooth headset, adjust volume. Verify that
volume stays around the same level when switches between
A2DP and HFP/HSP. Note that the volumes are not neccessary
the same since both profiles have different curve.

Change-Id: I6cda86e1129e46cc750e62c6c9c832e5d86fa270
Reviewed-on: https://chromium-review.googlesource.com/234626
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
532e64eee91fc4acf5796e0a61c242a442a4cc04 05-Dec-2014 Hsin-Yu Chao <hychao@chromium.org> CRAS: bt_io - Dummy plugged node in bt_io

Originally a2dp and hfp iodevs are planned to be exposed as
different nodes on one bt_io, this introduces a few issues
like:
1. Chrome stores seperate volume preference for them.
2. When CRAS auto-switches profile, node index update will
make Chrome re-select to the same device causing additional
device close/open and introduce trouble to a2dp if this
happens too fast.

Use a dummy plugged node to act as active and plugged other
profile specific nodes is a good work around to these problems.
We will address these issues to allow separate volume settings
for different profiles after AVRCP support is ready
crbug.com/256746

BUG=chromium:432432
TEST=Connect BT headset, adjust volume and verify the settings
stays the same when profile switches.

Change-Id: I2efe0200d381359138d2e5d4f8c2ca7705804196
Reviewed-on: https://chromium-review.googlesource.com/234624
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
b514951036b0ca233d4405c0fd6310ad021f2062 10-Dec-2014 Hsin-Yu Chao <hychao@chromium.org> CRAS: bt_device - try remove profile dev

There could be a case that BT profiles got disconnected one at
a time so there's a short period audio_thread is still accessing
the device before the bt_io destructor is called. For safety we
need to check if the profile iodev is open for use before we try
to remove it.

BUG=chromium:432432
TEST=Connect bluetooth headset, play YouTube, disconnect headset.

Change-Id: I1d5bf3a5e77fcec2c4af0727b985bd2f567904c2
Reviewed-on: https://chromium-review.googlesource.com/234623
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
583ddd2776fd9639e34fc138a692cd58dabd3306 27-Nov-2014 Hsin-Yu Chao <hychao@chromium.org> CRAS: bt_io - detect and switch profile

Implements the logic to detect the use scenario and auto switches
to the preferred profile.

BUG=chromium:432434
TEST=unittest

Change-Id: If687fdfcfa67a97021312406519bc09d1dab1c1e
Reviewed-on: https://chromium-review.googlesource.com/231872
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
0d17ce053a25f0c1bb7c15573a4253372d95c8e9 20-Aug-2014 Hsin-Yu Chao <hychao@chromium.org> CRAS: bt_io - Add bt_io to cras_bt_device

Make cras_bt_device holds a list of iodev of different stream
direction and add functions to append or remove profile specific
iodev to/from a cras_bt_device. In later changes, a2dp and hfp/hsp
iodev will not add to iodev_list directly but instead append to the
corresponding cras_bt_device and operates behind the bt_io wrapper.

BUG=chromium:432434
TEST=unittest

Change-Id: Iefe20a689f394f9d40849e82ff5410c04ae39232
Reviewed-on: https://chromium-review.googlesource.com/231868
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c
5f8889ab0bc94adba368f593232b0355744956d8 25-Nov-2014 Hsin-Yu Chao <hychao@chromium.org> CRAS: bt_io - Add bt_io module

To allow A2DP and HFP/HSP iodev to exist at the same time and can
switch between them. Adds the bt_io module as a wrapper to hold a
list of profile specific iodevs and delegate the audio sample
transmission job to the iodev of active profile.
In later change the bt_io will detect the situation user wants to
switch to a different proflie and communicate with cras_bt_device
to do the switch.

BUG=chromium:432434
TEST=unittest

Change-Id: I4dcd7269b27f012115676cb44b9b60cb0f9cda6d
Reviewed-on: https://chromium-review.googlesource.com/231867
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
/external/adhd/cras/src/server/cras_bt_io.c