Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebrady committed Nov 24, 2018
1 parent a932298 commit 998e7ce
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 79 deletions.
20 changes: 9 additions & 11 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,16 @@ sigset_t pselect_sigset;

static uint16_t UDPPortIndex = 0;

void resetFreeUDPPort() {
UDPPortIndex = 0;
}
void resetFreeUDPPort() { UDPPortIndex = 0; }

uint16_t nextFreeUDPPort() {
if (UDPPortIndex == 0)
UDPPortIndex = config.udp_port_base;
else if (UDPPortIndex == (config.udp_port_base + config.udp_port_range - 1))
UDPPortIndex = config.udp_port_base;
else
UDPPortIndex++;
return UDPPortIndex;
uint16_t nextFreeUDPPort() {
if (UDPPortIndex == 0)
UDPPortIndex = config.udp_port_base;
else if (UDPPortIndex == (config.udp_port_base + config.udp_port_range - 1))
UDPPortIndex = config.udp_port_base;
else
UDPPortIndex++;
return UDPPortIndex;
}

int get_requested_connection_state_to_output() { return requested_connection_state_to_output; }
Expand Down
44 changes: 22 additions & 22 deletions player.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,15 +464,16 @@ void player_put_packet(seq_t seqno, uint32_t actual_timestamp, uint8_t *data, in
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;

Expand Down Expand Up @@ -851,10 +852,11 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) {
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) <
Expand Down Expand Up @@ -953,11 +955,9 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *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,
"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);
}
}
}
Expand Down Expand Up @@ -988,7 +988,7 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *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;

Expand Down Expand Up @@ -2476,8 +2476,8 @@ void *player_thread_func(void *arg) {

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);
}

Expand Down Expand Up @@ -2776,7 +2776,7 @@ int player_play(rtsp_conn_info *conn) {

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) {
Expand Down
25 changes: 14 additions & 11 deletions rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void rtp_audio_receiver_cleanup_handler(void *arg) {
shutdown(conn->audio_socket, SHUT_RDWR);
debug(3, "close audio socket.");
close(conn->audio_socket);

debug(3, "Audio Receiver Cleanup Successful.");
}

Expand Down Expand Up @@ -170,8 +170,8 @@ void *rtp_audio_receiver(void *arg) {
// 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;
Expand All @@ -181,8 +181,8 @@ void *rtp_audio_receiver(void *arg) {
};
*obfp=0;
debug(1,"Audio Packet Received: \"%s\"",obf);
*/
*/

if (last_seqno == -1)
last_seqno = seqno;
else {
Expand All @@ -196,7 +196,7 @@ void *rtp_audio_receiver(void *arg) {
}

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);

Expand Down Expand Up @@ -308,8 +308,10 @@ void *rtp_control_receiver(void *arg) {
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
Expand Down Expand Up @@ -860,8 +862,8 @@ static uint16_t bind_port(int ip_family, const char *self_ip_address, uint32_t s
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;
Expand All @@ -888,7 +890,8 @@ static uint16_t bind_port(int ip_family, const char *self_ip_address, uint32_t s

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!");
}

Expand Down
74 changes: 39 additions & 35 deletions rtsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,8 @@ enum rtsp_read_request_response rtsp_read_request(rtsp_conn_info *conn, rtsp_mes
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;
}
Expand Down Expand Up @@ -896,7 +897,7 @@ void handle_setup(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) {
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
Expand Down Expand Up @@ -1522,51 +1523,51 @@ static void handle_set_parameter(rtsp_conn_info *conn, rtsp_message *req, rtsp_m

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);
Expand All @@ -1577,14 +1578,14 @@ static void handle_announce(rtsp_conn_info *conn, rtsp_message *req, rtsp_messag

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;
Expand All @@ -1597,8 +1598,7 @@ static void handle_announce(rtsp_conn_info *conn, rtsp_message *req, rtsp_messag
}
}
*/



resp->respcode = 456; // 456 - Header Field Not Valid for Resource
char *pssid = NULL;
char *paesiv = NULL;
Expand Down Expand Up @@ -1643,11 +1643,11 @@ static void handle_announce(rtsp_conn_info *conn, rtsp_message *req, rtsp_messag

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);
Expand Down Expand Up @@ -1751,7 +1751,7 @@ static void handle_announce(rtsp_conn_info *conn, rtsp_message *req, rtsp_messag
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);
}
Expand Down Expand Up @@ -2007,7 +2007,7 @@ void rtsp_conversation_thread_cleanup_function(void *arg) {
conn->auth_nonce = NULL;
}
rtp_terminate(conn);

if (conn->dacp_id) {
free(conn->dacp_id);
conn->dacp_id = NULL;
Expand All @@ -2025,7 +2025,7 @@ void rtsp_conversation_thread_cleanup_function(void *arg) {
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;
Expand Down Expand Up @@ -2141,7 +2141,9 @@ static void *rtsp_conversation_thread_func(void *pconn) {
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;
}
}
Expand All @@ -2161,7 +2163,8 @@ static void *rtsp_conversation_thread_func(void *pconn) {
// 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).",
Expand All @@ -2172,7 +2175,8 @@ static void *rtsp_conversation_thread_func(void *pconn) {
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);
Expand Down

0 comments on commit 998e7ce

Please sign in to comment.