You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1028 lines
38KB

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