1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
/* GStreamer Editing Services
* Copyright (C) 2015 Mathieu Duponchelle <mathieu.duponchelle@opencreed.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <stdlib.h>
#include <glib/gprintf.h>
#include <string.h>
#include <gst/gst.h>
#include "utils.h"
#define IS_ALPHANUM(c) (g_ascii_isalnum((c)) || ((c) == '-') || ((c) == '+'))
/* g_free after usage */
static gchar *
_sanitize_argument (gchar * arg)
{
gboolean has_non_alphanum = FALSE;
char *equal_index = strstr (arg, "=");
gchar *new_string, *tmp_string;
for (tmp_string = arg; *tmp_string != '\0'; tmp_string++) {
if (!IS_ALPHANUM (*tmp_string)) {
has_non_alphanum = TRUE;
break;
}
}
if (!has_non_alphanum)
return g_strdup (arg);
if (!equal_index)
return g_strdup_printf ("\"%s\"", arg);
tmp_string = new_string = g_malloc (sizeof (gchar) * (strlen (arg) + 3));
for (; *arg != '\0'; arg++) {
*tmp_string = *arg;
tmp_string += 1;
if (*arg == '=') {
*tmp_string = '"';
tmp_string += 1;
}
}
*tmp_string = '"';
tmp_string += 1;
*tmp_string = '\0';
return new_string;
}
gchar *
sanitize_timeline_description (int argc, char **argv)
{
gint i;
gchar *string = g_strdup (" ");
for (i = 1; i < argc; i++) {
gchar *new_string;
gchar *sanitized = _sanitize_argument (argv[i]);
new_string = g_strconcat (string, " ", sanitized, NULL);
g_free (sanitized);
g_free (string);
string = new_string;
}
return string;
}
guint
get_flags_from_string (GType type, const gchar * str_flags)
{
guint i;
gint flags = 0;
GFlagsClass *class = g_type_class_ref (type);
for (i = 0; i < class->n_values; i++) {
if (g_strrstr (str_flags, class->values[i].value_nick)) {
flags |= class->values[i].value;
}
}
g_type_class_unref (class);
return flags;
}
gchar *
ensure_uri (const gchar * location)
{
if (gst_uri_is_valid (location))
return g_strdup (location);
else
return gst_filename_to_uri (location, NULL);
}
GstEncodingProfile *
parse_encoding_profile (const gchar * format)
{
GstEncodingProfile *profile;
GValue value = G_VALUE_INIT;
g_value_init (&value, GST_TYPE_ENCODING_PROFILE);
if (!gst_value_deserialize (&value, format)) {
g_value_reset (&value);
return NULL;
}
profile = g_value_dup_object (&value);
g_value_reset (&value);
return profile;
}
void
print_enum (GType enum_type)
{
GEnumClass *enum_class = G_ENUM_CLASS (g_type_class_ref (enum_type));
guint i;
for (i = 0; i < enum_class->n_values; i++) {
g_printf ("%s\n", enum_class->values[i].value_nick);
}
g_type_class_unref (enum_class);
}
|