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) (#3355)
  • Loading branch information
atoppi committed Apr 24, 2024
1 parent 0200270 commit 5346a22
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/plugins/janus_videoroom.c
Expand Up @@ -8962,7 +8962,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 @@ -8976,7 +8976,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 @@ -11419,6 +11419,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 @@ -11432,6 +11433,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 @@ -11760,6 +11762,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 @@ -11930,7 +11933,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 @@ -11969,9 +11971,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 @@ -12027,6 +12031,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 @@ -12604,6 +12609,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 5346a22

Please sign in to comment.