annotate mxf.c @ 1191:976a91cec1ad libavformat

add error messages
author bcoudurier
date Fri, 28 Jul 2006 22:53:15 +0000
parents 03c0b0e61e5b
children ad731bdb7365
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 *
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
37 * Metadata reading functions read Local Tags, get InstanceUID(0x3C0A) and then resolve Strong Reference from another object.
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
38 * Returns -1 if Strong Reference could not be resolved.
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
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
42 * Only descriptors with EssenceSoundCompression or PictureEssenceCoding will be taken into account. "D/req" SMPTE 377M
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
43 */
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
44
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
45 //#define DEBUG
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
46
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
47 #include "avformat.h"
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
48 #include "dsputil.h"
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
49
1189
fb1a9ccffe89 declare and use UID type
bcoudurier
parents: 1188
diff changeset
50 typedef DECLARE_ALIGNED_16(uint8_t, UID[16]);
fb1a9ccffe89 declare and use UID type
bcoudurier
parents: 1188
diff changeset
51
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
52 enum MXFPackageType {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
53 MaterialPackage,
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
54 SourcePackage,
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
55 };
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
56
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
57 enum MXFStructuralComponentType {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
58 Timecode,
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
59 SourceClip,
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;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
64 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
65 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
66 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
67 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
68 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
69 enum MXFStructuralComponentType type;
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;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
74 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
75 MXFStructuralComponent **structural_components;
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;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
83 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
84 UID sequence_ref;
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
85 int track_id;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
86 int track_number;
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
87 AVRational edit_rate;
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
88 } MXFTrack;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
89
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
90 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
91 UID uid;
1189
fb1a9ccffe89 declare and use UID type
bcoudurier
parents: 1188
diff changeset
92 UID essence_container;
fb1a9ccffe89 declare and use UID type
bcoudurier
parents: 1188
diff changeset
93 UID essence_compression;
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
94 enum CodecType codec_type;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
95 AVRational sample_rate;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
96 AVRational aspect_ratio;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
97 int width;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
98 int height;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
99 int channels;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
100 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
101 struct MXFDescriptor **sub_descriptors;
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 block_align;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
105 int linked_track_id;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
106 } MXFDescriptor;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
107
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
108 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
109 UID uid;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
110 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
111 MXFTrack **tracks;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
112 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
113 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
114 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
115 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
116 enum MXFPackageType type;
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;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
121 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
122 } MXFEssenceContainerData;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
123
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
124 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
125 MXFPackage **packages;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
126 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
127 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
128 MXFEssenceContainerData **essence_container_data_sets;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
129 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
130 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
131 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
132 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
133 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
134 UID content_storage_uid;
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
135 AVFormatContext *fc;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
136 } MXFContext;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
137
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
138 typedef struct KLVPacket {
1189
fb1a9ccffe89 declare and use UID type
bcoudurier
parents: 1188
diff changeset
139 UID key;
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
140 offset_t offset;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
141 uint64_t length;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
142 } KLVPacket;
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 MXFCodecUL {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
145 UID uid;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
146 enum CodecID id;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
147 } MXFCodecUL;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
148
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
149 static const UID mxf_metadata_preface_key = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x2F, 0x00 };
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
150 static const UID mxf_metadata_content_storage_key = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x18, 0x00 };
1189
fb1a9ccffe89 declare and use UID type
bcoudurier
parents: 1188
diff changeset
151 static const UID mxf_metadata_source_package_key = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x37, 0x00 };
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
152 static const UID mxf_metadata_material_package_key = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x36, 0x00 };
1189
fb1a9ccffe89 declare and use UID type
bcoudurier
parents: 1188
diff changeset
153 static const UID mxf_metadata_sequence_key = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0F, 0x00 };
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
154 static const UID mxf_metadata_source_clip_key = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x11, 0x00 };
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
155 static const UID mxf_metadata_multiple_descriptor_key = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x44, 0x00 };
1189
fb1a9ccffe89 declare and use UID type
bcoudurier
parents: 1188
diff changeset
156 static const UID mxf_metadata_generic_sound_descriptor_key = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x42, 0x00 };
fb1a9ccffe89 declare and use UID type
bcoudurier
parents: 1188
diff changeset
157 static const UID mxf_metadata_cdci_descriptor_key = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x28, 0x00 };
fb1a9ccffe89 declare and use UID type
bcoudurier
parents: 1188
diff changeset
158 static const UID mxf_metadata_mpegvideo_descriptor_key = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x51, 0x00 };
fb1a9ccffe89 declare and use UID type
bcoudurier
parents: 1188
diff changeset
159 static const UID mxf_metadata_wave_descriptor_key = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x48, 0x00 };
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
160 static const UID mxf_metadata_static_track_key = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x3A, 0x00 };
1189
fb1a9ccffe89 declare and use UID type
bcoudurier
parents: 1188
diff changeset
161 static const UID mxf_metadata_track_key = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x3b, 0x00 };
fb1a9ccffe89 declare and use UID type
bcoudurier
parents: 1188
diff changeset
162
fb1a9ccffe89 declare and use UID type
bcoudurier
parents: 1188
diff changeset
163 /* partial keys to match */
fb1a9ccffe89 declare and use UID type
bcoudurier
parents: 1188
diff changeset
164 static const uint8_t mxf_header_partition_pack_key[] = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01, 0x01, 0x02 };
fb1a9ccffe89 declare and use UID type
bcoudurier
parents: 1188
diff changeset
165 static const uint8_t mxf_essence_element_key[] = { 0x06, 0x0e, 0x2b, 0x34, 0x01, 0x02, 0x01 };
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
166
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
167 #define IS_KLV_KEY(x, y) (!memcmp(x, y, sizeof(y)))
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
168
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
169 #define PRINT_KEY(x) \
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
170 do { \
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
171 int iterpk; \
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
172 for (iterpk = 0; iterpk < 16; iterpk++) { \
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
173 av_log(NULL, AV_LOG_DEBUG, "%02X ", x[iterpk]); \
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
174 } \
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
175 av_log(NULL, AV_LOG_DEBUG, "\n"); \
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
176 } while (0); \
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
177
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
178 static int64_t klv_decode_ber_length(ByteIOContext *pb)
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
179 {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
180 int64_t size = 0;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
181 uint8_t length = get_byte(pb);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
182 int type = length >> 7;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
183
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
184 if (type) { /* long form */
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
185 int bytes_num = length & 0x7f;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
186 /* SMPTE 379M 5.3.4 guarantee that bytes_num must not exceed 8 bytes */
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
187 if (bytes_num > 8)
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
188 return -1;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
189 while (bytes_num--)
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
190 size = size << 8 | get_byte(pb);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
191 } else {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
192 size = length & 0x7f;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
193 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
194 return size;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
195 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
196
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
197 static int klv_read_packet(KLVPacket *klv, ByteIOContext *pb)
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
198 {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
199 klv->offset = url_ftell(pb);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
200 get_buffer(pb, klv->key, 16);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
201 klv->length = klv_decode_ber_length(pb);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
202 if (klv->length == -1)
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
203 return -1;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
204 else
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
205 return 0;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
206 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
207
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
208 static int mxf_get_stream_index(AVFormatContext *s, KLVPacket *klv)
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
209 {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
210 int id = BE_32(klv->key + 12); /* SMPTE 379M 7.3 */
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
211 int i;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
212
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
213 for (i = 0; i < s->nb_streams; i++) {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
214 if (s->streams[i]->id == id)
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
215 return i;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
216 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
217 return -1;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
218 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
219
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
220 static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt)
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
221 {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
222 KLVPacket klv;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
223
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
224 while (!url_feof(&s->pb)) {
1191
976a91cec1ad add error messages
bcoudurier
parents: 1190
diff changeset
225 if (klv_read_packet(&klv, &s->pb) < 0) {
976a91cec1ad add error messages
bcoudurier
parents: 1190
diff changeset
226 av_log(s, AV_LOG_ERROR, "error reading KLV packet\n");
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
227 return -1;
1191
976a91cec1ad add error messages
bcoudurier
parents: 1190
diff changeset
228 }
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
229 if (IS_KLV_KEY(klv.key, mxf_essence_element_key)) {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
230 av_get_packet(&s->pb, pkt, klv.length);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
231 pkt->stream_index = mxf_get_stream_index(s, &klv);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
232 if (pkt->stream_index == -1)
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
233 return -1;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
234 return 0;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
235 } else
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
236 url_fskip(&s->pb, klv.length);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
237 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
238 return AVERROR_IO;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
239 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
240
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
241 static int mxf_read_metadata_preface(MXFContext *mxf, KLVPacket *klv)
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
242 {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
243 ByteIOContext *pb = &mxf->fc->pb;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
244 int bytes_read = 0;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
245
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
246 while (bytes_read < klv->length) {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
247 int tag = get_be16(pb);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
248 int size = get_be16(pb); /* SMPTE 336M Table 8 KLV specified length, 0x53 */
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
249
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
250 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
251 case 0x3B03:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
252 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
253 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
254 case 0x3B09:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
255 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
256 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
257 case 0x3B0A:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
258 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
259 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
260 return -1;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
261 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
262 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
263 get_buffer(pb, mxf->essence_containers_uls, mxf->essence_containers_uls_count * sizeof(UID));
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
264 break;
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
265 default:
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, size);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
267 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
268 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
269 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
270 return 0;
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
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
273 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
274 {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
275 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
276 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
277
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
278 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
279 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
280 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
281
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
282 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
283 switch (tag) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
284 case 0x1901:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
285 mxf->packages_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
286 if (mxf->packages_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
287 mxf->packages_count >= UINT_MAX / sizeof(*mxf->packages))
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
288 return -1;
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_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
290 mxf->packages = av_mallocz(mxf->packages_count * sizeof(*mxf->packages));
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
291 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
292 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
293 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
294 case 0x1902:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
295 mxf->essence_container_data_sets_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
296 if (mxf->essence_container_data_sets_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
297 mxf->essence_container_data_sets_count >= UINT_MAX / sizeof(*mxf->essence_container_data_sets))
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
298 return -1;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
299 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
300 mxf->essence_container_data_sets = av_mallocz(mxf->essence_container_data_sets_count * sizeof(*mxf->essence_container_data_sets));
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 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
318
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
319 source_clip->type = SourceClip;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
320 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
321 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
322 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
323
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
324 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
325 switch (tag) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
326 case 0x3C0A:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
327 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
328 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
329 case 0x0202:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
330 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
331 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
332 case 0x1201:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
333 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
334 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
335 case 0x1101:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
336 /* 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
337 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
338 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
339 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
340 case 0x1102:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
341 source_clip->source_track_id = get_be32(pb);
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
342 break;
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
343 default:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
344 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
345 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
346 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
347 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
348 for (i = 0; i < mxf->packages_count; i++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
349 if (mxf->packages[i]) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
350 for (j = 0; j < mxf->packages[i]->tracks_count; j++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
351 if (mxf->packages[i]->tracks[j] && mxf->packages[i]->tracks[j]->sequence) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
352 for (k = 0; k < mxf->packages[i]->tracks[j]->sequence->structural_components_count; k++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
353 if (!memcmp(mxf->packages[i]->tracks[j]->sequence->structural_components_refs[k], 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
354 mxf->packages[i]->tracks[j]->sequence->structural_components[k] = source_clip;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
355 return 0;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
356 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
357 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
358 }
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 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
361 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
362 return -1;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
363 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
364
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
365 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
366 {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
367 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
368 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
369 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
370 int i;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
371
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
372 package->type = MaterialPackage;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
373 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
374 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
375 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
376
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
377 switch (tag) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
378 case 0x3C0A:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
379 get_buffer(pb, package->uid, 16);
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
380 break;
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
381 case 0x4403:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
382 package->tracks_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
383 if (package->tracks_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
384 package->tracks_count >= UINT_MAX / sizeof(*package->tracks))
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
385 return -1;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
386 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
387 package->tracks = av_mallocz(package->tracks_count * sizeof(*package->tracks));
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
388 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
389 get_buffer(pb, package->tracks_refs, package->tracks_count * sizeof(UID));
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
390 break;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
391 default:
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
392 url_fskip(pb, size);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
393 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
394 bytes_read += size + 4;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
395 }
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
396 for (i = 0; i < mxf->packages_count; i++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
397 if (!memcmp(mxf->packages_refs[i], 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
398 mxf->packages[i] = package;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
399 return 0;
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
400 }
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
401 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
402 return -1;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
403 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
404
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
405 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
406 {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
407 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
408 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
409 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
410 int i, j;
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 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
413 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
414 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
415
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
416 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
417 switch (tag) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
418 case 0x3C0A:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
419 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
420 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
421 case 0x4801:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
422 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
423 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
424 case 0x4804:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
425 track->track_number = 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
426 dprintf("track number 0x%04X\n", track->track_number);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
427 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
428 case 0x4B01:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
429 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
430 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
431 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
432 case 0x4803:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
433 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
434 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
435 default:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
436 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
437 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
438 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
439 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
440 for (i = 0; i < mxf->packages_count; i++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
441 if (mxf->packages[i]) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
442 for (j = 0; j < mxf->packages[i]->tracks_count; j++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
443 if (!memcmp(mxf->packages[i]->tracks_refs[j], 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
444 mxf->packages[i]->tracks[j] = track;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
445 return 0;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
446 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
447 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
448 }
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 return -1;
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
451 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
452
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
453 static int mxf_read_metadata_sequence(MXFContext *mxf, KLVPacket *klv)
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
454 {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
455 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
456 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
457 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
458 int i, j;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
459
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
460 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
461 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
462 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
463
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
464 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
465 switch (tag) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
466 case 0x3C0A:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
467 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
468 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
469 case 0x0202:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
470 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
471 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
472 case 0x0201:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
473 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
474 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
475 case 0x1001:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
476 sequence->structural_components_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
477 if (sequence->structural_components_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
478 sequence->structural_components_count >= UINT_MAX / sizeof(*sequence->structural_components))
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
479 return -1;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
480 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
481 sequence->structural_components = av_mallocz(sequence->structural_components_count * sizeof(*sequence->structural_components));
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
482 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
483 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
484 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
485 default:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
486 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
487 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
488 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
489 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
490 for (i = 0; i < mxf->packages_count; i++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
491 if (mxf->packages[i]) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
492 for (j = 0; j < mxf->packages[i]->tracks_count; j++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
493 if (mxf->packages[i]->tracks[j]) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
494 if (!memcmp(mxf->packages[i]->tracks[j]->sequence_ref, 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
495 mxf->packages[i]->tracks[j]->sequence = sequence;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
496 return 0;
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 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
499 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
500 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
501 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
502 return -1;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
503 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
504
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
505 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
506 {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
507 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
508 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
509 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
510 int i;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
511
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
512 package->type = SourcePackage;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
513 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
514 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
515 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
516
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
517 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
518 switch (tag) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
519 case 0x3C0A:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
520 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
521 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
522 case 0x4403:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
523 package->tracks_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
524 if (package->tracks_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
525 package->tracks_count >= UINT_MAX / sizeof(*package->tracks))
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
526 return -1;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
527 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
528 package->tracks = av_mallocz(package->tracks_count * sizeof(*package->tracks));
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
529 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
530 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
531 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
532 case 0x4401:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
533 /* 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
534 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
535 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
536 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
537 case 0x4701:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
538 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
539 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
540 default:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
541 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
542 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
543 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
544 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
545 for (i = 0; i < mxf->packages_count; i++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
546 if (!memcmp(mxf->packages_refs[i], 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
547 mxf->packages[i] = package;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
548 return 0;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
549 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
550 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
551 return -1;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
552 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
553
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
554 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
555 {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
556 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
557 MXFDescriptor *descriptor = av_mallocz(sizeof(*descriptor));
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
558 int bytes_read = 0;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
559 int i;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
560
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
561 while (bytes_read < klv->length) {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
562 int tag = get_be16(pb);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
563 int size = get_be16(pb); /* KLV specified by 0x53 */
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
564
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
565 dprintf("tag 0x%04X, size %d\n", tag, size);
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
566 switch (tag) {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
567 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
568 get_buffer(pb, descriptor->uid, 16);
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
569 break;
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
570 case 0x3F01:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
571 descriptor->sub_descriptors_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
572 if (descriptor->sub_descriptors_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
573 descriptor->sub_descriptors_count >= UINT_MAX / sizeof(*descriptor->sub_descriptors))
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
574 return -1;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
575 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
576 descriptor->sub_descriptors = av_mallocz(descriptor->sub_descriptors_count * sizeof(*descriptor->sub_descriptors));
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
577 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
578 get_buffer(pb, descriptor->sub_descriptors_refs, descriptor->sub_descriptors_count * sizeof(UID));
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
579 break;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
580 default:
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
581 url_fskip(pb, size);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
582 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
583 bytes_read += size + 4;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
584 }
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
585 for (i = 0; i < mxf->packages_count; i++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
586 if (mxf->packages[i]) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
587 if (!memcmp(mxf->packages[i]->descriptor_ref, descriptor->uid, 16)) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
588 mxf->packages[i]->descriptor = descriptor;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
589 return 0;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
590 }
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
591 }
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
592 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
593 return -1;
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
594 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
595
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
596 static int mxf_read_metadata_generic_descriptor(MXFContext *mxf, KLVPacket *klv)
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
597 {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
598 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
599 MXFDescriptor *desc = av_mallocz(sizeof(*desc));
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
600 int bytes_read = 0;
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
601 int i, j;
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
602
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
603 while (bytes_read < klv->length) {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
604 int tag = get_be16(pb);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
605 int size = get_be16(pb); /* KLV specified by 0x53 */
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
606
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
607 dprintf("tag 0x%04X, size %d\n", tag, size);
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
608 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
609 case 0x3C0A:
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
610 get_buffer(pb, desc->uid, 16);
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
611 break;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
612 case 0x3004:
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
613 get_buffer(pb, desc->essence_container, 16);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
614 break;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
615 case 0x3006:
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
616 desc->linked_track_id = get_be32(pb);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
617 break;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
618 case 0x3201: /* PictureEssenceCoding */
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
619 desc->codec_type = CODEC_TYPE_VIDEO;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
620 get_buffer(pb, desc->essence_compression, 16);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
621 break;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
622 case 0x3203:
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
623 desc->width = get_be32(pb);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
624 break;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
625 case 0x3202:
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
626 desc->height = get_be32(pb);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
627 break;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
628 case 0x320E:
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
629 desc->aspect_ratio.num = get_be32(pb);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
630 desc->aspect_ratio.den = get_be32(pb);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
631 break;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
632 case 0x3D0A:
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
633 desc->block_align = get_be16(pb);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
634 break;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
635 case 0x3D03:
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
636 desc->sample_rate.num = get_be32(pb);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
637 desc->sample_rate.den = get_be32(pb);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
638 break;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
639 case 0x3D06: /* SoundEssenceCompression */
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
640 desc->codec_type = CODEC_TYPE_AUDIO;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
641 get_buffer(pb, desc->essence_compression, 16);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
642 break;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
643 case 0x3D07:
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
644 desc->channels = get_be32(pb);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
645 break;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
646 case 0x3D01:
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
647 desc->bits_per_sample = get_be32(pb);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
648 break;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
649 default:
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
650 url_fskip(pb, size);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
651 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
652 bytes_read += size + 4;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
653 }
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
654 for (i = 0; i < mxf->packages_count; i++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
655 if (mxf->packages[i]) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
656 if (!memcmp(mxf->packages[i]->descriptor_ref, desc->uid, 16)) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
657 mxf->packages[i]->descriptor = desc;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
658 return 0;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
659 } else if (mxf->packages[i]->descriptor) { /* MultipleDescriptor */
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
660 for (j = 0; j < mxf->packages[i]->descriptor->sub_descriptors_count; j++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
661 if (!memcmp(mxf->packages[i]->descriptor->sub_descriptors_refs[j], desc->uid, 16)) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
662 mxf->packages[i]->descriptor->sub_descriptors[j] = desc;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
663 return 0;
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
664 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
665 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
666 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
667 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
668 }
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
669 return -1;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
670 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
671
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
672 /* 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
673 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
674 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
675
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
676 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
677 /* PictureEssenceCoding */
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
678 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x02,0x00 }, CODEC_ID_MPEG2VIDEO }, /* I-Frame */
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
679 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x03,0x00 }, CODEC_ID_MPEG2VIDEO }, /* Long GoP */
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
680 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x03,0x00 }, CODEC_ID_MPEG2VIDEO }, /* Long GoP */
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
681 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x05 }, CODEC_ID_MPEG2VIDEO }, /* D-10 30Mbps PAL */
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
682 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x01 }, CODEC_ID_MPEG2VIDEO }, /* D-10 50Mbps PAL */
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
683 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x04,0x00 }, CODEC_ID_DVVIDEO }, /* DVCPRO50 PAL */
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
684 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x02,0x00 }, CODEC_ID_DVVIDEO }, /* DVCPRO25 PAL */
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
685 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x01,0x02,0x00 }, CODEC_ID_DVVIDEO }, /* DV25 IEC PAL */
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
686 /* SoundEssenceCompression */
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
687 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x7F,0x00,0x00,0x00 }, 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
688 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x07,0x04,0x02,0x02,0x01,0x7E,0x00,0x00,0x00 }, CODEC_ID_PCM_S16BE }, /* From Omneon MXF file */
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
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
691 static enum CodecID mxf_get_codec_id(const MXFCodecUL *uls, UID *uid)
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
692 {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
693 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
694 if(!memcmp(uls->uid, *uid, 16))
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
695 return uls->id;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
696 uls++;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
697 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
698 return 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
699 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
700
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
701 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
702 {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
703 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
704 MXFPackage *source_package = NULL;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
705 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
706
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
707 /* 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
708 for (i = 0; i < mxf->packages_count; i++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
709 if (mxf->packages[i]->type == MaterialPackage) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
710 material_package = mxf->packages[i];
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
711 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
712 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
713 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
714 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
715 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
716 return -1;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
717 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
718
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
719 for (i = 0; i < material_package->tracks_count; i++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
720 MXFTrack *material_track = material_package->tracks[i];
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
721 MXFTrack *source_track = NULL;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
722 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
723 MXFStructuralComponent *component = NULL;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
724 AVStream *st;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
725
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
726 /* 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
727 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
728 component = material_track->sequence->structural_components[j];
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
729 /* TODO: handle timecode component */
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
730 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
731 continue;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
732
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
733 for (k = 0; k < mxf->packages_count; k++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
734 if (!memcmp(mxf->packages[k]->package_uid, component->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
735 source_package = mxf->packages[k];
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
736 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
737 }
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 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
740 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
741 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
742 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
743 for (k = 0; k < source_package->tracks_count; k++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
744 if (source_package->tracks[k]->track_id == component->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
745 source_track = source_package->tracks[k];
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_track) {
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 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
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 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
754 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
755 continue;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
756
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
757 st = av_new_stream(mxf->fc, source_track->track_number);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
758 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
759 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
760 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
761 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
762 av_set_pts_info(st, 64, material_track->edit_rate.num, material_track->edit_rate.den);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
763 #ifdef DEBUG
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
764 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
765 #endif
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
766 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
767 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
768 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
769 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
770 else
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
771 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
772
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
773 if (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
774 if (source_package->descriptor->sub_descriptors_count > 0) { /* SourcePackage has MultipleDescriptor */
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
775 for (j = 0; j < source_package->descriptor->sub_descriptors_count; j++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
776 if (source_package->descriptor->sub_descriptors[j]) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
777 if (source_package->descriptor->sub_descriptors[j]->linked_track_id == source_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
778 descriptor = source_package->descriptor->sub_descriptors[j];
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
779 break;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
780 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
781 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
782 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
783 } else {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
784 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
785 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
786 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
787 if (!descriptor) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
788 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
789 continue;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
790 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
791 #ifdef DEBUG
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
792 PRINT_KEY(descriptor->essence_compression);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
793 #endif
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
794 st->codec->codec_id = mxf_get_codec_id(mxf_codec_uls, &descriptor->essence_compression);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
795 if (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
796 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
797 st->codec->height = descriptor->height;
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
798 } else if (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
799 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
800 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
801 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
802 /* 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
803 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
804 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
805 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
806 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
807 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
808 } 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
809 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
810 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
811 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
812 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
813 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
814 }
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 return 0;
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
817 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
818
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
819 static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap)
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
820 {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
821 MXFContext *mxf = s->priv_data;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
822 KLVPacket klv;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
823 int ret = 0;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
824
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
825 mxf->fc = s;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
826 while (!url_feof(&s->pb)) {
1191
976a91cec1ad add error messages
bcoudurier
parents: 1190
diff changeset
827 if (klv_read_packet(&klv, &s->pb) < 0) {
976a91cec1ad add error messages
bcoudurier
parents: 1190
diff changeset
828 av_log(s, AV_LOG_ERROR, "error reading KLV packet\n");
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
829 return -1;
1191
976a91cec1ad add error messages
bcoudurier
parents: 1190
diff changeset
830 }
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
831 if (IS_KLV_KEY(klv.key, mxf_metadata_track_key))
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
832 ret = mxf_read_metadata_track(mxf, &klv);
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
833 else if (IS_KLV_KEY(klv.key, mxf_metadata_static_track_key))
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
834 ret = mxf_read_metadata_track(mxf, &klv);
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
835 else if (IS_KLV_KEY(klv.key, mxf_metadata_source_package_key))
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
836 ret = mxf_read_metadata_source_package(mxf, &klv);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
837 else if (IS_KLV_KEY(klv.key, mxf_metadata_sequence_key))
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
838 ret = mxf_read_metadata_sequence(mxf, &klv);
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
839 else if (IS_KLV_KEY(klv.key, mxf_metadata_material_package_key))
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
840 ret = mxf_read_metadata_material_package(mxf, &klv);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
841 else if (IS_KLV_KEY(klv.key, mxf_metadata_source_clip_key))
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
842 ret = mxf_read_metadata_source_clip(mxf, &klv);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
843 else if (IS_KLV_KEY(klv.key, mxf_metadata_multiple_descriptor_key))
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
844 ret = mxf_read_metadata_multiple_descriptor(mxf, &klv);
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
845 else if (IS_KLV_KEY(klv.key, mxf_metadata_wave_descriptor_key))
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
846 ret = mxf_read_metadata_generic_descriptor(mxf, &klv);
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
847 else if (IS_KLV_KEY(klv.key, mxf_metadata_mpegvideo_descriptor_key))
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
848 ret = mxf_read_metadata_generic_descriptor(mxf, &klv);
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
849 else if (IS_KLV_KEY(klv.key, mxf_metadata_cdci_descriptor_key))
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
850 ret = mxf_read_metadata_generic_descriptor(mxf, &klv);
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
851 else if (IS_KLV_KEY(klv.key, mxf_metadata_generic_sound_descriptor_key))
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
852 ret = mxf_read_metadata_generic_descriptor(mxf, &klv);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
853 else if (IS_KLV_KEY(klv.key, mxf_metadata_preface_key))
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
854 ret = mxf_read_metadata_preface(mxf, &klv);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
855 else if (IS_KLV_KEY(klv.key, mxf_metadata_content_storage_key))
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
856 ret = mxf_read_metadata_content_storage(mxf, &klv);
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
857 else if (IS_KLV_KEY(klv.key, mxf_essence_element_key)) {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
858 /* FIXME avoid seek */
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
859 url_fseek(&s->pb, klv.offset, SEEK_SET);
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
860 break;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
861 } else
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
862 url_fskip(&s->pb, klv.length);
1191
976a91cec1ad add error messages
bcoudurier
parents: 1190
diff changeset
863 if (ret < 0) {
976a91cec1ad add error messages
bcoudurier
parents: 1190
diff changeset
864 av_log(s, AV_LOG_ERROR, "error reading header metadata\n");
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
865 return ret;
1191
976a91cec1ad add error messages
bcoudurier
parents: 1190
diff changeset
866 }
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
867 }
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
868 return mxf_parse_structural_metadata(mxf);
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
869 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
870
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
871 static int mxf_read_close(AVFormatContext *s)
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
872 {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
873 MXFContext *mxf = s->priv_data;
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
874 int i, j, k;
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
875
1190
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
876 for (i = 0; i < mxf->packages_count; i++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
877 for (j = 0; j < mxf->packages[i]->tracks_count; j++) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
878 for (k = 0; k < mxf->packages[i]->tracks[j]->sequence->structural_components_count; k++)
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
879 av_freep(&mxf->packages[i]->tracks[j]->sequence->structural_components[k]);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
880 av_freep(&mxf->packages[i]->tracks[j]->sequence->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
881 av_freep(&mxf->packages[i]->tracks[j]->sequence->structural_components);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
882 av_freep(&mxf->packages[i]->tracks[j]->sequence);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
883 av_freep(&mxf->packages[i]->tracks[j]);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
884 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
885 av_freep(&mxf->packages[i]->tracks_refs);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
886 av_freep(&mxf->packages[i]->tracks);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
887 if (mxf->packages[i]->descriptor) {
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
888 for (k = 0; k < mxf->packages[i]->descriptor->sub_descriptors_count; k++)
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
889 av_freep(&mxf->packages[i]->descriptor->sub_descriptors[k]);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
890 av_freep(&mxf->packages[i]->descriptor->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
891 av_freep(&mxf->packages[i]->descriptor->sub_descriptors);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
892 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
893 av_freep(&mxf->packages[i]->descriptor);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
894 av_freep(&mxf->packages[i]);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
895 }
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
896 av_freep(&mxf->packages_refs);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
897 av_freep(&mxf->packages);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
898 for (i = 0; i < mxf->essence_container_data_sets_count; i++)
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
899 av_freep(&mxf->essence_container_data_sets[i]);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
900 av_freep(&mxf->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
901 av_freep(&mxf->essence_container_data_sets);
03c0b0e61e5b demuxer reworked, more accurate parsing, prepare handling of other operational patterns, streaming demuxing, simplified codec detection
bcoudurier
parents: 1189
diff changeset
902 av_freep(&mxf->essence_containers_uls);
1186
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
903 return 0;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
904 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
905
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
906 static int mxf_probe(AVProbeData *p) {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
907 /* KLV packet describing MXF header partition pack */
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
908 if (p->buf_size < sizeof(mxf_header_partition_pack_key))
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
909 return 0;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
910
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
911 if (IS_KLV_KEY(p->buf, mxf_header_partition_pack_key))
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
912 return AVPROBE_SCORE_MAX;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
913 else
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
914 return 0;
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
915 }
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
916
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
917
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
918 AVInputFormat mxf_demuxer = {
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
919 "mxf",
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
920 "MXF format",
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
921 sizeof(MXFContext),
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
922 mxf_probe,
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
923 mxf_read_header,
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
924 mxf_read_packet,
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
925 mxf_read_close,
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
926 NULL,
fbdd53c2a12d MXF demuxer
bcoudurier
parents:
diff changeset
927 };