CRAS: server - ignore NULL dbus

In case dbus isn't running, don't call the functions that depend on
it.  This won't happen on ChromsOS, but can if running on a generic
Linux build/chroot.

BUG=none
TEST=build and run in chroot without dbus.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: I1305a0d57f29aeb5152d4a19b11ab70eb0a7f68c
Reviewed-on: https://gerrit.chromium.org/gerrit/39093
Reviewed-by: Scott James Remnant <keybuk@chromium.org>
CRAS: dbus - replace typedef with include.

Build was failing on some versions of gcc because cras_server includes
both cras_dbus.h and cras_bluetooth.h each had a typedef for
DBusConnection.  Remove the typedef completely replace with forward
declaration of the struct.

BUG=none
TEST=builds and passes all unit tests.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: I477b6b38ec2a64cfc7aadf30c760ae7e6e746e4f
Reviewed-on: https://gerrit.chromium.org/gerrit/39031
Reviewed-by: Scott James Remnant <keybuk@chromium.org>
CRAS: iodev - track sleep correction in iodev.

Instead of tracking the sleep correction frame count in alsa io, move it
to iodev as more iodev implementations will need to use this.

BUG=chromium-os:35272
TEST=alsa_io_unittest, and manual: cras_test_client with differnt
latencies.

Change-Id: I84406f65f59922d74c053635a43a56c693f5d77c
Signed-off-by: Dylan Reid <dgreid@chromium.or
CRAS: alsa_io - Have open/close take an iodev.

Instead of passing an alsa_io pointer to open and close, pass an iodev
pointer.  This will allow these functions to be called from the iodev
core without caring what type of iodev is being used.

BUG=chromium-os:35272
TEST=alsa_io_unittest

Change-Id: I2133b4d2ecc0be1f6b87040c3dced47e38212a15
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: alsa_io - Add get/put buffer helpers.

Pull out getting and returning mmap buffers from alsa to helper
functions.  This will aid in refactoring the logic in the read/write
functions to be alsa-independent.  Once it is alsa independent it will
be able to be reused across other types of io devices.
Rework some types so that no alsa-specific types are used.

BUG=chromium-os:35272
TEST=alsa_io_unittest

Change-Id: I81306a8aa54c599885ce6cbb5e8c1e6f7b673ed5
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: alsa_io - Remove extra audio fetch.

During playback of two streams, if one is much higher latency than the
other, there was a slight optimization to fetch the audio early if
possible.  There was a bug in that this fetched audio from the low
latency stream the first time it ran, and since the fetches don't block
unless about to underrun, it didn't save anything.  Remove the extra
fetch.

BUG=chromium-os:35272
TEST=alsa_io_unittest, plus simultaneous playback of two streams one
with 10mS latency the other with 100mS latency, ensure no dropouts.

Change-Id: I2b5196babdcb68093d6383a0c80ce77c9ff74766
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: alsa_io - factor out more alsa specifics from read/write.

Pull out checking the level and delay into functions so that the code
using the return values can be re-used for other iodevs.

BUG=chromium-os:35272
TEST=alsa_io_unittest

Change-Id: I45eae3d15566dc9892364aa5318bbbb66dc6acd8
CRAS: iodev - common time to sleep calculations.

Make the calculation of time remaining to sleep the same between input
and ouput in alsa io.

BUG=chromium-os:35272
TEST=alsa_io_unittest

Change-Id: I30ca84775c29fbd099e98ebecf59b03f01321eac
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: alsa_io - Pass iodev instead of aio.

Pass around an iodev pointer instead of an alsa_iodev pointer.  This
will allow refactoring much of this code into the iodev implementation
so it can be reused for new iodevs, such as synchronous ones and
bluetooth.

BUG=chromium-os:35272
TEST=alsa_io_unittest

Change-Id: I1641f3007e1de6a4f2a164a73aa86e84ba25c1c0
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: alsa_io - Add callbacks to iodev struct.

Add callbacks for all alsa-specific ops used from the audio callback to
struct cras_iodev.  This will allow these device specific functions to
be set differently for each typeof iodev and for the calling functions
to be moved to a common place.

BUG=chromium-os:35272
TEST=alsa_io_unittest, manually play and record audio.

Change-Id: I7c50c0e2add0c591338dd807825a52397b8a0c77
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: alsa_io - Move open/close ops to iodev base.

Prepares for moving the functions calling these ops to a common place.

BUG=none
TEST=make check

Change-Id: Id9f166e227035262ec013f9d0d2138fc60312736
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: alsa_io - Pass iodev to terminate and message functions.

Instead of taking an alsa_io take an iodev as an argument so they can be
moved to a common place as they have nothing to do with alsa.

BUG=chromium-os:35272
TEST=make check

Change-Id: I7f3c9098d2de814ebf63c29e5c0e29bff0793a5e
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: iodev - add is_open to iodev.

Add io_open to iodev and set/use if from alsa_io.  This removes the need
to check the alsa handle directly from the audio callback.

BUG=chromium-os:35272
TEST=make check

Change-Id: I2f6d7f4e15b199a35f92e05e2bab2448cf13116d
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: iodev - Add generic audio callback.

Add a callback pointer to iodev for processing audio samples, remove the
alsa-specific callback from alsa_io and use the generic iodev instead.
This will allow for the common threading code to be re-used.

BUG=chromium-os:35272
TEST=make check

Change-Id: Ib011591edef2d6b8cf2383a9ac14b6efa89e57ee
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: alsa_io - convert audio thread to take iodev as arg.

Take an iodev as an argument to the audio thread function.  This
prepares for moving the audio thread to the generic iodev code.

BUG=chromium-os:35272
TEST=make check

Change-Id: I0813395a341b5b248880e3dab2ad241ba57dcdf5
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: alsa_io - remove unused define

Change-Id: I77e0e535472729ea2f0dd77a7c718fb46562bd20
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: alsa_io - Move device settings init to open.

Move device setting initialization call into the open function.  They are
dependent on being called sequentially, no need to burden the caller
with calling both.

BUG=chromium-os:35272
TEST=make check

Change-Id: If15f46f4a41ed0814348beae48797f60fc03e54f
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: iodev - Remove extra arguments to init.

Direction needs to be set before calling init, so no need to pass it in.

BUG=chromium-os:35272
TEST=updated unit tests, play and record audio with the test client.

Change-Id: I59d2796d271023fbc264cd3e4772c7581fd93b20
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: iodev - factor out common audio thread funcs.

Pull the code for running the audio thread out of alsa_io/empty_iodev.
It can be reused by more types of iodevs, such as bluetooth.  This
will also enable pairing input and output iodevs to support unified,
synchronous, IO.

empty_iodev - Remove code that was duplicated from alsa_io and use the
common code refactored into audio_thread.

Mostly this just moves code around, while the patch is bug, there
aren't many functional changes.

BUG=chromium-os:35272
TEST=updated alsa_io_unittest and added audio_thread_unittest
run cras select empty iodev with the test client and play/record audio.

Change-Id: I7765cd33695c06689ad753708f7a0006d420cc37
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: alsa_io - Don't set iodev format twice.

The iodev format must be set before it is opened, so don't call it again
when opening the device.

BUG=chromium-os:35272
TEST=alsa_io_unittest

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