gst: init new flag types to pass make check
[platform/upstream/gstreamer.git] / gst / gst.c
index 4e36d9c..ddd68a1 100644 (file)
--- a/gst/gst.c
+++ b/gst/gst.c
@@ -71,9 +71,6 @@
  *       N_("Output tags (also known as metadata)"), NULL},
  *   {NULL}
  *  };
- *  // must initialise the threading system before using any other GLib funtion
- *  if (!g_thread_supported ())
- *    g_thread_init (NULL);
  *  ctx = g_option_context_new ("[ADDITIONAL ARGUMENTS]");
  *  g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
  *  g_option_context_add_group (ctx, gst_init_get_option_group ());
@@ -179,6 +176,7 @@ enum
   ARG_DEBUG,
   ARG_DEBUG_DISABLE,
   ARG_DEBUG_NO_COLOR,
+  ARG_DEBUG_COLOR_MODE,
   ARG_DEBUG_HELP,
 #endif
   ARG_PLUGIN_SPEW,
@@ -242,7 +240,7 @@ gst_init_get_option_group (void)
         NULL},
     {"gst-debug-level", 0, 0, G_OPTION_ARG_CALLBACK,
           (gpointer) parse_goption_arg,
-          N_("Default debug level from 1 (only error) to 5 (anything) or "
+          N_("Default debug level from 1 (only error) to 9 (anything) or "
               "0 for no output"),
         N_("LEVEL")},
     {"gst-debug", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) parse_goption_arg,
@@ -253,6 +251,11 @@ gst_init_get_option_group (void)
     {"gst-debug-no-color", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
           (gpointer) parse_goption_arg, N_("Disable colored debugging output"),
         NULL},
+    {"gst-debug-color-mode", 0, 0, G_OPTION_ARG_CALLBACK,
+          (gpointer) parse_goption_arg,
+          N_("Changes coloring mode of the debug log. "
+              "Possible modes: off, on, disable, auto, unix"),
+        NULL},
     {"gst-debug-disable", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
         (gpointer) parse_goption_arg, N_("Disable debugging"), NULL},
 #endif
@@ -312,10 +315,6 @@ gst_init_get_option_group (void)
  * for some reason.  If you want your program to fail fatally,
  * use gst_init() instead.
  *
- * This function should be called before calling any other GLib functions. If
- * this is not an option, your program must initialise the GLib thread system
- * using g_thread_init() before any other GLib functions are called.
- *
  * Returns: %TRUE if GStreamer could be initialized.
  */
 gboolean
@@ -334,6 +333,7 @@ gst_init_check (int *argc, char **argv[], GError ** err)
 #ifndef GST_DISABLE_OPTION_PARSING
   ctx = g_option_context_new ("- GStreamer initialization");
   g_option_context_set_ignore_unknown_options (ctx, TRUE);
+  g_option_context_set_help_enabled (ctx, FALSE);
   group = gst_init_get_option_group ();
   g_option_context_add_group (ctx, group);
   res = g_option_context_parse (ctx, argc, argv, err);
@@ -370,10 +370,6 @@ gst_init_check (int *argc, char **argv[], GError ** err)
  * <link linkend="gst-running">Running GStreamer Applications</link>
  * for how to disable automatic registry updates.
  *
- * This function should be called before calling any other GLib functions. If
- * this is not an option, your program must initialise the GLib thread system
- * using g_thread_init() before any other GLib functions are called.
- *
  * <note><para>
  * This function will terminate your program if it was unable to initialize
  * GStreamer for some reason.  If you want your program to fall back,
@@ -381,7 +377,7 @@ gst_init_check (int *argc, char **argv[], GError ** err)
  * </para></note>
  *
  * WARNING: This function does not work in the same way as corresponding
- * functions in other glib-style libraries, such as gtk_init().  In
+ * functions in other glib-style libraries, such as gtk_init\(\). In
  * particular, unknown command line options cause this function to
  * abort program execution.
  */
@@ -465,6 +461,7 @@ static gboolean
 init_pre (GOptionContext * context, GOptionGroup * group, gpointer data,
     GError ** error)
 {
+  gchar *libdir;
   if (gst_initialized) {
     GST_DEBUG ("already initialized");
     return TRUE;
@@ -475,6 +472,7 @@ init_pre (GOptionContext * context, GOptionGroup * group, gpointer data,
 
 #ifndef GST_DISABLE_GST_DEBUG
   _priv_gst_debug_init ();
+  priv_gst_dump_dot_dir = g_getenv ("GST_DEBUG_DUMP_DOT_DIR");
 #endif
 
 #ifdef ENABLE_NLS
@@ -482,25 +480,27 @@ init_pre (GOptionContext * context, GOptionGroup * group, gpointer data,
   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 #endif /* ENABLE_NLS */
 
-#ifndef GST_DISABLE_GST_DEBUG
+  /* This is the earliest we can make stuff show up in the logs.
+   * So give some useful info about GStreamer here */
+#ifdef G_OS_WIN32
   {
-    const gchar *debug_list;
-
-    if (g_getenv ("GST_DEBUG_NO_COLOR") != NULL)
-      gst_debug_set_colored (FALSE);
+    gchar *basedir =
+        g_win32_get_package_installation_directory_of_module
+        (_priv_gst_dll_handle);
 
-    debug_list = g_getenv ("GST_DEBUG");
-    if (debug_list) {
-      gst_debug_set_threshold_from_string (debug_list, FALSE);
-    }
+    libdir = g_build_filename (basedir,
+#ifdef _DEBUG
+        "debug"
+#endif
+        "lib", NULL);
+    g_free (basedir);
   }
-
-  priv_gst_dump_dot_dir = g_getenv ("GST_DEBUG_DUMP_DOT_DIR");
+#else
+  libdir = g_strdup (LIBDIR);
 #endif
-  /* This is the earliest we can make stuff show up in the logs.
-   * So give some useful info about GStreamer here */
   GST_INFO ("Initializing GStreamer Core Library version %s", VERSION);
-  GST_INFO ("Using library installed in %s", LIBDIR);
+  GST_INFO ("Using library installed in %s", libdir);
+  g_free (libdir);
 
   /* Print some basic system details if possible (OS/architecture) */
 #ifdef HAVE_SYS_UTSNAME_H
@@ -573,6 +573,7 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
   _priv_gst_query_initialize ();
   _priv_gst_structure_initialize ();
   _priv_gst_caps_initialize ();
+  _priv_gst_caps_features_initialize ();
   _priv_gst_meta_initialize ();
 
   g_type_class_ref (gst_object_get_type ());
@@ -584,6 +585,7 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
   g_type_class_ref (gst_bus_get_type ());
   g_type_class_ref (gst_task_get_type ());
   g_type_class_ref (gst_clock_get_type ());
+  g_type_class_ref (gst_debug_color_mode_get_type ());
 
   gst_uri_handler_get_type ();
 
@@ -661,10 +663,12 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
   g_type_class_ref (gst_meta_flags_get_type ());
   g_type_class_ref (gst_toc_entry_type_get_type ());
   g_type_class_ref (gst_toc_scope_get_type ());
+  g_type_class_ref (gst_toc_loop_type_get_type ());
   g_type_class_ref (gst_control_binding_get_type ());
   g_type_class_ref (gst_control_source_get_type ());
   g_type_class_ref (gst_lock_flags_get_type ());
   g_type_class_ref (gst_allocator_flags_get_type ());
+  g_type_class_ref (gst_stream_flags_get_type ());
 
   _priv_gst_event_initialize ();
   _priv_gst_buffer_initialize ();
@@ -672,6 +676,7 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
   _priv_gst_buffer_list_initialize ();
   _priv_gst_sample_initialize ();
   _priv_gst_value_initialize ();
+  _priv_gst_context_initialize ();
 
   g_type_class_ref (gst_param_spec_fraction_get_type ());
   _priv_gst_tag_initialize ();
@@ -750,9 +755,27 @@ gst_debug_help (void)
   g_print ("---------------------+--------+--------------------------------\n");
 
   while (walk) {
+    gboolean on_unix;
     GstDebugCategory *cat = (GstDebugCategory *) walk->data;
+    GstDebugColorMode coloring = gst_debug_get_color_mode ();
+#ifdef G_OS_UNIX
+    on_unix = TRUE;
+#else
+    on_unix = FALSE;
+#endif
+
+    if (GST_DEBUG_COLOR_MODE_UNIX == coloring
+        || (on_unix && GST_DEBUG_COLOR_MODE_ON == coloring)) {
+      gchar *color = gst_debug_construct_term_color (cat->color);
 
-    if (gst_debug_is_colored ()) {
+      g_print ("%s%-20s\033[00m  %1d %s  %s%s\033[00m\n",
+          color,
+          gst_debug_category_get_name (cat),
+          gst_debug_category_get_threshold (cat),
+          gst_debug_level_get_name (gst_debug_category_get_threshold (cat)),
+          color, gst_debug_category_get_description (cat));
+      g_free (color);
+    } else if (GST_DEBUG_COLOR_MODE_ON == coloring && !on_unix) {
 #ifdef G_OS_WIN32
       gint color = gst_debug_construct_win_color (cat->color);
       const gint clear = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
@@ -766,16 +789,6 @@ gst_debug_help (void)
       g_print ("%s", gst_debug_category_get_description (cat));
       SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), clear);
       g_print ("\n");
-#else /* G_OS_WIN32 */
-      gchar *color = gst_debug_construct_term_color (cat->color);
-
-      g_print ("%s%-20s\033[00m  %1d %s  %s%s\033[00m\n",
-          color,
-          gst_debug_category_get_name (cat),
-          gst_debug_category_get_threshold (cat),
-          gst_debug_level_get_name (gst_debug_category_get_threshold (cat)),
-          color, gst_debug_category_get_description (cat));
-      g_free (color);
 #endif /* G_OS_WIN32 */
     } else {
       g_print ("%-20s  %1d %s  %s\n", gst_debug_category_get_name (cat),
@@ -822,6 +835,9 @@ parse_one_option (gint opt, const gchar * arg, GError ** err)
     case ARG_DEBUG_NO_COLOR:
       gst_debug_set_colored (FALSE);
       break;
+    case ARG_DEBUG_COLOR_MODE:
+      gst_debug_set_color_mode_from_string (arg);
+      break;
     case ARG_DEBUG_DISABLE:
       gst_debug_set_active (FALSE);
       break;
@@ -877,6 +893,7 @@ parse_goption_arg (const gchar * opt,
     "--gst-debug", ARG_DEBUG}, {
     "--gst-debug-disable", ARG_DEBUG_DISABLE}, {
     "--gst-debug-no-color", ARG_DEBUG_NO_COLOR}, {
+    "--gst-debug-color-mode", ARG_DEBUG_COLOR_MODE}, {
     "--gst-debug-help", ARG_DEBUG_HELP},
 #endif
     {
@@ -916,6 +933,7 @@ parse_goption_arg (const gchar * opt,
 void
 gst_deinit (void)
 {
+  GstBinClass *bin_class;
   GstClock *clock;
 
   GST_INFO ("deinitializing GStreamer");
@@ -925,6 +943,14 @@ gst_deinit (void)
     return;
   }
 
+  g_thread_pool_set_max_unused_threads (0);
+  bin_class = GST_BIN_CLASS (g_type_class_peek (gst_bin_get_type ()));
+  if (bin_class->pool != NULL) {
+    g_thread_pool_free (bin_class->pool, FALSE, TRUE);
+    bin_class->pool = NULL;
+  }
+  gst_task_cleanup_all ();
+
   g_slist_foreach (_priv_gst_preload_plugins, (GFunc) g_free, NULL);
   g_slist_free (_priv_gst_preload_plugins);
   _priv_gst_preload_plugins = NULL;
@@ -1034,9 +1060,11 @@ gst_deinit (void)
   g_type_class_unref (g_type_class_peek (gst_control_binding_get_type ()));
   g_type_class_unref (g_type_class_peek (gst_control_source_get_type ()));
   g_type_class_unref (g_type_class_peek (gst_toc_entry_type_get_type ()));
+  g_type_class_unref (g_type_class_peek (gst_toc_loop_type_get_type ()));
   g_type_class_unref (g_type_class_peek (gst_lock_flags_get_type ()));
   g_type_class_unref (g_type_class_peek (gst_allocator_flags_get_type ()));
-
+  g_type_class_unref (g_type_class_peek (gst_stream_flags_get_type ()));
+  g_type_class_unref (g_type_class_peek (gst_debug_color_mode_get_type ()));
 
   gst_deinitialized = TRUE;
   GST_INFO ("deinitialized GStreamer");