1 /* SPDX-License-Identifier: LGPL-2.1-only */
3 * GStreamer Pipeline from/to PBTxt Converter Parser
4 * Copyright (C) 2021 MyungJoo Ham <myungjoo.ham@samsung.com>
5 * Copyright (C) 2021 Dongju Chae <dongju.chae@samsung.com>
10 * @brief Top-level program to parse gst pipeline and pbtxt
11 * @see http://github.com/nnstreamer/nnstreamer
12 * @author Dongju Chae <dongju.chae@samsung.com>
13 * @bug No known bugs except for NYI items
18 #define G_LOG_USE_STRUCTURED 1
24 #define INPUT_MAXLEN (512)
26 static gboolean from_pbtxt = FALSE;
27 static gboolean verbose = FALSE;
29 static GOptionEntry entries[] = {
30 {"from-pbtxt", 'p', 0, G_OPTION_ARG_NONE, &from_pbtxt,
31 "From pbtxt to gst pipeline", NULL},
32 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Enable verbose messages",
37 /** @brief Get input string for parsing */
39 get_input_string (char *str)
41 GIOChannel *channel = g_io_channel_unix_new (fileno (stdin));
47 status = g_io_channel_set_encoding (channel, "UTF-8", &error);
48 if (status == G_IO_STATUS_ERROR) {
49 g_printerr ("Error detected while setting encoding: %s\n", error->message);
56 g_io_channel_read_chars (channel, str, INPUT_MAXLEN, &length, &error);
57 if (status == G_IO_STATUS_ERROR) {
58 g_printerr ("Error detected while reading an input string: %s\n",
65 if (status != G_IO_STATUS_NORMAL) {
70 str[length - 1] = '\x00';
73 g_io_channel_shutdown (channel, TRUE, NULL);
77 /** @brief Log handler */
79 log_handler (const gchar * log_domain, GLogLevelFlags log_level,
80 const gchar * message, gpointer user_data)
85 g_printerr ("%s", message);
88 /** @brief Main routine for this program */
90 main (int argc, char *argv[])
93 GOptionContext *context;
94 char input_str[INPUT_MAXLEN] = { '\x00' };
95 GLogLevelFlags log_flags;
99 g_option_context_new ("- Prototxt to/from GStreamer Pipeline Converver");
100 g_option_context_add_main_entries (context, entries, NULL);
101 if (!g_option_context_parse (context, &argc, &argv, &error)) {
102 g_printerr ("Option parsing failed: %s\n", error->message);
103 g_error_free (error);
106 g_option_context_free (context);
109 g_print ("NYI: pbtxt-to-gstpipe conversion\n");
113 if (!get_input_string (input_str)) {
114 g_printerr ("Unable to get an input string for GStreamer pipeline\n");
118 /* all messages from glib */
119 log_flags = G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION;
121 log_flags &= ~G_LOG_LEVEL_DEBUG;
123 g_log_set_handler (NULL, log_flags, log_handler, NULL);
125 pipeline = priv_gst_parse_launch (input_str, NULL, NULL, __PARSE_FLAG_NONE);
126 if (pipeline == NULL) {
127 g_printerr ("Unable to parse the given pipeline string");
131 convert_to_pbtxt (pipeline);
132 nnstparser_element_unref (pipeline);