static void parse_debug_list (const gchar * list) { gchar **split; gchar **walk; g_assert (list); split = g_strsplit (list, ",", 0); for (walk = split; *walk; walk++) { if (strchr (*walk, ':')) { gchar **values = g_strsplit (*walk, ":", 2); if (values[0] && values[1]) { gint level; const gchar *category; if (parse_debug_category (values[0], &category) && parse_debug_level (values[1], &level)) gst_debug_set_threshold_for_name (category, level); } g_strfreev (values); } else { gint level; if (parse_debug_level (*walk, &level)) gst_debug_set_default_threshold (level); } } g_strfreev (split); }
void test_flags() { GstElement *element; GError *err = NULL; xmlfile = "test_flags"; std_log(LOG_FILENAME_LINE, "Test Started test_flags"); /* avoid misleading 'no such element' error debug messages when using cvs */ if (!g_getenv ("GST_DEBUG")) gst_debug_set_default_threshold (GST_LEVEL_NONE); /* default behaviour is to return any already constructed bins/elements */ element = gst_parse_launch_full ("fakesrc ! coffeesink", NULL, 0, &err); fail_unless (err != NULL, "expected error"); fail_unless_equals_int (err->code, GST_PARSE_ERROR_NO_SUCH_ELEMENT); fail_unless (element != NULL, "expected partial pipeline/element"); g_error_free (err); err = NULL; gst_object_unref (element); /* test GST_PARSE_FLAG_FATAL_ERRORS */ element = gst_parse_launch_full ("fakesrc ! coffeesink", NULL, GST_PARSE_FLAG_FATAL_ERRORS, &err); fail_unless (err != NULL, "expected error"); fail_unless_equals_int (err->code, GST_PARSE_ERROR_NO_SUCH_ELEMENT); fail_unless (element == NULL, "expected NULL return with FATAL_ERRORS"); g_error_free (err); err = NULL; std_log(LOG_FILENAME_LINE, "Test Successful"); create_xml(0); }
bool LLMediaImplGStreamer::setDebugLevel( LLMediaBase::EDebugLevel level ) { // Do parent class stuff. LLMediaImplCommon::setDebugLevel(level); // Set GStreamer verbosity. gst_debug_set_default_threshold( (GstDebugLevel)level ); return true; }
// must be called after gst_init(), see comment in setup_log_capture() void bt_check_init (void) { _priv_bt_info_start_time = gst_util_get_timestamp (); // disable logging from gstreamer itself gst_debug_remove_log_function (gst_debug_log_default); // set e.g. GST_DEBUG="bt-core:DEBUG" if more details are needed if (gst_debug_get_default_threshold () < GST_LEVEL_INFO) { gst_debug_set_default_threshold (GST_LEVEL_INFO); } // register our plugins extern gboolean bt_test_plugin_init (GstPlugin * plugin); gst_plugin_register_static (GST_VERSION_MAJOR, GST_VERSION_MINOR, "bt-test", "buzztrax test plugin - several unit test support elements", bt_test_plugin_init, VERSION, "LGPL", PACKAGE, PACKAGE_NAME, "http://www.buzztrax.org"); GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "bt-check", 0, "music production environment / unit tests"); const gchar *checks = g_getenv ("BT_CHECKS"); if (BT_IS_STRING (checks)) { // we're leaking this funcs = g_strsplit (checks, ",", -1); } #ifdef HAVE_SETRLIMIT // only fork mode limit cpu/mem usage const gchar *mode = g_getenv ("CK_FORK"); if (!mode || strcmp (mode, "no")) { struct rlimit rl; rl.rlim_max = RLIM_INFINITY; // limit cpu in seconds rl.rlim_cur = 20; if (setrlimit (RLIMIT_CPU, &rl) < 0) perror ("setrlimit(RLIMIT_CPU) failed"); // limit process’s data size in bytes // if we get failing tests and "mmap() failed: Cannot allocate memory" // this limit needs to be increased rl.rlim_cur = 515 * 1024 * 1024; // 0.5GB if (setrlimit (RLIMIT_DATA, &rl) < 0) perror ("setrlimit(RLIMIT_DATA) failed"); } #endif }
static void expected_fail_pipe (const gchar * pipe_descr) { GstElement *pipeline; GError *error = NULL; #ifndef GST_DISABLE_GST_DEBUG gst_debug_set_default_threshold (GST_LEVEL_NONE); #endif pipeline = gst_parse_launch (pipe_descr, &error); fail_unless (pipeline == NULL || error != NULL, "Expected failure pipeline %s: succeeded!", pipe_descr); g_error_free (error); /* We get a pipeline back even when parsing has failed, sometimes! */ if (pipeline) gst_object_unref (pipeline); }
int main (int argc, char *argv[]) { HTTPMgmt *httpmgmt; HTTPStreaming *httpstreaming; GMainLoop *loop; GOptionContext *ctx; GError *err = NULL; gboolean foreground; struct rlimit rlim; GDateTime *datetime; gchar exe_path[512], *date; ctx = g_option_context_new (NULL); g_option_context_add_main_entries (ctx, options, NULL); g_option_context_add_group (ctx, gst_init_get_option_group ()); if (!g_option_context_parse (ctx, &argc, &argv, &err)) { g_print ("Error initializing: %s\n", GST_STR_NULL (err->message)); exit (1); } g_option_context_free (ctx); GST_DEBUG_CATEGORY_INIT (GSTREAMILL, "gstreamill", 0, "gstreamill log"); if (version) { print_version_info (); exit (0); } /* stop gstreamill. */ if (stop) { gchar *pid_str; gint pid; g_file_get_contents (PID_FILE, &pid_str, NULL, NULL); if (pid_str == NULL) { g_print ("File %s not found, check if gstreamill is running.\n", PID_FILE); exit (1); } pid = atoi (pid_str); g_free (pid_str); g_print ("stoping gstreamill with pid %d ...\n", pid); kill (pid, SIGTERM); exit (0); } /* readlink exe path before setuid, on CentOS, readlink exe path after setgid/setuid failure on permission denied */ memset (exe_path, '\0', sizeof (exe_path)); if (readlink ("/proc/self/exe", exe_path, sizeof (exe_path)) == -1) { g_print ("Read /proc/self/exe error: %s", g_strerror (errno)); exit (2); } if (prepare_gstreamill_run_dir () != 0) { g_print ("Can't create gstreamill run directory\n"); exit (3); } /* if (set_user_and_group () != 0) { g_print ("set user and group failure\n"); exit (4); } */ if (job_file != NULL) { /* gstreamill command with job, run in foreground */ foreground = TRUE; } else { /* gstreamill command without job, run in background */ foreground = FALSE; } if (gst_debug_get_default_threshold () < GST_LEVEL_WARNING) { gst_debug_set_default_threshold (GST_LEVEL_WARNING); } /* initialize ts segment static plugin */ if (!gst_plugin_register_static (GST_VERSION_MAJOR, GST_VERSION_MINOR, "tssegment", "ts segment plugin", ts_segment_plugin_init, "0.1.0", "GPL", "GStreamer", "GStreamer", "http://gstreamer.net/")) { GST_ERROR ("registe tssegment error"); exit (17); } /* subprocess, create_job_process */ if (shm_name != NULL) { gint fd; gchar *job_desc, *p; Job *job; gchar *log_path, *name; gint ret; /* set subprocess maximum of core file */ rlim.rlim_cur = 0; rlim.rlim_max = 0; if (setrlimit (RLIMIT_CORE, &rlim) == -1) { GST_ERROR ("setrlimit error: %s", g_strerror (errno)); } /* read job description from share memory */ job_desc = NULL; fd = shm_open (shm_name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (ftruncate (fd, job_length) == -1) { exit (5); } p = mmap (NULL, job_length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); job_desc = g_strdup (p); if ((job_desc != NULL) && (!jobdesc_is_valid (job_desc))) { exit (6); } /* initialize log */ name = (gchar *)jobdesc_get_name (job_desc); if (!jobdesc_is_live (job_desc)) { gchar *p; p = jobdesc_get_log_path (job_desc); log_path = g_build_filename (p, "gstreamill.log", NULL); g_free (p); } else { log_path = g_build_filename (log_dir, name, "gstreamill.log", NULL); } ret = init_log (log_path); g_free (log_path); if (ret != 0) { exit (7); } /* launch a job. */ datetime = g_date_time_new_now_local (); date = g_date_time_format (datetime, "%b %d %H:%M:%S"); fprintf (_log->log_hd, "\n*** %s : job %s starting ***\n\n", date, name); g_date_time_unref (datetime); g_free (date); job = job_new ("name", name, "job", job_desc, NULL); job->is_live = jobdesc_is_live (job_desc); job->eos = FALSE; loop = g_main_loop_new (NULL, FALSE); GST_INFO ("Initializing job ..."); if (job_initialize (job, TRUE) != 0) { GST_ERROR ("initialize job failure, exit"); exit (8); } GST_INFO ("Initializing job done"); GST_INFO ("Initializing job's encoders output ..."); if (job_encoders_output_initialize (job) != 0) { GST_ERROR ("initialize job encoders' output failure, exit"); exit (8); } GST_INFO ("Initializing job's encoders output done"); GST_INFO ("Starting job ..."); if (job_start (job) != 0) { GST_ERROR ("start livejob failure, exit"); exit (9); } datetime = g_date_time_new_now_local (); date = g_date_time_format (datetime, "%b %d %H:%M:%S"); fprintf (_log->log_hd, "\n*** %s : job %s started ***\n\n", date, name); g_date_time_unref (datetime); g_free (date); g_free (name); g_free (job_desc); signal (SIGPIPE, SIG_IGN); signal (SIGUSR1, sighandler); signal (SIGTERM, stop_job); g_main_loop_run (loop); } else { /* set parent process maximum of core file */ rlim.rlim_cur = RLIM_INFINITY; rlim.rlim_max = RLIM_INFINITY; if (setrlimit (RLIMIT_CORE, &rlim) == -1) { GST_ERROR ("setrlimit error: %s", g_strerror (errno)); } } /* run in background? */ if (!foreground) { gchar *path; gint ret; /* pid file exist? */ if (g_file_test (PID_FILE, G_FILE_TEST_EXISTS)) { g_print ("file %s found, gstreamill already running !!!\n", PID_FILE); exit (10); } /* media directory */ path = g_strdup_printf ("%s/dvr", MEDIA_LOCATION); if (!g_file_test (path, G_FILE_TEST_EXISTS)) { g_printf ("Create DVR directory: %s", path); if (g_mkdir_with_parents (path, 0755) != 0) { g_printf ("Create DVR directory failure: %s", path); } } g_free (path); path = g_strdup_printf ("%s/transcode/in", MEDIA_LOCATION); if (!g_file_test (path, G_FILE_TEST_EXISTS)) { g_printf ("Create transcode directory: %s", path); if (g_mkdir_with_parents (path, 0755) != 0) { g_printf ("Create transcode directory failure: %s", path); } } g_free (path); path = g_strdup_printf ("%s/transcode/out", MEDIA_LOCATION); if (!g_file_test (path, G_FILE_TEST_EXISTS)) { g_printf ("Create transcode directory: %s", path); if (g_mkdir_with_parents (path, 0755) != 0) { g_printf ("Create transcode directory failure: %s", path); } } g_free (path); /* log to file */ path = g_build_filename (log_dir, "gstreamill.log", NULL); ret = init_log (path); g_free (path); if (ret != 0) { g_print ("Init log error, ret %d.\n", ret); exit (11); } /* daemonize */ if (daemon (0, 0) != 0) { fprintf (_log->log_hd, "Failed to daemonize"); remove_pid_file (); exit (1); } /* create pid file */ if (create_pid_file () != 0) { exit (1); } /* customize signal */ signal (SIGUSR1, sighandler); signal (SIGTERM, stop_gstreamill); datetime = g_date_time_new_now_local (); date = g_date_time_format (datetime, "%b %d %H:%M:%S"); fprintf (_log->log_hd, "\n*** %s : gstreamill started ***\n\n", date); g_free (date); g_date_time_unref (datetime); } /* ignore SIGPIPE */ signal (SIGPIPE, SIG_IGN); loop = g_main_loop_new (NULL, FALSE); /* gstreamill */ gstreamill = gstreamill_new ("daemon", !foreground, "log_dir", log_dir, "exe_path", exe_path, NULL); if (gstreamill_start (gstreamill) != 0) { GST_ERROR ("start gstreamill error, exit."); remove_pid_file (); exit (12); } /* httpstreaming, pull */ httpstreaming = httpstreaming_new ("gstreamill", gstreamill, "address", http_streaming, NULL); if (httpstreaming_start (httpstreaming, 10) != 0) { GST_ERROR ("start httpstreaming error, exit."); remove_pid_file (); exit (13); } if (!foreground) { /* run in background, management via http */ httpmgmt = httpmgmt_new ("gstreamill", gstreamill, "address", http_mgmt, NULL); if (httpmgmt_start (httpmgmt) != 0) { GST_ERROR ("start http mangment error, exit."); remove_pid_file (); exit (14); } } else { /* run in foreground, start job */ gchar *job, *p, *result; JSON_Value *val; JSON_Object *obj; /* ctrl-c, stop gstreamill */ signal (SIGINT, stop_gstreamill); /* ctrl-\, stop gstreamill */ signal (SIGQUIT, stop_gstreamill); if (!g_file_get_contents (job_file, &job, NULL, NULL)) { GST_ERROR ("Read job file %s error.", job_file); exit (15); } p = gstreamill_job_start (gstreamill, job); val = json_parse_string (p); obj = json_value_get_object (val); result = (gchar *)json_object_get_string (obj, "result"); GST_INFO ("start job result: %s.", result); if (g_strcmp0 (result, "success") != 0) { exit (16); } json_value_free (val); g_free (p); } g_main_loop_run (loop); return 0; }
static gboolean parse_one_option (gint opt, const gchar * arg, GError ** err) { switch (opt) { case ARG_VERSION: g_print ("GStreamer Core Library version %s\n", PACKAGE_VERSION); exit (0); case ARG_FATAL_WARNINGS:{ GLogLevelFlags fatal_mask; fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK); fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL; g_log_set_always_fatal (fatal_mask); break; } #ifndef GST_DISABLE_GST_DEBUG case ARG_DEBUG_LEVEL:{ GstDebugLevel tmp = GST_LEVEL_NONE; tmp = (GstDebugLevel) strtol (arg, NULL, 0); if (((guint) tmp) < GST_LEVEL_COUNT) { gst_debug_set_default_threshold (tmp); } break; } case ARG_DEBUG: gst_debug_set_threshold_from_string (arg, FALSE); break; 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; case ARG_DEBUG_HELP: gst_debug_help (); exit (0); #endif case ARG_PLUGIN_SPEW: break; case ARG_PLUGIN_PATH: #ifndef GST_DISABLE_REGISTRY split_and_iterate (arg, G_SEARCHPATH_SEPARATOR_S, add_path_func, NULL); #endif /* GST_DISABLE_REGISTRY */ break; case ARG_PLUGIN_LOAD: split_and_iterate (arg, ",", prepare_for_load_plugin_func, NULL); break; case ARG_SEGTRAP_DISABLE: _gst_disable_segtrap = TRUE; break; case ARG_REGISTRY_UPDATE_DISABLE: #ifndef GST_DISABLE_REGISTRY _priv_gst_disable_registry_update = TRUE; #endif break; case ARG_REGISTRY_FORK_DISABLE: gst_registry_fork_set_enabled (FALSE); break; default: g_set_error (err, G_OPTION_ERROR, G_OPTION_ERROR_UNKNOWN_OPTION, _("Unknown option")); return FALSE; } return TRUE; }
void test_missing_elements() { GstParseContext *ctx; GstElement *element; GError *err = NULL; gchar **arr; xmlfile = "test_missing_elements"; std_log(LOG_FILENAME_LINE, "Test Started test_missing_elements"); /* avoid misleading 'no such element' error debug messages when using cvs */ if (!g_getenv ("GST_DEBUG")) gst_debug_set_default_threshold (GST_LEVEL_NONE); /* one missing element */ ctx = gst_parse_context_new (); element = gst_parse_launch_full ("fakesrc ! coffeesink", ctx, GST_PARSE_FLAG_FATAL_ERRORS, &err); fail_unless (err != NULL, "expected error"); fail_unless_equals_int (err->code, GST_PARSE_ERROR_NO_SUCH_ELEMENT); fail_unless (element == NULL, "expected NULL return with FATAL_ERRORS"); arr = gst_parse_context_get_missing_elements (ctx); fail_unless (arr != NULL, "expected missing elements"); fail_unless_equals_string (arr[0], "coffeesink"); fail_unless (arr[1] == NULL); g_strfreev (arr); gst_parse_context_free (ctx); g_error_free (err); err = NULL; /* multiple missing elements */ ctx = gst_parse_context_new (); element = gst_parse_launch_full ("fakesrc ! bogusenc ! identity ! goomux ! " "fakesink", ctx, GST_PARSE_FLAG_FATAL_ERRORS, &err); fail_unless (err != NULL, "expected error"); fail_unless_equals_int (err->code, GST_PARSE_ERROR_NO_SUCH_ELEMENT); fail_unless (element == NULL, "expected NULL return with FATAL_ERRORS"); arr = gst_parse_context_get_missing_elements (ctx); fail_unless (arr != NULL, "expected missing elements"); fail_unless_equals_string (arr[0], "bogusenc"); fail_unless_equals_string (arr[1], "goomux"); fail_unless (arr[2] == NULL); g_strfreev (arr); gst_parse_context_free (ctx); g_error_free (err); err = NULL; /* multiple missing elements, different link pattern */ ctx = gst_parse_context_new (); element = gst_parse_launch_full ("fakesrc ! bogusenc ! mux.sink " "blahsrc ! goomux name=mux ! fakesink fakesrc ! goosink", ctx, GST_PARSE_FLAG_FATAL_ERRORS, &err); fail_unless (err != NULL, "expected error"); fail_unless_equals_int (err->code, GST_PARSE_ERROR_NO_SUCH_ELEMENT); fail_unless (element == NULL, "expected NULL return with FATAL_ERRORS"); arr = gst_parse_context_get_missing_elements (ctx); fail_unless (arr != NULL, "expected missing elements"); fail_unless_equals_string (arr[0], "bogusenc"); fail_unless_equals_string (arr[1], "blahsrc"); fail_unless_equals_string (arr[2], "goomux"); fail_unless_equals_string (arr[3], "goosink"); fail_unless (arr[4] == NULL); g_strfreev (arr); gst_parse_context_free (ctx); g_error_free (err); err = NULL; std_log(LOG_FILENAME_LINE, "Test Successful"); create_xml(0); }