[pulseaudio-commits] 3 commits - src/modules src/pulsecore
Tanu Kaskinen
tanuk at kemper.freedesktop.org
Thu Jul 20 13:36:21 UTC 2017
src/modules/bluetooth/backend-ofono.c | 6 +++
src/modules/bluetooth/bluez4-util.c | 12 ++++++-
src/modules/bluetooth/bluez5-util.c | 12 ++++++-
src/modules/dbus/iface-core.c | 4 +-
src/modules/module-default-device-restore.c | 30 +++++++++---------
src/modules/module-switch-on-connect.c | 8 ++--
src/modules/reserve.c | 6 +++
src/pulsecore/cli-command.c | 4 +-
src/pulsecore/core.c | 46 +++++++++++++++++-----------
src/pulsecore/core.h | 13 ++++---
src/pulsecore/protocol-native.c | 6 +--
src/pulsecore/sink.c | 5 ---
src/pulsecore/source.c | 5 ---
13 files changed, 96 insertions(+), 61 deletions(-)
New commits:
commit e7d7b29c174f0b97d8a06de6fa3b555e64cc267a
Author: Tanu Kaskinen <tanuk at iki.fi>
Date: Tue Jul 11 21:16:17 2017 +0300
protocol-native: fix bytes-to-usec conversion of "on-the-fly" data
The on_the_fly_snapshot variable contains the amount of bytes that has
been sent from the source IO thread to the main thread, but not yet
pushed to the stream memblockq. The data is in the stream format, but
the bytes-to-usec conversion used the source format, which caused random
latency reporting errors.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=81075
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index 068e0c00..866e2c64 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -2922,7 +2922,7 @@ static void command_get_record_latency(pa_pdispatch *pd, uint32_t command, uint3
pa_tagstruct_put_usec(reply, s->current_monitor_latency);
pa_tagstruct_put_usec(reply,
s->current_source_latency +
- pa_bytes_to_usec(s->on_the_fly_snapshot, &s->source_output->source->sample_spec));
+ pa_bytes_to_usec(s->on_the_fly_snapshot, &s->source_output->sample_spec));
pa_tagstruct_put_boolean(reply,
pa_source_get_state(s->source_output->source) == PA_SOURCE_RUNNING &&
pa_source_output_get_state(s->source_output) == PA_SOURCE_OUTPUT_RUNNING);
commit a448cc587c203bba42b1b9805317088e95775f71
Author: Tanu Kaskinen <tanuk at iki.fi>
Date: Fri Jun 30 00:09:34 2017 +0300
core: change configured_default_sink/source type to string
This allows us to restore the default device properly when a
hotpluggable device (e.g. a USB sound card) is set as the default, but
unplugged temporarily. Previously we would forget that the unplugged
device was ever set as the default, because we had to set
configured_default_sink to NULL to avoid having a stale pa_sink pointer,
and also because module-default-device-restore couldn't resolve the name
of a currently-unplugged device to a pa_sink pointer.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=89934
diff --git a/src/modules/dbus/iface-core.c b/src/modules/dbus/iface-core.c
index 3f368ab4..7177455b 100644
--- a/src/modules/dbus/iface-core.c
+++ b/src/modules/dbus/iface-core.c
@@ -721,7 +721,7 @@ static void handle_set_fallback_sink(DBusConnection *conn, DBusMessage *msg, DBu
return;
}
- pa_core_set_configured_default_sink(c->core, pa_dbusiface_device_get_sink(fallback_sink));
+ pa_core_set_configured_default_sink(c->core, pa_dbusiface_device_get_sink(fallback_sink)->name);
pa_dbus_send_empty_reply(conn, msg);
}
@@ -809,7 +809,7 @@ static void handle_set_fallback_source(DBusConnection *conn, DBusMessage *msg, D
return;
}
- pa_core_set_configured_default_source(c->core, pa_dbusiface_device_get_source(fallback_source));
+ pa_core_set_configured_default_source(c->core, pa_dbusiface_device_get_source(fallback_source)->name);
pa_dbus_send_empty_reply(conn, msg);
}
diff --git a/src/modules/module-default-device-restore.c b/src/modules/module-default-device-restore.c
index 56fee67f..adf19ff9 100644
--- a/src/modules/module-default-device-restore.c
+++ b/src/modules/module-default-device-restore.c
@@ -60,7 +60,6 @@ static void load(struct userdata *u) {
pa_log_info("Manually configured default sink, not overwriting.");
else if ((f = pa_fopen_cloexec(u->sink_filename, "r"))) {
char ln[256] = "";
- pa_sink *s;
if (fgets(ln, sizeof(ln)-1, f))
pa_strip_nl(ln);
@@ -68,11 +67,12 @@ static void load(struct userdata *u) {
if (!ln[0])
pa_log_info("No previous default sink setting, ignoring.");
- else if ((s = pa_namereg_get(u->core, ln, PA_NAMEREG_SINK))) {
- pa_core_set_configured_default_sink(u->core, s);
- pa_log_info("Restored default sink '%s'.", ln);
- } else
- pa_log_info("Saved default sink '%s' not existent, not restoring default sink setting.", ln);
+ else if (!pa_namereg_is_valid_name(ln))
+ pa_log_warn("Invalid sink name: %s", ln);
+ else {
+ pa_log_info("Restoring default sink '%s'.", ln);
+ pa_core_set_configured_default_sink(u->core, ln);
+ }
} else if (errno != ENOENT)
pa_log("Failed to load default sink: %s", pa_cstrerror(errno));
@@ -81,7 +81,6 @@ static void load(struct userdata *u) {
pa_log_info("Manually configured default source, not overwriting.");
else if ((f = pa_fopen_cloexec(u->source_filename, "r"))) {
char ln[256] = "";
- pa_source *s;
if (fgets(ln, sizeof(ln)-1, f))
pa_strip_nl(ln);
@@ -89,14 +88,15 @@ static void load(struct userdata *u) {
if (!ln[0])
pa_log_info("No previous default source setting, ignoring.");
- else if ((s = pa_namereg_get(u->core, ln, PA_NAMEREG_SOURCE))) {
- pa_core_set_configured_default_source(u->core, s);
- pa_log_info("Restored default source '%s'.", ln);
- } else
- pa_log_info("Saved default source '%s' not existent, not restoring default source setting.", ln);
+ else if (!pa_namereg_is_valid_name(ln))
+ pa_log_warn("Invalid source name: %s", ln);
+ else {
+ pa_log_info("Restoring default source '%s'.", ln);
+ pa_core_set_configured_default_source(u->core, ln);
+ }
} else if (errno != ENOENT)
- pa_log("Failed to load default sink: %s", pa_cstrerror(errno));
+ pa_log("Failed to load default source: %s", pa_cstrerror(errno));
}
static void save(struct userdata *u) {
@@ -107,7 +107,7 @@ static void save(struct userdata *u) {
if (u->sink_filename) {
if ((f = pa_fopen_cloexec(u->sink_filename, "w"))) {
- fprintf(f, "%s\n", u->core->default_sink ? u->core->default_sink->name : "");
+ fprintf(f, "%s\n", u->core->configured_default_sink ? u->core->configured_default_sink : "");
fclose(f);
} else
pa_log("Failed to save default sink: %s", pa_cstrerror(errno));
@@ -115,7 +115,7 @@ static void save(struct userdata *u) {
if (u->source_filename) {
if ((f = pa_fopen_cloexec(u->source_filename, "w"))) {
- fprintf(f, "%s\n", u->core->default_source ? u->core->default_source->name : "");
+ fprintf(f, "%s\n", u->core->configured_default_source ? u->core->configured_default_source : "");
fclose(f);
} else
pa_log("Failed to save default source: %s", pa_cstrerror(errno));
diff --git a/src/modules/module-switch-on-connect.c b/src/modules/module-switch-on-connect.c
index e2da7222..640024e9 100644
--- a/src/modules/module-switch-on-connect.c
+++ b/src/modules/module-switch-on-connect.c
@@ -77,7 +77,7 @@ static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, void*
/* No default sink, nothing to move away, just set the new default */
if (!c->default_sink) {
- pa_core_set_configured_default_sink(c, sink);
+ pa_core_set_configured_default_sink(c, sink->name);
return PA_HOOK_OK;
}
@@ -91,7 +91,7 @@ static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, void*
old_default_sink = c->default_sink;
/* Actually do the switch to the new sink */
- pa_core_set_configured_default_sink(c, sink);
+ pa_core_set_configured_default_sink(c, sink->name);
/* Now move all old inputs over */
if (pa_idxset_size(old_default_sink->inputs) <= 0) {
@@ -143,7 +143,7 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source,
/* No default source, nothing to move away, just set the new default */
if (!c->default_source) {
- pa_core_set_configured_default_source(c, source);
+ pa_core_set_configured_default_source(c, source->name);
return PA_HOOK_OK;
}
@@ -157,7 +157,7 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source,
old_default_source = c->default_source;
/* Actually do the switch to the new source */
- pa_core_set_configured_default_source(c, source);
+ pa_core_set_configured_default_source(c, source->name);
/* Now move all old outputs over */
if (pa_idxset_size(old_default_source->outputs) <= 0) {
diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c
index 5a632be4..01fea475 100644
--- a/src/pulsecore/cli-command.c
+++ b/src/pulsecore/cli-command.c
@@ -1030,7 +1030,7 @@ static int pa_cli_command_sink_default(pa_core *c, pa_tokenizer *t, pa_strbuf *b
}
if ((s = pa_namereg_get(c, n, PA_NAMEREG_SINK)))
- pa_core_set_configured_default_sink(c, s);
+ pa_core_set_configured_default_sink(c, s->name);
else
pa_strbuf_printf(buf, "Sink %s does not exist.\n", n);
@@ -1052,7 +1052,7 @@ static int pa_cli_command_source_default(pa_core *c, pa_tokenizer *t, pa_strbuf
}
if ((s = pa_namereg_get(c, n, PA_NAMEREG_SOURCE)))
- pa_core_set_configured_default_source(c, s);
+ pa_core_set_configured_default_source(c, s->name);
else
pa_strbuf_printf(buf, "Source %s does not exist.\n", n);
return 0;
diff --git a/src/pulsecore/core.c b/src/pulsecore/core.c
index 52e51db1..e01677d5 100644
--- a/src/pulsecore/core.c
+++ b/src/pulsecore/core.c
@@ -214,6 +214,8 @@ static void core_free(pa_object *o) {
pa_assert(!c->default_source);
pa_assert(!c->default_sink);
+ pa_xfree(c->configured_default_source);
+ pa_xfree(c->configured_default_sink);
pa_silence_cache_done(&c->silence_cache);
pa_mempool_unref(c->mempool);
@@ -224,38 +226,46 @@ static void core_free(pa_object *o) {
pa_xfree(c);
}
-void pa_core_set_configured_default_sink(pa_core *core, pa_sink *sink) {
- pa_sink *old_sink;
+void pa_core_set_configured_default_sink(pa_core *core, const char *sink) {
+ char *old_sink;
pa_assert(core);
- old_sink = core->configured_default_sink;
+ old_sink = pa_xstrdup(core->configured_default_sink);
- if (sink == old_sink)
- return;
+ if (pa_safe_streq(sink, old_sink))
+ goto finish;
- core->configured_default_sink = sink;
+ pa_xfree(core->configured_default_sink);
+ core->configured_default_sink = pa_xstrdup(sink);
pa_log_info("configured_default_sink: %s -> %s",
- old_sink ? old_sink->name : "(unset)", sink ? sink->name : "(unset)");
+ old_sink ? old_sink : "(unset)", sink ? sink : "(unset)");
pa_core_update_default_sink(core);
+
+finish:
+ pa_xfree(old_sink);
}
-void pa_core_set_configured_default_source(pa_core *core, pa_source *source) {
- pa_source *old_source;
+void pa_core_set_configured_default_source(pa_core *core, const char *source) {
+ char *old_source;
pa_assert(core);
- old_source = core->configured_default_source;
+ old_source = pa_xstrdup(core->configured_default_source);
- if (source == old_source)
- return;
+ if (pa_safe_streq(source, old_source))
+ goto finish;
- core->configured_default_source = source;
+ pa_xfree(core->configured_default_source);
+ core->configured_default_source = pa_xstrdup(source);
pa_log_info("configured_default_source: %s -> %s",
- old_source ? old_source->name : "(unset)", source ? source->name : "(unset)");
+ old_source ? old_source : "(unset)", source ? source : "(unset)");
pa_core_update_default_source(core);
+
+finish:
+ pa_xfree(old_source);
}
/* a < b -> return -1
@@ -275,9 +285,9 @@ static int compare_sinks(pa_sink *a, pa_sink *b) {
return 1;
/* The configured default sink is preferred over any other sink. */
- if (b == core->configured_default_sink)
+ if (pa_safe_streq(b->name, core->configured_default_sink))
return -1;
- if (a == core->configured_default_sink)
+ if (pa_safe_streq(a->name, core->configured_default_sink))
return 1;
if (a->priority < b->priority)
@@ -349,9 +359,9 @@ static int compare_sources(pa_source *a, pa_source *b) {
return 1;
/* The configured default source is preferred over any other source. */
- if (b == core->configured_default_source)
+ if (pa_safe_streq(b->name, core->configured_default_source))
return -1;
- if (a == core->configured_default_source)
+ if (pa_safe_streq(a->name, core->configured_default_source))
return 1;
/* Monitor sources lose to non-monitor sources. */
diff --git a/src/pulsecore/core.h b/src/pulsecore/core.h
index 8af14b04..79a095d2 100644
--- a/src/pulsecore/core.h
+++ b/src/pulsecore/core.h
@@ -163,9 +163,12 @@ struct pa_core {
pa_hashmap *namereg, *shared;
/* The default sink/source as configured by the user. If the user hasn't
- * explicitly configured anything, these are set to NULL. */
- pa_sink *configured_default_sink;
- pa_source *configured_default_source;
+ * explicitly configured anything, these are set to NULL. These are strings
+ * instead of sink/source pointers, because that allows us to reference
+ * devices that don't currently exist. That's useful for remembering that
+ * a hotplugged USB sink was previously set as the default sink. */
+ char *configured_default_sink;
+ char *configured_default_source;
/* The effective default sink/source. If no sink or source is explicitly
* configured as the default, we pick the device that ranks highest
@@ -236,8 +239,8 @@ enum {
pa_core* pa_core_new(pa_mainloop_api *m, bool shared, bool enable_memfd, size_t shm_size);
-void pa_core_set_configured_default_sink(pa_core *core, pa_sink *sink);
-void pa_core_set_configured_default_source(pa_core *core, pa_source *source);
+void pa_core_set_configured_default_sink(pa_core *core, const char *sink);
+void pa_core_set_configured_default_source(pa_core *core, const char *source);
/* These should be called whenever something changes that may affect the
* default sink or source choice.
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index 266b676d..068e0c00 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -4346,7 +4346,7 @@ static void command_set_default_sink_or_source(pa_pdispatch *pd, uint32_t comman
source = pa_namereg_get(c->protocol->core, s, PA_NAMEREG_SOURCE);
CHECK_VALIDITY(c->pstream, source, tag, PA_ERR_NOENTITY);
- pa_core_set_configured_default_source(c->protocol->core, source);
+ pa_core_set_configured_default_source(c->protocol->core, source->name);
} else {
pa_sink *sink;
pa_assert(command == PA_COMMAND_SET_DEFAULT_SINK);
@@ -4354,7 +4354,7 @@ static void command_set_default_sink_or_source(pa_pdispatch *pd, uint32_t comman
sink = pa_namereg_get(c->protocol->core, s, PA_NAMEREG_SINK);
CHECK_VALIDITY(c->pstream, sink, tag, PA_ERR_NOENTITY);
- pa_core_set_configured_default_sink(c->protocol->core, sink);
+ pa_core_set_configured_default_sink(c->protocol->core, sink->name);
}
pa_pstream_send_simple_ack(c->pstream, tag);
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 39463bd2..a8b4cd3d 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -694,10 +694,7 @@ void pa_sink_unlink(pa_sink* s) {
pa_namereg_unregister(s->core, s->name);
pa_idxset_remove_by_data(s->core->sinks, s, NULL);
- if (s == s->core->configured_default_sink)
- pa_core_set_configured_default_sink(s->core, NULL);
- else
- pa_core_update_default_sink(s->core);
+ pa_core_update_default_sink(s->core);
if (s->card)
pa_idxset_remove_by_data(s->card->sinks, s, NULL);
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index d56a13dd..b2936c5f 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -636,10 +636,7 @@ void pa_source_unlink(pa_source *s) {
pa_namereg_unregister(s->core, s->name);
pa_idxset_remove_by_data(s->core->sources, s, NULL);
- if (s == s->core->configured_default_source)
- pa_core_set_configured_default_source(s->core, NULL);
- else
- pa_core_update_default_source(s->core);
+ pa_core_update_default_source(s->core);
if (s->card)
pa_idxset_remove_by_data(s->card->sources, s, NULL);
commit abdd14d5e02204df411946751b206c07a3ea798b
Author: Tanu Kaskinen <tanuk at iki.fi>
Date: Mon Jul 3 17:35:08 2017 +0300
fix dbus message leaks
I reviewed all places that call
dbus_connection_send_with_reply_and_block(), and found several places
where dbus messages aren't properly unreffed.
diff --git a/src/modules/bluetooth/backend-ofono.c b/src/modules/bluetooth/backend-ofono.c
index 6e9a3664..2c51497f 100644
--- a/src/modules/bluetooth/backend-ofono.c
+++ b/src/modules/bluetooth/backend-ofono.c
@@ -168,9 +168,15 @@ static int hf_audio_agent_transport_acquire(pa_bluetooth_transport *t, bool opti
dbus_error_init(&derr);
pa_assert_se(m = dbus_message_new_method_call(t->owner, t->path, "org.ofono.HandsfreeAudioCard", "Connect"));
r = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(card->backend->connection), m, -1, &derr);
+ dbus_message_unref(m);
+ m = NULL;
+
if (!r)
return -1;
+ dbus_message_unref(r);
+ r = NULL;
+
if (card->connecting)
return -EAGAIN;
}
diff --git a/src/modules/bluetooth/bluez4-util.c b/src/modules/bluetooth/bluez4-util.c
index 82654508..ca606193 100644
--- a/src/modules/bluetooth/bluez4-util.c
+++ b/src/modules/bluetooth/bluez4-util.c
@@ -1116,6 +1116,8 @@ int pa_bluez4_transport_acquire(pa_bluez4_transport *t, bool optional, size_t *i
pa_assert_se(m = dbus_message_new_method_call(t->owner, t->path, "org.bluez.MediaTransport", "Acquire"));
pa_assert_se(dbus_message_append_args(m, DBUS_TYPE_STRING, &accesstype, DBUS_TYPE_INVALID));
r = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(t->device->discovery->connection), m, -1, &err);
+ dbus_message_unref(m);
+ m = NULL;
if (!r) {
dbus_error_free(&err);
@@ -1143,7 +1145,7 @@ fail:
void pa_bluez4_transport_release(pa_bluez4_transport *t) {
const char *accesstype = "rw";
- DBusMessage *m;
+ DBusMessage *m, *r;
DBusError err;
pa_assert(t);
@@ -1154,7 +1156,13 @@ void pa_bluez4_transport_release(pa_bluez4_transport *t) {
pa_assert_se(m = dbus_message_new_method_call(t->owner, t->path, "org.bluez.MediaTransport", "Release"));
pa_assert_se(dbus_message_append_args(m, DBUS_TYPE_STRING, &accesstype, DBUS_TYPE_INVALID));
- dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(t->device->discovery->connection), m, -1, &err);
+ r = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(t->device->discovery->connection), m, -1, &err);
+ dbus_message_unref(m);
+ m = NULL;
+ if (r) {
+ dbus_message_unref(r);
+ r = NULL;
+ }
if (dbus_error_is_set(&err)) {
pa_log("Failed to release transport %s: %s", t->path, err.message);
diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
index 8956fb13..c9283232 100644
--- a/src/modules/bluetooth/bluez5-util.c
+++ b/src/modules/bluetooth/bluez5-util.c
@@ -363,6 +363,8 @@ static int bluez5_transport_acquire_cb(pa_bluetooth_transport *t, bool optional,
dbus_error_init(&err);
r = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(t->device->discovery->connection), m, -1, &err);
+ 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);
@@ -393,7 +395,7 @@ finish:
}
static void bluez5_transport_release_cb(pa_bluetooth_transport *t) {
- DBusMessage *m;
+ DBusMessage *m, *r;
DBusError err;
pa_assert(t);
@@ -408,7 +410,13 @@ static void bluez5_transport_release_cb(pa_bluetooth_transport *t) {
}
pa_assert_se(m = dbus_message_new_method_call(t->owner, t->path, BLUEZ_MEDIA_TRANSPORT_INTERFACE, "Release"));
- dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(t->device->discovery->connection), m, -1, &err);
+ r = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(t->device->discovery->connection), m, -1, &err);
+ dbus_message_unref(m);
+ m = NULL;
+ if (r) {
+ dbus_message_unref(r);
+ r = NULL;
+ }
if (dbus_error_is_set(&err)) {
pa_log_error("Failed to release transport %s: %s", t->path, err.message);
diff --git a/src/modules/reserve.c b/src/modules/reserve.c
index f78805ed..b0038e66 100644
--- a/src/modules/reserve.c
+++ b/src/modules/reserve.c
@@ -474,6 +474,9 @@ int rd_acquire(
goto fail;
}
+ dbus_message_unref(m);
+ m = NULL;
+
if (!dbus_message_get_args(
reply,
error,
@@ -483,6 +486,9 @@ int rd_acquire(
goto fail;
}
+ dbus_message_unref(reply);
+ reply = NULL;
+
if (!good) {
r = -EBUSY;
goto fail;
More information about the pulseaudio-commits
mailing list