@@ -2949,13 +2949,19 @@ static void janus_videoroom_codecstr(janus_videoroom *videoroom, char *audio_cod
2949
2949
}
2950
2950
}
2951
2951
2952
- /* Helper method to send an RTCP PLI to a remote publisher */
2953
- static void janus_videoroom_rtcp_pli_send(janus_videoroom_publisher_stream *ps) {
2954
- if(ps == NULL || ps->publisher == NULL)
2955
- return;
2956
- janus_videoroom_publisher *publisher = ps->publisher;
2957
- if(publisher->remote_rtcp_fd < 0 || publisher->rtcp_addr.ss_family == 0)
2952
+ /* Helper method to send PLI to publishers.
2953
+ * Send an PLI to local publisher and RTCP PLI to a remote publishers */
2954
+ static void janus_videoroom_reqpli(janus_videoroom_publisher_stream *ps, const char *reason) {
2955
+ if(ps == NULL || g_atomic_int_get(&ps->destroyed))
2958
2956
return;
2957
+ janus_videoroom_publisher *remote_publisher = NULL;
2958
+ if(ps->publisher->remote) {
2959
+ if(ps->publisher == NULL || g_atomic_int_get(&ps->publisher->destroyed))
2960
+ return;
2961
+ remote_publisher = ps->publisher;
2962
+ if(remote_publisher->remote_rtcp_fd < 0 || remote_publisher->rtcp_addr.ss_family == 0)
2963
+ return;
2964
+ }
2959
2965
if(!g_atomic_int_compare_and_exchange(&ps->sending_pli, 0, 1))
2960
2966
return;
2961
2967
gint64 now = janus_get_monotonic_time();
@@ -2965,44 +2971,33 @@ static void janus_videoroom_rtcp_pli_send(janus_videoroom_publisher_stream *ps)
2965
2971
g_atomic_int_set(&ps->sending_pli, 0);
2966
2972
return;
2967
2973
}
2968
- /* Update the time of when we last sent a keyframe request */
2974
+ JANUS_LOG(LOG_VERB, "%s, sending PLI to %s (#%d, %s)\n", reason,
2975
+ ps->publisher->user_id_str, ps->mindex, ps->publisher->display ? ps->publisher->display : "??");
2969
2976
g_atomic_int_set(&ps->need_pli, 0);
2970
2977
ps->pli_latest = janus_get_monotonic_time();
2971
- JANUS_LOG(LOG_HUGE, "Sending PLI\n");
2972
- /* Generate a PLI */
2973
- char rtcp_buf[12];
2974
- int rtcp_len = 12;
2975
- janus_rtcp_pli((char *)&rtcp_buf, rtcp_len);
2976
- uint32_t ssrc = REMOTE_PUBLISHER_BASE_SSRC + (ps->mindex*REMOTE_PUBLISHER_SSRC_STEP);
2977
- janus_rtcp_fix_ssrc(NULL, rtcp_buf, rtcp_len, 1, 1, ssrc);
2978
- /* Send the packet */
2979
- socklen_t addrlen = publisher->rtcp_addr.ss_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6);
2980
- int sent = 0;
2981
- if((sent = sendto(publisher->remote_rtcp_fd, rtcp_buf, rtcp_len, 0,
2982
- (struct sockaddr *)&publisher->rtcp_addr, addrlen)) < 0) {
2983
- JANUS_LOG(LOG_ERR, "Error in sendto... %d (%s)\n", errno, g_strerror(errno));
2984
- } else {
2985
- JANUS_LOG(LOG_HUGE, "Sent %d/%d bytes\n", sent, rtcp_len);
2986
- }
2987
- g_atomic_int_set(&ps->sending_pli, 0);
2988
- }
2989
-
2990
- static void janus_videoroom_reqpli(janus_videoroom_publisher_stream *ps, const char *reason) {
2991
- if(ps == NULL || g_atomic_int_get(&ps->destroyed) || ps->publisher == NULL || g_atomic_int_get(&ps->publisher->destroyed))
2992
- return;
2993
- /* Send a PLI */
2994
- JANUS_LOG(LOG_VERB, "%s sending PLI to %s (#%d, %s)\n", reason,
2995
- ps->publisher->user_id_str, ps->mindex, ps->publisher->display ? ps->publisher->display : "??");
2996
- if(!ps->publisher->remote) {
2997
- /* Easy enough, local publisher so we ask the Janus core to send a PLI */
2978
+ /* Update the time of when we last sent a keyframe request */
2979
+ ps->fir_latest = ps->pli_latest;
2980
+ if(remote_publisher == NULL) {
2981
+ /* Local publisher so we ask the Janus core to send a PLI */
2998
2982
gateway->send_pli_stream(ps->publisher->session->handle, ps->mindex);
2999
2983
} else {
3000
- /* This is a remote publisher, so we'll need to send a PLI to the remote RTCP address */
3001
- JANUS_LOG(LOG_VERB, "Sending PLI to remote publisher\n");
3002
- janus_videoroom_rtcp_pli_send(ps);
2984
+ /* Generate a PLI */
2985
+ char rtcp_buf[12];
2986
+ int rtcp_len = 12;
2987
+ janus_rtcp_pli((char *)&rtcp_buf, rtcp_len);
2988
+ uint32_t ssrc = REMOTE_PUBLISHER_BASE_SSRC + (ps->mindex*REMOTE_PUBLISHER_SSRC_STEP);
2989
+ janus_rtcp_fix_ssrc(NULL, rtcp_buf, rtcp_len, 1, 1, ssrc);
2990
+ /* Send the packet */
2991
+ socklen_t addrlen = remote_publisher->rtcp_addr.ss_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6);
2992
+ int sent = 0;
2993
+ if((sent = sendto(remote_publisher->remote_rtcp_fd, rtcp_buf, rtcp_len, 0,
2994
+ (struct sockaddr *)&remote_publisher->rtcp_addr, addrlen)) < 0) {
2995
+ JANUS_LOG(LOG_ERR, "Error in sendto... %d (%s)\n", errno, g_strerror(errno));
2996
+ } else {
2997
+ JANUS_LOG(LOG_HUGE, "Sent %d/%d bytes\n", sent, rtcp_len);
2998
+ }
3003
2999
}
3004
- /* Update the time of when we last sent a keyframe request */
3005
- ps->fir_latest = janus_get_monotonic_time();
3000
+ g_atomic_int_set(&ps->sending_pli, 0);
3006
3001
}
3007
3002
3008
3003
/* Error codes */
@@ -13803,7 +13798,7 @@ static void *janus_videoroom_remote_publisher_thread(void *user_data) {
13803
13798
ps = (janus_videoroom_publisher_stream *)temp->data;
13804
13799
/* Any PLI and/or REMB we should send back to the source? */
13805
13800
if(ps->type == JANUS_VIDEOROOM_MEDIA_VIDEO && g_atomic_int_get(&ps->need_pli))
13806
- janus_videoroom_rtcp_pli_send (ps);
13801
+ janus_videoroom_reqpli (ps, "Delayed PLI request" );
13807
13802
temp = temp->next;
13808
13803
}
13809
13804
janus_mutex_unlock(&publisher->streams_mutex);
0 commit comments