webrtc_stats: Add support for masking stats type 52/271352/2
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 18 Feb 2022 07:29:08 +0000 (16:29 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 18 Feb 2022 07:37:29 +0000 (16:37 +0900)
Entering logs are added for each callback.

[Version] 0.3.56
[Issue Type] Improvement

Change-Id: I5e38d9640e5e0c4fa5c9520eacdcaf5edac0c58e
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc_stats.c

index e193d252c64a7138250bb50cacf202de02d0f697..062f7cc8462b1306bf76e4c4a4545916d69c676b 100644 (file)
@@ -712,7 +712,7 @@ int _destroy_data_channel(webrtc_data_channel_s *channel);
 int _data_channel_send_string(webrtc_data_channel_s *channel, const char *string);
 int _data_channel_send_bytes(webrtc_data_channel_s *channel, const char *data, unsigned int size);
 
-void _webrtcbin_get_stats(webrtc_s *webrtc);
+void _webrtcbin_get_stats(webrtc_s *webrtc, int type_mask);
 void _set_stats_timer(webrtc_s *webrtc);
 void _unset_stats_timer(webrtc_s *webrtc);
 
index aa70443e2c5790be0a8d9601d36e0d823cf6034e..ebc5ba7942dce76ca3ceeea1b6a72d184a6f56d8 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.55
+Version:    0.3.56
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 64cc9ec1145bd3952600c7d2745373de40f17b9b..c25052858a2eb0c73983fa27016e8b05f1173d33 100644 (file)
@@ -18,7 +18,6 @@
 #include "webrtc_private.h"
 
 //LCOV_EXCL_START
-typedef void (*__parse_stats_func)(const GstStructure *s, webrtc_callbacks_s *cb);
 
 /*
  * Description below is extracted from GstWebRTCBin::get-stats:
@@ -317,6 +316,8 @@ static void __parse_codec_and_invoke_callback(const GstStructure *s, webrtc_call
 
        RET_IF(cb == NULL, "cb is NULL");
 
+       LOG_DEBUG_ENTER();
+
        __get_common_stats(s, &common);
        __get_codec_stats(s, &codec);
 
@@ -334,6 +335,8 @@ static void __parse_inbound_rtp_and_invoke_callback(const GstStructure *s, webrt
 
        RET_IF(cb == NULL, "cb is NULL");
 
+       LOG_DEBUG_ENTER();
+
        __get_common_stats(s, &common);
        __get_rtp_stream_stats(s, &rtp_stream);
        __get_received_rtp_stream_stats(s, &received_rtp_stream);
@@ -360,6 +363,8 @@ static void __parse_outbound_rtp_and_invoke_callback(const GstStructure *s, webr
 
        RET_IF(cb == NULL, "cb is NULL");
 
+       LOG_DEBUG_ENTER();
+
        __get_common_stats(s, &common);
        __get_rtp_stream_stats(s, &rtp_stream);
        __get_sent_rtp_stream_stats(s, &sent_rtp_stream);
@@ -379,6 +384,8 @@ static void __parse_remote_inbound_rtp_and_invoke_callback(const GstStructure *s
 
        RET_IF(cb == NULL, "cb is NULL");
 
+       LOG_DEBUG_ENTER();
+
        __get_common_stats(s, &common);
        __get_rtp_stream_stats(s, &rtp_stream);
        /* FIXME: only 'jitter' and 'packet-lost'(int) are available. type of 'packet-lost' should be fixed.
@@ -397,6 +404,8 @@ static void __parse_remote_outbound_rtp_and_invoke_callback(const GstStructure *
 
        RET_IF(cb == NULL, "cb is NULL");
 
+       LOG_DEBUG_ENTER();
+
        __get_common_stats(s, &common);
        __get_rtp_stream_stats(s, &rtp_stream);
        __get_remote_outbound_rtp_stream_stats(s, &remote_outbound_rtp_stream);
@@ -408,6 +417,8 @@ static void __parse_csrc_and_invoke_callback(const GstStructure *s, webrtc_callb
 {
        RET_IF(cb == NULL, "cb is NULL");
 
+       LOG_DEBUG_ENTER();
+
        gst_structure_foreach(s, __gststructure_foreach_cb, NULL);
        /* not implemented */
 }
@@ -419,6 +430,8 @@ static void __parse_peer_connection_and_invoke_callback(const GstStructure *s, w
 
        RET_IF(cb == NULL, "cb is NULL");
 
+       LOG_DEBUG_ENTER();
+
        __get_common_stats(s, &common);
        __get_peer_connection_stats(s, &peer_connection);
 
@@ -429,6 +442,8 @@ static void __parse_data_channel_and_invoke_callback(const GstStructure *s, webr
 {
        RET_IF(cb == NULL, "cb is NULL");
 
+       LOG_DEBUG_ENTER();
+
        gst_structure_foreach(s, __gststructure_foreach_cb, NULL);
        /* not implemented */
 }
@@ -437,6 +452,8 @@ static void __parse_stream_and_invoke_callback(const GstStructure *s, webrtc_cal
 {
        RET_IF(cb == NULL, "cb is NULL");
 
+       LOG_DEBUG_ENTER();
+
        gst_structure_foreach(s, __gststructure_foreach_cb, NULL);
        /* not implemented */
 }
@@ -445,6 +462,8 @@ static void __parse_transport_and_invoke_callback(const GstStructure *s, webrtc_
 {
        RET_IF(cb == NULL, "cb is NULL");
 
+       LOG_DEBUG_ENTER();
+
        gst_structure_foreach(s, __gststructure_foreach_cb, NULL);
        /* not implemented */
 }
@@ -453,6 +472,8 @@ static void __parse_candidate_pair_and_invoke_callback(const GstStructure *s, we
 {
        RET_IF(cb == NULL, "cb is NULL");
 
+       LOG_DEBUG_ENTER();
+
        gst_structure_foreach(s, __gststructure_foreach_cb, NULL);
        /* not implemented */
 }
@@ -461,6 +482,8 @@ static void __parse_local_candidate_and_invoke_callback(const GstStructure *s, w
 {
        RET_IF(cb == NULL, "cb is NULL");
 
+       LOG_DEBUG_ENTER();
+
        gst_structure_foreach(s, __gststructure_foreach_cb, NULL);
        /* not implemented */
 }
@@ -469,6 +492,8 @@ static void __parse_remote_candidate_and_invoke_callback(const GstStructure *s,
 {
        RET_IF(cb == NULL, "cb is NULL");
 
+       LOG_DEBUG_ENTER();
+
        gst_structure_foreach(s, __gststructure_foreach_cb, NULL);
        /* not implemented */
 }
@@ -477,33 +502,68 @@ static void __parse_certificate_and_invoke_callback(const GstStructure *s, webrt
 {
        RET_IF(cb == NULL, "cb is NULL");
 
+       LOG_DEBUG_ENTER();
+
        gst_structure_foreach(s, __gststructure_foreach_cb, NULL);
        /* not implemented */
 }
 
-static __parse_stats_func __parse_stats_funcs[] = {
-       [GST_WEBRTC_STATS_CODEC] = __parse_codec_and_invoke_callback,
-       [GST_WEBRTC_STATS_INBOUND_RTP] = __parse_inbound_rtp_and_invoke_callback,
-       [GST_WEBRTC_STATS_OUTBOUND_RTP] = __parse_outbound_rtp_and_invoke_callback,
-       [GST_WEBRTC_STATS_REMOTE_INBOUND_RTP] = __parse_remote_inbound_rtp_and_invoke_callback,
-       [GST_WEBRTC_STATS_REMOTE_OUTBOUND_RTP] = __parse_remote_outbound_rtp_and_invoke_callback,
-       [GST_WEBRTC_STATS_CSRC] = __parse_csrc_and_invoke_callback,
-       [GST_WEBRTC_STATS_PEER_CONNECTION] = __parse_peer_connection_and_invoke_callback,
-       [GST_WEBRTC_STATS_DATA_CHANNEL] = __parse_data_channel_and_invoke_callback,
-       [GST_WEBRTC_STATS_STREAM] = __parse_stream_and_invoke_callback,
-       [GST_WEBRTC_STATS_TRANSPORT] = __parse_transport_and_invoke_callback,
-       [GST_WEBRTC_STATS_CANDIDATE_PAIR] = __parse_candidate_pair_and_invoke_callback,
-       [GST_WEBRTC_STATS_LOCAL_CANDIDATE] = __parse_local_candidate_and_invoke_callback,
-       [GST_WEBRTC_STATS_REMOTE_CANDIDATE] = __parse_remote_candidate_and_invoke_callback,
-       [GST_WEBRTC_STATS_CERTIFICATE] = __parse_certificate_and_invoke_callback,
+typedef void (*stats_func)(const GstStructure *s, webrtc_callbacks_s *cb);
+
+/* Note that stats_type_mask_e below follows GstWebRTCStatsType of webrtc_fwd.h */
+typedef enum {
+       STATS_TYPE_ALL_MASK                 = 0xFFFF,
+       STATS_TYPE_CODEC_MASK               = 0x0001,
+       STATS_TYPE_INBOUND_RTP_MASK         = 0x0002,
+       STATS_TYPE_OUTBOUND_RTP_MASK        = 0x0004,
+       STATS_TYPE_REMOTE_INBOUND_RTP_MASK  = 0x0008,
+       STATS_TYPE_REMOTE_OUTBOUND_RTP_MASK = 0x0010,
+       STATS_TYPE_CSRC_MASK                = 0x0020,
+       STATS_TYPE_PEER_CONNECTION_MASK     = 0x0040,
+       STATS_TYPE_DATA_CHANNEL_MASK        = 0x0080,
+       STATS_TYPE_STREAM_MASK              = 0x0100,
+       STATS_TYPE_TRANSPORT_MASK           = 0x0200,
+       STATS_TYPE_CANDIDATE_PAIR_MASK      = 0x0400,
+       STATS_TYPE_LOCAL_CANDIDATE_MASK     = 0x0800,
+       STATS_TYPE_REMOTE_CANDIDATE_MASK    = 0x1000,
+       STATS_TYPE_CERTIFICATE_MASK         = 0x2000,
+} stats_type_mask_e;
+
+typedef struct {
+       stats_func func;
+       stats_type_mask_e type_mask;
+} parse_stats_s;
+
+static parse_stats_s parse_stats[] = {
+       [GST_WEBRTC_STATS_CODEC] = { __parse_codec_and_invoke_callback, STATS_TYPE_CODEC_MASK },
+       [GST_WEBRTC_STATS_INBOUND_RTP] = { __parse_inbound_rtp_and_invoke_callback, STATS_TYPE_INBOUND_RTP_MASK },
+       [GST_WEBRTC_STATS_OUTBOUND_RTP] = { __parse_outbound_rtp_and_invoke_callback, STATS_TYPE_OUTBOUND_RTP_MASK },
+       [GST_WEBRTC_STATS_REMOTE_INBOUND_RTP] = { __parse_remote_inbound_rtp_and_invoke_callback, STATS_TYPE_REMOTE_INBOUND_RTP_MASK },
+       [GST_WEBRTC_STATS_REMOTE_OUTBOUND_RTP] = { __parse_remote_outbound_rtp_and_invoke_callback, STATS_TYPE_REMOTE_OUTBOUND_RTP_MASK },
+       [GST_WEBRTC_STATS_CSRC] = { __parse_csrc_and_invoke_callback, STATS_TYPE_CSRC_MASK },
+       [GST_WEBRTC_STATS_PEER_CONNECTION] = { __parse_peer_connection_and_invoke_callback, STATS_TYPE_PEER_CONNECTION_MASK },
+       [GST_WEBRTC_STATS_DATA_CHANNEL] = { __parse_data_channel_and_invoke_callback, STATS_TYPE_DATA_CHANNEL_MASK },
+       [GST_WEBRTC_STATS_STREAM] = { __parse_stream_and_invoke_callback, STATS_TYPE_STREAM_MASK },
+       [GST_WEBRTC_STATS_TRANSPORT] = { __parse_transport_and_invoke_callback, STATS_TYPE_TRANSPORT_MASK },
+       [GST_WEBRTC_STATS_CANDIDATE_PAIR] = { __parse_candidate_pair_and_invoke_callback, STATS_TYPE_CANDIDATE_PAIR_MASK },
+       [GST_WEBRTC_STATS_LOCAL_CANDIDATE] = { __parse_local_candidate_and_invoke_callback, STATS_TYPE_LOCAL_CANDIDATE_MASK },
+       [GST_WEBRTC_STATS_REMOTE_CANDIDATE] = { __parse_remote_candidate_and_invoke_callback, STATS_TYPE_REMOTE_CANDIDATE_MASK },
+       [GST_WEBRTC_STATS_CERTIFICATE] = { __parse_certificate_and_invoke_callback, STATS_TYPE_CERTIFICATE_MASK }
 };
 
+typedef struct _stats_userdata_s {
+       webrtc_s *webrtc;
+       int type_mask;
+} stats_userdata_s;
+
 static gboolean __webrtcbin_stats_cb(GQuark field_id, const GValue *value, gpointer user_data)
 {
-       webrtc_s *webrtc = (webrtc_s *)user_data;
+       stats_userdata_s *stats_userdata = (stats_userdata_s *)user_data;
        const GstStructure *s;
        GstWebRTCStatsType type;
 
+       RET_VAL_IF(stats_userdata == NULL, TRUE, "stats_userdata is NULL");
+
        if (GST_VALUE_HOLDS_STRUCTURE(value)) {
                s = gst_value_get_structure(value);
                gst_structure_get(s, "type", GST_TYPE_WEBRTC_STATS_TYPE, &type, NULL);
@@ -511,7 +571,10 @@ static gboolean __webrtcbin_stats_cb(GQuark field_id, const GValue *value, gpoin
                RET_VAL_IF((type < GST_WEBRTC_STATS_CODEC || type > GST_WEBRTC_STATS_CERTIFICATE),
                        TRUE, "invalid type(%u)", type);
 
-               __parse_stats_funcs[type](s, &webrtc->stats_cb);
+               if (!(stats_userdata->type_mask & parse_stats[type].type_mask))
+                       return TRUE;
+
+               parse_stats[type].func(s, &stats_userdata->webrtc->stats_cb);
 
        } else {
                LOG_ERROR("unknown field \'%s\' value type: \'%s\'",
@@ -521,7 +584,7 @@ static gboolean __webrtcbin_stats_cb(GQuark field_id, const GValue *value, gpoin
        return TRUE;
 }
 
-static void __webrtcbin_get_stats_cb(GstPromise *promise, webrtc_s *webrtc)
+static void __webrtcbin_get_stats_cb(GstPromise *promise, gpointer user_data)
 {
        const GstStructure *stats;
 
@@ -530,17 +593,18 @@ static void __webrtcbin_get_stats_cb(GstPromise *promise, webrtc_s *webrtc)
        stats = gst_promise_get_reply(promise);
        RET_IF(stats == NULL, "failed to gst_promise_get_reply()");
 
-       gst_structure_foreach(stats, __webrtcbin_stats_cb, webrtc);
+       gst_structure_foreach(stats, __webrtcbin_stats_cb, user_data);
 }
 
-void _webrtcbin_get_stats(webrtc_s *webrtc)
+void _webrtcbin_get_stats(webrtc_s *webrtc, int type_mask)
 {
        GstPromise *promise;
+       stats_userdata_s stats_userdata = { webrtc, type_mask };
 
        RET_IF(webrtc == NULL, "webrtc is NULL");
        RET_IF(webrtc->gst.webrtcbin == NULL, "webrtcbin is NULL");
 
-       promise = gst_promise_new_with_change_func((GstPromiseChangeFunc)__webrtcbin_get_stats_cb, webrtc, NULL);
+       promise = gst_promise_new_with_change_func((GstPromiseChangeFunc)__webrtcbin_get_stats_cb, &stats_userdata, NULL);
 
        g_signal_emit_by_name(webrtc->gst.webrtcbin, "get-stats", NULL, promise);
        LOG_DEBUG("emitting 'get-stats' on %p", webrtc->gst.webrtcbin);
@@ -553,7 +617,7 @@ static gboolean __get_stats_periodically(gpointer user_data)
        webrtc_s *webrtc = (webrtc_s *)user_data;
 
        if (webrtc->state == WEBRTC_STATE_PLAYING)
-               _webrtcbin_get_stats(webrtc);
+               _webrtcbin_get_stats(webrtc, STATS_TYPE_ALL_MASK);
 
        return G_SOURCE_CONTINUE;
 }