CRAS: audio_area_ut - Fix mono/stereo copy tests.

The 'frames' are the number of channel sets, they should always match.

BUG=none
TEST=this is a test.

Change-Id: I1e9246b7453f8bab834aacb37d808ce84d8140c2
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/207062
CRAS: audio_thread - Handle output buffer underruns better

Decouple the fill zero frames task from adjust_level() function
and better handle underrun in write_streams().
Originally when min_buffer_level is specified for output device, we
fill that amount of additional zero frames to prevent noise at
underrun. There are a few places we could add check for low buffer
level case. After test with cras_test_client to emulate a broken
client, found the USB noise problem is improved when padding
additional zero frames at the point that the output stream doesn't
reply the request and buffer level runs below min_buffer_level.

BUG=chromium:391663
TEST=Manual test on Stumpy using USB headset.
'cras_test_client --playback_file <file>' and hit 'p' to emulate
that the client doesn't response. Before this change, could hear
noise when client is paused. Verify there is less noise after
this change is applied.

Change-Id: I8948893bcc46883badc7a850eaebbe43c805604b
Reviewed-on: https://chromium-review.googlesource.com/206626
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Gnawty: add eq and volume tuning

BUG=chrome-os-partner:30299
TEST=`emerge-gnawty adhd` verify files are present

Change-Id: I1a914d7f820ede0dbffa01c64264e87ef6186341
Reviewed-on: https://chromium-review.googlesource.com/207061
Reviewed-by: Yung Leem <yungleem@chromium.org>
Commit-Queue: Bernie Thompson <bhthompson@chromium.org>
Tested-by: Bernie Thompson <bhthompson@chromium.org>
CRAS: a2dp_io - Write as much of the buffer as possible.

Loop in flush_data to write as much of the pcm buffer as possible.
This will make de-coupling the pcm and a2dp buffer levels easier.

Change-Id: I3a546a343d390e5defa1988e0b2cff55d94be575
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/206255
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: a2dp_info - make avdtp_write static.

It isn't used outside the c file.

Change-Id: I5c589c1f0b3895974107b5cbcca2377be90624a1
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/206256
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: a2dp_io - Handle ENOSPC error from SBC encoder.

If there isn't any space to encode samples then the SBC codec will
return -ENOSPC.  Handle that explicitly when encoding samples.

BUG=chromium:244625
TEST=play bluetooth audio to jambox.

Change-Id: If9e4fd44d5852580406e4810483893972b5530f2
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/206257
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: ionode: Clean up unused 'priority' field

CRAS used to have audio device auto selection, which relies
on a priority assigned to each node. Now the selection logic
moved to Chrome and Chrome is using device type and plugged
time to choose device instead.

BUG=None
TEST=plug and unplug mic jack to see device selection
works as expected.

Change-Id: If60e7a9967678ee87bafc782570edce32c7fe9f5
Reviewed-on: https://chromium-review.googlesource.com/205745
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Glimmer: Modify volume curve for speaker_eq enable from R35

   BUG=chrome-os-partner:30152
   TEST=test the volume using 1K tone
   Signed-off-by: Keith Tzeng <keith.tzeng@quantatw.com>

Change-Id: I308d4d5d04ba8cbcad6351e6119a37577e057bd3
Reviewed-on: https://chromium-review.googlesource.com/207308
Reviewed-by: Yung Leem <yungleem@chromium.org>
Commit-Queue: Keith Tzeng <keith.tzeng@quantatw.com>
Tested-by: Keith Tzeng <keith.tzeng@quantatw.com>
CRAS: a2dp: writes to socket in a chunk of size MTU

We're seeing strange behaviors on some devices when sending
payload less then MTU, even if it contains integral number of
SBC frames. For some speaker, bluetooth headset will even
disconnect from Chrome OS device. Fix that by limit a2dp samples
to be sent when it's near MTU.

BUG=chromium:306898
TEST=Test with HMDX RAVE bluetooth speaker, audio should play well
instead of disconnect from Chromebook.

Change-Id: Ia8d2cc67d24e5c0b96f2ecacadcde41310982d46
Reviewed-on: https://chromium-review.googlesource.com/205190
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
CRAS: HFP SLC and telephony: Add missing header

BUG=None
TEST=None

Change-Id: Ifc7dc67119fc88ab583395766849e0f2bb910e62
Reviewed-on: https://chromium-review.googlesource.com/206809
Commit-Queue: MengHuan Yu <menghuan@chromium.org>
Tested-by: MengHuan Yu <menghuan@chromium.org>
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: HFP SLC and telephony: Coding style clean up

Convert pointer type when using the return value of calloc.
Add spaces between string integral and identifier.
Fix indent on 3 lines.

BUG=None
TEST=None

Change-Id: I224be70027088b6cef4b227ae2d27d21386daf5f
Reviewed-on: https://chromium-review.googlesource.com/206980
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: MengHuan Yu <menghuan@chromium.org>
Tested-by: MengHuan Yu <menghuan@chromium.org>
CRAS: HFP SLC: Remove repeated "\r\n" in reply msg

By spec 4.33, each AG reply should be in "\r\nMSG\r\n" form.
So make the message sender to process internal and avoid to handle it in rest string literal.

BUG=chromium:211636
TEST=None

Change-Id: Id9f62e37e2761183bd69d400779fa2a6847a26cd
Reviewed-on: https://chromium-review.googlesource.com/206981
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Tested-by: MengHuan Yu <menghuan@chromium.org>
CRAS: a2dp_io - Break up encode and write.

Breaking up encode and write will make managing the amount of data
that is queued easier.

BUG=chromium:244615
TEST=play audio to jambox.

Change-Id: Iaa0105a2a55520f92d477b7fca823947db6a8f19
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - log delay when filling output

Add the delay to the audio thread log.

BUG=none
TEST=cras_test_client --dump_a

Change-Id: I3dea9b453446378bb77edbca37ff855a55dddf29
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: a2dp_io - drive socket writes from fd poll

Instead of writing to the A2DP socket based on a timer, write until it
is full.  Add the stream file descriptor to the select list in the
audio thread.  This will call back to write when the fd is writeable.

BUG=chromium:244615
TEST=play audio to the jambox.

Change-Id: I50e9e995a4f035d32a6934d6b23af2425c9dba19
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: a2dp_io - Set socket depth based on MTU size.

Setting this depth will allow the socket to be filled and writes to be
throttled at a reasonable level.  The default depth ends up being
almost four seconds of audio which caused unreasonable latency.
Account for the extra two MTUs of data in the delay calculation as
well.

BUG=chromium:244615
TEST=play A/V sync test on youtube.

Change-Id: Ie0d79743977340a5fb365432f67a857b32551a15
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: a2dp_io - Log encode and write to audio thread log.

Use the audio thread log to track when samples are encoded and when
data is written to a2dp.

BUG=none
TEST=cras_test_client --dump_a

Change-Id: I0f298017c18c00bf2e37aa7278dad5a2ffce5620
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: a2dp_io - Log mtu size at startup.

Add the mtu size to the print when opening an A2DP iodev.

BUG=chromium:244615
TEST=none

Change-Id: Id5af344cc02f9d2bfeb19a10c1c3c9c29fff78dd
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: a2dp_io - Increase a2cp pcm buffer size to 16k frames

Give more space for pcm samples to accumulate in the iodev.  This
larger buffer will allow for the min_buffer_level to be set higher and
for there to be more samples available to cover bursty requests from
bluetooth speakers.

BUG=chromium:244615
TEST=play audio to jambox.

Change-Id: I46aa2c8cdcb4f689acb6bee3369f8e4b51b965bc
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: a2dp_io - Limit frames_queued.

Make sure not to report that fewer frames are queued than are actually
present.  Reporting less here will tell audio_thread to fill (size -
frames_queued) which is a problem if there isn't room.

BUG=chromium:244615
TEST=youtube and drum machine to jambox.

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