Mercurial > libavformat.hg
annotate mxfenc.c @ 3805:d8a6432c76f3 libavformat
use strlen and do not write useless trailing 0 according to specs
| author | bcoudurier |
|---|---|
| date | Sat, 30 Aug 2008 22:24:19 +0000 |
| parents | 9a7f26d3b75c |
| children | fa043e93fc66 |
| rev | line source |
|---|---|
| 3721 | 1 /* |
| 2 * MXF muxer | |
| 3 * Copyright (c) 2008 GUCAS, Zhentan Feng <spyfeng at gmail dot com> | |
| 4 * | |
| 5 * This file is part of FFmpeg. | |
| 6 * | |
| 7 * FFmpeg 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 * FFmpeg 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 FFmpeg; if not, write to the Free Software | |
| 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 */ | |
| 21 | |
| 22 /* | |
| 23 * References | |
| 24 * SMPTE 336M KLV Data Encoding Protocol Using Key-Length-Value | |
| 25 * SMPTE 377M MXF File Format Specifications | |
| 26 * SMPTE 379M MXF Generic Container | |
| 27 * SMPTE 381M Mapping MPEG Streams into the MXF Generic Container | |
| 28 * SMPTE RP210: SMPTE Metadata Dictionary | |
| 29 * SMPTE RP224: Registry of SMPTE Universal Labels | |
| 30 */ | |
| 31 | |
| 32 //#define DEBUG | |
| 33 | |
| 3735 | 34 #include "mxf.h" |
| 35 | |
| 36 typedef struct { | |
| 37 int local_tag; | |
| 38 UID uid; | |
| 39 } MXFLocalTagPair; | |
| 40 | |
| 3740 | 41 typedef struct { |
| 42 UID track_essence_element_key; | |
| 43 } MXFStreamContext; | |
| 44 | |
| 45 typedef struct MXFContext { | |
| 46 int64_t header_byte_count; | |
| 47 int64_t header_byte_count_offset; | |
| 48 int64_t header_footer_partition_offset; | |
| 49 int essence_container_count; | |
| 50 } MXFContext; | |
| 3743 | 51 |
| 52 typedef struct { | |
| 53 const UID key; | |
| 3749 | 54 void (*write)(); |
| 3743 | 55 enum CodecType type; |
| 56 } MXFDescriptorWriteTableEntry; | |
| 57 | |
| 3735 | 58 static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd }; |
| 59 static const uint8_t umid_base[] = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x0F,0x00,0x13,0x00,0x00,0x00 }; | |
| 60 | |
| 61 /** | |
| 62 * complete key for operation pattern, partitions, and primer pack | |
| 63 */ | |
| 64 static const uint8_t op1a_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x01,0x01,0x00 }; | |
| 65 static const uint8_t header_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x02,0x04,0x00 }; // ClosedComplete | |
| 66 static const uint8_t footer_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x04,0x04,0x00 }; // ClosedComplete | |
| 67 static const uint8_t primer_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x05,0x01,0x00 }; | |
| 68 | |
| 3743 | 69 /** |
| 70 * partial key for header metadata | |
| 71 */ | |
| 72 static const uint8_t header_metadata_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01 }; | |
| 73 | |
| 74 static const MXFCodecUL mxf_essence_element_key[] = { | |
| 75 { { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 }, 14, CODEC_ID_MPEG2VIDEO}, | |
| 76 { { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x16,0x01,0x01,0x00 }, 14, CODEC_ID_PCM_S16LE}, | |
| 77 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, CODEC_ID_NONE}, | |
| 78 }; | |
| 79 | |
| 80 static const uint8_t multiple_desc_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x0D,0x01,0x03,0x01,0x02,0x7F,0x01,0x00 }; | |
| 81 | |
| 3749 | 82 /** |
| 83 * SMPTE RP210 http://www.smpte-ra.org/mdd/index.html | |
| 84 */ | |
| 85 static const MXFLocalTagPair mxf_local_tag_batch[] = { | |
| 86 // preface set | |
| 87 { 0x3C0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x15,0x02,0x00,0x00,0x00,0x00}}, /* Instance UID */ | |
| 88 { 0x3B02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x04,0x00,0x00}}, /* Last Modified Date */ | |
| 89 { 0x3B05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x01,0x05,0x00,0x00,0x00}}, /* Version */ | |
| 90 { 0x3B06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x04,0x00,0x00}}, /* Identifications reference */ | |
| 91 { 0x3B03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x01,0x00,0x00}}, /* Content Storage reference */ | |
| 92 { 0x3B09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x03,0x00,0x00,0x00,0x00}}, /* Operational Pattern UL */ | |
| 93 { 0x3B0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x10,0x02,0x01,0x00,0x00}}, /* Essence Containers UL batch */ | |
| 94 { 0x3B0B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x10,0x02,0x02,0x00,0x00}}, /* DM Schemes UL batch */ | |
| 95 // Identification | |
| 96 { 0x3C09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x01,0x00,0x00,0x00}}, /* This Generation UID */ | |
| 97 { 0x3C01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x02,0x01,0x00,0x00}}, /* Company Name */ | |
| 98 { 0x3C02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x03,0x01,0x00,0x00}}, /* Product Name */ | |
| 3792 | 99 { 0x3C04, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x05,0x01,0x00,0x00}}, /* Version String */ |
| 3749 | 100 { 0x3C05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x07,0x00,0x00,0x00}}, /* Product ID */ |
| 101 { 0x3C06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x03,0x00,0x00}}, /* Modification Date */ | |
| 102 // Content Storage | |
| 103 { 0x1901, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x05,0x01,0x00,0x00}}, /* Package strong reference batch */ | |
| 104 // Essence Container Data | |
| 105 { 0x2701, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x06,0x01,0x00,0x00,0x00}}, /* Linked Package UID */ | |
| 106 { 0x3F07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x01,0x03,0x04,0x04,0x00,0x00,0x00,0x00}}, /* BodySID */ | |
| 107 // Package | |
| 108 { 0x4401, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x15,0x10,0x00,0x00,0x00,0x00}}, /* Package UID */ | |
| 109 { 0x4405, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x01,0x03,0x00,0x00}}, /* Package Creation Date */ | |
| 110 { 0x4404, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x05,0x00,0x00}}, /* Package Modified Date */ | |
| 111 { 0x4403, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x05,0x00,0x00}}, /* Tracks Strong reference array */ | |
| 112 { 0x4701, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x03,0x00,0x00}}, /* Descriptor */ | |
| 113 // Track | |
| 114 { 0x4801, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x01,0x07,0x01,0x01,0x00,0x00,0x00,0x00}}, /* Track ID */ | |
| 3793 | 115 { 0x4804, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x01,0x03,0x00,0x00}}, /* Track Number */ |
| 3749 | 116 { 0x4B01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x30,0x04,0x05,0x00,0x00,0x00,0x00}}, /* Edit Rate */ |
| 117 { 0x4B02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x03,0x00,0x00}}, /* Origin */ | |
| 118 { 0x4803, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x04,0x00,0x00}}, /* Sequence reference */ | |
| 119 // Sequence | |
| 120 { 0x0201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x07,0x01,0x00,0x00,0x00,0x00,0x00}}, /* Data Definition UL */ | |
| 121 { 0x0202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x02,0x01,0x01,0x03,0x00,0x00}}, /* Duration */ | |
| 122 { 0x1001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x09,0x00,0x00}}, /* Structural Components reference array */ | |
| 123 // Source Clip | |
| 124 { 0x1201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x07,0x02,0x01,0x03,0x01,0x0A,0x00,0x00}}, /* Start position */ | |
| 125 { 0x1101, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x03,0x01,0x00,0x00,0x00}}, /* SourcePackageID */ | |
| 126 { 0x1102, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x03,0x02,0x00,0x00,0x00}}, /* SourceTrackID */ | |
| 3794 | 127 // File Descriptor |
| 128 { 0x3F01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x06,0x01,0x01,0x04,0x06,0x0B,0x00,0x00}}, /* Sub Descriptors reference array */ | |
| 3749 | 129 { 0x3006, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x06,0x01,0x01,0x03,0x05,0x00,0x00,0x00}}, /* Linked Track ID */ |
| 130 { 0x3001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x06,0x01,0x01,0x00,0x00,0x00,0x00}}, /* SampleRate */ | |
| 3794 | 131 { 0x3004, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x01,0x02,0x00,0x00}}, /* Essence Container */ |
| 132 // Generic Picture Essence Descriptor | |
| 133 { 0x3203, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x02,0x00,0x00,0x00}}, /* Stored Width */ | |
| 134 { 0x3202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x01,0x00,0x00,0x00}}, /* Stored Height */ | |
| 135 { 0x320E, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x00,0x00,0x00}}, /* Aspect Ratio */ | |
| 136 { 0x3201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x06,0x01,0x00,0x00,0x00,0x00}}, /* Picture Essence Coding */ | |
| 137 // Generic Sound Essence Descriptor | |
| 138 { 0x3D03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x01,0x01,0x01,0x00,0x00}}, /* Audio sampling rate */ | |
| 139 { 0x3D07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x01,0x01,0x04,0x00,0x00,0x00}}, /* ChannelCount */ | |
| 140 { 0x3D01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x03,0x04,0x00,0x00,0x00}}, /* Quantization bits */ | |
| 141 { 0x3D06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x06,0x01,0x00,0x00,0x00,0x00}}, /* Sound Essence Compression */ | |
| 3749 | 142 }; |
| 143 | |
| 3735 | 144 static void mxf_write_uuid(ByteIOContext *pb, enum CodecID type, int value) |
| 145 { | |
| 146 put_buffer(pb, uuid_base, 12); | |
| 147 put_be16(pb, type); | |
| 148 put_be16(pb, value); | |
| 149 } | |
| 150 | |
| 3740 | 151 static void mxf_write_umid(ByteIOContext *pb, enum CodecID type, int value) |
| 152 { | |
| 153 put_buffer(pb, umid_base, 16); | |
| 154 mxf_write_uuid(pb, type, value); | |
| 155 } | |
| 3743 | 156 |
| 157 static void mxf_write_refs_count(ByteIOContext *pb, int ref_count) | |
| 158 { | |
| 159 put_be32(pb, ref_count); | |
| 160 put_be32(pb, 16); | |
| 161 } | |
| 162 | |
| 3735 | 163 static int klv_encode_ber_length(ByteIOContext *pb, uint64_t len) |
| 164 { | |
| 165 // Determine the best BER size | |
| 166 int size; | |
| 167 if (len < 128) { | |
| 168 //short form | |
| 169 put_byte(pb, len); | |
| 170 return 1; | |
| 171 } | |
| 172 | |
| 173 size = (av_log2(len) >> 3) + 1; | |
| 174 | |
| 175 // long form | |
| 176 put_byte(pb, 0x80 + size); | |
| 177 while(size) { | |
| 178 size --; | |
| 179 put_byte(pb, len >> 8 * size & 0xff); | |
| 180 } | |
| 181 return 0; | |
| 182 } | |
| 183 | |
| 3721 | 184 static const MXFCodecUL *mxf_get_essence_container_ul(enum CodecID type) |
| 185 { | |
| 3735 | 186 const MXFCodecUL *uls = ff_mxf_essence_container_uls; |
| 3721 | 187 while (uls->id != CODEC_ID_NONE) { |
| 188 if (uls->id == type) | |
| 189 break; | |
| 190 uls++; | |
| 191 } | |
| 192 return uls; | |
| 193 } | |
| 194 | |
| 3749 | 195 static void mxf_write_primer_pack(AVFormatContext *s) |
| 3735 | 196 { |
| 197 ByteIOContext *pb = s->pb; | |
| 198 int local_tag_number, i = 0; | |
| 199 | |
| 200 local_tag_number = sizeof(mxf_local_tag_batch) / sizeof(MXFLocalTagPair); | |
| 201 | |
| 202 put_buffer(pb, primer_pack_key, 16); | |
| 203 klv_encode_ber_length(pb, local_tag_number * 18 + 8); | |
| 204 | |
| 205 put_be32(pb, local_tag_number); // local_tag num | |
| 206 put_be32(pb, 18); // item size, always 18 according to the specs | |
| 207 | |
| 208 for (i = 0; i < local_tag_number; i++) { | |
| 209 put_be16(pb, mxf_local_tag_batch[i].local_tag); | |
| 210 put_buffer(pb, mxf_local_tag_batch[i].uid, 16); | |
| 211 } | |
| 212 } | |
| 213 | |
| 214 static void mxf_write_local_tag(ByteIOContext *pb, int value_size, int tag) | |
| 215 { | |
| 216 put_be16(pb, tag); | |
| 217 put_be16(pb, value_size); | |
| 218 } | |
| 219 | |
| 3740 | 220 static void mxf_write_metadata_key(ByteIOContext *pb, unsigned int value) |
| 221 { | |
| 222 put_buffer(pb, header_metadata_key, 13); | |
| 223 put_be24(pb, value); | |
| 224 } | |
| 225 | |
| 3721 | 226 static void mxf_free(AVFormatContext *s) |
| 227 { | |
| 228 AVStream *st; | |
| 229 int i; | |
| 230 | |
| 231 for (i = 0; i < s->nb_streams; i++) { | |
| 232 st = s->streams[i]; | |
| 233 av_freep(&st->priv_data); | |
| 234 } | |
| 235 } | |
| 236 | |
| 237 static const MXFDataDefinitionUL *mxf_get_data_definition_ul(enum CodecType type) | |
| 238 { | |
| 3735 | 239 const MXFDataDefinitionUL *uls = ff_mxf_data_definition_uls; |
| 3721 | 240 while (uls->type != CODEC_TYPE_DATA) { |
| 241 if (type == uls->type) | |
| 242 break; | |
| 243 uls ++; | |
| 244 } | |
| 245 return uls; | |
| 246 } | |
| 247 | |
|
3780
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
248 static int mxf_write_essence_container_refs(AVFormatContext *s, int write) |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
249 { |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
250 ByteIOContext *pb = s->pb; |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
251 AVStream *st; |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
252 int i, count = 0, j = 0; |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
253 const MXFCodecUL *codec_ul; |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
254 int essence_container_ul_sign[sizeof(ff_mxf_essence_container_uls) / sizeof(MXFCodecUL)] = { 0 }; |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
255 |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
256 for (codec_ul = ff_mxf_essence_container_uls; codec_ul->id; codec_ul++) { |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
257 for (i = 0; i < s->nb_streams; i++) { |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
258 st = s->streams[i]; |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
259 if (st->codec->codec_id == codec_ul->id) { |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
260 essence_container_ul_sign[count] = j; |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
261 count++; |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
262 break; |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
263 } |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
264 } |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
265 j++; |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
266 // considering WAV/AES3 frame wrapped, when get the first CODEC_ID_PCM_S16LE, break; |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
267 // this is a temporary method, when we can get more information, modofy this. |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
268 if (codec_ul->id == CODEC_ID_PCM_S16LE) |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
269 break; |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
270 } |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
271 |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
272 if (write) { |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
273 mxf_write_refs_count(pb, count); |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
274 for (i = 0; i < count; i++) { |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
275 put_buffer(pb, ff_mxf_essence_container_uls[essence_container_ul_sign[i]].uid, 16); |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
276 } |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
277 av_log(s,AV_LOG_DEBUG, "essence container count:%d\n", count); |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
278 for (i = 0; i < count; i++) |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
279 PRINT_KEY(s, "essence container ul:\n", ff_mxf_essence_container_uls[essence_container_ul_sign[i]].uid); |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
280 } |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
281 return count; |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
282 } |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
283 |
| 3749 | 284 static void mxf_write_preface(AVFormatContext *s) |
| 285 { | |
| 286 MXFContext *mxf = s->priv_data; | |
| 287 ByteIOContext *pb = s->pb; | |
| 288 | |
| 289 mxf_write_metadata_key(pb, 0x012f00); | |
| 290 PRINT_KEY(s, "preface key", pb->buf_ptr - 16); | |
| 291 klv_encode_ber_length(pb, 130 + 16 * mxf->essence_container_count); | |
| 292 | |
| 293 // write preface set uid | |
| 294 mxf_write_local_tag(pb, 16, 0x3C0A); | |
| 295 mxf_write_uuid(pb, Preface, 0); | |
| 296 PRINT_KEY(s, "preface uid", pb->buf_ptr - 16); | |
| 297 | |
| 298 // write create date as unknown | |
| 299 mxf_write_local_tag(pb, 8, 0x3B02); | |
| 300 put_be64(pb, 0); | |
| 301 | |
| 302 // write version | |
| 303 mxf_write_local_tag(pb, 2, 0x3B05); | |
| 304 put_be16(pb, 1); | |
| 305 | |
| 306 // write identification_refs | |
| 307 mxf_write_local_tag(pb, 16 + 8, 0x3B06); | |
| 308 mxf_write_refs_count(pb, 1); | |
| 309 mxf_write_uuid(pb, Identification, 0); | |
| 310 | |
| 311 // write content_storage_refs | |
| 312 mxf_write_local_tag(pb, 16, 0x3B03); | |
| 313 mxf_write_uuid(pb, ContentStorage, 0); | |
| 314 | |
| 315 mxf_write_local_tag(pb, 16, 0x3B09); | |
| 316 put_buffer(pb, op1a_ul, 16); | |
| 317 | |
| 318 // write essence_container_refs | |
| 319 mxf_write_local_tag(pb, 8 + 16 * mxf->essence_container_count, 0x3B0A); | |
| 320 mxf_write_essence_container_refs(s, 1); | |
| 321 | |
| 322 // write dm_scheme_refs | |
| 323 mxf_write_local_tag(pb, 8, 0x3B0B); | |
| 324 put_be64(pb, 0); | |
| 325 } | |
| 326 | |
| 3804 | 327 /* |
| 328 * Write an ascii string as utf-16 | |
| 329 */ | |
| 330 static void mxf_write_utf16(ByteIOContext *pb, const char *value) | |
| 331 { | |
|
3805
d8a6432c76f3
use strlen and do not write useless trailing 0 according to specs
bcoudurier
parents:
3804
diff
changeset
|
332 int i, size = strlen(value); |
| 3804 | 333 for (i = 0; i < size; i++) |
| 334 put_be16(pb, value[i]); | |
| 335 } | |
| 336 | |
| 3749 | 337 static void mxf_write_identification(AVFormatContext *s) |
| 338 { | |
| 339 ByteIOContext *pb = s->pb; | |
| 340 int length, company_name_len, product_name_len, version_string_len; | |
| 341 | |
| 342 mxf_write_metadata_key(pb, 0x013000); | |
| 343 PRINT_KEY(s, "identification key", pb->buf_ptr - 16); | |
|
3805
d8a6432c76f3
use strlen and do not write useless trailing 0 according to specs
bcoudurier
parents:
3804
diff
changeset
|
344 company_name_len = strlen("FFmpeg") * 2; |
|
d8a6432c76f3
use strlen and do not write useless trailing 0 according to specs
bcoudurier
parents:
3804
diff
changeset
|
345 product_name_len = strlen("OP1a Muxer") * 2; |
| 3749 | 346 |
| 347 length = 80 + company_name_len + product_name_len; | |
| 348 if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) { | |
|
3805
d8a6432c76f3
use strlen and do not write useless trailing 0 according to specs
bcoudurier
parents:
3804
diff
changeset
|
349 version_string_len = strlen(LIBAVFORMAT_IDENT) * 2; |
| 3749 | 350 length += 4 + version_string_len; |
| 351 } | |
| 352 klv_encode_ber_length(pb, length); | |
| 353 | |
| 354 // write uid | |
| 355 mxf_write_local_tag(pb, 16, 0x3C0A); | |
| 356 mxf_write_uuid(pb, Identification, 0); | |
| 357 PRINT_KEY(s, "identification uid", pb->buf_ptr - 16); | |
| 358 // write generation uid | |
| 359 mxf_write_local_tag(pb, 16, 0x3C09); | |
| 360 mxf_write_uuid(pb, Identification, 1); | |
| 361 | |
| 362 mxf_write_local_tag(pb, company_name_len, 0x3C01); | |
| 3804 | 363 mxf_write_utf16(pb, "FFmpeg"); |
| 3749 | 364 |
| 365 mxf_write_local_tag(pb, product_name_len, 0x3C02); | |
| 3804 | 366 mxf_write_utf16(pb, "OP1a Muxer"); |
| 3749 | 367 |
| 368 if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) { | |
| 369 mxf_write_local_tag(pb, version_string_len, 0x3C04); | |
| 3804 | 370 mxf_write_utf16(pb, LIBAVFORMAT_IDENT); |
| 3749 | 371 } |
| 372 | |
| 373 // write product uid | |
| 374 mxf_write_local_tag(pb, 16, 0x3C05); | |
| 375 mxf_write_uuid(pb, Identification, 2); | |
| 376 | |
| 377 // write modified date | |
| 378 mxf_write_local_tag(pb, 8, 0x3C06); | |
| 379 put_be64(pb, 0); | |
| 380 } | |
| 381 | |
| 382 static void mxf_write_content_storage(AVFormatContext *s) | |
| 383 { | |
| 384 ByteIOContext *pb = s->pb; | |
| 385 | |
| 386 mxf_write_metadata_key(pb, 0x011800); | |
| 387 PRINT_KEY(s, "content storage key", pb->buf_ptr - 16); | |
| 388 klv_encode_ber_length(pb, 64); | |
| 389 | |
| 390 // write uid | |
| 391 mxf_write_local_tag(pb, 16, 0x3C0A); | |
| 392 mxf_write_uuid(pb, ContentStorage, 0); | |
| 393 PRINT_KEY(s, "content storage uid", pb->buf_ptr - 16); | |
| 394 // write package reference | |
| 395 mxf_write_local_tag(pb, 16 * 2 + 8, 0x1901); | |
| 396 mxf_write_refs_count(pb, 2); | |
| 397 mxf_write_uuid(pb, MaterialPackage, 0); | |
| 398 mxf_write_uuid(pb, SourcePackage, 0); | |
| 399 } | |
| 400 | |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
401 static void mxf_write_package(AVFormatContext *s, enum MXFMetadataSetType type) |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
402 { |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
403 ByteIOContext *pb = s->pb; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
404 int i; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
405 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
406 if (type == MaterialPackage) { |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
407 mxf_write_metadata_key(pb, 0x013600); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
408 PRINT_KEY(s, "Material Package key", pb->buf_ptr - 16); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
409 klv_encode_ber_length(pb, 92 + 16 * s->nb_streams); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
410 } |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
411 else { |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
412 mxf_write_metadata_key(pb, 0x013700); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
413 PRINT_KEY(s, "Source Package key", pb->buf_ptr - 16); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
414 klv_encode_ber_length(pb, 112 + 16 * s->nb_streams); // 20 bytes length for descriptor reference |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
415 } |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
416 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
417 // write uid |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
418 mxf_write_local_tag(pb, 16, 0x3C0A); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
419 mxf_write_uuid(pb, type, 0); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
420 av_log(s,AV_LOG_DEBUG, "package type:%d\n", type); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
421 PRINT_KEY(s, "package uid", pb->buf_ptr - 16); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
422 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
423 // write package umid |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
424 mxf_write_local_tag(pb, 32, 0x4401); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
425 mxf_write_umid(pb, type, 0); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
426 PRINT_KEY(s, "package umid second part", pb->buf_ptr - 16); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
427 // write create date |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
428 mxf_write_local_tag(pb, 8, 0x4405); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
429 put_be64(pb, 0); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
430 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
431 // write modified date |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
432 mxf_write_local_tag(pb, 8, 0x4404); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
433 put_be64(pb, 0); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
434 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
435 // write track refs |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
436 mxf_write_local_tag(pb, s->nb_streams * 16 + 8, 0x4403); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
437 mxf_write_refs_count(pb, s->nb_streams); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
438 for (i = 0; i < s->nb_streams; i++) |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
439 mxf_write_uuid(pb, type == MaterialPackage ? Track : Track + TypeBottom, i); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
440 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
441 if (type == SourcePackage) { |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
442 // write multiple descriptor reference |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
443 mxf_write_local_tag(pb, 16, 0x4701); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
444 mxf_write_uuid(pb, MultipleDescriptor, 0); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
445 } |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
446 } |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
447 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
448 static void mxf_write_track(AVFormatContext *s, int stream_index, enum MXFMetadataSetType type, int *track_number_sign) |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
449 { |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
450 ByteIOContext *pb = s->pb; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
451 AVStream *st; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
452 MXFStreamContext *sc; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
453 const MXFCodecUL *element; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
454 int i = 0; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
455 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
456 mxf_write_metadata_key(pb, 0x013b00); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
457 PRINT_KEY(s, "track key", pb->buf_ptr - 16); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
458 klv_encode_ber_length(pb, 80); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
459 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
460 st = s->streams[stream_index]; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
461 sc = st->priv_data; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
462 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
463 // write track uid |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
464 mxf_write_local_tag(pb, 16, 0x3C0A); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
465 mxf_write_uuid(pb, type == MaterialPackage ? Track : Track + TypeBottom, stream_index); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
466 PRINT_KEY(s, "track uid", pb->buf_ptr - 16); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
467 // write track id |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
468 mxf_write_local_tag(pb, 4, 0x4801); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
469 put_be32(pb, stream_index); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
470 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
471 mxf_write_local_tag(pb, 4, 0x4804); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
472 if (type != MaterialPackage) { |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
473 for (element = mxf_essence_element_key; element->id != CODEC_ID_NONE; element++) { |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
474 if (st->codec->codec_id== element->id) { |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
475 // set essence_element key |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
476 memcpy(sc->track_essence_element_key, element->uid, 16); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
477 sc->track_essence_element_key[15] += track_number_sign[i]; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
478 // write track number |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
479 put_buffer(pb, sc->track_essence_element_key + 12, 4); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
480 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
481 track_number_sign[i] ++; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
482 break; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
483 } |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
484 i++; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
485 } |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
486 } else { |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
487 put_be32(pb, 0); // track number of material package is 0 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
488 } |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
489 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
490 mxf_write_local_tag(pb, 8, 0x4B01); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
491 put_be32(pb, st->time_base.den); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
492 put_be32(pb, st->time_base.num); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
493 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
494 // write origin |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
495 mxf_write_local_tag(pb, 8, 0x4B02); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
496 put_be64(pb, 0); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
497 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
498 // write sequence refs |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
499 mxf_write_local_tag(pb, 16, 0x4803); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
500 mxf_write_uuid(pb, type == MaterialPackage ? Sequence: Sequence + TypeBottom, stream_index); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
501 } |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
502 |
| 3743 | 503 static void mxf_write_common_fields( ByteIOContext *pb, AVStream *st) |
| 504 { | |
| 505 const MXFDataDefinitionUL * data_def_ul; | |
| 506 | |
| 507 // find data define uls | |
| 508 data_def_ul = mxf_get_data_definition_ul(st->codec->codec_type); | |
| 509 mxf_write_local_tag(pb, 16, 0x0201); | |
| 510 put_buffer(pb, data_def_ul->uid, 16); | |
| 511 | |
| 512 // write duration | |
| 513 mxf_write_local_tag(pb, 8, 0x0202); | |
| 514 put_be64(pb, st->duration); | |
| 515 } | |
| 516 | |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
517 static void mxf_write_sequence(AVFormatContext *s, int stream_index, enum MXFMetadataSetType type) |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
518 { |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
519 ByteIOContext *pb = s->pb; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
520 AVStream *st; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
521 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
522 mxf_write_metadata_key(pb, 0x010f00); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
523 PRINT_KEY(s, "sequence key", pb->buf_ptr - 16); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
524 klv_encode_ber_length(pb, 80); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
525 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
526 st = s->streams[stream_index]; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
527 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
528 mxf_write_local_tag(pb, 16, 0x3C0A); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
529 mxf_write_uuid(pb, type == MaterialPackage ? Sequence: Sequence + TypeBottom, stream_index); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
530 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
531 PRINT_KEY(s, "sequence uid", pb->buf_ptr - 16); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
532 mxf_write_common_fields(pb, st); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
533 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
534 // write structural component |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
535 mxf_write_local_tag(pb, 16 + 8, 0x1001); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
536 mxf_write_refs_count(pb, 1); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
537 mxf_write_uuid(pb, type == MaterialPackage ? SourceClip: SourceClip + TypeBottom, stream_index); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
538 } |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
539 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
540 static void mxf_write_structural_component(AVFormatContext *s, int stream_index, enum MXFMetadataSetType type) |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
541 { |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
542 ByteIOContext *pb = s->pb; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
543 AVStream *st; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
544 int i; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
545 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
546 mxf_write_metadata_key(pb, 0x011100); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
547 PRINT_KEY(s, "sturctural component key", pb->buf_ptr - 16); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
548 klv_encode_ber_length(pb, 108); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
549 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
550 st = s->streams[stream_index]; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
551 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
552 // write uid |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
553 mxf_write_local_tag(pb, 16, 0x3C0A); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
554 mxf_write_uuid(pb, type == MaterialPackage ? SourceClip: SourceClip + TypeBottom, stream_index); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
555 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
556 PRINT_KEY(s, "structural component uid", pb->buf_ptr - 16); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
557 mxf_write_common_fields(pb, st); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
558 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
559 // write start_position |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
560 mxf_write_local_tag(pb, 8, 0x1201); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
561 put_be64(pb, 0); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
562 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
563 mxf_write_local_tag(pb, 32, 0x1101); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
564 if (type == SourcePackage) { |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
565 // write source package uid, end of the reference |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
566 for (i = 0; i < 4; i++) { |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
567 put_be64(pb, 0); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
568 } |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
569 } else |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
570 mxf_write_umid(pb, SourcePackage, 0); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
571 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
572 mxf_write_local_tag(pb, 4, 0x1102); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
573 if (type == SourcePackage) |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
574 // write source track id |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
575 put_be32(pb, 0); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
576 else |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
577 put_be32(pb, stream_index); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
578 } |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
579 |
| 3749 | 580 static void mxf_write_multi_descriptor(AVFormatContext *s) |
| 581 { | |
| 582 ByteIOContext *pb = s->pb; | |
| 583 int i; | |
| 584 | |
| 585 mxf_write_metadata_key(pb, 0x014400); | |
| 586 PRINT_KEY(s, "multiple descriptor key", pb->buf_ptr - 16); | |
| 587 klv_encode_ber_length(pb, 64 + 16 * s->nb_streams); | |
| 588 | |
| 589 mxf_write_local_tag(pb, 16, 0x3C0A); | |
| 590 mxf_write_uuid(pb, MultipleDescriptor, 0); | |
| 591 PRINT_KEY(s, "multi_desc uid", pb->buf_ptr - 16); | |
| 592 | |
| 593 // write sample rate | |
| 594 mxf_write_local_tag(pb, 8, 0x3001); | |
| 595 put_be32(pb, s->streams[0]->time_base.den); | |
| 596 put_be32(pb, s->streams[0]->time_base.num); | |
| 597 | |
| 598 // write essence container ul | |
| 599 mxf_write_local_tag(pb, 16, 0x3004); | |
| 600 put_buffer(pb, multiple_desc_ul, 16); | |
| 601 | |
| 602 // write sub descriptor refs | |
| 603 mxf_write_local_tag(pb, s->nb_streams * 16 + 8, 0x3F01); | |
| 604 mxf_write_refs_count(pb, s->nb_streams); | |
| 605 for (i = 0; i < s->nb_streams; i++) { | |
| 606 mxf_write_uuid(pb, SubDescriptor, i); | |
| 607 } | |
| 608 } | |
| 609 | |
| 3743 | 610 static void mxf_write_header_desc(ByteIOContext *pb, const MXFDescriptorWriteTableEntry *desc_tbl, AVStream *st) |
| 611 { | |
| 612 const MXFCodecUL *codec_ul; | |
| 613 | |
| 614 put_buffer(pb, desc_tbl->key, 16); | |
| 3749 | 615 klv_encode_ber_length(pb, 108); |
| 3743 | 616 |
| 617 mxf_write_local_tag(pb, 16, 0x3C0A); | |
| 618 mxf_write_uuid(pb, SubDescriptor, st->index); | |
| 619 | |
| 620 mxf_write_local_tag(pb, 4, 0x3006); | |
| 621 put_be32(pb, st->index); | |
| 622 | |
| 3749 | 623 mxf_write_local_tag(pb, 8, 0x3001); |
| 624 put_be32(pb, st->time_base.den); | |
| 625 put_be32(pb, st->time_base.num); | |
| 626 | |
| 3743 | 627 codec_ul = mxf_get_essence_container_ul(st->codec->codec_id); |
| 628 mxf_write_local_tag(pb, 16, 0x3004); | |
| 629 put_buffer(pb, codec_ul->uid, 16); | |
| 630 } | |
| 631 | |
| 3749 | 632 static void mxf_write_mpeg_video_desc(AVFormatContext *s, const MXFDescriptorWriteTableEntry *desc_tbl, int stream_index) |
| 3743 | 633 { |
| 634 ByteIOContext *pb = s->pb; | |
| 635 AVStream *st; | |
| 636 | |
| 637 st = s->streams[stream_index]; | |
| 638 mxf_write_header_desc(pb, desc_tbl, st); | |
| 639 | |
| 640 mxf_write_local_tag(pb, 4, 0x3203); | |
| 641 put_be32(pb, st->codec->width); | |
| 642 | |
| 643 mxf_write_local_tag(pb, 4, 0x3202); | |
| 644 put_be32(pb, st->codec->height); | |
| 645 | |
| 646 mxf_write_local_tag(pb, 8, 0x320E); | |
|
3759
27537074f2a9
convert every muxer/demuxer to write/read sample_aspect_ratio from/to
aurel
parents:
3749
diff
changeset
|
647 put_be32(pb, st->codec->height * st->sample_aspect_ratio.den); |
|
27537074f2a9
convert every muxer/demuxer to write/read sample_aspect_ratio from/to
aurel
parents:
3749
diff
changeset
|
648 put_be32(pb, st->codec->width * st->sample_aspect_ratio.num); |
| 3743 | 649 |
| 650 // tmp write, will modified later | |
| 651 mxf_write_local_tag(pb, 16, 0x3201); | |
| 652 put_buffer(pb, ff_mxf_codec_uls->uid, 16); | |
| 653 } | |
| 654 | |
| 3749 | 655 static void mxf_write_wav_desc(AVFormatContext *s, const MXFDescriptorWriteTableEntry *desc_tbl, int stream_index) |
| 3743 | 656 { |
| 657 ByteIOContext *pb = s->pb; | |
| 658 AVStream *st; | |
| 659 | |
| 660 st = s->streams[stream_index]; | |
| 661 mxf_write_header_desc(pb, desc_tbl, st); | |
| 662 | |
| 663 // write audio sampling rate | |
| 664 mxf_write_local_tag(pb, 8, 0x3D03); | |
| 665 put_be32(pb, st->codec->sample_rate); | |
| 666 put_be32(pb, 1); | |
| 667 | |
| 668 mxf_write_local_tag(pb, 4, 0x3D07); | |
| 669 put_be32(pb, st->codec->channels); | |
| 670 | |
| 671 mxf_write_local_tag(pb, 4, 0x3D01); | |
| 672 put_be32(pb, st->codec->bits_per_sample); | |
| 673 | |
| 674 // tmp write, will modified later | |
| 675 mxf_write_local_tag(pb, 16, 0x3201); | |
| 676 put_buffer(pb, (ff_mxf_codec_uls + 8) ->uid, 16); | |
| 677 } | |
| 678 | |
| 679 static const MXFDescriptorWriteTableEntry mxf_descriptor_write_table[] = { | |
| 680 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 }, mxf_write_mpeg_video_desc, CODEC_ID_MPEG2VIDEO}, | |
| 681 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 }, mxf_write_wav_desc, CODEC_ID_PCM_S16LE}, | |
| 682 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, NULL, CODEC_ID_NONE}, | |
| 683 }; | |
| 684 | |
| 3749 | 685 static void mxf_build_structural_metadata(AVFormatContext *s, enum MXFMetadataSetType type) |
| 3743 | 686 { |
| 687 int i; | |
| 688 const MXFDescriptorWriteTableEntry *desc = NULL; | |
| 689 int track_number_sign[sizeof(mxf_essence_element_key)/sizeof(MXFCodecUL)] = { 0 }; | |
| 690 | |
| 3749 | 691 mxf_write_package(s, type); |
| 692 if (type == SourcePackage) | |
| 693 mxf_write_multi_descriptor(s); | |
| 3743 | 694 |
| 695 for (i = 0;i < s->nb_streams; i++) { | |
| 3749 | 696 mxf_write_track(s, i, type, track_number_sign); |
| 697 mxf_write_sequence(s, i, type); | |
| 698 mxf_write_structural_component(s, i, type); | |
| 3743 | 699 |
| 700 if (type == SourcePackage) { | |
| 701 for (desc = mxf_descriptor_write_table; desc->write; desc++) { | |
| 702 if (s->streams[i]->codec->codec_id == desc->type) { | |
| 3749 | 703 desc->write(s, desc, i); |
| 3743 | 704 break; |
| 705 } | |
| 706 } | |
| 707 } | |
| 708 } | |
| 709 } | |
| 710 | |
| 3740 | 711 static int mxf_write_header_metadata_sets(AVFormatContext *s) |
| 712 { | |
| 713 AVStream *st; | |
| 714 MXFStreamContext *sc = NULL; | |
| 715 int i; | |
| 3749 | 716 mxf_write_preface(s); |
| 3740 | 717 |
| 3749 | 718 mxf_write_identification(s); |
| 3740 | 719 |
| 3749 | 720 mxf_write_content_storage(s); |
| 3740 | 721 |
| 722 for (i = 0; i < s->nb_streams; i++) { | |
| 723 st = s->streams[i]; | |
| 724 sc = av_mallocz(sizeof(MXFStreamContext)); | |
| 725 if (!sc) | |
| 726 return AVERROR(ENOMEM); | |
| 727 st->priv_data = sc; | |
| 728 // set pts information | |
| 729 if (st->codec->codec_type == CODEC_TYPE_VIDEO) { | |
| 730 av_set_pts_info(st, 64, 1, st->codec->time_base.den); | |
| 731 } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) { | |
| 732 av_set_pts_info(st, 64, 1, st->codec->sample_rate); | |
| 733 } | |
| 734 } | |
| 735 | |
| 3749 | 736 mxf_build_structural_metadata(s, MaterialPackage); |
| 737 mxf_build_structural_metadata(s, SourcePackage); | |
| 3740 | 738 return 0; |
| 739 } | |
| 740 | |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
741 static void mxf_write_partition(AVFormatContext *s, int64_t byte_position, int bodysid, const uint8_t *key) |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
742 { |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
743 MXFContext *mxf = s->priv_data; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
744 ByteIOContext *pb = s->pb; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
745 // write klv |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
746 put_buffer(pb, key, 16); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
747 if (!mxf->essence_container_count) |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
748 mxf->essence_container_count = mxf_write_essence_container_refs(s, 0); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
749 klv_encode_ber_length(pb, 88 + 16 * mxf->essence_container_count); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
750 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
751 // write partition value |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
752 put_be16(pb, 1); // majorVersion |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
753 put_be16(pb, 2); // minorVersion |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
754 put_be32(pb, 1); // kagSize |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
755 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
756 put_be64(pb, byte_position); // thisPartition |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
757 put_be64(pb, 0); // previousPartition |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
758 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
759 // set offset |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
760 if (!byte_position) |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
761 mxf->header_footer_partition_offset = url_ftell(pb); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
762 put_be64(pb, byte_position); // footerPartition,update later |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
763 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
764 // set offset |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
765 if (!byte_position) |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
766 mxf->header_byte_count_offset = url_ftell(pb); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
767 put_be64(pb, 0); // headerByteCount, update later |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
768 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
769 // no indexTable |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
770 put_be64(pb, 0); // indexByteCount |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
771 put_be32(pb, 0); // indexSID |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
772 put_be64(pb, 0); // bodyOffset |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
773 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
774 put_be32(pb, bodysid); // bodySID |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
775 put_buffer(pb, op1a_ul, 16); // operational pattern |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
776 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
777 // essence container |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
778 mxf_write_essence_container_refs(s, 1); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
779 } |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
780 |
| 3749 | 781 static int mux_write_header(AVFormatContext *s) |
| 782 { | |
| 783 MXFContext *mxf = s->priv_data; | |
| 784 ByteIOContext *pb = s->pb; | |
| 785 int64_t header_metadata_start, offset_now; | |
| 786 | |
| 787 mxf_write_partition(s, 0, 1, header_partition_key); | |
| 788 | |
| 789 // mark the start of the headermetadata and calculate metadata size | |
| 790 header_metadata_start = url_ftell(s->pb); | |
| 791 mxf_write_primer_pack(s); | |
| 792 if (mxf_write_header_metadata_sets(s) < 0) | |
| 793 goto fail; | |
| 794 offset_now = url_ftell(s->pb); | |
| 795 mxf->header_byte_count = offset_now - header_metadata_start; | |
| 796 // update header_byte_count | |
| 797 url_fseek(pb, mxf->header_byte_count_offset, SEEK_SET); | |
| 798 put_be64(pb, mxf->header_byte_count); | |
| 799 url_fseek(pb, offset_now, SEEK_SET); | |
| 800 | |
| 801 put_flush_packet(pb); | |
| 802 return 0; | |
| 803 fail: | |
| 804 mxf_free(s); | |
| 805 return -1; | |
| 806 } | |
| 807 | |
| 3778 | 808 static int mux_write_packet(AVFormatContext *s, AVPacket *pkt) |
| 809 { | |
| 810 ByteIOContext *pb = s->pb; | |
| 811 AVStream *st = s->streams[pkt->stream_index]; | |
| 812 MXFStreamContext *sc = st->priv_data; | |
| 813 | |
| 814 put_buffer(pb, sc->track_essence_element_key, 16); // write key | |
| 815 klv_encode_ber_length(pb, pkt->size); // write length | |
| 816 put_buffer(pb, pkt->data, pkt->size); // write value | |
| 817 | |
| 818 put_flush_packet(pb); | |
| 819 return 0; | |
| 820 } | |
| 821 | |
| 3749 | 822 static void mxf_update_header_partition(AVFormatContext *s, int64_t footer_partition_offset) |
| 3740 | 823 { |
| 824 MXFContext *mxf = s->priv_data; | |
| 825 ByteIOContext *pb = s->pb; | |
| 826 | |
| 827 url_fseek(pb, mxf->header_footer_partition_offset, SEEK_SET); | |
| 828 put_be64(pb, footer_partition_offset); | |
| 829 put_flush_packet(pb); | |
| 3749 | 830 } |
| 831 | |
| 832 | |
| 833 static int mux_write_footer(AVFormatContext *s) | |
| 834 { | |
| 835 ByteIOContext *pb = s->pb; | |
| 836 | |
| 837 int64_t byte_position= url_ftell(pb); | |
| 838 if (!url_is_streamed(s->pb)) { | |
| 839 mxf_write_partition(s, byte_position, 0, footer_partition_key); | |
| 840 | |
| 841 put_flush_packet(pb); | |
| 842 | |
| 843 mxf_update_header_partition(s, byte_position); | |
| 844 } | |
| 845 mxf_free(s); | |
| 3740 | 846 return 0; |
| 847 } | |
| 3749 | 848 |
| 3721 | 849 AVOutputFormat mxf_muxer = { |
| 850 "mxf", | |
| 851 NULL_IF_CONFIG_SMALL("Material eXchange Format"), | |
| 852 NULL, | |
| 853 "mxf", | |
| 854 sizeof(MXFContext), | |
| 855 CODEC_ID_PCM_S16LE, | |
| 856 CODEC_ID_MPEG2VIDEO, | |
| 857 mux_write_header, | |
| 858 mux_write_packet, | |
| 859 mux_write_footer, | |
| 860 }; | |
| 3749 | 861 |
| 862 |
