Skip to content

Commit

Permalink
Have VideoCall sessions reference each other, when in a call (see #2300)
Browse files Browse the repository at this point in the history
  • Loading branch information
lminiero committed Jul 28, 2020
1 parent a6731ba commit bb0ab09
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions plugins/janus_videocall.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ typedef struct janus_videocall_session {
volatile gint dataready;
volatile gint hangingup;
volatile gint destroyed;
janus_mutex mutex;
janus_refcount ref;
} janus_videocall_session;
static GHashTable *sessions = NULL, *usernames = NULL;
Expand Down Expand Up @@ -593,6 +594,7 @@ void janus_videocall_create_session(janus_plugin_session *handle, int *error) {
janus_rtp_switching_context_reset(&session->context);
janus_rtp_simulcasting_context_reset(&session->sim_context);
janus_vp8_simulcast_context_reset(&session->vp8_context);
janus_mutex_init(&session->mutex);
janus_mutex_init(&session->rec_mutex);
g_atomic_int_set(&session->incall, 0);
g_atomic_int_set(&session->hangingup, 0);
Expand Down Expand Up @@ -994,11 +996,11 @@ static void janus_videocall_hangup_media_internal(janus_plugin_session *handle)
janus_mutex_lock(&session->rec_mutex);
janus_videocall_recorder_close(session);
janus_mutex_unlock(&session->rec_mutex);
janus_mutex_lock(&session->mutex);
janus_videocall_session *peer = session->peer;
session->peer = NULL;
if(peer && !g_atomic_int_get(&peer->destroyed)) {
if(peer) {
/* Send event to our peer too */
janus_refcount_increase(&peer->ref);
json_t *call = json_object();
json_object_set_new(call, "videocall", json_string("event"));
json_t *calling = json_object();
Expand All @@ -1019,6 +1021,7 @@ static void janus_videocall_hangup_media_internal(janus_plugin_session *handle)
}
janus_refcount_decrease(&peer->ref);
}
janus_mutex_unlock(&session->mutex);
/* Reset controls */
session->has_audio = FALSE;
session->has_video = FALSE;
Expand Down Expand Up @@ -1272,8 +1275,14 @@ static void *janus_videocall_handler(void *data) {
}
janus_sdp_destroy(offer);
g_atomic_int_set(&peer->incall, 1);
janus_refcount_increase(&session->ref);
janus_refcount_increase(&peer->ref);
janus_mutex_lock(&session->mutex);
session->peer = peer;
janus_mutex_unlock(&session->mutex);
janus_mutex_lock(&peer->mutex);
peer->peer = session;
janus_mutex_unlock(&session->mutex);
session->has_audio = (strstr(msg_sdp, "m=audio") != NULL);
session->has_video = (strstr(msg_sdp, "m=video") != NULL);
session->has_data = (strstr(msg_sdp, "DTLS/SCTP") != NULL);
Expand Down

0 comments on commit bb0ab09

Please sign in to comment.