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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
#include <string.h>
#include "utils.h"
#include <gst/pbutils/descriptions.h>
void
print (GstDebugColorFlags c, gboolean err, gboolean nline, const gchar * format,
va_list var_args)
{
GString *str = g_string_new (NULL);
GstDebugColorMode color_mode;
gchar *color = NULL;
const gchar *clear = NULL;
color_mode = gst_debug_get_color_mode ();
#ifdef G_OS_WIN32
if (color_mode == GST_DEBUG_COLOR_MODE_UNIX) {
#else
if (color_mode != GST_DEBUG_COLOR_MODE_OFF) {
#endif
clear = "\033[00m";
color = gst_debug_construct_term_color (c);
}
if (color) {
g_string_append (str, color);
g_free (color);
}
g_string_append_vprintf (str, format, var_args);
if (nline)
g_string_append_c (str, '\n');
if (clear)
g_string_append (str, clear);
if (err)
g_printerr ("%s", str->str);
else
g_print ("%s", str->str);
g_string_free (str, TRUE);
}
void
ok (const gchar * format, ...)
{
va_list var_args;
va_start (var_args, format);
print (GST_DEBUG_FG_GREEN, FALSE, TRUE, format, var_args);
va_end (var_args);
}
void
warn (const gchar * format, ...)
{
va_list var_args;
va_start (var_args, format);
print (GST_DEBUG_FG_YELLOW, TRUE, TRUE, format, var_args);
va_end (var_args);
}
void
error (const gchar * format, ...)
{
va_list var_args;
va_start (var_args, format);
print (GST_DEBUG_FG_RED, TRUE, TRUE, format, var_args);
va_end (var_args);
}
gchar *
ensure_uri (const gchar * location)
{
if (gst_uri_is_valid (location))
return g_strdup (location);
else
return gst_filename_to_uri (location, NULL);
}
gchar *
get_file_extension (gchar * uri)
{
gchar *dot = g_strrstr (uri, ".");
if (!dot)
return NULL;
return dot + 1;
}
GList *
get_usable_profiles (GstEncodingTarget * target)
{
GList *tmpprof, *usable_profiles = NULL;
for (tmpprof = (GList *) gst_encoding_target_get_profiles (target);
tmpprof; tmpprof = tmpprof->next) {
GstEncodingProfile *profile = tmpprof->data;
GstElement *tmpencodebin = gst_element_factory_make ("encodebin", NULL);
gst_encoding_profile_set_presence (profile, 1);
if (GST_IS_ENCODING_CONTAINER_PROFILE (profile)) {
GList *tmpsubprof;
for (tmpsubprof = (GList *)
gst_encoding_container_profile_get_profiles
(GST_ENCODING_CONTAINER_PROFILE (profile)); tmpsubprof;
tmpsubprof = tmpsubprof->next)
gst_encoding_profile_set_presence (tmpsubprof->data, 1);
}
g_object_set (tmpencodebin, "profile", gst_object_ref (profile), NULL);
GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (tmpencodebin),
GST_DEBUG_GRAPH_SHOW_ALL, gst_encoding_profile_get_name (profile));
/* The profile could be expended */
if (GST_BIN (tmpencodebin)->children)
usable_profiles = g_list_prepend (usable_profiles, profile);
gst_object_unref (tmpencodebin);
}
return usable_profiles;
}
GstEncodingProfile *
create_encoding_profile (const gchar * pname)
{
GstEncodingProfile *profile;
GValue value = G_VALUE_INIT;
g_value_init (&value, GST_TYPE_ENCODING_PROFILE);
if (!gst_value_deserialize (&value, pname)) {
g_value_reset (&value);
return NULL;
}
profile = g_value_dup_object (&value);
g_value_reset (&value);
return profile;
}
static const gchar *
get_profile_type (GstEncodingProfile * profile)
{
if (GST_IS_ENCODING_CONTAINER_PROFILE (profile))
return "Container";
else if (GST_IS_ENCODING_AUDIO_PROFILE (profile))
return "Audio";
else if (GST_IS_ENCODING_VIDEO_PROFILE (profile))
return "Video";
else
return "Unknown";
}
static void
print_profile (GstEncodingProfile * profile, const gchar * prefix)
{
const gchar *name = gst_encoding_profile_get_name (profile);
const gchar *desc = gst_encoding_profile_get_description (profile);
GstCaps *format = gst_encoding_profile_get_format (profile);
gchar *capsdesc;
if (gst_caps_is_fixed (format))
capsdesc = gst_pb_utils_get_codec_description (format);
else
capsdesc = gst_caps_to_string (format);
g_print ("%s%s: %s%s%s%s%s%s\n", prefix, get_profile_type (profile),
name ? name : capsdesc, desc ? ": " : "", desc ? desc : "",
name ? " (" : "", name ? capsdesc : "", name ? ")" : "");
g_free (capsdesc);
}
void
describe_encoding_profile (GstEncodingProfile * profile)
{
g_return_if_fail (GST_IS_ENCODING_PROFILE (profile));
print_profile (profile, " ");
if (GST_IS_ENCODING_CONTAINER_PROFILE (profile)) {
const GList *tmp;
for (tmp =
gst_encoding_container_profile_get_profiles
(GST_ENCODING_CONTAINER_PROFILE (profile)); tmp; tmp = tmp->next)
print_profile (tmp->data, " - ");
}
}
|