From 07cf2da0c2fc4672ec96d17e53a1dc1a153be884 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 6 Dec 2002 20:06:06 +0000 Subject: [PATCH] Added syntax to make filtered connections like: osssrc src\!audio/raw, channels=int 2, width=int 8\!sink fakesink Original commit message from CVS: Added syntax to make filtered connections like: osssrc src\!audio/raw, channels=int 2, width=int 8\!sink fakesink --- gst/gstparse.c | 11 +++-- gst/parse/grammar.y | 3 +- gst/parse/parse.l | 105 +++++++++++++++++++++++++++++++++++++++++++- gst/parse/types.h | 1 + 4 files changed, 113 insertions(+), 7 deletions(-) diff --git a/gst/gstparse.c b/gst/gstparse.c index 1c43579f5b..01efa01a86 100644 --- a/gst/gstparse.c +++ b/gst/gstparse.c @@ -227,6 +227,7 @@ make_connections (graph_t *g, GError **error) GstElement *src, *sink; GstPad *p1, *p2; GstPadTemplate *pt1, *pt2; + GstCaps *caps; l = g->connections; while (l) { @@ -260,6 +261,8 @@ make_connections (graph_t *g, GError **error) a = c->src_pads; b = c->sink_pads; + caps = c->caps; + gst_caps_debug (caps, "foo"); /* g_print ("a: %p, b: %p\n", a, b); */ if (a && b) { /* balanced multipad connection */ @@ -285,7 +288,7 @@ make_connections (graph_t *g, GError **error) g_signal_connect (G_OBJECT (src), "new_pad", G_CALLBACK (dynamic_connect), dc); } else if (!p1) { goto could_not_get_pad_a; - } else if (!gst_pad_connect (p1, p2)) { + } else if (!gst_pad_connect_filtered (p1, p2, caps)) { goto could_not_connect_pads; } a = g_list_next (a); @@ -340,7 +343,7 @@ make_connections (graph_t *g, GError **error) goto could_not_get_pad_a; } - if (!gst_pad_connect (p1, p2)) { + if (!gst_pad_connect_filtered (p1, p2, caps)) { goto could_not_connect_pads; } } else if (b) { @@ -351,11 +354,11 @@ make_connections (graph_t *g, GError **error) if (!(p1 = gst_element_get_compatible_pad (src, p2))) { goto could_not_get_compatible_to_b; } - if (!gst_pad_connect (p1, p2)) { + if (!gst_pad_connect_filtered (p1, p2, caps)) { goto could_not_connect_pads; } } else { - if (!gst_element_connect (src, sink)) { + if (!gst_element_connect_filtered (src, sink, caps)) { goto could_not_connect_elements; } } diff --git a/gst/parse/grammar.y b/gst/parse/grammar.y index c3675186be..b3b3b637ee 100644 --- a/gst/parse/grammar.y +++ b/gst/parse/grammar.y @@ -23,7 +23,7 @@ static int yyerror (const char *s); } %token IDENTIFIER -%token CONNECTION BCONNECTION +%token CONNECTION BCONNECTION FCONNECTION %token VALUE %type id @@ -114,6 +114,7 @@ connection: CONNECTION rconnection: '!' { $$ = g_new0 (connection_t, 1); } | BCONNECTION { $$ = $1; } + | FCONNECTION { $$ = $1; } | id ',' rconnection ',' id { $$ = $3; $$->src_pads = g_list_prepend ($$->src_pads, $1); diff --git a/gst/parse/parse.l b/gst/parse/parse.l index 3fd200a9cd..d6c7e89cf1 100644 --- a/gst/parse/parse.l +++ b/gst/parse/parse.l @@ -34,11 +34,22 @@ _double [-+]?[[:digit:]]+"."*[[:digit:]]* _number {_integer}|{_double} _boolean "true"|"false"|"TRUE"|"FALSE" _identifier [[:alpha:]][[:alnum:]\-_%:]* +_char ([^[:space:]])|("\\".) +_string {_char}+|("\""([^\"]|"\\\"")*"\"") +_comma [[:space:]]*","[[:space:]]* +_assign [[:space:]]*"="[[:space:]]* +_caps_type_string "fourcc"|"string" +_caps_type_double "float" +_caps_string {_string}{_assign}{_caps_type_string}[[:space:]]+{_string} +_caps_int {_string}{_assign}"int"[[:space:]]+{_integer} +_caps_double {_string}{_assign}{_caps_type_double}[[:space:]]+{_double} +_caps_boolean {_string}{_assign}"boolean"[[:space:]]+{_boolean} +_caps_pair {_caps_string}|{_caps_int}|{_caps_double}|{_caps_boolean} +_caps {_string}({_comma}{_caps_pair})* _lconnection ({_identifier}\.)?{_identifier}! _rconnection !({_identifier}\.)?{_identifier} _bconnection ({_identifier}\.)?{_identifier}!({_identifier}\.)?{_identifier} -_char ([^[:space:]])|("\\".) -_string {_char}+|("\""([^\"]|"\\\"")*"\"") +_fconnection ({_identifier}\.)?{_identifier}!{_caps}!({_identifier}\.)?{_identifier} %x value %option noyywrap @@ -145,6 +156,96 @@ _string {_char}+|("\""([^\"]|"\\\"")*"\"") return BCONNECTION; } +{_fconnection} { + gchar *d1, *d2, *q1, *q2, *a1, *m1; + gchar *mime; + GstProps *props; + + lvalp->c = g_new0 (connection_t, 1); + PRINT ("An fconnection: %s\n", yytext); + q1 = strchr (yytext, '!'); + d1 = strchr (yytext, '.'); + q2 = strchr (q1+1, '!'); + d2 = strchr (q2, '.'); + if (d1 && d1 < q1) { + lvalp->c->src_name = g_strndup (yytext, d1 - yytext); + lvalp->c->src_pads = g_list_append (lvalp->c->src_pads, g_strndup (d1 + 1, q1 - d1 - 1)); + } else { + lvalp->c->src_pads = g_list_append (lvalp->c->src_pads, g_strndup (yytext, q1 - yytext)); + } + + if (d2) { + lvalp->c->sink_name = g_strndup (q2 + 1, d2 - q2 - 1); + lvalp->c->sink_pads = g_list_append (lvalp->c->sink_pads, g_strdup (d2 + 1)); + } else { + lvalp->c->sink_pads = g_list_append (lvalp->c->sink_pads, g_strdup (q2 + 1)); + } + /* parse mime type */ + m1 = strchr (q1 + 1, ','); + mime = g_strndup (q1 + 1, m1 - q1 - 1); + + props = gst_props_empty_new (); + + a1 = strchr (m1 + 1, ','); + if (a1 == NULL) + a1 = q2; + + while (a1 && a1 <= q2) { + gchar *key, *t, *v; + gchar *k1, *k2; + GstPropsEntry *entry = NULL; + + k1 = strchr (m1, '='); + key = g_strstrip (g_strndup (m1 + 1, k1 - m1 -1)); + + k1++; + + while (g_ascii_isspace (*k1)) k1++; + + k2 = strchr (k1, ' '); + t = g_strstrip (g_strndup (k1, k2 - k1)); + + while (g_ascii_isspace (*k2)) k2++; + + v = g_strstrip (g_strndup (k2, a1 - k2)); + + if (!strcmp (t, "string")) { + entry = gst_props_entry_new (key, GST_PROPS_STRING (v)); + } + else if (!strcmp (t, "fourcc")) { + entry = gst_props_entry_new (key, GST_PROPS_FOURCC (GST_STR_FOURCC(v))); + } + else if (!strcmp (t, "float")) { + gfloat f; + sscanf (v, "%f", &f); + entry = gst_props_entry_new (key, GST_PROPS_FLOAT (f)); + } + else if (!strcmp (t, "int")) { + gint i; + sscanf (v, "%d", &i); + entry = gst_props_entry_new (key, GST_PROPS_INT (i)); + } + else if (!strcmp (t, "boolean")) { + gboolean b; + b = (!strcmp (v, "true") || ! strcmp (v, "TRUE")); + entry = gst_props_entry_new (key, GST_PROPS_BOOLEAN (b)); + } + gst_props_add_entry (props, entry); + + m1 = a1; + if (a1 < q2) { + a1 = strchr (m1 + 1, ','); + if (a1 == NULL) + a1 = q2; + } + else + break; + } + lvalp->c->caps = gst_caps_new ("parse_caps", mime, props); + + return FCONNECTION; +} + {_identifier} { PRINT ("An identifier: %s\n", yytext); lvalp->s = g_strdup (yytext); diff --git a/gst/parse/types.h b/gst/parse/types.h index 149921f835..68f80e8a67 100644 --- a/gst/parse/types.h +++ b/gst/parse/types.h @@ -23,6 +23,7 @@ typedef struct { int sink_index; GList *src_pads; GList *sink_pads; + GstCaps *caps; } connection_t; typedef struct _graph_t graph_t;