CRAS: Keep next callback time per dev_stream.

For each stream, save the time it should next be serviced.  This time
is start + n * callback_number.  Add one callback threshold of sleep
time after every callback.

This time will later be used to better calculate when to make
callbacks to a stream.

Change-Id: I210329b320bdd0b9b885ad1d3ce0d50b166083f0
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - Prefill with more zeros for min_buffer_level > 0

If a device has min_buffer_level set, start with cb_threshold +
min_buffer_level samples.  Without this the device will need to make
more than one consecutive callbacks to get filled to the appropriate
level.

BUG=none
TEST=play audio to BT and USB

Change-Id: Idc5ca851433bbd217a46ca40d5acc3e465f6690d
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - Prefill shm for output streams.

Instead of dumping zeros into the output device, mark a buffer as
ready in the shared memory region.  This way it works for streams that
aren't the first ones added to a device.

Change-Id: I103858a54f588e62cff1116087df09fcfa74e7ac
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - Temporarily turn off audio_thread ut

This test as written has no chance of surviving the impending changes.
It will be replaced by more focused tests in a later commit.

Change-Id: I0baa66e2e6969e2d94fd0d9771c84a12c30b7258
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - Foundations of new timing.

This change remove a lot of cruft that will no longer be needed by the
new timing system.  No longer does the audio thread wait for playback
streams to reply, it now wakes back up when they do.  This will free
up the audio thread to handle other devices and streams while waiting.

Change-Id: Icb7ab398463c45d853dce6efcaf99526f8ae3f49
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - Remove level arg to write_streams

write_streams now only logs the level, it doesn't actually use it.
Remove the argument and the supporting functions to generate it.

BUG=none
TEST=play/record audio to USB on Big.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - pre-fill device when openning.

When a device is opened it should be filled to the min level.  Filling
it at this point means that it will be filled on stream switch as well
as on stream addition.

BUG=none
TEST=none

Change-Id: I24e6818e42e8f25e21d96063ff4b042a104c04d4
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - More preparation for new timing.

This further pulls apart the stream parameters and the parameters of
the device it is attached to.  This is important in future commits
because a device can have many different streams attached to it, each
with different configurations.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - remove unused now arg

Change-Id: I0b76d105b05d3e0495cb3e94304977af2b126493
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: Don't let draining streams block others from writing their samples

When playing back a draining stream, just copy what shm data is there,
don't limit the amount of data other streams can copy.

Change-Id: If41ca9801c06ca101619baf843ea84922d4c7694
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - Fill stream with less data if hw already has some.

If adding a playback stream to a device that is already partially full
with sample, only pre-fill the stream with enough that one callback
threshold total is queued.  Padding more samples adds extra latency.

Change-Id: Ibd654e3e54303db06b06309cec359c5ba0a3973d
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - remove unused max_frames

Change-Id: Id2ae350f092885a508b5897cc832129e50443a41
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: move wake time to rstream

The wakeup time is per stream, not per device/stream paring.

Change-Id: I7d255b9846306d788668325052ddf48910da859d
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - allow stream fetch to be inexact.

Allow for a stream to be fetch 500 micro-seconds before it's timer
expires.  It is unlikely that the system can sleep and wake again
before the timer should expire anyways.

Change-Id: I5b12a5669c01ae8f8a106409dc6de58b830d5d39
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: audio_thread - Prepare for input work.

This sets up some basic infrastructure that will be used by later
commits the get input streams working with the new timing scheme.

Change-Id: I526803379fec693641ff4ca754b007b742fc9102
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: rstream - Go back to one shm area.

Now that unified streams have been removed there is no need for
separate input and output shm areas.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: iodev_list - use define for "no device"

A zero index means "no device", use a #define for this.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: Add input mix helper.

This module helps track the write pointers of various input devices
that are writing to one stream.  This will help to decide how much of
a stream is finished being written and how much needs to wait for data
from one or more of the devices feeding the stream.

Change-Id: Idc587424ff7620e628f6238e76f711d21115fa91
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: shm - shm argument to "frames_written" can be const.

Make this const since it isn't modified.  This will allow this
function to be called with a const shm pointer in a later change.

Change-Id: Ia998d921a87f14c7ff59afd18dde922bbce33263
Signed-off-by: Dylan Reid <dgreid@chromium.org>
CRAS: Make input streams work with new timing.

This gets input streams working with the new timing scheme.  It also
lays the foundation for multiple input devices to feed one stream.

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