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);
113 if (strstr (string, "+track")) {
114 gchar *res = g_strconcat ("ges:", string, NULL);
120 timeline_str = g_string_new (string);
123 if (opts->track_types & GES_TRACK_TYPE_VIDEO) {
124 track_def = g_string_new (" +track video ");
126 if (opts->video_track_caps)
127 g_string_append_printf (track_def, " restrictions=[%s] ",
128 opts->video_track_caps);
130 g_string_prepend (timeline_str, track_def->str);
131 g_string_free (track_def, TRUE);
134 if (opts->track_types & GES_TRACK_TYPE_AUDIO) {
135 track_def = g_string_new (" +track audio ");
137 if (opts->audio_track_caps)
138 g_string_append_printf (track_def, " restrictions=[%s] ",
139 opts->audio_track_caps);
141 g_string_prepend (timeline_str, track_def->str);
142 g_string_free (track_def, TRUE);
145 g_string_prepend (timeline_str, "ges:");
147 return g_string_free (timeline_str, FALSE);
151 get_flags_from_string (GType type, const gchar * str_flags, guint * flags)
153 GValue value = G_VALUE_INIT;
154 g_value_init (&value, type);
156 if (!gst_value_deserialize (&value, str_flags)) {
157 g_value_unset (&value);
162 *flags = g_value_get_flags (&value);
163 g_value_unset (&value);
169 ensure_uri (const gchar * location)
171 if (gst_uri_is_valid (location))
172 return g_strdup (location);
174 return gst_filename_to_uri (location, NULL);
178 parse_encoding_profile (const gchar * format)
180 GstEncodingProfile *profile;
181 GValue value = G_VALUE_INIT;
183 g_value_init (&value, GST_TYPE_ENCODING_PROFILE);
185 if (!gst_value_deserialize (&value, format)) {
186 g_value_reset (&value);
191 profile = g_value_dup_object (&value);
192 g_value_reset (&value);
198 print_enum (GType enum_type)
200 GEnumClass *enum_class = G_ENUM_CLASS (g_type_class_ref (enum_type));
203 for (i = 0; i < enum_class->n_values; i++) {
204 g_printf ("%s\n", enum_class->values[i].value_nick);
207 g_type_class_unref (enum_class);
211 ges_print (GstDebugColorFlags c, gboolean err, gboolean nline,
212 const gchar * format, va_list var_args)
214 GString *str = g_string_new (NULL);
215 GstDebugColorMode color_mode;
217 const gchar *clear = NULL;
219 color_mode = gst_debug_get_color_mode ();
221 if (color_mode == GST_DEBUG_COLOR_MODE_UNIX) {
223 if (color_mode != GST_DEBUG_COLOR_MODE_OFF) {
226 color = gst_debug_construct_term_color (c);
230 g_string_append (str, color);
234 g_string_append_vprintf (str, format, var_args);
237 g_string_append_c (str, '\n');
240 g_string_append (str, clear);
243 g_printerr ("%s", str->str);
245 g_print ("%s", str->str);
247 g_string_free (str, TRUE);
251 ges_ok (const gchar * format, ...)
255 va_start (var_args, format);
256 ges_print (GST_DEBUG_FG_GREEN, FALSE, TRUE, format, var_args);
261 ges_warn (const gchar * format, ...)
265 va_start (var_args, format);
266 ges_print (GST_DEBUG_FG_YELLOW, TRUE, TRUE, format, var_args);
271 ges_printerr (const gchar * format, ...)
275 va_start (var_args, format);
276 ges_print (GST_DEBUG_FG_RED, TRUE, TRUE, format, var_args);
281 get_file_extension (gchar * uri)
290 if (uri[find] == '.')
298 return g_strdup (&uri[find + 1]);
302 get_type_icon (gpointer obj)
304 if (GST_IS_ENCODING_AUDIO_PROFILE (obj) || GST_IS_DISCOVERER_AUDIO_INFO (obj))
306 else if (GST_IS_ENCODING_VIDEO_PROFILE (obj)
307 || GST_IS_DISCOVERER_VIDEO_INFO (obj))
309 else if (GST_IS_ENCODING_CONTAINER_PROFILE (obj)
310 || GST_IS_DISCOVERER_CONTAINER_INFO (obj))
317 print_profile (GstEncodingProfile * profile, const gchar * prefix)
319 const gchar *name = gst_encoding_profile_get_name (profile);
320 const gchar *desc = gst_encoding_profile_get_description (profile);
321 GstCaps *format = gst_encoding_profile_get_format (profile);
322 gchar *capsdesc = NULL;
324 if (gst_caps_is_fixed (format))
325 capsdesc = gst_pb_utils_get_codec_description (format);
327 capsdesc = gst_caps_to_string (format);
329 if (GST_IS_ENCODING_CONTAINER_PROFILE (profile)) {
330 g_print ("%s> %s %s: %s%s%s%s\n", prefix,
331 get_type_icon (profile),
332 capsdesc, name ? name : "",
333 desc ? " (" : "", desc ? desc : "", desc ? ")" : "");
336 g_print ("%s%s %s%s%s%s%s%s", prefix, get_type_icon (profile),
337 name ? name : capsdesc, desc ? ": " : "", desc ? desc : "",
338 name ? " (" : "", name ? capsdesc : "", name ? ")" : "");
340 if (GST_IS_ENCODING_VIDEO_PROFILE (profile)) {
341 GstCaps *caps = gst_encoding_profile_get_restriction (profile);
343 if (!caps && gst_caps_is_fixed (format))
344 caps = gst_caps_ref (format);
349 if (gst_video_info_from_caps (&info, caps)) {
350 g_print (" (%dx%d", info.width, info.height);
352 g_print ("@%d/%dfps", info.fps_n, info.fps_d);
355 gst_caps_unref (caps);
357 } else if (GST_IS_ENCODING_AUDIO_PROFILE (profile)) {
358 GstCaps *caps = gst_encoding_profile_get_restriction (profile);
360 if (!caps && gst_caps_is_fixed (format))
361 caps = gst_caps_ref (format);
366 if (gst_caps_is_fixed (caps) && gst_audio_info_from_caps (&info, caps))
367 g_print (" (%d channels @ %dhz)", info.channels, info.rate);
368 gst_caps_unref (caps);
376 gst_caps_unref (format);
382 describe_encoding_profile (GstEncodingProfile * profile)
384 g_return_if_fail (GST_IS_ENCODING_PROFILE (profile));
386 print_profile (profile, " ");
387 if (GST_IS_ENCODING_CONTAINER_PROFILE (profile)) {
391 gst_encoding_container_profile_get_profiles
392 (GST_ENCODING_CONTAINER_PROFILE (profile)); tmp; tmp = tmp->next)
393 print_profile (tmp->data, " - ");
398 describe_stream_info (GstDiscovererStreamInfo * sinfo, GString * desc)
403 caps = gst_discoverer_stream_info_get_caps (sinfo);
404 capsdesc = gst_pb_utils_get_codec_description (caps);
406 capsdesc = gst_caps_to_string (caps);
407 gst_caps_unref (caps);
409 g_string_append_printf (desc, "%s%s%s", desc->len ? ", " : "",
410 get_type_icon (sinfo), capsdesc);
412 if (GST_IS_DISCOVERER_CONTAINER_INFO (sinfo)) {
413 GList *tmp, *streams;
416 gst_discoverer_container_info_get_streams (GST_DISCOVERER_CONTAINER_INFO
418 for (tmp = streams; tmp; tmp = tmp->next)
419 describe_stream_info (tmp->data, desc);
420 gst_discoverer_stream_info_list_free (streams);
425 describe_discoverer (GstDiscovererInfo * info)
427 GString *desc = g_string_new (NULL);
428 GstDiscovererStreamInfo *sinfo = gst_discoverer_info_get_stream_info (info);
430 describe_stream_info (sinfo, desc);
431 gst_discoverer_stream_info_unref (sinfo);
433 return g_string_free (desc, FALSE);
437 print_timeline (GESTimeline * timeline)
439 GList *layer, *clip, *clips;
441 if (!timeline->layers)
444 g_print ("\nTimeline description:\n");
445 g_print ("====================\n\n");
446 for (layer = timeline->layers; layer; layer = layer->next) {
447 clips = ges_layer_get_clips (layer->data);
452 g_printerr (" layer %d: \n", ges_layer_get_priority (layer->data));
453 g_printerr (" --------\n");
454 for (clip = clips; clip; clip = clip->next) {
457 if (GES_IS_URI_CLIP (clip->data)) {
458 GESUriClipAsset *asset =
459 GES_URI_CLIP_ASSET (ges_extractable_get_asset (clip->data));
461 describe_discoverer (ges_uri_clip_asset_get_info (asset));
463 name = g_strdup_printf ("Clip from: '%s' [%s]",
464 ges_asset_get_id (GES_ASSET (asset)), asset_desc);
467 name = g_strdup (GES_TIMELINE_ELEMENT_NAME (clip->data));
469 g_print (" - %s\n start=%" GST_TIME_FORMAT,
470 name, GST_TIME_ARGS (GES_TIMELINE_ELEMENT_START (clip->data)));
472 if (GES_TIMELINE_ELEMENT_INPOINT (clip->data))
473 g_print (" inpoint=%" GST_TIME_FORMAT,
474 GST_TIME_ARGS (GES_TIMELINE_ELEMENT_INPOINT (clip->data)));
475 g_print (" duration=%" GST_TIME_FORMAT "\n",
476 GST_TIME_ARGS (GES_TIMELINE_ELEMENT_END (clip->data)));
481 g_list_free_full (clips, gst_object_unref);