Some spring cleaning using clang-format

This commit is contained in:
Mike Brady
2017-10-05 17:48:24 +01:00
parent 87bf5e87ac
commit d343a851c0
12 changed files with 269 additions and 291 deletions
-2
View File
@@ -400,8 +400,6 @@ static int init(int argc, char **argv) {
debug(1, "Cannot get the dB range from the volume control \"%s\"", alsa_mix_ctrl);
}
/*
debug(1, "Min and max volumes are %d and
%d.",alsa_mix_minv,alsa_mix_maxv);
+25 -23
View File
@@ -9,36 +9,36 @@
#include "dbus_service.h"
void 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");
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");
debug(1, "deactivating loudness filter");
config.loudness = 0;
}
}
void notify_loudness_threshold_callback(ShairportSync *skeleton, gpointer user_data) {
gdouble th = shairport_sync_get_loudness_threshold (skeleton);
gdouble th = shairport_sync_get_loudness_threshold(skeleton);
if ((th <= 0.0) && (th >= -100.0)) {
debug(1,"Setting loudness threshhold to %f.",th);
debug(1, "Setting loudness threshhold to %f.", th);
config.loudness_reference_volume_db = th;
} else {
debug(1,"Invalid loudness threshhold: %f. Ignored.",th);
debug(1, "Invalid loudness threshhold: %f. Ignored.", th);
}
}
void notify_volume_callback(ShairportSync *skeleton, gpointer user_data) {
gdouble vo = shairport_sync_get_volume (skeleton);
gdouble vo = shairport_sync_get_volume(skeleton);
if (((vo <= 0.0) && (vo >= -30.0)) || (vo == -144.0)) {
debug(1,"Setting volume to %f.",vo);
debug(1, "Setting volume to %f.", vo);
if (playing_conn)
player_volume_without_notification(vo,playing_conn);
player_volume_without_notification(vo, playing_conn);
else
debug(1,"no thread playing -- ignored.");
debug(1, "no thread playing -- ignored.");
} else {
debug(1,"Invalid volume: %f -- ignored.",vo);
debug(1, "Invalid volume: %f -- ignored.", vo);
}
}
@@ -48,22 +48,24 @@ static void on_name_acquired(GDBusConnection *connection, const gchar *name, gpo
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_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");
debug(1, "Loudness is off");
} else {
shairport_sync_set_loudness_filter_active(SHAIRPORT_SYNC(skeleton), TRUE);
debug(1,"Loudness is on");
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, "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);
}
int start_dbus_service() {
+41 -53
View File
@@ -5,51 +5,42 @@
GMainLoop *loop;
void on_properties_changed (GDBusProxy *proxy,
GVariant *changed_properties,
const gchar* const *invalidated_properties,
gpointer user_data)
{
void on_properties_changed(GDBusProxy *proxy, GVariant *changed_properties,
const gchar *const *invalidated_properties, gpointer user_data) {
/* Note that we are guaranteed that changed_properties and
* invalidated_properties are never NULL
*/
if (g_variant_n_children (changed_properties) > 0)
{
GVariantIter *iter;
const gchar *key;
GVariant *value;
if (g_variant_n_children(changed_properties) > 0) {
GVariantIter *iter;
const gchar *key;
GVariant *value;
g_print (" *** Properties Changed:\n");
g_variant_get (changed_properties,
"a{sv}",
&iter);
while (g_variant_iter_loop (iter, "{&sv}", &key, &value))
{
gchar *value_str;
value_str = g_variant_print (value, TRUE);
g_print (" %s -> %s\n", key, value_str);
g_free (value_str);
}
g_variant_iter_free (iter);
g_print(" *** Properties Changed:\n");
g_variant_get(changed_properties, "a{sv}", &iter);
while (g_variant_iter_loop(iter, "{&sv}", &key, &value)) {
gchar *value_str;
value_str = g_variant_print(value, TRUE);
g_print(" %s -> %s\n", key, value_str);
g_free(value_str);
}
g_variant_iter_free(iter);
}
if (g_strv_length ((GStrv) invalidated_properties) > 0)
{
guint n;
g_print (" *** Properties Invalidated:\n");
for (n = 0; invalidated_properties[n] != NULL; n++)
{
const gchar *key = invalidated_properties[n];
g_print (" %s\n", key);
}
if (g_strv_length((GStrv)invalidated_properties) > 0) {
guint n;
g_print(" *** Properties Invalidated:\n");
for (n = 0; invalidated_properties[n] != NULL; n++) {
const gchar *key = invalidated_properties[n];
g_print(" %s\n", key);
}
}
}
void notify_loudness_filter_active_callback(ShairportSync *proxy, gpointer user_data) {
// printf("\"notify_loudness_filter_active_callback\" called with a gpointer of %lx.\n",(int64_t)user_data);
gboolean ebl = shairport_sync_get_loudness_filter_active (proxy);
// printf("\"notify_loudness_filter_active_callback\" called with a gpointer of
// %lx.\n",(int64_t)user_data);
gboolean ebl = shairport_sync_get_loudness_filter_active(proxy);
if (ebl == TRUE)
printf("Client reports loudness is enabled.\n");
else
@@ -57,26 +48,25 @@ void notify_loudness_filter_active_callback(ShairportSync *proxy, gpointer user_
}
void notify_loudness_threshold_callback(ShairportSync *proxy, gpointer user_data) {
gdouble th = shairport_sync_get_loudness_threshold (proxy);
printf("Client reports loudness threshold set to %.2f dB.\n",th);
gdouble th = shairport_sync_get_loudness_threshold(proxy);
printf("Client reports loudness threshold set to %.2f dB.\n", th);
}
void notify_volume_callback(ShairportSync *proxy, gpointer user_data) {
gdouble th = shairport_sync_get_volume (proxy);
printf("Client reports volume set to %.2f dB.\n",th);
gdouble th = shairport_sync_get_volume(proxy);
printf("Client reports volume set to %.2f dB.\n", th);
}
pthread_t dbus_thread;
void *dbus_thread_func(void *arg) {
loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(loop);
// dbus_service_main(); // let it run inside a thread
// dbus_service_main(); // let it run inside a thread
}
void main(void) {
pthread_create(&dbus_thread, NULL, &dbus_thread_func, NULL);
@@ -85,21 +75,19 @@ void main(void) {
GError *error = NULL;
proxy = shairport_sync_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
"org.gnome.ShairportSync", "/org/gnome/ShairportSync", NULL, &error);
"org.gnome.ShairportSync",
"/org/gnome/ShairportSync", NULL, &error);
// g_signal_connect(proxy, "notify::loudness-filter-active",
// G_CALLBACK(notify_loudness_filter_active_callback), NULL);
// g_signal_connect(proxy, "notify::loudness-filter-active", G_CALLBACK(notify_loudness_filter_active_callback), NULL);
g_signal_connect (proxy,
"g-properties-changed",
G_CALLBACK (on_properties_changed),
NULL);
g_signal_connect(proxy, "notify::loudness-threshold", G_CALLBACK(notify_loudness_threshold_callback), NULL);
g_signal_connect(proxy, "g-properties-changed", G_CALLBACK(on_properties_changed), NULL);
g_signal_connect(proxy, "notify::loudness-threshold",
G_CALLBACK(notify_loudness_threshold_callback), NULL);
g_signal_connect(proxy, "notify::volume", G_CALLBACK(notify_volume_callback), NULL);
g_print("Starting test...\n");
shairport_sync_set_volume(SHAIRPORT_SYNC(proxy), -20.0);
sleep(10);
shairport_sync_set_volume(SHAIRPORT_SYNC(proxy), -10.0);
@@ -121,8 +109,8 @@ void main(void) {
sleep(15);
g_print("Finished test...\n");
g_main_loop_quit(loop);
pthread_join(dbus_thread,NULL);
pthread_join(dbus_thread, NULL);
printf("exiting program.\n");
g_object_unref(proxy);
}
+6 -6
View File
@@ -104,21 +104,21 @@ void mdns_unregister(void) {
}
}
void mdns_dacp_monitor(char* dacp_id,uint16_t *port,void** private_pointer) {
void mdns_dacp_monitor(char *dacp_id, uint16_t *port, void **private_pointer) {
if ((config.mdns) && (config.mdns->mdns_dacp_monitor)) {
int error = config.mdns->mdns_dacp_monitor(dacp_id,port,private_pointer);
int error = config.mdns->mdns_dacp_monitor(dacp_id, port, private_pointer);
if (error) {
debug(1,"Error starting a DACP monitor.");
debug(1, "Error starting a DACP monitor.");
}
} else
debug(1,"Can't start a DACP monitor.");
debug(1, "Can't start a DACP monitor.");
}
void mdns_dacp_dont_monitor(void** private_pointer) {
void mdns_dacp_dont_monitor(void **private_pointer) {
if ((config.mdns) && (config.mdns->mdns_dacp_dont_monitor)) {
config.mdns->mdns_dacp_dont_monitor(private_pointer);
} else
debug(1,"Can't stop a DACP monitor.");
debug(1, "Can't stop a DACP monitor.");
}
void mdns_ls_backends(void) {
mdns_backend **b = NULL;
+5 -5
View File
@@ -1,15 +1,15 @@
#ifndef _MDNS_H
#define _MDNS_H
#include <stdint.h>
#include "config.h"
#include <stdint.h>
extern int mdns_pid;
void mdns_unregister(void);
void mdns_register(void);
void mdns_dacp_monitor(char* dacp_id,uint16_t *port,void** private_pointer);
void mdns_dacp_dont_monitor(void** private_pointer);
void mdns_dacp_monitor(char *dacp_id, uint16_t *port, void **private_pointer);
void mdns_dacp_dont_monitor(void **private_pointer);
void mdns_ls_backends(void);
@@ -17,8 +17,8 @@ typedef struct {
char *name;
int (*mdns_register)(char *apname, int port);
void (*mdns_unregister)(void);
int (*mdns_dacp_monitor)(char* dacp_id,uint16_t *port,void** private_pointer);
void (*mdns_dacp_dont_monitor)(void** private_pointer);
int (*mdns_dacp_monitor)(char *dacp_id, uint16_t *port, void **private_pointer);
void (*mdns_dacp_dont_monitor)(void **private_pointer);
} mdns_backend;
#ifdef CONFIG_METADATA
+157 -168
View File
@@ -25,8 +25,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <pthread.h>
#include <stdlib.h>
#include "common.h"
#include "mdns.h"
@@ -41,16 +41,15 @@
#include <avahi-client/lookup.h>
#include <avahi-common/alternative.h>
typedef struct {
AvahiThreadedPoll *service_poll;
AvahiClient *service_client;
AvahiServiceBrowser *service_browser;
char *dacp_id;
uint16_t *dacp_port;
AvahiThreadedPoll *service_poll;
AvahiClient *service_client;
AvahiServiceBrowser *service_browser;
char *dacp_id;
uint16_t *dacp_port;
} dacp_browser_struct;
//static AvahiServiceBrowser *sb = NULL;
// static AvahiServiceBrowser *sb = NULL;
static AvahiClient *client = NULL;
// static AvahiClient *service_client = NULL;
static AvahiEntryGroup *group = NULL;
@@ -60,100 +59,89 @@ static AvahiThreadedPoll *tpoll = NULL;
static char *service_name = NULL;
static int port = 0;
static void resolve_callback(
AvahiServiceResolver *r,
AVAHI_GCC_UNUSED AvahiIfIndex interface,
AVAHI_GCC_UNUSED AvahiProtocol protocol,
AvahiResolverEvent event,
const char *name,
const char *type,
const char *domain,
const char *host_name,
const AvahiAddress *address,
uint16_t port,
AvahiStringList *txt,
AvahiLookupResultFlags flags,
void* userdata) {
assert(r);
dacp_browser_struct *dbs = (dacp_browser_struct *)userdata;
/* Called whenever a service has been resolved successfully or timed out */
switch (event) {
case AVAHI_RESOLVER_FAILURE:
debug(1, "(Resolver) Failed to resolve service '%s' of type '%s' in domain '%s': %s.", name, type, domain, avahi_strerror(avahi_client_errno(avahi_service_resolver_get_client(r))));
break;
case AVAHI_RESOLVER_FOUND: {
char a[AVAHI_ADDRESS_STR_MAX], *t;
//debug(1, "Resolve callback: Service '%s' of type '%s' in domain '%s':", name, type, domain);
char* dacpid = strstr(name,"iTunes_Ctrl_");
if (dacpid) {
dacpid+=strlen("iTunes_Ctrl_");
if (strcmp(dacpid,dbs->dacp_id)==0) {
uint16_t *p = dbs->dacp_port;
if (*p != port) {
debug(1,"Client's DACP port: %u.",port);
*p = port;
}
}
} else {
debug(1,"Resolve callback: Can't see a DACP string in a DACP Record!");
}
static void resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interface,
AVAHI_GCC_UNUSED AvahiProtocol protocol, AvahiResolverEvent event,
const char *name, const char *type, const char *domain,
const char *host_name, const AvahiAddress *address, uint16_t port,
AvahiStringList *txt, AvahiLookupResultFlags flags, void *userdata) {
assert(r);
dacp_browser_struct *dbs = (dacp_browser_struct *)userdata;
/* Called whenever a service has been resolved successfully or timed out */
switch (event) {
case AVAHI_RESOLVER_FAILURE:
debug(1, "(Resolver) Failed to resolve service '%s' of type '%s' in domain '%s': %s.", name,
type, domain, avahi_strerror(avahi_client_errno(avahi_service_resolver_get_client(r))));
break;
case AVAHI_RESOLVER_FOUND: {
char a[AVAHI_ADDRESS_STR_MAX], *t;
// debug(1, "Resolve callback: Service '%s' of type '%s' in domain '%s':", name, type, domain);
char *dacpid = strstr(name, "iTunes_Ctrl_");
if (dacpid) {
dacpid += strlen("iTunes_Ctrl_");
if (strcmp(dacpid, dbs->dacp_id) == 0) {
uint16_t *p = dbs->dacp_port;
if (*p != port) {
debug(1, "Client's DACP port: %u.", port);
*p = port;
}
}
} else {
debug(1, "Resolve callback: Can't see a DACP string in a DACP Record!");
}
avahi_service_resolver_free(r);
}
}
avahi_service_resolver_free(r);
}
static void browse_callback(
AvahiServiceBrowser *b,
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiBrowserEvent event,
const char *name,
const char *type,
const char *domain,
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
void* userdata) {
dacp_browser_struct *dbs = (dacp_browser_struct *)userdata;
assert(b);
/* Called whenever a new services becomes available on the LAN or is removed from the LAN */
switch (event) {
case AVAHI_BROWSER_FAILURE:
warn("avahi: browser failure.", avahi_strerror(avahi_client_errno(avahi_service_browser_get_client(b))));
avahi_threaded_poll_quit(tpoll);
break;
case AVAHI_BROWSER_NEW:
// debug(1, "(Browser) NEW: service '%s' of type '%s' in domain '%s'.", name, type, domain);
/* We ignore the returned resolver object. In the callback
function we free it. If the server is terminated before
the callback function is called the server will free
the resolver for us. */
if (!(avahi_service_resolver_new(dbs->service_client, interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, 0, resolve_callback, userdata)))
debug(1, "Failed to resolve service '%s': %s.", name, avahi_strerror(avahi_client_errno(dbs->service_client)));
break;
case AVAHI_BROWSER_REMOVE:
debug(1, "(Browser) REMOVE: service '%s' of type '%s' in domain '%s'.", name, type, domain);
char* dacpid = strstr(name,"iTunes_Ctrl_");
if (dacpid) {
dacpid+=strlen("iTunes_Ctrl_");
if (strcmp(dacpid,dbs->dacp_id)==0) {
uint16_t *p = dbs->dacp_port;
if (*p != 0) {
debug(1,"Client's DACP status withdrawn.");
*p = 0;
}
}
} else {
debug(1,"Browse callback: Can't see a DACP string in a DACP Record!");
}
break;
case AVAHI_BROWSER_ALL_FOR_NOW:
case AVAHI_BROWSER_CACHE_EXHAUSTED:
// debug(1, "(Browser) %s.", event == AVAHI_BROWSER_CACHE_EXHAUSTED ? "CACHE_EXHAUSTED" : "ALL_FOR_NOW");
break;
static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol,
AvahiBrowserEvent event, const char *name, const char *type,
const char *domain, AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
void *userdata) {
dacp_browser_struct *dbs = (dacp_browser_struct *)userdata;
assert(b);
/* Called whenever a new services becomes available on the LAN or is removed from the LAN */
switch (event) {
case AVAHI_BROWSER_FAILURE:
warn("avahi: browser failure.",
avahi_strerror(avahi_client_errno(avahi_service_browser_get_client(b))));
avahi_threaded_poll_quit(tpoll);
break;
case AVAHI_BROWSER_NEW:
// debug(1, "(Browser) NEW: service '%s' of type '%s' in domain '%s'.", name, type, domain);
/* We ignore the returned resolver object. In the callback
function we free it. If the server is terminated before
the callback function is called the server will free
the resolver for us. */
if (!(avahi_service_resolver_new(dbs->service_client, interface, protocol, name, type, domain,
AVAHI_PROTO_UNSPEC, 0, resolve_callback, userdata)))
debug(1, "Failed to resolve service '%s': %s.", name,
avahi_strerror(avahi_client_errno(dbs->service_client)));
break;
case AVAHI_BROWSER_REMOVE:
debug(1, "(Browser) REMOVE: service '%s' of type '%s' in domain '%s'.", name, type, domain);
char *dacpid = strstr(name, "iTunes_Ctrl_");
if (dacpid) {
dacpid += strlen("iTunes_Ctrl_");
if (strcmp(dacpid, dbs->dacp_id) == 0) {
uint16_t *p = dbs->dacp_port;
if (*p != 0) {
debug(1, "Client's DACP status withdrawn.");
*p = 0;
}
}
} else {
debug(1, "Browse callback: Can't see a DACP string in a DACP Record!");
}
}
break;
case AVAHI_BROWSER_ALL_FOR_NOW:
case AVAHI_BROWSER_CACHE_EXHAUSTED:
// debug(1, "(Browser) %s.", event == AVAHI_BROWSER_CACHE_EXHAUSTED ? "CACHE_EXHAUSTED" :
// "ALL_FOR_NOW");
break;
}
}
static void register_service(AvahiClient *c);
@@ -219,15 +207,15 @@ static void register_service(AvahiClient *c) {
selected_interface = AVAHI_IF_UNSPEC;
#ifdef CONFIG_METADATA
if (config.metadata_enabled) {
ret = avahi_entry_group_add_service(group, selected_interface, AVAHI_PROTO_UNSPEC, 0, service_name,
config.regtype, NULL, NULL, port,
ret = avahi_entry_group_add_service(group, selected_interface, AVAHI_PROTO_UNSPEC, 0,
service_name, config.regtype, NULL, NULL, port,
MDNS_RECORD_WITH_METADATA, NULL);
if (ret == 0)
debug(1, "avahi: request to add \"%s\" service with metadata", config.regtype);
} else {
#endif
ret = avahi_entry_group_add_service(group, selected_interface, AVAHI_PROTO_UNSPEC, 0, service_name,
config.regtype, NULL, NULL, port,
ret = avahi_entry_group_add_service(group, selected_interface, AVAHI_PROTO_UNSPEC, 0,
service_name, config.regtype, NULL, NULL, port,
MDNS_RECORD_WITHOUT_METADATA, NULL);
if (ret == 0)
debug(1, "avahi: request to add \"%s\" service without metadata", config.regtype);
@@ -294,10 +282,9 @@ static void client_callback(AvahiClient *c, AvahiClientState state,
}
}
static void service_client_callback(AvahiClient *c, AvahiClientState state,
void *userdata) {
static void service_client_callback(AvahiClient *c, AvahiClientState state, void *userdata) {
int err;
dacp_browser_struct *dbs = (dacp_browser_struct *)userdata;
switch (state) {
@@ -316,8 +303,9 @@ static void service_client_callback(AvahiClient *c, AvahiClientState state,
avahi_client_free(c);
c = NULL;
if (!(dbs->service_client = avahi_client_new(avahi_threaded_poll_get(dbs->service_poll), AVAHI_CLIENT_NO_FAIL,
service_client_callback, userdata, &err))) {
if (!(dbs->service_client =
avahi_client_new(avahi_threaded_poll_get(dbs->service_poll), AVAHI_CLIENT_NO_FAIL,
service_client_callback, userdata, &err))) {
warn("avahi: failed to create service client object: %s", avahi_strerror(err));
avahi_threaded_poll_quit(dbs->service_poll);
}
@@ -328,7 +316,8 @@ static void service_client_callback(AvahiClient *c, AvahiClientState state,
break;
case AVAHI_CLIENT_S_COLLISION:
debug(2, "avahi: service client state is AVAHI_CLIENT_S_COLLISION...needs a rename: %s", service_name);
debug(2, "avahi: service client state is AVAHI_CLIENT_S_COLLISION...needs a rename: %s",
service_name);
break;
case AVAHI_CLIENT_CONNECTING:
@@ -376,86 +365,86 @@ static void avahi_unregister(void) {
service_name = NULL;
}
int avahi_dacp_monitor(char* dacp_id,uint16_t *port,void** private_pointer) {
dacp_browser_struct **pdbs = (dacp_browser_struct **)private_pointer;
dacp_browser_struct *dbs = (dacp_browser_struct*)malloc(sizeof(dacp_browser_struct));
if (dbs==NULL)
die("can not allocate a dacp_browser_struct.");
int avahi_dacp_monitor(char *dacp_id, uint16_t *port, void **private_pointer) {
dbs->dacp_id=dacp_id;
dbs->dacp_port=port;
dacp_browser_struct **pdbs = (dacp_browser_struct **)private_pointer;
// create the threaded poll code
dacp_browser_struct *dbs = (dacp_browser_struct *)malloc(sizeof(dacp_browser_struct));
if (dbs == NULL)
die("can not allocate a dacp_browser_struct.");
dbs->dacp_id = dacp_id;
dbs->dacp_port = port;
// create the threaded poll code
int err;
if (!(dbs->service_poll = avahi_threaded_poll_new())) {
warn("couldn't create avahi threaded service_poll!");
if(dbs) {
free((char*)dbs);
if (dbs) {
free((char *)dbs);
}
return -1;
}
}
// create the service client
if (!(dbs->service_client = avahi_client_new(avahi_threaded_poll_get(dbs->service_poll), AVAHI_CLIENT_NO_FAIL,
service_client_callback, (void*)dbs, &err))) {
// create the service client
if (!(dbs->service_client =
avahi_client_new(avahi_threaded_poll_get(dbs->service_poll), AVAHI_CLIENT_NO_FAIL,
service_client_callback, (void *)dbs, &err))) {
warn("couldn't create avahi service client: %s!", avahi_strerror(err));
if(dbs) { //should free the threaded poll code
avahi_threaded_poll_free(dbs->service_poll);
free((char*)dbs);
if (dbs) { // should free the threaded poll code
avahi_threaded_poll_free(dbs->service_poll);
free((char *)dbs);
}
return -1;
}
/* Create the service browser */
if (!(dbs->service_browser = avahi_service_browser_new(dbs->service_client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_dacp._tcp", NULL, 0, browse_callback, (void *)dbs))) {
warn("Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(dbs->service_client)));
if(dbs) { //should free the threaded poll code and the service client
avahi_client_free(dbs->service_client);
avahi_threaded_poll_free(dbs->service_poll);
free((char*)dbs);
}
return -1;
}
// start the polling thread
if (avahi_threaded_poll_start(dbs->service_poll) < 0) {
warn("couldn't start avahi service_poll thread");
if(dbs) { //should free the threaded poll code and the service client and the service browser
avahi_service_browser_free(dbs->service_browser);
avahi_client_free(dbs->service_client);
avahi_threaded_poll_free(dbs->service_poll);
free((char*)dbs);
if (!(dbs->service_browser =
avahi_service_browser_new(dbs->service_client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
"_dacp._tcp", NULL, 0, browse_callback, (void *)dbs))) {
warn("Failed to create service browser: %s\n",
avahi_strerror(avahi_client_errno(dbs->service_client)));
if (dbs) { // should free the threaded poll code and the service client
avahi_client_free(dbs->service_client);
avahi_threaded_poll_free(dbs->service_poll);
free((char *)dbs);
}
return -1;
}
*pdbs = dbs;
// start the polling thread
if (avahi_threaded_poll_start(dbs->service_poll) < 0) {
warn("couldn't start avahi service_poll thread");
if (dbs) { // should free the threaded poll code and the service client and the service browser
avahi_service_browser_free(dbs->service_browser);
avahi_client_free(dbs->service_client);
avahi_threaded_poll_free(dbs->service_poll);
free((char *)dbs);
}
return -1;
}
*pdbs = dbs;
return 0;
}
void avahi_dacp_dont_monitor(void** private_pointer) {
dacp_browser_struct **pdbs = (dacp_browser_struct **)private_pointer;
// stop and dispose of everything
if ((*pdbs)->service_poll)
avahi_threaded_poll_stop((*pdbs)->service_poll);
if ((*pdbs)->service_browser)
avahi_service_browser_free((*pdbs)->service_browser);
if ((*pdbs)->service_client)
avahi_client_free((*pdbs)->service_client);
if ((*pdbs)->service_poll)
avahi_threaded_poll_free((*pdbs)->service_poll);
free((char*)(*pdbs));
*pdbs = NULL;
void avahi_dacp_dont_monitor(void **private_pointer) {
dacp_browser_struct **pdbs = (dacp_browser_struct **)private_pointer;
// stop and dispose of everything
if ((*pdbs)->service_poll)
avahi_threaded_poll_stop((*pdbs)->service_poll);
if ((*pdbs)->service_browser)
avahi_service_browser_free((*pdbs)->service_browser);
if ((*pdbs)->service_client)
avahi_client_free((*pdbs)->service_client);
if ((*pdbs)->service_poll)
avahi_threaded_poll_free((*pdbs)->service_poll);
free((char *)(*pdbs));
*pdbs = NULL;
}
mdns_backend mdns_avahi = {
.name = "avahi",
.mdns_register = avahi_register,
.mdns_unregister = avahi_unregister,
.mdns_dacp_monitor = avahi_dacp_monitor,
.mdns_dacp_dont_monitor = avahi_dacp_dont_monitor
};
mdns_backend mdns_avahi = {.name = "avahi",
.mdns_register = avahi_register,
.mdns_unregister = avahi_unregister,
.mdns_dacp_monitor = avahi_dacp_monitor,
.mdns_dacp_dont_monitor = avahi_dacp_dont_monitor};
+15 -14
View File
@@ -1561,9 +1561,10 @@ static void *player_thread_func(void *arg) {
// as a null operand, so we'll use it like that too
int sync_error_out_of_bounds =
0; // number of times in a row that there's been a serious sync error
// start an mdns/zeroconf thread to look for DACP messages containing our DACP_ID and getting the port number
mdns_dacp_monitor(conn->dacp_id,&conn->dacp_port,&conn->dacp_private);
// start an mdns/zeroconf thread to look for DACP messages containing our DACP_ID and getting the
// port number
mdns_dacp_monitor(conn->dacp_id, &conn->dacp_port, &conn->dacp_private);
conn->framesProcessedInThisEpoch = 0;
conn->framesGeneratedInThisEpoch = 0;
@@ -2169,15 +2170,16 @@ static void *player_thread_func(void *arg) {
elapsedSec);
}
// stop watching for DACP port number stuff
mdns_dacp_dont_monitor(&conn->dacp_private); // begin looking out for information about the client as a remote control. Specifically we might need the port number
// stop watching for DACP port number stuff
mdns_dacp_dont_monitor(&conn->dacp_private); // begin looking out for information about the client
// as a remote control. Specifically we might need
// the port number
if (config.output->stop)
config.output->stop();
usleep(100000); // allow this time to (?) allow the alsa subsystem to finish cleaning up after
// itself. 50 ms seems too short
debug(2, "Shut down audio, control and timing threads");
conn->please_stop = 1;
pthread_kill(rtp_audio_thread, SIGUSR1);
@@ -2209,10 +2211,10 @@ static void *player_thread_func(void *arg) {
debug(1, "Error destroying vol_mutex variable.");
debug(1, "Player thread exit on RTSP conversation thread %d.", conn->connection_number);
if (conn->dacp_id) {
free(conn->dacp_id);
conn->dacp_id = NULL;
}
if (conn->dacp_id) {
free(conn->dacp_id);
conn->dacp_id = NULL;
}
if (outbuf)
free(outbuf);
if (silence)
@@ -2257,7 +2259,6 @@ void player_volume_without_notification(double airplay_volume, rtsp_conn_info *c
// Thus, we ask our vol2attn function for an appropriate dB between -96.3 and 0 dB and translate
// it back to a number.
int32_t hw_min_db, hw_max_db, hw_range_db, range_to_use, min_db,
max_db; // hw_range_db is a flag; if 0 means no mixer
@@ -2448,10 +2449,10 @@ void player_volume_without_notification(double airplay_volume, rtsp_conn_info *c
}
void player_volume(double airplay_volume, rtsp_conn_info *conn) {
command_set_volume(airplay_volume);
#ifdef HAVE_DBUS
command_set_volume(airplay_volume);
#ifdef HAVE_DBUS
shairport_sync_set_volume(SHAIRPORT_SYNC(skeleton), airplay_volume);
#endif
#endif
player_volume_without_notification(airplay_volume, conn);
}
+7 -6
View File
@@ -158,14 +158,15 @@ typedef struct {
int64_t session_corrections;
int play_number_after_flush;
// remote control stuff. The port to which to send commands is not specified, so you have to use mdns to find it.
// remote control stuff. The port to which to send commands is not specified, so you have to use
// mdns to find it.
// at present, only avahi can do this
char* dacp_id; // id of the client -- used to find the port to be used
uint16_t dacp_port; // port on the client to send remote control messages to, else zero
char *dacp_id; // id of the client -- used to find the port to be used
uint16_t dacp_port; // port on the client to send remote control messages to, else zero
uint32_t dacp_active_remote; // key to send to the remote controller
void* dacp_private; // private storage (just a pointer) for the dacp_port resolver
void *dacp_private; // private storage (just a pointer) for the dacp_port resolver
} rtsp_conn_info;
+2 -2
View File
@@ -593,8 +593,8 @@ static int bind_port(int ip_family, const char *self_ip_address, uint32_t scope_
return sport;
}
void rtp_setup(SOCKADDR *local, SOCKADDR *remote, int cport, int tport,
int *lsport, int *lcport, int *ltport, rtsp_conn_info *conn) {
void rtp_setup(SOCKADDR *local, SOCKADDR *remote, int cport, int tport, int *lsport, int *lcport,
int *ltport, rtsp_conn_info *conn) {
// this gets the local and remote ip numbers (and ports used for the TCD stuff)
// we use the local stuff to specify the address we are coming from and
+2 -2
View File
@@ -13,8 +13,8 @@ void *rtp_control_receiver(void *arg);
void *rtp_timing_receiver(void *arg);
void rtp_setup(SOCKADDR *local, SOCKADDR *remote, int controlport, int timingport,
int *local_server_port, int *local_control_port,
int *local_timing_port, rtsp_conn_info *conn);
int *local_server_port, int *local_control_port, int *local_timing_port,
rtsp_conn_info *conn);
void rtp_request_resend(seq_t first, uint32_t count, rtsp_conn_info *conn);
void rtp_request_client_pause(rtsp_conn_info *conn); // ask the client to pause
+2 -3
View File
@@ -792,8 +792,7 @@ static void handle_setup(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *
tport = atoi(p);
// rtsp_take_player();
rtp_setup(&conn->local, &conn->remote, cport, tport, &lsport, &lcport, &ltport,
conn);
rtp_setup(&conn->local, &conn->remote, cport, tport, &lsport, &lcport, &ltport, conn);
if (!lsport)
goto error;
char *q;
@@ -1876,7 +1875,7 @@ void rtsp_listen_loop(void) {
int *sockfd = NULL;
int nsock = 0;
int i, ret;
playing_conn = NULL; // the data structure representing the connection that has the player.
memset(&hints, 0, sizeof(hints));
+7 -7
View File
@@ -965,12 +965,12 @@ int parse_options(int argc, char **argv) {
return optind + 1;
}
#if defined(HAVE_DBUS) || defined (HAVE_MPRIS)
#if defined(HAVE_DBUS) || defined(HAVE_MPRIS)
GMainLoop *loop;
pthread_t dbus_thread;
void *dbus_thread_func(void *arg) {
loop = g_main_loop_new(NULL, FALSE);
loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(loop);
}
#endif
@@ -1497,11 +1497,11 @@ int main(int argc, char **argv) {
#if defined(HAVE_DBUS)
// Start up DBUS services after initial settings are all made
debug(1,"Starting up D-Bus services");
pthread_create(&dbus_thread, NULL, &dbus_thread_func, NULL);
#ifdef HAVE_DBUS
start_dbus_service();
#endif
debug(1, "Starting up D-Bus services");
pthread_create(&dbus_thread, NULL, &dbus_thread_func, NULL);
#ifdef HAVE_DBUS
start_dbus_service();
#endif
#endif
daemon_log(LOG_INFO, "Successful Startup");