webrtc_tbm/stats: Introduce ASSERT() macro function 70/304170/1
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 11 Jan 2024 07:37:40 +0000 (16:37 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 11 Jan 2024 08:41:39 +0000 (17:41 +0900)
Note that this assertion would be helpful not only during early
of the development phase to check unexpected wrong codes but
also during the runtime with being attributed to the compiler
optimizations.

Enough awareness of parameters whether if they are inevitable
or not would be prerequisite before applying it.

[Version] 0.4.35
[Issue Type] Debug

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

index 36ef21f3630e70c34f2b101cc78ab80368123f6a..e530d924dd235932c7f218e24df66f0f313e635c 100644 (file)
@@ -145,6 +145,15 @@ do { \
        return WEBRTC_ERROR_NOT_SUPPORTED; \
 } while (0)
 
+#define UNLIKELY(x) (__builtin_expect(!!(x),0))
+#define ASSERT(expr) \
+do {\
+       if (UNLIKELY(!(expr))) { \
+               LOG_ERROR("Assertion '%s' failed. Aborting.", #expr); \
+               abort(); \
+       } \
+} while (0)
+
 #define SAFE_STR(str)               (str) ? str : "null"
 
 #define SAFE_FREE(src) \
@@ -865,7 +874,6 @@ int _release_all_resources(webrtc_s *webrtc);
 webrtc_tbm_s *_alloc_tbm(void);
 void _release_tbm(webrtc_tbm_s *tbm);
 void _create_tbm_bo_list(webrtc_tbm_s *tbm, int bo_size, int list_length);
-void _destroy_tbm_bo_list(webrtc_tbm_s *tbm);
 void *_get_unused_tbm_bo(webrtc_tbm_s *tbm, unsigned int timeout_sec);
 void _release_tbm_bo(webrtc_tbm_s *tbm, void *bo);
 
index 0f9b1bbb8871d73c466d53b20f9524a4106187b7..06522f4363a8ffa163c95aa87103928147bbb8d0 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.4.34
+Version:    0.4.35
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 7489a023b26bb1321268f587386d43fbba48b9cd..ace3ba2e1456d4a2a5ed17aef02b6768048ccf81 100644 (file)
@@ -399,7 +399,7 @@ static gboolean __stats_field_foreach_cb(GQuark field_id, const GValue *val, gpo
        webrtc_stats_prop_e prop;
        int i, j;
 
-       RET_VAL_IF(user_data == NULL, FALSE, "user_data is NULL");
+       ASSERT(user_data);
        RET_VAL_IF(stats->p_userdata == NULL, FALSE, "p_userdata is NULL");
        RET_VAL_IF(stats->p_userdata->webrtc == NULL, FALSE, "webrtc is NULL");
 
@@ -546,7 +546,7 @@ static gboolean __stats_codec_invoke_callback(const GstStructure *s, webrtc_stat
        stats_userdata_s stats_userdata = { .p_userdata = user_data, .type = type, .fields_list = fields_list, .export = true };
        gboolean ret;
 
-       RET_VAL_IF(user_data == NULL, FALSE, "user_data is NULL");
+       ASSERT(user_data);
 
        LOG_DEBUG_ENTER();
 
@@ -568,7 +568,7 @@ static gboolean __stats_inbound_rtp_invoke_callback(const GstStructure *s, webrt
        g_autoptr(GstStructure) rtpsource_stats = NULL;
        gboolean ret;
 
-       RET_VAL_IF(user_data == NULL, FALSE, "user_data is NULL");
+       ASSERT(user_data);
 
        LOG_DEBUG_ENTER();
 
@@ -610,7 +610,7 @@ static gboolean __stats_outbound_rtp_invoke_callback(const GstStructure *s, webr
        g_autoptr(GstStructure) rtpsource_stats = NULL;
        gboolean ret;
 
-       RET_VAL_IF(user_data == NULL, FALSE, "user_data is NULL");
+       ASSERT(user_data);
 
        LOG_DEBUG_ENTER();
 
@@ -642,7 +642,7 @@ static gboolean __stats_remote_inbound_rtp_invoke_callback(const GstStructure *s
        stats_userdata_s stats_userdata = { .p_userdata = user_data, .type = type, .fields_list = fields_list, .export = true };
        gboolean ret;
 
-       RET_VAL_IF(user_data == NULL, FALSE, "user_data is NULL");
+       ASSERT(user_data);
 
        LOG_DEBUG_ENTER();
 
@@ -660,9 +660,10 @@ static gboolean __stats_remote_inbound_rtp_invoke_callback(const GstStructure *s
 static gboolean __stats_remote_outbound_rtp_invoke_callback(const GstStructure *s, webrtc_stats_type_e type, stats_field_s **fields_list, promise_userdata_s *user_data)
 {
        stats_userdata_s stats_userdata = { .p_userdata = user_data, .type = type, .fields_list = fields_list, .export = true };
-       RET_VAL_IF(user_data == NULL, FALSE, "user_data is NULL");
        gboolean ret;
 
+       ASSERT(user_data);
+
        LOG_DEBUG_ENTER();
 
        if (user_data->dump)
@@ -679,7 +680,8 @@ static gboolean __stats_remote_outbound_rtp_invoke_callback(const GstStructure *
 static gboolean __stats_csrc_invoke_callback(const GstStructure *s, webrtc_stats_type_e type, stats_field_s **fields_list, promise_userdata_s *user_data)
 {
        stats_userdata_s stats_userdata = { .p_userdata = user_data, .type = type, .fields_list = fields_list };
-       RET_VAL_IF(user_data == NULL, FALSE, "user_data is NULL");
+
+       ASSERT(user_data);
 
        LOG_DEBUG_ENTER();
 
@@ -690,7 +692,8 @@ static gboolean __stats_csrc_invoke_callback(const GstStructure *s, webrtc_stats
 static gboolean __stats_peer_connection_invoke_callback(const GstStructure *s, webrtc_stats_type_e type, stats_field_s **fields_list, promise_userdata_s *user_data)
 {
        stats_userdata_s stats_userdata = { .p_userdata = user_data, .type = type, .fields_list = fields_list };
-       RET_VAL_IF(user_data == NULL, FALSE, "user_data is NULL");
+
+       ASSERT(user_data);
 
        LOG_DEBUG_ENTER();
 
@@ -700,7 +703,8 @@ static gboolean __stats_peer_connection_invoke_callback(const GstStructure *s, w
 static gboolean __stats_data_channel_invoke_callback(const GstStructure *s, webrtc_stats_type_e type, stats_field_s **fields_list, promise_userdata_s *user_data)
 {
        stats_userdata_s stats_userdata = { .p_userdata = user_data, .type = type, .fields_list = fields_list };
-       RET_VAL_IF(user_data == NULL, FALSE, "user_data is NULL");
+
+       ASSERT(user_data);
 
        LOG_DEBUG_ENTER();
 
@@ -711,7 +715,8 @@ static gboolean __stats_data_channel_invoke_callback(const GstStructure *s, webr
 static gboolean __stats_stream_invoke_callback(const GstStructure *s, webrtc_stats_type_e type, stats_field_s **fields_list, promise_userdata_s *user_data)
 {
        stats_userdata_s stats_userdata = { .p_userdata = user_data, .type = type, .fields_list = fields_list };
-       RET_VAL_IF(user_data == NULL, FALSE, "user_data is NULL");
+
+       ASSERT(user_data);
 
        LOG_DEBUG_ENTER();
 
@@ -722,7 +727,8 @@ static gboolean __stats_stream_invoke_callback(const GstStructure *s, webrtc_sta
 static gboolean __stats_transport_invoke_callback(const GstStructure *s, webrtc_stats_type_e type, stats_field_s **fields_list, promise_userdata_s *user_data)
 {
        stats_userdata_s stats_userdata = { .p_userdata = user_data, .type = type, .fields_list = fields_list };
-       RET_VAL_IF(user_data == NULL, FALSE, "user_data is NULL");
+
+       ASSERT(user_data);
 
        LOG_DEBUG_ENTER();
 
@@ -734,7 +740,7 @@ static gboolean __stats_candidate_pair_invoke_callback(const GstStructure *s, we
        stats_userdata_s stats_userdata = { .p_userdata = user_data, .type = type, .fields_list = fields_list, .export = true };
        gboolean ret;
 
-       RET_VAL_IF(user_data == NULL, FALSE, "user_data is NULL");
+       ASSERT(user_data);
 
        LOG_DEBUG_ENTER();
 
@@ -754,7 +760,7 @@ static gboolean __stats_local_candidate_invoke_callback(const GstStructure *s, w
        stats_userdata_s stats_userdata = { .p_userdata = user_data, .type = type, .fields_list = fields_list, .export = true };
        gboolean ret;
 
-       RET_VAL_IF(user_data == NULL, FALSE, "user_data is NULL");
+       ASSERT(user_data);
 
        LOG_DEBUG_ENTER();
 
@@ -774,7 +780,7 @@ static gboolean __stats_remote_candidate_invoke_callback(const GstStructure *s,
        stats_userdata_s stats_userdata = { .p_userdata = user_data, .type = type, .fields_list = fields_list, .export = true };
        gboolean ret;
 
-       RET_VAL_IF(user_data == NULL, FALSE, "user_data is NULL");
+       ASSERT(user_data);
 
        LOG_DEBUG_ENTER();
 
@@ -792,7 +798,8 @@ static gboolean __stats_remote_candidate_invoke_callback(const GstStructure *s,
 static gboolean __stats_certificate_invoke_callback(const GstStructure *s, webrtc_stats_type_e type, stats_field_s **fields_list, promise_userdata_s *user_data)
 {
        stats_userdata_s stats_userdata = { .p_userdata = user_data, .type = type, .fields_list = fields_list };
-       RET_VAL_IF(user_data == NULL, FALSE, "user_data is NULL");
+
+       ASSERT(user_data);
 
        LOG_DEBUG_ENTER();
 
@@ -854,7 +861,7 @@ static gboolean __webrtcbin_stats_cb(GQuark field_id, const GValue *value, gpoin
        const GstStructure *s;
        GstWebRTCStatsType type;
 
-       RET_VAL_IF(userdata == NULL, TRUE, "userdata is NULL");
+       ASSERT(userdata);
 
        if (GST_VALUE_HOLDS_STRUCTURE(value)) {
                s = gst_value_get_structure(value);
@@ -886,8 +893,9 @@ static void __webrtcbin_get_stats_cb(GstPromise *promise, gpointer user_data)
        const GstStructure *stats;
        promise_userdata_s *data = (promise_userdata_s *)user_data;
 
+       ASSERT(user_data);
+
        RET_IF(gst_promise_wait(promise) != GST_PROMISE_RESULT_REPLIED, "failed to gst_promise_wait()");
-       RET_IF(user_data == NULL, "user_data is NULL");
 
        stats = gst_promise_get_reply(promise);
        RET_IF(stats == NULL, "failed to gst_promise_get_reply()");
@@ -906,8 +914,8 @@ static void __dump_json_object_to_file(JsonObject *object, const gchar *path)
        JsonGenerator *generator;
        g_autoptr(GError) error = NULL;
 
-       RET_IF(object == NULL, "object is NULL");
-       RET_IF(path == NULL, "path is NULL");
+       ASSERT(object);
+       ASSERT(path);
 
        root = json_node_init_object(json_node_alloc(), object);
        generator = json_generator_new();
@@ -929,8 +937,7 @@ void _webrtcbin_foreach_stats(webrtc_s *webrtc, int type_mask, void *callback, v
        GstPromise *promise;
        promise_userdata_s *userdata;
        gint64 end_time = g_get_monotonic_time() + FOREACH_STATS_TIMEOUT_SEC * G_TIME_SPAN_SECOND;
-       bool dump_stats = false;
-       JsonObject *dump;
+       JsonObject *dump = NULL;
 
        RET_IF(webrtc == NULL, "webrtc is NULL");
        RET_IF(webrtc->gst.webrtcbin == NULL, "webrtcbin is NULL");
@@ -945,7 +952,6 @@ void _webrtcbin_foreach_stats(webrtc_s *webrtc, int type_mask, void *callback, v
                userdata->stats_cb.user_data = user_data;
        } else {
                /* this should be triggered by ini setting as of now, "stats log period" */
-               dump_stats = true;
                dump = json_object_new();
                userdata->dump = dump;
        }
@@ -961,7 +967,7 @@ void _webrtcbin_foreach_stats(webrtc_s *webrtc, int type_mask, void *callback, v
                LOG_ERROR("failed to get stats within %d sec. of timeout", FOREACH_STATS_TIMEOUT_SEC);
        g_mutex_unlock(&webrtc->stats_mutex);
 
-       if (dump_stats) {
+       if (dump) {
                g_autofree gchar *path = g_strdup_printf("/tmp/webrtc-stats-%d-%p.dump", getpid(), webrtc);
                __dump_json_object_to_file(dump, path);
                if (!g_list_find_custom(g_stats_dump_files, path, __str_equal))
index 807e3057419087bba4200b3a899b38b0a0b6ba19..9f441307f579fb89665c1fbe41e3a2a0b62945e2 100644 (file)
@@ -25,8 +25,7 @@ typedef struct _webrtc_tbm_bo_s {
 //LCOV_EXCL_START
 static void __tbm_bo_destroy_cb(webrtc_tbm_bo_s *tbm_bo)
 {
-       if (tbm_bo == NULL)
-               return;
+       ASSERT(tbm_bo);
 
        if (tbm_bo->bo && tbm_bo->used) {
                tbm_bo->used = false;
@@ -38,11 +37,11 @@ static void __tbm_bo_destroy_cb(webrtc_tbm_bo_s *tbm_bo)
        g_free(tbm_bo);
 }
 
-void _destroy_tbm_bo_list(webrtc_tbm_s *tbm)
+static void __destroy_tbm_bo_list(webrtc_tbm_s *tbm)
 {
        g_autoptr(GMutexLocker) locker = NULL;
 
-       RET_IF(tbm == NULL, "tbm is NULL");
+       ASSERT(tbm);
 
        locker = g_mutex_locker_new(&tbm->mutex);
 
@@ -160,7 +159,7 @@ void _release_tbm(webrtc_tbm_s *tbm)
 {
        RET_IF(tbm == NULL, "tbm is NULL");
 
-       _destroy_tbm_bo_list(tbm);
+       __destroy_tbm_bo_list(tbm);
 
        g_mutex_lock(&tbm->mutex);