Generate dot files to take snapshots of pipeline 29/244429/4
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 18 Sep 2020 09:38:02 +0000 (18:38 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 24 Sep 2020 07:11:56 +0000 (07:11 +0000)
Add code to create dot files when
 - after invoking state changed callback
 - a decodebin is added inside of pad-added callback of the webrtcbin
 - a rendering sink is added inside of pad-added callback of the decodebin

[Version] 0.1.28
[Issue Type] Debug

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

index 76050b03029acbfaf2cda69cc5000cd3b0e8e463..a54bc367cf38369918068d307ad171b21d32ae67 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.1.27
+Version:    0.1.28
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 98d0aa42df548b5e90124f3f18792aa4a55e3e1f..34225b106672a2a948577d3e0c3ed4508a8bb4c2 100644 (file)
@@ -51,6 +51,9 @@
 #define DEFAULT_AUDIO_CHANNELS            1
 #define DEFAULT_AUDIO_SAMPLERATE          8000
 
+#define DEFAULT_DOT_FILE_NAME_PREFIX      "webrtc"
+#define DEFAULT_DOT_DIRECTORY             "/tmp"
+
 typedef enum {
        CODEC_TYPE_OPUS,
        CODEC_TYPE_VORBIS,
@@ -97,12 +100,41 @@ do { \
        } \
 } while (0)
 
+#define GENERATE_DOT(x_webrtc, x_fmt, x_arg...) \
+do { \
+       gchar *dot_name; \
+       if (!x_webrtc->ini.generate_dot) \
+               break; \
+       dot_name = g_strdup_printf(""x_fmt"", x_arg); \
+       __generate_dot(x_webrtc, dot_name); \
+       g_free(dot_name); \
+} while (0)
+
 static const char* __state_str[] = {
        "IDLE",
        "NEGOTIATING",
        "PLAYING",
 };
 
+static void __generate_dot(webrtc_s *webrtc, const gchar *name)
+{
+       gchar *dot_name;
+
+       RET_IF(webrtc == NULL, "webrtc is NULL");
+       RET_IF(webrtc->gst.pipeline == NULL, "pipeline is NULL");
+
+       if (!name)
+               dot_name = g_strdup(DEFAULT_DOT_FILE_NAME_PREFIX);
+       else
+               dot_name = g_strconcat(DEFAULT_DOT_FILE_NAME_PREFIX, ".", name, NULL);
+
+       GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(webrtc->gst.pipeline), GST_DEBUG_GRAPH_SHOW_ALL, dot_name);
+
+       LOG_INFO("dot file[%s] is generated", dot_name);
+
+       g_free(dot_name);
+}
+
 /* Use g_free() to release the return value. */
 static gchar* __get_string_from_json_object(JsonObject *object)
 {
@@ -203,6 +235,8 @@ static void __invoke_state_changed_cb(webrtc_s *webrtc, webrtc_state_e old, webr
                ((webrtc_state_changed_cb)(webrtc->state_changed_cb.callback))((webrtc_h)webrtc, old, new, webrtc->state_changed_cb.user_data);
                LOG_DEBUG("<<< end of the callback");
        }
+
+       GENERATE_DOT(webrtc, "STATE_%s", __state_str[webrtc->state]);
 }
 
 static gboolean __bus_watch_cb(GstBus *bus, GstMessage *message, gpointer user_data)
@@ -256,8 +290,6 @@ static gboolean __bus_watch_cb(GstBus *bus, GstMessage *message, gpointer user_d
                LOG_INFO("GST_MESSAGE_STATE_CHANGED: %s", state_transition_name);
                g_free(state_transition_name);
 
-               /* TODO: generate dot */
-
                g_mutex_lock(&webrtc->mutex);
                if (webrtc->pend_state == webrtc->state) {
                        LOG_DEBUG("pend_state[%s] is same with current state", __state_str[webrtc->pend_state]);
@@ -405,8 +437,14 @@ int _ini_load(webrtc_s *webrtc)
        memset(&webrtc->ini, 0, sizeof(webrtc_ini_s));
 
        /* FIXME: load from ini file */
+       /* set it TRUE temporarily until ini ready */
+       webrtc->ini.generate_dot = TRUE;
 
-       webrtc->ini.generate_dot = FALSE;
+       if (webrtc->ini.generate_dot) {
+               /* FIXME: get path from ini */
+               LOG_INFO("dot file will be stored in [%s]", DEFAULT_DOT_DIRECTORY);
+               g_setenv("GST_DEBUG_DUMP_DOT_DIR", DEFAULT_DOT_DIRECTORY, FALSE);
+       }
 
        return WEBRTC_ERROR_NONE;
 }
@@ -830,6 +868,8 @@ static void __decodebin_pad_added_cb(GstElement *decodebin, GstPad *new_pad, gpo
 
        if (ret != WEBRTC_ERROR_NONE)
                LOG_ERROR("failed to build a rendering pipeline");
+
+       GENERATE_DOT(webrtc, "%s", GST_ELEMENT_NAME(decodebin));
 }
 
 static int __decodebin_autoplug_select_cb(GstElement *decodebin, GstPad *pad, GstCaps *caps, GstElementFactory *factory, gpointer user_data)
@@ -1029,6 +1069,8 @@ static void __webrtcbin_pad_added_cb(GstElement *webrtcbin, GstPad *new_pad, gpo
 
        ret = __add_rendering_sink_bin(webrtc, new_pad);
        RET_IF(ret != WEBRTC_ERROR_NONE, "failed to __add_rendering_sink_bin()");
+
+       GENERATE_DOT(webrtc, "webrtcbin_%s", GST_PAD_NAME(new_pad));
 }
 
 static void __webrtcbin_no_more_pads_cb(GstElement *webrtcbin, gpointer user_data)