Mercurial > libavformat.hg
comparison mxfenc.c @ 3845:c266530d56b4 libavformat
merge descriptor write table with essence container uls table and simplify
author | bcoudurier |
---|---|
date | Sun, 31 Aug 2008 04:07:41 +0000 |
parents | b597c00051a6 |
children | 0ee95f0b4c00 |
comparison
equal
deleted
inserted
replaced
3844:b597c00051a6 | 3845:c266530d56b4 |
---|---|
41 typedef struct { | 41 typedef struct { |
42 UID track_essence_element_key; | 42 UID track_essence_element_key; |
43 const UID *essence_container_ul; | 43 const UID *essence_container_ul; |
44 const UID *codec_ul; | 44 const UID *codec_ul; |
45 int64_t duration; | 45 int64_t duration; |
46 void (*write_desc)(); | |
46 } MXFStreamContext; | 47 } MXFStreamContext; |
47 | 48 |
48 typedef struct { | 49 typedef struct { |
49 UID container_ul; | 50 UID container_ul; |
50 UID element_ul; | 51 UID element_ul; |
51 UID codec_ul; | 52 UID codec_ul; |
52 enum CodecID id; | 53 enum CodecID id; |
54 void (*write_desc)(); | |
53 } MXFContainerEssencePair; | 55 } MXFContainerEssencePair; |
56 | |
57 static void mxf_write_wav_desc(AVFormatContext *s, AVStream *st); | |
58 static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st); | |
54 | 59 |
55 static const MXFContainerEssencePair mxf_essence_container_uls[] = { | 60 static const MXFContainerEssencePair mxf_essence_container_uls[] = { |
56 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 }, | 61 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 }, |
57 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 }, | 62 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 }, |
58 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x00,0x00,0x00 }, CODEC_ID_MPEG2VIDEO }, | 63 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x00,0x00,0x00 }, |
64 CODEC_ID_MPEG2VIDEO, mxf_write_mpegvideo_desc }, | |
59 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x01,0x00 }, | 65 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x01,0x00 }, |
60 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x16,0x01,0x01,0x00 }, | 66 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x16,0x01,0x01,0x00 }, |
61 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, CODEC_ID_PCM_S16LE }, | 67 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, |
68 CODEC_ID_PCM_S16LE, mxf_write_wav_desc }, | |
62 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, | 69 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, |
63 { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, | 70 { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, |
64 { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, CODEC_ID_NONE }, | 71 { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, |
72 CODEC_ID_NONE, NULL }, | |
65 }; | 73 }; |
66 | 74 |
67 typedef struct MXFContext { | 75 typedef struct MXFContext { |
68 int64_t footer_partition_offset; | 76 int64_t footer_partition_offset; |
69 int essence_container_count; | 77 int essence_container_count; |
70 uint8_t essence_containers_indices[sizeof(mxf_essence_container_uls)/ | 78 uint8_t essence_containers_indices[sizeof(mxf_essence_container_uls)/ |
71 sizeof(*mxf_essence_container_uls)]; | 79 sizeof(*mxf_essence_container_uls)]; |
72 } MXFContext; | 80 } MXFContext; |
73 | |
74 typedef struct { | |
75 const UID key; | |
76 void (*write)(); | |
77 enum CodecType type; | |
78 } MXFDescriptorWriteTableEntry; | |
79 | 81 |
80 static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd }; | 82 static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd }; |
81 static const uint8_t umid_base[] = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x0F,0x00,0x13,0x00,0x00,0x00 }; | 83 static const uint8_t umid_base[] = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x0F,0x00,0x13,0x00,0x00,0x00 }; |
82 | 84 |
83 /** | 85 /** |
573 mxf_write_refs_count(pb, s->nb_streams); | 575 mxf_write_refs_count(pb, s->nb_streams); |
574 for (i = 0; i < s->nb_streams; i++) | 576 for (i = 0; i < s->nb_streams; i++) |
575 mxf_write_uuid(pb, SubDescriptor, i); | 577 mxf_write_uuid(pb, SubDescriptor, i); |
576 } | 578 } |
577 | 579 |
578 static void mxf_write_generic_desc(ByteIOContext *pb, const MXFDescriptorWriteTableEntry *desc_tbl, AVStream *st) | 580 static void mxf_write_generic_desc(ByteIOContext *pb, AVStream *st, const UID key) |
579 { | 581 { |
580 MXFStreamContext *sc = st->priv_data; | 582 MXFStreamContext *sc = st->priv_data; |
581 | 583 |
582 put_buffer(pb, desc_tbl->key, 16); | 584 put_buffer(pb, key, 16); |
583 klv_encode_ber_length(pb, 108); | 585 klv_encode_ber_length(pb, 108); |
584 | 586 |
585 mxf_write_local_tag(pb, 16, 0x3C0A); | 587 mxf_write_local_tag(pb, 16, 0x3C0A); |
586 mxf_write_uuid(pb, SubDescriptor, st->index); | 588 mxf_write_uuid(pb, SubDescriptor, st->index); |
587 | 589 |
597 | 599 |
598 mxf_write_local_tag(pb, 16, 0x3201); | 600 mxf_write_local_tag(pb, 16, 0x3201); |
599 put_buffer(pb, *sc->codec_ul, 16); | 601 put_buffer(pb, *sc->codec_ul, 16); |
600 } | 602 } |
601 | 603 |
602 static void mxf_write_mpegvideo_desc(AVFormatContext *s, const MXFDescriptorWriteTableEntry *desc_tbl, AVStream *st) | 604 static const UID mxf_mpegvideo_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 }; |
603 { | 605 static const UID mxf_wav_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 }; |
604 ByteIOContext *pb = s->pb; | 606 |
605 | 607 static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st) |
606 mxf_write_generic_desc(pb, desc_tbl, st); | 608 { |
609 ByteIOContext *pb = s->pb; | |
610 | |
611 mxf_write_generic_desc(pb, st, mxf_mpegvideo_descriptor_key); | |
607 | 612 |
608 mxf_write_local_tag(pb, 4, 0x3203); | 613 mxf_write_local_tag(pb, 4, 0x3203); |
609 put_be32(pb, st->codec->width); | 614 put_be32(pb, st->codec->width); |
610 | 615 |
611 mxf_write_local_tag(pb, 4, 0x3202); | 616 mxf_write_local_tag(pb, 4, 0x3202); |
614 mxf_write_local_tag(pb, 8, 0x320E); | 619 mxf_write_local_tag(pb, 8, 0x320E); |
615 put_be32(pb, st->codec->height * st->sample_aspect_ratio.den); | 620 put_be32(pb, st->codec->height * st->sample_aspect_ratio.den); |
616 put_be32(pb, st->codec->width * st->sample_aspect_ratio.num); | 621 put_be32(pb, st->codec->width * st->sample_aspect_ratio.num); |
617 } | 622 } |
618 | 623 |
619 static void mxf_write_wav_desc(AVFormatContext *s, const MXFDescriptorWriteTableEntry *desc_tbl, AVStream *st) | 624 static void mxf_write_wav_desc(AVFormatContext *s, AVStream *st) |
620 { | 625 { |
621 ByteIOContext *pb = s->pb; | 626 ByteIOContext *pb = s->pb; |
622 | 627 |
623 mxf_write_generic_desc(pb, desc_tbl, st); | 628 mxf_write_generic_desc(pb, st, mxf_wav_descriptor_key); |
624 | 629 |
625 // write audio sampling rate | 630 // write audio sampling rate |
626 mxf_write_local_tag(pb, 8, 0x3D03); | 631 mxf_write_local_tag(pb, 8, 0x3D03); |
627 put_be32(pb, st->codec->sample_rate); | 632 put_be32(pb, st->codec->sample_rate); |
628 put_be32(pb, 1); | 633 put_be32(pb, 1); |
632 | 637 |
633 mxf_write_local_tag(pb, 4, 0x3D01); | 638 mxf_write_local_tag(pb, 4, 0x3D01); |
634 put_be32(pb, st->codec->bits_per_sample); | 639 put_be32(pb, st->codec->bits_per_sample); |
635 } | 640 } |
636 | 641 |
637 static const MXFDescriptorWriteTableEntry mxf_descriptor_write_table[] = { | |
638 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 }, mxf_write_mpegvideo_desc, CODEC_ID_MPEG2VIDEO}, | |
639 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 }, mxf_write_wav_desc, CODEC_ID_PCM_S16LE}, | |
640 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, NULL, CODEC_ID_NONE}, | |
641 }; | |
642 | |
643 static void mxf_build_structural_metadata(AVFormatContext *s, enum MXFMetadataSetType type) | 642 static void mxf_build_structural_metadata(AVFormatContext *s, enum MXFMetadataSetType type) |
644 { | 643 { |
645 int i; | 644 int i; |
646 const MXFDescriptorWriteTableEntry *desc = NULL; | |
647 | 645 |
648 mxf_write_package(s, type); | 646 mxf_write_package(s, type); |
649 if (type == SourcePackage) | 647 if (type == SourcePackage) |
650 mxf_write_multi_descriptor(s); | 648 mxf_write_multi_descriptor(s); |
651 | 649 |
654 mxf_write_track(s, st, type); | 652 mxf_write_track(s, st, type); |
655 mxf_write_sequence(s, st, type); | 653 mxf_write_sequence(s, st, type); |
656 mxf_write_structural_component(s, st, type); | 654 mxf_write_structural_component(s, st, type); |
657 | 655 |
658 if (type == SourcePackage) { | 656 if (type == SourcePackage) { |
659 for (desc = mxf_descriptor_write_table; desc->write; desc++) { | 657 MXFStreamContext *sc = st->priv_data; |
660 if (s->streams[i]->codec->codec_id == desc->type) { | 658 sc->write_desc(s, st); |
661 desc->write(s, desc, st); | |
662 break; | |
663 } | |
664 } | |
665 } | 659 } |
666 } | 660 } |
667 } | 661 } |
668 | 662 |
669 static int mxf_write_header_metadata_sets(AVFormatContext *s) | 663 static int mxf_write_header_metadata_sets(AVFormatContext *s) |
810 } else | 804 } else |
811 present[index]++; | 805 present[index]++; |
812 memcpy(sc->track_essence_element_key, mxf_essence_container_uls[index].element_ul, 15); | 806 memcpy(sc->track_essence_element_key, mxf_essence_container_uls[index].element_ul, 15); |
813 sc->track_essence_element_key[15] = present[index]; | 807 sc->track_essence_element_key[15] = present[index]; |
814 PRINT_KEY(s, "track essence element key", sc->track_essence_element_key); | 808 PRINT_KEY(s, "track essence element key", sc->track_essence_element_key); |
809 sc->write_desc = mxf_essence_container_uls[index].write_desc; | |
815 } | 810 } |
816 | 811 |
817 mxf_write_partition(s, 1, header_open_partition_key, 1); | 812 mxf_write_partition(s, 1, header_open_partition_key, 1); |
818 | 813 |
819 return 0; | 814 return 0; |