CRAS: a2dp_io - Don't send empty packets.

Don't send a packet just because nothing was processed this time.  If
there isn't data in the buffer there isn't anything to send.

Change-Id: If93a1e2255ef896ed21087331ce99e6d9c7fb1d8
Signed-off-by: Dylan Reid <dgreid@chromium.org>
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

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: I3fd3518ebee16ce8f2928ead4875d27ef0d26ebf
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: a2dp_io - Reset frames count when buffer fills up.

The bt buffer count tries to track how many frames are written to the
device vs how many have been consumed.  This number will inevitably
drift over time because the clock on the device is not known.  To
avoid this problem, reset the count whenever the end of the send
buffer fills up.  When the buffer is full we know that exactly the
buffer length of audio has been written but not consumed.

BUG=chromium:
TEST=play youtube and listen for dropouts overnight.

Change-Id: Id3f29a78650a5bf534480fb7886033e953fe0903
Signed-off-by: Dylan Reid <dgreid@chromium.org>
only send data near mtu sized chunks

Change-Id: Ia16b559d07d504fb34821aacdf0356f41c09c6d0
wip: find beginning of audio log