conn->initial_reference_time = 0;
conn->initial_reference_timestamp = 0;
} else {
- /*
- if ((conn->flush_rtp_timestamp != 0) &&
- (modulo_32_offset(conn->flush_rtp_timestamp, actual_timestamp) > conn->input_rate / 5) &&
- (modulo_32_offset(conn->flush_rtp_timestamp, actual_timestamp) < conn->input_rate)) {
- // between 0.2 and 1 second
- debug(2, "Dropping flush request in player_put_packet");
- conn->flush_rtp_timestamp = 0;
- }
- */
+ /*
+ if ((conn->flush_rtp_timestamp != 0) &&
+ (modulo_32_offset(conn->flush_rtp_timestamp, actual_timestamp) > conn->input_rate / 5)
+ &&
+ (modulo_32_offset(conn->flush_rtp_timestamp, actual_timestamp) < conn->input_rate)) {
+ // between 0.2 and 1 second
+ debug(2, "Dropping flush request in player_put_packet");
+ conn->flush_rtp_timestamp = 0;
+ }
+ */
abuf_t *abuf = 0;
debug(1, "Inconsistent sequence numbers detected");
}
}
-
- //if (conn->flush_rtp_timestamp != 0)
- // debug(2,"flush_rtp_timestamp is %" PRIx32 " and curframe->given_timestamp is %" PRIx32 ".", conn->flush_rtp_timestamp , curframe->given_timestamp);
-
+
+ // if (conn->flush_rtp_timestamp != 0)
+ // debug(2,"flush_rtp_timestamp is %" PRIx32 " and curframe->given_timestamp is %" PRIx32
+ // ".", conn->flush_rtp_timestamp , curframe->given_timestamp);
+
if ((conn->flush_rtp_timestamp != 0) &&
(curframe->given_timestamp != conn->flush_rtp_timestamp) &&
(modulo_32_offset(curframe->given_timestamp, conn->flush_rtp_timestamp) <
if (local_time_now > conn->first_packet_time_to_play) {
uint64_t lateness = local_time_now - conn->first_packet_time_to_play;
lateness = (lateness * 1000000) >> 32; // microseconds
- debug(
- 3,
- "First packet is %" PRIu64 " microseconds late! Flushing 0.5 seconds",lateness);
- do_flush(conn->first_packet_timestamp + 5 * 4410,
- conn);
+ debug(3, "First packet is %" PRIu64 " microseconds late! Flushing 0.5 seconds",
+ lateness);
+ do_flush(conn->first_packet_timestamp + 5 * 4410, conn);
}
}
}
if (local_time_now > conn->first_packet_time_to_play) {
uint64_t lateness = local_time_now - conn->first_packet_time_to_play;
lateness = (lateness * 1000000) >> 32; // microseconds
- debug(3,"Gone past starting time by %" PRIu64 " microseconds.", lateness);
+ debug(3, "Gone past starting time by %" PRIu64 " microseconds.", lateness);
have_sent_prefiller_silence = 1;
conn->ab_buffering = 0;
debug(1, "This should never be called.");
pthread_cleanup_pop(1); // pop the cleanup handler
-// debug(1, "This should never be called either.");
-// pthread_cleanup_pop(1); // pop the initial cleanup handler
+ // debug(1, "This should never be called either.");
+ // pthread_cleanup_pop(1); // pop the initial cleanup handler
pthread_exit(NULL);
}
int player_stop(rtsp_conn_info *conn) {
// note -- this may be called from another connection thread.
- //int dl = debuglev;
+ // int dl = debuglev;
// debuglev = 3;
debug(3, "player_stop");
if (conn->player_thread) {
shutdown(conn->audio_socket, SHUT_RDWR);
debug(3, "close audio socket.");
close(conn->audio_socket);
-
+
debug(3, "Audio Receiver Cleanup Successful.");
}
// increment last_seqno and see if it's the same as the incoming seqno
if (type == 0x60) { // regular audio data
-
- /*
+
+ /*
char obf[4096];
char *obfp = obf;
int obfc;
};
*obfp=0;
debug(1,"Audio Packet Received: \"%s\"",obf);
- */
-
+ */
+
if (last_seqno == -1)
last_seqno = seqno;
else {
}
uint32_t actual_timestamp = ntohl(*(uint32_t *)(pktp + 4));
-
+
// uint32_t ssid = ntohl(*(uint32_t *)(pktp + 8));
// debug(1, "Audio packet SSID: %08X,%u", ssid,ssid);
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));
+ 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
int tryCount = 0;
uint16_t desired_port;
do {
- tryCount++;
- desired_port = nextFreeUDPPort();
+ tryCount++;
+ desired_port = nextFreeUDPPort();
memset(&myaddr, 0, sizeof(myaddr));
if (ip_family == AF_INET) {
struct sockaddr_in *sa = (struct sockaddr_in *)&myaddr;
if (ret < 0) {
close(local_socket);
- die("error: could not bind a UDP port! Check the udp_port_range is large enough -- it must be at least 3, and 10 or more is suggested -- or "
+ die("error: could not bind a UDP port! Check the udp_port_range is large enough -- it must be "
+ "at least 3, and 10 or more is suggested -- or "
"check for restrictive firewall settings or a bad router!");
}
continue;
char errorstring[1024];
strerror_r(errno, (char *)errorstring, sizeof(errorstring));
- debug(1, "Connection %d: rtsp_read_request_response_read_error %d: \"%s\".", conn->connection_number, errno, (char *)errorstring);
+ debug(1, "Connection %d: rtsp_read_request_response_read_error %d: \"%s\".",
+ conn->connection_number, errno, (char *)errorstring);
reply = rtsp_read_request_response_read_error;
goto shutdown;
}
error:
warn("Connection %d: SETUP -- Error in setup request -- unlocking play lock.",
conn->connection_number);
- debug_mutex_lock(&playing_conn_lock, 1000000 , 3);
+ debug_mutex_lock(&playing_conn_lock, 1000000, 3);
playing_conn = NULL; // this connection definitely doesn't have the play lock
debug_mutex_unlock(&playing_conn_lock, 3);
resp->respcode = 451; // invalid arguments
static void handle_announce(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) {
debug(2, "Connection %d: ANNOUNCE", conn->connection_number);
-
-
+
int have_the_player = 0;
int should_wait = 0; // this will be true if you're trying to break in to the current session
int interrupting_current_session = 0;
-
+
// try to become the current playing_conn
-
- debug_mutex_lock(&playing_conn_lock, 1000000 , 3); //get it
-
+
+ debug_mutex_lock(&playing_conn_lock, 1000000, 3); // get it
+
if (playing_conn == NULL) {
playing_conn = conn;
have_the_player = 1;
} else if (playing_conn == conn) {
- have_the_player = 1;
- warn("Duplicate ANNOUNCE, by the look of it!");
+ have_the_player = 1;
+ warn("Duplicate ANNOUNCE, by the look of it!");
} else if (playing_conn->stop) {
- debug(2, "Connection %d: ANNOUNCE: already shutting down; waiting for it...",playing_conn->connection_number);
- should_wait = 1;
+ debug(2, "Connection %d: ANNOUNCE: already shutting down; waiting for it...",
+ playing_conn->connection_number);
+ should_wait = 1;
} else if (config.allow_session_interruption == 1) {
debug(2, "Connection %d: ANNOUNCE: asking playing connection %d to shut down.",
- conn->connection_number, playing_conn->connection_number);
+ conn->connection_number, playing_conn->connection_number);
playing_conn->stop = 1;
interrupting_current_session = 1;
- should_wait = 1;
+ should_wait = 1;
pthread_cancel(playing_conn->thread); // asking the RTSP thread to exit
- }
+ }
debug_mutex_unlock(&playing_conn_lock, 3);
if (should_wait) {
useconds_t time_remaining = 3000000;
-
+
while ((time_remaining > 0) && (have_the_player == 0)) {
- debug_mutex_lock(&playing_conn_lock, 1000000 , 3); //get it
+ debug_mutex_lock(&playing_conn_lock, 1000000, 3); // get it
if (playing_conn == NULL) {
playing_conn = conn;
have_the_player = 1;
debug_mutex_unlock(&playing_conn_lock, 3);
if (have_the_player == 0) {
- usleep(100000);
- time_remaining -= 100000;
- }
+ usleep(100000);
+ time_remaining -= 100000;
}
+ }
if ((have_the_player == 1) && (interrupting_current_session == 1)) {
debug(2, "Connection %d: ANNOUNCE got the player", conn->connection_number);
if (have_the_player) {
debug(3, "RTSP conversation thread %d has acquired play lock.", conn->connection_number);
-
+
// now, if this new session did not break in, then it's okay to reset the next UDP ports
// to the start of the range
-
+
if (interrupting_current_session == 0) { // will be zero if it wasn't waiting to break in
- resetFreeUDPPort();
+ resetFreeUDPPort();
}
-
+
/*
{
char *cp = req->content;
}
}
*/
-
-
+
resp->respcode = 456; // 456 - Header Field Not Valid for Resource
char *pssid = NULL;
char *paesiv = NULL;
cp = next;
}
-
+
if (pssid) {
uint32_t ssid = uatoi(pssid);
- debug(3, "Synchronisation Source Identifier: %08X,%u", ssid,ssid);
- }
+ debug(3, "Synchronisation Source Identifier: %08X,%u", ssid, ssid);
+ }
if (pminlatency) {
conn->minimum_latency = atoi(pminlatency);
if (resp->respcode != 200 && resp->respcode != 453) {
debug(1, "Connection %d: Error in handling ANNOUNCE. Unlocking the play lock.",
conn->connection_number);
- debug_mutex_lock(&playing_conn_lock, 1000000 , 3); //get it
+ debug_mutex_lock(&playing_conn_lock, 1000000, 3); // get it
playing_conn = NULL;
debug_mutex_unlock(&playing_conn_lock, 3);
}
conn->auth_nonce = NULL;
}
rtp_terminate(conn);
-
+
if (conn->dacp_id) {
free(conn->dacp_id);
conn->dacp_id = NULL;
if (rc)
debug(1, "Connection %d: error %d destroying flush_mutex.", conn->connection_number, rc);
- debug_mutex_lock(&playing_conn_lock, 1000000 , 3); //get it
+ debug_mutex_lock(&playing_conn_lock, 1000000, 3); // get it
if (playing_conn == conn) {
debug(3, "Connection %d: Unlocking play lock.", conn->connection_number);
playing_conn = NULL;
if (conn->stop == 0) {
int err = msg_write_response(conn->fd, resp);
if (err) {
- debug(1, "Connection %d: Unable to write an RTSP message response. Terminating the connection.", conn->connection_number);
+ debug(1, "Connection %d: Unable to write an RTSP message response. Terminating the "
+ "connection.",
+ conn->connection_number);
conn->stop = 1;
}
}
// debuglev = 3; // see what happens next
} else {
if (reply == rtsp_read_request_response_channel_closed)
- debug(2, "Connection %d: RTSP channel unexpectedly closed -- will try again %d time(s).",
+ debug(2,
+ "Connection %d: RTSP channel unexpectedly closed -- will try again %d time(s).",
conn->connection_number, rtsp_read_request_attempt_count);
if (reply == rtsp_read_request_response_read_error)
debug(2, "Connection %d: RTSP channel read error -- will try again %d time(s).",
tstop = 1;
}
} else {
- debug(1, "Connection %d: rtsp_read_request error %d, packet ignored.", conn->connection_number, (int)reply);
+ debug(1, "Connection %d: rtsp_read_request error %d, packet ignored.",
+ conn->connection_number, (int)reply);
}
if (tstop) {
debug(3, "Connection %d: Terminate RTSP connection.", conn->connection_number);