File: ges-meta-container.c

package info (click to toggle)
gstreamer-editing-services1.0 1.14.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 8,388 kB
  • sloc: ansic: 43,396; sh: 4,773; perl: 1,583; makefile: 1,172; python: 581; xml: 80; lex: 44
file content (919 lines) | stat: -rw-r--r-- 29,147 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
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
356
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
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
472
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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
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
742
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
773
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
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
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
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
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
/* GStreamer Editing Services
 * Copyright (C) 2012 Paul Lange <palango@gmx.de>
 * Copyright (C) <2014> Thibault Saunier <thibault.saunier@collabora.com>
 *
 * 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.
 */

#include <glib-object.h>
#include <gst/gst.h>

#include "ges-meta-container.h"

/**
* SECTION: gesmetacontainer
* @short_description: An interface for storing meta
*
* Interface that allows reading and writing meta
*/

static GQuark ges_meta_key;

G_DEFINE_INTERFACE_WITH_CODE (GESMetaContainer, ges_meta_container,
    G_TYPE_OBJECT, ges_meta_key =
    g_quark_from_static_string ("ges-meta-container-data"););

enum
{
  NOTIFY_SIGNAL,
  LAST_SIGNAL
};

static guint _signals[LAST_SIGNAL] = { 0 };

typedef struct RegisteredMeta
{
  GType item_type;
  GESMetaFlag flags;
} RegisteredMeta;

typedef struct ContainerData
{
  GstStructure *structure;
  GHashTable *static_items;
} ContainerData;

static void
ges_meta_container_default_init (GESMetaContainerInterface * iface)
{

  /**
   * GESMetaContainer::notify:
   * @container: a #GESMetaContainer
   * @prop: the key of the value that changed
   * @value: the #GValue containing the new value
   *
   * The notify signal is used to be notify of changes of values
   * of some metadatas
   */
  _signals[NOTIFY_SIGNAL] =
      g_signal_new ("notify-meta", G_TYPE_FROM_INTERFACE (iface),
      G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED |
      G_SIGNAL_NO_HOOKS, 0, NULL, NULL, g_cclosure_marshal_generic,
      G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VALUE);
}

static void
_free_meta_container_data (ContainerData * data)
{
  gst_structure_free (data->structure);
  g_hash_table_unref (data->static_items);

  g_slice_free (ContainerData, data);
}

static void
_free_static_item (RegisteredMeta * item)
{
  g_slice_free (RegisteredMeta, item);
}

static ContainerData *
_create_container_data (GESMetaContainer * container)
{
  ContainerData *data = g_slice_new (ContainerData);
  data->structure = gst_structure_new_empty ("metadatas");
  data->static_items = g_hash_table_new_full (g_str_hash, g_str_equal,
      g_free, (GDestroyNotify) (GDestroyNotify) _free_static_item);
  g_object_set_qdata_full (G_OBJECT (container), ges_meta_key, data,
      (GDestroyNotify) _free_meta_container_data);

  return data;
}

static GstStructure *
_meta_container_get_structure (GESMetaContainer * container)
{
  ContainerData *data;

  data = g_object_get_qdata (G_OBJECT (container), ges_meta_key);
  if (!data)
    data = _create_container_data (container);

  return data->structure;
}

typedef struct
{
  GESMetaForeachFunc func;
  const GESMetaContainer *container;
  gpointer data;
} MetadataForeachData;

static gboolean
structure_foreach_wrapper (GQuark field_id, const GValue * value,
    gpointer user_data)
{
  MetadataForeachData *data = (MetadataForeachData *) user_data;

  data->func (data->container, g_quark_to_string (field_id), value, data->data);
  return TRUE;
}

static gboolean
_append_foreach (GQuark field_id, const GValue * value, GESMetaContainer * self)
{
  ges_meta_container_set_meta (self, g_quark_to_string (field_id), value);

  return TRUE;
}

/**
 * ges_meta_container_foreach:
 * @container: container to iterate over
 * @func: (scope call): function to be called for each metadata
 * @user_data: (closure): user specified data
 *
 * Calls the given function for each metadata inside the meta container. Note
 * that if there is no metadata, the function won't be called at all.
 */
void
ges_meta_container_foreach (GESMetaContainer * container,
    GESMetaForeachFunc func, gpointer user_data)
{
  GstStructure *structure;
  MetadataForeachData foreach_data;

  g_return_if_fail (GES_IS_META_CONTAINER (container));
  g_return_if_fail (func != NULL);

  structure = _meta_container_get_structure (container);

  foreach_data.func = func;
  foreach_data.container = container;
  foreach_data.data = user_data;

  gst_structure_foreach (structure,
      (GstStructureForeachFunc) structure_foreach_wrapper, &foreach_data);
}

/* _can_write_value should have been checked before calling */
static gboolean
_register_meta (GESMetaContainer * container, GESMetaFlag flags,
    const gchar * meta_item, GType type)
{
  ContainerData *data;
  RegisteredMeta *static_item;

  data = g_object_get_qdata (G_OBJECT (container), ges_meta_key);
  if (!data)
    data = _create_container_data (container);
  else if (g_hash_table_lookup (data->static_items, meta_item)) {
    GST_WARNING_OBJECT (container, "Static meta %s already registered",
        meta_item);

    return FALSE;
  }

  static_item = g_slice_new0 (RegisteredMeta);
  static_item->item_type = type;
  static_item->flags = flags;
  g_hash_table_insert (data->static_items, g_strdup (meta_item), static_item);

  return TRUE;
}

static gboolean
_set_value (GESMetaContainer * container, const gchar * meta_item,
    const GValue * value)
{
  GstStructure *structure;
  gchar *val = gst_value_serialize (value);

  if (val == NULL) {
    GST_WARNING_OBJECT (container, "Could not set value on item: %s",
        meta_item);

    g_free (val);
    return FALSE;
  }

  structure = _meta_container_get_structure (container);

  GST_DEBUG_OBJECT (container, "Setting meta_item %s value: %s::%s",
      meta_item, G_VALUE_TYPE_NAME (value), val);

  gst_structure_set_value (structure, meta_item, value);
  g_signal_emit (container, _signals[NOTIFY_SIGNAL], 0, meta_item, value);

  g_free (val);
  return TRUE;
}

static gboolean
_can_write_value (GESMetaContainer * container, const gchar * item_name,
    GType type)
{
  ContainerData *data;
  RegisteredMeta *static_item = NULL;

  data = g_object_get_qdata (G_OBJECT (container), ges_meta_key);
  if (!data) {
    _create_container_data (container);
    return TRUE;
  }

  static_item = g_hash_table_lookup (data->static_items, item_name);

  if (static_item == NULL)
    return TRUE;

  if ((static_item->flags & GES_META_WRITABLE) == FALSE) {
    GST_WARNING_OBJECT (container, "Can not write %s", item_name);
    return FALSE;
  }

  if (static_item->item_type != type) {
    GST_WARNING_OBJECT (container, "Can not set value of type %s on %s "
        "its type is: %s", g_type_name (static_item->item_type), item_name,
        g_type_name (type));
    return FALSE;
  }

  return TRUE;
}

#define CREATE_SETTER(name, value_ctype, value_gtype,  setter_name)     \
gboolean                                                                \
ges_meta_container_set_ ## name (GESMetaContainer *container,      \
                           const gchar *meta_item, value_ctype value)   \
{                                                                       \
  GValue gval = { 0 };                                                  \
  gboolean ret;                                                         \
                                                                        \
  g_return_val_if_fail (GES_IS_META_CONTAINER (container), FALSE);      \
  g_return_val_if_fail (meta_item != NULL, FALSE);                      \
                                                                        \
  if (_can_write_value (container, meta_item, value_gtype) == FALSE)    \
    return FALSE;                                                       \
                                                                        \
  g_value_init (&gval, value_gtype);                                    \
  g_value_set_ ##setter_name (&gval, value);                            \
                                                                        \
  ret = _set_value (container, meta_item, &gval);                       \
  g_value_unset (&gval);                                                \
  return ret;                                                           \
}

/**
 * ges_meta_container_set_boolean:
 * @container: Target container
 * @meta_item: Name of the meta item to set
 * @value: Value to set
 *
 * Sets the value of a given meta item
 *
 * Return: %TRUE if the meta could be added, %FALSE otherwize
 */
CREATE_SETTER (boolean, gboolean, G_TYPE_BOOLEAN, boolean)

/**
 * ges_meta_container_set_int:
 * @container: Target container
 * @meta_item: Name of the meta item to set
 * @value: Value to set
 *
 * Sets the value of a given meta item
 *
 * Return: %TRUE if the meta could be added, %FALSE otherwize
 */
    CREATE_SETTER (int, gint, G_TYPE_INT, int)

/**
 * ges_meta_container_set_uint:
 * @container: Target container
 * @meta_item: Name of the meta item to set
 * @value: Value to set
 *
 * Sets the value of a given meta item
 *
 * Return: %TRUE if the meta could be added, %FALSE otherwize
 */
    CREATE_SETTER (uint, guint, G_TYPE_UINT, uint)

/**
 * ges_meta_container_set_int64:
 * @container: Target container
 * @meta_item: Name of the meta item to set
 * @value: Value to set
 *
 * Sets the value of a given meta item
 *
 * Return: %TRUE if the meta could be added, %FALSE otherwize
 */
    CREATE_SETTER (int64, gint64, G_TYPE_INT64, int64)

/**
 * ges_meta_container_set_uint64:
 * @container: Target container
 * @meta_item: Name of the meta item to set
 * @value: Value to set
 *
 * Sets the value of a given meta item
 *
 * Return: %TRUE if the meta could be added, %FALSE otherwize
 */
    CREATE_SETTER (uint64, guint64, G_TYPE_UINT64, uint64)

/**
 * ges_meta_container_set_float:
 * @container: Target container
 * @meta_item: Name of the meta item to set
 * @value: Value to set
 *
 * Sets the value of a given meta item
 *
 * Return: %TRUE if the meta could be added, %FALSE otherwize
 */
    CREATE_SETTER (float, float, G_TYPE_FLOAT, float)

/**
 * ges_meta_container_set_double:
 * @container: Target container
 * @meta_item: Name of the meta item to set
 * @value: Value to set
 *
 * Sets the value of a given meta item
 *
 * Return: %TRUE if the meta could be added, %FALSE otherwize
 */
CREATE_SETTER (double, double, G_TYPE_DOUBLE, double)

/**
 * ges_meta_container_set_date:
 * @container: Target container
 * @meta_item: Name of the meta item to set
 * @value: Value to set
 *
 * Sets the value of a given meta item
 *
 * Return: %TRUE if the meta could be added, %FALSE otherwize
 */
CREATE_SETTER (date, const GDate *, G_TYPE_DATE, boxed)

/**
 * ges_meta_container_set_date_time:
 * @container: Target container
 * @meta_item: Name of the meta item to set
 * @value: Value to set
 *
 * Sets the value of a given meta item
 *
 * Return: %TRUE if the meta could be added, %FALSE otherwize
 */
CREATE_SETTER (date_time, const GstDateTime *, GST_TYPE_DATE_TIME, boxed)

/**
* ges_meta_container_set_string:
* @container: Target container
* @meta_item: Name of the meta item to set
* @value: Value to set
*
* Sets the value of a given meta item
*
* Return: %TRUE if the meta could be added, %FALSE otherwize
*/
CREATE_SETTER (string, const gchar *, G_TYPE_STRING, string)

/**
 * ges_meta_container_set_meta:
 * @container: Target container
 * @meta_item: Name of the meta item to set
 * @value: (allow-none): Value to set
 * Sets the value of a given meta item
 *
 * Return: %TRUE if the meta could be added, %FALSE otherwize
 */
  gboolean
ges_meta_container_set_meta (GESMetaContainer * container,
    const gchar * meta_item, const GValue * value)
{
  g_return_val_if_fail (GES_IS_META_CONTAINER (container), FALSE);
  g_return_val_if_fail (meta_item != NULL, FALSE);

  if (value == NULL) {
    GstStructure *structure = _meta_container_get_structure (container);
    gst_structure_remove_field (structure, meta_item);

    g_signal_emit (container, _signals[NOTIFY_SIGNAL], 0, meta_item, value);

    return TRUE;
  }

  if (_can_write_value (container, meta_item, G_VALUE_TYPE (value)) == FALSE)
    return FALSE;

  return _set_value (container, meta_item, value);
}

/**
 * ges_meta_container_metas_to_string:
 * @container: a #GESMetaContainer
 *
 * Serializes a meta container to a string.
 *
 * Returns: (nullable): a newly-allocated string, or NULL in case of an error.
 * The string must be freed with g_free() when no longer needed.
 */
gchar *
ges_meta_container_metas_to_string (GESMetaContainer * container)
{
  GstStructure *structure;

  g_return_val_if_fail (GES_IS_META_CONTAINER (container), NULL);

  structure = _meta_container_get_structure (container);

  return gst_structure_to_string (structure);
}

/**
 * ges_meta_container_add_metas_from_string:
 * @container: Target container
 * @str: a string created with ges_meta_container_metas_to_string()
 *
 * Deserializes a meta container.
 *
 * Returns: TRUE on success, FALSE if there was an error.
 */
gboolean
ges_meta_container_add_metas_from_string (GESMetaContainer * container,
    const gchar * str)
{
  GstStructure *n_structure;

  g_return_val_if_fail (GES_IS_META_CONTAINER (container), FALSE);

  n_structure = gst_structure_from_string (str, NULL);
  if (n_structure == NULL) {
    GST_WARNING_OBJECT (container, "Could not add metas: %s", str);
    return FALSE;
  }

  gst_structure_foreach (n_structure, (GstStructureForeachFunc) _append_foreach,
      container);

  gst_structure_free (n_structure);
  return TRUE;
}

#define CREATE_REGISTER_STATIC(name, value_ctype, value_gtype, setter_name) \
gboolean                                                                      \
ges_meta_container_register_meta_ ## name (GESMetaContainer *container,\
    GESMetaFlag flags, const gchar *meta_item, value_ctype value)             \
{                                                                             \
  gboolean ret;                                                               \
  GValue gval = { 0 };                                                        \
                                                                              \
  g_return_val_if_fail (GES_IS_META_CONTAINER (container), FALSE);            \
  g_return_val_if_fail (meta_item != NULL, FALSE);                            \
                                                                              \
  if (!_register_meta (container, flags, meta_item, value_gtype))             \
    return FALSE;                                                             \
                                                                              \
  g_value_init (&gval, value_gtype);                                          \
  g_value_set_ ##setter_name (&gval, value);                                  \
                                                                              \
  ret = _set_value  (container, meta_item, &gval);                            \
                                                                              \
  g_value_unset (&gval);                                                      \
  return ret;                                                                 \
}

/**
 * register_meta_:
 * @container: Target container
 * @flags: The #GESMetaFlag to be used
 * @meta_item: Name of the meta item to set
 * @value: (allow-none): Value to set
 *
 * Sets a static meta on @container. This method lets you define static
 * metadatas, which means that the type of the registered will be the only
 * type accepted for this meta on that particular @container.
 *
 * Return: %TRUE if the meta could be register, %FALSE otherwize
 */
CREATE_REGISTER_STATIC (boolean, gboolean, G_TYPE_BOOLEAN, boolean)

/**
 * ges_meta_container_register_meta_int:
 * @container: Target container
 * @flags: The #GESMetaFlag to be used
 * @meta_item: Name of the meta item to set
 * @value: Value to set
 *
 * Sets a static meta on @container. This method lets you define static
 * metadatas, which means that the type of the registered will be the only
 * type accepted for this meta on that particular @container.
 *
 * Return: %TRUE if the meta could be register, %FALSE otherwize
 */
    CREATE_REGISTER_STATIC (int, gint, G_TYPE_INT, int)

/**
 * ges_meta_container_register_meta_uint:
 * @container: Target container
 * @flags: The #GESMetaFlag to be used
 * @meta_item: Name of the meta item to set
 * @value: Value to set
 *
 * Sets a static meta on @container. This method lets you define static
 * metadatas, which means that the type of the registered will be the only
 * type accepted for this meta on that particular @container.
 *
 * Return: %TRUE if the meta could be register, %FALSE otherwize
 */
    CREATE_REGISTER_STATIC (uint, guint, G_TYPE_UINT, uint)

/**
 * ges_meta_container_register_meta_int64:
 * @container: Target container
 * @flags: The #GESMetaFlag to be used
 * @meta_item: Name of the meta item to set
 * @value: Value to set
 *
 * Sets a static meta on @container. This method lets you define static
 * metadatas, which means that the type of the registered will be the only
 * type accepted for this meta on that particular @container.
 *
 * Return: %TRUE if the meta could be register, %FALSE otherwize
 */
    CREATE_REGISTER_STATIC (int64, gint64, G_TYPE_INT64, int64)

/**
 * ges_meta_container_register_meta_uint64:
 * @container: Target container
 * @flags: The #GESMetaFlag to be used
 * @meta_item: Name of the meta item to set
 * @value: Value to set
 *
 * Sets a static meta on @container. This method lets you define static
 * metadatas, which means that the type of the registered will be the only
 * type accepted for this meta on that particular @container.
 *
 * Return: %TRUE if the meta could be register, %FALSE otherwize
 */
    CREATE_REGISTER_STATIC (uint64, guint64, G_TYPE_UINT64, uint64)

/**
 * ges_meta_container_register_meta_float:
 * @container: Target container
 * @flags: The #GESMetaFlag to be used
 * @meta_item: Name of the meta item to set
 * @value: Value to set
 *
 * Sets a static meta on @container. This method lets you define static
 * metadatas, which means that the type of the registered will be the only
 * type accepted for this meta on that particular @container.
 *
 * Return: %TRUE if the meta could be register, %FALSE otherwize
*/
    CREATE_REGISTER_STATIC (float, float, G_TYPE_FLOAT, float)

/**
 * ges_meta_container_register_meta_double:
 * @container: Target container
 * @flags: The #GESMetaFlag to be used
 * @meta_item: Name of the meta item to set
 * @value: Value to set
 *
 * Sets a static meta on @container. This method lets you define static
 * metadatas, which means that the type of the registered will be the only
 * type accepted for this meta on that particular @container.
 *
 * Return: %TRUE if the meta could be register, %FALSE otherwize
 */
CREATE_REGISTER_STATIC (double, double, G_TYPE_DOUBLE, double)

/**
 * ges_meta_container_register_meta_date:
 * @container: Target container
 * @flags: The #GESMetaFlag to be used
 * @meta_item: Name of the meta item to set
 * @value: (allow-none): Value to set
 *
 * Sets a static meta on @container. This method lets you define static
 * metadatas, which means that the type of the registered will be the only
 * type accepted for this meta on that particular @container.
 *
 * Return: %TRUE if the meta could be register, %FALSE otherwize
 */
CREATE_REGISTER_STATIC (date, const GDate *, G_TYPE_DATE, boxed)

/**
 * ges_meta_container_register_meta_date_time:
 * @container: Target container
 * @flags: The #GESMetaFlag to be used
 * @meta_item: Name of the meta item to set
 * @value: (allow-none): Value to set
 *
 * Sets a static meta on @container. This method lets you define static
 * metadatas, which means that the type of the registered will be the only
 * type accepted for this meta on that particular @container.
 *
 * Return: %TRUE if the meta could be register, %FALSE otherwize
 */
CREATE_REGISTER_STATIC (date_time, const GstDateTime *, GST_TYPE_DATE_TIME,
    boxed)

/**
 * ges_meta_container_register_meta_string:
 * @container: Target container
 * @flags: The #GESMetaFlag to be used
 * @meta_item: Name of the meta item to set
 * @value: (allow-none): Value to set
 *
 * Sets a static meta on @container. This method lets you define static
 * metadatas, which means that the type of the registered will be the only
 * type accepted for this meta on that particular @container.
 *
 * Return: %TRUE if the meta could be register, %FALSE otherwize
 */
CREATE_REGISTER_STATIC (string, const gchar *, G_TYPE_STRING, string)

/**
 * ges_meta_container_register_meta:
 * @container: Target container
 * @flags: The #GESMetaFlag to be used
 * @meta_item: Name of the meta item to set
 * @value: Value to set
 *
 * Sets a static meta on @container. This method lets you define static
 * metadatas, which means that the type of the registered will be the only
 * type accepted for this meta on that particular @container.
 *
 * Return: %TRUE if the static meta could be added, %FALSE otherwize
 */
  gboolean
ges_meta_container_register_meta (GESMetaContainer * container,
    GESMetaFlag flags, const gchar * meta_item, const GValue * value)
{
  g_return_val_if_fail (GES_IS_META_CONTAINER (container), FALSE);
  g_return_val_if_fail (meta_item != NULL, FALSE);

  if (!_register_meta (container, flags, meta_item, G_VALUE_TYPE (value)))
    return FALSE;

  return _set_value (container, meta_item, value);
}

gboolean
ges_meta_container_check_meta_registered (GESMetaContainer * container,
    const gchar * meta_item, GESMetaFlag * flags, GType * type)
{
  ContainerData *data;
  RegisteredMeta *static_item;

  data = g_object_get_qdata (G_OBJECT (container), ges_meta_key);
  if (!data)
    return FALSE;

  static_item = g_hash_table_lookup (data->static_items, meta_item);
  if (static_item == NULL) {
    GST_WARNING_OBJECT (container, "Static meta %s already registered",
        meta_item);

    return FALSE;
  }

  if (type)
    *type = static_item->item_type;

  if (flags)
    *flags = static_item->flags;

  return TRUE;
}

/* Copied from gsttaglist.c */
/***** evil macros to get all the *_get_* functions right *****/

#define CREATE_GETTER(name,type)                                         \
gboolean                                                                 \
ges_meta_container_get_ ## name (GESMetaContainer *container,    \
                           const gchar *meta_item, type value)       \
{                                                                        \
  GstStructure *structure;                                                     \
                                                                         \
  g_return_val_if_fail (GES_IS_META_CONTAINER (container), FALSE);   \
  g_return_val_if_fail (meta_item != NULL, FALSE);                   \
  g_return_val_if_fail (value != NULL, FALSE);                           \
                                                                         \
  structure = _meta_container_get_structure (container);                    \
                                                                         \
  return gst_structure_get_ ## name (structure, meta_item, value);   \
}

/**
 * ges_meta_container_get_boolean:
 * @container: Target container
 * @meta_item: Name of the meta item to get
 * @dest: (out): Destination to which value of meta item will be copied
 * Gets the value of a given meta item, returns NULL if @meta_item
 * can not be found.
 */
CREATE_GETTER (boolean, gboolean *);
/**
 * ges_meta_container_get_int:
 * @container: Target container
 * @meta_item: Name of the meta item to get
 * @dest: (out): Destination to which value of meta item will be copied
 * Gets the value of a given meta item, returns NULL if @meta_item
 * can not be found.
 */
CREATE_GETTER (int, gint *);
/**
 * ges_meta_container_get_uint:
 * @container: Target container
 * @meta_item: Name of the meta item to get
 * @dest: (out): Destination to which value of meta item will be copied
 * Gets the value of a given meta item, returns NULL if @meta_item
 * can not be found.
 */
CREATE_GETTER (uint, guint *);
/**
 * ges_meta_container_get_double:
 * @container: Target container
 * @meta_item: Name of the meta item to get
 * @dest: (out): Destination to which value of meta item will be copied
 * Gets the value of a given meta item, returns NULL if @meta_item
 * can not be found.
 */
CREATE_GETTER (double, gdouble *);

/**
 * ges_meta_container_get_int64:
 * @container: Target container
 * @meta_item: Name of the meta item to get
 * @dest: (out): Destination to which value of meta item will be copied
 * Gets the value of a given meta item, returns %FALSE if @meta_item
 * can not be found.
 */
gboolean
ges_meta_container_get_int64 (GESMetaContainer * container,
    const gchar * meta_item, gint64 * dest)
{
  GstStructure *structure;
  const GValue *value;

  g_return_val_if_fail (GES_IS_META_CONTAINER (container), FALSE);
  g_return_val_if_fail (meta_item != NULL, FALSE);
  g_return_val_if_fail (dest != NULL, FALSE);

  structure = _meta_container_get_structure (container);

  value = gst_structure_get_value (structure, meta_item);
  if (!value || G_VALUE_TYPE (value) != G_TYPE_INT64)
    return FALSE;

  *dest = g_value_get_int64 (value);

  return TRUE;
}

/**
 * ges_meta_container_get_uint64:
 * @container: Target container
 * @meta_item: Name of the meta item to get
 * @dest: (out): Destination to which value of meta item will be copied
 * Gets the value of a given meta item, returns NULL if @meta_item
 * can not be found.
 */
gboolean
ges_meta_container_get_uint64 (GESMetaContainer * container,
    const gchar * meta_item, guint64 * dest)
{
  GstStructure *structure;
  const GValue *value;

  g_return_val_if_fail (GES_IS_META_CONTAINER (container), FALSE);
  g_return_val_if_fail (meta_item != NULL, FALSE);
  g_return_val_if_fail (dest != NULL, FALSE);

  structure = _meta_container_get_structure (container);

  value = gst_structure_get_value (structure, meta_item);
  if (!value || G_VALUE_TYPE (value) != G_TYPE_UINT64)
    return FALSE;

  *dest = g_value_get_uint64 (value);

  return TRUE;
}

/**
 * ges_meta_container_get_float:
 * @container: Target container
 * @meta_item: Name of the meta item to get
 * @dest: (out): Destination to which value of meta item will be copied
 * Gets the value of a given meta item, returns FALSE if @meta_item
 * can not be found.
 */
gboolean
ges_meta_container_get_float (GESMetaContainer * container,
    const gchar * meta_item, gfloat * dest)
{
  GstStructure *structure;
  const GValue *value;

  g_return_val_if_fail (GES_IS_META_CONTAINER (container), FALSE);
  g_return_val_if_fail (meta_item != NULL, FALSE);
  g_return_val_if_fail (dest != NULL, FALSE);

  structure = _meta_container_get_structure (container);

  value = gst_structure_get_value (structure, meta_item);
  if (!value || G_VALUE_TYPE (value) != G_TYPE_FLOAT)
    return FALSE;

  *dest = g_value_get_float (value);

  return TRUE;
}

/**
 * ges_meta_container_get_string:
 * @container: Target container
 * @meta_item: Name of the meta item to get
 * Gets the value of a given meta item, returns NULL if @meta_item
 * can not be found.
 */
const gchar *
ges_meta_container_get_string (GESMetaContainer * container,
    const gchar * meta_item)
{
  GstStructure *structure;

  g_return_val_if_fail (GES_IS_META_CONTAINER (container), FALSE);
  g_return_val_if_fail (meta_item != NULL, FALSE);

  structure = _meta_container_get_structure (container);

  return gst_structure_get_string (structure, meta_item);
}

/**
 * ges_meta_container_get_meta:
 * @container: Target container
 * @key: The key name of the meta to retrieve
 *
 * Gets the value of a given meta item, returns NULL if @key
 * can not be found.
 *
 * Returns: the #GValue corresponding to the meta with the given @key.
 */
const GValue *
ges_meta_container_get_meta (GESMetaContainer * container, const gchar * key)
{
  GstStructure *structure;

  g_return_val_if_fail (GES_IS_META_CONTAINER (container), FALSE);
  g_return_val_if_fail (key != NULL, FALSE);

  structure = _meta_container_get_structure (container);

  return gst_structure_get_value (structure, key);
}

/**
 * ges_meta_container_get_date:
 * @container: Target container
 * @meta_item: Name of the meta item to get
 * @dest: (out): Destination to which value of meta item will be copied
 * Gets the value of a given meta item, returns NULL if @meta_item
 * can not be found.
 */
CREATE_GETTER (date, GDate **);

/**
 * ges_meta_container_get_date_time:
 * @container: Target container
 * @meta_item: Name of the meta item to get
 * @dest: (out): Destination to which value of meta item will be copied
 * Gets the value of a given meta item, returns NULL if @meta_item
 * can not be found.
 */
CREATE_GETTER (date_time, GstDateTime **);