Skip to content

Commit

Permalink
Stop using an unsigned integer for time when we want to watch if it g…
Browse files Browse the repository at this point in the history
…oes negative. Only release the playing_conn if we already own it!
  • Loading branch information
mikebrady committed Dec 2, 2018
1 parent 898aad1 commit 8c9b159
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1142,10 +1142,10 @@ int sps_pthread_mutex_timedlock(pthread_mutex_t *mutex, useconds_t dally_time,
// this is not pthread_cancellation safe because is contains a cancellation point
int oldState;
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState);
useconds_t time_to_wait = dally_time;
int time_to_wait = dally_time;
int r = pthread_mutex_trylock(mutex);
while ((r == EBUSY) && (time_to_wait > 0)) {
useconds_t st = time_to_wait;
int st = time_to_wait;
if (st > 1000)
st = 1000;
sps_nanosleep(0, st * 1000); // this contains a cancellation point
Expand Down
14 changes: 8 additions & 6 deletions rtsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ int pc_queue_get_item(pc_queue *the_queue, void *the_stuff) {
int have_player(rtsp_conn_info *conn) {
int response = 0;
debug_mutex_lock(&playing_conn_lock, 1000000, 3);
if (playing_conn == conn) // this connection definitely doesn't have the play lock
if (playing_conn == conn) // this connection definitely has the play lock
response = 1;
debug_mutex_unlock(&playing_conn_lock, 3);
return response;
Expand Down Expand Up @@ -970,7 +970,8 @@ void handle_setup(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) {
if (resp->respcode != 200) {
debug(1, "Connection %d: SETUP error -- releasing the player lock.", conn->connection_number);
debug_mutex_lock(&playing_conn_lock, 1000000, 3);
playing_conn = NULL; // this connection definitely doesn't have the play lock
if (playing_conn == conn) // if we have the player
playing_conn = NULL; // let it go
debug_mutex_unlock(&playing_conn_lock, 3);
}

Expand Down Expand Up @@ -1630,7 +1631,7 @@ static void handle_announce(rtsp_conn_info *conn, rtsp_message *req, rtsp_messag
debug_mutex_unlock(&playing_conn_lock, 3);

if (should_wait) {
useconds_t time_remaining = 3000000;
int time_remaining = 3000000; // must be signed, as it could go negative...

while ((time_remaining > 0) && (have_the_player == 0)) {
debug_mutex_lock(&playing_conn_lock, 1000000, 3); // get it
Expand Down Expand Up @@ -1829,7 +1830,8 @@ static void handle_announce(rtsp_conn_info *conn, rtsp_message *req, rtsp_messag
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
playing_conn = NULL;
if (playing_conn == conn) // if we managed to acquire it
playing_conn = NULL; // let it go
debug_mutex_unlock(&playing_conn_lock, 3);
}
}
Expand Down Expand Up @@ -2123,9 +2125,9 @@ void rtsp_conversation_thread_cleanup_function(void *arg) {

debug(3, "Connection %d: Checking play lock.", conn->connection_number);
debug_mutex_lock(&playing_conn_lock, 1000000, 3); // get it
if (playing_conn == conn) {
if (playing_conn == conn) { // if it's ours
debug(2, "Connection %d: Unlocking play lock.", conn->connection_number);
playing_conn = NULL;
playing_conn = NULL; // let it go
}
debug_mutex_unlock(&playing_conn_lock, 3);

Expand Down

0 comments on commit 8c9b159

Please sign in to comment.