[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, master, updated. v0.9.15-60-gc95cc9e

Lennart Poettering gitmailer-noreply at 0pointer.de
Wed Apr 29 14:23:30 PDT 2009


This is an automated email from the git hooks/post-receive script. It was
generated because of a push to the "PulseAudio Sound Server" repository.

The master branch has been updated
      from  84a92f2a88e9655a4d54410b37d9ca1d741646b9 (commit)

- Log -----------------------------------------------------------------
c95cc9e rygel: add module that interfaces with Rygel UPnP
390fe02 http: split out mime type handling calls
-----------------------------------------------------------------------

Summary of changes:
 src/Makefile.am                                    |   13 +-
 src/modules/module-rygel-media-server.c            |  549 ++++++++++++++++++++
 src/pulsecore/mime-type.c                          |  179 +++++++
 .../sig2str-test.c => pulsecore/mime-type.h}       |   22 +-
 src/pulsecore/protocol-http.c                      |  159 +------
 5 files changed, 756 insertions(+), 166 deletions(-)
 create mode 100644 src/modules/module-rygel-media-server.c
 create mode 100644 src/pulsecore/mime-type.c
 copy src/{tests/sig2str-test.c => pulsecore/mime-type.h} (62%)

-----------------------------------------------------------------------

commit 390fe02aa9215692c385e90028df1acdf6a73f77
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Apr 29 23:22:08 2009 +0200

    http: split out mime type handling calls

diff --git a/src/Makefile.am b/src/Makefile.am
index 719f9dd..c3c6945 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -883,7 +883,7 @@ libprotocol_cli_la_SOURCES = pulsecore/protocol-cli.c pulsecore/protocol-cli.h
 libprotocol_cli_la_LDFLAGS = -avoid-version
 libprotocol_cli_la_LIBADD = $(AM_LIBADD) libpulsecore- at PA_MAJORMINORMICRO@.la libpulsecommon- at PA_MAJORMINORMICRO@.la libpulse.la libcli.la
 
-libprotocol_http_la_SOURCES = pulsecore/protocol-http.c pulsecore/protocol-http.h
+libprotocol_http_la_SOURCES = pulsecore/protocol-http.c pulsecore/protocol-http.h pulsecore/mime-type.c pulsecore/mime-type.h
 libprotocol_http_la_LDFLAGS = -avoid-version
 libprotocol_http_la_LIBADD = $(AM_LIBADD) libpulsecore- at PA_MAJORMINORMICRO@.la libpulsecommon- at PA_MAJORMINORMICRO@.la libpulse.la
 
diff --git a/src/pulsecore/mime-type.c b/src/pulsecore/mime-type.c
new file mode 100644
index 0000000..55b8ffd
--- /dev/null
+++ b/src/pulsecore/mime-type.c
@@ -0,0 +1,179 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2005-2009 Lennart Poettering
+
+  PulseAudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License,
+  or (at your option) any later version.
+
+  PulseAudio is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <pulse/xmalloc.h>
+#include <pulsecore/core-util.h>
+
+#include "mime-type.h"
+
+pa_bool_t pa_sample_spec_is_mime(const pa_sample_spec *ss, const pa_channel_map *cm) {
+
+    pa_assert(pa_channel_map_compatible(cm, ss));
+
+    switch (ss->format) {
+        case PA_SAMPLE_S16BE:
+        case PA_SAMPLE_S24BE:
+        case PA_SAMPLE_U8:
+
+            if (ss->rate != 8000 &&
+                ss->rate != 11025 &&
+                ss->rate != 16000 &&
+                ss->rate != 22050 &&
+                ss->rate != 24000 &&
+                ss->rate != 32000 &&
+                ss->rate != 44100 &&
+                ss->rate != 48000)
+                return FALSE;
+
+            if (ss->channels != 1 &&
+                ss->channels != 2)
+                return FALSE;
+
+            if ((cm->channels == 1 && cm->map[0] != PA_CHANNEL_POSITION_MONO) ||
+                (cm->channels == 2 && (cm->map[0] != PA_CHANNEL_POSITION_LEFT || cm->map[1] != PA_CHANNEL_POSITION_RIGHT)))
+                return FALSE;
+
+            return TRUE;
+
+        case PA_SAMPLE_ULAW:
+
+            if (ss->rate != 8000)
+                return FALSE;
+
+            if (ss->channels != 1)
+                return FALSE;
+
+            if (cm->map[0] != PA_CHANNEL_POSITION_MONO)
+                return FALSE;
+
+            return TRUE;
+
+        default:
+            return FALSE;
+    }
+}
+
+void pa_sample_spec_mimefy(pa_sample_spec *ss, pa_channel_map *cm) {
+
+    pa_assert(pa_channel_map_compatible(cm, ss));
+
+    /* Turns the sample type passed in into the next 'better' one that
+     * can be encoded for HTTP. If there is no 'better' one we pick
+     * the 'best' one that is 'worse'. */
+
+    if (ss->channels > 2)
+        ss->channels = 2;
+
+    if (ss->rate > 44100)
+        ss->rate = 48000;
+    else if (ss->rate > 32000)
+        ss->rate = 44100;
+    else if (ss->rate > 24000)
+        ss->rate = 32000;
+    else if (ss->rate > 22050)
+        ss->rate = 24000;
+    else if (ss->rate > 16000)
+        ss->rate = 22050;
+    else if (ss->rate > 11025)
+        ss->rate = 16000;
+    else if (ss->rate > 8000)
+        ss->rate = 11025;
+    else
+        ss->rate = 8000;
+
+    switch (ss->format) {
+        case PA_SAMPLE_S24BE:
+        case PA_SAMPLE_S24LE:
+        case PA_SAMPLE_S24_32LE:
+        case PA_SAMPLE_S24_32BE:
+        case PA_SAMPLE_S32LE:
+        case PA_SAMPLE_S32BE:
+        case PA_SAMPLE_FLOAT32LE:
+        case PA_SAMPLE_FLOAT32BE:
+            ss->format = PA_SAMPLE_S24BE;
+            break;
+
+        case PA_SAMPLE_S16BE:
+        case PA_SAMPLE_S16LE:
+            ss->format = PA_SAMPLE_S16BE;
+            break;
+
+        case PA_SAMPLE_ULAW:
+        case PA_SAMPLE_ALAW:
+
+            if (ss->rate == 8000 && ss->channels == 1)
+                ss->format = PA_SAMPLE_ULAW;
+            else
+                ss->format = PA_SAMPLE_S16BE;
+            break;
+
+        case PA_SAMPLE_U8:
+            ss->format = PA_SAMPLE_U8;
+            break;
+
+        case PA_SAMPLE_MAX:
+        case PA_SAMPLE_INVALID:
+            pa_assert_not_reached();
+    }
+
+    pa_channel_map_init_auto(cm, ss->channels, PA_CHANNEL_MAP_DEFAULT);
+
+    pa_assert(pa_sample_spec_is_mime(ss, cm));
+}
+
+char *pa_sample_spec_to_mime_type(const pa_sample_spec *ss, const pa_channel_map *cm) {
+    pa_assert(pa_channel_map_compatible(cm, ss));
+
+    if (!pa_sample_spec_is_mime(ss, cm))
+        return NULL;
+
+    switch (ss->format) {
+
+        case PA_SAMPLE_S16BE:
+        case PA_SAMPLE_S24BE:
+        case PA_SAMPLE_U8:
+            return pa_sprintf_malloc("audio/%s; rate=%u; channels=%u",
+                                     ss->format == PA_SAMPLE_S16BE ? "L16" :
+                                     (ss->format == PA_SAMPLE_S24BE ? "L24" : "L8"),
+                                     ss->rate, ss->channels);
+
+        case PA_SAMPLE_ULAW:
+            return pa_xstrdup("audio/basic");
+
+        default:
+            pa_assert_not_reached();
+    }
+
+    pa_assert(pa_sample_spec_valid(ss));
+}
+
+char *pa_sample_spec_to_mime_type_mimefy(const pa_sample_spec *_ss, const pa_channel_map *_cm) {
+    pa_sample_spec ss = *_ss;
+    pa_channel_map cm = *_cm;
+
+    pa_sample_spec_mimefy(&ss, &cm);
+
+    return pa_sample_spec_to_mime_type(&ss, &cm);
+}
diff --git a/src/pulsecore/mime-type.h b/src/pulsecore/mime-type.h
new file mode 100644
index 0000000..db77379
--- /dev/null
+++ b/src/pulsecore/mime-type.h
@@ -0,0 +1,37 @@
+#ifndef foopulsecoremimetypehfoo
+#define foopulsecoremimetypehfoo
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2009 Lennart Poettering
+
+  PulseAudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License,
+  or (at your option) any later version.
+
+  PulseAudio is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <pulsecore/macro.h>
+#include <pulse/sample.h>
+#include <pulse/channelmap.h>
+
+pa_bool_t pa_sample_spec_is_mime(const pa_sample_spec *ss, const pa_channel_map *cm);
+void pa_sample_spec_mimefy(pa_sample_spec *ss, pa_channel_map *cm);
+char *pa_sample_spec_to_mime_type(const pa_sample_spec *ss, const pa_channel_map *cm);
+char *pa_sample_spec_to_mime_type_mimefy(const pa_sample_spec *_ss, const pa_channel_map *_cm);
+
+#endif
diff --git a/src/pulsecore/protocol-http.c b/src/pulsecore/protocol-http.c
index 6467024..46850b2 100644
--- a/src/pulsecore/protocol-http.c
+++ b/src/pulsecore/protocol-http.c
@@ -40,6 +40,7 @@
 #include <pulsecore/cli-text.h>
 #include <pulsecore/shared.h>
 #include <pulsecore/core-error.h>
+#include <pulsecore/mime-type.h>
 
 #include "protocol-http.h"
 
@@ -256,156 +257,6 @@ static void io_callback(pa_iochannel*io, void *userdata) {
     do_work(c);
 }
 
-static pa_bool_t is_mime_sample_spec(const pa_sample_spec *ss, const pa_channel_map *cm) {
-
-    pa_assert(pa_channel_map_compatible(cm, ss));
-
-    switch (ss->format) {
-        case PA_SAMPLE_S16BE:
-        case PA_SAMPLE_S24BE:
-        case PA_SAMPLE_U8:
-
-            if (ss->rate != 8000 &&
-                ss->rate != 11025 &&
-                ss->rate != 16000 &&
-                ss->rate != 22050 &&
-                ss->rate != 24000 &&
-                ss->rate != 32000 &&
-                ss->rate != 44100 &&
-                ss->rate != 48000)
-                return FALSE;
-
-            if (ss->channels != 1 &&
-                ss->channels != 2)
-                return FALSE;
-
-            if ((cm->channels == 1 && cm->map[0] != PA_CHANNEL_POSITION_MONO) ||
-                (cm->channels == 2 && (cm->map[0] != PA_CHANNEL_POSITION_LEFT || cm->map[1] != PA_CHANNEL_POSITION_RIGHT)))
-                return FALSE;
-
-            return TRUE;
-
-        case PA_SAMPLE_ULAW:
-
-            if (ss->rate != 8000)
-                return FALSE;
-
-            if (ss->channels != 1)
-                return FALSE;
-
-            if (cm->map[0] != PA_CHANNEL_POSITION_MONO)
-                return FALSE;
-
-            return TRUE;
-
-        default:
-            return FALSE;
-    }
-}
-
-static void mimefy_sample_spec(pa_sample_spec *ss, pa_channel_map *cm) {
-
-    pa_assert(pa_channel_map_compatible(cm, ss));
-
-    /* Turns the sample type passed in into the next 'better' one that
-     * can be encoded for HTTP. If there is no 'better' one we pick
-     * the 'best' one that is 'worse'. */
-
-    if (ss->channels > 2)
-        ss->channels = 2;
-
-    if (ss->rate > 44100)
-        ss->rate = 48000;
-    else if (ss->rate > 32000)
-        ss->rate = 44100;
-    else if (ss->rate > 24000)
-        ss->rate = 32000;
-    else if (ss->rate > 22050)
-        ss->rate = 24000;
-    else if (ss->rate > 16000)
-        ss->rate = 22050;
-    else if (ss->rate > 11025)
-        ss->rate = 16000;
-    else if (ss->rate > 8000)
-        ss->rate = 11025;
-    else
-        ss->rate = 8000;
-
-    switch (ss->format) {
-        case PA_SAMPLE_S24BE:
-        case PA_SAMPLE_S24LE:
-        case PA_SAMPLE_S24_32LE:
-        case PA_SAMPLE_S24_32BE:
-        case PA_SAMPLE_S32LE:
-        case PA_SAMPLE_S32BE:
-        case PA_SAMPLE_FLOAT32LE:
-        case PA_SAMPLE_FLOAT32BE:
-            ss->format = PA_SAMPLE_S24BE;
-            break;
-
-        case PA_SAMPLE_S16BE:
-        case PA_SAMPLE_S16LE:
-            ss->format = PA_SAMPLE_S16BE;
-            break;
-
-        case PA_SAMPLE_ULAW:
-        case PA_SAMPLE_ALAW:
-
-            if (ss->rate == 8000 && ss->channels == 1)
-                ss->format = PA_SAMPLE_ULAW;
-            else
-                ss->format = PA_SAMPLE_S16BE;
-            break;
-
-        case PA_SAMPLE_U8:
-            ss->format = PA_SAMPLE_U8;
-            break;
-
-        case PA_SAMPLE_MAX:
-        case PA_SAMPLE_INVALID:
-            pa_assert_not_reached();
-    }
-
-    pa_channel_map_init_auto(cm, ss->channels, PA_CHANNEL_MAP_DEFAULT);
-
-    pa_assert(is_mime_sample_spec(ss, cm));
-}
-
-static char *sample_spec_to_mime_type(const pa_sample_spec *ss, const pa_channel_map *cm) {
-    pa_assert(pa_channel_map_compatible(cm, ss));
-
-    if (!is_mime_sample_spec(ss, cm))
-        return NULL;
-
-    switch (ss->format) {
-
-        case PA_SAMPLE_S16BE:
-        case PA_SAMPLE_S24BE:
-        case PA_SAMPLE_U8:
-            return pa_sprintf_malloc("audio/%s; rate=%u; channels=%u",
-                                     ss->format == PA_SAMPLE_S16BE ? "L16" :
-                                     (ss->format == PA_SAMPLE_S24BE ? "L24" : "L8"),
-                                     ss->rate, ss->channels);
-
-        case PA_SAMPLE_ULAW:
-            return pa_xstrdup("audio/basic");
-
-        default:
-            pa_assert_not_reached();
-    }
-
-    pa_assert(pa_sample_spec_valid(ss));
-}
-
-static char *mimefy_and_stringify_sample_spec(const pa_sample_spec *_ss, const pa_channel_map *_cm) {
-    pa_sample_spec ss = *_ss;
-    pa_channel_map cm = *_cm;
-
-    mimefy_sample_spec(&ss, &cm);
-
-    return sample_spec_to_mime_type(&ss, &cm);
-}
-
 static char *escape_html(const char *t) {
     pa_strbuf *sb;
     const char *p, *e;
@@ -587,7 +438,7 @@ static void handle_listen(struct connection *c) {
         char *t, *m;
 
         t = escape_html(pa_strna(pa_proplist_gets(sink->proplist, PA_PROP_DEVICE_DESCRIPTION)));
-        m = mimefy_and_stringify_sample_spec(&sink->sample_spec, &sink->channel_map);
+        m = pa_sample_spec_to_mime_type_mimefy(&sink->sample_spec, &sink->channel_map);
 
         pa_ioline_printf(c->line,
                          "<a href=\"" URL_LISTEN_SOURCE "%s\" title=\"%s\">%s</a><br/>\n",
@@ -609,7 +460,7 @@ static void handle_listen(struct connection *c) {
             continue;
 
         t = escape_html(pa_strna(pa_proplist_gets(source->proplist, PA_PROP_DEVICE_DESCRIPTION)));
-        m = mimefy_and_stringify_sample_spec(&source->sample_spec, &source->channel_map);
+        m = pa_sample_spec_to_mime_type_mimefy(&source->sample_spec, &source->channel_map);
 
         pa_ioline_printf(c->line,
                          "<a href=\"" URL_LISTEN_SOURCE "%s\" title=\"%s\">%s</a><br/>\n",
@@ -666,7 +517,7 @@ static void handle_listen_prefix(struct connection *c, const char *source_name)
     ss = source->sample_spec;
     cm = source->channel_map;
 
-    mimefy_sample_spec(&ss, &cm);
+    pa_sample_spec_mimefy(&ss, &cm);
 
     pa_source_output_new_data_init(&data);
     data.driver = __FILE__;
@@ -706,7 +557,7 @@ static void handle_listen_prefix(struct connection *c, const char *source_name)
 
     pa_source_output_put(c->source_output);
 
-    t = sample_spec_to_mime_type(&ss, &cm);
+    t = pa_sample_spec_to_mime_type(&ss, &cm);
     http_response(c, 200, "OK", t);
     pa_xfree(t);
 

commit c95cc9e55f02ea7cf4e86e40c6d9ee390c112d9f
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Apr 29 23:23:25 2009 +0200

    rygel: add module that interfaces with Rygel UPnP

diff --git a/src/Makefile.am b/src/Makefile.am
index c3c6945..b41ae39 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1060,6 +1060,11 @@ modlibexec_LTLIBRARIES += \
 		module-hal-detect.la
 endif
 
+if HAVE_DBUS
+modlibexec_LTLIBRARIES += \
+		module-rygel-media-server.la
+endif
+
 if HAVE_BLUEZ
 modlibexec_LTLIBRARIES += \
 		libbluetooth-util.la \
@@ -1115,6 +1120,7 @@ SYMDEF_FILES = \
 		modules/module-mmkbd-evdev-symdef.h \
 		modules/module-http-protocol-tcp-symdef.h \
 		modules/module-http-protocol-unix-symdef.h \
+		modules/module-rygel-media-server-symdef.h \
 		modules/x11/module-x11-bell-symdef.h \
 		modules/x11/module-x11-publish-symdef.h \
 		modules/x11/module-x11-xsmp-symdef.h \
@@ -1567,6 +1573,11 @@ module_raop_discover_la_LDFLAGS = $(MODULE_LDFLAGS)
 module_raop_discover_la_LIBADD = $(AM_LIBADD) $(AVAHI_LIBS) libavahi-wrap.la libpulsecore- at PA_MAJORMINORMICRO@.la libpulsecommon- at PA_MAJORMINORMICRO@.la libpulse.la
 module_raop_discover_la_CFLAGS = $(AM_CFLAGS) $(AVAHI_CFLAGS)
 
+# Rygel
+module_rygel_media_server_la_SOURCES = modules/module-rygel-media-server.c
+module_rygel_media_server_la_LDFLAGS = $(MODULE_LDFLAGS)
+module_rygel_media_server_la_LIBADD = $(AM_LIBADD) $(DBUS_LIBS) libpulsecore- at PA_MAJORMINORMICRO@.la libpulsecommon- at PA_MAJORMINORMICRO@.la libpulse.la libprotocol-http.la
+module_rygel_media_server_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
 
 ###################################
 #        Some minor stuff         #
diff --git a/src/modules/module-rygel-media-server.c b/src/modules/module-rygel-media-server.c
new file mode 100644
index 0000000..b851612
--- /dev/null
+++ b/src/modules/module-rygel-media-server.c
@@ -0,0 +1,549 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2005-2009 Lennart Poettering
+
+  PulseAudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License,
+  or (at your option) any later version.
+
+  PulseAudio is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <pulse/xmalloc.h>
+#include <pulse/util.h>
+#include <pulse/i18n.h>
+
+#include <pulsecore/sink.h>
+#include <pulsecore/source.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/log.h>
+#include <pulsecore/modargs.h>
+#include <pulsecore/dbus-shared.h>
+#include <pulsecore/endianmacros.h>
+#include <pulsecore/namereg.h>
+#include <pulsecore/mime-type.h>
+#include <pulsecore/strbuf.h>
+
+#include "module-rygel-media-server-symdef.h"
+
+PA_MODULE_AUTHOR("Lennart Poettering");
+PA_MODULE_DESCRIPTION("UPnP MediaServer Plugin for Rygel");
+PA_MODULE_VERSION(PACKAGE_VERSION);
+PA_MODULE_LOAD_ONCE(TRUE);
+
+/* This implements http://live.gnome.org/action/edit/Rygel/MediaProviderSpec */
+
+#define SERVICE_NAME "org.Rygel.MediaServer1.PulseAudio"
+
+#define OBJECT_ROOT "/org/Rygel/MediaServer1/PulseAudio"
+#define OBJECT_SINKS "/org/Rygel/MediaServer1/PulseAudio/Sinks"
+#define OBJECT_SOURCES "/org/Rygel/MediaServer1/PulseAudio/Sources"
+
+#define CONTAINER_INTROSPECT_XML_PREFIX                                 \
+    DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                           \
+    "<node>"                                                            \
+    " <!-- If you are looking for documentation make sure to check out" \
+    "      http://live.gnome.org/Rygel/MediaProviderSpec -->"           \
+    " <interface name=\"org.Rygel.MediaContainer1\">"                   \
+    "  <method name=\"GetContainers\">"                                 \
+    "   <arg name=\"children\" type=\"ao\" direction=\"out\"/>"         \
+    "  </method>"                                                       \
+    "  <method name=\"GetItems\">"                                      \
+    "   <arg name=\"children\" type=\"ao\" direction=\"out\"/>"         \
+    "  </method>"                                                       \
+    "  <signal name=\"ItemAdded\">"                                     \
+    "   <arg name=\"path\" type=\"o\"/>"                                \
+    "  </signal>"                                                       \
+    "  <signal name=\"ItemRemoved\">"                                   \
+    "   <arg name=\"path\" type=\"o\"/>"                                \
+    "  </signal>"                                                       \
+    "  <signal name=\"ContainerAdded\">"                                \
+    "   <arg name=\"path\" type=\"o\"/>"                                \
+    "  </signal>"                                                       \
+    "  <signal name=\"ContainerRemoved\">"                              \
+    "   <arg name=\"path\" type=\"o\"/>"                                \
+    "  </signal>"                                                       \
+    " </interface>"                                                     \
+    " <interface name=\"org.Rygel.MediaObject1\">"                      \
+    "  <property name=\"display-name\" type=\"s\" access=\"read\"/>"    \
+    " </interface>"                                                     \
+    " <interface name=\"org.freedesktop.DBus.Properties\">"             \
+    "  <method name=\"Get\">"                                           \
+    "   <arg name=\"interface\" direction=\"in\" type=\"s\"/>"          \
+    "   <arg name=\"property\" direction=\"in\" type=\"s\"/>"           \
+    "   <arg name=\"value\" direction=\"out\" type=\"v\"/>"             \
+    "  </method>"                                                       \
+    " </interface>"                                                     \
+    " <interface name=\"org.freedesktop.DBus.Introspectable\">"         \
+    "  <method name=\"Introspect\">"                                    \
+    "   <arg name=\"data\" type=\"s\" direction=\"out\"/>"              \
+    "  </method>"                                                       \
+    " </interface>"
+
+#define CONTAINER_INTROSPECT_XML_POSTFIX                                \
+    "</node>"
+
+#define ROOT_INTROSPECT_XML                                             \
+    CONTAINER_INTROSPECT_XML_PREFIX                                     \
+    "<node name=\"Sinks\"/>"                                            \
+    "<node name=\"Sources\"/>"                                          \
+    CONTAINER_INTROSPECT_XML_POSTFIX
+
+#define ITEM_INTROSPECT_XML                                             \
+    DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                           \
+    "<node>"                                                            \
+    " <!-- If you are looking for documentation make sure to check out" \
+    "      http://live.gnome.org/Rygel/MediaProviderSpec -->"           \
+    " <interface name=\"org.Rygel.MediaItem1\">"                        \
+    "  <property name=\"urls\" type=\"as\" access=\"read\"/>"           \
+    "  <property name=\"mime-type\" type=\"s\" access=\"read\"/>"       \
+    "  <property name=\"type\" type=\"s\" access=\"read\"/>"            \
+    " </interface>"                                                     \
+    " <interface name=\"org.Rygel.MediaObject1\">"                      \
+    "  <property name=\"display-name\" type=\"s\" access=\"read\"/>"    \
+    " </interface>"                                                     \
+    " <interface name=\"org.freedesktop.DBus.Properties\">"             \
+    "  <method name=\"Get\">"                                           \
+    "   <arg name=\"interface\" direction=\"in\" type=\"s\"/>"          \
+    "   <arg name=\"property\" direction=\"in\" type=\"s\"/>"           \
+    "   <arg name=\"value\" direction=\"out\" type=\"v\"/>"             \
+    "  </method>"                                                       \
+    " </interface>"                                                     \
+    " <interface name=\"org.freedesktop.DBus.Introspectable\">"         \
+    "  <method name=\"Introspect\">"                                    \
+    "   <arg name=\"data\" type=\"s\" direction=\"out\"/>"              \
+    "  </method>"                                                       \
+    " </interface>"                                                     \
+    "</node>"
+
+
+static const char* const valid_modargs[] = {
+    NULL
+};
+
+struct userdata {
+    pa_core *core;
+    pa_module *module;
+
+    pa_dbus_connection *bus;
+    pa_bool_t got_name:1;
+
+    pa_hook_slot *source_new_slot, *source_unlink_slot;
+};
+
+static void send_signal(struct userdata *u, pa_source *s, const char *name) {
+    DBusMessage *m;
+    char *child;
+    const char *parent;
+
+    pa_assert(u);
+    pa_source_assert_ref(s);
+
+    if (u->core->state == PA_CORE_SHUTDOWN)
+        return;
+
+    if (s->monitor_of) {
+        parent = OBJECT_SINKS;
+        child = pa_sprintf_malloc(OBJECT_SINKS "/%s", s->monitor_of->name);
+    } else {
+        parent = OBJECT_SOURCES;
+        child = pa_sprintf_malloc(OBJECT_SOURCES "/%s", s->name);
+    }
+
+    pa_assert_se(m = dbus_message_new_signal(parent, "org.Rygel.MediaContainer1", name));
+    pa_assert_se(dbus_message_append_args(m, DBUS_TYPE_OBJECT_PATH, &child, DBUS_TYPE_INVALID));
+    pa_assert_se(dbus_connection_send(pa_dbus_connection_get(u->bus), m, NULL));
+
+    pa_xfree(child);
+
+    dbus_message_unref(m);
+}
+
+static pa_hook_result_t source_new_cb(pa_core *c, pa_source *s, struct userdata *u) {
+    pa_assert(c);
+    pa_source_assert_ref(s);
+
+    send_signal(u, s, "ItemAdded");
+
+    return PA_HOOK_OK;
+}
+
+
+static pa_hook_result_t source_unlink_cb(pa_core *c, pa_source *s, struct userdata *u) {
+    pa_assert(c);
+    pa_source_assert_ref(s);
+
+    send_signal(u, s, "ItemRemoved");
+
+    return PA_HOOK_OK;
+}
+
+static pa_bool_t message_is_property_get(DBusMessage *m, const char *interface, const char *property) {
+    char *i, *p;
+    DBusError error;
+
+    dbus_error_init(&error);
+
+    pa_assert(m);
+
+    if (!dbus_message_is_method_call(m, "org.freedesktop.DBus.Properties", "Get"))
+        return FALSE;
+
+    if (!dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &i, DBUS_TYPE_STRING, &p, DBUS_TYPE_INVALID) || dbus_error_is_set(&error)) {
+        dbus_error_free(&error);
+        return FALSE;
+    }
+
+    return pa_streq(i, interface) && pa_streq(p, property);
+}
+
+static void append_variant_string(DBusMessage *m, const char *s) {
+    DBusMessageIter iter, sub;
+
+    pa_assert(m);
+    pa_assert(s);
+
+    dbus_message_iter_init_append(m, &iter);
+    pa_assert_se(dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, "s", &sub));
+    pa_assert_se(dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &s));
+    pa_assert_se(dbus_message_iter_close_container(&iter, &sub));
+}
+
+static DBusHandlerResult root_handler(DBusConnection *c, DBusMessage *m, void *userdata) {
+    struct userdata *u = userdata;
+    DBusMessage *r = NULL;
+
+    pa_assert(u);
+
+    if (dbus_message_is_method_call(m, "org.Rygel.MediaContainer1", "GetContainers")) {
+        const char * array[] = { OBJECT_SINKS, OBJECT_SOURCES };
+        const char ** parray = array;
+
+        pa_assert_se(r = dbus_message_new_method_return(m));
+        pa_assert_se(dbus_message_append_args(
+                             r,
+                             DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &parray, 2,
+                             DBUS_TYPE_INVALID));
+
+    } else if (dbus_message_is_method_call(m, "org.Rygel.MediaContainer1", "GetItems")) {
+        const char * array[] = { };
+        const char **  parray = array;
+
+        pa_assert_se(r = dbus_message_new_method_return(m));
+        pa_assert_se(dbus_message_append_args(
+                             r,
+                             DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &parray, 0,
+                             DBUS_TYPE_INVALID));
+
+    } else if (message_is_property_get(m, "org.Rygel.MediaObject1", "display-name")) {
+        pa_assert_se(r = dbus_message_new_method_return(m));
+        append_variant_string(r, "PulseAudio");
+    } else if (dbus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect")) {
+        const char *xml = ROOT_INTROSPECT_XML;
+
+        pa_assert_se(r = dbus_message_new_method_return(m));
+        pa_assert_se(dbus_message_append_args(
+                             r,
+                             DBUS_TYPE_STRING, &xml,
+                             DBUS_TYPE_INVALID));
+
+    } else
+        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+    if (r) {
+        pa_assert_se(dbus_connection_send(pa_dbus_connection_get(u->bus), r, NULL));
+        dbus_message_unref(r);
+    }
+
+    return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusHandlerResult sinks_and_sources_handler(DBusConnection *c, DBusMessage *m, void *userdata) {
+    struct userdata *u = userdata;
+    DBusMessage *r = NULL;
+    const char *path;
+
+    pa_assert(u);
+
+    path = dbus_message_get_path(m);
+
+    if (pa_streq(path, OBJECT_SINKS) || pa_streq(path, OBJECT_SOURCES)) {
+
+        /* Container nodes */
+
+        if (dbus_message_is_method_call(m, "org.Rygel.MediaContainer1", "GetContainers")) {
+
+            const char * array[] = { };
+            const char ** parray = array;
+
+            pa_assert_se(r = dbus_message_new_method_return(m));
+            pa_assert_se(dbus_message_append_args(
+                                 r,
+                                 DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &parray, 0,
+                                 DBUS_TYPE_INVALID));
+
+        } else if (dbus_message_is_method_call(m, "org.Rygel.MediaContainer1", "GetItems")) {
+            unsigned n, i = 0;
+            char ** array;
+            uint32_t idx;
+
+            if (pa_streq(path, OBJECT_SINKS))
+                n = pa_idxset_size(u->core->sinks);
+            else
+                n = pa_idxset_size(u->core->sources);
+
+            array = pa_xnew(char*, n);
+
+            if (pa_streq(path, OBJECT_SINKS)) {
+                pa_sink *sink;
+
+                PA_IDXSET_FOREACH(sink, u->core->sinks, idx)
+                    array[i++] = pa_sprintf_malloc(OBJECT_SINKS "/%u", sink->index);
+            } else {
+                pa_source *source;
+
+                PA_IDXSET_FOREACH(source, u->core->sources, idx)
+                    if (!source->monitor_of)
+                        array[i++] = pa_sprintf_malloc(OBJECT_SOURCES "/%u", source->index);
+            }
+
+            pa_assert(i <= n);
+
+            pa_assert_se(r = dbus_message_new_method_return(m));
+            pa_assert_se(dbus_message_append_args(
+                                 r,
+                                 DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &array, i,
+                                 DBUS_TYPE_INVALID));
+
+            for (; i >= 1; i--)
+                pa_xfree(array[i-1]);
+
+            pa_xfree(array);
+
+        } else if (message_is_property_get(m, "org.Rygel.MediaObject1", "display-name")) {
+
+            if (pa_streq(path, OBJECT_SINKS)) {
+                pa_assert_se(r = dbus_message_new_method_return(m));
+                append_variant_string(r, _("Output Devices"));
+            } else {
+                pa_assert_se(r = dbus_message_new_method_return(m));
+                append_variant_string(r, _("Input Devices"));
+            }
+
+        } else if (dbus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect")) {
+            pa_strbuf *sb;
+            char *xml;
+            uint32_t idx;
+
+            sb = pa_strbuf_new();
+            pa_strbuf_puts(sb, CONTAINER_INTROSPECT_XML_PREFIX);
+
+            if (pa_streq(path, OBJECT_SINKS)) {
+                pa_sink *sink;
+
+                PA_IDXSET_FOREACH(sink, u->core->sinks, idx)
+                    pa_strbuf_printf(sb, "<node name=\"%u\"/>", sink->index);
+            } else {
+                pa_source *source;
+
+                PA_IDXSET_FOREACH(source, u->core->sources, idx)
+                    if (!source->monitor_of)
+                        pa_strbuf_printf(sb, "<node name=\"%u\"/>", source->index);
+            }
+
+            pa_strbuf_puts(sb, CONTAINER_INTROSPECT_XML_POSTFIX);
+            xml = pa_strbuf_tostring_free(sb);
+
+            pa_assert_se(r = dbus_message_new_method_return(m));
+            pa_assert_se(dbus_message_append_args(
+                                 r,
+                                 DBUS_TYPE_STRING, &xml,
+                                 DBUS_TYPE_INVALID));
+
+            pa_xfree(xml);
+        }
+
+    } else {
+        pa_sink *sink = NULL;
+        pa_source *source = NULL;
+
+        /* Child nodes */
+
+        if (pa_startswith(path, OBJECT_SINKS "/"))
+            sink = pa_namereg_get(u->core, path + sizeof(OBJECT_SINKS), PA_NAMEREG_SINK);
+        else if (pa_startswith(path, OBJECT_SOURCES "/"))
+            source = pa_namereg_get(u->core, path + sizeof(OBJECT_SOURCES), PA_NAMEREG_SOURCE);
+
+        if (!sink && !source)
+            return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+        if (message_is_property_get(m, "org.Rygel.MediaObject1", "display-name")) {
+            pa_assert_se(r = dbus_message_new_method_return(m));
+            append_variant_string(r, pa_strna(pa_proplist_gets(sink ? sink->proplist : source->proplist, PA_PROP_DEVICE_DESCRIPTION)));
+
+        } else if (message_is_property_get(m, "org.Rygel.MediaItem1", "type")) {
+            pa_assert_se(r = dbus_message_new_method_return(m));
+            append_variant_string(r, "audio");
+
+        } else if (message_is_property_get(m, "org.Rygel.MediaItem1", "mime-type")) {
+            char *t;
+
+            if (sink)
+                t = pa_sample_spec_to_mime_type_mimefy(&sink->sample_spec, &sink->channel_map);
+            else
+                t = pa_sample_spec_to_mime_type_mimefy(&source->sample_spec, &source->channel_map);
+
+            pa_assert_se(r = dbus_message_new_method_return(m));
+            append_variant_string(r, t);
+
+        } else if (message_is_property_get(m, "org.Rygel.MediaItem1", "urls")) {
+            char * array[1];
+            char ** parray = array;
+
+            pa_assert_se(r = dbus_message_new_method_return(m));
+
+            array[0] = pa_sprintf_malloc("http://@ADDRESS@:4714/listen/source/%s",
+                                         sink ? sink->monitor_source->name : source->name);
+
+            pa_assert_se(dbus_message_append_args(
+                                 r,
+                                 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &parray, 1,
+                                 DBUS_TYPE_INVALID));
+
+            pa_xfree(array[0]);
+
+        } else if (dbus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect")) {
+            const char *xml =
+                ITEM_INTROSPECT_XML;
+
+            pa_assert_se(r = dbus_message_new_method_return(m));
+            pa_assert_se(dbus_message_append_args(
+                                 r,
+                                 DBUS_TYPE_STRING, &xml,
+                                 DBUS_TYPE_INVALID));
+
+        } else
+            return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+    }
+
+    if (r) {
+        pa_assert_se(dbus_connection_send(pa_dbus_connection_get(u->bus), r, NULL));
+        dbus_message_unref(r);
+    }
+
+    return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+int pa__init(pa_module *m) {
+
+    struct userdata *u;
+    pa_modargs *ma = NULL;
+    DBusError error;
+    static const DBusObjectPathVTable vtable_root = {
+        .message_function = root_handler,
+    };
+    static const DBusObjectPathVTable vtable_sinks_and_sources = {
+        .message_function = sinks_and_sources_handler,
+    };
+
+    dbus_error_init(&error);
+
+    if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
+        pa_log("Failed to parse module arguments.");
+        goto fail;
+    }
+
+    m->userdata = u = pa_xnew0(struct userdata, 1);
+    u->core = m->core;
+    u->module = m;
+
+    u->source_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_LATE, (pa_hook_cb_t) source_new_cb, u);
+    u->source_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) source_unlink_cb, u);
+
+    if (!(u->bus = pa_dbus_bus_get(m->core, DBUS_BUS_SESSION, &error))) {
+        pa_log("Failed to get session bus connection: %s", error.message);
+        goto fail;
+    }
+
+    pa_assert_se(dbus_connection_register_object_path(pa_dbus_connection_get(u->bus), OBJECT_ROOT, &vtable_root, u));
+    pa_assert_se(dbus_connection_register_fallback(pa_dbus_connection_get(u->bus), OBJECT_SINKS, &vtable_sinks_and_sources, u));
+    pa_assert_se(dbus_connection_register_fallback(pa_dbus_connection_get(u->bus), OBJECT_SOURCES, &vtable_sinks_and_sources, u));
+
+    if (dbus_bus_request_name(pa_dbus_connection_get(u->bus), SERVICE_NAME, DBUS_NAME_FLAG_DO_NOT_QUEUE, &error) != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+        pa_log("Failed to request service name " SERVICE_NAME ": %s", error.message);
+        goto fail;
+    }
+
+    u->got_name = TRUE;
+
+    pa_modargs_free(ma);
+
+    return 0;
+
+fail:
+    pa__done(m);
+
+    if (ma)
+        pa_modargs_free(ma);
+
+    dbus_error_free(&error);
+
+    return -1;
+}
+
+void pa__done(pa_module*m) {
+    struct userdata*u;
+    pa_assert(m);
+
+    if (!(u = m->userdata))
+        return;
+
+    if (u->source_new_slot)
+        pa_hook_slot_free(u->source_new_slot);
+    if (u->source_unlink_slot)
+        pa_hook_slot_free(u->source_unlink_slot);
+
+    if (u->bus) {
+        DBusError error;
+
+        dbus_error_init(&error);
+
+        dbus_connection_unregister_object_path(pa_dbus_connection_get(u->bus), OBJECT_ROOT);
+        dbus_connection_unregister_object_path(pa_dbus_connection_get(u->bus), OBJECT_SINKS);
+        dbus_connection_unregister_object_path(pa_dbus_connection_get(u->bus), OBJECT_SOURCES);
+
+        if (u->got_name) {
+            if (dbus_bus_release_name(pa_dbus_connection_get(u->bus), SERVICE_NAME, &error) != DBUS_RELEASE_NAME_REPLY_RELEASED) {
+                pa_log("Failed to release service name " SERVICE_NAME ": %s", error.message);
+                dbus_error_free(&error);
+            }
+        }
+
+        pa_dbus_connection_unref(u->bus);
+    }
+
+    pa_xfree(u);
+}

-- 
hooks/post-receive
PulseAudio Sound Server



More information about the pulseaudio-commits mailing list