patches/libcanberra-02-device.diff
author yippi
Mon, 27 Sep 2010 21:07:51 +0000
changeset 20108 51df67ca9307
parent 20106 5bdb40599e51
permissions -rw-r--r--
I had these modules listed as being owned by me, but they are really owned by wangke, correcting.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20055
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     1
--- libcanberra-0.25/src/Makefile.am-orig	2010-09-13 23:46:23.884713926 -0500
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     2
+++ libcanberra-0.25/src/Makefile.am	2010-09-13 23:46:45.949907623 -0500
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     3
@@ -60,8 +60,10 @@ libcanberra_la_SOURCES = \
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     4
 	fork-detect.c fork-detect.h
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     5
 libcanberra_la_CFLAGS = \
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     6
 	$(AM_CFLAGS) \
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     7
+	$(GCONF_CFLAGS) \
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     8
 	$(VORBIS_CFLAGS)
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     9
 libcanberra_la_LIBADD = \
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    10
+	$(GCONF_LIBS) \
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    11
 	$(VORBIS_LIBS)
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    12
 libcanberra_la_LDFLAGS = \
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    13
 	-export-dynamic \
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    14
--- libcanberra-0.25/src/common.c-orig	2010-09-13 19:17:02.032029728 -0500
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    15
+++ libcanberra-0.25/src/common.c	2010-09-14 00:06:00.628638823 -0500
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    16
@@ -26,6 +26,8 @@
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    17
 
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    18
 #include <stdarg.h>
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    19
 
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    20
+#include <gconf/gconf-client.h>
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    21
+
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    22
 #include "canberra.h"
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    23
 #include "common.h"
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    24
 #include "malloc.h"
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    25
@@ -34,6 +36,8 @@
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    26
 #include "macro.h"
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    27
 #include "fork-detect.h"
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    28
 
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    29
+#define GNOME_VOLUME_CONTROL_KEY_ACTIVE_ELEMENT "/apps/gnome-volume-control/active-element"
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    30
+
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    31
 /**
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    32
  * SECTION:canberra
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    33
  * @short_description: General libcanberra API
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    34
@@ -129,6 +133,7 @@ int ca_context_create(ca_context **_c) {
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    35
         ca_context *c;
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    36
         int ret;
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    37
         const char *d;
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    38
+        const char *device = NULL;
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    39
 
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    40
         ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED);
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    41
         ca_return_val_if_fail(_c, CA_ERROR_INVALID);
20106
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    42
@@ -153,13 +158,79 @@ int ca_context_create(ca_context **_c) {
20055
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    43
                 }
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    44
         }
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    45
 
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    46
-        if ((d = getenv("CANBERRA_DEVICE"))) {
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    47
-                if ((ret = ca_context_change_device(c, d)) < 0) {
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    48
+        /*
20106
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    49
+         * If the user sets CANBERRA_DEVICE, use that.  Then fallback to the
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    50
+         * gnome-volume-control setting.  If neither is set, then do not set
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    51
+         * the device and just let OSS use its default.
20055
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    52
+         */
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    53
+        if ((device = getenv("CANBERRA_DEVICE"))) {
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    54
+                if ((ret = ca_context_change_device(c, device)) < 0) {
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    55
                         ca_context_destroy(c);
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    56
                         return ret;
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    57
                 }
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    58
         }
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    59
 
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    60
+        /*
20106
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    61
+         * Note that the following code only works with OSSv4.  Also note that
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    62
+         * gnome-volume-control saves the device via GConf in this format:
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    63
+         *
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    64
+         * foo#0 (OSS v4 Audio Mixer)
20055
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    65
+         *
20106
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    66
+         * Where the actual device is "/dev/sound/"; followed by the first word
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    67
+         * in the GConf value with the "#" changed to a ":"; and "dsp" appended
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    68
+         * to the end.  So "foo#0" becomes /dev/sound/foo:0dsp.  The "dsp" is
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    69
+         * needed since canberra uses OSS ioctls.
20055
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    70
+         */
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    71
+        if (device == NULL) {
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    72
+                GConfClient *gconf_client;
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    73
+                char *gvc_active;
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    74
+
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    75
+                gconf_client = gconf_client_get_default ();
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    76
+                
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    77
+                gvc_active = gconf_client_get_string (gconf_client,
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    78
+                        GNOME_VOLUME_CONTROL_KEY_ACTIVE_ELEMENT, NULL);
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    79
+
20106
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    80
+                /*
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    81
+                 * Only use the gnome-volume-control setting if the value
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    82
+                 * is associated with an OSS device.  Check for "OSS" string
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    83
+                 * in the value since it will be "foo#0 (OSS v4 Audio Mixer)"
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    84
+                 * if using OSS.
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    85
+                 */
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    86
+                if (gvc_active != NULL && strstr (gvc_active, "OSS") != NULL) {
20055
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    87
+                       char ** element_arr;
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    88
+                       element_arr = g_strsplit (gvc_active, " ", 2);
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    89
+
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    90
+                        if (element_arr != NULL &&
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    91
+                            element_arr[0] != NULL) {
20106
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    92
+                                char **device_arr = g_strsplit (element_arr[0],
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    93
+                                                                "#", 2);
20055
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    94
+                                if (device_arr != NULL &&
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    95
+                                    device_arr[0] != NULL &&
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    96
+                                    device_arr[1] != NULL) {
20106
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    97
+                                        /*
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    98
+                                         * Need to prepend "/dev/sound/" and
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
    99
+                                         * append "dsp" to the device name
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
   100
+                                         * returned by gnome-volume-control.
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
   101
+                                         * The "dsp" is needed since canberra
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
   102
+                                         * uses OSS ioctls.
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
   103
+                                         */
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
   104
+                                        char * device_name = g_strdup_printf
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
   105
+                                                ("/dev/sound/%s:%sdsp",
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
   106
+                                                device_arr[0], device_arr[1]);
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
   107
+                                        if ((ret = ca_context_change_device(c,
5bdb40599e51 2010-09-27 Brian Cameron <[email protected]>
yippi
parents: 20055
diff changeset
   108
+                                             device_name)) < 0) {
20055
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   109
+                                                ca_context_destroy(c);
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   110
+                                                return ret;
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   111
+                                        }
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   112
+                                        g_free (device_name);
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   113
+                                }
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   114
+                                g_strfreev (device_arr);
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   115
+                        }
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   116
+                        g_strfreev (element_arr);
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   117
+                }
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   118
+                g_free (gvc_active);
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   119
+        }
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   120
+
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   121
         *_c = c;
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   122
         return CA_SUCCESS;
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   123
 }
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   124
--- libcanberra-0.25/configure.ac-orig	2010-09-13 23:43:25.620576446 -0500
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   125
+++ libcanberra-0.25/configure.ac	2010-09-13 23:46:13.839034621 -0500
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   126
@@ -490,6 +490,10 @@ AM_CONDITIONAL([USE_LYNX], [test "x$have
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   127
 
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   128
 PKG_CHECK_MODULES(VORBIS, [ vorbisfile ])
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   129
 
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   130
+### GConf (mandatory) ###
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   131
+
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   132
+PKG_CHECK_MODULES(GCONF, [ gconf-2.0 ])
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   133
+
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   134
 ### Chose builtin driver ###
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   135
 
9d1b5fad7578 2010-09-13 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   136
 AC_ARG_WITH([builtin],