Skip to content

Commit

Permalink
Move closing of ports to the player thread cleanup. They can be bound…
Browse files Browse the repository at this point in the history
… without the UDP threads ever having been called, so they must be closed when the player thread exits.
  • Loading branch information
mikebrady committed Nov 29, 2018
1 parent f2a3ba0 commit 0eac2b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
8 changes: 8 additions & 0 deletions player.c
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,14 @@ void player_thread_cleanup_handler(void *arg) {
pthread_join(conn->rtp_audio_thread, NULL);
debug(2, "Audio thread terminated.");

debug(2, "Closing timing, control and audio sockets...");
if (conn->control_socket)
close(conn->control_socket);
if (conn->timing_socket)
close(conn->timing_socket);
if (conn->audio_socket)
close(conn->audio_socket);

if (conn->outbuf) {
free(conn->outbuf);
conn->outbuf = NULL;
Expand Down
33 changes: 6 additions & 27 deletions rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,8 @@ uint64_t local_to_remote_time_difference_now(rtsp_conn_info *conn) {
return conn->local_to_remote_time_difference + (uint64_t)(drift * (uint64_t)0x100000000);
}

void rtp_audio_receiver_cleanup_handler(void *arg) {
int oldState;
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState);
debug(3, "Audio Receiver Cleanup.");
rtsp_conn_info *conn = (rtsp_conn_info *)arg;
debug(3, "Close Audio Socket.");
close(conn->audio_socket);
debug(3, "Audio Receiver Cleanup Successful.");
usleep(20000); // microseconds
pthread_setcancelstate(oldState, NULL);
void rtp_audio_receiver_cleanup_handler(__attribute__((unused)) void *arg) {
debug(3, "Audio Receiver Cleanup Done.");
}

void *rtp_audio_receiver(void *arg) {
Expand Down Expand Up @@ -240,18 +232,8 @@ void *rtp_audio_receiver(void *arg) {
pthread_exit(NULL);
}

void rtp_control_handler_cleanup_handler(void *arg) {
int oldState;
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState);
debug(3, "Control Receiver Cleanup.");
rtsp_conn_info *conn = (rtsp_conn_info *)arg;
debug(3, "Shut Down Control Socket.");
shutdown(conn->control_socket, SHUT_RDWR);
debug(3, "Close Control Socket.");
close(conn->control_socket);
debug(3, "Control Receiver Cleanup Successful.");
usleep(20000); // microseconds
pthread_setcancelstate(oldState, NULL);
void rtp_control_handler_cleanup_handler(__attribute__((unused)) void *arg) {
debug(3, "Control Receiver Cleanup Done.");
}

void *rtp_control_receiver(void *arg) {
Expand Down Expand Up @@ -564,18 +546,15 @@ void *rtp_timing_sender(void *arg) {
}

void rtp_timing_receiver_cleanup_handler(void *arg) {
int oldState;
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState);
debug(3, "Timing Receiver Cleanup.");
rtsp_conn_info *conn = (rtsp_conn_info *)arg;
debug(3, "Cancel Timing Requester.");
pthread_cancel(conn->timer_requester);
int oldState;
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState);
debug(3, "Join Timing Requester.");
pthread_join(conn->timer_requester, NULL);
debug(3, "Close Timing Socket.");
close(conn->timing_socket);
debug(3, "Timing Receiver Cleanup Successful.");
usleep(20000); // microseconds
pthread_setcancelstate(oldState, NULL);
}

Expand Down

0 comments on commit 0eac2b9

Please sign in to comment.