From: Mike Brady Date: Thu, 17 May 2018 09:29:59 +0000 (+0100) Subject: Move to using pthread_cancel in place of pthread_kill -- due to a problem in CYGWIN... X-Git-Tag: 3.2RC8~2^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a5a29e2c25b7043b449fc2f836f6c3b11916de5;p=thirdparty%2Fshairport-sync.git Move to using pthread_cancel in place of pthread_kill -- due to a problem in CYGWIN, but the move makes the code simpler and more rugged. Tidy up the code a bit and remove a clobbering warning. --- diff --git a/audio_ao.c b/audio_ao.c index 9c87f892..8a78e880 100644 --- a/audio_ao.c +++ b/audio_ao.c @@ -121,7 +121,7 @@ static void deinit(void) { static void start(__attribute__((unused)) int sample_rate, __attribute__((unused)) int sample_format) {} -static void play(void * buf, int samples) { ao_play(dev, buf, samples * 4); } +static void play(void *buf, int samples) { ao_play(dev, buf, samples * 4); } static void stop(void) {} diff --git a/mdns.c b/mdns.c index f6a191a3..b8d870c6 100644 --- a/mdns.c +++ b/mdns.c @@ -106,14 +106,14 @@ void mdns_unregister(void) { void *mdns_dacp_monitor(char *dacp_id) { void *reply = NULL; - if ((dacp_id!=NULL) && (*dacp_id!='\0')) { - if ((config.mdns) && (config.mdns->mdns_dacp_monitor)) { - reply = config.mdns->mdns_dacp_monitor(dacp_id); - if (reply == NULL) { - debug(1, "Error starting a DACP monitor."); - } - } else - debug(3, "Can't start a DACP monitor -- none registered."); + if ((dacp_id != NULL) && (*dacp_id != '\0')) { + if ((config.mdns) && (config.mdns->mdns_dacp_monitor)) { + reply = config.mdns->mdns_dacp_monitor(dacp_id); + if (reply == NULL) { + debug(1, "Error starting a DACP monitor."); + } + } else + debug(3, "Can't start a DACP monitor -- none registered."); } return reply; } diff --git a/player.c b/player.c index 41199da9..8e29678a 100644 --- a/player.c +++ b/player.c @@ -545,8 +545,9 @@ void player_put_packet(seq_t seqno, uint32_t actual_timestamp, int64_t timestamp if (config.disable_resend_requests == 0) { rtp_request_resend(next, 1, conn); if ((back_step + k + resend_interval) >= sd) - debug(2, "Last-ditch (#%d) resend request for packet %u in range %u to %u. Looking back %d packets.", j, next, - conn->ab_read, conn->ab_write,back_step + k); + debug(2, "Last-ditch (#%d) resend request for packet %u in range %u to %u. " + "Looking back %d packets.", + j, next, conn->ab_read, conn->ab_write, back_step + k); conn->resend_requests++; } } diff --git a/rtp.c b/rtp.c index a900c7a4..e15c18ad 100644 --- a/rtp.c +++ b/rtp.c @@ -177,7 +177,7 @@ void *rtp_audio_receiver(void *arg) { debug(3, "Audio receiver -- Server RTP thread interrupted. terminating."); close(conn->audio_socket); */ - + debug(1, "Audio receiver thread \"normal\" exit -- this can't happen. Hah!"); pthread_cleanup_pop(0); // don't execute anything here. debug(2, "Audio receiver thread exit."); @@ -211,50 +211,50 @@ void *rtp_control_receiver(void *arg) { (drand48() > config.diagnostic_drop_packet_fraction)) { ssize_t plen = nread; - if (packet[1] == 0xd4) { // sync data - /* - // the following stanza is for debugging only -- normally commented out. - { - char obf[4096]; - char *obfp = obf; - int obfc; - for (obfc = 0; obfc < plen; obfc++) { - snprintf(obfp, 3, "%02X", packet[obfc]); - obfp += 2; - }; - *obfp = 0; - - - // get raw timestamp information - // I think that a good way to understand these timestamps is that - // (1) the rtlt below is the timestamp of the frame that should be playing at the - // client-time specified in the packet if there was no delay - // and (2) that the rt below is the timestamp of the frame that should be playing - // at the client-time specified in the packet on this device taking account of - // the delay - // Thus, (3) the latency can be calculated by subtracting the second from the - // first. - // There must be more to it -- there something missing. - - // In addition, it seems that if the value of the short represented by the second - // pair of bytes in the packe is 7 - // then an extra time lag is expected to be added, presumably by - // the AirPort Express. - - // Best guess is that this delay is 11,025 frames. - - // uint32_t rtlt = nctohl(&packet[4]); // raw timestamp less latency - // uint32_t rt = nctohl(&packet[16]); // raw timestamp - - // uint32_t fl = nctohs(&packet[2]); // - - // debug(1,"Sync Packet of %d bytes received: \"%s\", flags: %d, timestamps %u and - %u, - giving a latency of %d frames.",plen,obf,fl,rt,rtlt,rt-rtlt); - // debug(1,"Monotonic timestamps are: %" PRId64 " and %" PRId64 " - respectively.",monotonic_timestamp(rt, conn),monotonic_timestamp(rtlt, conn)); - } - */ + if (packet[1] == 0xd4) { // sync data + /* + // the following stanza is for debugging only -- normally commented out. + { + char obf[4096]; + char *obfp = obf; + int obfc; + for (obfc = 0; obfc < plen; obfc++) { + snprintf(obfp, 3, "%02X", packet[obfc]); + obfp += 2; + }; + *obfp = 0; + + + // get raw timestamp information + // I think that a good way to understand these timestamps is that + // (1) the rtlt below is the timestamp of the frame that should be playing at the + // client-time specified in the packet if there was no delay + // and (2) that the rt below is the timestamp of the frame that should be playing + // at the client-time specified in the packet on this device taking account of + // the delay + // Thus, (3) the latency can be calculated by subtracting the second from the + // first. + // There must be more to it -- there something missing. + + // In addition, it seems that if the value of the short represented by the second + // pair of bytes in the packe is 7 + // then an extra time lag is expected to be added, presumably by + // the AirPort Express. + + // Best guess is that this delay is 11,025 frames. + + // uint32_t rtlt = nctohl(&packet[4]); // raw timestamp less latency + // uint32_t rt = nctohl(&packet[16]); // raw timestamp + + // uint32_t fl = nctohs(&packet[2]); // + + // debug(1,"Sync Packet of %d bytes received: \"%s\", flags: %d, timestamps %u and + %u, + giving a latency of %d frames.",plen,obf,fl,rt,rtlt,rt-rtlt); + // debug(1,"Monotonic timestamps are: %" PRId64 " and %" PRId64 " + respectively.",monotonic_timestamp(rt, conn),monotonic_timestamp(rtlt, conn)); + } + */ if (conn->local_to_remote_time_difference) { // need a time packet to be interchanged // first... @@ -455,7 +455,7 @@ void *rtp_timing_sender(void *arg) { request_number++; if (request_number <= 4) - usleep(500000); //these are thread cancellation points + usleep(500000); // these are thread cancellation points else usleep(3000000); } @@ -518,9 +518,9 @@ void *rtp_timing_receiver(void *arg) { return_time = arrival_time - conn->departure_time; - uint64_t rtus = (return_time * 1000000) >> 32; + //uint64_t rtus = (return_time * 1000000) >> 32; - if (rtus < 300000) { + if (((return_time * 1000000) >> 32) < 300000) { // debug(2,"Synchronisation ping return time is %f milliseconds.",(rtus*1.0)/1000); @@ -683,7 +683,7 @@ void *rtp_timing_receiver(void *arg) { //(return_time*1000000)>>32); } else { debug(2, "Time ping turnaround time: %lld us -- it looks like a timing ping was lost.", - rtus); + (return_time * 1000000) >> 32); } } else { debug(1, "Timing port -- Unknown RTP packet of type 0x%02X length %d.", packet[1], nread); @@ -947,8 +947,8 @@ void rtp_request_resend(seq_t first, uint32_t count, rtsp_conn_info *conn) { (struct sockaddr *)&conn->rtp_client_control_socket, msgsize) == -1) { char em[1024]; strerror_r(errno, em, sizeof(em)); - debug(1, - "Error %d using send-to to an audio socket: \"%s\". Backing off for 1/16th of a second.", + debug(1, "Error %d using send-to to an audio socket: \"%s\". Backing off for 1/16th of a " + "second.", errno, em); conn->rtp_time_of_last_resend_request_error_fp = time_of_sending_fp; } else { @@ -956,8 +956,10 @@ void rtp_request_resend(seq_t first, uint32_t count, rtsp_conn_info *conn) { } } else { - debug(3, "Dropping resend request packet to simulate a bad network. Backing off for 1/16th of a " - "second."); + debug( + 3, + "Dropping resend request packet to simulate a bad network. Backing off for 1/16th of a " + "second."); conn->rtp_time_of_last_resend_request_error_fp = time_of_sending_fp; } } else {