2
* Copyright (C) 2008 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., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
29
GST_DEBUG_CATEGORY_EXTERN (mxf_debug);
30
#define GST_CAT_DEFAULT mxf_debug
32
/* SMPTE 377M 3.3: A value of 0 for every field means unknown timestamp */
33
static const MXFTimestamp mxf_timestamp_unknown = { 0, 0, 0, 0, 0, 0, 0 };
35
static const MXFUMID umid_zero = { {0,} };
36
static const MXFUL key_zero = { {0,} };
38
/* UL common to all MXF UL */
39
static const guint8 mxf_key[] = { 0x06, 0x0e, 0x2b, 0x34 };
42
static const guint8 partition_pack_key[] =
43
{ 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01,
48
static const guint8 fill_key[] =
49
{ 0x06, 0x0e, 0x2b, 0x34, 0x01, 0x01, 0x01, 0x01, 0x03, 0x01, 0x02, 0x10,
50
0x01, 0x00, 0x00, 0x00
54
static const guint8 primer_pack_key[] =
55
{ 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01,
56
0x01, 0x05, 0x01, 0x00
60
static const guint8 metadata_key[] =
61
{ 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01,
65
static const guint8 random_index_pack_key[] =
66
{ 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01,
67
0x01, 0x11, 0x01, 0x00
70
static const guint8 index_table_segment_key[] =
71
{ 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01,
72
0x01, 0x10, 0x01, 0x00
76
mxf_is_mxf_packet (const MXFUL * key)
78
return (memcmp (key, mxf_key, 4) == 0);
81
/* SMPTE 377M 6.1: Check if this is a valid partition pack */
83
mxf_is_partition_pack (const MXFUL * key)
85
if (memcmp (key, partition_pack_key, 13) == 0 && key->u[13] >= 0x02
86
&& key->u[13] <= 0x04 && key->u[14] < 0x05 && key->u[15] == 0x00)
92
/* SMPTE 377M 6.2: header partition pack has byte 14 == 0x02 */
94
mxf_is_header_partition_pack (const MXFUL * key)
96
if (memcmp (key, partition_pack_key, 13) == 0 && key->u[13] == 0x02 &&
97
key->u[14] < 0x05 && key->u[15] == 0x00)
103
/* SMPTE 377M 6.3: body partition pack has byte 14 == 0x03 */
105
mxf_is_body_partition_pack (const MXFUL * key)
107
if (memcmp (key, partition_pack_key, 13) == 0 && key->u[13] == 0x03 &&
108
key->u[14] < 0x05 && key->u[15] == 0x00)
114
/* SMPTE 377M 6.4: footer partition pack has byte 14 == 0x04 */
116
mxf_is_footer_partition_pack (const MXFUL * key)
118
if (memcmp (key, partition_pack_key, 13) == 0 && key->u[13] == 0x04 &&
119
key->u[14] < 0x05 && key->u[15] == 0x00)
126
mxf_is_fill (const MXFUL * key)
128
return (memcmp (key, fill_key, 16) == 0);
132
mxf_is_primer_pack (const MXFUL * key)
134
return (memcmp (key, primer_pack_key, 16) == 0);
138
mxf_is_metadata (const MXFUL * key)
140
return (memcmp (key, metadata_key, 13) == 0 && key->u[15] == 0x00);
143
/* SMPTE 377M 8.7.3 */
145
mxf_is_descriptive_metadata (const MXFUL * key)
147
return (memcmp (key, mxf_key, 4) == 0 &&
152
key->u[9] == 0x01 && key->u[10] == 0x04 && key->u[11] == 0x01);
156
mxf_is_random_index_pack (const MXFUL * key)
158
return (memcmp (key, random_index_pack_key, 16) == 0);
162
mxf_is_index_table_segment (const MXFUL * key)
164
return (memcmp (key, index_table_segment_key, 16) == 0);
167
/* SMPTE 379M 6.2.1 */
169
mxf_is_generic_container_system_item (const MXFUL * key)
171
return (memcmp (key, mxf_key, 4) == 0 && key->u[4] == 0x02
172
&& key->u[6] == 0x01 && key->u[8] == 0x0d && key->u[9] == 0x01
173
&& key->u[10] == 0x03 && key->u[11] == 0x01 && (key->u[12] == 0x04
174
|| key->u[12] == 0x14));
179
mxf_is_generic_container_essence_element (const MXFUL * key)
181
return (memcmp (key, mxf_key, 4) == 0 && key->u[4] == 0x01
182
&& key->u[5] == 0x02 && key->u[6] == 0x01 && key->u[8] == 0x0d
183
&& key->u[9] == 0x01 && key->u[10] == 0x03 && key->u[11] == 0x01
184
&& (key->u[12] == 0x05 || key->u[12] == 0x06 || key->u[12] == 0x07
185
|| key->u[12] == 0x15 || key->u[12] == 0x16 || key->u[12] == 0x17
186
|| key->u[12] == 0x18));
191
mxf_is_generic_container_essence_container_label (const MXFUL * key)
193
return (key->u[0] == 0x06 &&
202
key->u[10] == 0x03 &&
203
key->u[11] == 0x01 && (key->u[12] == 0x01 || key->u[12] == 0x02));
207
mxf_ul_is_equal (const MXFUL * a, const MXFUL * b)
209
return (memcmp (a, b, 16) == 0);
213
mxf_ul_is_zero (const MXFUL * key)
215
return (memcmp (key, &key_zero, 16) == 0);
219
mxf_ul_to_string (const MXFUL * key, gchar str[48])
221
g_return_val_if_fail (key != NULL, NULL);
222
g_return_val_if_fail (str != NULL, NULL);
225
"%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x",
226
key->u[0], key->u[1], key->u[2], key->u[3], key->u[4], key->u[5],
227
key->u[6], key->u[7], key->u[8], key->u[9], key->u[10], key->u[11],
228
key->u[12], key->u[13], key->u[14], key->u[15]);
234
mxf_umid_is_equal (const MXFUMID * a, const MXFUMID * b)
236
return (memcmp (a, b, 32) == 0);
240
mxf_umid_is_zero (const MXFUMID * umid)
242
return (memcmp (umid, &umid_zero, 32) == 0);
246
mxf_umid_to_string (const MXFUMID * key, gchar str[96])
248
g_return_val_if_fail (key != NULL, NULL);
249
g_return_val_if_fail (str != NULL, NULL);
252
"%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x."
253
"%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x",
254
key->u[0], key->u[1], key->u[2], key->u[3], key->u[4], key->u[5],
255
key->u[6], key->u[7], key->u[8], key->u[9], key->u[10], key->u[11],
256
key->u[12], key->u[13], key->u[14], key->u[15],
267
key->u[26], key->u[27], key->u[28], key->u[29], key->u[30], key->u[31]
274
mxf_umid_from_string (const gchar * str, MXFUMID * umid)
279
g_return_val_if_fail (str != NULL, NULL);
282
memset (umid, 0, 32);
285
GST_ERROR ("Invalid UMID string length %d", len);
289
for (i = 0, j = 0; i < 32; i++) {
290
if (!g_ascii_isxdigit (str[j]) ||
291
!g_ascii_isxdigit (str[j + 1]) ||
292
(str[j + 2] != '.' && str[j + 2] != '\0')) {
293
GST_ERROR ("Invalid UMID string '%s'", str);
298
(g_ascii_xdigit_value (str[j]) << 4) | (g_ascii_xdigit_value (str[j +
306
gst_mxf_ul_hash (const MXFUL * key)
311
for (i = 0; i < 4; i++)
313
(key->u[i * 4 + 0] << 24) | (key->u[i * 4 + 1] << 16) | (key->u[i * 4 +
314
2] << 8) | (key->u[i * 4 + 3] << 0);
320
gst_mxf_ul_equal (const MXFUL * a, const MXFUL * b)
322
return (memcmp (a, b, 16) == 0);
326
mxf_timestamp_parse (MXFTimestamp * timestamp, const guint8 * data, guint size)
328
g_return_val_if_fail (data != NULL, FALSE);
329
g_return_val_if_fail (timestamp != NULL, FALSE);
331
memset (timestamp, 0, sizeof (MXFTimestamp));
336
timestamp->year = GST_READ_UINT16_BE (data);
337
timestamp->month = GST_READ_UINT8 (data + 2);
338
timestamp->day = GST_READ_UINT8 (data + 3);
339
timestamp->hour = GST_READ_UINT8 (data + 4);
340
timestamp->minute = GST_READ_UINT8 (data + 5);
341
timestamp->second = GST_READ_UINT8 (data + 6);
342
timestamp->quarter_msecond = GST_READ_UINT8 (data + 7);
348
mxf_timestamp_is_unknown (const MXFTimestamp * a)
350
return (memcmp (a, &mxf_timestamp_unknown, sizeof (MXFTimestamp)) == 0);
354
mxf_timestamp_compare (const MXFTimestamp * a, const MXFTimestamp * b)
358
if ((diff = a->year - b->year) != 0)
360
else if ((diff = a->month - b->month) != 0)
362
else if ((diff = a->day - b->day) != 0)
364
else if ((diff = a->hour - b->hour) != 0)
366
else if ((diff = a->minute - b->minute) != 0)
368
else if ((diff = a->second - b->second) != 0)
370
else if ((diff = a->quarter_msecond - b->quarter_msecond) != 0)
377
mxf_fraction_parse (MXFFraction * fraction, const guint8 * data, guint size)
379
g_return_val_if_fail (fraction != NULL, FALSE);
380
g_return_val_if_fail (data != NULL, FALSE);
382
memset (fraction, 0, sizeof (MXFFraction));
387
fraction->n = GST_READ_UINT32_BE (data);
388
fraction->d = GST_READ_UINT32_BE (data + 4);
394
mxf_utf16_to_utf8 (const guint8 * data, guint size)
397
GError *error = NULL;
400
g_convert ((const gchar *) data, size, "UTF-8", "UTF-16BE", NULL, NULL,
404
GST_WARNING ("UTF-16-BE to UTF-8 conversion failed: %s", error->message);
405
g_error_free (error);
413
mxf_product_version_parse (MXFProductVersion * product_version,
414
const guint8 * data, guint size)
416
g_return_val_if_fail (product_version != NULL, FALSE);
417
g_return_val_if_fail (data != NULL, FALSE);
419
memset (product_version, 0, sizeof (MXFProductVersion));
424
product_version->major = GST_READ_UINT16_BE (data);
425
product_version->minor = GST_READ_UINT16_BE (data + 2);
426
product_version->patch = GST_READ_UINT16_BE (data + 4);
427
product_version->build = GST_READ_UINT16_BE (data + 6);
429
/* Avid writes a 9 byte product version */
431
product_version->release = GST_READ_UINT8 (data + 8);
433
product_version->release = GST_READ_UINT16_BE (data + 8);
438
/* SMPTE 377M 6.1, Table 2 */
440
mxf_partition_pack_parse (const MXFUL * key, MXFPartitionPack * pack,
441
const guint8 * data, guint size)
444
#ifndef GST_DISABLE_GST_DEBUG
448
g_return_val_if_fail (data != NULL, FALSE);
449
g_return_val_if_fail (size >= 84, FALSE);
451
memset (pack, 0, sizeof (MXFPartitionPack));
453
GST_DEBUG ("Parsing partition pack:");
455
if (key->u[13] == 0x02)
456
pack->type = MXF_PARTITION_PACK_HEADER;
457
else if (key->u[13] == 0x03)
458
pack->type = MXF_PARTITION_PACK_BODY;
459
else if (key->u[13] == 0x04)
460
pack->type = MXF_PARTITION_PACK_FOOTER;
462
GST_DEBUG (" type = %s",
463
(pack->type == MXF_PARTITION_PACK_HEADER) ? "header" : (pack->type ==
464
MXF_PARTITION_PACK_BODY) ? "body" : "footer");
466
pack->closed = (key->u[14] == 0x02 || key->u[14] == 0x04);
467
pack->complete = (key->u[14] == 0x03 || key->u[14] == 0x04);
469
GST_DEBUG (" closed = %s, complete = %s", (pack->closed) ? "yes" : "no",
470
(pack->complete) ? "yes" : "no");
472
pack->major_version = GST_READ_UINT16_BE (data);
473
if (pack->major_version != 1)
478
pack->minor_version = GST_READ_UINT16_BE (data);
482
GST_DEBUG (" MXF version = %u.%u", pack->major_version, pack->minor_version);
484
pack->kag_size = GST_READ_UINT32_BE (data);
488
GST_DEBUG (" KAG size = %u", pack->kag_size);
490
pack->this_partition = GST_READ_UINT64_BE (data);
494
GST_DEBUG (" this partition offset = %" G_GUINT64_FORMAT,
495
pack->this_partition);
497
pack->prev_partition = GST_READ_UINT64_BE (data);
501
GST_DEBUG (" previous partition offset = %" G_GUINT64_FORMAT,
502
pack->prev_partition);
504
pack->footer_partition = GST_READ_UINT64_BE (data);
508
GST_DEBUG (" footer partition offset = %" G_GUINT64_FORMAT,
509
pack->footer_partition);
511
pack->header_byte_count = GST_READ_UINT64_BE (data);
515
GST_DEBUG (" header byte count = %" G_GUINT64_FORMAT,
516
pack->header_byte_count);
518
pack->index_byte_count = GST_READ_UINT64_BE (data);
522
pack->index_sid = GST_READ_UINT32_BE (data);
526
GST_DEBUG (" index sid = %u, size = %" G_GUINT64_FORMAT, pack->index_sid,
527
pack->index_byte_count);
529
pack->body_offset = GST_READ_UINT64_BE (data);
533
pack->body_sid = GST_READ_UINT32_BE (data);
537
GST_DEBUG (" body sid = %u, offset = %" G_GUINT64_FORMAT, pack->body_sid,
540
memcpy (&pack->operational_pattern, data, 16);
544
GST_DEBUG (" operational pattern = %s",
545
mxf_ul_to_string (&pack->operational_pattern, str));
547
pack->n_essence_containers = GST_READ_UINT32_BE (data);
551
GST_DEBUG (" number of essence containers = %u", pack->n_essence_containers);
553
if (GST_READ_UINT32_BE (data) != 16)
558
if (size < 16 * pack->n_essence_containers)
561
if (pack->n_essence_containers) {
562
pack->essence_containers = g_new (MXFUL, pack->n_essence_containers);
563
for (i = 0; i < pack->n_essence_containers; i++) {
564
memcpy (&pack->essence_containers[i], data + i * 16, 16);
565
GST_DEBUG (" essence container %u = %s", i,
566
mxf_ul_to_string (&pack->essence_containers[i], str));
575
GST_ERROR ("Invalid partition pack");
577
mxf_partition_pack_reset (pack);
582
mxf_partition_pack_reset (MXFPartitionPack * pack)
584
g_return_if_fail (pack != NULL);
586
g_free (pack->essence_containers);
588
memset (pack, 0, sizeof (MXFPartitionPack));
591
/* SMPTE 377M 11.1 */
593
mxf_random_index_pack_parse (const MXFUL * key, const guint8 * data, guint size,
597
MXFRandomIndexPackEntry entry;
599
g_return_val_if_fail (data != NULL, FALSE);
600
g_return_val_if_fail (array != NULL, FALSE);
605
if ((size - 4) % 12 != 0)
608
GST_DEBUG ("Parsing random index pack:");
610
len = (size - 4) / 12;
612
GST_DEBUG (" number of entries = %u", len);
615
g_array_sized_new (FALSE, FALSE, sizeof (MXFRandomIndexPackEntry), len);
617
for (i = 0; i < len; i++) {
618
entry.body_sid = GST_READ_UINT32_BE (data);
619
entry.offset = GST_READ_UINT64_BE (data + 4);
622
GST_DEBUG (" entry %u = body sid %u at offset %" G_GUINT64_FORMAT, i,
623
entry.body_sid, entry.offset);
625
g_array_append_val (*array, entry);
631
/* SMPTE 377M 10.2.3 */
633
mxf_index_table_segment_parse (const MXFUL * key,
634
MXFIndexTableSegment * segment, const MXFPrimerPack * primer,
635
const guint8 * data, guint size)
637
#ifndef GST_DISABLE_GST_DEBUG
640
guint16 tag, tag_size;
641
const guint8 *tag_data;
643
g_return_val_if_fail (key != NULL, FALSE);
644
g_return_val_if_fail (data != NULL, FALSE);
645
g_return_val_if_fail (primer != NULL, FALSE);
647
memset (segment, 0, sizeof (MXFIndexTableSegment));
652
GST_DEBUG ("Parsing index table segment:");
654
while (mxf_local_tag_parse (data, size, &tag, &tag_size, &tag_data)) {
655
if (tag_size == 0 || tag == 0x0000)
662
memcpy (&segment->instance_id, tag_data, 16);
663
GST_DEBUG (" instance id = %s",
664
mxf_ul_to_string (&segment->instance_id, str));
667
if (!mxf_fraction_parse (&segment->index_edit_rate, tag_data, tag_size))
669
GST_DEBUG (" index edit rate = %d/%d", segment->index_edit_rate.n,
670
segment->index_edit_rate.d);
675
segment->index_start_position = GST_READ_UINT64_BE (tag_data);
676
GST_DEBUG (" index start position = %" G_GINT64_FORMAT,
677
segment->index_start_position);
682
segment->index_duration = GST_READ_UINT64_BE (tag_data);
683
GST_DEBUG (" index duration = %" G_GINT64_FORMAT,
684
segment->index_duration);
689
segment->edit_unit_byte_count = GST_READ_UINT32_BE (tag_data);
690
GST_DEBUG (" edit unit byte count = %u",
691
segment->edit_unit_byte_count);
696
segment->index_sid = GST_READ_UINT32_BE (tag_data);
697
GST_DEBUG (" index sid = %u", segment->index_sid);
702
segment->body_sid = GST_READ_UINT32_BE (tag_data);
703
GST_DEBUG (" body sid = %u", segment->body_sid);
708
segment->slice_count = GST_READ_UINT8 (tag_data);
709
GST_DEBUG (" slice count = %u", segment->slice_count);
714
segment->pos_table_count = GST_READ_UINT8 (tag_data);
715
GST_DEBUG (" pos table count = %u", segment->pos_table_count);
723
len = GST_READ_UINT32_BE (tag_data);
724
segment->n_delta_entries = len;
725
GST_DEBUG (" number of delta entries = %u", segment->n_delta_entries);
731
if (GST_READ_UINT32_BE (tag_data) != 6)
737
if (tag_size < len * 6)
740
segment->delta_entries = g_new (MXFDeltaEntry, len);
742
for (i = 0; i < len; i++) {
743
GST_DEBUG (" delta entry %u:", i);
745
segment->delta_entries[i].pos_table_index = GST_READ_UINT8 (tag_data);
748
GST_DEBUG (" pos table index = %d",
749
segment->delta_entries[i].pos_table_index);
751
segment->delta_entries[i].slice = GST_READ_UINT8 (tag_data);
754
GST_DEBUG (" slice = %u", segment->delta_entries[i].slice);
756
segment->delta_entries[i].element_delta =
757
GST_READ_UINT32_BE (tag_data);
760
GST_DEBUG (" element delta = %u",
761
segment->delta_entries[i].element_delta);
771
len = GST_READ_UINT32_BE (tag_data);
772
segment->n_index_entries = len;
773
GST_DEBUG (" number of index entries = %u", segment->n_index_entries);
779
if (GST_READ_UINT32_BE (tag_data) !=
780
(11 + 4 * segment->slice_count + 8 * segment->pos_table_count))
787
len * (11 + 4 * segment->slice_count +
788
8 * segment->pos_table_count))
791
segment->index_entries = g_new (MXFIndexEntry, len);
793
for (i = 0; i < len; i++) {
794
MXFIndexEntry *entry = &segment->index_entries[i];
796
GST_DEBUG (" index entry %u:", i);
798
entry->temporal_offset = GST_READ_UINT8 (tag_data);
801
GST_DEBUG (" temporal offset = %d", entry->temporal_offset);
803
entry->key_frame_offset = GST_READ_UINT8 (tag_data);
806
GST_DEBUG (" keyframe offset = %d", entry->key_frame_offset);
808
entry->flags = GST_READ_UINT8 (tag_data);
811
GST_DEBUG (" flags = 0x%02x", entry->flags);
813
entry->stream_offset = GST_READ_UINT64_BE (tag_data);
816
GST_DEBUG (" stream offset = %" G_GUINT64_FORMAT,
817
entry->stream_offset);
819
for (j = 0; j < segment->slice_count; j++) {
820
entry->slice_offset[j] = GST_READ_UINT32_BE (tag_data);
823
GST_DEBUG (" slice %u offset = %u", j, entry->slice_offset[j]);
826
for (j = 0; j < segment->pos_table_count; j++) {
827
mxf_fraction_parse (&entry->pos_table[j], tag_data, tag_size);
830
GST_DEBUG (" pos table %u = %d/%d", j, entry->pos_table[j].n,
831
entry->pos_table[j].d);
837
if (!mxf_local_tag_add_to_hash_table (primer, tag, tag_data, tag_size,
838
&segment->other_tags))
844
data += 4 + tag_size;
845
size -= 4 + tag_size;
850
GST_ERROR ("Invalid index table segment");
855
mxf_index_table_segment_reset (MXFIndexTableSegment * segment)
858
g_return_if_fail (segment != NULL);
860
for (i = 0; i < segment->n_index_entries; i++) {
861
g_free (segment->index_entries[i].slice_offset);
862
g_free (segment->index_entries[i].pos_table);
864
g_free (segment->index_entries);
865
g_free (segment->delta_entries);
867
if (segment->other_tags)
868
g_hash_table_destroy (segment->other_tags);
870
memset (segment, 0, sizeof (MXFIndexTableSegment));
873
/* SMPTE 377M 8.2 Table 1 and 2 */
876
_mxf_mapping_ul_free (MXFUL * ul)
878
g_slice_free (MXFUL, ul);
882
mxf_primer_pack_parse (const MXFUL * key, MXFPrimerPack * pack,
883
const guint8 * data, guint size)
888
g_return_val_if_fail (data != NULL, FALSE);
889
g_return_val_if_fail (size >= 8, FALSE);
891
memset (pack, 0, sizeof (MXFPrimerPack));
893
GST_DEBUG ("Parsing primer pack:");
896
g_hash_table_new_full (g_direct_hash, g_direct_equal,
897
(GDestroyNotify) NULL, (GDestroyNotify) _mxf_mapping_ul_free);
899
n = GST_READ_UINT32_BE (data);
902
GST_DEBUG (" number of mappings = %u", n);
904
if (GST_READ_UINT32_BE (data) != 18)
908
if (size < 8 + n * 18)
911
for (i = 0; i < n; i++) {
913
#ifndef GST_DISABLE_GST_DEBUG
918
local_tag = GST_READ_UINT16_BE (data);
921
if (g_hash_table_lookup (pack->mappings, GUINT_TO_POINTER (local_tag)))
924
uid = g_slice_new (MXFUL);
925
memcpy (uid, data, 16);
928
g_hash_table_insert (pack->mappings, GUINT_TO_POINTER (local_tag), uid);
929
GST_DEBUG (" Adding mapping = 0x%04x -> %s", local_tag,
930
mxf_ul_to_string (uid, str));
938
GST_DEBUG ("Invalid primer pack");
939
mxf_primer_pack_reset (pack);
944
mxf_primer_pack_reset (MXFPrimerPack * pack)
946
g_return_if_fail (pack != NULL);
949
g_hash_table_destroy (pack->mappings);
950
memset (pack, 0, sizeof (MXFPrimerPack));
953
/* structural metadata parsing */
956
mxf_local_tag_parse (const guint8 * data, guint size, guint16 * tag,
957
guint16 * tag_size, const guint8 ** tag_data)
959
g_return_val_if_fail (data != NULL, FALSE);
964
*tag = GST_READ_UINT16_BE (data);
965
*tag_size = GST_READ_UINT16_BE (data + 2);
967
if (size < 4 + *tag_size)
970
*tag_data = data + 4;
976
gst_mxf_local_tag_free (MXFLocalTag * tag)
979
g_slice_free (MXFLocalTag, tag);
983
mxf_local_tag_add_to_hash_table (const MXFPrimerPack * primer,
984
guint16 tag, const guint8 * tag_data, guint16 tag_size,
985
GHashTable ** hash_table)
987
MXFLocalTag *local_tag;
990
g_return_val_if_fail (primer != NULL, FALSE);
991
g_return_val_if_fail (tag_data != NULL, FALSE);
992
g_return_val_if_fail (hash_table != NULL, FALSE);
993
g_return_val_if_fail (primer->mappings != NULL, FALSE);
995
if (*hash_table == NULL)
997
g_hash_table_new_full ((GHashFunc) gst_mxf_ul_hash,
998
(GEqualFunc) gst_mxf_ul_equal, (GDestroyNotify) NULL,
999
(GDestroyNotify) gst_mxf_local_tag_free);
1001
g_return_val_if_fail (*hash_table != NULL, FALSE);
1003
key = (MXFUL *) g_hash_table_lookup (primer->mappings,
1004
GUINT_TO_POINTER (((guint) tag)));
1007
#ifndef GST_DISABLE_GST_DEBUG
1011
GST_DEBUG ("Adding local tag 0x%04x with UL %s and size %u", tag,
1012
mxf_ul_to_string (key, str), tag_size);
1014
local_tag = g_slice_new (MXFLocalTag);
1015
memcpy (&local_tag->key, key, sizeof (MXFUL));
1016
local_tag->size = tag_size;
1017
local_tag->data = g_memdup (tag_data, tag_size);
1019
g_hash_table_insert (*hash_table, &local_tag->key, local_tag);
1021
GST_WARNING ("Local tag with no entry in primer pack: 0x%04x", tag);
1027
static GSList *_mxf_essence_element_handler_registry = NULL;
1030
mxf_essence_element_handler_register (const MXFEssenceElementHandler * handler)
1032
_mxf_essence_element_handler_registry =
1033
g_slist_prepend (_mxf_essence_element_handler_registry,
1034
(gpointer) handler);
1037
const MXFEssenceElementHandler *
1038
mxf_essence_element_handler_find (const MXFMetadataTimelineTrack * track)
1041
const MXFEssenceElementHandler *ret = NULL;
1043
for (l = _mxf_essence_element_handler_registry; l; l = l->next) {
1044
MXFEssenceElementHandler *current = l->data;
1046
if (current->handles_track (track)) {