Commit e36d6e20 authored by pali's avatar pali
Browse files

bluetooth: Set all new streams to suspended state and remove argument...

bluetooth: Set all new streams to suspended state and remove argument "optional" from transport acquire function

Now when broken local AudioGateway role was removed there is no need to
have special (and moreover non-working) hacks for it in transport code.
This would allow to create streams for all transports immediately in
suspended state, so applications can bind to them.

A2DP source profiles can be also initialized via "Acquire" method, so there
not need to "TryAcquire" method for them. Special handling is needed only
for SCO master sockets which are not handled by pulseaudio anymore.
Moreover is is possible to do it in smarter way, like in hsphfpd daemon.
parent 07b01854
......@@ -411,18 +411,17 @@ void pa_bluetooth_transport_free(pa_bluetooth_transport *t) {
pa_xfree(t);
}
static int bluez5_transport_acquire_cb(pa_bluetooth_transport *t, bool optional, size_t *imtu, size_t *omtu) {
static int bluez5_transport_acquire_cb(pa_bluetooth_transport *t, size_t *imtu, size_t *omtu) {
DBusMessage *m, *r;
DBusError err;
int ret;
uint16_t i, o;
const char *method = optional ? "TryAcquire" : "Acquire";
pa_assert(t);
pa_assert(t->device);
pa_assert(t->device->discovery);
pa_assert_se(m = dbus_message_new_method_call(t->owner, t->path, BLUEZ_MEDIA_TRANSPORT_INTERFACE, method));
pa_assert_se(m = dbus_message_new_method_call(t->owner, t->path, BLUEZ_MEDIA_TRANSPORT_INTERFACE, "Acquire"));
dbus_error_init(&err);
......@@ -430,10 +429,7 @@ static int bluez5_transport_acquire_cb(pa_bluetooth_transport *t, bool optional,
dbus_message_unref(m);
m = NULL;
if (!r) {
if (optional && pa_streq(err.name, "org.bluez.Error.NotAvailable"))
pa_log_info("Failed optional acquire of unavailable transport %s", t->path);
else
pa_log_error("Transport %s() failed for transport %s (%s)", method, t->path, err.message);
pa_log_error("Transport Acquire() failed for transport %s (%s)", t->path, err.message);
dbus_error_free(&err);
return -1;
......@@ -441,7 +437,7 @@ static int bluez5_transport_acquire_cb(pa_bluetooth_transport *t, bool optional,
if (!dbus_message_get_args(r, &err, DBUS_TYPE_UNIX_FD, &ret, DBUS_TYPE_UINT16, &i, DBUS_TYPE_UINT16, &o,
DBUS_TYPE_INVALID)) {
pa_log_error("Failed to parse %s() reply: %s", method, err.message);
pa_log_error("Failed to parse Acquire() reply: %s", err.message);
dbus_error_free(&err);
ret = -1;
goto finish;
......
......@@ -69,7 +69,7 @@ typedef enum pa_bluetooth_transport_state {
PA_BLUETOOTH_TRANSPORT_STATE_PLAYING
} pa_bluetooth_transport_state_t;
typedef int (*pa_bluetooth_transport_acquire_cb)(pa_bluetooth_transport *t, bool optional, size_t *imtu, size_t *omtu);
typedef int (*pa_bluetooth_transport_acquire_cb)(pa_bluetooth_transport *t, size_t *imtu, size_t *omtu);
typedef void (*pa_bluetooth_transport_release_cb)(pa_bluetooth_transport *t);
typedef void (*pa_bluetooth_transport_destroy_cb)(pa_bluetooth_transport *t);
typedef void (*pa_bluetooth_transport_set_speaker_gain_cb)(pa_bluetooth_transport *t, uint16_t gain);
......
......@@ -574,7 +574,7 @@ static void hsphfpd_unregister_application(pa_bluetooth_backend *backend) {
pa_bluetooth_discovery_legacy_hsp_backend_enable(backend->discovery, true);
}
static int hsphfpd_transport_acquire(pa_bluetooth_transport *transport, bool optional, size_t *imtu, size_t *omtu) {
static int hsphfpd_transport_acquire(pa_bluetooth_transport *transport, size_t *imtu, size_t *omtu) {
struct hsphfpd_transport_data *transport_data = transport->userdata;
if (imtu) *imtu = transport_data->mtu;
......
......@@ -153,7 +153,7 @@ fail_close:
return -1;
}
static int sco_acquire_cb(pa_bluetooth_transport *t, bool optional, size_t *imtu, size_t *omtu) {
static int sco_acquire_cb(pa_bluetooth_transport *t, size_t *imtu, size_t *omtu) {
int sock;
socklen_t len;
......
......@@ -702,7 +702,7 @@ static void teardown_stream(struct userdata *u) {
u->stream_setup_done = false;
}
static int transport_acquire(struct userdata *u, bool optional) {
static int transport_acquire(struct userdata *u) {
pa_assert(u->transport);
if (u->transport_acquired)
......@@ -710,7 +710,7 @@ static int transport_acquire(struct userdata *u, bool optional) {
pa_log_debug("Acquiring transport %s", u->transport->path);
u->stream_fd = u->transport->acquire(u->transport, optional, &u->read_link_mtu, &u->write_link_mtu);
u->stream_fd = u->transport->acquire(u->transport, &u->read_link_mtu, &u->write_link_mtu);
if (u->stream_fd < 0)
return u->stream_fd;
......@@ -870,7 +870,7 @@ static int setup_stream(struct userdata *u) {
static bool setup_transport_and_stream(struct userdata *u) {
int transport_error;
transport_error = transport_acquire(u, false);
transport_error = transport_acquire(u);
if (transport_error < 0) {
if (transport_error != -EAGAIN)
return false;
......@@ -1033,20 +1033,8 @@ static int add_source(struct userdata *u) {
connect_ports(u, &data, PA_DIRECTION_INPUT);
if (!u->transport_acquired) {
if (u->profile == PA_BLUETOOTH_PROFILE_HEADSET_AUDIO_GATEWAY || pa_bluetooth_profile_is_a2dp(u->profile)) {
data.suspend_cause = PA_SUSPEND_USER;
} else if (u->profile == PA_BLUETOOTH_PROFILE_HEADSET_HEAD_UNIT) {
/* u->stream_fd contains the error returned by the last transport_acquire()
* EAGAIN means we are waiting for a NewConnection signal */
if (u->stream_fd == -EAGAIN)
data.suspend_cause = PA_SUSPEND_USER;
else
pa_assert_not_reached();
} else {
pa_assert_not_reached();
}
}
if (!u->transport_acquired)
data.suspend_cause = PA_SUSPEND_USER;
u->source = pa_source_new(u->core, &data, PA_SOURCE_HARDWARE|PA_SOURCE_LATENCY);
pa_source_new_data_done(&data);
......@@ -1218,23 +1206,7 @@ static int add_sink(struct userdata *u) {
connect_ports(u, &data, PA_DIRECTION_OUTPUT);
if (!u->transport_acquired)
switch (u->profile) {
case PA_BLUETOOTH_PROFILE_HEADSET_AUDIO_GATEWAY:
data.suspend_cause = PA_SUSPEND_USER;
break;
case PA_BLUETOOTH_PROFILE_HEADSET_HEAD_UNIT:
/* u->stream_fd contains the error returned by the last transport_acquire()
* EAGAIN means we are waiting for a NewConnection signal */
if (u->stream_fd == -EAGAIN)
data.suspend_cause = PA_SUSPEND_USER;
else
pa_assert_not_reached();
break;
default:
/* Profile switch should have failed */
pa_assert_not_reached();
break;
}
data.suspend_cause = PA_SUSPEND_USER;
u->sink = pa_sink_new(u->core, &data, PA_SINK_HARDWARE|PA_SINK_LATENCY);
pa_sink_new_data_done(&data);
......@@ -1336,6 +1308,7 @@ off:
/* Run from main thread */
static int setup_transport(struct userdata *u) {
pa_bluetooth_transport *t;
int transport_error;
pa_assert(u);
pa_assert(!u->transport);
......@@ -1356,15 +1329,10 @@ static int setup_transport(struct userdata *u) {
u->transport = t;
if (pa_bluetooth_profile_is_a2dp_source(u->profile) || u->profile == PA_BLUETOOTH_PROFILE_HEADSET_AUDIO_GATEWAY)
transport_acquire(u, true); /* In case of error, the sink/sources will be created suspended */
else {
int transport_error;
transport_error = transport_acquire(u, false);
if (transport_error < 0 && transport_error != -EAGAIN)
return -1; /* We need to fail here until the interactions with module-suspend-on-idle and alike get improved */
}
transport_error = transport_acquire(u);
if (transport_error < 0 && transport_error != -EAGAIN)
return -1; /* We need to fail here until the interactions with module-suspend-on-idle and alike get improved */
/* When transport_error is -EAGAIN then the sink/sources will be created suspended */
return transport_config(u);
}
......@@ -2297,7 +2265,7 @@ static void handle_transport_state_change(struct userdata *u, struct pa_bluetoot
acquire = (t->state == PA_BLUETOOTH_TRANSPORT_STATE_PLAYING && u->profile == t->profile);
release = (oldavail != PA_AVAILABLE_NO && t->state != PA_BLUETOOTH_TRANSPORT_STATE_PLAYING && u->profile == t->profile);
if (acquire && transport_acquire(u, true) >= 0) {
if (acquire && transport_acquire(u) >= 0) {
if (u->source) {
pa_log_debug("Resuming source %s because its transport state changed to playing", u->source->name);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment