comparison mxfenc.c @ 3740:b31821aa2235 libavformat

Ok-ed parts from patch by zhentan feng.
author cehoyos
date Tue, 19 Aug 2008 12:36:17 +0000
parents 75fd6b0b1356
children 68414dc4c4d1
comparison
equal deleted inserted replaced
3739:d7fa8d9effe5 3740:b31821aa2235
36 typedef struct { 36 typedef struct {
37 int local_tag; 37 int local_tag;
38 UID uid; 38 UID uid;
39 } MXFLocalTagPair; 39 } MXFLocalTagPair;
40 40
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;
41 static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd }; 51 static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd };
42 static const uint8_t umid_base[] = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x0F,0x00,0x13,0x00,0x00,0x00 }; 52 static const uint8_t umid_base[] = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x0F,0x00,0x13,0x00,0x00,0x00 };
43 53
44 /** 54 /**
45 * complete key for operation pattern, partitions, and primer pack 55 * complete key for operation pattern, partitions, and primer pack
54 put_buffer(pb, uuid_base, 12); 64 put_buffer(pb, uuid_base, 12);
55 put_be16(pb, type); 65 put_be16(pb, type);
56 put_be16(pb, value); 66 put_be16(pb, value);
57 } 67 }
58 68
69 static void mxf_write_umid(ByteIOContext *pb, enum CodecID type, int value)
70 {
71 put_buffer(pb, umid_base, 16);
72 mxf_write_uuid(pb, type, value);
73 }
59 static int klv_encode_ber_length(ByteIOContext *pb, uint64_t len) 74 static int klv_encode_ber_length(ByteIOContext *pb, uint64_t len)
60 { 75 {
61 // Determine the best BER size 76 // Determine the best BER size
62 int size; 77 int size;
63 if (len < 128) { 78 if (len < 128) {
112 { 127 {
113 put_be16(pb, tag); 128 put_be16(pb, tag);
114 put_be16(pb, value_size); 129 put_be16(pb, value_size);
115 } 130 }
116 131
132 static void mxf_write_metadata_key(ByteIOContext *pb, unsigned int value)
133 {
134 put_buffer(pb, header_metadata_key, 13);
135 put_be24(pb, value);
136 }
137
117 static void mxf_free(AVFormatContext *s) 138 static void mxf_free(AVFormatContext *s)
118 { 139 {
119 MXFContext *mxf = s->priv_data;
120 AVStream *st; 140 AVStream *st;
121 int i; 141 int i;
122 142
123 for (i = 0; i < s->nb_streams; i++) { 143 for (i = 0; i < s->nb_streams; i++) {
124 st = s->streams[i]; 144 st = s->streams[i];
125 av_freep(&st->priv_data); 145 av_freep(&st->priv_data);
126 } 146 }
127 av_freep(&mxf->essence_container_uls);
128 } 147 }
129 148
130 static const MXFDataDefinitionUL *mxf_get_data_definition_ul(enum CodecType type) 149 static const MXFDataDefinitionUL *mxf_get_data_definition_ul(enum CodecType type)
131 { 150 {
132 const MXFDataDefinitionUL *uls = ff_mxf_data_definition_uls; 151 const MXFDataDefinitionUL *uls = ff_mxf_data_definition_uls;
150 169
151 put_flush_packet(pb); 170 put_flush_packet(pb);
152 return 0; 171 return 0;
153 } 172 }
154 173
174 static int mxf_write_header_metadata_sets(AVFormatContext *s)
175 {
176 AVStream *st;
177 MXFStreamContext *sc = NULL;
178 int i;
179 if (mxf_write_preface(s) < 0)
180 return -1;
181
182 if (mxf_write_identification(s) < 0)
183 return -1;
184
185 if (mxf_write_content_storage(s) < 0)
186 return -1;
187
188 for (i = 0; i < s->nb_streams; i++) {
189 st = s->streams[i];
190 sc = av_mallocz(sizeof(MXFStreamContext));
191 if (!sc)
192 return AVERROR(ENOMEM);
193 st->priv_data = sc;
194 // set pts information
195 if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
196 av_set_pts_info(st, 64, 1, st->codec->time_base.den);
197 } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
198 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
199 }
200 }
201
202 if (mxf_build_structural_metadata(s, MaterialPackage) < 0)
203 return -1;
204
205 if (mxf_build_structural_metadata(s, SourcePackage) < 0)
206 return -1;
207 return 0;
208 }
209
210 static int mxf_update_header_partition(AVFormatContext *s, int64_t footer_partition_offset)
211 {
212 MXFContext *mxf = s->priv_data;
213 ByteIOContext *pb = s->pb;
214
215 url_fseek(pb, mxf->header_byte_count_offset, SEEK_SET);
216 put_be64(pb, mxf->header_byte_count);
217 put_flush_packet(pb);
218
219 url_fseek(pb, mxf->header_footer_partition_offset, SEEK_SET);
220 put_be64(pb, footer_partition_offset);
221 put_flush_packet(pb);
222 return 0;
223 }
155 AVOutputFormat mxf_muxer = { 224 AVOutputFormat mxf_muxer = {
156 "mxf", 225 "mxf",
157 NULL_IF_CONFIG_SMALL("Material eXchange Format"), 226 NULL_IF_CONFIG_SMALL("Material eXchange Format"),
158 NULL, 227 NULL,
159 "mxf", 228 "mxf",