From 065eada6b54f479511025b21cefef881b87ede76 Mon Sep 17 00:00:00 2001 From: Mike Brady Date: Tue, 9 Jan 2018 15:56:06 +0000 Subject: [PATCH] Separate out metadata hub, dacp client, mpris and dbus interfaces a bit. Probably not finished. --- Makefile.am | 8 ++++++-- configure.ac | 22 +++++++++++++++++----- mdns_avahi.c | 6 +++--- metadata_hub.h | 7 ++++++- player.c | 13 +++++++++---- shairport.c | 10 +++++++--- 6 files changed, 48 insertions(+), 18 deletions(-) diff --git a/Makefile.am b/Makefile.am index 9c445486..4d774433 100644 --- a/Makefile.am +++ b/Makefile.am @@ -87,8 +87,12 @@ dbus-interface.c: org.gnome.ShairportSync.xml gdbus-codegen --interface-prefix org.gnome --generate-c-code dbus-interface org.gnome.ShairportSync.xml endif -if USE_DBUS_CORE_AND_DACP -shairport_sync_SOURCES += dacp.c metadata_hub.c tinyhttp/chunk.c tinyhttp/header.c tinyhttp/http.c +if USE_METADATA_HUB +shairport_sync_SOURCES += metadata_hub.c +endif + +if USE_DACP_CLIENT +shairport_sync_SOURCES += dacp.c tinyhttp/chunk.c tinyhttp/header.c tinyhttp/http.c endif if USE_MPRIS diff --git a/configure.ac b/configure.ac index fc42407d..beea4985 100644 --- a/configure.ac +++ b/configure.ac @@ -266,7 +266,7 @@ AC_ARG_WITH(dns_sd, [ --with-dns_sd = choose dns_sd mDNS support], [ AM_CONDITIONAL([USE_DNS_SD], [test "x$HAS_DNS_SD" = "x1"]) # Look for dbus flag -AC_ARG_WITH(dbus, [ --with-dbus = choose dbus support], [ +AC_ARG_WITH(dbus, [ --with-dbus-interface = include support for a native Shairport Sync D-Bus interface], [ AC_MSG_RESULT(>>Including dbus support) HAS_DBUS=1 AC_DEFINE([HAVE_DBUS], 1, [Needed by the compiler.]) @@ -279,14 +279,14 @@ AC_ARG_WITH(dbus-test-client, [ --with-dbus-test-client = compile dbus test cli AC_MSG_RESULT(>>Including dbus test client) HAS_DBUS_CLIENT=1 AC_DEFINE([HAVE_DBUS_CLIENT], 1, [Needed by the compiler.]) - AC_DEFINE([CONFIG_DACP], 1, [Needed by the compiler.]) +# AC_DEFINE([CONFIG_DACP], 1, [Needed by the compiler.]) PKG_CHECK_MODULES([GIO_UNIX], [gio-unix-2.0 >= 2.30.0],[CFLAGS="${GIO_UNIX_CFLAGS} ${CFLAGS}" LIBS="${GIO_UNIX_LIBS} ${LIBS}"],[AC_MSG_ERROR(dbus client support requires the glib 2.0 library -- libglib2.0-dev suggested!)]) ], ) AM_CONDITIONAL([USE_DBUS_CLIENT], [test "x$HAS_DBUS_CLIENT" = "x1"]) # Look for mpris flag -AC_ARG_WITH(mpris, [ --with-mpris = choose mpris support], [ - AC_MSG_RESULT(>>Including mpris support) +AC_ARG_WITH(mpris, [ --with-mpris-interface = include support for a Shairport Sync D-Bus interface conforming to the MPRIS standard], [ + AC_MSG_RESULT(>>Including the MPRIS D-Bus Interface) HAS_MPRIS=1 AC_DEFINE([HAVE_MPRIS], 1, [Needed by the compiler.]) AC_DEFINE([CONFIG_DACP], 1, [Needed by the compiler.]) @@ -303,7 +303,19 @@ AC_ARG_WITH(mpris-test-client, [ --with-mpris-test-client = compile mpris test ], ) AM_CONDITIONAL([USE_MPRIS_CLIENT], [test "x$HAS_MPRIS_CLIENT" = "x1"]) -AM_CONDITIONAL([USE_DBUS_CORE_AND_DACP], [test "x$HAS_MPRIS" = "x1" -o "x$HAS_DBUS" = "x1"]) +#AM_CONDITIONAL([USE_DBUS_CORE_AND_DACP], [test "x$HAS_MPRIS" = "x1" -o "x$HAS_DBUS" = "x1"]) + +if test "x$HAS_MPRIS" = "x1" -o "x$HAS_DBUS" = "x1" ; then + AC_MSG_RESULT(>>Including the metadata hub) + HAS_METADATA_HUB=1 + AC_DEFINE([HAVE_METADATA_HUB], 1, [Needed by the compiler.]) + AC_MSG_RESULT(>>Including the DACP client) + HAS_DACP_CLIENT=1 + AC_DEFINE([HAVE_DACP_CLIENT], 1, [Needed by the compiler.]) +fi +AM_CONDITIONAL([USE_METADATA_HUB], [test "x$HAS_METADATA_HUB" = "x1"]) +AM_CONDITIONAL([USE_DACP_CLIENT], [test "x$HAS_DACP_CLIENT" = "x1"]) + if test "x${with_systemd}" = xyes ; then # Find systemd unit dir diff --git a/mdns_avahi.c b/mdns_avahi.c index d3927059..786163b0 100644 --- a/mdns_avahi.c +++ b/mdns_avahi.c @@ -33,7 +33,7 @@ #include "common.h" #include "mdns.h" #include "rtsp.h" -#ifdef CONFIG_DACP +#ifdef HAVE_DACP_CLIENT #include "dacp.h" #endif #include @@ -89,7 +89,7 @@ static void resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIn if (conn->dacp_port != port) { debug(1, "Client's DACP port: %u.", port); conn->dacp_port = port; -#if defined(HAVE_DBUS) || defined(HAVE_MPRIS) +#ifdef HAVE_DACP_CLIENT set_dacp_server_information(conn); #endif #ifdef CONFIG_METADATA @@ -141,7 +141,7 @@ static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, Avah if (conn->dacp_id != 0) { debug(1, "Client's DACP status withdrawn."); conn->dacp_port = 0; -#if defined(HAVE_DBUS) || defined(HAVE_MPRIS) +#ifdef HAVE_DACP_CLIENT set_dacp_server_information(conn); // this will have the effect of telling the scanner // that the DACP server is no longer working #endif diff --git a/metadata_hub.h b/metadata_hub.h index cb116f05..7ce9ed48 100644 --- a/metadata_hub.h +++ b/metadata_hub.h @@ -58,7 +58,12 @@ typedef struct metadata_bundle { unsigned char item_composite_id[16]; // seems to be nowplaying 4 ids: dbid, plid, playlistItem, itemid - + + // + + enum play_status_type player_state; // this is the state of the actual player itself, which can be a bit noisy. + + metadata_watcher watchers[number_of_watchers]; // functions to call if the metadata is changed. void *watchers_data[number_of_watchers]; // their individual data diff --git a/player.c b/player.c index d3be8577..736fcd07 100644 --- a/player.c +++ b/player.c @@ -68,7 +68,11 @@ #include #endif -#if defined(HAVE_DBUS) || defined(HAVE_MPRIS) +#ifdef HAVE_METADATA_HUB +#include "metadata_hub.h" +#endif + +#ifdef HAVE_DACP_CLIENT #include "dacp.h" #include #endif @@ -817,11 +821,12 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) { // frames...",curframe->timestamp,seq_diff(ab_read, ab_write)); // say we have started playing here -#if defined(HAVE_MPRIS) +#ifdef HAVE_METADATA_HUB if ((conn->play_state != SST_stopped) && (conn->play_state != SST_playing)) { conn->play_state = SST_playing; - debug(1, "MPRIS Playing"); - media_player2_player_set_playback_status(mprisPlayerPlayerSkeleton, "Playing"); + debug(1, "Player State: Playing"); + metadata_store.player_state = PS_PLAYING; +// media_player2_player_set_playback_status(mprisPlayerPlayerSkeleton, "Playing"); } #endif if (reference_timestamp) { // if we have a reference time diff --git a/shairport.c b/shairport.c index ed3623c9..ecabd075 100644 --- a/shairport.c +++ b/shairport.c @@ -58,8 +58,12 @@ #include #endif -#if defined(HAVE_DBUS) || defined(HAVE_MPRIS) +#if defined(HAVE_DACP_CLIENT) #include "dacp.h" +#endif + + +#if defined(HAVE_METADATA_HUB) #include "metadata_hub.h" #endif @@ -1541,12 +1545,12 @@ int main(int argc, char **argv) { metadata_init(); // create the metadata pipe if necessary #endif -#if defined(HAVE_DBUS) || defined(HAVE_MPRIS) +#ifdef HAVE_METADATA_HUB debug(1, "Initialising metadata hub"); metadata_hub_init(); #endif -#if defined(HAVE_DBUS) || defined(HAVE_MPRIS) +#ifdef HAVE_DACP_CLIENT debug(1, "Requesting DACP Monitor"); dacp_monitor_start(); #endif