use a data definition uls table to fetch codec type
[ffmpeg.git] / libavformat / mxf.c
1 /*
2  * MXF demuxer.
3  * Copyright (c) 2006 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19
20 /*
21  * References
22  * SMPTE 336M KLV Data Encoding Protocol Using Key-Length-Value
23  * SMPTE 377M MXF File Format Specifications
24  * SMPTE 378M Operational Pattern 1a
25  * SMPTE 379M MXF Generic Container
26  * SMPTE 381M Mapping MPEG Streams into the MXF Generic Container
27  * SMPTE 382M Mapping AES3 and Broadcast Wave Audio into the MXF Generic Container
28  * SMPTE 383M Mapping DV-DIF Data to the MXF Generic Container
29  *
30  * Principle
31  * Search for Track numbers which will identify essence element KLV packets.
32  * Search for SourcePackage which define tracks which contains Track numbers.
33  * Material Package contains tracks with reference to SourcePackage tracks.
34  * Search for Descriptors (Picture, Sound) which contains codec info and parameters.
35  * Assign Descriptors to correct Tracks.
36  *
37  * Metadata reading functions read Local Tags, get InstanceUID(0x3C0A) then add MetaDataSet to MXFContext.
38  * Metadata parsing resolves Strong References to objects.
39  *
40  * Simple demuxer, only OP1A supported and some files might not work at all.
41  * Only tracks with associated descriptors will be decoded. "Highly Desirable" SMPTE 377M D.1
42  */
43
44 //#define DEBUG
45
46 #include "avformat.h"
47
48 typedef uint8_t UID[16];
49
50 enum MXFMetadataSetType {
51     MaterialPackage,
52     SourcePackage,
53     SourceClip,
54     TimecodeComponent,
55     Sequence,
56     MultipleDescriptor,
57     Descriptor,
58     Track,
59     EssenceContainerData,
60 };
61
62 typedef struct MXFStructuralComponent {
63     UID uid;
64     enum MXFMetadataSetType type;
65     UID source_package_uid;
66     UID data_definition_ul;
67     int64_t duration;
68     int64_t start_position;
69     int source_track_id;
70 } MXFStructuralComponent;
71
72 typedef struct MXFSequence {
73     UID uid;
74     enum MXFMetadataSetType type;
75     UID data_definition_ul;
76     UID *structural_components_refs;
77     int structural_components_count;
78     int64_t duration;
79 } MXFSequence;
80
81 typedef struct MXFTrack {
82     UID uid;
83     enum MXFMetadataSetType type;
84     MXFSequence *sequence; /* mandatory, and only one */
85     UID sequence_ref;
86     int track_id;
87     uint8_t track_number[4];
88     AVRational edit_rate;
89 } MXFTrack;
90
91 typedef struct MXFDescriptor {
92     UID uid;
93     enum MXFMetadataSetType type;
94     UID essence_container_ul;
95     UID essence_codec_ul;
96     AVRational sample_rate;
97     AVRational aspect_ratio;
98     int width;
99     int height;
100     int channels;
101     int bits_per_sample;
102     UID *sub_descriptors_refs;
103     int sub_descriptors_count;
104     int linked_track_id;
105     uint8_t *extradata;
106     int extradata_size;
107 } MXFDescriptor;
108
109 typedef struct MXFPackage {
110     UID uid;
111     enum MXFMetadataSetType type;
112     UID package_uid;
113     UID *tracks_refs;
114     int tracks_count;
115     MXFDescriptor *descriptor; /* only one */
116     UID descriptor_ref;
117 } MXFPackage;
118
119 typedef struct MXFEssenceContainerData {
120     UID uid;
121     enum MXFMetadataSetType type;
122     UID linked_package_uid;
123 } MXFEssenceContainerData;
124
125 typedef struct {
126     UID uid;
127     enum MXFMetadataSetType type;
128 } MXFMetadataSet;
129
130 typedef struct MXFContext {
131     UID *packages_refs;
132     int packages_count;
133     UID *essence_container_data_sets_refs;
134     int essence_container_data_sets_count;
135     UID *essence_containers_uls; /* Universal Labels SMPTE RP224 */
136     int essence_containers_uls_count;
137     UID operational_pattern_ul;
138     UID content_storage_uid;
139     MXFMetadataSet **metadata_sets;
140     int metadata_sets_count;
141     AVFormatContext *fc;
142 } MXFContext;
143
144 typedef struct KLVPacket {
145     UID key;
146     offset_t offset;
147     uint64_t length;
148 } KLVPacket;
149
150 enum MXFWrappingScheme {
151     Frame,
152     Clip,
153 };
154
155 typedef struct MXFCodecUL {
156     UID uid;
157     enum CodecID id;
158     enum MXFWrappingScheme wrapping;
159 } MXFCodecUL;
160
161 typedef struct MXFDataDefinitionUL {
162     UID uid;
163     enum CodecType type;
164 } MXFDataDefinitionUL;
165
166 typedef struct MXFMetadataReadTableEntry {
167     const UID key;
168     int (*read)(MXFContext *mxf, KLVPacket *klv);
169 } MXFMetadataReadTableEntry;
170
171 /* partial keys to match */
172 static const uint8_t mxf_header_partition_pack_key[]       = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02 };
173 static const uint8_t mxf_essence_element_key[]             = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01 };
174
175 #define IS_KLV_KEY(x, y) (!memcmp(x, y, sizeof(y)))
176
177 #define PRINT_KEY(s, x) dprintf("%s %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", s, \
178                              (x)[0], (x)[1], (x)[2], (x)[3], (x)[4], (x)[5], (x)[6], (x)[7], (x)[8], (x)[9], (x)[10], (x)[11], (x)[12], (x)[13], (x)[14], (x)[15])
179
180 static int64_t klv_decode_ber_length(ByteIOContext *pb)
181 {
182     int64_t size = 0;
183     uint8_t length = get_byte(pb);
184     int type = length >> 7;
185
186     if (type) { /* long form */
187         int bytes_num = length & 0x7f;
188         /* SMPTE 379M 5.3.4 guarantee that bytes_num must not exceed 8 bytes */
189         if (bytes_num > 8)
190             return -1;
191         while (bytes_num--)
192             size = size << 8 | get_byte(pb);
193     } else {
194         size = length & 0x7f;
195     }
196     return size;
197 }
198
199 static int klv_read_packet(KLVPacket *klv, ByteIOContext *pb)
200 {
201     klv->offset = url_ftell(pb);
202     get_buffer(pb, klv->key, 16);
203     klv->length = klv_decode_ber_length(pb);
204     return klv->length == -1 ? -1 : 0;
205 }
206
207 static int mxf_get_stream_index(AVFormatContext *s, KLVPacket *klv)
208 {
209     int i;
210
211     for (i = 0; i < s->nb_streams; i++) {
212         MXFTrack *track = s->streams[i]->priv_data;
213          /* SMPTE 379M 7.3 */
214         if (!memcmp(klv->key + sizeof(mxf_essence_element_key), track->track_number, sizeof(track->track_number)))
215             return i;
216     }
217     return -1;
218 }
219
220 static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt)
221 {
222     KLVPacket klv;
223
224     while (!url_feof(&s->pb)) {
225         if (klv_read_packet(&klv, &s->pb) < 0) {
226             av_log(s, AV_LOG_ERROR, "error reading KLV packet\n");
227             return -1;
228         }
229 #ifdef DEBUG
230         PRINT_KEY("read packet", klv.key);
231 #endif
232         if (IS_KLV_KEY(klv.key, mxf_essence_element_key)) {
233             av_get_packet(&s->pb, pkt, klv.length);
234             pkt->stream_index = mxf_get_stream_index(s, &klv);
235             return pkt->stream_index == -1 ? -1 : 0;
236         } else
237             url_fskip(&s->pb, klv.length);
238     }
239     return AVERROR_IO;
240 }
241
242 static int mxf_add_metadata_set(MXFContext *mxf, void *metadata_set)
243 {
244     mxf->metadata_sets = av_realloc(mxf->metadata_sets, (mxf->metadata_sets_count + 1) * sizeof(*mxf->metadata_sets));
245     mxf->metadata_sets[mxf->metadata_sets_count] = metadata_set;
246     mxf->metadata_sets_count++;
247     return 0;
248 }
249
250 static int mxf_read_metadata_preface(MXFContext *mxf, KLVPacket *klv)
251 {
252     ByteIOContext *pb = &mxf->fc->pb;
253     int bytes_read = 0;
254
255     while (bytes_read < klv->length) {
256         int tag = get_be16(pb);
257         int size = get_be16(pb); /* SMPTE 336M Table 8 KLV specified length, 0x53 */
258
259         switch (tag) {
260         case 0x3B03:
261             get_buffer(pb, mxf->content_storage_uid, 16);
262             break;
263         case 0x3B09:
264             get_buffer(pb, mxf->operational_pattern_ul, 16);
265             break;
266         case 0x3B0A:
267             mxf->essence_containers_uls_count = get_be32(pb);
268             if (mxf->essence_containers_uls_count >= UINT_MAX / sizeof(UID))
269                 return -1;
270             mxf->essence_containers_uls = av_malloc(mxf->essence_containers_uls_count * sizeof(UID));
271             url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
272             get_buffer(pb, (uint8_t *)mxf->essence_containers_uls, mxf->essence_containers_uls_count * sizeof(UID));
273             break;
274         default:
275             url_fskip(pb, size);
276         }
277         bytes_read += size + 4;
278     }
279     return 0;
280 }
281
282 static int mxf_read_metadata_content_storage(MXFContext *mxf, KLVPacket *klv)
283 {
284     ByteIOContext *pb = &mxf->fc->pb;
285     int bytes_read = 0;
286
287     while (bytes_read < klv->length) {
288         int tag = get_be16(pb);
289         int size = get_be16(pb); /* SMPTE 336M Table 8 KLV specified length, 0x53 */
290
291         dprintf("tag 0x%04X, size %d\n", tag, size);
292         switch (tag) {
293         case 0x1901:
294             mxf->packages_count = get_be32(pb);
295             if (mxf->packages_count >= UINT_MAX / sizeof(UID))
296                 return -1;
297             mxf->packages_refs = av_malloc(mxf->packages_count * sizeof(UID));
298             url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
299             get_buffer(pb, (uint8_t *)mxf->packages_refs, mxf->packages_count * sizeof(UID));
300             break;
301         case 0x1902:
302             mxf->essence_container_data_sets_count = get_be32(pb);
303             if (mxf->essence_container_data_sets_count >= UINT_MAX / sizeof(UID))
304                 return -1;
305             mxf->essence_container_data_sets_refs = av_malloc(mxf->essence_container_data_sets_count * sizeof(UID));
306             url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
307             get_buffer(pb, (uint8_t *)mxf->essence_container_data_sets_refs, mxf->essence_container_data_sets_count * sizeof(UID));
308             break;
309         default:
310             url_fskip(pb, size);
311         }
312         bytes_read += size + 4;
313     }
314     return 0;
315 }
316
317 static int mxf_read_metadata_source_clip(MXFContext *mxf, KLVPacket *klv)
318 {
319     ByteIOContext *pb = &mxf->fc->pb;
320     MXFStructuralComponent *source_clip = av_mallocz(sizeof(*source_clip));
321     int bytes_read = 0;
322
323     while (bytes_read < klv->length) {
324         int tag = get_be16(pb);
325         int size = get_be16(pb); /* SMPTE 336M Table 8 KLV specified length, 0x53 */
326
327         bytes_read += size + 4;
328         dprintf("tag 0x%04X, size %d\n", tag, size);
329         if (!size) /* ignore empty tag, needed for some files with empty UMID tag */
330             continue;
331         switch (tag) {
332         case 0x3C0A:
333             get_buffer(pb, source_clip->uid, 16);
334             break;
335         case 0x0202:
336             source_clip->duration = get_be64(pb);
337             break;
338         case 0x1201:
339             source_clip->start_position = get_be64(pb);
340             break;
341         case 0x1101:
342             /* UMID, only get last 16 bytes */
343             url_fskip(pb, 16);
344             get_buffer(pb, source_clip->source_package_uid, 16);
345             break;
346         case 0x1102:
347             source_clip->source_track_id = get_be32(pb);
348             break;
349         default:
350             url_fskip(pb, size);
351         }
352     }
353     source_clip->type = SourceClip;
354     return mxf_add_metadata_set(mxf, source_clip);
355 }
356
357 static int mxf_read_metadata_material_package(MXFContext *mxf, KLVPacket *klv)
358 {
359     ByteIOContext *pb = &mxf->fc->pb;
360     MXFPackage *package = av_mallocz(sizeof(*package));
361     int bytes_read = 0;
362
363     while (bytes_read < klv->length) {
364         int tag = get_be16(pb);
365         int size = get_be16(pb); /* KLV specified by 0x53 */
366
367         switch (tag) {
368         case 0x3C0A:
369             get_buffer(pb, package->uid, 16);
370             break;
371         case 0x4403:
372             package->tracks_count = get_be32(pb);
373             if (package->tracks_count >= UINT_MAX / sizeof(UID))
374                 return -1;
375             package->tracks_refs = av_malloc(package->tracks_count * sizeof(UID));
376             url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
377             get_buffer(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID));
378             break;
379         default:
380             url_fskip(pb, size);
381         }
382         bytes_read += size + 4;
383     }
384     package->type = MaterialPackage;
385     return mxf_add_metadata_set(mxf, package);
386 }
387
388 static int mxf_read_metadata_track(MXFContext *mxf, KLVPacket *klv)
389 {
390     ByteIOContext *pb = &mxf->fc->pb;
391     MXFTrack *track = av_mallocz(sizeof(*track));
392     int bytes_read = 0;
393
394     while (bytes_read < klv->length) {
395         int tag = get_be16(pb);
396         int size = get_be16(pb); /* KLV specified by 0x53 */
397
398         dprintf("tag 0x%04X, size %d\n", tag, size);
399         switch (tag) {
400         case 0x3C0A:
401             get_buffer(pb, track->uid, 16);
402             break;
403         case 0x4801:
404             track->track_id = get_be32(pb);
405             break;
406         case 0x4804:
407             get_buffer(pb, track->track_number, 4);
408             break;
409         case 0x4B01:
410             track->edit_rate.den = get_be32(pb);
411             track->edit_rate.num = get_be32(pb);
412             break;
413         case 0x4803:
414             get_buffer(pb, track->sequence_ref, 16);
415             break;
416         default:
417             url_fskip(pb, size);
418         }
419         bytes_read += size + 4;
420     }
421     track->type = Track;
422     return mxf_add_metadata_set(mxf, track);
423 }
424
425 static int mxf_read_metadata_sequence(MXFContext *mxf, KLVPacket *klv)
426 {
427     ByteIOContext *pb = &mxf->fc->pb;
428     MXFSequence *sequence = av_mallocz(sizeof(*sequence));
429     int bytes_read = 0;
430
431     while (bytes_read < klv->length) {
432         int tag = get_be16(pb);
433         int size = get_be16(pb); /* KLV specified by 0x53 */
434
435         dprintf("tag 0x%04X, size %d\n", tag, size);
436         switch (tag) {
437         case 0x3C0A:
438             get_buffer(pb, sequence->uid, 16);
439             break;
440         case 0x0202:
441             sequence->duration = get_be64(pb);
442             break;
443         case 0x0201:
444             get_buffer(pb, sequence->data_definition_ul, 16);
445             break;
446         case 0x1001:
447             sequence->structural_components_count = get_be32(pb);
448             if (sequence->structural_components_count >= UINT_MAX / sizeof(UID))
449                 return -1;
450             sequence->structural_components_refs = av_malloc(sequence->structural_components_count * sizeof(UID));
451             url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
452             get_buffer(pb, (uint8_t *)sequence->structural_components_refs, sequence->structural_components_count * sizeof(UID));
453             break;
454         default:
455             url_fskip(pb, size);
456         }
457         bytes_read += size + 4;
458     }
459     sequence->type = Sequence;
460     return mxf_add_metadata_set(mxf, sequence);
461 }
462
463 static int mxf_read_metadata_source_package(MXFContext *mxf, KLVPacket *klv)
464 {
465     ByteIOContext *pb = &mxf->fc->pb;
466     MXFPackage *package = av_mallocz(sizeof(*package));
467     int bytes_read = 0;
468
469     while (bytes_read < klv->length) {
470         int tag = get_be16(pb);
471         int size = get_be16(pb); /* KLV specified by 0x53 */
472
473         dprintf("tag 0x%04X, size %d\n", tag, size);
474         switch (tag) {
475         case 0x3C0A:
476             get_buffer(pb, package->uid, 16);
477             break;
478         case 0x4403:
479             package->tracks_count = get_be32(pb);
480             if (package->tracks_count >= UINT_MAX / sizeof(UID))
481                 return -1;
482             package->tracks_refs = av_malloc(package->tracks_count * sizeof(UID));
483             url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
484             get_buffer(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID));
485             break;
486         case 0x4401:
487             /* UMID, only get last 16 bytes */
488             url_fskip(pb, 16);
489             get_buffer(pb, package->package_uid, 16);
490             break;
491         case 0x4701:
492             get_buffer(pb, package->descriptor_ref, 16);
493             break;
494         default:
495             url_fskip(pb, size);
496         }
497         bytes_read += size + 4;
498     }
499     package->type = SourcePackage;
500     return mxf_add_metadata_set(mxf, package);
501 }
502
503 static int mxf_read_metadata_multiple_descriptor(MXFContext *mxf, KLVPacket *klv)
504 {
505     ByteIOContext *pb = &mxf->fc->pb;
506     MXFDescriptor *descriptor = av_mallocz(sizeof(*descriptor));
507     int bytes_read = 0;
508
509     while (bytes_read < klv->length) {
510         int tag = get_be16(pb);
511         int size = get_be16(pb); /* KLV specified by 0x53 */
512
513         dprintf("tag 0x%04X, size %d\n", tag, size);
514         switch (tag) {
515         case 0x3C0A:
516             get_buffer(pb, descriptor->uid, 16);
517             break;
518         case 0x3F01:
519             descriptor->sub_descriptors_count = get_be32(pb);
520             if (descriptor->sub_descriptors_count >= UINT_MAX / sizeof(UID))
521                 return -1;
522             descriptor->sub_descriptors_refs = av_malloc(descriptor->sub_descriptors_count * sizeof(UID));
523             url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
524             get_buffer(pb, (uint8_t *)descriptor->sub_descriptors_refs, descriptor->sub_descriptors_count * sizeof(UID));
525             break;
526         default:
527             url_fskip(pb, size);
528         }
529         bytes_read += size + 4;
530     }
531     descriptor->type = MultipleDescriptor;
532     return mxf_add_metadata_set(mxf, descriptor);
533 }
534
535 static void mxf_read_metadata_pixel_layout(ByteIOContext *pb, MXFDescriptor *descriptor)
536 {
537     int code;
538
539     do {
540         code = get_byte(pb);
541         dprintf("pixel layout: code 0x%x\n", code);
542         switch (code) {
543         case 0x52: /* R */
544             descriptor->bits_per_sample += get_byte(pb);
545             break;
546         case 0x47: /* G */
547             descriptor->bits_per_sample += get_byte(pb);
548             break;
549         case 0x42: /* B */
550             descriptor->bits_per_sample += get_byte(pb);
551             break;
552         default:
553             get_byte(pb);
554         }
555     } while (code != 0); /* SMPTE 377M E.2.46 */
556 }
557
558 static int mxf_read_metadata_generic_descriptor(MXFContext *mxf, KLVPacket *klv)
559 {
560     ByteIOContext *pb = &mxf->fc->pb;
561     MXFDescriptor *descriptor = av_mallocz(sizeof(*descriptor));
562     int bytes_read = 0;
563
564     while (bytes_read < klv->length) {
565         int tag = get_be16(pb);
566         int size = get_be16(pb); /* KLV specified by 0x53 */
567
568         dprintf("tag 0x%04X, size %d\n", tag, size);
569         switch (tag) {
570         case 0x3C0A:
571             get_buffer(pb, descriptor->uid, 16);
572             break;
573         case 0x3004:
574             get_buffer(pb, descriptor->essence_container_ul, 16);
575             break;
576         case 0x3006:
577             descriptor->linked_track_id = get_be32(pb);
578             break;
579         case 0x3201: /* PictureEssenceCoding */
580             get_buffer(pb, descriptor->essence_codec_ul, 16);
581             break;
582         case 0x3203:
583             descriptor->width = get_be32(pb);
584             break;
585         case 0x3202:
586             descriptor->height = get_be32(pb);
587             break;
588         case 0x320E:
589             descriptor->aspect_ratio.num = get_be32(pb);
590             descriptor->aspect_ratio.den = get_be32(pb);
591             break;
592         case 0x3D03:
593             descriptor->sample_rate.num = get_be32(pb);
594             descriptor->sample_rate.den = get_be32(pb);
595             break;
596         case 0x3D06: /* SoundEssenceCompression */
597             get_buffer(pb, descriptor->essence_codec_ul, 16);
598             break;
599         case 0x3D07:
600             descriptor->channels = get_be32(pb);
601             break;
602         case 0x3D01:
603             descriptor->bits_per_sample = get_be32(pb);
604             break;
605         case 0x3401:
606             mxf_read_metadata_pixel_layout(pb, descriptor);
607             break;
608         case 0x8201: /* Private tag used by SONY C0023S01.mxf */
609             descriptor->extradata = av_malloc(size);
610             descriptor->extradata_size = size;
611             get_buffer(pb, descriptor->extradata, size);
612             break;
613         default:
614             url_fskip(pb, size);
615         }
616         bytes_read += size + 4;
617     }
618     descriptor->type = Descriptor;
619     return mxf_add_metadata_set(mxf, descriptor);
620 }
621
622 /* SMPTE RP224 http://www.smpte-ra.org/mdd/index.html */
623 static const MXFDataDefinitionUL mxf_data_definition_uls[] = {
624     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x01,0x00,0x00,0x00 }, CODEC_TYPE_VIDEO },
625     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x02,0x00,0x00,0x00 }, CODEC_TYPE_AUDIO },
626     { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },  CODEC_TYPE_DATA },
627 };
628
629 static const MXFCodecUL mxf_codec_uls[] = {
630     /* PictureEssenceCoding */
631     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x02,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* 422P@ML I-Frame */
632     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x03,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* 422P@HL Long GoP */
633     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x11,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* MP@ML Long GoP */
634     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x03,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* 422P@ML Long GoP */
635     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x03,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* MP@HL Long GoP */
636     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x20,0x02,0x03 },      CODEC_ID_MPEG4, Frame }, /* XDCAM proxy_pal030926.mxf */
637     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x20,0x02,0x04 },      CODEC_ID_MPEG4, Frame }, /* XDCAM Proxy C0023S01.mxf */
638     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x05 }, CODEC_ID_MPEG2VIDEO, Frame }, /* D-10 30Mbps PAL */
639     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x01 }, CODEC_ID_MPEG2VIDEO, Frame }, /* D-10 50Mbps PAL */
640     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x04,0x00 },    CODEC_ID_DVVIDEO, Frame }, /* DVCPRO50 PAL */
641     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x02,0x00 },    CODEC_ID_DVVIDEO, Frame }, /* DVCPRO25 PAL */
642     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x01,0x02,0x00 },    CODEC_ID_DVVIDEO, Frame }, /* DV25 IEC PAL */
643     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x07,0x04,0x01,0x02,0x02,0x03,0x01,0x01,0x00 },   CODEC_ID_JPEG2000, Frame }, /* JPEG2000 Codestream */
644     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x01,0x7F,0x00,0x00,0x00 },   CODEC_ID_RAWVIDEO, Frame }, /* Uncompressed */
645     /* SoundEssenceCompression */
646     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },  CODEC_ID_PCM_S16LE, Frame }, /* Uncompressed */
647     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x7F,0x00,0x00,0x00 },  CODEC_ID_PCM_S16LE, Frame },
648     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x07,0x04,0x02,0x02,0x01,0x7E,0x00,0x00,0x00 },  CODEC_ID_PCM_S16BE, Frame }, /* From Omneon MXF file */
649     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x01,0x01,0x00 },   CODEC_ID_PCM_ALAW, Frame },
650     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x04,0x04,0x02,0x02,0x02,0x03,0x01,0x01,0x00 },   CODEC_ID_PCM_ALAW, Frame }, /* XDCAM Proxy C0023S01.mxf */
651     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x01,0x00 },        CODEC_ID_AC3, Frame },
652     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x05,0x00 },        CODEC_ID_MP2, Frame }, /* MP2 or MP3 */
653   //{ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x1C,0x00 },    CODEC_ID_DOLBY_E, Frame }, /* Dolby-E */
654     { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },       CODEC_ID_NONE, Frame },
655 };
656
657 static const MXFCodecUL mxf_picture_essence_container_uls[] = {
658     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 }, CODEC_ID_MPEG2VIDEO, Frame }, /* MPEG-ES Frame wrapped */
659     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0xe0,0x02 }, CODEC_ID_MPEG2VIDEO,  Clip }, /* MPEG-ES Clip wrapped, 0xe0 MPV stream id */
660     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x04,0x61,0x07 }, CODEC_ID_MPEG2VIDEO,  Clip }, /* MPEG-ES Custom wrapped, 0x61 ??? stream id */
661     { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },       CODEC_ID_NONE, Frame },
662 };
663
664 static const MXFCodecUL mxf_sound_essence_container_uls[] = {
665     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x01,0x00 },  CODEC_ID_PCM_S16LE, Frame }, /* BWF Frame wrapped */
666     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x03,0x00 },  CODEC_ID_PCM_S16LE, Frame }, /* AES Frame wrapped */
667     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x40,0x01 },        CODEC_ID_MP2, Frame }, /* MPEG-ES Frame wrapped, 0x40 ??? stream id */
668     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0xc0,0x01 },        CODEC_ID_MP2, Frame }, /* MPEG-ES Frame wrapped, 0xc0 MPA stream id */
669     { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0xc0,0x02 },        CODEC_ID_MP2,  Clip }, /* MPEG-ES Clip wrapped, 0xc0 MPA stream id */
670   //{ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x05,0x01 },   CODEC_ID_PCM_AES3, Frame }, /* D-10 Mapping 30Mbps PAL Extended Template */
671     { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },       CODEC_ID_NONE, Frame },
672 };
673
674 static const MXFCodecUL *mxf_get_codec_ul(const MXFCodecUL *uls, UID *uid)
675 {
676     while (uls->id != CODEC_ID_NONE) {
677         if(!memcmp(uls->uid, *uid, 16))
678             break;
679         uls++;
680     }
681     return uls;
682 }
683
684 static enum CodecType mxf_get_codec_type(const MXFDataDefinitionUL *uls, UID *uid)
685 {
686     while (uls->type != CODEC_TYPE_DATA) {
687         if(!memcmp(uls->uid, *uid, 16))
688             break;
689         uls++;
690     }
691     return uls->type;
692 }
693
694 static void *mxf_resolve_strong_ref(MXFContext *mxf, UID *strong_ref)
695 {
696     int i;
697
698     if (!strong_ref)
699         return NULL;
700     for (i = 0; i < mxf->metadata_sets_count; i++) {
701         if (!memcmp(*strong_ref, mxf->metadata_sets[i]->uid, 16)) {
702             return mxf->metadata_sets[i];
703         }
704     }
705     return NULL;
706 }
707
708 static int mxf_parse_structural_metadata(MXFContext *mxf)
709 {
710     MXFPackage *material_package = NULL;
711     MXFPackage *source_package = NULL;
712     MXFPackage *temp_package = NULL;
713     int i, j, k;
714
715     dprintf("metadata sets count %d\n", mxf->metadata_sets_count);
716     /* TODO: handle multiple material packages (OP3x) */
717     for (i = 0; i < mxf->packages_count; i++) {
718         if (!(temp_package = mxf_resolve_strong_ref(mxf, &mxf->packages_refs[i]))) {
719             av_log(mxf->fc, AV_LOG_ERROR, "could not resolve package strong ref\n");
720             return -1;
721         }
722         if (temp_package->type == MaterialPackage) {
723             material_package = temp_package;
724             break;
725         }
726     }
727     if (!material_package) {
728         av_log(mxf->fc, AV_LOG_ERROR, "no material package found\n");
729         return -1;
730     }
731
732     for (i = 0; i < material_package->tracks_count; i++) {
733         MXFTrack *material_track = NULL;
734         MXFTrack *source_track = NULL;
735         MXFTrack *temp_track = NULL;
736         MXFDescriptor *descriptor = NULL;
737         MXFStructuralComponent *component = NULL;
738         const MXFCodecUL *codec_ul = NULL;
739         const MXFCodecUL *container_ul = NULL;
740         AVStream *st;
741
742         if (!(material_track = mxf_resolve_strong_ref(mxf, &material_package->tracks_refs[i]))) {
743             av_log(mxf->fc, AV_LOG_ERROR, "could not resolve material track strong ref\n");
744             continue;
745         }
746
747         if (!(material_track->sequence = mxf_resolve_strong_ref(mxf, &material_track->sequence_ref))) {
748             av_log(mxf->fc, AV_LOG_ERROR, "could not resolve material track sequence strong ref\n");
749             return -1;
750         }
751
752         /* TODO: handle multiple source clips */
753         for (j = 0; j < material_track->sequence->structural_components_count; j++) {
754             /* TODO: handle timecode component */
755             component = mxf_resolve_strong_ref(mxf, &material_track->sequence->structural_components_refs[j]);
756             if (!component || component->type != SourceClip)
757                 continue;
758
759             for (k = 0; k < mxf->packages_count; k++) {
760                 if (!(temp_package = mxf_resolve_strong_ref(mxf, &mxf->packages_refs[k]))) {
761                     av_log(mxf->fc, AV_LOG_ERROR, "could not resolve source track strong ref\n");
762                     return -1;
763                 }
764                 if (!memcmp(temp_package->package_uid, component->source_package_uid, 16)) {
765                     source_package = temp_package;
766                     break;
767                 }
768             }
769             if (!source_package) {
770                 av_log(mxf->fc, AV_LOG_ERROR, "material track %d: no corresponding source package found\n", material_track->track_id);
771                 break;
772             }
773             for (k = 0; k < source_package->tracks_count; k++) {
774                 if (!(temp_track = mxf_resolve_strong_ref(mxf, &source_package->tracks_refs[k]))) {
775                     av_log(mxf->fc, AV_LOG_ERROR, "could not resolve source track strong ref\n");
776                     return -1;
777                 }
778                 if (temp_track->track_id == component->source_track_id) {
779                     source_track = temp_track;
780                     break;
781                 }
782             }
783             if (!source_track) {
784                 av_log(mxf->fc, AV_LOG_ERROR, "material track %d: no corresponding source track found\n", material_track->track_id);
785                 break;
786             }
787         }
788         if (!source_track)
789             continue;
790
791         st = av_new_stream(mxf->fc, source_track->track_id);
792         st->priv_data = source_track;
793         st->duration = component->duration;
794         if (st->duration == -1)
795             st->duration = AV_NOPTS_VALUE;
796         st->start_time = component->start_position;
797         av_set_pts_info(st, 64, material_track->edit_rate.num, material_track->edit_rate.den);
798
799         if (!(source_track->sequence = mxf_resolve_strong_ref(mxf, &source_track->sequence_ref))) {
800             av_log(mxf->fc, AV_LOG_ERROR, "could not resolve source track sequence strong ref\n");
801             return -1;
802         }
803
804 #ifdef DEBUG
805         PRINT_KEY("data definition   ul", source_track->sequence->data_definition_ul);
806 #endif
807         st->codec->codec_type = mxf_get_codec_type(mxf_data_definition_uls, &source_track->sequence->data_definition_ul);
808
809         source_package->descriptor = mxf_resolve_strong_ref(mxf, &source_package->descriptor_ref);
810         if (source_package->descriptor) {
811             if (source_package->descriptor->type == MultipleDescriptor) {
812                 for (j = 0; j < source_package->descriptor->sub_descriptors_count; j++) {
813                     MXFDescriptor *sub_descriptor = mxf_resolve_strong_ref(mxf, &source_package->descriptor->sub_descriptors_refs[j]);
814
815                     if (!sub_descriptor) {
816                         av_log(mxf->fc, AV_LOG_ERROR, "could not resolve sub descriptor strong ref\n");
817                         continue;
818                     }
819                     if (sub_descriptor->linked_track_id == source_track->track_id) {
820                         descriptor = sub_descriptor;
821                         break;
822                     }
823                 }
824             } else
825                 descriptor = source_package->descriptor;
826         }
827         if (!descriptor) {
828             av_log(mxf->fc, AV_LOG_INFO, "source track %d: stream %d, no descriptor found\n", source_track->track_id, st->index);
829             continue;
830         }
831 #ifdef DEBUG
832         PRINT_KEY("essence codec     ul", descriptor->essence_codec_ul);
833         PRINT_KEY("essence container ul", descriptor->essence_container_ul);
834 #endif
835         /* TODO: drop PictureEssenceCoding and SoundEssenceCompression, only check EssenceContainer */
836         codec_ul = mxf_get_codec_ul(mxf_codec_uls, &descriptor->essence_codec_ul);
837         st->codec->codec_id = codec_ul->id;
838         if (descriptor->extradata) {
839             st->codec->extradata = descriptor->extradata;
840             st->codec->extradata_size = descriptor->extradata_size;
841         }
842         if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
843             container_ul = mxf_get_codec_ul(mxf_picture_essence_container_uls, &descriptor->essence_container_ul);
844             if (st->codec->codec_id == CODEC_ID_NONE)
845                 st->codec->codec_id = container_ul->id;
846             st->codec->width = descriptor->width;
847             st->codec->height = descriptor->height;
848             st->codec->bits_per_sample = descriptor->bits_per_sample; /* Uncompressed */
849         } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
850             container_ul = mxf_get_codec_ul(mxf_sound_essence_container_uls, &descriptor->essence_container_ul);
851             if (st->codec->codec_id == CODEC_ID_NONE)
852                 st->codec->codec_id = container_ul->id;
853             st->codec->channels = descriptor->channels;
854             st->codec->bits_per_sample = descriptor->bits_per_sample;
855             st->codec->sample_rate = descriptor->sample_rate.num / descriptor->sample_rate.den;
856             /* TODO: implement CODEC_ID_RAWAUDIO */
857             if (st->codec->codec_id == CODEC_ID_PCM_S16LE) {
858                 if (descriptor->bits_per_sample == 24)
859                     st->codec->codec_id = CODEC_ID_PCM_S24LE;
860                 else if (descriptor->bits_per_sample == 32)
861                     st->codec->codec_id = CODEC_ID_PCM_S32LE;
862             } else if (st->codec->codec_id == CODEC_ID_PCM_S16BE) {
863                 if (descriptor->bits_per_sample == 24)
864                     st->codec->codec_id = CODEC_ID_PCM_S24BE;
865                 else if (descriptor->bits_per_sample == 32)
866                     st->codec->codec_id = CODEC_ID_PCM_S32BE;
867             }
868         }
869         if (container_ul && container_ul->wrapping == Clip) {
870             dprintf("stream %d: clip wrapped essence\n", st->index);
871             st->need_parsing = 1;
872         }
873     }
874     return 0;
875 }
876
877 static const MXFMetadataReadTableEntry mxf_metadata_read_table[] = {
878     { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x2F,0x00 }, mxf_read_metadata_preface },
879     { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x18,0x00 }, mxf_read_metadata_content_storage },
880     { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x37,0x00 }, mxf_read_metadata_source_package },
881     { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x36,0x00 }, mxf_read_metadata_material_package },
882     { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x0F,0x00 }, mxf_read_metadata_sequence },
883     { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x11,0x00 }, mxf_read_metadata_source_clip },
884     { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x44,0x00 }, mxf_read_metadata_multiple_descriptor },
885     { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x42,0x00 }, mxf_read_metadata_generic_descriptor }, /* Generic Sound */
886     { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x28,0x00 }, mxf_read_metadata_generic_descriptor }, /* CDCI */
887     { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x29,0x00 }, mxf_read_metadata_generic_descriptor }, /* RGBA */
888     { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 }, mxf_read_metadata_generic_descriptor }, /* MPEG 2 Video */
889     { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 }, mxf_read_metadata_generic_descriptor }, /* Wave */
890     { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 }, mxf_read_metadata_generic_descriptor }, /* AES3 */
891     { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3A,0x00 }, mxf_read_metadata_track }, /* Static Track */
892     { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3B,0x00 }, mxf_read_metadata_track }, /* Generic Track */
893     { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, NULL },
894 };
895
896 static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap)
897 {
898     MXFContext *mxf = s->priv_data;
899     KLVPacket klv;
900
901     mxf->fc = s;
902     while (!url_feof(&s->pb)) {
903         const MXFMetadataReadTableEntry *function;
904
905         if (klv_read_packet(&klv, &s->pb) < 0) {
906             av_log(s, AV_LOG_ERROR, "error reading KLV packet\n");
907             return -1;
908         }
909 #ifdef DEBUG
910         PRINT_KEY("read header", klv.key);
911 #endif
912         if (IS_KLV_KEY(klv.key, mxf_essence_element_key)) {
913             /* FIXME avoid seek */
914             url_fseek(&s->pb, klv.offset, SEEK_SET);
915             break;
916         }
917
918         for (function = mxf_metadata_read_table; function->read; function++) {
919             if (IS_KLV_KEY(klv.key, function->key)) {
920                 if (function->read(mxf, &klv) < 0) {
921                     av_log(s, AV_LOG_ERROR, "error reading header metadata\n");
922                     return -1;
923                 }
924                 break;
925             }
926         }
927         if (!function->read)
928             url_fskip(&s->pb, klv.length);
929     }
930     return mxf_parse_structural_metadata(mxf);
931 }
932
933 static int mxf_read_close(AVFormatContext *s)
934 {
935     MXFContext *mxf = s->priv_data;
936     int i;
937
938     av_freep(&mxf->packages_refs);
939     av_freep(&mxf->essence_container_data_sets_refs);
940     av_freep(&mxf->essence_containers_uls);
941     for (i = 0; i < mxf->metadata_sets_count; i++) {
942         switch (mxf->metadata_sets[i]->type) {
943         case MultipleDescriptor:
944             av_freep(&((MXFDescriptor *)mxf->metadata_sets[i])->sub_descriptors_refs);
945             break;
946         case Sequence:
947             av_freep(&((MXFSequence *)mxf->metadata_sets[i])->structural_components_refs);
948             break;
949         case SourcePackage:
950         case MaterialPackage:
951             av_freep(&((MXFPackage *)mxf->metadata_sets[i])->tracks_refs);
952             break;
953         default:
954             break;
955         }
956         av_freep(&mxf->metadata_sets[i]);
957     }
958     av_freep(&mxf->metadata_sets);
959     return 0;
960 }
961
962 static int mxf_probe(AVProbeData *p) {
963     uint8_t *bufp = p->buf;
964     uint8_t *end = p->buf + p->buf_size;
965
966     if (p->buf_size < sizeof(mxf_header_partition_pack_key))
967         return 0;
968
969     /* Must skip Run-In Sequence and search for MXF header partition pack key SMPTE 377M 5.5 */
970     end -= sizeof(mxf_header_partition_pack_key);
971     for (; bufp < end; bufp++) {
972         if (IS_KLV_KEY(bufp, mxf_header_partition_pack_key))
973             return AVPROBE_SCORE_MAX;
974     }
975     return 0;
976 }
977
978
979 AVInputFormat mxf_demuxer = {
980     "mxf",
981     "MXF format",
982     sizeof(MXFContext),
983     mxf_probe,
984     mxf_read_header,
985     mxf_read_packet,
986     mxf_read_close,
987     NULL,
988 };