@@ -467,6 +467,22 @@ static gboolean janus_ice_nacked_packet_cleanup(gpointer user_data) {
467
467
return G_SOURCE_REMOVE ;
468
468
}
469
469
470
+ const char * janus_media_type_str (janus_media_type type ) {
471
+ switch (type ) {
472
+ case JANUS_MEDIA_AUDIO :
473
+ return "audio" ;
474
+ case JANUS_MEDIA_VIDEO :
475
+ return "video" ;
476
+ case JANUS_MEDIA_DATA :
477
+ return "data" ;
478
+ case JANUS_MEDIA_UNKNOWN :
479
+ return "unknown" ;
480
+ default :
481
+ break ;
482
+ }
483
+ return NULL ;
484
+ }
485
+
470
486
/* Deallocation helpers for handles and related structs */
471
487
static void janus_ice_handle_free (const janus_refcount * handle_ref );
472
488
static void janus_ice_webrtc_free (janus_ice_handle * handle );
@@ -2490,6 +2506,12 @@ static void janus_ice_cb_nice_recv(NiceAgent *agent, guint stream_id, guint comp
2490
2506
/* Update stats (TODO Do the same for the last second window as well) */
2491
2507
pc -> dtls_in_stats .info [0 ].packets ++ ;
2492
2508
pc -> dtls_in_stats .info [0 ].bytes += len ;
2509
+ /* If there's a datachannel medium, update the stats there too */
2510
+ janus_ice_peerconnection_medium * medium = g_hash_table_lookup (pc -> media_bytype , GINT_TO_POINTER (JANUS_MEDIA_DATA ));
2511
+ if (medium ) {
2512
+ medium -> out_stats .info [0 ].packets ++ ;
2513
+ medium -> out_stats .info [0 ].bytes += len ;
2514
+ }
2493
2515
return ;
2494
2516
}
2495
2517
/* Not DTLS... RTP or RTCP? (http://tools.ietf.org/html/rfc5761#section-4) */
@@ -4242,8 +4264,8 @@ static gboolean janus_ice_outgoing_stats_handle(gpointer user_data) {
4242
4264
uint mi = 0 ;
4243
4265
for (mi = 0 ; mi < g_hash_table_size (pc -> media ); mi ++ ) {
4244
4266
medium = g_hash_table_lookup (pc -> media , GUINT_TO_POINTER (mi ));
4245
- if (!medium || ( medium -> type != JANUS_MEDIA_AUDIO && medium -> type != JANUS_MEDIA_VIDEO ) )
4246
- continue ; /* We don't process data channels here */
4267
+ if (!medium )
4268
+ continue ;
4247
4269
int vindex = 0 ;
4248
4270
for (vindex = 0 ; vindex < 3 ; vindex ++ ) {
4249
4271
if (vindex > 0 && (medium -> type != JANUS_MEDIA_VIDEO || medium -> rtcp_ctx [1 ] == NULL ))
@@ -4258,6 +4280,8 @@ static gboolean janus_ice_outgoing_stats_handle(gpointer user_data) {
4258
4280
medium -> out_stats .info [vindex ].bytes_lastsec = 0 ;
4259
4281
medium -> out_stats .info [vindex ].bytes_lastsec_temp = 0 ;
4260
4282
}
4283
+ if (medium -> type != JANUS_MEDIA_AUDIO && medium -> type != JANUS_MEDIA_VIDEO )
4284
+ continue ;
4261
4285
/* Now let's see if we need to notify the user about no incoming audio or video */
4262
4286
if (no_media_timer > 0 && pc -> dtls && pc -> dtls -> dtls_connected > 0 && (now - pc -> dtls -> dtls_connected >= G_USEC_PER_SEC )) {
4263
4287
gint64 last = medium -> in_stats .info [vindex ].updated ;
@@ -4285,38 +4309,42 @@ static gboolean janus_ice_outgoing_stats_handle(gpointer user_data) {
4285
4309
combined_event = json_array ();
4286
4310
int vindex = 0 ;
4287
4311
for (vindex = 0 ; vindex < 3 ; vindex ++ ) {
4288
- if (medium && medium -> rtcp_ctx [vindex ]) {
4312
+ if (medium && (( medium -> type == JANUS_MEDIA_DATA && vindex == 0 ) || medium -> rtcp_ctx [vindex ]) ) {
4289
4313
json_t * info = json_object ();
4290
4314
json_object_set_new (info , "mid" , json_string (medium -> mid ));
4291
4315
json_object_set_new (info , "mindex" , json_integer (medium -> mindex ));
4292
4316
if (vindex == 0 )
4293
- json_object_set_new (info , "media" , json_string (medium -> type == JANUS_MEDIA_VIDEO ? "video" : "audio" ));
4317
+ json_object_set_new (info , "media" , json_string (janus_media_type_str ( medium -> type ) ));
4294
4318
else if (vindex == 1 )
4295
4319
json_object_set_new (info , "media" , json_string ("video-sim1" ));
4296
4320
else
4297
4321
json_object_set_new (info , "media" , json_string ("video-sim2" ));
4298
- if (medium -> codec )
4299
- json_object_set_new (info , "codec" , json_string (medium -> codec ));
4300
- json_object_set_new (info , "base" , json_integer (medium -> rtcp_ctx [vindex ]-> tb ));
4301
- if (vindex == 0 )
4302
- json_object_set_new (info , "rtt" , json_integer (janus_rtcp_context_get_rtt (medium -> rtcp_ctx [vindex ])));
4303
- json_object_set_new (info , "lost" , json_integer (janus_rtcp_context_get_lost_all (medium -> rtcp_ctx [vindex ], FALSE)));
4304
- json_object_set_new (info , "lost-by-remote" , json_integer (janus_rtcp_context_get_lost_all (medium -> rtcp_ctx [vindex ], TRUE)));
4305
- json_object_set_new (info , "jitter-local" , json_integer (janus_rtcp_context_get_jitter (medium -> rtcp_ctx [vindex ], FALSE)));
4306
- json_object_set_new (info , "jitter-remote" , json_integer (janus_rtcp_context_get_jitter (medium -> rtcp_ctx [vindex ], TRUE)));
4307
- json_object_set_new (info , "in-link-quality" , json_integer (janus_rtcp_context_get_in_link_quality (medium -> rtcp_ctx [vindex ])));
4308
- json_object_set_new (info , "in-media-link-quality" , json_integer (janus_rtcp_context_get_in_media_link_quality (medium -> rtcp_ctx [vindex ])));
4309
- json_object_set_new (info , "out-link-quality" , json_integer (janus_rtcp_context_get_out_link_quality (medium -> rtcp_ctx [vindex ])));
4310
- json_object_set_new (info , "out-media-link-quality" , json_integer (janus_rtcp_context_get_out_media_link_quality (medium -> rtcp_ctx [vindex ])));
4322
+ if (medium -> type == JANUS_MEDIA_AUDIO || medium -> type == JANUS_MEDIA_VIDEO ) {
4323
+ if (medium -> codec )
4324
+ json_object_set_new (info , "codec" , json_string (medium -> codec ));
4325
+ json_object_set_new (info , "base" , json_integer (medium -> rtcp_ctx [vindex ]-> tb ));
4326
+ if (vindex == 0 )
4327
+ json_object_set_new (info , "rtt" , json_integer (janus_rtcp_context_get_rtt (medium -> rtcp_ctx [vindex ])));
4328
+ json_object_set_new (info , "lost" , json_integer (janus_rtcp_context_get_lost_all (medium -> rtcp_ctx [vindex ], FALSE)));
4329
+ json_object_set_new (info , "lost-by-remote" , json_integer (janus_rtcp_context_get_lost_all (medium -> rtcp_ctx [vindex ], TRUE)));
4330
+ json_object_set_new (info , "jitter-local" , json_integer (janus_rtcp_context_get_jitter (medium -> rtcp_ctx [vindex ], FALSE)));
4331
+ json_object_set_new (info , "jitter-remote" , json_integer (janus_rtcp_context_get_jitter (medium -> rtcp_ctx [vindex ], TRUE)));
4332
+ json_object_set_new (info , "in-link-quality" , json_integer (janus_rtcp_context_get_in_link_quality (medium -> rtcp_ctx [vindex ])));
4333
+ json_object_set_new (info , "in-media-link-quality" , json_integer (janus_rtcp_context_get_in_media_link_quality (medium -> rtcp_ctx [vindex ])));
4334
+ json_object_set_new (info , "out-link-quality" , json_integer (janus_rtcp_context_get_out_link_quality (medium -> rtcp_ctx [vindex ])));
4335
+ json_object_set_new (info , "out-media-link-quality" , json_integer (janus_rtcp_context_get_out_media_link_quality (medium -> rtcp_ctx [vindex ])));
4336
+ }
4311
4337
json_object_set_new (info , "packets-received" , json_integer (medium -> in_stats .info [vindex ].packets ));
4312
4338
json_object_set_new (info , "packets-sent" , json_integer (medium -> out_stats .info [vindex ].packets ));
4313
4339
json_object_set_new (info , "bytes-received" , json_integer (medium -> in_stats .info [vindex ].bytes ));
4314
4340
json_object_set_new (info , "bytes-sent" , json_integer (medium -> out_stats .info [vindex ].bytes ));
4315
- json_object_set_new (info , "bytes-received-lastsec" , json_integer (medium -> in_stats .info [vindex ].bytes_lastsec ));
4316
- json_object_set_new (info , "bytes-sent-lastsec" , json_integer (medium -> out_stats .info [vindex ].bytes_lastsec ));
4317
- json_object_set_new (info , "nacks-received" , json_integer (medium -> in_stats .info [vindex ].nacks ));
4318
- json_object_set_new (info , "nacks-sent" , json_integer (medium -> out_stats .info [vindex ].nacks ));
4319
- json_object_set_new (info , "retransmissions-received" , json_integer (medium -> rtcp_ctx [vindex ]-> retransmitted ));
4341
+ if (medium -> type == JANUS_MEDIA_AUDIO || medium -> type == JANUS_MEDIA_VIDEO ) {
4342
+ json_object_set_new (info , "bytes-received-lastsec" , json_integer (medium -> in_stats .info [vindex ].bytes_lastsec ));
4343
+ json_object_set_new (info , "bytes-sent-lastsec" , json_integer (medium -> out_stats .info [vindex ].bytes_lastsec ));
4344
+ json_object_set_new (info , "nacks-received" , json_integer (medium -> in_stats .info [vindex ].nacks ));
4345
+ json_object_set_new (info , "nacks-sent" , json_integer (medium -> out_stats .info [vindex ].nacks ));
4346
+ json_object_set_new (info , "retransmissions-received" , json_integer (medium -> rtcp_ctx [vindex ]-> retransmitted ));
4347
+ }
4320
4348
if (medium -> mindex == 0 && pc -> remb_bitrate > 0 )
4321
4349
json_object_set_new (info , "remb-bitrate" , json_integer (pc -> remb_bitrate ));
4322
4350
if (combined_event != NULL ) {
0 commit comments