Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * MXF muxer | ||
3 | * Copyright (c) 2008 GUCAS, Zhentan Feng <spyfeng at gmail dot com> | ||
4 | * Copyright (c) 2008 Baptiste Coudurier <baptiste dot coudurier at gmail dot com> | ||
5 | * | ||
6 | * This file is part of FFmpeg. | ||
7 | * | ||
8 | * FFmpeg is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU Lesser General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2.1 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * FFmpeg is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with FFmpeg; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | |||
23 | /* | ||
24 | * signal_standard, color_siting, store_user_comments, sample rate and klv_fill_key version | ||
25 | * fixes sponsored by NOA GmbH | ||
26 | */ | ||
27 | |||
28 | /* | ||
29 | * References | ||
30 | * SMPTE 336M KLV Data Encoding Protocol Using Key-Length-Value | ||
31 | * SMPTE 377M MXF File Format Specifications | ||
32 | * SMPTE 379M MXF Generic Container | ||
33 | * SMPTE 381M Mapping MPEG Streams into the MXF Generic Container | ||
34 | * SMPTE 422M Mapping JPEG 2000 Codestreams into the MXF Generic Container | ||
35 | * SMPTE ST2019-4 (2009 or later) Mapping VC-3 Coding Units into the MXF Generic Container | ||
36 | * SMPTE RP210: SMPTE Metadata Dictionary | ||
37 | * SMPTE RP224: Registry of SMPTE Universal Labels | ||
38 | */ | ||
39 | |||
40 | #include <inttypes.h> | ||
41 | #include <time.h> | ||
42 | |||
43 | #include "libavutil/mem.h" | ||
44 | #include "libavutil/opt.h" | ||
45 | #include "libavutil/random_seed.h" | ||
46 | #include "libavutil/timecode.h" | ||
47 | #include "libavutil/avassert.h" | ||
48 | #include "libavutil/mastering_display_metadata.h" | ||
49 | #include "libavutil/pixdesc.h" | ||
50 | #include "libavutil/time_internal.h" | ||
51 | #include "libavcodec/defs.h" | ||
52 | #include "libavcodec/bytestream.h" | ||
53 | #include "libavcodec/golomb.h" | ||
54 | #include "libavcodec/h264.h" | ||
55 | #include "libavcodec/jpeg2000.h" | ||
56 | #include "libavcodec/packet_internal.h" | ||
57 | #include "libavcodec/rangecoder.h" | ||
58 | #include "libavcodec/startcode.h" | ||
59 | #include "avformat.h" | ||
60 | #include "avio_internal.h" | ||
61 | #include "internal.h" | ||
62 | #include "avc.h" | ||
63 | #include "nal.h" | ||
64 | #include "mux.h" | ||
65 | #include "mxf.h" | ||
66 | #include "config.h" | ||
67 | #include "version.h" | ||
68 | |||
69 | extern const FFOutputFormat ff_mxf_d10_muxer; | ||
70 | extern const FFOutputFormat ff_mxf_opatom_muxer; | ||
71 | |||
72 | #define IS_D10(s) ((s)->oformat == &ff_mxf_d10_muxer.p) | ||
73 | #define IS_OPATOM(s) ((s)->oformat == &ff_mxf_opatom_muxer.p) | ||
74 | |||
75 | #define EDIT_UNITS_PER_BODY 250 | ||
76 | #define KAG_SIZE 512 | ||
77 | |||
78 | typedef struct MXFIndexEntry { | ||
79 | uint64_t offset; | ||
80 | unsigned slice_offset; ///< offset of audio slice | ||
81 | uint16_t temporal_ref; | ||
82 | uint8_t flags; | ||
83 | } MXFIndexEntry; | ||
84 | |||
85 | typedef struct j2k_info_t { | ||
86 | uint16_t j2k_cap; ///< j2k required decoder capabilities | ||
87 | uint16_t j2k_rsiz; ///< j2k required decoder capabilities (Rsiz) | ||
88 | uint32_t j2k_xsiz; ///< j2k width of the reference grid (Xsiz) | ||
89 | uint32_t j2k_ysiz; ///< j2k height of the reference grid (Ysiz) | ||
90 | uint32_t j2k_x0siz; ///< j2k horizontal offset from the origin of the reference grid to the left side of the image (X0siz) | ||
91 | uint32_t j2k_y0siz; ///< j2k vertical offset from the origin of the reference grid to the left side of the image (Y0siz) | ||
92 | uint32_t j2k_xtsiz; ///< j2k width of one reference tile with respect to the reference grid (XTsiz) | ||
93 | uint32_t j2k_ytsiz; ///< j2k height of one reference tile with respect to the reference grid (YTsiz) | ||
94 | uint32_t j2k_xt0siz; ///< j2k horizontal offset from the origin of the reference grid to the left side of the first tile (XT0siz) | ||
95 | uint32_t j2k_yt0siz; ///< j2k vertical offset from the origin of the reference grid to the left side of the first tile (YT0siz) | ||
96 | uint8_t j2k_comp_desc[12]; ///< j2k components descriptor (Ssiz(i), XRsiz(i), YRsiz(i)) | ||
97 | } j2k_info_t; | ||
98 | |||
99 | typedef struct MXFStreamContext { | ||
100 | int64_t pkt_cnt; ///< pkt counter for muxed packets | ||
101 | UID track_essence_element_key; | ||
102 | int index; ///< index in mxf_essence_container_uls table | ||
103 | const UID *codec_ul; | ||
104 | const UID *container_ul; | ||
105 | int order; ///< interleaving order if dts are equal | ||
106 | int interlaced; ///< whether picture is interlaced | ||
107 | int field_dominance; ///< tff=1, bff=2 | ||
108 | int component_depth; | ||
109 | int color_siting; | ||
110 | int signal_standard; | ||
111 | int h_chroma_sub_sample; | ||
112 | int v_chroma_sub_sample; | ||
113 | int temporal_reordering; | ||
114 | AVRational aspect_ratio; ///< display aspect ratio | ||
115 | int closed_gop; ///< gop is closed, used in mpeg-2 frame parsing | ||
116 | int video_bit_rate; | ||
117 | int slice_offset; | ||
118 | int frame_size; ///< frame size in bytes | ||
119 | int seq_closed_gop; ///< all gops in sequence are closed, used in mpeg-2 descriptor | ||
120 | int max_gop; ///< maximum gop size, used by mpeg-2 descriptor | ||
121 | int b_picture_count; ///< maximum number of consecutive b pictures, used in mpeg-2 descriptor | ||
122 | int low_delay; ///< low delay, used in mpeg-2 descriptor | ||
123 | int avc_intra; | ||
124 | int micro_version; ///< format micro_version, used in ffv1 descriptor | ||
125 | j2k_info_t j2k_info; | ||
126 | } MXFStreamContext; | ||
127 | |||
128 | typedef struct MXFContainerEssenceEntry { | ||
129 | UID container_ul; | ||
130 | UID element_ul; | ||
131 | UID codec_ul; | ||
132 | void (*write_desc)(AVFormatContext *, AVStream *); | ||
133 | } MXFContainerEssenceEntry; | ||
134 | |||
135 | typedef struct MXFPackage { | ||
136 | char *name; | ||
137 | enum MXFMetadataSetType type; | ||
138 | int instance; | ||
139 | struct MXFPackage *ref; | ||
140 | } MXFPackage; | ||
141 | |||
142 | enum ULIndex { | ||
143 | INDEX_MPEG2 = 0, | ||
144 | INDEX_AES3, | ||
145 | INDEX_WAV, | ||
146 | INDEX_D10_VIDEO, | ||
147 | INDEX_D10_AUDIO, | ||
148 | INDEX_DV, | ||
149 | INDEX_DNXHD, | ||
150 | INDEX_JPEG2000, | ||
151 | INDEX_H264, | ||
152 | INDEX_S436M, | ||
153 | INDEX_PRORES, | ||
154 | INDEX_FFV1, | ||
155 | }; | ||
156 | |||
157 | static const struct { | ||
158 | enum AVCodecID id; | ||
159 | enum ULIndex index; | ||
160 | } mxf_essence_mappings[] = { | ||
161 | { AV_CODEC_ID_MPEG2VIDEO, INDEX_MPEG2 }, | ||
162 | { AV_CODEC_ID_PCM_S24LE, INDEX_AES3 }, | ||
163 | { AV_CODEC_ID_PCM_S16LE, INDEX_AES3 }, | ||
164 | { AV_CODEC_ID_DVVIDEO, INDEX_DV }, | ||
165 | { AV_CODEC_ID_DNXHD, INDEX_DNXHD }, | ||
166 | { AV_CODEC_ID_JPEG2000, INDEX_JPEG2000 }, | ||
167 | { AV_CODEC_ID_H264, INDEX_H264 }, | ||
168 | { AV_CODEC_ID_PRORES, INDEX_PRORES }, | ||
169 | { AV_CODEC_ID_FFV1, INDEX_FFV1 }, | ||
170 | { AV_CODEC_ID_NONE } | ||
171 | }; | ||
172 | |||
173 | static void mxf_write_wav_desc(AVFormatContext *s, AVStream *st); | ||
174 | static void mxf_write_aes3_desc(AVFormatContext *s, AVStream *st); | ||
175 | static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st); | ||
176 | static void mxf_write_h264_desc(AVFormatContext *s, AVStream *st); | ||
177 | static void mxf_write_ffv1_desc(AVFormatContext *s, AVStream *st); | ||
178 | static void mxf_write_cdci_desc(AVFormatContext *s, AVStream *st); | ||
179 | static void mxf_write_generic_sound_desc(AVFormatContext *s, AVStream *st); | ||
180 | static void mxf_write_s436m_anc_desc(AVFormatContext *s, AVStream *st); | ||
181 | |||
182 | static const MXFContainerEssenceEntry mxf_essence_container_uls[] = { | ||
183 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 }, | ||
184 | { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 }, | ||
185 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x00,0x00,0x00 }, | ||
186 | mxf_write_mpegvideo_desc }, | ||
187 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x03,0x00 }, | ||
188 | { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x16,0x01,0x03,0x00 }, | ||
189 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, | ||
190 | mxf_write_aes3_desc }, | ||
191 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x01,0x00 }, | ||
192 | { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x16,0x01,0x01,0x00 }, | ||
193 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, | ||
194 | mxf_write_wav_desc }, | ||
195 | // D-10 Video | ||
196 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, | ||
197 | { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 }, | ||
198 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x01 }, | ||
199 | mxf_write_cdci_desc }, | ||
200 | // D-10 Audio | ||
201 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, | ||
202 | { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 }, | ||
203 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, | ||
204 | mxf_write_generic_sound_desc }, | ||
205 | // DV | ||
206 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x7F,0x01 }, | ||
207 | { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x18,0x01,0x01,0x00 }, | ||
208 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x00,0x00,0x00 }, | ||
209 | mxf_write_cdci_desc }, | ||
210 | // DNxHD | ||
211 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x0D,0x01,0x03,0x01,0x02,0x11,0x01,0x00 }, | ||
212 | { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x0C,0x00 }, | ||
213 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x71,0x01,0x00,0x00 }, | ||
214 | mxf_write_cdci_desc }, | ||
215 | // JPEG2000 | ||
216 | { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0c,0x01,0x00 }, | ||
217 | { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x15,0x01,0x08,0x00 }, | ||
218 | { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x04,0x01,0x02,0x02,0x03,0x01,0x01,0x00 }, | ||
219 | mxf_write_cdci_desc }, | ||
220 | // H.264 | ||
221 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x0D,0x01,0x03,0x01,0x02,0x10,0x60,0x01 }, | ||
222 | { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 }, | ||
223 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x00,0x00,0x00 }, | ||
224 | mxf_write_h264_desc }, | ||
225 | // S436M ANC | ||
226 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x0D,0x01,0x03,0x01,0x02,0x0e,0x00,0x00 }, | ||
227 | { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x17,0x01,0x02,0x00 }, | ||
228 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x01,0x5C,0x00 }, | ||
229 | mxf_write_s436m_anc_desc }, | ||
230 | // ProRes | ||
231 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x0d,0x01,0x03,0x01,0x02,0x1c,0x01,0x00 }, | ||
232 | { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x15,0x01,0x17,0x00 }, | ||
233 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x03,0x00 }, | ||
234 | mxf_write_cdci_desc }, | ||
235 | // FFV1 | ||
236 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x0d,0x01,0x03,0x01,0x02,0x23,0x01,0x00 }, | ||
237 | { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x15,0x01,0x1d,0x00 }, | ||
238 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x09,0x00,0x00 }, | ||
239 | mxf_write_ffv1_desc }, | ||
240 | { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, | ||
241 | { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, | ||
242 | { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, | ||
243 | NULL }, | ||
244 | }; | ||
245 | |||
246 | static const UID mxf_d10_codec_uls[] = { | ||
247 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x01 }, // D-10 625/50 PAL 50mb/s | ||
248 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x02 }, // D-10 525/50 NTSC 50mb/s | ||
249 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x03 }, // D-10 625/50 PAL 40mb/s | ||
250 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x04 }, // D-10 525/50 NTSC 40mb/s | ||
251 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x05 }, // D-10 625/50 PAL 30mb/s | ||
252 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x06 }, // D-10 525/50 NTSC 30mb/s | ||
253 | }; | ||
254 | |||
255 | static const UID mxf_d10_container_uls[] = { | ||
256 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, // D-10 625/50 PAL 50mb/s | ||
257 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x02,0x01 }, // D-10 525/50 NTSC 50mb/s | ||
258 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x03,0x01 }, // D-10 625/50 PAL 40mb/s | ||
259 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x04,0x01 }, // D-10 525/50 NTSC 40mb/s | ||
260 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x05,0x01 }, // D-10 625/50 PAL 30mb/s | ||
261 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x06,0x01 }, // D-10 525/50 NTSC 30mb/s | ||
262 | }; | ||
263 | |||
264 | |||
265 | static const UID mxf_ffv1_codec_uls[] = { | ||
266 | { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x01,0x00 }, // FFV1 version 0 | ||
267 | { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x02,0x00 }, // FFV1 version 1 | ||
268 | { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x03,0x00 }, // FFV1 version 2 (was only experimental) | ||
269 | { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x04,0x00 }, // FFV1 version 3 | ||
270 | { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x05,0x00 }, // FFV1 version 4 | ||
271 | }; | ||
272 | |||
273 | static const uint8_t product_uid[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd,0x00,0x0c,0x00,0x02}; | ||
274 | static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff }; | ||
275 | static const uint8_t umid_ul[] = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x01,0x0D,0x00,0x13 }; | ||
276 | |||
277 | /** | ||
278 | * complete key for operation pattern, partitions, and primer pack | ||
279 | */ | ||
280 | static const uint8_t op1a_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x01,0x09,0x00 }; | ||
281 | static const uint8_t opatom_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x02,0x01,0x10,0x03,0x00,0x00 }; | ||
282 | static const uint8_t footer_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x04,0x04,0x00 }; // ClosedComplete | ||
283 | static const uint8_t primer_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x05,0x01,0x00 }; | ||
284 | static const uint8_t index_table_segment_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x10,0x01,0x00 }; | ||
285 | static const uint8_t header_open_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x02,0x01,0x00 }; // OpenIncomplete | ||
286 | static const uint8_t header_closed_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x02,0x04,0x00 }; // ClosedComplete | ||
287 | static const uint8_t klv_fill_key[] = { 0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x10,0x01,0x00,0x00,0x00 }; | ||
288 | static const uint8_t body_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x03,0x04,0x00 }; // ClosedComplete | ||
289 | |||
290 | /** | ||
291 | * partial key for header metadata | ||
292 | */ | ||
293 | static const uint8_t header_metadata_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01 }; | ||
294 | static const uint8_t multiple_desc_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x0D,0x01,0x03,0x01,0x02,0x7F,0x01,0x00 }; | ||
295 | |||
296 | /** | ||
297 | * SMPTE RP210 http://www.smpte-ra.org/mdd/index.html | ||
298 | * https://smpte-ra.org/sites/default/files/Labels.xml | ||
299 | */ | ||
300 | static const MXFLocalTagPair mxf_local_tag_batch[] = { | ||
301 | // preface set | ||
302 | { 0x3C0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x15,0x02,0x00,0x00,0x00,0x00}}, /* Instance UID */ | ||
303 | { 0x3B02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x04,0x00,0x00}}, /* Last Modified Date */ | ||
304 | { 0x3B05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x01,0x05,0x00,0x00,0x00}}, /* Version */ | ||
305 | { 0x3B07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x01,0x04,0x00,0x00,0x00}}, /* Object Model Version */ | ||
306 | { 0x3B06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x04,0x00,0x00}}, /* Identifications reference */ | ||
307 | { 0x3B03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x01,0x00,0x00}}, /* Content Storage reference */ | ||
308 | { 0x3B09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x03,0x00,0x00,0x00,0x00}}, /* Operational Pattern UL */ | ||
309 | { 0x3B0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x10,0x02,0x01,0x00,0x00}}, /* Essence Containers UL batch */ | ||
310 | { 0x3B0B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x10,0x02,0x02,0x00,0x00}}, /* DM Schemes UL batch */ | ||
311 | // Identification | ||
312 | { 0x3C09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x01,0x00,0x00,0x00}}, /* This Generation UID */ | ||
313 | { 0x3C01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x02,0x01,0x00,0x00}}, /* Company Name */ | ||
314 | { 0x3C02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x03,0x01,0x00,0x00}}, /* Product Name */ | ||
315 | { 0x3C03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x04,0x00,0x00,0x00}}, /* Product Version */ | ||
316 | { 0x3C04, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x05,0x01,0x00,0x00}}, /* Version String */ | ||
317 | { 0x3C05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x07,0x00,0x00,0x00}}, /* Product ID */ | ||
318 | { 0x3C06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x03,0x00,0x00}}, /* Modification Date */ | ||
319 | { 0x3C07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x0A,0x00,0x00,0x00}}, /* Toolkit Version */ | ||
320 | { 0x3C08, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x06,0x01,0x00,0x00}}, /* Platform */ | ||
321 | // Content Storage | ||
322 | { 0x1901, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x05,0x01,0x00,0x00}}, /* Package strong reference batch */ | ||
323 | { 0x1902, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x05,0x02,0x00,0x00}}, /* Package strong reference batch */ | ||
324 | // Essence Container Data | ||
325 | { 0x2701, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x06,0x01,0x00,0x00,0x00}}, /* Linked Package UID */ | ||
326 | { 0x3F07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x01,0x03,0x04,0x04,0x00,0x00,0x00,0x00}}, /* BodySID */ | ||
327 | // Package | ||
328 | { 0x4401, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x15,0x10,0x00,0x00,0x00,0x00}}, /* Package UID */ | ||
329 | { 0x4405, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x01,0x03,0x00,0x00}}, /* Package Creation Date */ | ||
330 | { 0x4404, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x05,0x00,0x00}}, /* Package Modified Date */ | ||
331 | { 0x4402, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x03,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Package Name */ | ||
332 | { 0x4403, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x05,0x00,0x00}}, /* Tracks Strong reference array */ | ||
333 | { 0x4701, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x03,0x00,0x00}}, /* Descriptor */ | ||
334 | // Track | ||
335 | { 0x4801, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x01,0x07,0x01,0x01,0x00,0x00,0x00,0x00}}, /* Track ID */ | ||
336 | { 0x4804, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x01,0x04,0x01,0x03,0x00,0x00,0x00,0x00}}, /* Track Number */ | ||
337 | { 0x4B01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x30,0x04,0x05,0x00,0x00,0x00,0x00}}, /* Edit Rate */ | ||
338 | { 0x4B02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x03,0x00,0x00}}, /* Origin */ | ||
339 | { 0x4803, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x04,0x00,0x00}}, /* Sequence reference */ | ||
340 | // Sequence | ||
341 | { 0x0201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x07,0x01,0x00,0x00,0x00,0x00,0x00}}, /* Data Definition UL */ | ||
342 | { 0x0202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x02,0x01,0x01,0x03,0x00,0x00}}, /* Duration */ | ||
343 | { 0x1001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x09,0x00,0x00}}, /* Structural Components reference array */ | ||
344 | // Source Clip | ||
345 | { 0x1201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x04,0x00,0x00}}, /* Start position */ | ||
346 | { 0x1101, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x03,0x01,0x00,0x00,0x00}}, /* SourcePackageID */ | ||
347 | { 0x1102, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x03,0x02,0x00,0x00,0x00}}, /* SourceTrackID */ | ||
348 | // Timecode Component | ||
349 | { 0x1501, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x05,0x00,0x00}}, /* Start Time Code */ | ||
350 | { 0x1502, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x04,0x01,0x01,0x02,0x06,0x00,0x00}}, /* Rounded Time Code Base */ | ||
351 | { 0x1503, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x04,0x01,0x01,0x05,0x00,0x00,0x00}}, /* Drop Frame */ | ||
352 | // File Descriptor | ||
353 | { 0x3F01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x06,0x01,0x01,0x04,0x06,0x0B,0x00,0x00}}, /* Sub Descriptors reference array */ | ||
354 | { 0x3006, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x06,0x01,0x01,0x03,0x05,0x00,0x00,0x00}}, /* Linked Track ID */ | ||
355 | { 0x3001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x06,0x01,0x01,0x00,0x00,0x00,0x00}}, /* SampleRate */ | ||
356 | { 0x3002, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x06,0x01,0x02,0x00,0x00,0x00,0x00}}, /* ContainerDuration */ | ||
357 | { 0x3004, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x01,0x02,0x00,0x00}}, /* Essence Container */ | ||
358 | // Generic Picture Essence Descriptor | ||
359 | { 0x320C, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x03,0x01,0x04,0x00,0x00,0x00}}, /* Frame Layout */ | ||
360 | { 0x320D, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x02,0x05,0x00,0x00,0x00}}, /* Video Line Map */ | ||
361 | { 0x3203, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x02,0x00,0x00,0x00}}, /* Stored Width */ | ||
362 | { 0x3202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x01,0x00,0x00,0x00}}, /* Stored Height */ | ||
363 | { 0x3216, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x03,0x02,0x08,0x00,0x00,0x00}}, /* Stored F2 Offset */ | ||
364 | { 0x3205, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x08,0x00,0x00,0x00}}, /* Sampled Width */ | ||
365 | { 0x3204, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x07,0x00,0x00,0x00}}, /* Sampled Height */ | ||
366 | { 0x3206, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x09,0x00,0x00,0x00}}, /* Sampled X Offset */ | ||
367 | { 0x3207, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0A,0x00,0x00,0x00}}, /* Sampled Y Offset */ | ||
368 | { 0x3209, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0C,0x00,0x00,0x00}}, /* Display Width */ | ||
369 | { 0x3208, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0B,0x00,0x00,0x00}}, /* Display Height */ | ||
370 | { 0x320A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0D,0x00,0x00,0x00}}, /* Display X offset */ | ||
371 | { 0x320B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0E,0x00,0x00,0x00}}, /* Presentation Y offset */ | ||
372 | { 0x3217, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x03,0x02,0x07,0x00,0x00,0x00}}, /* Display F2 offset */ | ||
373 | { 0x320E, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x00,0x00,0x00}}, /* Aspect Ratio */ | ||
374 | { 0x3210, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x02,0x01,0x01,0x01,0x02,0x00}}, /* Transfer characteristic */ | ||
375 | { 0x321A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x02,0x01,0x01,0x03,0x01,0x00}}, /* Coding Equations (color space) */ | ||
376 | { 0x3219, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x09,0x04,0x01,0x02,0x01,0x01,0x06,0x01,0x00}}, /* Color Primaries */ | ||
377 | { 0x3213, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x18,0x01,0x02,0x00,0x00,0x00,0x00}}, /* Image Start Offset */ | ||
378 | { 0x3214, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x18,0x01,0x03,0x00,0x00,0x00,0x00}}, /* Image End Offset */ | ||
379 | { 0x3201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x06,0x01,0x00,0x00,0x00,0x00}}, /* Picture Essence Coding */ | ||
380 | { 0x3212, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x01,0x06,0x00,0x00,0x00}}, /* Field Dominance (Opt) */ | ||
381 | { 0x3215, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x05,0x01,0x13,0x00,0x00,0x00,0x00}}, /* Signal Standard */ | ||
382 | // CDCI Picture Essence Descriptor | ||
383 | { 0x3301, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x03,0x0A,0x00,0x00,0x00}}, /* Component Depth */ | ||
384 | { 0x3302, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x05,0x00,0x00,0x00}}, /* Horizontal Subsampling */ | ||
385 | { 0x3308, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x01,0x10,0x00,0x00,0x00}}, /* Vertical Subsampling */ | ||
386 | { 0x3303, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x06,0x00,0x00,0x00}}, /* Color Siting */ | ||
387 | { 0x3307, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x18,0x01,0x04,0x00,0x00,0x00,0x00}}, /* Padding Bits */ | ||
388 | { 0x3304, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x03,0x03,0x00,0x00,0x00}}, /* Black Ref level */ | ||
389 | { 0x3305, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x03,0x04,0x00,0x00,0x00}}, /* White Ref level */ | ||
390 | { 0x3306, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x03,0x05,0x00,0x00,0x00}}, /* Color Range */ | ||
391 | // Generic Sound Essence Descriptor | ||
392 | { 0x3D02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x01,0x04,0x00,0x00,0x00}}, /* Locked/Unlocked */ | ||
393 | { 0x3D03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x01,0x01,0x01,0x00,0x00}}, /* Audio sampling rate */ | ||
394 | { 0x3D04, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x02,0x01,0x01,0x03,0x00,0x00,0x00}}, /* Audio Ref Level */ | ||
395 | { 0x3D07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x01,0x01,0x04,0x00,0x00,0x00}}, /* ChannelCount */ | ||
396 | { 0x3D01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x03,0x04,0x00,0x00,0x00}}, /* Quantization bits */ | ||
397 | { 0x3D06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x02,0x04,0x02,0x00,0x00,0x00,0x00}}, /* Sound Essence Compression */ | ||
398 | // Index Table Segment | ||
399 | { 0x3F0B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x05,0x30,0x04,0x06,0x00,0x00,0x00,0x00}}, /* Index Edit Rate */ | ||
400 | { 0x3F0C, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x07,0x02,0x01,0x03,0x01,0x0A,0x00,0x00}}, /* Index Start Position */ | ||
401 | { 0x3F0D, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x07,0x02,0x02,0x01,0x01,0x02,0x00,0x00}}, /* Index Duration */ | ||
402 | { 0x3F05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x06,0x02,0x01,0x00,0x00,0x00,0x00}}, /* Edit Unit Byte Count */ | ||
403 | { 0x3F06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x01,0x03,0x04,0x05,0x00,0x00,0x00,0x00}}, /* IndexSID */ | ||
404 | { 0x3F08, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x04,0x04,0x01,0x01,0x00,0x00,0x00}}, /* Slice Count */ | ||
405 | { 0x3F09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x01,0x06,0x00,0x00,0x00}}, /* Delta Entry Array */ | ||
406 | { 0x3F0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x02,0x05,0x00,0x00,0x00}}, /* Index Entry Array */ | ||
407 | // MPEG video Descriptor | ||
408 | { 0x8000, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0B,0x00,0x00}}, /* BitRate */ | ||
409 | { 0x8003, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x05,0x00,0x00}}, /* LowDelay */ | ||
410 | { 0x8004, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x06,0x00,0x00}}, /* ClosedGOP */ | ||
411 | { 0x8006, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x08,0x00,0x00}}, /* MaxGOP */ | ||
412 | { 0x8007, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0A,0x00,0x00}}, /* ProfileAndLevel */ | ||
413 | { 0x8008, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x09,0x00,0x00}}, /* BPictureCount */ | ||
414 | // Wave Audio Essence Descriptor | ||
415 | { 0x3D09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x03,0x05,0x00,0x00,0x00}}, /* Average Bytes Per Second */ | ||
416 | { 0x3D0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Block Align */ | ||
417 | // mxf_user_comments_local_tag | ||
418 | { 0x4406, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x02,0x01,0x02,0x0C,0x00,0x00,0x00}}, /* User Comments */ | ||
419 | { 0x5001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x02,0x01,0x02,0x09,0x01,0x00,0x00}}, /* Name */ | ||
420 | { 0x5003, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x02,0x01,0x02,0x0A,0x01,0x00,0x00}}, /* Value */ | ||
421 | // mxf_avc_subdescriptor_local_tags | ||
422 | { 0x8100, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x09,0x06,0x01,0x01,0x04,0x06,0x10,0x00,0x00}}, /* SubDescriptors */ | ||
423 | { 0x8200, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x06,0x01,0x0E,0x00,0x00}}, /* AVC Decoding Delay */ | ||
424 | { 0x8201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x06,0x01,0x0A,0x00,0x00}}, /* AVC Profile */ | ||
425 | { 0x8202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x06,0x01,0x0D,0x00,0x00}}, /* AVC Level */ | ||
426 | // ff_mxf_mastering_display_local_tags | ||
427 | { 0x8301, FF_MXF_MasteringDisplayPrimaries }, | ||
428 | { 0x8302, FF_MXF_MasteringDisplayWhitePointChromaticity }, | ||
429 | { 0x8303, FF_MXF_MasteringDisplayMaximumLuminance }, | ||
430 | { 0x8304, FF_MXF_MasteringDisplayMinimumLuminance }, | ||
431 | // FFV1 | ||
432 | { 0xDFD9, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x0C,0x06,0x00,0x00,0x00}}, /* FFV1 Micro-version */ | ||
433 | { 0xDFDA, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x0C,0x05,0x00,0x00,0x00}}, /* FFV1 Version */ | ||
434 | { 0xDFDB, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x0C,0x01,0x00,0x00,0x00}}, /* FFV1 Initialization Metadata */ | ||
435 | // ff_mxf_jpeg2000_local_tags | ||
436 | { 0x8400, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x09,0x06,0x01,0x01,0x04,0x06,0x10,0x00,0x00}}, /* Sub Descriptors / Opt Ordered array of strong references to sub descriptor sets */ | ||
437 | { 0x8401, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x01,0x00,0x00,0x00}}, /* Rsiz: An enumerated value that defines the decoder capabilities */ | ||
438 | { 0x8402, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x02,0x00,0x00,0x00}}, /* Xsiz: Width of the reference grid */ | ||
439 | { 0x8403, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x03,0x00,0x00,0x00}}, /* Ysiz: Height of the reference grid */ | ||
440 | { 0x8404, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x04,0x00,0x00,0x00}}, /* X0siz: Horizontal offset from the origin of the reference grid to the left side of the image area */ | ||
441 | { 0x8405, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x05,0x00,0x00,0x00}}, /* Y0siz: Vertical offset from the origin of the reference grid to the left side of the image area */ | ||
442 | { 0x8406, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x06,0x00,0x00,0x00}}, /* XTsiz: Width of one reference tile with respect to the reference grid */ | ||
443 | { 0x8407, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x07,0x00,0x00,0x00}}, /* YTsiz: Height of one reference tile with respect to the reference grid */ | ||
444 | { 0x8408, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x08,0x00,0x00,0x00}}, /* XT0siz: Horizontal offset from the origin of the reference grid to the left side of the first tile */ | ||
445 | { 0x8409, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x09,0x00,0x00,0x00}}, /* YT0siz: Vertical offset from the origin of the reference grid to the left side of the first tile */ | ||
446 | { 0x840A, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x0A,0x00,0x00,0x00}}, /* Csiz: The number of components in the picture */ | ||
447 | { 0x840B, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x0B,0x00,0x00,0x00}}, /* Ssizi, XRSizi, YRSizi: Array of picture components where each component comprises 3 bytes named Ssizi, XRSizi, YRSizi. The array of 3-byte groups is preceded by the array header comprising a 4-byte value of the number of components followed by a 4-byte value of 3. */ | ||
448 | { 0x840C, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x0E,0x00,0x00,0x00}}, /* The nature and order of the image components in the compressed domain as carried in the J2C codestream. */ | ||
449 | }; | ||
450 | |||
451 | #define MXF_NUM_TAGS FF_ARRAY_ELEMS(mxf_local_tag_batch) | ||
452 | |||
453 | typedef struct MXFContext { | ||
454 | AVClass *av_class; | ||
455 | int64_t footer_partition_offset; | ||
456 | int essence_container_count; | ||
457 | AVRational time_base; | ||
458 | int header_written; | ||
459 | MXFIndexEntry *index_entries; | ||
460 | unsigned edit_units_count; | ||
461 | uint64_t timestamp; ///< timestamp, as year(16),month(8),day(8),hour(8),minutes(8),msec/4(8) | ||
462 | uint8_t slice_count; ///< index slice count minus 1 (1 if no audio, 0 otherwise) | ||
463 | int last_indexed_edit_unit; | ||
464 | uint64_t *body_partition_offset; | ||
465 | unsigned body_partitions_count; | ||
466 | int last_key_index; ///< index of last key frame | ||
467 | uint64_t duration; | ||
468 | AVTimecode tc; ///< timecode context | ||
469 | AVStream *timecode_track; | ||
470 | int timecode_base; ///< rounded time code base (25 or 30) | ||
471 | int edit_unit_byte_count; ///< fixed edit unit byte count | ||
472 | int content_package_rate; ///< content package rate in system element, see SMPTE 326M | ||
473 | uint64_t body_offset; | ||
474 | uint32_t instance_number; | ||
475 | uint8_t umid[16]; ///< unique material identifier | ||
476 | int channel_count; | ||
477 | int signal_standard; | ||
478 | uint32_t tagged_value_count; | ||
479 | AVRational audio_edit_rate; | ||
480 | int store_user_comments; | ||
481 | int track_instance_count; // used to generate MXFTrack uuids | ||
482 | int cbr_index; ///< use a constant bitrate index | ||
483 | uint8_t unused_tags[MXF_NUM_TAGS]; ///< local tags that we know will not be used | ||
484 | MXFStreamContext timecode_track_priv; | ||
485 | } MXFContext; | ||
486 | |||
487 | 1754 | static void mxf_write_uuid(AVIOContext *pb, enum MXFMetadataSetType type, int value) | |
488 | { | ||
489 | 1754 | avio_write(pb, uuid_base, 10); | |
490 | 1754 | avio_wb16(pb, type); | |
491 | 1754 | avio_wb32(pb, value); | |
492 | 1754 | } | |
493 | |||
494 | 428 | static void mxf_write_umid(AVFormatContext *s, int type) | |
495 | { | ||
496 | 428 | MXFContext *mxf = s->priv_data; | |
497 | 428 | avio_write(s->pb, umid_ul, 13); | |
498 | 428 | avio_wb24(s->pb, mxf->instance_number); | |
499 | 428 | avio_write(s->pb, mxf->umid, 15); | |
500 | 428 | avio_w8(s->pb, type); | |
501 | 428 | } | |
502 | |||
503 | 498 | static void mxf_write_refs_count(AVIOContext *pb, int ref_count) | |
504 | { | ||
505 | 498 | avio_wb32(pb, ref_count); | |
506 | 498 | avio_wb32(pb, 16); | |
507 | 498 | } | |
508 | |||
509 | 857 | static int klv_ber_length(uint64_t len) | |
510 | { | ||
511 |
2/2✓ Branch 0 taken 693 times.
✓ Branch 1 taken 164 times.
|
857 | if (len < 128) |
512 | 693 | return 1; | |
513 | else | ||
514 | 164 | return (av_log2(len) >> 3) + 2; | |
515 | } | ||
516 | |||
517 | 857 | static int klv_encode_ber_length(AVIOContext *pb, uint64_t len) | |
518 | { | ||
519 | // Determine the best BER size | ||
520 | 857 | int size = klv_ber_length(len); | |
521 |
2/2✓ Branch 0 taken 693 times.
✓ Branch 1 taken 164 times.
|
857 | if (size == 1) { |
522 | //short form | ||
523 | 693 | avio_w8(pb, len); | |
524 | 693 | return 1; | |
525 | } | ||
526 | |||
527 | 164 | size --; | |
528 | // long form | ||
529 | 164 | avio_w8(pb, 0x80 + size); | |
530 |
2/2✓ Branch 0 taken 198 times.
✓ Branch 1 taken 164 times.
|
362 | while(size) { |
531 | 198 | size--; | |
532 | 198 | avio_w8(pb, len >> 8 * size & 0xff); | |
533 | } | ||
534 | 164 | return 0; | |
535 | } | ||
536 | |||
537 | 2114 | static void klv_encode_ber4_length(AVIOContext *pb, int len) | |
538 | { | ||
539 | 2114 | avio_w8(pb, 0x80 + 3); | |
540 | 2114 | avio_wb24(pb, len); | |
541 | 2114 | } | |
542 | |||
543 | 6 | static void klv_encode_ber9_length(AVIOContext *pb, uint64_t len) | |
544 | { | ||
545 | 6 | avio_w8(pb, 0x80 + 8); | |
546 | 6 | avio_wb64(pb, len); | |
547 | 6 | } | |
548 | |||
549 | /* | ||
550 | * Get essence container ul index | ||
551 | */ | ||
552 | 25 | static int mxf_get_essence_container_ul_index(enum AVCodecID id) | |
553 | { | ||
554 | int i; | ||
555 |
1/2✓ Branch 0 taken 73 times.
✗ Branch 1 not taken.
|
73 | for (i = 0; mxf_essence_mappings[i].id; i++) |
556 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 48 times.
|
73 | if (mxf_essence_mappings[i].id == id) |
557 | 25 | return mxf_essence_mappings[i].index; | |
558 | ✗ | return -1; | |
559 | } | ||
560 | |||
561 | 6782 | static const MXFLocalTagPair* mxf_lookup_local_tag(int tag) | |
562 | { | ||
563 |
1/2✓ Branch 0 taken 306312 times.
✗ Branch 1 not taken.
|
306312 | for (int i = 0; i < MXF_NUM_TAGS; i++) { |
564 |
2/2✓ Branch 0 taken 6782 times.
✓ Branch 1 taken 299530 times.
|
306312 | if (mxf_local_tag_batch[i].local_tag == tag) { |
565 | 6782 | return &mxf_local_tag_batch[i]; | |
566 | } | ||
567 | } | ||
568 | |||
569 | // this assert can only be hit during development | ||
570 | ✗ | av_assert0(0 && "you forgot to add your new tag to mxf_local_tag_batch"); | |
571 | return NULL; | ||
572 | } | ||
573 | |||
574 | 884 | static void mxf_mark_tag_unused(MXFContext *mxf, int tag) | |
575 | { | ||
576 | 884 | const MXFLocalTagPair *pair = mxf_lookup_local_tag(tag); | |
577 | 884 | mxf->unused_tags[pair - mxf_local_tag_batch] = 1; | |
578 | 884 | } | |
579 | |||
580 | 34 | static void mxf_write_primer_pack(AVFormatContext *s) | |
581 | { | ||
582 | 34 | MXFContext *mxf = s->priv_data; | |
583 | 34 | AVIOContext *pb = s->pb; | |
584 | 34 | int local_tag_number = MXF_NUM_TAGS, i; | |
585 | 34 | int will_have_avc_tags = 0, will_have_mastering_tags = 0, will_have_ffv1_tags = 0, will_have_jpeg2000_tags = 0; | |
586 | |||
587 |
2/2✓ Branch 0 taken 58 times.
✓ Branch 1 taken 34 times.
|
92 | for (i = 0; i < s->nb_streams; i++) { |
588 | 58 | MXFStreamContext *sc = s->streams[i]->priv_data; | |
589 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
58 | if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_H264 && !sc->avc_intra) { |
590 | ✗ | will_have_avc_tags = 1; | |
591 | } | ||
592 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 56 times.
|
58 | if (av_packet_side_data_get(s->streams[i]->codecpar->coded_side_data, |
593 | 58 | s->streams[i]->codecpar->nb_coded_side_data, | |
594 | AV_PKT_DATA_MASTERING_DISPLAY_METADATA)) { | ||
595 | 2 | will_have_mastering_tags = 1; | |
596 | } | ||
597 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 56 times.
|
58 | if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_FFV1) { |
598 | 2 | will_have_ffv1_tags = 1; | |
599 | } | ||
600 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_JPEG2000){ |
601 | ✗ | will_have_jpeg2000_tags = 1; | |
602 | } | ||
603 | } | ||
604 | |||
605 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 6 times.
|
34 | if (!mxf->store_user_comments) { |
606 | 28 | mxf_mark_tag_unused(mxf, 0x4406); | |
607 | 28 | mxf_mark_tag_unused(mxf, 0x5001); | |
608 | 28 | mxf_mark_tag_unused(mxf, 0x5003); | |
609 | } | ||
610 | |||
611 |
3/4✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 2 times.
|
34 | if (!will_have_avc_tags && !will_have_ffv1_tags) { |
612 | 32 | mxf_mark_tag_unused(mxf, 0x8100); | |
613 | } | ||
614 | |||
615 |
1/2✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
|
34 | if (!will_have_avc_tags) { |
616 | 34 | mxf_mark_tag_unused(mxf, 0x8200); | |
617 | 34 | mxf_mark_tag_unused(mxf, 0x8201); | |
618 | 34 | mxf_mark_tag_unused(mxf, 0x8202); | |
619 | } | ||
620 | |||
621 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 2 times.
|
34 | if (!will_have_mastering_tags) { |
622 | 32 | mxf_mark_tag_unused(mxf, 0x8301); | |
623 | 32 | mxf_mark_tag_unused(mxf, 0x8302); | |
624 | 32 | mxf_mark_tag_unused(mxf, 0x8303); | |
625 | 32 | mxf_mark_tag_unused(mxf, 0x8304); | |
626 | } | ||
627 | |||
628 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 2 times.
|
34 | if (!will_have_ffv1_tags) { |
629 | 32 | mxf_mark_tag_unused(mxf, 0xDFD9); | |
630 | 32 | mxf_mark_tag_unused(mxf, 0xDFDA); | |
631 | 32 | mxf_mark_tag_unused(mxf, 0xDFDB); | |
632 | } | ||
633 | |||
634 |
1/2✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
|
34 | if (!will_have_jpeg2000_tags) { |
635 | 34 | mxf_mark_tag_unused(mxf, 0x8400); | |
636 | 34 | mxf_mark_tag_unused(mxf, 0x8401); | |
637 | 34 | mxf_mark_tag_unused(mxf, 0x8402); | |
638 | 34 | mxf_mark_tag_unused(mxf, 0x8403); | |
639 | 34 | mxf_mark_tag_unused(mxf, 0x8404); | |
640 | 34 | mxf_mark_tag_unused(mxf, 0x8405); | |
641 | 34 | mxf_mark_tag_unused(mxf, 0x8406); | |
642 | 34 | mxf_mark_tag_unused(mxf, 0x8407); | |
643 | 34 | mxf_mark_tag_unused(mxf, 0x8408); | |
644 | 34 | mxf_mark_tag_unused(mxf, 0x8409); | |
645 | 34 | mxf_mark_tag_unused(mxf, 0x840A); | |
646 | 34 | mxf_mark_tag_unused(mxf, 0x840B); | |
647 | 34 | mxf_mark_tag_unused(mxf, 0x840C); | |
648 | } | ||
649 | |||
650 |
2/2✓ Branch 0 taken 4318 times.
✓ Branch 1 taken 34 times.
|
4352 | for (i = 0; i < MXF_NUM_TAGS; i++) { |
651 |
2/2✓ Branch 0 taken 884 times.
✓ Branch 1 taken 3434 times.
|
4318 | if (mxf->unused_tags[i]) { |
652 | 884 | local_tag_number--; | |
653 | } | ||
654 | } | ||
655 | |||
656 | 34 | avio_write(pb, primer_pack_key, 16); | |
657 | 34 | klv_encode_ber_length(pb, local_tag_number * 18 + 8); | |
658 | |||
659 | 34 | avio_wb32(pb, local_tag_number); // local_tag num | |
660 | 34 | avio_wb32(pb, 18); // item size, always 18 according to the specs | |
661 | |||
662 |
2/2✓ Branch 0 taken 4318 times.
✓ Branch 1 taken 34 times.
|
4352 | for (i = 0; i < MXF_NUM_TAGS; i++) { |
663 |
2/2✓ Branch 0 taken 3434 times.
✓ Branch 1 taken 884 times.
|
4318 | if (mxf->unused_tags[i] == 0) { |
664 | 3434 | avio_wb16(pb, mxf_local_tag_batch[i].local_tag); | |
665 | 3434 | avio_write(pb, mxf_local_tag_batch[i].uid, 16); | |
666 | } | ||
667 | } | ||
668 | 34 | } | |
669 | |||
670 | 5898 | static void mxf_write_local_tag(AVFormatContext *s, int size, int tag) | |
671 | { | ||
672 | 5898 | MXFContext *mxf = s->priv_data; | |
673 | 5898 | AVIOContext *pb = s->pb; | |
674 | 5898 | const MXFLocalTagPair *pair = mxf_lookup_local_tag(tag); | |
675 | |||
676 | // make sure the tag was not declared unnecessary upfront | ||
677 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5898 times.
|
5898 | av_assert0(mxf->unused_tags[pair - mxf_local_tag_batch] == 0); |
678 | |||
679 | 5898 | avio_wb16(pb, tag); | |
680 | 5898 | avio_wb16(pb, size); | |
681 | 5898 | } | |
682 | |||
683 | 806 | static void mxf_write_metadata_key(AVIOContext *pb, unsigned int value) | |
684 | { | ||
685 | 806 | avio_write(pb, header_metadata_key, 13); | |
686 | 806 | avio_wb24(pb, value); | |
687 | 806 | } | |
688 | |||
689 | 336 | static const MXFCodecUL *mxf_get_codec_ul_by_id(const MXFCodecUL *uls, int id) | |
690 | { | ||
691 |
2/2✓ Branch 0 taken 1184 times.
✓ Branch 1 taken 82 times.
|
1266 | while (uls->uid[0]) { |
692 |
2/2✓ Branch 0 taken 254 times.
✓ Branch 1 taken 930 times.
|
1184 | if (id == uls->id) |
693 | 254 | break; | |
694 | 930 | uls++; | |
695 | } | ||
696 | 336 | return uls; | |
697 | } | ||
698 | |||
699 | //one EC -> one descriptor. N ECs -> MultipleDescriptor + N descriptors | ||
700 | #define DESCRIPTOR_COUNT(essence_container_count) \ | ||
701 | (essence_container_count > 1 ? essence_container_count + 1 : essence_container_count) | ||
702 | |||
703 | 100 | static void mxf_write_essence_container_refs(AVFormatContext *s) | |
704 | { | ||
705 | 100 | MXFContext *c = s->priv_data; | |
706 | 100 | AVIOContext *pb = s->pb; | |
707 | int i; | ||
708 | |||
709 |
2/2✓ Branch 0 taken 57 times.
✓ Branch 1 taken 43 times.
|
100 | mxf_write_refs_count(pb, DESCRIPTOR_COUNT(c->essence_container_count)); |
710 | 100 | av_log(s,AV_LOG_DEBUG, "essence container count:%d\n", c->essence_container_count); | |
711 |
2/2✓ Branch 0 taken 163 times.
✓ Branch 1 taken 57 times.
|
220 | for (i = 0; i < s->nb_streams; i++) { |
712 | 163 | MXFStreamContext *sc = s->streams[i]->priv_data; | |
713 | // check first track of essence container type and only write it once | ||
714 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 157 times.
|
163 | if (sc->track_essence_element_key[15] != 0) |
715 | 6 | continue; | |
716 | 157 | avio_write(pb, *sc->container_ul, 16); | |
717 |
2/2✓ Branch 0 taken 43 times.
✓ Branch 1 taken 114 times.
|
157 | if (c->essence_container_count == 1) |
718 | 43 | break; | |
719 | } | ||
720 | |||
721 |
2/2✓ Branch 0 taken 57 times.
✓ Branch 1 taken 43 times.
|
100 | if (c->essence_container_count > 1) |
722 | 57 | avio_write(pb, multiple_desc_ul, 16); | |
723 | 100 | } | |
724 | |||
725 | 34 | static void mxf_write_preface(AVFormatContext *s) | |
726 | { | ||
727 | 34 | MXFContext *mxf = s->priv_data; | |
728 | 34 | AVIOContext *pb = s->pb; | |
729 | |||
730 | 34 | mxf_write_metadata_key(pb, 0x012f00); | |
731 | PRINT_KEY(s, "preface key", pb->buf_ptr - 16); | ||
732 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 14 times.
|
34 | klv_encode_ber_length(pb, 138 + 16LL * DESCRIPTOR_COUNT(mxf->essence_container_count)); |
733 | |||
734 | // write preface set uid | ||
735 | 34 | mxf_write_local_tag(s, 16, 0x3C0A); | |
736 | 34 | mxf_write_uuid(pb, Preface, 0); | |
737 | PRINT_KEY(s, "preface uid", pb->buf_ptr - 16); | ||
738 | |||
739 | // last modified date | ||
740 | 34 | mxf_write_local_tag(s, 8, 0x3B02); | |
741 | 34 | avio_wb64(pb, mxf->timestamp); | |
742 | |||
743 | // write version | ||
744 | 34 | mxf_write_local_tag(s, 2, 0x3B05); | |
745 | 34 | avio_wb16(pb, 259); // v1.3 | |
746 | |||
747 | // Object Model Version | ||
748 | 34 | mxf_write_local_tag(s, 4, 0x3B07); | |
749 | 34 | avio_wb32(pb, 1); | |
750 | |||
751 | // write identification_refs | ||
752 | 34 | mxf_write_local_tag(s, 16 + 8, 0x3B06); | |
753 | 34 | mxf_write_refs_count(pb, 1); | |
754 | 34 | mxf_write_uuid(pb, Identification, 0); | |
755 | |||
756 | // write content_storage_refs | ||
757 | 34 | mxf_write_local_tag(s, 16, 0x3B03); | |
758 | 34 | mxf_write_uuid(pb, ContentStorage, 0); | |
759 | |||
760 | // operational pattern | ||
761 | 34 | mxf_write_local_tag(s, 16, 0x3B09); | |
762 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 28 times.
|
34 | if (IS_OPATOM(s)) |
763 | 6 | avio_write(pb, opatom_ul, 16); | |
764 | else | ||
765 | 28 | avio_write(pb, op1a_ul, 16); | |
766 | |||
767 | // write essence_container_refs | ||
768 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 14 times.
|
34 | mxf_write_local_tag(s, 8 + 16LL * DESCRIPTOR_COUNT(mxf->essence_container_count), 0x3B0A); |
769 | 34 | mxf_write_essence_container_refs(s); | |
770 | |||
771 | // write dm_scheme_refs | ||
772 | 34 | mxf_write_local_tag(s, 8, 0x3B0B); | |
773 | 34 | avio_wb64(pb, 0); | |
774 | 34 | } | |
775 | |||
776 | /* | ||
777 | * Returns the length of the UTF-16 string, in 16-bit characters, that would result | ||
778 | * from decoding the utf-8 string. | ||
779 | */ | ||
780 | 294 | static uint64_t mxf_utf16len(const char *utf8_str) | |
781 | { | ||
782 | 294 | const uint8_t *q = utf8_str; | |
783 | 294 | uint64_t size = 0; | |
784 |
2/2✓ Branch 0 taken 1866 times.
✓ Branch 1 taken 294 times.
|
2160 | while (*q) { |
785 | uint32_t ch; | ||
786 |
3/8✓ Branch 0 taken 1866 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1866 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1866 times.
|
1866 | GET_UTF8(ch, *q++, goto invalid;) |
787 |
1/2✓ Branch 0 taken 1866 times.
✗ Branch 1 not taken.
|
1866 | if (ch < 0x10000) |
788 | 1866 | size++; | |
789 | else | ||
790 | ✗ | size += 2; | |
791 | 1866 | continue; | |
792 | ✗ | invalid: | |
793 | ✗ | av_log(NULL, AV_LOG_ERROR, "Invalid UTF8 sequence in mxf_utf16len\n\n"); | |
794 | } | ||
795 | 294 | size += 1; | |
796 | 294 | return size; | |
797 | } | ||
798 | |||
799 | /* | ||
800 | * Returns the calculated length a local tag containing an utf-8 string as utf-16 | ||
801 | */ | ||
802 | 218 | static int mxf_utf16_local_tag_length(const char *utf8_str) | |
803 | { | ||
804 | uint64_t size; | ||
805 | |||
806 |
2/2✓ Branch 0 taken 68 times.
✓ Branch 1 taken 150 times.
|
218 | if (!utf8_str) |
807 | 68 | return 0; | |
808 | |||
809 | 150 | size = mxf_utf16len(utf8_str); | |
810 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 150 times.
|
150 | if (size >= UINT16_MAX/2) { |
811 | ✗ | av_log(NULL, AV_LOG_ERROR, "utf16 local tag size %"PRIx64" invalid (too large), ignoring\n", size); | |
812 | ✗ | return 0; | |
813 | } | ||
814 | |||
815 | 150 | return 4 + size * 2; | |
816 | } | ||
817 | |||
818 | /* | ||
819 | * Write a local tag containing an utf-8 string as utf-16 | ||
820 | */ | ||
821 | 144 | static void mxf_write_local_tag_utf16(AVFormatContext *s, int tag, const char *value) | |
822 | { | ||
823 | 144 | AVIOContext *pb = s->pb; | |
824 | 144 | uint64_t size = mxf_utf16len(value); | |
825 | |||
826 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 144 times.
|
144 | if (size >= UINT16_MAX/2) { |
827 | ✗ | av_log(NULL, AV_LOG_ERROR, "utf16 local tag size %"PRIx64" invalid (too large), ignoring\n", size); | |
828 | ✗ | return; | |
829 | } | ||
830 | |||
831 | 144 | mxf_write_local_tag(s, size*2, tag); | |
832 | 144 | avio_put_str16be(pb, value); | |
833 | } | ||
834 | |||
835 | 68 | static void store_version(AVFormatContext *s){ | |
836 | 68 | AVIOContext *pb = s->pb; | |
837 | |||
838 |
1/2✓ Branch 0 taken 68 times.
✗ Branch 1 not taken.
|
68 | if (s->flags & AVFMT_FLAG_BITEXACT) { |
839 | 68 | avio_wb16(pb, 0); // major | |
840 | 68 | avio_wb16(pb, 0); // minor | |
841 | 68 | avio_wb16(pb, 0); // tertiary | |
842 | } else { | ||
843 | ✗ | avio_wb16(pb, LIBAVFORMAT_VERSION_MAJOR); // major | |
844 | ✗ | avio_wb16(pb, LIBAVFORMAT_VERSION_MINOR); // minor | |
845 | ✗ | avio_wb16(pb, LIBAVFORMAT_VERSION_MICRO); // tertiary | |
846 | } | ||
847 | 68 | avio_wb16(pb, 0); // patch | |
848 | 68 | avio_wb16(pb, 0); // release | |
849 | 68 | } | |
850 | |||
851 | #define PLATFORM_IDENT "Lavf " AV_STRINGIFY((OS_NAME)) | ||
852 | 34 | static void mxf_write_identification(AVFormatContext *s) | |
853 | { | ||
854 | 34 | MXFContext *mxf = s->priv_data; | |
855 | 34 | AVIOContext *pb = s->pb; | |
856 | 34 | AVDictionaryEntry *com_entry = av_dict_get(s->metadata, "company_name", NULL, 0); | |
857 | 34 | AVDictionaryEntry *product_entry = av_dict_get(s->metadata, "product_name", NULL, 0); | |
858 | 34 | AVDictionaryEntry *version_entry = av_dict_get(s->metadata, "product_version", NULL, 0); | |
859 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 32 times.
|
34 | const char *company = com_entry ? com_entry->value : "FFmpeg"; |
860 |
4/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 26 times.
✓ Branch 3 taken 6 times.
|
34 | const char *product = product_entry ? product_entry->value : !IS_OPATOM(s) ? "OP1a Muxer" : "OPAtom Muxer"; |
861 |
1/2✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
|
34 | const char *platform = s->flags & AVFMT_FLAG_BITEXACT ? "Lavf" : PLATFORM_IDENT; |
862 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 32 times.
|
66 | const char *version = version_entry ? version_entry->value : |
863 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | s->flags & AVFMT_FLAG_BITEXACT ? "0.0.0" : |
864 | AV_STRINGIFY(LIBAVFORMAT_VERSION); | ||
865 | int length; | ||
866 | |||
867 | 34 | mxf_write_metadata_key(pb, 0x013000); | |
868 | PRINT_KEY(s, "identification key", pb->buf_ptr - 16); | ||
869 | |||
870 | 34 | length = 100 +mxf_utf16_local_tag_length(company) + | |
871 | 34 | mxf_utf16_local_tag_length(product) + | |
872 | 34 | mxf_utf16_local_tag_length(platform) + | |
873 | 34 | mxf_utf16_local_tag_length(version); | |
874 | 34 | klv_encode_ber_length(pb, length); | |
875 | |||
876 | // write uid | ||
877 | 34 | mxf_write_local_tag(s, 16, 0x3C0A); | |
878 | 34 | mxf_write_uuid(pb, Identification, 0); | |
879 | PRINT_KEY(s, "identification uid", pb->buf_ptr - 16); | ||
880 | |||
881 | // write generation uid | ||
882 | 34 | mxf_write_local_tag(s, 16, 0x3C09); | |
883 | 34 | mxf_write_uuid(pb, Identification, 1); | |
884 | 34 | mxf_write_local_tag_utf16(s, 0x3C01, company); // Company Name | |
885 | 34 | mxf_write_local_tag_utf16(s, 0x3C02, product); // Product Name | |
886 | |||
887 | 34 | mxf_write_local_tag(s, 10, 0x3C03); // Product Version | |
888 | 34 | store_version(s); | |
889 | |||
890 | 34 | mxf_write_local_tag_utf16(s, 0x3C04, version); // Version String | |
891 | 34 | mxf_write_local_tag_utf16(s, 0x3C08, platform); // Platform | |
892 | |||
893 | // write product uid | ||
894 | 34 | mxf_write_local_tag(s, 16, 0x3C05); | |
895 | 34 | avio_write(pb, product_uid, 16); | |
896 | |||
897 | // modification date | ||
898 | 34 | mxf_write_local_tag(s, 8, 0x3C06); | |
899 | 34 | avio_wb64(pb, mxf->timestamp); | |
900 | |||
901 | 34 | mxf_write_local_tag(s, 10, 0x3C07); // Toolkit Version | |
902 | 34 | store_version(s); | |
903 | 34 | } | |
904 | |||
905 | 34 | static void mxf_write_content_storage(AVFormatContext *s, MXFPackage *packages, int package_count) | |
906 | { | ||
907 | 34 | AVIOContext *pb = s->pb; | |
908 | int i; | ||
909 | |||
910 | 34 | mxf_write_metadata_key(pb, 0x011800); | |
911 | PRINT_KEY(s, "content storage key", pb->buf_ptr - 16); | ||
912 | 34 | klv_encode_ber_length(pb, 60 + (16 * package_count)); | |
913 | |||
914 | // write uid | ||
915 | 34 | mxf_write_local_tag(s, 16, 0x3C0A); | |
916 | 34 | mxf_write_uuid(pb, ContentStorage, 0); | |
917 | PRINT_KEY(s, "content storage uid", pb->buf_ptr - 16); | ||
918 | |||
919 | // write package reference | ||
920 | 34 | mxf_write_local_tag(s, 16 * package_count + 8, 0x1901); | |
921 | 34 | mxf_write_refs_count(pb, package_count); | |
922 |
2/2✓ Branch 0 taken 70 times.
✓ Branch 1 taken 34 times.
|
104 | for (i = 0; i < package_count; i++) { |
923 | 70 | mxf_write_uuid(pb, packages[i].type, packages[i].instance); | |
924 | } | ||
925 | |||
926 | // write essence container data | ||
927 | 34 | mxf_write_local_tag(s, 8 + 16, 0x1902); | |
928 | 34 | mxf_write_refs_count(pb, 1); | |
929 | 34 | mxf_write_uuid(pb, EssenceContainerData, 0); | |
930 | 34 | } | |
931 | |||
932 | 190 | static void mxf_write_track(AVFormatContext *s, AVStream *st, MXFPackage *package) | |
933 | { | ||
934 | 190 | MXFContext *mxf = s->priv_data; | |
935 | 190 | AVIOContext *pb = s->pb; | |
936 | 190 | MXFStreamContext *sc = st->priv_data; | |
937 | |||
938 | 190 | mxf_write_metadata_key(pb, 0x013b00); | |
939 | PRINT_KEY(s, "track key", pb->buf_ptr - 16); | ||
940 | 190 | klv_encode_ber_length(pb, 80); | |
941 | |||
942 | // write track uid | ||
943 | 190 | mxf_write_local_tag(s, 16, 0x3C0A); | |
944 | 190 | mxf_write_uuid(pb, Track, mxf->track_instance_count); | |
945 | PRINT_KEY(s, "track uid", pb->buf_ptr - 16); | ||
946 | |||
947 | // write track id | ||
948 | 190 | mxf_write_local_tag(s, 4, 0x4801); | |
949 | 190 | avio_wb32(pb, st->index+2); | |
950 | |||
951 | // write track number | ||
952 | 190 | mxf_write_local_tag(s, 4, 0x4804); | |
953 |
2/2✓ Branch 0 taken 92 times.
✓ Branch 1 taken 98 times.
|
190 | if (package->type == MaterialPackage) |
954 | 92 | avio_wb32(pb, 0); // track number of material package is 0 | |
955 | else | ||
956 | 98 | avio_write(pb, sc->track_essence_element_key + 12, 4); | |
957 | |||
958 | // write edit rate | ||
959 | 190 | mxf_write_local_tag(s, 8, 0x4B01); | |
960 | |||
961 |
4/4✓ Branch 0 taken 70 times.
✓ Branch 1 taken 120 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 58 times.
|
190 | if (st == mxf->timecode_track && IS_OPATOM(s)) { |
962 | 12 | avio_wb32(pb, mxf->tc.rate.num); | |
963 | 12 | avio_wb32(pb, mxf->tc.rate.den); | |
964 | } else { | ||
965 | 178 | avio_wb32(pb, mxf->time_base.den); | |
966 | 178 | avio_wb32(pb, mxf->time_base.num); | |
967 | } | ||
968 | |||
969 | // write origin | ||
970 | 190 | mxf_write_local_tag(s, 8, 0x4B02); | |
971 | 190 | avio_wb64(pb, 0); | |
972 | |||
973 | // write sequence refs | ||
974 | 190 | mxf_write_local_tag(s, 16, 0x4803); | |
975 | 190 | mxf_write_uuid(pb, Sequence, mxf->track_instance_count); | |
976 | 190 | } | |
977 | |||
978 | static const uint8_t smpte_12m_timecode_track_data_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x01,0x01,0x00,0x00,0x00 }; | ||
979 | |||
980 | 380 | static void mxf_write_common_fields(AVFormatContext *s, AVStream *st) | |
981 | { | ||
982 | 380 | MXFContext *mxf = s->priv_data; | |
983 | 380 | AVIOContext *pb = s->pb; | |
984 | |||
985 | // find data define uls | ||
986 | 380 | mxf_write_local_tag(s, 16, 0x0201); | |
987 |
2/2✓ Branch 0 taken 140 times.
✓ Branch 1 taken 240 times.
|
380 | if (st == mxf->timecode_track) |
988 | 140 | avio_write(pb, smpte_12m_timecode_track_data_ul, 16); | |
989 | else { | ||
990 | 240 | const MXFCodecUL *data_def_ul = mxf_get_codec_ul_by_id(ff_mxf_data_definition_uls, st->codecpar->codec_type); | |
991 | 240 | avio_write(pb, data_def_ul->uid, 16); | |
992 | } | ||
993 | |||
994 | // write duration | ||
995 | 380 | mxf_write_local_tag(s, 8, 0x0202); | |
996 | |||
997 |
6/6✓ Branch 0 taken 240 times.
✓ Branch 1 taken 140 times.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 216 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 16 times.
|
380 | if (st != mxf->timecode_track && IS_OPATOM(s) && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { |
998 | 8 | avio_wb64(pb, mxf->body_offset / mxf->edit_unit_byte_count); | |
999 | } else { | ||
1000 | 372 | avio_wb64(pb, mxf->duration); | |
1001 | } | ||
1002 | 380 | } | |
1003 | |||
1004 | 190 | static void mxf_write_sequence(AVFormatContext *s, AVStream *st, MXFPackage *package) | |
1005 | { | ||
1006 | 190 | MXFContext *mxf = s->priv_data; | |
1007 | 190 | AVIOContext *pb = s->pb; | |
1008 | enum MXFMetadataSetType component; | ||
1009 | |||
1010 | 190 | mxf_write_metadata_key(pb, 0x010f00); | |
1011 | PRINT_KEY(s, "sequence key", pb->buf_ptr - 16); | ||
1012 | 190 | klv_encode_ber_length(pb, 80); | |
1013 | |||
1014 | 190 | mxf_write_local_tag(s, 16, 0x3C0A); | |
1015 | 190 | mxf_write_uuid(pb, Sequence, mxf->track_instance_count); | |
1016 | |||
1017 | PRINT_KEY(s, "sequence uid", pb->buf_ptr - 16); | ||
1018 | 190 | mxf_write_common_fields(s, st); | |
1019 | |||
1020 | // write structural component | ||
1021 | 190 | mxf_write_local_tag(s, 16 + 8, 0x1001); | |
1022 | 190 | mxf_write_refs_count(pb, 1); | |
1023 |
2/2✓ Branch 0 taken 70 times.
✓ Branch 1 taken 120 times.
|
190 | if (st == mxf->timecode_track) |
1024 | 70 | component = TimecodeComponent; | |
1025 | else | ||
1026 | 120 | component = SourceClip; | |
1027 | |||
1028 | 190 | mxf_write_uuid(pb, component, mxf->track_instance_count); | |
1029 | 190 | } | |
1030 | |||
1031 | 70 | static void mxf_write_timecode_component(AVFormatContext *s, AVStream *st, MXFPackage *package) | |
1032 | { | ||
1033 | 70 | MXFContext *mxf = s->priv_data; | |
1034 | 70 | AVIOContext *pb = s->pb; | |
1035 | |||
1036 | 70 | mxf_write_metadata_key(pb, 0x011400); | |
1037 | 70 | klv_encode_ber_length(pb, 75); | |
1038 | |||
1039 | // UID | ||
1040 | 70 | mxf_write_local_tag(s, 16, 0x3C0A); | |
1041 | 70 | mxf_write_uuid(pb, TimecodeComponent, mxf->track_instance_count); | |
1042 | |||
1043 | 70 | mxf_write_common_fields(s, st); | |
1044 | |||
1045 | // Start Time Code | ||
1046 | 70 | mxf_write_local_tag(s, 8, 0x1501); | |
1047 | 70 | avio_wb64(pb, mxf->tc.start); | |
1048 | |||
1049 | // Rounded Time Code Base | ||
1050 | 70 | mxf_write_local_tag(s, 2, 0x1502); | |
1051 | 70 | avio_wb16(pb, mxf->timecode_base); | |
1052 | |||
1053 | // Drop Frame | ||
1054 | 70 | mxf_write_local_tag(s, 1, 0x1503); | |
1055 | 70 | avio_w8(pb, !!(mxf->tc.flags & AV_TIMECODE_FLAG_DROPFRAME)); | |
1056 | 70 | } | |
1057 | |||
1058 | 120 | static void mxf_write_structural_component(AVFormatContext *s, AVStream *st, MXFPackage *package) | |
1059 | { | ||
1060 | 120 | MXFContext *mxf = s->priv_data; | |
1061 | 120 | AVIOContext *pb = s->pb; | |
1062 | |||
1063 | 120 | mxf_write_metadata_key(pb, 0x011100); | |
1064 | PRINT_KEY(s, "sturctural component key", pb->buf_ptr - 16); | ||
1065 | 120 | klv_encode_ber_length(pb, 108); | |
1066 | |||
1067 | // write uid | ||
1068 | 120 | mxf_write_local_tag(s, 16, 0x3C0A); | |
1069 | 120 | mxf_write_uuid(pb, SourceClip, mxf->track_instance_count); | |
1070 | |||
1071 | PRINT_KEY(s, "structural component uid", pb->buf_ptr - 16); | ||
1072 | 120 | mxf_write_common_fields(s, st); | |
1073 | |||
1074 | // write start_position | ||
1075 | 120 | mxf_write_local_tag(s, 8, 0x1201); | |
1076 | 120 | avio_wb64(pb, 0); | |
1077 | |||
1078 | // write source package uid, end of the reference | ||
1079 | 120 | mxf_write_local_tag(s, 32, 0x1101); | |
1080 |
2/2✓ Branch 0 taken 58 times.
✓ Branch 1 taken 62 times.
|
120 | if (!package->ref) { |
1081 | 58 | ffio_fill(pb, 0, 32); | |
1082 | } else | ||
1083 | 62 | mxf_write_umid(s, package->ref->instance); | |
1084 | |||
1085 | // write source track id | ||
1086 | 120 | mxf_write_local_tag(s, 4, 0x1102); | |
1087 |
4/4✓ Branch 0 taken 62 times.
✓ Branch 1 taken 58 times.
✓ Branch 2 taken 58 times.
✓ Branch 3 taken 4 times.
|
120 | if (package->type == SourcePackage && !package->ref) |
1088 | 58 | avio_wb32(pb, 0); | |
1089 | else | ||
1090 | 62 | avio_wb32(pb, st->index+2); | |
1091 | 120 | } | |
1092 | |||
1093 | 2 | static void mxf_write_tape_descriptor(AVFormatContext *s) | |
1094 | { | ||
1095 | 2 | AVIOContext *pb = s->pb; | |
1096 | |||
1097 | 2 | mxf_write_metadata_key(pb, 0x012e00); | |
1098 | PRINT_KEY(s, "tape descriptor key", pb->buf_ptr - 16); | ||
1099 | 2 | klv_encode_ber_length(pb, 20); | |
1100 | 2 | mxf_write_local_tag(s, 16, 0x3C0A); | |
1101 | 2 | mxf_write_uuid(pb, TapeDescriptor, 0); | |
1102 | PRINT_KEY(s, "tape_desc uid", pb->buf_ptr - 16); | ||
1103 | 2 | } | |
1104 | |||
1105 | |||
1106 | 22 | static void mxf_write_multi_descriptor(AVFormatContext *s) | |
1107 | { | ||
1108 | 22 | MXFContext *mxf = s->priv_data; | |
1109 | 22 | AVIOContext *pb = s->pb; | |
1110 | const uint8_t *ul; | ||
1111 | int i; | ||
1112 | |||
1113 | 22 | mxf_write_metadata_key(pb, 0x014400); | |
1114 | PRINT_KEY(s, "multiple descriptor key", pb->buf_ptr - 16); | ||
1115 | 22 | klv_encode_ber_length(pb, 64 + 16LL * s->nb_streams); | |
1116 | |||
1117 | 22 | mxf_write_local_tag(s, 16, 0x3C0A); | |
1118 | 22 | mxf_write_uuid(pb, MultipleDescriptor, 0); | |
1119 | PRINT_KEY(s, "multi_desc uid", pb->buf_ptr - 16); | ||
1120 | |||
1121 | // write sample rate | ||
1122 | 22 | mxf_write_local_tag(s, 8, 0x3001); | |
1123 | 22 | avio_wb32(pb, mxf->time_base.den); | |
1124 | 22 | avio_wb32(pb, mxf->time_base.num); | |
1125 | |||
1126 | // write essence container ul | ||
1127 | 22 | mxf_write_local_tag(s, 16, 0x3004); | |
1128 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 2 times.
|
22 | if (mxf->essence_container_count > 1) |
1129 | 20 | ul = multiple_desc_ul; | |
1130 | else { | ||
1131 | 2 | MXFStreamContext *sc = s->streams[0]->priv_data; | |
1132 | 2 | ul = *sc->container_ul; | |
1133 | } | ||
1134 | 22 | avio_write(pb, ul, 16); | |
1135 | |||
1136 | // write sub descriptor refs | ||
1137 | 22 | mxf_write_local_tag(s, s->nb_streams * 16 + 8, 0x3F01); | |
1138 | 22 | mxf_write_refs_count(pb, s->nb_streams); | |
1139 |
2/2✓ Branch 0 taken 46 times.
✓ Branch 1 taken 22 times.
|
68 | for (i = 0; i < s->nb_streams; i++) |
1140 | 46 | mxf_write_uuid(pb, SubDescriptor, i); | |
1141 | 22 | } | |
1142 | |||
1143 | 58 | static int64_t mxf_write_generic_desc(AVFormatContext *s, AVStream *st, const UID key) | |
1144 | { | ||
1145 | 58 | MXFContext *mxf = s->priv_data; | |
1146 | 58 | MXFStreamContext *sc = st->priv_data; | |
1147 | 58 | AVIOContext *pb = s->pb; | |
1148 | int64_t pos; | ||
1149 | |||
1150 | 58 | avio_write(pb, key, 16); | |
1151 | 58 | klv_encode_ber4_length(pb, 0); | |
1152 | 58 | pos = avio_tell(pb); | |
1153 | |||
1154 | 58 | mxf_write_local_tag(s, 16, 0x3C0A); | |
1155 | 58 | mxf_write_uuid(pb, SubDescriptor, st->index); | |
1156 | |||
1157 | 58 | mxf_write_local_tag(s, 4, 0x3006); | |
1158 | 58 | avio_wb32(pb, st->index+2); | |
1159 | |||
1160 | 58 | mxf_write_local_tag(s, 8, 0x3001); | |
1161 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 52 times.
|
58 | if (IS_D10(s)) { |
1162 | 6 | avio_wb32(pb, mxf->time_base.den); | |
1163 | 6 | avio_wb32(pb, mxf->time_base.num); | |
1164 | } else { | ||
1165 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 20 times.
|
52 | if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16LE || |
1166 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 28 times.
|
32 | st->codecpar->codec_id == AV_CODEC_ID_PCM_S24LE) { |
1167 | 24 | avio_wb32(pb, st->codecpar->sample_rate); | |
1168 | 24 | avio_wb32(pb, 1); | |
1169 | } else { | ||
1170 | 28 | avio_wb32(pb, mxf->time_base.den); | |
1171 | 28 | avio_wb32(pb, mxf->time_base.num); | |
1172 | } | ||
1173 | } | ||
1174 | |||
1175 | 58 | mxf_write_local_tag(s, 16, 0x3004); | |
1176 | 58 | avio_write(pb, *sc->container_ul, 16); | |
1177 | |||
1178 | 58 | return pos; | |
1179 | } | ||
1180 | |||
1181 | static const UID mxf_s436m_anc_descriptor_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x5c,0x00 }; | ||
1182 | static const UID mxf_mpegvideo_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 }; | ||
1183 | static const UID mxf_wav_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 }; | ||
1184 | static const UID mxf_aes3_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 }; | ||
1185 | static const UID mxf_cdci_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x28,0x00 }; | ||
1186 | static const UID mxf_rgba_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x29,0x00 }; | ||
1187 | static const UID mxf_generic_sound_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x42,0x00 }; | ||
1188 | |||
1189 | static const UID mxf_avc_subdescriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x6E,0x00 }; | ||
1190 | static const UID mxf_ffv1_subdescriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x81,0x03 }; | ||
1191 | static const UID mxf_jpeg2000_subdescriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x5A,0x00}; | ||
1192 | |||
1193 | 16 | static inline uint16_t rescale_mastering_chroma(AVRational q) | |
1194 | { | ||
1195 | 16 | return av_clip_uint16(av_rescale(q.num, FF_MXF_MASTERING_CHROMA_DEN, q.den)); | |
1196 | } | ||
1197 | |||
1198 | 4 | static inline uint32_t rescale_mastering_luma(AVRational q) | |
1199 | { | ||
1200 | 4 | return av_rescale(q.num, FF_MXF_MASTERING_LUMA_DEN, q.den); | |
1201 | } | ||
1202 | |||
1203 | 32 | static int64_t mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID key) | |
1204 | { | ||
1205 | 32 | MXFStreamContext *sc = st->priv_data; | |
1206 | 32 | AVIOContext *pb = s->pb; | |
1207 | 32 | int stored_width = st->codecpar->width; | |
1208 | 32 | int stored_height = st->codecpar->height; | |
1209 | int display_width; | ||
1210 | int display_height; | ||
1211 | int f1, f2; | ||
1212 | const MXFCodecUL *color_primaries_ul; | ||
1213 | const MXFCodecUL *color_trc_ul; | ||
1214 | const MXFCodecUL *color_space_ul; | ||
1215 | 32 | int64_t pos = mxf_write_generic_desc(s, st, key); | |
1216 | const AVPacketSideData *side_data; | ||
1217 | |||
1218 | 32 | color_primaries_ul = mxf_get_codec_ul_by_id(ff_mxf_color_primaries_uls, st->codecpar->color_primaries); | |
1219 | 32 | color_trc_ul = mxf_get_codec_ul_by_id(ff_mxf_color_trc_uls, st->codecpar->color_trc); | |
1220 | 32 | color_space_ul = mxf_get_codec_ul_by_id(ff_mxf_color_space_uls, st->codecpar->color_space); | |
1221 | |||
1222 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 26 times.
|
32 | if (st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO) { |
1223 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
|
6 | if (st->codecpar->height == 1080) |
1224 | 2 | stored_width = 1920; | |
1225 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | else if (st->codecpar->height == 720) |
1226 | ✗ | stored_width = 1280; | |
1227 | } | ||
1228 | 32 | display_width = stored_width; | |
1229 | |||
1230 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 12 times.
|
32 | switch (st->codecpar->codec_id) { |
1231 | 20 | case AV_CODEC_ID_MPEG2VIDEO: | |
1232 | case AV_CODEC_ID_H264: | ||
1233 | //Based on 16x16 macroblocks | ||
1234 | 20 | stored_width = (stored_width+15)/16*16; | |
1235 | 20 | stored_height = (stored_height+15)/16*16; | |
1236 | 20 | break; | |
1237 | 12 | default: | |
1238 | 12 | break; | |
1239 | } | ||
1240 | |||
1241 | //Stored width | ||
1242 | 32 | mxf_write_local_tag(s, 4, 0x3203); | |
1243 | 32 | avio_wb32(pb, stored_width); | |
1244 | |||
1245 | //Stored height | ||
1246 | 32 | mxf_write_local_tag(s, 4, 0x3202); | |
1247 | 32 | avio_wb32(pb, stored_height>>sc->interlaced); | |
1248 | |||
1249 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 28 times.
|
32 | if (IS_D10(s)) { |
1250 | //Stored F2 Offset | ||
1251 | 4 | mxf_write_local_tag(s, 4, 0x3216); | |
1252 | 4 | avio_wb32(pb, 0); | |
1253 | |||
1254 | //Image Start Offset | ||
1255 | 4 | mxf_write_local_tag(s, 4, 0x3213); | |
1256 | 4 | avio_wb32(pb, 0); | |
1257 | |||
1258 | //Image End Offset | ||
1259 | 4 | mxf_write_local_tag(s, 4, 0x3214); | |
1260 | 4 | avio_wb32(pb, 0); | |
1261 | } | ||
1262 | |||
1263 | //Sampled width | ||
1264 | 32 | mxf_write_local_tag(s, 4, 0x3205); | |
1265 | 32 | avio_wb32(pb, display_width); | |
1266 | |||
1267 | //Samples height | ||
1268 | 32 | mxf_write_local_tag(s, 4, 0x3204); | |
1269 | 32 | avio_wb32(pb, st->codecpar->height>>sc->interlaced); | |
1270 | |||
1271 | //Sampled X Offset | ||
1272 | 32 | mxf_write_local_tag(s, 4, 0x3206); | |
1273 | 32 | avio_wb32(pb, 0); | |
1274 | |||
1275 | //Sampled Y Offset | ||
1276 | 32 | mxf_write_local_tag(s, 4, 0x3207); | |
1277 | 32 | avio_wb32(pb, 0); | |
1278 | |||
1279 | //Display width | ||
1280 | 32 | mxf_write_local_tag(s, 4, 0x3209); | |
1281 | 32 | avio_wb32(pb, display_width); | |
1282 | |||
1283 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 24 times.
|
32 | if (st->codecpar->height == 608) // PAL + VBI |
1284 | 8 | display_height = 576; | |
1285 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | else if (st->codecpar->height == 512) // NTSC + VBI |
1286 | ✗ | display_height = 486; | |
1287 | else | ||
1288 | 24 | display_height = st->codecpar->height; | |
1289 | |||
1290 | //Display height | ||
1291 | 32 | mxf_write_local_tag(s, 4, 0x3208); | |
1292 | 32 | avio_wb32(pb, display_height>>sc->interlaced); | |
1293 | |||
1294 | // display X offset | ||
1295 | 32 | mxf_write_local_tag(s, 4, 0x320A); | |
1296 | 32 | avio_wb32(pb, 0); | |
1297 | |||
1298 | // display Y offset | ||
1299 | 32 | mxf_write_local_tag(s, 4, 0x320B); | |
1300 | 32 | avio_wb32(pb, (st->codecpar->height - display_height)>>sc->interlaced); | |
1301 | |||
1302 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 18 times.
|
32 | if (sc->interlaced) { |
1303 | //Display F2 Offset | ||
1304 | 14 | mxf_write_local_tag(s, 4, 0x3217); | |
1305 | 14 | avio_wb32(pb, -((st->codecpar->height - display_height)&1)); | |
1306 | } | ||
1307 | |||
1308 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | if (key != mxf_rgba_descriptor_key) { |
1309 | // component depth | ||
1310 | 32 | mxf_write_local_tag(s, 4, 0x3301); | |
1311 | 32 | avio_wb32(pb, sc->component_depth); | |
1312 | |||
1313 | // horizontal subsampling | ||
1314 | 32 | mxf_write_local_tag(s, 4, 0x3302); | |
1315 | 32 | avio_wb32(pb, sc->h_chroma_sub_sample); | |
1316 | |||
1317 | // vertical subsampling | ||
1318 | 32 | mxf_write_local_tag(s, 4, 0x3308); | |
1319 | 32 | avio_wb32(pb, sc->v_chroma_sub_sample); | |
1320 | |||
1321 | // color siting | ||
1322 | 32 | mxf_write_local_tag(s, 1, 0x3303); | |
1323 | 32 | avio_w8(pb, sc->color_siting); | |
1324 | |||
1325 | // Padding Bits | ||
1326 | 32 | mxf_write_local_tag(s, 2, 0x3307); | |
1327 | 32 | avio_wb16(pb, 0); | |
1328 | |||
1329 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | if (st->codecpar->color_range != AVCOL_RANGE_UNSPECIFIED) { |
1330 | 32 | int black = 0, | |
1331 | 32 | white = (1<<sc->component_depth) - 1, | |
1332 | 32 | color = (1<<sc->component_depth); | |
1333 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | if (st->codecpar->color_range == AVCOL_RANGE_MPEG) { |
1334 | 32 | black = 1 << (sc->component_depth - 4); | |
1335 | 32 | white = 235 << (sc->component_depth - 8); | |
1336 | 32 | color = (14 << (sc->component_depth - 4)) + 1; | |
1337 | } | ||
1338 | 32 | mxf_write_local_tag(s, 4, 0x3304); | |
1339 | 32 | avio_wb32(pb, black); | |
1340 | 32 | mxf_write_local_tag(s, 4, 0x3305); | |
1341 | 32 | avio_wb32(pb, white); | |
1342 | 32 | mxf_write_local_tag(s, 4, 0x3306); | |
1343 | 32 | avio_wb32(pb, color); | |
1344 | } | ||
1345 | } | ||
1346 | |||
1347 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 28 times.
|
32 | if (sc->signal_standard) { |
1348 | 4 | mxf_write_local_tag(s, 1, 0x3215); | |
1349 | 4 | avio_w8(pb, sc->signal_standard); | |
1350 | } | ||
1351 | |||
1352 | // frame layout | ||
1353 | 32 | mxf_write_local_tag(s, 1, 0x320C); | |
1354 | 32 | avio_w8(pb, sc->interlaced); | |
1355 | |||
1356 | // video line map | ||
1357 |
5/7✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 8 times.
|
32 | switch (st->codecpar->height) { |
1358 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
|
8 | case 576: f1 = 23; f2 = st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO ? 335 : 336; break; |
1359 | 8 | case 608: f1 = 7; f2 = 320; break; | |
1360 | ✗ | case 480: f1 = 20; f2 = st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO ? 285 : 283; break; | |
1361 | ✗ | case 512: f1 = 7; f2 = 270; break; | |
1362 | 4 | case 720: f1 = 26; f2 = 0; break; // progressive | |
1363 | 4 | case 1080: f1 = 21; f2 = 584; break; | |
1364 | 8 | default: f1 = 0; f2 = 0; break; | |
1365 | } | ||
1366 | |||
1367 |
4/4✓ Branch 0 taken 18 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 12 times.
|
32 | if (!sc->interlaced && f2) { |
1368 | 6 | f2 = 0; | |
1369 | 6 | f1 *= 2; | |
1370 | } | ||
1371 | |||
1372 | |||
1373 | 32 | mxf_write_local_tag(s, 16, 0x320D); | |
1374 | 32 | avio_wb32(pb, 2); | |
1375 | 32 | avio_wb32(pb, 4); | |
1376 | 32 | avio_wb32(pb, f1); | |
1377 | 32 | avio_wb32(pb, f2); | |
1378 | |||
1379 | 32 | mxf_write_local_tag(s, 8, 0x320E); | |
1380 | 32 | avio_wb32(pb, sc->aspect_ratio.num); | |
1381 | 32 | avio_wb32(pb, sc->aspect_ratio.den); | |
1382 | |||
1383 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 30 times.
|
32 | if (color_primaries_ul->uid[0]) { |
1384 | 2 | mxf_write_local_tag(s, 16, 0x3219); | |
1385 | 2 | avio_write(pb, color_primaries_ul->uid, 16); | |
1386 | }; | ||
1387 | |||
1388 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 22 times.
|
32 | if (color_trc_ul->uid[0]) { |
1389 | 10 | mxf_write_local_tag(s, 16, 0x3210); | |
1390 | 10 | avio_write(pb, color_trc_ul->uid, 16); | |
1391 | }; | ||
1392 | |||
1393 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 30 times.
|
32 | if (color_space_ul->uid[0]) { |
1394 | 2 | mxf_write_local_tag(s, 16, 0x321A); | |
1395 | 2 | avio_write(pb, color_space_ul->uid, 16); | |
1396 | }; | ||
1397 | |||
1398 | 32 | mxf_write_local_tag(s, 16, 0x3201); | |
1399 | 32 | avio_write(pb, *sc->codec_ul, 16); | |
1400 | |||
1401 | // Mastering Display metadata | ||
1402 | 32 | side_data = av_packet_side_data_get(st->codecpar->coded_side_data, | |
1403 | 32 | st->codecpar->nb_coded_side_data, | |
1404 | AV_PKT_DATA_MASTERING_DISPLAY_METADATA); | ||
1405 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 30 times.
|
32 | if (side_data) { |
1406 | 2 | const AVMasteringDisplayMetadata *metadata = (const AVMasteringDisplayMetadata*)side_data->data; | |
1407 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (metadata->has_primaries) { |
1408 | 2 | mxf_write_local_tag(s, 12, 0x8301); | |
1409 | 2 | avio_wb16(pb, rescale_mastering_chroma(metadata->display_primaries[0][0])); | |
1410 | 2 | avio_wb16(pb, rescale_mastering_chroma(metadata->display_primaries[0][1])); | |
1411 | 2 | avio_wb16(pb, rescale_mastering_chroma(metadata->display_primaries[1][0])); | |
1412 | 2 | avio_wb16(pb, rescale_mastering_chroma(metadata->display_primaries[1][1])); | |
1413 | 2 | avio_wb16(pb, rescale_mastering_chroma(metadata->display_primaries[2][0])); | |
1414 | 2 | avio_wb16(pb, rescale_mastering_chroma(metadata->display_primaries[2][1])); | |
1415 | 2 | mxf_write_local_tag(s, 4, 0x8302); | |
1416 | 2 | avio_wb16(pb, rescale_mastering_chroma(metadata->white_point[0])); | |
1417 | 2 | avio_wb16(pb, rescale_mastering_chroma(metadata->white_point[1])); | |
1418 | } else { | ||
1419 | ✗ | av_log(NULL, AV_LOG_VERBOSE, "Not writing mastering display primaries. Missing data.\n"); | |
1420 | } | ||
1421 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (metadata->has_luminance) { |
1422 | 2 | mxf_write_local_tag(s, 4, 0x8303); | |
1423 | 2 | avio_wb32(pb, rescale_mastering_luma(metadata->max_luminance)); | |
1424 | 2 | mxf_write_local_tag(s, 4, 0x8304); | |
1425 | 2 | avio_wb32(pb, rescale_mastering_luma(metadata->min_luminance)); | |
1426 | } else { | ||
1427 | ✗ | av_log(NULL, AV_LOG_VERBOSE, "Not writing mastering display luminances. Missing data.\n"); | |
1428 | } | ||
1429 | } | ||
1430 | |||
1431 |
4/4✓ Branch 0 taken 14 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 6 times.
|
32 | if (sc->interlaced && sc->field_dominance) { |
1432 | 8 | mxf_write_local_tag(s, 1, 0x3212); | |
1433 | 8 | avio_w8(pb, sc->field_dominance); | |
1434 | } | ||
1435 | |||
1436 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
32 | if (st->codecpar->codec_id == AV_CODEC_ID_H264 && !sc->avc_intra) { |
1437 | // write avc sub descriptor ref | ||
1438 | ✗ | mxf_write_local_tag(s, 8 + 16, 0x8100); | |
1439 | ✗ | mxf_write_refs_count(pb, 1); | |
1440 | ✗ | mxf_write_uuid(pb, AVCSubDescriptor, 0); | |
1441 | } | ||
1442 | |||
1443 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 30 times.
|
32 | if (st->codecpar->codec_id == AV_CODEC_ID_FFV1) { |
1444 | // write ffv1 sub descriptor ref | ||
1445 | 2 | mxf_write_local_tag(s, 8 + 16, 0x8100); | |
1446 | 2 | mxf_write_refs_count(pb, 1); | |
1447 | 2 | mxf_write_uuid(pb, FFV1SubDescriptor, 0); | |
1448 | } | ||
1449 | |||
1450 | 32 | return pos; | |
1451 | } | ||
1452 | |||
1453 | 82 | static void mxf_update_klv_size(AVIOContext *pb, int64_t pos) | |
1454 | { | ||
1455 | 82 | int64_t cur_pos = avio_tell(pb); | |
1456 | 82 | int size = cur_pos - pos; | |
1457 | 82 | avio_seek(pb, pos - 4, SEEK_SET); | |
1458 | 82 | klv_encode_ber4_length(pb, size); | |
1459 | 82 | avio_seek(pb, cur_pos, SEEK_SET); | |
1460 | 82 | } | |
1461 | |||
1462 | ✗ | static void mxf_write_avc_subdesc(AVFormatContext *s, AVStream *st) | |
1463 | { | ||
1464 | ✗ | AVIOContext *pb = s->pb; | |
1465 | int64_t pos; | ||
1466 | |||
1467 | ✗ | avio_write(pb, mxf_avc_subdescriptor_key, 16); | |
1468 | ✗ | klv_encode_ber4_length(pb, 0); | |
1469 | ✗ | pos = avio_tell(pb); | |
1470 | |||
1471 | ✗ | mxf_write_local_tag(s, 16, 0x3C0A); | |
1472 | ✗ | mxf_write_uuid(pb, AVCSubDescriptor, 0); | |
1473 | |||
1474 | ✗ | mxf_write_local_tag(s, 1, 0x8200); | |
1475 | ✗ | avio_w8(pb, 0xFF); // AVC Decoding Delay, unknown | |
1476 | |||
1477 | ✗ | mxf_write_local_tag(s, 1, 0x8201); | |
1478 | ✗ | avio_w8(pb, st->codecpar->profile); // AVC Profile | |
1479 | |||
1480 | ✗ | mxf_write_local_tag(s, 1, 0x8202); | |
1481 | ✗ | avio_w8(pb, st->codecpar->level); // AVC Level | |
1482 | |||
1483 | ✗ | mxf_update_klv_size(s->pb, pos); | |
1484 | ✗ | } | |
1485 | |||
1486 | ✗ | static void mxf_write_jpeg2000_subdesc(AVFormatContext *s, AVStream *st) | |
1487 | { | ||
1488 | ✗ | MXFStreamContext *sc = st->priv_data; | |
1489 | ✗ | AVIOContext *pb = s->pb; | |
1490 | int64_t pos; | ||
1491 | ✗ | const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codecpar->format); | |
1492 | |||
1493 | ✗ | if (!pix_desc) { | |
1494 | ✗ | av_log(s, AV_LOG_ERROR, "Pixel format not set - not writing JPEG2000SubDescriptor\n"); | |
1495 | ✗ | return; | |
1496 | } | ||
1497 | |||
1498 | /* JPEG2000 subdescriptor key */ | ||
1499 | ✗ | avio_write(pb, mxf_jpeg2000_subdescriptor_key, 16); | |
1500 | ✗ | klv_encode_ber4_length(pb, 0); | |
1501 | ✗ | pos = avio_tell(pb); | |
1502 | |||
1503 | ✗ | mxf_write_local_tag(s, 16, 0x3C0A); | |
1504 | ✗ | mxf_write_uuid(pb, JPEG2000SubDescriptor, 0); | |
1505 | |||
1506 | /* Value defining the decoder capabilities (rsiz) */ | ||
1507 | ✗ | mxf_write_local_tag(s, 2, 0x8401); | |
1508 | ✗ | avio_wb16(pb, sc->j2k_info.j2k_rsiz); | |
1509 | /* Width of the JPEG2000 reference grid (Xsiz) */ | ||
1510 | ✗ | mxf_write_local_tag(s, 4, 0x8402); | |
1511 | ✗ | avio_wb32(pb, st->codecpar->width); | |
1512 | /* Height of the JPEG2000 reference grid (Ysiz) */ | ||
1513 | ✗ | mxf_write_local_tag(s, 4, 0x8403); | |
1514 | ✗ | avio_wb32(pb, st->codecpar->height); | |
1515 | /* Horizontal offset from the reference grid origin to the left side of the image area (X0siz) */ | ||
1516 | ✗ | mxf_write_local_tag(s, 4, 0x8404); | |
1517 | ✗ | avio_wb32(pb, sc->j2k_info.j2k_x0siz); | |
1518 | /* Vertical offset from the reference grid origin to the left side of the image area (Y0siz) */ | ||
1519 | ✗ | mxf_write_local_tag(s, 4, 0x8405); | |
1520 | ✗ | avio_wb32(pb, sc->j2k_info.j2k_y0siz); | |
1521 | /* Width of one reference tile with respect to the reference grid (XTsiz) */ | ||
1522 | ✗ | mxf_write_local_tag(s, 4, 0x8406); | |
1523 | ✗ | avio_wb32(pb, sc->j2k_info.j2k_xtsiz); | |
1524 | /* Height of one reference tile with respect to the reference grid (YTsiz) */ | ||
1525 | ✗ | mxf_write_local_tag(s, 4, 0x8407); | |
1526 | ✗ | avio_wb32(pb, sc->j2k_info.j2k_ytsiz); | |
1527 | /* Horizontal offset from the origin of the reference grid to the left side of the first tile (XT0siz) */ | ||
1528 | ✗ | mxf_write_local_tag(s, 4, 0x8408); | |
1529 | ✗ | avio_wb32(pb, sc->j2k_info.j2k_xt0siz); | |
1530 | /* Vertical offset from the origin of the reference grid to the left side of the first tile (YT0siz) */ | ||
1531 | ✗ | mxf_write_local_tag(s, 4, 0x8409); | |
1532 | ✗ | avio_wb32(pb, sc->j2k_info.j2k_yt0siz); | |
1533 | /* Image components number (Csiz) */ | ||
1534 | ✗ | mxf_write_local_tag(s, 2, 0x840A); | |
1535 | ✗ | avio_wb16(pb, pix_desc->nb_components); | |
1536 | /* Array of picture components where each component comprises 3 bytes named Ssiz(i) (Pixel bitdepth - 1), | ||
1537 | XRSiz(i) (Horizontal sampling), YRSiz(i) (Vertical sampling). The array of 3-byte groups is preceded | ||
1538 | by the array header comprising a 4-byte value of the number of components followed by a 4-byte | ||
1539 | value of 3. */ | ||
1540 | ✗ | mxf_write_local_tag(s, 8 + 3*pix_desc->nb_components, 0x840B); | |
1541 | ✗ | avio_wb32(pb, pix_desc->nb_components); | |
1542 | ✗ | avio_wb32(pb, 3); | |
1543 | ✗ | avio_write(pb, sc->j2k_info.j2k_comp_desc, 3*pix_desc->nb_components); | |
1544 | |||
1545 | ✗ | mxf_update_klv_size(pb, pos); | |
1546 | } | ||
1547 | |||
1548 | 14 | static void mxf_write_cdci_desc(AVFormatContext *s, AVStream *st) | |
1549 | { | ||
1550 | 14 | int64_t pos = mxf_write_cdci_common(s, st, mxf_cdci_descriptor_key); | |
1551 | 14 | mxf_update_klv_size(s->pb, pos); | |
1552 | |||
1553 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
|
14 | if (st->codecpar->codec_id == AV_CODEC_ID_H264) { |
1554 | ✗ | mxf_write_avc_subdesc(s, st); | |
1555 | } | ||
1556 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
|
14 | if (st->codecpar->codec_id == AV_CODEC_ID_JPEG2000) { |
1557 | ✗ | mxf_write_jpeg2000_subdesc(s, st); | |
1558 | } | ||
1559 | 14 | } | |
1560 | |||
1561 | ✗ | static void mxf_write_h264_desc(AVFormatContext *s, AVStream *st) | |
1562 | { | ||
1563 | ✗ | MXFStreamContext *sc = st->priv_data; | |
1564 | ✗ | if (sc->avc_intra) { | |
1565 | ✗ | mxf_write_mpegvideo_desc(s, st); | |
1566 | } else { | ||
1567 | ✗ | int64_t pos = mxf_write_cdci_common(s, st, mxf_cdci_descriptor_key); | |
1568 | ✗ | mxf_update_klv_size(s->pb, pos); | |
1569 | ✗ | mxf_write_avc_subdesc(s, st); | |
1570 | } | ||
1571 | ✗ | } | |
1572 | |||
1573 | 2 | static void mxf_write_ffv1_subdesc(AVFormatContext *s, AVStream *st) | |
1574 | { | ||
1575 | 2 | AVIOContext *pb = s->pb; | |
1576 | 2 | MXFStreamContext *sc = st->priv_data; | |
1577 | int64_t pos; | ||
1578 | |||
1579 | 2 | avio_write(pb, mxf_ffv1_subdescriptor_key, 16); | |
1580 | 2 | klv_encode_ber4_length(pb, 0); | |
1581 | 2 | pos = avio_tell(pb); | |
1582 | |||
1583 | 2 | mxf_write_local_tag(s, 16, 0x3C0A); | |
1584 | 2 | mxf_write_uuid(pb, FFV1SubDescriptor, 0); | |
1585 | |||
1586 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (st->codecpar->extradata_size) { |
1587 | 2 | mxf_write_local_tag(s, st->codecpar->extradata_size, 0xDFDB); | |
1588 | 2 | avio_write(pb, st->codecpar->extradata, st->codecpar->extradata_size); // FFV1InitializationMetadata | |
1589 | } | ||
1590 | |||
1591 | 2 | mxf_write_local_tag(s, 2, 0xDFDA); | |
1592 | 2 | avio_wb16(pb, (*sc->codec_ul)[14]); // FFV1Version | |
1593 | |||
1594 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (st->codecpar->extradata_size) { |
1595 | 2 | mxf_write_local_tag(s, 2, 0xDFD9); | |
1596 | 2 | avio_wb16(pb, sc->micro_version); // FFV1MicroVersion | |
1597 | } | ||
1598 | |||
1599 | 2 | mxf_update_klv_size(s->pb, pos); | |
1600 | 2 | } | |
1601 | |||
1602 | 2 | static void mxf_write_ffv1_desc(AVFormatContext *s, AVStream *st) | |
1603 | { | ||
1604 | int is_rgb, pos; | ||
1605 | 2 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(st->codecpar->format); | |
1606 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | av_assert0(desc); |
1607 | 2 | is_rgb = desc->flags & AV_PIX_FMT_FLAG_RGB; | |
1608 | |||
1609 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | pos = mxf_write_cdci_common(s, st, is_rgb ? mxf_rgba_descriptor_key : mxf_cdci_descriptor_key); |
1610 | 2 | mxf_update_klv_size(s->pb, pos); | |
1611 | 2 | mxf_write_ffv1_subdesc(s, st); | |
1612 | 2 | } | |
1613 | |||
1614 | ✗ | static void mxf_write_s436m_anc_desc(AVFormatContext *s, AVStream *st) | |
1615 | { | ||
1616 | ✗ | int64_t pos = mxf_write_generic_desc(s, st, mxf_s436m_anc_descriptor_key); | |
1617 | ✗ | mxf_update_klv_size(s->pb, pos); | |
1618 | ✗ | } | |
1619 | |||
1620 | 16 | static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st) | |
1621 | { | ||
1622 | 16 | AVIOContext *pb = s->pb; | |
1623 | 16 | MXFStreamContext *sc = st->priv_data; | |
1624 | 16 | int profile_and_level = (st->codecpar->profile<<4) | st->codecpar->level; | |
1625 | 16 | int64_t pos = mxf_write_cdci_common(s, st, mxf_mpegvideo_descriptor_key); | |
1626 | |||
1627 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | if (st->codecpar->codec_id != AV_CODEC_ID_H264) { |
1628 | // bit rate | ||
1629 | 16 | mxf_write_local_tag(s, 4, 0x8000); | |
1630 | 16 | avio_wb32(pb, sc->video_bit_rate); | |
1631 | |||
1632 | // profile and level | ||
1633 | 16 | mxf_write_local_tag(s, 1, 0x8007); | |
1634 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
|
16 | if (!st->codecpar->profile) |
1635 | 8 | profile_and_level |= 0x80; // escape bit | |
1636 | 16 | avio_w8(pb, profile_and_level); | |
1637 | |||
1638 | // low delay | ||
1639 | 16 | mxf_write_local_tag(s, 1, 0x8003); | |
1640 | 16 | avio_w8(pb, sc->low_delay); | |
1641 | |||
1642 | // closed gop | ||
1643 | 16 | mxf_write_local_tag(s, 1, 0x8004); | |
1644 | 16 | avio_w8(pb, sc->seq_closed_gop); | |
1645 | |||
1646 | // max gop | ||
1647 | 16 | mxf_write_local_tag(s, 2, 0x8006); | |
1648 | 16 | avio_wb16(pb, sc->max_gop); | |
1649 | |||
1650 | // b picture count | ||
1651 | 16 | mxf_write_local_tag(s, 2, 0x8008); | |
1652 | 16 | avio_wb16(pb, sc->b_picture_count); | |
1653 | } | ||
1654 | |||
1655 | 16 | mxf_update_klv_size(pb, pos); | |
1656 | 16 | } | |
1657 | |||
1658 | 26 | static int64_t mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st, const UID key) | |
1659 | { | ||
1660 | 26 | AVIOContext *pb = s->pb; | |
1661 | 26 | MXFContext *mxf = s->priv_data; | |
1662 | 26 | int show_warnings = !mxf->footer_partition_offset; | |
1663 | 26 | int64_t pos = mxf_write_generic_desc(s, st, key); | |
1664 | |||
1665 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 24 times.
|
26 | if (IS_OPATOM(s)) { |
1666 | 2 | mxf_write_local_tag(s, 8, 0x3002); | |
1667 | 2 | avio_wb64(pb, mxf->body_offset / mxf->edit_unit_byte_count); | |
1668 | } | ||
1669 | |||
1670 | // audio locked | ||
1671 | 26 | mxf_write_local_tag(s, 1, 0x3D02); | |
1672 | 26 | avio_w8(pb, 1); | |
1673 | |||
1674 | // write audio sampling rate | ||
1675 | 26 | mxf_write_local_tag(s, 8, 0x3D03); | |
1676 | 26 | avio_wb32(pb, st->codecpar->sample_rate); | |
1677 | 26 | avio_wb32(pb, 1); | |
1678 | |||
1679 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 24 times.
|
26 | if (IS_D10(s)) { |
1680 | 2 | mxf_write_local_tag(s, 1, 0x3D04); | |
1681 | 2 | avio_w8(pb, 0); | |
1682 | } | ||
1683 | |||
1684 | 26 | mxf_write_local_tag(s, 4, 0x3D07); | |
1685 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 24 times.
|
26 | if (mxf->channel_count == -1) { |
1686 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | if (show_warnings && IS_D10(s) && |
1687 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | (st->codecpar->ch_layout.nb_channels != 4) && |
1688 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | (st->codecpar->ch_layout.nb_channels != 8)) |
1689 | 1 | av_log(s, AV_LOG_WARNING, "the number of audio channels shall be 4 or 8 : the output will not comply to MXF D-10 specs, use -d10_channelcount to fix this\n"); | |
1690 | 2 | avio_wb32(pb, st->codecpar->ch_layout.nb_channels); | |
1691 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | } else if (IS_D10(s)) { |
1692 | ✗ | if (show_warnings && (mxf->channel_count < st->codecpar->ch_layout.nb_channels)) | |
1693 | ✗ | av_log(s, AV_LOG_WARNING, "d10_channelcount < actual number of audio channels : some channels will be discarded\n"); | |
1694 | ✗ | if (show_warnings && (mxf->channel_count != 4) && (mxf->channel_count != 8)) | |
1695 | ✗ | av_log(s, AV_LOG_WARNING, "d10_channelcount shall be set to 4 or 8 : the output will not comply to MXF D-10 specs\n"); | |
1696 | ✗ | avio_wb32(pb, mxf->channel_count); | |
1697 | } else { | ||
1698 | 24 | avio_wb32(pb, st->codecpar->ch_layout.nb_channels); | |
1699 | } | ||
1700 | |||
1701 | 26 | mxf_write_local_tag(s, 4, 0x3D01); | |
1702 | 26 | avio_wb32(pb, av_get_bits_per_sample(st->codecpar->codec_id)); | |
1703 | |||
1704 | 26 | return pos; | |
1705 | } | ||
1706 | |||
1707 | 24 | static int64_t mxf_write_wav_common(AVFormatContext *s, AVStream *st, const UID key) | |
1708 | { | ||
1709 | 24 | AVIOContext *pb = s->pb; | |
1710 | 24 | int64_t pos = mxf_write_generic_sound_common(s, st, key); | |
1711 | |||
1712 | 24 | mxf_write_local_tag(s, 2, 0x3D0A); | |
1713 | 24 | avio_wb16(pb, st->codecpar->block_align); | |
1714 | |||
1715 | // avg bytes per sec | ||
1716 | 24 | mxf_write_local_tag(s, 4, 0x3D09); | |
1717 | 24 | avio_wb32(pb, st->codecpar->block_align*st->codecpar->sample_rate); | |
1718 | |||
1719 | 24 | return pos; | |
1720 | } | ||
1721 | |||
1722 | 2 | static void mxf_write_wav_desc(AVFormatContext *s, AVStream *st) | |
1723 | { | ||
1724 | 2 | int64_t pos = mxf_write_wav_common(s, st, mxf_wav_descriptor_key); | |
1725 | 2 | mxf_update_klv_size(s->pb, pos); | |
1726 | 2 | } | |
1727 | |||
1728 | 22 | static void mxf_write_aes3_desc(AVFormatContext *s, AVStream *st) | |
1729 | { | ||
1730 | 22 | int64_t pos = mxf_write_wav_common(s, st, mxf_aes3_descriptor_key); | |
1731 | 22 | mxf_update_klv_size(s->pb, pos); | |
1732 | 22 | } | |
1733 | |||
1734 | 2 | static void mxf_write_generic_sound_desc(AVFormatContext *s, AVStream *st) | |
1735 | { | ||
1736 | 2 | int64_t pos = mxf_write_generic_sound_common(s, st, mxf_generic_sound_descriptor_key); | |
1737 | 2 | mxf_update_klv_size(s->pb, pos); | |
1738 | 2 | } | |
1739 | |||
1740 | static const uint8_t mxf_indirect_value_utf16le[] = { 0x4c,0x00,0x02,0x10,0x01,0x00,0x00,0x00,0x00,0x06,0x0e,0x2b,0x34,0x01,0x04,0x01,0x01 }; | ||
1741 | |||
1742 | 6 | static int mxf_write_tagged_value(AVFormatContext *s, const char* name, const char* value) | |
1743 | { | ||
1744 | 6 | MXFContext *mxf = s->priv_data; | |
1745 | 6 | AVIOContext *pb = s->pb; | |
1746 | 6 | int name_size = mxf_utf16_local_tag_length(name); | |
1747 | 6 | int indirect_value_size = 13 + mxf_utf16_local_tag_length(value); | |
1748 | |||
1749 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
|
6 | if (!name_size || indirect_value_size == 13) |
1750 | ✗ | return 1; | |
1751 | |||
1752 | 6 | mxf_write_metadata_key(pb, 0x013f00); | |
1753 | 6 | klv_encode_ber_length(pb, 24 + name_size + indirect_value_size); | |
1754 | |||
1755 | // write instance UID | ||
1756 | 6 | mxf_write_local_tag(s, 16, 0x3C0A); | |
1757 | 6 | mxf_write_uuid(pb, TaggedValue, mxf->tagged_value_count); | |
1758 | |||
1759 | // write name | ||
1760 | 6 | mxf_write_local_tag_utf16(s, 0x5001, name); // Name | |
1761 | |||
1762 | // write indirect value | ||
1763 | 6 | mxf_write_local_tag(s, indirect_value_size, 0x5003); | |
1764 | 6 | avio_write(pb, mxf_indirect_value_utf16le, 17); | |
1765 | 6 | avio_put_str16le(pb, value); | |
1766 | |||
1767 | 6 | mxf->tagged_value_count++; | |
1768 | 6 | return 0; | |
1769 | } | ||
1770 | |||
1771 | 6 | static int mxf_write_user_comments(AVFormatContext *s, const AVDictionary *m) | |
1772 | { | ||
1773 | 6 | MXFContext *mxf = s->priv_data; | |
1774 | 6 | AVDictionaryEntry *t = NULL; | |
1775 | 6 | int count = 0; | |
1776 | |||
1777 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
|
12 | while ((t = av_dict_get(m, "comment_", t, AV_DICT_IGNORE_SUFFIX))) { |
1778 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (mxf->tagged_value_count >= UINT16_MAX) { |
1779 | ✗ | av_log(s, AV_LOG_ERROR, "too many tagged values, ignoring remaining\n"); | |
1780 | ✗ | return count; | |
1781 | } | ||
1782 | |||
1783 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | if (mxf_write_tagged_value(s, t->key + 8, t->value) == 0) |
1784 | 6 | count++; | |
1785 | } | ||
1786 | 6 | return count; | |
1787 | } | ||
1788 | |||
1789 | 70 | static void mxf_write_package(AVFormatContext *s, MXFPackage *package) | |
1790 | { | ||
1791 | 70 | MXFContext *mxf = s->priv_data; | |
1792 | 70 | AVIOContext *pb = s->pb; | |
1793 | 70 | int i, track_count = s->nb_streams+1; | |
1794 | 70 | int name_size = mxf_utf16_local_tag_length(package->name); | |
1795 | 70 | int user_comment_count = 0; | |
1796 | |||
1797 |
2/2✓ Branch 0 taken 34 times.
✓ Branch 1 taken 36 times.
|
70 | if (package->type == MaterialPackage) { |
1798 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 28 times.
|
34 | if (mxf->store_user_comments) |
1799 | 6 | user_comment_count = mxf_write_user_comments(s, s->metadata); | |
1800 | 34 | mxf_write_metadata_key(pb, 0x013600); | |
1801 | PRINT_KEY(s, "Material Package key", pb->buf_ptr - 16); | ||
1802 | 34 | klv_encode_ber_length(pb, 92 + name_size + (16*track_count) + (16*user_comment_count) + 12LL*mxf->store_user_comments); | |
1803 | } else { | ||
1804 | 36 | mxf_write_metadata_key(pb, 0x013700); | |
1805 | PRINT_KEY(s, "Source Package key", pb->buf_ptr - 16); | ||
1806 | 36 | klv_encode_ber_length(pb, 112 + name_size + (16*track_count) + 12LL*mxf->store_user_comments); // 20 bytes length for descriptor reference | |
1807 | } | ||
1808 | |||
1809 | // write uid | ||
1810 | 70 | mxf_write_local_tag(s, 16, 0x3C0A); | |
1811 | 70 | mxf_write_uuid(pb, package->type, package->instance); | |
1812 | 70 | av_log(s, AV_LOG_DEBUG, "package type:%d\n", package->type); | |
1813 | PRINT_KEY(s, "package uid", pb->buf_ptr - 16); | ||
1814 | |||
1815 | // write package umid | ||
1816 | 70 | mxf_write_local_tag(s, 32, 0x4401); | |
1817 | 70 | mxf_write_umid(s, package->instance); | |
1818 | PRINT_KEY(s, "package umid second part", pb->buf_ptr - 16); | ||
1819 | |||
1820 | // package name | ||
1821 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 68 times.
|
70 | if (name_size) |
1822 | 2 | mxf_write_local_tag_utf16(s, 0x4402, package->name); | |
1823 | |||
1824 | // package creation date | ||
1825 | 70 | mxf_write_local_tag(s, 8, 0x4405); | |
1826 | 70 | avio_wb64(pb, mxf->timestamp); | |
1827 | |||
1828 | // package modified date | ||
1829 | 70 | mxf_write_local_tag(s, 8, 0x4404); | |
1830 | 70 | avio_wb64(pb, mxf->timestamp); | |
1831 | |||
1832 | // write track refs | ||
1833 | 70 | mxf_write_local_tag(s, track_count*16 + 8, 0x4403); | |
1834 | 70 | mxf_write_refs_count(pb, track_count); | |
1835 | // these are the uuids of the tracks the will be written in mxf_write_track | ||
1836 |
2/2✓ Branch 0 taken 190 times.
✓ Branch 1 taken 70 times.
|
260 | for (i = 0; i < track_count; i++) |
1837 | 190 | mxf_write_uuid(pb, Track, mxf->track_instance_count + i); | |
1838 | |||
1839 | // write user comment refs | ||
1840 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 58 times.
|
70 | if (mxf->store_user_comments) { |
1841 | 12 | mxf_write_local_tag(s, user_comment_count*16 + 8, 0x4406); | |
1842 | 12 | mxf_write_refs_count(pb, user_comment_count); | |
1843 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
|
18 | for (i = 0; i < user_comment_count; i++) |
1844 | 6 | mxf_write_uuid(pb, TaggedValue, mxf->tagged_value_count - user_comment_count + i); | |
1845 | } | ||
1846 | |||
1847 | // write multiple descriptor reference | ||
1848 |
4/4✓ Branch 0 taken 36 times.
✓ Branch 1 taken 34 times.
✓ Branch 2 taken 34 times.
✓ Branch 3 taken 2 times.
|
70 | if (package->type == SourcePackage && package->instance == 1) { |
1849 | 34 | mxf_write_local_tag(s, 16, 0x4701); | |
1850 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 12 times.
|
34 | if (s->nb_streams > 1) { |
1851 | 22 | mxf_write_uuid(pb, MultipleDescriptor, 0); | |
1852 | 22 | mxf_write_multi_descriptor(s); | |
1853 | } else | ||
1854 | 12 | mxf_write_uuid(pb, SubDescriptor, 0); | |
1855 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 34 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
36 | } else if (package->type == SourcePackage && package->instance == 2) { |
1856 | 2 | mxf_write_local_tag(s, 16, 0x4701); | |
1857 | 2 | mxf_write_uuid(pb, TapeDescriptor, 0); | |
1858 | 2 | mxf_write_tape_descriptor(s); | |
1859 | } | ||
1860 | |||
1861 | /* | ||
1862 | * for every 1 track in a package there is 1 sequence and 1 component. | ||
1863 | * all 3 of these elements share the same instance number for generating | ||
1864 | * there instance uuids. mxf->track_instance_count stores this value. | ||
1865 | * mxf->track_instance_count is incremented after a group of all 3 of | ||
1866 | * these elements are written. | ||
1867 | */ | ||
1868 | |||
1869 | // write timecode track | ||
1870 | 70 | mxf_write_track(s, mxf->timecode_track, package); | |
1871 | 70 | mxf_write_sequence(s, mxf->timecode_track, package); | |
1872 | 70 | mxf_write_timecode_component(s, mxf->timecode_track, package); | |
1873 | 70 | mxf->track_instance_count++; | |
1874 | |||
1875 |
2/2✓ Branch 0 taken 120 times.
✓ Branch 1 taken 70 times.
|
190 | for (i = 0; i < s->nb_streams; i++) { |
1876 | 120 | AVStream *st = s->streams[i]; | |
1877 | 120 | mxf_write_track(s, st, package); | |
1878 | 120 | mxf_write_sequence(s, st, package); | |
1879 | 120 | mxf_write_structural_component(s, st, package); | |
1880 | 120 | mxf->track_instance_count++; | |
1881 | |||
1882 |
4/4✓ Branch 0 taken 62 times.
✓ Branch 1 taken 58 times.
✓ Branch 2 taken 58 times.
✓ Branch 3 taken 4 times.
|
120 | if (package->type == SourcePackage && package->instance == 1) { |
1883 | 58 | MXFStreamContext *sc = st->priv_data; | |
1884 | 58 | mxf_essence_container_uls[sc->index].write_desc(s, st); | |
1885 | } | ||
1886 | } | ||
1887 | 70 | } | |
1888 | |||
1889 | 34 | static int mxf_write_essence_container_data(AVFormatContext *s) | |
1890 | { | ||
1891 | 34 | AVIOContext *pb = s->pb; | |
1892 | |||
1893 | 34 | mxf_write_metadata_key(pb, 0x012300); | |
1894 | 34 | klv_encode_ber_length(pb, 72); | |
1895 | |||
1896 | 34 | mxf_write_local_tag(s, 16, 0x3C0A); // Instance UID | |
1897 | 34 | mxf_write_uuid(pb, EssenceContainerData, 0); | |
1898 | |||
1899 | 34 | mxf_write_local_tag(s, 32, 0x2701); // Linked Package UID | |
1900 | 34 | mxf_write_umid(s, 1); | |
1901 | |||
1902 | 34 | mxf_write_local_tag(s, 4, 0x3F07); // BodySID | |
1903 | 34 | avio_wb32(pb, 1); | |
1904 | |||
1905 | 34 | mxf_write_local_tag(s, 4, 0x3F06); // IndexSID | |
1906 | 34 | avio_wb32(pb, 2); | |
1907 | |||
1908 | 34 | return 0; | |
1909 | } | ||
1910 | |||
1911 | 34 | static int mxf_write_header_metadata_sets(AVFormatContext *s) | |
1912 | { | ||
1913 | 34 | MXFContext *mxf = s->priv_data; | |
1914 | 34 | AVDictionaryEntry *entry = NULL; | |
1915 | 34 | AVStream *st = NULL; | |
1916 | int i; | ||
1917 | 34 | MXFPackage packages[3] = {{0}}; | |
1918 | 34 | int package_count = 2; | |
1919 | 34 | packages[0].type = MaterialPackage; | |
1920 | 34 | packages[1].type = SourcePackage; | |
1921 | 34 | packages[1].instance = 1; | |
1922 | 34 | packages[0].ref = &packages[1]; | |
1923 | |||
1924 | |||
1925 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
|
34 | if (entry = av_dict_get(s->metadata, "material_package_name", NULL, 0)) |
1926 | ✗ | packages[0].name = entry->value; | |
1927 | |||
1928 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
|
34 | if (entry = av_dict_get(s->metadata, "file_package_name", NULL, 0)) { |
1929 | ✗ | packages[1].name = entry->value; | |
1930 | } else { | ||
1931 | /* check if any of the streams contain a file_package_name */ | ||
1932 |
2/2✓ Branch 0 taken 58 times.
✓ Branch 1 taken 34 times.
|
92 | for (i = 0; i < s->nb_streams; i++) { |
1933 | 58 | st = s->streams[i]; | |
1934 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 58 times.
|
58 | if (entry = av_dict_get(st->metadata, "file_package_name", NULL, 0)) { |
1935 | ✗ | packages[1].name = entry->value; | |
1936 | ✗ | break; | |
1937 | } | ||
1938 | } | ||
1939 | } | ||
1940 | |||
1941 | 34 | entry = av_dict_get(s->metadata, "reel_name", NULL, 0); | |
1942 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 32 times.
|
34 | if (entry) { |
1943 | 2 | packages[2].name = entry->value; | |
1944 | 2 | packages[2].type = SourcePackage; | |
1945 | 2 | packages[2].instance = 2; | |
1946 | 2 | packages[1].ref = &packages[2]; | |
1947 | 2 | package_count = 3; | |
1948 | } | ||
1949 | |||
1950 | 34 | mxf_write_preface(s); | |
1951 | 34 | mxf_write_identification(s); | |
1952 | 34 | mxf_write_content_storage(s, packages, package_count); | |
1953 | 34 | mxf->track_instance_count = 0; | |
1954 |
2/2✓ Branch 0 taken 70 times.
✓ Branch 1 taken 34 times.
|
104 | for (i = 0; i < package_count; i++) |
1955 | 70 | mxf_write_package(s, &packages[i]); | |
1956 | 34 | mxf_write_essence_container_data(s); | |
1957 | 34 | return 0; | |
1958 | } | ||
1959 | |||
1960 | 1416 | static unsigned klv_fill_size(uint64_t size) | |
1961 | { | ||
1962 | 1416 | unsigned pad = KAG_SIZE - (size & (KAG_SIZE-1)); | |
1963 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1411 times.
|
1416 | if (pad < 20) // smallest fill item possible |
1964 | 5 | return pad + KAG_SIZE; | |
1965 | else | ||
1966 | 1411 | return pad & (KAG_SIZE-1); | |
1967 | } | ||
1968 | |||
1969 | 31 | static void mxf_write_index_table_segment(AVFormatContext *s) | |
1970 | { | ||
1971 | 31 | MXFContext *mxf = s->priv_data; | |
1972 | 31 | AVIOContext *pb = s->pb; | |
1973 | 31 | int i, j, temporal_reordering = 0; | |
1974 | 31 | int key_index = mxf->last_key_index; | |
1975 | 31 | int prev_non_b_picture = 0; | |
1976 | 31 | int audio_frame_size = 0; | |
1977 | int64_t pos; | ||
1978 | |||
1979 | 31 | av_log(s, AV_LOG_DEBUG, "edit units count %d\n", mxf->edit_units_count); | |
1980 | |||
1981 |
4/4✓ Branch 0 taken 14 times.
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 5 times.
|
31 | if (!mxf->edit_units_count && !mxf->edit_unit_byte_count) |
1982 | 9 | return; | |
1983 | |||
1984 | 22 | avio_write(pb, index_table_segment_key, 16); | |
1985 | |||
1986 | 22 | klv_encode_ber4_length(pb, 0); | |
1987 | 22 | pos = avio_tell(pb); | |
1988 | |||
1989 | // instance id | ||
1990 | 22 | mxf_write_local_tag(s, 16, 0x3C0A); | |
1991 | 22 | mxf_write_uuid(pb, IndexTableSegment, mxf->last_indexed_edit_unit); | |
1992 | |||
1993 | // index edit rate | ||
1994 | 22 | mxf_write_local_tag(s, 8, 0x3F0B); | |
1995 | 22 | avio_wb32(pb, mxf->time_base.den); | |
1996 | 22 | avio_wb32(pb, mxf->time_base.num); | |
1997 | |||
1998 | // index start position | ||
1999 | 22 | mxf_write_local_tag(s, 8, 0x3F0C); | |
2000 | 22 | avio_wb64(pb, mxf->last_indexed_edit_unit); | |
2001 | |||
2002 | // index duration | ||
2003 | 22 | mxf_write_local_tag(s, 8, 0x3F0D); | |
2004 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 10 times.
|
22 | if (mxf->edit_unit_byte_count) |
2005 | 12 | avio_wb64(pb, 0); // index table covers whole container | |
2006 | else | ||
2007 | 10 | avio_wb64(pb, mxf->edit_units_count); | |
2008 | |||
2009 | // edit unit byte count | ||
2010 | 22 | mxf_write_local_tag(s, 4, 0x3F05); | |
2011 | 22 | avio_wb32(pb, mxf->edit_unit_byte_count); | |
2012 | |||
2013 | // index sid | ||
2014 | 22 | mxf_write_local_tag(s, 4, 0x3F06); | |
2015 | 22 | avio_wb32(pb, 2); | |
2016 | |||
2017 | // body sid | ||
2018 | 22 | mxf_write_local_tag(s, 4, 0x3F07); | |
2019 | 22 | avio_wb32(pb, 1); | |
2020 | |||
2021 | // real slice count - 1 | ||
2022 | 22 | mxf_write_local_tag(s, 1, 0x3F08); | |
2023 | 22 | avio_w8(pb, !mxf->edit_unit_byte_count); // only one slice for CBR | |
2024 | |||
2025 | // delta entry array | ||
2026 | 22 | mxf_write_local_tag(s, 8 + (s->nb_streams+1)*6, 0x3F09); | |
2027 | 22 | avio_wb32(pb, s->nb_streams+1); // num of entries | |
2028 | 22 | avio_wb32(pb, 6); // size of one entry | |
2029 | // write system item delta entry | ||
2030 | 22 | avio_w8(pb, 0); | |
2031 | 22 | avio_w8(pb, 0); // slice entry | |
2032 | 22 | avio_wb32(pb, 0); // element delta | |
2033 | // write each stream delta entry | ||
2034 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 22 times.
|
60 | for (i = 0; i < s->nb_streams; i++) { |
2035 | 38 | AVStream *st = s->streams[i]; | |
2036 | 38 | MXFStreamContext *sc = st->priv_data; | |
2037 | 38 | avio_w8(pb, sc->temporal_reordering); | |
2038 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 35 times.
|
38 | if (sc->temporal_reordering) |
2039 | 3 | temporal_reordering = 1; | |
2040 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 18 times.
|
38 | if (mxf->edit_unit_byte_count) { |
2041 | 20 | avio_w8(pb, 0); // slice number | |
2042 | 20 | avio_wb32(pb, sc->slice_offset); | |
2043 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8 times.
|
18 | } else if (i == 0) { // video track |
2044 | 10 | avio_w8(pb, 0); // slice number | |
2045 | 10 | avio_wb32(pb, KAG_SIZE); // system item size including klv fill | |
2046 | } else { // audio or data track | ||
2047 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
8 | if (!audio_frame_size) { |
2048 | 7 | audio_frame_size = sc->frame_size; | |
2049 | 7 | audio_frame_size += klv_fill_size(audio_frame_size); | |
2050 | } | ||
2051 | 8 | avio_w8(pb, 1); | |
2052 | 8 | avio_wb32(pb, (i-1)*audio_frame_size); // element delta | |
2053 | } | ||
2054 | } | ||
2055 | |||
2056 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 12 times.
|
22 | if (!mxf->edit_unit_byte_count) { |
2057 | 10 | MXFStreamContext *sc = s->streams[0]->priv_data; | |
2058 | 10 | mxf_write_local_tag(s, 8 + mxf->edit_units_count*15, 0x3F0A); | |
2059 | 10 | avio_wb32(pb, mxf->edit_units_count); // num of entries | |
2060 | 10 | avio_wb32(pb, 15); // size of one entry | |
2061 | |||
2062 |
2/2✓ Branch 0 taken 141 times.
✓ Branch 1 taken 10 times.
|
151 | for (i = 0; i < mxf->edit_units_count; i++) { |
2063 | 141 | int temporal_offset = 0; | |
2064 | |||
2065 |
2/2✓ Branch 0 taken 54 times.
✓ Branch 1 taken 87 times.
|
141 | if (!(mxf->index_entries[i].flags & 0x33)) { // I-frame |
2066 | 54 | sc->max_gop = FFMAX(sc->max_gop, i - mxf->last_key_index); | |
2067 | 54 | mxf->last_key_index = key_index; | |
2068 | 54 | key_index = i; | |
2069 | } | ||
2070 | |||
2071 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 61 times.
|
141 | if (temporal_reordering) { |
2072 | 80 | int pic_num_in_gop = i - key_index; | |
2073 |
2/2✓ Branch 0 taken 77 times.
✓ Branch 1 taken 3 times.
|
80 | if (pic_num_in_gop != mxf->index_entries[i].temporal_ref) { |
2074 |
1/2✓ Branch 0 taken 444 times.
✗ Branch 1 not taken.
|
444 | for (j = key_index; j < mxf->edit_units_count; j++) { |
2075 |
2/2✓ Branch 0 taken 77 times.
✓ Branch 1 taken 367 times.
|
444 | if (pic_num_in_gop == mxf->index_entries[j].temporal_ref) |
2076 | 77 | break; | |
2077 | } | ||
2078 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 77 times.
|
77 | if (j == mxf->edit_units_count) |
2079 | ✗ | av_log(s, AV_LOG_WARNING, "missing frames\n"); | |
2080 | 77 | temporal_offset = j - key_index - pic_num_in_gop; | |
2081 | } | ||
2082 | } | ||
2083 | 141 | avio_w8(pb, temporal_offset); | |
2084 | |||
2085 |
2/2✓ Branch 0 taken 51 times.
✓ Branch 1 taken 90 times.
|
141 | if ((mxf->index_entries[i].flags & 0x30) == 0x30) { // back and forward prediction |
2086 | 51 | sc->b_picture_count = FFMAX(sc->b_picture_count, i - prev_non_b_picture); | |
2087 | 51 | avio_w8(pb, mxf->last_key_index - i); | |
2088 | } else { | ||
2089 | 90 | avio_w8(pb, key_index - i); // key frame offset | |
2090 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 54 times.
|
90 | if ((mxf->index_entries[i].flags & 0x20) == 0x20) // only forward |
2091 | 36 | mxf->last_key_index = key_index; | |
2092 | 90 | prev_non_b_picture = i; | |
2093 | } | ||
2094 | |||
2095 |
2/2✓ Branch 0 taken 54 times.
✓ Branch 1 taken 87 times.
|
141 | if (!(mxf->index_entries[i].flags & 0x33) && // I-frame |
2096 |
4/4✓ Branch 0 taken 24 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 6 times.
|
54 | mxf->index_entries[i].flags & 0x40 && !temporal_offset) |
2097 | 18 | mxf->index_entries[i].flags |= 0x80; // random access | |
2098 | 141 | avio_w8(pb, mxf->index_entries[i].flags); | |
2099 | // stream offset | ||
2100 | 141 | avio_wb64(pb, mxf->index_entries[i].offset); | |
2101 |
2/2✓ Branch 0 taken 111 times.
✓ Branch 1 taken 30 times.
|
141 | if (s->nb_streams > 1) |
2102 | 111 | avio_wb32(pb, mxf->index_entries[i].slice_offset); | |
2103 | else | ||
2104 | 30 | avio_wb32(pb, 0); | |
2105 | } | ||
2106 | |||
2107 | 10 | mxf->last_key_index = key_index - mxf->edit_units_count; | |
2108 | 10 | mxf->last_indexed_edit_unit += mxf->edit_units_count; | |
2109 | 10 | mxf->edit_units_count = 0; | |
2110 | } | ||
2111 | |||
2112 | 22 | mxf_update_klv_size(pb, pos); | |
2113 | } | ||
2114 | |||
2115 | 891 | static void mxf_write_klv_fill(AVFormatContext *s) | |
2116 | { | ||
2117 | 891 | unsigned pad = klv_fill_size(avio_tell(s->pb)); | |
2118 |
2/2✓ Branch 0 taken 882 times.
✓ Branch 1 taken 9 times.
|
891 | if (pad) { |
2119 | 882 | avio_write(s->pb, klv_fill_key, 16); | |
2120 | 882 | pad -= 16 + 4; | |
2121 | 882 | klv_encode_ber4_length(s->pb, pad); | |
2122 | 882 | ffio_fill(s->pb, 0, pad); | |
2123 | av_assert1(!(avio_tell(s->pb) & (KAG_SIZE-1))); | ||
2124 | } | ||
2125 | 891 | } | |
2126 | |||
2127 | 66 | static int mxf_write_partition(AVFormatContext *s, int bodysid, | |
2128 | int indexsid, | ||
2129 | const uint8_t *key, int write_metadata) | ||
2130 | { | ||
2131 | 66 | MXFContext *mxf = s->priv_data; | |
2132 | 66 | AVIOContext *pb = s->pb; | |
2133 | int64_t header_byte_count_offset; | ||
2134 | 66 | unsigned index_byte_count = 0; | |
2135 | 66 | uint64_t partition_offset = avio_tell(pb); | |
2136 | int err; | ||
2137 | |||
2138 |
4/4✓ Branch 0 taken 41 times.
✓ Branch 1 taken 25 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 31 times.
|
66 | if (!mxf->edit_unit_byte_count && mxf->edit_units_count) |
2139 | 10 | index_byte_count = 85 + 12+(s->nb_streams+1)*6 + | |
2140 | 10 | 12+mxf->edit_units_count*15; | |
2141 |
4/4✓ Branch 0 taken 25 times.
✓ Branch 1 taken 31 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 13 times.
|
56 | else if (mxf->edit_unit_byte_count && indexsid) |
2142 | 12 | index_byte_count = 80; | |
2143 | |||
2144 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 44 times.
|
66 | if (index_byte_count) { |
2145 | 22 | index_byte_count += 16 + 4; // add encoded ber4 length | |
2146 | 22 | index_byte_count += klv_fill_size(index_byte_count); | |
2147 | } | ||
2148 | |||
2149 |
4/4✓ Branch 0 taken 63 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 51 times.
|
66 | if (key && !memcmp(key, body_partition_key, 16)) { |
2150 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
|
12 | if ((err = av_reallocp_array(&mxf->body_partition_offset, mxf->body_partitions_count + 1, |
2151 | sizeof(*mxf->body_partition_offset))) < 0) { | ||
2152 | ✗ | mxf->body_partitions_count = 0; | |
2153 | ✗ | return err; | |
2154 | } | ||
2155 | 12 | mxf->body_partition_offset[mxf->body_partitions_count++] = partition_offset; | |
2156 | } | ||
2157 | |||
2158 | // write klv | ||
2159 |
2/2✓ Branch 0 taken 63 times.
✓ Branch 1 taken 3 times.
|
66 | if (key) |
2160 | 63 | avio_write(pb, key, 16); | |
2161 | else | ||
2162 | 3 | avio_write(pb, body_partition_key, 16); | |
2163 | |||
2164 |
2/2✓ Branch 0 taken 37 times.
✓ Branch 1 taken 29 times.
|
66 | klv_encode_ber4_length(pb, 88 + 16LL * DESCRIPTOR_COUNT(mxf->essence_container_count)); |
2165 | |||
2166 | // write partition value | ||
2167 | 66 | avio_wb16(pb, 1); // majorVersion | |
2168 | 66 | avio_wb16(pb, 3); // minorVersion | |
2169 | 66 | avio_wb32(pb, KAG_SIZE); // KAGSize | |
2170 | |||
2171 | 66 | avio_wb64(pb, partition_offset); // ThisPartition | |
2172 | |||
2173 |
5/6✓ Branch 0 taken 63 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 51 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 12 times.
|
66 | if (key && !memcmp(key, body_partition_key, 16) && mxf->body_partitions_count > 1) |
2174 | ✗ | avio_wb64(pb, mxf->body_partition_offset[mxf->body_partitions_count-2]); // PreviousPartition | |
2175 |
6/6✓ Branch 0 taken 63 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 46 times.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 5 times.
|
66 | else if (key && !memcmp(key, footer_partition_key, 16) && mxf->body_partitions_count) |
2176 | 12 | avio_wb64(pb, mxf->body_partition_offset[mxf->body_partitions_count-1]); // PreviousPartition | |
2177 | else | ||
2178 | 54 | avio_wb64(pb, 0); | |
2179 | |||
2180 | 66 | avio_wb64(pb, mxf->footer_partition_offset); // footerPartition | |
2181 | |||
2182 | // set offset | ||
2183 | 66 | header_byte_count_offset = avio_tell(pb); | |
2184 | 66 | avio_wb64(pb, 0); // headerByteCount, update later | |
2185 | |||
2186 | // indexTable | ||
2187 | 66 | avio_wb64(pb, index_byte_count); // indexByteCount | |
2188 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 44 times.
|
66 | avio_wb32(pb, index_byte_count ? indexsid : 0); // indexSID |
2189 | |||
2190 | // BodyOffset | ||
2191 |
7/8✓ Branch 0 taken 25 times.
✓ Branch 1 taken 41 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 5 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
|
66 | if (bodysid && mxf->edit_units_count && mxf->body_partitions_count && !IS_OPATOM(s)) |
2192 | ✗ | avio_wb64(pb, mxf->body_offset); | |
2193 | else | ||
2194 | 66 | avio_wb64(pb, 0); | |
2195 | |||
2196 | 66 | avio_wb32(pb, bodysid); // bodySID | |
2197 | |||
2198 | // operational pattern | ||
2199 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 51 times.
|
66 | if (IS_OPATOM(s)) |
2200 | 15 | avio_write(pb, opatom_ul, 16); | |
2201 | else | ||
2202 | 51 | avio_write(pb, op1a_ul, 16); | |
2203 | |||
2204 | // essence container | ||
2205 | 66 | mxf_write_essence_container_refs(s); | |
2206 | |||
2207 |
2/2✓ Branch 0 taken 34 times.
✓ Branch 1 taken 32 times.
|
66 | if (write_metadata) { |
2208 | // mark the start of the headermetadata and calculate metadata size | ||
2209 | int64_t pos, start; | ||
2210 | unsigned header_byte_count; | ||
2211 | |||
2212 | 34 | mxf_write_klv_fill(s); | |
2213 | 34 | start = avio_tell(s->pb); | |
2214 | 34 | mxf_write_primer_pack(s); | |
2215 | 34 | mxf_write_klv_fill(s); | |
2216 | 34 | mxf_write_header_metadata_sets(s); | |
2217 | 34 | pos = avio_tell(s->pb); | |
2218 | 34 | header_byte_count = pos - start + klv_fill_size(pos); | |
2219 | |||
2220 | // update header_byte_count | ||
2221 | 34 | avio_seek(pb, header_byte_count_offset, SEEK_SET); | |
2222 | 34 | avio_wb64(pb, header_byte_count); | |
2223 | 34 | avio_seek(pb, pos, SEEK_SET); | |
2224 | } | ||
2225 | |||
2226 |
2/2✓ Branch 0 taken 63 times.
✓ Branch 1 taken 3 times.
|
66 | if(key) |
2227 | 63 | avio_write_marker(pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT); | |
2228 | |||
2229 | 66 | return 0; | |
2230 | } | ||
2231 | |||
2232 | static const struct { | ||
2233 | int profile; | ||
2234 | UID codec_ul; | ||
2235 | } mxf_prores_codec_uls[] = { | ||
2236 | { AV_PROFILE_PRORES_PROXY, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x01,0x00 } }, | ||
2237 | { AV_PROFILE_PRORES_LT, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x02,0x00 } }, | ||
2238 | { AV_PROFILE_PRORES_STANDARD, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x03,0x00 } }, | ||
2239 | { AV_PROFILE_PRORES_HQ, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x04,0x00 } }, | ||
2240 | { AV_PROFILE_PRORES_4444, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x05,0x00 } }, | ||
2241 | { AV_PROFILE_PRORES_XQ, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x06,0x00 } }, | ||
2242 | }; | ||
2243 | |||
2244 | 5 | static int mxf_parse_prores_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt) | |
2245 | { | ||
2246 | 5 | MXFContext *mxf = s->priv_data; | |
2247 | 5 | MXFStreamContext *sc = st->priv_data; | |
2248 | int i, profile; | ||
2249 | |||
2250 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | if (mxf->header_written) |
2251 | 4 | return 1; | |
2252 | |||
2253 | 1 | profile = st->codecpar->profile; | |
2254 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | for (i = 0; i < FF_ARRAY_ELEMS(mxf_prores_codec_uls); i++) { |
2255 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (profile == mxf_prores_codec_uls[i].profile) { |
2256 | 1 | sc->codec_ul = &mxf_prores_codec_uls[i].codec_ul; | |
2257 | 1 | break; | |
2258 | } | ||
2259 | } | ||
2260 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (i == FF_ARRAY_ELEMS(mxf_prores_codec_uls)) |
2261 | ✗ | return 0; | |
2262 | |||
2263 | 1 | sc->frame_size = pkt->size; | |
2264 | |||
2265 | 1 | return 1; | |
2266 | } | ||
2267 | |||
2268 | static const struct { | ||
2269 | uint16_t cid; | ||
2270 | uint8_t interlaced; | ||
2271 | UID codec_ul; | ||
2272 | } mxf_dnxhd_codec_uls[] = { | ||
2273 | { 1235, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x01,0x00,0x00 } }, // 1080p 10bit HIGH | ||
2274 | { 1237, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x03,0x00,0x00 } }, // 1080p 8bit MED | ||
2275 | { 1238, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x04,0x00,0x00 } }, // 1080p 8bit HIGH | ||
2276 | { 1241, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x07,0x00,0x00 } }, // 1080i 10bit HIGH | ||
2277 | { 1242, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x08,0x00,0x00 } }, // 1080i 8bit MED | ||
2278 | { 1243, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x09,0x00,0x00 } }, // 1080i 8bit HIGH | ||
2279 | { 1244, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x0a,0x00,0x00 } }, // 1080i 8bit TR | ||
2280 | { 1250, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x10,0x00,0x00 } }, // 720p 10bit | ||
2281 | { 1251, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x11,0x00,0x00 } }, // 720p 8bit HIGH | ||
2282 | { 1252, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x12,0x00,0x00 } }, // 720p 8bit MED | ||
2283 | { 1253, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x13,0x00,0x00 } }, // 720p 8bit LOW | ||
2284 | { 1256, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x16,0x00,0x00 } }, // 1080p 10bit 444 | ||
2285 | { 1258, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x18,0x00,0x00 } }, // 720p 8bit TR | ||
2286 | { 1259, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x19,0x00,0x00 } }, // 1080p 8bit TR | ||
2287 | { 1260, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x1a,0x00,0x00 } }, // 1080i 8bit TR MBAFF | ||
2288 | { 1270, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x24,0x00,0x00 } }, // DNXHR 444 | ||
2289 | { 1271, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x25,0x00,0x00 } }, // DNXHR HQX | ||
2290 | { 1272, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x26,0x00,0x00 } }, // DNXHR HQ | ||
2291 | { 1273, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x27,0x00,0x00 } }, // DNXHR SQ | ||
2292 | { 1274, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x28,0x00,0x00 } }, // DNXHR LB | ||
2293 | }; | ||
2294 | |||
2295 | 25 | static int mxf_parse_dnxhd_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt) | |
2296 | { | ||
2297 | 25 | MXFContext *mxf = s->priv_data; | |
2298 | 25 | MXFStreamContext *sc = st->priv_data; | |
2299 | int i, cid; | ||
2300 | |||
2301 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
|
25 | if (mxf->header_written) |
2302 | 24 | return 1; | |
2303 | |||
2304 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (pkt->size < 43) |
2305 | ✗ | return 0; | |
2306 | |||
2307 | 1 | cid = AV_RB32(pkt->data + 0x28); | |
2308 |
1/2✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
|
11 | for (i = 0; i < FF_ARRAY_ELEMS(mxf_dnxhd_codec_uls); i++) { |
2309 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10 times.
|
11 | if (cid == mxf_dnxhd_codec_uls[i].cid) { |
2310 | 1 | sc->codec_ul = &mxf_dnxhd_codec_uls[i].codec_ul; | |
2311 | 1 | sc->interlaced = mxf_dnxhd_codec_uls[i].interlaced; | |
2312 | 1 | break; | |
2313 | } | ||
2314 | } | ||
2315 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (i == FF_ARRAY_ELEMS(mxf_dnxhd_codec_uls)) |
2316 | ✗ | return 0; | |
2317 | |||
2318 | 1 | sc->component_depth = 0; | |
2319 |
1/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
1 | switch (pkt->data[0x21] >> 5) { |
2320 | 1 | case 1: sc->component_depth = 8; break; | |
2321 | ✗ | case 2: sc->component_depth = 10; break; | |
2322 | ✗ | case 3: sc->component_depth = 12; break; | |
2323 | } | ||
2324 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!sc->component_depth) |
2325 | ✗ | return 0; | |
2326 | |||
2327 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (cid >= 1270) { // RI raster |
2328 | ✗ | av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den, | |
2329 | ✗ | st->codecpar->width, st->codecpar->height, | |
2330 | INT_MAX); | ||
2331 | } else { | ||
2332 | 1 | sc->aspect_ratio = (AVRational){ 16, 9 }; | |
2333 | } | ||
2334 | |||
2335 | 1 | sc->frame_size = pkt->size; | |
2336 | |||
2337 | 1 | return 1; | |
2338 | } | ||
2339 | |||
2340 | static const struct { | ||
2341 | const UID container_ul; | ||
2342 | const UID codec_ul; | ||
2343 | } mxf_dv_uls[] = { | ||
2344 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x01,0x01 }, // IEC DV25 525/60 | ||
2345 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x01,0x01,0x00 } }, | ||
2346 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x02,0x01 }, // IEC DV25 626/50 | ||
2347 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x01,0x02,0x00 } }, | ||
2348 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x40,0x01 }, // DV25 525/60 | ||
2349 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x01,0x00 }, }, | ||
2350 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x41,0x01 }, // DV25 625/50 | ||
2351 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x02,0x00 }, }, | ||
2352 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x50,0x01 }, // DV50 525/60 | ||
2353 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x03,0x00 }, }, | ||
2354 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x51,0x01 }, // DV50 625/50 | ||
2355 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x04,0x00 }, }, | ||
2356 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x60,0x01 }, // DV100 1080/60 | ||
2357 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x05,0x00 }, }, | ||
2358 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x61,0x01 }, // DV100 1080/50 | ||
2359 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x06,0x00 }, }, | ||
2360 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x62,0x01 }, // DV100 720/60 | ||
2361 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x07,0x00 }, }, | ||
2362 | { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x63,0x01 }, // DV100 720/50 | ||
2363 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x08,0x00 }, }, | ||
2364 | }; | ||
2365 | |||
2366 | 75 | static int mxf_parse_dv_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt) | |
2367 | { | ||
2368 | 75 | MXFContext *mxf = s->priv_data; | |
2369 | 75 | MXFStreamContext *sc = st->priv_data; | |
2370 | const uint8_t *vs_pack, *vsc_pack; | ||
2371 | int apt, ul_index, stype, pal; | ||
2372 | |||
2373 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 3 times.
|
75 | if (mxf->header_written) |
2374 | 72 | return 1; | |
2375 | |||
2376 | // Check for minimal frame size | ||
2377 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (pkt->size < 120000) |
2378 | ✗ | return -1; | |
2379 | |||
2380 | 3 | apt = pkt->data[4] & 0x7; | |
2381 | 3 | vs_pack = pkt->data + 80*5 + 48; | |
2382 | 3 | vsc_pack = pkt->data + 80*5 + 53; | |
2383 | 3 | stype = vs_pack[3] & 0x1f; | |
2384 | 3 | pal = (vs_pack[3] >> 5) & 0x1; | |
2385 | |||
2386 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if ((vsc_pack[2] & 0x07) == 0x02) { |
2387 | 2 | sc->aspect_ratio = (AVRational){ 16, 9 }; | |
2388 | } else { | ||
2389 | 1 | sc->aspect_ratio = (AVRational){ 4, 3 }; | |
2390 | } | ||
2391 | |||
2392 | 3 | sc->interlaced = (vsc_pack[3] >> 4) & 0x01; | |
2393 | // TODO: fix dv encoder to set proper FF/FS value in VSC pack | ||
2394 | // and set field dominance accordingly | ||
2395 | // av_log(s, AV_LOG_DEBUG, "DV vsc pack ff/ss = %x\n", vsc_pack[2] >> 6); | ||
2396 | |||
2397 |
3/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
3 | switch (stype) { |
2398 | ✗ | case 0x18: // DV100 720p | |
2399 | ✗ | ul_index = 8+pal; | |
2400 | ✗ | if (sc->interlaced) { | |
2401 | ✗ | av_log(s, AV_LOG_ERROR, "source marked as interlaced but codec profile is progressive\n"); | |
2402 | ✗ | sc->interlaced = 0; | |
2403 | } | ||
2404 | ✗ | break; | |
2405 | 1 | case 0x14: // DV100 1080i | |
2406 | 1 | ul_index = 6+pal; | |
2407 | 1 | break; | |
2408 | 1 | case 0x04: // DV50 | |
2409 | 1 | ul_index = 4+pal; | |
2410 | 1 | break; | |
2411 | 1 | default: // DV25 | |
2412 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (!apt) { // IEC |
2413 | 1 | ul_index = 0+pal; | |
2414 | } else { | ||
2415 | ✗ | ul_index = 2+pal; | |
2416 | } | ||
2417 | } | ||
2418 | |||
2419 | 3 | sc->container_ul = &mxf_dv_uls[ul_index].container_ul; | |
2420 | 3 | sc->codec_ul = &mxf_dv_uls[ul_index].codec_ul; | |
2421 | |||
2422 | 3 | sc->frame_size = pkt->size; | |
2423 | |||
2424 | 3 | return 1; | |
2425 | } | ||
2426 | |||
2427 | static const struct { | ||
2428 | UID uid; | ||
2429 | int frame_size; | ||
2430 | uint8_t profile; | ||
2431 | uint8_t interlaced; | ||
2432 | int8_t intra_only; // 1 or 0 when there are separate UIDs for Long GOP and Intra, -1 when Intra/LGOP detection can be ignored | ||
2433 | } mxf_h264_codec_uls[] = { | ||
2434 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x11,0x01 }, 0, 66, 0, -1 }, // AVC Baseline | ||
2435 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x20,0x01 }, 0, 77, 0, -1 }, // AVC Main | ||
2436 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x30,0x01 }, 0, 88, 0, -1 }, // AVC Extended | ||
2437 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x40,0x01 }, 0, 100, 0, -1 }, // AVC High | ||
2438 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x50,0x01 }, 0, 110, 0, 0 }, // AVC High 10 | ||
2439 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x60,0x01 }, 0, 122, 0, 0 }, // AVC High 422 | ||
2440 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x70,0x01 }, 0, 244, 0, 0 }, // AVC High 444 | ||
2441 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x20,0x01 }, 0, 110, 0, 1 }, // AVC High 10 Intra | ||
2442 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x01 }, 232960, 110, 1, 1 }, // AVC High 10 Intra RP2027 Class 50 1080/59.94i | ||
2443 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x02 }, 281088, 110, 1, 1 }, // AVC High 10 Intra RP2027 Class 50 1080/50i | ||
2444 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x03 }, 232960, 110, 0, 1 }, // AVC High 10 Intra RP2027 Class 50 1080/29.97p | ||
2445 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x04 }, 281088, 110, 0, 1 }, // AVC High 10 Intra RP2027 Class 50 1080/25p | ||
2446 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x08 }, 116736, 110, 0, 1 }, // AVC High 10 Intra RP2027 Class 50 720/59.94p | ||
2447 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x09 }, 140800, 110, 0, 1 }, // AVC High 10 Intra RP2027 Class 50 720/50p | ||
2448 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x30,0x01 }, 0, 122, 0, 1 }, // AVC High 422 Intra | ||
2449 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x01 }, 472576, 122, 1, 1 }, // AVC High 422 Intra RP2027 Class 100 1080/59.94i | ||
2450 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x02 }, 568832, 122, 1, 1 }, // AVC High 422 Intra RP2027 Class 100 1080/50i | ||
2451 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x03 }, 472576, 122, 0, 1 }, // AVC High 422 Intra RP2027 Class 100 1080/29.97p | ||
2452 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x04 }, 568832, 122, 0, 1 }, // AVC High 422 Intra RP2027 Class 100 1080/25p | ||
2453 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x08 }, 236544, 122, 0, 1 }, // AVC High 422 Intra RP2027 Class 100 720/59.94p | ||
2454 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x09 }, 284672, 122, 0, 1 }, // AVC High 422 Intra RP2027 Class 100 720/50p | ||
2455 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x01,0x32,0x40,0x01 }, 0, 244, 0, 1 }, // AVC High 444 Intra | ||
2456 | {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x01,0x32,0x50,0x01 }, 0, 44, 0, -1 }, // AVC CAVLC 444 | ||
2457 | }; | ||
2458 | |||
2459 | ✗ | static int mxf_parse_h264_frame(AVFormatContext *s, AVStream *st, | |
2460 | AVPacket *pkt, MXFIndexEntry *e) | ||
2461 | { | ||
2462 | ✗ | MXFContext *mxf = s->priv_data; | |
2463 | ✗ | MXFStreamContext *sc = st->priv_data; | |
2464 | ✗ | H264SPS seq, *const sps = &seq; | |
2465 | GetBitContext gb; | ||
2466 | ✗ | const uint8_t *buf = pkt->data; | |
2467 | ✗ | const uint8_t *buf_end = pkt->data + pkt->size; | |
2468 | const uint8_t *nal_end; | ||
2469 | ✗ | const UID *codec_ul = NULL; | |
2470 | ✗ | uint32_t state = -1; | |
2471 | ✗ | int extra_size = 512; // support AVC Intra files without SPS/PPS header | |
2472 | ✗ | int i, frame_size, slice_type, has_sps = 0, intra_only = 0, ret; | |
2473 | |||
2474 | for (;;) { | ||
2475 | ✗ | buf = avpriv_find_start_code(buf, buf_end, &state); | |
2476 | ✗ | if (buf >= buf_end) | |
2477 | ✗ | break; | |
2478 | |||
2479 | ✗ | switch (state & 0x1f) { | |
2480 | ✗ | case H264_NAL_SPS: | |
2481 | ✗ | e->flags |= 0x40; | |
2482 | |||
2483 | ✗ | if (mxf->header_written) | |
2484 | ✗ | break; | |
2485 | |||
2486 | ✗ | nal_end = ff_nal_find_startcode(buf, buf_end); | |
2487 | ✗ | ret = ff_avc_decode_sps(sps, buf, nal_end - buf); | |
2488 | ✗ | if (ret < 0) { | |
2489 | ✗ | av_log(s, AV_LOG_ERROR, "error parsing sps\n"); | |
2490 | ✗ | return 0; | |
2491 | } | ||
2492 | ✗ | has_sps = 1; | |
2493 | |||
2494 | ✗ | sc->aspect_ratio.num = st->codecpar->width * sps->sar.num; | |
2495 | ✗ | sc->aspect_ratio.den = st->codecpar->height * sps->sar.den; | |
2496 | ✗ | av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den, | |
2497 | ✗ | sc->aspect_ratio.num, sc->aspect_ratio.den, 1024*1024); | |
2498 | ✗ | intra_only = (sps->constraint_set_flags >> 3) & 1; | |
2499 | ✗ | sc->interlaced = !sps->frame_mbs_only_flag; | |
2500 | ✗ | sc->component_depth = sps->bit_depth_luma; | |
2501 | |||
2502 | ✗ | buf = nal_end; | |
2503 | ✗ | break; | |
2504 | ✗ | case H264_NAL_PPS: | |
2505 | ✗ | if (e->flags & 0x40) { // sequence header present | |
2506 | ✗ | e->flags |= 0x80; // random access | |
2507 | ✗ | extra_size = 0; | |
2508 | } | ||
2509 | ✗ | break; | |
2510 | ✗ | case H264_NAL_IDR_SLICE: | |
2511 | ✗ | e->flags |= 0x04; // IDR Picture | |
2512 | ✗ | buf = buf_end; | |
2513 | ✗ | break; | |
2514 | ✗ | case H264_NAL_SLICE: | |
2515 | ✗ | init_get_bits8(&gb, buf, buf_end - buf); | |
2516 | ✗ | get_ue_golomb_long(&gb); // skip first_mb_in_slice | |
2517 | ✗ | slice_type = get_ue_golomb_31(&gb); | |
2518 | ✗ | switch (slice_type % 5) { | |
2519 | ✗ | case 0: | |
2520 | ✗ | e->flags |= 0x20; // P Picture | |
2521 | ✗ | e->flags |= 0x06; // P Picture | |
2522 | ✗ | break; | |
2523 | ✗ | case 1: | |
2524 | ✗ | e->flags |= 0x30; // B Picture | |
2525 | ✗ | e->flags |= 0x03; // non-referenced B Picture | |
2526 | ✗ | break; | |
2527 | } | ||
2528 | ✗ | buf = buf_end; | |
2529 | ✗ | break; | |
2530 | ✗ | default: | |
2531 | ✗ | break; | |
2532 | } | ||
2533 | } | ||
2534 | |||
2535 | ✗ | if (mxf->header_written) | |
2536 | ✗ | return 1; | |
2537 | |||
2538 | ✗ | if (!has_sps) | |
2539 | ✗ | sc->interlaced = st->codecpar->field_order != AV_FIELD_PROGRESSIVE ? 1 : 0; | |
2540 | ✗ | frame_size = pkt->size + extra_size; | |
2541 | |||
2542 | ✗ | for (i = 0; i < FF_ARRAY_ELEMS(mxf_h264_codec_uls); i++) { | |
2543 | ✗ | if (frame_size == mxf_h264_codec_uls[i].frame_size && sc->interlaced == mxf_h264_codec_uls[i].interlaced) { | |
2544 | ✗ | codec_ul = &mxf_h264_codec_uls[i].uid; | |
2545 | ✗ | sc->component_depth = 10; // AVC Intra is always 10 Bit | |
2546 | ✗ | sc->aspect_ratio = (AVRational){ 16, 9 }; // 16:9 is mandatory for broadcast HD | |
2547 | ✗ | st->codecpar->profile = mxf_h264_codec_uls[i].profile; | |
2548 | ✗ | sc->avc_intra = 1; | |
2549 | ✗ | mxf->cbr_index = 1; | |
2550 | ✗ | sc->frame_size = pkt->size; | |
2551 | ✗ | if (sc->interlaced) | |
2552 | ✗ | sc->field_dominance = 1; // top field first is mandatory for AVC Intra | |
2553 | ✗ | break; | |
2554 | ✗ | } else if (has_sps && mxf_h264_codec_uls[i].frame_size == 0 && | |
2555 | ✗ | mxf_h264_codec_uls[i].profile == sps->profile_idc && | |
2556 | ✗ | (mxf_h264_codec_uls[i].intra_only < 0 || | |
2557 | ✗ | mxf_h264_codec_uls[i].intra_only == intra_only)) { | |
2558 | ✗ | codec_ul = &mxf_h264_codec_uls[i].uid; | |
2559 | ✗ | st->codecpar->profile = sps->profile_idc; | |
2560 | ✗ | st->codecpar->level = sps->level_idc; | |
2561 | // continue to check for avc intra | ||
2562 | } | ||
2563 | } | ||
2564 | |||
2565 | ✗ | if (!codec_ul) { | |
2566 | ✗ | av_log(s, AV_LOG_ERROR, "h264 profile not supported\n"); | |
2567 | ✗ | return 0; | |
2568 | } | ||
2569 | ✗ | sc->codec_ul = codec_ul; | |
2570 | |||
2571 | ✗ | return 1; | |
2572 | } | ||
2573 | |||
2574 | 2 | static inline int get_ffv1_unsigned_symbol(RangeCoder *c, uint8_t *state) { | |
2575 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if(get_rac(c, state+0)) |
2576 | ✗ | return 0; | |
2577 | else{ | ||
2578 | int i, e; | ||
2579 | unsigned a; | ||
2580 | 2 | e= 0; | |
2581 |
3/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 2 times.
|
5 | while(get_rac(c, state+1 + FFMIN(e,9))){ //1..10 |
2582 | 3 | e++; | |
2583 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (e > 31) |
2584 | ✗ | return AVERROR_INVALIDDATA; | |
2585 | } | ||
2586 | |||
2587 | 2 | a= 1; | |
2588 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
|
5 | for(i=e-1; i>=0; i--){ |
2589 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | a += a + get_rac(c, state+22 + FFMIN(i,9)); //22..31 |
2590 | } | ||
2591 | |||
2592 | 2 | return a; | |
2593 | } | ||
2594 | } | ||
2595 | #define FFV1_CONTEXT_SIZE 32 | ||
2596 | 25 | static int mxf_parse_ffv1_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt) | |
2597 | { | ||
2598 | 25 | MXFContext *mxf = s->priv_data; | |
2599 | 25 | MXFStreamContext *sc = st->priv_data; | |
2600 | uint8_t state[FFV1_CONTEXT_SIZE]; | ||
2601 | RangeCoder c; | ||
2602 | unsigned v; | ||
2603 | |||
2604 | 25 | sc->frame_size = pkt->size; | |
2605 | |||
2606 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
|
25 | if (mxf->header_written) |
2607 | 24 | return 1; | |
2608 | |||
2609 | 1 | memset(state, 128, sizeof(state)); | |
2610 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (st->codecpar->extradata) { |
2611 | 1 | ff_init_range_decoder(&c, st->codecpar->extradata, st->codecpar->extradata_size); | |
2612 | 1 | ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8); | |
2613 | 1 | v = get_ffv1_unsigned_symbol(&c, state); | |
2614 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | av_assert0(v >= 2); |
2615 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (v > 4) { |
2616 | ✗ | av_log(s, AV_LOG_ERROR, "unsupported ffv1 version %d\n", v); | |
2617 | ✗ | return 0; | |
2618 | } | ||
2619 | 1 | sc->micro_version = get_ffv1_unsigned_symbol(&c, state); | |
2620 | } else { | ||
2621 | ✗ | uint8_t keystate = 128; | |
2622 | ✗ | ff_init_range_decoder(&c, pkt->data, pkt->size); | |
2623 | ✗ | ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8); | |
2624 | ✗ | get_rac(&c, &keystate); // keyframe | |
2625 | ✗ | v = get_ffv1_unsigned_symbol(&c, state); | |
2626 | ✗ | av_assert0(v < 2); | |
2627 | } | ||
2628 | 1 | sc->codec_ul = &mxf_ffv1_codec_uls[v]; | |
2629 | |||
2630 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (st->codecpar->field_order > AV_FIELD_PROGRESSIVE) { |
2631 | ✗ | sc->interlaced = 1; | |
2632 | ✗ | sc->field_dominance = st->codecpar->field_order == (st->codecpar->field_order == AV_FIELD_TT || st->codecpar->field_order == AV_FIELD_TB) ? 1 : 2; | |
2633 | } | ||
2634 | 1 | sc->aspect_ratio.num = st->codecpar->width * st->codecpar->sample_aspect_ratio.num; | |
2635 | 1 | sc->aspect_ratio.den = st->codecpar->height * st->codecpar->sample_aspect_ratio.den; | |
2636 | 1 | av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den, | |
2637 | 1 | sc->aspect_ratio.num, sc->aspect_ratio.den, INT_MAX); | |
2638 | |||
2639 | 1 | return 1; | |
2640 | } | ||
2641 | |||
2642 | ✗ | static int mxf_parse_jpeg2000_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt) | |
2643 | { | ||
2644 | ✗ | MXFContext *mxf = s->priv_data; | |
2645 | ✗ | MXFStreamContext *sc = st->priv_data; | |
2646 | ✗ | const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codecpar->format); | |
2647 | GetByteContext g; | ||
2648 | uint32_t j2k_ncomponents; | ||
2649 | |||
2650 | ✗ | if (!pix_desc) { | |
2651 | ✗ | av_log(s, AV_LOG_ERROR, "Pixel format not set\n"); | |
2652 | ✗ | return AVERROR(EINVAL); | |
2653 | } | ||
2654 | |||
2655 | ✗ | if (mxf->header_written) | |
2656 | ✗ | return 1; | |
2657 | |||
2658 | ✗ | bytestream2_init(&g,pkt->data,pkt->size); | |
2659 | |||
2660 | ✗ | while (bytestream2_get_bytes_left(&g) >= 3 && bytestream2_peek_be16(&g) != JPEG2000_SOC) | |
2661 | ✗ | bytestream2_skip(&g, 1); | |
2662 | |||
2663 | ✗ | if (bytestream2_get_be16u(&g) != JPEG2000_SOC) { | |
2664 | ✗ | av_log(s, AV_LOG_ERROR, "Mandatory SOC marker is not present\n"); | |
2665 | ✗ | return AVERROR_INVALIDDATA; | |
2666 | } | ||
2667 | |||
2668 | /* Extract usefull size information from the SIZ marker */ | ||
2669 | ✗ | if (bytestream2_get_be16u(&g) != JPEG2000_SIZ) { | |
2670 | ✗ | av_log(s, AV_LOG_ERROR, "Mandatory SIZ marker is not present\n"); | |
2671 | ✗ | return AVERROR_INVALIDDATA; | |
2672 | } | ||
2673 | ✗ | bytestream2_skip(&g, 2); // Skip Lsiz | |
2674 | ✗ | sc->j2k_info.j2k_cap = bytestream2_get_be16u(&g); | |
2675 | ✗ | sc->j2k_info.j2k_xsiz = bytestream2_get_be32u(&g); | |
2676 | ✗ | sc->j2k_info.j2k_ysiz = bytestream2_get_be32u(&g); | |
2677 | ✗ | sc->j2k_info.j2k_x0siz = bytestream2_get_be32u(&g); | |
2678 | ✗ | sc->j2k_info.j2k_y0siz = bytestream2_get_be32u(&g); | |
2679 | ✗ | sc->j2k_info.j2k_xtsiz = bytestream2_get_be32u(&g); | |
2680 | ✗ | sc->j2k_info.j2k_ytsiz = bytestream2_get_be32u(&g); | |
2681 | ✗ | sc->j2k_info.j2k_xt0siz = bytestream2_get_be32u(&g); | |
2682 | ✗ | sc->j2k_info.j2k_yt0siz = bytestream2_get_be32u(&g); | |
2683 | ✗ | j2k_ncomponents = bytestream2_get_be16u(&g); | |
2684 | ✗ | if (j2k_ncomponents != pix_desc->nb_components) { | |
2685 | ✗ | av_log(s, AV_LOG_ERROR, "Incoherence about components image number.\n"); | |
2686 | ✗ | return AVERROR_INVALIDDATA; | |
2687 | } | ||
2688 | ✗ | bytestream2_get_bufferu(&g, sc->j2k_info.j2k_comp_desc, 3 * j2k_ncomponents); | |
2689 | |||
2690 | ✗ | sc->frame_size = pkt->size; | |
2691 | |||
2692 | ✗ | return 1; | |
2693 | } | ||
2694 | |||
2695 | static const UID mxf_mpeg2_codec_uls[] = { | ||
2696 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x10,0x00 }, // MP-ML I-Frame | ||
2697 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x11,0x00 }, // MP-ML Long GOP | ||
2698 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x02,0x00 }, // 422P-ML I-Frame | ||
2699 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x03,0x00 }, // 422P-ML Long GOP | ||
2700 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x02,0x00 }, // MP-HL I-Frame | ||
2701 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x03,0x00 }, // MP-HL Long GOP | ||
2702 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x02,0x00 }, // 422P-HL I-Frame | ||
2703 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x03,0x00 }, // 422P-HL Long GOP | ||
2704 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x02,0x00 }, // MP@H-14 I-Frame | ||
2705 | { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x03,0x00 }, // MP@H-14 Long GOP | ||
2706 | }; | ||
2707 | |||
2708 | 111 | static const UID *mxf_get_mpeg2_codec_ul(AVCodecParameters *par) | |
2709 | { | ||
2710 | 111 | int long_gop = 1; | |
2711 | |||
2712 |
2/2✓ Branch 0 taken 81 times.
✓ Branch 1 taken 30 times.
|
111 | if (par->profile == 4) { // Main |
2713 |
1/2✓ Branch 0 taken 81 times.
✗ Branch 1 not taken.
|
81 | if (par->level == 8) // Main |
2714 | 81 | return &mxf_mpeg2_codec_uls[0+long_gop]; | |
2715 | ✗ | else if (par->level == 4) // High | |
2716 | ✗ | return &mxf_mpeg2_codec_uls[4+long_gop]; | |
2717 | ✗ | else if (par->level == 6) // High 14 | |
2718 | ✗ | return &mxf_mpeg2_codec_uls[8+long_gop]; | |
2719 |
1/2✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
|
30 | } else if (par->profile == 0) { // 422 |
2720 |
1/2✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
|
30 | if (par->level == 5) // Main |
2721 | 30 | return &mxf_mpeg2_codec_uls[2+long_gop]; | |
2722 | ✗ | else if (par->level == 2) // High | |
2723 | ✗ | return &mxf_mpeg2_codec_uls[6+long_gop]; | |
2724 | } | ||
2725 | ✗ | return NULL; | |
2726 | } | ||
2727 | |||
2728 | 161 | static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, | |
2729 | AVPacket *pkt, MXFIndexEntry *e) | ||
2730 | { | ||
2731 | 161 | MXFStreamContext *sc = st->priv_data; | |
2732 | 161 | uint32_t c = -1; | |
2733 | int i; | ||
2734 | |||
2735 |
1/2✓ Branch 0 taken 3941 times.
✗ Branch 1 not taken.
|
3941 | for(i = 0; i < pkt->size - 4; i++) { |
2736 | 3941 | c = (c<<8) + pkt->data[i]; | |
2737 |
2/2✓ Branch 0 taken 216 times.
✓ Branch 1 taken 3725 times.
|
3941 | if (c == 0x1b5) { |
2738 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 164 times.
|
216 | if ((pkt->data[i+1] & 0xf0) == 0x10) { // seq ext |
2739 | 52 | st->codecpar->profile = pkt->data[i+1] & 0x07; | |
2740 | 52 | st->codecpar->level = pkt->data[i+2] >> 4; | |
2741 | 52 | sc->low_delay = pkt->data[i+6] >> 7; | |
2742 |
3/4✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 161 times.
✓ Branch 3 taken 3 times.
|
164 | } else if (i + 5 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x80) { // pict coding ext |
2743 | 161 | sc->interlaced = !(pkt->data[i+5] & 0x80); // progressive frame | |
2744 |
2/2✓ Branch 0 taken 37 times.
✓ Branch 1 taken 124 times.
|
161 | if (sc->interlaced) |
2745 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
|
37 | sc->field_dominance = 1 + !(pkt->data[i+4] & 0x80); // top field first |
2746 | 161 | break; | |
2747 | } | ||
2748 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 3673 times.
|
3725 | } else if (c == 0x1b8) { // gop |
2749 |
2/2✓ Branch 0 taken 31 times.
✓ Branch 1 taken 21 times.
|
52 | if (pkt->data[i+4]>>6 & 0x01) { // closed |
2750 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 24 times.
|
31 | if (sc->seq_closed_gop == -1) |
2751 | 7 | sc->seq_closed_gop = 1; | |
2752 | 31 | sc->closed_gop = 1; | |
2753 |
1/2✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
|
31 | if (e->flags & 0x40) // sequence header present |
2754 | 31 | e->flags |= 0x80; // random access | |
2755 | } else { | ||
2756 | 21 | sc->seq_closed_gop = 0; | |
2757 | 21 | sc->closed_gop = 0; | |
2758 | } | ||
2759 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 3621 times.
|
3673 | } else if (c == 0x1b3) { // seq |
2760 | 52 | e->flags |= 0x40; | |
2761 |
3/4✓ Branch 0 taken 15 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 34 times.
|
52 | switch ((pkt->data[i+4]>>4) & 0xf) { |
2762 | 18 | case 2: sc->aspect_ratio = (AVRational){ 4, 3}; break; | |
2763 | 3 | case 3: sc->aspect_ratio = (AVRational){ 16, 9}; break; | |
2764 | ✗ | case 4: sc->aspect_ratio = (AVRational){221,100}; break; | |
2765 | 34 | default: | |
2766 | 34 | av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den, | |
2767 | 34 | st->codecpar->width, st->codecpar->height, 1024*1024); | |
2768 | } | ||
2769 |
2/2✓ Branch 0 taken 161 times.
✓ Branch 1 taken 3460 times.
|
3621 | } else if (c == 0x100) { // pic |
2770 | 161 | int pict_type = (pkt->data[i+2]>>3) & 0x07; | |
2771 | 161 | e->temporal_ref = (pkt->data[i+1]<<2) | (pkt->data[i+2]>>6); | |
2772 |
2/2✓ Branch 0 taken 58 times.
✓ Branch 1 taken 103 times.
|
161 | if (pict_type == 2) { // P-frame |
2773 | 58 | e->flags |= 0x22; | |
2774 | 58 | sc->closed_gop = 0; // reset closed GOP, don't matter anymore | |
2775 |
2/2✓ Branch 0 taken 51 times.
✓ Branch 1 taken 52 times.
|
103 | } else if (pict_type == 3) { // B-frame |
2776 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
|
51 | if (sc->closed_gop) |
2777 | ✗ | e->flags |= 0x13; // only backward prediction | |
2778 | else | ||
2779 | 51 | e->flags |= 0x33; | |
2780 | 51 | sc->temporal_reordering = -1; | |
2781 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 52 times.
|
52 | } else if (!pict_type) { |
2782 | ✗ | av_log(s, AV_LOG_ERROR, "error parsing mpeg2 frame\n"); | |
2783 | ✗ | return 0; | |
2784 | } | ||
2785 | } | ||
2786 | } | ||
2787 |
2/2✓ Branch 0 taken 111 times.
✓ Branch 1 taken 50 times.
|
161 | if (!IS_D10(s)) { |
2788 | 111 | const UID *codec_ul = mxf_get_mpeg2_codec_ul(st->codecpar); | |
2789 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 111 times.
|
111 | if (!codec_ul) |
2790 | ✗ | return 0; | |
2791 | 111 | sc->codec_ul = codec_ul; | |
2792 | } | ||
2793 | 161 | return 1; | |
2794 | } | ||
2795 | |||
2796 | ✗ | static uint64_t mxf_parse_timestamp(int64_t timestamp64) | |
2797 | { | ||
2798 | ✗ | time_t timestamp = timestamp64 / 1000000; | |
2799 | struct tm tmbuf; | ||
2800 | ✗ | struct tm *time = gmtime_r(×tamp, &tmbuf); | |
2801 | ✗ | if (!time) | |
2802 | ✗ | return 0; | |
2803 | ✗ | return (uint64_t)(time->tm_year+1900) << 48 | | |
2804 | ✗ | (uint64_t)(time->tm_mon+1) << 40 | | |
2805 | ✗ | (uint64_t) time->tm_mday << 32 | | |
2806 | ✗ | time->tm_hour << 24 | | |
2807 | ✗ | time->tm_min << 16 | | |
2808 | ✗ | time->tm_sec << 8 | | |
2809 | ✗ | (timestamp64 % 1000000) / 4000; | |
2810 | } | ||
2811 | |||
2812 | ✗ | static void mxf_gen_umid(AVFormatContext *s) | |
2813 | { | ||
2814 | ✗ | MXFContext *mxf = s->priv_data; | |
2815 | ✗ | uint32_t seed = av_get_random_seed(); | |
2816 | ✗ | uint64_t umid = seed + 0x5294713400000000LL; | |
2817 | |||
2818 | ✗ | AV_WB64(mxf->umid , umid); | |
2819 | ✗ | AV_WB64(mxf->umid+8, umid>>8); | |
2820 | |||
2821 | ✗ | mxf->instance_number = seed & 0xFFFFFF; | |
2822 | ✗ | } | |
2823 | |||
2824 | 17 | static int mxf_init_timecode(AVFormatContext *s, AVStream *st, AVRational tbc) | |
2825 | { | ||
2826 | 17 | MXFContext *mxf = s->priv_data; | |
2827 | 17 | AVDictionaryEntry *tcr = av_dict_get(s->metadata, "timecode", NULL, 0); | |
2828 | |||
2829 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
17 | if (!ff_mxf_get_content_package_rate(tbc)) { |
2830 | ✗ | if (s->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) { | |
2831 | ✗ | av_log(s, AV_LOG_ERROR, "Unsupported frame rate %d/%d. Set -strict option to 'unofficial' or lower in order to allow it!\n", tbc.den, tbc.num); | |
2832 | ✗ | return AVERROR(EINVAL); | |
2833 | } else { | ||
2834 | ✗ | av_log(s, AV_LOG_WARNING, "Unofficial frame rate %d/%d.\n", tbc.den, tbc.num); | |
2835 | } | ||
2836 | } | ||
2837 | |||
2838 | 17 | mxf->timecode_base = (tbc.den + tbc.num/2) / tbc.num; | |
2839 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 7 times.
|
17 | if (!tcr) |
2840 | 10 | tcr = av_dict_get(st->metadata, "timecode", NULL, 0); | |
2841 | |||
2842 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 10 times.
|
17 | if (tcr) |
2843 | 7 | return av_timecode_init_from_string(&mxf->tc, av_inv_q(tbc), tcr->value, s); | |
2844 | else | ||
2845 | 10 | return av_timecode_init(&mxf->tc, av_inv_q(tbc), 0, 0, s); | |
2846 | } | ||
2847 | |||
2848 | 16 | static enum AVChromaLocation choose_chroma_location(AVFormatContext *s, AVStream *st) | |
2849 | { | ||
2850 | 16 | AVCodecParameters *par = st->codecpar; | |
2851 | 16 | const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(par->format); | |
2852 | |||
2853 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 10 times.
|
16 | if (par->chroma_location != AVCHROMA_LOC_UNSPECIFIED) |
2854 | 6 | return par->chroma_location; | |
2855 | |||
2856 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | if (pix_desc) { |
2857 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
|
10 | if (pix_desc->log2_chroma_h == 0) { |
2858 | 5 | return AVCHROMA_LOC_TOPLEFT; | |
2859 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | } else if (pix_desc->log2_chroma_w == 1 && pix_desc->log2_chroma_h == 1) { |
2860 |
3/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 1 times.
|
5 | if (par->field_order == AV_FIELD_UNKNOWN || par->field_order == AV_FIELD_PROGRESSIVE) { |
2861 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | switch (par->codec_id) { |
2862 | ✗ | case AV_CODEC_ID_MJPEG: | |
2863 | ✗ | case AV_CODEC_ID_MPEG1VIDEO: return AVCHROMA_LOC_CENTER; | |
2864 | } | ||
2865 | } | ||
2866 |
3/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 4 times.
|
5 | if (par->field_order == AV_FIELD_UNKNOWN || par->field_order != AV_FIELD_PROGRESSIVE) { |
2867 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | switch (par->codec_id) { |
2868 | ✗ | case AV_CODEC_ID_MPEG2VIDEO: return AVCHROMA_LOC_LEFT; | |
2869 | } | ||
2870 | } | ||
2871 | } | ||
2872 | } | ||
2873 | |||
2874 | 5 | return AVCHROMA_LOC_UNSPECIFIED; | |
2875 | } | ||
2876 | |||
2877 | 17 | static int mxf_init(AVFormatContext *s) | |
2878 | { | ||
2879 | 17 | MXFContext *mxf = s->priv_data; | |
2880 | int i, ret; | ||
2881 | 17 | uint8_t present[FF_ARRAY_ELEMS(mxf_essence_container_uls)] = {0}; | |
2882 | 17 | int64_t timestamp = 0; | |
2883 | |||
2884 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
17 | if (IS_OPATOM(s) && s->nb_streams != 1) { |
2885 | ✗ | av_log(s, AV_LOG_ERROR, "there must be exactly one stream for mxf opatom\n"); | |
2886 | ✗ | return -1; | |
2887 | } | ||
2888 | |||
2889 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 2 taken 3 times.
|
17 | if (!av_dict_get(s->metadata, "comment_", NULL, AV_DICT_IGNORE_SUFFIX)) |
2890 | 14 | mxf->store_user_comments = 0; | |
2891 | |||
2892 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 17 times.
|
46 | for (i = 0; i < s->nb_streams; i++) { |
2893 | 29 | AVStream *st = s->streams[i]; | |
2894 | 29 | MXFStreamContext *sc = av_mallocz(sizeof(*sc)); | |
2895 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
|
29 | if (!sc) |
2896 | ✗ | return AVERROR(ENOMEM); | |
2897 | 29 | st->priv_data = sc; | |
2898 | 29 | sc->index = -1; | |
2899 | |||
2900 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
29 | if (((i == 0) ^ (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)) && !IS_OPATOM(s)) { |
2901 | ✗ | av_log(s, AV_LOG_ERROR, "there must be exactly one video stream and it must be the first one\n"); | |
2902 | ✗ | return -1; | |
2903 | } | ||
2904 | |||
2905 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 13 times.
|
29 | if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { |
2906 | 16 | const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codecpar->format); | |
2907 | 16 | AVRational tbc = (AVRational){ 0, 0 }; | |
2908 |
3/4✓ Branch 0 taken 15 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
|
16 | if (st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0) |
2909 | 15 | tbc = av_inv_q(st->avg_frame_rate); | |
2910 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | else if (st->r_frame_rate.num > 0 && st->r_frame_rate.den > 0) |
2911 | 1 | tbc = av_inv_q(st->r_frame_rate); | |
2912 | |||
2913 | // Default component depth to 8 | ||
2914 | 16 | sc->component_depth = 8; | |
2915 | 16 | sc->h_chroma_sub_sample = 2; | |
2916 | 16 | sc->v_chroma_sub_sample = 2; | |
2917 | 16 | sc->color_siting = 0xFF; | |
2918 | |||
2919 |
3/4✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
|
16 | if (st->codecpar->sample_aspect_ratio.num && st->codecpar->sample_aspect_ratio.den) { |
2920 | 11 | sc->aspect_ratio = av_mul_q(st->codecpar->sample_aspect_ratio, | |
2921 | 11 | av_make_q(st->codecpar->width, st->codecpar->height)); | |
2922 | } | ||
2923 | |||
2924 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | if (pix_desc) { |
2925 | 16 | sc->component_depth = pix_desc->comp[0].depth; | |
2926 | 16 | sc->h_chroma_sub_sample = 1 << pix_desc->log2_chroma_w; | |
2927 | 16 | sc->v_chroma_sub_sample = 1 << pix_desc->log2_chroma_h; | |
2928 | } | ||
2929 |
3/5✓ Branch 1 taken 10 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 5 times.
|
16 | switch (choose_chroma_location(s, st)) { |
2930 | 10 | case AVCHROMA_LOC_TOPLEFT: sc->color_siting = 0; break; | |
2931 | 1 | case AVCHROMA_LOC_LEFT: sc->color_siting = 6; break; | |
2932 | ✗ | case AVCHROMA_LOC_TOP: sc->color_siting = 1; break; | |
2933 | ✗ | case AVCHROMA_LOC_CENTER: sc->color_siting = 3; break; | |
2934 | } | ||
2935 | |||
2936 | 16 | mxf->content_package_rate = ff_mxf_get_content_package_rate(tbc); | |
2937 | 16 | mxf->time_base = tbc; | |
2938 | 16 | avpriv_set_pts_info(st, 64, mxf->time_base.num, mxf->time_base.den); | |
2939 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
|
16 | if((ret = mxf_init_timecode(s, st, tbc)) < 0) |
2940 | ✗ | return ret; | |
2941 | |||
2942 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 6 times.
|
16 | if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) { |
2943 | 10 | sc->seq_closed_gop = -1; // unknown yet | |
2944 | } | ||
2945 | |||
2946 | 16 | sc->video_bit_rate = st->codecpar->bit_rate; | |
2947 | |||
2948 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 2 times.
|
16 | if (IS_D10(s) || |
2949 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 1 times.
|
14 | st->codecpar->codec_id == AV_CODEC_ID_DNXHD || |
2950 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 10 times.
|
13 | st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO) |
2951 | 6 | mxf->cbr_index = 1; | |
2952 | |||
2953 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 14 times.
|
16 | if (IS_D10(s)) { |
2954 | 2 | int ntsc = mxf->time_base.den != 25; | |
2955 | int ul_index; | ||
2956 | |||
2957 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (st->codecpar->codec_id != AV_CODEC_ID_MPEG2VIDEO) { |
2958 | ✗ | av_log(s, AV_LOG_ERROR, "error MXF D-10 only support MPEG-2 Video\n"); | |
2959 | ✗ | return AVERROR(EINVAL); | |
2960 | } | ||
2961 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
2 | if ((sc->video_bit_rate == 50000000) && (mxf->time_base.den == 25)) { |
2962 | ✗ | ul_index = 0; | |
2963 |
2/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
2 | } else if ((sc->video_bit_rate == 49999840 || sc->video_bit_rate == 50000000) && ntsc) { |
2964 | ✗ | ul_index = 1; | |
2965 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | } else if (sc->video_bit_rate == 40000000) { |
2966 | ✗ | ul_index = 2+ntsc; | |
2967 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | } else if (sc->video_bit_rate == 30000000) { |
2968 | 2 | ul_index = 4+ntsc; | |
2969 | } else { | ||
2970 | ✗ | av_log(s, AV_LOG_ERROR, "error MXF D-10 only support 30/40/50 mbit/s\n"); | |
2971 | ✗ | return -1; | |
2972 | } | ||
2973 | |||
2974 | 2 | sc->codec_ul = &mxf_d10_codec_uls[ul_index]; | |
2975 | 2 | sc->container_ul = &mxf_d10_container_uls[ul_index]; | |
2976 | 2 | sc->index = INDEX_D10_VIDEO; | |
2977 | 2 | sc->signal_standard = 1; | |
2978 | 2 | sc->color_siting = 0; | |
2979 | 2 | sc->frame_size = (int64_t)sc->video_bit_rate * | |
2980 | 2 | mxf->time_base.num / (8*mxf->time_base.den); | |
2981 | } | ||
2982 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | if (mxf->signal_standard >= 0) |
2983 | ✗ | sc->signal_standard = mxf->signal_standard; | |
2984 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { |
2985 | char bsf_arg[32]; | ||
2986 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (st->codecpar->sample_rate != 48000) { |
2987 | ✗ | av_log(s, AV_LOG_ERROR, "only 48khz is implemented\n"); | |
2988 | ✗ | return -1; | |
2989 | } | ||
2990 | 13 | avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); | |
2991 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 12 times.
|
13 | if (IS_D10(s)) { |
2992 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (st->index != 1) { |
2993 | ✗ | av_log(s, AV_LOG_ERROR, "MXF D-10 only support one audio track\n"); | |
2994 | ✗ | return -1; | |
2995 | } | ||
2996 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (st->codecpar->codec_id != AV_CODEC_ID_PCM_S16LE && |
2997 | ✗ | st->codecpar->codec_id != AV_CODEC_ID_PCM_S24LE) { | |
2998 | ✗ | av_log(s, AV_LOG_ERROR, "MXF D-10 only support 16 or 24 bits le audio\n"); | |
2999 | } | ||
3000 | 1 | sc->index = INDEX_D10_AUDIO; | |
3001 | 1 | sc->container_ul = ((MXFStreamContext*)s->streams[0]->priv_data)->container_ul; | |
3002 | 1 | sc->frame_size = 4 + 8 * av_rescale_rnd(st->codecpar->sample_rate, mxf->time_base.num, mxf->time_base.den, AV_ROUND_UP) * 4; | |
3003 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11 times.
|
12 | } else if (IS_OPATOM(s)) { |
3004 | 1 | AVRational tbc = av_inv_q(mxf->audio_edit_rate); | |
3005 | |||
3006 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (st->codecpar->codec_id != AV_CODEC_ID_PCM_S16LE && |
3007 | ✗ | st->codecpar->codec_id != AV_CODEC_ID_PCM_S24LE) { | |
3008 | ✗ | av_log(s, AV_LOG_ERROR, "Only pcm_s16le and pcm_s24le audio codecs are implemented\n"); | |
3009 | ✗ | return AVERROR_PATCHWELCOME; | |
3010 | } | ||
3011 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (st->codecpar->ch_layout.nb_channels != 1) { |
3012 | ✗ | av_log(s, AV_LOG_ERROR, "MXF OPAtom only supports single channel audio\n"); | |
3013 | ✗ | return AVERROR(EINVAL); | |
3014 | } | ||
3015 | |||
3016 | 1 | mxf->time_base = st->time_base; | |
3017 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if((ret = mxf_init_timecode(s, st, tbc)) < 0) |
3018 | ✗ | return ret; | |
3019 | |||
3020 | 1 | mxf->edit_unit_byte_count = (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->ch_layout.nb_channels) >> 3; | |
3021 | 1 | sc->index = INDEX_WAV; | |
3022 | } else { | ||
3023 | 11 | mxf->slice_count = 1; | |
3024 | 22 | sc->frame_size = st->codecpar->ch_layout.nb_channels * | |
3025 | 22 | av_rescale_rnd(st->codecpar->sample_rate, mxf->time_base.num, mxf->time_base.den, AV_ROUND_UP) * | |
3026 | 11 | av_get_bits_per_sample(st->codecpar->codec_id) / 8; | |
3027 | } | ||
3028 | 13 | snprintf(bsf_arg, sizeof(bsf_arg), "r=%d/%d", mxf->tc.rate.num, mxf->tc.rate.den); | |
3029 | 13 | ret = ff_stream_add_bitstream_filter(st, "pcm_rechunk", bsf_arg); | |
3030 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (ret < 0) |
3031 | ✗ | return ret; | |
3032 | ✗ | } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) { | |
3033 | ✗ | AVDictionaryEntry *e = av_dict_get(st->metadata, "data_type", NULL, 0); | |
3034 | ✗ | if (e && !strcmp(e->value, "vbi_vanc_smpte_436M")) { | |
3035 | ✗ | sc->index = INDEX_S436M; | |
3036 | } else { | ||
3037 | ✗ | av_log(s, AV_LOG_ERROR, "track %d: unsupported data type\n", i); | |
3038 | ✗ | return -1; | |
3039 | } | ||
3040 | ✗ | if (st->index != s->nb_streams - 1) { | |
3041 | ✗ | av_log(s, AV_LOG_ERROR, "data track must be placed last\n"); | |
3042 | ✗ | return -1; | |
3043 | } | ||
3044 | } | ||
3045 | |||
3046 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 4 times.
|
29 | if (sc->index == -1) { |
3047 | 25 | sc->index = mxf_get_essence_container_ul_index(st->codecpar->codec_id); | |
3048 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (sc->index == -1) { |
3049 | ✗ | av_log(s, AV_LOG_ERROR, "track %d: could not find essence container ul, " | |
3050 | "codec not currently supported in container\n", i); | ||
3051 | ✗ | return -1; | |
3052 | } | ||
3053 | } | ||
3054 | |||
3055 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 2 times.
|
29 | if (!sc->codec_ul) |
3056 | 27 | sc->codec_ul = &mxf_essence_container_uls[sc->index].codec_ul; | |
3057 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 3 times.
|
29 | if (!sc->container_ul) |
3058 | 26 | sc->container_ul = &mxf_essence_container_uls[sc->index].container_ul; | |
3059 | |||
3060 | 29 | memcpy(sc->track_essence_element_key, mxf_essence_container_uls[sc->index].element_ul, 15); | |
3061 | 29 | sc->track_essence_element_key[15] = present[sc->index]; | |
3062 |
4/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 26 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
|
29 | if (IS_OPATOM(s) && st->codecpar->codec_id == AV_CODEC_ID_DNXHD) { |
3063 | // clip-wrapping requires 0x0D per ST2019-4:2009 or 0x06 per previous version ST2019-4:2008 | ||
3064 | // we choose to use 0x06 instead 0x0D to be compatible with AVID systems | ||
3065 | // and produce mxf files with the most relevant flavour for opatom | ||
3066 | 1 | sc->track_essence_element_key[14] = 0x06; | |
3067 | } | ||
3068 | PRINT_KEY(s, "track essence element key", sc->track_essence_element_key); | ||
3069 | |||
3070 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 1 times.
|
29 | if (!present[sc->index]) |
3071 | 28 | mxf->essence_container_count++; | |
3072 | 29 | present[sc->index]++; | |
3073 | } | ||
3074 | |||
3075 |
4/4✓ Branch 0 taken 15 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 12 times.
|
17 | if (IS_D10(s) || IS_OPATOM(s)) { |
3076 | 5 | mxf->essence_container_count = 1; | |
3077 | } | ||
3078 | |||
3079 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | if (!(s->flags & AVFMT_FLAG_BITEXACT)) |
3080 | ✗ | mxf_gen_umid(s); | |
3081 | |||
3082 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 17 times.
|
46 | for (i = 0; i < s->nb_streams; i++) { |
3083 | 29 | MXFStreamContext *sc = s->streams[i]->priv_data; | |
3084 | // update element count | ||
3085 | 29 | sc->track_essence_element_key[13] = present[sc->index]; | |
3086 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 26 times.
|
29 | if (!memcmp(sc->track_essence_element_key, mxf_essence_container_uls[INDEX_DV].element_ul, 13)) // DV |
3087 | 3 | sc->order = (0x15 << 24) | AV_RB32(sc->track_essence_element_key+13); | |
3088 | else | ||
3089 | 26 | sc->order = AV_RB32(sc->track_essence_element_key+12); | |
3090 | } | ||
3091 | |||
3092 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
17 | if (ff_parse_creation_time_metadata(s, ×tamp, 0) > 0) |
3093 | ✗ | mxf->timestamp = mxf_parse_timestamp(timestamp); | |
3094 | 17 | mxf->duration = -1; | |
3095 | |||
3096 | 17 | mxf->timecode_track = av_mallocz(sizeof(*mxf->timecode_track)); | |
3097 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | if (!mxf->timecode_track) |
3098 | ✗ | return AVERROR(ENOMEM); | |
3099 | 17 | mxf->timecode_track->priv_data = &mxf->timecode_track_priv; | |
3100 | 17 | mxf->timecode_track->index = -1; | |
3101 | |||
3102 | 17 | return 0; | |
3103 | } | ||
3104 | |||
3105 | static const uint8_t system_metadata_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x03,0x01,0x04,0x01,0x01,0x00 }; | ||
3106 | static const uint8_t system_metadata_package_set_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x43,0x01,0x01,0x0D,0x01,0x03,0x01,0x04,0x01,0x02,0x01 }; | ||
3107 | |||
3108 | 262 | static void mxf_write_system_item(AVFormatContext *s) | |
3109 | { | ||
3110 | 262 | MXFContext *mxf = s->priv_data; | |
3111 | 262 | AVIOContext *pb = s->pb; | |
3112 | unsigned frame; | ||
3113 | uint32_t time_code; | ||
3114 | 262 | int i, system_item_bitmap = 0x58; // UL, user date/time stamp, picture present | |
3115 | |||
3116 | 262 | frame = mxf->last_indexed_edit_unit + mxf->edit_units_count; | |
3117 | |||
3118 | // write system metadata pack | ||
3119 | 262 | avio_write(pb, system_metadata_pack_key, 16); | |
3120 | 262 | klv_encode_ber4_length(pb, 57); | |
3121 | |||
3122 |
2/2✓ Branch 0 taken 478 times.
✓ Branch 1 taken 262 times.
|
740 | for (i = 0; i < s->nb_streams; i++) { |
3123 |
2/2✓ Branch 0 taken 216 times.
✓ Branch 1 taken 262 times.
|
478 | if (s->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) |
3124 | 216 | system_item_bitmap |= 0x4; | |
3125 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 262 times.
|
262 | else if (s->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_DATA) |
3126 | ✗ | system_item_bitmap |= 0x2; | |
3127 | } | ||
3128 | 262 | avio_w8(pb, system_item_bitmap); | |
3129 | 262 | avio_w8(pb, mxf->content_package_rate); // content package rate | |
3130 | 262 | avio_w8(pb, 0x00); // content package type | |
3131 | 262 | avio_wb16(pb, 0x00); // channel handle | |
3132 | 262 | avio_wb16(pb, frame & 0xFFFF); // continuity count, supposed to overflow | |
3133 |
2/2✓ Branch 0 taken 186 times.
✓ Branch 1 taken 76 times.
|
262 | if (mxf->essence_container_count > 1) |
3134 | 186 | avio_write(pb, multiple_desc_ul, 16); | |
3135 | else { | ||
3136 | 76 | MXFStreamContext *sc = s->streams[0]->priv_data; | |
3137 | 76 | avio_write(pb, *sc->container_ul, 16); | |
3138 | } | ||
3139 | 262 | avio_w8(pb, 0); | |
3140 | 262 | avio_wb64(pb, 0); | |
3141 | 262 | avio_wb64(pb, 0); // creation date/time stamp | |
3142 | |||
3143 | 262 | avio_w8(pb, 0x81); // SMPTE 12M time code | |
3144 | 262 | time_code = av_timecode_get_smpte_from_framenum(&mxf->tc, frame); | |
3145 | 262 | avio_wb32(pb, time_code); | |
3146 | 262 | avio_wb32(pb, 0); // binary group data | |
3147 | 262 | avio_wb64(pb, 0); | |
3148 | |||
3149 | // write system metadata package set | ||
3150 | 262 | avio_write(pb, system_metadata_package_set_key, 16); | |
3151 | 262 | klv_encode_ber4_length(pb, 35); | |
3152 | 262 | avio_w8(pb, 0x83); // UMID | |
3153 | 262 | avio_wb16(pb, 0x20); | |
3154 | 262 | mxf_write_umid(s, 1); | |
3155 | 262 | } | |
3156 | |||
3157 | 25 | static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt) | |
3158 | { | ||
3159 | 25 | MXFContext *mxf = s->priv_data; | |
3160 | 25 | AVIOContext *pb = s->pb; | |
3161 | 25 | int frame_size = pkt->size / st->codecpar->block_align; | |
3162 | 25 | const uint8_t *samples = pkt->data; | |
3163 | 25 | const uint8_t *const end = pkt->data + pkt->size; | |
3164 | int i; | ||
3165 | |||
3166 | 25 | klv_encode_ber4_length(pb, 4 + frame_size*4*8); | |
3167 | |||
3168 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | avio_w8(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1)); |
3169 | 25 | avio_wl16(pb, frame_size); | |
3170 | 25 | avio_w8(pb, (1 << st->codecpar->ch_layout.nb_channels)-1); | |
3171 | |||
3172 |
2/2✓ Branch 0 taken 48000 times.
✓ Branch 1 taken 25 times.
|
48025 | while (samples < end) { |
3173 |
2/2✓ Branch 0 taken 96000 times.
✓ Branch 1 taken 48000 times.
|
144000 | for (i = 0; i < st->codecpar->ch_layout.nb_channels; i++) { |
3174 | uint32_t sample; | ||
3175 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 96000 times.
|
96000 | if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S24LE) { |
3176 | ✗ | sample = AV_RL24(samples)<< 4; | |
3177 | ✗ | samples += 3; | |
3178 | } else { | ||
3179 | 96000 | sample = AV_RL16(samples)<<12; | |
3180 | 96000 | samples += 2; | |
3181 | } | ||
3182 | 96000 | avio_wl32(pb, sample | i); | |
3183 | } | ||
3184 |
2/2✓ Branch 0 taken 288000 times.
✓ Branch 1 taken 48000 times.
|
336000 | for (; i < 8; i++) |
3185 | 288000 | avio_wl32(pb, i); | |
3186 | } | ||
3187 | 25 | } | |
3188 | |||
3189 | 6 | static int mxf_write_opatom_body_partition(AVFormatContext *s) | |
3190 | { | ||
3191 | 6 | MXFContext *mxf = s->priv_data; | |
3192 | 6 | AVIOContext *pb = s->pb; | |
3193 | 6 | AVStream *st = s->streams[0]; | |
3194 | 6 | MXFStreamContext *sc = st->priv_data; | |
3195 | 6 | const uint8_t *key = NULL; | |
3196 | |||
3197 | int err; | ||
3198 | |||
3199 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | if (!mxf->header_written) |
3200 | 3 | key = body_partition_key; | |
3201 | |||
3202 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
|
6 | if ((err = mxf_write_partition(s, 1, 0, key, 0)) < 0) |
3203 | ✗ | return err; | |
3204 | 6 | mxf_write_klv_fill(s); | |
3205 | 6 | avio_write(pb, sc->track_essence_element_key, 16); | |
3206 | 6 | klv_encode_ber9_length(pb, mxf->body_offset); | |
3207 | 6 | return 0; | |
3208 | } | ||
3209 | |||
3210 | 54 | static int mxf_write_opatom_packet(AVFormatContext *s, AVPacket *pkt, MXFIndexEntry *ie) | |
3211 | { | ||
3212 | 54 | MXFContext *mxf = s->priv_data; | |
3213 | 54 | AVIOContext *pb = s->pb; | |
3214 | |||
3215 | int err; | ||
3216 | |||
3217 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 51 times.
|
54 | if (!mxf->header_written) { |
3218 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if ((err = mxf_write_partition(s, 0, 0, header_open_partition_key, 1)) < 0) |
3219 | ✗ | return err; | |
3220 | 3 | mxf_write_klv_fill(s); | |
3221 | |||
3222 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if ((err = mxf_write_opatom_body_partition(s)) < 0) |
3223 | ✗ | return err; | |
3224 | 3 | mxf->header_written = 1; | |
3225 | } | ||
3226 | |||
3227 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 50 times.
|
54 | if (!mxf->edit_unit_byte_count) { |
3228 | 4 | mxf->index_entries[mxf->edit_units_count].offset = mxf->body_offset; | |
3229 | 4 | mxf->index_entries[mxf->edit_units_count].flags = ie->flags; | |
3230 | 4 | mxf->index_entries[mxf->edit_units_count].temporal_ref = ie->temporal_ref; | |
3231 | } | ||
3232 | 54 | mxf->edit_units_count++; | |
3233 | 54 | avio_write(pb, pkt->data, pkt->size); | |
3234 | 54 | mxf->body_offset += pkt->size; | |
3235 | |||
3236 | 54 | return 0; | |
3237 | } | ||
3238 | |||
3239 | 6 | static void mxf_compute_edit_unit_byte_count(AVFormatContext *s) | |
3240 | { | ||
3241 | 6 | MXFContext *mxf = s->priv_data; | |
3242 | int i; | ||
3243 | |||
3244 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
|
6 | if (IS_OPATOM(s)) { |
3245 | 1 | MXFStreamContext *sc = s->streams[0]->priv_data; | |
3246 | 1 | mxf->edit_unit_byte_count = sc->frame_size; | |
3247 | 1 | return; | |
3248 | } | ||
3249 | |||
3250 | 5 | mxf->edit_unit_byte_count = KAG_SIZE; // system element | |
3251 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 5 times.
|
14 | for (i = 0; i < s->nb_streams; i++) { |
3252 | 9 | AVStream *st = s->streams[i]; | |
3253 | 9 | MXFStreamContext *sc = st->priv_data; | |
3254 | 9 | sc->slice_offset = mxf->edit_unit_byte_count; | |
3255 | 9 | mxf->edit_unit_byte_count += 16 + 4 + sc->frame_size; | |
3256 | 9 | mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count); | |
3257 | } | ||
3258 | } | ||
3259 | |||
3260 | 532 | static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt) | |
3261 | { | ||
3262 | 532 | MXFContext *mxf = s->priv_data; | |
3263 | 532 | AVIOContext *pb = s->pb; | |
3264 | 532 | AVStream *st = s->streams[pkt->stream_index]; | |
3265 | 532 | MXFStreamContext *sc = st->priv_data; | |
3266 | 532 | MXFIndexEntry ie = {0}; | |
3267 | int err; | ||
3268 | |||
3269 |
3/4✓ Branch 0 taken 17 times.
✓ Branch 1 taken 515 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
|
532 | if (!mxf->header_written && pkt->stream_index != 0 && |
3270 | ✗ | !IS_OPATOM(s)) { | |
3271 | ✗ | av_log(s, AV_LOG_ERROR, "Received non-video packet before " | |
3272 | "header has been written\n"); | ||
3273 | ✗ | return AVERROR_INVALIDDATA; | |
3274 | } | ||
3275 | |||
3276 |
6/6✓ Branch 0 taken 282 times.
✓ Branch 1 taken 250 times.
✓ Branch 2 taken 257 times.
✓ Branch 3 taken 25 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 247 times.
|
532 | if (!mxf->cbr_index && !mxf->edit_unit_byte_count && !(mxf->edit_units_count % EDIT_UNITS_PER_BODY)) { |
3277 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if ((err = av_reallocp_array(&mxf->index_entries, mxf->edit_units_count |
3278 | 10 | + EDIT_UNITS_PER_BODY, sizeof(*mxf->index_entries))) < 0) { | |
3279 | ✗ | mxf->edit_units_count = 0; | |
3280 | ✗ | av_log(s, AV_LOG_ERROR, "could not allocate index entries\n"); | |
3281 | ✗ | return err; | |
3282 | } | ||
3283 | } | ||
3284 | |||
3285 |
2/2✓ Branch 0 taken 161 times.
✓ Branch 1 taken 371 times.
|
532 | if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) { |
3286 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 161 times.
|
161 | if (!mxf_parse_mpeg2_frame(s, st, pkt, &ie)) { |
3287 | ✗ | av_log(s, AV_LOG_ERROR, "could not get mpeg2 profile and level\n"); | |
3288 | ✗ | return -1; | |
3289 | } | ||
3290 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 346 times.
|
371 | } else if (st->codecpar->codec_id == AV_CODEC_ID_DNXHD) { |
3291 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
|
25 | if (!mxf_parse_dnxhd_frame(s, st, pkt)) { |
3292 | ✗ | av_log(s, AV_LOG_ERROR, "could not get dnxhd profile\n"); | |
3293 | ✗ | return -1; | |
3294 | } | ||
3295 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 341 times.
|
346 | } else if (st->codecpar->codec_id == AV_CODEC_ID_PRORES) { |
3296 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
|
5 | if (!mxf_parse_prores_frame(s, st, pkt)) { |
3297 | ✗ | av_log(s, AV_LOG_ERROR, "could not get prores profile\n"); | |
3298 | ✗ | return -1; | |
3299 | } | ||
3300 |
2/2✓ Branch 0 taken 75 times.
✓ Branch 1 taken 266 times.
|
341 | } else if (st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO) { |
3301 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 75 times.
|
75 | if (!mxf_parse_dv_frame(s, st, pkt)) { |
3302 | ✗ | av_log(s, AV_LOG_ERROR, "could not get dv profile\n"); | |
3303 | ✗ | return -1; | |
3304 | } | ||
3305 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 266 times.
|
266 | } else if (st->codecpar->codec_id == AV_CODEC_ID_H264) { |
3306 | ✗ | if (!mxf_parse_h264_frame(s, st, pkt, &ie)) { | |
3307 | ✗ | av_log(s, AV_LOG_ERROR, "could not get h264 profile\n"); | |
3308 | ✗ | return -1; | |
3309 | } | ||
3310 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 241 times.
|
266 | } else if (st->codecpar->codec_id == AV_CODEC_ID_FFV1) { |
3311 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
|
25 | if (!mxf_parse_ffv1_frame(s, st, pkt)) { |
3312 | ✗ | av_log(s, AV_LOG_ERROR, "could not get ffv1 version\n"); | |
3313 | ✗ | return -1; | |
3314 | } | ||
3315 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 241 times.
|
241 | } else if (st->codecpar->codec_id == AV_CODEC_ID_JPEG2000) { |
3316 | ✗ | if (!mxf_parse_jpeg2000_frame(s, st, pkt)) { | |
3317 | ✗ | av_log(s, AV_LOG_ERROR, "could not get jpeg2000 profile\n"); | |
3318 | ✗ | return -1; | |
3319 | } | ||
3320 | } | ||
3321 | |||
3322 |
2/2✓ Branch 0 taken 250 times.
✓ Branch 1 taken 282 times.
|
532 | if (mxf->cbr_index) { |
3323 |
3/4✓ Branch 0 taken 25 times.
✓ Branch 1 taken 225 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 25 times.
|
250 | if (pkt->size != sc->frame_size && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { |
3324 | ✗ | av_log(s, AV_LOG_ERROR, "track %d: frame size does not match index unit size, %d != %d\n", | |
3325 | st->index, pkt->size, sc->frame_size); | ||
3326 | ✗ | return -1; | |
3327 | } | ||
3328 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 244 times.
|
250 | if (!mxf->header_written) |
3329 | 6 | mxf_compute_edit_unit_byte_count(s); | |
3330 | } | ||
3331 | |||
3332 |
2/2✓ Branch 0 taken 54 times.
✓ Branch 1 taken 478 times.
|
532 | if (IS_OPATOM(s)) |
3333 | 54 | return mxf_write_opatom_packet(s, pkt, &ie); | |
3334 | |||
3335 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 464 times.
|
478 | if (!mxf->header_written) { |
3336 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 9 times.
|
14 | if (mxf->edit_unit_byte_count) { |
3337 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
|
5 | if ((err = mxf_write_partition(s, 1, 2, header_open_partition_key, 1)) < 0) |
3338 | ✗ | return err; | |
3339 | 5 | mxf_write_klv_fill(s); | |
3340 | 5 | mxf_write_index_table_segment(s); | |
3341 | } else { | ||
3342 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
|
9 | if ((err = mxf_write_partition(s, 0, 0, header_open_partition_key, 1)) < 0) |
3343 | ✗ | return err; | |
3344 | } | ||
3345 | 14 | mxf->header_written = 1; | |
3346 | } | ||
3347 | |||
3348 |
2/2✓ Branch 0 taken 262 times.
✓ Branch 1 taken 216 times.
|
478 | if (st->index == 0) { |
3349 |
2/2✓ Branch 0 taken 137 times.
✓ Branch 1 taken 125 times.
|
262 | if (!mxf->edit_unit_byte_count && |
3350 |
3/4✓ Branch 0 taken 128 times.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 128 times.
|
137 | (!mxf->edit_units_count || mxf->edit_units_count > EDIT_UNITS_PER_BODY) && |
3351 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | !(ie.flags & 0x33)) { // I-frame, GOP start |
3352 | 9 | mxf_write_klv_fill(s); | |
3353 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
|
9 | if ((err = mxf_write_partition(s, 1, 2, body_partition_key, 0)) < 0) |
3354 | ✗ | return err; | |
3355 | 9 | mxf_write_klv_fill(s); | |
3356 | 9 | mxf_write_index_table_segment(s); | |
3357 | } | ||
3358 | |||
3359 | 262 | mxf_write_klv_fill(s); | |
3360 | 262 | mxf_write_system_item(s); | |
3361 | |||
3362 |
2/2✓ Branch 0 taken 137 times.
✓ Branch 1 taken 125 times.
|
262 | if (!mxf->edit_unit_byte_count) { |
3363 | 137 | mxf->index_entries[mxf->edit_units_count].offset = mxf->body_offset; | |
3364 | 137 | mxf->index_entries[mxf->edit_units_count].flags = ie.flags; | |
3365 | 137 | mxf->index_entries[mxf->edit_units_count].temporal_ref = ie.temporal_ref; | |
3366 | 137 | mxf->body_offset += KAG_SIZE; // size of system element | |
3367 | } | ||
3368 | 262 | mxf->edit_units_count++; | |
3369 |
4/4✓ Branch 0 taken 116 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 111 times.
✓ Branch 3 taken 5 times.
|
216 | } else if (!mxf->edit_unit_byte_count && st->index == 1) { |
3370 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 111 times.
|
111 | if (!mxf->edit_units_count) { |
3371 | ✗ | av_log(s, AV_LOG_ERROR, "No packets in first stream\n"); | |
3372 | ✗ | return AVERROR_PATCHWELCOME; | |
3373 | } | ||
3374 | 111 | mxf->index_entries[mxf->edit_units_count-1].slice_offset = | |
3375 | 111 | mxf->body_offset - mxf->index_entries[mxf->edit_units_count-1].offset; | |
3376 | } | ||
3377 | |||
3378 | 478 | mxf_write_klv_fill(s); | |
3379 | 478 | avio_write(pb, sc->track_essence_element_key, 16); // write key | |
3380 |
4/4✓ Branch 0 taken 75 times.
✓ Branch 1 taken 403 times.
✓ Branch 2 taken 25 times.
✓ Branch 3 taken 50 times.
|
478 | if (IS_D10(s) && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { |
3381 | 25 | mxf_write_d10_audio_packet(s, st, pkt); | |
3382 | } else { | ||
3383 | 453 | klv_encode_ber4_length(pb, pkt->size); // write length | |
3384 | 453 | avio_write(pb, pkt->data, pkt->size); | |
3385 | 453 | mxf->body_offset += 16+4+pkt->size + klv_fill_size(16+4+pkt->size); | |
3386 | } | ||
3387 | |||
3388 | 478 | return 0; | |
3389 | } | ||
3390 | |||
3391 | 17 | static void mxf_write_random_index_pack(AVFormatContext *s) | |
3392 | { | ||
3393 | 17 | MXFContext *mxf = s->priv_data; | |
3394 | 17 | AVIOContext *pb = s->pb; | |
3395 | 17 | uint64_t pos = avio_tell(pb); | |
3396 | int i; | ||
3397 | |||
3398 | 17 | avio_write(pb, ff_mxf_random_index_pack_key, 16); | |
3399 | 17 | klv_encode_ber_length(pb, 28 + 12LL*mxf->body_partitions_count); | |
3400 | |||
3401 |
4/4✓ Branch 0 taken 7 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 2 times.
|
17 | if (mxf->edit_unit_byte_count && !IS_OPATOM(s)) |
3402 | 5 | avio_wb32(pb, 1); // BodySID of header partition | |
3403 | else | ||
3404 | 12 | avio_wb32(pb, 0); | |
3405 | 17 | avio_wb64(pb, 0); // offset of header partition | |
3406 | |||
3407 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 17 times.
|
29 | for (i = 0; i < mxf->body_partitions_count; i++) { |
3408 | 12 | avio_wb32(pb, 1); // BodySID | |
3409 | 12 | avio_wb64(pb, mxf->body_partition_offset[i]); | |
3410 | } | ||
3411 | |||
3412 | 17 | avio_wb32(pb, 0); // BodySID of footer partition | |
3413 | 17 | avio_wb64(pb, mxf->footer_partition_offset); | |
3414 | |||
3415 | 17 | avio_wb32(pb, avio_tell(pb) - pos + 4); | |
3416 | 17 | } | |
3417 | |||
3418 | 17 | static int mxf_write_footer(AVFormatContext *s) | |
3419 | { | ||
3420 | 17 | MXFContext *mxf = s->priv_data; | |
3421 | 17 | AVIOContext *pb = s->pb; | |
3422 | int i, err; | ||
3423 | |||
3424 |
1/2✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
|
17 | if (!mxf->header_written || |
3425 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
17 | (IS_OPATOM(s) && !mxf->body_partition_offset)) { |
3426 | /* reason could be invalid options/not supported codec/out of memory */ | ||
3427 | ✗ | return AVERROR_UNKNOWN; | |
3428 | } | ||
3429 | |||
3430 | 17 | mxf->duration = mxf->last_indexed_edit_unit + mxf->edit_units_count; | |
3431 | |||
3432 | 17 | mxf_write_klv_fill(s); | |
3433 | 17 | mxf->footer_partition_offset = avio_tell(pb); | |
3434 |
4/4✓ Branch 0 taken 7 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 2 times.
|
17 | if (mxf->edit_unit_byte_count && !IS_OPATOM(s)) { // no need to repeat index |
3435 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
|
5 | if ((err = mxf_write_partition(s, 0, 0, footer_partition_key, 0)) < 0) |
3436 | ✗ | return err; | |
3437 | } else { | ||
3438 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
|
12 | if ((err = mxf_write_partition(s, 0, 2, footer_partition_key, 0)) < 0) |
3439 | ✗ | return err; | |
3440 | 12 | mxf_write_klv_fill(s); | |
3441 | 12 | mxf_write_index_table_segment(s); | |
3442 | } | ||
3443 | |||
3444 | 17 | mxf_write_klv_fill(s); | |
3445 | 17 | mxf_write_random_index_pack(s); | |
3446 | |||
3447 |
1/2✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
|
17 | if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) { |
3448 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 14 times.
|
17 | if (IS_OPATOM(s)) { |
3449 | /* rewrite body partition to update lengths */ | ||
3450 | 3 | avio_seek(pb, mxf->body_partition_offset[0], SEEK_SET); | |
3451 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if ((err = mxf_write_opatom_body_partition(s)) < 0) |
3452 | ✗ | return err; | |
3453 | } | ||
3454 | |||
3455 | 17 | avio_seek(pb, 0, SEEK_SET); | |
3456 |
4/4✓ Branch 0 taken 7 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 2 times.
|
17 | if (mxf->edit_unit_byte_count && !IS_OPATOM(s)) { |
3457 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
|
5 | if ((err = mxf_write_partition(s, 1, 2, header_closed_partition_key, 1)) < 0) |
3458 | ✗ | return err; | |
3459 | 5 | mxf_write_klv_fill(s); | |
3460 | 5 | mxf_write_index_table_segment(s); | |
3461 | } else { | ||
3462 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
|
12 | if ((err = mxf_write_partition(s, 0, 0, header_closed_partition_key, 1)) < 0) |
3463 | ✗ | return err; | |
3464 | } | ||
3465 | // update footer partition offset | ||
3466 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 17 times.
|
29 | for (i = 0; i < mxf->body_partitions_count; i++) { |
3467 | 12 | avio_seek(pb, mxf->body_partition_offset[i]+44, SEEK_SET); | |
3468 | 12 | avio_wb64(pb, mxf->footer_partition_offset); | |
3469 | } | ||
3470 | } | ||
3471 | |||
3472 | 17 | return 0; | |
3473 | } | ||
3474 | |||
3475 | 17 | static void mxf_deinit(AVFormatContext *s) | |
3476 | { | ||
3477 | 17 | MXFContext *mxf = s->priv_data; | |
3478 | |||
3479 | 17 | av_freep(&mxf->index_entries); | |
3480 | 17 | av_freep(&mxf->body_partition_offset); | |
3481 | 17 | av_freep(&mxf->timecode_track); | |
3482 | 17 | } | |
3483 | |||
3484 | 1094 | static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, int flush) | |
3485 | { | ||
3486 | 1094 | FFFormatContext *const si = ffformatcontext(s); | |
3487 | 1094 | int i, stream_count = 0; | |
3488 | |||
3489 |
2/2✓ Branch 0 taken 2003 times.
✓ Branch 1 taken 1094 times.
|
3097 | for (i = 0; i < s->nb_streams; i++) |
3490 | 2003 | stream_count += !!ffstream(s->streams[i])->last_in_packet_buffer; | |
3491 | |||
3492 |
6/6✓ Branch 0 taken 972 times.
✓ Branch 1 taken 122 times.
✓ Branch 2 taken 452 times.
✓ Branch 3 taken 520 times.
✓ Branch 4 taken 440 times.
✓ Branch 5 taken 12 times.
|
1094 | if (stream_count && (s->nb_streams == stream_count || flush)) { |
3493 | 532 | PacketListEntry *pktl = si->packet_buffer.head; | |
3494 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 520 times.
|
532 | if (s->nb_streams != stream_count) { |
3495 | 12 | PacketListEntry *last = NULL; | |
3496 | // find last packet in edit unit | ||
3497 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 11 times.
|
25 | while (pktl) { |
3498 |
3/4✓ Branch 0 taken 13 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
|
14 | if (!stream_count || pktl->pkt.stream_index == 0) |
3499 | break; | ||
3500 | // update last packet in packet buffer | ||
3501 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 12 times.
|
13 | if (ffstream(s->streams[pktl->pkt.stream_index])->last_in_packet_buffer != pktl) |
3502 | 1 | ffstream(s->streams[pktl->pkt.stream_index])->last_in_packet_buffer = pktl; | |
3503 | 13 | last = pktl; | |
3504 | 13 | pktl = pktl->next; | |
3505 | 13 | stream_count--; | |
3506 | } | ||
3507 | // purge packet queue | ||
3508 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 12 times.
|
25 | while (pktl) { |
3509 | 13 | PacketListEntry *next = pktl->next; | |
3510 | 13 | av_packet_unref(&pktl->pkt); | |
3511 | 13 | av_freep(&pktl); | |
3512 | 13 | pktl = next; | |
3513 | } | ||
3514 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | if (last) |
3515 | 12 | last->next = NULL; | |
3516 | else { | ||
3517 | ✗ | si->packet_buffer.head = NULL; | |
3518 | ✗ | si->packet_buffer.tail = NULL; | |
3519 | ✗ | goto out; | |
3520 | } | ||
3521 | 12 | pktl = si->packet_buffer.head; | |
3522 | } | ||
3523 | |||
3524 |
2/2✓ Branch 1 taken 345 times.
✓ Branch 2 taken 187 times.
|
532 | if (ffstream(s->streams[pktl->pkt.stream_index])->last_in_packet_buffer == pktl) |
3525 | 345 | ffstream(s->streams[pktl->pkt.stream_index])->last_in_packet_buffer = NULL; | |
3526 | 532 | avpriv_packet_list_get(&si->packet_buffer, out); | |
3527 | 532 | av_log(s, AV_LOG_TRACE, "out st:%d dts:%"PRId64"\n", out->stream_index, out->dts); | |
3528 | 532 | return 1; | |
3529 | } else { | ||
3530 | 562 | out: | |
3531 | 562 | return 0; | |
3532 | } | ||
3533 | } | ||
3534 | |||
3535 | 610 | static int mxf_compare_timestamps(AVFormatContext *s, const AVPacket *next, | |
3536 | const AVPacket *pkt) | ||
3537 | { | ||
3538 | 610 | MXFStreamContext *sc = s->streams[pkt ->stream_index]->priv_data; | |
3539 | 610 | MXFStreamContext *sc2 = s->streams[next->stream_index]->priv_data; | |
3540 | |||
3541 |
2/2✓ Branch 0 taken 420 times.
✓ Branch 1 taken 190 times.
|
1030 | return next->dts > pkt->dts || |
3542 |
4/4✓ Branch 0 taken 224 times.
✓ Branch 1 taken 196 times.
✓ Branch 2 taken 198 times.
✓ Branch 3 taken 26 times.
|
420 | (next->dts == pkt->dts && sc->order < sc2->order); |
3543 | } | ||
3544 | |||
3545 | 1094 | static int mxf_interleave(AVFormatContext *s, AVPacket *pkt, | |
3546 | int flush, int has_packet) | ||
3547 | { | ||
3548 | int ret; | ||
3549 |
2/2✓ Branch 0 taken 545 times.
✓ Branch 1 taken 549 times.
|
1094 | if (has_packet) { |
3550 | 545 | MXFStreamContext *sc = s->streams[pkt->stream_index]->priv_data; | |
3551 | 545 | pkt->pts = pkt->dts = sc->pkt_cnt++; | |
3552 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 545 times.
|
545 | if ((ret = ff_interleave_add_packet(s, pkt, mxf_compare_timestamps)) < 0) |
3553 | ✗ | return ret; | |
3554 | } | ||
3555 | 1094 | return mxf_interleave_get_packet(s, pkt, flush); | |
3556 | } | ||
3557 | |||
3558 | 26 | static int mxf_check_bitstream(AVFormatContext *s, AVStream *st, const AVPacket *pkt) | |
3559 | { | ||
3560 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (st->codecpar->codec_id == AV_CODEC_ID_H264) { |
3561 | ✗ | if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 && | |
3562 | ✗ | AV_RB24(pkt->data) != 0x000001) | |
3563 | ✗ | return ff_stream_add_bitstream_filter(st, "h264_mp4toannexb", NULL); | |
3564 | } | ||
3565 | 26 | return 1; | |
3566 | } | ||
3567 | |||
3568 | #define MXF_COMMON_OPTIONS \ | ||
3569 | { "signal_standard", "Force/set Signal Standard",\ | ||
3570 | offsetof(MXFContext, signal_standard), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\ | ||
3571 | { "bt601", "ITU-R BT.601 and BT.656, also SMPTE 125M (525 and 625 line interlaced)",\ | ||
3572 | 0, AV_OPT_TYPE_CONST, {.i64 = 1}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\ | ||
3573 | { "bt1358", "ITU-R BT.1358 and ITU-R BT.799-3, also SMPTE 293M (525 and 625 line progressive)",\ | ||
3574 | 0, AV_OPT_TYPE_CONST, {.i64 = 2}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\ | ||
3575 | { "smpte347m", "SMPTE 347M (540 Mbps mappings)",\ | ||
3576 | 0, AV_OPT_TYPE_CONST, {.i64 = 3}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\ | ||
3577 | { "smpte274m", "SMPTE 274M (1125 line)",\ | ||
3578 | 0, AV_OPT_TYPE_CONST, {.i64 = 4}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\ | ||
3579 | { "smpte296m", "SMPTE 296M (750 line progressive)",\ | ||
3580 | 0, AV_OPT_TYPE_CONST, {.i64 = 5}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\ | ||
3581 | { "smpte349m", "SMPTE 349M (1485 Mbps mappings)",\ | ||
3582 | 0, AV_OPT_TYPE_CONST, {.i64 = 6}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\ | ||
3583 | { "smpte428", "SMPTE 428-1 DCDM",\ | ||
3584 | 0, AV_OPT_TYPE_CONST, {.i64 = 7}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"}, | ||
3585 | |||
3586 | |||
3587 | |||
3588 | static const AVOption mxf_options[] = { | ||
3589 | MXF_COMMON_OPTIONS | ||
3590 | { "store_user_comments", "", | ||
3591 | offsetof(MXFContext, store_user_comments), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM}, | ||
3592 | { NULL }, | ||
3593 | }; | ||
3594 | |||
3595 | static const AVClass mxf_muxer_class = { | ||
3596 | .class_name = "MXF muxer", | ||
3597 | .item_name = av_default_item_name, | ||
3598 | .option = mxf_options, | ||
3599 | .version = LIBAVUTIL_VERSION_INT, | ||
3600 | }; | ||
3601 | |||
3602 | static const AVOption d10_options[] = { | ||
3603 | { "d10_channelcount", "Force/set channelcount in generic sound essence descriptor", | ||
3604 | offsetof(MXFContext, channel_count), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 8, AV_OPT_FLAG_ENCODING_PARAM}, | ||
3605 | MXF_COMMON_OPTIONS | ||
3606 | { "store_user_comments", "", | ||
3607 | offsetof(MXFContext, store_user_comments), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM}, | ||
3608 | { NULL }, | ||
3609 | }; | ||
3610 | |||
3611 | static const AVClass mxf_d10_muxer_class = { | ||
3612 | .class_name = "MXF-D10 muxer", | ||
3613 | .item_name = av_default_item_name, | ||
3614 | .option = d10_options, | ||
3615 | .version = LIBAVUTIL_VERSION_INT, | ||
3616 | }; | ||
3617 | |||
3618 | static const AVOption opatom_options[] = { | ||
3619 | { "mxf_audio_edit_rate", "Audio edit rate for timecode", | ||
3620 | offsetof(MXFContext, audio_edit_rate), AV_OPT_TYPE_RATIONAL, {.dbl=25}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM }, | ||
3621 | MXF_COMMON_OPTIONS | ||
3622 | { "store_user_comments", "", | ||
3623 | offsetof(MXFContext, store_user_comments), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM}, | ||
3624 | { NULL }, | ||
3625 | }; | ||
3626 | |||
3627 | static const AVClass mxf_opatom_muxer_class = { | ||
3628 | .class_name = "MXF-OPAtom muxer", | ||
3629 | .item_name = av_default_item_name, | ||
3630 | .option = opatom_options, | ||
3631 | .version = LIBAVUTIL_VERSION_INT, | ||
3632 | }; | ||
3633 | |||
3634 | const FFOutputFormat ff_mxf_muxer = { | ||
3635 | .p.name = "mxf", | ||
3636 | .p.long_name = NULL_IF_CONFIG_SMALL("MXF (Material eXchange Format)"), | ||
3637 | .p.mime_type = "application/mxf", | ||
3638 | .p.extensions = "mxf", | ||
3639 | .priv_data_size = sizeof(MXFContext), | ||
3640 | .p.audio_codec = AV_CODEC_ID_PCM_S16LE, | ||
3641 | .p.video_codec = AV_CODEC_ID_MPEG2VIDEO, | ||
3642 | .init = mxf_init, | ||
3643 | .write_packet = mxf_write_packet, | ||
3644 | .write_trailer = mxf_write_footer, | ||
3645 | .deinit = mxf_deinit, | ||
3646 | .p.flags = AVFMT_NOTIMESTAMPS, | ||
3647 | .interleave_packet = mxf_interleave, | ||
3648 | .p.priv_class = &mxf_muxer_class, | ||
3649 | .check_bitstream = mxf_check_bitstream, | ||
3650 | }; | ||
3651 | |||
3652 | const FFOutputFormat ff_mxf_d10_muxer = { | ||
3653 | .p.name = "mxf_d10", | ||
3654 | .p.long_name = NULL_IF_CONFIG_SMALL("MXF (Material eXchange Format) D-10 Mapping"), | ||
3655 | .p.mime_type = "application/mxf", | ||
3656 | .priv_data_size = sizeof(MXFContext), | ||
3657 | .p.audio_codec = AV_CODEC_ID_PCM_S16LE, | ||
3658 | .p.video_codec = AV_CODEC_ID_MPEG2VIDEO, | ||
3659 | .init = mxf_init, | ||
3660 | .write_packet = mxf_write_packet, | ||
3661 | .write_trailer = mxf_write_footer, | ||
3662 | .deinit = mxf_deinit, | ||
3663 | .p.flags = AVFMT_NOTIMESTAMPS, | ||
3664 | .interleave_packet = mxf_interleave, | ||
3665 | .p.priv_class = &mxf_d10_muxer_class, | ||
3666 | }; | ||
3667 | |||
3668 | const FFOutputFormat ff_mxf_opatom_muxer = { | ||
3669 | .p.name = "mxf_opatom", | ||
3670 | .p.long_name = NULL_IF_CONFIG_SMALL("MXF (Material eXchange Format) Operational Pattern Atom"), | ||
3671 | .p.mime_type = "application/mxf", | ||
3672 | .p.extensions = "mxf", | ||
3673 | .priv_data_size = sizeof(MXFContext), | ||
3674 | .p.audio_codec = AV_CODEC_ID_PCM_S16LE, | ||
3675 | .p.video_codec = AV_CODEC_ID_DNXHD, | ||
3676 | .init = mxf_init, | ||
3677 | .write_packet = mxf_write_packet, | ||
3678 | .write_trailer = mxf_write_footer, | ||
3679 | .deinit = mxf_deinit, | ||
3680 | .p.flags = AVFMT_NOTIMESTAMPS, | ||
3681 | .interleave_packet = mxf_interleave, | ||
3682 | .p.priv_class = &mxf_opatom_muxer_class, | ||
3683 | .check_bitstream = mxf_check_bitstream, | ||
3684 | }; | ||
3685 |