gststructure.c 32.6 KB
Newer Older
David Schleef's avatar
David Schleef committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* GStreamer
 * Copyright (C) 2003 David A. Schleef <ds@schleef.org>
 *
 * gststructure.c: lists of { GQuark, GValue } tuples
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <string.h>

#include <gst/gst.h>
#include <gobject/gvaluecollector.h>

static GType _gst_structure_type;

David Schleef's avatar
David Schleef committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
typedef struct _GstStructureField GstStructureField;
struct _GstStructureField {
  GQuark name;
  GValue value;
};

#define GST_STRUCTURE_FIELD(structure, index) \
    &g_array_index((structure)->fields, GstStructureField, (index))

static void gst_structure_set_field (GstStructure *structure,
    GstStructureField *field);
static GstStructureField *gst_structure_get_field(const GstStructure *structure,
        const gchar *fieldname);
static GstStructureField *gst_structure_id_get_field(const GstStructure *structure,
        GQuark fieldname);

David Schleef's avatar
David Schleef committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
static void _gst_structure_transform_to_string(const GValue *src_value,
    GValue *dest_value);

static void _gst_structure_value_init (GValue *value);
static void _gst_structure_value_free (GValue *value);
static void _gst_structure_value_copy (const GValue *src, GValue *dest);
static gpointer _gst_structure_value_peek_pointer (const GValue *value);


GType gst_structure_get_type(void)
{
  return _gst_structure_type;
}

void _gst_structure_initialize(void)
{
Benjamin Otte's avatar
Benjamin Otte committed
65
  static const GTypeValueTable type_value_table = {
David Schleef's avatar
David Schleef committed
66
67
68
69
70
71
72
73
74
    _gst_structure_value_init,
    _gst_structure_value_free,
    _gst_structure_value_copy,
    _gst_structure_value_peek_pointer,
    NULL,
    NULL,
    NULL,
    NULL,
  };
Benjamin Otte's avatar
Benjamin Otte committed
75
  static const GTypeInfo structure_info = {
David Schleef's avatar
David Schleef committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
    0,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    0, /* sizeof(GstStructure), */
    0,
    NULL, /* _gst_structure_init, */
    &type_value_table,
  };

  _gst_structure_type = g_type_register_static(G_TYPE_BOXED, "GstStructure",
      &structure_info, 0);
#if 0
  _gst_structure_type = g_boxed_type_register_static("GstStructure",
92
      (GBoxedCopyFunc) gst_structure_copy,
David Schleef's avatar
David Schleef committed
93
94
95
96
97
98
99
      (GBoxedFreeFunc) gst_structure_free);
#endif

  g_value_register_transform_func(_gst_structure_type, G_TYPE_STRING,
      _gst_structure_transform_to_string);
}

Benjamin Otte's avatar
Benjamin Otte committed
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
 * gst_structure_id_empty_new:
 * @name: name of new structure
 *
 * Creates a new, empty #GstStructure with the given name.
 *
 * Returns: a new, empty #GstStructure
 */
GstStructure *gst_structure_id_empty_new(GQuark quark)
{
  GstStructure *structure;

  g_return_val_if_fail(quark != 0, NULL);

  structure = g_new0(GstStructure, 1);
  structure->name = quark;
  structure->fields = g_array_new(FALSE,TRUE,sizeof(GstStructureField));

  return structure;
}

David Schleef's avatar
David Schleef committed
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/**
 * gst_structure_empty_new:
 * @name: name of new structure
 *
 * Creates a new, empty #GstStructure with the given name.
 *
 * Returns: a new, empty #GstStructure
 */
GstStructure *gst_structure_empty_new(const gchar *name)
{
  GstStructure *structure;

  g_return_val_if_fail(name != NULL, NULL);

  structure = g_new0(GstStructure, 1);
  structure->name = g_quark_from_string(name);
  structure->fields = g_array_new(FALSE,TRUE,sizeof(GstStructureField));

  return structure;
}

/**
 * gst_structure_new:
 * @name: name of new structure
 * @firstfield: name of first field to set
 * @...: additional arguments
 *
 * Creates a new #GstStructure with the given name.  Parses the
 * list of variable arguments and sets fields to the values listed.
 * Variable arguments should be passed as field name, field type,
 * and value.  Last variable argument should be NULL.
 *
 * Returns: a new #GstStructure
 */
GstStructure *gst_structure_new(const gchar *name,
    const gchar *firstfield, ...)
{
  GstStructure *structure;
  va_list varargs;

  g_return_val_if_fail(name != NULL, NULL);

  va_start(varargs, firstfield);

  structure = gst_structure_new_valist(name,firstfield,varargs);

  va_end(varargs);

  return structure;
}

/**
 * gst_structure_new_valist:
 * @name: name of new structure
 * @firstfield: name of first field to set
 * @varags: variable argument list
 *
 * Creates a new #GstStructure with the given name.  Structure fields
 * are set according to the varargs in a manner similar to
 * @gst_structure_new.
 *
 * Returns: a new #GstStructure
 */
GstStructure *gst_structure_new_valist(const gchar *name,
    const gchar *firstfield, va_list varargs)
{
  GstStructure *structure;

  g_return_val_if_fail(name != NULL, NULL);

  structure = gst_structure_empty_new(name);
  gst_structure_set_valist(structure, firstfield, varargs);

  return structure;
}

/**
198
 * gst_structure_copy:
David Schleef's avatar
David Schleef committed
199
200
201
202
203
204
 * @structure: a #GstStructure to duplicate
 *
 * Duplicates a #GstStructure and all its fields and values.
 *
 * Returns: a new #GstStructure.
 */
205
GstStructure *gst_structure_copy(GstStructure *structure)
David Schleef's avatar
David Schleef committed
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
{
  GstStructure *new_structure;
  GstStructureField *field;
  int i;

  g_return_val_if_fail(structure != NULL, NULL);

  new_structure = gst_structure_empty_new(g_quark_to_string(structure->name));
  new_structure->name = structure->name;

  for(i=0;i<structure->fields->len;i++){
    GstStructureField new_field = { 0 };

    field = GST_STRUCTURE_FIELD(structure, i);

    new_field.name = field->name;
222
    gst_value_init_and_copy (&new_field.value, &field->value);
David Schleef's avatar
David Schleef committed
223
224
225
    g_array_append_val(new_structure->fields, new_field);
  }

226
  return new_structure;
David Schleef's avatar
David Schleef committed
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
}

/**
 * gst_structure_free: 
 * @structure: the #GstStructure to free
 *
 * Frees a #GstStructure and all its fields and values.
 */
void gst_structure_free(GstStructure *structure)
{
  GstStructureField *field;
  int i;

  return;

  g_return_if_fail(structure != NULL);

  for(i=0;i<structure->fields->len;i++){
    field = GST_STRUCTURE_FIELD(structure, i);

    if(G_IS_VALUE(&field->value)){
      g_value_unset(&field->value);
    }
  }
David Schleef's avatar
David Schleef committed
251
252
253
#ifdef USE_POISONING
  memset (structure, 0xff, sizeof(GstStructure));
#endif
David Schleef's avatar
David Schleef committed
254
255
256
257
258
259
260
261
262
263
264
  g_free(structure);
}

/**
 * gst_structure_get_name:
 * @structure: a #GstStructure
 *
 * Accessor fuction.
 *
 * Returns: the name of the structure.
 */
David Schleef's avatar
David Schleef committed
265
const gchar *gst_structure_get_name(const GstStructure *structure)
David Schleef's avatar
David Schleef committed
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
{
  g_return_val_if_fail(structure != NULL, NULL);

  return g_quark_to_string(structure->name);
}

/**
 * gst_structure_set_name:
 * @structure: a #GstStructure
 * @name: the new name of the structure
 *
 * Sets the name of the structure to the given name.  The string
 * provided is copied before being used.
 */
void gst_structure_set_name(GstStructure *structure, const gchar *name)
{
  g_return_if_fail(structure != NULL);
  g_return_if_fail(name != NULL);

  structure->name = g_quark_from_string(name);
}

/**
 * gst_structure_id_set_value:
 * @structure: a #GstStructure
 * @field_id: a #GQuark representing a field
 * @value: the new value of the field
 *
 * Sets the field with the given ID to the provided value.  If the field
 * does not exist, it is created.  If the field exists, the previous
 * value is freed.
 */
void gst_structure_id_set_value(GstStructure *structure, GQuark fieldname,
Benjamin Otte's avatar
Benjamin Otte committed
299
    const GValue *value)
David Schleef's avatar
David Schleef committed
300
{
Benjamin Otte's avatar
Benjamin Otte committed
301
  GstStructureField field = { 0, { 0, } };
David Schleef's avatar
David Schleef committed
302
303
304
305
306

  g_return_if_fail(structure != NULL);
  g_return_if_fail(G_IS_VALUE(value));

  field.name = fieldname;
307
  gst_value_init_and_copy (&field.value, value);
David Schleef's avatar
David Schleef committed
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322

  gst_structure_set_field(structure, &field);
}

/**
 * gst_structure_set_value:
 * @structure: a #GstStructure
 * @field: the name of the field to set
 * @value: the new value of the field
 *
 * Sets the field with the given name to the provided value.  If the field
 * does not exist, it is created.  If the field exists, the previous
 * value is freed.
 */
void gst_structure_set_value(GstStructure *structure, const gchar *field,
Benjamin Otte's avatar
Benjamin Otte committed
323
    const GValue *value)
David Schleef's avatar
David Schleef committed
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
{
  g_return_if_fail(structure != NULL);
  g_return_if_fail(field != NULL);
  g_return_if_fail(G_IS_VALUE(value));

  gst_structure_id_set_value(structure, g_quark_from_string(field), value);
}

/**
 * gst_structure_set:
 * @structure: a #GstStructure
 * @field: the name of the field to set
 * @...: variable arguments
 *
 * Parses the variable arguments and sets fields accordingly.
 * Variable arguments should be in the form field name, field type
 * (as a GType), value.  The last variable argument should be NULL.
 */
void gst_structure_set(GstStructure *structure, const gchar *field, ...)
{
  va_list varargs;

  g_return_if_fail(structure != NULL);

  va_start(varargs, field);

  gst_structure_set_valist(structure,field,varargs);

  va_end(varargs);
}

/**
David Schleef's avatar
David Schleef committed
356
 * gst_structure_set_valist:
David Schleef's avatar
David Schleef committed
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
 * @structure: a #GstStructure
 * @field: the name of the field to set
 * @varargs: variable arguments
 *
 * va_list form of #gst_structure_set.
 */
void gst_structure_set_valist(GstStructure *structure, const gchar *fieldname,
    va_list varargs)
{
  GType type;
  int i;
  double d;
  char *s;

  g_return_if_fail(structure != NULL);

  while(fieldname){
    GstStructureField field = { 0 };

    field.name = g_quark_from_string(fieldname);

    type = va_arg (varargs, GType); 

    switch(type){
      case G_TYPE_INT:
	i = va_arg(varargs, int);
        g_value_init(&field.value, G_TYPE_INT);
        g_value_set_int(&field.value, i);
	break;
      case G_TYPE_DOUBLE:
	d = va_arg(varargs, double);
        g_value_init(&field.value, G_TYPE_DOUBLE);
        g_value_set_double(&field.value, d);
	break;
      case G_TYPE_BOOLEAN:
	i = va_arg(varargs, int);
        g_value_init(&field.value, G_TYPE_BOOLEAN);
        g_value_set_boolean(&field.value, i);
	break;
      case G_TYPE_STRING:
	s = va_arg(varargs, char *);
        g_value_init(&field.value, G_TYPE_STRING);
        g_value_set_string(&field.value, s);
	break;
      default:
Benjamin Otte's avatar
Benjamin Otte committed
402
403
404
405
	if(type == GST_TYPE_FOURCC){
	  i = va_arg(varargs, int);
	  g_value_init(&field.value, GST_TYPE_FOURCC);
	  gst_value_set_fourcc(&field.value, i);
David Schleef's avatar
David Schleef committed
406
407
408
409
410
411
412
413
414
415
416
417
418
        } else if (type == GST_TYPE_INT_RANGE){
          int min, max;
	  min = va_arg(varargs, int);
	  max = va_arg(varargs, int);
	  g_value_init(&field.value, GST_TYPE_INT_RANGE);
	  gst_value_set_int_range(&field.value, min, max);
        } else if (type == GST_TYPE_DOUBLE_RANGE){
          double min, max;
	  min = va_arg(varargs, double);
	  max = va_arg(varargs, double);
	  g_value_init(&field.value, GST_TYPE_DOUBLE_RANGE);
	  gst_value_set_double_range(&field.value, min, max);
	} else {
Benjamin Otte's avatar
Benjamin Otte committed
419
	  g_critical("unimplemented vararg field type %d\n", (int)type);
David Schleef's avatar
David Schleef committed
420
          return;
Benjamin Otte's avatar
Benjamin Otte committed
421
	}
David Schleef's avatar
David Schleef committed
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
	break;
    }

    gst_structure_set_field(structure, &field);

    fieldname = va_arg (varargs, gchar *);
  }
}

/**
 * gst_structure_set_field:
 * @structure: a #GstStructure
 * @field: the #GstStructureField to set
 *
 * Sets a field in the structure.  If the structure currently contains
 * a field with the same name, it is replaced with the provided field.
 * Otherwise, the field is added to the structure.  The field's value
 * is not deeply copied.
 *
 * This function is intended mainly for internal use.  The function
 * #gst_structure_set() is recommended instead of this one.
 */
David Schleef's avatar
David Schleef committed
444
static void gst_structure_set_field(GstStructure *structure, GstStructureField *field)
David Schleef's avatar
David Schleef committed
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
{
  GstStructureField *f;
  int i;

  for(i=0;i<structure->fields->len;i++){
    f = GST_STRUCTURE_FIELD(structure, i);

    if(f->name == field->name){
      g_value_unset(&f->value);
      memcpy(f,field,sizeof(GstStructureField));
      return;
    }
  }

  g_array_append_val(structure->fields, *field);
}

/**
 * gst_structure_id_get_field:
 * @structure: a #GstStructure
 * @field_id: the GQuark of the field to get
 *
 * Gets the specified field from the structure.  If there is no
 * field with the given ID, NULL is returned.
 *
 * Returns: the #GstStructureField with the given ID
 */
David Schleef's avatar
David Schleef committed
472
static GstStructureField *gst_structure_id_get_field(const GstStructure *structure,
David Schleef's avatar
David Schleef committed
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
    GQuark field_id)
{
  GstStructureField *field;
  int i;

  g_return_val_if_fail(structure != NULL, NULL);

  for(i=0;i<structure->fields->len;i++){
    field = GST_STRUCTURE_FIELD(structure, i);

    if(field->name == field_id) return field;
  }

  return NULL;
}

/**
 * gst_structure_get_field:
 * @structure: a #GstStructure
 * @fieldname: the name of the field to get
 *
 * Gets the specified field from the structure.  If there is no
 * field with the given ID, NULL is returned.
 *
 * Returns: the #GstStructureField with the given name
 */
David Schleef's avatar
David Schleef committed
499
static GstStructureField *
Benjamin Otte's avatar
Benjamin Otte committed
500
gst_structure_get_field(const GstStructure *structure, const gchar *fieldname)
David Schleef's avatar
David Schleef committed
501
502
503
504
505
506
507
508
509
{
  g_return_val_if_fail(structure != NULL, NULL);
  g_return_val_if_fail(fieldname != NULL, NULL);

  return gst_structure_id_get_field(structure,
      g_quark_from_string(fieldname));
}

/**
510
 * gst_structure_get_value:
David Schleef's avatar
David Schleef committed
511
512
513
514
515
516
517
518
 * @structure: a #GstStructure
 * @fieldname: the name of the field to get
 *
 * Accessor function.
 *
 * Returns: the #GValue corresponding to the field with the given name.
 */
const GValue *
Benjamin Otte's avatar
Benjamin Otte committed
519
gst_structure_get_value(const GstStructure *structure, const gchar *fieldname)
David Schleef's avatar
David Schleef committed
520
521
522
523
524
525
526
527
528
529
530
531
{
  GstStructureField *field;

  g_return_val_if_fail(structure != NULL, NULL);
  g_return_val_if_fail(fieldname != NULL, NULL);

  field = gst_structure_get_field(structure, fieldname);
  if(field == NULL) return NULL;

  return &field->value;
}

David Schleef's avatar
David Schleef committed
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
/**
 * gst_structure_id_get_value:
 * @structure: a #GstStructure
 * @id: the #GQuark of the field to get
 *
 * Accessor function.
 *
 * Returns: the #GValue corresponding to the field with the given name 
 *          identifier.
 */
const GValue *
gst_structure_id_get_value(const GstStructure *structure, GQuark id)
{
  GstStructureField *field;

  g_return_val_if_fail(structure != NULL, NULL);

  field = gst_structure_id_get_field(structure, id);
  if(field == NULL) return NULL;

  return &field->value;
}

David Schleef's avatar
David Schleef committed
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
/**
 * gst_structure_remove_field:
 * @structure: a #GstStructure
 * @fieldname: the name of the field to remove
 *
 * Removes the field with the given name.  If the field with the given
 * name does not exist, the structure is unchanged.
 */
void
gst_structure_remove_field(GstStructure *structure, const gchar *fieldname)
{
  GstStructureField *field;
  GQuark id;
  int i;

  g_return_if_fail(structure != NULL);
  g_return_if_fail(fieldname != NULL);

  id = g_quark_from_string(fieldname);

  for(i=0;i<structure->fields->len;i++){
    field = GST_STRUCTURE_FIELD(structure, i);

    if(field->name == id){
      if(G_IS_VALUE(&field->value)){
        g_value_unset(&field->value);
      }
      structure->fields = g_array_remove_index(structure->fields, i);
      return;
    }
  }
}

Benjamin Otte's avatar
Benjamin Otte committed
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
/**
 * gst_structure_remove_all_fields:
 * @structure: a #GstStructure
 *
 * Removes all fields in a GstStructure. 
 */
void
gst_structure_remove_all_fields(GstStructure *structure)
{
  GstStructureField *field;
  int i;

  g_return_if_fail(structure != NULL);

  for (i = structure->fields->len - 1; i >= 0; i-- ) {
    field = GST_STRUCTURE_FIELD(structure, i);

    if (G_IS_VALUE (&field->value)) {
      g_value_unset(&field->value);
    }
    structure->fields = g_array_remove_index (structure->fields, i);
  }
}

David Schleef's avatar
David Schleef committed
612
613
614
615
616
617
/**
 * gst_structure_get_field_type:
 * @structure: a #GstStructure
 * @fieldname: the name of the field
 *
 * Finds the field with the given name, and returns the type of the
618
 * value it contains.  If the field is not found, G_TYPE_INVALID is
David Schleef's avatar
David Schleef committed
619
620
621
622
623
 * returned.
 *
 * Returns: the #GValue of the field
 */
GType
Benjamin Otte's avatar
Benjamin Otte committed
624
gst_structure_get_field_type(const GstStructure *structure, const gchar *fieldname)
David Schleef's avatar
David Schleef committed
625
626
627
{
  GstStructureField *field;

628
629
  g_return_val_if_fail(structure != NULL, G_TYPE_INVALID);
  g_return_val_if_fail(fieldname != NULL, G_TYPE_INVALID);
David Schleef's avatar
David Schleef committed
630
631

  field = gst_structure_get_field(structure, fieldname);
632
  if(field == NULL) return G_TYPE_INVALID;
David Schleef's avatar
David Schleef committed
633
634
635
636
637
638
639
640
641
642
643
644
645

  return G_VALUE_TYPE(&field->value);
}

/**
 * gst_structure_n_fields:
 * @structure: a #GstStructure
 *
 * Accessor function.
 *
 * Returns: the number of fields in the structure
 */
gint
Benjamin Otte's avatar
Benjamin Otte committed
646
gst_structure_n_fields(const GstStructure *structure)
David Schleef's avatar
David Schleef committed
647
648
649
650
651
652
{
  g_return_val_if_fail(structure != NULL, 0);

  return structure->fields->len;
}

653
/**
David Schleef's avatar
David Schleef committed
654
 * gst_structure_foreach:
655
656
657
658
659
660
 * @structure: a #GstStructure
 * @func: a function to call for each field
 * @user_data: private data
 *
 * Calls the provided function once for each field in the #GstStructure.
 */
David Schleef's avatar
David Schleef committed
661
662
gboolean
gst_structure_foreach (GstStructure *structure,
663
664
665
666
    GstStructureForeachFunc func, gpointer user_data)
{
  int i;
  GstStructureField *field;
David Schleef's avatar
David Schleef committed
667
  gboolean ret;
668
669
670
671

  for(i=0;i<structure->fields->len;i++){
    field = GST_STRUCTURE_FIELD(structure, i);

David Schleef's avatar
David Schleef committed
672
673
    ret = func (field->name, &field->value, user_data);
    if (!ret) return FALSE;
674
  }
David Schleef's avatar
David Schleef committed
675
676

  return TRUE;
677
678
}

David Schleef's avatar
David Schleef committed
679
680
681
682
683
684
685
686
687
688
/**
 * gst_structure_has_field:
 * @structure: a #GstStructure
 * @fieldname: the name of a field
 *
 * Accessor function.
 *
 * Returns: TRUE if the structure contains a field with the given name
 */
gboolean
Benjamin Otte's avatar
Benjamin Otte committed
689
gst_structure_has_field(const GstStructure *structure, const gchar *fieldname)
David Schleef's avatar
David Schleef committed
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
{
  GstStructureField *field;

  g_return_val_if_fail(structure != NULL, 0);
  g_return_val_if_fail(fieldname != NULL, 0);

  field = gst_structure_get_field(structure, fieldname);

  return (field != NULL);
}

/**
 * gst_structure_has_field:
 * @structure: a #GstStructure
 * @fieldname: the name of a field
 * @type: the type of a value
 *
 * Accessor function.
 *
 * Returns: TRUE if the structure contains a field with the given name and type
 */
gboolean
Benjamin Otte's avatar
Benjamin Otte committed
712
gst_structure_has_field_typed(const GstStructure *structure, const gchar *fieldname,
David Schleef's avatar
David Schleef committed
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
    GType type)
{
  GstStructureField *field;

  g_return_val_if_fail(structure != NULL, 0);
  g_return_val_if_fail(fieldname != NULL, 0);

  field = gst_structure_get_field(structure, fieldname);
  if(field == NULL) return FALSE;

  return (G_VALUE_TYPE(&field->value) == type);
}


/* utility functions */

/**
 * gst_structure_get_boolean:
 * @structure: a #GstStructure
 * @fieldname: the name of a field
 * @ptr: a pointer to a #gboolean to set
 *
 * Sets the boolean pointed to by @ptr corresponding to the value of the
 * given field.  Caller is responsible for making sure the field exists
 * and has the correct type.
 *
 * Returns: TRUE if the value could be set correctly
 */
gboolean
Benjamin Otte's avatar
Benjamin Otte committed
742
gst_structure_get_boolean(const GstStructure *structure, const gchar *fieldname,
David Schleef's avatar
David Schleef committed
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
    gboolean *value)
{
  GstStructureField *field;

  g_return_val_if_fail(structure != NULL, FALSE);
  g_return_val_if_fail(fieldname != NULL, FALSE);

  field = gst_structure_get_field(structure, fieldname);

  if(field == NULL) return FALSE;
  if(!G_VALUE_HOLDS_BOOLEAN(&field->value))return FALSE;

  *value = g_value_get_boolean(&field->value);

  return TRUE;
}

/**
 * gst_structure_get_int:
 * @structure: a #GstStructure
 * @fieldname: the name of a field
 * @ptr: a pointer to an int to set
 *
 * Sets the int pointed to by @ptr corresponding to the value of the
 * given field.  Caller is responsible for making sure the field exists
 * and has the correct type.
 *
 * Returns: TRUE if the value could be set correctly
 */
gboolean
Benjamin Otte's avatar
Benjamin Otte committed
773
gst_structure_get_int(const GstStructure *structure, const gchar *fieldname,
David Schleef's avatar
David Schleef committed
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
    gint *value)
{
  GstStructureField *field;

  g_return_val_if_fail(structure != NULL, FALSE);
  g_return_val_if_fail(fieldname != NULL, FALSE);
  g_return_val_if_fail(value != NULL, FALSE);

  field = gst_structure_get_field(structure, fieldname);

  if(field == NULL) return FALSE;
  if(!G_VALUE_HOLDS_INT(&field->value))return FALSE;

  *value = g_value_get_int(&field->value);

  return TRUE;
}

/**
 * gst_structure_get_fourcc:
 * @structure: a #GstStructure
 * @fieldname: the name of a field
 * @ptr: a pointer to a #GstFourcc to set
 *
 * Sets the #GstFourcc pointed to by @ptr corresponding to the value of the
 * given field.  Caller is responsible for making sure the field exists
 * and has the correct type.
 *
 * Returns: TRUE if the value could be set correctly
 */
gboolean
Benjamin Otte's avatar
Benjamin Otte committed
805
gst_structure_get_fourcc(const GstStructure *structure, const gchar *fieldname,
David Schleef's avatar
David Schleef committed
806
807
808
809
810
811
812
813
814
815
816
    guint32 *value)
{
  GstStructureField *field;

  g_return_val_if_fail(structure != NULL, FALSE);
  g_return_val_if_fail(fieldname != NULL, FALSE);
  g_return_val_if_fail(value != NULL, FALSE);

  field = gst_structure_get_field(structure, fieldname);

  if(field == NULL) return FALSE;
David Schleef's avatar
David Schleef committed
817
  if(!GST_VALUE_HOLDS_FOURCC(&field->value))return FALSE;
David Schleef's avatar
David Schleef committed
818

David Schleef's avatar
David Schleef committed
819
  *value = gst_value_get_fourcc (&field->value);
David Schleef's avatar
David Schleef committed
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835

  return TRUE;
}

/**
 * gst_structure_get_double:
 * @structure: a #GstStructure
 * @fieldname: the name of a field
 * @ptr: a pointer to a #GstFourcc to set
 *
 * Sets the double pointed to by @ptr corresponding to the value of the
 * given field.  Caller is responsible for making sure the field exists
 * and has the correct type.
 *
 * Returns: TRUE if the value could be set correctly
 */
Benjamin Otte's avatar
Benjamin Otte committed
836
gboolean gst_structure_get_double(const GstStructure *structure,
David Schleef's avatar
David Schleef committed
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
    const gchar *fieldname, gdouble *value)
{
  GstStructureField *field;

  g_return_val_if_fail(structure != NULL, FALSE);
  g_return_val_if_fail(fieldname != NULL, FALSE);
  g_return_val_if_fail(value != NULL, FALSE);

  field = gst_structure_get_field(structure, fieldname);

  if(field == NULL) return FALSE;
  if(!G_VALUE_HOLDS_DOUBLE(&field->value))return FALSE;

  *value = g_value_get_double(&field->value);

  return TRUE;
}

/**
 * gst_structure_get_string:
 * @structure: a #GstStructure
 * @fieldname: the name of a field
 * @ptr: a pointer to a #GstFourcc to set
 *
 * Finds the field corresponding to @fieldname, and returns the string
 * contained in the field's value.  Caller is responsible for making
 * sure the field exists and has the correct type.
 *
 * The string should not be modified, and remains valid until the next
 * call to a gst_structure_*() function with the given structure.
 *
 * Returns: a pointer to the string
 */
const gchar *
Benjamin Otte's avatar
Benjamin Otte committed
871
gst_structure_get_string(const GstStructure *structure, const gchar *fieldname)
David Schleef's avatar
David Schleef committed
872
873
874
875
876
877
878
879
880
881
882
883
884
885
{
  GstStructureField *field;

  g_return_val_if_fail(structure != NULL, NULL);
  g_return_val_if_fail(fieldname != NULL, NULL);

  field = gst_structure_get_field(structure, fieldname);

  if(field == NULL) return FALSE;
  if(!G_VALUE_HOLDS_STRING(&field->value))return FALSE;

  return g_value_get_string(&field->value);
}

886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
typedef struct _GstStructureAbbreviation {
  char *type_name;
  GType type;
} GstStructureAbbreviation;

static GstStructureAbbreviation _gst_structure_abbrs[] = {
  { "int",	G_TYPE_INT },
  { "i",	G_TYPE_INT },
  { "float",	G_TYPE_FLOAT },
  { "f",	G_TYPE_FLOAT },
  { "double",	G_TYPE_DOUBLE },
  { "d",	G_TYPE_DOUBLE },
//{ "fourcc",	GST_TYPE_FOURCC },
  { "boolean",	G_TYPE_BOOLEAN },
  { "bool",	G_TYPE_BOOLEAN },
  { "b",	G_TYPE_BOOLEAN },
  { "string",	G_TYPE_STRING },
  { "str",	G_TYPE_STRING },
  { "s",	G_TYPE_STRING }
};

static GType _gst_structure_from_abbr(const char *type_name)
{
  int i;

  g_return_val_if_fail(type_name != NULL, G_TYPE_INVALID);

  for(i=0;i<G_N_ELEMENTS(_gst_structure_abbrs);i++){
    if(strcmp(type_name,_gst_structure_abbrs[i].type_name)==0){
      return _gst_structure_abbrs[i].type;
    }
  }

  /* FIXME shouldn't be a special case */
  if (strcmp (type_name,"fourcc") == 0 || strcmp (type_name, "4") == 0) {
    return GST_TYPE_FOURCC;
  }

  return g_type_from_name (type_name);
}

static const char *_gst_structure_to_abbr(GType type)
{
  int i;

  g_return_val_if_fail(type != G_TYPE_INVALID, NULL);

  for(i=0;i<G_N_ELEMENTS(_gst_structure_abbrs);i++){
    if(type == _gst_structure_abbrs[i].type){
      return _gst_structure_abbrs[i].type_name;
    }
  }

  /* FIXME shouldn't be a special case */
  if (type == GST_TYPE_FOURCC) {
    return "fourcc";
  }

  return g_type_name(type);
}

David Schleef's avatar
David Schleef committed
947
948
949
950
#define GST_ASCII_IS_STRING(c) (g_ascii_isalnum((c)) || ((c) == '_') || \
      ((c) == '-') || ((c) == '+') || ((c) == '/') || ((c) == ':') || \
      ((c) == '.'))

David Schleef's avatar
David Schleef committed
951
952
953
954
955
956
957
958
959
/**
 * gst_structure_to_string:
 * @structure: a #GstStructure
 *
 * Converts @structure to a human-readable representation.
 * 
 * Returns: a pointer to string allocated by g_malloc()
 */
gchar *
Benjamin Otte's avatar
Benjamin Otte committed
960
gst_structure_to_string(const GstStructure *structure)
David Schleef's avatar
David Schleef committed
961
962
963
964
{
  GstStructureField *field;
  GString *s;
  int i;
965
966
967
968
969
970
  
  /* NOTE:  This function is potentially called by the debug system,
   * so any calls to gst_log() (and GST_DEBUG(), GST_LOG(), etc.)
   * should be careful to avoid recursion.  This includes any functions
   * called by gst_structure_to_string.  In particular, calls should
   * not use the GST_PTR_FORMAT extension.  */
David Schleef's avatar
David Schleef committed
971
972
973
974

  g_return_val_if_fail(structure != NULL, NULL);

  s = g_string_new("");
David Schleef's avatar
David Schleef committed
975
976
977
  /* 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++) {
978
    char *t;
979
    GType type;
David Schleef's avatar
David Schleef committed
980
981
982

    field = GST_STRUCTURE_FIELD(structure, i);

983
    t = gst_value_serialize (&field->value);
984
985
986
    type = G_VALUE_TYPE (&field->value);

    if (type == GST_TYPE_LIST) {
David Schleef's avatar
David Schleef committed
987
988
989
      GArray *array = g_value_peek_pointer (&field->value);
      if (array->len > 0){
        GValue *value = &g_array_index (array, GValue, 0);
990
991
992
993
994
995
996
997
998
999

	type = G_VALUE_TYPE (value);
      } else {
	type = G_TYPE_INT;
      }
    } else if (G_VALUE_TYPE(&field->value) == GST_TYPE_INT_RANGE) {
      type = G_TYPE_INT;
    } else if (G_VALUE_TYPE(&field->value) == GST_TYPE_DOUBLE_RANGE) {
      type = G_TYPE_DOUBLE;
    }
David Schleef's avatar
David Schleef committed
1000
1001
1002
    g_string_append_printf(s, ", %s=(%s)%s", g_quark_to_string(field->name),
	_gst_structure_to_abbr(type), t);
    g_free(t);
David Schleef's avatar
David Schleef committed
1003
1004
1005
1006
  }
  return g_string_free(s, FALSE);
}

1007
1008
1009
1010
1011
1012
1013
/*
 * r will still point to the string. if end == next, the string will not be 
 * null-terminated. In all other cases it will be.
 * end = pointer to char behind end of string, next = pointer to start of
 * unread data.
 * THIS FUNCTION MODIFIES THE STRING AND DETECTS INSIDE A NONTERMINATED STRING 
 */
David Schleef's avatar
David Schleef committed
1014
static gboolean _gst_structure_parse_simple_string (gchar *s, gchar **end);
1015
static gboolean
David Schleef's avatar
David Schleef committed
1016
_gst_structure_parse_string (gchar *s, gchar **end, gchar **next)
1017
1018
1019
{
  gchar *w;

David Schleef's avatar
David Schleef committed
1020
  if (*s == 0) return FALSE;
1021

David Schleef's avatar
David Schleef committed
1022
1023
  if (*s != '"') {
    int ret;
1024

David Schleef's avatar
David Schleef committed
1025
1026
    ret = _gst_structure_parse_simple_string (s, end);
    *next = *end;
1027

David Schleef's avatar
David Schleef committed
1028
1029
    return ret;
  }
1030

David Schleef's avatar
David Schleef committed
1031
1032
1033
1034
1035
1036
1037
  w = s;
  s++;
  while (*s != '"') {
    if (*s == 0) return FALSE;

    if (*s == '\\') {
      s++;
1038
    }
David Schleef's avatar
David Schleef committed
1039
1040
1041
1042

    *w = *s;
    w++;
    s++;
1043
  }
David Schleef's avatar
David Schleef committed
1044
  s++;
1045
1046

  *end = w;
David Schleef's avatar
David Schleef committed
1047
  *next = s;
1048

David Schleef's avatar
David Schleef committed
1049
  return TRUE;
1050
1051
}

David Schleef's avatar
David Schleef committed
1052
1053
1054
static gboolean _gst_structure_parse_value (gchar *str, gchar **after,
    GValue *value, GType default_type);

1055
static gboolean
David Schleef's avatar
David Schleef committed
1056
_gst_structure_parse_range (gchar *s, gchar **after, GValue *value, GType type)
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
{
  GValue value1 = { 0 };
  GValue value2 = { 0 };
  GType range_type;
  gboolean ret;


  if (*s != '[') return FALSE;
  s++;

David Schleef's avatar
David Schleef committed
1067
  ret = _gst_structure_parse_value(s, &s, &value1, type);
1068
1069
1070
1071
1072
1073
1074
1075
1076
  if (ret == FALSE) return FALSE;

  while (g_ascii_isspace (*s)) s++;
    
  if (*s != ',') return FALSE;
  s++;

  while (g_ascii_isspace (*s)) s++;

David Schleef's avatar
David Schleef committed
1077
  ret = _gst_structure_parse_value(s, &s, &value2, type);
1078
1079
1080
1081
1082
1083
1084
  if (ret == FALSE) return FALSE;

  while (g_ascii_isspace (*s)) s++;

  if (*s != ']') return FALSE;
  s++;

David Schleef's avatar
David Schleef committed
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
  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;
  }

1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
  g_value_init(value, range_type);
  if (range_type == GST_TYPE_DOUBLE_RANGE) {
    gst_value_set_double_range(value, g_value_get_double(&value1),
	g_value_get_double(&value2));
  } else {
    gst_value_set_int_range(value, g_value_get_int(&value1),
	g_value_get_int(&value2));
  }

  *after = s;
  return TRUE;
}

static gboolean
David Schleef's avatar
David Schleef committed
1109
_gst_structure_parse_list (gchar *s, gchar **after, GValue *value, GType type)
1110
1111
1112
{
  GValue list_value = { 0 };
  gboolean ret;
David Schleef's avatar
David Schleef committed
1113
  GArray *array;
1114
1115

  g_value_init(value, GST_TYPE_LIST);
David Schleef's avatar
David Schleef committed
1116
  array = g_value_peek_pointer (value);
1117

David Schleef's avatar
David Schleef committed
1118
  if (*s != '{') return FALSE;
1119
1120
1121
  s++;

  while (g_ascii_isspace (*s)) s++;
David Schleef's avatar
David Schleef committed
1122
  if (*s == '}') {
1123
1124
1125
1126
1127
    s++;
    *after = s;
    return TRUE;
  }

David Schleef's avatar
David Schleef committed
1128
  ret = _gst_structure_parse_value(s, &s, &list_value, type);
1129
  if (ret == FALSE) return FALSE;
David Schleef's avatar
David Schleef committed
1130
1131
  
  g_array_append_val (array, list_value);
1132
1133
1134

  while (g_ascii_isspace (*s)) s++;
    
David Schleef's avatar
David Schleef committed
1135
  while (*s != '}') {
1136
1137
1138
1139
1140
1141
    if (*s != ',') return FALSE;
    s++;

    while (g_ascii_isspace (*s)) s++;

    memset (&list_value, 0, sizeof (list_value));
David Schleef's avatar
David Schleef committed
1142
    ret = _gst_structure_parse_value(s, &s, &list_value, type);
1143
1144
    if (ret == FALSE) return FALSE;

David Schleef's avatar
David Schleef committed
1145
    g_array_append_val (array, list_value);
1146
1147
1148
1149
1150
1151
1152
1153
1154
    while (g_ascii_isspace (*s)) s++;
  }

  s++;

  *after = s;
  return TRUE;
}

David Schleef's avatar
David Schleef committed
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
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);
}

1169
1170
1171
1172
static gboolean
_gst_structure_parse_field (gchar *str, gchar **after, GstStructureField *field)
{
  gchar *name;
David Schleef's avatar
David Schleef committed
1173
1174
1175
  gchar *name_end;
  gchar *s;
  gchar c;
1176

David Schleef's avatar
David Schleef committed
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
  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;
1187
1188
  s++;

David Schleef's avatar
David Schleef committed
1189
1190
  c = *name_end;
  *name_end = 0;
1191
  field->name = g_quark_from_string (name);
David Schleef's avatar
David Schleef committed
1192
  *name_end = c;
1193

David Schleef's avatar
David Schleef committed
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
  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;
1211
  int ret = 0;
David Schleef's avatar
David Schleef committed
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
  GType type = default_type;


  s = str;
  while(g_ascii_isspace (*s)) s++;

  type_name = NULL;
  if (*s == '(') {
    type = G_TYPE_INVALID;

    s++;
    while(g_ascii_isspace (*s)) s++;
1224
    type_name = s;
David Schleef's avatar
David Schleef committed
1225
1226
1227
1228
    if (!_gst_structure_parse_simple_string (s, &type_end)) return FALSE;
    s = type_end;
    while(g_ascii_isspace (*s)) s++;
    if (*s != ')') return FALSE;
1229
    s++;
David Schleef's avatar
David Schleef committed
1230
1231
1232
1233
    while(g_ascii_isspace (*s)) s++;

    c = *type_end;
    *type_end = 0;
1234
    type = _gst_structure_from_abbr(type_name);
David Schleef's avatar
David Schleef committed
1235
    *type_end = c;
1236
1237
1238
1239

    if (type == G_TYPE_INVALID) return FALSE;
  }

David Schleef's avatar
David Schleef committed
1240
  while(g_ascii_isspace (*s)) s++;
1241
  if (*s == '[') {
David Schleef's avatar
David Schleef committed
1242
1243
1244
    ret = _gst_structure_parse_range (s, &s, value, type);
  } else if (*s == '{') {
    ret = _gst_structure_parse_list (s, &s, value, type);
1245
  } else {
David Schleef's avatar
David Schleef committed
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
    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]);
1257
	ret = gst_value_deserialize (value, value_s);
David Schleef's avatar
David Schleef committed
1258
1259
1260
1261
1262
1263
	if (ret) break;
	g_value_unset(value);
      }
    } else {
      g_value_init(value, type);

1264
      ret = gst_value_deserialize (value, value_s);
David Schleef's avatar
David Schleef committed
1265
1266
    }
    *value_end = c;
1267
1268
1269
1270
1271
1272
1273
  }
  
  *after = s;

  return ret;
}

David Schleef's avatar
David Schleef committed
1274
1275
1276
1277
1278
1279
1280
1281
1282
/**
 * gst_structure_from_string:
 * @structure: a #GstStructure
 *
 * Creates a #GstStructure from a string representation.
 * 
 * Returns: a new #GstStructure
 */
GstStructure *
1283
gst_structure_from_string (const gchar *string, gchar **end)
David Schleef's avatar
David Schleef committed
1284
{
1285
1286
1287
1288
1289
1290
1291
1292
  char *name;
  char *copy;
  char *w;
  char *r;
  char save;
  GstStructure *structure;
  GstStructureField field = { 0 };
  gboolean res;
David Schleef's avatar
David Schleef committed
1293
1294
1295

  g_return_val_if_fail(string != NULL, NULL);

1296
1297
  copy = g_strdup(string);
  r = copy;
David Schleef's avatar
David Schleef committed
1298

1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
  name = r;
  res = _gst_structure_parse_string (r, &w, &r);
  if (!res) return NULL;
  
  while (g_ascii_isspace(*r)) r++;
  if(*r != 0 && *r != ';' && *r != ',') return NULL;

  save = *w;
  *w = 0;
  structure = gst_structure_empty_new(name);
  *w = save;

  while (*r && (*r != ';')){
    if(*r != ',') {
      return NULL;
    }
    r++;
    while (*r && g_ascii_isspace(*r)) r++;

    memset(&field,0,sizeof(field));
    res = _gst_structure_parse_field (r, &r, &field);
    if (!res) {
      gst_structure_free (structure);
      return NULL;
    }
    gst_structure_set_field(structure, &field);
    while (*r && g_ascii_isspace(*r)) r++;
  }

  if (end) *end = (char *)string + (r - copy);
  return structure;
David Schleef's avatar
David Schleef committed
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
}

static void
_gst_structure_transform_to_string(const GValue *src_value, GValue *dest_value)
{
  g_return_if_fail(src_value != NULL);
  g_return_if_fail(dest_value != NULL);

  dest_value->data[0].v_pointer =
    gst_structure_to_string (src_value->data[0].v_pointer);
}


static void _gst_structure_value_init (GValue *value)
{
  value->data[0].v_pointer = gst_structure_empty_new("");
}

static void _gst_structure_value_free (GValue *value)
{
  gst_structure_free(value->data[0].v_pointer);

}

static void _gst_structure_value_copy (const GValue *src, GValue *dest)
{
1356
  dest->data[0].v_pointer = gst_structure_copy(src->data[0].v_pointer);
David Schleef's avatar
David Schleef committed
1357
1358
1359
1360
1361
1362
1363
}

static gpointer _gst_structure_value_peek_pointer (const GValue *value)
{
  return value->data[0].v_pointer;
}