[pulseaudio-discuss] [PATCH v1 07/18] bluetooth: Set profile even if transport not acquired
Mikel Astiz
mikel.astiz.oss at gmail.com
Mon Aug 27 08:24:02 PDT 2012
From: Mikel Astiz <mikel.astiz at bmw-carit.de>
If the acquisition of the transport fails, the profile should still be
set. In this case the audio is not actually streaming, so the sink and
source will be created but left suspended.
If the transport needs to be acquired later, for example because the
user wants to route the audio the remote device, the suspend flag should
have to be changed.
---
src/modules/bluetooth/bluetooth-util.c | 1 -
src/modules/bluetooth/module-bluetooth-device.c | 30 +++++++++++++++++-----
2 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index bfe00dc..cb7b69d 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -1014,7 +1014,6 @@ int pa_bluetooth_transport_acquire(const pa_bluetooth_transport *t, const char *
r = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(t->y->connection), m, -1, &err);
if (dbus_error_is_set(&err) || !r) {
- pa_log("Failed to acquire transport fd: %s", err.message);
dbus_error_free(&err);
return -1;
}
diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 660f8a2..1915e81 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -346,8 +346,14 @@ static int bt_transport_acquire(struct userdata *u, pa_bool_t start) {
}
u->stream_fd = pa_bluetooth_transport_acquire(t, accesstype, &u->read_link_mtu, &u->write_link_mtu);
- if (u->stream_fd < 0)
+ if (u->stream_fd < 0) {
+ if (start)
+ pa_log("Failed to acquire transport %s", u->transport);
+ else
+ pa_log_info("Failed optional acquire of transport %s", u->transport);
+
return -1;
+ }
u->accesstype = pa_xstrdup(accesstype);
pa_log_info("Transport %s acquired: fd %d", u->transport, u->stream_fd);
@@ -378,7 +384,8 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
switch ((pa_sink_state_t) PA_PTR_TO_UINT(data)) {
case PA_SINK_SUSPENDED:
- pa_assert(PA_SINK_IS_OPENED(u->sink->thread_info.state));
+ 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)
@@ -452,7 +459,8 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
switch ((pa_source_state_t) PA_PTR_TO_UINT(data)) {
case PA_SOURCE_SUSPENDED:
- pa_assert(PA_SOURCE_IS_OPENED(u->source->thread_info.state));
+ 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)
@@ -972,8 +980,10 @@ static void thread_func(void *userdata) {
pa_thread_mq_install(&u->thread_mq);
- if (bt_transport_acquire(u, TRUE) < 0)
- goto fail;
+ /* Setup the stream only if the transport was already acquired */
+ if (bt_transport_is_acquired(u))
+ if (setup_stream(u) < 0)
+ goto fail;
for (;;) {
struct pollfd *pollfd;
@@ -1546,6 +1556,9 @@ static int add_sink(struct userdata *u) {
}
connect_ports(u, &data, PA_DIRECTION_OUTPUT);
+ if (!bt_transport_is_acquired(u))
+ data.suspend_cause = PA_SUSPEND_IDLE;
+
u->sink = pa_sink_new(u->core, &data, PA_SINK_HARDWARE|PA_SINK_LATENCY);
pa_sink_new_data_done(&data);
@@ -1609,6 +1622,10 @@ static int add_source(struct userdata *u) {
}
connect_ports(u, &data, PA_DIRECTION_INPUT);
+
+ if (!bt_transport_is_acquired(u))
+ data.suspend_cause = PA_SUSPEND_IDLE;
+
u->source = pa_source_new(u->core, &data, PA_SOURCE_HARDWARE|PA_SOURCE_LATENCY);
pa_source_new_data_done(&data);
@@ -1805,8 +1822,7 @@ static int setup_bt(struct userdata *u) {
u->transport = pa_xstrdup(t->path);
- if (bt_transport_acquire(u, FALSE) < 0)
- return -1;
+ bt_transport_acquire(u, FALSE);
return 0;
}
--
1.7.7.6
More information about the pulseaudio-discuss
mailing list