From: Mike Brady Date: Wed, 11 Apr 2018 19:05:21 +0000 (+0100) Subject: Allow audio packets as well as resends on the control port. Add some debug messages. X-Git-Tag: 3.2RC3~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd7c2d7954c23a386c8f73cec67c3cc1e9d1d6cc;p=thirdparty%2Fshairport-sync.git Allow audio packets as well as resends on the control port. Add some debug messages. --- diff --git a/dacp.c b/dacp.c index 63001113..4ecc2064 100644 --- a/dacp.c +++ b/dacp.c @@ -223,7 +223,7 @@ int dacp_send_command(const char *command, char **body, ssize_t *bodysize) { if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tv, sizeof tv) == -1) debug(1, "Error %d setting receive timeout for DACP service.", errno); int ndata = recv(sockfd, buffer, sizeof(buffer), 0); - debug(3, "Received %d bytes: \"%s\".", ndata, buffer); + // debug(3, "Received %d bytes: \"%s\".", ndata, buffer); if (ndata <= 0) { debug(1, "dacp_send_command -- error receiving response for command \"%s\".", command); diff --git a/player.c b/player.c index 3552410a..4f652802 100644 --- a/player.c +++ b/player.c @@ -1173,7 +1173,7 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) { if (!conn->ab_buffering) { // check once, after a short period of has elapsed, assuming 352 frames per packet - i = ((250 * 44100) / 352) / 1000; // approx 250 ms + i = ((125 * 44100) / 352) / 1000; // approx 125 ms if (i < seq_diff(conn->ab_read, conn->ab_write, conn->ab_read)) { seq_t next = seq_sum(conn->ab_read, i); abuf = conn->audio_buffer + BUFIDX(next); @@ -1686,7 +1686,7 @@ static void *player_thread_func(void *arg) { config.output->play(silence, conn->max_frames_per_packet * conn->output_sample_ratio); } else if (frames_to_drop) { if (frames_to_drop > 3 * config.output_rate) - warn("Very large number of frames to drop: %" PRId64 ".",frames_to_drop); + warn("Very large number of frames to drop: %" PRId64 ".", frames_to_drop); debug(3, "%" PRId64 " frames to drop.", frames_to_drop); frames_to_drop -= inframe->length; if (frames_to_drop < 0) @@ -1888,7 +1888,10 @@ static void *player_thread_func(void *arg) { (!conn->player_thread_please_stop) && (config.resyncthreshold > 0.0) && (abs_sync_error > config.resyncthreshold * config.output_rate)) { if (abs_sync_error > 3 * config.output_rate) { - warn("Very large sync error: %" PRId64 " frames, with a delay of %" PRId64 "frames.",sync_error,delay); + warn("Very large sync error: %" PRId64 " frames, with delay: %" PRId64 + ", td_in_frames: %" PRId64 ", rt: %" PRId64 ", nt: %" PRId64 + ", current_delay: %" PRId64 ", frames.", + sync_error, delay, td_in_frames, rt, nt, current_delay); } sync_error_out_of_bounds++; } else { diff --git a/rtp.c b/rtp.c index 8168de14..f4020804 100644 --- a/rtp.c +++ b/rtp.c @@ -134,6 +134,7 @@ void *rtp_audio_receiver(void *arg) { if (type == 0x56) { pktp += 4; plen -= 4; + debug(1, "resent packet %u received in audio port.", ntohs(*(uint16_t *)(pktp + 2))); } seq_t seqno = ntohs(*(uint16_t *)(pktp + 2)); // increment last_seqno and see if it's the same as the incoming seqno @@ -344,27 +345,42 @@ void *rtp_control_receiver(void *arg) { } else { debug(1, "Sync packet received before we got a timing packet back."); } - } else if (packet[1] == 0xd6) { // resent audio data in the control path -- whaale only? - // debug(1, "Control Port -- Retransmitted Audio Data Packet received."); - pktp = packet + 4; - plen -= 4; - seq_t seqno = ntohs(*(uint16_t *)(pktp + 2)); + } else { + uint8_t type = packet[1] & ~0x80; + if ((type == 0x60) || + (type == 0x56)) { // audio data / resent audio data in the control path -- whaale only? + pktp = packet; + + if (type == 0x56) { // resent audio data in the control path -- whaale only? + // debug(1, "Control Port -- Retransmitted Audio Data Packet received."); + pktp = packet + 4; + plen -= 4; + } - int64_t timestamp = monotonic_timestamp(ntohl(*(uint32_t *)(pktp + 4)), conn); + seq_t seqno = ntohs(*(uint16_t *)(pktp + 2)); + if (type == 0x56) + debug(1, "Resent audio packet %u received in the control port.", seqno); + else + debug(1, "Audio packet %u received in the control port.", seqno); - pktp += 12; - plen -= 12; + int64_t timestamp = monotonic_timestamp(ntohl(*(uint32_t *)(pktp + 4)), conn); - // check if packet contains enough content to be reasonable - if (plen >= 16) { - player_put_packet(seqno, timestamp, pktp, plen, conn); - continue; + pktp += 12; + plen -= 12; + + // check if packet contains enough content to be reasonable + + if (plen >= 16) { + player_put_packet(seqno, timestamp, pktp, plen, conn); + continue; + } else { + debug(3, "Too-short retransmitted audio packet received in control port, ignored."); + } } else { - debug(3, "Too-short retransmitted audio packet received in control port, ignored."); + debug(1, "Control Port -- Unknown RTP packet of type 0x%02X length %d, ignored.", packet[1], + nread); } - } else - debug(1, "Control Port -- Unknown RTP packet of type 0x%02X length %d, ignored.", packet[1], - nread); + } } debug(3, "Control RTP thread interrupted. terminating.");