1 /* GStreamer Editing Services
2 * Copyright (C) 2015 Mathieu Duponchelle <mathieu.duponchelle@opencreed.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #include <glib/gprintf.h>
25 #include "../ges/ges-internal.h"
27 #undef GST_CAT_DEFAULT
29 /* Copy of GST_ASCII_IS_STRING */
30 #define ASCII_IS_STRING(c) (g_ascii_isalnum((c)) || ((c) == '_') || \
31 ((c) == '-') || ((c) == '+') || ((c) == '/') || ((c) == ':') || \
34 /* g_free after usage */
36 _sanitize_argument (gchar * arg, const gchar * prev_arg)
38 gboolean expect_equal = !(arg[0] == '+' || g_str_has_prefix (arg, "set-")
39 || prev_arg == NULL || prev_arg[0] == '+'
40 || g_str_has_prefix (prev_arg, "set-"));
41 gboolean need_wrap = FALSE;
42 gchar *first_equal = NULL;
44 gchar *new_string, *tmp_string;
47 for (tmp_string = arg; *tmp_string != '\0'; tmp_string++) {
48 if (expect_equal && first_equal == NULL && *tmp_string == '=') {
49 first_equal = tmp_string;
50 /* if this is the first equal, then don't count it as necessarily
52 } else if (!ASCII_IS_STRING (*tmp_string)) {
59 return g_strdup (arg);
62 wrap_start = first_equal + 1;
66 /* need to escape any '"' or '\\' to correctly parse in as a structure */
68 for (tmp_string = wrap_start; *tmp_string != '\0'; tmp_string++) {
69 if (*tmp_string == '"' || *tmp_string == '\\')
73 tmp_string = new_string =
74 g_malloc (sizeof (gchar) * (strlen (arg) + num_escape + 3));
76 while (arg != wrap_start)
77 *(tmp_string++) = *(arg++);
78 (*tmp_string++) = '"';
80 while (*arg != '\0') {
81 if (*arg == '"' || *arg == '\\')
82 (*tmp_string++) = '\\';
83 *(tmp_string++) = *(arg++);
85 *(tmp_string++) = '"';
92 sanitize_timeline_description (gchar ** args, GESLauncherParsedOptions * opts)
95 gchar *prev_arg = NULL;
97 GString *timeline_str;
99 gchar *string = g_strdup (" ");
101 for (i = 1; args[i]; i++) {
103 gchar *sanitized = _sanitize_argument (args[i], prev_arg);
105 new_string = g_strconcat (string, " ", sanitized, NULL);
119 if (strstr (string, "+track")) {
120 gchar *res = g_strconcat ("ges:", string, NULL);
126 timeline_str = g_string_new (string);
129 if (opts->track_types & GES_TRACK_TYPE_VIDEO) {
130 track_def = g_string_new (" +track video ");
132 if (opts->video_track_caps)
133 g_string_append_printf (track_def, " restrictions=[%s] ",
134 opts->video_track_caps);
136 g_string_prepend (timeline_str, track_def->str);
137 g_string_free (track_def, TRUE);
140 if (opts->track_types & GES_TRACK_TYPE_AUDIO) {
141 track_def = g_string_new (" +track audio ");
143 if (opts->audio_track_caps)
144 g_string_append_printf (track_def, " restrictions=[%s] ",
145 opts->audio_track_caps);
147 g_string_prepend (timeline_str, track_def->str);
148 g_string_free (track_def, TRUE);
151 g_string_prepend (timeline_str, "ges:");
153 return g_string_free (timeline_str, FALSE);
157 get_flags_from_string (GType type, const gchar * str_flags, guint * flags)
159 GValue value = G_VALUE_INIT;
160 g_value_init (&value, type);
162 if (!gst_value_deserialize (&value, str_flags)) {
163 g_value_unset (&value);
168 *flags = g_value_get_flags (&value);
169 g_value_unset (&value);
175 ensure_uri (const gchar * location)
177 if (gst_uri_is_valid (location))
178 return g_strdup (location);
180 return gst_filename_to_uri (location, NULL);
184 parse_encoding_profile (const gchar * format)
186 GstEncodingProfile *profile;
187 GValue value = G_VALUE_INIT;
189 g_value_init (&value, GST_TYPE_ENCODING_PROFILE);
191 if (!gst_value_deserialize (&value, format)) {
192 g_value_reset (&value);
197 profile = g_value_dup_object (&value);
198 g_value_reset (&value);
204 print_enum (GType enum_type)
206 GEnumClass *enum_class = G_ENUM_CLASS (g_type_class_ref (enum_type));
209 for (i = 0; i < enum_class->n_values; i++) {
210 gst_print ("%s\n", enum_class->values[i].value_nick);
213 g_type_class_unref (enum_class);
217 ges_print (GstDebugColorFlags c, gboolean err, gboolean nline,
218 const gchar * format, va_list var_args)
220 GString *str = g_string_new (NULL);
221 GstDebugColorMode color_mode;
223 const gchar *clear = NULL;
225 color_mode = gst_debug_get_color_mode ();
227 if (color_mode == GST_DEBUG_COLOR_MODE_UNIX) {
229 if (color_mode != GST_DEBUG_COLOR_MODE_OFF) {
232 color = gst_debug_construct_term_color (c);
236 g_string_append (str, color);
240 g_string_append_vprintf (str, format, var_args);
243 g_string_append_c (str, '\n');
246 g_string_append (str, clear);
249 gst_printerr ("%s", str->str);
251 gst_print ("%s", str->str);
253 g_string_free (str, TRUE);
257 ges_ok (const gchar * format, ...)
261 va_start (var_args, format);
262 ges_print (GST_DEBUG_FG_GREEN, FALSE, TRUE, format, var_args);
267 ges_warn (const gchar * format, ...)
271 va_start (var_args, format);
272 ges_print (GST_DEBUG_FG_YELLOW, TRUE, TRUE, format, var_args);
277 ges_printerr (const gchar * format, ...)
281 va_start (var_args, format);
282 ges_print (GST_DEBUG_FG_RED, TRUE, TRUE, format, var_args);
287 get_file_extension (gchar * uri)
296 if (uri[find] == '.')
304 return g_strdup (&uri[find + 1]);
308 get_type_icon (gpointer obj)
310 if (GST_IS_ENCODING_AUDIO_PROFILE (obj) || GST_IS_DISCOVERER_AUDIO_INFO (obj))
312 else if (GST_IS_ENCODING_VIDEO_PROFILE (obj)
313 || GST_IS_DISCOVERER_VIDEO_INFO (obj))
315 else if (GST_IS_ENCODING_CONTAINER_PROFILE (obj)
316 || GST_IS_DISCOVERER_CONTAINER_INFO (obj))
323 print_profile (GstEncodingProfile * profile, const gchar * prefix)
325 const gchar *name = gst_encoding_profile_get_name (profile);
326 const gchar *desc = gst_encoding_profile_get_description (profile);
327 GstCaps *format = gst_encoding_profile_get_format (profile);
328 gchar *capsdesc = NULL;
330 if (gst_caps_is_fixed (format))
331 capsdesc = gst_pb_utils_get_codec_description (format);
333 capsdesc = gst_caps_to_string (format);
335 if (GST_IS_ENCODING_CONTAINER_PROFILE (profile)) {
336 gst_print ("%s> %s %s: %s%s%s%s\n", prefix,
337 get_type_icon (profile),
338 capsdesc, name ? name : "",
339 desc ? " (" : "", desc ? desc : "", desc ? ")" : "");
342 gst_print ("%s%s %s%s%s%s%s%s", prefix, get_type_icon (profile),
343 name ? name : capsdesc, desc ? ": " : "", desc ? desc : "",
344 name ? " (" : "", name ? capsdesc : "", name ? ")" : "");
346 if (GST_IS_ENCODING_VIDEO_PROFILE (profile)) {
347 GstCaps *caps = gst_encoding_profile_get_restriction (profile);
349 if (!caps && gst_caps_is_fixed (format))
350 caps = gst_caps_ref (format);
355 if (gst_video_info_from_caps (&info, caps)) {
356 gst_print (" (%dx%d", info.width, info.height);
358 gst_print ("@%d/%dfps", info.fps_n, info.fps_d);
361 gst_caps_unref (caps);
363 } else if (GST_IS_ENCODING_AUDIO_PROFILE (profile)) {
364 GstCaps *caps = gst_encoding_profile_get_restriction (profile);
366 if (!caps && gst_caps_is_fixed (format))
367 caps = gst_caps_ref (format);
372 if (gst_caps_is_fixed (caps) && gst_audio_info_from_caps (&info, caps))
373 gst_print (" (%d channels @ %dhz)", info.channels, info.rate);
374 gst_caps_unref (caps);
382 gst_caps_unref (format);
388 describe_encoding_profile (GstEncodingProfile * profile)
390 g_return_if_fail (GST_IS_ENCODING_PROFILE (profile));
392 print_profile (profile, " ");
393 if (GST_IS_ENCODING_CONTAINER_PROFILE (profile)) {
397 gst_encoding_container_profile_get_profiles
398 (GST_ENCODING_CONTAINER_PROFILE (profile)); tmp; tmp = tmp->next)
399 print_profile (tmp->data, " - ");
404 describe_stream_info (GstDiscovererStreamInfo * sinfo, GString * desc)
409 caps = gst_discoverer_stream_info_get_caps (sinfo);
410 capsdesc = gst_pb_utils_get_codec_description (caps);
412 capsdesc = gst_caps_to_string (caps);
413 gst_caps_unref (caps);
415 g_string_append_printf (desc, "%s%s%s", desc->len ? ", " : "",
416 get_type_icon (sinfo), capsdesc);
420 if (GST_IS_DISCOVERER_CONTAINER_INFO (sinfo)) {
421 GList *tmp, *streams;
424 gst_discoverer_container_info_get_streams (GST_DISCOVERER_CONTAINER_INFO
426 for (tmp = streams; tmp; tmp = tmp->next)
427 describe_stream_info (tmp->data, desc);
428 gst_discoverer_stream_info_list_free (streams);
433 describe_discoverer (GstDiscovererInfo * info)
435 GString *desc = g_string_new (NULL);
436 GstDiscovererStreamInfo *sinfo = gst_discoverer_info_get_stream_info (info);
438 describe_stream_info (sinfo, desc);
439 gst_discoverer_stream_info_unref (sinfo);
441 return g_string_free (desc, FALSE);
445 print_timeline (GESTimeline * timeline)
448 GList *layer, *clip, *clips;
450 if (!timeline->layers)
453 uri = ges_command_line_formatter_get_timeline_uri (timeline);
454 gst_print ("\nTimeline description: `%s`\n", &uri[5]);
456 gst_print ("====================\n\n");
457 for (layer = timeline->layers; layer; layer = layer->next) {
458 clips = ges_layer_get_clips (layer->data);
463 gst_printerr (" layer %d: \n", ges_layer_get_priority (layer->data));
464 gst_printerr (" --------\n");
465 for (clip = clips; clip; clip = clip->next) {
468 if (GES_IS_URI_CLIP (clip->data)) {
469 GESUriClipAsset *asset =
470 GES_URI_CLIP_ASSET (ges_extractable_get_asset (clip->data));
472 describe_discoverer (ges_uri_clip_asset_get_info (asset));
474 name = g_strdup_printf ("Clip from: '%s' [%s]",
475 ges_asset_get_id (GES_ASSET (asset)), asset_desc);
478 name = g_strdup (GES_TIMELINE_ELEMENT_NAME (clip->data));
480 gst_print (" - %s\n start=%" GST_TIME_FORMAT,
481 name, GST_TIME_ARGS (GES_TIMELINE_ELEMENT_START (clip->data)));
483 if (GES_TIMELINE_ELEMENT_INPOINT (clip->data))
484 gst_print (" inpoint=%" GST_TIME_FORMAT,
485 GST_TIME_ARGS (GES_TIMELINE_ELEMENT_INPOINT (clip->data)));
486 gst_print (" duration=%" GST_TIME_FORMAT "\n",
487 GST_TIME_ARGS (GES_TIMELINE_ELEMENT_END (clip->data)));
492 g_list_free_full (clips, gst_object_unref);