Fix resuming of stream on rapid unix client reconnects

This commit is contained in:
Johan Hedberg 2007-08-15 11:34:56 +00:00
parent f802c1c270
commit c5c555e1b7

View File

@ -59,6 +59,8 @@ struct sink {
struct pending_request *c;
DBusConnection *conn;
gboolean initiator;
gboolean suspending;
gboolean resume;
};
static void pending_connect_free(struct pending_request *c)
@ -108,6 +110,8 @@ void stream_state_changed(struct avdtp_stream *stream, avdtp_state_t old_state,
}
break;
case AVDTP_STATE_OPEN:
sink->suspending = FALSE;
if (old_state == AVDTP_STATE_CONFIGURED)
dbus_connection_emit_signal(dev->conn, dev->path,
AUDIO_SINK_INTERFACE,
@ -117,13 +121,14 @@ void stream_state_changed(struct avdtp_stream *stream, avdtp_state_t old_state,
if (!sink->initiator)
break;
if (sink->c && sink->c->pkt) {
if (sink->resume || (sink->c && sink->c->pkt)) {
cmd_err = avdtp_start(sink->session, stream);
if (cmd_err < 0) {
error("Error on avdtp_start %s (%d)",
strerror(-cmd_err), cmd_err);
goto failed;
}
sink->resume = FALSE;
}
else
c = sink->c;
@ -370,7 +375,7 @@ int sink_get_config(struct device *dev, int sock, struct ipc_packet *req,
int err;
struct pending_request *c = NULL;
if (sink->state == AVDTP_STATE_STREAMING)
if (!sink->suspending && sink->state == AVDTP_STATE_STREAMING)
goto proceed;
if (sink->c) {
@ -390,7 +395,10 @@ int sink_get_config(struct device *dev, int sock, struct ipc_packet *req,
err = avdtp_discover(sink->session, discovery_complete, dev);
else if (sink->state < AVDTP_STATE_STREAMING)
err = avdtp_start(sink->session, sink->stream);
else
else if (sink->suspending) {
sink->resume = TRUE;
err = 0;
} else
err = -EINVAL;
if (err < 0)
@ -451,8 +459,10 @@ void sink_set_state(struct device *dev, avdtp_state_t state)
case AVDTP_STATE_STREAMING:
if (state == AVDTP_STATE_OPEN) {
err = avdtp_suspend(sink->session, sink->stream);
if (err == 0)
if (err == 0) {
sink->suspending = TRUE;
return;
}
}
else if (state == AVDTP_STATE_IDLE) {
err = avdtp_close(sink->session, sink->stream);