#include <pulsecore/modargs.h>
#include <pulsecore/poll.h>
#include <pulsecore/rtpoll.h>
+#include <pulsecore/shared.h>
#include <pulsecore/socket-util.h>
#include <pulsecore/thread.h>
#include <pulsecore/thread-mq.h>
void *d;
ssize_t l;
size_t to_write, to_decode;
+ size_t total_written = 0;
a2dp_prepare_buffer(u);
pa_assert((size_t) l <= sbc_info->buffer_size);
- u->read_index += (uint64_t) l;
-
/* TODO: get timestamp from rtp */
if (!found_tstamp) {
/* pa_log_warn("Couldn't find SO_TIMESTAMP data in auxiliary recvmsg() data!"); */
tstamp = pa_rtclock_now();
}
- pa_smoother_put(u->read_smoother, tstamp, pa_bytes_to_usec(u->read_index, &u->sample_spec));
- pa_smoother_resume(u->read_smoother, tstamp, true);
-
p = (uint8_t*) sbc_info->buffer + sizeof(*header) + sizeof(*payload);
to_decode = l - sizeof(*header) - sizeof(*payload);
pa_log_error("SBC decoding error (%li)", (long) decoded);
pa_memblock_release(memchunk.memblock);
pa_memblock_unref(memchunk.memblock);
- return -1;
+ return 0;
}
+ total_written += written;
+
/* Reset frame length, it can be changed due to bitpool change */
sbc_info->frame_length = sbc_get_frame_length(&sbc_info->sbc);
to_write -= written;
}
+ u->read_index += (uint64_t) total_written;
+ pa_smoother_put(u->read_smoother, tstamp, pa_bytes_to_usec(u->read_index, &u->sample_spec));
+ pa_smoother_resume(u->read_smoother, tstamp, true);
+
memchunk.length -= to_write;
pa_memblock_release(memchunk.memblock);
if (n_read < 0)
goto io_fail;
- /* We just read something, so we are supposed to write something, too */
- pending_read_bytes += n_read;
- do_write += pending_read_bytes / u->write_block_size;
- pending_read_bytes = pending_read_bytes % u->write_block_size;
+ if (n_read > 0) {
+ /* We just read something, so we are supposed to write something, too */
+ pending_read_bytes += n_read;
+ do_write += pending_read_bytes / u->write_block_size;
+ pending_read_bytes = pending_read_bytes % u->write_block_size;
+ }
}
}
pa_assert_se(output_port = pa_hashmap_get(ports, u->output_port_name));
if (pa_streq(uuid, PA_BLUETOOTH_UUID_A2DP_SINK)) {
- /* TODO: Change this profile's name to a2dp_sink, to reflect the remote
- * device's role and be consistent with the a2dp source profile */
- cp = pa_card_profile_new("a2dp", _("High Fidelity Playback (A2DP Sink)"), sizeof(pa_bluetooth_profile_t));
+ cp = pa_card_profile_new("a2dp_sink", _("High Fidelity Playback (A2DP Sink)"), sizeof(pa_bluetooth_profile_t));
cp->priority = 10;
cp->n_sinks = 1;
cp->n_sources = 0;
off:
stop_thread(u);
- pa_assert_se(pa_card_set_profile(u->card, "off", false) >= 0);
+ pa_assert_se(pa_card_set_profile(u->card, pa_hashmap_get(u->card->profiles, "off"), false) >= 0);
return -PA_ERR_IO;
}
if (acquire && transport_acquire(u, true) >= 0) {
if (u->source) {
pa_log_debug("Resuming source %s because its transport state changed to playing", u->source->name);
+
+ /* We remove the IDLE suspend cause, because otherwise
+ * module-loopback doesn't uncork its streams. FIXME: Messing with
+ * the IDLE suspend cause here is wrong, the correct way to handle
+ * this would probably be to uncork the loopback streams not only
+ * when the other end is unsuspended, but also when the other end's
+ * suspend cause changes to IDLE only (currently there's no
+ * notification mechanism for suspend cause changes, though). */
pa_source_suspend(u->source, false, PA_SUSPEND_IDLE|PA_SUSPEND_USER);
}
if (u->sink) {
pa_log_debug("Resuming sink %s because its transport state changed to playing", u->sink->name);
+
+ /* FIXME: See the previous comment. */
pa_sink_suspend(u->sink, false, PA_SUSPEND_IDLE|PA_SUSPEND_USER);
}
}
pa_assert(u);
if (t == u->transport && t->state <= PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED)
- pa_assert_se(pa_card_set_profile(u->card, "off", false) >= 0);
+ pa_assert_se(pa_card_set_profile(u->card, pa_hashmap_get(u->card->profiles, "off"), false) >= 0);
if (t->device == u->device)
handle_transport_state_change(u, t);
break;
pa_log_debug("Switching the profile to off due to IO thread failure.");
- pa_assert_se(pa_card_set_profile(u->card, "off", false) >= 0);
+ pa_assert_se(pa_card_set_profile(u->card, pa_hashmap_get(u->card->profiles, "off"), false) >= 0);
break;
}
goto fail;
}
- if (!(u->discovery = pa_bluetooth_discovery_get(m->core)))
+ if ((u->discovery = pa_shared_get(u->core, "bluetooth-discovery")))
+ pa_bluetooth_discovery_ref(u->discovery);
+ else {
+ pa_log_error("module-bluez5-discover doesn't seem to be loaded, refusing to load module-bluez5-device");
goto fail;
+ }
if (!(u->device = pa_bluetooth_discovery_get_device_by_path(u->discovery, path))) {
pa_log_error("%s is unknown", path);
off:
stop_thread(u);
- pa_assert_se(pa_card_set_profile(u->card, "off", false) >= 0);
+ pa_assert_se(pa_card_set_profile(u->card, pa_hashmap_get(u->card->profiles, "off"), false) >= 0);
return 0;