Merge lp:~cjcurran/indicator-sound/default_sink_fixes into lp:indicator-sound/0.1

Proposed by Conor Curran
Status: Merged
Merged at revision: not available
Proposed branch: lp:~cjcurran/indicator-sound/default_sink_fixes
Merge into: lp:indicator-sound/0.1
Diff against target: 80 lines (+27/-14)
1 file modified
src/pulse-manager.c (+27/-14)
To merge this branch: bzr merge lp:~cjcurran/indicator-sound/default_sink_fixes
Reviewer Review Type Date Requested Status
David Barth Approve
Review via email: mp+19330@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Conor Curran (cjcurran) wrote :

1. Fixes default sink device detection bug in first release.
2. Logic for the default sink detection should now be far more robust.

Revision history for this message
David Barth (dbarth) wrote :

Looks easier to understand with those changes.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/pulse-manager.c'
2--- src/pulse-manager.c 2010-02-11 15:19:22 +0000
3+++ src/pulse-manager.c 2010-02-15 12:52:17 +0000
4@@ -44,6 +44,7 @@
5 static void pulse_server_info_callback(pa_context *c, const pa_server_info *info, void *userdata);
6 static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, void *userdata);
7 static void destroy_sink_info(void *value);
8+static gboolean determine_sink_availability();
9
10
11 /*
12@@ -99,15 +100,32 @@
13 Controllers & Utilities
14 */
15
16-static gboolean sink_available()
17+static gboolean determine_sink_availability()
18 {
19- if (g_hash_table_size(sink_hash) < 1)
20+
21+ // Firstly check to see if we have any sinks
22+ // if not get the hell out of here !
23+ if (g_hash_table_size(sink_hash) < 1){
24+ g_debug("Sink_available returning false because sinks_hash is empty !!!");
25+ DEFAULT_SINK_INDEX = -1;
26 return FALSE;
27+ }
28+
29+ // Secondly, make sure the default sink index is set
30+ // If the default sink index has not been set (via the server) it will attempt to set it to the value of the first
31+ // index in the array of keys from the sink_hash.
32+ GList *keys = g_hash_table_get_keys(sink_hash);
33+ DEFAULT_SINK_INDEX = (DEFAULT_SINK_INDEX < 0) ? GPOINTER_TO_INT(g_list_first(keys)) : DEFAULT_SINK_INDEX;
34+
35+ // Thirdly ensure the default sink index does not have the name "auto_null"
36 sink_info *s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX));
37- // TODO more testing is required for the case of having no available sink
38- // This will need to iterate through the sinks to find an available
39- // one as opposed to just picking the first
40- return ((g_strcasecmp(s->name, " auto_null ") != 0) && s->active_port == TRUE);
41+ // Up until now the most rebost method to test this is to manually remove the available sink device
42+ // kernel module and then reload (rmmod & modprobe).
43+ // TODO: Edge case of dynamic loading and unloading of sinks should be handled also.
44+ g_debug("About to test for to see if the available sink is null - s->name = %s", s->name);
45+ gboolean available = g_ascii_strncasecmp("auto_null", s->name, 9) != 0;
46+ g_debug("sink_available: %i", available);
47+ return available;
48 }
49
50 static gboolean default_sink_is_muted()
51@@ -222,18 +240,14 @@
52 static void pulse_sink_info_callback(pa_context *c, const pa_sink_info *sink, int eol, void *userdata)
53 {
54 if (eol > 0) {
55- gboolean device_available = sink_available();
56+
57+ gboolean device_available = determine_sink_availability();
58 if(device_available == TRUE)
59 {
60- // Hopefully the PA server has set the default device if not default to 0
61- DEFAULT_SINK_INDEX = (DEFAULT_SINK_INDEX < 0) ? 0 : DEFAULT_SINK_INDEX;
62- // TODO optimize
63- // Cache method returns! (unneccessary multiple utility calls)
64- // test_hash();
65 update_pa_state(TRUE, device_available, default_sink_is_muted(), get_default_sink_volume());
66 sound_service_dbus_update_sink_volume(dbus_service, get_default_sink_volume());
67 sound_service_dbus_update_sink_mute(dbus_service, default_sink_is_muted());
68- g_debug("default sink index : %d", DEFAULT_SINK_INDEX);
69+ g_debug("default sink index : %d", DEFAULT_SINK_INDEX);
70 }
71 else{
72 //Update the indicator to show PA either is not ready or has no available sink
73@@ -261,7 +275,6 @@
74
75 static void pulse_default_sink_info_callback(pa_context *c, const pa_sink_info *info, int eol, void *userdata)
76 {
77- g_debug("default sink info callback");
78 if (eol > 0) {
79 if (pa_context_errno(c) == PA_ERR_NOENTITY)
80 return;

Subscribers

People subscribed via source and target branches