Skip to content

Commit

Permalink
videoroom: keep subscriber reference for the whole message handler (f…
Browse files Browse the repository at this point in the history
…ixes #3354)
  • Loading branch information
atoppi committed Apr 8, 2024
1 parent cb6e491 commit b5d7bc3
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/plugins/janus_videoroom.c
Expand Up @@ -8743,7 +8743,7 @@ static void *janus_videoroom_handler(void *data) {
error_code = 0;
root = NULL;
if(msg->message == NULL) {
if(session->participant_type == janus_videoroom_p_type_subscriber) {
if(subscriber != NULL) {
janus_refcount_decrease(&subscriber->ref);
}
JANUS_LOG(LOG_ERR, "No message??\n");
Expand All @@ -8757,7 +8757,7 @@ static void *janus_videoroom_handler(void *data) {
error_code, error_cause, TRUE,
JANUS_VIDEOROOM_ERROR_MISSING_ELEMENT, JANUS_VIDEOROOM_ERROR_INVALID_ELEMENT);
if(error_code != 0) {
if(session->participant_type == janus_videoroom_p_type_subscriber) {
if(subscriber != NULL) {
janus_refcount_decrease(&subscriber->ref);
}
goto error;
Expand Down Expand Up @@ -11156,6 +11156,7 @@ static void *janus_videoroom_handler(void *data) {
g_atomic_int_set(&subscriber->pending_restart, 1);
janus_mutex_unlock(&subscriber->streams_mutex);
JANUS_LOG(LOG_VERB, "Post-poning new ICE restart offer, waiting for previous answer\n");
janus_refcount_decrease(&subscriber->ref);
janus_videoroom_message_free(msg);
continue;
}
Expand All @@ -11169,6 +11170,7 @@ static void *janus_videoroom_handler(void *data) {
JANUS_LOG(LOG_VERB, " >> Pushing event: %d (took %"SCNu64" us)\n", res, janus_get_monotonic_time()-start);
json_decref(event);
json_decref(jsep);
janus_refcount_decrease(&subscriber->ref);
/* Done */
janus_videoroom_message_free(msg);
continue;
Expand Down Expand Up @@ -11477,6 +11479,7 @@ static void *janus_videoroom_handler(void *data) {
janus_mutex_unlock(&stream_ps->subscribers_mutex);
janus_refcount_decrease(&stream_ps->ref);
}

/* Subscribe to the new one */
janus_mutex_lock(&ps->subscribers_mutex);
stream->publisher_streams = g_slist_append(stream->publisher_streams, ps);
Expand Down Expand Up @@ -11625,7 +11628,6 @@ static void *janus_videoroom_handler(void *data) {
janus_refcount_decrease(&subscriber->ref);
goto error;
}
janus_refcount_decrease(&subscriber->ref);
}

/* Prepare JSON event */
Expand Down Expand Up @@ -11664,9 +11666,11 @@ static void *janus_videoroom_handler(void *data) {
JANUS_LOG(LOG_VERB, " >> %d (%s)\n", ret, janus_get_api_error(ret));
json_decref(event);
/* Take note of the fact we got our answer */
janus_videoroom_subscriber *subscriber = (janus_videoroom_subscriber *)session->participant;
if(subscriber == NULL) {
if(session->participant == NULL) {
/* Shouldn't happen? */
if(subscriber != NULL)
janus_refcount_decrease(&subscriber->ref);
janus_videoroom_message_free(msg);
continue;
}
janus_mutex_lock(&subscriber->streams_mutex);
Expand Down Expand Up @@ -11722,6 +11726,7 @@ static void *janus_videoroom_handler(void *data) {
g_atomic_int_set(&subscriber->answered, 1);
janus_mutex_unlock(&subscriber->streams_mutex);
}
janus_refcount_decrease(&subscriber->ref);
janus_videoroom_message_free(msg);
continue;
} else {
Expand Down Expand Up @@ -12299,6 +12304,8 @@ static void *janus_videoroom_handler(void *data) {
if(participant != NULL)
janus_refcount_decrease(&participant->ref);
}
if(subscriber != NULL)
janus_refcount_decrease(&subscriber->ref);
janus_videoroom_message_free(msg);

continue;
Expand Down

0 comments on commit b5d7bc3

Please sign in to comment.