annotate src/ffmpeg/libavformat/mxf.c @ 844:80e7162bd968 trunk

[svn] - seek is implemented as it should be, but appears to not work
author nenolod
date Mon, 12 Mar 2007 18:53:58 -0700
parents e8776388b02a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1 /*
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
2 * MXF demuxer.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
3 * Copyright (c) 2006 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
4 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
5 * This file is part of FFmpeg.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
6 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
11 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
15 * Lesser General Public License for more details.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
16 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
20 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
21
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
22 /*
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
23 * References
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
24 * SMPTE 336M KLV Data Encoding Protocol Using Key-Length-Value
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
25 * SMPTE 377M MXF File Format Specifications
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
26 * SMPTE 378M Operational Pattern 1a
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
27 * SMPTE 379M MXF Generic Container
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
28 * SMPTE 381M Mapping MPEG Streams into the MXF Generic Container
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
29 * SMPTE 382M Mapping AES3 and Broadcast Wave Audio into the MXF Generic Container
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
30 * SMPTE 383M Mapping DV-DIF Data to the MXF Generic Container
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
31 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
32 * Principle
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
33 * Search for Track numbers which will identify essence element KLV packets.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
34 * Search for SourcePackage which define tracks which contains Track numbers.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
35 * Material Package contains tracks with reference to SourcePackage tracks.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
36 * Search for Descriptors (Picture, Sound) which contains codec info and parameters.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
37 * Assign Descriptors to correct Tracks.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
38 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
39 * Metadata reading functions read Local Tags, get InstanceUID(0x3C0A) then add MetaDataSet to MXFContext.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
40 * Metadata parsing resolves Strong References to objects.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
41 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
42 * Simple demuxer, only OP1A supported and some files might not work at all.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
43 * Only tracks with associated descriptors will be decoded. "Highly Desirable" SMPTE 377M D.1
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
44 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
45
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
46 //#define DEBUG
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
47
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
48 #include "avformat.h"
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
49
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
50 typedef uint8_t UID[16];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
51
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
52 enum MXFMetadataSetType {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
53 MaterialPackage,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
54 SourcePackage,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
55 SourceClip,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
56 TimecodeComponent,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
57 Sequence,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
58 MultipleDescriptor,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
59 Descriptor,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
60 Track,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
61 EssenceContainerData,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
62 };
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
63
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
64 typedef struct MXFStructuralComponent {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
65 UID uid;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
66 enum MXFMetadataSetType type;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
67 UID source_package_uid;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
68 UID data_definition_ul;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
69 int64_t duration;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
70 int64_t start_position;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
71 int source_track_id;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
72 } MXFStructuralComponent;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
73
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
74 typedef struct MXFSequence {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
75 UID uid;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
76 enum MXFMetadataSetType type;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
77 UID data_definition_ul;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
78 UID *structural_components_refs;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
79 int structural_components_count;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
80 int64_t duration;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
81 } MXFSequence;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
82
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
83 typedef struct MXFTrack {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
84 UID uid;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
85 enum MXFMetadataSetType type;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
86 MXFSequence *sequence; /* mandatory, and only one */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
87 UID sequence_ref;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
88 int track_id;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
89 uint8_t track_number[4];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
90 AVRational edit_rate;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
91 } MXFTrack;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
92
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
93 typedef struct MXFDescriptor {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
94 UID uid;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
95 enum MXFMetadataSetType type;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
96 UID essence_container_ul;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
97 UID essence_codec_ul;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
98 AVRational sample_rate;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
99 AVRational aspect_ratio;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
100 int width;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
101 int height;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
102 int channels;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
103 int bits_per_sample;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
104 UID *sub_descriptors_refs;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
105 int sub_descriptors_count;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
106 int linked_track_id;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
107 uint8_t *extradata;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
108 int extradata_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
109 } MXFDescriptor;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
110
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
111 typedef struct MXFPackage {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
112 UID uid;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
113 enum MXFMetadataSetType type;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
114 UID package_uid;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
115 UID *tracks_refs;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
116 int tracks_count;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
117 MXFDescriptor *descriptor; /* only one */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
118 UID descriptor_ref;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
119 } MXFPackage;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
120
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
121 typedef struct MXFEssenceContainerData {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
122 UID uid;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
123 enum MXFMetadataSetType type;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
124 UID linked_package_uid;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
125 } MXFEssenceContainerData;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
126
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
127 typedef struct {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
128 UID uid;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
129 enum MXFMetadataSetType type;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
130 } MXFMetadataSet;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
131
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
132 typedef struct MXFContext {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
133 UID *packages_refs;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
134 int packages_count;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
135 UID *essence_container_data_sets_refs;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
136 int essence_container_data_sets_count;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
137 UID *essence_containers_uls; /* Universal Labels SMPTE RP224 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
138 int essence_containers_uls_count;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
139 UID operational_pattern_ul;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
140 UID content_storage_uid;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
141 MXFMetadataSet **metadata_sets;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
142 int metadata_sets_count;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
143 AVFormatContext *fc;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
144 } MXFContext;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
145
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
146 typedef struct KLVPacket {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
147 UID key;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
148 offset_t offset;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
149 uint64_t length;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
150 } KLVPacket;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
151
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
152 enum MXFWrappingScheme {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
153 Frame,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
154 Clip,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
155 };
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
156
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
157 typedef struct MXFCodecUL {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
158 UID uid;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
159 enum CodecID id;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
160 enum MXFWrappingScheme wrapping;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
161 } MXFCodecUL;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
162
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
163 typedef struct MXFDataDefinitionUL {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
164 UID uid;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
165 enum CodecType type;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
166 } MXFDataDefinitionUL;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
167
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
168 typedef struct MXFMetadataReadTableEntry {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
169 const UID key;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
170 int (*read)(MXFContext *mxf, KLVPacket *klv);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
171 } MXFMetadataReadTableEntry;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
172
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
173 /* partial keys to match */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
174 static const uint8_t mxf_header_partition_pack_key[] = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02 };
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
175 static const uint8_t mxf_essence_element_key[] = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01 };
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
176
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
177 #define IS_KLV_KEY(x, y) (!memcmp(x, y, sizeof(y)))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
178
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
179 #define PRINT_KEY(s, x) dprintf("%s %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", s, \
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
180 (x)[0], (x)[1], (x)[2], (x)[3], (x)[4], (x)[5], (x)[6], (x)[7], (x)[8], (x)[9], (x)[10], (x)[11], (x)[12], (x)[13], (x)[14], (x)[15])
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
181
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
182 static int64_t klv_decode_ber_length(ByteIOContext *pb)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
183 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
184 int64_t size = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
185 uint8_t length = get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
186 int type = length >> 7;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
187
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
188 if (type) { /* long form */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
189 int bytes_num = length & 0x7f;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
190 /* SMPTE 379M 5.3.4 guarantee that bytes_num must not exceed 8 bytes */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
191 if (bytes_num > 8)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
192 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
193 while (bytes_num--)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
194 size = size << 8 | get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
195 } else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
196 size = length & 0x7f;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
197 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
198 return size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
199 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
200
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
201 static int klv_read_packet(KLVPacket *klv, ByteIOContext *pb)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
202 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
203 klv->offset = url_ftell(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
204 get_buffer(pb, klv->key, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
205 klv->length = klv_decode_ber_length(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
206 return klv->length == -1 ? -1 : 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
207 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
208
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
209 static int mxf_get_stream_index(AVFormatContext *s, KLVPacket *klv)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
210 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
211 int i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
212
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
213 for (i = 0; i < s->nb_streams; i++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
214 MXFTrack *track = s->streams[i]->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
215 /* SMPTE 379M 7.3 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
216 if (!memcmp(klv->key + sizeof(mxf_essence_element_key), track->track_number, sizeof(track->track_number)))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
217 return i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
218 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
219 /* return 0 if only one stream, for OP Atom files with 0 as track number */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
220 return s->nb_streams == 1 ? 0 : -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
221 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
222
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
223 /* XXX: use AVBitStreamFilter */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
224 static int mxf_get_d10_aes3_packet(ByteIOContext *pb, AVStream *st, AVPacket *pkt, int64_t length)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
225 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
226 uint8_t buffer[61444];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
227 uint8_t *buf_ptr, *end_ptr, *data_ptr;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
228
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
229 if (length > 61444) /* worst case PAL 1920 samples 8 channels */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
230 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
231 get_buffer(pb, buffer, length);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
232 av_new_packet(pkt, length);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
233 data_ptr = pkt->data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
234 end_ptr = buffer + length;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
235 buf_ptr = buffer + 4; /* skip SMPTE 331M header */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
236 for (; buf_ptr < end_ptr; buf_ptr += 4) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
237 if (st->codec->bits_per_sample == 24) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
238 data_ptr[0] = (buf_ptr[2] >> 4) | ((buf_ptr[3] & 0x0f) << 4);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
239 data_ptr[1] = (buf_ptr[1] >> 4) | ((buf_ptr[2] & 0x0f) << 4);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
240 data_ptr[2] = (buf_ptr[0] >> 4) | ((buf_ptr[1] & 0x0f) << 4);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
241 data_ptr += 3;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
242 } else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
243 data_ptr[0] = (buf_ptr[2] >> 4) | ((buf_ptr[3] & 0x0f) << 4);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
244 data_ptr[1] = (buf_ptr[1] >> 4) | ((buf_ptr[2] & 0x0f) << 4);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
245 data_ptr += 2;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
246 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
247 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
248 pkt->size = data_ptr - pkt->data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
249 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
250 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
251
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
252 static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
253 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
254 KLVPacket klv;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
255
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
256 while (!url_feof(&s->pb)) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
257 if (klv_read_packet(&klv, &s->pb) < 0) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
258 av_log(s, AV_LOG_ERROR, "error reading KLV packet\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
259 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
260 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
261 #ifdef DEBUG
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
262 PRINT_KEY("read packet", klv.key);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
263 #endif
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
264 if (IS_KLV_KEY(klv.key, mxf_essence_element_key)) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
265 int index = mxf_get_stream_index(s, &klv);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
266 if (index < 0) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
267 av_log(s, AV_LOG_ERROR, "error getting stream index\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
268 url_fskip(&s->pb, klv.length);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
269 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
270 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
271 /* check for 8 channels AES3 element */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
272 if (klv.key[12] == 0x06 && klv.key[13] == 0x01 && klv.key[14] == 0x10) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
273 if (mxf_get_d10_aes3_packet(&s->pb, s->streams[index], pkt, klv.length) < 0) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
274 av_log(s, AV_LOG_ERROR, "error reading D-10 aes3 frame\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
275 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
276 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
277 } else
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
278 av_get_packet(&s->pb, pkt, klv.length);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
279 pkt->stream_index = index;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
280 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
281 } else
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
282 url_fskip(&s->pb, klv.length);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
283 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
284 return AVERROR_IO;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
285 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
286
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
287 static int mxf_add_metadata_set(MXFContext *mxf, void *metadata_set)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
288 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
289 mxf->metadata_sets = av_realloc(mxf->metadata_sets, (mxf->metadata_sets_count + 1) * sizeof(*mxf->metadata_sets));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
290 mxf->metadata_sets[mxf->metadata_sets_count] = metadata_set;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
291 mxf->metadata_sets_count++;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
292 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
293 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
294
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
295 static int mxf_read_metadata_preface(MXFContext *mxf, KLVPacket *klv)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
296 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
297 ByteIOContext *pb = &mxf->fc->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
298 int bytes_read = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
299
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
300 while (bytes_read < klv->length) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
301 int tag = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
302 int size = get_be16(pb); /* SMPTE 336M Table 8 KLV specified length, 0x53 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
303
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
304 switch (tag) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
305 case 0x3B03:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
306 get_buffer(pb, mxf->content_storage_uid, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
307 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
308 case 0x3B09:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
309 get_buffer(pb, mxf->operational_pattern_ul, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
310 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
311 case 0x3B0A:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
312 mxf->essence_containers_uls_count = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
313 if (mxf->essence_containers_uls_count >= UINT_MAX / sizeof(UID))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
314 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
315 mxf->essence_containers_uls = av_malloc(mxf->essence_containers_uls_count * sizeof(UID));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
316 url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
317 get_buffer(pb, (uint8_t *)mxf->essence_containers_uls, mxf->essence_containers_uls_count * sizeof(UID));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
318 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
319 default:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
320 url_fskip(pb, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
321 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
322 bytes_read += size + 4;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
323 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
324 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
325 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
326
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
327 static int mxf_read_metadata_content_storage(MXFContext *mxf, KLVPacket *klv)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
328 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
329 ByteIOContext *pb = &mxf->fc->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
330 int bytes_read = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
331
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
332 while (bytes_read < klv->length) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
333 int tag = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
334 int size = get_be16(pb); /* SMPTE 336M Table 8 KLV specified length, 0x53 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
335
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
336 dprintf("tag 0x%04X, size %d\n", tag, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
337 switch (tag) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
338 case 0x1901:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
339 mxf->packages_count = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
340 if (mxf->packages_count >= UINT_MAX / sizeof(UID))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
341 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
342 mxf->packages_refs = av_malloc(mxf->packages_count * sizeof(UID));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
343 url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
344 get_buffer(pb, (uint8_t *)mxf->packages_refs, mxf->packages_count * sizeof(UID));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
345 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
346 case 0x1902:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
347 mxf->essence_container_data_sets_count = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
348 if (mxf->essence_container_data_sets_count >= UINT_MAX / sizeof(UID))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
349 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
350 mxf->essence_container_data_sets_refs = av_malloc(mxf->essence_container_data_sets_count * sizeof(UID));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
351 url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
352 get_buffer(pb, (uint8_t *)mxf->essence_container_data_sets_refs, mxf->essence_container_data_sets_count * sizeof(UID));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
353 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
354 default:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
355 url_fskip(pb, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
356 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
357 bytes_read += size + 4;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
358 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
359 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
360 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
361
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
362 static int mxf_read_metadata_source_clip(MXFContext *mxf, KLVPacket *klv)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
363 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
364 ByteIOContext *pb = &mxf->fc->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
365 MXFStructuralComponent *source_clip = av_mallocz(sizeof(*source_clip));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
366 int bytes_read = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
367
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
368 while (bytes_read < klv->length) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
369 int tag = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
370 int size = get_be16(pb); /* SMPTE 336M Table 8 KLV specified length, 0x53 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
371
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
372 bytes_read += size + 4;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
373 dprintf("tag 0x%04X, size %d\n", tag, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
374 if (!size) /* ignore empty tag, needed for some files with empty UMID tag */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
375 continue;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
376 switch (tag) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
377 case 0x3C0A:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
378 get_buffer(pb, source_clip->uid, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
379 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
380 case 0x0202:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
381 source_clip->duration = get_be64(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
382 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
383 case 0x1201:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
384 source_clip->start_position = get_be64(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
385 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
386 case 0x1101:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
387 /* UMID, only get last 16 bytes */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
388 url_fskip(pb, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
389 get_buffer(pb, source_clip->source_package_uid, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
390 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
391 case 0x1102:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
392 source_clip->source_track_id = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
393 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
394 default:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
395 url_fskip(pb, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
396 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
397 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
398 source_clip->type = SourceClip;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
399 return mxf_add_metadata_set(mxf, source_clip);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
400 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
401
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
402 static int mxf_read_metadata_material_package(MXFContext *mxf, KLVPacket *klv)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
403 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
404 ByteIOContext *pb = &mxf->fc->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
405 MXFPackage *package = av_mallocz(sizeof(*package));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
406 int bytes_read = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
407
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
408 while (bytes_read < klv->length) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
409 int tag = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
410 int size = get_be16(pb); /* KLV specified by 0x53 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
411
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
412 switch (tag) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
413 case 0x3C0A:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
414 get_buffer(pb, package->uid, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
415 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
416 case 0x4403:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
417 package->tracks_count = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
418 if (package->tracks_count >= UINT_MAX / sizeof(UID))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
419 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
420 package->tracks_refs = av_malloc(package->tracks_count * sizeof(UID));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
421 url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
422 get_buffer(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
423 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
424 default:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
425 url_fskip(pb, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
426 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
427 bytes_read += size + 4;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
428 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
429 package->type = MaterialPackage;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
430 return mxf_add_metadata_set(mxf, package);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
431 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
432
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
433 static int mxf_read_metadata_track(MXFContext *mxf, KLVPacket *klv)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
434 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
435 ByteIOContext *pb = &mxf->fc->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
436 MXFTrack *track = av_mallocz(sizeof(*track));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
437 int bytes_read = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
438
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
439 while (bytes_read < klv->length) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
440 int tag = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
441 int size = get_be16(pb); /* KLV specified by 0x53 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
442
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
443 dprintf("tag 0x%04X, size %d\n", tag, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
444 switch (tag) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
445 case 0x3C0A:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
446 get_buffer(pb, track->uid, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
447 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
448 case 0x4801:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
449 track->track_id = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
450 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
451 case 0x4804:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
452 get_buffer(pb, track->track_number, 4);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
453 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
454 case 0x4B01:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
455 track->edit_rate.den = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
456 track->edit_rate.num = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
457 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
458 case 0x4803:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
459 get_buffer(pb, track->sequence_ref, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
460 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
461 default:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
462 url_fskip(pb, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
463 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
464 bytes_read += size + 4;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
465 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
466 track->type = Track;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
467 return mxf_add_metadata_set(mxf, track);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
468 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
469
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
470 static int mxf_read_metadata_sequence(MXFContext *mxf, KLVPacket *klv)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
471 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
472 ByteIOContext *pb = &mxf->fc->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
473 MXFSequence *sequence = av_mallocz(sizeof(*sequence));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
474 int bytes_read = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
475
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
476 while (bytes_read < klv->length) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
477 int tag = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
478 int size = get_be16(pb); /* KLV specified by 0x53 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
479
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
480 dprintf("tag 0x%04X, size %d\n", tag, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
481 switch (tag) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
482 case 0x3C0A:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
483 get_buffer(pb, sequence->uid, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
484 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
485 case 0x0202:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
486 sequence->duration = get_be64(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
487 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
488 case 0x0201:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
489 get_buffer(pb, sequence->data_definition_ul, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
490 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
491 case 0x1001:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
492 sequence->structural_components_count = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
493 if (sequence->structural_components_count >= UINT_MAX / sizeof(UID))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
494 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
495 sequence->structural_components_refs = av_malloc(sequence->structural_components_count * sizeof(UID));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
496 url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
497 get_buffer(pb, (uint8_t *)sequence->structural_components_refs, sequence->structural_components_count * sizeof(UID));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
498 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
499 default:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
500 url_fskip(pb, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
501 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
502 bytes_read += size + 4;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
503 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
504 sequence->type = Sequence;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
505 return mxf_add_metadata_set(mxf, sequence);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
506 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
507
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
508 static int mxf_read_metadata_source_package(MXFContext *mxf, KLVPacket *klv)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
509 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
510 ByteIOContext *pb = &mxf->fc->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
511 MXFPackage *package = av_mallocz(sizeof(*package));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
512 int bytes_read = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
513
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
514 while (bytes_read < klv->length) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
515 int tag = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
516 int size = get_be16(pb); /* KLV specified by 0x53 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
517
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
518 dprintf("tag 0x%04X, size %d\n", tag, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
519 switch (tag) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
520 case 0x3C0A:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
521 get_buffer(pb, package->uid, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
522 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
523 case 0x4403:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
524 package->tracks_count = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
525 if (package->tracks_count >= UINT_MAX / sizeof(UID))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
526 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
527 package->tracks_refs = av_malloc(package->tracks_count * sizeof(UID));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
528 url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
529 get_buffer(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
530 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
531 case 0x4401:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
532 /* UMID, only get last 16 bytes */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
533 url_fskip(pb, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
534 get_buffer(pb, package->package_uid, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
535 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
536 case 0x4701:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
537 get_buffer(pb, package->descriptor_ref, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
538 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
539 default:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
540 url_fskip(pb, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
541 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
542 bytes_read += size + 4;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
543 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
544 package->type = SourcePackage;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
545 return mxf_add_metadata_set(mxf, package);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
546 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
547
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
548 static int mxf_read_metadata_multiple_descriptor(MXFContext *mxf, KLVPacket *klv)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
549 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
550 ByteIOContext *pb = &mxf->fc->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
551 MXFDescriptor *descriptor = av_mallocz(sizeof(*descriptor));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
552 int bytes_read = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
553
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
554 while (bytes_read < klv->length) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
555 int tag = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
556 int size = get_be16(pb); /* KLV specified by 0x53 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
557
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
558 dprintf("tag 0x%04X, size %d\n", tag, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
559 switch (tag) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
560 case 0x3C0A:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
561 get_buffer(pb, descriptor->uid, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
562 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
563 case 0x3F01:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
564 descriptor->sub_descriptors_count = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
565 if (descriptor->sub_descriptors_count >= UINT_MAX / sizeof(UID))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
566 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
567 descriptor->sub_descriptors_refs = av_malloc(descriptor->sub_descriptors_count * sizeof(UID));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
568 url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
569 get_buffer(pb, (uint8_t *)descriptor->sub_descriptors_refs, descriptor->sub_descriptors_count * sizeof(UID));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
570 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
571 default:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
572 url_fskip(pb, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
573 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
574 bytes_read += size + 4;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
575 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
576 descriptor->type = MultipleDescriptor;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
577 return mxf_add_metadata_set(mxf, descriptor);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
578 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
579
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
580 static void mxf_read_metadata_pixel_layout(ByteIOContext *pb, MXFDescriptor *descriptor)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
581 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
582 int code;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
583
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
584 do {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
585 code = get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
586 dprintf("pixel layout: code 0x%x\n", code);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
587 switch (code) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
588 case 0x52: /* R */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
589 descriptor->bits_per_sample += get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
590 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
591 case 0x47: /* G */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
592 descriptor->bits_per_sample += get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
593 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
594 case 0x42: /* B */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
595 descriptor->bits_per_sample += get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
596 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
597 default:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
598 get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
599 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
600 } while (code != 0); /* SMPTE 377M E.2.46 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
601 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
602
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
603 static int mxf_read_metadata_generic_descriptor(MXFContext *mxf, KLVPacket *klv)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
604 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
605 ByteIOContext *pb = &mxf->fc->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
606 MXFDescriptor *descriptor = av_mallocz(sizeof(*descriptor));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
607 int bytes_read = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
608
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
609 while (bytes_read < klv->length) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
610 int tag = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
611 int size = get_be16(pb); /* KLV specified by 0x53 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
612
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
613 dprintf("tag 0x%04X, size %d\n", tag, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
614 switch (tag) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
615 case 0x3C0A:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
616 get_buffer(pb, descriptor->uid, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
617 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
618 case 0x3004:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
619 get_buffer(pb, descriptor->essence_container_ul, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
620 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
621 case 0x3006:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
622 descriptor->linked_track_id = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
623 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
624 case 0x3201: /* PictureEssenceCoding */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
625 get_buffer(pb, descriptor->essence_codec_ul, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
626 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
627 case 0x3203:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
628 descriptor->width = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
629 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
630 case 0x3202:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
631 descriptor->height = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
632 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
633 case 0x320E:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
634 descriptor->aspect_ratio.num = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
635 descriptor->aspect_ratio.den = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
636 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
637 case 0x3D03:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
638 descriptor->sample_rate.num = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
639 descriptor->sample_rate.den = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
640 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
641 case 0x3D06: /* SoundEssenceCompression */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
642 get_buffer(pb, descriptor->essence_codec_ul, 16);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
643 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
644 case 0x3D07:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
645 descriptor->channels = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
646 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
647 case 0x3D01:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
648 descriptor->bits_per_sample = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
649 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
650 case 0x3401:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
651 mxf_read_metadata_pixel_layout(pb, descriptor);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
652 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
653 case 0x8201: /* Private tag used by SONY C0023S01.mxf */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
654 descriptor->extradata = av_malloc(size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
655 descriptor->extradata_size = size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
656 get_buffer(pb, descriptor->extradata, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
657 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
658 default:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
659 url_fskip(pb, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
660 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
661 bytes_read += size + 4;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
662 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
663 descriptor->type = Descriptor;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
664 return mxf_add_metadata_set(mxf, descriptor);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
665 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
666
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
667 /* SMPTE RP224 http://www.smpte-ra.org/mdd/index.html */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
668 static const MXFDataDefinitionUL mxf_data_definition_uls[] = {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
669 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x01,0x00,0x00,0x00 }, CODEC_TYPE_VIDEO },
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
670 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x02,0x00,0x00,0x00 }, CODEC_TYPE_AUDIO },
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
671 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x05,0x01,0x03,0x02,0x02,0x02,0x02,0x00,0x00 }, CODEC_TYPE_AUDIO },
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
672 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, CODEC_TYPE_DATA },
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
673 };
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
674
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
675 static const MXFCodecUL mxf_codec_uls[] = {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
676 /* PictureEssenceCoding */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
677 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x02,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* 422P@ML I-Frame */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
678 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x03,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* 422P@HL Long GoP */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
679 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x11,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* MP@ML Long GoP */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
680 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x03,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* 422P@ML Long GoP */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
681 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x03,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* MP@HL Long GoP */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
682 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x20,0x02,0x03 }, CODEC_ID_MPEG4, Frame }, /* XDCAM proxy_pal030926.mxf */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
683 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x20,0x02,0x04 }, CODEC_ID_MPEG4, Frame }, /* XDCAM Proxy C0023S01.mxf */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
684 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x05 }, CODEC_ID_MPEG2VIDEO, Frame }, /* D-10 30Mbps PAL */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
685 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x01 }, CODEC_ID_MPEG2VIDEO, Frame }, /* D-10 50Mbps PAL */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
686 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x04,0x00 }, CODEC_ID_DVVIDEO, Frame }, /* DVCPRO50 PAL */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
687 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x02,0x00 }, CODEC_ID_DVVIDEO, Frame }, /* DVCPRO25 PAL */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
688 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x01,0x02,0x00 }, CODEC_ID_DVVIDEO, Frame }, /* DV25 IEC PAL */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
689 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x07,0x04,0x01,0x02,0x02,0x03,0x01,0x01,0x00 }, CODEC_ID_JPEG2000, Frame }, /* JPEG2000 Codestream */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
690 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x01,0x7F,0x00,0x00,0x00 }, CODEC_ID_RAWVIDEO, Frame }, /* Uncompressed */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
691 /* SoundEssenceCompression */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
692 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, CODEC_ID_PCM_S16LE, Frame }, /* Uncompressed */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
693 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x7F,0x00,0x00,0x00 }, CODEC_ID_PCM_S16LE, Frame },
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
694 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x07,0x04,0x02,0x02,0x01,0x7E,0x00,0x00,0x00 }, CODEC_ID_PCM_S16BE, Frame }, /* From Omneon MXF file */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
695 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x01,0x01,0x00 }, CODEC_ID_PCM_ALAW, Frame },
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
696 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x04,0x04,0x02,0x02,0x02,0x03,0x01,0x01,0x00 }, CODEC_ID_PCM_ALAW, Frame }, /* XDCAM Proxy C0023S01.mxf */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
697 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x01,0x00 }, CODEC_ID_AC3, Frame },
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
698 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x05,0x00 }, CODEC_ID_MP2, Frame }, /* MP2 or MP3 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
699 //{ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x1C,0x00 }, CODEC_ID_DOLBY_E, Frame }, /* Dolby-E */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
700 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, CODEC_ID_NONE, Frame },
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
701 };
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
702
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
703 static const MXFCodecUL mxf_picture_essence_container_uls[] = {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
704 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 }, CODEC_ID_MPEG2VIDEO, Frame }, /* MPEG-ES Frame wrapped */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
705 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0xe0,0x02 }, CODEC_ID_MPEG2VIDEO, Clip }, /* MPEG-ES Clip wrapped, 0xe0 MPV stream id */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
706 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x04,0x61,0x07 }, CODEC_ID_MPEG2VIDEO, Clip }, /* MPEG-ES Custom wrapped, 0x61 ??? stream id */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
707 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, CODEC_ID_NONE, Frame },
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
708 };
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
709
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
710 static const MXFCodecUL mxf_sound_essence_container_uls[] = {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
711 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x01,0x00 }, CODEC_ID_PCM_S16LE, Frame }, /* BWF Frame wrapped */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
712 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x03,0x00 }, CODEC_ID_PCM_S16LE, Frame }, /* AES Frame wrapped */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
713 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x40,0x01 }, CODEC_ID_MP2, Frame }, /* MPEG-ES Frame wrapped, 0x40 ??? stream id */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
714 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0xc0,0x01 }, CODEC_ID_MP2, Frame }, /* MPEG-ES Frame wrapped, 0xc0 MPA stream id */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
715 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0xc0,0x02 }, CODEC_ID_MP2, Clip }, /* MPEG-ES Clip wrapped, 0xc0 MPA stream id */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
716 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x05,0x01 }, CODEC_ID_PCM_S16BE, Frame }, /* D-10 Mapping 30Mbps PAL Extended Template */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
717 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, CODEC_ID_PCM_S16BE, Frame }, /* D-10 Mapping 50Mbps PAL Extended Template */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
718 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, CODEC_ID_NONE, Frame },
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
719 };
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
720
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
721 static const MXFCodecUL *mxf_get_codec_ul(const MXFCodecUL *uls, UID *uid)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
722 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
723 while (uls->id != CODEC_ID_NONE) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
724 if(!memcmp(uls->uid, *uid, 16))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
725 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
726 uls++;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
727 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
728 return uls;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
729 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
730
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
731 static enum CodecType mxf_get_codec_type(const MXFDataDefinitionUL *uls, UID *uid)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
732 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
733 while (uls->type != CODEC_TYPE_DATA) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
734 if(!memcmp(uls->uid, *uid, 16))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
735 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
736 uls++;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
737 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
738 return uls->type;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
739 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
740
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
741 static void *mxf_resolve_strong_ref(MXFContext *mxf, UID *strong_ref)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
742 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
743 int i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
744
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
745 if (!strong_ref)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
746 return NULL;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
747 for (i = 0; i < mxf->metadata_sets_count; i++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
748 if (!memcmp(*strong_ref, mxf->metadata_sets[i]->uid, 16)) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
749 return mxf->metadata_sets[i];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
750 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
751 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
752 return NULL;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
753 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
754
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
755 static int mxf_parse_structural_metadata(MXFContext *mxf)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
756 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
757 MXFPackage *material_package = NULL;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
758 MXFPackage *source_package = NULL;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
759 MXFPackage *temp_package = NULL;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
760 int i, j, k;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
761
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
762 dprintf("metadata sets count %d\n", mxf->metadata_sets_count);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
763 /* TODO: handle multiple material packages (OP3x) */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
764 for (i = 0; i < mxf->packages_count; i++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
765 if (!(temp_package = mxf_resolve_strong_ref(mxf, &mxf->packages_refs[i]))) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
766 av_log(mxf->fc, AV_LOG_ERROR, "could not resolve package strong ref\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
767 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
768 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
769 if (temp_package->type == MaterialPackage) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
770 material_package = temp_package;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
771 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
772 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
773 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
774 if (!material_package) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
775 av_log(mxf->fc, AV_LOG_ERROR, "no material package found\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
776 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
777 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
778
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
779 for (i = 0; i < material_package->tracks_count; i++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
780 MXFTrack *material_track = NULL;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
781 MXFTrack *source_track = NULL;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
782 MXFTrack *temp_track = NULL;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
783 MXFDescriptor *descriptor = NULL;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
784 MXFStructuralComponent *component = NULL;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
785 const MXFCodecUL *codec_ul = NULL;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
786 const MXFCodecUL *container_ul = NULL;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
787 AVStream *st;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
788
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
789 if (!(material_track = mxf_resolve_strong_ref(mxf, &material_package->tracks_refs[i]))) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
790 av_log(mxf->fc, AV_LOG_ERROR, "could not resolve material track strong ref\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
791 continue;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
792 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
793
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
794 if (!(material_track->sequence = mxf_resolve_strong_ref(mxf, &material_track->sequence_ref))) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
795 av_log(mxf->fc, AV_LOG_ERROR, "could not resolve material track sequence strong ref\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
796 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
797 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
798
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
799 /* TODO: handle multiple source clips */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
800 for (j = 0; j < material_track->sequence->structural_components_count; j++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
801 /* TODO: handle timecode component */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
802 component = mxf_resolve_strong_ref(mxf, &material_track->sequence->structural_components_refs[j]);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
803 if (!component || component->type != SourceClip)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
804 continue;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
805
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
806 for (k = 0; k < mxf->packages_count; k++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
807 if (!(temp_package = mxf_resolve_strong_ref(mxf, &mxf->packages_refs[k]))) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
808 av_log(mxf->fc, AV_LOG_ERROR, "could not resolve source track strong ref\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
809 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
810 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
811 if (!memcmp(temp_package->package_uid, component->source_package_uid, 16)) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
812 source_package = temp_package;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
813 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
814 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
815 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
816 if (!source_package) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
817 av_log(mxf->fc, AV_LOG_ERROR, "material track %d: no corresponding source package found\n", material_track->track_id);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
818 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
819 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
820 for (k = 0; k < source_package->tracks_count; k++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
821 if (!(temp_track = mxf_resolve_strong_ref(mxf, &source_package->tracks_refs[k]))) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
822 av_log(mxf->fc, AV_LOG_ERROR, "could not resolve source track strong ref\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
823 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
824 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
825 if (temp_track->track_id == component->source_track_id) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
826 source_track = temp_track;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
827 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
828 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
829 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
830 if (!source_track) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
831 av_log(mxf->fc, AV_LOG_ERROR, "material track %d: no corresponding source track found\n", material_track->track_id);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
832 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
833 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
834 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
835 if (!source_track)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
836 continue;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
837
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
838 st = av_new_stream(mxf->fc, source_track->track_id);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
839 st->priv_data = source_track;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
840 st->duration = component->duration;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
841 if (st->duration == -1)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
842 st->duration = AV_NOPTS_VALUE;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
843 st->start_time = component->start_position;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
844 av_set_pts_info(st, 64, material_track->edit_rate.num, material_track->edit_rate.den);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
845
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
846 if (!(source_track->sequence = mxf_resolve_strong_ref(mxf, &source_track->sequence_ref))) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
847 av_log(mxf->fc, AV_LOG_ERROR, "could not resolve source track sequence strong ref\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
848 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
849 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
850
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
851 #ifdef DEBUG
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
852 PRINT_KEY("data definition ul", source_track->sequence->data_definition_ul);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
853 #endif
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
854 st->codec->codec_type = mxf_get_codec_type(mxf_data_definition_uls, &source_track->sequence->data_definition_ul);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
855
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
856 source_package->descriptor = mxf_resolve_strong_ref(mxf, &source_package->descriptor_ref);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
857 if (source_package->descriptor) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
858 if (source_package->descriptor->type == MultipleDescriptor) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
859 for (j = 0; j < source_package->descriptor->sub_descriptors_count; j++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
860 MXFDescriptor *sub_descriptor = mxf_resolve_strong_ref(mxf, &source_package->descriptor->sub_descriptors_refs[j]);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
861
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
862 if (!sub_descriptor) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
863 av_log(mxf->fc, AV_LOG_ERROR, "could not resolve sub descriptor strong ref\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
864 continue;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
865 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
866 if (sub_descriptor->linked_track_id == source_track->track_id) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
867 descriptor = sub_descriptor;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
868 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
869 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
870 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
871 } else
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
872 descriptor = source_package->descriptor;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
873 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
874 if (!descriptor) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
875 av_log(mxf->fc, AV_LOG_INFO, "source track %d: stream %d, no descriptor found\n", source_track->track_id, st->index);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
876 continue;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
877 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
878 #ifdef DEBUG
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
879 PRINT_KEY("essence codec ul", descriptor->essence_codec_ul);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
880 PRINT_KEY("essence container ul", descriptor->essence_container_ul);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
881 #endif
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
882 /* TODO: drop PictureEssenceCoding and SoundEssenceCompression, only check EssenceContainer */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
883 codec_ul = mxf_get_codec_ul(mxf_codec_uls, &descriptor->essence_codec_ul);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
884 st->codec->codec_id = codec_ul->id;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
885 if (descriptor->extradata) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
886 st->codec->extradata = descriptor->extradata;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
887 st->codec->extradata_size = descriptor->extradata_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
888 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
889 if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
890 container_ul = mxf_get_codec_ul(mxf_picture_essence_container_uls, &descriptor->essence_container_ul);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
891 if (st->codec->codec_id == CODEC_ID_NONE)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
892 st->codec->codec_id = container_ul->id;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
893 st->codec->width = descriptor->width;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
894 st->codec->height = descriptor->height;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
895 st->codec->bits_per_sample = descriptor->bits_per_sample; /* Uncompressed */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
896 } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
897 container_ul = mxf_get_codec_ul(mxf_sound_essence_container_uls, &descriptor->essence_container_ul);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
898 if (st->codec->codec_id == CODEC_ID_NONE)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
899 st->codec->codec_id = container_ul->id;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
900 st->codec->channels = descriptor->channels;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
901 st->codec->bits_per_sample = descriptor->bits_per_sample;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
902 st->codec->sample_rate = descriptor->sample_rate.num / descriptor->sample_rate.den;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
903 /* TODO: implement CODEC_ID_RAWAUDIO */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
904 if (st->codec->codec_id == CODEC_ID_PCM_S16LE) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
905 if (descriptor->bits_per_sample == 24)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
906 st->codec->codec_id = CODEC_ID_PCM_S24LE;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
907 else if (descriptor->bits_per_sample == 32)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
908 st->codec->codec_id = CODEC_ID_PCM_S32LE;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
909 } else if (st->codec->codec_id == CODEC_ID_PCM_S16BE) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
910 if (descriptor->bits_per_sample == 24)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
911 st->codec->codec_id = CODEC_ID_PCM_S24BE;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
912 else if (descriptor->bits_per_sample == 32)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
913 st->codec->codec_id = CODEC_ID_PCM_S32BE;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
914 if (descriptor->essence_container_ul[13] == 0x01) /* D-10 Mapping */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
915 st->codec->channels = 8; /* force channels to 8 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
916 } else if (st->codec->codec_id == CODEC_ID_MP2) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
917 st->need_parsing = 1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
918 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
919 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
920 if (container_ul && container_ul->wrapping == Clip) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
921 dprintf("stream %d: clip wrapped essence\n", st->index);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
922 st->need_parsing = 1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
923 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
924 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
925 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
926 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
927
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
928 static const MXFMetadataReadTableEntry mxf_metadata_read_table[] = {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
929 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x2F,0x00 }, mxf_read_metadata_preface },
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
930 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x18,0x00 }, mxf_read_metadata_content_storage },
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
931 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x37,0x00 }, mxf_read_metadata_source_package },
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
932 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x36,0x00 }, mxf_read_metadata_material_package },
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
933 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x0F,0x00 }, mxf_read_metadata_sequence },
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
934 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x11,0x00 }, mxf_read_metadata_source_clip },
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
935 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x44,0x00 }, mxf_read_metadata_multiple_descriptor },
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
936 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x42,0x00 }, mxf_read_metadata_generic_descriptor }, /* Generic Sound */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
937 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x28,0x00 }, mxf_read_metadata_generic_descriptor }, /* CDCI */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
938 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x29,0x00 }, mxf_read_metadata_generic_descriptor }, /* RGBA */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
939 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 }, mxf_read_metadata_generic_descriptor }, /* MPEG 2 Video */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
940 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 }, mxf_read_metadata_generic_descriptor }, /* Wave */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
941 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 }, mxf_read_metadata_generic_descriptor }, /* AES3 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
942 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3A,0x00 }, mxf_read_metadata_track }, /* Static Track */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
943 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3B,0x00 }, mxf_read_metadata_track }, /* Generic Track */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
944 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, NULL },
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
945 };
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
946
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
947 static int mxf_read_sync(ByteIOContext *pb, const uint8_t *key, unsigned size)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
948 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
949 int i, b;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
950 for (i = 0; i < size && !url_feof(pb); i++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
951 b = get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
952 if (b == key[0])
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
953 i = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
954 else if (b != key[i])
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
955 i = -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
956 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
957 return i == size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
958 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
959
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
960 static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
961 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
962 MXFContext *mxf = s->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
963 KLVPacket klv;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
964
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
965 if (!mxf_read_sync(&s->pb, mxf_header_partition_pack_key, 14)) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
966 av_log(s, AV_LOG_ERROR, "could not find header partition pack key\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
967 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
968 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
969 url_fseek(&s->pb, -14, SEEK_CUR);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
970 mxf->fc = s;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
971 while (!url_feof(&s->pb)) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
972 const MXFMetadataReadTableEntry *function;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
973
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
974 if (klv_read_packet(&klv, &s->pb) < 0) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
975 av_log(s, AV_LOG_ERROR, "error reading KLV packet\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
976 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
977 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
978 #ifdef DEBUG
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
979 PRINT_KEY("read header", klv.key);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
980 #endif
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
981 if (IS_KLV_KEY(klv.key, mxf_essence_element_key)) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
982 /* FIXME avoid seek */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
983 url_fseek(&s->pb, klv.offset, SEEK_SET);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
984 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
985 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
986
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
987 for (function = mxf_metadata_read_table; function->read; function++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
988 if (IS_KLV_KEY(klv.key, function->key)) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
989 if (function->read(mxf, &klv) < 0) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
990 av_log(s, AV_LOG_ERROR, "error reading header metadata\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
991 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
992 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
993 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
994 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
995 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
996 if (!function->read)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
997 url_fskip(&s->pb, klv.length);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
998 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
999 return mxf_parse_structural_metadata(mxf);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1000 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1001
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1002 static int mxf_read_close(AVFormatContext *s)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1003 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1004 MXFContext *mxf = s->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1005 int i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1006
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1007 av_freep(&mxf->packages_refs);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1008 av_freep(&mxf->essence_container_data_sets_refs);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1009 av_freep(&mxf->essence_containers_uls);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1010 for (i = 0; i < mxf->metadata_sets_count; i++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1011 switch (mxf->metadata_sets[i]->type) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1012 case MultipleDescriptor:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1013 av_freep(&((MXFDescriptor *)mxf->metadata_sets[i])->sub_descriptors_refs);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1014 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1015 case Sequence:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1016 av_freep(&((MXFSequence *)mxf->metadata_sets[i])->structural_components_refs);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1017 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1018 case SourcePackage:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1019 case MaterialPackage:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1020 av_freep(&((MXFPackage *)mxf->metadata_sets[i])->tracks_refs);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1021 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1022 default:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1023 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1024 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1025 av_freep(&mxf->metadata_sets[i]);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1026 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1027 av_freep(&mxf->metadata_sets);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1028 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1029 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1030
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1031 static int mxf_probe(AVProbeData *p) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1032 uint8_t *bufp = p->buf;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1033 uint8_t *end = p->buf + p->buf_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1034
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1035 if (p->buf_size < sizeof(mxf_header_partition_pack_key))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1036 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1037
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1038 /* Must skip Run-In Sequence and search for MXF header partition pack key SMPTE 377M 5.5 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1039 end -= sizeof(mxf_header_partition_pack_key);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1040 for (; bufp < end; bufp++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1041 if (IS_KLV_KEY(bufp, mxf_header_partition_pack_key))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1042 return AVPROBE_SCORE_MAX;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1043 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1044 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1045 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1046
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1047 /* rudimentary binary seek */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1048 /* XXX: use MXF Index */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1049 static int mxf_read_seek(AVFormatContext *s, int stream_index, int64_t sample_time, int flags)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1050 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1051 AVStream *st = s->streams[stream_index];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1052 int64_t seconds;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1053
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1054 if (!s->bit_rate)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1055 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1056 if (sample_time < 0)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1057 sample_time = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1058 seconds = av_rescale(sample_time, st->time_base.num, st->time_base.den);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1059 url_fseek(&s->pb, (s->bit_rate * seconds) >> 3, SEEK_SET);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1060 if (!mxf_read_sync(&s->pb, mxf_essence_element_key, 12))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1061 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1062
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1063 /* found KLV key */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1064 url_fseek(&s->pb, -12, SEEK_CUR);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1065 av_update_cur_dts(s, st, sample_time);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1066 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1067 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1068
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1069 AVInputFormat mxf_demuxer = {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1070 "mxf",
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1071 "MXF format",
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1072 sizeof(MXFContext),
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1073 mxf_probe,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1074 mxf_read_header,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1075 mxf_read_packet,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1076 mxf_read_close,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1077 mxf_read_seek,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1078 };