diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index cb89c7419..4af335412 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -1241,7 +1241,7 @@ static void stream_param_changed(void *data, uint32_t id, const struct spa_pod * SPA_PROP_mute, 1, &val, 0); } if (stream->corked) - pw_stream_set_active(stream->stream, false); + stream_set_paused(stream, true, "cork after create"); /* if peer exists, reply immediately, otherwise reply when the link is created */ peer = find_linked(stream->client->manager, stream->id, stream->direction); @@ -1524,7 +1524,7 @@ static void stream_drained(void *data) reply_simple_ack(stream->client, stream->drain_tag); stream->drain_tag = 0; - pw_stream_set_active(stream->stream, true); + stream_set_paused(stream, false, "complete drain"); } } @@ -2702,7 +2702,7 @@ static int do_cork_stream(struct client *client, uint32_t command, uint32_t tag, return -ENOENT; stream->corked = cork; - pw_stream_set_active(stream->stream, !cork); + stream_set_paused(stream, cork, "cork request"); if (cork) { stream->is_underrun = true; } else { @@ -3462,7 +3462,7 @@ static int do_drain_stream(struct client *client, uint32_t command, uint32_t tag stream->drain_tag = tag; stream->draining = true; - pw_stream_set_active(stream->stream, true); + stream_set_paused(stream, false, "drain start"); return 0; } diff --git a/src/modules/module-protocol-pulse/stream.c b/src/modules/module-protocol-pulse/stream.c index 730580da3..f0b0d3587 100644 --- a/src/modules/module-protocol-pulse/stream.c +++ b/src/modules/module-protocol-pulse/stream.c @@ -207,6 +207,20 @@ uint32_t stream_pop_missing(struct stream *stream) return missing; } +void stream_set_paused(struct stream *stream, bool paused, const char *reason) +{ + if (stream->is_paused == paused) + return; + + if (reason && stream->client) + pw_log_info("%p: [%s] %s because of %s", + stream, stream->client->name, + paused ? "paused" : "resumed", reason); + + stream->is_paused = paused; + pw_stream_set_active(stream->stream, !paused); +} + int stream_send_underflow(struct stream *stream, int64_t offset) { struct client *client = stream->client; diff --git a/src/modules/module-protocol-pulse/stream.h b/src/modules/module-protocol-pulse/stream.h index 7ee6de36b..ac144118f 100644 --- a/src/modules/module-protocol-pulse/stream.h +++ b/src/modules/module-protocol-pulse/stream.h @@ -115,6 +115,7 @@ struct stream { unsigned int in_prebuf:1; unsigned int killed:1; unsigned int pending:1; + unsigned int is_paused:1; }; struct stream *stream_new(struct client *client, enum stream_type type, uint32_t create_tag, @@ -124,6 +125,8 @@ void stream_free(struct stream *stream); void stream_flush(struct stream *stream); uint32_t stream_pop_missing(struct stream *stream); +void stream_set_paused(struct stream *stream, bool paused, const char *reason); + int stream_send_underflow(struct stream *stream, int64_t offset); int stream_send_overflow(struct stream *stream); int stream_send_killed(struct stream *stream);