Skip to content

Commit

Permalink
Refactored VideoRoom plugin to support multistream
Browse files Browse the repository at this point in the history
  • Loading branch information
lminiero committed Jun 8, 2020
1 parent 656eaac commit 9efd375
Show file tree
Hide file tree
Showing 7 changed files with 3,871 additions and 1,866 deletions.
16 changes: 15 additions & 1 deletion ice.c
Original file line number Diff line number Diff line change
Expand Up @@ -4438,11 +4438,25 @@ void janus_ice_relay_rtcp(janus_ice_handle *handle, janus_plugin_rtcp *packet) {
}

void janus_ice_send_pli(janus_ice_handle *handle) {
if(handle == NULL || handle->pc == NULL)
return;
/* Iterate on all video streams, and send the PLI there */
janus_ice_peerconnection_medium *medium = NULL;
uint mi=0;
for(mi=0; mi<g_hash_table_size(handle->pc->media); mi++) {
medium = g_hash_table_lookup(handle->pc->media, GUINT_TO_POINTER(mi));
if(!medium || medium->type != JANUS_MEDIA_VIDEO)
continue;
janus_ice_send_pli_stream(handle, medium->mindex);
}
}

void janus_ice_send_pli_stream(janus_ice_handle *handle, int mindex) {
char rtcpbuf[12];
memset(rtcpbuf, 0, 12);
janus_rtcp_pli((char *)&rtcpbuf, 12);
/* FIXME We send the PLI on the first video m-line we have */
janus_plugin_rtcp rtcp = { .mindex = -1, .video = TRUE, .buffer = rtcpbuf, .length = 12 };
janus_plugin_rtcp rtcp = { .mindex = mindex, .video = TRUE, .buffer = rtcpbuf, .length = 12 };
janus_ice_relay_rtcp(handle, &rtcp);
}

Expand Down
4 changes: 4 additions & 0 deletions ice.h
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,10 @@ void janus_ice_relay_data(janus_ice_handle *handle, janus_plugin_data *packet);
/*! \brief Helper core callback, called when a plugin wants to send a RTCP PLI to a peer
* @param[in] handle The Janus ICE handle associated with the peer */
void janus_ice_send_pli(janus_ice_handle *handle);
/*! \brief Helper core callback, called when a plugin wants to send a RTCP PLI to a single video stream of a peer
* @param[in] handle The Janus ICE handle associated with the peer
* @param[in] mindex Index of the stream to send the PLI to (relative to the SDP) */
void janus_ice_send_pli_stream(janus_ice_handle *handle, int mindex);
/*! \brief Helper core callback, called when a plugin wants to send a RTCP REMB to a peer
* @param[in] handle The Janus ICE handle associated with the peer
* @param[in] bitrate The bitrate value to put in the REMB message */
Expand Down
12 changes: 12 additions & 0 deletions janus.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ void janus_plugin_relay_rtp(janus_plugin_session *plugin_session, janus_plugin_r
void janus_plugin_relay_rtcp(janus_plugin_session *plugin_session, janus_plugin_rtcp *packet);
void janus_plugin_relay_data(janus_plugin_session *plugin_session, janus_plugin_data *message);
void janus_plugin_send_pli(janus_plugin_session *plugin_session);
void janus_plugin_send_pli_stream(janus_plugin_session *plugin_session, int mindex);
void janus_plugin_send_remb(janus_plugin_session *plugin_session, uint32_t bitrate);
void janus_plugin_close_pc(janus_plugin_session *plugin_session);
void janus_plugin_end_session(janus_plugin_session *plugin_session);
Expand All @@ -545,6 +546,7 @@ static janus_callbacks janus_handler_plugin =
.relay_rtcp = janus_plugin_relay_rtcp,
.relay_data = janus_plugin_relay_data,
.send_pli = janus_plugin_send_pli,
.send_pli_stream = janus_plugin_send_pli_stream,
.send_remb = janus_plugin_send_remb,
.close_pc = janus_plugin_close_pc,
.end_session = janus_plugin_end_session,
Expand Down Expand Up @@ -3675,6 +3677,16 @@ void janus_plugin_send_pli(janus_plugin_session *plugin_session) {
janus_ice_send_pli(handle);
}

void janus_plugin_send_pli_stream(janus_plugin_session *plugin_session, int mindex) {
if((plugin_session < (janus_plugin_session *)0x1000) || g_atomic_int_get(&plugin_session->stopped))
return;
janus_ice_handle *handle = (janus_ice_handle *)plugin_session->gateway_handle;
if(!handle || janus_flags_is_set(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_STOP)
|| janus_flags_is_set(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_ALERT))
return;
janus_ice_send_pli_stream(handle, mindex);
}

void janus_plugin_send_remb(janus_plugin_session *plugin_session, uint32_t bitrate) {
if((plugin_session < (janus_plugin_session *)0x1000) || g_atomic_int_get(&plugin_session->stopped))
return;
Expand Down
Loading

0 comments on commit 9efd375

Please sign in to comment.