2 * Copyright (C) 2008-2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
28 #include "mxfmetadata.h"
31 GST_DEBUG_CATEGORY_EXTERN (mxf_debug);
32 #define GST_CAT_DEFAULT mxf_debug
34 G_DEFINE_ABSTRACT_TYPE (MXFMetadataBase, mxf_metadata_base, G_TYPE_OBJECT);
37 mxf_metadata_base_finalize (GObject * object)
39 MXFMetadataBase *self = MXF_METADATA_BASE (object);
41 if (self->other_tags) {
42 g_hash_table_destroy (self->other_tags);
43 self->other_tags = NULL;
46 G_OBJECT_CLASS (mxf_metadata_base_parent_class)->finalize (object);
50 mxf_metadata_base_handle_tag (MXFMetadataBase * self, MXFPrimerPack * primer,
51 guint16 tag, const guint8 * tag_data, guint tag_size)
53 return (mxf_local_tag_add_to_hash_table (primer, tag, tag_data, tag_size,
58 mxf_metadata_base_resolve_default (MXFMetadataBase * self,
59 GHashTable * metadata)
65 mxf_metadata_base_to_structure_default (MXFMetadataBase * self)
67 MXFMetadataBaseClass *klass = MXF_METADATA_BASE_GET_CLASS (self);
71 g_return_val_if_fail (klass->name_quark != 0, NULL);
73 ret = gst_structure_new_id_empty (klass->name_quark);
75 if (!mxf_uuid_is_zero (&self->instance_uid)) {
76 mxf_uuid_to_string (&self->instance_uid, str);
77 gst_structure_id_set (ret, MXF_QUARK (INSTANCE_UID), G_TYPE_STRING, str,
81 if (!mxf_uuid_is_zero (&self->generation_uid)) {
82 mxf_uuid_to_string (&self->generation_uid, str);
83 gst_structure_id_set (ret, MXF_QUARK (GENERATION_UID), G_TYPE_STRING, str,
87 if (self->other_tags) {
96 g_hash_table_iter_init (&iter, self->other_tags);
97 g_value_init (&va, GST_TYPE_ARRAY);
99 while (g_hash_table_iter_next (&iter, NULL, (gpointer) & tag)) {
100 g_value_init (&v, GST_TYPE_STRUCTURE);
101 s = gst_structure_new_id_empty (MXF_QUARK (TAG));
103 mxf_ul_to_string (&tag->ul, str);
105 buf = gst_buffer_new_and_alloc (tag->size);
106 gst_buffer_map (buf, &map, GST_MAP_WRITE);
107 memcpy (map.data, tag->data, tag->size);
108 gst_buffer_unmap (buf, &map);
110 gst_structure_id_set (s, MXF_QUARK (NAME), G_TYPE_STRING, str,
111 MXF_QUARK (DATA), GST_TYPE_BUFFER, buf, NULL);
113 gst_value_set_structure (&v, s);
114 gst_structure_free (s);
115 gst_buffer_unref (buf);
116 gst_value_array_append_value (&va, &v);
120 gst_structure_id_set_value (ret, MXF_QUARK (OTHER_TAGS), &va);
128 mxf_metadata_base_init (MXFMetadataBase * self)
134 mxf_metadata_base_class_init (MXFMetadataBaseClass * klass)
136 GObjectClass *object_class = (GObjectClass *) klass;
138 object_class->finalize = mxf_metadata_base_finalize;
139 klass->handle_tag = mxf_metadata_base_handle_tag;
140 klass->resolve = mxf_metadata_base_resolve_default;
141 klass->to_structure = mxf_metadata_base_to_structure_default;
145 mxf_metadata_base_parse (MXFMetadataBase * self, MXFPrimerPack * primer,
146 const guint8 * data, guint size)
148 guint16 tag, tag_size;
149 const guint8 *tag_data;
151 g_return_val_if_fail (MXF_IS_METADATA_BASE (self), FALSE);
152 g_return_val_if_fail (primer != NULL, FALSE);
157 g_return_val_if_fail (data != NULL, FALSE);
159 while (mxf_local_tag_parse (data, size, &tag, &tag_size, &tag_data)) {
160 if (tag_size == 0 || tag == 0x0000)
163 if (!MXF_METADATA_BASE_GET_CLASS (self)->handle_tag (self, primer, tag,
167 data += 4 + tag_size;
168 size -= 4 + tag_size;
175 mxf_metadata_base_resolve (MXFMetadataBase * self, GHashTable * metadata)
177 MXFMetadataBaseClass *klass;
180 g_return_val_if_fail (MXF_IS_METADATA_BASE (self), FALSE);
181 g_return_val_if_fail (metadata != NULL, FALSE);
183 if (self->resolved == MXF_METADATA_BASE_RESOLVE_STATE_SUCCESS)
185 else if (self->resolved != MXF_METADATA_BASE_RESOLVE_STATE_NONE)
188 self->resolved = MXF_METADATA_BASE_RESOLVE_STATE_RUNNING;
190 klass = MXF_METADATA_BASE_GET_CLASS (self);
193 ret = klass->resolve (self, metadata);
196 (ret) ? MXF_METADATA_BASE_RESOLVE_STATE_SUCCESS :
197 MXF_METADATA_BASE_RESOLVE_STATE_FAILURE;
203 mxf_metadata_base_to_structure (MXFMetadataBase * self)
205 MXFMetadataBaseClass *klass;
207 g_return_val_if_fail (MXF_IS_METADATA_BASE (self), NULL);
209 g_return_val_if_fail (self->resolved ==
210 MXF_METADATA_BASE_RESOLVE_STATE_SUCCESS, NULL);
212 klass = MXF_METADATA_BASE_GET_CLASS (self);
214 if (klass->to_structure)
215 return klass->to_structure (self);
221 mxf_metadata_base_to_buffer (MXFMetadataBase * self, MXFPrimerPack * primer)
223 MXFMetadataBaseClass *klass;
227 guint size = 0, slen;
229 MXFLocalTag *t, *last;
232 g_return_val_if_fail (MXF_IS_METADATA_BASE (self), NULL);
233 g_return_val_if_fail (primer != NULL, NULL);
235 klass = MXF_METADATA_BASE_GET_CLASS (self);
236 g_return_val_if_fail (klass->write_tags, NULL);
238 tags = klass->write_tags (self, primer);
239 g_return_val_if_fail (tags != NULL, NULL);
241 /* Add unknown tags */
242 if (self->other_tags) {
246 g_hash_table_iter_init (&iter, self->other_tags);
248 while (g_hash_table_iter_next (&iter, NULL, (gpointer) & t)) {
249 tmp = g_slice_dup (MXFLocalTag, t);
251 tmp->data = g_slice_alloc (t->size);
252 mxf_primer_pack_add_mapping (primer, 0x0000, &t->ul);
253 memcpy (tmp->data, t->data, t->size);
255 tmp->data = g_memdup (t->data, t->size);
257 tags = g_list_prepend (tags, tmp);
261 l = g_list_last (tags);
263 tags = g_list_delete_link (tags, l);
264 /* Last element contains the metadata UL */
265 g_return_val_if_fail (last->size == 0, NULL);
267 for (l = tags; l; l = l->next) {
269 g_assert (G_MAXUINT - t->size >= size);
273 slen = mxf_ber_encode_size (size, ber);
276 ret = gst_buffer_new_and_alloc (size);
277 gst_buffer_map (ret, &map, GST_MAP_WRITE);
279 memcpy (map.data, &last->ul, 16);
280 mxf_local_tag_free (last);
282 memcpy (map.data + 16, ber, slen);
284 data = map.data + 16 + slen;
287 for (l = tags; l; l = l->next) {
290 g_assert (size >= 4);
294 GPOINTER_TO_UINT (g_hash_table_lookup (primer->reverse_mappings,
296 g_assert (local_tag != 0);
298 GST_WRITE_UINT16_BE (data, local_tag);
299 GST_WRITE_UINT16_BE (data + 2, t->size);
302 g_assert (size >= t->size);
304 memcpy (data, t->data, t->size);
308 mxf_local_tag_free (t);
313 gst_buffer_unmap (ret, &map);
318 G_DEFINE_ABSTRACT_TYPE (MXFMetadata, mxf_metadata, MXF_TYPE_METADATA_BASE);
321 mxf_metadata_handle_tag (MXFMetadataBase * metadata, MXFPrimerPack * primer,
322 guint16 tag, const guint8 * tag_data, guint tag_size)
324 #ifndef GST_DISABLE_GST_DEBUG
327 MXFMetadata *self = MXF_METADATA (metadata);
334 memcpy (&self->parent.instance_uid, tag_data, 16);
335 GST_DEBUG (" instance uid = %s",
336 mxf_uuid_to_string (&self->parent.instance_uid, str));
341 memcpy (&self->parent.generation_uid, tag_data, 16);
342 GST_DEBUG (" generation uid = %s",
343 mxf_uuid_to_string (&self->parent.generation_uid, str));
347 MXF_METADATA_BASE_CLASS (mxf_metadata_parent_class)->handle_tag
348 (metadata, primer, tag, tag_data, tag_size);
356 GST_ERROR ("Invalid metadata local tag 0x%04x of size %u", tag, tag_size);
362 mxf_metadata_write_tags (MXFMetadataBase * m, MXFPrimerPack * primer)
364 MXFMetadata *self = MXF_METADATA (m);
367 MXFMetadataClass *klass;
369 g_return_val_if_fail (MXF_IS_METADATA (self), NULL);
370 klass = MXF_METADATA_GET_CLASS (self);
372 /* Last element contains the metadata key */
373 t = g_slice_new0 (MXFLocalTag);
374 memcpy (&t->ul, MXF_UL (METADATA), 16);
375 GST_WRITE_UINT16_BE (&t->ul.u[13], klass->type);
376 ret = g_list_prepend (ret, t);
378 t = g_slice_new0 (MXFLocalTag);
379 memcpy (&t->ul, MXF_UL (INSTANCE_UID), 16);
381 t->data = g_slice_alloc (16);
383 memcpy (t->data, &self->parent.instance_uid, 16);
384 mxf_primer_pack_add_mapping (primer, 0x3c0a, &t->ul);
385 ret = g_list_prepend (ret, t);
387 if (!mxf_uuid_is_zero (&self->parent.generation_uid)) {
388 t = g_slice_new0 (MXFLocalTag);
389 memcpy (&t->ul, MXF_UL (GENERATION_UID), 16);
391 t->data = g_slice_alloc (16);
393 memcpy (t->data, &self->parent.generation_uid, 16);
394 mxf_primer_pack_add_mapping (primer, 0x0102, &t->ul);
395 ret = g_list_prepend (ret, t);
402 mxf_metadata_class_init (MXFMetadataClass * klass)
404 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
406 metadata_base_class->handle_tag = mxf_metadata_handle_tag;
407 metadata_base_class->write_tags = mxf_metadata_write_tags;
411 mxf_metadata_init (MXFMetadata * self)
415 static GArray *_mxf_metadata_registry = NULL;
417 #define _add_metadata_type(type) G_STMT_START { \
420 g_array_append_val (_mxf_metadata_registry, t); \
424 mxf_metadata_init_types (void)
426 g_return_if_fail (_mxf_metadata_registry == NULL);
428 _mxf_metadata_registry = g_array_new (FALSE, TRUE, sizeof (GType));
430 _add_metadata_type (MXF_TYPE_METADATA_PREFACE);
431 _add_metadata_type (MXF_TYPE_METADATA_IDENTIFICATION);
432 _add_metadata_type (MXF_TYPE_METADATA_CONTENT_STORAGE);
433 _add_metadata_type (MXF_TYPE_METADATA_ESSENCE_CONTAINER_DATA);
434 _add_metadata_type (MXF_TYPE_METADATA_MATERIAL_PACKAGE);
435 _add_metadata_type (MXF_TYPE_METADATA_SOURCE_PACKAGE);
436 _add_metadata_type (MXF_TYPE_METADATA_TIMELINE_TRACK);
437 _add_metadata_type (MXF_TYPE_METADATA_EVENT_TRACK);
438 _add_metadata_type (MXF_TYPE_METADATA_STATIC_TRACK);
439 _add_metadata_type (MXF_TYPE_METADATA_SEQUENCE);
440 _add_metadata_type (MXF_TYPE_METADATA_SOURCE_CLIP);
441 _add_metadata_type (MXF_TYPE_METADATA_FILLER);
442 _add_metadata_type (MXF_TYPE_METADATA_TIMECODE_COMPONENT);
443 _add_metadata_type (MXF_TYPE_METADATA_DM_SEGMENT);
444 _add_metadata_type (MXF_TYPE_METADATA_DM_SOURCE_CLIP);
445 _add_metadata_type (MXF_TYPE_METADATA_FILE_DESCRIPTOR);
446 _add_metadata_type (MXF_TYPE_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR);
447 _add_metadata_type (MXF_TYPE_METADATA_CDCI_PICTURE_ESSENCE_DESCRIPTOR);
448 _add_metadata_type (MXF_TYPE_METADATA_RGBA_PICTURE_ESSENCE_DESCRIPTOR);
449 _add_metadata_type (MXF_TYPE_METADATA_GENERIC_SOUND_ESSENCE_DESCRIPTOR);
450 _add_metadata_type (MXF_TYPE_METADATA_GENERIC_DATA_ESSENCE_DESCRIPTOR);
451 _add_metadata_type (MXF_TYPE_METADATA_MULTIPLE_DESCRIPTOR);
452 _add_metadata_type (MXF_TYPE_METADATA_NETWORK_LOCATOR);
453 _add_metadata_type (MXF_TYPE_METADATA_TEXT_LOCATOR);
456 #undef _add_metadata_type
459 mxf_metadata_register (GType type)
461 g_return_if_fail (g_type_is_a (type, MXF_TYPE_METADATA));
463 g_array_append_val (_mxf_metadata_registry, type);
467 mxf_metadata_new (guint16 type, MXFPrimerPack * primer, guint64 offset,
468 const guint8 * data, guint size)
471 GType t = G_TYPE_INVALID;
472 MXFMetadata *ret = NULL;
474 g_return_val_if_fail (type != 0, NULL);
475 g_return_val_if_fail (primer != NULL, NULL);
476 g_return_val_if_fail (_mxf_metadata_registry != NULL, NULL);
478 for (i = 0; i < _mxf_metadata_registry->len; i++) {
479 GType tmp = g_array_index (_mxf_metadata_registry, GType, i);
480 MXFMetadataClass *klass = MXF_METADATA_CLASS (g_type_class_ref (tmp));
482 if (klass->type == type) {
483 g_type_class_unref (klass);
487 g_type_class_unref (klass);
490 if (t == G_TYPE_INVALID) {
492 ("No handler for type 0x%04x found -- using generic metadata parser",
498 GST_DEBUG ("Metadata type 0x%04x is handled by type %s", type,
501 ret = (MXFMetadata *) g_type_create_instance (t);
502 if (!mxf_metadata_base_parse (MXF_METADATA_BASE (ret), primer, data, size)) {
503 GST_ERROR ("Parsing metadata failed");
504 g_object_unref (ret);
508 ret->parent.offset = offset;
512 G_DEFINE_TYPE (MXFMetadataPreface, mxf_metadata_preface, MXF_TYPE_METADATA);
515 mxf_metadata_preface_finalize (GObject * object)
517 MXFMetadataPreface *self = MXF_METADATA_PREFACE (object);
519 g_free (self->identifications_uids);
520 self->identifications_uids = NULL;
522 g_free (self->identifications);
523 self->identifications = NULL;
525 g_free (self->essence_containers);
526 self->essence_containers = NULL;
528 g_free (self->dm_schemes);
529 self->dm_schemes = NULL;
531 G_OBJECT_CLASS (mxf_metadata_preface_parent_class)->finalize (object);
535 mxf_metadata_preface_handle_tag (MXFMetadataBase * metadata,
536 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
539 MXFMetadataPreface *self = MXF_METADATA_PREFACE (metadata);
540 #ifndef GST_DISABLE_GST_DEBUG
547 if (!mxf_timestamp_parse (&self->last_modified_date, tag_data, tag_size))
549 GST_DEBUG (" last modified date = %s",
550 mxf_timestamp_to_string (&self->last_modified_date, str));
555 self->version = GST_READ_UINT16_BE (tag_data);
556 GST_DEBUG (" version = %u.%u", (self->version >> 8),
557 (self->version & 0x0f));
562 self->object_model_version = GST_READ_UINT32_BE (tag_data);
563 GST_DEBUG (" object model version = %u", self->object_model_version);
568 memcpy (&self->primary_package_uid, tag_data, 16);
569 GST_DEBUG (" primary package = %s",
570 mxf_uuid_to_string (&self->primary_package_uid, str));
573 if (!mxf_uuid_array_parse (&self->identifications_uids,
574 &self->n_identifications, tag_data, tag_size))
577 GST_DEBUG (" number of identifications = %u", self->n_identifications);
578 #ifndef GST_DISABLE_GST_DEBUG
581 for (i = 0; i < self->n_identifications; i++) {
582 GST_DEBUG (" identification %u = %s", i,
583 mxf_uuid_to_string (&self->identifications_uids[i], str));
591 memcpy (&self->content_storage_uid, tag_data, 16);
592 GST_DEBUG (" content storage = %s",
593 mxf_uuid_to_string (&self->content_storage_uid, str));
598 memcpy (&self->operational_pattern, tag_data, 16);
599 GST_DEBUG (" operational pattern = %s",
600 mxf_ul_to_string (&self->operational_pattern, str));
603 if (!mxf_ul_array_parse (&self->essence_containers,
604 &self->n_essence_containers, tag_data, tag_size))
607 GST_DEBUG (" number of essence containers = %u",
608 self->n_essence_containers);
609 #ifndef GST_DISABLE_GST_DEBUG
612 for (i = 0; i < self->n_essence_containers; i++) {
613 GST_DEBUG (" essence container %u = %s", i,
614 mxf_ul_to_string (&self->essence_containers[i], str));
620 if (!mxf_ul_array_parse (&self->dm_schemes, &self->n_dm_schemes, tag_data,
623 GST_DEBUG (" number of DM schemes = %u", self->n_dm_schemes);
625 #ifndef GST_DISABLE_GST_DEBUG
628 for (i = 0; i < self->n_dm_schemes; i++) {
629 GST_DEBUG (" DM schemes %u = %s", i,
630 mxf_ul_to_string (&self->dm_schemes[i], str));
637 MXF_METADATA_BASE_CLASS
638 (mxf_metadata_preface_parent_class)->handle_tag (metadata, primer,
639 tag, tag_data, tag_size);
647 GST_ERROR ("Invalid preface local tag 0x%04x of size %u", tag, tag_size);
653 mxf_metadata_preface_resolve (MXFMetadataBase * m, GHashTable * metadata)
655 MXFMetadataPreface *self = MXF_METADATA_PREFACE (m);
656 MXFMetadataBase *current = NULL;
658 #ifndef GST_DISABLE_GST_DEBUG
662 if (!mxf_uuid_is_zero (&self->primary_package_uid)) {
663 current = g_hash_table_lookup (metadata, &self->primary_package_uid);
664 if (!current || !MXF_IS_METADATA_GENERIC_PACKAGE (current)) {
665 GST_ERROR ("Primary package %s not found",
666 mxf_uuid_to_string (&self->primary_package_uid, str));
668 if (mxf_metadata_base_resolve (current, metadata)) {
669 self->primary_package = MXF_METADATA_GENERIC_PACKAGE (current);
675 current = g_hash_table_lookup (metadata, &self->content_storage_uid);
676 if (!current || !MXF_IS_METADATA_CONTENT_STORAGE (current)) {
677 GST_ERROR ("Content storage %s not found",
678 mxf_uuid_to_string (&self->content_storage_uid, str));
681 if (mxf_metadata_base_resolve (current, metadata)) {
682 self->content_storage = MXF_METADATA_CONTENT_STORAGE (current);
684 GST_ERROR ("Couldn't resolve content storage %s",
685 mxf_uuid_to_string (&self->content_storage_uid, str));
691 if (self->identifications)
692 memset (self->identifications, 0,
693 sizeof (gpointer) * self->n_identifications);
695 self->identifications =
696 g_new0 (MXFMetadataIdentification *, self->n_identifications);
697 for (i = 0; i < self->n_identifications; i++) {
698 current = g_hash_table_lookup (metadata, &self->identifications_uids[i]);
699 if (current && MXF_IS_METADATA_IDENTIFICATION (current)) {
700 if (mxf_metadata_base_resolve (current, metadata))
701 self->identifications[i] = MXF_METADATA_IDENTIFICATION (current);
707 MXF_METADATA_BASE_CLASS (mxf_metadata_preface_parent_class)->resolve (m,
711 static GstStructure *
712 mxf_metadata_preface_to_structure (MXFMetadataBase * m)
715 MXF_METADATA_BASE_CLASS (mxf_metadata_preface_parent_class)->to_structure
717 MXFMetadataPreface *self = MXF_METADATA_PREFACE (m);
721 if (!mxf_timestamp_is_unknown (&self->last_modified_date)) {
722 mxf_timestamp_to_string (&self->last_modified_date, str);
723 gst_structure_id_set (ret, MXF_QUARK (LAST_MODIFIED_DATE), G_TYPE_STRING,
727 if (self->version != 0)
728 gst_structure_id_set (ret, MXF_QUARK (VERSION), G_TYPE_UINT, self->version,
731 if (self->object_model_version != 0)
732 gst_structure_id_set (ret, MXF_QUARK (OBJECT_MODEL_VERSION), G_TYPE_UINT,
733 self->object_model_version, NULL);
735 if (!mxf_uuid_is_zero (&self->primary_package_uid)) {
736 mxf_uuid_to_string (&self->primary_package_uid, str);
737 gst_structure_id_set (ret, MXF_QUARK (PRIMARY_PACKAGE), G_TYPE_STRING, str,
741 if (self->n_identifications > 0) {
746 g_value_init (&arr, GST_TYPE_ARRAY);
748 for (i = 0; i < self->n_identifications; i++) {
751 if (self->identifications[i] == NULL)
754 g_value_init (&val, GST_TYPE_STRUCTURE);
756 s = mxf_metadata_base_to_structure (MXF_METADATA_BASE
757 (self->identifications[i]));
758 gst_value_set_structure (&val, s);
759 gst_structure_free (s);
760 gst_value_array_append_value (&arr, &val);
761 g_value_unset (&val);
764 if (gst_value_array_get_size (&arr) > 0)
765 gst_structure_id_set_value (ret, MXF_QUARK (IDENTIFICATIONS), &arr);
767 g_value_unset (&arr);
770 if (self->content_storage) {
772 mxf_metadata_base_to_structure (MXF_METADATA_BASE
773 (self->content_storage));
774 gst_structure_id_set (ret, MXF_QUARK (CONTENT_STORAGE), GST_TYPE_STRUCTURE,
776 gst_structure_free (s);
779 if (!mxf_ul_is_zero (&self->operational_pattern)) {
780 mxf_ul_to_string (&self->operational_pattern, str);
781 gst_structure_id_set (ret, MXF_QUARK (OPERATIONAL_PATTERN), G_TYPE_STRING,
785 if (self->n_essence_containers > 0) {
790 g_value_init (&arr, GST_TYPE_ARRAY);
792 for (i = 0; i < self->n_essence_containers; i++) {
793 if (mxf_ul_is_zero (&self->essence_containers[i]))
796 g_value_init (&val, G_TYPE_STRING);
798 mxf_ul_to_string (&self->essence_containers[i], str);
799 g_value_set_string (&val, str);
801 gst_value_array_append_value (&arr, &val);
802 g_value_unset (&val);
805 if (gst_value_array_get_size (&arr) > 0)
806 gst_structure_id_set_value (ret, MXF_QUARK (ESSENCE_CONTAINERS), &arr);
808 g_value_unset (&arr);
811 if (self->n_dm_schemes > 0) {
816 g_value_init (&arr, GST_TYPE_ARRAY);
818 for (i = 0; i < self->n_dm_schemes; i++) {
819 if (mxf_ul_is_zero (&self->dm_schemes[i]))
822 g_value_init (&val, G_TYPE_STRING);
824 mxf_ul_to_string (&self->dm_schemes[i], str);
825 g_value_set_string (&val, str);
827 gst_value_array_append_value (&arr, &val);
828 g_value_unset (&val);
831 if (gst_value_array_get_size (&arr) > 0)
832 gst_structure_id_set_value (ret, MXF_QUARK (DM_SCHEMES), &arr);
834 g_value_unset (&arr);
841 mxf_metadata_preface_write_tags (MXFMetadataBase * m, MXFPrimerPack * primer)
843 MXFMetadataPreface *self = MXF_METADATA_PREFACE (m);
845 MXF_METADATA_BASE_CLASS (mxf_metadata_preface_parent_class)->write_tags
850 t = g_slice_new0 (MXFLocalTag);
851 memcpy (&t->ul, MXF_UL (LAST_MODIFIED_DATE), 16);
853 t->data = g_slice_alloc (8);
855 mxf_timestamp_write (&self->last_modified_date, t->data);
856 mxf_primer_pack_add_mapping (primer, 0x3b02, &t->ul);
857 ret = g_list_prepend (ret, t);
859 t = g_slice_new0 (MXFLocalTag);
860 memcpy (&t->ul, MXF_UL (VERSION), 16);
862 t->data = g_slice_alloc (2);
864 GST_WRITE_UINT16_BE (t->data, self->version);
865 mxf_primer_pack_add_mapping (primer, 0x3b05, &t->ul);
866 ret = g_list_prepend (ret, t);
868 if (self->object_model_version) {
869 t = g_slice_new0 (MXFLocalTag);
870 memcpy (&t->ul, MXF_UL (OBJECT_MODEL_VERSION), 16);
872 t->data = g_slice_alloc (4);
874 GST_WRITE_UINT32_BE (t->data, self->object_model_version);
875 mxf_primer_pack_add_mapping (primer, 0x3b07, &t->ul);
876 ret = g_list_prepend (ret, t);
879 if (!mxf_uuid_is_zero (&self->primary_package_uid)) {
880 t = g_slice_new0 (MXFLocalTag);
881 memcpy (&t->ul, MXF_UL (PRIMARY_PACKAGE), 16);
883 t->data = g_slice_alloc (16);
885 memcpy (t->data, &self->primary_package_uid, 16);
886 mxf_primer_pack_add_mapping (primer, 0x3b08, &t->ul);
887 ret = g_list_prepend (ret, t);
890 t = g_slice_new0 (MXFLocalTag);
891 memcpy (&t->ul, MXF_UL (IDENTIFICATIONS), 16);
892 t->size = 8 + 16 * self->n_identifications;
893 t->data = g_slice_alloc0 (t->size);
895 mxf_primer_pack_add_mapping (primer, 0x3b06, &t->ul);
896 GST_WRITE_UINT32_BE (t->data, self->n_identifications);
897 GST_WRITE_UINT32_BE (t->data + 4, 16);
898 for (i = 0; i < self->n_identifications; i++) {
899 if (!self->identifications[i])
902 memcpy (t->data + 8 + 16 * i,
903 &MXF_METADATA_BASE (self->identifications[i])->instance_uid, 16);
905 ret = g_list_prepend (ret, t);
907 t = g_slice_new0 (MXFLocalTag);
908 memcpy (&t->ul, MXF_UL (CONTENT_STORAGE), 16);
910 t->data = g_slice_alloc (t->size);
912 mxf_primer_pack_add_mapping (primer, 0x3b03, &t->ul);
913 memcpy (t->data, &MXF_METADATA_BASE (self->content_storage)->instance_uid,
915 ret = g_list_prepend (ret, t);
917 t = g_slice_new0 (MXFLocalTag);
918 memcpy (&t->ul, MXF_UL (OPERATIONAL_PATTERN), 16);
920 t->data = g_slice_alloc (t->size);
922 mxf_primer_pack_add_mapping (primer, 0x3b09, &t->ul);
923 memcpy (t->data, &self->operational_pattern, 16);
924 ret = g_list_prepend (ret, t);
926 t = g_slice_new0 (MXFLocalTag);
927 memcpy (&t->ul, MXF_UL (ESSENCE_CONTAINERS), 16);
928 t->size = 8 + 16 * self->n_essence_containers;
929 t->data = g_slice_alloc0 (t->size);
931 mxf_primer_pack_add_mapping (primer, 0x3b0a, &t->ul);
932 GST_WRITE_UINT32_BE (t->data, self->n_essence_containers);
933 GST_WRITE_UINT32_BE (t->data + 4, 16);
934 for (i = 0; i < self->n_essence_containers; i++) {
935 memcpy (t->data + 8 + 16 * i, &self->essence_containers[i], 16);
937 ret = g_list_prepend (ret, t);
939 t = g_slice_new0 (MXFLocalTag);
940 memcpy (&t->ul, MXF_UL (DM_SCHEMES), 16);
941 t->size = 8 + 16 * self->n_dm_schemes;
942 t->data = g_slice_alloc0 (t->size);
944 mxf_primer_pack_add_mapping (primer, 0x3b0b, &t->ul);
945 GST_WRITE_UINT32_BE (t->data, self->n_dm_schemes);
946 GST_WRITE_UINT32_BE (t->data + 4, 16);
947 for (i = 0; i < self->n_dm_schemes; i++) {
948 memcpy (t->data + 8 + 16 * i, &self->dm_schemes[i], 16);
950 ret = g_list_prepend (ret, t);
956 mxf_metadata_preface_init (MXFMetadataPreface * self)
962 mxf_metadata_preface_class_init (MXFMetadataPrefaceClass * klass)
964 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
965 GObjectClass *object_class = (GObjectClass *) klass;
966 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
968 object_class->finalize = mxf_metadata_preface_finalize;
969 metadata_base_class->handle_tag = mxf_metadata_preface_handle_tag;
970 metadata_base_class->resolve = mxf_metadata_preface_resolve;
971 metadata_base_class->to_structure = mxf_metadata_preface_to_structure;
972 metadata_base_class->write_tags = mxf_metadata_preface_write_tags;
973 metadata_base_class->name_quark = MXF_QUARK (PREFACE);
974 metadata_class->type = 0x012f;
977 G_DEFINE_TYPE (MXFMetadataIdentification, mxf_metadata_identification,
981 mxf_metadata_identification_finalize (GObject * object)
983 MXFMetadataIdentification *self = MXF_METADATA_IDENTIFICATION (object);
985 g_free (self->company_name);
986 self->company_name = NULL;
988 g_free (self->product_name);
989 self->product_name = NULL;
991 g_free (self->version_string);
992 self->version_string = NULL;
994 g_free (self->platform);
995 self->platform = NULL;
997 G_OBJECT_CLASS (mxf_metadata_identification_parent_class)->finalize (object);
1001 mxf_metadata_identification_handle_tag (MXFMetadataBase * metadata,
1002 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
1005 MXFMetadataIdentification *self = MXF_METADATA_IDENTIFICATION (metadata);
1006 gboolean ret = TRUE;
1007 #ifndef GST_DISABLE_GST_DEBUG
1015 memcpy (&self->this_generation_uid, tag_data, 16);
1016 GST_DEBUG (" this generation uid = %s",
1017 mxf_uuid_to_string (&self->this_generation_uid, str));
1020 self->company_name = mxf_utf16_to_utf8 (tag_data, tag_size);
1021 GST_DEBUG (" company name = %s", GST_STR_NULL (self->company_name));
1024 self->product_name = mxf_utf16_to_utf8 (tag_data, tag_size);
1025 GST_DEBUG (" product name = %s", GST_STR_NULL (self->product_name));
1028 if (!mxf_product_version_parse (&self->product_version,
1029 tag_data, tag_size))
1031 GST_DEBUG (" product version = %u.%u.%u.%u.%u",
1032 self->product_version.major,
1033 self->product_version.minor,
1034 self->product_version.patch,
1035 self->product_version.build, self->product_version.release);
1038 self->version_string = mxf_utf16_to_utf8 (tag_data, tag_size);
1039 GST_DEBUG (" version string = %s", GST_STR_NULL (self->version_string));
1044 memcpy (&self->product_uid, tag_data, 16);
1045 GST_DEBUG (" product uid = %s",
1046 mxf_uuid_to_string (&self->product_uid, str));
1049 if (!mxf_timestamp_parse (&self->modification_date, tag_data, tag_size))
1051 GST_DEBUG (" modification date = %s",
1052 mxf_timestamp_to_string (&self->modification_date, str));
1055 if (!mxf_product_version_parse (&self->toolkit_version,
1056 tag_data, tag_size))
1058 GST_DEBUG (" toolkit version = %u.%u.%u.%u.%u",
1059 self->toolkit_version.major,
1060 self->toolkit_version.minor,
1061 self->toolkit_version.patch,
1062 self->toolkit_version.build, self->toolkit_version.release);
1065 self->platform = mxf_utf16_to_utf8 (tag_data, tag_size);
1066 GST_DEBUG (" platform = %s", GST_STR_NULL (self->platform));
1070 MXF_METADATA_BASE_CLASS
1071 (mxf_metadata_identification_parent_class)->handle_tag (metadata,
1072 primer, tag, tag_data, tag_size);
1079 GST_ERROR ("Invalid identification local tag 0x%04x of size %u", tag,
1085 static GstStructure *
1086 mxf_metadata_identification_to_structure (MXFMetadataBase * m)
1089 MXF_METADATA_BASE_CLASS
1090 (mxf_metadata_identification_parent_class)->to_structure (m);
1091 MXFMetadataIdentification *self = MXF_METADATA_IDENTIFICATION (m);
1094 if (!mxf_uuid_is_zero (&self->this_generation_uid)) {
1095 mxf_uuid_to_string (&self->this_generation_uid, str);
1096 gst_structure_id_set (ret, MXF_QUARK (THIS_GENERATION_UID), G_TYPE_STRING,
1100 if (self->company_name)
1101 gst_structure_id_set (ret, MXF_QUARK (COMPANY_NAME), G_TYPE_STRING,
1102 self->company_name, NULL);
1104 if (self->product_name)
1105 gst_structure_id_set (ret, MXF_QUARK (PRODUCT_NAME), G_TYPE_STRING,
1106 self->product_name, NULL);
1108 if (self->product_version.major ||
1109 self->product_version.minor ||
1110 self->product_version.patch ||
1111 self->product_version.build || self->product_version.release) {
1112 g_snprintf (str, 48, "%u.%u.%u.%u.%u", self->product_version.major,
1113 self->product_version.minor,
1114 self->product_version.patch,
1115 self->product_version.build, self->product_version.release);
1116 gst_structure_id_set (ret, MXF_QUARK (PRODUCT_VERSION), G_TYPE_STRING, str,
1120 if (self->version_string)
1121 gst_structure_id_set (ret, MXF_QUARK (VERSION_STRING), G_TYPE_STRING,
1122 self->version_string, NULL);
1124 if (!mxf_uuid_is_zero (&self->product_uid)) {
1125 mxf_uuid_to_string (&self->product_uid, str);
1126 gst_structure_id_set (ret, MXF_QUARK (PRODUCT_UID), G_TYPE_STRING, str,
1130 if (!mxf_timestamp_is_unknown (&self->modification_date)) {
1131 mxf_timestamp_to_string (&self->modification_date, str);
1132 gst_structure_id_set (ret, MXF_QUARK (MODIFICATION_DATE), G_TYPE_STRING,
1136 if (self->toolkit_version.major ||
1137 self->toolkit_version.minor ||
1138 self->toolkit_version.patch ||
1139 self->toolkit_version.build || self->toolkit_version.release) {
1140 g_snprintf (str, 48, "%u.%u.%u.%u.%u", self->toolkit_version.major,
1141 self->toolkit_version.minor,
1142 self->toolkit_version.patch,
1143 self->toolkit_version.build, self->toolkit_version.release);
1144 gst_structure_id_set (ret, MXF_QUARK (TOOLKIT_VERSION), G_TYPE_STRING, str,
1149 gst_structure_id_set (ret, MXF_QUARK (PLATFORM), G_TYPE_STRING,
1150 self->platform, NULL);
1156 mxf_metadata_identification_write_tags (MXFMetadataBase * m,
1157 MXFPrimerPack * primer)
1159 MXFMetadataIdentification *self = MXF_METADATA_IDENTIFICATION (m);
1161 MXF_METADATA_BASE_CLASS
1162 (mxf_metadata_identification_parent_class)->write_tags (m, primer);
1165 if (self->company_name) {
1166 t = g_slice_new0 (MXFLocalTag);
1167 memcpy (&t->ul, MXF_UL (COMPANY_NAME), 16);
1168 t->data = mxf_utf8_to_utf16 (self->company_name, &t->size);
1169 mxf_primer_pack_add_mapping (primer, 0x3c01, &t->ul);
1170 ret = g_list_prepend (ret, t);
1173 if (self->product_name) {
1174 t = g_slice_new0 (MXFLocalTag);
1175 memcpy (&t->ul, MXF_UL (PRODUCT_NAME), 16);
1176 t->data = mxf_utf8_to_utf16 (self->product_name, &t->size);
1177 mxf_primer_pack_add_mapping (primer, 0x3c02, &t->ul);
1178 ret = g_list_prepend (ret, t);
1181 if (!mxf_product_version_is_valid (&self->product_version)) {
1182 t = g_slice_new0 (MXFLocalTag);
1183 memcpy (&t->ul, MXF_UL (PRODUCT_VERSION), 16);
1185 t->data = g_slice_alloc (t->size);
1187 mxf_product_version_write (&self->product_version, t->data);
1188 mxf_primer_pack_add_mapping (primer, 0x3c03, &t->ul);
1189 ret = g_list_prepend (ret, t);
1192 if (self->version_string) {
1193 t = g_slice_new0 (MXFLocalTag);
1194 memcpy (&t->ul, MXF_UL (VERSION_STRING), 16);
1195 t->data = mxf_utf8_to_utf16 (self->version_string, &t->size);
1196 mxf_primer_pack_add_mapping (primer, 0x3c04, &t->ul);
1197 ret = g_list_prepend (ret, t);
1200 if (!mxf_uuid_is_zero (&self->product_uid)) {
1201 t = g_slice_new0 (MXFLocalTag);
1202 memcpy (&t->ul, MXF_UL (PRODUCT_UID), 16);
1204 t->data = g_slice_alloc (t->size);
1206 memcpy (t->data, &self->product_uid, 16);
1207 mxf_primer_pack_add_mapping (primer, 0x3c05, &t->ul);
1208 ret = g_list_prepend (ret, t);
1211 if (!mxf_timestamp_is_unknown (&self->modification_date)) {
1212 t = g_slice_new0 (MXFLocalTag);
1213 memcpy (&t->ul, MXF_UL (MODIFICATION_DATE), 16);
1215 t->data = g_slice_alloc (t->size);
1217 mxf_timestamp_write (&self->modification_date, t->data);
1218 mxf_primer_pack_add_mapping (primer, 0x3c06, &t->ul);
1219 ret = g_list_prepend (ret, t);
1222 if (!mxf_product_version_is_valid (&self->toolkit_version)) {
1223 t = g_slice_new0 (MXFLocalTag);
1224 memcpy (&t->ul, MXF_UL (TOOLKIT_VERSION), 16);
1226 t->data = g_slice_alloc (t->size);
1228 mxf_product_version_write (&self->toolkit_version, t->data);
1229 mxf_primer_pack_add_mapping (primer, 0x3c07, &t->ul);
1230 ret = g_list_prepend (ret, t);
1233 if (self->platform) {
1234 t = g_slice_new0 (MXFLocalTag);
1235 memcpy (&t->ul, MXF_UL (PLATFORM), 16);
1236 t->data = mxf_utf8_to_utf16 (self->platform, &t->size);
1237 mxf_primer_pack_add_mapping (primer, 0x3c08, &t->ul);
1238 ret = g_list_prepend (ret, t);
1241 if (!mxf_uuid_is_zero (&self->this_generation_uid)) {
1242 t = g_slice_new0 (MXFLocalTag);
1243 memcpy (&t->ul, MXF_UL (THIS_GENERATION_UID), 16);
1245 t->data = g_slice_alloc (t->size);
1247 memcpy (t->data, &self->this_generation_uid, 16);
1248 mxf_primer_pack_add_mapping (primer, 0x3c09, &t->ul);
1249 ret = g_list_prepend (ret, t);
1256 mxf_metadata_identification_init (MXFMetadataIdentification * self)
1262 mxf_metadata_identification_class_init (MXFMetadataIdentificationClass * klass)
1264 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
1265 GObjectClass *object_class = (GObjectClass *) klass;
1266 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
1268 object_class->finalize = mxf_metadata_identification_finalize;
1269 metadata_base_class->handle_tag = mxf_metadata_identification_handle_tag;
1270 metadata_base_class->name_quark = MXF_QUARK (IDENTIFICATION);
1271 metadata_base_class->to_structure = mxf_metadata_identification_to_structure;
1272 metadata_base_class->write_tags = mxf_metadata_identification_write_tags;
1273 metadata_class->type = 0x0130;
1276 G_DEFINE_TYPE (MXFMetadataContentStorage, mxf_metadata_content_storage,
1280 mxf_metadata_content_storage_finalize (GObject * object)
1282 MXFMetadataContentStorage *self = MXF_METADATA_CONTENT_STORAGE (object);
1284 g_free (self->packages);
1285 self->packages = NULL;
1286 g_free (self->packages_uids);
1287 self->packages_uids = NULL;
1288 g_free (self->essence_container_data);
1289 self->essence_container_data = NULL;
1290 g_free (self->essence_container_data_uids);
1291 self->essence_container_data_uids = NULL;
1293 G_OBJECT_CLASS (mxf_metadata_content_storage_parent_class)->finalize (object);
1297 mxf_metadata_content_storage_handle_tag (MXFMetadataBase * metadata,
1298 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
1301 MXFMetadataContentStorage *self = MXF_METADATA_CONTENT_STORAGE (metadata);
1302 gboolean ret = TRUE;
1303 #ifndef GST_DISABLE_GST_DEBUG
1309 if (!mxf_uuid_array_parse (&self->packages_uids, &self->n_packages,
1310 tag_data, tag_size))
1312 GST_DEBUG (" number of packages = %u", self->n_packages);
1313 #ifndef GST_DISABLE_GST_DEBUG
1316 for (i = 0; i < self->n_packages; i++) {
1317 GST_DEBUG (" package %u = %s", i,
1318 mxf_uuid_to_string (&self->packages_uids[i], str));
1324 if (!mxf_uuid_array_parse (&self->essence_container_data_uids,
1325 &self->n_essence_container_data, tag_data, tag_size))
1328 GST_DEBUG (" number of essence container data = %u",
1329 self->n_essence_container_data);
1330 #ifndef GST_DISABLE_GST_DEBUG
1333 for (i = 0; i < self->n_essence_container_data; i++) {
1334 GST_DEBUG (" essence container data %u = %s", i,
1335 mxf_uuid_to_string (&self->essence_container_data_uids[i], str));
1342 MXF_METADATA_BASE_CLASS
1343 (mxf_metadata_content_storage_parent_class)->handle_tag (metadata,
1344 primer, tag, tag_data, tag_size);
1352 GST_ERROR ("Invalid content storage local tag 0x%04x of size %u", tag,
1359 mxf_metadata_content_storage_resolve (MXFMetadataBase * m,
1360 GHashTable * metadata)
1362 MXFMetadataContentStorage *self = MXF_METADATA_CONTENT_STORAGE (m);
1363 MXFMetadataBase *current = NULL;
1365 gboolean have_package = FALSE;
1366 gboolean have_ecd = FALSE;
1367 #ifndef GST_DISABLE_GST_DEBUG
1372 memset (self->packages, 0, sizeof (gpointer) * self->n_packages);
1374 self->packages = g_new0 (MXFMetadataGenericPackage *, self->n_packages);
1376 for (i = 0; i < self->n_packages; i++) {
1377 current = g_hash_table_lookup (metadata, &self->packages_uids[i]);
1378 if (current && MXF_IS_METADATA_GENERIC_PACKAGE (current)) {
1379 if (mxf_metadata_base_resolve (current, metadata)) {
1380 self->packages[i] = MXF_METADATA_GENERIC_PACKAGE (current);
1381 have_package = TRUE;
1383 GST_ERROR ("Couldn't resolve package %s",
1384 mxf_uuid_to_string (&self->packages_uids[i], str));
1387 GST_ERROR ("Package %s not found",
1388 mxf_uuid_to_string (&self->packages_uids[i], str));
1392 if (self->essence_container_data)
1393 memset (self->essence_container_data, 0,
1394 sizeof (gpointer) * self->n_essence_container_data);
1396 self->essence_container_data =
1397 g_new0 (MXFMetadataEssenceContainerData *,
1398 self->n_essence_container_data);
1399 for (i = 0; i < self->n_essence_container_data; i++) {
1401 g_hash_table_lookup (metadata, &self->essence_container_data_uids[i]);
1402 if (current && MXF_IS_METADATA_ESSENCE_CONTAINER_DATA (current)) {
1403 if (mxf_metadata_base_resolve (current, metadata)) {
1404 self->essence_container_data[i] =
1405 MXF_METADATA_ESSENCE_CONTAINER_DATA (current);
1408 GST_ERROR ("Couldn't resolve essence container data %s",
1409 mxf_uuid_to_string (&self->essence_container_data_uids[i], str));
1412 GST_ERROR ("Essence container data %s not found",
1413 mxf_uuid_to_string (&self->essence_container_data_uids[i], str));
1417 if (!have_package) {
1418 GST_ERROR ("Couldn't resolve any package");
1420 } else if (!have_ecd) {
1421 GST_ERROR ("Couldn't resolve any essence container data");
1426 MXF_METADATA_BASE_CLASS
1427 (mxf_metadata_content_storage_parent_class)->resolve (m, metadata);
1430 static GstStructure *
1431 mxf_metadata_content_storage_to_structure (MXFMetadataBase * m)
1434 MXF_METADATA_BASE_CLASS
1435 (mxf_metadata_content_storage_parent_class)->to_structure (m);
1436 MXFMetadataContentStorage *self = MXF_METADATA_CONTENT_STORAGE (m);
1439 if (self->n_packages > 0) {
1444 g_value_init (&arr, GST_TYPE_ARRAY);
1446 for (i = 0; i < self->n_packages; i++) {
1449 if (self->packages[i] == NULL)
1452 g_value_init (&val, GST_TYPE_STRUCTURE);
1454 s = mxf_metadata_base_to_structure (MXF_METADATA_BASE (self->packages
1456 gst_value_set_structure (&val, s);
1457 gst_structure_free (s);
1458 gst_value_array_append_value (&arr, &val);
1459 g_value_unset (&val);
1462 if (gst_value_array_get_size (&arr) > 0)
1463 gst_structure_id_set_value (ret, MXF_QUARK (PACKAGES), &arr);
1465 g_value_unset (&arr);
1468 if (self->n_essence_container_data > 0) {
1473 g_value_init (&arr, GST_TYPE_ARRAY);
1475 for (i = 0; i < self->n_essence_container_data; i++) {
1478 if (self->essence_container_data[i] == NULL)
1481 g_value_init (&val, GST_TYPE_STRUCTURE);
1483 s = mxf_metadata_base_to_structure (MXF_METADATA_BASE
1484 (self->essence_container_data[i]));
1485 gst_value_set_structure (&val, s);
1486 gst_structure_free (s);
1487 gst_value_array_append_value (&arr, &val);
1488 g_value_unset (&val);
1491 if (gst_value_array_get_size (&arr) > 0)
1492 gst_structure_id_set_value (ret, MXF_QUARK (ESSENCE_CONTAINER_DATA),
1495 g_value_unset (&arr);
1502 mxf_metadata_content_storage_write_tags (MXFMetadataBase * m,
1503 MXFPrimerPack * primer)
1505 MXFMetadataContentStorage *self = MXF_METADATA_CONTENT_STORAGE (m);
1507 MXF_METADATA_BASE_CLASS
1508 (mxf_metadata_content_storage_parent_class)->write_tags (m, primer);
1512 if (self->packages) {
1513 t = g_slice_new0 (MXFLocalTag);
1514 memcpy (&t->ul, MXF_UL (PACKAGES), 16);
1515 t->size = 8 + 16 * self->n_packages;
1516 t->data = g_slice_alloc0 (t->size);
1518 GST_WRITE_UINT32_BE (t->data, self->n_packages);
1519 GST_WRITE_UINT32_BE (t->data + 4, 16);
1520 for (i = 0; i < self->n_packages; i++) {
1521 if (!self->packages[i])
1524 memcpy (t->data + 8 + i * 16,
1525 &MXF_METADATA_BASE (self->packages[i])->instance_uid, 16);
1528 mxf_primer_pack_add_mapping (primer, 0x1901, &t->ul);
1529 ret = g_list_prepend (ret, t);
1532 if (self->essence_container_data) {
1533 t = g_slice_new0 (MXFLocalTag);
1534 memcpy (&t->ul, MXF_UL (ESSENCE_CONTAINER_DATA), 16);
1535 t->size = 8 + 16 * self->n_essence_container_data;
1536 t->data = g_slice_alloc0 (t->size);
1538 GST_WRITE_UINT32_BE (t->data, self->n_essence_container_data);
1539 GST_WRITE_UINT32_BE (t->data + 4, 16);
1540 for (i = 0; i < self->n_essence_container_data; i++) {
1541 if (!self->essence_container_data[i])
1544 memcpy (t->data + 8 + i * 16,
1545 &MXF_METADATA_BASE (self->essence_container_data[i])->instance_uid,
1549 mxf_primer_pack_add_mapping (primer, 0x1902, &t->ul);
1550 ret = g_list_prepend (ret, t);
1557 mxf_metadata_content_storage_init (MXFMetadataContentStorage * self)
1563 mxf_metadata_content_storage_class_init (MXFMetadataContentStorageClass * klass)
1565 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
1566 GObjectClass *object_class = (GObjectClass *) klass;
1567 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
1569 object_class->finalize = mxf_metadata_content_storage_finalize;
1570 metadata_base_class->handle_tag = mxf_metadata_content_storage_handle_tag;
1571 metadata_base_class->resolve = mxf_metadata_content_storage_resolve;
1572 metadata_base_class->name_quark = MXF_QUARK (CONTENT_STORAGE);
1573 metadata_base_class->to_structure = mxf_metadata_content_storage_to_structure;
1574 metadata_base_class->write_tags = mxf_metadata_content_storage_write_tags;
1575 metadata_class->type = 0x0118;
1578 G_DEFINE_TYPE (MXFMetadataEssenceContainerData,
1579 mxf_metadata_essence_container_data, MXF_TYPE_METADATA);
1582 mxf_metadata_essence_container_data_handle_tag (MXFMetadataBase * metadata,
1583 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
1586 MXFMetadataEssenceContainerData *self =
1587 MXF_METADATA_ESSENCE_CONTAINER_DATA (metadata);
1588 gboolean ret = TRUE;
1589 #ifndef GST_DISABLE_GST_DEBUG
1597 memcpy (&self->linked_package_uid, tag_data, 32);
1598 GST_DEBUG (" linked package = %s",
1599 mxf_umid_to_string (&self->linked_package_uid, str));
1604 self->index_sid = GST_READ_UINT32_BE (tag_data);
1605 GST_DEBUG (" index sid = %u", self->index_sid);
1610 self->body_sid = GST_READ_UINT32_BE (tag_data);
1611 GST_DEBUG (" body sid = %u", self->body_sid);
1615 MXF_METADATA_BASE_CLASS
1616 (mxf_metadata_essence_container_data_parent_class)->handle_tag
1617 (metadata, primer, tag, tag_data, tag_size);
1625 GST_ERROR ("Invalid essence container data local tag 0x%04x of size %u", tag,
1632 mxf_metadata_essence_container_data_resolve (MXFMetadataBase * m,
1633 GHashTable * metadata)
1635 MXFMetadataEssenceContainerData *self =
1636 MXF_METADATA_ESSENCE_CONTAINER_DATA (m);
1637 MXFMetadataBase *current = NULL;
1638 GHashTableIter iter;
1639 #ifndef GST_DISABLE_GST_DEBUG
1643 g_hash_table_iter_init (&iter, metadata);
1645 while (g_hash_table_iter_next (&iter, NULL, (gpointer) & current)) {
1646 if (MXF_IS_METADATA_SOURCE_PACKAGE (current)) {
1647 MXFMetadataSourcePackage *package = MXF_METADATA_SOURCE_PACKAGE (current);
1649 if (mxf_umid_is_equal (&package->parent.package_uid,
1650 &self->linked_package_uid)) {
1651 if (mxf_metadata_base_resolve (current, metadata)) {
1652 self->linked_package = package;
1654 GST_ERROR ("Couldn't resolve linked package %s",
1655 mxf_umid_to_string (&self->linked_package_uid, str));
1662 if (!self->linked_package) {
1663 GST_ERROR ("Couldn't resolve or find linked package %s",
1664 mxf_umid_to_string (&self->linked_package_uid, str));
1669 MXF_METADATA_BASE_CLASS
1670 (mxf_metadata_essence_container_data_parent_class)->resolve (m, metadata);
1673 static GstStructure *
1674 mxf_metadata_essence_container_data_to_structure (MXFMetadataBase * m)
1677 MXF_METADATA_BASE_CLASS
1678 (mxf_metadata_essence_container_data_parent_class)->to_structure (m);
1679 MXFMetadataEssenceContainerData *self =
1680 MXF_METADATA_ESSENCE_CONTAINER_DATA (m);
1683 if (!mxf_umid_is_zero (&self->linked_package_uid)) {
1684 mxf_umid_to_string (&self->linked_package_uid, str);
1685 gst_structure_id_set (ret, MXF_QUARK (LINKED_PACKAGE), G_TYPE_STRING, str,
1689 gst_structure_id_set (ret, MXF_QUARK (INDEX_SID), G_TYPE_UINT,
1690 self->index_sid, MXF_QUARK (BODY_SID), G_TYPE_UINT, self->body_sid, NULL);
1697 mxf_metadata_essence_container_data_write_tags (MXFMetadataBase * m,
1698 MXFPrimerPack * primer)
1700 MXFMetadataEssenceContainerData *self =
1701 MXF_METADATA_ESSENCE_CONTAINER_DATA (m);
1703 MXF_METADATA_BASE_CLASS
1704 (mxf_metadata_essence_container_data_parent_class)->write_tags (m,
1708 t = g_slice_new0 (MXFLocalTag);
1709 memcpy (&t->ul, MXF_UL (LINKED_PACKAGE_UID), 16);
1711 t->data = g_slice_alloc0 (32);
1713 if (self->linked_package)
1714 memcpy (t->data, &self->linked_package->parent.package_uid, 32);
1715 mxf_primer_pack_add_mapping (primer, 0x2701, &t->ul);
1716 ret = g_list_prepend (ret, t);
1718 t = g_slice_new0 (MXFLocalTag);
1719 memcpy (&t->ul, MXF_UL (BODY_SID), 16);
1721 t->data = g_slice_alloc (4);
1723 GST_WRITE_UINT32_BE (t->data, self->body_sid);
1724 mxf_primer_pack_add_mapping (primer, 0x3f07, &t->ul);
1725 ret = g_list_prepend (ret, t);
1727 if (self->index_sid) {
1728 t = g_slice_new0 (MXFLocalTag);
1729 memcpy (&t->ul, MXF_UL (INDEX_SID), 16);
1731 t->data = g_slice_alloc (4);
1733 GST_WRITE_UINT32_BE (t->data, self->index_sid);
1734 mxf_primer_pack_add_mapping (primer, 0x3f06, &t->ul);
1735 ret = g_list_prepend (ret, t);
1742 mxf_metadata_essence_container_data_init (MXFMetadataEssenceContainerData *
1749 mxf_metadata_essence_container_data_class_init
1750 (MXFMetadataEssenceContainerDataClass * klass)
1752 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
1753 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
1755 metadata_base_class->handle_tag =
1756 mxf_metadata_essence_container_data_handle_tag;
1757 metadata_base_class->resolve = mxf_metadata_essence_container_data_resolve;
1758 metadata_base_class->name_quark = MXF_QUARK (ESSENCE_CONTAINER_DATA);
1759 metadata_base_class->to_structure =
1760 mxf_metadata_essence_container_data_to_structure;
1761 metadata_base_class->write_tags =
1762 mxf_metadata_essence_container_data_write_tags;
1763 metadata_class->type = 0x0123;
1766 G_DEFINE_ABSTRACT_TYPE (MXFMetadataGenericPackage, mxf_metadata_generic_package,
1770 mxf_metadata_generic_package_finalize (GObject * object)
1772 MXFMetadataGenericPackage *self = MXF_METADATA_GENERIC_PACKAGE (object);
1774 g_free (self->name);
1776 g_free (self->tracks_uids);
1777 self->tracks_uids = NULL;
1779 g_free (self->tracks);
1780 self->tracks = NULL;
1782 G_OBJECT_CLASS (mxf_metadata_generic_package_parent_class)->finalize (object);
1786 mxf_metadata_generic_package_handle_tag (MXFMetadataBase * metadata,
1787 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
1790 MXFMetadataGenericPackage *self = MXF_METADATA_GENERIC_PACKAGE (metadata);
1791 gboolean ret = TRUE;
1792 #ifndef GST_DISABLE_GST_DEBUG
1800 memcpy (&self->package_uid, tag_data, 32);
1801 GST_DEBUG (" UMID = %s", mxf_umid_to_string (&self->package_uid, str));
1804 self->name = mxf_utf16_to_utf8 (tag_data, tag_size);
1805 GST_DEBUG (" name = %s", GST_STR_NULL (self->name));
1808 if (!mxf_timestamp_parse (&self->package_creation_date,
1809 tag_data, tag_size))
1811 GST_DEBUG (" creation date = %s",
1812 mxf_timestamp_to_string (&self->package_creation_date, str));
1815 if (!mxf_timestamp_parse (&self->package_modified_date,
1816 tag_data, tag_size))
1818 GST_DEBUG (" modification date = %s",
1819 mxf_timestamp_to_string (&self->package_modified_date, str));
1822 if (!mxf_uuid_array_parse (&self->tracks_uids, &self->n_tracks, tag_data,
1826 GST_DEBUG (" number of tracks = %u", self->n_tracks);
1827 #ifndef GST_DISABLE_GST_DEBUG
1830 for (i = 0; i < self->n_tracks; i++) {
1831 GST_DEBUG (" track %u = %s", i,
1832 mxf_uuid_to_string (&self->tracks_uids[i], str));
1839 MXF_METADATA_BASE_CLASS
1840 (mxf_metadata_generic_package_parent_class)->handle_tag (metadata,
1841 primer, tag, tag_data, tag_size);
1849 GST_ERROR ("Invalid generic package local tag 0x%04x of size %u", tag,
1856 mxf_metadata_generic_package_resolve (MXFMetadataBase * m,
1857 GHashTable * metadata)
1859 MXFMetadataGenericPackage *self = MXF_METADATA_GENERIC_PACKAGE (m);
1860 MXFMetadataBase *current = NULL;
1862 gboolean have_track = FALSE;
1863 #ifndef GST_DISABLE_GST_DEBUG
1868 memset (self->tracks, 0, sizeof (gpointer) * self->n_tracks);
1870 self->tracks = g_new0 (MXFMetadataTrack *, self->n_tracks);
1871 for (i = 0; i < self->n_tracks; i++) {
1872 current = g_hash_table_lookup (metadata, &self->tracks_uids[i]);
1873 if (current && MXF_IS_METADATA_TRACK (current)) {
1874 if (mxf_metadata_base_resolve (current, metadata)) {
1875 MXFMetadataTrack *track = MXF_METADATA_TRACK (current);
1877 self->tracks[i] = track;
1879 if ((track->type & 0xf0) == 0x10)
1880 self->n_timecode_tracks++;
1881 else if ((track->type & 0xf0) == 0x20)
1882 self->n_metadata_tracks++;
1883 else if ((track->type & 0xf0) == 0x30)
1884 self->n_essence_tracks++;
1885 else if ((track->type & 0xf0) == 0x40)
1886 self->n_other_tracks++;
1888 GST_ERROR ("Track %s couldn't be resolved",
1889 mxf_uuid_to_string (&self->tracks_uids[i], str));
1892 GST_ERROR ("Track %s not found",
1893 mxf_uuid_to_string (&self->tracks_uids[i], str));
1898 GST_ERROR ("Couldn't resolve a track");
1903 MXF_METADATA_BASE_CLASS
1904 (mxf_metadata_generic_package_parent_class)->resolve (m, metadata);
1907 static GstStructure *
1908 mxf_metadata_generic_package_to_structure (MXFMetadataBase * m)
1911 MXF_METADATA_BASE_CLASS
1912 (mxf_metadata_generic_package_parent_class)->to_structure (m);
1913 MXFMetadataGenericPackage *self = MXF_METADATA_GENERIC_PACKAGE (m);
1917 mxf_umid_to_string (&self->package_uid, str);
1918 gst_structure_id_set (ret, MXF_QUARK (PACKAGE_UID), G_TYPE_STRING, str, NULL);
1921 gst_structure_id_set (ret, MXF_QUARK (NAME), G_TYPE_STRING, self->name,
1924 if (!mxf_timestamp_is_unknown (&self->package_creation_date)) {
1925 mxf_timestamp_to_string (&self->package_creation_date, str);
1926 gst_structure_id_set (ret, MXF_QUARK (PACKAGE_CREATION_DATE), G_TYPE_STRING,
1930 if (!mxf_timestamp_is_unknown (&self->package_modified_date)) {
1931 mxf_timestamp_to_string (&self->package_modified_date, str);
1932 gst_structure_id_set (ret, MXF_QUARK (PACKAGE_MODIFIED_DATE), G_TYPE_STRING,
1936 if (self->n_tracks > 0) {
1941 g_value_init (&arr, GST_TYPE_ARRAY);
1943 for (i = 0; i < self->n_tracks; i++) {
1946 if (self->tracks[i] == NULL)
1949 g_value_init (&val, GST_TYPE_STRUCTURE);
1951 s = mxf_metadata_base_to_structure (MXF_METADATA_BASE (self->tracks[i]));
1952 gst_value_set_structure (&val, s);
1953 gst_structure_free (s);
1954 gst_value_array_append_value (&arr, &val);
1955 g_value_unset (&val);
1958 if (gst_value_array_get_size (&arr) > 0)
1959 gst_structure_id_set_value (ret, MXF_QUARK (TRACKS), &arr);
1961 g_value_unset (&arr);
1968 mxf_metadata_generic_package_write_tags (MXFMetadataBase * m,
1969 MXFPrimerPack * primer)
1971 MXFMetadataGenericPackage *self = MXF_METADATA_GENERIC_PACKAGE (m);
1973 MXF_METADATA_BASE_CLASS
1974 (mxf_metadata_generic_package_parent_class)->write_tags (m, primer);
1977 t = g_slice_new0 (MXFLocalTag);
1978 memcpy (&t->ul, MXF_UL (PACKAGE_UID), 16);
1980 t->data = g_slice_alloc (t->size);
1982 memcpy (t->data, &self->package_uid, 32);
1983 mxf_primer_pack_add_mapping (primer, 0x4401, &t->ul);
1984 ret = g_list_prepend (ret, t);
1987 t = g_slice_new0 (MXFLocalTag);
1988 memcpy (&t->ul, MXF_UL (PACKAGE_NAME), 16);
1989 t->data = mxf_utf8_to_utf16 (self->name, &t->size);
1990 mxf_primer_pack_add_mapping (primer, 0x4402, &t->ul);
1991 ret = g_list_prepend (ret, t);
1994 t = g_slice_new0 (MXFLocalTag);
1995 memcpy (&t->ul, MXF_UL (PACKAGE_CREATION_DATE), 16);
1997 t->data = g_slice_alloc (t->size);
1999 mxf_timestamp_write (&self->package_creation_date, t->data);
2000 mxf_primer_pack_add_mapping (primer, 0x4405, &t->ul);
2001 ret = g_list_prepend (ret, t);
2003 t = g_slice_new0 (MXFLocalTag);
2004 memcpy (&t->ul, MXF_UL (PACKAGE_MODIFIED_DATE), 16);
2006 t->data = g_slice_alloc (t->size);
2008 mxf_timestamp_write (&self->package_modified_date, t->data);
2009 mxf_primer_pack_add_mapping (primer, 0x4404, &t->ul);
2010 ret = g_list_prepend (ret, t);
2015 t = g_slice_new0 (MXFLocalTag);
2016 memcpy (&t->ul, MXF_UL (TRACKS), 16);
2017 t->size = 8 + 16 * self->n_tracks;
2018 t->data = g_slice_alloc0 (t->size);
2020 GST_WRITE_UINT32_BE (t->data, self->n_tracks);
2021 GST_WRITE_UINT32_BE (t->data + 4, 16);
2022 for (i = 0; i < self->n_tracks; i++) {
2023 if (!self->tracks[i])
2026 memcpy (t->data + 8 + 16 * i,
2027 &MXF_METADATA_BASE (self->tracks[i])->instance_uid, 16);
2029 mxf_primer_pack_add_mapping (primer, 0x4403, &t->ul);
2030 ret = g_list_prepend (ret, t);
2037 mxf_metadata_generic_package_init (MXFMetadataGenericPackage * self)
2043 mxf_metadata_generic_package_class_init (MXFMetadataGenericPackageClass * klass)
2045 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
2046 GObjectClass *object_class = (GObjectClass *) klass;
2048 object_class->finalize = mxf_metadata_generic_package_finalize;
2049 metadata_base_class->handle_tag = mxf_metadata_generic_package_handle_tag;
2050 metadata_base_class->resolve = mxf_metadata_generic_package_resolve;
2051 metadata_base_class->to_structure = mxf_metadata_generic_package_to_structure;
2052 metadata_base_class->write_tags = mxf_metadata_generic_package_write_tags;
2055 G_DEFINE_TYPE (MXFMetadataMaterialPackage, mxf_metadata_material_package,
2056 MXF_TYPE_METADATA_GENERIC_PACKAGE);
2059 mxf_metadata_material_package_resolve (MXFMetadataBase * m,
2060 GHashTable * metadata)
2063 MXF_METADATA_BASE_CLASS
2064 (mxf_metadata_material_package_parent_class)->resolve (m, metadata);
2065 MXFMetadataGenericPackage *self = MXF_METADATA_GENERIC_PACKAGE (m);
2072 for (i = 0; i < self->n_tracks; i++) {
2073 MXFMetadataTrack *track = self->tracks[i];
2074 MXFMetadataSequence *sequence;
2080 sequence = track->sequence;
2082 if (!sequence || !sequence->structural_components)
2085 for (j = 0; j < sequence->n_structural_components; j++) {
2086 MXFMetadataSourceClip *sc;
2087 MXFMetadataTimelineTrack *st = NULL;
2090 if (!sequence->structural_components[j]
2091 || !MXF_IS_METADATA_SOURCE_CLIP (sequence->structural_components[j]))
2094 sc = MXF_METADATA_SOURCE_CLIP (sequence->structural_components[j]);
2096 if (!sc->source_package) {
2097 GST_ERROR ("Material package track %u without resolved source package",
2103 if (!mxf_metadata_base_resolve (MXF_METADATA_BASE (sc->source_package),
2105 GST_ERROR ("Couldn't resolve source package for track %u", i);
2110 sc->source_package->top_level = TRUE;
2111 for (k = 0; k < sc->source_package->parent.n_tracks; k++) {
2112 MXFMetadataTimelineTrack *tmp;
2114 if (!sc->source_package->parent.tracks[k] ||
2115 !MXF_IS_METADATA_TIMELINE_TRACK (sc->source_package->parent.
2120 MXF_METADATA_TIMELINE_TRACK (sc->source_package->parent.tracks[k]);
2121 if (tmp->parent.track_id == sc->source_track_id) {
2128 GST_ERROR ("Material package track %u without resolved source track",
2137 self->tracks[i] = NULL;
2141 GST_ERROR ("No tracks could be resolved");
2143 } else if (ntracks != self->n_tracks) {
2144 GST_WARNING ("Not all tracks could be resolved");
2151 mxf_metadata_material_package_init (MXFMetadataMaterialPackage * self)
2156 mxf_metadata_material_package_class_init (MXFMetadataMaterialPackageClass *
2159 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
2160 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
2162 metadata_base_class->resolve = mxf_metadata_material_package_resolve;
2163 metadata_base_class->name_quark = MXF_QUARK (MATERIAL_PACKAGE);
2164 metadata_class->type = 0x0136;
2167 G_DEFINE_TYPE (MXFMetadataSourcePackage, mxf_metadata_source_package,
2168 MXF_TYPE_METADATA_GENERIC_PACKAGE);
2171 mxf_metadata_source_package_handle_tag (MXFMetadataBase * metadata,
2172 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
2175 MXFMetadataSourcePackage *self = MXF_METADATA_SOURCE_PACKAGE (metadata);
2176 gboolean ret = TRUE;
2177 #ifndef GST_DISABLE_GST_DEBUG
2186 memcpy (&self->descriptor_uid, tag_data, 16);
2187 GST_DEBUG (" descriptor = %s",
2188 mxf_uuid_to_string (&self->descriptor_uid, str));
2192 MXF_METADATA_BASE_CLASS
2193 (mxf_metadata_source_package_parent_class)->handle_tag (metadata,
2194 primer, tag, tag_data, tag_size);
2202 GST_ERROR ("Invalid source package local tag 0x%04x of size %u", tag,
2209 mxf_metadata_source_package_resolve (MXFMetadataBase * m, GHashTable * metadata)
2211 MXFMetadataSourcePackage *self = MXF_METADATA_SOURCE_PACKAGE (m);
2212 MXFMetadataGenericPackage *package = MXF_METADATA_GENERIC_PACKAGE (m);
2213 MXFMetadataBase *current = NULL;
2216 MXFMetadataFileDescriptor *d;
2217 #ifndef GST_DISABLE_GST_DEBUG
2221 if (mxf_uuid_is_zero (&self->descriptor_uid))
2223 MXF_METADATA_BASE_CLASS
2224 (mxf_metadata_source_package_parent_class)->resolve (m, metadata);
2226 current = g_hash_table_lookup (metadata, &self->descriptor_uid);
2228 GST_ERROR ("Descriptor %s not found",
2229 mxf_uuid_to_string (&self->descriptor_uid, str));
2233 if (!mxf_metadata_base_resolve (MXF_METADATA_BASE (current), metadata)) {
2234 GST_ERROR ("Couldn't resolve descriptor %s",
2235 mxf_uuid_to_string (&self->descriptor_uid, str));
2239 self->descriptor = MXF_METADATA_GENERIC_DESCRIPTOR (current);
2242 MXF_METADATA_BASE_CLASS
2243 (mxf_metadata_source_package_parent_class)->resolve (m, metadata);
2245 if (!MXF_IS_METADATA_FILE_DESCRIPTOR (self->descriptor))
2248 d = MXF_METADATA_FILE_DESCRIPTOR (current);
2250 for (i = 0; i < package->n_tracks; i++) {
2251 if (!package->tracks[i])
2254 if (!MXF_IS_METADATA_MULTIPLE_DESCRIPTOR (d)) {
2255 if (d->linked_track_id == package->tracks[i]->track_id ||
2256 (d->linked_track_id == 0 && package->n_essence_tracks == 1 &&
2257 (package->tracks[i]->type & 0xf0) == 0x30)) {
2258 g_free (package->tracks[i]->descriptor);
2259 package->tracks[i]->descriptor =
2260 g_new0 (MXFMetadataFileDescriptor *, 1);
2261 package->tracks[i]->descriptor[0] = d;
2262 package->tracks[i]->n_descriptor = 1;
2266 guint n_descriptor = 0, j, k = 0;
2267 MXFMetadataMultipleDescriptor *md = MXF_METADATA_MULTIPLE_DESCRIPTOR (d);
2269 for (j = 0; j < md->n_sub_descriptors; j++) {
2270 MXFMetadataFileDescriptor *fd;
2272 if (!md->sub_descriptors[j] ||
2273 !MXF_METADATA_FILE_DESCRIPTOR (md->sub_descriptors[j]))
2276 fd = MXF_METADATA_FILE_DESCRIPTOR (md->sub_descriptors[j]);
2278 if (fd->linked_track_id == package->tracks[i]->track_id ||
2279 (fd->linked_track_id == 0 && package->n_essence_tracks == 1 &&
2280 (package->tracks[i]->type & 0xf0) == 0x30))
2284 g_free (package->tracks[i]->descriptor);
2285 package->tracks[i]->descriptor =
2286 g_new0 (MXFMetadataFileDescriptor *, n_descriptor);
2287 package->tracks[i]->n_descriptor = n_descriptor;
2289 for (j = 0; j < md->n_sub_descriptors; j++) {
2290 MXFMetadataFileDescriptor *fd;
2292 if (!md->sub_descriptors[j] ||
2293 !MXF_METADATA_FILE_DESCRIPTOR (md->sub_descriptors[j]))
2296 fd = MXF_METADATA_FILE_DESCRIPTOR (md->sub_descriptors[j]);
2298 if (fd->linked_track_id == package->tracks[i]->track_id ||
2299 (fd->linked_track_id == 0 && package->n_essence_tracks == 1 &&
2300 (package->tracks[i]->type & 0xf0) == 0x30)) {
2301 package->tracks[i]->descriptor[k] = fd;
2311 static GstStructure *
2312 mxf_metadata_source_package_to_structure (MXFMetadataBase * m)
2315 MXF_METADATA_BASE_CLASS
2316 (mxf_metadata_source_package_parent_class)->to_structure (m);
2317 MXFMetadataSourcePackage *self = MXF_METADATA_SOURCE_PACKAGE (m);
2320 if (!self->descriptor)
2323 s = mxf_metadata_base_to_structure (MXF_METADATA_BASE (self->descriptor));
2324 gst_structure_id_set (ret, MXF_QUARK (DESCRIPTOR), GST_TYPE_STRUCTURE, s,
2326 gst_structure_free (s);
2332 mxf_metadata_source_package_write_tags (MXFMetadataBase * m,
2333 MXFPrimerPack * primer)
2335 MXFMetadataSourcePackage *self = MXF_METADATA_SOURCE_PACKAGE (m);
2337 MXF_METADATA_BASE_CLASS
2338 (mxf_metadata_source_package_parent_class)->write_tags (m, primer);
2341 if (self->descriptor) {
2342 t = g_slice_new0 (MXFLocalTag);
2343 memcpy (&t->ul, MXF_UL (DESCRIPTOR), 16);
2345 t->data = g_slice_alloc (t->size);
2347 memcpy (t->data, &MXF_METADATA_BASE (self->descriptor)->instance_uid, 16);
2348 mxf_primer_pack_add_mapping (primer, 0x4701, &t->ul);
2349 ret = g_list_prepend (ret, t);
2356 mxf_metadata_source_package_init (MXFMetadataSourcePackage * self)
2362 mxf_metadata_source_package_class_init (MXFMetadataSourcePackageClass * klass)
2364 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
2365 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
2367 metadata_base_class->handle_tag = mxf_metadata_source_package_handle_tag;
2368 metadata_base_class->resolve = mxf_metadata_source_package_resolve;
2369 metadata_base_class->name_quark = MXF_QUARK (SOURCE_PACKAGE);
2370 metadata_base_class->to_structure = mxf_metadata_source_package_to_structure;
2371 metadata_base_class->write_tags = mxf_metadata_source_package_write_tags;
2372 metadata_class->type = 0x0137;
2375 G_DEFINE_ABSTRACT_TYPE (MXFMetadataTrack, mxf_metadata_track,
2379 mxf_metadata_track_finalize (GObject * object)
2381 MXFMetadataTrack *self = MXF_METADATA_TRACK (object);
2383 g_free (self->track_name);
2384 self->track_name = NULL;
2385 g_free (self->descriptor);
2386 self->descriptor = NULL;
2388 G_OBJECT_CLASS (mxf_metadata_track_parent_class)->finalize (object);
2392 mxf_metadata_track_handle_tag (MXFMetadataBase * metadata,
2393 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
2396 MXFMetadataTrack *self = MXF_METADATA_TRACK (metadata);
2397 gboolean ret = TRUE;
2398 #ifndef GST_DISABLE_GST_DEBUG
2406 self->track_id = GST_READ_UINT32_BE (tag_data);
2407 GST_DEBUG (" track id = %u", self->track_id);
2412 self->track_number = GST_READ_UINT32_BE (tag_data);
2413 GST_DEBUG (" track number = %u", self->track_number);
2416 self->track_name = mxf_utf16_to_utf8 (tag_data, tag_size);
2417 GST_DEBUG (" track name = %s", GST_STR_NULL (self->track_name));
2422 memcpy (&self->sequence_uid, tag_data, 16);
2423 GST_DEBUG (" sequence uid = %s",
2424 mxf_uuid_to_string (&self->sequence_uid, str));
2428 MXF_METADATA_BASE_CLASS (mxf_metadata_track_parent_class)->handle_tag
2429 (metadata, primer, tag, tag_data, tag_size);
2437 GST_ERROR ("Invalid track local tag 0x%04x of size %u", tag, tag_size);
2443 mxf_metadata_track_resolve (MXFMetadataBase * m, GHashTable * metadata)
2445 MXFMetadataTrack *self = MXF_METADATA_TRACK (m);
2446 MXFMetadataBase *current = NULL;
2448 #ifndef GST_DISABLE_GST_DEBUG
2452 current = g_hash_table_lookup (metadata, &self->sequence_uid);
2453 if (current && MXF_IS_METADATA_SEQUENCE (current)) {
2454 if (mxf_metadata_base_resolve (current, metadata)) {
2455 self->sequence = MXF_METADATA_SEQUENCE (current);
2457 GST_ERROR ("Couldn't resolve sequence %s",
2458 mxf_uuid_to_string (&self->sequence_uid, str));
2462 GST_ERROR ("Couldn't find sequence %s",
2463 mxf_uuid_to_string (&self->sequence_uid, str));
2468 mxf_metadata_track_identifier_parse (&self->sequence->data_definition);
2469 if (self->type == MXF_METADATA_TRACK_UNKNOWN) {
2470 MXFMetadataSequence *sequence = self->sequence;
2472 for (i = 0; i < sequence->n_structural_components; i++) {
2473 MXFMetadataStructuralComponent *component =
2474 sequence->structural_components[i];
2480 mxf_metadata_track_identifier_parse (&component->data_definition);
2481 if (self->type != MXF_METADATA_TRACK_UNKNOWN)
2486 return MXF_METADATA_BASE_CLASS (mxf_metadata_track_parent_class)->resolve (m,
2490 static GstStructure *
2491 mxf_metadata_track_to_structure (MXFMetadataBase * m)
2494 MXF_METADATA_BASE_CLASS (mxf_metadata_track_parent_class)->to_structure
2496 MXFMetadataTrack *self = MXF_METADATA_TRACK (m);
2498 gst_structure_id_set (ret, MXF_QUARK (TRACK_ID), G_TYPE_UINT, self->track_id,
2499 MXF_QUARK (TRACK_NUMBER), G_TYPE_UINT, self->track_number, NULL);
2501 if (self->track_name)
2502 gst_structure_id_set (ret, MXF_QUARK (TRACK_NAME), G_TYPE_STRING,
2503 self->track_name, NULL);
2505 if (self->sequence) {
2507 mxf_metadata_base_to_structure (MXF_METADATA_BASE (self->sequence));
2509 gst_structure_id_set (ret, MXF_QUARK (SEQUENCE), GST_TYPE_STRUCTURE, s,
2511 gst_structure_free (s);
2519 mxf_metadata_track_write_tags (MXFMetadataBase * m, MXFPrimerPack * primer)
2521 MXFMetadataTrack *self = MXF_METADATA_TRACK (m);
2523 MXF_METADATA_BASE_CLASS (mxf_metadata_track_parent_class)->write_tags (m,
2527 t = g_slice_new0 (MXFLocalTag);
2528 memcpy (&t->ul, MXF_UL (TRACK_ID), 16);
2530 t->data = g_slice_alloc (t->size);
2532 GST_WRITE_UINT32_BE (t->data, self->track_id);
2533 mxf_primer_pack_add_mapping (primer, 0x4801, &t->ul);
2534 ret = g_list_prepend (ret, t);
2536 t = g_slice_new0 (MXFLocalTag);
2537 memcpy (&t->ul, MXF_UL (TRACK_NUMBER), 16);
2539 t->data = g_slice_alloc (t->size);
2541 GST_WRITE_UINT32_BE (t->data, self->track_number);
2542 mxf_primer_pack_add_mapping (primer, 0x4804, &t->ul);
2543 ret = g_list_prepend (ret, t);
2545 if (self->track_name) {
2546 t = g_slice_new0 (MXFLocalTag);
2547 memcpy (&t->ul, MXF_UL (TRACK_NAME), 16);
2548 t->data = mxf_utf8_to_utf16 (self->track_name, &t->size);
2549 mxf_primer_pack_add_mapping (primer, 0x4802, &t->ul);
2550 ret = g_list_prepend (ret, t);
2553 t = g_slice_new0 (MXFLocalTag);
2554 memcpy (&t->ul, MXF_UL (SEQUENCE), 16);
2556 t->data = g_slice_alloc (t->size);
2558 memcpy (t->data, &MXF_METADATA_BASE (self->sequence)->instance_uid, 16);
2559 mxf_primer_pack_add_mapping (primer, 0x4803, &t->ul);
2560 ret = g_list_prepend (ret, t);
2566 mxf_metadata_track_init (MXFMetadataTrack * self)
2572 mxf_metadata_track_class_init (MXFMetadataTrackClass * klass)
2574 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
2575 GObjectClass *object_class = (GObjectClass *) klass;
2577 object_class->finalize = mxf_metadata_track_finalize;
2578 metadata_base_class->handle_tag = mxf_metadata_track_handle_tag;
2579 metadata_base_class->resolve = mxf_metadata_track_resolve;
2580 metadata_base_class->to_structure = mxf_metadata_track_to_structure;
2581 metadata_base_class->write_tags = mxf_metadata_track_write_tags;
2588 const MXFMetadataTrackType type;
2589 } mxf_metadata_track_identifier[] = {
2591 MXF_UL (TRACK_TIMECODE_12M_INACTIVE),
2592 MXF_METADATA_TRACK_TIMECODE_12M_INACTIVE}, {
2593 MXF_UL (TRACK_TIMECODE_12M_ACTIVE), MXF_METADATA_TRACK_TIMECODE_12M_ACTIVE}, {
2594 MXF_UL (TRACK_TIMECODE_309M), MXF_METADATA_TRACK_TIMECODE_309M}, {
2595 MXF_UL (TRACK_METADATA), MXF_METADATA_TRACK_METADATA}, {
2596 MXF_UL (TRACK_PICTURE_ESSENCE), MXF_METADATA_TRACK_PICTURE_ESSENCE}, {
2597 MXF_UL (TRACK_SOUND_ESSENCE), MXF_METADATA_TRACK_SOUND_ESSENCE}, {
2598 MXF_UL (TRACK_DATA_ESSENCE), MXF_METADATA_TRACK_DATA_ESSENCE}, {
2599 MXF_UL (TRACK_AUXILIARY_DATA), MXF_METADATA_TRACK_AUXILIARY_DATA}, {
2600 MXF_UL (TRACK_PARSED_TEXT), MXF_METADATA_TRACK_PARSED_TEXT},
2603 MXF_UL (TRACK_AVID_PICTURE_ESSENCE), MXF_METADATA_TRACK_PICTURE_ESSENCE}
2606 MXFMetadataTrackType
2607 mxf_metadata_track_identifier_parse (const MXFUL * track_identifier)
2611 for (i = 0; i < G_N_ELEMENTS (mxf_metadata_track_identifier); i++)
2612 if (mxf_ul_is_equal (mxf_metadata_track_identifier[i].ul, track_identifier))
2613 return mxf_metadata_track_identifier[i].type;
2615 return MXF_METADATA_TRACK_UNKNOWN;
2619 mxf_metadata_track_identifier_get (MXFMetadataTrackType type)
2623 for (i = 0; i < G_N_ELEMENTS (mxf_metadata_track_identifier); i++)
2624 if (mxf_metadata_track_identifier[i].type == type)
2625 return mxf_metadata_track_identifier[i].ul;
2630 G_DEFINE_TYPE (MXFMetadataTimelineTrack, mxf_metadata_timeline_track,
2631 MXF_TYPE_METADATA_TRACK);
2634 mxf_metadata_timeline_track_handle_tag (MXFMetadataBase * metadata,
2635 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
2638 MXFMetadataTimelineTrack *self = MXF_METADATA_TIMELINE_TRACK (metadata);
2639 gboolean ret = TRUE;
2643 if (!mxf_fraction_parse (&self->edit_rate, tag_data, tag_size))
2645 GST_DEBUG (" edit rate = %d/%d", self->edit_rate.n, self->edit_rate.d);
2650 self->origin = GST_READ_UINT64_BE (tag_data);
2651 GST_DEBUG (" origin = %" G_GINT64_FORMAT, self->origin);
2655 MXF_METADATA_BASE_CLASS
2656 (mxf_metadata_timeline_track_parent_class)->handle_tag (metadata,
2657 primer, tag, tag_data, tag_size);
2665 GST_ERROR ("Invalid timeline track local tag 0x%04x of size %u", tag,
2671 static GstStructure *
2672 mxf_metadata_timeline_track_to_structure (MXFMetadataBase * m)
2675 MXF_METADATA_BASE_CLASS
2676 (mxf_metadata_timeline_track_parent_class)->to_structure (m);
2677 MXFMetadataTimelineTrack *self = MXF_METADATA_TIMELINE_TRACK (m);
2679 gst_structure_id_set (ret, MXF_QUARK (EDIT_RATE), GST_TYPE_FRACTION,
2680 self->edit_rate.n, self->edit_rate.d, MXF_QUARK (ORIGIN), G_TYPE_INT64,
2681 self->origin, NULL);
2687 mxf_metadata_timeline_track_write_tags (MXFMetadataBase * m,
2688 MXFPrimerPack * primer)
2690 MXFMetadataTimelineTrack *self = MXF_METADATA_TIMELINE_TRACK (m);
2692 MXF_METADATA_BASE_CLASS
2693 (mxf_metadata_timeline_track_parent_class)->write_tags (m, primer);
2696 t = g_slice_new0 (MXFLocalTag);
2697 memcpy (&t->ul, MXF_UL (EDIT_RATE), 16);
2699 t->data = g_slice_alloc (t->size);
2701 GST_WRITE_UINT32_BE (t->data, self->edit_rate.n);
2702 GST_WRITE_UINT32_BE (t->data + 4, self->edit_rate.d);
2703 mxf_primer_pack_add_mapping (primer, 0x4b01, &t->ul);
2704 ret = g_list_prepend (ret, t);
2706 t = g_slice_new0 (MXFLocalTag);
2707 memcpy (&t->ul, MXF_UL (ORIGIN), 16);
2709 t->data = g_slice_alloc (t->size);
2711 GST_WRITE_UINT64_BE (t->data, self->origin);
2712 mxf_primer_pack_add_mapping (primer, 0x4b02, &t->ul);
2713 ret = g_list_prepend (ret, t);
2719 mxf_metadata_timeline_track_init (MXFMetadataTimelineTrack * self)
2725 mxf_metadata_timeline_track_class_init (MXFMetadataTimelineTrackClass * klass)
2727 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
2728 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
2730 metadata_base_class->handle_tag = mxf_metadata_timeline_track_handle_tag;
2731 metadata_base_class->name_quark = MXF_QUARK (TIMELINE_TRACK);
2732 metadata_base_class->to_structure = mxf_metadata_timeline_track_to_structure;
2733 metadata_base_class->write_tags = mxf_metadata_timeline_track_write_tags;
2734 metadata_class->type = 0x013b;
2737 G_DEFINE_TYPE (MXFMetadataEventTrack, mxf_metadata_event_track,
2738 MXF_TYPE_METADATA_TRACK);
2741 mxf_metadata_event_track_handle_tag (MXFMetadataBase * metadata,
2742 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
2745 MXFMetadataEventTrack *self = MXF_METADATA_EVENT_TRACK (metadata);
2746 gboolean ret = TRUE;
2750 if (!mxf_fraction_parse (&self->event_edit_rate, tag_data, tag_size))
2752 GST_DEBUG (" event edit rate = %d/%d", self->event_edit_rate.n,
2753 self->event_edit_rate.d);
2758 self->event_origin = GST_READ_UINT64_BE (tag_data);
2759 GST_DEBUG (" event origin = %" G_GINT64_FORMAT, self->event_origin);
2763 MXF_METADATA_BASE_CLASS
2764 (mxf_metadata_event_track_parent_class)->handle_tag (metadata, primer,
2765 tag, tag_data, tag_size);
2773 GST_ERROR ("Invalid event track local tag 0x%04x of size %u", tag, tag_size);
2778 static GstStructure *
2779 mxf_metadata_event_track_to_structure (MXFMetadataBase * m)
2782 MXF_METADATA_BASE_CLASS
2783 (mxf_metadata_event_track_parent_class)->to_structure (m);
2784 MXFMetadataEventTrack *self = MXF_METADATA_EVENT_TRACK (m);
2786 gst_structure_id_set (ret, MXF_QUARK (EVENT_EDIT_RATE), GST_TYPE_FRACTION,
2787 self->event_edit_rate.n, self->event_edit_rate.d,
2788 MXF_QUARK (EVENT_ORIGIN), G_TYPE_INT64, self->event_origin, NULL);
2794 mxf_metadata_event_track_write_tags (MXFMetadataBase * m,
2795 MXFPrimerPack * primer)
2797 MXFMetadataEventTrack *self = MXF_METADATA_EVENT_TRACK (m);
2799 MXF_METADATA_BASE_CLASS
2800 (mxf_metadata_event_track_parent_class)->write_tags (m, primer);
2803 t = g_slice_new0 (MXFLocalTag);
2804 memcpy (&t->ul, MXF_UL (EVENT_EDIT_RATE), 16);
2806 t->data = g_slice_alloc (t->size);
2808 GST_WRITE_UINT32_BE (t->data, self->event_edit_rate.n);
2809 GST_WRITE_UINT32_BE (t->data + 4, self->event_edit_rate.d);
2810 mxf_primer_pack_add_mapping (primer, 0x4901, &t->ul);
2811 ret = g_list_prepend (ret, t);
2813 t = g_slice_new0 (MXFLocalTag);
2814 memcpy (&t->ul, MXF_UL (EVENT_ORIGIN), 16);
2816 t->data = g_slice_alloc (t->size);
2818 GST_WRITE_UINT64_BE (t->data, self->event_origin);
2819 mxf_primer_pack_add_mapping (primer, 0x4902, &t->ul);
2820 ret = g_list_prepend (ret, t);
2826 mxf_metadata_event_track_init (MXFMetadataEventTrack * self)
2832 mxf_metadata_event_track_class_init (MXFMetadataEventTrackClass * klass)
2834 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
2835 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
2837 metadata_base_class->handle_tag = mxf_metadata_event_track_handle_tag;
2838 metadata_base_class->name_quark = MXF_QUARK (EVENT_TRACK);
2839 metadata_base_class->to_structure = mxf_metadata_event_track_to_structure;
2840 metadata_base_class->write_tags = mxf_metadata_event_track_write_tags;
2841 metadata_class->type = 0x0139;
2844 G_DEFINE_TYPE (MXFMetadataStaticTrack, mxf_metadata_static_track,
2845 MXF_TYPE_METADATA_TRACK);
2848 mxf_metadata_static_track_init (MXFMetadataStaticTrack * self)
2853 mxf_metadata_static_track_class_init (MXFMetadataStaticTrackClass * klass)
2855 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
2856 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
2858 metadata_base_class->name_quark = MXF_QUARK (STATIC_TRACK);
2859 metadata_class->type = 0x013a;
2862 G_DEFINE_TYPE (MXFMetadataSequence, mxf_metadata_sequence, MXF_TYPE_METADATA);
2865 mxf_metadata_sequence_finalize (GObject * object)
2867 MXFMetadataSequence *self = MXF_METADATA_SEQUENCE (object);
2869 g_free (self->structural_components_uids);
2870 self->structural_components_uids = NULL;
2871 g_free (self->structural_components);
2872 self->structural_components = NULL;
2874 G_OBJECT_CLASS (mxf_metadata_sequence_parent_class)->finalize (object);
2878 mxf_metadata_sequence_handle_tag (MXFMetadataBase * metadata,
2879 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
2882 MXFMetadataSequence *self = MXF_METADATA_SEQUENCE (metadata);
2883 gboolean ret = TRUE;
2884 #ifndef GST_DISABLE_GST_DEBUG
2892 memcpy (&self->data_definition, tag_data, 16);
2893 GST_DEBUG (" data definition = %s",
2894 mxf_ul_to_string (&self->data_definition, str));
2899 self->duration = GST_READ_UINT64_BE (tag_data);
2900 GST_DEBUG (" duration = %" G_GINT64_FORMAT, self->duration);
2903 if (!mxf_uuid_array_parse (&self->structural_components_uids,
2904 &self->n_structural_components, tag_data, tag_size))
2907 GST_DEBUG (" number of structural components = %u",
2908 self->n_structural_components);
2909 #ifndef GST_DISABLE_GST_DEBUG
2912 for (i = 0; i < self->n_structural_components; i++) {
2913 GST_DEBUG (" structural component %u = %s", i,
2914 mxf_uuid_to_string (&self->structural_components_uids[i], str));
2921 MXF_METADATA_BASE_CLASS
2922 (mxf_metadata_sequence_parent_class)->handle_tag (metadata, primer,
2923 tag, tag_data, tag_size);
2931 GST_ERROR ("Invalid sequence local tag 0x%04x of size %u", tag, tag_size);
2937 mxf_metadata_sequence_resolve (MXFMetadataBase * m, GHashTable * metadata)
2939 MXFMetadataSequence *self = MXF_METADATA_SEQUENCE (m);
2940 MXFMetadataBase *current = NULL;
2942 #ifndef GST_DISABLE_GST_DEBUG
2946 if (self->structural_components)
2947 memset (self->structural_components, 0,
2948 sizeof (gpointer) * self->n_structural_components);
2950 self->structural_components =
2951 g_new0 (MXFMetadataStructuralComponent *,
2952 self->n_structural_components);
2953 for (i = 0; i < self->n_structural_components; i++) {
2955 g_hash_table_lookup (metadata, &self->structural_components_uids[i]);
2956 if (current && MXF_IS_METADATA_STRUCTURAL_COMPONENT (current)) {
2957 if (mxf_metadata_base_resolve (current, metadata)) {
2958 self->structural_components[i] =
2959 MXF_METADATA_STRUCTURAL_COMPONENT (current);
2961 GST_ERROR ("Couldn't resolve structural component %s",
2962 mxf_uuid_to_string (&self->structural_components_uids[i], str));
2966 GST_ERROR ("Structural component %s not found",
2967 mxf_uuid_to_string (&self->structural_components_uids[i], str));
2973 MXF_METADATA_BASE_CLASS (mxf_metadata_sequence_parent_class)->resolve (m,
2978 static GstStructure *
2979 mxf_metadata_sequence_to_structure (MXFMetadataBase * m)
2982 MXF_METADATA_BASE_CLASS (mxf_metadata_sequence_parent_class)->to_structure
2984 MXFMetadataSequence *self = MXF_METADATA_SEQUENCE (m);
2988 mxf_ul_to_string (&self->data_definition, str);
2989 gst_structure_id_set (ret, MXF_QUARK (DATA_DEFINITION), G_TYPE_STRING, str,
2990 MXF_QUARK (DURATION), G_TYPE_INT64, self->duration, NULL);
2992 if (self->n_structural_components > 0) {
2997 g_value_init (&arr, GST_TYPE_ARRAY);
2999 for (i = 0; i < self->n_structural_components; i++) {
3002 if (self->structural_components[i] == NULL)
3005 g_value_init (&val, GST_TYPE_STRUCTURE);
3007 s = mxf_metadata_base_to_structure (MXF_METADATA_BASE
3008 (self->structural_components[i]));
3009 gst_value_set_structure (&val, s);
3010 gst_structure_free (s);
3011 gst_value_array_append_value (&arr, &val);
3012 g_value_unset (&val);
3015 if (gst_value_array_get_size (&arr) > 0)
3016 gst_structure_id_set_value (ret, MXF_QUARK (STRUCTURAL_COMPONENTS), &arr);
3018 g_value_unset (&arr);
3025 mxf_metadata_sequence_write_tags (MXFMetadataBase * m, MXFPrimerPack * primer)
3027 MXFMetadataSequence *self = MXF_METADATA_SEQUENCE (m);
3029 MXF_METADATA_BASE_CLASS (mxf_metadata_sequence_parent_class)->write_tags
3033 t = g_slice_new0 (MXFLocalTag);
3034 memcpy (&t->ul, MXF_UL (DATA_DEFINITION), 16);
3036 t->data = g_slice_alloc (t->size);
3038 memcpy (t->data, &self->data_definition, 16);
3039 mxf_primer_pack_add_mapping (primer, 0x0201, &t->ul);
3040 ret = g_list_prepend (ret, t);
3042 t = g_slice_new0 (MXFLocalTag);
3043 memcpy (&t->ul, MXF_UL (DURATION), 16);
3045 t->data = g_slice_alloc (t->size);
3047 GST_WRITE_UINT64_BE (t->data, self->duration);
3048 mxf_primer_pack_add_mapping (primer, 0x0202, &t->ul);
3049 ret = g_list_prepend (ret, t);
3051 if (self->structural_components) {
3053 t = g_slice_new0 (MXFLocalTag);
3054 memcpy (&t->ul, MXF_UL (STRUCTURAL_COMPONENTS), 16);
3055 t->size = 8 + 16 * self->n_structural_components;
3056 t->data = g_slice_alloc0 (t->size);
3059 GST_WRITE_UINT32_BE (t->data, self->n_structural_components);
3060 GST_WRITE_UINT32_BE (t->data + 4, 16);
3061 for (i = 0; i < self->n_structural_components; i++) {
3062 if (!self->structural_components[i])
3065 memcpy (t->data + 8 + i * 16,
3066 &MXF_METADATA_BASE (self->structural_components[i])->instance_uid,
3070 mxf_primer_pack_add_mapping (primer, 0x1001, &t->ul);
3071 ret = g_list_prepend (ret, t);
3078 mxf_metadata_sequence_init (MXFMetadataSequence * self)
3080 self->duration = -1;
3084 mxf_metadata_sequence_class_init (MXFMetadataSequenceClass * klass)
3086 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
3087 GObjectClass *object_class = (GObjectClass *) klass;
3088 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
3090 object_class->finalize = mxf_metadata_sequence_finalize;
3091 metadata_base_class->handle_tag = mxf_metadata_sequence_handle_tag;
3092 metadata_base_class->resolve = mxf_metadata_sequence_resolve;
3093 metadata_base_class->name_quark = MXF_QUARK (SEQUENCE);
3094 metadata_base_class->to_structure = mxf_metadata_sequence_to_structure;
3095 metadata_base_class->write_tags = mxf_metadata_sequence_write_tags;
3096 metadata_class->type = 0x010f;
3099 G_DEFINE_TYPE (MXFMetadataStructuralComponent,
3100 mxf_metadata_structural_component, MXF_TYPE_METADATA);
3103 mxf_metadata_structural_component_handle_tag (MXFMetadataBase * metadata,
3104 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
3107 MXFMetadataStructuralComponent *self =
3108 MXF_METADATA_STRUCTURAL_COMPONENT (metadata);
3109 gboolean ret = TRUE;
3110 #ifndef GST_DISABLE_GST_DEBUG
3118 memcpy (&self->data_definition, tag_data, 16);
3119 GST_DEBUG (" data definition = %s",
3120 mxf_ul_to_string (&self->data_definition, str));
3125 self->duration = GST_READ_UINT64_BE (tag_data);
3126 GST_DEBUG (" duration = %" G_GINT64_FORMAT, self->duration);
3130 MXF_METADATA_BASE_CLASS
3131 (mxf_metadata_structural_component_parent_class)->handle_tag
3132 (metadata, primer, tag, tag_data, tag_size);
3140 GST_ERROR ("Invalid structural component local tag 0x%04x of size %u", tag,
3146 static GstStructure *
3147 mxf_metadata_structural_component_to_structure (MXFMetadataBase * m)
3150 MXF_METADATA_BASE_CLASS
3151 (mxf_metadata_structural_component_parent_class)->to_structure (m);
3152 MXFMetadataStructuralComponent *self = MXF_METADATA_STRUCTURAL_COMPONENT (m);
3155 mxf_ul_to_string (&self->data_definition, str);
3156 gst_structure_id_set (ret, MXF_QUARK (DATA_DEFINITION), G_TYPE_STRING, str,
3157 MXF_QUARK (DURATION), G_TYPE_INT64, self->duration, NULL);
3163 mxf_metadata_structural_component_write_tags (MXFMetadataBase * m,
3164 MXFPrimerPack * primer)
3166 MXFMetadataStructuralComponent *self = MXF_METADATA_STRUCTURAL_COMPONENT (m);
3168 MXF_METADATA_BASE_CLASS
3169 (mxf_metadata_structural_component_parent_class)->write_tags (m, primer);
3172 t = g_slice_new0 (MXFLocalTag);
3173 memcpy (&t->ul, MXF_UL (DATA_DEFINITION), 16);
3175 t->data = g_slice_alloc (t->size);
3177 memcpy (t->data, &self->data_definition, 16);
3178 mxf_primer_pack_add_mapping (primer, 0x0201, &t->ul);
3179 ret = g_list_prepend (ret, t);
3181 t = g_slice_new0 (MXFLocalTag);
3182 memcpy (&t->ul, MXF_UL (DURATION), 16);
3184 t->data = g_slice_alloc (t->size);
3186 GST_WRITE_UINT64_BE (t->data, self->duration);
3187 mxf_primer_pack_add_mapping (primer, 0x0202, &t->ul);
3188 ret = g_list_prepend (ret, t);
3194 mxf_metadata_structural_component_init (MXFMetadataStructuralComponent * self)
3196 self->duration = -1;
3200 mxf_metadata_structural_component_class_init
3201 (MXFMetadataStructuralComponentClass * klass)
3203 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
3205 metadata_base_class->handle_tag =
3206 mxf_metadata_structural_component_handle_tag;
3207 metadata_base_class->to_structure =
3208 mxf_metadata_structural_component_to_structure;
3209 metadata_base_class->write_tags =
3210 mxf_metadata_structural_component_write_tags;
3213 G_DEFINE_TYPE (MXFMetadataTimecodeComponent, mxf_metadata_timecode_component,
3214 MXF_TYPE_METADATA_STRUCTURAL_COMPONENT);
3217 mxf_metadata_timecode_component_handle_tag (MXFMetadataBase * metadata,
3218 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
3221 MXFMetadataTimecodeComponent *self =
3222 MXF_METADATA_TIMECODE_COMPONENT (metadata);
3223 gboolean ret = TRUE;
3229 self->rounded_timecode_base = GST_READ_UINT16_BE (tag_data);
3230 GST_DEBUG (" rounded timecode base = %u", self->rounded_timecode_base);
3235 self->start_timecode = GST_READ_UINT64_BE (tag_data);
3236 GST_DEBUG (" start timecode = %" G_GINT64_FORMAT, self->start_timecode);
3241 self->drop_frame = (GST_READ_UINT8 (tag_data) != 0);
3242 GST_DEBUG (" drop frame = %s", (self->drop_frame) ? "yes" : "no");
3246 MXF_METADATA_BASE_CLASS
3247 (mxf_metadata_timecode_component_parent_class)->handle_tag (metadata,
3248 primer, tag, tag_data, tag_size);
3256 GST_ERROR ("Invalid timecode component local tag 0x%04x of size %u", tag,
3262 static GstStructure *
3263 mxf_metadata_timecode_component_to_structure (MXFMetadataBase * m)
3266 MXF_METADATA_BASE_CLASS
3267 (mxf_metadata_timecode_component_parent_class)->to_structure (m);
3268 MXFMetadataTimecodeComponent *self = MXF_METADATA_TIMECODE_COMPONENT (m);
3270 gst_structure_id_set (ret, MXF_QUARK (START_TIMECODE), G_TYPE_INT64,
3271 self->start_timecode, MXF_QUARK (ROUNDED_TIMECODE_BASE), G_TYPE_UINT,
3272 self->rounded_timecode_base, MXF_QUARK (DROP_FRAME), G_TYPE_BOOLEAN,
3273 self->drop_frame, NULL);
3279 mxf_metadata_timecode_component_write_tags (MXFMetadataBase * m,
3280 MXFPrimerPack * primer)
3282 MXFMetadataTimecodeComponent *self = MXF_METADATA_TIMECODE_COMPONENT (m);
3284 MXF_METADATA_BASE_CLASS
3285 (mxf_metadata_timecode_component_parent_class)->write_tags (m, primer);
3288 t = g_slice_new0 (MXFLocalTag);
3289 memcpy (&t->ul, MXF_UL (ROUNDED_TIMECODE_BASE), 16);
3291 t->data = g_slice_alloc (t->size);
3293 GST_WRITE_UINT16_BE (t->data, self->rounded_timecode_base);
3294 mxf_primer_pack_add_mapping (primer, 0x1502, &t->ul);
3295 ret = g_list_prepend (ret, t);
3297 t = g_slice_new0 (MXFLocalTag);
3298 memcpy (&t->ul, MXF_UL (START_TIMECODE), 16);
3300 t->data = g_slice_alloc (t->size);
3302 GST_WRITE_UINT64_BE (t->data, self->start_timecode);
3303 mxf_primer_pack_add_mapping (primer, 0x1501, &t->ul);
3304 ret = g_list_prepend (ret, t);
3306 t = g_slice_new0 (MXFLocalTag);
3307 memcpy (&t->ul, MXF_UL (DROP_FRAME), 16);
3309 t->data = g_slice_alloc (t->size);
3311 GST_WRITE_UINT8 (t->data, (self->drop_frame) ? 1 : 0);
3312 mxf_primer_pack_add_mapping (primer, 0x1503, &t->ul);
3313 ret = g_list_prepend (ret, t);
3319 mxf_metadata_timecode_component_init (MXFMetadataTimecodeComponent * self)
3325 mxf_metadata_timecode_component_class_init (MXFMetadataTimecodeComponentClass *
3328 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
3329 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
3331 metadata_base_class->handle_tag = mxf_metadata_timecode_component_handle_tag;
3332 metadata_base_class->name_quark = MXF_QUARK (TIMECODE_COMPONENT);
3333 metadata_base_class->to_structure =
3334 mxf_metadata_timecode_component_to_structure;
3335 metadata_base_class->write_tags = mxf_metadata_timecode_component_write_tags;
3336 metadata_class->type = 0x0114;
3339 G_DEFINE_TYPE (MXFMetadataSourceClip, mxf_metadata_source_clip,
3340 MXF_TYPE_METADATA_STRUCTURAL_COMPONENT);
3343 mxf_metadata_source_clip_handle_tag (MXFMetadataBase * metadata,
3344 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
3347 MXFMetadataSourceClip *self = MXF_METADATA_SOURCE_CLIP (metadata);
3348 gboolean ret = TRUE;
3349 #ifndef GST_DISABLE_GST_DEBUG
3358 self->start_position = GST_READ_UINT64_BE (tag_data);
3359 GST_DEBUG (" start position = %" G_GINT64_FORMAT, self->start_position);
3365 memcpy (&self->source_package_id, tag_data, 32);
3366 GST_DEBUG (" source package id = %s",
3367 mxf_umid_to_string (&self->source_package_id, str));
3373 self->source_track_id = GST_READ_UINT32_BE (tag_data);
3374 GST_DEBUG (" source track id = %u", self->source_track_id);
3378 MXF_METADATA_BASE_CLASS
3379 (mxf_metadata_source_clip_parent_class)->handle_tag (metadata, primer,
3380 tag, tag_data, tag_size);
3388 GST_ERROR ("Invalid source clip local tag 0x%04x of size %u", tag, tag_size);
3394 mxf_metadata_source_clip_resolve (MXFMetadataBase * m, GHashTable * metadata)
3396 MXFMetadataSourceClip *self = MXF_METADATA_SOURCE_CLIP (m);
3397 MXFMetadataBase *current = NULL;
3398 GHashTableIter iter;
3399 #ifndef GST_DISABLE_GST_DEBUG
3403 g_hash_table_iter_init (&iter, metadata);
3405 while (g_hash_table_iter_next (&iter, NULL, (gpointer) & current)) {
3406 if (MXF_IS_METADATA_SOURCE_PACKAGE (current)) {
3407 MXFMetadataGenericPackage *p = MXF_METADATA_GENERIC_PACKAGE (current);
3409 if (mxf_umid_is_equal (&p->package_uid, &self->source_package_id)) {
3410 self->source_package = MXF_METADATA_SOURCE_PACKAGE (current);
3416 if (!self->source_package) {
3417 GST_ERROR ("Couldn't find source package %s",
3418 mxf_umid_to_string (&self->source_package_id, str));
3422 MXF_METADATA_BASE_CLASS (mxf_metadata_source_clip_parent_class)->resolve
3426 static GstStructure *
3427 mxf_metadata_source_clip_to_structure (MXFMetadataBase * m)
3430 MXF_METADATA_BASE_CLASS
3431 (mxf_metadata_source_clip_parent_class)->to_structure (m);
3432 MXFMetadataSourceClip *self = MXF_METADATA_SOURCE_CLIP (m);
3435 mxf_umid_to_string (&self->source_package_id, str);
3436 gst_structure_id_set (ret, MXF_QUARK (START_POSITION), G_TYPE_INT64,
3437 self->start_position, MXF_QUARK (SOURCE_PACKAGE), G_TYPE_STRING, str,
3438 MXF_QUARK (SOURCE_TRACK_ID), G_TYPE_UINT, self->source_track_id, NULL);
3444 mxf_metadata_source_clip_write_tags (MXFMetadataBase * m,
3445 MXFPrimerPack * primer)
3447 MXFMetadataSourceClip *self = MXF_METADATA_SOURCE_CLIP (m);
3449 MXF_METADATA_BASE_CLASS
3450 (mxf_metadata_source_clip_parent_class)->write_tags (m, primer);
3453 t = g_slice_new0 (MXFLocalTag);
3454 memcpy (&t->ul, MXF_UL (START_POSITION), 16);
3456 t->data = g_slice_alloc (t->size);
3458 GST_WRITE_UINT64_BE (t->data, self->start_position);
3459 mxf_primer_pack_add_mapping (primer, 0x1201, &t->ul);
3460 ret = g_list_prepend (ret, t);
3462 t = g_slice_new0 (MXFLocalTag);
3463 memcpy (&t->ul, MXF_UL (SOURCE_PACKAGE_ID), 16);
3465 t->data = g_slice_alloc (t->size);
3467 memcpy (t->data, &self->source_package_id, 32);
3468 mxf_primer_pack_add_mapping (primer, 0x1101, &t->ul);
3469 ret = g_list_prepend (ret, t);
3471 t = g_slice_new0 (MXFLocalTag);
3472 memcpy (&t->ul, MXF_UL (SOURCE_TRACK_ID), 16);
3474 t->data = g_slice_alloc (t->size);
3476 GST_WRITE_UINT32_BE (t->data, self->source_track_id);
3477 mxf_primer_pack_add_mapping (primer, 0x1102, &t->ul);
3478 ret = g_list_prepend (ret, t);
3484 mxf_metadata_source_clip_init (MXFMetadataSourceClip * self)
3490 mxf_metadata_source_clip_class_init (MXFMetadataSourceClipClass * klass)
3492 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
3493 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
3495 metadata_base_class->handle_tag = mxf_metadata_source_clip_handle_tag;
3496 metadata_base_class->resolve = mxf_metadata_source_clip_resolve;
3497 metadata_base_class->name_quark = MXF_QUARK (SOURCE_CLIP);
3498 metadata_base_class->to_structure = mxf_metadata_source_clip_to_structure;
3499 metadata_base_class->write_tags = mxf_metadata_source_clip_write_tags;
3500 metadata_class->type = 0x0111;
3504 G_DEFINE_TYPE (MXFMetadataFiller, mxf_metadata_filler,
3505 MXF_TYPE_METADATA_STRUCTURAL_COMPONENT);
3508 mxf_metadata_filler_init (MXFMetadataFiller * self)
3514 mxf_metadata_filler_class_init (MXFMetadataFillerClass * klass)
3516 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
3517 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
3519 metadata_base_class->name_quark = MXF_QUARK (FILLER);
3520 metadata_class->type = 0x0109;
3523 G_DEFINE_TYPE (MXFMetadataDMSourceClip, mxf_metadata_dm_source_clip,
3524 MXF_TYPE_METADATA_SOURCE_CLIP);
3527 mxf_metadata_dm_source_clip_finalize (GObject * object)
3529 MXFMetadataDMSourceClip *self = MXF_METADATA_DM_SOURCE_CLIP (object);
3531 g_free (self->track_ids);
3532 self->track_ids = NULL;
3534 G_OBJECT_CLASS (mxf_metadata_dm_source_clip_parent_class)->finalize (object);
3538 mxf_metadata_dm_source_clip_handle_tag (MXFMetadataBase * metadata,
3539 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
3542 MXFMetadataDMSourceClip *self = MXF_METADATA_DM_SOURCE_CLIP (metadata);
3543 gboolean ret = TRUE;
3554 len = GST_READ_UINT32_BE (tag_data);
3555 GST_DEBUG (" number of track ids = %u", len);
3559 if (GST_READ_UINT32_BE (tag_data + 4) != 4)
3565 if (tag_size / 4 < len)
3568 self->n_track_ids = len;
3569 self->track_ids = g_new0 (guint32, len);
3571 for (i = 0; i < len; i++) {
3572 self->track_ids[i] = GST_READ_UINT32_BE (tag_data);
3573 GST_DEBUG (" track id %u = %u", i, self->track_ids[i]);
3581 MXF_METADATA_BASE_CLASS
3582 (mxf_metadata_dm_source_clip_parent_class)->handle_tag (metadata,
3583 primer, tag, tag_data, tag_size);
3591 GST_ERROR ("Invalid DM source clip local tag 0x%04x of size %u", tag,
3597 static GstStructure *
3598 mxf_metadata_dm_source_clip_to_structure (MXFMetadataBase * m)
3601 MXF_METADATA_BASE_CLASS
3602 (mxf_metadata_dm_source_clip_parent_class)->to_structure (m);
3603 MXFMetadataDMSourceClip *self = MXF_METADATA_DM_SOURCE_CLIP (m);
3606 if (self->n_track_ids > 0) {
3611 g_value_init (&arr, GST_TYPE_ARRAY);
3613 for (i = 0; i < self->n_track_ids; i++) {
3614 g_value_init (&val, G_TYPE_UINT);
3616 g_value_set_uint (&val, self->track_ids[i]);
3617 gst_value_array_append_value (&arr, &val);
3618 g_value_unset (&val);
3621 if (gst_value_array_get_size (&arr) > 0)
3622 gst_structure_id_set_value (ret, MXF_QUARK (TRACK_IDS), &arr);
3624 g_value_unset (&arr);
3631 mxf_metadata_dm_source_clip_write_tags (MXFMetadataBase * m,
3632 MXFPrimerPack * primer)
3634 MXFMetadataDMSourceClip *self = MXF_METADATA_DM_SOURCE_CLIP (m);
3636 MXF_METADATA_BASE_CLASS
3637 (mxf_metadata_dm_source_clip_parent_class)->write_tags (m, primer);
3640 if (self->track_ids) {
3643 t = g_slice_new0 (MXFLocalTag);
3644 memcpy (&t->ul, MXF_UL (DM_SOURCECLIP_TRACK_IDS), 16);
3645 t->size = 8 + 4 * self->n_track_ids;
3646 t->data = g_slice_alloc (t->size);
3648 GST_WRITE_UINT32_BE (t->data, self->n_track_ids);
3649 GST_WRITE_UINT32_BE (t->data + 4, 4);
3650 for (i = 0; i < self->n_track_ids; i++)
3651 GST_WRITE_UINT32_BE (t->data + 8 + i * 4, self->track_ids[i]);
3652 mxf_primer_pack_add_mapping (primer, 0x6103, &t->ul);
3653 ret = g_list_prepend (ret, t);
3660 mxf_metadata_dm_source_clip_init (MXFMetadataDMSourceClip * self)
3666 mxf_metadata_dm_source_clip_class_init (MXFMetadataDMSourceClipClass * klass)
3668 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
3669 GObjectClass *object_class = (GObjectClass *) klass;
3670 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
3672 object_class->finalize = mxf_metadata_dm_source_clip_finalize;
3673 metadata_base_class->handle_tag = mxf_metadata_dm_source_clip_handle_tag;
3674 metadata_base_class->name_quark = MXF_QUARK (DM_SOURCE_CLIP);
3675 metadata_base_class->to_structure = mxf_metadata_dm_source_clip_to_structure;
3676 metadata_base_class->write_tags = mxf_metadata_dm_source_clip_write_tags;
3677 metadata_class->type = 0x0145;
3680 G_DEFINE_TYPE (MXFMetadataDMSegment, mxf_metadata_dm_segment,
3681 MXF_TYPE_METADATA_STRUCTURAL_COMPONENT);
3684 mxf_metadata_dm_segment_finalize (GObject * object)
3686 MXFMetadataDMSegment *self = MXF_METADATA_DM_SEGMENT (object);
3688 g_free (self->track_ids);
3689 self->track_ids = NULL;
3691 g_free (self->event_comment);
3692 self->event_comment = NULL;
3694 G_OBJECT_CLASS (mxf_metadata_dm_segment_parent_class)->finalize (object);
3698 mxf_metadata_dm_segment_handle_tag (MXFMetadataBase * metadata,
3699 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
3702 MXFMetadataDMSegment *self = MXF_METADATA_DM_SEGMENT (metadata);
3703 gboolean ret = TRUE;
3704 #ifndef GST_DISABLE_GST_DEBUG
3712 self->event_start_position = GST_READ_UINT64_BE (tag_data);
3713 GST_DEBUG (" event start position = %" G_GINT64_FORMAT,
3714 self->event_start_position);
3717 self->event_comment = mxf_utf16_to_utf8 (tag_data, tag_size);
3718 GST_DEBUG (" event comment = %s", GST_STR_NULL (self->event_comment));
3727 len = GST_READ_UINT32_BE (tag_data);
3728 GST_DEBUG (" number of track ids = %u", len);
3732 if (GST_READ_UINT32_BE (tag_data + 4) != 4)
3738 if (len < tag_size / 4)
3741 self->n_track_ids = len;
3742 self->track_ids = g_new0 (guint32, len);
3747 for (i = 0; i < len; i++) {
3748 self->track_ids[i] = GST_READ_UINT32_BE (tag_data);
3749 GST_DEBUG (" track id %u = %u", i, self->track_ids[i]);
3759 memcpy (&self->dm_framework_uid, tag_data, 16);
3760 GST_DEBUG (" DM framework = %s",
3761 mxf_uuid_to_string (&self->dm_framework_uid, str));
3765 MXF_METADATA_BASE_CLASS
3766 (mxf_metadata_dm_segment_parent_class)->handle_tag (metadata, primer,
3767 tag, tag_data, tag_size);
3775 GST_ERROR ("Invalid DM segment local tag 0x%04x of size %u", tag, tag_size);
3781 mxf_metadata_dm_segment_resolve (MXFMetadataBase * m, GHashTable * metadata)
3783 MXFMetadataDMSegment *self = MXF_METADATA_DM_SEGMENT (m);
3784 MXFMetadataBase *current = NULL;
3785 #ifndef GST_DISABLE_GST_DEBUG
3789 current = g_hash_table_lookup (metadata, &self->dm_framework_uid);
3790 if (current && MXF_IS_DESCRIPTIVE_METADATA_FRAMEWORK (current)) {
3791 if (mxf_metadata_base_resolve (current, metadata)) {
3792 self->dm_framework = MXF_DESCRIPTIVE_METADATA_FRAMEWORK (current);
3794 GST_ERROR ("Couldn't resolve DM framework %s",
3795 mxf_uuid_to_string (&self->dm_framework_uid, str));
3799 GST_ERROR ("Couldn't find DM framework %s",
3800 mxf_uuid_to_string (&self->dm_framework_uid, str));
3806 MXF_METADATA_BASE_CLASS (mxf_metadata_dm_segment_parent_class)->resolve
3810 static GstStructure *
3811 mxf_metadata_dm_segment_to_structure (MXFMetadataBase * m)
3814 MXF_METADATA_BASE_CLASS
3815 (mxf_metadata_dm_segment_parent_class)->to_structure (m);
3816 MXFMetadataDMSegment *self = MXF_METADATA_DM_SEGMENT (m);
3819 gst_structure_id_set (ret, MXF_QUARK (EVENT_START_POSITION), G_TYPE_INT64,
3820 self->event_start_position, NULL);
3822 if (self->event_comment)
3823 gst_structure_id_set (ret, MXF_QUARK (EVENT_COMMENT), G_TYPE_STRING,
3824 self->event_comment, NULL);
3825 /* FIXME: DMS1 doesn't support serializing to a structure yet */
3827 if (self->dm_framework) {
3829 mxf_metadata_base_to_structure (MXF_METADATA_BASE (self->dm_framework));
3831 gst_structure_id_set (ret, MXF_QUARK (DM_FRAMEWORK), GST_TYPE_STRUCTURE,
3833 gst_structure_free (s);
3837 if (self->n_track_ids > 0) {
3842 g_value_init (&arr, GST_TYPE_ARRAY);
3844 for (i = 0; i < self->n_track_ids; i++) {
3845 g_value_init (&val, G_TYPE_UINT);
3847 g_value_set_uint (&val, self->track_ids[i]);
3848 gst_value_array_append_value (&arr, &val);
3849 g_value_unset (&val);
3852 if (gst_value_array_get_size (&arr) > 0)
3853 gst_structure_id_set_value (ret, MXF_QUARK (TRACK_IDS), &arr);
3855 g_value_unset (&arr);
3862 mxf_metadata_dm_segment_write_tags (MXFMetadataBase * m, MXFPrimerPack * primer)
3864 MXFMetadataDMSegment *self = MXF_METADATA_DM_SEGMENT (m);
3866 MXF_METADATA_BASE_CLASS (mxf_metadata_dm_segment_parent_class)->write_tags
3870 if (self->event_start_position != -1) {
3871 t = g_slice_new0 (MXFLocalTag);
3872 memcpy (&t->ul, MXF_UL (EVENT_START_POSITION), 16);
3874 t->data = g_slice_alloc (t->size);
3876 GST_WRITE_UINT64_BE (t->data, self->event_start_position);
3877 mxf_primer_pack_add_mapping (primer, 0x0601, &t->ul);
3878 ret = g_list_prepend (ret, t);
3881 if (self->event_comment) {
3882 t = g_slice_new0 (MXFLocalTag);
3883 memcpy (&t->ul, MXF_UL (EVENT_COMMENT), 16);
3884 t->data = mxf_utf8_to_utf16 (self->event_comment, &t->size);
3885 mxf_primer_pack_add_mapping (primer, 0x0602, &t->ul);
3886 ret = g_list_prepend (ret, t);
3889 if (self->track_ids) {
3892 t = g_slice_new0 (MXFLocalTag);
3893 memcpy (&t->ul, MXF_UL (DM_SEGMENT_TRACK_IDS), 16);
3894 t->size = 8 + 4 * self->n_track_ids;
3895 t->data = g_slice_alloc (t->size);
3897 GST_WRITE_UINT32_BE (t->data, self->n_track_ids);
3898 GST_WRITE_UINT32_BE (t->data + 4, 4);
3899 for (i = 0; i < self->n_track_ids; i++)
3900 GST_WRITE_UINT32_BE (t->data + 8 + i * 4, self->track_ids[i]);
3901 mxf_primer_pack_add_mapping (primer, 0x6102, &t->ul);
3902 ret = g_list_prepend (ret, t);
3905 if (self->dm_framework) {
3906 t = g_slice_new0 (MXFLocalTag);
3907 memcpy (&t->ul, MXF_UL (DM_FRAMEWORK), 16);
3909 t->data = g_slice_alloc (t->size);
3911 memcpy (t->data, &MXF_METADATA_BASE (self->dm_framework)->instance_uid, 16);
3912 mxf_primer_pack_add_mapping (primer, 0x6101, &t->ul);
3913 ret = g_list_prepend (ret, t);
3920 mxf_metadata_dm_segment_init (MXFMetadataDMSegment * self)
3922 self->event_start_position = -1;
3926 mxf_metadata_dm_segment_class_init (MXFMetadataDMSegmentClass * klass)
3928 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
3929 GObjectClass *object_class = (GObjectClass *) klass;
3930 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
3932 object_class->finalize = mxf_metadata_dm_segment_finalize;
3933 metadata_base_class->handle_tag = mxf_metadata_dm_segment_handle_tag;
3934 metadata_base_class->resolve = mxf_metadata_dm_segment_resolve;
3935 metadata_base_class->name_quark = MXF_QUARK (DM_SEGMENT);
3936 metadata_base_class->to_structure = mxf_metadata_dm_segment_to_structure;
3937 metadata_base_class->write_tags = mxf_metadata_dm_segment_write_tags;
3938 metadata_class->type = 0x0141;
3941 G_DEFINE_ABSTRACT_TYPE (MXFMetadataGenericDescriptor,
3942 mxf_metadata_generic_descriptor, MXF_TYPE_METADATA);
3945 mxf_metadata_generic_descriptor_finalize (GObject * object)
3947 MXFMetadataGenericDescriptor *self = MXF_METADATA_GENERIC_DESCRIPTOR (object);
3949 g_free (self->locators_uids);
3950 self->locators_uids = NULL;
3952 g_free (self->locators);
3953 self->locators = NULL;
3955 G_OBJECT_CLASS (mxf_metadata_generic_descriptor_parent_class)->finalize
3960 mxf_metadata_generic_descriptor_handle_tag (MXFMetadataBase * metadata,
3961 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
3964 MXFMetadataGenericDescriptor *self =
3965 MXF_METADATA_GENERIC_DESCRIPTOR (metadata);
3966 gboolean ret = TRUE;
3967 #ifndef GST_DISABLE_GST_DEBUG
3973 if (!mxf_uuid_array_parse (&self->locators_uids, &self->n_locators,
3974 tag_data, tag_size))
3977 GST_DEBUG (" number of locators = %u", self->n_locators);
3978 #ifndef GST_DISABLE_GST_DEBUG
3981 for (i = 0; i < self->n_locators; i++) {
3982 GST_DEBUG (" locator %u = %s", i,
3983 mxf_uuid_to_string (&self->locators_uids[i], str));
3990 MXF_METADATA_BASE_CLASS
3991 (mxf_metadata_generic_descriptor_parent_class)->handle_tag (metadata,
3992 primer, tag, tag_data, tag_size);
4000 GST_ERROR ("Invalid generic descriptor local tag 0x%04x of size %u", tag,
4007 mxf_metadata_generic_descriptor_resolve (MXFMetadataBase * m,
4008 GHashTable * metadata)
4010 MXFMetadataGenericDescriptor *self = MXF_METADATA_GENERIC_DESCRIPTOR (m);
4011 MXFMetadataBase *current = NULL;
4013 gboolean have_locator = FALSE;
4014 #ifndef GST_DISABLE_GST_DEBUG
4019 memset (self->locators, 0, sizeof (gpointer) * self->n_locators);
4021 self->locators = g_new0 (MXFMetadataLocator *, self->n_locators);
4022 for (i = 0; i < self->n_locators; i++) {
4023 current = g_hash_table_lookup (metadata, &self->locators_uids[i]);
4024 if (current && MXF_IS_METADATA_LOCATOR (current)) {
4025 if (mxf_metadata_base_resolve (current, metadata)) {
4026 self->locators[i] = MXF_METADATA_LOCATOR (current);
4027 have_locator = TRUE;
4029 GST_ERROR ("Couldn't resolve locator %s",
4030 mxf_uuid_to_string (&self->locators_uids[i], str));
4033 GST_ERROR ("Locator %s not found",
4034 mxf_uuid_to_string (&self->locators_uids[i], str));
4038 if (!have_locator && self->n_locators > 0) {
4039 GST_ERROR ("Couldn't resolve a locator");
4044 MXF_METADATA_BASE_CLASS
4045 (mxf_metadata_generic_descriptor_parent_class)->resolve (m, metadata);
4048 static GstStructure *
4049 mxf_metadata_generic_descriptor_to_structure (MXFMetadataBase * m)
4052 MXF_METADATA_BASE_CLASS
4053 (mxf_metadata_generic_descriptor_parent_class)->to_structure (m);
4054 MXFMetadataGenericDescriptor *self = MXF_METADATA_GENERIC_DESCRIPTOR (m);
4057 if (self->n_locators > 0) {
4062 g_value_init (&arr, GST_TYPE_ARRAY);
4064 for (i = 0; i < self->n_locators; i++) {
4067 if (self->locators[i] == NULL)
4070 g_value_init (&val, GST_TYPE_STRUCTURE);
4072 s = mxf_metadata_base_to_structure (MXF_METADATA_BASE (self->locators
4074 gst_value_set_structure (&val, s);
4075 gst_structure_free (s);
4076 gst_value_array_append_value (&arr, &val);
4077 g_value_unset (&val);
4080 if (gst_value_array_get_size (&arr) > 0)
4081 gst_structure_id_set_value (ret, MXF_QUARK (LOCATORS), &arr);
4083 g_value_unset (&arr);
4090 mxf_metadata_generic_descriptor_write_tags (MXFMetadataBase * m,
4091 MXFPrimerPack * primer)
4093 MXFMetadataGenericDescriptor *self = MXF_METADATA_GENERIC_DESCRIPTOR (m);
4095 MXF_METADATA_BASE_CLASS
4096 (mxf_metadata_generic_descriptor_parent_class)->write_tags (m, primer);
4099 if (self->locators) {
4102 t = g_slice_new0 (MXFLocalTag);
4103 memcpy (&t->ul, MXF_UL (LOCATORS), 16);
4104 t->size = 8 + 16 * self->n_locators;
4105 t->data = g_slice_alloc0 (t->size);
4107 GST_WRITE_UINT32_BE (t->data, self->n_locators);
4108 GST_WRITE_UINT32_BE (t->data + 4, 16);
4109 for (i = 0; i < self->n_locators; i++) {
4110 if (!self->locators[i])
4112 memcpy (t->data + 8 + 16 * i,
4113 &MXF_METADATA_BASE (self->locators[i])->instance_uid, 16);
4115 mxf_primer_pack_add_mapping (primer, 0x2f01, &t->ul);
4116 ret = g_list_prepend (ret, t);
4123 mxf_metadata_generic_descriptor_init (MXFMetadataGenericDescriptor * self)
4129 mxf_metadata_generic_descriptor_class_init (MXFMetadataGenericDescriptorClass *
4132 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
4133 GObjectClass *object_class = (GObjectClass *) klass;
4135 object_class->finalize = mxf_metadata_generic_descriptor_finalize;
4136 metadata_base_class->handle_tag = mxf_metadata_generic_descriptor_handle_tag;
4137 metadata_base_class->resolve = mxf_metadata_generic_descriptor_resolve;
4138 metadata_base_class->to_structure =
4139 mxf_metadata_generic_descriptor_to_structure;
4140 metadata_base_class->write_tags = mxf_metadata_generic_descriptor_write_tags;
4143 G_DEFINE_TYPE (MXFMetadataFileDescriptor, mxf_metadata_file_descriptor,
4144 MXF_TYPE_METADATA_GENERIC_DESCRIPTOR);
4147 mxf_metadata_file_descriptor_handle_tag (MXFMetadataBase * metadata,
4148 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
4151 MXFMetadataFileDescriptor *self = MXF_METADATA_FILE_DESCRIPTOR (metadata);
4152 gboolean ret = TRUE;
4153 #ifndef GST_DISABLE_GST_DEBUG
4161 self->linked_track_id = GST_READ_UINT32_BE (tag_data);
4162 GST_DEBUG (" linked track id = %u", self->linked_track_id);
4165 if (!mxf_fraction_parse (&self->sample_rate, tag_data, tag_size))
4167 GST_DEBUG (" sample rate = %d/%d", self->sample_rate.n,
4168 self->sample_rate.d);
4173 self->container_duration = GST_READ_UINT64_BE (tag_data);
4174 GST_DEBUG (" container duration = %" G_GINT64_FORMAT,
4175 self->container_duration);
4180 memcpy (&self->essence_container, tag_data, 16);
4181 GST_DEBUG (" essence container = %s",
4182 mxf_ul_to_string (&self->essence_container, str));
4187 memcpy (&self->codec, tag_data, 16);
4188 GST_DEBUG (" codec = %s", mxf_ul_to_string (&self->codec, str));
4192 MXF_METADATA_BASE_CLASS
4193 (mxf_metadata_file_descriptor_parent_class)->handle_tag (metadata,
4194 primer, tag, tag_data, tag_size);
4202 GST_ERROR ("Invalid file descriptor local tag 0x%04x of size %u", tag,
4208 static GstStructure *
4209 mxf_metadata_file_descriptor_to_structure (MXFMetadataBase * m)
4212 MXF_METADATA_BASE_CLASS
4213 (mxf_metadata_file_descriptor_parent_class)->to_structure (m);
4214 MXFMetadataFileDescriptor *self = MXF_METADATA_FILE_DESCRIPTOR (m);
4217 if (self->linked_track_id)
4218 gst_structure_id_set (ret, MXF_QUARK (LINKED_TRACK_ID), G_TYPE_UINT,
4219 self->linked_track_id, NULL);
4221 if (self->sample_rate.n && self->sample_rate.d)
4222 gst_structure_id_set (ret, MXF_QUARK (SAMPLE_RATE), GST_TYPE_FRACTION,
4223 self->sample_rate.n, self->sample_rate.d, NULL);
4225 if (self->container_duration)
4226 gst_structure_id_set (ret, MXF_QUARK (CONTAINER_DURATION), G_TYPE_INT64,
4227 self->container_duration, NULL);
4229 mxf_ul_to_string (&self->essence_container, str);
4230 gst_structure_id_set (ret, MXF_QUARK (ESSENCE_CONTAINER), G_TYPE_STRING, str,
4233 if (!mxf_ul_is_zero (&self->codec)) {
4234 mxf_ul_to_string (&self->codec, str);
4235 gst_structure_id_set (ret, MXF_QUARK (CODEC), G_TYPE_STRING, str, NULL);
4242 mxf_metadata_file_descriptor_write_tags (MXFMetadataBase * m,
4243 MXFPrimerPack * primer)
4245 MXFMetadataFileDescriptor *self = MXF_METADATA_FILE_DESCRIPTOR (m);
4247 MXF_METADATA_BASE_CLASS
4248 (mxf_metadata_file_descriptor_parent_class)->write_tags (m, primer);
4251 if (self->linked_track_id) {
4252 t = g_slice_new0 (MXFLocalTag);
4253 memcpy (&t->ul, MXF_UL (LINKED_TRACK_ID), 16);
4255 t->data = g_slice_alloc (t->size);
4257 GST_WRITE_UINT32_BE (t->data, self->linked_track_id);
4258 mxf_primer_pack_add_mapping (primer, 0x3006, &t->ul);
4259 ret = g_list_prepend (ret, t);
4262 t = g_slice_new0 (MXFLocalTag);
4263 memcpy (&t->ul, MXF_UL (SAMPLE_RATE), 16);
4265 t->data = g_slice_alloc (t->size);
4267 GST_WRITE_UINT32_BE (t->data, self->sample_rate.n);
4268 GST_WRITE_UINT32_BE (t->data + 4, self->sample_rate.d);
4269 mxf_primer_pack_add_mapping (primer, 0x3001, &t->ul);
4270 ret = g_list_prepend (ret, t);
4272 if (self->container_duration > 0) {
4273 t = g_slice_new0 (MXFLocalTag);
4274 memcpy (&t->ul, MXF_UL (CONTAINER_DURATION), 16);
4276 t->data = g_slice_alloc (t->size);
4278 GST_WRITE_UINT64_BE (t->data, self->container_duration);
4279 mxf_primer_pack_add_mapping (primer, 0x3002, &t->ul);
4280 ret = g_list_prepend (ret, t);
4283 t = g_slice_new0 (MXFLocalTag);
4284 memcpy (&t->ul, MXF_UL (ESSENCE_CONTAINER), 16);
4286 t->data = g_slice_alloc (t->size);
4288 memcpy (t->data, &self->essence_container, 16);
4289 mxf_primer_pack_add_mapping (primer, 0x3004, &t->ul);
4290 ret = g_list_prepend (ret, t);
4292 if (!mxf_ul_is_zero (&self->codec)) {
4293 t = g_slice_new0 (MXFLocalTag);
4294 memcpy (&t->ul, MXF_UL (CODEC), 16);
4296 t->data = g_slice_alloc (t->size);
4298 memcpy (t->data, &self->codec, 16);
4299 mxf_primer_pack_add_mapping (primer, 0x3005, &t->ul);
4300 ret = g_list_prepend (ret, t);
4307 mxf_metadata_file_descriptor_init (MXFMetadataFileDescriptor * self)
4313 mxf_metadata_file_descriptor_class_init (MXFMetadataFileDescriptorClass * klass)
4315 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
4316 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
4318 metadata_base_class->handle_tag = mxf_metadata_file_descriptor_handle_tag;
4319 metadata_base_class->name_quark = MXF_QUARK (FILE_DESCRIPTOR);
4320 metadata_base_class->to_structure = mxf_metadata_file_descriptor_to_structure;
4321 metadata_base_class->write_tags = mxf_metadata_file_descriptor_write_tags;
4322 metadata_class->type = 0x0125;
4325 G_DEFINE_TYPE (MXFMetadataGenericPictureEssenceDescriptor,
4326 mxf_metadata_generic_picture_essence_descriptor,
4327 MXF_TYPE_METADATA_FILE_DESCRIPTOR);
4330 mxf_metadata_generic_picture_essence_descriptor_handle_tag (MXFMetadataBase *
4331 metadata, MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
4334 MXFMetadataGenericPictureEssenceDescriptor *self =
4335 MXF_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR (metadata);
4336 gboolean ret = TRUE;
4337 #ifndef GST_DISABLE_GST_DEBUG
4345 self->signal_standard = GST_READ_UINT8 (tag_data);
4346 GST_DEBUG (" signal standard = %u", self->signal_standard);
4351 self->frame_layout = GST_READ_UINT8 (tag_data);
4352 GST_DEBUG (" frame layout = %u", self->frame_layout);
4357 self->stored_width = GST_READ_UINT32_BE (tag_data);
4358 GST_DEBUG (" stored width = %u", self->stored_width);
4363 self->stored_height = GST_READ_UINT32_BE (tag_data);
4364 GST_DEBUG (" stored height = %u", self->stored_height);
4369 self->stored_f2_offset = GST_READ_UINT32_BE (tag_data);
4370 GST_DEBUG (" stored f2 offset = %d", self->stored_f2_offset);
4375 self->sampled_width = GST_READ_UINT32_BE (tag_data);
4376 GST_DEBUG (" sampled width = %u", self->sampled_width);
4381 self->sampled_height = GST_READ_UINT32_BE (tag_data);
4382 GST_DEBUG (" sampled height = %u", self->sampled_height);
4387 self->sampled_x_offset = GST_READ_UINT32_BE (tag_data);
4388 GST_DEBUG (" sampled x offset = %d", self->sampled_x_offset);
4393 self->sampled_y_offset = GST_READ_UINT32_BE (tag_data);
4394 GST_DEBUG (" sampled y offset = %d", self->sampled_y_offset);
4399 self->display_height = GST_READ_UINT32_BE (tag_data);
4400 GST_DEBUG (" display height = %u", self->display_height);
4405 self->display_width = GST_READ_UINT32_BE (tag_data);
4406 GST_DEBUG (" display width = %u", self->display_width);
4411 self->display_x_offset = GST_READ_UINT32_BE (tag_data);
4412 GST_DEBUG (" display x offset = %d", self->display_x_offset);
4417 self->display_y_offset = GST_READ_UINT32_BE (tag_data);
4418 GST_DEBUG (" display y offset = %d", self->display_y_offset);
4423 self->display_f2_offset = GST_READ_UINT32_BE (tag_data);
4424 GST_DEBUG (" display f2 offset = %d", self->display_f2_offset);
4427 if (!mxf_fraction_parse (&self->aspect_ratio, tag_data, tag_size))
4429 GST_DEBUG (" aspect ratio = %d/%d", self->aspect_ratio.n,
4430 self->aspect_ratio.d);
4435 self->active_format_descriptor = GST_READ_UINT8 (tag_data);
4436 GST_DEBUG (" active format descriptor = %u",
4437 self->active_format_descriptor);
4443 if (GST_READ_UINT32_BE (tag_data) == 0)
4446 if (GST_READ_UINT32_BE (tag_data + 4) != 4)
4449 if (GST_READ_UINT32_BE (tag_data) != 1 &&
4450 GST_READ_UINT32_BE (tag_data) != 2)
4453 if ((GST_READ_UINT32_BE (tag_data) == 1 && tag_size != 12) ||
4454 (GST_READ_UINT32_BE (tag_data) == 2 && tag_size != 16))
4457 self->video_line_map[0] = GST_READ_UINT32_BE (tag_data + 8);
4459 /* Workaround for files created by ffmpeg */
4460 if (GST_READ_UINT32_BE (tag_data) == 1)
4461 self->video_line_map[0] = 0;
4463 self->video_line_map[1] = GST_READ_UINT32_BE (tag_data + 12);
4465 GST_DEBUG (" video line map = {%i, %i}", self->video_line_map[0],
4466 self->video_line_map[1]);
4471 self->alpha_transparency = GST_READ_UINT8 (tag_data);
4472 GST_DEBUG (" alpha transparency = %u", self->alpha_transparency);
4477 memcpy (&self->capture_gamma, tag_data, 16);
4478 GST_DEBUG (" capture gamma = %s",
4479 mxf_ul_to_string (&self->capture_gamma, str));
4484 self->image_alignment_offset = GST_READ_UINT32_BE (tag_data);
4485 GST_DEBUG (" image alignment offset = %u", self->image_alignment_offset);
4490 self->image_start_offset = GST_READ_UINT32_BE (tag_data);
4491 GST_DEBUG (" image start offset = %u", self->image_start_offset);
4496 self->image_end_offset = GST_READ_UINT32_BE (tag_data);
4497 GST_DEBUG (" image end offset = %u", self->image_end_offset);
4502 self->field_dominance = GST_READ_UINT8 (tag_data);
4503 GST_DEBUG (" field dominance = %u", self->field_dominance);
4508 memcpy (&self->picture_essence_coding, tag_data, 16);
4509 GST_DEBUG (" picture essence coding = %s",
4510 mxf_ul_to_string (&self->picture_essence_coding, str));
4514 MXF_METADATA_BASE_CLASS
4515 (mxf_metadata_generic_picture_essence_descriptor_parent_class)->handle_tag
4516 (metadata, primer, tag, tag_data, tag_size);
4525 ("Invalid generic picture essence descriptor local tag 0x%04x of size %u",
4531 static GstStructure *
4532 mxf_metadata_generic_picture_essence_descriptor_to_structure (MXFMetadataBase *
4536 MXF_METADATA_BASE_CLASS
4537 (mxf_metadata_generic_picture_essence_descriptor_parent_class)->to_structure
4539 MXFMetadataGenericPictureEssenceDescriptor *self =
4540 MXF_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR (m);
4543 gst_structure_id_set (ret, MXF_QUARK (SIGNAL_STANDARD), G_TYPE_UCHAR,
4544 self->signal_standard, NULL);
4546 gst_structure_id_set (ret, MXF_QUARK (FRAME_LAYOUT), G_TYPE_UCHAR,
4547 self->frame_layout, NULL);
4549 gst_structure_id_set (ret, MXF_QUARK (STORED_WIDTH), G_TYPE_UINT,
4550 self->stored_width, MXF_QUARK (STORED_HEIGHT), G_TYPE_UINT,
4551 self->stored_height, NULL);
4553 if (self->stored_f2_offset != 0)
4554 gst_structure_id_set (ret, MXF_QUARK (STORED_F2_OFFSET), G_TYPE_INT,
4555 self->stored_f2_offset, NULL);
4557 if (self->sampled_width != 0 && self->sampled_height != 0)
4558 gst_structure_id_set (ret, MXF_QUARK (SAMPLED_WIDTH), G_TYPE_UINT,
4559 self->sampled_width, MXF_QUARK (SAMPLED_HEIGHT), G_TYPE_UINT,
4560 self->sampled_height, NULL);
4562 if (self->sampled_x_offset != 0)
4563 gst_structure_id_set (ret, MXF_QUARK (SAMPLED_X_OFFSET), G_TYPE_INT,
4564 self->sampled_x_offset, NULL);
4566 if (self->sampled_y_offset != 0)
4567 gst_structure_id_set (ret, MXF_QUARK (SAMPLED_Y_OFFSET), G_TYPE_INT,
4568 self->sampled_y_offset, NULL);
4570 if (self->display_width != 0 && self->display_height != 0)
4571 gst_structure_id_set (ret, MXF_QUARK (DISPLAY_WIDTH), G_TYPE_UINT,
4572 self->display_width, MXF_QUARK (DISPLAY_HEIGHT), G_TYPE_UINT,
4573 self->display_height, NULL);
4575 if (self->display_x_offset != 0)
4576 gst_structure_id_set (ret, MXF_QUARK (DISPLAY_X_OFFSET), G_TYPE_INT,
4577 self->display_x_offset, NULL);
4579 if (self->display_y_offset != 0)
4580 gst_structure_id_set (ret, MXF_QUARK (DISPLAY_Y_OFFSET), G_TYPE_INT,
4581 self->display_y_offset, NULL);
4583 if (self->display_f2_offset != 0)
4584 gst_structure_id_set (ret, MXF_QUARK (DISPLAY_F2_OFFSET), G_TYPE_INT,
4585 self->display_f2_offset, NULL);
4587 if (self->aspect_ratio.n != 0 && self->aspect_ratio.d != 0)
4588 gst_structure_id_set (ret, MXF_QUARK (ASPECT_RATIO), GST_TYPE_FRACTION,
4589 self->aspect_ratio.n, self->aspect_ratio.d, NULL);
4591 if (self->active_format_descriptor)
4592 gst_structure_id_set (ret, MXF_QUARK (ACTIVE_FORMAT_DESCRIPTOR),
4593 G_TYPE_UCHAR, self->active_format_descriptor, NULL);
4595 gst_structure_id_set (ret, MXF_QUARK (VIDEO_LINE_MAP_0), G_TYPE_UINT,
4596 self->video_line_map[0], MXF_QUARK (VIDEO_LINE_MAP_1), G_TYPE_UINT,
4597 self->video_line_map[1], NULL);
4599 if (self->alpha_transparency != 0)
4600 gst_structure_id_set (ret, MXF_QUARK (ALPHA_TRANSPARENCY), G_TYPE_UCHAR,
4601 self->alpha_transparency, NULL);
4603 if (!mxf_ul_is_zero (&self->capture_gamma)) {
4604 mxf_ul_to_string (&self->capture_gamma, str);
4605 gst_structure_id_set (ret, MXF_QUARK (CAPTURE_GAMMA), G_TYPE_STRING, str,
4609 if (self->image_alignment_offset != 0)
4610 gst_structure_id_set (ret, MXF_QUARK (IMAGE_ALIGNMENT_OFFSET), G_TYPE_UINT,
4611 self->image_alignment_offset, NULL);
4613 if (self->image_start_offset != 0)
4614 gst_structure_id_set (ret, MXF_QUARK (IMAGE_START_OFFSET), G_TYPE_UINT,
4615 self->image_start_offset, NULL);
4617 if (self->image_end_offset != 0)
4618 gst_structure_id_set (ret, MXF_QUARK (IMAGE_END_OFFSET), G_TYPE_UINT,
4619 self->image_end_offset, NULL);
4621 if (self->field_dominance != 0)
4622 gst_structure_id_set (ret, MXF_QUARK (FIELD_DOMINANCE), G_TYPE_UCHAR,
4623 self->field_dominance, NULL);
4625 if (!mxf_ul_is_zero (&self->picture_essence_coding)) {
4626 mxf_ul_to_string (&self->picture_essence_coding, str);
4627 gst_structure_id_set (ret, MXF_QUARK (PICTURE_ESSENCE_CODING),
4628 G_TYPE_STRING, str, NULL);
4635 mxf_metadata_generic_picture_essence_descriptor_write_tags (MXFMetadataBase * m,
4636 MXFPrimerPack * primer)
4638 MXFMetadataGenericPictureEssenceDescriptor *self =
4639 MXF_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR (m);
4641 MXF_METADATA_BASE_CLASS
4642 (mxf_metadata_generic_picture_essence_descriptor_parent_class)->write_tags
4646 if (self->signal_standard != 1) {
4647 t = g_slice_new0 (MXFLocalTag);
4648 memcpy (&t->ul, MXF_UL (SIGNAL_STANDARD), 16);
4650 t->data = g_slice_alloc (t->size);
4652 GST_WRITE_UINT8 (t->data, self->signal_standard);
4653 mxf_primer_pack_add_mapping (primer, 0x3215, &t->ul);
4654 ret = g_list_prepend (ret, t);
4657 t = g_slice_new0 (MXFLocalTag);
4658 memcpy (&t->ul, MXF_UL (FRAME_LAYOUT), 16);
4660 t->data = g_slice_alloc (t->size);
4662 GST_WRITE_UINT8 (t->data, self->frame_layout);
4663 mxf_primer_pack_add_mapping (primer, 0x320c, &t->ul);
4664 ret = g_list_prepend (ret, t);
4666 t = g_slice_new0 (MXFLocalTag);
4667 memcpy (&t->ul, MXF_UL (STORED_WIDTH), 16);
4669 t->data = g_slice_alloc (t->size);
4671 GST_WRITE_UINT32_BE (t->data, self->stored_width);
4672 mxf_primer_pack_add_mapping (primer, 0x3203, &t->ul);
4673 ret = g_list_prepend (ret, t);
4675 t = g_slice_new0 (MXFLocalTag);
4676 memcpy (&t->ul, MXF_UL (STORED_HEIGHT), 16);
4678 t->data = g_slice_alloc (t->size);
4680 GST_WRITE_UINT32_BE (t->data, self->stored_height);
4681 mxf_primer_pack_add_mapping (primer, 0x3202, &t->ul);
4682 ret = g_list_prepend (ret, t);
4684 if (self->stored_f2_offset != 0) {
4685 t = g_slice_new0 (MXFLocalTag);
4686 memcpy (&t->ul, MXF_UL (STORED_F2_OFFSET), 16);
4688 t->data = g_slice_alloc (t->size);
4690 GST_WRITE_UINT32_BE (t->data, self->stored_f2_offset);
4691 mxf_primer_pack_add_mapping (primer, 0x3216, &t->ul);
4692 ret = g_list_prepend (ret, t);
4695 if (self->sampled_width != 0) {
4696 t = g_slice_new0 (MXFLocalTag);
4697 memcpy (&t->ul, MXF_UL (SAMPLED_WIDTH), 16);
4699 t->data = g_slice_alloc (t->size);
4701 GST_WRITE_UINT32_BE (t->data, self->sampled_width);
4702 mxf_primer_pack_add_mapping (primer, 0x3205, &t->ul);
4703 ret = g_list_prepend (ret, t);
4706 if (self->sampled_height != 0) {
4707 t = g_slice_new0 (MXFLocalTag);
4708 memcpy (&t->ul, MXF_UL (SAMPLED_HEIGHT), 16);
4710 t->data = g_slice_alloc (t->size);
4712 GST_WRITE_UINT32_BE (t->data, self->sampled_height);
4713 mxf_primer_pack_add_mapping (primer, 0x3204, &t->ul);
4714 ret = g_list_prepend (ret, t);
4717 if (self->sampled_x_offset != 0) {
4718 t = g_slice_new0 (MXFLocalTag);
4719 memcpy (&t->ul, MXF_UL (SAMPLED_X_OFFSET), 16);
4721 t->data = g_slice_alloc (t->size);
4723 GST_WRITE_UINT32_BE (t->data, self->sampled_x_offset);
4724 mxf_primer_pack_add_mapping (primer, 0x3206, &t->ul);
4725 ret = g_list_prepend (ret, t);
4728 if (self->sampled_y_offset != 0) {
4729 t = g_slice_new0 (MXFLocalTag);
4730 memcpy (&t->ul, MXF_UL (SAMPLED_Y_OFFSET), 16);
4732 t->data = g_slice_alloc (t->size);
4734 GST_WRITE_UINT32_BE (t->data, self->sampled_y_offset);
4735 mxf_primer_pack_add_mapping (primer, 0x3207, &t->ul);
4736 ret = g_list_prepend (ret, t);
4739 if (self->display_height != 0) {
4740 t = g_slice_new0 (MXFLocalTag);
4741 memcpy (&t->ul, MXF_UL (DISPLAY_HEIGHT), 16);
4743 t->data = g_slice_alloc (t->size);
4745 GST_WRITE_UINT32_BE (t->data, self->display_height);
4746 mxf_primer_pack_add_mapping (primer, 0x3208, &t->ul);
4747 ret = g_list_prepend (ret, t);
4750 if (self->display_width != 0) {
4751 t = g_slice_new0 (MXFLocalTag);
4752 memcpy (&t->ul, MXF_UL (DISPLAY_WIDTH), 16);
4754 t->data = g_slice_alloc (t->size);
4756 GST_WRITE_UINT32_BE (t->data, self->display_width);
4757 mxf_primer_pack_add_mapping (primer, 0x3209, &t->ul);
4758 ret = g_list_prepend (ret, t);
4761 if (self->display_x_offset != 0) {
4762 t = g_slice_new0 (MXFLocalTag);
4763 memcpy (&t->ul, MXF_UL (DISPLAY_X_OFFSET), 16);
4765 t->data = g_slice_alloc (t->size);
4767 GST_WRITE_UINT32_BE (t->data, self->display_x_offset);
4768 mxf_primer_pack_add_mapping (primer, 0x320a, &t->ul);
4769 ret = g_list_prepend (ret, t);
4772 if (self->display_y_offset != 0) {
4773 t = g_slice_new0 (MXFLocalTag);
4774 memcpy (&t->ul, MXF_UL (DISPLAY_Y_OFFSET), 16);
4776 t->data = g_slice_alloc (t->size);
4778 GST_WRITE_UINT32_BE (t->data, self->display_y_offset);
4779 mxf_primer_pack_add_mapping (primer, 0x320b, &t->ul);
4780 ret = g_list_prepend (ret, t);
4783 if (self->display_f2_offset != 0) {
4784 t = g_slice_new0 (MXFLocalTag);
4785 memcpy (&t->ul, MXF_UL (DISPLAY_F2_OFFSET), 16);
4787 t->data = g_slice_alloc (t->size);
4789 GST_WRITE_UINT32_BE (t->data, self->display_f2_offset);
4790 mxf_primer_pack_add_mapping (primer, 0x3217, &t->ul);
4791 ret = g_list_prepend (ret, t);
4794 t = g_slice_new0 (MXFLocalTag);
4795 memcpy (&t->ul, MXF_UL (ASPECT_RATIO), 16);
4797 t->data = g_slice_alloc (t->size);
4799 GST_WRITE_UINT32_BE (t->data, self->aspect_ratio.n);
4800 GST_WRITE_UINT32_BE (t->data + 4, self->aspect_ratio.d);
4801 mxf_primer_pack_add_mapping (primer, 0x320e, &t->ul);
4802 ret = g_list_prepend (ret, t);
4804 if (self->active_format_descriptor != 0) {
4805 t = g_slice_new0 (MXFLocalTag);
4806 memcpy (&t->ul, MXF_UL (ACTIVE_FORMAT_DESCRIPTOR), 16);
4808 t->data = g_slice_alloc (t->size);
4810 GST_WRITE_UINT8 (t->data, self->active_format_descriptor);
4811 mxf_primer_pack_add_mapping (primer, 0x3218, &t->ul);
4812 ret = g_list_prepend (ret, t);
4815 t = g_slice_new0 (MXFLocalTag);
4816 memcpy (&t->ul, MXF_UL (VIDEO_LINE_MAP), 16);
4818 t->data = g_slice_alloc (t->size);
4820 GST_WRITE_UINT32_BE (t->data, 2);
4821 GST_WRITE_UINT32_BE (t->data + 4, 4);
4822 GST_WRITE_UINT32_BE (t->data + 8, self->video_line_map[0]);
4823 GST_WRITE_UINT32_BE (t->data + 12, self->video_line_map[1]);
4824 mxf_primer_pack_add_mapping (primer, 0x320d, &t->ul);
4825 ret = g_list_prepend (ret, t);
4827 if (self->alpha_transparency != 0) {
4828 t = g_slice_new0 (MXFLocalTag);
4829 memcpy (&t->ul, MXF_UL (ALPHA_TRANSPARENCY), 16);
4831 t->data = g_slice_alloc (t->size);
4833 GST_WRITE_UINT8 (t->data, self->alpha_transparency);
4834 mxf_primer_pack_add_mapping (primer, 0x320f, &t->ul);
4835 ret = g_list_prepend (ret, t);
4838 if (!mxf_ul_is_zero (&self->capture_gamma)) {
4839 t = g_slice_new0 (MXFLocalTag);
4840 memcpy (&t->ul, MXF_UL (CAPTURE_GAMMA), 16);
4842 t->data = g_slice_alloc (t->size);
4844 memcpy (t->data, &self->capture_gamma, 16);
4845 mxf_primer_pack_add_mapping (primer, 0x3210, &t->ul);
4846 ret = g_list_prepend (ret, t);
4849 if (self->image_alignment_offset != 0) {
4850 t = g_slice_new0 (MXFLocalTag);
4851 memcpy (&t->ul, MXF_UL (IMAGE_ALIGNMENT_OFFSET), 16);
4853 t->data = g_slice_alloc (t->size);
4855 GST_WRITE_UINT32_BE (t->data, self->image_alignment_offset);
4856 mxf_primer_pack_add_mapping (primer, 0x3211, &t->ul);
4857 ret = g_list_prepend (ret, t);
4860 if (self->image_start_offset != 0) {
4861 t = g_slice_new0 (MXFLocalTag);
4862 memcpy (&t->ul, MXF_UL (IMAGE_START_OFFSET), 16);
4864 t->data = g_slice_alloc (t->size);
4866 GST_WRITE_UINT32_BE (t->data, self->image_start_offset);
4867 mxf_primer_pack_add_mapping (primer, 0x3213, &t->ul);
4868 ret = g_list_prepend (ret, t);
4871 if (self->image_end_offset != 0) {
4872 t = g_slice_new0 (MXFLocalTag);
4873 memcpy (&t->ul, MXF_UL (IMAGE_END_OFFSET), 16);
4875 t->data = g_slice_alloc (t->size);
4877 GST_WRITE_UINT32_BE (t->data, self->image_end_offset);
4878 mxf_primer_pack_add_mapping (primer, 0x3214, &t->ul);
4879 ret = g_list_prepend (ret, t);
4882 if (self->field_dominance != 0) {
4883 t = g_slice_new0 (MXFLocalTag);
4884 memcpy (&t->ul, MXF_UL (FIELD_DOMINANCE), 16);
4886 t->data = g_slice_alloc (t->size);
4888 GST_WRITE_UINT8 (t->data, self->field_dominance);
4889 mxf_primer_pack_add_mapping (primer, 0x3212, &t->ul);
4890 ret = g_list_prepend (ret, t);
4893 if (!mxf_ul_is_zero (&self->picture_essence_coding)) {
4894 t = g_slice_new0 (MXFLocalTag);
4895 memcpy (&t->ul, MXF_UL (PICTURE_ESSENCE_CODING), 16);
4897 t->data = g_slice_alloc (t->size);
4899 memcpy (t->data, &self->picture_essence_coding, 16);
4900 mxf_primer_pack_add_mapping (primer, 0x3201, &t->ul);
4901 ret = g_list_prepend (ret, t);
4908 mxf_metadata_generic_picture_essence_descriptor_init
4909 (MXFMetadataGenericPictureEssenceDescriptor * self)
4911 self->signal_standard = 1;
4912 self->frame_layout = 255;
4916 mxf_metadata_generic_picture_essence_descriptor_class_init
4917 (MXFMetadataGenericPictureEssenceDescriptorClass * klass)
4919 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
4920 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
4922 metadata_base_class->handle_tag =
4923 mxf_metadata_generic_picture_essence_descriptor_handle_tag;
4924 metadata_base_class->name_quark =
4925 MXF_QUARK (GENERIC_PICTURE_ESSENCE_DESCRIPTOR);
4926 metadata_base_class->to_structure =
4927 mxf_metadata_generic_picture_essence_descriptor_to_structure;
4928 metadata_base_class->write_tags =
4929 mxf_metadata_generic_picture_essence_descriptor_write_tags;
4930 metadata_class->type = 0x0127;
4933 void mxf_metadata_generic_picture_essence_descriptor_set_caps
4934 (MXFMetadataGenericPictureEssenceDescriptor * self, GstCaps * caps)
4937 guint width, height;
4938 MXFMetadataFileDescriptor *f = (MXFMetadataFileDescriptor *) self;
4940 g_return_if_fail (MXF_IS_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR (self));
4941 g_return_if_fail (GST_IS_CAPS (caps));
4943 if (f->sample_rate.d == 0) {
4944 GST_ERROR ("Invalid framerate");
4946 gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION, f->sample_rate.n,
4947 f->sample_rate.d, NULL);
4950 width = self->stored_width;
4951 height = self->stored_height;
4952 if (self->sampled_width && self->sampled_height) {
4953 width = self->sampled_width;
4954 height = self->sampled_height;
4956 if (self->display_width && self->display_height) {
4957 width = self->display_width;
4958 height = self->display_height;
4961 /* If the video is stored as separate fields the
4962 * height is only the height of one field, i.e.
4963 * half the height of the frame.
4965 * See SMPTE 377M E2.2 and E1.2
4967 if (self->frame_layout == 1 || self->frame_layout == 2
4968 || self->frame_layout == 4) {
4970 gst_caps_set_simple (caps, "interlaced", G_TYPE_BOOLEAN, TRUE, NULL);
4972 if (self->field_dominance == 2) {
4973 gst_caps_set_simple (caps, "field-order", G_TYPE_STRING,
4974 "bottom-field-first", NULL);
4976 gst_caps_set_simple (caps, "field-order", G_TYPE_STRING,
4977 "top-field-first", NULL);
4981 if (width == 0 || height == 0) {
4982 GST_ERROR ("Invalid width/height");
4986 gst_caps_set_simple (caps, "width", G_TYPE_INT, width, "height", G_TYPE_INT,
4989 if (self->aspect_ratio.n == 0 && self->aspect_ratio.d == 0) {
4990 gst_caps_set_simple (caps, "pixel-aspect-ratio", GST_TYPE_FRACTION,
4992 } else if (self->aspect_ratio.n == 0 || self->aspect_ratio.d == 0) {
4993 GST_ERROR ("Invalid aspect ratio");
4995 par_n = height * self->aspect_ratio.n;
4996 par_d = width * self->aspect_ratio.d;
4998 gst_caps_set_simple (caps, "pixel-aspect-ratio", GST_TYPE_FRACTION,
4999 par_n, par_d, NULL);
5004 gst_greatest_common_divisor (gint a, gint b)
5017 mxf_metadata_generic_picture_essence_descriptor_from_caps
5018 (MXFMetadataGenericPictureEssenceDescriptor * self, GstCaps * caps) {
5019 gint par_n, par_d, gcd;
5022 MXFMetadataFileDescriptor *f = (MXFMetadataFileDescriptor *) self;
5024 gboolean interlaced = FALSE;
5025 const gchar *field_order = NULL;
5027 g_return_val_if_fail (MXF_IS_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR
5029 g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
5031 s = gst_caps_get_structure (caps, 0);
5033 if (!gst_structure_get_boolean (s, "interlaced", &interlaced) || !interlaced) {
5034 self->frame_layout = 0;
5036 self->frame_layout = 3;
5037 field_order = gst_structure_get_string (s, "field-order");
5038 if (!field_order || strcmp (field_order, "top-field-first") == 0)
5039 self->field_dominance = 1;
5041 self->field_dominance = 2;
5044 if (!gst_structure_get_fraction (s, "framerate", &fps_n, &fps_d)) {
5045 GST_ERROR ("Invalid framerate");
5048 f->sample_rate.n = fps_n;
5049 f->sample_rate.d = fps_d;
5051 if (!gst_structure_get_int (s, "width", &width) ||
5052 !gst_structure_get_int (s, "height", &height)) {
5053 GST_ERROR ("Invalid width/height");
5057 self->stored_width = width;
5058 self->stored_height = height;
5060 if (!gst_structure_get_fraction (s, "pixel-aspect-ratio", &par_n, &par_d)) {
5065 self->aspect_ratio.n = par_n * width;
5066 self->aspect_ratio.d = par_d * height;
5068 gst_greatest_common_divisor (self->aspect_ratio.n, self->aspect_ratio.d);
5069 self->aspect_ratio.n /= gcd;
5070 self->aspect_ratio.d /= gcd;
5076 G_DEFINE_TYPE (MXFMetadataGenericSoundEssenceDescriptor,
5077 mxf_metadata_generic_sound_essence_descriptor,
5078 MXF_TYPE_METADATA_FILE_DESCRIPTOR);
5081 mxf_metadata_generic_sound_essence_descriptor_handle_tag (MXFMetadataBase *
5082 metadata, MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
5085 MXFMetadataGenericSoundEssenceDescriptor *self =
5086 MXF_METADATA_GENERIC_SOUND_ESSENCE_DESCRIPTOR (metadata);
5087 gboolean ret = TRUE;
5088 #ifndef GST_DISABLE_GST_DEBUG
5094 if (!mxf_fraction_parse (&self->audio_sampling_rate, tag_data, tag_size))
5096 GST_DEBUG (" audio sampling rate = %d/%d",
5097 self->audio_sampling_rate.n, self->audio_sampling_rate.d);
5102 self->locked = (GST_READ_UINT8 (tag_data) != 0);
5103 GST_DEBUG (" locked = %s", (self->locked) ? "yes" : "no");
5108 self->audio_ref_level = GST_READ_UINT8 (tag_data);
5109 GST_DEBUG (" audio ref level = %d", self->audio_ref_level);
5114 self->electro_spatial_formulation = GST_READ_UINT8 (tag_data);
5115 GST_DEBUG (" electro spatial formulation = %u",
5116 self->electro_spatial_formulation);
5121 self->channel_count = GST_READ_UINT32_BE (tag_data);
5122 GST_DEBUG (" channel count = %u", self->channel_count);
5127 self->quantization_bits = GST_READ_UINT32_BE (tag_data);
5128 GST_DEBUG (" quantization bits = %u", self->quantization_bits);
5133 self->dial_norm = GST_READ_UINT8 (tag_data);
5134 GST_DEBUG (" dial norm = %d", self->dial_norm);
5139 memcpy (&self->sound_essence_compression, tag_data, 16);
5140 GST_DEBUG (" sound essence compression = %s",
5141 mxf_ul_to_string (&self->sound_essence_compression, str));
5145 MXF_METADATA_BASE_CLASS
5146 (mxf_metadata_generic_sound_essence_descriptor_parent_class)->handle_tag
5147 (metadata, primer, tag, tag_data, tag_size);
5156 ("Invalid generic sound essence descriptor local tag 0x%04x of size %u",
5162 static GstStructure *
5163 mxf_metadata_generic_sound_essence_descriptor_to_structure (MXFMetadataBase * m)
5166 MXF_METADATA_BASE_CLASS
5167 (mxf_metadata_generic_sound_essence_descriptor_parent_class)->to_structure
5169 MXFMetadataGenericSoundEssenceDescriptor *self =
5170 MXF_METADATA_GENERIC_SOUND_ESSENCE_DESCRIPTOR (m);
5172 gst_structure_id_set (ret, MXF_QUARK (AUDIO_SAMPLING_RATE), GST_TYPE_FRACTION,
5173 self->audio_sampling_rate.n, self->audio_sampling_rate.d, NULL);
5175 gst_structure_id_set (ret, MXF_QUARK (LOCKED), G_TYPE_BOOLEAN, self->locked,
5178 if (self->electro_spatial_formulation != 0)
5179 gst_structure_id_set (ret, MXF_QUARK (ELECTRO_SPATIAL_FORMULATION),
5180 G_TYPE_UCHAR, self->electro_spatial_formulation, NULL);
5182 gst_structure_id_set (ret, MXF_QUARK (CHANNEL_COUNT), G_TYPE_UINT,
5183 self->channel_count, NULL);
5185 gst_structure_id_set (ret, MXF_QUARK (QUANTIZATION_BITS), G_TYPE_UINT,
5186 self->quantization_bits, NULL);
5188 if (self->dial_norm != 0)
5189 gst_structure_id_set (ret, MXF_QUARK (DIAL_NORM), G_TYPE_CHAR,
5190 self->dial_norm, NULL);
5192 if (!mxf_ul_is_zero (&self->sound_essence_compression)) {
5195 mxf_ul_to_string (&self->sound_essence_compression, str);
5196 gst_structure_id_set (ret, MXF_QUARK (SOUND_ESSENCE_COMPRESSION),
5197 G_TYPE_STRING, str, NULL);
5204 mxf_metadata_generic_sound_essence_descriptor_write_tags (MXFMetadataBase * m,
5205 MXFPrimerPack * primer)
5207 MXFMetadataGenericSoundEssenceDescriptor *self =
5208 MXF_METADATA_GENERIC_SOUND_ESSENCE_DESCRIPTOR (m);
5210 MXF_METADATA_BASE_CLASS
5211 (mxf_metadata_generic_sound_essence_descriptor_parent_class)->write_tags
5215 t = g_slice_new0 (MXFLocalTag);
5216 memcpy (&t->ul, MXF_UL (AUDIO_SAMPLING_RATE), 16);
5218 t->data = g_slice_alloc (t->size);
5220 GST_WRITE_UINT32_BE (t->data, self->audio_sampling_rate.n);
5221 GST_WRITE_UINT32_BE (t->data + 4, self->audio_sampling_rate.d);
5222 mxf_primer_pack_add_mapping (primer, 0x3d03, &t->ul);
5223 ret = g_list_prepend (ret, t);
5225 t = g_slice_new0 (MXFLocalTag);
5226 memcpy (&t->ul, MXF_UL (LOCKED), 16);
5228 t->data = g_slice_alloc (t->size);
5230 GST_WRITE_UINT8 (t->data, (self->locked) ? 1 : 0);
5231 mxf_primer_pack_add_mapping (primer, 0x3d02, &t->ul);
5232 ret = g_list_prepend (ret, t);
5234 if (self->audio_ref_level) {
5235 t = g_slice_new0 (MXFLocalTag);
5236 memcpy (&t->ul, MXF_UL (AUDIO_REF_LEVEL), 16);
5238 t->data = g_slice_alloc (t->size);
5240 GST_WRITE_UINT8 (t->data, self->audio_ref_level);
5241 mxf_primer_pack_add_mapping (primer, 0x3d04, &t->ul);
5242 ret = g_list_prepend (ret, t);
5245 if (self->electro_spatial_formulation != 255) {
5246 t = g_slice_new0 (MXFLocalTag);
5247 memcpy (&t->ul, MXF_UL (ELECTRO_SPATIAL_FORMULATION), 16);
5249 t->data = g_slice_alloc (t->size);
5251 GST_WRITE_UINT8 (t->data, self->electro_spatial_formulation);
5252 mxf_primer_pack_add_mapping (primer, 0x3d05, &t->ul);
5253 ret = g_list_prepend (ret, t);
5256 t = g_slice_new0 (MXFLocalTag);
5257 memcpy (&t->ul, MXF_UL (CHANNEL_COUNT), 16);
5259 t->data = g_slice_alloc (t->size);
5261 GST_WRITE_UINT32_BE (t->data, self->channel_count);
5262 mxf_primer_pack_add_mapping (primer, 0x3d07, &t->ul);
5263 ret = g_list_prepend (ret, t);
5265 t = g_slice_new0 (MXFLocalTag);
5266 memcpy (&t->ul, MXF_UL (QUANTIZATION_BITS), 16);
5268 t->data = g_slice_alloc (t->size);
5270 GST_WRITE_UINT32_BE (t->data, self->quantization_bits);
5271 mxf_primer_pack_add_mapping (primer, 0x3d01, &t->ul);
5272 ret = g_list_prepend (ret, t);
5274 if (self->dial_norm != 0) {
5275 t = g_slice_new0 (MXFLocalTag);
5276 memcpy (&t->ul, MXF_UL (DIAL_NORM), 16);
5278 t->data = g_slice_alloc (t->size);
5280 GST_WRITE_UINT8 (t->data, self->dial_norm);
5281 mxf_primer_pack_add_mapping (primer, 0x3d0c, &t->ul);
5282 ret = g_list_prepend (ret, t);
5285 if (!mxf_ul_is_zero (&self->sound_essence_compression)) {
5286 t = g_slice_new0 (MXFLocalTag);
5287 memcpy (&t->ul, MXF_UL (SOUND_ESSENCE_COMPRESSION), 16);
5289 t->data = g_slice_alloc (t->size);
5291 memcpy (t->data, &self->sound_essence_compression, 16);
5292 mxf_primer_pack_add_mapping (primer, 0x3d06, &t->ul);
5293 ret = g_list_prepend (ret, t);
5300 mxf_metadata_generic_sound_essence_descriptor_init
5301 (MXFMetadataGenericSoundEssenceDescriptor * self)
5303 self->audio_sampling_rate.n = 0;
5304 self->audio_sampling_rate.d = 1;
5305 self->electro_spatial_formulation = 255;
5309 mxf_metadata_generic_sound_essence_descriptor_class_init
5310 (MXFMetadataGenericSoundEssenceDescriptorClass * klass)
5312 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
5313 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
5315 metadata_base_class->handle_tag =
5316 mxf_metadata_generic_sound_essence_descriptor_handle_tag;
5317 metadata_base_class->name_quark =
5318 MXF_QUARK (GENERIC_SOUND_ESSENCE_DESCRIPTOR);
5319 metadata_base_class->to_structure =
5320 mxf_metadata_generic_sound_essence_descriptor_to_structure;
5321 metadata_base_class->write_tags =
5322 mxf_metadata_generic_sound_essence_descriptor_write_tags;
5323 metadata_class->type = 0x0142;
5326 void mxf_metadata_generic_sound_essence_descriptor_set_caps
5327 (MXFMetadataGenericSoundEssenceDescriptor * self, GstCaps * caps)
5329 g_return_if_fail (MXF_IS_METADATA_GENERIC_SOUND_ESSENCE_DESCRIPTOR (self));
5330 g_return_if_fail (GST_IS_CAPS (caps));
5332 if (self->audio_sampling_rate.n == 0 || self->audio_sampling_rate.d == 0) {
5333 GST_ERROR ("Invalid audio sampling rate");
5335 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
5336 (gint) (mxf_fraction_to_double (&self->audio_sampling_rate) + 0.5),
5340 if (self->channel_count == 0) {
5341 GST_ERROR ("Invalid number of channels (0)");
5343 gst_caps_set_simple (caps, "channels", G_TYPE_INT, self->channel_count,
5348 GstCaps *mxf_metadata_generic_sound_essence_descriptor_create_caps
5349 (MXFMetadataGenericSoundEssenceDescriptor * self, GstAudioFormat * format)
5355 g_return_val_if_fail (MXF_IS_METADATA_GENERIC_SOUND_ESSENCE_DESCRIPTOR (self),
5358 gst_audio_info_init (&info);
5360 if (self->audio_sampling_rate.n == 0 || self->audio_sampling_rate.d == 0) {
5361 GST_ERROR ("Invalid audio sampling rate");
5363 rate = (gint) (mxf_fraction_to_double (&self->audio_sampling_rate)
5367 if (self->channel_count == 0) {
5368 GST_ERROR ("Invalid number of channels (0)");
5370 channels = self->channel_count;
5373 gst_audio_info_set_format (&info, *format, rate, channels, NULL);
5375 return gst_audio_info_to_caps (&info);
5379 mxf_metadata_generic_sound_essence_descriptor_from_caps
5380 (MXFMetadataGenericSoundEssenceDescriptor * self, GstCaps * caps) {
5385 g_return_val_if_fail (MXF_IS_METADATA_GENERIC_SOUND_ESSENCE_DESCRIPTOR (self),
5387 g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
5389 s = gst_caps_get_structure (caps, 0);
5391 if (!gst_structure_get_int (s, "rate", &rate) || rate == 0) {
5392 GST_WARNING ("No samplerate");
5395 self->audio_sampling_rate.n = rate;
5396 self->audio_sampling_rate.d = 1;
5399 if (!gst_structure_get_int (s, "channels", &channels) || channels == 0) {
5400 GST_WARNING ("No channels");
5403 self->channel_count = channels;
5410 G_DEFINE_TYPE (MXFMetadataCDCIPictureEssenceDescriptor,
5411 mxf_metadata_cdci_picture_essence_descriptor,
5412 MXF_TYPE_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR);
5415 mxf_metadata_cdci_picture_essence_descriptor_handle_tag (MXFMetadataBase *
5416 metadata, MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
5419 MXFMetadataCDCIPictureEssenceDescriptor *self =
5420 MXF_METADATA_CDCI_PICTURE_ESSENCE_DESCRIPTOR (metadata);
5421 gboolean ret = TRUE;
5427 self->component_depth = GST_READ_UINT32_BE (tag_data);
5428 GST_DEBUG (" component depth = %u", self->component_depth);
5433 self->horizontal_subsampling = GST_READ_UINT32_BE (tag_data);
5434 GST_DEBUG (" horizontal subsampling = %u", self->horizontal_subsampling);
5439 self->vertical_subsampling = GST_READ_UINT32_BE (tag_data);
5440 GST_DEBUG (" vertical subsampling = %u", self->vertical_subsampling);
5445 self->color_siting = GST_READ_UINT8 (tag_data);
5446 GST_DEBUG (" color siting = %u", self->color_siting);
5451 self->reversed_byte_order = GST_READ_UINT8 (tag_data);
5452 GST_DEBUG (" reversed byte order = %s",
5453 (self->reversed_byte_order) ? "yes" : "no");
5458 self->padding_bits = GST_READ_UINT16_BE (tag_data);
5459 GST_DEBUG (" padding bits = %d", self->padding_bits);
5464 self->alpha_sample_depth = GST_READ_UINT32_BE (tag_data);
5465 GST_DEBUG (" alpha sample depth = %u", self->alpha_sample_depth);
5470 self->black_ref_level = GST_READ_UINT32_BE (tag_data);
5471 GST_DEBUG (" black ref level = %u", self->black_ref_level);
5476 self->white_ref_level = GST_READ_UINT32_BE (tag_data);
5477 GST_DEBUG (" white ref level = %u", self->white_ref_level);
5482 self->color_range = GST_READ_UINT32_BE (tag_data);
5483 GST_DEBUG (" color range = %u", self->color_range);
5487 MXF_METADATA_BASE_CLASS
5488 (mxf_metadata_cdci_picture_essence_descriptor_parent_class)->handle_tag
5489 (metadata, primer, tag, tag_data, tag_size);
5498 ("Invalid CDCI picture essence descriptor local tag 0x%04x of size %u",
5504 static GstStructure *
5505 mxf_metadata_cdci_picture_essence_descriptor_to_structure (MXFMetadataBase * m)
5508 MXF_METADATA_BASE_CLASS
5509 (mxf_metadata_cdci_picture_essence_descriptor_parent_class)->to_structure
5511 MXFMetadataCDCIPictureEssenceDescriptor *self =
5512 MXF_METADATA_CDCI_PICTURE_ESSENCE_DESCRIPTOR (m);
5514 gst_structure_id_set (ret, MXF_QUARK (COMPONENT_DEPTH), G_TYPE_UINT,
5515 self->component_depth, NULL);
5517 gst_structure_id_set (ret, MXF_QUARK (HORIZONTAL_SUBSAMPLING), G_TYPE_UINT,
5518 self->horizontal_subsampling, NULL);
5520 if (self->vertical_subsampling != 0)
5521 gst_structure_id_set (ret, MXF_QUARK (VERTICAL_SUBSAMPLING), G_TYPE_UINT,
5522 self->vertical_subsampling, NULL);
5524 if (self->color_siting != 255)
5525 gst_structure_id_set (ret, MXF_QUARK (COLOR_SITING), G_TYPE_UCHAR,
5526 self->color_siting, NULL);
5528 gst_structure_id_set (ret, MXF_QUARK (REVERSED_BYTE_ORDER), G_TYPE_BOOLEAN,
5529 self->reversed_byte_order, NULL);
5531 if (self->padding_bits != 0)
5532 gst_structure_id_set (ret, MXF_QUARK (PADDING_BITS), G_TYPE_INT,
5533 self->padding_bits, NULL);
5535 if (self->alpha_sample_depth != 0)
5536 gst_structure_id_set (ret, MXF_QUARK (ALPHA_SAMPLE_DEPTH), G_TYPE_UINT,
5537 self->alpha_sample_depth, NULL);
5539 if (self->black_ref_level != 0)
5540 gst_structure_id_set (ret, MXF_QUARK (BLACK_REF_LEVEL), G_TYPE_UINT,
5541 self->black_ref_level, NULL);
5543 if (self->white_ref_level != 0)
5544 gst_structure_id_set (ret, MXF_QUARK (WHITE_REF_LEVEL), G_TYPE_UINT,
5545 self->white_ref_level, NULL);
5547 if (self->color_range != 0)
5548 gst_structure_id_set (ret, MXF_QUARK (COLOR_RANGE), G_TYPE_UINT,
5549 self->color_range, NULL);
5555 mxf_metadata_cdci_picture_essence_descriptor_write_tags (MXFMetadataBase * m,
5556 MXFPrimerPack * primer)
5558 MXFMetadataCDCIPictureEssenceDescriptor *self =
5559 MXF_METADATA_CDCI_PICTURE_ESSENCE_DESCRIPTOR (m);
5561 MXF_METADATA_BASE_CLASS
5562 (mxf_metadata_cdci_picture_essence_descriptor_parent_class)->write_tags
5566 t = g_slice_new0 (MXFLocalTag);
5567 memcpy (&t->ul, MXF_UL (COMPONENT_DEPTH), 16);
5569 t->data = g_slice_alloc (t->size);
5571 GST_WRITE_UINT32_BE (t->data, self->component_depth);
5572 mxf_primer_pack_add_mapping (primer, 0x3301, &t->ul);
5573 ret = g_list_prepend (ret, t);
5575 t = g_slice_new0 (MXFLocalTag);
5576 memcpy (&t->ul, MXF_UL (HORIZONTAL_SUBSAMPLING), 16);
5578 t->data = g_slice_alloc (t->size);
5580 GST_WRITE_UINT32_BE (t->data, self->horizontal_subsampling);
5581 mxf_primer_pack_add_mapping (primer, 0x3302, &t->ul);
5582 ret = g_list_prepend (ret, t);
5584 if (self->vertical_subsampling) {
5585 t = g_slice_new0 (MXFLocalTag);
5586 memcpy (&t->ul, MXF_UL (VERTICAL_SUBSAMPLING), 16);
5588 t->data = g_slice_alloc (t->size);
5590 GST_WRITE_UINT32_BE (t->data, self->vertical_subsampling);
5591 mxf_primer_pack_add_mapping (primer, 0x3308, &t->ul);
5592 ret = g_list_prepend (ret, t);
5595 if (self->color_siting != 0xff) {
5596 t = g_slice_new0 (MXFLocalTag);
5597 memcpy (&t->ul, MXF_UL (COLOR_SITING), 16);
5599 t->data = g_slice_alloc (t->size);
5601 GST_WRITE_UINT8 (t->data, self->color_siting);
5602 mxf_primer_pack_add_mapping (primer, 0x3303, &t->ul);
5603 ret = g_list_prepend (ret, t);
5606 if (self->reversed_byte_order) {
5607 t = g_slice_new0 (MXFLocalTag);
5608 memcpy (&t->ul, MXF_UL (REVERSED_BYTE_ORDER), 16);
5610 t->data = g_slice_alloc (t->size);
5612 GST_WRITE_UINT8 (t->data, (self->reversed_byte_order) ? 1 : 0);
5613 mxf_primer_pack_add_mapping (primer, 0x330b, &t->ul);
5614 ret = g_list_prepend (ret, t);
5617 if (self->padding_bits) {
5618 t = g_slice_new0 (MXFLocalTag);
5619 memcpy (&t->ul, MXF_UL (PADDING_BITS), 16);
5621 t->data = g_slice_alloc (t->size);
5623 GST_WRITE_UINT16_BE (t->data, self->padding_bits);
5624 mxf_primer_pack_add_mapping (primer, 0x3307, &t->ul);
5625 ret = g_list_prepend (ret, t);
5628 if (self->alpha_sample_depth) {
5629 t = g_slice_new0 (MXFLocalTag);
5630 memcpy (&t->ul, MXF_UL (ALPHA_SAMPLE_DEPTH), 16);
5632 t->data = g_slice_alloc (t->size);
5634 GST_WRITE_UINT32_BE (t->data, self->alpha_sample_depth);
5635 mxf_primer_pack_add_mapping (primer, 0x3309, &t->ul);
5636 ret = g_list_prepend (ret, t);
5639 if (self->black_ref_level) {
5640 t = g_slice_new0 (MXFLocalTag);
5641 memcpy (&t->ul, MXF_UL (BLACK_REF_LEVEL), 16);
5643 t->data = g_slice_alloc (t->size);
5645 GST_WRITE_UINT32_BE (t->data, self->black_ref_level);
5646 mxf_primer_pack_add_mapping (primer, 0x3304, &t->ul);
5647 ret = g_list_prepend (ret, t);
5650 if (self->white_ref_level) {
5651 t = g_slice_new0 (MXFLocalTag);
5652 memcpy (&t->ul, MXF_UL (WHITE_REF_LEVEL), 16);
5654 t->data = g_slice_alloc (t->size);
5656 GST_WRITE_UINT32_BE (t->data, self->white_ref_level);
5657 mxf_primer_pack_add_mapping (primer, 0x3305, &t->ul);
5658 ret = g_list_prepend (ret, t);
5661 if (self->color_range) {
5662 t = g_slice_new0 (MXFLocalTag);
5663 memcpy (&t->ul, MXF_UL (COLOR_RANGE), 16);
5665 t->data = g_slice_alloc (t->size);
5667 GST_WRITE_UINT32_BE (t->data, self->color_range);
5668 mxf_primer_pack_add_mapping (primer, 0x3306, &t->ul);
5669 ret = g_list_prepend (ret, t);
5676 mxf_metadata_cdci_picture_essence_descriptor_init
5677 (MXFMetadataCDCIPictureEssenceDescriptor * self)
5679 self->color_siting = 0xff;
5683 mxf_metadata_cdci_picture_essence_descriptor_class_init
5684 (MXFMetadataCDCIPictureEssenceDescriptorClass * klass)
5686 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
5687 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
5689 metadata_base_class->handle_tag =
5690 mxf_metadata_cdci_picture_essence_descriptor_handle_tag;
5691 metadata_base_class->name_quark = MXF_QUARK (CDCI_PICTURE_ESSENCE_DESCRIPTOR);
5692 metadata_base_class->to_structure =
5693 mxf_metadata_cdci_picture_essence_descriptor_to_structure;
5694 metadata_base_class->write_tags =
5695 mxf_metadata_cdci_picture_essence_descriptor_write_tags;
5696 metadata_class->type = 0x0128;
5699 G_DEFINE_TYPE (MXFMetadataRGBAPictureEssenceDescriptor,
5700 mxf_metadata_rgba_picture_essence_descriptor,
5701 MXF_TYPE_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR);
5704 mxf_metadata_rgba_picture_essence_descriptor_finalize (GObject * object)
5706 MXFMetadataRGBAPictureEssenceDescriptor *self =
5707 MXF_METADATA_RGBA_PICTURE_ESSENCE_DESCRIPTOR (object);
5709 g_free (self->pixel_layout);
5710 self->pixel_layout = NULL;
5713 (mxf_metadata_rgba_picture_essence_descriptor_parent_class)->finalize
5718 mxf_metadata_rgba_picture_essence_descriptor_handle_tag (MXFMetadataBase *
5719 metadata, MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
5722 MXFMetadataRGBAPictureEssenceDescriptor *self =
5723 MXF_METADATA_RGBA_PICTURE_ESSENCE_DESCRIPTOR (metadata);
5724 gboolean ret = TRUE;
5730 self->component_max_ref = GST_READ_UINT32_BE (tag_data);
5731 GST_DEBUG (" component max ref = %u", self->component_max_ref);
5736 self->component_min_ref = GST_READ_UINT32_BE (tag_data);
5737 GST_DEBUG (" component min ref = %u", self->component_min_ref);
5742 self->alpha_max_ref = GST_READ_UINT32_BE (tag_data);
5743 GST_DEBUG (" alpha max ref = %u", self->alpha_max_ref);
5748 self->alpha_min_ref = GST_READ_UINT32_BE (tag_data);
5749 GST_DEBUG (" alpha min ref = %u", self->alpha_min_ref);
5754 self->scanning_direction = GST_READ_UINT8 (tag_data);
5755 GST_DEBUG (" scanning direction = %u", self->scanning_direction);
5760 if (tag_size % 2 != 0 || tag_size > 16)
5764 while (tag_data[i] != 0 && tag_data[i + 1] != 0 && i + 2 <= tag_size)
5768 self->n_pixel_layout = len;
5769 GST_DEBUG (" number of pixel layouts = %u", len);
5773 self->pixel_layout = g_malloc0 (16);
5775 for (i = 0; i < len; i++) {
5776 self->pixel_layout[2 * i] = tag_data[2 * i];
5777 self->pixel_layout[2 * i + 1] = tag_data[2 * i + 1];
5778 GST_DEBUG (" pixel layout %u = %c : %u", i,
5779 (gchar) self->pixel_layout[2 * i], self->pixel_layout[2 * i + 1]);
5786 /* TODO: handle this */
5787 GST_WARNING (" tag 0x%04x not implemented yet", tag);
5791 MXF_METADATA_BASE_CLASS
5792 (mxf_metadata_rgba_picture_essence_descriptor_parent_class)->handle_tag
5793 (metadata, primer, tag, tag_data, tag_size);
5802 ("Invalid RGBA picture essence descriptor local tag 0x%04x of size %u",
5808 static GstStructure *
5809 mxf_metadata_rgba_picture_essence_descriptor_to_structure (MXFMetadataBase * m)
5812 MXF_METADATA_BASE_CLASS
5813 (mxf_metadata_rgba_picture_essence_descriptor_parent_class)->to_structure
5815 MXFMetadataRGBAPictureEssenceDescriptor *self =
5816 MXF_METADATA_RGBA_PICTURE_ESSENCE_DESCRIPTOR (m);
5818 if (self->component_max_ref != 255)
5819 gst_structure_id_set (ret, MXF_QUARK (COMPONENT_MAX_REF), G_TYPE_UINT,
5820 self->component_max_ref, NULL);
5822 if (self->component_min_ref != 0)
5823 gst_structure_id_set (ret, MXF_QUARK (COMPONENT_MIN_REF), G_TYPE_UINT,
5824 self->component_min_ref, NULL);
5826 if (self->alpha_max_ref != 255)
5827 gst_structure_id_set (ret, MXF_QUARK (ALPHA_MAX_REF), G_TYPE_UINT,
5828 self->alpha_max_ref, NULL);
5830 if (self->alpha_min_ref != 0)
5831 gst_structure_id_set (ret, MXF_QUARK (ALPHA_MIN_REF), G_TYPE_UINT,
5832 self->alpha_min_ref, NULL);
5834 if (self->scanning_direction != 0)
5835 gst_structure_id_set (ret, MXF_QUARK (SCANNING_DIRECTION), G_TYPE_UCHAR,
5836 self->scanning_direction, NULL);
5838 if (self->n_pixel_layout != 0) {
5839 gchar *pl = g_new0 (gchar, self->n_pixel_layout * 2 + 1);
5841 memcpy (pl, self->pixel_layout, self->n_pixel_layout * 2);
5843 gst_structure_id_set (ret, MXF_QUARK (PIXEL_LAYOUT), G_TYPE_STRING, pl,
5853 mxf_metadata_rgba_picture_essence_descriptor_write_tags (MXFMetadataBase * m,
5854 MXFPrimerPack * primer)
5856 MXFMetadataRGBAPictureEssenceDescriptor *self =
5857 MXF_METADATA_RGBA_PICTURE_ESSENCE_DESCRIPTOR (m);
5859 MXF_METADATA_BASE_CLASS
5860 (mxf_metadata_rgba_picture_essence_descriptor_parent_class)->write_tags
5864 if (self->component_max_ref != 255) {
5865 t = g_slice_new0 (MXFLocalTag);
5866 memcpy (&t->ul, MXF_UL (COMPONENT_MAX_REF), 16);
5868 t->data = g_slice_alloc (t->size);
5870 GST_WRITE_UINT32_BE (t->data, self->component_max_ref);
5871 mxf_primer_pack_add_mapping (primer, 0x3406, &t->ul);
5872 ret = g_list_prepend (ret, t);
5875 if (self->component_min_ref) {
5876 t = g_slice_new0 (MXFLocalTag);
5877 memcpy (&t->ul, MXF_UL (COMPONENT_MIN_REF), 16);
5879 t->data = g_slice_alloc (t->size);
5881 GST_WRITE_UINT32_BE (t->data, self->component_min_ref);
5882 mxf_primer_pack_add_mapping (primer, 0x3407, &t->ul);
5883 ret = g_list_prepend (ret, t);
5886 if (self->alpha_max_ref != 255) {
5887 t = g_slice_new0 (MXFLocalTag);
5888 memcpy (&t->ul, MXF_UL (ALPHA_MAX_REF), 16);
5890 t->data = g_slice_alloc (t->size);
5892 GST_WRITE_UINT32_BE (t->data, self->alpha_max_ref);
5893 mxf_primer_pack_add_mapping (primer, 0x3408, &t->ul);
5894 ret = g_list_prepend (ret, t);
5897 if (self->alpha_min_ref) {
5898 t = g_slice_new0 (MXFLocalTag);
5899 memcpy (&t->ul, MXF_UL (ALPHA_MIN_REF), 16);
5901 t->data = g_slice_alloc (t->size);
5903 GST_WRITE_UINT32_BE (t->data, self->alpha_min_ref);
5904 mxf_primer_pack_add_mapping (primer, 0x3409, &t->ul);
5905 ret = g_list_prepend (ret, t);
5908 if (self->scanning_direction) {
5909 t = g_slice_new0 (MXFLocalTag);
5910 memcpy (&t->ul, MXF_UL (SCANNING_DIRECTION), 16);
5912 t->data = g_slice_alloc (t->size);
5914 GST_WRITE_UINT8 (t->data, self->scanning_direction);
5915 mxf_primer_pack_add_mapping (primer, 0x3405, &t->ul);
5916 ret = g_list_prepend (ret, t);
5919 t = g_slice_new0 (MXFLocalTag);
5920 memcpy (&t->ul, MXF_UL (PIXEL_LAYOUT), 16);
5922 t->data = g_slice_alloc0 (t->size);
5924 if (self->pixel_layout)
5925 memcpy (t->data, self->pixel_layout, self->n_pixel_layout * 2);
5926 mxf_primer_pack_add_mapping (primer, 0x3401, &t->ul);
5927 ret = g_list_prepend (ret, t);
5933 mxf_metadata_rgba_picture_essence_descriptor_init
5934 (MXFMetadataRGBAPictureEssenceDescriptor * self)
5936 self->component_max_ref = 255;
5937 self->alpha_max_ref = 255;
5941 mxf_metadata_rgba_picture_essence_descriptor_class_init
5942 (MXFMetadataRGBAPictureEssenceDescriptorClass * klass)
5944 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
5945 GObjectClass *object_class = (GObjectClass *) klass;
5946 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
5948 object_class->finalize =
5949 mxf_metadata_rgba_picture_essence_descriptor_finalize;
5950 metadata_base_class->handle_tag =
5951 mxf_metadata_rgba_picture_essence_descriptor_handle_tag;
5952 metadata_base_class->name_quark = MXF_QUARK (RGBA_PICTURE_ESSENCE_DESCRIPTOR);
5953 metadata_base_class->to_structure =
5954 mxf_metadata_rgba_picture_essence_descriptor_to_structure;
5955 metadata_base_class->write_tags =
5956 mxf_metadata_rgba_picture_essence_descriptor_write_tags;
5957 metadata_class->type = 0x0129;
5960 G_DEFINE_TYPE (MXFMetadataGenericDataEssenceDescriptor,
5961 mxf_metadata_generic_data_essence_descriptor,
5962 MXF_TYPE_METADATA_FILE_DESCRIPTOR);
5965 mxf_metadata_generic_data_essence_descriptor_handle_tag (MXFMetadataBase *
5966 metadata, MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
5969 MXFMetadataGenericDataEssenceDescriptor *self =
5970 MXF_METADATA_GENERIC_DATA_ESSENCE_DESCRIPTOR (metadata);
5971 gboolean ret = TRUE;
5972 #ifndef GST_DISABLE_GST_DEBUG
5980 memcpy (&self->data_essence_coding, tag_data, 16);
5981 GST_DEBUG (" data essence coding = %s",
5982 mxf_ul_to_string (&self->data_essence_coding, str));
5986 MXF_METADATA_BASE_CLASS
5987 (mxf_metadata_generic_data_essence_descriptor_parent_class)->handle_tag
5988 (metadata, primer, tag, tag_data, tag_size);
5997 ("Invalid generic data essence descriptor local tag 0x%04x of size %u",
6003 static GstStructure *
6004 mxf_metadata_generic_data_essence_descriptor_to_structure (MXFMetadataBase * m)
6007 MXF_METADATA_BASE_CLASS
6008 (mxf_metadata_generic_data_essence_descriptor_parent_class)->to_structure
6010 MXFMetadataGenericDataEssenceDescriptor *self =
6011 MXF_METADATA_GENERIC_DATA_ESSENCE_DESCRIPTOR (m);
6014 if (!mxf_ul_is_zero (&self->data_essence_coding)) {
6015 mxf_ul_to_string (&self->data_essence_coding, str);
6016 gst_structure_id_set (ret, MXF_QUARK (DATA_ESSENCE_CODING), G_TYPE_STRING,
6024 mxf_metadata_generic_data_essence_descriptor_write_tags (MXFMetadataBase * m,
6025 MXFPrimerPack * primer)
6027 MXFMetadataGenericDataEssenceDescriptor *self =
6028 MXF_METADATA_GENERIC_DATA_ESSENCE_DESCRIPTOR (m);
6030 MXF_METADATA_BASE_CLASS
6031 (mxf_metadata_generic_data_essence_descriptor_parent_class)->write_tags
6035 if (!mxf_ul_is_zero (&self->data_essence_coding)) {
6036 t = g_slice_new0 (MXFLocalTag);
6037 memcpy (&t->ul, MXF_UL (DATA_ESSENCE_CODING), 16);
6039 t->data = g_slice_alloc (t->size);
6041 memcpy (t->data, &self->data_essence_coding, 16);
6042 mxf_primer_pack_add_mapping (primer, 0x3e01, &t->ul);
6043 ret = g_list_prepend (ret, t);
6050 mxf_metadata_generic_data_essence_descriptor_init
6051 (MXFMetadataGenericDataEssenceDescriptor * self)
6057 mxf_metadata_generic_data_essence_descriptor_class_init
6058 (MXFMetadataGenericDataEssenceDescriptorClass * klass)
6060 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
6061 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
6063 metadata_base_class->handle_tag =
6064 mxf_metadata_generic_data_essence_descriptor_handle_tag;
6065 metadata_base_class->name_quark = MXF_QUARK (GENERIC_DATA_ESSENCE_DESCRIPTOR);
6066 metadata_base_class->to_structure =
6067 mxf_metadata_generic_data_essence_descriptor_to_structure;
6068 metadata_base_class->write_tags =
6069 mxf_metadata_generic_data_essence_descriptor_write_tags;
6070 metadata_class->type = 0x0143;
6073 G_DEFINE_TYPE (MXFMetadataMultipleDescriptor, mxf_metadata_multiple_descriptor,
6074 MXF_TYPE_METADATA_FILE_DESCRIPTOR);
6077 mxf_metadata_multiple_descriptor_finalize (GObject * object)
6079 MXFMetadataMultipleDescriptor *self =
6080 MXF_METADATA_MULTIPLE_DESCRIPTOR (object);
6082 g_free (self->sub_descriptors_uids);
6083 self->sub_descriptors_uids = NULL;
6084 g_free (self->sub_descriptors);
6085 self->sub_descriptors = NULL;
6088 (mxf_metadata_multiple_descriptor_parent_class)->finalize (object);
6092 mxf_metadata_multiple_descriptor_handle_tag (MXFMetadataBase * metadata,
6093 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
6096 MXFMetadataMultipleDescriptor *self =
6097 MXF_METADATA_MULTIPLE_DESCRIPTOR (metadata);
6098 gboolean ret = TRUE;
6099 #ifndef GST_DISABLE_GST_DEBUG
6105 if (!mxf_uuid_array_parse (&self->sub_descriptors_uids,
6106 &self->n_sub_descriptors, tag_data, tag_size))
6109 GST_DEBUG (" number of sub descriptors = %u", self->n_sub_descriptors);
6110 #ifndef GST_DISABLE_GST_DEBUG
6113 for (i = 0; i < self->n_sub_descriptors; i++) {
6114 GST_DEBUG (" sub descriptor %u = %s", i,
6115 mxf_uuid_to_string (&self->sub_descriptors_uids[i], str));
6123 MXF_METADATA_BASE_CLASS
6124 (mxf_metadata_multiple_descriptor_parent_class)->handle_tag (metadata,
6125 primer, tag, tag_data, tag_size);
6133 GST_ERROR ("Invalid multiple descriptor local tag 0x%04x of size %u", tag,
6140 mxf_metadata_multiple_descriptor_resolve (MXFMetadataBase * m,
6141 GHashTable * metadata)
6143 MXFMetadataMultipleDescriptor *self = MXF_METADATA_MULTIPLE_DESCRIPTOR (m);
6144 MXFMetadataBase *current = NULL;
6145 guint i, have_subdescriptors = 0;
6146 #ifndef GST_DISABLE_GST_DEBUG
6150 if (self->sub_descriptors)
6151 memset (self->sub_descriptors, 0,
6152 sizeof (gpointer) * self->n_sub_descriptors);
6154 self->sub_descriptors =
6155 g_new0 (MXFMetadataGenericDescriptor *, self->n_sub_descriptors);
6156 for (i = 0; i < self->n_sub_descriptors; i++) {
6157 current = g_hash_table_lookup (metadata, &self->sub_descriptors_uids[i]);
6158 if (current && MXF_IS_METADATA_GENERIC_DESCRIPTOR (current)) {
6159 if (mxf_metadata_base_resolve (current, metadata)) {
6160 self->sub_descriptors[i] = MXF_METADATA_GENERIC_DESCRIPTOR (current);
6161 have_subdescriptors++;
6163 GST_ERROR ("Couldn't resolve descriptor %s",
6164 mxf_uuid_to_string (&self->sub_descriptors_uids[i], str));
6168 GST_ERROR ("Descriptor %s not found",
6169 mxf_uuid_to_string (&self->sub_descriptors_uids[i], str));
6174 MXF_METADATA_BASE_CLASS
6175 (mxf_metadata_multiple_descriptor_parent_class)->resolve (m, metadata);
6178 static GstStructure *
6179 mxf_metadata_multiple_descriptor_to_structure (MXFMetadataBase * m)
6182 MXF_METADATA_BASE_CLASS
6183 (mxf_metadata_multiple_descriptor_parent_class)->to_structure (m);
6184 MXFMetadataMultipleDescriptor *self = MXF_METADATA_MULTIPLE_DESCRIPTOR (m);
6187 if (self->n_sub_descriptors > 0) {
6192 g_value_init (&arr, GST_TYPE_ARRAY);
6194 for (i = 0; i < self->n_sub_descriptors; i++) {
6197 if (self->sub_descriptors[i] == NULL)
6200 g_value_init (&val, GST_TYPE_STRUCTURE);
6202 s = mxf_metadata_base_to_structure (MXF_METADATA_BASE
6203 (self->sub_descriptors[i]));
6204 gst_value_set_structure (&val, s);
6205 gst_structure_free (s);
6206 gst_value_array_append_value (&arr, &val);
6207 g_value_unset (&val);
6210 if (gst_value_array_get_size (&arr) > 0)
6211 gst_structure_id_set_value (ret, MXF_QUARK (SUB_DESCRIPTORS), &arr);
6213 g_value_unset (&arr);
6220 mxf_metadata_multiple_descriptor_write_tags (MXFMetadataBase * m,
6221 MXFPrimerPack * primer)
6223 MXFMetadataMultipleDescriptor *self = MXF_METADATA_MULTIPLE_DESCRIPTOR (m);
6225 MXF_METADATA_BASE_CLASS
6226 (mxf_metadata_multiple_descriptor_parent_class)->write_tags (m, primer);
6229 if (self->sub_descriptors) {
6232 t = g_slice_new0 (MXFLocalTag);
6233 memcpy (&t->ul, MXF_UL (SUB_DESCRIPTORS), 16);
6234 t->size = 8 + 16 * self->n_sub_descriptors;
6235 t->data = g_slice_alloc0 (t->size);
6237 GST_WRITE_UINT32_BE (t->data, self->n_sub_descriptors);
6238 GST_WRITE_UINT32_BE (t->data + 4, 16);
6239 for (i = 0; i < self->n_sub_descriptors; i++) {
6240 if (!self->sub_descriptors[i])
6243 memcpy (t->data + 8 + 16 * i,
6244 &MXF_METADATA_BASE (self->sub_descriptors[i])->instance_uid, 16);
6246 mxf_primer_pack_add_mapping (primer, 0x3f01, &t->ul);
6247 ret = g_list_prepend (ret, t);
6254 mxf_metadata_multiple_descriptor_init (MXFMetadataMultipleDescriptor * self)
6260 mxf_metadata_multiple_descriptor_class_init (MXFMetadataMultipleDescriptorClass
6263 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
6264 GObjectClass *object_class = (GObjectClass *) klass;
6265 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
6267 object_class->finalize = mxf_metadata_multiple_descriptor_finalize;
6268 metadata_base_class->handle_tag = mxf_metadata_multiple_descriptor_handle_tag;
6269 metadata_base_class->resolve = mxf_metadata_multiple_descriptor_resolve;
6270 metadata_base_class->name_quark = MXF_QUARK (MULTIPLE_DESCRIPTOR);
6271 metadata_base_class->to_structure =
6272 mxf_metadata_multiple_descriptor_to_structure;
6273 metadata_base_class->write_tags = mxf_metadata_multiple_descriptor_write_tags;
6274 metadata_class->type = 0x0144;
6277 G_DEFINE_ABSTRACT_TYPE (MXFMetadataLocator, mxf_metadata_locator,
6281 mxf_metadata_locator_init (MXFMetadataLocator * self)
6286 mxf_metadata_locator_class_init (MXFMetadataLocatorClass * klass)
6290 G_DEFINE_TYPE (MXFMetadataTextLocator, mxf_metadata_text_locator,
6291 MXF_TYPE_METADATA_LOCATOR);
6294 mxf_metadata_text_locator_finalize (GObject * object)
6296 MXFMetadataTextLocator *self = MXF_METADATA_TEXT_LOCATOR (object);
6298 g_free (self->locator_name);
6299 self->locator_name = NULL;
6301 G_OBJECT_CLASS (mxf_metadata_text_locator_parent_class)->finalize (object);
6305 mxf_metadata_text_locator_handle_tag (MXFMetadataBase * metadata,
6306 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
6309 MXFMetadataTextLocator *self = MXF_METADATA_TEXT_LOCATOR (metadata);
6310 gboolean ret = TRUE;
6314 self->locator_name = mxf_utf16_to_utf8 (tag_data, tag_size);
6315 GST_DEBUG (" text locator = %s", GST_STR_NULL (self->locator_name));
6319 MXF_METADATA_BASE_CLASS
6320 (mxf_metadata_text_locator_parent_class)->handle_tag (metadata,
6321 primer, tag, tag_data, tag_size);
6328 static GstStructure *
6329 mxf_metadata_text_locator_to_structure (MXFMetadataBase * m)
6332 MXF_METADATA_BASE_CLASS
6333 (mxf_metadata_text_locator_parent_class)->to_structure (m);
6334 MXFMetadataTextLocator *self = MXF_METADATA_TEXT_LOCATOR (m);
6336 gst_structure_id_set (ret, MXF_QUARK (LOCATOR_NAME), G_TYPE_STRING,
6337 self->locator_name, NULL);
6343 mxf_metadata_text_locator_write_tags (MXFMetadataBase * m,
6344 MXFPrimerPack * primer)
6346 MXFMetadataTextLocator *self = MXF_METADATA_TEXT_LOCATOR (m);
6348 MXF_METADATA_BASE_CLASS
6349 (mxf_metadata_text_locator_parent_class)->write_tags (m, primer);
6352 if (self->locator_name) {
6353 t = g_slice_new0 (MXFLocalTag);
6354 memcpy (&t->ul, MXF_UL (LOCATOR_NAME), 16);
6355 t->data = mxf_utf8_to_utf16 (self->locator_name, &t->size);
6356 mxf_primer_pack_add_mapping (primer, 0x4101, &t->ul);
6357 ret = g_list_prepend (ret, t);
6364 mxf_metadata_text_locator_init (MXFMetadataTextLocator * self)
6370 mxf_metadata_text_locator_class_init (MXFMetadataTextLocatorClass * klass)
6372 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
6373 GObjectClass *object_class = (GObjectClass *) klass;
6374 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
6376 object_class->finalize = mxf_metadata_text_locator_finalize;
6377 metadata_base_class->handle_tag = mxf_metadata_text_locator_handle_tag;
6378 metadata_base_class->name_quark = MXF_QUARK (TEXT_LOCATOR);
6379 metadata_base_class->to_structure = mxf_metadata_text_locator_to_structure;
6380 metadata_base_class->write_tags = mxf_metadata_text_locator_write_tags;
6381 metadata_class->type = 0x0133;
6384 G_DEFINE_TYPE (MXFMetadataNetworkLocator, mxf_metadata_network_locator,
6385 MXF_TYPE_METADATA_LOCATOR);
6388 mxf_metadata_network_locator_finalize (GObject * object)
6390 MXFMetadataNetworkLocator *self = MXF_METADATA_NETWORK_LOCATOR (object);
6392 g_free (self->url_string);
6393 self->url_string = NULL;
6395 G_OBJECT_CLASS (mxf_metadata_network_locator_parent_class)->finalize (object);
6399 mxf_metadata_network_locator_handle_tag (MXFMetadataBase * metadata,
6400 MXFPrimerPack * primer, guint16 tag, const guint8 * tag_data,
6403 MXFMetadataNetworkLocator *self = MXF_METADATA_NETWORK_LOCATOR (metadata);
6404 gboolean ret = TRUE;
6408 self->url_string = mxf_utf16_to_utf8 (tag_data, tag_size);
6409 GST_DEBUG (" url string = %s", GST_STR_NULL (self->url_string));
6413 MXF_METADATA_BASE_CLASS
6414 (mxf_metadata_network_locator_parent_class)->handle_tag (metadata,
6415 primer, tag, tag_data, tag_size);
6422 static GstStructure *
6423 mxf_metadata_network_locator_to_structure (MXFMetadataBase * m)
6426 MXF_METADATA_BASE_CLASS
6427 (mxf_metadata_network_locator_parent_class)->to_structure (m);
6428 MXFMetadataNetworkLocator *self = MXF_METADATA_NETWORK_LOCATOR (m);
6430 gst_structure_id_set (ret, MXF_QUARK (URL_STRING), G_TYPE_STRING,
6431 self->url_string, NULL);
6437 mxf_metadata_network_locator_write_tags (MXFMetadataBase * m,
6438 MXFPrimerPack * primer)
6440 MXFMetadataNetworkLocator *self = MXF_METADATA_NETWORK_LOCATOR (m);
6442 MXF_METADATA_BASE_CLASS
6443 (mxf_metadata_network_locator_parent_class)->write_tags (m, primer);
6446 if (self->url_string) {
6447 t = g_slice_new0 (MXFLocalTag);
6448 memcpy (&t->ul, MXF_UL (URL_STRING), 16);
6449 t->data = mxf_utf8_to_utf16 (self->url_string, &t->size);
6450 mxf_primer_pack_add_mapping (primer, 0x4001, &t->ul);
6451 ret = g_list_prepend (ret, t);
6458 mxf_metadata_network_locator_init (MXFMetadataNetworkLocator * self)
6463 mxf_metadata_network_locator_class_init (MXFMetadataNetworkLocatorClass * klass)
6465 MXFMetadataBaseClass *metadata_base_class = (MXFMetadataBaseClass *) klass;
6466 GObjectClass *object_class = (GObjectClass *) klass;
6467 MXFMetadataClass *metadata_class = (MXFMetadataClass *) klass;
6469 object_class->finalize = mxf_metadata_network_locator_finalize;
6470 metadata_base_class->handle_tag = mxf_metadata_network_locator_handle_tag;
6471 metadata_base_class->name_quark = MXF_QUARK (NETWORK_LOCATOR);
6472 metadata_base_class->to_structure = mxf_metadata_network_locator_to_structure;
6473 metadata_base_class->write_tags = mxf_metadata_network_locator_write_tags;
6474 metadata_class->type = 0x0133;
6477 G_DEFINE_ABSTRACT_TYPE (MXFDescriptiveMetadata, mxf_descriptive_metadata,
6478 MXF_TYPE_METADATA_BASE);
6481 mxf_descriptive_metadata_init (MXFDescriptiveMetadata * self)
6486 mxf_descriptive_metadata_class_init (MXFDescriptiveMetadataClass * klass)
6494 } _MXFDescriptiveMetadataScheme;
6496 static GArray *_dm_schemes = NULL;
6499 mxf_descriptive_metadata_register (guint8 scheme, GType * types)
6501 _MXFDescriptiveMetadataScheme s;
6505 g_array_new (FALSE, TRUE, sizeof (_MXFDescriptiveMetadataScheme));
6510 g_array_append_val (_dm_schemes, s);
6513 MXFDescriptiveMetadata *
6514 mxf_descriptive_metadata_new (guint8 scheme, guint32 type,
6515 MXFPrimerPack * primer, guint64 offset, const guint8 * data, guint size)
6518 GType t = G_TYPE_INVALID, *p;
6519 _MXFDescriptiveMetadataScheme *s = NULL;
6520 MXFDescriptiveMetadata *ret = NULL;
6522 g_return_val_if_fail (primer != NULL, NULL);
6524 if (G_UNLIKELY (type == 0)) {
6525 GST_WARNING ("Type 0 is invalid");
6529 for (i = 0; _dm_schemes && i < _dm_schemes->len; i++) {
6530 _MXFDescriptiveMetadataScheme *data =
6531 &g_array_index (_dm_schemes, _MXFDescriptiveMetadataScheme, i);
6533 if (data->scheme == scheme) {
6540 GST_WARNING ("Descriptive metadata scheme 0x%02x not supported", scheme);
6547 MXFDescriptiveMetadataClass *klass =
6548 MXF_DESCRIPTIVE_METADATA_CLASS (g_type_class_ref (tmp));
6550 if (klass->type == type) {
6551 g_type_class_unref (klass);
6555 g_type_class_unref (klass);
6559 if (t == G_TYPE_INVALID) {
6561 ("No handler for type 0x%06x of descriptive metadata scheme 0x%02x found",
6566 GST_DEBUG ("DM scheme 0x%02x type 0x%06x is handled by type %s", scheme, type,
6569 ret = (MXFDescriptiveMetadata *) g_type_create_instance (t);
6570 if (!mxf_metadata_base_parse (MXF_METADATA_BASE (ret), primer, data, size)) {
6571 GST_ERROR ("Parsing metadata failed");
6572 g_object_unref (ret);
6576 ret->parent.offset = offset;
6582 mxf_descriptive_metadata_framework_get_type (void)
6584 static volatile gsize type = 0;
6585 if (g_once_init_enter (&type)) {
6587 static const GTypeInfo info = {
6588 sizeof (MXFDescriptiveMetadataFrameworkInterface),
6589 NULL, /* base_init */
6590 NULL, /* base_finalize */
6591 NULL, /* class_init */
6592 NULL, /* class_finalize */
6593 NULL, /* class_data */
6594 0, /* instance_size */
6595 0, /* n_preallocs */
6596 NULL /* instance_init */
6598 _type = g_type_register_static (G_TYPE_INTERFACE,
6599 "MXFDescriptiveMetadataFrameworkInterface", &info, 0);
6601 g_type_interface_add_prerequisite (_type, MXF_TYPE_DESCRIPTIVE_METADATA);
6603 g_once_init_leave (&type, (gsize) _type);
6606 return (GType) type;
6610 mxf_metadata_hash_table_new (void)
6612 return g_hash_table_new_full ((GHashFunc) mxf_uuid_hash,
6613 (GEqualFunc) mxf_uuid_is_equal, (GDestroyNotify) NULL,
6614 (GDestroyNotify) g_object_unref);