CRAS: a2dp_io - Use a more "normal" pcm buffer.

The pcm buffer will work as a circular buffer, there isn't a helper
for this pattern even though it is used everywhere, that can be fixed
later, just open-code another one for now.

This change will make separating the timing of bt socket and the
stream's client easier in a later change.

Change-Id: Ibdae989b6f3cb10c8803e423bf31618ca1eef2f0
Signed-off-by: Dylan Reid <dgreid@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>
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>
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>
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 --udmp_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
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>
only send data near mtu sized chunks

Change-Id: Ia16b559d07d504fb34821aacdf0356f41c09c6d0
CRAS: test_client - Add parsing of output log.

Printing the parsed log directly will make it more useful than a bunch
of numbers that you need to find a decoder ring for.

BUG=none
TEST=cras_test_client --dump_a

Change-Id: I78ae9f81fc3ce2298569b9a0ac5e800125fcfc43
Signed-off-by: Dylan Reid <dgreid@chromium.org>
wip: find beginning of audio log

Change-Id: I844edad5cb18404e8fe6d293548864feae4a1844
Set frame count based on number of times encode is called

Change-Id: If90f446bf6011a6441db69ca802a4fcbb62aafbd
Increase a2cp pcm buffer size to 16k frames

Change-Id: I46aa2c8cdcb4f689acb6bee3369f8e4b51b965bc
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>
CRAS: a2dp_io - set min_buffer_level for a2dp iodev

Set a minimum buffer level for a2dp devices.  This is needed because
of how bursty the devices are, often requesting audio in chunks of >
50ms.  The min_buffer level will guarantee there is audio ready when
the burst is needed.

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

Change-Id: I949180fa96b41781fcb43636f0138065bc8c3657
CRAS: a2dp_io - Better pre-filling of a2dp socket.

Pre fill the a2dp socket until it returns EAGAIN.  Only then do we set
the start time for the frames_consumed estimation.

BUG=chromium:244615
TEST=play youttube and web audio drum machine on jambox

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