annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
1 /*
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
2 * MXF muxer
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
3 * Copyright (c) 2008 GUCAS, Zhentan Feng <spyfeng at gmail dot com>
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
4 *
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
5 * This file is part of FFmpeg.
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
6 *
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
11 *
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
15 * Lesser General Public License for more details.
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
16 *
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
20 */
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
21
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
22 /*
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
23 * References
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
24 * SMPTE 336M KLV Data Encoding Protocol Using Key-Length-Value
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
25 * SMPTE 377M MXF File Format Specifications
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
26 * SMPTE 379M MXF Generic Container
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
27 * SMPTE 381M Mapping MPEG Streams into the MXF Generic Container
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
28 * SMPTE RP210: SMPTE Metadata Dictionary
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
29 * SMPTE RP224: Registry of SMPTE Universal Labels
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
30 */
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
31
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
32 //#define DEBUG
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
33
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
34 #include "mxf.h"
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
35
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
36 typedef struct {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
37 int local_tag;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
38 UID uid;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
39 } MXFLocalTagPair;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
40
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
41 typedef struct {
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
42 UID track_essence_element_key;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
43 } MXFStreamContext;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
44
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
45 typedef struct MXFContext {
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
46 int64_t header_byte_count;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
47 int64_t header_byte_count_offset;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
48 int64_t header_footer_partition_offset;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
49 int essence_container_count;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
50 } MXFContext;
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
51 static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd };
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
52 static const uint8_t umid_base[] = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x0F,0x00,0x13,0x00,0x00,0x00 };
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
53
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
54 /**
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
55 * complete key for operation pattern, partitions, and primer pack
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
56 */
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
57 static const uint8_t op1a_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x01,0x01,0x00 };
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
58 static const uint8_t header_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x02,0x04,0x00 }; // ClosedComplete
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
59 static const uint8_t footer_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x04,0x04,0x00 }; // ClosedComplete
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
60 static const uint8_t primer_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x05,0x01,0x00 };
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
61
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
62 static void mxf_write_uuid(ByteIOContext *pb, enum CodecID type, int value)
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
63 {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
64 put_buffer(pb, uuid_base, 12);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
65 put_be16(pb, type);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
66 put_be16(pb, value);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
67 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
68
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
69 static void mxf_write_umid(ByteIOContext *pb, enum CodecID type, int value)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
70 {
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
71 put_buffer(pb, umid_base, 16);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
72 mxf_write_uuid(pb, type, value);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
73 }
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
74 static int klv_encode_ber_length(ByteIOContext *pb, uint64_t len)
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
75 {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
76 // Determine the best BER size
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
77 int size;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
78 if (len < 128) {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
79 //short form
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
80 put_byte(pb, len);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
81 return 1;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
82 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
83
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
84 size = (av_log2(len) >> 3) + 1;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
85
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
86 // long form
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
87 put_byte(pb, 0x80 + size);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
88 while(size) {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
89 size --;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
90 put_byte(pb, len >> 8 * size & 0xff);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
91 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
92 return 0;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
93 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
94
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
95 static const MXFCodecUL *mxf_get_essence_container_ul(enum CodecID type)
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
96 {
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
97 const MXFCodecUL *uls = ff_mxf_essence_container_uls;
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
98 while (uls->id != CODEC_ID_NONE) {
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
99 if (uls->id == type)
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
100 break;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
101 uls++;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
102 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
103 return uls;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
104 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
105
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
106 static int mxf_write_primer_pack(AVFormatContext *s)
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
107 {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
108 ByteIOContext *pb = s->pb;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
109 int local_tag_number, i = 0;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
110
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
111 local_tag_number = sizeof(mxf_local_tag_batch) / sizeof(MXFLocalTagPair);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
112
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
113 put_buffer(pb, primer_pack_key, 16);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
114 klv_encode_ber_length(pb, local_tag_number * 18 + 8);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
115
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
116 put_be32(pb, local_tag_number); // local_tag num
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
117 put_be32(pb, 18); // item size, always 18 according to the specs
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
118
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
119 for (i = 0; i < local_tag_number; i++) {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
120 put_be16(pb, mxf_local_tag_batch[i].local_tag);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
121 put_buffer(pb, mxf_local_tag_batch[i].uid, 16);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
122 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
123 return 0;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
124 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
125
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
126 static void mxf_write_local_tag(ByteIOContext *pb, int value_size, int tag)
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
127 {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
128 put_be16(pb, tag);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
129 put_be16(pb, value_size);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
130 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
131
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
132 static void mxf_write_metadata_key(ByteIOContext *pb, unsigned int value)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
133 {
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
134 put_buffer(pb, header_metadata_key, 13);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
135 put_be24(pb, value);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
136 }
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
137
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
138 static void mxf_free(AVFormatContext *s)
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
139 {
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
140 AVStream *st;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
141 int i;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
142
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
143 for (i = 0; i < s->nb_streams; i++) {
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
144 st = s->streams[i];
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
145 av_freep(&st->priv_data);
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
146 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
147 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
148
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
149 static const MXFDataDefinitionUL *mxf_get_data_definition_ul(enum CodecType type)
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
150 {
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
151 const MXFDataDefinitionUL *uls = ff_mxf_data_definition_uls;
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
152 while (uls->type != CODEC_TYPE_DATA) {
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
153 if (type == uls->type)
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
154 break;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
155 uls ++;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
156 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
157 return uls;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
158 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
159
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
160 static int mux_write_packet(AVFormatContext *s, AVPacket *pkt)
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
161 {
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
162 ByteIOContext *pb = s->pb;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
163 AVStream *st = s->streams[pkt->stream_index];
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
164 MXFStreamContext *sc = st->priv_data;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
165
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
166 put_buffer(pb, sc->track_essence_element_key, 16); // write key
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
167 klv_encode_ber_length(pb, pkt->size); // write length
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
168 put_buffer(pb, pkt->data, pkt->size); // write value
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
169
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
170 put_flush_packet(pb);
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
171 return 0;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
172 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
173
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
174 static int mxf_write_header_metadata_sets(AVFormatContext *s)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
175 {
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
176 AVStream *st;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
177 MXFStreamContext *sc = NULL;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
178 int i;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
179 if (mxf_write_preface(s) < 0)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
180 return -1;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
181
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
182 if (mxf_write_identification(s) < 0)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
183 return -1;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
184
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
185 if (mxf_write_content_storage(s) < 0)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
186 return -1;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
187
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
188 for (i = 0; i < s->nb_streams; i++) {
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
189 st = s->streams[i];
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
190 sc = av_mallocz(sizeof(MXFStreamContext));
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
191 if (!sc)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
192 return AVERROR(ENOMEM);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
193 st->priv_data = sc;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
194 // set pts information
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
195 if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
196 av_set_pts_info(st, 64, 1, st->codec->time_base.den);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
197 } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
198 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
199 }
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
200 }
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
201
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
202 if (mxf_build_structural_metadata(s, MaterialPackage) < 0)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
203 return -1;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
204
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
205 if (mxf_build_structural_metadata(s, SourcePackage) < 0)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
206 return -1;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
207 return 0;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
208 }
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
209
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
210 static int mxf_update_header_partition(AVFormatContext *s, int64_t footer_partition_offset)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
211 {
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
212 MXFContext *mxf = s->priv_data;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
213 ByteIOContext *pb = s->pb;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
214
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
215 url_fseek(pb, mxf->header_byte_count_offset, SEEK_SET);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
216 put_be64(pb, mxf->header_byte_count);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
217 put_flush_packet(pb);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
218
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
219 url_fseek(pb, mxf->header_footer_partition_offset, SEEK_SET);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
220 put_be64(pb, footer_partition_offset);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
221 put_flush_packet(pb);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
222 return 0;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
223 }
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
224 AVOutputFormat mxf_muxer = {
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
225 "mxf",
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
226 NULL_IF_CONFIG_SMALL("Material eXchange Format"),
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
227 NULL,
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
228 "mxf",
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
229 sizeof(MXFContext),
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
230 CODEC_ID_PCM_S16LE,
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
231 CODEC_ID_MPEG2VIDEO,
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
232 mux_write_header,
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
233 mux_write_packet,
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
234 mux_write_footer,
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
235 };