On Sat, Sep 21, 2013 at 11:43 AM, Tanu Kaskinen <tanu.kaskinen at linux.intel.com> wrote: > On Wed, 2013-09-18 at 16:17 -0500, jprvita at gmail.com wrote: >> From: Jo?o Paulo Rechi Vita <jprvita at openbossa.org> >> >> --- >> src/modules/bluetooth/module-bluez5-device.c | 77 ++++++++++++++++++++++++++++ >> 1 file changed, 77 insertions(+) >> >> diff --git a/src/modules/bluetooth/module-bluez5-device.c b/src/modules/bluetooth/module-bluez5-device.c >> index 31088b7..d9e1fc6 100644 >> --- a/src/modules/bluetooth/module-bluez5-device.c >> +++ b/src/modules/bluetooth/module-bluez5-device.c >> @@ -660,6 +660,82 @@ static void setup_stream(struct userdata *u) { >> u->read_smoother = pa_smoother_new(PA_USEC_PER_SEC, 2*PA_USEC_PER_SEC, true, true, 10, pa_rtclock_now(), true); >> } >> >> +/* Run from IO thread */ >> +static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) { >> + struct userdata *u = PA_SOURCE(o)->userdata; >> + bool failed = false; >> + int r; >> + >> + pa_assert(u->source == PA_SOURCE(o)); >> + pa_assert(u->transport); >> + >> + switch (code) { >> + >> + case PA_SOURCE_MESSAGE_SET_STATE: >> + >> + switch ((pa_source_state_t) PA_PTR_TO_UINT(data)) { >> + >> + case PA_SOURCE_SUSPENDED: >> + /* Ignore if transition is PA_SOURCE_INIT->PA_SOURCE_SUSPENDED */ >> + if (!PA_SOURCE_IS_OPENED(u->source->thread_info.state)) >> + break; >> + >> + /* Stop the device if the sink is suspended as well */ >> + if (!u->sink || u->sink->state == PA_SINK_SUSPENDED) >> + transport_release(u); >> + >> + if (u->read_smoother) >> + pa_smoother_pause(u->read_smoother, pa_rtclock_now()); >> + >> + break; >> + >> + case PA_SOURCE_IDLE: >> + case PA_SOURCE_RUNNING: >> + if (u->source->thread_info.state != PA_SOURCE_SUSPENDED) >> + break; >> + >> + /* Resume the device if the sink was suspended as well */ >> + if (!u->sink || !PA_SINK_IS_OPENED(u->sink->thread_info.state)) { >> + if (transport_acquire(u, false) < 0) >> + failed = true; >> + else >> + setup_stream(u); >> + } >> + >> + /* We don't resume the smoother here. Instead we >> + * wait until the first packet arrives */ >> + >> + break; >> + >> + case PA_SOURCE_UNLINKED: >> + case PA_SOURCE_INIT: >> + case PA_SOURCE_INVALID_STATE: >> + break; >> + } >> + >> + break; >> + >> + case PA_SOURCE_MESSAGE_GET_LATENCY: { >> + pa_usec_t wi, ri; >> + >> + if (u->read_smoother) { >> + wi = pa_smoother_get(u->read_smoother, pa_rtclock_now()); >> + ri = pa_bytes_to_usec(u->read_index, &u->sample_spec); >> + >> + *((pa_usec_t*) data) = FIXED_LATENCY_PLAYBACK_A2DP + wi - ri > 0 ? FIXED_LATENCY_PLAYBACK_A2DP + wi - ri : 0; > > The same complaint as with the sink: the comparison to 0 doesn't work. > Also, the constant should be FIXED_LATENCY_RECORD_A2DP, not > FIXED_LATENCY_PLAYBACK_A2DP. > Ok -- Jo?o Paulo Rechi Vita http://about.me/jprvita