[pulseaudio-commits] [Git][pulseaudio/pulseaudio][master] 6 commits: switch-on-port-available: Improve readability
Tanu Kaskinen
gitlab at gitlab.freedesktop.org
Wed Oct 3 08:44:34 UTC 2018
Tanu Kaskinen pushed to branch master at PulseAudio / pulseaudio
Commits:
cefe037a by João Paulo Rechi Vita at 2018-10-03T08:27:42Z
switch-on-port-available: Improve readability
Split a big conditional into separate checks and use pa_safe_streq
instead of checking if a pointer is valid and calling pa_streq inside a
conditional.
- - - - -
e9f5fa94 by João Paulo Rechi Vita at 2018-10-03T08:31:51Z
switch-on-connect: Improve readability
Make code easier to read by moving pa_proplist_gets out of the if
condition and using pa_safe_streq.
- - - - -
b53d8177 by João Paulo Rechi Vita at 2018-10-03T08:33:34Z
switch-on-connect: Clean-up tabs used for identation
- - - - -
b15f12ef by João Paulo Rechi Vita at 2018-10-03T08:36:00Z
switch-on-connect: Add debug logs
Log when module-switch-on-connect tries to change the default sink or
source.
- - - - -
723ae511 by João Paulo Rechi Vita at 2018-10-03T08:37:14Z
module-rescue-streams: Fix tab used for identation
- - - - -
1bae214d by João Paulo Rechi Vita at 2018-10-03T08:40:22Z
card: Fix typo in comments
- - - - -
4 changed files:
- src/modules/module-rescue-streams.c
- src/modules/module-switch-on-connect.c
- src/modules/module-switch-on-port-available.c
- src/pulsecore/card.h
Changes:
=====================================
src/modules/module-rescue-streams.c
=====================================
@@ -136,7 +136,7 @@ static pa_sink* find_evacuation_sink(pa_core *c, pa_sink_input *i, pa_sink *skip
target = fb_sink;
if (!target)
- pa_log_debug("No evacuation sink found.");
+ pa_log_debug("No evacuation sink found.");
return target;
}
=====================================
src/modules/module-switch-on-connect.c
=====================================
@@ -68,17 +68,20 @@ static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, void*
if (c->state != PA_CORE_RUNNING)
return PA_HOOK_OK;
+ pa_log_debug("Trying to switch to new sink %s", sink->name);
+
/* Don't switch to any internal devices */
- if ((s = pa_proplist_gets(sink->proplist, PA_PROP_DEVICE_BUS))) {
- if (pa_streq(s, "pci"))
- return PA_HOOK_OK;
- else if (pa_streq(s, "isa"))
- return PA_HOOK_OK;
+ s = pa_proplist_gets(sink->proplist, PA_PROP_DEVICE_BUS);
+ if (pa_safe_streq(s, "pci") || pa_safe_streq(s, "isa")) {
+ pa_log_debug("Refusing to switch to sink on %s bus", s);
+ return PA_HOOK_OK;
}
/* Ignore virtual sinks if not configured otherwise on the command line */
- if (u->ignore_virtual && !(sink->flags & PA_SINK_HARDWARE))
+ if (u->ignore_virtual && !(sink->flags & PA_SINK_HARDWARE)) {
+ pa_log_debug("Refusing to switch to virtual sink");
return PA_HOOK_OK;
+ }
/* No default sink, nothing to move away, just set the new default */
if (!c->default_sink) {
@@ -86,12 +89,16 @@ static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, void*
return PA_HOOK_OK;
}
- if (c->default_sink == sink)
+ if (c->default_sink == sink) {
+ pa_log_debug("%s already is the default sink", sink->name);
return PA_HOOK_OK;
+ }
if (u->only_from_unavailable)
- if (!c->default_sink->active_port || c->default_sink->active_port->available != PA_AVAILABLE_NO)
+ if (!c->default_sink->active_port || c->default_sink->active_port->available != PA_AVAILABLE_NO) {
+ pa_log_debug("Current default sink is available and module argument only_from_unavailable was set");
return PA_HOOK_OK;
+ }
old_default_sink = c->default_sink;
@@ -138,17 +145,20 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source,
if (source->monitor_of)
return PA_HOOK_OK;
+ pa_log_debug("Trying to switch to new source %s", source->name);
+
/* Don't switch to any internal devices */
- if ((s = pa_proplist_gets(source->proplist, PA_PROP_DEVICE_BUS))) {
- if (pa_streq(s, "pci"))
- return PA_HOOK_OK;
- else if (pa_streq(s, "isa"))
- return PA_HOOK_OK;
+ s = pa_proplist_gets(source->proplist, PA_PROP_DEVICE_BUS);
+ if (pa_safe_streq(s, "pci") || pa_safe_streq(s, "isa")) {
+ pa_log_debug("Refusing to switch to source on %s bus", s);
+ return PA_HOOK_OK;
}
/* Ignore virtual sources if not configured otherwise on the command line */
- if (u->ignore_virtual && !(source->flags & PA_SOURCE_HARDWARE))
+ if (u->ignore_virtual && !(source->flags & PA_SOURCE_HARDWARE)) {
+ pa_log_debug("Refusing to switch to virtual source");
return PA_HOOK_OK;
+ }
/* No default source, nothing to move away, just set the new default */
if (!c->default_source) {
@@ -156,12 +166,16 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source,
return PA_HOOK_OK;
}
- if (c->default_source == source)
+ if (c->default_source == source) {
+ pa_log_debug("%s already is the default source", source->name);
return PA_HOOK_OK;
+ }
if (u->only_from_unavailable)
- if (!c->default_source->active_port || c->default_source->active_port->available != PA_AVAILABLE_NO)
+ if (!c->default_source->active_port || c->default_source->active_port->available != PA_AVAILABLE_NO) {
+ pa_log_debug("Current default source is available and module argument only_from_unavailable was set");
return PA_HOOK_OK;
+ }
old_default_source = c->default_source;
@@ -207,14 +221,14 @@ int pa__init(pa_module*m) {
pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_LATE+20, (pa_hook_cb_t) source_put_hook_callback, u);
if (pa_modargs_get_value_boolean(ma, "only_from_unavailable", &u->only_from_unavailable) < 0) {
- pa_log("Failed to get a boolean value for only_from_unavailable.");
- goto fail;
+ pa_log("Failed to get a boolean value for only_from_unavailable.");
+ goto fail;
}
u->ignore_virtual = true;
if (pa_modargs_get_value_boolean(ma, "ignore_virtual", &u->ignore_virtual) < 0) {
- pa_log("Failed to get a boolean value for ignore_virtual.");
- goto fail;
+ pa_log("Failed to get a boolean value for ignore_virtual.");
+ goto fail;
}
pa_modargs_free(ma);
=====================================
src/modules/module-switch-on-port-available.c
=====================================
@@ -156,7 +156,7 @@ static int try_to_switch_profile(pa_device_port *port) {
continue;
/* Give a high bonus in case this is the preferred profile */
- if (port->preferred_profile && pa_streq(name ? name : profile->name, port->preferred_profile))
+ if (pa_safe_streq(name ? name : profile->name, port->preferred_profile))
prio += 1000000;
if (best_profile && best_prio >= prio)
@@ -261,10 +261,19 @@ static void switch_from_port(pa_device_port *port) {
return; /* Already deselected */
/* Try to find a good enough port to switch to */
- PA_HASHMAP_FOREACH(p, port->card->ports, state)
- if (p->direction == port->direction && p != port && p->available != PA_AVAILABLE_NO &&
- (!best_port || best_port->priority < p->priority))
+ PA_HASHMAP_FOREACH(p, port->card->ports, state) {
+ if (p == port)
+ continue;
+
+ if (p->available == PA_AVAILABLE_NO)
+ continue;
+
+ if (p->direction != port->direction)
+ continue;
+
+ if (!best_port || best_port->priority < p->priority)
best_port = p;
+ }
pa_log_debug("Trying to switch away from port %s, found %s", port->name, best_port ? best_port->name : "no better option");
=====================================
src/pulsecore/card.h
=====================================
@@ -128,7 +128,7 @@ pa_card *pa_card_new(pa_core *c, pa_card_new_data *data);
/* Select the initial card profile according to the configured policies. This
* must be called between pa_card_new() and pa_card_put(), after the port and
- * profile availablities have been initialized. */
+ * profile availabilities have been initialized. */
void pa_card_choose_initial_profile(pa_card *card);
void pa_card_put(pa_card *c);
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/compare/48021941a2ae072a87f6eca589566dd576cc6ab6...1bae214d8b2c9c7a0c11ee8bce2b98c775f21ead
--
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/compare/48021941a2ae072a87f6eca589566dd576cc6ab6...1bae214d8b2c9c7a0c11ee8bce2b98c775f21ead
You're receiving this email because of your account on gitlab.freedesktop.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-commits/attachments/20181003/40f50143/attachment-0001.html>
More information about the pulseaudio-commits
mailing list