annotate mxf.c @ 1250:0492aa3dffc9 libavformat

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