]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
dbus-related files taken from directories and renamed
authorMike Brady <mikebrady@eircom.net>
Sun, 12 Nov 2017 14:45:29 +0000 (15:45 +0100)
committerMike Brady <mikebrady@eircom.net>
Sun, 12 Nov 2017 14:45:29 +0000 (15:45 +0100)
14 files changed:
.gitignore
Makefile.am
configure.ac
dbus/data/Makefile.am [deleted file]
dbus/sample dbus-send calls [deleted file]
dbus/src/Makefile.am [deleted file]
org.gnome.ShairportSync.service.in [moved from dbus/data/org.gnome.ShairportSync.service.in with 100% similarity]
org.gnome.ShairportSync.xml [moved from dbus/src/org.gnome.ShairportSync.xml with 100% similarity]
player.c
shairport-sync-dbus-policy.conf [moved from dbus/config/system-bus-policy/shairport-sync.conf with 100% similarity]
shairport-sync-dbus-service.c [new file with mode: 0644]
shairport-sync-dbus-service.h [new file with mode: 0644]
shairport-sync-dbus-test-client.c [moved from dbus/src/shairport-sync-dbus-client.c with 100% similarity]
shairport.c

index 6e823f228f5924761b1608a26e1a85112eeb35fd..034064aa0ace7c8f641c5b75602f46222d2efc76 100644 (file)
@@ -1,6 +1,8 @@
 /INSTALL
 /shairport-sync
 /shairport-sync.exe
+/shairport-sync-dbus-test-client
+
 *.o
 /*~
 *.xml~
@@ -26,12 +28,8 @@ scripts/shairport-sync
 shairport-sync.core
 
 #Some dbus files that are automatically generated
-dbus/data/org.gnome.ShairportSync.service
-dbus/src/shairport-sync-dbus-client
-dbus/src/shairport-sync-dbus-interface.c
-dbus/src/shairport-sync-dbus-interface.h
-dbus/src/shairport-sync-dbus-service.c
-dbus/src/shairport-sync-dbus-service.h
+/org.gnome.ShairportSync.service
+/shairport-sync-dbus-interface.*
 
 # Some eclipse project files
 .cproject
index de2e90709c06a6755bf97afb0efc5166f44b16b1..85baebcb43b52615474b806dd610169b15a542bc 100644 (file)
@@ -1,17 +1,9 @@
 SUBDIRS = man
 
-if USE_DBUS
-  SUBDIRS += dbus/src dbus/data
-else
-if USE_DBUS_CLIENT
-  SUBDIRS += dbus/src dbus/data
-endif
-endif
-
 bin_PROGRAMS = shairport-sync
 
 if USE_DBUS_CLIENT
-noinst_PROGRAMS = dbus/src/shairport-sync-dbus-client
+noinst_PROGRAMS = shairport-sync-dbus-test-client
 endif
 
 shairport_sync_SOURCES = shairport.c rtsp.c mdns.c mdns_external.c common.c rtp.c player.c alac.c audio.c loudness.c
@@ -82,7 +74,46 @@ shairport_sync_SOURCES += mdns_dns_sd.c
 endif
 
 if USE_DBUS
-shairport_sync_SOURCES += dbus/src/shairport-sync-dbus-service.c dbus/src/shairport-sync-dbus-interface.c dacp.c
+shairport_sync_SOURCES += shairport-sync-dbus-service.c shairport-sync-dbus-interface.c dacp.c
+endif
+
+if USE_DBUS_CLIENT
+shairport_sync_dbus_test_client_SOURCES = shairport-sync-dbus-interface.c shairport-sync-dbus-interface.h shairport-sync-dbus-test-client.c
+endif
+
+if USE_DBUS
+BUILT_SOURCES = shairport-sync-dbus-interface.h shairport-sync-dbus-interface.c org.gnome.ShairportSync.service
+# We don't want to install this header
+noinst_HEADERS = $(BUILT_SOURCES)
+
+# Correctly clean the generated headers, but keep the xml description
+CLEANFILES = $(BUILT_SOURCES)
+#EXTRA_DIST = org.gnome.ShairportSync.xml
+
+#Rule to generate the binding headers
+shairport-sync-dbus-interface.h:  org.gnome.ShairportSync.xml
+       gdbus-codegen --interface-prefix org.gnome --generate-c-code shairport-sync-dbus-interface org.gnome.ShairportSync.xml
+
+shairport-sync-dbus-interface.c:  org.gnome.ShairportSync.xml
+       gdbus-codegen --interface-prefix org.gnome --generate-c-code shairport-sync-dbus-interface org.gnome.ShairportSync.xml
+
+# Dbus service file
+
+interfacesdir = $(DESTDIR)/usr/local/share/dbus-1/interfaces
+interfaces_DATA = org.gnome.ShairportSync.xml
+
+servicedir = $(DESTDIR)/usr/local/share/dbus-1/services
+service_in_files = org.gnome.ShairportSync.service.in
+service_DATA = $(service_in_files:.service.in=.service)
+EXTRA_DIST = $(service_in_files) org.gnome.ShairportSync.xml
+
+# Rule to make the service file with bindir expanded
+$(service_DATA): $(service_in_files) Makefile
+       @sed -e "s|\@bindir\@|$(bindir)|" $? > $@
+
+clean-local:
+       rm -rf $(service_DATA)
+
 endif
 
 install-exec-hook:
@@ -91,7 +122,7 @@ if INSTALL_CONFIG_FILES
        cp scripts/shairport-sync.conf $(DESTDIR)$(sysconfdir)/shairport-sync.conf.sample
        [ -f $(DESTDIR)$(sysconfdir)/shairport-sync.conf ] || cp scripts/shairport-sync.conf $(DESTDIR)$(sysconfdir)/shairport-sync.conf
 if USE_DBUS
-       cp dbus/config/system-bus-policy/shairport-sync.conf $(DESTDIR)$(sysconfdir)/dbus-1/system.d/shairport-sync.conf
+       cp shairport-sync-dbus-policy.conf $(DESTDIR)$(sysconfdir)/dbus-1/system.d/shairport-sync.conf
 endif
 endif
 if INSTALL_SYSTEMV
index 6a4d0c6870bf42ac155552639875fc7c866fb9ca..23959ad379196b15bf28b030ec29b903895fad50 100644 (file)
@@ -334,6 +334,6 @@ AC_FUNC_ERROR_AT_LINE
 AC_FUNC_FORK
 AC_CHECK_FUNCS([atexit clock_gettime gethostname inet_ntoa memchr memmove memset mkfifo pow select socket stpcpy strcasecmp strchr strdup strerror strstr strtol strtoul])
 
-AC_CONFIG_FILES([Makefile man/Makefile dbus/src/Makefile dbus/data/Makefile scripts/shairport-sync.service])
+AC_CONFIG_FILES([Makefile man/Makefile scripts/shairport-sync.service])
 AC_CONFIG_FILES([scripts/shairport-sync],[chmod +x scripts/shairport-sync])
 AC_OUTPUT
diff --git a/dbus/data/Makefile.am b/dbus/data/Makefile.am
deleted file mode 100644 (file)
index 22685d8..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-# Dbus service file
-
-if USE_DBUS
-servicedir = $(DESTDIR)/usr/local/share/dbus-1/services
-service_in_files = org.gnome.ShairportSync.service.in
-service_DATA = $(service_in_files:.service.in=.service)
-EXTRA_DIST = $(service_in_files)
-
-# Rule to make the service file with bindir expanded
-$(service_DATA): $(service_in_files) Makefile
-       @sed -e "s|\@bindir\@|$(bindir)|" $? > $@
-
-clean-local:
-       rm -rf $(service_DATA)
-
-endif
diff --git a/dbus/sample dbus-send calls b/dbus/sample dbus-send calls
deleted file mode 100644 (file)
index 2bbf2de..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#Enable the loudness filter (multiline)
-dbus-send --system --print-reply --dest=org.gnome.ShairportSync /org/gnome/ShairportSync \
-org.freedesktop.DBus.Properties.Set string:"org.gnome.ShairportSync" \
-string:"LoudnessFilterActive" variant:boolean:true
-
-
-
-#Here it is in action:
-mike@ubuntu:~/sps$ dbus-send --system --print-reply --dest=org.gnome.ShairportSync /org/gnome/ShairportSync \
-> org.freedesktop.DBus.Properties.Set string:"org.gnome.ShairportSync" \
-> string:"LoudnessFilterActive" variant:boolean:true
-method return time=1505039217.715753 sender=:1.87 -> destination=:1.91 serial=27 reply_serial=2
-
-#Get the state of LoudnessFilterActive:
-mike@ubuntu:~/sps$ dbus-send --system --print-reply --dest=org.gnome.ShairportSync /org/gnome/ShairportSync org.freedesktop.DBus.Properties.Get string:"org.gnome.ShairportSync" string:"LoudnessFilterActive"
-method return time=1505047038.024401 sender=:1.131 -> destination=:1.144 serial=34 reply_serial=2
-   variant       boolean true
-
-#Set the Loudness Threshold:
-mike@ubuntu:~/sps$ dbus-send --system --print-reply --dest=org.gnome.ShairportSync /org/gnome/ShairportSync org.freedesktop.DBus.Properties.Set string:"org.gnome.ShairportSync" string:"LoudnessThreshold" variant:double:-10.0
-method return time=1505039378.650185 sender=:1.87 -> destination=:1.92 serial=61 reply_serial=2
-
-#Set the Volume:
-mike@ubuntu:~/sps$ dbus-send --system --print-reply --dest=org.gnome.ShairportSync /org/gnome/ShairportSync org.freedesktop.DBus.Properties.Set string:"org.gnome.ShairportSync" string:"Volume" variant:double:-13.5
-method return time=1505039453.757603 sender=:1.87 -> destination=:1.93 serial=73 reply_serial=2
-
-#Get the Volume:
-mike@ubuntu:~/sps$ dbus-send --system --print-reply --dest=org.gnome.ShairportSync /org/gnome/ShairportSync org.freedesktop.DBus.Properties.Get string:"org.gnome.ShairportSync" string:"Volume"
-method return time=1505046937.165751 sender=:1.131 -> destination=:1.141 serial=30 reply_serial=2
-   variant       double -13.5
-
-
diff --git a/dbus/src/Makefile.am b/dbus/src/Makefile.am
deleted file mode 100644 (file)
index b617928..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-if USE_DBUS_CLIENT
-  noinst_PROGRAMS = shairport-sync-dbus-client
-  shairport_sync_dbus_client_SOURCES = shairport-sync-dbus-interface.c shairport-sync-dbus-interface.h shairport-sync-dbus-client.c
-endif
-
-BUILT_SOURCES = shairport-sync-dbus-interface.h shairport-sync-dbus-interface.c
-# We don't want to install this header
-noinst_HEADERS = $(BUILT_SOURCES)
-
-# Correctly clean the generated headers, but keep the xml description
-CLEANFILES = $(BUILT_SOURCES)
-EXTRA_DIST = org.gnome.ShairportSync.xml
-
-#Rule to generate the binding headers
-shairport-sync-dbus-interface.h:  org.gnome.ShairportSync.xml
-       gdbus-codegen --interface-prefix org.gnome --generate-c-code shairport-sync-dbus-interface org.gnome.ShairportSync.xml
-
-shairport-sync-dbus-interface.c:  org.gnome.ShairportSync.xml
-       gdbus-codegen --interface-prefix org.gnome --generate-c-code shairport-sync-dbus-interface org.gnome.ShairportSync.xml
-
-# Dbus service file
-
-if USE_DBUS
-interfacesdir = $(DESTDIR)/usr/local/share/dbus-1/interfaces
-interfaces_DATA = org.gnome.ShairportSync.xml
-endif
index d92a1ecf65f2698eda4c6d523f198ed8469161a3..50241608e24482218f7cf3f58ff4c717d0690f9d 100644 (file)
--- a/player.c
+++ b/player.c
@@ -74,8 +74,8 @@
 
 #ifdef HAVE_DBUS
 #include "dacp.h"
-#include "dbus/src/shairport-sync-dbus-interface.h"
-#include "dbus/src/shairport-sync-dbus-service.h"
+#include "shairport-sync-dbus-interface.h"
+#include "shairport-sync-dbus-service.h"
 #endif
 
 #include "common.h"
diff --git a/shairport-sync-dbus-service.c b/shairport-sync-dbus-service.c
new file mode 100644 (file)
index 0000000..1dbba65
--- /dev/null
@@ -0,0 +1,213 @@
+#include <stdio.h>
+#include <string.h>
+
+#include "config.h"
+
+#include "common.h"
+#include "player.h"
+#include "rtsp.h"
+
+#include "rtp.h"
+
+#include "dacp.h"
+
+#include "shairport-sync-dbus-service.h"
+
+gboolean notify_loudness_filter_active_callback(ShairportSync *skeleton, gpointer user_data) {
+  debug(1, "\"notify_loudness_filter_active_callback\" called.");
+  if (shairport_sync_get_loudness_filter_active(skeleton)) {
+    debug(1, "activating loudness filter");
+    config.loudness = 1;
+  } else {
+    debug(1, "deactivating loudness filter");
+    config.loudness = 0;
+  }
+  return TRUE;
+}
+
+gboolean notify_loudness_threshold_callback(ShairportSync *skeleton, gpointer user_data) {
+  gdouble th = shairport_sync_get_loudness_threshold(skeleton);
+  if ((th <= 0.0) && (th >= -100.0)) {
+    debug(1, "Setting loudness threshhold to %f.", th);
+    config.loudness_reference_volume_db = th;
+  } else {
+    debug(1, "Invalid loudness threshhold: %f. Ignored.", th);
+  }
+  return TRUE;
+}
+
+gboolean notify_volume_callback(ShairportSync *skeleton, gpointer user_data) {
+  gint vo = shairport_sync_get_volume(skeleton);
+  if ((vo >= 0) && (vo <= 100)) {
+    if (playing_conn) {
+      if (vo !=
+          playing_conn
+              ->dacp_volume) { // this is to stop an infinite loop of setting->checking->setting...
+        // debug(1, "Remote-setting volume to %d.", vo);
+        // get the information we need -- the absolute volume, the speaker list, our ID
+        struct dacp_speaker_stuff speaker_info[50];
+        int32_t overall_volume = dacp_get_client_volume(playing_conn);
+        int speaker_count =
+            dacp_get_speaker_list(playing_conn, (dacp_spkr_stuff *)&speaker_info, 50);
+
+        // get our machine number
+        uint16_t *hn = (uint16_t *)config.hw_addr;
+        uint32_t *ln = (uint32_t *)(config.hw_addr + 2);
+        uint64_t t1 = ntohs(*hn);
+        uint64_t t2 = ntohl(*ln);
+        int64_t machine_number = (t1 << 32) + t2; // this form is useful
+
+        // Let's find our own speaker in the array and pick up its relative volume
+        int i;
+        int32_t relative_volume = 0;
+        int32_t active_speakers = 0;
+        for (i = 0; i < speaker_count; i++) {
+          if (speaker_info[i].speaker_number == machine_number) {
+            // debug(1,"Our speaker number found: %ld.",machine_number);
+            relative_volume = speaker_info[i].volume;
+          }
+          if (speaker_info[i].active == 1) {
+            active_speakers++;
+          }
+        }
+
+        if (active_speakers == 1) {
+          // must be just this speaker
+          dacp_set_include_speaker_volume(playing_conn, machine_number, vo);
+        } else if (active_speakers == 0) {
+          debug(1, "No speakers!");
+        } else {
+          // debug(1, "Speakers: %d, active: %d",speaker_count,active_speakers);
+          if (vo >= overall_volume) {
+            // debug(1,"Multiple speakers active, but desired new volume is highest");
+            dacp_set_include_speaker_volume(playing_conn, machine_number, vo);
+          } else {
+            // the desired volume is less than the current overall volume and there is more than one
+            // speaker
+            // we must find out the highest other speaker volume.
+            // If the desired volume is less than it, we must set the current_overall volume to that
+            // highest volume
+            // and set our volume relative to it.
+            // If the desired volume is greater than the highest current volume, then we can just go
+            // ahead
+            // with dacp_set_include_speaker_volume, setting the new current overall volume to the
+            // desired new level
+            // with the speaker at 100%
+
+            int32_t highest_other_volume = 0;
+            for (i = 0; i < speaker_count; i++) {
+              if ((speaker_info[i].speaker_number != machine_number) &&
+                  (speaker_info[i].active == 1) &&
+                  (speaker_info[i].volume > highest_other_volume)) {
+                highest_other_volume = speaker_info[i].volume;
+              }
+            }
+            highest_other_volume = (highest_other_volume * overall_volume + 50) / 100;
+            if (highest_other_volume <= vo) {
+              // debug(1,"Highest other volume %d is less than or equal to the desired new volume
+              // %d.",highest_other_volume,vo);
+              dacp_set_include_speaker_volume(playing_conn, machine_number, vo);
+            } else {
+              // debug(1,"Highest other volume %d is greater than the desired new volume
+              // %d.",highest_other_volume,vo);
+              // if the present overall volume is higher than the highest other volume at present,
+              // then bring it down to it.
+              if (overall_volume > highest_other_volume) {
+                // debug(1,"Lower overall volume to new highest volume.");
+                dacp_set_include_speaker_volume(
+                    playing_conn, machine_number,
+                    highest_other_volume); // set the overall volume to the highest one
+              }
+              int32_t desired_relative_volume =
+                  (vo * 100 + (highest_other_volume / 2)) / highest_other_volume;
+              // debug(1,"Set our speaker volume relative to the highest volume.");
+              dacp_set_speaker_volume(
+                  playing_conn, machine_number,
+                  desired_relative_volume); // set the overall volume to the highest one
+            }
+          }
+        }
+        //     } else {
+        //       debug(1, "No need to remote-set volume to %d, as it is already set to this
+        //       value.",playing_conn->dacp_volume);
+      }
+    } else
+      debug(1, "no thread playing -- ignored.");
+  } else {
+    debug(1, "Invalid volume: %d -- ignored.", vo);
+  }
+  return TRUE;
+}
+
+static gboolean on_handle_remote_command(ShairportSync *skeleton, GDBusMethodInvocation *invocation,
+                                         const gchar *command, gpointer user_data) {
+  debug(1, "RemoteCommand with command \"%s\".", command);
+  if (playing_conn) {
+    char server_reply[2000];
+    ssize_t reply_size =
+        dacp_send_client_command(playing_conn, command, server_reply, sizeof(server_reply));
+    if (reply_size >= 0) {
+      // not interested in the response.
+      //      if (strstr(server_reply, "HTTP/1.1 204") == server_reply) {
+      //        debug(1,"Client response is No Content");
+      //      } else if (strstr(server_reply, "HTTP/1.1 200 OK") != server_reply) {
+      //        debug("Client response is OK, with content");
+      //      } else {
+
+      if (strstr(server_reply, "HTTP/1.1 204") != server_reply) {
+        debug(1,
+              "Client request to server responded with %d characters starting with this response:",
+              strlen(server_reply));
+        int i;
+        for (i = 0; i < reply_size; i++)
+          if (server_reply[i] < ' ')
+            debug(1, "%d  %02x", i, server_reply[i]);
+          else
+            debug(1, "%d  %02x  '%c'", i, server_reply[i], server_reply[i]);
+        // sprintf((char *)message + 2 * i, "%02x", server_reply[i]);
+        // debug(1,"Content is \"%s\".",message);
+      }
+    } else {
+      debug(1, "Error at rtp_send_client_command");
+    }
+  } else {
+    debug(1, "no thread playing -- RemoteCommand ignored.");
+  }
+  shairport_sync_complete_remote_command(skeleton, invocation);
+  return TRUE;
+}
+
+static void on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) {
+
+  skeleton = shairport_sync_skeleton_new();
+
+  g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(skeleton), connection,
+                                   "/org/gnome/ShairportSync", NULL);
+
+  shairport_sync_set_loudness_threshold(SHAIRPORT_SYNC(skeleton),
+                                        config.loudness_reference_volume_db);
+  debug(1, "Loudness threshold is %f.", config.loudness_reference_volume_db);
+
+  if (config.loudness == 0) {
+    shairport_sync_set_loudness_filter_active(SHAIRPORT_SYNC(skeleton), FALSE);
+    debug(1, "Loudness is off");
+  } else {
+    shairport_sync_set_loudness_filter_active(SHAIRPORT_SYNC(skeleton), TRUE);
+    debug(1, "Loudness is on");
+  }
+
+  g_signal_connect(skeleton, "notify::loudness-filter-active",
+                   G_CALLBACK(notify_loudness_filter_active_callback), NULL);
+  g_signal_connect(skeleton, "notify::loudness-threshold",
+                   G_CALLBACK(notify_loudness_threshold_callback), NULL);
+  g_signal_connect(skeleton, "notify::volume", G_CALLBACK(notify_volume_callback), NULL);
+  g_signal_connect(skeleton, "handle-remote-command", G_CALLBACK(on_handle_remote_command), NULL);
+}
+
+int start_dbus_service() {
+  skeleton = NULL;
+  g_bus_own_name(G_BUS_TYPE_SYSTEM, "org.gnome.ShairportSync", G_BUS_NAME_OWNER_FLAGS_NONE, NULL,
+                 on_name_acquired, NULL, NULL, NULL);
+  //  G_BUS_TYPE_SESSION or G_BUS_TYPE_SYSTEM
+  return 0; // this is just to quieten a compiler warning
+}
diff --git a/shairport-sync-dbus-service.h b/shairport-sync-dbus-service.h
new file mode 100644 (file)
index 0000000..d029c7a
--- /dev/null
@@ -0,0 +1,11 @@
+
+#ifndef DBUS_SERVICE_H
+#define DBUS_SERVICE_H
+
+#include "shairport-sync-dbus-interface.h"
+
+ShairportSync *skeleton;
+
+int start_dbus_service();
+
+#endif /* #ifndef DBUS_SERVICE_H */
index acb782dd64d563b51e2fafdcaa6444f633a6e3b1..4f6a9c3095cf59f6b5cbb75ddc3fca091c11bf47 100644 (file)
@@ -59,7 +59,7 @@
 #endif
 
 #ifdef HAVE_DBUS
-#include "dbus/src/shairport-sync-dbus-service.h"
+#include "shairport-sync-dbus-service.h"
 #endif
 
 #include "common.h"