diff options
author | Mike Brady <mikebrady@eircom.net> | 2018-03-10 17:01:42 +0000 |
---|---|---|
committer | Mike Brady <mikebrady@eircom.net> | 2018-03-10 17:01:42 +0000 |
commit | 9d9b0a1824d15b5c5695783c7e26bf71b687a415 (patch) | |
tree | db28782a354436dc9d9e813139db0b89f4cb69d9 | |
parent | 39f159bf9ea6a07c9e60837802c2c71e3263f263 (diff) |
Add a Shairport Sync Diagnostics DBus Onject, only part working
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile.am | 24 | ||||
-rw-r--r-- | common.c | 8 | ||||
-rw-r--r-- | common.h | 2 | ||||
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | dbus-diagnostics.c | 75 | ||||
-rw-r--r-- | dbus-diagnostics.h | 10 | ||||
-rw-r--r-- | dbus-service.c | 16 | ||||
-rw-r--r-- | dbus-service.h | 1 | ||||
-rw-r--r-- | org.gnome.ShairportSync.Diagnostics.xml | 10 | ||||
-rw-r--r-- | rtsp.c | 5 |
11 files changed, 140 insertions, 15 deletions
@@ -33,6 +33,7 @@ shairport-sync.core /dbus-interface.* /mpris-interface.* /mpris-player-interface.* +/dbus-diagnostics-interface.* # Some eclipse project files .cproject diff --git a/Makefile.am b/Makefile.am index 1e98c17..aa34790 100644 --- a/Makefile.am +++ b/Makefile.am @@ -75,6 +75,14 @@ if USE_DNS_SD shairport_sync_SOURCES += mdns_dns_sd.c endif +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 + BUILT_SOURCES = noinst_HEADERS = CLEANFILES = @@ -91,14 +99,20 @@ dbus-interface.h 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_METADATA_HUB -shairport_sync_SOURCES += metadata_hub.c -endif +if USE_DBUS_DIAGNOSTICS +shairport_sync_SOURCES += dbus-diagnostics.c dbus-diagnostics-interface.c +BUILT_SOURCES += dbus-diagnostics-interface.h dbus-diagnostics-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) -if USE_DACP_CLIENT -shairport_sync_SOURCES += dacp.c tinyhttp/chunk.c tinyhttp/header.c tinyhttp/http.c +dbus-diagnostics-interface.h dbus-diagnostics-interface.c: org.gnome.ShairportSync.Diagnostics.xml + gdbus-codegen --interface-prefix org.gnome --generate-c-code dbus-diagnostics-interface org.gnome.ShairportSync.Diagnostics.xml endif + + if USE_MPRIS shairport_sync_SOURCES += mpris-service.c mpris-interface.c mpris-player-interface.c BUILT_SOURCES += mpris-interface.h mpris-interface.c mpris-player-interface.h mpris-player-interface.c @@ -976,3 +976,11 @@ uint32_t nctohl(const uint8_t *p) { // read 4 characters from the p and do ntohl memcpy(&holder, p, sizeof(holder)); return ntohl(holder); } + +static pthread_mutex_t barrier_mutex = PTHREAD_MUTEX_INITIALIZER; + +void memory_barrier() { + pthread_mutex_lock(&barrier_mutex); + pthread_mutex_unlock(&barrier_mutex); +} + @@ -178,6 +178,8 @@ typedef struct { } shairport_cfg; uint32_t nctohl(const uint8_t *p); // read 4 characters from the p and do ntohl on them +void memory_barrier(); + // true if Shairport Sync is supposed to be sending output to the output device, false otherwise diff --git a/configure.ac b/configure.ac index c033ade..6bef971 100644 --- a/configure.ac +++ b/configure.ac @@ -279,9 +279,12 @@ AC_ARG_WITH(dbus, [ --with-dbus-interface = include support for a native Shairp AC_MSG_RESULT(>>Including dbus support) HAS_DBUS=1 AC_DEFINE([HAVE_DBUS], 1, [Needed by the compiler.]) + AC_DEFINE([HAVE_DBUS_DIAGNOSTICS], 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 messaging support requires the glib 2.0 library -- libglib2.0-dev suggested!)]) ], ) AM_CONDITIONAL([USE_DBUS], [test "x$HAS_DBUS" = "x1"]) +# Automatically include the diagnostics interface +AM_CONDITIONAL([USE_DBUS_DIAGNOSTICS], [test "x$HAS_DBUS" = "x1"]) # Look for dbus test client flag AC_ARG_WITH(dbus-test-client, [ --with-dbus-test-client = compile dbus test client], [ diff --git a/dbus-diagnostics.c b/dbus-diagnostics.c new file mode 100644 index 0000000..8a1cbc1 --- /dev/null +++ b/dbus-diagnostics.c @@ -0,0 +1,75 @@ +#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 "metadata_hub.h" + +#include "dbus-diagnostics.h" +#include "dbus-diagnostics-interface.h" + +ShairportSyncDiagnostics *shairportSyncDiagnosticsSkeleton; + +gboolean notify_include_statistics_in_log_callback(ShairportSyncDiagnostics *skeleton, + __attribute__((unused)) gpointer user_data) { + debug(1, "\"notify_include_statistics_in_log_callback\" called."); + if (shairport_sync_diagnostics_get_include_statistics_in_log(skeleton)) { + debug(1, ">> start logging statistics"); + config.statistics_requested = 1; + } else { + debug(1, ">> stop logging statistics"); + config.statistics_requested = 0; + } + return TRUE; +} + +gboolean notify_log_verbosity_callback(ShairportSyncDiagnostics *skeleton, + __attribute__((unused)) gpointer user_data) { + gint th = shairport_sync_diagnostics_get_log_verbosity(skeleton); + if ((th >= 0) && (th <= 3)) { + debug(1, "Setting log verbosity to %d.", th); + debuglev = th; + } else { + debug(1, "Invalid log verbosity: %d. Ignored.", th); + } + return TRUE; +} + +void dbus_diagnostics_on_dbus_name_acquired(GDBusConnection *connection, + __attribute__((unused)) const gchar *name, + __attribute__((unused)) gpointer user_data) { + debug(1,"dbus_diagnostics_on_dbus_name_acquired"); + shairportSyncDiagnosticsSkeleton = shairport_sync_diagnostics_skeleton_new(); + g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(shairportSyncDiagnosticsSkeleton), connection, + "/org/gnome/ShairportSync/Diagnostics", NULL); + + shairport_sync_diagnostics_set_log_verbosity(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), + debuglev); + + debug(1,"Log verbosity is %d.",debuglev); + + if (config.statistics_requested == 0) { + shairport_sync_diagnostics_set_include_statistics_in_log(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), FALSE); + debug(1, "Statistics Logging is off"); + } else { + shairport_sync_diagnostics_set_include_statistics_in_log(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), TRUE); + debug(1, "Statistics Logging is on"); + } + + g_signal_connect(shairportSyncDiagnosticsSkeleton, "notify::log-verbosity", + G_CALLBACK(notify_log_verbosity_callback), NULL); + + + g_signal_connect(shairportSyncDiagnosticsSkeleton, "notify::include-statistics-in-log", + G_CALLBACK(notify_include_statistics_in_log_callback), NULL); + + +} + diff --git a/dbus-diagnostics.h b/dbus-diagnostics.h new file mode 100644 index 0000000..acfa879 --- /dev/null +++ b/dbus-diagnostics.h @@ -0,0 +1,10 @@ + +#ifndef DBUS_DIAGNOSTICS_H +#define DBUS_DIAGNOSTICS_H + +#include "dbus-diagnostics-interface.h" +ShairportSyncDiagnostics *shairportSyncDiagnosticsSkeleton; + +void dbus_diagnostics_on_dbus_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data); + +#endif /* #ifndef DBUS_SERVICE_H */ diff --git a/dbus-service.c b/dbus-service.c index 753d621..d6fb011 100644 --- a/dbus-service.c +++ b/dbus-service.c @@ -10,9 +10,14 @@ #include "rtp.h" #include "dacp.h" +#include "metadata_hub.h" #include "dbus-service.h" -#include "metadata_hub.h" + +#ifdef HAVE_DBUS_DIAGNOSTICS + #include "dbus-diagnostics.h" +#endif + void dbus_metadata_watcher(struct metadata_bundle *argc, __attribute__((unused)) void *userdata) { // debug(1, "DBUS metadata watcher called"); @@ -62,8 +67,7 @@ static gboolean on_handle_remote_command(ShairportSync *skeleton, GDBusMethodInv return TRUE; } -static void on_dbus_name_acquired(GDBusConnection *connection, const gchar *name, - __attribute__((unused)) gpointer user_data) { +static void on_dbus_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { // debug(1, "Shairport Sync native D-Bus interface \"%s\" acquired on the %s bus.", name, // (config.dbus_service_bus_type == DBT_session) ? "session" : "system"); @@ -94,6 +98,10 @@ static void on_dbus_name_acquired(GDBusConnection *connection, const gchar *name NULL); add_metadata_watcher(dbus_metadata_watcher, NULL); + +#ifdef HAVE_DBUS_DIAGNOSTICS + dbus_diagnostics_on_dbus_name_acquired(connection,name,user_data); +#endif debug(1, "Shairport Sync native D-Bus service started at \"%s\" on the %s bus.", name, (config.dbus_service_bus_type == DBT_session) ? "session" : "system"); @@ -126,7 +134,7 @@ static void on_dbus_name_lost(__attribute__((unused)) GDBusConnection *connectio } int start_dbus_service() { - shairportSyncSkeleton = NULL; +// shairportSyncSkeleton = NULL; GBusType dbus_bus_type = G_BUS_TYPE_SYSTEM; if (config.dbus_service_bus_type == DBT_session) dbus_bus_type = G_BUS_TYPE_SESSION; diff --git a/dbus-service.h b/dbus-service.h index f4db1ae..ea6e976 100644 --- a/dbus-service.h +++ b/dbus-service.h @@ -3,7 +3,6 @@ #define DBUS_SERVICE_H #include "dbus-interface.h" - ShairportSync *shairportSyncSkeleton; int start_dbus_service(); diff --git a/org.gnome.ShairportSync.Diagnostics.xml b/org.gnome.ShairportSync.Diagnostics.xml new file mode 100644 index 0000000..4a85b6e --- /dev/null +++ b/org.gnome.ShairportSync.Diagnostics.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd"> + <interface name="org.gnome.ShairportSync.Diagnostics"> + <property name="LogVerbosity" type="i" access="readwrite" /> + <property name="IncludeStatisticsInLog" type="b" access="readwrite" /> + <property name="IncludeElapsedTimeInLog" type="b" access="readwrite" /> + <property name="IncludeDeltaTimeInLog" type="b" access="readwrite" /> + <property name="DisableResendRequests" type="b" access="readwrite" /> + </interface> +</node> @@ -85,7 +85,6 @@ enum rtsp_read_request_response { }; // Mike Brady's part... -static pthread_mutex_t barrier_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t play_lock = PTHREAD_MUTEX_INITIALIZER; // every time we want to retain or release a reference count, lock it with this @@ -102,10 +101,6 @@ static rtsp_conn_info **conns = NULL; int RTSP_connection_index = 0; -void memory_barrier() { - pthread_mutex_lock(&barrier_mutex); - pthread_mutex_unlock(&barrier_mutex); -} #ifdef CONFIG_METADATA typedef struct { |