| 1 |
%{ |
| 2 |
#include "../gst_private.h" |
| 3 |
|
| 4 |
#include <glib-object.h> |
| 5 |
#include <glib.h> |
| 6 |
#include <stdio.h> |
| 7 |
#include <string.h> |
| 8 |
#include <stdlib.h> |
| 9 |
|
| 10 |
#include <glib/gi18n-lib.h> |
| 11 |
|
| 12 |
#include "../gstconfig.h" |
| 13 |
#include "../gstparse.h" |
| 14 |
#include "../gstinfo.h" |
| 15 |
#include "../gsterror.h" |
| 16 |
#include "../gststructure.h" |
| 17 |
#include "../gsturi.h" |
| 18 |
#include "../gstutils.h" |
| 19 |
#include "../gstvalue.h" |
| 20 |
#include "../gstchildproxy.h" |
| 21 |
#include "types.h" |
| 22 |
|
| 23 |
/* All error messages in this file are user-visible and need to be translated. |
| 24 |
* Don't start the message with a capital, and don't end them with a period, |
| 25 |
* as they will be presented inside a sentence/error. |
| 26 |
*/ |
| 27 |
|
| 28 |
#define YYERROR_VERBOSE 1 |
| 29 |
|
| 30 |
#define YYENABLE_NLS 0 |
| 31 |
|
| 32 |
#ifndef YYLTYPE_IS_TRIVIAL |
| 33 |
#define YYLTYPE_IS_TRIVIAL 0 |
| 34 |
#endif |
| 35 |
|
| 36 |
/******************************************************************************************* |
| 37 |
*** Tracing memory leaks |
| 38 |
*******************************************************************************************/ |
| 39 |
|
| 40 |
#ifdef __GST_PARSE_TRACE |
| 41 |
static guint __strings; |
| 42 |
static guint __links; |
| 43 |
static guint __chains; |
| 44 |
static guint __elements; |
| 45 |
gchar * |
| 46 |
__gst_parse_strdup (gchar *org) |
| 47 |
{ |
| 48 |
gchar *ret; |
| 49 |
__strings++; |
| 50 |
ret = g_strdup (org); |
| 51 |
/* g_print ("ALLOCATED STR (%3u): %p %s\n", __strings, ret, ret); */ |
| 52 |
return ret; |
| 53 |
} |
| 54 |
void |
| 55 |
__gst_parse_strfree (gchar *str) |
| 56 |
{ |
| 57 |
if (str) { |
| 58 |
/* g_print ("FREEING STR (%3u): %p %s\n", __strings - 1, str, str); */ |
| 59 |
g_free (str); |
| 60 |
g_return_if_fail (__strings > 0); |
| 61 |
__strings--; |
| 62 |
} |
| 63 |
} |
| 64 |
link_t *__gst_parse_link_new (void) |
| 65 |
{ |
| 66 |
link_t *ret; |
| 67 |
__links++; |
| 68 |
ret = g_new0 (link_t, 1); |
| 69 |
/* g_print ("ALLOCATED LINK (%3u): %p\n", __links, ret); */ |
| 70 |
return ret; |
| 71 |
} |
| 72 |
void |
| 73 |
__gst_parse_link_free (link_t *data) |
| 74 |
{ |
| 75 |
if (data) { |
| 76 |
/* g_print ("FREEING LINK (%3u): %p\n", __links - 1, data); */ |
| 77 |
g_free (data); |
| 78 |
g_return_if_fail (__links > 0); |
| 79 |
__links--; |
| 80 |
} |
| 81 |
} |
| 82 |
chain_t * |
| 83 |
__gst_parse_chain_new (void) |
| 84 |
{ |
| 85 |
chain_t *ret; |
| 86 |
__chains++; |
| 87 |
ret = g_new0 (chain_t, 1); |
| 88 |
/* g_print ("@%p: ALLOCATED CHAIN (%3u):\n", ret, __chains); */ |
| 89 |
return ret; |
| 90 |
} |
| 91 |
void |
| 92 |
__gst_parse_chain_free (chain_t *data) |
| 93 |
{ |
| 94 |
/* g_print ("@%p: FREEING CHAIN (%3u):\n", data, __chains - 1); */ |
| 95 |
g_free (data); |
| 96 |
g_return_if_fail (__chains > 0); |
| 97 |
__chains--; |
| 98 |
} |
| 99 |
|
| 100 |
element_t * |
| 101 |
__gst_parse_element_new (void) |
| 102 |
{ |
| 103 |
element_t *ret; |
| 104 |
__elements++; |
| 105 |
ret = g_new0 (element_t, 1); |
| 106 |
/* g_print ("@%p: ALLOCATED ELEMENT (%3u):\n", ret, __elements); */ |
| 107 |
return ret; |
| 108 |
} |
| 109 |
void |
| 110 |
__gst_parse_element_free (element_t *data) |
| 111 |
{ |
| 112 |
/* g_print ("@%p: FREEING ELEMENT (%3u):\n", data, __elements - 1); */ |
| 113 |
g_free (data); |
| 114 |
g_return_if_fail (__elements > 0); |
| 115 |
__elements--; |
| 116 |
} |
| 117 |
|
| 118 |
#endif /* __GST_PARSE_TRACE */ |
| 119 |
|
| 120 |
/******************************************************************************************* |
| 121 |
*** define SET_ERROR macro/function |
| 122 |
* |
| 123 |
* SET_ERROR() must only be called from the thread running priv_gst_parse_launch() and must |
| 124 |
* only be used for errors that occur during the initial construction of the chain, i.e. |
| 125 |
* before priv_gst_parse_launch() returns. |
| 126 |
*******************************************************************************************/ |
| 127 |
static void error_append_probable_reason (graph_t *graph); |
| 128 |
|
| 129 |
#ifdef G_HAVE_ISO_VARARGS |
| 130 |
|
| 131 |
# define SET_ERROR(graph, type, ...) \ |
| 132 |
G_STMT_START { \ |
| 133 |
GError** error = (graph)->error; \ |
| 134 |
GST_CAT_ERROR (GST_CAT_PIPELINE, __VA_ARGS__); \ |
| 135 |
if ((error) && !*(error)) { \ |
| 136 |
g_set_error ((error), GST_PARSE_ERROR, (type), __VA_ARGS__); \ |
| 137 |
error_append_probable_reason ((graph)); \ |
| 138 |
} \ |
| 139 |
} G_STMT_END |
| 140 |
|
| 141 |
#elif defined(G_HAVE_GNUC_VARARGS) |
| 142 |
|
| 143 |
# define SET_ERROR(graph, type, args...) \ |
| 144 |
G_STMT_START { \ |
| 145 |
GError** error = (graph)->error; \ |
| 146 |
GST_CAT_ERROR (GST_CAT_PIPELINE, args ); \ |
| 147 |
if (error && !*error) { \ |
| 148 |
g_set_error (error, GST_PARSE_ERROR, (type), args ); \ |
| 149 |
error_append_probable_reason ((graph)); \ |
| 150 |
} \ |
| 151 |
} G_STMT_END |
| 152 |
|
| 153 |
#else |
| 154 |
|
| 155 |
static inline void |
| 156 |
SET_ERROR (graph_t *graph, gint type, const char *format, ...) |
| 157 |
{ |
| 158 |
GError** error = graph->error; |
| 159 |
if (error) { |
| 160 |
if (*error) { |
| 161 |
g_warning ("error while parsing"); |
| 162 |
} else { |
| 163 |
va_list varargs; |
| 164 |
char *string; |
| 165 |
|
| 166 |
va_start (varargs, format); |
| 167 |
string = g_strdup_vprintf (format, varargs); |
| 168 |
va_end (varargs); |
| 169 |
|
| 170 |
g_set_error (error, GST_PARSE_ERROR, type, string); |
| 171 |
|
| 172 |
g_free (string); |
| 173 |
error_append_probable_reason ((graph)); |
| 174 |
} |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
#endif /* G_HAVE_ISO_VARARGS */ |
| 179 |
|
| 180 |
static void error_append_probable_reason (graph_t *graph) { |
| 181 |
g_return_if_fail (*graph->error); |
| 182 |
GError* error = *graph->error; |
| 183 |
|
| 184 |
reason_receiver_t* receiver = graph->error_probable_reason_receiver; |
| 185 |
/* If by the time SET_ERROR() was called no bus was set, there is no receiver |
| 186 |
* and no error from the bus to append. */ |
| 187 |
if (!receiver) |
| 188 |
return; |
| 189 |
|
| 190 |
g_mutex_lock (&receiver->mutex); |
| 191 |
if (receiver->reason) { |
| 192 |
gchar *new_message = g_strdup_printf ("%s -- %s", error->message, |
| 193 |
receiver->reason); |
| 194 |
g_free (error->message); |
| 195 |
error->message = new_message; |
| 196 |
} |
| 197 |
g_mutex_unlock (&receiver->mutex); |
| 198 |
} |
| 199 |
|
| 200 |
/*** define YYPRINTF macro/function if we're debugging */ |
| 201 |
|
| 202 |
/* bison 1.35 calls this macro with side effects, we need to make sure the |
| 203 |
side effects work - crappy bison */ |
| 204 |
|
| 205 |
#ifndef GST_DISABLE_GST_DEBUG |
| 206 |
# define YYDEBUG 1 |
| 207 |
|
| 208 |
# ifdef G_HAVE_ISO_VARARGS |
| 209 |
|
| 210 |
/* # define YYFPRINTF(a, ...) GST_CAT_DEBUG (GST_CAT_PIPELINE, __VA_ARGS__) */ |
| 211 |
# define YYFPRINTF(a, ...) \ |
| 212 |
G_STMT_START { \ |
| 213 |
GST_CAT_LOG (GST_CAT_PIPELINE, __VA_ARGS__); \ |
| 214 |
} G_STMT_END |
| 215 |
|
| 216 |
# elif defined(G_HAVE_GNUC_VARARGS) |
| 217 |
|
| 218 |
# define YYFPRINTF(a, args...) \ |
| 219 |
G_STMT_START { \ |
| 220 |
GST_CAT_LOG (GST_CAT_PIPELINE, args); \ |
| 221 |
} G_STMT_END |
| 222 |
|
| 223 |
# else |
| 224 |
|
| 225 |
static inline void |
| 226 |
YYPRINTF(const char *format, ...) |
| 227 |
{ |
| 228 |
va_list varargs; |
| 229 |
gchar *temp; |
| 230 |
|
| 231 |
va_start (varargs, format); |
| 232 |
temp = g_strdup_vprintf (format, varargs); |
| 233 |
GST_CAT_LOG (GST_CAT_PIPELINE, "%s", temp); |
| 234 |
g_free (temp); |
| 235 |
va_end (varargs); |
| 236 |
} |
| 237 |
|
| 238 |
# endif /* G_HAVE_ISO_VARARGS */ |
| 239 |
|
| 240 |
#endif /* GST_DISABLE_GST_DEBUG */ |
| 241 |
|
| 242 |
|
| 243 |
/* |
| 244 |
* include headers generated by bison & flex, after defining (or not defining) YYDEBUG |
| 245 |
*/ |
| 246 |
#include "grammar.tab.h" |
| 247 |
#include "parse_lex.h" |
| 248 |
|
| 249 |
/******************************************************************************************* |
| 250 |
*** report missing elements/bins/.. |
| 251 |
*******************************************************************************************/ |
| 252 |
|
| 253 |
|
| 254 |
static void add_missing_element(graph_t *graph,gchar *name){ |
| 255 |
if ((graph)->ctx){ |
| 256 |
(graph)->ctx->missing_elements = g_list_append ((graph)->ctx->missing_elements, g_strdup (name)); |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
static gchar * |
| 261 |
str_unwrap (const gchar * s) |
| 262 |
{ |
| 263 |
gchar *ret; |
| 264 |
gchar *read, *write; |
| 265 |
|
| 266 |
/* NULL string returns NULL */ |
| 267 |
if (s == NULL) |
| 268 |
return NULL; |
| 269 |
|
| 270 |
/* make copy of original string to hold the result. This |
| 271 |
* string will always be smaller than the original */ |
| 272 |
ret = g_strdup (s); |
| 273 |
read = ret; |
| 274 |
write = ret; |
| 275 |
|
| 276 |
while (*read) { |
| 277 |
if (GST_ASCII_IS_STRING (*read)) { |
| 278 |
/* normal chars are just copied */ |
| 279 |
*write++ = *read++; |
| 280 |
} else if (*read == '\\') { |
| 281 |
/* got an escape char, move to next position to read a tripplet |
| 282 |
* of octal numbers */ |
| 283 |
read++; |
| 284 |
/* is the next char a possible first octal number? */ |
| 285 |
if (*read >= '0' && *read <= '3') { |
| 286 |
/* parse other 2 numbers, if one of them is not in the range of |
| 287 |
* an octal number, we error. We also catch the case where a zero |
| 288 |
* byte is found here. */ |
| 289 |
if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7') |
| 290 |
goto beach; |
| 291 |
|
| 292 |
/* now convert the octal number to a byte again. */ |
| 293 |
*write++ = ((read[0] - '0') << 6) + |
| 294 |
((read[1] - '0') << 3) + (read[2] - '0'); |
| 295 |
|
| 296 |
read += 3; |
| 297 |
} else { |
| 298 |
/* if we run into a \0 here, we definitely won't get a quote later */ |
| 299 |
if (*read == 0) |
| 300 |
goto beach; |
| 301 |
/* else copy \X sequence */ |
| 302 |
*write++ = *read++; |
| 303 |
} |
| 304 |
} else if (*read == '\0') { |
| 305 |
goto beach; |
| 306 |
} else { |
| 307 |
*write++ = *read++; |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
/* null terminate result string and return */ |
| 312 |
*write = '\0'; |
| 313 |
return ret; |
| 314 |
|
| 315 |
beach: |
| 316 |
g_free (ret); |
| 317 |
return NULL; |
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
/******************************************************************************************* |
| 322 |
*** helpers for pipeline-setup |
| 323 |
*******************************************************************************************/ |
| 324 |
|
| 325 |
#define TRY_SETUP_LINK(l) G_STMT_START { \ |
| 326 |
if( (!(l)->src.element) && (!(l)->src.name) ){ \ |
| 327 |
SET_ERROR (graph, GST_PARSE_ERROR_LINK, _("link has no source [sink=%s@%p]"), \ |
| 328 |
(l)->sink.name ? (l)->sink.name : "", \ |
| 329 |
(l)->sink.element); \ |
| 330 |
gst_parse_free_link (l); \ |
| 331 |
}else if( (!(l)->sink.element) && (!(l)->sink.name) ){ \ |
| 332 |
SET_ERROR (graph, GST_PARSE_ERROR_LINK, _("link has no sink [source=%s@%p]"), \ |
| 333 |
(l)->src.name ? (l)->src.name : "", \ |
| 334 |
(l)->src.element); \ |
| 335 |
gst_parse_free_link (l); \ |
| 336 |
}else{ \ |
| 337 |
graph->links = g_slist_append (graph->links, l ); \ |
| 338 |
} \ |
| 339 |
} G_STMT_END |
| 340 |
|
| 341 |
typedef struct { |
| 342 |
gchar *src_pad; |
| 343 |
gchar *sink_pad; |
| 344 |
GstElement *sink; |
| 345 |
GstCaps *caps; |
| 346 |
gulong pad_added_signal_id, no_more_pads_signal_id; |
| 347 |
gboolean all_pads; |
| 348 |
} DelayedLink; |
| 349 |
|
| 350 |
typedef struct { |
| 351 |
gchar *name; |
| 352 |
gchar *value_str; |
| 353 |
gulong signal_id; |
| 354 |
} DelayedSet; |
| 355 |
|
| 356 |
static int gst_resolve_reference(reference_t *rr, GstElement *pipeline){ |
| 357 |
GstBin *bin; |
| 358 |
|
| 359 |
if(rr->element) return 0; /* already resolved! */ |
| 360 |
if(!rr->name) return -2; /* no chance! */ |
| 361 |
|
| 362 |
if (GST_IS_BIN (pipeline)){ |
| 363 |
bin = GST_BIN (pipeline); |
| 364 |
rr->element = gst_bin_get_by_name_recurse_up (bin, rr->name); |
| 365 |
} else { |
| 366 |
rr->element = strcmp (GST_ELEMENT_NAME (pipeline), rr->name) == 0 ? |
| 367 |
gst_object_ref(pipeline) : NULL; |
| 368 |
} |
| 369 |
if(rr->element) return 0; /* resolved */ |
| 370 |
else return -1; /* not found */ |
| 371 |
} |
| 372 |
|
| 373 |
static void gst_parse_free_delayed_set (DelayedSet *set) |
| 374 |
{ |
| 375 |
g_free(set->name); |
| 376 |
g_free(set->value_str); |
| 377 |
g_free(set); |
| 378 |
} |
| 379 |
|
| 380 |
static void gst_parse_new_child (GstChildProxy *child_proxy, GObject *object, |
| 381 |
const gchar * name, gpointer data); |
| 382 |
|
| 383 |
static void gst_parse_add_delayed_set (GstChildProxy *proxy, gchar *name, gchar *value_str) |
| 384 |
{ |
| 385 |
DelayedSet *data = g_new0 (DelayedSet, 1); |
| 386 |
gchar **names, **current; |
| 387 |
GObject *parent, *child; |
| 388 |
|
| 389 |
GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, proxy, "delaying property set %s to %s", |
| 390 |
name, value_str); |
| 391 |
|
| 392 |
data->name = g_strdup (name); |
| 393 |
data->value_str = g_strdup (value_str); |
| 394 |
data->signal_id = g_signal_connect_data (proxy, "child-added", |
| 395 |
G_CALLBACK (gst_parse_new_child), data, (GClosureNotify) |
| 396 |
gst_parse_free_delayed_set, (GConnectFlags) 0); |
| 397 |
|
| 398 |
current = names = g_strsplit (name, "::", -1); |
| 399 |
parent = gst_child_proxy_get_child_by_name (GST_CHILD_PROXY (proxy), current[0]); |
| 400 |
current++; |
| 401 |
|
| 402 |
while (parent && current[0]) { |
| 403 |
if (!GST_IS_CHILD_PROXY (parent)) { |
| 404 |
GST_INFO ("Not recursing into non-proxy child %p", parent); |
| 405 |
break; |
| 406 |
} |
| 407 |
|
| 408 |
child = gst_child_proxy_get_child_by_name (GST_CHILD_PROXY (parent), current[0]); |
| 409 |
if (!child && current[1]) { |
| 410 |
char *sub_name = g_strjoinv ("::", ¤t[0]); |
| 411 |
|
| 412 |
gst_parse_add_delayed_set (GST_CHILD_PROXY (parent), sub_name, value_str); |
| 413 |
g_free (sub_name); |
| 414 |
} |
| 415 |
|
| 416 |
gst_object_unref (parent); |
| 417 |
parent = child; |
| 418 |
current++; |
| 419 |
} |
| 420 |
|
| 421 |
if (parent) |
| 422 |
gst_object_unref (parent); |
| 423 |
g_strfreev (names); |
| 424 |
} |
| 425 |
|
| 426 |
static gboolean |
| 427 |
gst_parse_separate_prop_from_children (const gchar *name, gchar **children, gchar **property) |
| 428 |
{ |
| 429 |
static const gchar *separator = "::"; |
| 430 |
const gchar *prop = NULL; |
| 431 |
|
| 432 |
g_return_val_if_fail (name, FALSE); |
| 433 |
g_return_val_if_fail (children, FALSE); |
| 434 |
g_return_val_if_fail (property, FALSE); |
| 435 |
|
| 436 |
/* Given "child1::child2::prop" isolate "prop" */ |
| 437 |
prop = g_strrstr (name, separator); |
| 438 |
if (!prop) { |
| 439 |
GST_WARNING ("%s is not a valid childproxy path", name); |
| 440 |
return FALSE; |
| 441 |
} |
| 442 |
|
| 443 |
/* Make a copy of prop skipping "::" */ |
| 444 |
*property = g_strdup (prop + 2); |
| 445 |
|
| 446 |
/* Extract "child1::child2" from "child1::child2::prop" */ |
| 447 |
*children = |
| 448 |
g_strndup (name, strlen (name) - strlen (prop)); |
| 449 |
|
| 450 |
return TRUE; |
| 451 |
} |
| 452 |
|
| 453 |
static void gst_parse_new_child(GstChildProxy *child_proxy, GObject *object, |
| 454 |
const gchar * name, gpointer data) |
| 455 |
{ |
| 456 |
DelayedSet *set = (DelayedSet *) data; |
| 457 |
GParamSpec *pspec; |
| 458 |
GValue v = { 0, }; |
| 459 |
GObject *target = NULL; |
| 460 |
GType value_type; |
| 461 |
|
| 462 |
GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, child_proxy, "new child %s, checking property %s", |
| 463 |
name, set->name); |
| 464 |
|
| 465 |
if (gst_child_proxy_lookup (child_proxy, set->name, &target, &pspec)) { |
| 466 |
gboolean got_value = FALSE; |
| 467 |
|
| 468 |
value_type = pspec->value_type; |
| 469 |
|
| 470 |
GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, child_proxy, "parsing delayed property %s as a %s from %s", |
| 471 |
pspec->name, g_type_name (value_type), set->value_str); |
| 472 |
g_value_init (&v, value_type); |
| 473 |
if (gst_value_deserialize_with_pspec (&v, set->value_str, pspec)) |
| 474 |
got_value = TRUE; |
| 475 |
else if (g_type_is_a (value_type, GST_TYPE_ELEMENT)) { |
| 476 |
GstElement *bin; |
| 477 |
|
| 478 |
bin = gst_parse_bin_from_description_full (set->value_str, TRUE, NULL, |
| 479 |
GST_PARSE_FLAG_NO_SINGLE_ELEMENT_BINS | GST_PARSE_FLAG_PLACE_IN_BIN, NULL); |
| 480 |
if (bin) { |
| 481 |
g_value_set_object (&v, bin); |
| 482 |
got_value = TRUE; |
| 483 |
} |
| 484 |
} |
| 485 |
g_signal_handler_disconnect (child_proxy, set->signal_id); |
| 486 |
if (!got_value) |
| 487 |
goto error; |
| 488 |
g_object_set_property (target, pspec->name, &v); |
| 489 |
} else { |
| 490 |
gint len = strlen (name); |
| 491 |
|
| 492 |
/* |
| 493 |
* We've been notified that a new child has beed added, but the |
| 494 |
* property was still not found. Three things could be happening: |
| 495 |
* |
| 496 |
* 1. The target property is of the form obj_name::child_name::property |
| 497 |
* and is for a child that does not (yet) exist: |
| 498 |
* We need to add the delayed property setting handler on that new child. |
| 499 |
* |
| 500 |
* 2. The target property is of the form obj_name::property or |
| 501 |
* obj_name::child_name::property and the child already exists: |
| 502 |
* We warn about a nonexistent property |
| 503 |
* |
| 504 |
* 3. The target property is of the form other_obj_name::child_name::property |
| 505 |
* or other_obj_name::property: |
| 506 |
* We ignore this case as another delayed set will catch it. |
| 507 |
*/ |
| 508 |
|
| 509 |
/* Cases 1,2: The child just added corresponds to this delayed set */ |
| 510 |
if ((strlen (set->name) > (len+2)) && !strncmp (set->name, name, len) |
| 511 |
&& !strncmp (&set->name[len], "::", 2)) { |
| 512 |
gchar *children = NULL; |
| 513 |
gchar *prop = NULL; |
| 514 |
GObject *child = NULL; |
| 515 |
|
| 516 |
if (!gst_parse_separate_prop_from_children (set->name, &children, &prop)) { |
| 517 |
/* Malformed property name, ignore */ |
| 518 |
return; |
| 519 |
} |
| 520 |
|
| 521 |
child = gst_child_proxy_get_child_by_name_recurse (child_proxy, children); |
| 522 |
g_free (children); |
| 523 |
g_free (prop); |
| 524 |
|
| 525 |
/* Case 1: A child in the hierarchy does not exist yet, add a new delayed set */ |
| 526 |
if (NULL == child) { |
| 527 |
gst_parse_add_delayed_set (child_proxy, set->name, set->value_str); |
| 528 |
} |
| 529 |
/* Case 2: The target child exists already but there's no such property */ |
| 530 |
else { |
| 531 |
gst_object_unref (child); |
| 532 |
GST_ELEMENT_WARNING(GST_ELEMENT (child_proxy), PARSE, NO_SUCH_PROPERTY, |
| 533 |
(_("No such property.")), (_("no property \"%s\" in element \"%s\""), |
| 534 |
set->name, GST_ELEMENT_NAME(child_proxy))); |
| 535 |
} |
| 536 |
} |
| 537 |
/* Case 3: The child just added does not correspond to this delayed set, just ignore |
| 538 |
* else { } |
| 539 |
*/ |
| 540 |
} |
| 541 |
|
| 542 |
out: |
| 543 |
if (G_IS_VALUE (&v)) |
| 544 |
g_value_unset (&v); |
| 545 |
if (target) |
| 546 |
gst_object_unref (target); |
| 547 |
return; |
| 548 |
|
| 549 |
error: |
| 550 |
GST_CAT_ERROR (GST_CAT_PIPELINE, "could not set property \"%s\" in %" |
| 551 |
GST_PTR_FORMAT, pspec->name, target); |
| 552 |
goto out; |
| 553 |
} |
| 554 |
|
| 555 |
static gchar * |
| 556 |
gst_parse_split_assignment (gchar *value) { |
| 557 |
gchar *pos = value; |
| 558 |
|
| 559 |
/* parse the string, so the property name is null-terminated and pos points |
| 560 |
to the beginning of the value */ |
| 561 |
while (!g_ascii_isspace (*pos) && (*pos != '=')) pos++; |
| 562 |
if (*pos == '=') { |
| 563 |
*pos = '\0'; |
| 564 |
} else { |
| 565 |
*pos = '\0'; |
| 566 |
pos++; |
| 567 |
while (g_ascii_isspace (*pos)) pos++; |
| 568 |
} |
| 569 |
pos++; |
| 570 |
while (g_ascii_isspace (*pos)) pos++; |
| 571 |
/* truncate a string if it is delimited with double quotes */ |
| 572 |
if (*pos == '"' && pos[strlen (pos) - 1] == '"') { |
| 573 |
pos++; |
| 574 |
pos[strlen (pos) - 1] = '\0'; |
| 575 |
} |
| 576 |
gst_parse_unescape (pos); |
| 577 |
|
| 578 |
return pos; |
| 579 |
} |
| 580 |
|
| 581 |
static gboolean |
| 582 |
collect_value (GParamSpec *pspec, gchar *value_str, GValue *v) |
| 583 |
{ |
| 584 |
gboolean got_value = FALSE; |
| 585 |
|
| 586 |
GST_CAT_LOG (GST_CAT_PIPELINE, "parsing property %s as a %s", |
| 587 |
pspec->name, g_type_name (pspec->value_type)); |
| 588 |
|
| 589 |
g_value_init (v, pspec->value_type); |
| 590 |
if (gst_value_deserialize_with_pspec (v, value_str, pspec)) |
| 591 |
got_value = TRUE; |
| 592 |
else if (g_type_is_a (pspec->value_type, GST_TYPE_ELEMENT)) { |
| 593 |
GstElement *bin; |
| 594 |
|
| 595 |
bin = gst_parse_bin_from_description_full (value_str, TRUE, NULL, |
| 596 |
GST_PARSE_FLAG_NO_SINGLE_ELEMENT_BINS | GST_PARSE_FLAG_PLACE_IN_BIN, NULL); |
| 597 |
if (bin) { |
| 598 |
g_value_set_object (v, bin); |
| 599 |
got_value = TRUE; |
| 600 |
} |
| 601 |
} |
| 602 |
|
| 603 |
return got_value; |
| 604 |
} |
| 605 |
|
| 606 |
static void gst_parse_element_preset (gchar *value, GstElement *element, graph_t *graph) |
| 607 |
{ |
| 608 |
/* do nothing if preset is for missing element or its not a preset element */ |
| 609 |
if (element == NULL) |
| 610 |
goto out; |
| 611 |
|
| 612 |
if (!GST_IS_PRESET(element)) |
| 613 |
goto not_a_preset; |
| 614 |
|
| 615 |
/* do nothing if no preset is given */ |
| 616 |
if (value == NULL || *value == '\0') |
| 617 |
goto out; |
| 618 |
|
| 619 |
gst_parse_unescape (value); |
| 620 |
if (!gst_preset_load_preset (GST_PRESET (element), value)) |
| 621 |
goto error; |
| 622 |
|
| 623 |
out: |
| 624 |
return; |
| 625 |
|
| 626 |
not_a_preset: |
| 627 |
SET_ERROR (graph, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY, |
| 628 |
_("Element \"%s\" is not a GstPreset"), |
| 629 |
GST_ELEMENT_NAME (element)); |
| 630 |
goto out; |
| 631 |
|
| 632 |
error: |
| 633 |
SET_ERROR (graph, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY, |
| 634 |
_("could not set preset \"%s\" in element \"%s\""), |
| 635 |
value, GST_ELEMENT_NAME (element)); |
| 636 |
goto out; |
| 637 |
} |
| 638 |
|
| 639 |
typedef struct |
| 640 |
{ |
| 641 |
gchar *name; |
| 642 |
gchar *value; |
| 643 |
} proxied_property_t; |
| 644 |
|
| 645 |
static void |
| 646 |
proxied_property_free (proxied_property_t *pp) { |
| 647 |
g_free (pp); |
| 648 |
} |
| 649 |
|
| 650 |
static GstElement * gst_parse_element_make (graph_t *graph, element_t *data) { |
| 651 |
GstElementFactory *loaded_factory; |
| 652 |
GstElementFactory *factory = gst_element_factory_find (data->factory_name); |
| 653 |
GObjectClass *klass; |
| 654 |
GParamSpec *pspec = NULL; |
| 655 |
GSList *tmp; |
| 656 |
gboolean is_proxy; |
| 657 |
GSList *proxied = NULL; |
| 658 |
guint n_params = 0; |
| 659 |
guint n_params_alloc = 16; |
| 660 |
const gchar **names_array; |
| 661 |
GValue *values_array; |
| 662 |
GstElement *ret = NULL; |
| 663 |
|
| 664 |
if (!factory) { |
| 665 |
SET_ERROR (graph, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), data->factory_name); |
| 666 |
return NULL; |
| 667 |
} |
| 668 |
|
| 669 |
loaded_factory = |
| 670 |
GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE |
| 671 |
(factory))); |
| 672 |
|
| 673 |
gst_object_unref (factory); |
| 674 |
|
| 675 |
klass = g_type_class_ref (gst_element_factory_get_element_type (loaded_factory)); |
| 676 |
|
| 677 |
is_proxy = g_type_is_a (gst_element_factory_get_element_type (loaded_factory), GST_TYPE_CHILD_PROXY); |
| 678 |
|
| 679 |
names_array = g_new0 (const gchar *, n_params_alloc); |
| 680 |
values_array = g_new0 (GValue, n_params_alloc); |
| 681 |
|
| 682 |
for (tmp = data->values; tmp; tmp = tmp->next) { |
| 683 |
gchar *name = tmp->data; |
| 684 |
gchar *value = gst_parse_split_assignment (tmp->data); |
| 685 |
|
| 686 |
if (is_proxy && strstr (name, "::") != NULL) { |
| 687 |
proxied_property_t *pp = g_new (proxied_property_t, 1); |
| 688 |
pp->name = name; |
| 689 |
pp->value = value; |
| 690 |
proxied = g_slist_prepend (proxied, pp); |
| 691 |
continue; |
| 692 |
} |
| 693 |
|
| 694 |
pspec = g_object_class_find_property (klass, name); |
| 695 |
|
| 696 |
if (pspec != NULL) { |
| 697 |
if (G_UNLIKELY (n_params == n_params_alloc)) { |
| 698 |
n_params_alloc *= 2u; |
| 699 |
names_array = |
| 700 |
g_realloc (names_array, sizeof (const gchar *) * n_params_alloc); |
| 701 |
values_array = g_realloc (values_array, sizeof (GValue) * n_params_alloc); |
| 702 |
memset (&values_array[n_params], 0, |
| 703 |
sizeof (GValue) * (n_params_alloc - n_params)); |
| 704 |
} |
| 705 |
|
| 706 |
if (!collect_value (pspec, value, &values_array[n_params])) { |
| 707 |
SET_ERROR (graph, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY, |
| 708 |
_("could not set property \"%s\" in element \"%s\" to \"%s\""), |
| 709 |
name, data->factory_name, value); |
| 710 |
g_value_unset (&values_array[n_params]); |
| 711 |
goto done; |
| 712 |
} else { |
| 713 |
names_array[n_params] = name; |
| 714 |
} |
| 715 |
|
| 716 |
++n_params; |
| 717 |
} else { |
| 718 |
SET_ERROR (graph, GST_PARSE_ERROR_NO_SUCH_PROPERTY, \ |
| 719 |
_("no property \"%s\" in element \"%s\""), name, \ |
| 720 |
data->factory_name); |
| 721 |
goto done; |
| 722 |
} |
| 723 |
} |
| 724 |
|
| 725 |
ret = gst_element_factory_create_with_properties (factory, n_params, names_array, |
| 726 |
values_array); |
| 727 |
|
| 728 |
for (tmp = proxied; tmp; tmp = tmp->next) { |
| 729 |
GObject *target = NULL; |
| 730 |
proxied_property_t *pp = tmp->data; |
| 731 |
|
| 732 |
if (!gst_child_proxy_lookup (GST_CHILD_PROXY (ret), pp->name, &target, &pspec)) { |
| 733 |
/* the property was not found. if the target child doesn't exist |
| 734 |
then we do a delayed set waiting for new elements to be added. If |
| 735 |
the child was found, we fail since the property doesn't exist. |
| 736 |
*/ |
| 737 |
gchar *children = NULL; |
| 738 |
gchar *property = NULL; |
| 739 |
if (!gst_parse_separate_prop_from_children (pp->name, &children, &property)) { |
| 740 |
/* malformed childproxy path, skip */ |
| 741 |
continue; |
| 742 |
} |
| 743 |
|
| 744 |
target = gst_child_proxy_get_child_by_name_recurse (GST_CHILD_PROXY (ret), children); |
| 745 |
g_free (children); |
| 746 |
g_free (property); |
| 747 |
|
| 748 |
if (target == NULL) { |
| 749 |
gst_parse_add_delayed_set (GST_CHILD_PROXY (ret), pp->name, pp->value); |
| 750 |
} else { |
| 751 |
gst_object_unref (target); |
| 752 |
SET_ERROR (graph, GST_PARSE_ERROR_NO_SUCH_PROPERTY, \ |
| 753 |
_("no property \"%s\" in element \"%s\""), pp->name, \ |
| 754 |
GST_ELEMENT_NAME (ret)); |
| 755 |
goto done; |
| 756 |
} |
| 757 |
} else { |
| 758 |
GValue v = { 0, }; |
| 759 |
|
| 760 |
if (!collect_value (pspec, pp->value, &v)) { |
| 761 |
SET_ERROR (graph, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY, |
| 762 |
_("could not set property \"%s\" in child of element \"%s\" to \"%s\""), |
| 763 |
pp->name, data->factory_name, pp->value); |
| 764 |
g_value_unset (&v); |
| 765 |
goto done; |
| 766 |
} else { |
| 767 |
g_object_set_property (target, pspec->name, &v); |
| 768 |
g_value_unset (&v); |
| 769 |
} |
| 770 |
|
| 771 |
gst_object_unref (target); |
| 772 |
} |
| 773 |
} |
| 774 |
|
| 775 |
for (tmp = data->presets; tmp; tmp = tmp->next) { |
| 776 |
gst_parse_element_preset (tmp->data, ret, graph); |
| 777 |
} |
| 778 |
|
| 779 |
done: |
| 780 |
g_slist_free_full (proxied, (GDestroyNotify) proxied_property_free); |
| 781 |
gst_object_unref (loaded_factory); |
| 782 |
g_type_class_unref (klass); |
| 783 |
g_free (names_array); |
| 784 |
while (n_params--) |
| 785 |
g_value_unset (&values_array[n_params]); |
| 786 |
g_free (values_array); |
| 787 |
|
| 788 |
return ret; |
| 789 |
} |
| 790 |
|
| 791 |
static gboolean gst_parse_child_proxy_find_child ( |
| 792 |
GstChildProxy * child_proxy, const gchar *name) |
| 793 |
{ |
| 794 |
gchar **names = NULL, **current = NULL; |
| 795 |
GObject *obj = NULL; |
| 796 |
gboolean found = FALSE; |
| 797 |
|
| 798 |
obj = G_OBJECT (g_object_ref (child_proxy)); |
| 799 |
|
| 800 |
current = names = g_strsplit (name, "::", -1); |
| 801 |
|
| 802 |
/* find the owner of the property */ |
| 803 |
while (current[1]) { |
| 804 |
GObject *next = NULL; |
| 805 |
|
| 806 |
/* Cannot ask for the child of a non-childproxy */ |
| 807 |
if (!GST_IS_CHILD_PROXY (obj)) { |
| 808 |
break; |
| 809 |
} |
| 810 |
|
| 811 |
next = gst_child_proxy_get_child_by_name (GST_CHILD_PROXY (obj), |
| 812 |
current[0]); |
| 813 |
|
| 814 |
/* The child doesn't exist yet */ |
| 815 |
if (!next) { |
| 816 |
break; |
| 817 |
} |
| 818 |
|
| 819 |
gst_object_unref (obj); |
| 820 |
obj = next; |
| 821 |
current++; |
| 822 |
} |
| 823 |
|
| 824 |
gst_object_unref (obj); |
| 825 |
|
| 826 |
/* The remaining name is the property, we have found the object */ |
| 827 |
if (current[1] == NULL) { |
| 828 |
found = TRUE; |
| 829 |
} |
| 830 |
g_strfreev (names); |
| 831 |
|
| 832 |
return found; |
| 833 |
} |
| 834 |
|
| 835 |
static void gst_parse_element_set (gchar *value, GstElement *element, graph_t *graph) |
| 836 |
{ |
| 837 |
GParamSpec *pspec = NULL; |
| 838 |
gchar *pos; |
| 839 |
GValue v = { 0, }; |
| 840 |
GObject *target = NULL; |
| 841 |
|
| 842 |
/* do nothing if assignment is for missing element */ |
| 843 |
if (element == NULL) |
| 844 |
goto out; |
| 845 |
|
| 846 |
pos = gst_parse_split_assignment (value); |
| 847 |
|
| 848 |
if (GST_IS_CHILD_PROXY (element) && strstr (value, "::") != NULL) { |
| 849 |
if (!gst_child_proxy_lookup (GST_CHILD_PROXY (element), value, &target, &pspec)) { |
| 850 |
/* the property was not found. if the target child doesn't exist |
| 851 |
then we do a delayed set waiting for new elements to be added. If |
| 852 |
the child was found, we fail since the property doesn't exist. |
| 853 |
*/ |
| 854 |
if (!gst_parse_child_proxy_find_child (GST_CHILD_PROXY (element), value)) { |
| 855 |
gst_parse_add_delayed_set (GST_CHILD_PROXY (element), value, pos); |
| 856 |
} else { |
| 857 |
goto error; |
| 858 |
} |
| 859 |
} |
| 860 |
} else { |
| 861 |
pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (element), value); |
| 862 |
if (pspec != NULL) { |
| 863 |
target = G_OBJECT (g_object_ref (element)); |
| 864 |
GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, target, "found %s property", value); |
| 865 |
} else { |
| 866 |
SET_ERROR (graph, GST_PARSE_ERROR_NO_SUCH_PROPERTY, \ |
| 867 |
_("no property \"%s\" in element \"%s\""), value, \ |
| 868 |
GST_ELEMENT_NAME (element)); |
| 869 |
} |
| 870 |
} |
| 871 |
|
| 872 |
if (pspec != NULL && target != NULL) { |
| 873 |
if (!collect_value (pspec, pos, &v)) { |
| 874 |
goto error; |
| 875 |
} else { |
| 876 |
g_object_set_property (target, pspec->name, &v); |
| 877 |
} |
| 878 |
} |
| 879 |
|
| 880 |
out: |
| 881 |
gst_parse_strfree (value); |
| 882 |
if (G_IS_VALUE (&v)) |
| 883 |
g_value_unset (&v); |
| 884 |
if (target) |
| 885 |
gst_object_unref (target); |
| 886 |
return; |
| 887 |
|
| 888 |
error: |
| 889 |
SET_ERROR (graph, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY, |
| 890 |
_("could not set property \"%s\" in element \"%s\" to \"%s\""), |
| 891 |
value, GST_ELEMENT_NAME (element), pos); |
| 892 |
goto out; |
| 893 |
} |
| 894 |
|
| 895 |
static void gst_parse_free_reference (reference_t *rr) |
| 896 |
{ |
| 897 |
if(rr->element) gst_object_unref(rr->element); |
| 898 |
gst_parse_strfree (rr->name); |
| 899 |
g_slist_foreach (rr->pads, (GFunc) gst_parse_strfree, NULL); |
| 900 |
g_slist_free (rr->pads); |
| 901 |
} |
| 902 |
|
| 903 |
static void gst_parse_free_link (link_t *link) |
| 904 |
{ |
| 905 |
gst_parse_free_reference (&(link->src)); |
| 906 |
gst_parse_free_reference (&(link->sink)); |
| 907 |
if (link->caps) gst_caps_unref (link->caps); |
| 908 |
gst_parse_link_free (link); |
| 909 |
} |
| 910 |
|
| 911 |
static void gst_parse_free_chain (chain_t *ch) |
| 912 |
{ |
| 913 |
GSList *walk; |
| 914 |
gst_parse_free_reference (&(ch->first)); |
| 915 |
gst_parse_free_reference (&(ch->last)); |
| 916 |
for(walk=ch->elements;walk;walk=walk->next) |
| 917 |
gst_object_unref (walk->data); |
| 918 |
g_slist_free (ch->elements); |
| 919 |
gst_parse_chain_free (ch); |
| 920 |
} |
| 921 |
|
| 922 |
static void gst_parse_free_element (element_t *el) |
| 923 |
{ |
| 924 |
g_slist_free_full (el->values, gst_parse_strfree); |
| 925 |
g_slist_free_full (el->presets, gst_parse_strfree); |
| 926 |
gst_parse_strfree (el->factory_name); |
| 927 |
gst_parse_element_free (el); |
| 928 |
} |
| 929 |
|
| 930 |
static void gst_parse_free_delayed_link (DelayedLink *link) |
| 931 |
{ |
| 932 |
g_free (link->src_pad); |
| 933 |
g_free (link->sink_pad); |
| 934 |
if (link->caps) gst_caps_unref (link->caps); |
| 935 |
g_free (link); |
| 936 |
} |
| 937 |
|
| 938 |
#define PRETTY_PAD_NAME_FMT "%s %s of %s named %s" |
| 939 |
#define PRETTY_PAD_NAME_ARGS(elem, pad_name) \ |
| 940 |
(pad_name ? "pad" : "some"), (pad_name ? pad_name : "pad"), \ |
| 941 |
G_OBJECT_TYPE_NAME(elem), GST_STR_NULL (GST_ELEMENT_NAME (elem)) |
| 942 |
|
| 943 |
static void gst_parse_no_more_pads (GstElement *src, gpointer data) |
| 944 |
{ |
| 945 |
DelayedLink *link = data; |
| 946 |
|
| 947 |
/* Don't warn for all-pads links, as we expect those to |
| 948 |
* still be active at no-more-pads */ |
| 949 |
if (!link->all_pads) { |
| 950 |
GST_ELEMENT_WARNING(src, PARSE, DELAYED_LINK, |
| 951 |
(_("Delayed linking failed.")), |
| 952 |
("failed delayed linking " PRETTY_PAD_NAME_FMT " to " PRETTY_PAD_NAME_FMT, |
| 953 |
PRETTY_PAD_NAME_ARGS (src, link->src_pad), |
| 954 |
PRETTY_PAD_NAME_ARGS (link->sink, link->sink_pad))); |
| 955 |
} |
| 956 |
/* we keep the handlers connected, so that in case an element still adds a pad |
| 957 |
* despite no-more-pads, we will consider it for pending delayed links */ |
| 958 |
} |
| 959 |
|
| 960 |
static void gst_parse_found_pad (GstElement *src, GstPad *pad, gpointer data) |
| 961 |
{ |
| 962 |
DelayedLink *link = data; |
| 963 |
|
| 964 |
GST_CAT_INFO (GST_CAT_PIPELINE, |
| 965 |
"trying delayed linking %s " PRETTY_PAD_NAME_FMT " to " PRETTY_PAD_NAME_FMT, |
| 966 |
link->all_pads ? "all pads" : "one pad", |
| 967 |
PRETTY_PAD_NAME_ARGS (src, link->src_pad), |
| 968 |
PRETTY_PAD_NAME_ARGS (link->sink, link->sink_pad)); |
| 969 |
|
| 970 |
if (gst_element_link_pads_filtered (src, link->src_pad, link->sink, |
| 971 |
link->sink_pad, link->caps)) { |
| 972 |
/* do this here, we don't want to get any problems later on when |
| 973 |
* unlocking states */ |
| 974 |
GST_CAT_DEBUG (GST_CAT_PIPELINE, |
| 975 |
"delayed linking %s " PRETTY_PAD_NAME_FMT " to " PRETTY_PAD_NAME_FMT " worked", |
| 976 |
link->all_pads ? "all pads" : "one pad", |
| 977 |
PRETTY_PAD_NAME_ARGS (src, link->src_pad), |
| 978 |
PRETTY_PAD_NAME_ARGS (link->sink, link->sink_pad)); |
| 979 |
/* releases 'link' */ |
| 980 |
if (!link->all_pads) { |
| 981 |
g_signal_handler_disconnect (src, link->no_more_pads_signal_id); |
| 982 |
g_signal_handler_disconnect (src, link->pad_added_signal_id); |
| 983 |
} |
| 984 |
} |
| 985 |
} |
| 986 |
|
| 987 |
/* both padnames and the caps may be NULL */ |
| 988 |
static gboolean |
| 989 |
gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad, |
| 990 |
GstElement *sink, const gchar *sink_pad, |
| 991 |
GstCaps *caps, gboolean all_pads) |
| 992 |
{ |
| 993 |
GList *templs = gst_element_class_get_pad_template_list ( |
| 994 |
GST_ELEMENT_GET_CLASS (src)); |
| 995 |
|
| 996 |
for (; templs; templs = templs->next) { |
| 997 |
GstPadTemplate *templ = (GstPadTemplate *) templs->data; |
| 998 |
if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) && |
| 999 |
(GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES)) |
| 1000 |
{ |
| 1001 |
DelayedLink *data = g_new (DelayedLink, 1); |
| 1002 |
|
| 1003 |
data->all_pads = all_pads; |
| 1004 |
|
| 1005 |
/* TODO: maybe we should check if src_pad matches this template's names */ |
| 1006 |
|
| 1007 |
GST_CAT_DEBUG (GST_CAT_PIPELINE, |
| 1008 |
"trying delayed link " PRETTY_PAD_NAME_FMT " to " PRETTY_PAD_NAME_FMT, |
| 1009 |
PRETTY_PAD_NAME_ARGS (src, src_pad), |
| 1010 |
PRETTY_PAD_NAME_ARGS (sink, sink_pad)); |
| 1011 |
|
| 1012 |
data->src_pad = g_strdup (src_pad); |
| 1013 |
data->sink = sink; |
| 1014 |
data->sink_pad = g_strdup (sink_pad); |
| 1015 |
if (caps) { |
| 1016 |
data->caps = gst_caps_copy (caps); |
| 1017 |
} else { |
| 1018 |
data->caps = NULL; |
| 1019 |
} |
| 1020 |
data->pad_added_signal_id = g_signal_connect_data (src, "pad-added", |
| 1021 |
G_CALLBACK (gst_parse_found_pad), data, |
| 1022 |
(GClosureNotify) gst_parse_free_delayed_link, (GConnectFlags) 0); |
| 1023 |
data->no_more_pads_signal_id = g_signal_connect (src, "no-more-pads", |
| 1024 |
G_CALLBACK (gst_parse_no_more_pads), data); |
| 1025 |
return TRUE; |
| 1026 |
} |
| 1027 |
} |
| 1028 |
return FALSE; |
| 1029 |
} |
| 1030 |
|
| 1031 |
static gboolean |
| 1032 |
gst_parse_element_can_do_caps (GstElement * e, GstPadDirection dir, |
| 1033 |
GstCaps * link_caps) |
| 1034 |
{ |
| 1035 |
gboolean can_do = FALSE, done = FALSE; |
| 1036 |
GstIterator *it; |
| 1037 |
|
| 1038 |
it = (dir == GST_PAD_SRC) ? gst_element_iterate_src_pads (e) : gst_element_iterate_sink_pads (e); |
| 1039 |
|
| 1040 |
while (!done && !can_do) { |
| 1041 |
GValue v = G_VALUE_INIT; |
| 1042 |
GstPad *pad; |
| 1043 |
GstCaps *caps; |
| 1044 |
|
| 1045 |
switch (gst_iterator_next (it, &v)) { |
| 1046 |
case GST_ITERATOR_OK: |
| 1047 |
pad = g_value_get_object (&v); |
| 1048 |
|
| 1049 |
caps = gst_pad_get_current_caps (pad); |
| 1050 |
if (caps == NULL) |
| 1051 |
caps = gst_pad_query_caps (pad, NULL); |
| 1052 |
|
| 1053 |
can_do = gst_caps_can_intersect (caps, link_caps); |
| 1054 |
|
| 1055 |
GST_TRACE ("can_do: %d for %" GST_PTR_FORMAT " and %" GST_PTR_FORMAT, |
| 1056 |
can_do, caps, link_caps); |
| 1057 |
|
| 1058 |
gst_caps_unref (caps); |
| 1059 |
|
| 1060 |
g_value_unset (&v); |
| 1061 |
break; |
| 1062 |
case GST_ITERATOR_DONE: |
| 1063 |
case GST_ITERATOR_ERROR: |
| 1064 |
done = TRUE; |
| 1065 |
break; |
| 1066 |
case GST_ITERATOR_RESYNC: |
| 1067 |
gst_iterator_resync (it); |
| 1068 |
break; |
| 1069 |
} |
| 1070 |
} |
| 1071 |
|
| 1072 |
gst_iterator_free (it); |
| 1073 |
|
| 1074 |
return can_do; |
| 1075 |
} |
| 1076 |
|
| 1077 |
static gchar* |
| 1078 |
format_pad_names(const GSList* list) |
| 1079 |
{ |
| 1080 |
if (!list) |
| 1081 |
return g_strdup ("(any)"); |
| 1082 |
GString* str = g_string_new (NULL); |
| 1083 |
gboolean is_first = TRUE; |
| 1084 |
while (list) { |
| 1085 |
if (!is_first) |
| 1086 |
g_string_append (str, ", "); |
| 1087 |
g_string_append (str, (const gchar *) list->data); |
| 1088 |
list = list->next; |
| 1089 |
is_first = FALSE; |
| 1090 |
} |
| 1091 |
return g_string_free (str, FALSE); |
| 1092 |
} |
| 1093 |
|
| 1094 |
/* |
| 1095 |
* performs a link and frees the struct. src and sink elements must be given |
| 1096 |
* return values 0 - link performed |
| 1097 |
* 1 - link delayed |
| 1098 |
* <0 - error |
| 1099 |
*/ |
| 1100 |
static gint |
| 1101 |
gst_parse_perform_link (link_t *link, graph_t *graph) |
| 1102 |
{ |
| 1103 |
GstElement *src = link->src.element; |
| 1104 |
GstElement *sink = link->sink.element; |
| 1105 |
GSList *srcs = link->src.pads; |
| 1106 |
GSList *sinks = link->sink.pads; |
| 1107 |
g_assert (GST_IS_ELEMENT (src)); |
| 1108 |
g_assert (GST_IS_ELEMENT (sink)); |
| 1109 |
|
| 1110 |
#ifndef GST_DISABLE_GST_DEBUG |
| 1111 |
gchar* srcpad_names = format_pad_names (srcs); |
| 1112 |
gchar* sinkpad_names = format_pad_names (sinks); |
| 1113 |
GST_CAT_INFO (GST_CAT_PIPELINE, |
| 1114 |
"linking pads {%s} of %s named %s to pads {%s} of %s named %s with caps \"%" GST_PTR_FORMAT "\"", |
| 1115 |
srcpad_names, G_OBJECT_TYPE_NAME (src), GST_STR_NULL (GST_ELEMENT_NAME (src)), |
| 1116 |
sinkpad_names, G_OBJECT_TYPE_NAME (sink), GST_STR_NULL (GST_ELEMENT_NAME (sink)), |
| 1117 |
link->caps); |
| 1118 |
g_free (srcpad_names); |
| 1119 |
g_free (sinkpad_names); |
| 1120 |
#endif |
| 1121 |
|
| 1122 |
if (!srcs || !sinks) { |
| 1123 |
gboolean found_one = gst_element_link_pads_filtered (src, |
| 1124 |
srcs ? (const gchar *) srcs->data : NULL, sink, |
| 1125 |
sinks ? (const gchar *) sinks->data : NULL, link->caps); |
| 1126 |
|
| 1127 |
if (found_one) { |
| 1128 |
if (!link->all_pads) |
| 1129 |
goto success; /* Linked one, and not an all-pads link = we're done */ |
| 1130 |
|
| 1131 |
/* Try and link more available pads */ |
| 1132 |
while (gst_element_link_pads_filtered (src, |
| 1133 |
srcs ? (const gchar *) srcs->data : NULL, sink, |
| 1134 |
sinks ? (const gchar *) sinks->data : NULL, link->caps)); |
| 1135 |
} |
| 1136 |
|
| 1137 |
/* We either didn't find any static pads, or this is a all-pads link, |
| 1138 |
* in which case watch for future pads and link those. Not a failure |
| 1139 |
* in the all-pads case if there's no sometimes pads to watch */ |
| 1140 |
if (gst_parse_perform_delayed_link (src, |
| 1141 |
srcs ? (const gchar *) srcs->data : NULL, |
| 1142 |
sink, sinks ? (const gchar *) sinks->data : NULL, link->caps, |
| 1143 |
link->all_pads) || link->all_pads) { |
| 1144 |
goto success; |
| 1145 |
} else { |
| 1146 |
goto error; |
| 1147 |
} |
| 1148 |
} |
| 1149 |
if (g_slist_length (link->src.pads) != g_slist_length (link->sink.pads)) { |
| 1150 |
goto error; |
| 1151 |
} |
| 1152 |
while (srcs && sinks) { |
| 1153 |
const gchar *src_pad = (const gchar *) srcs->data; |
| 1154 |
const gchar *sink_pad = (const gchar *) sinks->data; |
| 1155 |
srcs = g_slist_next (srcs); |
| 1156 |
sinks = g_slist_next (sinks); |
| 1157 |
if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad, |
| 1158 |
link->caps)) { |
| 1159 |
continue; |
| 1160 |
} else { |
| 1161 |
if (gst_parse_perform_delayed_link (src, src_pad, |
| 1162 |
sink, sink_pad, |
| 1163 |
link->caps, link->all_pads)) { |
| 1164 |
continue; |
| 1165 |
} else { |
| 1166 |
goto error; |
| 1167 |
} |
| 1168 |
} |
| 1169 |
} |
| 1170 |
|
| 1171 |
success: |
| 1172 |
gst_parse_free_link (link); |
| 1173 |
return 0; |
| 1174 |
|
| 1175 |
error: |
| 1176 |
if (link->caps != NULL) { |
| 1177 |
gboolean src_can_do_caps, sink_can_do_caps; |
| 1178 |
gchar *caps_str = gst_caps_to_string (link->caps); |
| 1179 |
|
| 1180 |
src_can_do_caps = |
| 1181 |
gst_parse_element_can_do_caps (src, GST_PAD_SRC, link->caps); |
| 1182 |
sink_can_do_caps = |
| 1183 |
gst_parse_element_can_do_caps (sink, GST_PAD_SINK, link->caps); |
| 1184 |
|
| 1185 |
if (!src_can_do_caps && sink_can_do_caps) { |
| 1186 |
SET_ERROR (graph, GST_PARSE_ERROR_LINK, |
| 1187 |
_("could not link %s to %s, %s can't handle caps %s"), |
| 1188 |
GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (sink), |
| 1189 |
GST_ELEMENT_NAME (src), caps_str); |
| 1190 |
} else if (src_can_do_caps && !sink_can_do_caps) { |
| 1191 |
SET_ERROR (graph, GST_PARSE_ERROR_LINK, |
| 1192 |
_("could not link %s to %s, %s can't handle caps %s"), |
| 1193 |
GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (sink), |
| 1194 |
GST_ELEMENT_NAME (sink), caps_str); |
| 1195 |
} else if (!src_can_do_caps && !sink_can_do_caps) { |
| 1196 |
SET_ERROR (graph, GST_PARSE_ERROR_LINK, |
| 1197 |
_("could not link %s to %s, neither element can handle caps %s"), |
| 1198 |
GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (sink), caps_str); |
| 1199 |
} else { |
| 1200 |
SET_ERROR (graph, GST_PARSE_ERROR_LINK, |
| 1201 |
_("could not link %s to %s with caps %s"), |
| 1202 |
GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (sink), caps_str); |
| 1203 |
} |
| 1204 |
g_free (caps_str); |
| 1205 |
} else { |
| 1206 |
SET_ERROR (graph, GST_PARSE_ERROR_LINK, |
| 1207 |
_("could not link %s to %s"), GST_ELEMENT_NAME (src), |
| 1208 |
GST_ELEMENT_NAME (sink)); |
| 1209 |
} |
| 1210 |
gst_parse_free_link (link); |
| 1211 |
return -1; |
| 1212 |
} |
| 1213 |
|
| 1214 |
|
| 1215 |
static int yyerror (void *scanner, graph_t *graph, const char *s); |
| 1216 |
%} |
| 1217 |
|
| 1218 |
%union { |
| 1219 |
gchar *ss; |
| 1220 |
chain_t *cc; |
| 1221 |
link_t *ll; |
| 1222 |
reference_t rr; |
| 1223 |
element_t *ee; |
| 1224 |
GSList *pp; |
| 1225 |
graph_t *gg; |
| 1226 |
} |
| 1227 |
|
| 1228 |
/* No grammar ambiguities expected, FAIL otherwise */ |
| 1229 |
%expect 0 |
| 1230 |
|
| 1231 |
%token <ss> PARSE_URL |
| 1232 |
%token <ss> IDENTIFIER |
| 1233 |
%left <ss> REF PADREF BINREF |
| 1234 |
%token <ss> ASSIGNMENT PRESET |
| 1235 |
%token <ss> LINK |
| 1236 |
%token <ss> LINK_ALL |
| 1237 |
|
| 1238 |
%type <ss> binopener |
| 1239 |
%type <gg> graph |
| 1240 |
%type <cc> chain bin chainlist openchain elementary |
| 1241 |
%type <rr> reference |
| 1242 |
%type <ll> link |
| 1243 |
%type <ee> element |
| 1244 |
%type <pp> morepads pads assignments |
| 1245 |
|
| 1246 |
%destructor { gst_parse_strfree ($$); } <ss> |
| 1247 |
%destructor { if($$) |
| 1248 |
gst_parse_free_chain($$); } <cc> |
| 1249 |
%destructor { gst_parse_free_link ($$); } <ll> |
| 1250 |
%destructor { gst_parse_free_reference(&($$));} <rr> |
| 1251 |
%destructor { gst_parse_free_element ($$); } <ee> |
| 1252 |
%destructor { GSList *walk; |
| 1253 |
for(walk=$$;walk;walk=walk->next) |
| 1254 |
gst_parse_strfree (walk->data); |
| 1255 |
g_slist_free ($$); } <pp> |
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
%left '(' ')' |
| 1260 |
%left ',' |
| 1261 |
%right '.' |
| 1262 |
%left '!' '=' ':' |
| 1263 |
|
| 1264 |
%lex-param { void *scanner } |
| 1265 |
%parse-param { void *scanner } |
| 1266 |
%parse-param { graph_t *graph } |
| 1267 |
@BISON_PURE_PARSER@ |
| 1268 |
|
| 1269 |
%start graph |
| 1270 |
%% |
| 1271 |
|
| 1272 |
/************************************************************* |
| 1273 |
* Grammar explanation: |
| 1274 |
* _element_s are specified by an identifier of their type. |
| 1275 |
* a name can be give in the optional property-assignments |
| 1276 |
* coffeeelement |
| 1277 |
* fakesrc name=john |
| 1278 |
* identity silence=false name=frodo |
| 1279 |
* (cont'd) |
| 1280 |
**************************************************************/ |
| 1281 |
element: IDENTIFIER { |
| 1282 |
$$ = gst_parse_element_new(); |
| 1283 |
$$->factory_name = $1; |
| 1284 |
|
| 1285 |
/* silence unused but set warnings/errors */ |
| 1286 |
(void) yynerrs; |
| 1287 |
} |
| 1288 |
| element PRESET { |
| 1289 |
$$->presets = g_slist_append ($$->presets, $2); |
| 1290 |
$$ = $1; |
| 1291 |
} |
| 1292 |
| element ASSIGNMENT { |
| 1293 |
$$->values = g_slist_append ($$->values, $2); |
| 1294 |
$$ = $1; |
| 1295 |
} |
| 1296 |
; |
| 1297 |
|
| 1298 |
/************************************************************* |
| 1299 |
* Grammar explanation: (cont'd) |
| 1300 |
* a graph has (pure) _element_s, _bin_s and _link_s. |
| 1301 |
* since bins are special elements, bins and elements can |
| 1302 |
* be generalized as _elementary_. |
| 1303 |
* The construction of _bin_s will be discussed later. |
| 1304 |
* (cont'd) |
| 1305 |
* |
| 1306 |
**************************************************************/ |
| 1307 |
elementary: |
| 1308 |
element { |
| 1309 |
GstElement *element = NULL; |
| 1310 |
|
| 1311 |
$$ = gst_parse_chain_new (); |
| 1312 |
|
| 1313 |
if ($1 && !(element = gst_parse_element_make (graph, $1))) { |
| 1314 |
add_missing_element(graph, $1->factory_name); |
| 1315 |
} else { |
| 1316 |
/* g_print ("@%p: CHAINing elementary\n", $$); */ |
| 1317 |
$$->first.element = element ? gst_object_ref(element) : NULL; |
| 1318 |
$$->last.element = element ? gst_object_ref(element) : NULL; |
| 1319 |
$$->first.name = $$->last.name = NULL; |
| 1320 |
$$->first.pads = $$->last.pads = NULL; |
| 1321 |
$$->elements = element ? g_slist_prepend (NULL, element) : NULL; |
| 1322 |
} |
| 1323 |
|
| 1324 |
gst_parse_free_element ($1); |
| 1325 |
|
| 1326 |
} |
| 1327 |
| bin { $$=$1; } |
| 1328 |
; |
| 1329 |
|
| 1330 |
/************************************************************* |
| 1331 |
* Grammar explanation: (cont'd) |
| 1332 |
* a _chain_ is a list of _elementary_s that have _link_s in between |
| 1333 |
* which are represented through infix-notation. |
| 1334 |
* |
| 1335 |
* fakesrc ! sometransformation ! fakesink |
| 1336 |
* |
| 1337 |
* every _link_ can be augmented with _pads_. |
| 1338 |
* |
| 1339 |
* coffeesrc .sound ! speakersink |
| 1340 |
* multisrc .movie,ads ! .projector,smallscreen multisink |
| 1341 |
* |
| 1342 |
* and every _link_ can be setup to filter media-types |
| 1343 |
* mediasrc ! audio/x-raw, signed=TRUE ! stereosink |
| 1344 |
* |
| 1345 |
* User HINT: |
| 1346 |
* if the lexer does not recognize your media-type it |
| 1347 |
* will make it an element name. that results in errors |
| 1348 |
* like |
| 1349 |
* NO SUCH ELEMENT: no element audio7x-raw |
| 1350 |
* '7' vs. '/' in https://en.wikipedia.org/wiki/QWERTZ |
| 1351 |
* |
| 1352 |
* Parsing HINT: |
| 1353 |
* in the parser we need to differ between chains that can |
| 1354 |
* be extended by more elementaries (_openchain_) and others |
| 1355 |
* that are syntactically closed (handled later in this file). |
| 1356 |
* (e.g. fakesrc ! sinkreferencename.padname) |
| 1357 |
**************************************************************/ |
| 1358 |
chain: openchain { $$=$1; |
| 1359 |
if($$->last.name){ |
| 1360 |
SET_ERROR (graph, GST_PARSE_ERROR_SYNTAX, |
| 1361 |
_("unexpected reference \"%s\" - ignoring"), $$->last.name); |
| 1362 |
gst_parse_strfree($$->last.name); |
| 1363 |
$$->last.name=NULL; |
| 1364 |
} |
| 1365 |
if($$->last.pads){ |
| 1366 |
SET_ERROR (graph, GST_PARSE_ERROR_SYNTAX, |
| 1367 |
_("unexpected pad-reference \"%s\" - ignoring"), (gchar*)$$->last.pads->data); |
| 1368 |
g_slist_foreach ($$->last.pads, (GFunc) gst_parse_strfree, NULL); |
| 1369 |
g_slist_free ($$->last.pads); |
| 1370 |
$$->last.pads=NULL; |
| 1371 |
} |
| 1372 |
} |
| 1373 |
; |
| 1374 |
|
| 1375 |
openchain: |
| 1376 |
elementary pads { $$=$1; |
| 1377 |
$$->last.pads = g_slist_concat ($$->last.pads, $2); |
| 1378 |
/* g_print ("@%p@%p: FKI elementary pads\n", $1, $$->last.pads); */ |
| 1379 |
} |
| 1380 |
| openchain link pads elementary pads |
| 1381 |
{ |
| 1382 |
$2->src = $1->last; |
| 1383 |
$2->sink = $4->first; |
| 1384 |
$2->sink.pads = g_slist_concat ($3, $2->sink.pads); |
| 1385 |
TRY_SETUP_LINK($2); |
| 1386 |
$4->first = $1->first; |
| 1387 |
$4->elements = g_slist_concat ($1->elements, $4->elements); |
| 1388 |
gst_parse_chain_free($1); |
| 1389 |
$$ = $4; |
| 1390 |
$$->last.pads = g_slist_concat ($$->last.pads, $5); |
| 1391 |
} |
| 1392 |
; |
| 1393 |
|
| 1394 |
link: LINK { $$ = gst_parse_link_new (); |
| 1395 |
$$->all_pads = FALSE; |
| 1396 |
if ($1) { |
| 1397 |
gchar *str = str_unwrap ($1); |
| 1398 |
$$->caps = gst_caps_from_string (str); |
| 1399 |
g_free (str); |
| 1400 |
if ($$->caps == NULL) |
| 1401 |
SET_ERROR (graph, GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $1); |
| 1402 |
gst_parse_strfree ($1); |
| 1403 |
} |
| 1404 |
} |
| 1405 |
| LINK_ALL { $$ = gst_parse_link_new (); |
| 1406 |
$$->all_pads = TRUE; |
| 1407 |
if ($1) { |
| 1408 |
gchar *str = str_unwrap ($1); |
| 1409 |
$$->caps = gst_caps_from_string (str); |
| 1410 |
g_free (str); |
| 1411 |
if ($$->caps == NULL) |
| 1412 |
SET_ERROR (graph, GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $1); |
| 1413 |
gst_parse_strfree ($1); |
| 1414 |
} |
| 1415 |
} |
| 1416 |
; |
| 1417 |
pads: /* NOP */ { $$ = NULL; } |
| 1418 |
| PADREF morepads { $$ = $2; |
| 1419 |
$$ = g_slist_prepend ($$, $1); |
| 1420 |
} |
| 1421 |
; |
| 1422 |
morepads: /* NOP */ { $$ = NULL; } |
| 1423 |
| ',' IDENTIFIER morepads { $$ = g_slist_prepend ($3, $2); } |
| 1424 |
; |
| 1425 |
|
| 1426 |
/************************************************************* |
| 1427 |
* Grammar explanation: (cont'd) |
| 1428 |
* the first and last elements of a _chain_ can be give |
| 1429 |
* as URL. This creates special elements that fit the URL. |
| 1430 |
* |
| 1431 |
* fakesrc ! http://fake-sink.org |
| 1432 |
* http://somesource.org ! fakesink |
| 1433 |
**************************************************************/ |
| 1434 |
|
| 1435 |
chain: openchain link PARSE_URL { GstElement *element = |
| 1436 |
gst_element_make_from_uri (GST_URI_SINK, $3, NULL, NULL); |
| 1437 |
/* FIXME: get and parse error properly */ |
| 1438 |
if (!element) { |
| 1439 |
SET_ERROR (graph, GST_PARSE_ERROR_NO_SUCH_ELEMENT, |
| 1440 |
_("no sink element for URI \"%s\""), $3); |
| 1441 |
} |
| 1442 |
$$ = $1; |
| 1443 |
$2->sink.element = element?gst_object_ref(element):NULL; |
| 1444 |
$2->src = $1->last; |
| 1445 |
TRY_SETUP_LINK($2); |
| 1446 |
$$->last.element = NULL; |
| 1447 |
$$->last.name = NULL; |
| 1448 |
$$->last.pads = NULL; |
| 1449 |
if(element) $$->elements = g_slist_append ($$->elements, element); |
| 1450 |
g_free ($3); |
| 1451 |
} |
| 1452 |
; |
| 1453 |
openchain: |
| 1454 |
PARSE_URL { GstElement *element = |
| 1455 |
gst_element_make_from_uri (GST_URI_SRC, $1, NULL, NULL); |
| 1456 |
/* FIXME: get and parse error properly */ |
| 1457 |
if (!element) { |
| 1458 |
SET_ERROR (graph, GST_PARSE_ERROR_NO_SUCH_ELEMENT, |
| 1459 |
_("no source element for URI \"%s\""), $1); |
| 1460 |
} |
| 1461 |
$$ = gst_parse_chain_new (); |
| 1462 |
/* g_print ("@%p: CHAINing srcURL\n", $$); */ |
| 1463 |
$$->first.element = NULL; |
| 1464 |
$$->first.name = NULL; |
| 1465 |
$$->first.pads = NULL; |
| 1466 |
$$->last.element = element ? gst_object_ref(element):NULL; |
| 1467 |
$$->last.name = NULL; |
| 1468 |
$$->last.pads = NULL; |
| 1469 |
$$->elements = element ? g_slist_prepend (NULL, element) : NULL; |
| 1470 |
g_free($1); |
| 1471 |
} |
| 1472 |
; |
| 1473 |
|
| 1474 |
|
| 1475 |
/************************************************************* |
| 1476 |
* Grammar explanation: (cont'd) |
| 1477 |
* the first and last elements of a _chain_ can be linked |
| 1478 |
* to a named _reference_ (with optional pads). |
| 1479 |
* |
| 1480 |
* fakesrc ! nameOfSinkElement. |
| 1481 |
* fakesrc ! nameOfSinkElement.Padname |
| 1482 |
* fakesrc ! nameOfSinkElement.Padname, anotherPad |
| 1483 |
* nameOfSource.Padname ! fakesink |
| 1484 |
**************************************************************/ |
| 1485 |
|
| 1486 |
chain: openchain link reference { $$ = $1; |
| 1487 |
$2->sink= $3; |
| 1488 |
$2->src = $1->last; |
| 1489 |
TRY_SETUP_LINK($2); |
| 1490 |
$$->last.element = NULL; |
| 1491 |
$$->last.name = NULL; |
| 1492 |
$$->last.pads = NULL; |
| 1493 |
} |
| 1494 |
; |
| 1495 |
|
| 1496 |
|
| 1497 |
openchain: |
| 1498 |
reference { $$ = gst_parse_chain_new (); |
| 1499 |
$$->last=$1; |
| 1500 |
$$->first.element = NULL; |
| 1501 |
$$->first.name = NULL; |
| 1502 |
$$->first.pads = NULL; |
| 1503 |
$$->elements = NULL; |
| 1504 |
} |
| 1505 |
; |
| 1506 |
reference: REF morepads { |
| 1507 |
gchar *padname = $1; |
| 1508 |
GSList *pads = $2; |
| 1509 |
if (padname) { |
| 1510 |
while (*padname != '.') padname++; |
| 1511 |
*padname = '\0'; |
| 1512 |
padname++; |
| 1513 |
if (*padname != '\0') |
| 1514 |
pads = g_slist_prepend (pads, gst_parse_strdup (padname)); |
| 1515 |
} |
| 1516 |
$$.element=NULL; |
| 1517 |
$$.name=$1; |
| 1518 |
$$.pads=pads; |
| 1519 |
} |
| 1520 |
; |
| 1521 |
|
| 1522 |
|
| 1523 |
/************************************************************* |
| 1524 |
* Grammar explanation: (cont'd) |
| 1525 |
* a _chainlist_ is just a list of _chain_s. |
| 1526 |
* |
| 1527 |
* You can specify _link_s with named |
| 1528 |
* _reference_ on each side. That |
| 1529 |
* works already after the explanations above. |
| 1530 |
* someSourceName.Pad ! someSinkName. |
| 1531 |
* someSourceName.Pad,anotherPad ! someSinkName.Apad,Bpad |
| 1532 |
* |
| 1533 |
* If a syntax error occurs, the already finished _chain_s |
| 1534 |
* and _links_ are kept intact. |
| 1535 |
*************************************************************/ |
| 1536 |
|
| 1537 |
chainlist: /* NOP */ { $$ = NULL; } |
| 1538 |
| chainlist chain { if ($1){ |
| 1539 |
gst_parse_free_reference(&($1->last)); |
| 1540 |
gst_parse_free_reference(&($2->first)); |
| 1541 |
$2->first = $1->first; |
| 1542 |
$2->elements = g_slist_concat ($1->elements, $2->elements); |
| 1543 |
gst_parse_chain_free ($1); |
| 1544 |
} |
| 1545 |
$$ = $2; |
| 1546 |
} |
| 1547 |
| chainlist error { $$=$1; |
| 1548 |
GST_CAT_DEBUG (GST_CAT_PIPELINE,"trying to recover from syntax error"); |
| 1549 |
SET_ERROR (graph, GST_PARSE_ERROR_SYNTAX, _("syntax error")); |
| 1550 |
} |
| 1551 |
; |
| 1552 |
|
| 1553 |
/************************************************************* |
| 1554 |
* Grammar explanation: (cont'd) |
| 1555 |
* _bins_ |
| 1556 |
*************************************************************/ |
| 1557 |
|
| 1558 |
|
| 1559 |
assignments: /* NOP */ { $$ = NULL; } |
| 1560 |
| ASSIGNMENT assignments { $$ = g_slist_prepend ($2, $1); } |
| 1561 |
; |
| 1562 |
|
| 1563 |
binopener: '(' { $$ = gst_parse_strdup("bin"); } |
| 1564 |
| BINREF { $$ = $1; } |
| 1565 |
; |
| 1566 |
bin: binopener assignments chainlist ')' { |
| 1567 |
chain_t *chain = $3; |
| 1568 |
GSList *walk; |
| 1569 |
GstBin *bin = (GstBin *) gst_element_factory_make ($1, NULL); |
| 1570 |
if (!chain) { |
| 1571 |
SET_ERROR (graph, GST_PARSE_ERROR_EMPTY_BIN, |
| 1572 |
_("specified empty bin \"%s\", not allowed"), $1); |
| 1573 |
chain = gst_parse_chain_new (); |
| 1574 |
chain->first.element = chain->last.element = NULL; |
| 1575 |
chain->first.name = chain->last.name = NULL; |
| 1576 |
chain->first.pads = chain->last.pads = NULL; |
| 1577 |
chain->elements = NULL; |
| 1578 |
} |
| 1579 |
if (!bin) { |
| 1580 |
add_missing_element(graph, $1); |
| 1581 |
SET_ERROR (graph, GST_PARSE_ERROR_NO_SUCH_ELEMENT, |
| 1582 |
_("no bin \"%s\", unpacking elements"), $1); |
| 1583 |
/* clear property-list */ |
| 1584 |
g_slist_foreach ($2, (GFunc) gst_parse_strfree, NULL); |
| 1585 |
g_slist_free ($2); |
| 1586 |
$2 = NULL; |
| 1587 |
} else { |
| 1588 |
for (walk = chain->elements; walk; walk = walk->next ) |
| 1589 |
gst_bin_add (bin, GST_ELEMENT (walk->data)); |
| 1590 |
g_slist_free (chain->elements); |
| 1591 |
chain->elements = g_slist_prepend (NULL, bin); |
| 1592 |
} |
| 1593 |
$$ = chain; |
| 1594 |
/* set the properties now |
| 1595 |
* HINT: property-list cleared above, if bin==NULL |
| 1596 |
*/ |
| 1597 |
for (walk = $2; walk; walk = walk->next) |
| 1598 |
gst_parse_element_set ((gchar *) walk->data, |
| 1599 |
GST_ELEMENT (bin), graph); |
| 1600 |
g_slist_free ($2); |
| 1601 |
gst_parse_strfree ($1); |
| 1602 |
} |
| 1603 |
; |
| 1604 |
|
| 1605 |
/************************************************************* |
| 1606 |
* Grammar explanation: (cont'd) |
| 1607 |
* _graph_ |
| 1608 |
*************************************************************/ |
| 1609 |
|
| 1610 |
graph: chainlist { $$ = graph; |
| 1611 |
$$->chain = $1; |
| 1612 |
if(!$1) { |
| 1613 |
SET_ERROR (graph, GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed")); |
| 1614 |
} |
| 1615 |
} |
| 1616 |
; |
| 1617 |
|
| 1618 |
%% |
| 1619 |
|
| 1620 |
|
| 1621 |
static int |
| 1622 |
yyerror (void *scanner, graph_t *graph, const char *s) |
| 1623 |
{ |
| 1624 |
/* FIXME: This should go into the GError somehow, but how? */ |
| 1625 |
GST_WARNING ("Error during parsing: %s", s); |
| 1626 |
return -1; |
| 1627 |
} |
| 1628 |
|
| 1629 |
|
| 1630 |
static GstBusSyncReply |
| 1631 |
parse_launch_handle_message_sync (GstBus * bus, GstMessage * message, gpointer user_data) |
| 1632 |
{ |
| 1633 |
reason_receiver_t *receiver = (reason_receiver_t *) user_data; |
| 1634 |
GstObject *src = GST_MESSAGE_SRC (message); |
| 1635 |
GstMessageType type = GST_MESSAGE_TYPE (message); |
| 1636 |
|
| 1637 |
switch (type) { |
| 1638 |
case GST_MESSAGE_ERROR: |
| 1639 |
{ |
| 1640 |
GError *error; |
| 1641 |
gchar *debug_msg; |
| 1642 |
gchar *explanation; |
| 1643 |
const GstStructure *details; |
| 1644 |
gst_message_parse_error (message, &error, &debug_msg); |
| 1645 |
gst_message_parse_error_details (message, &details); |
| 1646 |
|
| 1647 |
explanation = gst_info_strdup_printf ("%s %" GST_PTR_FORMAT " posted " |
| 1648 |
"an error message: %s", src ? G_OBJECT_TYPE_NAME(src) : "", src, |
| 1649 |
error->message); |
| 1650 |
/* We lock the mutex a bit early so that if errors occur simultaneously |
| 1651 |
* from two threads the following log lines are logged one error at a |
| 1652 |
* time, just for convenience of the person reading the logs. */ |
| 1653 |
g_mutex_lock (&receiver->mutex); |
| 1654 |
GST_CAT_ERROR (GST_CAT_PIPELINE, "%s", explanation); |
| 1655 |
if (debug_msg) |
| 1656 |
GST_CAT_ERROR (GST_CAT_PIPELINE, "Debug message: %s", debug_msg); |
| 1657 |
if (details) |
| 1658 |
GST_CAT_ERROR (GST_CAT_PIPELINE, "Details: %" GST_PTR_FORMAT, details); |
| 1659 |
|
| 1660 |
/* This message will be suffixed when SET_ERROR() is called. |
| 1661 |
* This allows the message to be seen in gst-launch even if no logging is |
| 1662 |
* enabled, which is the default for GStreamer releases. */ |
| 1663 |
if (!receiver->reason) |
| 1664 |
receiver->reason = g_strdup (explanation); |
| 1665 |
g_mutex_unlock (&receiver->mutex); |
| 1666 |
|
| 1667 |
g_free (explanation); |
| 1668 |
g_error_free (error); |
| 1669 |
g_free (debug_msg); |
| 1670 |
break; |
| 1671 |
} |
| 1672 |
default: |
| 1673 |
break; |
| 1674 |
} |
| 1675 |
|
| 1676 |
return GST_BUS_PASS; |
| 1677 |
} |
| 1678 |
|
| 1679 |
static reason_receiver_t* |
| 1680 |
reason_receiver_new (void) { |
| 1681 |
reason_receiver_t *receiver = g_atomic_rc_box_new0 (reason_receiver_t); |
| 1682 |
g_mutex_init (&receiver->mutex); |
| 1683 |
receiver->reason = NULL; |
| 1684 |
return receiver; |
| 1685 |
} |
| 1686 |
|
| 1687 |
static void |
| 1688 |
reason_receiver_clear (reason_receiver_t *receiver) { |
| 1689 |
g_mutex_clear (&receiver->mutex); |
| 1690 |
g_free (receiver->reason); |
| 1691 |
} |
| 1692 |
|
| 1693 |
#define reason_receiver_ref(receiver) g_atomic_rc_box_acquire (receiver) |
| 1694 |
|
| 1695 |
static void |
| 1696 |
reason_receiver_unref (reason_receiver_t *receiver) { |
| 1697 |
g_atomic_rc_box_release_full (receiver, |
| 1698 |
(GDestroyNotify) reason_receiver_clear); |
| 1699 |
} |
| 1700 |
|
| 1701 |
GstElement * |
| 1702 |
priv_gst_parse_launch (const gchar *str, GError **error, GstParseContext *ctx, |
| 1703 |
GstParseFlags flags) |
| 1704 |
{ |
| 1705 |
graph_t g; |
| 1706 |
gchar *dstr; |
| 1707 |
GSList *walk; |
| 1708 |
GstElement *ret; |
| 1709 |
yyscan_t scanner; |
| 1710 |
GstBin *bin = NULL; |
| 1711 |
GstBus *temp_bus = NULL, *old_bus = NULL; |
| 1712 |
|
| 1713 |
g_return_val_if_fail (str != NULL, NULL); |
| 1714 |
g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
| 1715 |
|
| 1716 |
g.chain = NULL; |
| 1717 |
g.links = NULL; |
| 1718 |
g.error = error; |
| 1719 |
g.ctx = ctx; |
| 1720 |
g.flags = flags; |
| 1721 |
g.error_probable_reason_receiver = NULL; |
| 1722 |
|
| 1723 |
#ifdef __GST_PARSE_TRACE |
| 1724 |
GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled"); |
| 1725 |
__strings = __chains = __links = __elements = 0; |
| 1726 |
#endif /* __GST_PARSE_TRACE */ |
| 1727 |
|
| 1728 |
/* g_print("Now scanning: %s\n", str); */ |
| 1729 |
|
| 1730 |
dstr = g_strdup (str); |
| 1731 |
priv_gst_parse_yylex_init (&scanner); |
| 1732 |
priv_gst_parse_yy_scan_string (dstr, scanner); |
| 1733 |
|
| 1734 |
#if YYDEBUG |
| 1735 |
yydebug = 1; |
| 1736 |
#endif |
| 1737 |
|
| 1738 |
if (yyparse (scanner, &g) != 0) { |
| 1739 |
SET_ERROR (&g, GST_PARSE_ERROR_SYNTAX, |
| 1740 |
"Unrecoverable syntax error while parsing pipeline %s", str); |
| 1741 |
|
| 1742 |
priv_gst_parse_yylex_destroy (scanner); |
| 1743 |
g_free (dstr); |
| 1744 |
|
| 1745 |
goto error1; |
| 1746 |
} |
| 1747 |
priv_gst_parse_yylex_destroy (scanner); |
| 1748 |
g_free (dstr); |
| 1749 |
|
| 1750 |
GST_CAT_DEBUG (GST_CAT_PIPELINE, "got %u elements and %u links", |
| 1751 |
g.chain ? g_slist_length (g.chain->elements) : 0, |
| 1752 |
g_slist_length (g.links)); |
| 1753 |
|
| 1754 |
/* ensure chain is not NULL */ |
| 1755 |
if (!g.chain){ |
| 1756 |
g.chain=gst_parse_chain_new (); |
| 1757 |
g.chain->elements=NULL; |
| 1758 |
g.chain->first.element=NULL; |
| 1759 |
g.chain->first.name=NULL; |
| 1760 |
g.chain->first.pads=NULL; |
| 1761 |
g.chain->last.element=NULL; |
| 1762 |
g.chain->last.name=NULL; |
| 1763 |
g.chain->last.pads=NULL; |
| 1764 |
}; |
| 1765 |
|
| 1766 |
/* ensure elements is not empty */ |
| 1767 |
if(!g.chain->elements){ |
| 1768 |
g.chain->elements= g_slist_prepend (NULL, NULL); |
| 1769 |
}; |
| 1770 |
|
| 1771 |
/* put all elements in our bin if necessary */ |
| 1772 |
if(g.chain->elements->next){ |
| 1773 |
if (flags & GST_PARSE_FLAG_PLACE_IN_BIN) |
| 1774 |
bin = GST_BIN (gst_element_factory_make ("bin", NULL)); |
| 1775 |
else |
| 1776 |
bin = GST_BIN (gst_element_factory_make ("pipeline", NULL)); |
| 1777 |
g_assert (bin); |
| 1778 |
|
| 1779 |
/* Assign the bin a temporary bus to catch any error messages posted during |
| 1780 |
* the construction of the pipeline and log them in a way that is visible |
| 1781 |
* by default in gst-launch. */ |
| 1782 |
old_bus = gst_element_get_bus (GST_ELEMENT (bin)); |
| 1783 |
temp_bus = gst_bus_new (); |
| 1784 |
g.error_probable_reason_receiver = reason_receiver_new (); |
| 1785 |
gst_bus_set_sync_handler (temp_bus, parse_launch_handle_message_sync, |
| 1786 |
reason_receiver_ref (g.error_probable_reason_receiver), |
| 1787 |
(GDestroyNotify) reason_receiver_unref); |
| 1788 |
gst_element_set_bus (GST_ELEMENT (bin), temp_bus); |
| 1789 |
|
| 1790 |
for (walk = g.chain->elements; walk; walk = walk->next) { |
| 1791 |
if (walk->data != NULL) |
| 1792 |
gst_bin_add (bin, GST_ELEMENT (walk->data)); |
| 1793 |
} |
| 1794 |
g_slist_free (g.chain->elements); |
| 1795 |
g.chain->elements = g_slist_prepend (NULL, bin); |
| 1796 |
} |
| 1797 |
|
| 1798 |
ret = (GstElement *) g.chain->elements->data; |
| 1799 |
g_slist_free (g.chain->elements); |
| 1800 |
g.chain->elements=NULL; |
| 1801 |
gst_parse_free_chain (g.chain); |
| 1802 |
g.chain = NULL; |
| 1803 |
|
| 1804 |
|
| 1805 |
/* resolve and perform links */ |
| 1806 |
for (walk = g.links; walk; walk = walk->next) { |
| 1807 |
link_t *l = (link_t *) walk->data; |
| 1808 |
int err; |
| 1809 |
err=gst_resolve_reference( &(l->src), ret); |
| 1810 |
if (err) { |
| 1811 |
if(-1==err){ |
| 1812 |
SET_ERROR (&g, GST_PARSE_ERROR_NO_SUCH_ELEMENT, |
| 1813 |
"No src-element named \"%s\" - omitting link", l->src.name); |
| 1814 |
}else{ |
| 1815 |
/* probably a missing element which we've handled already */ |
| 1816 |
SET_ERROR (&g, GST_PARSE_ERROR_NO_SUCH_ELEMENT, |
| 1817 |
"No src-element found - omitting link"); |
| 1818 |
} |
| 1819 |
gst_parse_free_link (l); |
| 1820 |
continue; |
| 1821 |
} |
| 1822 |
|
| 1823 |
err=gst_resolve_reference( &(l->sink), ret); |
| 1824 |
if (err) { |
| 1825 |
if(-1==err){ |
| 1826 |
SET_ERROR (&g, GST_PARSE_ERROR_NO_SUCH_ELEMENT, |
| 1827 |
"No sink-element named \"%s\" - omitting link", l->src.name); |
| 1828 |
}else{ |
| 1829 |
/* probably a missing element which we've handled already */ |
| 1830 |
SET_ERROR (&g, GST_PARSE_ERROR_NO_SUCH_ELEMENT, |
| 1831 |
"No sink-element found - omitting link"); |
| 1832 |
} |
| 1833 |
gst_parse_free_link (l); |
| 1834 |
continue; |
| 1835 |
} |
| 1836 |
gst_parse_perform_link (l, &g); |
| 1837 |
} |
| 1838 |
g_slist_free (g.links); |
| 1839 |
|
| 1840 |
out: |
| 1841 |
#ifdef __GST_PARSE_TRACE |
| 1842 |
GST_CAT_DEBUG (GST_CAT_PIPELINE, |
| 1843 |
"TRACE: %u strings, %u chains, %u links and %u elements left", __strings, __chains, |
| 1844 |
__links, __elements); |
| 1845 |
if (__strings || __chains || __links || __elements) { |
| 1846 |
g_warning ("TRACE: %u strings, %u chains, %u links and %u elements left", __strings, |
| 1847 |
__chains, __links, __elements); |
| 1848 |
} |
| 1849 |
#endif /* __GST_PARSE_TRACE */ |
| 1850 |
|
| 1851 |
if (bin && temp_bus) { |
| 1852 |
gst_element_set_bus (GST_ELEMENT (bin), old_bus); |
| 1853 |
reason_receiver_unref (g.error_probable_reason_receiver); |
| 1854 |
g.error_probable_reason_receiver = NULL; |
| 1855 |
g_clear_object (&temp_bus); |
| 1856 |
g_clear_object (&old_bus); |
| 1857 |
} |
| 1858 |
|
| 1859 |
return ret; |
| 1860 |
|
| 1861 |
error1: |
| 1862 |
if (g.chain) { |
| 1863 |
gst_parse_free_chain (g.chain); |
| 1864 |
g.chain=NULL; |
| 1865 |
} |
| 1866 |
|
| 1867 |
g_slist_foreach (g.links, (GFunc)gst_parse_free_link, NULL); |
| 1868 |
g_slist_free (g.links); |
| 1869 |
|
| 1870 |
if (error) |
| 1871 |
g_assert (*error); |
| 1872 |
ret = NULL; |
| 1873 |
|
| 1874 |
goto out; |
| 1875 |
} |