CRAS: audio_thread - Increase audio thread log size to 32k.

This allows more wake cycles to be dumped for debugging.

Change-Id: I75afd1c62e63c162ec5f07760fe276c2f3471393
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - Log stream add/remove.

Log when streams are added or removed to the audio thread.  This will
make it easier to debug timing issues that occur when a stream is
attached.

BUG=chromium:244615
TEST=check audio log for new events.

Change-Id: I2d45de3c72dd0111f7ec1113b08ae06a56ad6438
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - Move logging to its own header file.

Move the logging functions to a separate header file so that logging
can be done from outside of audio_thread.c.

BUG=none
TEST=cras_test_client --dump_s

Change-Id: I47dd00bbeb6879ec58ab92c07a2513a9a5e115c2
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - Remove unused args from iodev callback.

The 'ts' and 'polled' arguments aren't needed.  hfp is the only user,
it totally ignores ts and used polled to check if it should run.  Only
call the callbacks when the fd is ready.

BUG=none
TEST=unittests pass.

Change-Id: Ic9413865fca58a2a635d23bda26826662496e733
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - Allow disabling callbacks and write fds

Enable audio_thread callbacks to poll an fd for being ready for a
write.  This will allow the a2dp iodev to check when the bluetooth
socket is ready for more data.

BUG=chromium:244615
TEST=unittest only

Change-Id: I6e01aa8ca8dabf2ed0a5801b90b2dd4dbdd400e6
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: a2dp_info - always set frame_count to one.

frame_count is only useful if packets are being broken up, always set
it to one.  This indicates that this is the last fragment of the
packet, which is true because there is only one fragment.

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

Change-Id: I04b2e4d18a33b90425a8dcaa2599f647d393ef20
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: sbc - Return on error.

If there is an error from the sbc codec, propagate it.  If it doesn't
totally fill the buffer, keep going and mark what it wrote as written
instead of bailing out.

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

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 - 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>
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