annotate mxfenc.c @ 3743:68414dc4c4d1 libavformat

Ok-ed parts from patch by zhentan feng.
author cehoyos
date Tue, 19 Aug 2008 22:01:57 +0000
parents b31821aa2235
children 84ad19dea09f
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;
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
51
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
52 typedef struct {
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
53 const UID key;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
54 int (*write)();
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
55 enum CodecType type;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
56 } MXFDescriptorWriteTableEntry;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
57
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
58 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
59 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
60
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 * complete key for operation pattern, partitions, and primer pack
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 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
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
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
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
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
67 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
68
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
69 /**
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
70 * partial key for header metadata
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
71 */
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
72 static const uint8_t header_metadata_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01 };
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
73
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
74 static const MXFCodecUL mxf_essence_element_key[] = {
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
75 { { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 }, 14, CODEC_ID_MPEG2VIDEO},
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
76 { { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x16,0x01,0x01,0x00 }, 14, CODEC_ID_PCM_S16LE},
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
77 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, CODEC_ID_NONE},
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
78 };
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
79
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
80 static const uint8_t multiple_desc_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x0D,0x01,0x03,0x01,0x02,0x7F,0x01,0x00 };
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
81
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
82 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
83 {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
84 put_buffer(pb, uuid_base, 12);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
85 put_be16(pb, type);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
86 put_be16(pb, value);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
87 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
88
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
89 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
90 {
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
91 put_buffer(pb, umid_base, 16);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
92 mxf_write_uuid(pb, type, value);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
93 }
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
94
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
95 static void mxf_write_refs_count(ByteIOContext *pb, int ref_count)
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
96 {
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
97 put_be32(pb, ref_count);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
98 put_be32(pb, 16);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
99 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
100
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
101 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
102 {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
103 // Determine the best BER size
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
104 int size;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
105 if (len < 128) {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
106 //short form
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
107 put_byte(pb, len);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
108 return 1;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
109 }
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 size = (av_log2(len) >> 3) + 1;
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 // long form
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
114 put_byte(pb, 0x80 + size);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
115 while(size) {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
116 size --;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
117 put_byte(pb, len >> 8 * size & 0xff);
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 return 0;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
120 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
121
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
122 static const MXFCodecUL *mxf_get_essence_container_ul(enum CodecID type)
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
123 {
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
124 const MXFCodecUL *uls = ff_mxf_essence_container_uls;
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
125 while (uls->id != CODEC_ID_NONE) {
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
126 if (uls->id == type)
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
127 break;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
128 uls++;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
129 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
130 return uls;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
131 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
132
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
133 static int mxf_write_primer_pack(AVFormatContext *s)
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
134 {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
135 ByteIOContext *pb = s->pb;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
136 int local_tag_number, i = 0;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
137
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
138 local_tag_number = sizeof(mxf_local_tag_batch) / sizeof(MXFLocalTagPair);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
139
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
140 put_buffer(pb, primer_pack_key, 16);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
141 klv_encode_ber_length(pb, local_tag_number * 18 + 8);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
142
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
143 put_be32(pb, local_tag_number); // local_tag num
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
144 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
145
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
146 for (i = 0; i < local_tag_number; i++) {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
147 put_be16(pb, mxf_local_tag_batch[i].local_tag);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
148 put_buffer(pb, mxf_local_tag_batch[i].uid, 16);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
149 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
150 return 0;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
151 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
152
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
153 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
154 {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
155 put_be16(pb, tag);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
156 put_be16(pb, value_size);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
157 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
158
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
159 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
160 {
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
161 put_buffer(pb, header_metadata_key, 13);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
162 put_be24(pb, value);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
163 }
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
164
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
165 static void mxf_free(AVFormatContext *s)
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
166 {
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
167 AVStream *st;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
168 int i;
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 for (i = 0; i < s->nb_streams; i++) {
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
171 st = s->streams[i];
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
172 av_freep(&st->priv_data);
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
173 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
174 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
175
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
176 static const MXFDataDefinitionUL *mxf_get_data_definition_ul(enum CodecType type)
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
177 {
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
178 const MXFDataDefinitionUL *uls = ff_mxf_data_definition_uls;
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
179 while (uls->type != CODEC_TYPE_DATA) {
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
180 if (type == uls->type)
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
181 break;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
182 uls ++;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
183 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
184 return uls;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
185 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
186
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
187 static void mxf_write_common_fields( ByteIOContext *pb, AVStream *st)
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
188 {
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
189 const MXFDataDefinitionUL * data_def_ul;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
190
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
191 // find data define uls
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
192 data_def_ul = mxf_get_data_definition_ul(st->codec->codec_type);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
193 mxf_write_local_tag(pb, 16, 0x0201);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
194 put_buffer(pb, data_def_ul->uid, 16);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
195
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
196 // write duration
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
197 mxf_write_local_tag(pb, 8, 0x0202);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
198 put_be64(pb, st->duration);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
199 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
200
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
201 static int mux_write_packet(AVFormatContext *s, AVPacket *pkt)
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
202 {
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
203 ByteIOContext *pb = s->pb;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
204 AVStream *st = s->streams[pkt->stream_index];
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
205 MXFStreamContext *sc = st->priv_data;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
206
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
207 put_buffer(pb, sc->track_essence_element_key, 16); // write key
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
208 klv_encode_ber_length(pb, pkt->size); // write length
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
209 put_buffer(pb, pkt->data, pkt->size); // write value
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
210
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
211 put_flush_packet(pb);
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
212 return 0;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
213 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
214
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
215 static void mxf_write_header_desc(ByteIOContext *pb, const MXFDescriptorWriteTableEntry *desc_tbl, AVStream *st)
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
216 {
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
217 const MXFCodecUL *codec_ul;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
218
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
219 put_buffer(pb, desc_tbl->key, 16);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
220 klv_encode_ber_length(pb, 96);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
221
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
222 mxf_write_local_tag(pb, 16, 0x3C0A);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
223 mxf_write_uuid(pb, SubDescriptor, st->index);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
224
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
225 mxf_write_local_tag(pb, 4, 0x3006);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
226 put_be32(pb, st->index);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
227
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
228 codec_ul = mxf_get_essence_container_ul(st->codec->codec_id);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
229 mxf_write_local_tag(pb, 16, 0x3004);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
230 put_buffer(pb, codec_ul->uid, 16);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
231 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
232
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
233 static int mxf_write_mpeg_video_desc(AVFormatContext *s, const MXFDescriptorWriteTableEntry *desc_tbl, int stream_index)
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
234 {
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
235 ByteIOContext *pb = s->pb;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
236 AVStream *st;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
237
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
238 st = s->streams[stream_index];
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
239 mxf_write_header_desc(pb, desc_tbl, st);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
240
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
241 mxf_write_local_tag(pb, 4, 0x3203);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
242 put_be32(pb, st->codec->width);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
243
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
244 mxf_write_local_tag(pb, 4, 0x3202);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
245 put_be32(pb, st->codec->height);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
246
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
247 mxf_write_local_tag(pb, 8, 0x320E);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
248 put_be32(pb, st->codec->height * st->codec->sample_aspect_ratio.den);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
249 put_be32(pb, st->codec->width * st->codec->sample_aspect_ratio.num);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
250
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
251 // tmp write, will modified later
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
252 mxf_write_local_tag(pb, 16, 0x3201);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
253 put_buffer(pb, ff_mxf_codec_uls->uid, 16);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
254 return 0;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
255 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
256
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
257 static int mxf_write_wav_desc(AVFormatContext *s, const MXFDescriptorWriteTableEntry *desc_tbl, int stream_index)
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
258 {
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
259 ByteIOContext *pb = s->pb;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
260 AVStream *st;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
261
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
262 st = s->streams[stream_index];
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
263 mxf_write_header_desc(pb, desc_tbl, st);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
264
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
265 // write audio sampling rate
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
266 mxf_write_local_tag(pb, 8, 0x3D03);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
267 put_be32(pb, st->codec->sample_rate);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
268 put_be32(pb, 1);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
269
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
270 mxf_write_local_tag(pb, 4, 0x3D07);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
271 put_be32(pb, st->codec->channels);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
272
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
273 mxf_write_local_tag(pb, 4, 0x3D01);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
274 put_be32(pb, st->codec->bits_per_sample);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
275
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
276 // tmp write, will modified later
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
277 mxf_write_local_tag(pb, 16, 0x3201);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
278 put_buffer(pb, (ff_mxf_codec_uls + 8) ->uid, 16);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
279 return 0;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
280 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
281
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
282 static const MXFDescriptorWriteTableEntry mxf_descriptor_write_table[] = {
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
283 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 }, mxf_write_mpeg_video_desc, CODEC_ID_MPEG2VIDEO},
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
284 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 }, mxf_write_wav_desc, CODEC_ID_PCM_S16LE},
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
285 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, NULL, CODEC_ID_NONE},
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
286 };
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
287
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
288 static int mxf_build_structural_metadata(AVFormatContext *s, enum MXFMetadataSetType type)
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
289 {
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
290 int i;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
291 const MXFDescriptorWriteTableEntry *desc = NULL;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
292 int track_number_sign[sizeof(mxf_essence_element_key)/sizeof(MXFCodecUL)] = { 0 };
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
293
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
294 if (mxf_write_package(s, type) < 0)
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
295 return -1;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
296 if (type == SourcePackage) {
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
297 if (mxf_write_multi_descriptor(s) < 0)
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
298 return -1;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
299 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
300
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
301 for (i = 0;i < s->nb_streams; i++) {
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
302 if ( mxf_write_track(s, i, type, track_number_sign) < 0)
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
303 return -1;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
304 if ( mxf_write_sequence(s, i, type) < 0)
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
305 return -1;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
306 if ( mxf_write_structural_component(s, i, type) < 0)
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
307 return -1;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
308
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
309 if (type == SourcePackage) {
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
310 for (desc = mxf_descriptor_write_table; desc->write; desc++) {
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
311 if (s->streams[i]->codec->codec_id == desc->type) {
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
312 if ( desc->write(s, desc, i) < 0) {
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
313 av_log(s, AV_LOG_ERROR, "error writing descriptor\n");
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
314 return -1;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
315 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
316 break;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
317 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
318 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
319 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
320 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
321 return 0;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
322 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
323
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
324 static int mxf_write_header_metadata_sets(AVFormatContext *s)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
325 {
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
326 AVStream *st;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
327 MXFStreamContext *sc = NULL;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
328 int i;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
329 if (mxf_write_preface(s) < 0)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
330 return -1;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
331
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
332 if (mxf_write_identification(s) < 0)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
333 return -1;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
334
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
335 if (mxf_write_content_storage(s) < 0)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
336 return -1;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
337
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
338 for (i = 0; i < s->nb_streams; i++) {
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
339 st = s->streams[i];
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
340 sc = av_mallocz(sizeof(MXFStreamContext));
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
341 if (!sc)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
342 return AVERROR(ENOMEM);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
343 st->priv_data = sc;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
344 // set pts information
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
345 if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
346 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
347 } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
348 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
349 }
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
350 }
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
351
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
352 if (mxf_build_structural_metadata(s, MaterialPackage) < 0)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
353 return -1;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
354
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
355 if (mxf_build_structural_metadata(s, SourcePackage) < 0)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
356 return -1;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
357 return 0;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
358 }
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
359
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
360 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
361 {
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
362 MXFContext *mxf = s->priv_data;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
363 ByteIOContext *pb = s->pb;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
364
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
365 url_fseek(pb, mxf->header_byte_count_offset, SEEK_SET);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
366 put_be64(pb, mxf->header_byte_count);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
367 put_flush_packet(pb);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
368
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
369 url_fseek(pb, mxf->header_footer_partition_offset, SEEK_SET);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
370 put_be64(pb, footer_partition_offset);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
371 put_flush_packet(pb);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
372 return 0;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
373 }
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
374 AVOutputFormat mxf_muxer = {
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
375 "mxf",
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
376 NULL_IF_CONFIG_SMALL("Material eXchange Format"),
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
377 NULL,
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
378 "mxf",
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
379 sizeof(MXFContext),
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
380 CODEC_ID_PCM_S16LE,
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
381 CODEC_ID_MPEG2VIDEO,
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
382 mux_write_header,
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
383 mux_write_packet,
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
384 mux_write_footer,
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
385 };