It's time to get a little momentum on the Jack detection again. I hope to be able to work with it this week.

As you might know, my udev patch turned controversial [1] [2], so I decided to attack the problem from another angle. Here's a preliminary idea of how the API could look like from the "volume control UI" perspective. As Tanuk originally suggested, every port now has an "available" property which can be yes/no/unknown. Also imagine the same thing implemented for sources as now being presented for sinks.

--
David Henningsson, Canonical Ltd.
http://launchpad.net/~diwic

[1] http://www.spinics.net/lists/hotplug/msg04936.html
[2] http://mailman.alsa-project.org/pipermail/alsa-devel/2011-June/041071.html
diff --git a/src/pulse/introspect.h b/src/pulse/introspect.h
index 196d44d..6f62497 100644
--- a/src/pulse/introspect.h
+++ b/src/pulse/introspect.h
@@ -193,6 +193,10 @@
 
 PA_C_DECL_BEGIN
 
+#define PA_PORT_AVAILABLE_UNKNOWN (0)   /**< This port does not support jack detection \since MERGE_OF_JACK_DETECTION */
+#define PA_PORT_AVAILABLE_NO (1)        /**< This port is not available, likely because the jack is not plugged in. \since MERGE_OF_JACK_DETECTION */
+#define PA_PORT_AVAILABLE_YES (2)       /**< This port is available, likely because the jack is plugged in. \since MERGE_OF_JACK_DETECTION */
+
 /** @{ \name Sinks */
 
 /** Stores information about a specific port of a sink.  Please
@@ -202,6 +206,8 @@ typedef struct pa_sink_port_info {
     const char *name;                   /**< Name of this port */
     const char *description;            /**< Description of this port */
     uint32_t priority;                  /**< The higher this value is the more useful this port is as a default */
+    uint32_t available;                 /**< PA_PORT_AVAILABLE_UNKNOWN, PA_PORT_AVAILABLE_NO or PA_PORT_AVAILABLE_YES \since MERGE_OF_JACK_DETECTION */
+    int switch_on_avail;                /**< Boolean indicating that when "available" changes to PA_PORT_AVAILABLE_YES, streams should move to this sink. \since MERGE_OF_JACK_DETECTION */
 } pa_sink_port_info;
 
 /** Stores information about sinks. Please note that this structure
@@ -267,6 +273,9 @@ pa_operation* pa_context_suspend_sink_by_index(pa_context *c, uint32_t idx, int
 /** Change the profile of a sink. \since 0.9.16 */
 pa_operation* pa_context_set_sink_port_by_index(pa_context *c, uint32_t idx, const char*port, pa_context_success_cb_t cb, void *userdata);
 
+/** Change the "switch_on_available" attribute of a port of a sink. \since MERGE_OF_JACK_DETECTION */
+pa_operation* pa_context_set_sink_port_switch_on_avail_by_index(pa_context *c, uint32_t idx, const char*port, int switch_on_available, pa_context_success_cb_t cb, void *userdata);
+
 /** Change the profile of a sink. \since 0.9.15 */
 pa_operation* pa_context_set_sink_port_by_name(pa_context *c, const char*name, const char*port, pa_context_success_cb_t cb, void *userdata);
 
diff --git a/src/pulsecore/native-common.h b/src/pulsecore/native-common.h
index 5d1ba6a..ce88ddd 100644
--- a/src/pulsecore/native-common.h
+++ b/src/pulsecore/native-common.h
@@ -173,6 +173,9 @@ enum {
     PA_COMMAND_SET_SOURCE_OUTPUT_VOLUME,
     PA_COMMAND_SET_SOURCE_OUTPUT_MUTE,
 
+    /* Supported since protocol v23 (MERGE_OF_JACK_DETECTION) */
+    PA_COMMAND_SET_SINK_PORT_SWITCH_ON_AVAIL,
+
     PA_COMMAND_MAX
 };
 
diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h
index 85c22ec..38e3f9d 100644
--- a/src/pulsecore/sink.h
+++ b/src/pulsecore/sink.h
@@ -59,6 +59,8 @@ struct pa_device_port {
     char *description;
 
     unsigned priority;
+    uint32_t available;                 /**< PA_PORT_AVAILABLE_UNKNOWN, PA_PORT_AVAILABLE_NO or PA_PORT_AVAILABLE_YES \since MERGE_OF_JACK_DETECTION */
+    int switch_when_available;          /**< Boolean indicating that when "available" changes to PA_PORT_AVAILABLE_YES, streams should move to this sink. \since MERGE_OF_JACK_DETECTION */
 
     /* .. followed by some implementation specific data */
 };
@@ -396,6 +398,7 @@ pa_bool_t pa_sink_get_mute(pa_sink *sink, pa_bool_t force_refresh);
 pa_bool_t pa_sink_update_proplist(pa_sink *s, pa_update_mode_t mode, pa_proplist *p);
 
 int pa_sink_set_port(pa_sink *s, const char *name, pa_bool_t save);
+int pa_sink_set_port_available(pa_sink *s, const char *name, int available);
 
 unsigned pa_sink_linked_by(pa_sink *s); /* Number of connected streams */
 unsigned pa_sink_used_by(pa_sink *s); /* Number of connected streams which are not corked */
_______________________________________________
pulseaudio-discuss mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss

Reply via email to