Add fixate stuff. Fix a few prototypes. Change caps strings to a different, more parseable format. Fix elements.

Original commit message from CVS:
Add fixate stuff. Fix a few prototypes. Change caps strings to a
different, more parseable format.  Fix elements.
This commit is contained in:
David Schleef 2003-12-02 18:45:10 +00:00
parent f84d9ae2da
commit 2197234a09
17 changed files with 390 additions and 183 deletions

2
common

@ -1 +1 @@
Subproject commit 2c2bce01ed5ed1d1684bd76a334477398009ef4a
Subproject commit b5288e8215c6eacf0782880f6c5b6dea8f445a34

View file

@ -74,7 +74,7 @@ static void gst_spider_identity_init (GstSpiderIdentity *spider_identity);
static void gst_spider_identity_chain (GstPad *pad, GstBuffer *buf);
static GstElementStateReturn gst_spider_identity_change_state (GstElement *element);
static GstPadLinkReturn gst_spider_identity_link (GstPad *pad, const GstCaps2 *caps);
static GstCaps2 * gst_spider_identity_getcaps (GstPad *pad, const GstCaps2 *caps);
static GstCaps2 * gst_spider_identity_getcaps (GstPad *pad);
/* loop functions */
static void gst_spider_identity_dumb_loop (GstSpiderIdentity *ident);
static void gst_spider_identity_src_loop (GstSpiderIdentity *ident);
@ -244,7 +244,7 @@ gst_spider_identity_link (GstPad *pad, const GstCaps2 *caps)
}
static GstCaps2*
gst_spider_identity_getcaps (GstPad *pad, const GstCaps2 *caps)
gst_spider_identity_getcaps (GstPad *pad)
{
GstSpiderIdentity *spider_identity = GST_SPIDER_IDENTITY (gst_pad_get_parent (pad));
GstPad *otherpad;

View file

@ -163,7 +163,7 @@ gst_identity_get_bufferpool (GstPad *pad)
}
static GstCaps2*
gst_identity_getcaps (GstPad *pad, const GstCaps2 *caps)
gst_identity_getcaps (GstPad *pad)
{
GstIdentity *identity;
GstPad *otherpad;

View file

@ -181,7 +181,7 @@ gst_shaper_get_bufferpool (GstPad *pad)
}
static GstCaps2*
gst_shaper_getcaps (GstPad *pad, const GstCaps2 *caps)
gst_shaper_getcaps (GstPad *pad)
{
GstPad *otherpad;
GstShaperConnection *connection;

View file

@ -182,7 +182,7 @@ gst_tee_srclink (GstPad *pad, const GstCaps2 *caps)
}
static GstCaps2*
gst_tee_getcaps (GstPad *pad, const GstCaps2 *filter)
gst_tee_getcaps (GstPad *pad)
{
GstCaps2 *caps = GST_CAPS2_ANY;
GstTee *tee;

View file

@ -188,6 +188,10 @@ const GstCaps2 *gst_static_caps2_get (GstStaticCaps2 *static_caps)
caps->type = _gst_caps2_type;
caps->structs = g_ptr_array_new();
_gst_caps2_from_string_inplace (caps, static_caps->string);
if (caps->type == 0) {
g_critical ("Could not convert static caps \"%s\"", static_caps->string);
}
}
return caps;
@ -225,6 +229,13 @@ GstCaps2 *gst_caps2_split_one (GstCaps2 *caps)
return NULL;
}
int gst_caps2_get_n_structures (const GstCaps2 *caps)
{
g_return_val_if_fail (caps != NULL, 0);
return caps->structs->len;
}
GstStructure *gst_caps2_get_nth_cap (const GstCaps2 *caps, int index)
{
g_return_val_if_fail (caps != NULL, NULL);
@ -337,7 +348,7 @@ static gboolean _gst_cap_is_always_compatible (const GstStructure *struct1,
return TRUE;
}
static gboolean _gst_caps_cap_is_always_compatible (const GstStructure
static gboolean _gst_caps2_cap_is_always_compatible (const GstStructure
*struct1, const GstCaps2 *caps2)
{
int i;
@ -361,7 +372,7 @@ gboolean gst_caps2_is_always_compatible (const GstCaps2 *caps1,
for(i=0;i<caps1->structs->len;i++) {
GstStructure *struct1 = gst_caps2_get_nth_cap (caps1, i);
if (_gst_caps_cap_is_always_compatible(struct1, caps2) == FALSE){
if (_gst_caps2_cap_is_always_compatible(struct1, caps2) == FALSE){
return FALSE;
}
@ -649,3 +660,100 @@ static gpointer _gst_caps2_value_peek_pointer (const GValue *value)
return value->data[0].v_pointer;
}
/* fixate utility functions */
gboolean gst_caps2_structure_fixate_field_nearest_int (GstStructure *structure,
const char *field_name, int target)
{
const GValue *value;
g_return_val_if_fail(gst_structure_has_field (structure, field_name), FALSE);
value = gst_structure_get_value (structure, field_name);
if (G_VALUE_TYPE (value) == G_TYPE_INT) {
/* already fixed */
return FALSE;
} else if (G_VALUE_TYPE (value) == GST_TYPE_INT_RANGE) {
int x;
x = gst_value_get_int_range_min (value);
if (target < x) target = x;
x = gst_value_get_int_range_max (value);
if (target > x) target = x;
gst_structure_set (structure, field_name, G_TYPE_INT, target, NULL);
return TRUE;
} else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
const GValue *list_value;
int i, n;
int best = 0;
int best_index = -1;
n = gst_value_list_get_size (value);
for(i=0;i<n;i++){
list_value = gst_value_list_get_value (value, i);
if (G_VALUE_TYPE (list_value) == G_TYPE_INT) {
int x = g_value_get_int (list_value);
if (best_index == -1 || (ABS(target-x) < ABS(best-x))) {
best_index = i;
best = x;
}
}
}
if(best_index != -1) {
gst_structure_set (structure, field_name, G_TYPE_INT, best, NULL);
return TRUE;
}
return FALSE;
}
return FALSE;
}
gboolean gst_caps2_structure_fixate_field_nearest_double (GstStructure
*structure, const char *field_name, double target)
{
const GValue *value;
g_return_val_if_fail(gst_structure_has_field (structure, field_name), FALSE);
value = gst_structure_get_value (structure, field_name);
if (G_VALUE_TYPE (value) == G_TYPE_DOUBLE) {
/* already fixed */
return FALSE;
} else if (G_VALUE_TYPE (value) == GST_TYPE_DOUBLE_RANGE) {
double x;
x = gst_value_get_double_range_min (value);
if (target < x) target = x;
x = gst_value_get_double_range_max (value);
if (target > x) target = x;
gst_structure_set (structure, field_name, G_TYPE_DOUBLE, target, NULL);
return TRUE;
} else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
const GValue *list_value;
int i, n;
double best = 0;
int best_index = -1;
n = gst_value_list_get_size (value);
for(i=0;i<n;i++){
list_value = gst_value_list_get_value (value, i);
if (G_VALUE_TYPE (list_value) == G_TYPE_DOUBLE) {
double x = g_value_get_double (list_value);
if (best_index == -1 || (ABS(target-x) < ABS(best-x))) {
best_index = i;
best = x;
}
}
}
if(best_index != -1) {
gst_structure_set (structure, field_name, G_TYPE_DOUBLE, best, NULL);
return TRUE;
}
return FALSE;
}
return FALSE;
}

View file

@ -75,6 +75,7 @@ G_CONST_RETURN GstCaps2 *gst_static_caps2_get (GstStaticCaps2 *caps);
void gst_caps2_append (GstCaps2 *caps1, GstCaps2 *caps2);
void gst_caps2_append_cap (GstCaps2 *caps1, GstStructure *structure);
GstCaps2 *gst_caps2_split_one (GstCaps2 *caps);
int gst_caps2_get_n_structures (const GstCaps2 *caps);
GstStructure *gst_caps2_get_nth_cap (const GstCaps2 *caps, int index);
GstCaps2 *gst_caps2_copy_1 (const GstCaps2 *caps);
@ -102,6 +103,11 @@ gchar *gst_caps2_to_string (const GstCaps2 *caps);
GstCaps2 *gst_caps2_from_string (const gchar *string);
void gst_caps2_debug (const GstCaps2 *caps, const gchar *string);
gboolean gst_caps2_structure_fixate_field_nearest_int (GstStructure *structure,
const char *field_name, int target);
gboolean gst_caps2_structure_fixate_field_nearest_double (GstStructure
*structure, const char *field_name, double target);
G_END_DECLS

View file

@ -1875,7 +1875,7 @@ gst_pad_get_caps (GstPad *pad)
GstCaps2 *caps;
GST_CAT_DEBUG (GST_CAT_CAPS, "using pad get function");
caps = GST_RPAD_GETCAPSFUNC (realpad) (GST_PAD_CAST (realpad), NULL);
caps = GST_RPAD_GETCAPSFUNC (realpad) (GST_PAD_CAST (realpad));
/* FIXME */
if (caps == NULL) {

View file

@ -149,7 +149,8 @@ typedef const GstQueryType* (*GstPadQueryTypeFunction) (GstPad *pad);
typedef GstPadLinkReturn (*GstPadLinkFunction) (GstPad *pad, const GstCaps2 *caps);
typedef void (*GstPadUnlinkFunction) (GstPad *pad);
typedef GstCaps2* (*GstPadGetCapsFunction) (GstPad *pad, const GstCaps2 *caps);
typedef GstCaps2* (*GstPadGetCapsFunction) (GstPad *pad);
typedef GstCaps2* (*GstPadFixateFunction) (GstPad *pad, const GstCaps2 *caps, gpointer user_data);
typedef GstBufferPool* (*GstPadBufferPoolFunction) (GstPad *pad);
typedef gboolean (*GstPadDispatcherFunction) (GstPad *pad, gpointer data);
@ -191,6 +192,7 @@ struct _GstRealPad {
GstCaps2 *filter;
GstCaps2 *appfilter;
GstPadGetCapsFunction getcapsfunc;
GstPadFixateFunction fixatefunc;
GstPadDirection direction;
@ -479,6 +481,7 @@ GstPadLinkReturn gst_pad_try_set_caps (GstPad *pad, const GstCaps2 *caps);
gboolean gst_pad_check_compatibility (GstPad *srcpad, GstPad *sinkpad);
void gst_pad_set_getcaps_function (GstPad *pad, GstPadGetCapsFunction getcaps);
void gst_pad_set_fixate_function (GstPad *pad, GstPadFixateFunction fixate);
GstPadLinkReturn gst_pad_proxy_link (GstPad *pad, const GstCaps2 *caps);
gboolean gst_pad_relink_filtered (GstPad *srcpad, GstPad *sinkpad, const GstCaps2 *filtercaps);
gboolean gst_pad_perform_negotiate (GstPad *srcpad, GstPad *sinkpad);

View file

@ -192,7 +192,7 @@ gst_queue_link (GstPad *pad, const GstCaps2 *caps)
}
static GstCaps2 *
gst_queue_getcaps (GstPad *pad, const GstCaps2 *caps)
gst_queue_getcaps (GstPad *pad)
{
GstQueue *queue = GST_QUEUE (gst_pad_get_parent (pad));
GstPad *otherpad;

View file

@ -249,7 +249,7 @@ void gst_structure_free(GstStructure *structure)
*
* Returns: the name of the structure.
*/
const gchar *gst_structure_get_name(GstStructure *structure)
const gchar *gst_structure_get_name(const GstStructure *structure)
{
g_return_val_if_fail(structure != NULL, NULL);
@ -341,7 +341,7 @@ void gst_structure_set(GstStructure *structure, const gchar *field, ...)
}
/**
* gst_structure_set:
* gst_structure_set_valist:
* @structure: a #GstStructure
* @field: the name of the field to set
* @varargs: variable arguments
@ -926,6 +926,59 @@ static const char *_gst_structure_to_abbr(GType type)
return g_type_name(type);
}
#define GST_ASCII_IS_STRING(c) (g_ascii_isalnum((c)) || ((c) == '_') || \
((c) == '-') || ((c) == '+') || ((c) == '/') || ((c) == ':') || \
((c) == '.'))
static gchar *
_gst_structure_wrap_string(gchar *s)
{
gchar *t;
int len;
gchar *d, *e;
gboolean wrap = FALSE;
len = 0;
t = s;
while (*t) {
if(GST_ASCII_IS_STRING(*t)) {
len++;
} else if(*t < 0x20 || *t >= 0x7f) {
wrap = TRUE;
len += 4;
} else {
wrap = TRUE;
len += 2;
}
t++;
}
if (!wrap) return s;
e = d = g_malloc(len + 3);
*e++ = '\"';
t = s;
while (*t) {
if(GST_ASCII_IS_STRING(*t)) {
*e++ = *t++;
} else if(*t < 0x20 || *t >= 0x7f) {
*e++ = '\\';
*e++ = '0' + ((*t)>>6);
*e++ = '0' + (((*t)>>3)&0x7);
*e++ = '0' + ((*t++)&0x7);
} else {
*e++ = '\\';
*e++ = *t++;
}
}
*e++ = '\"';
*e = 0;
g_free(s);
return d;
}
/**
* gst_structure_to_string:
* @structure: a #GstStructure
@ -939,13 +992,15 @@ gst_structure_to_string(const GstStructure *structure)
{
GstStructureField *field;
GString *s;
char *t;
int i;
g_return_val_if_fail(structure != NULL, NULL);
s = g_string_new("");
g_string_append_printf(s, "\"%s\"", g_quark_to_string(structure->name));
for(i=0;i<structure->fields->len;i++){
/* FIXME this string may need to be escaped */
g_string_append_printf(s, "%s", g_quark_to_string(structure->name));
for(i=0;i<structure->fields->len;i++) {
GValue s_val = { 0 };
GType type;
@ -957,21 +1012,30 @@ gst_structure_to_string(const GstStructure *structure)
type = G_VALUE_TYPE (&field->value);
if (type == GST_TYPE_LIST) {
GPtrArray *ptr_array = g_value_peek_pointer (&field->value);
if (ptr_array->len > 0){
GValue *value = g_ptr_array_index (ptr_array, 0);
GArray *array = g_value_peek_pointer (&field->value);
if (array->len > 0){
GValue *value = &g_array_index (array, GValue, 0);
type = G_VALUE_TYPE (value);
} else {
type = G_TYPE_INT;
}
t = g_strdup(g_value_get_string(&s_val));
} else if (G_VALUE_TYPE(&field->value) == GST_TYPE_INT_RANGE) {
type = G_TYPE_INT;
t = g_strdup(g_value_get_string(&s_val));
} else if (G_VALUE_TYPE(&field->value) == GST_TYPE_DOUBLE_RANGE) {
type = G_TYPE_DOUBLE;
t = g_strdup(g_value_get_string(&s_val));
} else {
t = _gst_structure_wrap_string(g_strdup(g_value_get_string(&s_val)));
}
g_string_append_printf(s, ", %s:%s=%s", g_quark_to_string(field->name),
_gst_structure_to_abbr(type), g_value_get_string(&s_val));
g_print("appending: %s=(%s)%s\n", g_quark_to_string(field->name),
_gst_structure_to_abbr(type), t);
g_string_append_printf(s, ", %s=(%s)%s", g_quark_to_string(field->name),
_gst_structure_to_abbr(type), t);
g_free(t);
g_value_unset (&s_val);
}
return g_string_free(s, FALSE);
@ -984,86 +1048,59 @@ gst_structure_to_string(const GstStructure *structure)
* unread data.
* THIS FUNCTION MODIFIES THE STRING AND DETECTS INSIDE A NONTERMINATED STRING
*/
static gboolean _gst_structure_parse_simple_string (gchar *s, gchar **end);
static gboolean
_gst_structure_parse_string (gchar *r, gchar **end, gchar **next)
_gst_structure_parse_string (gchar *s, gchar **end, gchar **next)
{
gchar *w;
gchar c = '\0';
w = r;
if (*r == '\'' || *r == '\"') {
c = *r;
r++;
if (*s == 0) return FALSE;
if (*s != '"') {
int ret;
ret = _gst_structure_parse_simple_string (s, end);
*next = *end;
return ret;
}
for (;;r++) {
if (*r == '\0') {
if (c) {
goto error;
} else {
goto found;
}
w = s;
s++;
while (*s != '"') {
if (*s == 0) return FALSE;
if (*s == '\\') {
s++;
}
if (*r == '\\') {
r++;
if (*r == '\0')
goto error;
*w++ = *r;
continue;
}
if (*r == c) {
r++;
if (*r == '\0')
goto found;
break;
}
if (!c) {
if (g_ascii_isspace (*r))
break;
/* this needs to be escaped */
if (*r == ',' || *r == ')' || *r == ']' || *r == ':' ||
*r == ';' || *r == '(' || *r == '[')
break;
}
*w++ = *r;
*w = *s;
w++;
s++;
}
s++;
found:
while (g_ascii_isspace (*r)) r++;
if (w != r)
*w++ = '\0';
*end = w;
*next = r;
return TRUE;
*next = s;
error:
return FALSE;
return TRUE;
}
static gboolean
_gst_structure_parse_value (gchar *s, gchar **after, GType type,
GValue *value)
gst_value_from_string (GValue *value, const char *s)
{
gboolean ret = FALSE;
gchar *val;
gchar *end;
GType type = G_VALUE_TYPE (value);
if (type == G_TYPE_INVALID) return FALSE;
while (g_ascii_isspace (*s)) s++;
g_value_init(value, type);
val = s;
switch (type) {
case G_TYPE_INT:
{
int x;
x = strtol (val, &s, 0);
if (val != s) {
x = strtol (s, &end, 0);
if (*end == 0) {
g_value_set_int (value, x);
ret = TRUE;
}
@ -1072,8 +1109,8 @@ _gst_structure_parse_value (gchar *s, gchar **after, GType type,
case G_TYPE_FLOAT:
{
double x;
x = g_ascii_strtod (val, &s);
if (val != s) {
x = g_ascii_strtod (s, &end);
if (*end == 0) {
g_value_set_float (value, x);
ret = TRUE;
}
@ -1082,8 +1119,8 @@ _gst_structure_parse_value (gchar *s, gchar **after, GType type,
case G_TYPE_DOUBLE:
{
double x;
x = g_ascii_strtod (val, &s);
if (val != s) {
x = g_ascii_strtod (s, &end);
if (*end == 0) {
g_value_set_double (value, x);
ret = TRUE;
}
@ -1091,51 +1128,37 @@ _gst_structure_parse_value (gchar *s, gchar **after, GType type,
break;
case G_TYPE_BOOLEAN:
{
int len;
ret = _gst_structure_parse_string (val, &end, &s);
len = end - val;
if (ret && len > 0) {
if (g_ascii_strncasecmp (val, "true", len) == 0 ||
g_ascii_strncasecmp (val, "yes", len) == 0 ||
g_ascii_strncasecmp (val, "t", len) == 0 ||
strncmp (val, "1", len)) {
g_value_set_boolean (value, TRUE);
} else if (g_ascii_strncasecmp (val, "false", len) == 0 ||
g_ascii_strncasecmp (val, "no", len) == 0 ||
g_ascii_strncasecmp (val, "f", len) == 0 ||
strncmp (val, "0", len)) {
g_value_set_boolean (value, FALSE);
} else {
ret = FALSE;
}
if (g_ascii_strcasecmp (s, "true") == 0 ||
g_ascii_strcasecmp (s, "yes") == 0 ||
g_ascii_strcasecmp (s, "t") == 0 ||
strcmp (s, "1") == 0) {
g_value_set_boolean (value, TRUE);
ret = TRUE;
} else if (g_ascii_strcasecmp (s, "false") == 0 ||
g_ascii_strcasecmp (s, "no") == 0 ||
g_ascii_strcasecmp (s, "f") == 0 ||
strcmp (s, "0") == 0) {
g_value_set_boolean (value, FALSE);
ret = TRUE;
}
}
break;
case G_TYPE_STRING:
{
ret = _gst_structure_parse_string (val, &end, &s);
if (ret) {
g_value_set_string_take_ownership (value,
g_strndup(val, end - val));
ret = TRUE;
}
g_value_set_string (value, s);
ret = TRUE;
}
break;
default:
/* FIXME: make more general */
if (type == GST_TYPE_FOURCC) {
guint32 fourcc = 0;
if (g_ascii_isdigit (*s)) {
fourcc = strtoul (val, &s, 0);
if (val != s) {
ret = TRUE;
}
} else {
ret = _gst_structure_parse_string (val, &end, &s);
g_print("end - val = %d\n", end - val);
if (end - val >= 4) {
fourcc = GST_MAKE_FOURCC(val[0], val[1], val[2], val[3]);
if (strlen(s) == 4) {
fourcc = GST_MAKE_FOURCC(s[0], s[1], s[2], s[3]);
ret = TRUE;
} else if (g_ascii_isdigit (*s)) {
fourcc = strtoul (s, &end, 0);
if (*end == 0) {
ret = TRUE;
}
}
@ -1146,34 +1169,28 @@ g_print("end - val = %d\n", end - val);
break;
}
*after = s;
return ret;
}
static gboolean _gst_structure_parse_value (gchar *str, gchar **after,
GValue *value, GType default_type);
static gboolean
_gst_structure_parse_range (gchar *s, gchar **after, GType type,
GValue *value)
_gst_structure_parse_range (gchar *s, gchar **after, GValue *value, GType type)
{
GValue value1 = { 0 };
GValue value2 = { 0 };
GType range_type;
gboolean ret;
if (type == G_TYPE_DOUBLE) {
range_type = GST_TYPE_DOUBLE_RANGE;
} else if (type == G_TYPE_INT) {
range_type = GST_TYPE_INT_RANGE;
} else {
return FALSE;
}
g_print("parse_range: \"%s\"\n", s);
g_print("%d \"%s\"\n", __LINE__, s);
if (*s != '[') return FALSE;
s++;
g_print("%d \"%s\"\n", __LINE__, s);
ret = _gst_structure_parse_value(s, &s, type, &value1);
ret = _gst_structure_parse_value(s, &s, &value1, type);
if (ret == FALSE) return FALSE;
while (g_ascii_isspace (*s)) s++;
@ -1185,7 +1202,7 @@ g_print("%d \"%s\"\n", __LINE__, s);
while (g_ascii_isspace (*s)) s++;
g_print("%d \"%s\"\n", __LINE__, s);
ret = _gst_structure_parse_value(s, &s, type, &value2);
ret = _gst_structure_parse_value(s, &s, &value2, type);
if (ret == FALSE) return FALSE;
while (g_ascii_isspace (*s)) s++;
@ -1194,6 +1211,19 @@ g_print("%d \"%s\"\n", __LINE__, s);
if (*s != ']') return FALSE;
s++;
g_print("type1 %s type2 %s\n", g_type_name(G_VALUE_TYPE(&value1)),
g_type_name(G_VALUE_TYPE(&value2)));
if (G_VALUE_TYPE (&value1) != G_VALUE_TYPE (&value2)) return FALSE;
if (G_VALUE_TYPE (&value1) == G_TYPE_DOUBLE) {
range_type = GST_TYPE_DOUBLE_RANGE;
} else if (G_VALUE_TYPE (&value1) == G_TYPE_INT) {
range_type = GST_TYPE_INT_RANGE;
} else {
return FALSE;
}
g_value_init(value, range_type);
if (range_type == GST_TYPE_DOUBLE_RANGE) {
gst_value_set_double_range(value, g_value_get_double(&value1),
@ -1208,38 +1238,44 @@ g_print("%d \"%s\"\n", __LINE__, s);
}
static gboolean
_gst_structure_parse_list (gchar *s, gchar **after, GType type, GValue *value)
_gst_structure_parse_list (gchar *s, gchar **after, GValue *value, GType type)
{
GValue list_value = { 0 };
gboolean ret;
GArray *array;
g_print("parse_list: \"%s\"\n", s);
g_value_init(value, GST_TYPE_LIST);
array = g_value_peek_pointer (value);
if (*s != '(') return FALSE;
if (*s != '{') return FALSE;
s++;
while (g_ascii_isspace (*s)) s++;
if (*s == ')') {
if (*s == '}') {
s++;
*after = s;
return TRUE;
}
ret = _gst_structure_parse_value(s, &s, type, &list_value);
ret = _gst_structure_parse_value(s, &s, &list_value, type);
if (ret == FALSE) return FALSE;
g_array_append_val (array, list_value);
while (g_ascii_isspace (*s)) s++;
while (*s != ')') {
while (*s != '}') {
if (*s != ',') return FALSE;
s++;
while (g_ascii_isspace (*s)) s++;
memset (&list_value, 0, sizeof (list_value));
ret = _gst_structure_parse_value(s, &s, type, &list_value);
ret = _gst_structure_parse_value(s, &s, &list_value, type);
if (ret == FALSE) return FALSE;
g_array_append_val (array, list_value);
while (g_ascii_isspace (*s)) s++;
}
@ -1249,68 +1285,122 @@ _gst_structure_parse_list (gchar *s, gchar **after, GType type, GValue *value)
return TRUE;
}
static gboolean
_gst_structure_parse_simple_string (gchar *str, gchar **end)
{
char *s = str;
while(GST_ASCII_IS_STRING(*s)){
s++;
}
*end = s;
return (s != str);
}
static gboolean
_gst_structure_parse_field (gchar *str, gchar **after, GstStructureField *field)
{
/* NAME[:TYPE]=VALUE */
gchar *name;
gchar *type_name;
gchar *s, *del;
gboolean have_type = FALSE;
GType type = G_TYPE_INVALID;
int ret;
gchar *name_end;
gchar *s;
gchar c;
g_print("parsing: \"%s\"\n", str);
name = s = str;
while (g_ascii_isalnum (*s) || *s == '_' || *s == '-') s++;
del = s;
while (g_ascii_isspace (*s)) s++;
if (!(*s == '=' || *s == ':')) return FALSE;
if (*s == ':') have_type = TRUE;
g_print("parse_field: \"%s\"\n", str);
s = str;
while(g_ascii_isspace (*s)) s++;
name = s;
if (!_gst_structure_parse_simple_string (s, &name_end)) return FALSE;
s = name_end;
while(g_ascii_isspace (*s)) s++;
if (*s != '=') return FALSE;
s++;
while (g_ascii_isspace (*s)) s++;
*del = '\0';
c = *name_end;
*name_end = 0;
field->name = g_quark_from_string (name);
*name_end = c;
if (!_gst_structure_parse_value (s, &s, &field->value, G_TYPE_INVALID))
return FALSE;
*after = s;
return TRUE;
}
static gboolean
_gst_structure_parse_value (gchar *str, gchar **after, GValue *value,
GType default_type)
{
gchar *type_name;
gchar *type_end;
gchar *value_s;
gchar *value_end;
gchar *s;
gchar c;
int ret;
GType type = default_type;
g_print("parse_value: \"%s\"\n", str);
s = str;
while(g_ascii_isspace (*s)) s++;
type_name = NULL;
if (*s == '(') {
type = G_TYPE_INVALID;
if (have_type) {
while (g_ascii_isspace (*s)) s++;
type_name = s;
while (g_ascii_isalnum (*s) || *s == '_' || *s == '-') s++;
del = s;
while (g_ascii_isspace (*s)) s++;
if (*s != '=') return FALSE;
s++;
while (g_ascii_isspace (*s)) s++;
*del = '\0';
while(g_ascii_isspace (*s)) s++;
type_name = s;
if (!_gst_structure_parse_simple_string (s, &type_end)) return FALSE;
s = type_end;
while(g_ascii_isspace (*s)) s++;
if (*s != ')') return FALSE;
s++;
while(g_ascii_isspace (*s)) s++;
c = *type_end;
*type_end = 0;
g_print("type name is \"%s\"\n",type_name);
type = _gst_structure_from_abbr(type_name);
g_print("type n is \"%s\"\n",g_type_name(type));
*type_end = c;
if (type == G_TYPE_INVALID) return FALSE;
} else {
if (g_ascii_isdigit (*s) ||
((*s == '-' || *s == '+') && g_ascii_isdigit (s[1]))) {
char *t = s;
while (g_ascii_isdigit (*t)) t++;
if (*t == '.'){
type = G_TYPE_DOUBLE;
} else {
type = G_TYPE_INT;
}
} else if (g_ascii_isalpha (*s) || *s == '"' || *s == '\'') {
type = G_TYPE_STRING;
}
}
while(g_ascii_isspace (*s)) s++;
if (*s == '[') {
ret = _gst_structure_parse_range (s, &s, type, &field->value);
} else if (*s == '(') {
ret = _gst_structure_parse_list (s, &s, type, &field->value);
ret = _gst_structure_parse_range (s, &s, value, type);
} else if (*s == '{') {
ret = _gst_structure_parse_list (s, &s, value, type);
} else {
ret = _gst_structure_parse_value(s, &s, type, &field->value);
value_s = s;
if (!_gst_structure_parse_string (s, &value_end, &s)) return FALSE;
c = *value_end;
*value_end = 0;
if (type == G_TYPE_INVALID) {
GType try_types[] = { G_TYPE_INT, G_TYPE_DOUBLE, G_TYPE_STRING };
int i;
for(i=0;i<3;i++) {
g_value_init(value, try_types[i]);
ret = gst_value_from_string (value, value_s);
if (ret) break;
g_value_unset(value);
}
} else {
g_value_init(value, type);
ret = gst_value_from_string (value, value_s);
}
*value_end = c;
}
*after = s;

View file

@ -59,7 +59,7 @@ GstStructure *gst_structure_new_valist(const gchar *name,
GstStructure *gst_structure_copy(GstStructure *structure);
void gst_structure_free(GstStructure *structure);
G_CONST_RETURN gchar *gst_structure_get_name(GstStructure *structure);
G_CONST_RETURN gchar *gst_structure_get_name(const GstStructure *structure);
void gst_structure_set_name(GstStructure *structure, const gchar *name);
void gst_structure_set_field_copy (GstStructure *structure,
const GstStructureField *field);

View file

@ -469,7 +469,7 @@ gst_value_transform_fourcc_string (const GValue *src_value,
g_ascii_isprint ((fourcc>>16) & 0xff) &&
g_ascii_isprint ((fourcc>>24) & 0xff)){
dest_value->data[0].v_pointer = g_strdup_printf(
"\"" GST_FOURCC_FORMAT "\"", GST_FOURCC_ARGS(fourcc));
GST_FOURCC_FORMAT, GST_FOURCC_ARGS(fourcc));
} else {
dest_value->data[0].v_pointer = g_strdup_printf("0x%08x", fourcc);
}
@ -503,7 +503,7 @@ gst_value_transform_list_string (const GValue *src_value,
array = src_value->data[0].v_pointer;
s = g_string_new("(");
s = g_string_new("{ ");
for(i=0;i<array->len;i++){
list_value = &g_array_index(array, GValue, i);
@ -514,7 +514,7 @@ gst_value_transform_list_string (const GValue *src_value,
g_string_append (s, list_s);
g_free (list_s);
}
g_string_append (s, ")");
g_string_append (s, " }");
dest_value->data[0].v_pointer = g_string_free (s, FALSE);
}

View file

@ -163,7 +163,7 @@ gst_identity_get_bufferpool (GstPad *pad)
}
static GstCaps2*
gst_identity_getcaps (GstPad *pad, const GstCaps2 *caps)
gst_identity_getcaps (GstPad *pad)
{
GstIdentity *identity;
GstPad *otherpad;

View file

@ -192,7 +192,7 @@ gst_queue_link (GstPad *pad, const GstCaps2 *caps)
}
static GstCaps2 *
gst_queue_getcaps (GstPad *pad, const GstCaps2 *caps)
gst_queue_getcaps (GstPad *pad)
{
GstQueue *queue = GST_QUEUE (gst_pad_get_parent (pad));
GstPad *otherpad;

View file

@ -181,7 +181,7 @@ gst_shaper_get_bufferpool (GstPad *pad)
}
static GstCaps2*
gst_shaper_getcaps (GstPad *pad, const GstCaps2 *caps)
gst_shaper_getcaps (GstPad *pad)
{
GstPad *otherpad;
GstShaperConnection *connection;

View file

@ -182,7 +182,7 @@ gst_tee_srclink (GstPad *pad, const GstCaps2 *caps)
}
static GstCaps2*
gst_tee_getcaps (GstPad *pad, const GstCaps2 *filter)
gst_tee_getcaps (GstPad *pad)
{
GstCaps2 *caps = GST_CAPS2_ANY;
GstTee *tee;