CRAS: HSP - Register Headset Profile for AG role

Register HSP AG profile, which doesn't require any initialization
procedure for SLC at new device connection.

BUG=chromium:258183
TEST=Apply whole patch set for HSP, run HSP_AG_IAC qualification
test.

Change-Id: I65914102b8521097161b629fb201762ae70f7ad1
Reviewed-on: https://chromium-review.googlesource.com/209126
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
CRAS: HSP - handle HSP connection establishment and release

Handle the key press event (AT+CKPD command) from headset
profile device, and pass in the flag for headset profile to
handle call events differently, e.g don't send the indicator
notifications which only required by HFP.

BUG=chromium:258183
TEST=Apply whole patch set, run all HSP qualification tests.

Change-Id: I2a146372b320a03779ef6c2850ceb6ab6e46f432
Reviewed-on: https://chromium-review.googlesource.com/209127
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
CRAS: HFP - Free resource in correct order

Make sure an hfp_info is destroyed after the hfp_iodevs using it.
Also add check to prevent an hfp_info being used or stopped when
it's not in start mode.

BUG=chromium:258183
TEST=Run HSP_AG_ACR qualification tests can pass without seeing
CRAS crash.

Change-Id: I6cee8639e815f5317ec68227a6b1e3122b644d66
Reviewed-on: https://chromium-review.googlesource.com/209128
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
UCM config: peach - Use new HP enables.

These Headphone enable controls aren't automatically set when a Jack
plug is detected (unlike the pin switch that was used previously).
This was the Headphones don't unmute too early and cause a pop.

BUG=chrome-os-partner:26094
TEST=plug/unplug headphones while playing silence.

Change-Id: Idc664c24bf42cca1b4495da3cf11ccc09bfc84f1
Signed-off-by: Wonjoon Lee <woojoo.lee@samsung.com>
Reviewed-on: https://chromium-review.googlesource.com/203389
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
UCM config: daisy - Use new HP enables.

These Headphone enable controls aren't automatically set when a Jack
plug is detected (unlike the pin switch that was used previously).
This was the Headphones don't unmute too early and cause a pop.

BUG=chrome-os-partner:26094
TEST=plug/unplug headphones while playing silence.

Change-Id: I54fb8f15d66d67e6a088a067095b205bc71efdce
Signed-off-by: Wonjoon Lee <woojoo.lee@samsung.com>
Reviewed-on: https://chromium-review.googlesource.com/203406
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
CRAS: audio_thread - Remove draining streams from fetch.

Remove the function "remove_empty_streams".  All streams are already
looped through each wakeup in "fetch_and_set_timestamp", remove the
empty ones during that loop.  This will cause one extra wakeup before
the stream is removed after being emptied, but that is worth saving
the extra loop and the extra code.  This will also help make pending
timing changes easier by making sure streams are set to draining
before sleep time calculations occur.

BUG=none
TEST=cras_test_client --playback_file, let go to completion.

Change-Id: I328db7bc661a91dd6ab52c83a21f0884ec96d071
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/209276
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Owen Lin <owenlin@chromium.org>
CRAS: audio_thread - Fix line > 80 characters

Change-Id: I472a44ae42d0c83b6d68b8c57d744bd281a2cb40
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/209277
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
CRAS: audio_thread - Add find stream function.

This currently doesn't add much but will be more useful later when the
streams are kept in different places.

BUG=none
TEST=unittest

Change-Id: I995c1a6325159f27d52346bf7c0b5bbe4dbb7a48
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/209278
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: audio_thread - Factor out stream fetch.

Make fetching an individual stream its own function as a later change
will re-use this code to pre-fill the buffer.

BUG=none
TEST=none

Change-Id: I9715d3d1c2522f9d2dd86ef894a2ecf5630275f7
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/209279
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: telephony - Save callsetup state

This fixes a bug for HFP qualification test TCA 04, that
callsetup state needs to be saved at dial number event,
or the call status won't report correct right after call hangup.

BUG=chromium:211636
TEST=Run and pass HFP qualification test AG_TCA_BV_04

Change-Id: Ic7a67cfb5d27c166f35a61a30c5386eea0f3b7b1
Reviewed-on: https://chromium-review.googlesource.com/209743
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Revert "CRAS: type - Add node type keyboard mic"

This reverts commit a7c74b59229956b78940592e4ede973e6dd0ae29.

BUG=chromium:397407

Change-Id: Ia73777aa55f35a78d6911f858b7f9832142fbe0d
Reviewed-on: https://chromium-review.googlesource.com/209726
Tested-by: Chinyue Chen <chinyue@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Chinyue Chen <chinyue@chromium.org>
CRAS: HSP: register correct service record for HSP AG

Bluez handles the service record for HFP but not HSP,
so attach the full record for HSP in CRAS when registering
it using the external profile API of bluez.

This will let SDP report the correct service class list and
profile descriptor for headset profile to pass qualification.

BUG=chromium:258183
TEST=Manual test on Pixe, set DUT to discoverable.
Run IOPT_SDAS_BT_03 test case, verify it passes.

Change-Id: I235b3a27cf32a4807506cfe48084b4ddae275b1d
Reviewed-on: https://chromium-review.googlesource.com/210111
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
CRAS: audio_thread - Remvoe extra output check.

Now that unified streams are removed the extra check for output after
checking stream_uses_output is redundant, get rid of it.

BUG=none
TEST=make check

Change-Id: I97d8e0c1b92ac992a1ae9bd5fb05b16be16b0f70
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - Only set timestamp when fetching audio.

The timestamp is only used in the audio callback, only set it when the
callback will be invoked.

BUG=none
TEST=make check

Change-Id: I276100fc66812168766ad9cd820f130c0f8c9de8
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - Fix out-of-date comment.

There has only been one audio thread for a long time.

Change-Id: I99c2c7160f3ece8547c868d51373e15dc4601a7e
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - move first_dev helpers.

They are needed earlier in the file by a later commit

BUG=none
TEST=unittests

Change-Id: I37196bddc22c9fcf63cd6e01f61183b51697cc5a
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - pre-fill the odev when opening it.

Filling the odev with one cb_threshold of data will prevent the client
from seeing two quick requests when adding the first stream.

BUG=none
TEST=unittest and play audio on Yoshi.

Change-Id: Id98aaaf18164e684ba07185f9ae11e9264a219c0
CRAS: util - Add helper to add timespecs.

BUG=none
TEST=none =(

Change-Id: Idf70a1cc038395dca20de385401525b755d9f79f
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CARS: audio_thread - Keep next callback time per stream.

For each stream, save the time it should next be serviced.  This time
is start + n * callback_number.  Add one callback threshold of sleep
time after every callback.

This time will later be used to better calculate when to make a
callback to a stream.

Change-Id: I210329b320bdd0b9b885ad1d3ce0d50b166083f0
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - set stream draining on error.

If there is an error communicating with a stream, mark is as draining
so it is removed as soon as the audio is used up.

BUG=none
TEST=play audio on Blaze

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