if ((conn->time_of_last_audio_packet != 0) && (conn->stop == 0) &&
(config.dont_check_timeout == 0)) {
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) &&
(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;
pthread_kill(conn->thread, SIGUSR1);
}
} else if ((sync_error < 0) && ((-sync_error) > filler_length)) {
// debug(1, "Large negative sync error: %lld. Inserting silence.", sync_error);
size_t silence_length = -sync_error;
- if (silence_length>(filler_length*5))
- silence_length = filler_length*5;
-
+ if (silence_length > (filler_length * 5))
+ silence_length = filler_length * 5;
+
char *long_silence = malloc(conn->output_bytes_per_frame * silence_length);
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);
config.output->play((short *)long_silence, silence_length);
free(long_silence);
rc = pthread_mutex_destroy(&conn->vol_mutex);
if (rc)
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)
free(outbuf);
if (silence)
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
- if (conn->player_thread!=NULL)
+ if (conn->player_thread != NULL)
die("Trying to create a second player thread for this RTSP session");
if (config.buffer_start_fill > BUFFER_FRAMES)
die("specified buffer starting fill %d > buffer size %d", config.buffer_start_fill,
send_ssnc_metadata('pbeg', NULL, 0, 1);
#endif
pthread_t *pt = malloc(sizeof(pthread_t));
- if (pt==NULL)
+ if (pt == NULL)
die("Couldn't allocate space for pthread_t");
conn->player_thread = pt;
size_t size = (PTHREAD_STACK_MIN + 256 * 1024);
void player_stop(rtsp_conn_info *conn) {
if (conn->player_thread) {
- conn->player_thread_please_stop = 1;
- pthread_cond_signal(&conn->flowcontrol); // tell it to give up
- pthread_kill(*conn->player_thread, SIGUSR1);
- pthread_join(*conn->player_thread, NULL);
+ conn->player_thread_please_stop = 1;
+ pthread_cond_signal(&conn->flowcontrol); // tell it to give up
+ pthread_kill(*conn->player_thread, SIGUSR1);
+ pthread_join(*conn->player_thread, NULL);
#ifdef CONFIG_METADATA
- send_ssnc_metadata('pend', NULL, 0, 1);
+ send_ssnc_metadata('pend', NULL, 0, 1);
#endif
- command_stop();
- free(conn->player_thread);
- conn->player_thread = NULL;
+ command_stop();
+ free(conn->player_thread);
+ conn->player_thread = NULL;
} 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);
}
}
// debug(2, "culling threads.");
for (i = 0; i < nconns;) {
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);
- 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]);
nconns--;
if (nconns)
while (msg_size < 0) {
memory_barrier();
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;
goto shutdown;
}
if (nread == 0) {
// 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;
goto shutdown;
}
}
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;
// I think this is for telling the client what the absolute minimum latency
// actually is,
}
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;
msg_add_header(resp, "Public", "ANNOUNCE, SETUP, RECORD, "
"PAUSE, FLUSH, TEARDOWN, "
}
static void handle_teardown(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) {
- debug(3, "Connection %d: TEARDOWN",conn->connection_number);
- //if (!rtsp_playing())
+ debug(3, "Connection %d: TEARDOWN", conn->connection_number);
+ // if (!rtsp_playing())
// 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);
resp->respcode = 200;
msg_add_header(resp, "Connection", "close");
-
- debug(3, "TEARDOWN: synchronously terminating the player thread of RTSP conversation thread %d (2).",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);
- //}
+
+ debug(3,
+ "TEARDOWN: synchronously terminating the player thread of RTSP conversation thread %d (2).",
+ 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) {
- debug(3, "Connection %d: FLUSH",conn->connection_number);
-// if (!rtsp_playing())
-// 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);
+ debug(3, "Connection %d: FLUSH", conn->connection_number);
+ // if (!rtsp_playing())
+ // 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);
char *p = NULL;
uint32_t rtptime = 0;
char *hdr = msg_get_header(req, "RTP-Info");
}
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 lsport, lcport, ltport;
uint32_t active_remote = 0;
return;
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;
pthread_mutex_unlock(&play_lock);
resp->respcode = 451; // invalid arguments
}
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;
}
#endif
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;
}
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)
// debug(1, "received empty SET_PARAMETER request.");
}
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;
// interrupt session if permitted
if (pthread_mutex_trylock(&play_lock) == 0) {
have_the_player = 1;
} else {
- if (playing_conn) {
- debug(1,"RTSP Conversation thread %d already playing when asked by thread %d.",playing_conn->connection_number,conn->connection_number);
- } else {
- debug(1,"play_lock locked but no 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);
+ } else {
+ debug(1, "play_lock locked but no playing_conn.");
+ }
if (config.allow_session_interruption == 1) {
// some other thread has the player ... ask it to relinquish the thread
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) {
debug(1, "ANNOUNCE asking to stop itself.");
} else {
playing_conn->stop = 1;
memory_barrier();
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 {
die("Non existent the_playing_conn with play_lock enabled.");
}
if (have_the_player) {
- playing_conn = conn; // the present connection is now playing
- debug(3,"RTSP conversation thread %d has acquired play lock.",conn->connection_number);
+ playing_conn = conn; // the present connection is now playing
+ debug(3, "RTSP conversation thread %d has acquired play lock.", conn->connection_number);
resp->respcode = 456; // 456 - Header Field Not Valid for Resource
char *paesiv = NULL;
char *prsaaeskey = NULL;
char *hdr = msg_get_header(req, "X-Apple-Client-Name");
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
send_metadata('ssnc', 'snam', hdr, strlen(hdr), req, 1);
#endif
}
hdr = msg_get_header(req, "User-Agent");
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
send_metadata('ssnc', 'snua', hdr, strlen(hdr), req, 1);
#endif
out:
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;
pthread_mutex_unlock(&play_lock);
}
int chall_len;
uint8_t *chall = base64_dec(hdr, &chall_len);
- if (chall==NULL)
+ if (chall == NULL)
die("null chall in apple_challenge");
uint8_t buf[48], *bp = buf;
int i;
uint8_t *challresp = rsa_apply(buf, buflen, &resplen, RSA_MODE_AUTH);
char *encoded = base64_enc(challresp, resplen);
- if (encoded==NULL)
+ if (encoded == NULL)
die("could not allocate memory for \"encoded\"");
// strip the padding.
char *padding = strchr(encoded, '=');
char *hdr, *auth_nonce = NULL;
enum rtsp_read_request_response reply;
-
- while (conn->stop==0) {
+
+ while (conn->stop == 0) {
reply = rtsp_read_request(conn, &req);
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);
resp = msg_init();
resp->respcode = 400;
}
}
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);
msg_write_response(conn->fd, resp);
msg_free(req);
msg_free(resp);
} else {
- if ((reply==rtsp_read_request_response_immediate_shutdown_requested) ||
- (reply==rtsp_read_request_response_channel_closed)) {
- debug(3, "Synchronously terminate playing thread of RTSP conversation thread %d.",conn->connection_number);
+ if ((reply == rtsp_read_request_response_immediate_shutdown_requested) ||
+ (reply == rtsp_read_request_response_channel_closed)) {
+ debug(3, "Synchronously terminate playing thread of RTSP conversation thread %d.",
+ conn->connection_number);
player_stop(conn);
- debug(3, "Successful termination of playing thread of RTSP conversation thread %d.",conn->connection_number);
- debug(3, "Request termination of RTSP conversation thread %d.",conn->connection_number);
- conn->stop = 1;
- } else {
+ debug(3, "Successful termination of playing thread of RTSP conversation thread %d.",
+ conn->connection_number);
+ debug(3, "Request termination of RTSP conversation thread %d.", conn->connection_number);
+ conn->stop = 1;
+ } else {
debug(1, "rtsp_read_request error %d, packet ignored.", (int)reply);
}
}
if (auth_nonce)
free(auth_nonce);
rtp_terminate(conn);
- if (playing_conn==conn) {
- debug(3,"Unlocking play lock on RTSP conversation thread %d.",conn->connection_number);
+ if (playing_conn == conn) {
+ debug(3, "Unlocking play lock on RTSP conversation thread %d.", conn->connection_number);
playing_conn = NULL;
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;
conn->running = 0;
return NULL;
send_ssnc_metadata('clip', strdup(remote_ip4), strlen(remote_ip4), 1);
send_ssnc_metadata('svip', strdup(ip4), strlen(ip4), 1);
#endif
- debug(1, "New RTSP connection from %s:%u to self at %s:%u on conversation thread %d.", remote_ip4, rport, ip4,
- tport,conn->connection_number);
+ debug(1, "New RTSP connection from %s:%u to self at %s:%u on conversation thread %d.",
+ remote_ip4, rport, ip4, tport, conn->connection_number);
}
#ifdef AF_INET6
if (local_info->SAFAMILY == AF_INET6) {
send_ssnc_metadata('clip', strdup(remote_ip6), strlen(remote_ip6), 1);
send_ssnc_metadata('svip', strdup(ip6), strlen(ip6), 1);
#endif
- debug(1, "New RTSP connection from [%s]:%u to self at [%s]:%u on conversation thread %d.", remote_ip6, rport, ip6,
- tport,conn->connection_number);
+ debug(1, "New RTSP connection from [%s]:%u to self at [%s]:%u on conversation thread %d.",
+ remote_ip6, rport, ip6, tport, conn->connection_number);
}
#endif
ret = pthread_create(&conn->thread, NULL, rtsp_conversation_thread_func,
conn); // also acts as a memory barrier
if (ret)
- die("Failed to create RTSP receiver thread %d!",conn->connection_number);
- debug(3,"Successfully created 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);
conn->running = 1; // this must happen before the thread is tracked
track_thread(conn);
}