[pulseaudio-discuss] [PATCH v4 34/41] bluetooth: Process sink messages for BlueZ 5 cards

João Paulo Rechi Vita jprvita at gmail.com
Tue Sep 24 11:43:11 PDT 2013


On Sat, Sep 21, 2013 at 11:40 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 | 75 ++++++++++++++++++++++++++++
>>  1 file changed, 75 insertions(+)
>>
>> diff --git a/src/modules/bluetooth/module-bluez5-device.c b/src/modules/bluetooth/module-bluez5-device.c
>> index 4f2fbd8..31088b7 100644
>> --- a/src/modules/bluetooth/module-bluez5-device.c
>> +++ b/src/modules/bluetooth/module-bluez5-device.c
>> @@ -700,6 +700,80 @@ static int add_source(struct userdata *u) {
>>      return 0;
>>  }
>>
>> +/* Run from IO thread */
>> +static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
>> +    struct userdata *u = PA_SINK(o)->userdata;
>> +    bool failed = false;
>> +    int r;
>> +
>> +    pa_assert(u->sink == PA_SINK(o));
>> +    pa_assert(u->transport);
>> +
>> +    switch (code) {
>> +
>> +        case PA_SINK_MESSAGE_SET_STATE:
>> +
>> +            switch ((pa_sink_state_t) PA_PTR_TO_UINT(data)) {
>> +
>> +                case PA_SINK_SUSPENDED:
>> +                    /* Ignore if transition is PA_SINK_INIT->PA_SINK_SUSPENDED */
>> +                    if (!PA_SINK_IS_OPENED(u->sink->thread_info.state))
>> +                        break;
>> +
>> +                    /* Stop the device if the source is suspended as well */
>> +                    if (!u->source || u->source->state == PA_SOURCE_SUSPENDED)
>> +                        /* We deliberately ignore whether stopping
>> +                         * actually worked. Since the stream_fd is
>> +                         * closed it doesn't really matter */
>> +                        transport_release(u);
>> +
>> +                    break;
>> +
>> +                case PA_SINK_IDLE:
>> +                case PA_SINK_RUNNING:
>> +                    if (u->sink->thread_info.state != PA_SINK_SUSPENDED)
>> +                        break;
>> +
>> +                    /* Resume the device if the source was suspended as well */
>> +                    if (!u->source || !PA_SOURCE_IS_OPENED(u->source->thread_info.state)) {
>> +                        if (transport_acquire(u, false) < 0)
>> +                            failed = true;
>> +                        else
>> +                            setup_stream(u);
>> +                    }
>> +
>> +                    break;
>> +
>> +                case PA_SINK_UNLINKED:
>> +                case PA_SINK_INIT:
>> +                case PA_SINK_INVALID_STATE:
>> +                    break;
>> +            }
>> +
>> +            break;
>> +
>> +        case PA_SINK_MESSAGE_GET_LATENCY: {
>> +            pa_usec_t wi, ri;
>> +
>> +            if (u->read_smoother) {
>> +                ri = pa_smoother_get(u->read_smoother, pa_rtclock_now());
>> +                wi = pa_bytes_to_usec(u->write_index + u->write_block_size, &u->sample_spec);
>> +            } else {
>> +                ri = pa_rtclock_now() - u->started_at;
>> +                wi = pa_bytes_to_usec(u->write_index, &u->sample_spec);
>> +            }
>> +
>> +            *((pa_usec_t*) data) = FIXED_LATENCY_PLAYBACK_A2DP + wi - ri > 0 ? FIXED_LATENCY_PLAYBACK_A2DP + wi - ri : 0;
>
> The compiler treats the result of "FIXED_LATENCY_PLAYBACK_A2DP + wi -
> ri" as an unsigned integer, so it's never negative, and thus the
> comparison to 0 doesn't work as intended.
>

All right, good catch.

-- 
João Paulo Rechi Vita
http://about.me/jprvita


More information about the pulseaudio-discuss mailing list