diff --git a/player.c b/player.c index 2a659f6e..e4dd7389 100644 --- a/player.c +++ b/player.c @@ -2385,7 +2385,7 @@ void player_volume_without_notification(double airplay_volume, rtsp_conn_info *c int32_t hw_min_db, hw_max_db, hw_range_db, min_db, max_db; // hw_range_db is a flag; if 0 means no mixer - if (config.output->parameters) { + if (config.output->parameters) { // no cancellation points in here audio_parameters audio_information; // have a hardware mixer config.output->parameters(&audio_information); @@ -2515,9 +2515,9 @@ void player_volume_without_notification(double airplay_volume, rtsp_conn_info *c if (config.ignore_volume_control == 1) scaled_attenuation = max_db; else if (config.volume_control_profile == VCP_standard) - scaled_attenuation = vol2attn(airplay_volume, max_db, min_db); + scaled_attenuation = vol2attn(airplay_volume, max_db, min_db); // no cancellation points else if (config.volume_control_profile == VCP_flat) - scaled_attenuation = flat_vol2attn(airplay_volume, max_db, min_db); + scaled_attenuation = flat_vol2attn(airplay_volume, max_db, min_db); // no cancellation points else debug(1, "Unrecognised volume control profile"); @@ -2552,7 +2552,7 @@ void player_volume_without_notification(double airplay_volume, rtsp_conn_info *c // %f",software_attenuation,temp_fix_volume,airplay_volume); conn->fix_volume = temp_fix_volume; - memory_barrier(); + memory_barrier(); // no cancellation points if (config.loudness) loudness_set_volume(software_attenuation / 100); @@ -2599,7 +2599,7 @@ void do_flush(int64_t timestamp, rtsp_conn_info *conn) { // otherwise if (conn->first_packet_timestamp) { debug(2, "pfls"); - send_ssnc_metadata('pfls', NULL, 0, 1); + send_ssnc_metadata('pfls', NULL, 0, 1); // contains cancellation points } #endif @@ -2621,7 +2621,7 @@ int player_play(rtsp_conn_info *conn) { command_start(); #ifdef CONFIG_METADATA debug(2, "pbeg"); - send_ssnc_metadata('pbeg', NULL, 0, 1); + send_ssnc_metadata('pbeg', NULL, 0, 1); // contains cancellation points #endif pthread_t *pt = malloc(sizeof(pthread_t)); if (pt == NULL) @@ -2640,6 +2640,7 @@ int player_play(rtsp_conn_info *conn) { } int player_stop(rtsp_conn_info *conn) { + // will only ever be called by the connection thread debug(3, "player_stop"); if (conn->player_thread) { debug(3, "player_thread exists"); @@ -2652,7 +2653,7 @@ int player_stop(rtsp_conn_info *conn) { conn->player_thread = NULL; #ifdef CONFIG_METADATA debug(2, "pend"); - send_ssnc_metadata('pend', NULL, 0, 1); + send_ssnc_metadata('pend', NULL, 0, 1); // contains cancellation points #endif command_stop(); return 0; diff --git a/rtsp.c b/rtsp.c index 00a168ba..3d515247 100644 --- a/rtsp.c +++ b/rtsp.c @@ -163,6 +163,13 @@ int send_ssnc_metadata(uint32_t code, char *data, uint32_t length, int block) { return send_metadata('ssnc', code, data, length, NULL, block); } +void pc_queue_cleanup_handler(void *arg) { + pc_queue *the_queue = (pc_queue *)arg; + int rc = pthread_mutex_unlock(&the_queue->pc_queue_lock); + if (rc) + debug(1, "Error unlocking for pc_queue_add_item or pc_queue_get_item."); +} + int pc_queue_add_item(pc_queue *the_queue, const void *the_stuff, int block) { int rc; if (the_queue) { @@ -174,6 +181,7 @@ int pc_queue_add_item(pc_queue *the_queue, const void *the_stuff, int block) { rc = pthread_mutex_lock(&the_queue->pc_queue_lock); if (rc) debug(1, "Error locking for pc_queue_add_item"); + pthread_cleanup_push(pc_queue_cleanup_handler,(void *)the_queue); while (the_queue->count == the_queue->capacity) { rc = pthread_cond_wait(&the_queue->pc_queue_item_removed_signal, &the_queue->pc_queue_lock); if (rc) @@ -196,9 +204,7 @@ int pc_queue_add_item(pc_queue *the_queue, const void *the_stuff, int block) { rc = pthread_cond_signal(&the_queue->pc_queue_item_added_signal); if (rc) debug(1, "Error signalling after pc_queue_add_item"); - rc = pthread_mutex_unlock(&the_queue->pc_queue_lock); - if (rc) - debug(1, "Error unlocking for pc_queue_add_item"); + pthread_cleanup_pop(1); // unlock the queue lock. } else { debug(1, "Adding an item to a NULL queue"); } @@ -211,6 +217,7 @@ int pc_queue_get_item(pc_queue *the_queue, void *the_stuff) { rc = pthread_mutex_lock(&the_queue->pc_queue_lock); if (rc) debug(1, "Error locking for pc_queue_get_item"); + pthread_cleanup_push(pc_queue_cleanup_handler,(void *)the_queue); while (the_queue->count == 0) { rc = pthread_cond_wait(&the_queue->pc_queue_item_added_signal, &the_queue->pc_queue_lock); if (rc) @@ -231,9 +238,7 @@ int pc_queue_get_item(pc_queue *the_queue, void *the_stuff) { rc = pthread_cond_signal(&the_queue->pc_queue_item_removed_signal); if (rc) debug(1, "Error signalling after pc_queue_removed_item"); - rc = pthread_mutex_unlock(&the_queue->pc_queue_lock); - if (rc) - debug(1, "Error unlocking for pc_queue_get_item"); + pthread_cleanup_pop(1); // unlock the queue lock. } else { debug(1, "Removing an item from a NULL queue"); }