enum am_state { am_inactive, am_active, am_timing_out } state;
enum ps_state { ps_inactive, ps_active } player_state;
+int activity_monitor_running = 0;
+
pthread_t activity_monitor_thread;
pthread_mutex_t activity_monitor_mutex;
pthread_cond_t activity_monitor_cv;
void activity_monitor_start() {
// debug(1,"activity_monitor_start");
pthread_create(&activity_monitor_thread, NULL, activity_monitor_thread_code, NULL);
+ activity_monitor_running = 1;
}
void activity_monitor_stop() {
- debug(1, "activity_monitor_stop start...");
- pthread_cancel(activity_monitor_thread);
- pthread_join(activity_monitor_thread, NULL);
- debug(1, "activity_monitor_stop complete");
+ if (activity_monitor_running) {
+ debug(1, "activity_monitor_stop start...");
+ pthread_cancel(activity_monitor_thread);
+ pthread_join(activity_monitor_thread, NULL);
+ debug(1, "activity_monitor_stop complete");
+ }
}
void *port_monitor_private_storage;
} dacp_server_record;
+int dacp_monitor_initialised = 0;
pthread_t dacp_monitor_thread;
dacp_server_record dacp_server;
void *mdns_dacp_monitor_private_storage_pointer;
memset(&dacp_server, 0, sizeof(dacp_server_record));
pthread_create(&dacp_monitor_thread, NULL, dacp_monitor_thread_code, NULL);
+ dacp_monitor_initialised = 1;
}
void dacp_monitor_stop() {
- debug(1, "dacp_monitor_stop");
- pthread_cancel(dacp_monitor_thread);
- pthread_join(dacp_monitor_thread, NULL);
- pthread_mutex_destroy(&dacp_server_information_lock);
- debug(1, "DACP Conversation Lock Mutex Destroyed");
- pthread_mutex_destroy(&dacp_conversation_lock);
+ if (dacp_monitor_initialised) { // only if it's been started and initialised
+ debug(1, "dacp_monitor_stop");
+ pthread_cancel(dacp_monitor_thread);
+ pthread_join(dacp_monitor_thread, NULL);
+ pthread_mutex_destroy(&dacp_server_information_lock);
+ debug(1, "DACP Conversation Lock Mutex Destroyed");
+ pthread_mutex_destroy(&dacp_conversation_lock);
+ }
}
uint32_t dacp_tlv_crawl(char **p, int32_t *length) {
#include <openssl/md5.h>
#endif
+int metadata_hub_initialised = 0;
+
pthread_rwlock_t metadata_hub_re_lock = PTHREAD_RWLOCK_INITIALIZER;
struct track_metadata_bundle *track_metadata; // used for a temporary track metadata store
// debug(1, "Metadata bundle initialisation.");
memset(&metadata_store, 0, sizeof(metadata_store));
track_metadata = NULL;
+ metadata_hub_initialised = 1;
}
void metadata_hub_stop(void) {
- debug(1, "metadata_hub_stop.");
- metadata_hub_release_track_artwork();
- if (metadata_store.track_metadata) {
- metadata_hub_release_track_metadata(metadata_store.track_metadata);
- metadata_store.track_metadata = NULL;
- }
- if (track_metadata) {
- metadata_hub_release_track_metadata(track_metadata);
- track_metadata = NULL;
+ if (metadata_hub_initialised) {
+ debug(1, "metadata_hub_stop.");
+ metadata_hub_release_track_artwork();
+ if (metadata_store.track_metadata) {
+ metadata_hub_release_track_metadata(metadata_store.track_metadata);
+ metadata_store.track_metadata = NULL;
+ }
+ if (track_metadata) {
+ metadata_hub_release_track_metadata(track_metadata);
+ track_metadata = NULL;
+ }
}
}
// Mike Brady's part...
+int metadata_running = 0;
+
// always lock use this when accessing the playing conn value
static pthread_mutex_t playing_conn_lock = PTHREAD_MUTEX_INITIALIZER;
int ret = pthread_create(&metadata_thread, NULL, metadata_thread_function, NULL);
if (ret)
debug(1, "Failed to create metadata thread!");
+ metadata_running = 1;
}
void metadata_stop(void) {
- debug(1, "metadata_stop called.");
- pthread_cancel(metadata_thread);
- pthread_join(metadata_thread, NULL);
+ if (metadata_running) {
+ debug(1, "metadata_stop called.");
+ pthread_cancel(metadata_thread);
+ pthread_join(metadata_thread, NULL);
+ }
}
int send_metadata(uint32_t type, uint32_t code, char *data, uint32_t length, rtsp_message *carrier,
}
#if defined(CONFIG_DBUS_INTERFACE) || defined(CONFIG_MPRIS_INTERFACE)
-GMainLoop *g_main_loop;
+static GMainLoop *g_main_loop = NULL;
pthread_t dbus_thread;
void *dbus_thread_func(__attribute__((unused)) void *arg) {
#endif
void main_cleanup_handler(__attribute__((unused)) void *arg) {
- // it doesn't look like this is called when the main function terminates.
+ // it doesn't look like this is called when the main function is cancelled eith a pthread cancel.
debug(1, "main cleanup handler called.");
#ifdef CONFIG_MQTT
if (config.mqtt_enabled) {
#ifdef CONFIG_DBUS_INTERFACE
stop_dbus_service();
#endif
- debug(1, "Stopping DBUS Loop Thread");
- g_main_loop_quit(g_main_loop);
- pthread_join(dbus_thread, NULL);
+ if (g_main_loop) {
+ debug(1, "Stopping DBUS Loop Thread");
+ g_main_loop_quit(g_main_loop);
+ pthread_join(dbus_thread, NULL);
+ }
#endif
#ifdef CONFIG_DACP_CLIENT
activity_monitor_stop(0);
- if (config.output->deinit) {
+ if ((config.output) && (config.output->deinit)) {
debug(1, "Deinitialise the audio backend.");
config.output->deinit();
}