3.1.2 pretty-print using clang-format

This commit is contained in:
Mike Brady
2017-09-07 12:02:00 +01:00
parent bbdefd9802
commit 3001f39bc5
9 changed files with 121 additions and 99 deletions
+1 -1
View File
@@ -1004,7 +1004,7 @@ alac_file *alac_create(int samplesize, int numchannels) {
newfile->numchannels = numchannels; newfile->numchannels = numchannels;
newfile->bytespersample = (samplesize / 8) * numchannels; newfile->bytespersample = (samplesize / 8) * numchannels;
} else { } else {
fprintf(stderr, "FIXME: can not allocate memory for a new file in alac_cxreate."); fprintf(stderr, "FIXME: can not allocate memory for a new file in alac_cxreate.");
} }
return newfile; return newfile;
} }
+1 -1
View File
@@ -259,7 +259,7 @@ char *base64_enc(uint8_t *input, int length) {
BIO_get_mem_ptr(b64, &bptr); BIO_get_mem_ptr(b64, &bptr);
char *buf = (char *)malloc(bptr->length); char *buf = (char *)malloc(bptr->length);
if (buf==NULL) if (buf == NULL)
die("could not allocate memory for buf in base64_enc"); die("could not allocate memory for buf in base64_enc");
if (bptr->length) { if (bptr->length) {
memcpy(buf, bptr->data, bptr->length - 1); memcpy(buf, bptr->data, bptr->length - 1);
+22 -19
View File
@@ -710,10 +710,12 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) {
if ((conn->time_of_last_audio_packet != 0) && (conn->stop == 0) && if ((conn->time_of_last_audio_packet != 0) && (conn->stop == 0) &&
(config.dont_check_timeout == 0)) { (config.dont_check_timeout == 0)) {
uint64_t ct = config.timeout; // go from int to 64-bit int uint64_t ct = config.timeout; // go from int to 64-bit int
// if (conn->packet_count>500) { //for testing -- about 4 seconds of play first // if (conn->packet_count>500) { //for testing -- about 4 seconds of play first
if ((local_time_now > conn->time_of_last_audio_packet) && if ((local_time_now > conn->time_of_last_audio_packet) &&
(local_time_now - conn->time_of_last_audio_packet >= ct << 32)) { (local_time_now - conn->time_of_last_audio_packet >= ct << 32)) {
debug(1, "As Yeats almost said, \"Too long a silence / can make a stone of the heart\" from RTSP conversation %d.",conn->connection_number); debug(1, "As Yeats almost said, \"Too long a silence / can make a stone of the heart\" "
"from RTSP conversation %d.",
conn->connection_number);
conn->stop = 1; conn->stop = 1;
pthread_kill(conn->thread, SIGUSR1); pthread_kill(conn->thread, SIGUSR1);
} }
@@ -1830,12 +1832,13 @@ static void *player_thread_func(void *arg) {
} else if ((sync_error < 0) && ((-sync_error) > filler_length)) { } else if ((sync_error < 0) && ((-sync_error) > filler_length)) {
// debug(1, "Large negative sync error: %lld. Inserting silence.", sync_error); // debug(1, "Large negative sync error: %lld. Inserting silence.", sync_error);
size_t silence_length = -sync_error; size_t silence_length = -sync_error;
if (silence_length>(filler_length*5)) if (silence_length > (filler_length * 5))
silence_length = filler_length*5; silence_length = filler_length * 5;
char *long_silence = malloc(conn->output_bytes_per_frame * silence_length); char *long_silence = malloc(conn->output_bytes_per_frame * silence_length);
if (long_silence == NULL) if (long_silence == NULL)
die("Failed to allocate memory for a long_silence buffer of %d frames.",silence_length); die("Failed to allocate memory for a long_silence buffer of %d frames.",
silence_length);
memset(long_silence, 0, conn->output_bytes_per_frame * silence_length); memset(long_silence, 0, conn->output_bytes_per_frame * silence_length);
config.output->play((short *)long_silence, silence_length); config.output->play((short *)long_silence, silence_length);
free(long_silence); free(long_silence);
@@ -2187,8 +2190,8 @@ static void *player_thread_func(void *arg) {
rc = pthread_mutex_destroy(&conn->vol_mutex); rc = pthread_mutex_destroy(&conn->vol_mutex);
if (rc) if (rc)
debug(1, "Error destroying vol_mutex variable."); debug(1, "Error destroying vol_mutex variable.");
debug(1, "Player thread exit on RTSP conversation thread %d.",conn->connection_number); debug(1, "Player thread exit on RTSP conversation thread %d.", conn->connection_number);
if (outbuf) if (outbuf)
free(outbuf); free(outbuf);
if (silence) if (silence)
@@ -2440,7 +2443,7 @@ void player_flush(int64_t timestamp, rtsp_conn_info *conn) {
int player_play(rtsp_conn_info *conn) { int player_play(rtsp_conn_info *conn) {
// need to use conn in place of streram below. Need to put the stream as a parameter to he // need to use conn in place of streram below. Need to put the stream as a parameter to he
if (conn->player_thread!=NULL) if (conn->player_thread != NULL)
die("Trying to create a second player thread for this RTSP session"); die("Trying to create a second player thread for this RTSP session");
if (config.buffer_start_fill > BUFFER_FRAMES) if (config.buffer_start_fill > BUFFER_FRAMES)
die("specified buffer starting fill %d > buffer size %d", config.buffer_start_fill, die("specified buffer starting fill %d > buffer size %d", config.buffer_start_fill,
@@ -2450,7 +2453,7 @@ int player_play(rtsp_conn_info *conn) {
send_ssnc_metadata('pbeg', NULL, 0, 1); send_ssnc_metadata('pbeg', NULL, 0, 1);
#endif #endif
pthread_t *pt = malloc(sizeof(pthread_t)); pthread_t *pt = malloc(sizeof(pthread_t));
if (pt==NULL) if (pt == NULL)
die("Couldn't allocate space for pthread_t"); die("Couldn't allocate space for pthread_t");
conn->player_thread = pt; conn->player_thread = pt;
size_t size = (PTHREAD_STACK_MIN + 256 * 1024); size_t size = (PTHREAD_STACK_MIN + 256 * 1024);
@@ -2466,17 +2469,17 @@ int player_play(rtsp_conn_info *conn) {
void player_stop(rtsp_conn_info *conn) { void player_stop(rtsp_conn_info *conn) {
if (conn->player_thread) { if (conn->player_thread) {
conn->player_thread_please_stop = 1; conn->player_thread_please_stop = 1;
pthread_cond_signal(&conn->flowcontrol); // tell it to give up pthread_cond_signal(&conn->flowcontrol); // tell it to give up
pthread_kill(*conn->player_thread, SIGUSR1); pthread_kill(*conn->player_thread, SIGUSR1);
pthread_join(*conn->player_thread, NULL); pthread_join(*conn->player_thread, NULL);
#ifdef CONFIG_METADATA #ifdef CONFIG_METADATA
send_ssnc_metadata('pend', NULL, 0, 1); send_ssnc_metadata('pend', NULL, 0, 1);
#endif #endif
command_stop(); command_stop();
free(conn->player_thread); free(conn->player_thread);
conn->player_thread = NULL; conn->player_thread = NULL;
} else { } else {
debug(3,"player thread of RTSP conversation %d is already deleted.",conn->connection_number); debug(3, "player thread of RTSP conversation %d is already deleted.", conn->connection_number);
} }
} }
+1 -1
View File
@@ -60,7 +60,7 @@ typedef struct {
int stop; int stop;
int running; int running;
pthread_t thread; pthread_t thread;
// pthread_t *ptp; // pthread_t *ptp;
pthread_t *player_thread; pthread_t *player_thread;
+7 -5
View File
@@ -254,7 +254,8 @@ void *rtp_control_receiver(void *arg) {
debug(3, "Too-short retransmitted audio packet received in control port, ignored."); debug(3, "Too-short retransmitted audio packet received in control port, ignored.");
} }
} else } else
debug(1, "Control Port -- Unknown RTP packet of type 0x%02X length %d, ignored.", packet[1], nread); debug(1, "Control Port -- Unknown RTP packet of type 0x%02X length %d, ignored.", packet[1],
nread);
} }
debug(3, "Control RTP thread interrupted. terminating."); debug(3, "Control RTP thread interrupted. terminating.");
@@ -290,7 +291,8 @@ void *rtp_timing_sender(void *arg) {
// debug(1,"Send a timing request"); // debug(1,"Send a timing request");
if (!conn->rtp_running) if (!conn->rtp_running)
debug(1,"rtp_timing_sender called without active stream in RTSP conversation thread %d!",conn->connection_number); debug(1, "rtp_timing_sender called without active stream in RTSP conversation thread %d!",
conn->connection_number);
// debug(1, "Requesting ntp timestamp exchange."); // debug(1, "Requesting ntp timestamp exchange.");
@@ -639,8 +641,8 @@ void rtp_setup(SOCKADDR *local, SOCKADDR *remote, int cport, int tport, uint32_t
inet_ntop(conn->connection_ip_family, self_addr, conn->self_ip_string, inet_ntop(conn->connection_ip_family, self_addr, conn->self_ip_string,
sizeof(conn->self_ip_string)); sizeof(conn->self_ip_string));
debug(1, "Set up play connection from %s to self at %s on RTSP conversation thread %d.", conn->client_ip_string, debug(1, "Set up play connection from %s to self at %s on RTSP conversation thread %d.",
conn->self_ip_string, conn->connection_number); conn->client_ip_string, conn->self_ip_string, conn->connection_number);
// set up a the record of the remote's control socket // set up a the record of the remote's control socket
struct addrinfo hints; struct addrinfo hints;
@@ -713,7 +715,7 @@ void get_reference_timestamp_stuff(int64_t *timestamp, uint64_t *timestamp_time,
pthread_mutex_lock(&conn->reference_time_mutex); pthread_mutex_lock(&conn->reference_time_mutex);
*timestamp = conn->reference_timestamp; *timestamp = conn->reference_timestamp;
*timestamp_time = conn->reference_timestamp_time; *timestamp_time = conn->reference_timestamp_time;
//if ((*timestamp == 0) && (*timestamp_time == 0)) { // if ((*timestamp == 0) && (*timestamp_time == 0)) {
// debug(1,"Reference timestamp is invalid."); // debug(1,"Reference timestamp is invalid.");
//} //}
*remote_timestamp_time = conn->remote_reference_timestamp_time; *remote_timestamp_time = conn->remote_reference_timestamp_time;
+75 -60
View File
@@ -266,9 +266,10 @@ static void cleanup_threads(void) {
// debug(2, "culling threads."); // debug(2, "culling threads.");
for (i = 0; i < nconns;) { for (i = 0; i < nconns;) {
if (conns[i]->running == 0) { if (conns[i]->running == 0) {
debug(3, "found RTSP connection thread %d in a non-running state.",conns[i]->connection_number); debug(3, "found RTSP connection thread %d in a non-running state.",
conns[i]->connection_number);
pthread_join(conns[i]->thread, &retval); pthread_join(conns[i]->thread, &retval);
debug(3, "RTSP connection thread %d deleted...",conns[i]->connection_number); debug(3, "RTSP connection thread %d deleted...", conns[i]->connection_number);
free(conns[i]); free(conns[i]);
nconns--; nconns--;
if (nconns) if (nconns)
@@ -467,7 +468,7 @@ static enum rtsp_read_request_response rtsp_read_request(rtsp_conn_info *conn,
while (msg_size < 0) { while (msg_size < 0) {
memory_barrier(); memory_barrier();
if (conn->stop != 0) { if (conn->stop != 0) {
debug(3, "RTSP conversation thread %d shutdown requested.",conn->connection_number); debug(3, "RTSP conversation thread %d shutdown requested.", conn->connection_number);
reply = rtsp_read_request_response_immediate_shutdown_requested; reply = rtsp_read_request_response_immediate_shutdown_requested;
goto shutdown; goto shutdown;
} }
@@ -475,7 +476,7 @@ static enum rtsp_read_request_response rtsp_read_request(rtsp_conn_info *conn,
if (nread == 0) { if (nread == 0) {
// a blocking read that returns zero means eof -- implies connection closed // a blocking read that returns zero means eof -- implies connection closed
debug(3, "RTSP conversation thread %d -- connection closed.",conn->connection_number); debug(3, "RTSP conversation thread %d -- connection closed.", conn->connection_number);
reply = rtsp_read_request_response_channel_closed; reply = rtsp_read_request_response_channel_closed;
goto shutdown; goto shutdown;
} }
@@ -602,7 +603,7 @@ static void msg_write_response(int fd, rtsp_message *resp) {
} }
static void handle_record(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) { static void handle_record(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) {
debug(3,"Connection %d: RECORD",conn->connection_number); debug(3, "Connection %d: RECORD", conn->connection_number);
resp->respcode = 200; resp->respcode = 200;
// I think this is for telling the client what the absolute minimum latency // I think this is for telling the client what the absolute minimum latency
// actually is, // actually is,
@@ -637,7 +638,7 @@ static void handle_record(rtsp_conn_info *conn, rtsp_message *req, rtsp_message
} }
static void handle_options(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) { static void handle_options(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) {
debug(3, "Connection %d: OPTIONS",conn->connection_number); debug(3, "Connection %d: OPTIONS", conn->connection_number);
resp->respcode = 200; resp->respcode = 200;
msg_add_header(resp, "Public", "ANNOUNCE, SETUP, RECORD, " msg_add_header(resp, "Public", "ANNOUNCE, SETUP, RECORD, "
"PAUSE, FLUSH, TEARDOWN, " "PAUSE, FLUSH, TEARDOWN, "
@@ -645,25 +646,28 @@ static void handle_options(rtsp_conn_info *conn, rtsp_message *req, rtsp_message
} }
static void handle_teardown(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) { static void handle_teardown(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) {
debug(3, "Connection %d: TEARDOWN",conn->connection_number); debug(3, "Connection %d: TEARDOWN", conn->connection_number);
//if (!rtsp_playing()) // if (!rtsp_playing())
// debug(1, "This RTSP connection thread (%d) doesn't think it's playing, but " // debug(1, "This RTSP connection thread (%d) doesn't think it's playing, but "
// "it's sending a response to teardown anyway",conn->connection_number); // "it's sending a response to teardown anyway",conn->connection_number);
resp->respcode = 200; resp->respcode = 200;
msg_add_header(resp, "Connection", "close"); msg_add_header(resp, "Connection", "close");
debug(3, "TEARDOWN: synchronously terminating the player thread of RTSP conversation thread %d (2).",conn->connection_number); debug(3,
//if (rtsp_playing()) { "TEARDOWN: synchronously terminating the player thread of RTSP conversation thread %d (2).",
player_stop(conn); conn->connection_number);
debug(3, "TEARDOWN: successful termination of playing thread of RTSP conversation thread %d.",conn->connection_number); // if (rtsp_playing()) {
//} player_stop(conn);
debug(3, "TEARDOWN: successful termination of playing thread of RTSP conversation thread %d.",
conn->connection_number);
//}
} }
static void handle_flush(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) { static void handle_flush(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) {
debug(3, "Connection %d: FLUSH",conn->connection_number); debug(3, "Connection %d: FLUSH", conn->connection_number);
// if (!rtsp_playing()) // if (!rtsp_playing())
// debug(1, "This RTSP conversation thread (%d) doesn't think it's playing, but " // debug(1, "This RTSP conversation thread (%d) doesn't think it's playing, but "
// "it's sending a response to flush anyway",conn->connection_number); // "it's sending a response to flush anyway",conn->connection_number);
char *p = NULL; char *p = NULL;
uint32_t rtptime = 0; uint32_t rtptime = 0;
char *hdr = msg_get_header(req, "RTP-Info"); char *hdr = msg_get_header(req, "RTP-Info");
@@ -690,7 +694,7 @@ static void handle_flush(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *
} }
static void handle_setup(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) { static void handle_setup(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) {
debug(3,"Connection %d: SETUP",conn->connection_number); debug(3, "Connection %d: SETUP", conn->connection_number);
int cport, tport; int cport, tport;
int lsport, lcport, ltport; int lsport, lcport, ltport;
uint32_t active_remote = 0; uint32_t active_remote = 0;
@@ -828,14 +832,15 @@ static void handle_setup(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *
return; return;
error: error:
warn("Error in setup request -- unlocking play lock on RTSP conversation thread %d.",conn->connection_number); warn("Error in setup request -- unlocking play lock on RTSP conversation thread %d.",
conn->connection_number);
playing_conn = NULL; playing_conn = NULL;
pthread_mutex_unlock(&play_lock); pthread_mutex_unlock(&play_lock);
resp->respcode = 451; // invalid arguments resp->respcode = 451; // invalid arguments
} }
static void handle_ignore(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) { static void handle_ignore(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) {
debug(1, "Connection thread %d: IGNORE",conn->connection_number); debug(1, "Connection thread %d: IGNORE", conn->connection_number);
resp->respcode = 200; resp->respcode = 200;
} }
@@ -1289,12 +1294,12 @@ static void handle_set_parameter_metadata(rtsp_conn_info *conn, rtsp_message *re
#endif #endif
static void handle_get_parameter(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) { static void handle_get_parameter(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) {
debug(3,"Connection %d: GET_PARAMETER",conn->connection_number); debug(3, "Connection %d: GET_PARAMETER", conn->connection_number);
resp->respcode = 200; resp->respcode = 200;
} }
static void handle_set_parameter(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) { static void handle_set_parameter(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) {
debug(3,"Connection %d: SET_PARAMETER",conn->connection_number); debug(3, "Connection %d: SET_PARAMETER", conn->connection_number);
// if (!req->contentlength) // if (!req->contentlength)
// debug(1, "received empty SET_PARAMETER request."); // debug(1, "received empty SET_PARAMETER request.");
@@ -1385,29 +1390,32 @@ 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) { static void handle_announce(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) {
debug(3,"Connection %d: ANNOUNCE",conn->connection_number); debug(3, "Connection %d: ANNOUNCE", conn->connection_number);
int have_the_player = 0; int have_the_player = 0;
// interrupt session if permitted // interrupt session if permitted
if (pthread_mutex_trylock(&play_lock) == 0) { if (pthread_mutex_trylock(&play_lock) == 0) {
have_the_player = 1; have_the_player = 1;
} else { } else {
if (playing_conn) { if (playing_conn) {
debug(1,"RTSP Conversation thread %d already playing when asked by thread %d.",playing_conn->connection_number,conn->connection_number); debug(1, "RTSP Conversation thread %d already playing when asked by thread %d.",
} else { playing_conn->connection_number, conn->connection_number);
debug(1,"play_lock locked but no playing_conn."); } else {
} debug(1, "play_lock locked but no playing_conn.");
}
if (config.allow_session_interruption == 1) { if (config.allow_session_interruption == 1) {
// some other thread has the player ... ask it to relinquish the thread // some other thread has the player ... ask it to relinquish the thread
if (playing_conn) { if (playing_conn) {
debug(1, "ANNOUNCE: playing connection %d being interrupted by connection %d.",playing_conn->connection_number,conn->connection_number); debug(1, "ANNOUNCE: playing connection %d being interrupted by connection %d.",
playing_conn->connection_number, conn->connection_number);
if (playing_conn == conn) { if (playing_conn == conn) {
debug(1, "ANNOUNCE asking to stop itself."); debug(1, "ANNOUNCE asking to stop itself.");
} else { } else {
playing_conn->stop = 1; playing_conn->stop = 1;
memory_barrier(); memory_barrier();
pthread_kill(playing_conn->thread, SIGUSR1); pthread_kill(playing_conn->thread, SIGUSR1);
usleep(1000000); // here, it is possible for other connections to come in and nab the player. usleep(
1000000); // here, it is possible for other connections to come in and nab the player.
} }
} else { } else {
die("Non existent the_playing_conn with play_lock enabled."); die("Non existent the_playing_conn with play_lock enabled.");
@@ -1422,8 +1430,8 @@ static void handle_announce(rtsp_conn_info *conn, rtsp_message *req, rtsp_messag
} }
if (have_the_player) { if (have_the_player) {
playing_conn = conn; // the present connection is now playing playing_conn = conn; // the present connection is now playing
debug(3,"RTSP conversation thread %d has acquired play lock.",conn->connection_number); debug(3, "RTSP conversation thread %d has acquired play lock.", conn->connection_number);
resp->respcode = 456; // 456 - Header Field Not Valid for Resource resp->respcode = 456; // 456 - Header Field Not Valid for Resource
char *paesiv = NULL; char *paesiv = NULL;
char *prsaaeskey = NULL; char *prsaaeskey = NULL;
@@ -1502,14 +1510,16 @@ static void handle_announce(rtsp_conn_info *conn, rtsp_message *req, rtsp_messag
char *hdr = msg_get_header(req, "X-Apple-Client-Name"); char *hdr = msg_get_header(req, "X-Apple-Client-Name");
if (hdr) { if (hdr) {
debug(1, "Play connection from device named \"%s\" on RTSP conversation thread %d.", hdr,conn->connection_number); debug(1, "Play connection from device named \"%s\" on RTSP conversation thread %d.", hdr,
conn->connection_number);
#ifdef CONFIG_METADATA #ifdef CONFIG_METADATA
send_metadata('ssnc', 'snam', hdr, strlen(hdr), req, 1); send_metadata('ssnc', 'snam', hdr, strlen(hdr), req, 1);
#endif #endif
} }
hdr = msg_get_header(req, "User-Agent"); hdr = msg_get_header(req, "User-Agent");
if (hdr) { if (hdr) {
debug(1, "Play connection from user agent \"%s\" on RTSP conversation thread %d.", hdr,conn->connection_number); debug(1, "Play connection from user agent \"%s\" on RTSP conversation thread %d.", hdr,
conn->connection_number);
#ifdef CONFIG_METADATA #ifdef CONFIG_METADATA
send_metadata('ssnc', 'snua', hdr, strlen(hdr), req, 1); send_metadata('ssnc', 'snua', hdr, strlen(hdr), req, 1);
#endif #endif
@@ -1522,7 +1532,8 @@ static void handle_announce(rtsp_conn_info *conn, rtsp_message *req, rtsp_messag
out: out:
if (resp->respcode != 200 && resp->respcode != 453) { if (resp->respcode != 200 && resp->respcode != 453) {
debug(1,"Error in handling ANNOUNCE on conversation thread %d. Unlocking the play lock.",conn->connection_number); debug(1, "Error in handling ANNOUNCE on conversation thread %d. Unlocking the play lock.",
conn->connection_number);
playing_conn = NULL; playing_conn = NULL;
pthread_mutex_unlock(&play_lock); pthread_mutex_unlock(&play_lock);
} }
@@ -1552,7 +1563,7 @@ static void apple_challenge(int fd, rtsp_message *req, rtsp_message *resp) {
int chall_len; int chall_len;
uint8_t *chall = base64_dec(hdr, &chall_len); uint8_t *chall = base64_dec(hdr, &chall_len);
if (chall==NULL) if (chall == NULL)
die("null chall in apple_challenge"); die("null chall in apple_challenge");
uint8_t buf[48], *bp = buf; uint8_t buf[48], *bp = buf;
int i; int i;
@@ -1590,7 +1601,7 @@ static void apple_challenge(int fd, rtsp_message *req, rtsp_message *resp) {
uint8_t *challresp = rsa_apply(buf, buflen, &resplen, RSA_MODE_AUTH); uint8_t *challresp = rsa_apply(buf, buflen, &resplen, RSA_MODE_AUTH);
char *encoded = base64_enc(challresp, resplen); char *encoded = base64_enc(challresp, resplen);
if (encoded==NULL) if (encoded == NULL)
die("could not allocate memory for \"encoded\""); die("could not allocate memory for \"encoded\"");
// strip the padding. // strip the padding.
char *padding = strchr(encoded, '='); char *padding = strchr(encoded, '=');
@@ -1775,11 +1786,12 @@ static void *rtsp_conversation_thread_func(void *pconn) {
char *hdr, *auth_nonce = NULL; char *hdr, *auth_nonce = NULL;
enum rtsp_read_request_response reply; enum rtsp_read_request_response reply;
while (conn->stop==0) { while (conn->stop == 0) {
reply = rtsp_read_request(conn, &req); reply = rtsp_read_request(conn, &req);
if (reply == rtsp_read_request_response_ok) { if (reply == rtsp_read_request_response_ok) {
debug(3, "RTSP thread %d received an RTSP Packet of type \"%s\":",conn->connection_number, req->method), debug(3, "RTSP thread %d received an RTSP Packet of type \"%s\":", conn->connection_number,
req->method),
debug_print_msg_headers(3, req); debug_print_msg_headers(3, req);
resp = msg_init(); resp = msg_init();
resp->respcode = 400; resp->respcode = 400;
@@ -1803,22 +1815,25 @@ static void *rtsp_conversation_thread_func(void *pconn) {
} }
} }
if (method_selected == 0) if (method_selected == 0)
debug(1, "RTSP thread %d: Unrecognised and unhandled rtsp request \"%s\".",conn->connection_number, req->method); debug(1, "RTSP thread %d: Unrecognised and unhandled rtsp request \"%s\".",
conn->connection_number, req->method);
} }
debug(3, "RTSP thread %d: RTSP Response:",conn->connection_number); debug(3, "RTSP thread %d: RTSP Response:", conn->connection_number);
debug_print_msg_headers(3, resp); debug_print_msg_headers(3, resp);
msg_write_response(conn->fd, resp); msg_write_response(conn->fd, resp);
msg_free(req); msg_free(req);
msg_free(resp); msg_free(resp);
} else { } else {
if ((reply==rtsp_read_request_response_immediate_shutdown_requested) || if ((reply == rtsp_read_request_response_immediate_shutdown_requested) ||
(reply==rtsp_read_request_response_channel_closed)) { (reply == rtsp_read_request_response_channel_closed)) {
debug(3, "Synchronously terminate playing thread of RTSP conversation thread %d.",conn->connection_number); debug(3, "Synchronously terminate playing thread of RTSP conversation thread %d.",
conn->connection_number);
player_stop(conn); player_stop(conn);
debug(3, "Successful termination of playing thread of RTSP conversation thread %d.",conn->connection_number); debug(3, "Successful termination of playing thread of RTSP conversation thread %d.",
debug(3, "Request termination of RTSP conversation thread %d.",conn->connection_number); conn->connection_number);
conn->stop = 1; debug(3, "Request termination of RTSP conversation thread %d.", conn->connection_number);
} else { conn->stop = 1;
} else {
debug(1, "rtsp_read_request error %d, packet ignored.", (int)reply); debug(1, "rtsp_read_request error %d, packet ignored.", (int)reply);
} }
} }
@@ -1829,12 +1844,12 @@ static void *rtsp_conversation_thread_func(void *pconn) {
if (auth_nonce) if (auth_nonce)
free(auth_nonce); free(auth_nonce);
rtp_terminate(conn); rtp_terminate(conn);
if (playing_conn==conn) { if (playing_conn == conn) {
debug(3,"Unlocking play lock on RTSP conversation thread %d.",conn->connection_number); debug(3, "Unlocking play lock on RTSP conversation thread %d.", conn->connection_number);
playing_conn = NULL; playing_conn = NULL;
pthread_mutex_unlock(&play_lock); pthread_mutex_unlock(&play_lock);
} }
debug(1, "RTSP conversation thread %d terminated.",conn->connection_number); debug(1, "RTSP conversation thread %d terminated.", conn->connection_number);
// please_shutdown = 0; // please_shutdown = 0;
conn->running = 0; conn->running = 0;
return NULL; return NULL;
@@ -2011,8 +2026,8 @@ void rtsp_listen_loop(void) {
send_ssnc_metadata('clip', strdup(remote_ip4), strlen(remote_ip4), 1); send_ssnc_metadata('clip', strdup(remote_ip4), strlen(remote_ip4), 1);
send_ssnc_metadata('svip', strdup(ip4), strlen(ip4), 1); send_ssnc_metadata('svip', strdup(ip4), strlen(ip4), 1);
#endif #endif
debug(1, "New RTSP connection from %s:%u to self at %s:%u on conversation thread %d.", remote_ip4, rport, ip4, debug(1, "New RTSP connection from %s:%u to self at %s:%u on conversation thread %d.",
tport,conn->connection_number); remote_ip4, rport, ip4, tport, conn->connection_number);
} }
#ifdef AF_INET6 #ifdef AF_INET6
if (local_info->SAFAMILY == AF_INET6) { if (local_info->SAFAMILY == AF_INET6) {
@@ -2032,8 +2047,8 @@ void rtsp_listen_loop(void) {
send_ssnc_metadata('clip', strdup(remote_ip6), strlen(remote_ip6), 1); send_ssnc_metadata('clip', strdup(remote_ip6), strlen(remote_ip6), 1);
send_ssnc_metadata('svip', strdup(ip6), strlen(ip6), 1); send_ssnc_metadata('svip', strdup(ip6), strlen(ip6), 1);
#endif #endif
debug(1, "New RTSP connection from [%s]:%u to self at [%s]:%u on conversation thread %d.", remote_ip6, rport, ip6, debug(1, "New RTSP connection from [%s]:%u to self at [%s]:%u on conversation thread %d.",
tport,conn->connection_number); remote_ip6, rport, ip6, tport, conn->connection_number);
} }
#endif #endif
@@ -2048,8 +2063,8 @@ void rtsp_listen_loop(void) {
ret = pthread_create(&conn->thread, NULL, rtsp_conversation_thread_func, ret = pthread_create(&conn->thread, NULL, rtsp_conversation_thread_func,
conn); // also acts as a memory barrier conn); // also acts as a memory barrier
if (ret) if (ret)
die("Failed to create RTSP receiver thread %d!",conn->connection_number); die("Failed to create RTSP receiver thread %d!", conn->connection_number);
debug(3,"Successfully created RTSP receiver thread %d.",conn->connection_number); debug(3, "Successfully created RTSP receiver thread %d.", conn->connection_number);
conn->running = 1; // this must happen before the thread is tracked conn->running = 1; // this must happen before the thread is tracked
track_thread(conn); track_thread(conn);
} }
+8 -6
View File
@@ -478,10 +478,11 @@ int parse_options(int argc, char **argv) {
config.packet_stuffing = ST_basic; config.packet_stuffing = ST_basic;
else if (strcasecmp(str, "soxr") == 0) else if (strcasecmp(str, "soxr") == 0)
#ifdef HAVE_LIBSOXR #ifdef HAVE_LIBSOXR
config.packet_stuffing = ST_soxr; config.packet_stuffing = ST_soxr;
#else #else
die("The soxr option not available because this version of shairport-sync was built without libsoxr " die("The soxr option not available because this version of shairport-sync was built "
"support. Change the \"general/interpolation\" setting in the configuration file."); "without libsoxr "
"support. Change the \"general/interpolation\" setting in the configuration file.");
#endif #endif
else else
die("Invalid interpolation option choice. It should be \"basic\" or \"soxr\""); die("Invalid interpolation option choice. It should be \"basic\" or \"soxr\"");
@@ -848,7 +849,8 @@ int parse_options(int argc, char **argv) {
#ifdef HAVE_LIBSOXR #ifdef HAVE_LIBSOXR
config.packet_stuffing = ST_soxr; config.packet_stuffing = ST_soxr;
#else #else
die("The soxr option not available because this version of shairport-sync was built without libsoxr " die("The soxr option not available because this version of shairport-sync was built "
"without libsoxr "
"support. Change the -S option setting."); "support. Change the -S option setting.");
#endif #endif
else else
@@ -971,7 +973,7 @@ int main(int argc, char **argv) {
char *basec = strdup(argv[0]); char *basec = strdup(argv[0]);
char *bname = basename(basec); char *bname = basename(basec);
appName = strdup(bname); appName = strdup(bname);
if (appName==NULL) if (appName == NULL)
die("can not allocate memory for the app name!"); die("can not allocate memory for the app name!");
free(basec); free(basec);
@@ -996,7 +998,7 @@ int main(int argc, char **argv) {
endianness = SS_BIG_ENDIAN; endianness = SS_BIG_ENDIAN;
else else
die("Can not recognise the endianness of the processor."); die("Can not recognise the endianness of the processor.");
// set non-zero / non-NULL default values here // set non-zero / non-NULL default values here
// but note that audio back ends also have a chance to set defaults // but note that audio back ends also have a chance to set defaults
+4 -4
View File
@@ -127,7 +127,7 @@ char *nlabel_to_str(const uint8_t *name) {
assert(name != NULL); assert(name != NULL);
label = labelp = malloc(256); label = labelp = malloc(256);
if (label) { if (label) {
for (p = name; *p; p++) { for (p = name; *p; p++) {
strncpy(labelp, (char *)p + 1, *p); strncpy(labelp, (char *)p + 1, *p);
@@ -820,8 +820,8 @@ struct mdns_pkt *mdns_parse_pkt(uint8_t *pkt_buf, size_t pkt_len) {
return NULL; return NULL;
MALLOC_ZERO_STRUCT(pkt, mdns_pkt); MALLOC_ZERO_STRUCT(pkt, mdns_pkt);
if (pkt==NULL) if (pkt == NULL)
die("cannot allocate memory for \"pkt\" in tinysvcmdns.c."); die("cannot allocate memory for \"pkt\" in tinysvcmdns.c.");
// parse header // parse header
@@ -1600,7 +1600,7 @@ struct mdns_service *mdnsd_register_svc(struct mdnsd *svr, const char *instance_
if (inst_nlabel) { if (inst_nlabel) {
nlabel = join_nlabel(inst_nlabel, type_nlabel); nlabel = join_nlabel(inst_nlabel, type_nlabel);
} else { } else {
die("could not allocate memory for \"inst_nlabel\" in tinysvcmdns"); die("could not allocate memory for \"inst_nlabel\" in tinysvcmdns");
} }
// create TXT record // create TXT record
+2 -2
View File
@@ -47,8 +47,8 @@
#define MALLOC_ZERO_STRUCT(x, type) \ #define MALLOC_ZERO_STRUCT(x, type) \
x = malloc(sizeof(struct type)); \ x = malloc(sizeof(struct type)); \
if (x) \ if (x) \
memset(x, 0, sizeof(struct type)); memset(x, 0, sizeof(struct type));
#define DECL_MALLOC_ZERO_STRUCT(x, type) struct type *MALLOC_ZERO_STRUCT(x, type) #define DECL_MALLOC_ZERO_STRUCT(x, type) struct type *MALLOC_ZERO_STRUCT(x, type)