annotate mxfenc.c @ 5351:49d4ac4b6516 libavformat

10l, typo
author bcoudurier
date Thu, 05 Nov 2009 08:53:05 +0000
parents 36d130853c9b
children 16a2de6da57e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
1 /*
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
2 * MXF muxer
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
3 * Copyright (c) 2008 GUCAS, Zhentan Feng <spyfeng at gmail dot com>
4325
56f0e5097632 add my copyright as well
bcoudurier
parents: 4324
diff changeset
4 * Copyright (c) 2008 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
5 *
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
6 * This file is part of FFmpeg.
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
7 *
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
12 *
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
16 * Lesser General Public License for more details.
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
17 *
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
21 */
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
22
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
23 /*
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
24 * References
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
25 * SMPTE 336M KLV Data Encoding Protocol Using Key-Length-Value
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
26 * SMPTE 377M MXF File Format Specifications
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
27 * SMPTE 379M MXF Generic Container
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
28 * SMPTE 381M Mapping MPEG Streams into the MXF Generic Container
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
29 * SMPTE RP210: SMPTE Metadata Dictionary
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
30 * SMPTE RP224: Registry of SMPTE Universal Labels
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
31 */
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
32
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
33 //#define DEBUG
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
34
4363
8142fb82cd75 be more flexible with frame rate check
bcoudurier
parents: 4351
diff changeset
35 #include <math.h>
4385
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
36 #include <time.h>
4363
8142fb82cd75 be more flexible with frame rate check
bcoudurier
parents: 4351
diff changeset
37
4696
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
38 #include "libavutil/random_seed.h"
4403
39f6b190c772 remove implicit header inclusions from mxf.h
bcoudurier
parents: 4402
diff changeset
39 #include "libavcodec/bytestream.h"
4400
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents: 4397
diff changeset
40 #include "audiointerleave.h"
4403
39f6b190c772 remove implicit header inclusions from mxf.h
bcoudurier
parents: 4402
diff changeset
41 #include "avformat.h"
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
42 #include "mxf.h"
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
43
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
44 static const int NTSC_samples_per_frame[] = { 1602, 1601, 1602, 1601, 1602, 0 };
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
45 static const int PAL_samples_per_frame[] = { 1920, 0 };
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
46
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
47 AVOutputFormat mxf_d10_muxer;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
48
4440
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
49 #define EDIT_UNITS_PER_BODY 250
4393
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
50 #define KAG_SIZE 512
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
51
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
52 typedef struct {
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
53 int local_tag;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
54 UID uid;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
55 } MXFLocalTagPair;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
56
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
57 typedef struct {
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
58 uint8_t flags;
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
59 uint64_t offset;
4407
b6b31de76359 fix doxygen
bcoudurier
parents: 4404
diff changeset
60 unsigned slice_offset; ///< offset of audio slice
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
61 } MXFIndexEntry;
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
62
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
63 typedef struct {
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
64 AudioInterleaveContext aic;
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
65 UID track_essence_element_key;
5081
56f6b1d56db9 cosmetics, change case and comments alignment
bcoudurier
parents: 5080
diff changeset
66 int index; ///< index in mxf_essence_container_uls table
3833
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
67 const UID *codec_ul;
5081
56f6b1d56db9 cosmetics, change case and comments alignment
bcoudurier
parents: 5080
diff changeset
68 int order; ///< interleaving order if dts are equal
56f6b1d56db9 cosmetics, change case and comments alignment
bcoudurier
parents: 5080
diff changeset
69 int interlaced; ///< wether picture is interlaced
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
70 int temporal_reordering;
4505
da04428a94db fetch display aspect ratio from mpeg-2 essence
bcoudurier
parents: 4504
diff changeset
71 AVRational aspect_ratio; ///< display aspect ratio
5080
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
72 int closed_gop; ///< gop is closed, used in mpeg-2 frame parsing
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
73 } MXFStreamContext;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
74
3826
da2d0c162cde introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents: 3825
diff changeset
75 typedef struct {
da2d0c162cde introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents: 3825
diff changeset
76 UID container_ul;
da2d0c162cde introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents: 3825
diff changeset
77 UID element_ul;
3833
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
78 UID codec_ul;
3845
c266530d56b4 merge descriptor write table with essence container uls table and simplify
bcoudurier
parents: 3844
diff changeset
79 void (*write_desc)();
3847
b104a66d828e cosmetics, Pair -> Entry
bcoudurier
parents: 3846
diff changeset
80 } MXFContainerEssenceEntry;
3826
da2d0c162cde introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents: 3825
diff changeset
81
4345
8e3538adb529 more flexible mapping selection
bcoudurier
parents: 4344
diff changeset
82 static const struct {
8e3538adb529 more flexible mapping selection
bcoudurier
parents: 4344
diff changeset
83 enum CodecID id;
8e3538adb529 more flexible mapping selection
bcoudurier
parents: 4344
diff changeset
84 int index;
8e3538adb529 more flexible mapping selection
bcoudurier
parents: 4344
diff changeset
85 } mxf_essence_mappings[] = {
8e3538adb529 more flexible mapping selection
bcoudurier
parents: 4344
diff changeset
86 { CODEC_ID_MPEG2VIDEO, 0 },
4346
0a142b4b841e 24bit pcm support
bcoudurier
parents: 4345
diff changeset
87 { CODEC_ID_PCM_S24LE, 1 },
4345
8e3538adb529 more flexible mapping selection
bcoudurier
parents: 4344
diff changeset
88 { CODEC_ID_PCM_S16LE, 1 },
8e3538adb529 more flexible mapping selection
bcoudurier
parents: 4344
diff changeset
89 { 0 }
8e3538adb529 more flexible mapping selection
bcoudurier
parents: 4344
diff changeset
90 };
8e3538adb529 more flexible mapping selection
bcoudurier
parents: 4344
diff changeset
91
3845
c266530d56b4 merge descriptor write table with essence container uls table and simplify
bcoudurier
parents: 3844
diff changeset
92 static void mxf_write_wav_desc(AVFormatContext *s, AVStream *st);
4320
3524125567f3 add aes3 pcm wrapping and use it by default
bcoudurier
parents: 4319
diff changeset
93 static void mxf_write_aes3_desc(AVFormatContext *s, AVStream *st);
3845
c266530d56b4 merge descriptor write table with essence container uls table and simplify
bcoudurier
parents: 3844
diff changeset
94 static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st);
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
95 static void mxf_write_cdci_desc(AVFormatContext *s, AVStream *st);
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
96 static void mxf_write_generic_sound_desc(AVFormatContext *s, AVStream *st);
3845
c266530d56b4 merge descriptor write table with essence container uls table and simplify
bcoudurier
parents: 3844
diff changeset
97
3847
b104a66d828e cosmetics, Pair -> Entry
bcoudurier
parents: 3846
diff changeset
98 static const MXFContainerEssenceEntry mxf_essence_container_uls[] = {
3826
da2d0c162cde introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents: 3825
diff changeset
99 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 },
3833
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
100 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 },
3845
c266530d56b4 merge descriptor write table with essence container uls table and simplify
bcoudurier
parents: 3844
diff changeset
101 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x00,0x00,0x00 },
4345
8e3538adb529 more flexible mapping selection
bcoudurier
parents: 4344
diff changeset
102 mxf_write_mpegvideo_desc },
4320
3524125567f3 add aes3 pcm wrapping and use it by default
bcoudurier
parents: 4319
diff changeset
103 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x03,0x00 },
3524125567f3 add aes3 pcm wrapping and use it by default
bcoudurier
parents: 4319
diff changeset
104 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x16,0x01,0x03,0x00 },
3524125567f3 add aes3 pcm wrapping and use it by default
bcoudurier
parents: 4319
diff changeset
105 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
4345
8e3538adb529 more flexible mapping selection
bcoudurier
parents: 4344
diff changeset
106 mxf_write_aes3_desc },
3826
da2d0c162cde introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents: 3825
diff changeset
107 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x01,0x00 },
3833
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
108 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x16,0x01,0x01,0x00 },
3845
c266530d56b4 merge descriptor write table with essence container uls table and simplify
bcoudurier
parents: 3844
diff changeset
109 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
4345
8e3538adb529 more flexible mapping selection
bcoudurier
parents: 4344
diff changeset
110 mxf_write_wav_desc },
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
111 // D-10 625/50 PAL 50mb/s
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
112 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
113 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
114 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x01 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
115 mxf_write_cdci_desc },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
116 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
117 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
118 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
119 mxf_write_generic_sound_desc },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
120 // D-10 525/60 NTSC 50mb/s
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
121 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x02,0x01 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
122 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
123 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x02 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
124 mxf_write_cdci_desc },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
125 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x02,0x01 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
126 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
127 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
128 mxf_write_generic_sound_desc },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
129 // D-10 625/50 PAL 40mb/s
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
130 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x03,0x01 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
131 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
132 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x03 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
133 mxf_write_cdci_desc },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
134 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x03,0x01 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
135 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
136 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
137 mxf_write_generic_sound_desc },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
138 // D-10 525/60 NTSC 40mb/s
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
139 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x04,0x01 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
140 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
141 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x04 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
142 mxf_write_cdci_desc },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
143 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x04,0x01 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
144 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
145 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
146 mxf_write_generic_sound_desc },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
147 // D-10 625/50 PAL 30mb/s
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
148 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x05,0x01 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
149 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
150 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x05 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
151 mxf_write_cdci_desc },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
152 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x05,0x01 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
153 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
154 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
155 mxf_write_generic_sound_desc },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
156 // D-10 525/60 NTSC 30mb/s
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
157 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x06,0x01 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
158 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
159 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x06 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
160 mxf_write_cdci_desc },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
161 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x06,0x01 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
162 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
163 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
164 mxf_write_generic_sound_desc },
3826
da2d0c162cde introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents: 3825
diff changeset
165 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
3833
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
166 { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
3845
c266530d56b4 merge descriptor write table with essence container uls table and simplify
bcoudurier
parents: 3844
diff changeset
167 { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
4345
8e3538adb529 more flexible mapping selection
bcoudurier
parents: 4344
diff changeset
168 NULL },
3826
da2d0c162cde introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents: 3825
diff changeset
169 };
da2d0c162cde introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents: 3825
diff changeset
170
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
171 typedef struct MXFContext {
3842
c4e0e02a4832 simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents: 3841
diff changeset
172 int64_t footer_partition_offset;
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
173 int essence_container_count;
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
174 AVRational time_base;
4313
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
175 int header_written;
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
176 MXFIndexEntry *index_entries;
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
177 unsigned edit_units_count;
4385
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
178 uint64_t timestamp; ///< timestamp, as year(16),month(8),day(8),hour(8),minutes(8),msec/4(8)
4407
b6b31de76359 fix doxygen
bcoudurier
parents: 4404
diff changeset
179 uint8_t slice_count; ///< index slice count minus 1 (1 if no audio, 0 otherwise)
4440
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
180 int last_indexed_edit_unit;
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
181 uint64_t *body_partition_offset;
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
182 unsigned body_partitions_count;
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
183 int last_key_index; ///< index of last key frame
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
184 uint64_t duration;
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
185 AVStream *timecode_track;
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
186 int timecode_base; ///< rounded time code base (25 or 30)
4449
aaae79b414f3 parse mpeg2 gop header time code and use it
bcoudurier
parents: 4448
diff changeset
187 int timecode_start; ///< frame number computed from mpeg-2 gop header timecode
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
188 int timecode_drop_frame; ///< time code use drop frame method frop mpeg-2 essence gop header
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
189 int edit_unit_byte_count; ///< fixed edit unit byte count
4481
27fd3af46000 compute body offset and index entry offset correctly
bcoudurier
parents: 4478
diff changeset
190 uint64_t body_offset;
4696
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
191 uint32_t instance_number;
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
192 uint8_t umid[16]; ///< unique material identifier
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
193 } MXFContext;
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
194
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
195 static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd };
4696
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
196 static const uint8_t umid_ul[] = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x01,0x0D,0x00,0x13 };
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
197
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
198 /**
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
199 * complete key for operation pattern, partitions, and primer pack
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
200 */
4536
b94bedbb59d7 always use multi track since timecode track is present
bcoudurier
parents: 4535
diff changeset
201 static const uint8_t op1a_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x01,0x09,0x00 };
4351
e9b7237e3f3d cosmetics: whitespaces, empty lines
bcoudurier
parents: 4350
diff changeset
202 static const uint8_t footer_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x04,0x04,0x00 }; // ClosedComplete
e9b7237e3f3d cosmetics: whitespaces, empty lines
bcoudurier
parents: 4350
diff changeset
203 static const uint8_t primer_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x05,0x01,0x00 };
e9b7237e3f3d cosmetics: whitespaces, empty lines
bcoudurier
parents: 4350
diff changeset
204 static const uint8_t index_table_segment_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x10,0x01,0x00 };
e9b7237e3f3d cosmetics: whitespaces, empty lines
bcoudurier
parents: 4350
diff changeset
205 static const uint8_t random_index_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x11,0x01,0x00 };
3839
2b1b25134815 header partition is open incomplete for now
bcoudurier
parents: 3838
diff changeset
206 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
2b1b25134815 header partition is open incomplete for now
bcoudurier
parents: 3838
diff changeset
207 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
4393
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
208 static const uint8_t klv_fill_key[] = { 0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x03,0x01,0x02,0x10,0x01,0x00,0x00,0x00 };
4440
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
209 static const uint8_t body_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x03,0x04,0x00 }; // ClosedComplete
3839
2b1b25134815 header partition is open incomplete for now
bcoudurier
parents: 3838
diff changeset
210
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
211 /**
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
212 * partial key for header metadata
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
213 */
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
214 static const uint8_t header_metadata_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01 };
4351
e9b7237e3f3d cosmetics: whitespaces, empty lines
bcoudurier
parents: 4350
diff changeset
215 static const uint8_t multiple_desc_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x0D,0x01,0x03,0x01,0x02,0x7F,0x01,0x00 };
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
216
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
217 /**
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
218 * SMPTE RP210 http://www.smpte-ra.org/mdd/index.html
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
219 */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
220 static const MXFLocalTagPair mxf_local_tag_batch[] = {
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
221 // preface set
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
222 { 0x3C0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x15,0x02,0x00,0x00,0x00,0x00}}, /* Instance UID */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
223 { 0x3B02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x04,0x00,0x00}}, /* Last Modified Date */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
224 { 0x3B05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x01,0x05,0x00,0x00,0x00}}, /* Version */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
225 { 0x3B06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x04,0x00,0x00}}, /* Identifications reference */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
226 { 0x3B03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x01,0x00,0x00}}, /* Content Storage reference */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
227 { 0x3B09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x03,0x00,0x00,0x00,0x00}}, /* Operational Pattern UL */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
228 { 0x3B0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x10,0x02,0x01,0x00,0x00}}, /* Essence Containers UL batch */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
229 { 0x3B0B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x10,0x02,0x02,0x00,0x00}}, /* DM Schemes UL batch */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
230 // Identification
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
231 { 0x3C09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x01,0x00,0x00,0x00}}, /* This Generation UID */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
232 { 0x3C01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x02,0x01,0x00,0x00}}, /* Company Name */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
233 { 0x3C02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x03,0x01,0x00,0x00}}, /* Product Name */
3792
a6d4e93e171b fix version string ul
bcoudurier
parents: 3780
diff changeset
234 { 0x3C04, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x05,0x01,0x00,0x00}}, /* Version String */
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
235 { 0x3C05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x07,0x00,0x00,0x00}}, /* Product ID */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
236 { 0x3C06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x03,0x00,0x00}}, /* Modification Date */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
237 // Content Storage
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
238 { 0x1901, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x05,0x01,0x00,0x00}}, /* Package strong reference batch */
4279
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
239 { 0x1902, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x05,0x02,0x00,0x00}}, /* Package strong reference batch */
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
240 // Essence Container Data
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
241 { 0x2701, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x06,0x01,0x00,0x00,0x00}}, /* Linked Package UID */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
242 { 0x3F07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x01,0x03,0x04,0x04,0x00,0x00,0x00,0x00}}, /* BodySID */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
243 // Package
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
244 { 0x4401, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x15,0x10,0x00,0x00,0x00,0x00}}, /* Package UID */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
245 { 0x4405, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x01,0x03,0x00,0x00}}, /* Package Creation Date */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
246 { 0x4404, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x05,0x00,0x00}}, /* Package Modified Date */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
247 { 0x4403, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x05,0x00,0x00}}, /* Tracks Strong reference array */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
248 { 0x4701, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x03,0x00,0x00}}, /* Descriptor */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
249 // Track
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
250 { 0x4801, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x01,0x07,0x01,0x01,0x00,0x00,0x00,0x00}}, /* Track ID */
3827
e206d10f28db fix track number ul in primer pack
bcoudurier
parents: 3826
diff changeset
251 { 0x4804, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x01,0x04,0x01,0x03,0x00,0x00,0x00,0x00}}, /* Track Number */
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
252 { 0x4B01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x30,0x04,0x05,0x00,0x00,0x00,0x00}}, /* Edit Rate */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
253 { 0x4B02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x03,0x00,0x00}}, /* Origin */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
254 { 0x4803, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x04,0x00,0x00}}, /* Sequence reference */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
255 // Sequence
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
256 { 0x0201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x07,0x01,0x00,0x00,0x00,0x00,0x00}}, /* Data Definition UL */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
257 { 0x0202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x02,0x01,0x01,0x03,0x00,0x00}}, /* Duration */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
258 { 0x1001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x09,0x00,0x00}}, /* Structural Components reference array */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
259 // Source Clip
4431
723d05287ae9 fix primer pack local tags uls
bcoudurier
parents: 4430
diff changeset
260 { 0x1201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x04,0x00,0x00}}, /* Start position */
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
261 { 0x1101, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x03,0x01,0x00,0x00,0x00}}, /* SourcePackageID */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
262 { 0x1102, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x03,0x02,0x00,0x00,0x00}}, /* SourceTrackID */
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
263 // Timecode Component
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
264 { 0x1501, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x05,0x00,0x00}}, /* Start Time Code */
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
265 { 0x1502, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x04,0x01,0x01,0x02,0x06,0x00,0x00}}, /* Rounded Time Code Base */
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
266 { 0x1503, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x04,0x01,0x01,0x05,0x00,0x00,0x00}}, /* Drop Frame */
3794
137c5f8c36d5 cosmetics, typos, case
bcoudurier
parents: 3793
diff changeset
267 // File Descriptor
137c5f8c36d5 cosmetics, typos, case
bcoudurier
parents: 3793
diff changeset
268 { 0x3F01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x06,0x01,0x01,0x04,0x06,0x0B,0x00,0x00}}, /* Sub Descriptors reference array */
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
269 { 0x3006, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x06,0x01,0x01,0x03,0x05,0x00,0x00,0x00}}, /* Linked Track ID */
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
270 { 0x3001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x06,0x01,0x01,0x00,0x00,0x00,0x00}}, /* SampleRate */
3794
137c5f8c36d5 cosmetics, typos, case
bcoudurier
parents: 3793
diff changeset
271 { 0x3004, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x01,0x02,0x00,0x00}}, /* Essence Container */
137c5f8c36d5 cosmetics, typos, case
bcoudurier
parents: 3793
diff changeset
272 // Generic Picture Essence Descriptor
4321
68de70aa392b add frame layout local tag, best effort
bcoudurier
parents: 4320
diff changeset
273 { 0x320C, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x03,0x01,0x04,0x00,0x00,0x00}}, /* Frame Layout */
4431
723d05287ae9 fix primer pack local tags uls
bcoudurier
parents: 4430
diff changeset
274 { 0x320D, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x02,0x05,0x00,0x00,0x00}}, /* Video Line Map */
3794
137c5f8c36d5 cosmetics, typos, case
bcoudurier
parents: 3793
diff changeset
275 { 0x3203, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x02,0x00,0x00,0x00}}, /* Stored Width */
137c5f8c36d5 cosmetics, typos, case
bcoudurier
parents: 3793
diff changeset
276 { 0x3202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x01,0x00,0x00,0x00}}, /* Stored Height */
4335
e6fb8644af02 write display height/width tags
bcoudurier
parents: 4330
diff changeset
277 { 0x3209, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0C,0x00,0x00,0x00}}, /* Display Width */
e6fb8644af02 write display height/width tags
bcoudurier
parents: 4330
diff changeset
278 { 0x3208, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0B,0x00,0x00,0x00}}, /* Display Height */
3794
137c5f8c36d5 cosmetics, typos, case
bcoudurier
parents: 3793
diff changeset
279 { 0x320E, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x00,0x00,0x00}}, /* Aspect Ratio */
137c5f8c36d5 cosmetics, typos, case
bcoudurier
parents: 3793
diff changeset
280 { 0x3201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x06,0x01,0x00,0x00,0x00,0x00}}, /* Picture Essence Coding */
4434
a75d42745d16 write component depth and horizontal subsampling best effort local tags
bcoudurier
parents: 4433
diff changeset
281 // CDCI Picture Essence Descriptor
a75d42745d16 write component depth and horizontal subsampling best effort local tags
bcoudurier
parents: 4433
diff changeset
282 { 0x3301, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x03,0x0A,0x00,0x00,0x00}}, /* Component Depth */
a75d42745d16 write component depth and horizontal subsampling best effort local tags
bcoudurier
parents: 4433
diff changeset
283 { 0x3302, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x05,0x00,0x00,0x00}}, /* Horizontal Subsampling */
3794
137c5f8c36d5 cosmetics, typos, case
bcoudurier
parents: 3793
diff changeset
284 // Generic Sound Essence Descriptor
4431
723d05287ae9 fix primer pack local tags uls
bcoudurier
parents: 4430
diff changeset
285 { 0x3D02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x01,0x04,0x00,0x00,0x00}}, /* Locked/Unlocked */
3794
137c5f8c36d5 cosmetics, typos, case
bcoudurier
parents: 3793
diff changeset
286 { 0x3D03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x01,0x01,0x01,0x00,0x00}}, /* Audio sampling rate */
137c5f8c36d5 cosmetics, typos, case
bcoudurier
parents: 3793
diff changeset
287 { 0x3D07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x01,0x01,0x04,0x00,0x00,0x00}}, /* ChannelCount */
137c5f8c36d5 cosmetics, typos, case
bcoudurier
parents: 3793
diff changeset
288 { 0x3D01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x03,0x04,0x00,0x00,0x00}}, /* Quantization bits */
4011
eeb2b9dd42ea fix sound essence compression UL
bcoudurier
parents: 4010
diff changeset
289 { 0x3D06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x02,0x04,0x02,0x00,0x00,0x00,0x00}}, /* Sound Essence Compression */
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
290 // Index Table Segment
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
291 { 0x3F0B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x05,0x30,0x04,0x06,0x00,0x00,0x00,0x00}}, /* Index Edit Rate */
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
292 { 0x3F0C, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x07,0x02,0x01,0x03,0x01,0x0A,0x00,0x00}}, /* Index Start Position */
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
293 { 0x3F0D, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x07,0x02,0x02,0x01,0x01,0x02,0x00,0x00}}, /* Index Duration */
4431
723d05287ae9 fix primer pack local tags uls
bcoudurier
parents: 4430
diff changeset
294 { 0x3F05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x06,0x02,0x01,0x00,0x00,0x00,0x00}}, /* Edit Unit Byte Count */
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
295 { 0x3F06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x01,0x03,0x04,0x05,0x00,0x00,0x00,0x00}}, /* IndexSID */
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
296 { 0x3F08, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x04,0x04,0x01,0x01,0x00,0x00,0x00}}, /* Slice Count */
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
297 { 0x3F09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x01,0x06,0x00,0x00,0x00}}, /* Delta Entry Array */
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
298 { 0x3F0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x02,0x05,0x00,0x00,0x00}}, /* Index Entry Array */
4336
87455a164f2b write bitrate tag
bcoudurier
parents: 4335
diff changeset
299 // MPEG video Descriptor
87455a164f2b write bitrate tag
bcoudurier
parents: 4335
diff changeset
300 { 0x8000, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0B,0x00,0x00}}, /* BitRate */
5090
f2671cc3467c write profile and level local tag in mpeg descriptor
bcoudurier
parents: 5081
diff changeset
301 { 0x8007, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0A,0x00,0x00}}, /* ProfileAndLevel */
4339
eaecbe63bcc5 write req local tags for wav
bcoudurier
parents: 4338
diff changeset
302 // Wave Audio Essence Descriptor
eaecbe63bcc5 write req local tags for wav
bcoudurier
parents: 4338
diff changeset
303 { 0x3D09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x03,0x05,0x00,0x00,0x00}}, /* Average Bytes Per Second */
eaecbe63bcc5 write req local tags for wav
bcoudurier
parents: 4338
diff changeset
304 { 0x3D0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Block Align */
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
305 };
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
306
3844
b597c00051a6 fix type in prototype
bcoudurier
parents: 3843
diff changeset
307 static void mxf_write_uuid(ByteIOContext *pb, enum MXFMetadataSetType type, int value)
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
308 {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
309 put_buffer(pb, uuid_base, 12);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
310 put_be16(pb, type);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
311 put_be16(pb, value);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
312 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
313
4696
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
314 static void mxf_write_umid(AVFormatContext *s, int type)
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
315 {
4696
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
316 MXFContext *mxf = s->priv_data;
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
317 put_buffer(s->pb, umid_ul, 13);
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
318 put_be24(s->pb, mxf->instance_number);
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
319 put_buffer(s->pb, mxf->umid, 15);
4697
ca6a35b5c915 again 10l, typo, put_byte instead of put_buffer
bcoudurier
parents: 4696
diff changeset
320 put_byte(s->pb, type);
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
321 }
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
322
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
323 static void mxf_write_refs_count(ByteIOContext *pb, int ref_count)
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
324 {
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
325 put_be32(pb, ref_count);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
326 put_be32(pb, 16);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
327 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
328
4393
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
329 static int klv_ber_length(uint64_t len)
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
330 {
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
331 if (len < 128)
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
332 return 1;
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
333 else
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
334 return (av_log2(len) >> 3) + 2;
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
335 }
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
336
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
337 static int klv_encode_ber_length(ByteIOContext *pb, uint64_t len)
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
338 {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
339 // Determine the best BER size
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
340 int size;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
341 if (len < 128) {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
342 //short form
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
343 put_byte(pb, len);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
344 return 1;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
345 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
346
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
347 size = (av_log2(len) >> 3) + 1;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
348
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
349 // long form
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
350 put_byte(pb, 0x80 + size);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
351 while(size) {
4351
e9b7237e3f3d cosmetics: whitespaces, empty lines
bcoudurier
parents: 4350
diff changeset
352 size--;
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
353 put_byte(pb, len >> 8 * size & 0xff);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
354 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
355 return 0;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
356 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
357
4469
49cf858ac430 encode klv fill item length in fixed ber 4 bytes
bcoudurier
parents: 4461
diff changeset
358 static void klv_encode_ber4_length(ByteIOContext *pb, int len)
49cf858ac430 encode klv fill item length in fixed ber 4 bytes
bcoudurier
parents: 4461
diff changeset
359 {
49cf858ac430 encode klv fill item length in fixed ber 4 bytes
bcoudurier
parents: 4461
diff changeset
360 put_byte(pb, 0x80 + 3);
49cf858ac430 encode klv fill item length in fixed ber 4 bytes
bcoudurier
parents: 4461
diff changeset
361 put_be24(pb, len);
49cf858ac430 encode klv fill item length in fixed ber 4 bytes
bcoudurier
parents: 4461
diff changeset
362 }
49cf858ac430 encode klv fill item length in fixed ber 4 bytes
bcoudurier
parents: 4461
diff changeset
363
3818
ae0d01b63679 compute essence containers in mxf_write_header, this simplifies the code
bcoudurier
parents: 3817
diff changeset
364 /*
3846
0ee95f0b4c00 store index in table in MXFStreamContext, simplify
bcoudurier
parents: 3845
diff changeset
365 * Get essence container ul index
3818
ae0d01b63679 compute essence containers in mxf_write_header, this simplifies the code
bcoudurier
parents: 3817
diff changeset
366 */
3846
0ee95f0b4c00 store index in table in MXFStreamContext, simplify
bcoudurier
parents: 3845
diff changeset
367 static int mxf_get_essence_container_ul_index(enum CodecID id)
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
368 {
3846
0ee95f0b4c00 store index in table in MXFStreamContext, simplify
bcoudurier
parents: 3845
diff changeset
369 int i;
4345
8e3538adb529 more flexible mapping selection
bcoudurier
parents: 4344
diff changeset
370 for (i = 0; mxf_essence_mappings[i].id; i++)
8e3538adb529 more flexible mapping selection
bcoudurier
parents: 4344
diff changeset
371 if (mxf_essence_mappings[i].id == id)
8e3538adb529 more flexible mapping selection
bcoudurier
parents: 4344
diff changeset
372 return mxf_essence_mappings[i].index;
3846
0ee95f0b4c00 store index in table in MXFStreamContext, simplify
bcoudurier
parents: 3845
diff changeset
373 return -1;
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
374 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
375
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
376 static void mxf_write_primer_pack(AVFormatContext *s)
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
377 {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
378 ByteIOContext *pb = s->pb;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
379 int local_tag_number, i = 0;
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
380
4001
fcb9de59245f uses FF_ARRAY_ELEMS() where appropriate
aurel
parents: 3908
diff changeset
381 local_tag_number = FF_ARRAY_ELEMS(mxf_local_tag_batch);
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
382
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
383 put_buffer(pb, primer_pack_key, 16);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
384 klv_encode_ber_length(pb, local_tag_number * 18 + 8);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
385
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
386 put_be32(pb, local_tag_number); // local_tag num
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
387 put_be32(pb, 18); // item size, always 18 according to the specs
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
388
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
389 for (i = 0; i < local_tag_number; i++) {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
390 put_be16(pb, mxf_local_tag_batch[i].local_tag);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
391 put_buffer(pb, mxf_local_tag_batch[i].uid, 16);
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
392 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
393 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
394
3815
af8d6067206e rename variable
bcoudurier
parents: 3814
diff changeset
395 static void mxf_write_local_tag(ByteIOContext *pb, int size, int tag)
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
396 {
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
397 put_be16(pb, tag);
3815
af8d6067206e rename variable
bcoudurier
parents: 3814
diff changeset
398 put_be16(pb, size);
3735
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
399 }
75fd6b0b1356 Ok-ed parts from patch by zhentan feng.
michael
parents: 3721
diff changeset
400
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
401 static void mxf_write_metadata_key(ByteIOContext *pb, unsigned int value)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
402 {
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
403 put_buffer(pb, header_metadata_key, 13);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
404 put_be24(pb, value);
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
405 }
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
406
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
407 static void mxf_free(AVFormatContext *s)
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
408 {
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
409 int i;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
410
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
411 for (i = 0; i < s->nb_streams; i++) {
3823
42ed5e2f1b4b merge declaration and init
bcoudurier
parents: 3822
diff changeset
412 AVStream *st = s->streams[i];
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
413 av_freep(&st->priv_data);
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
414 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
415 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
416
4404
7cf3b77ad6ff reuse MXFCodecUL for data def and simplify
bcoudurier
parents: 4403
diff changeset
417 static const MXFCodecUL *mxf_get_data_definition_ul(int type)
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
418 {
4404
7cf3b77ad6ff reuse MXFCodecUL for data def and simplify
bcoudurier
parents: 4403
diff changeset
419 const MXFCodecUL *uls = ff_mxf_data_definition_uls;
7cf3b77ad6ff reuse MXFCodecUL for data def and simplify
bcoudurier
parents: 4403
diff changeset
420 while (uls->uid[0]) {
7cf3b77ad6ff reuse MXFCodecUL for data def and simplify
bcoudurier
parents: 4403
diff changeset
421 if (type == uls->id)
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
422 break;
3812
1db39c874eb7 cosmetics, remove useless braces, move comments where appropriate, remove whitespaces
bcoudurier
parents: 3811
diff changeset
423 uls++;
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
424 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
425 return uls;
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
426 }
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
427
3821
7a1f6dd123a9 simplify mxf_write_essence_container_refs
bcoudurier
parents: 3820
diff changeset
428 static void mxf_write_essence_container_refs(AVFormatContext *s)
3780
261cd3e672e5 Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents: 3778
diff changeset
429 {
3818
ae0d01b63679 compute essence containers in mxf_write_header, this simplifies the code
bcoudurier
parents: 3817
diff changeset
430 MXFContext *c = s->priv_data;
3780
261cd3e672e5 Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents: 3778
diff changeset
431 ByteIOContext *pb = s->pb;
3818
ae0d01b63679 compute essence containers in mxf_write_header, this simplifies the code
bcoudurier
parents: 3817
diff changeset
432 int i;
3780
261cd3e672e5 Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents: 3778
diff changeset
433
3822
be33feb6984f reindent
bcoudurier
parents: 3821
diff changeset
434 mxf_write_refs_count(pb, c->essence_container_count);
be33feb6984f reindent
bcoudurier
parents: 3821
diff changeset
435 av_log(s,AV_LOG_DEBUG, "essence container count:%d\n", c->essence_container_count);
be33feb6984f reindent
bcoudurier
parents: 3821
diff changeset
436 for (i = 0; i < c->essence_container_count; i++) {
4475
fc3806848a49 simplify
bcoudurier
parents: 4474
diff changeset
437 MXFStreamContext *sc = s->streams[i]->priv_data;
fc3806848a49 simplify
bcoudurier
parents: 4474
diff changeset
438 put_buffer(pb, mxf_essence_container_uls[sc->index].container_ul, 16);
3822
be33feb6984f reindent
bcoudurier
parents: 3821
diff changeset
439 }
3780
261cd3e672e5 Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents: 3778
diff changeset
440 }
261cd3e672e5 Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents: 3778
diff changeset
441
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
442 static void mxf_write_preface(AVFormatContext *s)
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
443 {
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
444 MXFContext *mxf = s->priv_data;
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
445 ByteIOContext *pb = s->pb;
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
446
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
447 mxf_write_metadata_key(pb, 0x012f00);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
448 PRINT_KEY(s, "preface key", pb->buf_ptr - 16);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
449 klv_encode_ber_length(pb, 130 + 16 * mxf->essence_container_count);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
450
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
451 // write preface set uid
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
452 mxf_write_local_tag(pb, 16, 0x3C0A);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
453 mxf_write_uuid(pb, Preface, 0);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
454 PRINT_KEY(s, "preface uid", pb->buf_ptr - 16);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
455
4385
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
456 // last modified date
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
457 mxf_write_local_tag(pb, 8, 0x3B02);
4385
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
458 put_be64(pb, mxf->timestamp);
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
459
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
460 // write version
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
461 mxf_write_local_tag(pb, 2, 0x3B05);
4535
be04cfe425ed fix preface version
bcoudurier
parents: 4533
diff changeset
462 put_be16(pb, 258); // v1.2
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
463
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
464 // write identification_refs
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
465 mxf_write_local_tag(pb, 16 + 8, 0x3B06);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
466 mxf_write_refs_count(pb, 1);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
467 mxf_write_uuid(pb, Identification, 0);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
468
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
469 // write content_storage_refs
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
470 mxf_write_local_tag(pb, 16, 0x3B03);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
471 mxf_write_uuid(pb, ContentStorage, 0);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
472
4430
d6fe53c5c8d2 correctly set multi track operational pattern
bcoudurier
parents: 4426
diff changeset
473 // operational pattern
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
474 mxf_write_local_tag(pb, 16, 0x3B09);
4536
b94bedbb59d7 always use multi track since timecode track is present
bcoudurier
parents: 4535
diff changeset
475 put_buffer(pb, op1a_ul, 16);
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
476
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
477 // write essence_container_refs
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
478 mxf_write_local_tag(pb, 8 + 16 * mxf->essence_container_count, 0x3B0A);
3821
7a1f6dd123a9 simplify mxf_write_essence_container_refs
bcoudurier
parents: 3820
diff changeset
479 mxf_write_essence_container_refs(s);
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
480
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
481 // write dm_scheme_refs
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
482 mxf_write_local_tag(pb, 8, 0x3B0B);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
483 put_be64(pb, 0);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
484 }
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
485
3804
9a7f26d3b75c write strings as utf16be
bcoudurier
parents: 3794
diff changeset
486 /*
3806
fa043e93fc66 introduce mxf_write_local_tag_utf16 and factorize
bcoudurier
parents: 3805
diff changeset
487 * Write a local tag containing an ascii string as utf-16
3804
9a7f26d3b75c write strings as utf16be
bcoudurier
parents: 3794
diff changeset
488 */
3806
fa043e93fc66 introduce mxf_write_local_tag_utf16 and factorize
bcoudurier
parents: 3805
diff changeset
489 static void mxf_write_local_tag_utf16(ByteIOContext *pb, int tag, const char *value)
3804
9a7f26d3b75c write strings as utf16be
bcoudurier
parents: 3794
diff changeset
490 {
3805
d8a6432c76f3 use strlen and do not write useless trailing 0 according to specs
bcoudurier
parents: 3804
diff changeset
491 int i, size = strlen(value);
3806
fa043e93fc66 introduce mxf_write_local_tag_utf16 and factorize
bcoudurier
parents: 3805
diff changeset
492 mxf_write_local_tag(pb, size*2, tag);
3804
9a7f26d3b75c write strings as utf16be
bcoudurier
parents: 3794
diff changeset
493 for (i = 0; i < size; i++)
9a7f26d3b75c write strings as utf16be
bcoudurier
parents: 3794
diff changeset
494 put_be16(pb, value[i]);
9a7f26d3b75c write strings as utf16be
bcoudurier
parents: 3794
diff changeset
495 }
9a7f26d3b75c write strings as utf16be
bcoudurier
parents: 3794
diff changeset
496
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
497 static void mxf_write_identification(AVFormatContext *s)
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
498 {
4385
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
499 MXFContext *mxf = s->priv_data;
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
500 ByteIOContext *pb = s->pb;
3810
297ad1d4d4d6 simplify, and factorize
bcoudurier
parents: 3809
diff changeset
501 const char *company = "FFmpeg";
297ad1d4d4d6 simplify, and factorize
bcoudurier
parents: 3809
diff changeset
502 const char *product = "OP1a Muxer";
3807
24113c3ebeaf always write required version string local tag
bcoudurier
parents: 3806
diff changeset
503 const char *version;
3810
297ad1d4d4d6 simplify, and factorize
bcoudurier
parents: 3809
diff changeset
504 int length;
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
505
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
506 mxf_write_metadata_key(pb, 0x013000);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
507 PRINT_KEY(s, "identification key", pb->buf_ptr - 16);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
508
3808
dd88c58a4432 simplify
bcoudurier
parents: 3807
diff changeset
509 version = s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT ?
3809
22b984b6cec1 only put version in tag
bcoudurier
parents: 3808
diff changeset
510 "0.0.0" : AV_STRINGIFY(LIBAVFORMAT_VERSION);
3810
297ad1d4d4d6 simplify, and factorize
bcoudurier
parents: 3809
diff changeset
511 length = 84 + (strlen(company)+strlen(product)+strlen(version))*2; // utf-16
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
512 klv_encode_ber_length(pb, length);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
513
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
514 // write uid
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
515 mxf_write_local_tag(pb, 16, 0x3C0A);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
516 mxf_write_uuid(pb, Identification, 0);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
517 PRINT_KEY(s, "identification uid", pb->buf_ptr - 16);
3811
0daa9773c9c3 cosmetics
bcoudurier
parents: 3810
diff changeset
518
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
519 // write generation uid
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
520 mxf_write_local_tag(pb, 16, 0x3C09);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
521 mxf_write_uuid(pb, Identification, 1);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
522
3810
297ad1d4d4d6 simplify, and factorize
bcoudurier
parents: 3809
diff changeset
523 mxf_write_local_tag_utf16(pb, 0x3C01, company); // Company Name
297ad1d4d4d6 simplify, and factorize
bcoudurier
parents: 3809
diff changeset
524 mxf_write_local_tag_utf16(pb, 0x3C02, product); // Product Name
3807
24113c3ebeaf always write required version string local tag
bcoudurier
parents: 3806
diff changeset
525 mxf_write_local_tag_utf16(pb, 0x3C04, version); // Version String
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
526
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
527 // write product uid
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
528 mxf_write_local_tag(pb, 16, 0x3C05);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
529 mxf_write_uuid(pb, Identification, 2);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
530
4384
bfb10be2b631 use timestamp as modification date
bcoudurier
parents: 4382
diff changeset
531 // modification date
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
532 mxf_write_local_tag(pb, 8, 0x3C06);
4385
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
533 put_be64(pb, mxf->timestamp);
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
534 }
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
535
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
536 static void mxf_write_content_storage(AVFormatContext *s)
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
537 {
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
538 ByteIOContext *pb = s->pb;
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
539
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
540 mxf_write_metadata_key(pb, 0x011800);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
541 PRINT_KEY(s, "content storage key", pb->buf_ptr - 16);
4279
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
542 klv_encode_ber_length(pb, 92);
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
543
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
544 // write uid
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
545 mxf_write_local_tag(pb, 16, 0x3C0A);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
546 mxf_write_uuid(pb, ContentStorage, 0);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
547 PRINT_KEY(s, "content storage uid", pb->buf_ptr - 16);
3812
1db39c874eb7 cosmetics, remove useless braces, move comments where appropriate, remove whitespaces
bcoudurier
parents: 3811
diff changeset
548
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
549 // write package reference
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
550 mxf_write_local_tag(pb, 16 * 2 + 8, 0x1901);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
551 mxf_write_refs_count(pb, 2);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
552 mxf_write_uuid(pb, MaterialPackage, 0);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
553 mxf_write_uuid(pb, SourcePackage, 0);
4279
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
554
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
555 // write essence container data
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
556 mxf_write_local_tag(pb, 8 + 16, 0x1902);
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
557 mxf_write_refs_count(pb, 1);
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
558 mxf_write_uuid(pb, EssenceContainerData, 0);
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
559 }
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
560
3832
f3a099c0fdf8 simplify, pass AVStream directly instead of index
bcoudurier
parents: 3831
diff changeset
561 static void mxf_write_track(AVFormatContext *s, AVStream *st, enum MXFMetadataSetType type)
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
562 {
4374
1664a812629f use sample rate as audio input time base
bcoudurier
parents: 4370
diff changeset
563 MXFContext *mxf = s->priv_data;
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
564 ByteIOContext *pb = s->pb;
3823
42ed5e2f1b4b merge declaration and init
bcoudurier
parents: 3822
diff changeset
565 MXFStreamContext *sc = st->priv_data;
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
566
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
567 mxf_write_metadata_key(pb, 0x013b00);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
568 PRINT_KEY(s, "track key", pb->buf_ptr - 16);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
569 klv_encode_ber_length(pb, 80);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
570
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
571 // write track uid
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
572 mxf_write_local_tag(pb, 16, 0x3C0A);
3832
f3a099c0fdf8 simplify, pass AVStream directly instead of index
bcoudurier
parents: 3831
diff changeset
573 mxf_write_uuid(pb, type == MaterialPackage ? Track : Track + TypeBottom, st->index);
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
574 PRINT_KEY(s, "track uid", pb->buf_ptr - 16);
3812
1db39c874eb7 cosmetics, remove useless braces, move comments where appropriate, remove whitespaces
bcoudurier
parents: 3811
diff changeset
575
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
576 // write track id
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
577 mxf_write_local_tag(pb, 4, 0x4801);
4565
168e8eafefc6 start track id at 2, track id 1 for timecode
bcoudurier
parents: 4537
diff changeset
578 put_be32(pb, st->index+2);
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
579
3826
da2d0c162cde introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents: 3825
diff changeset
580 // write track number
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
581 mxf_write_local_tag(pb, 4, 0x4804);
3826
da2d0c162cde introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents: 3825
diff changeset
582 if (type == MaterialPackage)
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
583 put_be32(pb, 0); // track number of material package is 0
3826
da2d0c162cde introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents: 3825
diff changeset
584 else
da2d0c162cde introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents: 3825
diff changeset
585 put_buffer(pb, sc->track_essence_element_key + 12, 4);
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
586
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
587 mxf_write_local_tag(pb, 8, 0x4B01);
4374
1664a812629f use sample rate as audio input time base
bcoudurier
parents: 4370
diff changeset
588 put_be32(pb, mxf->time_base.den);
1664a812629f use sample rate as audio input time base
bcoudurier
parents: 4370
diff changeset
589 put_be32(pb, mxf->time_base.num);
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
590
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
591 // write origin
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
592 mxf_write_local_tag(pb, 8, 0x4B02);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
593 put_be64(pb, 0);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
594
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
595 // write sequence refs
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
596 mxf_write_local_tag(pb, 16, 0x4803);
3832
f3a099c0fdf8 simplify, pass AVStream directly instead of index
bcoudurier
parents: 3831
diff changeset
597 mxf_write_uuid(pb, type == MaterialPackage ? Sequence: Sequence + TypeBottom, st->index);
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
598 }
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
599
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
600 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 };
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
601
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
602 static void mxf_write_common_fields(AVFormatContext *s, AVStream *st)
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
603 {
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
604 MXFContext *mxf = s->priv_data;
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
605 ByteIOContext *pb = s->pb;
3834
d49f55ab650c set duration to distinguished value
bcoudurier
parents: 3833
diff changeset
606
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
607 // find data define uls
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
608 mxf_write_local_tag(pb, 16, 0x0201);
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
609 if (st == mxf->timecode_track)
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
610 put_buffer(pb, smpte_12m_timecode_track_data_ul, 16);
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
611 else {
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
612 const MXFCodecUL *data_def_ul = mxf_get_data_definition_ul(st->codec->codec_type);
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
613 put_buffer(pb, data_def_ul->uid, 16);
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
614 }
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
615
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
616 // write duration
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
617 mxf_write_local_tag(pb, 8, 0x0202);
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
618 put_be64(pb, mxf->duration);
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
619 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
620
3832
f3a099c0fdf8 simplify, pass AVStream directly instead of index
bcoudurier
parents: 3831
diff changeset
621 static void mxf_write_sequence(AVFormatContext *s, AVStream *st, enum MXFMetadataSetType type)
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
622 {
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
623 MXFContext *mxf = s->priv_data;
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
624 ByteIOContext *pb = s->pb;
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
625 enum MXFMetadataSetType component;
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
626
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
627 mxf_write_metadata_key(pb, 0x010f00);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
628 PRINT_KEY(s, "sequence key", pb->buf_ptr - 16);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
629 klv_encode_ber_length(pb, 80);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
630
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
631 mxf_write_local_tag(pb, 16, 0x3C0A);
3832
f3a099c0fdf8 simplify, pass AVStream directly instead of index
bcoudurier
parents: 3831
diff changeset
632 mxf_write_uuid(pb, type == MaterialPackage ? Sequence: Sequence + TypeBottom, st->index);
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
633
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
634 PRINT_KEY(s, "sequence uid", pb->buf_ptr - 16);
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
635 mxf_write_common_fields(s, st);
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
636
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
637 // write structural component
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
638 mxf_write_local_tag(pb, 16 + 8, 0x1001);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
639 mxf_write_refs_count(pb, 1);
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
640 if (st == mxf->timecode_track)
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
641 component = TimecodeComponent;
4529
ade95792aa16 use index 0 for timecode track and write it in source package also
bcoudurier
parents: 4528
diff changeset
642 else
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
643 component = SourceClip;
4529
ade95792aa16 use index 0 for timecode track and write it in source package also
bcoudurier
parents: 4528
diff changeset
644 if (type == SourcePackage)
ade95792aa16 use index 0 for timecode track and write it in source package also
bcoudurier
parents: 4528
diff changeset
645 component += TypeBottom;
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
646 mxf_write_uuid(pb, component, st->index);
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
647 }
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
648
4529
ade95792aa16 use index 0 for timecode track and write it in source package also
bcoudurier
parents: 4528
diff changeset
649 static void mxf_write_timecode_component(AVFormatContext *s, AVStream *st, enum MXFMetadataSetType type)
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
650 {
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
651 MXFContext *mxf = s->priv_data;
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
652 ByteIOContext *pb = s->pb;
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
653
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
654 mxf_write_metadata_key(pb, 0x011400);
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
655 klv_encode_ber_length(pb, 75);
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
656
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
657 // UID
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
658 mxf_write_local_tag(pb, 16, 0x3C0A);
4529
ade95792aa16 use index 0 for timecode track and write it in source package also
bcoudurier
parents: 4528
diff changeset
659 mxf_write_uuid(pb, type == MaterialPackage ? TimecodeComponent :
ade95792aa16 use index 0 for timecode track and write it in source package also
bcoudurier
parents: 4528
diff changeset
660 TimecodeComponent + TypeBottom, st->index);
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
661
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
662 mxf_write_common_fields(s, st);
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
663
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
664 // Start Time Code
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
665 mxf_write_local_tag(pb, 8, 0x1501);
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
666 put_be64(pb, mxf->timecode_start);
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
667
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
668 // Rounded Time Code Base
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
669 mxf_write_local_tag(pb, 2, 0x1502);
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
670 put_be16(pb, mxf->timecode_base);
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
671
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
672 // Drop Frame
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
673 mxf_write_local_tag(pb, 1, 0x1503);
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
674 put_byte(pb, mxf->timecode_drop_frame);
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
675 }
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
676
3832
f3a099c0fdf8 simplify, pass AVStream directly instead of index
bcoudurier
parents: 3831
diff changeset
677 static void mxf_write_structural_component(AVFormatContext *s, AVStream *st, enum MXFMetadataSetType type)
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
678 {
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
679 ByteIOContext *pb = s->pb;
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
680 int i;
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
681
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
682 mxf_write_metadata_key(pb, 0x011100);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
683 PRINT_KEY(s, "sturctural component key", pb->buf_ptr - 16);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
684 klv_encode_ber_length(pb, 108);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
685
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
686 // write uid
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
687 mxf_write_local_tag(pb, 16, 0x3C0A);
3832
f3a099c0fdf8 simplify, pass AVStream directly instead of index
bcoudurier
parents: 3831
diff changeset
688 mxf_write_uuid(pb, type == MaterialPackage ? SourceClip: SourceClip + TypeBottom, st->index);
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
689
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
690 PRINT_KEY(s, "structural component uid", pb->buf_ptr - 16);
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
691 mxf_write_common_fields(s, st);
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
692
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
693 // write start_position
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
694 mxf_write_local_tag(pb, 8, 0x1201);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
695 put_be64(pb, 0);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
696
3812
1db39c874eb7 cosmetics, remove useless braces, move comments where appropriate, remove whitespaces
bcoudurier
parents: 3811
diff changeset
697 // write source package uid, end of the reference
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
698 mxf_write_local_tag(pb, 32, 0x1101);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
699 if (type == SourcePackage) {
3812
1db39c874eb7 cosmetics, remove useless braces, move comments where appropriate, remove whitespaces
bcoudurier
parents: 3811
diff changeset
700 for (i = 0; i < 4; i++)
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
701 put_be64(pb, 0);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
702 } else
4696
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
703 mxf_write_umid(s, 1);
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
704
3812
1db39c874eb7 cosmetics, remove useless braces, move comments where appropriate, remove whitespaces
bcoudurier
parents: 3811
diff changeset
705 // write source track id
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
706 mxf_write_local_tag(pb, 4, 0x1102);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
707 if (type == SourcePackage)
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
708 put_be32(pb, 0);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
709 else
4565
168e8eafefc6 start track id at 2, track id 1 for timecode
bcoudurier
parents: 4537
diff changeset
710 put_be32(pb, st->index+2);
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
711 }
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
712
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
713 static void mxf_write_multi_descriptor(AVFormatContext *s)
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
714 {
4376
2b46680bf82f always write mxf time base in descriptors
bcoudurier
parents: 4374
diff changeset
715 MXFContext *mxf = s->priv_data;
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
716 ByteIOContext *pb = s->pb;
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
717 const uint8_t *ul;
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
718 int i;
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
719
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
720 mxf_write_metadata_key(pb, 0x014400);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
721 PRINT_KEY(s, "multiple descriptor key", pb->buf_ptr - 16);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
722 klv_encode_ber_length(pb, 64 + 16 * s->nb_streams);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
723
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
724 mxf_write_local_tag(pb, 16, 0x3C0A);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
725 mxf_write_uuid(pb, MultipleDescriptor, 0);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
726 PRINT_KEY(s, "multi_desc uid", pb->buf_ptr - 16);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
727
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
728 // write sample rate
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
729 mxf_write_local_tag(pb, 8, 0x3001);
4376
2b46680bf82f always write mxf time base in descriptors
bcoudurier
parents: 4374
diff changeset
730 put_be32(pb, mxf->time_base.den);
2b46680bf82f always write mxf time base in descriptors
bcoudurier
parents: 4374
diff changeset
731 put_be32(pb, mxf->time_base.num);
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
732
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
733 // write essence container ul
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
734 mxf_write_local_tag(pb, 16, 0x3004);
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
735 if (mxf->essence_container_count > 1)
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
736 ul = multiple_desc_ul;
4475
fc3806848a49 simplify
bcoudurier
parents: 4474
diff changeset
737 else {
fc3806848a49 simplify
bcoudurier
parents: 4474
diff changeset
738 MXFStreamContext *sc = s->streams[0]->priv_data;
fc3806848a49 simplify
bcoudurier
parents: 4474
diff changeset
739 ul = mxf_essence_container_uls[sc->index].container_ul;
fc3806848a49 simplify
bcoudurier
parents: 4474
diff changeset
740 }
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
741 put_buffer(pb, ul, 16);
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
742
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
743 // write sub descriptor refs
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
744 mxf_write_local_tag(pb, s->nb_streams * 16 + 8, 0x3F01);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
745 mxf_write_refs_count(pb, s->nb_streams);
3812
1db39c874eb7 cosmetics, remove useless braces, move comments where appropriate, remove whitespaces
bcoudurier
parents: 3811
diff changeset
746 for (i = 0; i < s->nb_streams; i++)
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
747 mxf_write_uuid(pb, SubDescriptor, i);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
748 }
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
749
4376
2b46680bf82f always write mxf time base in descriptors
bcoudurier
parents: 4374
diff changeset
750 static void mxf_write_generic_desc(AVFormatContext *s, AVStream *st, const UID key, unsigned size)
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
751 {
4376
2b46680bf82f always write mxf time base in descriptors
bcoudurier
parents: 4374
diff changeset
752 MXFContext *mxf = s->priv_data;
3817
22831cc65a35 get essence container ul in header and set it per track, check for unsupported codec
bcoudurier
parents: 3816
diff changeset
753 MXFStreamContext *sc = st->priv_data;
4376
2b46680bf82f always write mxf time base in descriptors
bcoudurier
parents: 4374
diff changeset
754 ByteIOContext *pb = s->pb;
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
755
3845
c266530d56b4 merge descriptor write table with essence container uls table and simplify
bcoudurier
parents: 3844
diff changeset
756 put_buffer(pb, key, 16);
5091
d1609b5528e6 use ber4 length for descriptors preferred by specs
bcoudurier
parents: 5090
diff changeset
757 klv_encode_ber4_length(pb, size+20+8+12+20);
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
758
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
759 mxf_write_local_tag(pb, 16, 0x3C0A);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
760 mxf_write_uuid(pb, SubDescriptor, st->index);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
761
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
762 mxf_write_local_tag(pb, 4, 0x3006);
4565
168e8eafefc6 start track id at 2, track id 1 for timecode
bcoudurier
parents: 4537
diff changeset
763 put_be32(pb, st->index+2);
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
764
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
765 mxf_write_local_tag(pb, 8, 0x3001);
4376
2b46680bf82f always write mxf time base in descriptors
bcoudurier
parents: 4374
diff changeset
766 put_be32(pb, mxf->time_base.den);
2b46680bf82f always write mxf time base in descriptors
bcoudurier
parents: 4374
diff changeset
767 put_be32(pb, mxf->time_base.num);
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
768
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
769 mxf_write_local_tag(pb, 16, 0x3004);
3846
0ee95f0b4c00 store index in table in MXFStreamContext, simplify
bcoudurier
parents: 3845
diff changeset
770 put_buffer(pb, mxf_essence_container_uls[sc->index].container_ul, 16);
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
771 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
772
3845
c266530d56b4 merge descriptor write table with essence container uls table and simplify
bcoudurier
parents: 3844
diff changeset
773 static const UID mxf_mpegvideo_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 };
c266530d56b4 merge descriptor write table with essence container uls table and simplify
bcoudurier
parents: 3844
diff changeset
774 static const UID mxf_wav_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 };
4320
3524125567f3 add aes3 pcm wrapping and use it by default
bcoudurier
parents: 4319
diff changeset
775 static const UID mxf_aes3_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 };
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
776 static const UID mxf_cdci_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x28,0x00 };
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
777 static const UID mxf_generic_sound_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x42,0x00 };
3845
c266530d56b4 merge descriptor write table with essence container uls table and simplify
bcoudurier
parents: 3844
diff changeset
778
4471
bac4bfb54ff7 split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents: 4470
diff changeset
779 static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID key, unsigned size)
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
780 {
4316
3c4392f087dc stored height is stupidly /2 if interlaced
bcoudurier
parents: 4315
diff changeset
781 MXFStreamContext *sc = st->priv_data;
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
782 ByteIOContext *pb = s->pb;
4277
a5e558f1a64f stored height is a multiple of 16 for mpeg2
bcoudurier
parents: 4012
diff changeset
783 int stored_height = (st->codec->height+15)/16*16;
4472
3ef8f4df0a54 store display height without vbi
bcoudurier
parents: 4471
diff changeset
784 int display_height;
4322
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
785 int f1, f2;
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
786
4527
3aa54e7973d7 simplify descriptor size computation logic
bcoudurier
parents: 4505
diff changeset
787 mxf_write_generic_desc(s, st, key, size+8+8+8+8+8+8+5+16+sc->interlaced*4+12+20);
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
788
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
789 mxf_write_local_tag(pb, 4, 0x3203);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
790 put_be32(pb, st->codec->width);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
791
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
792 mxf_write_local_tag(pb, 4, 0x3202);
4316
3c4392f087dc stored height is stupidly /2 if interlaced
bcoudurier
parents: 4315
diff changeset
793 put_be32(pb, stored_height>>sc->interlaced);
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
794
4335
e6fb8644af02 write display height/width tags
bcoudurier
parents: 4330
diff changeset
795 mxf_write_local_tag(pb, 4, 0x3209);
e6fb8644af02 write display height/width tags
bcoudurier
parents: 4330
diff changeset
796 put_be32(pb, st->codec->width);
e6fb8644af02 write display height/width tags
bcoudurier
parents: 4330
diff changeset
797
4472
3ef8f4df0a54 store display height without vbi
bcoudurier
parents: 4471
diff changeset
798 if (st->codec->height == 608) // PAL + VBI
3ef8f4df0a54 store display height without vbi
bcoudurier
parents: 4471
diff changeset
799 display_height = 576;
3ef8f4df0a54 store display height without vbi
bcoudurier
parents: 4471
diff changeset
800 else if (st->codec->height == 512) // NTSC + VBI
3ef8f4df0a54 store display height without vbi
bcoudurier
parents: 4471
diff changeset
801 display_height = 486;
3ef8f4df0a54 store display height without vbi
bcoudurier
parents: 4471
diff changeset
802 else
3ef8f4df0a54 store display height without vbi
bcoudurier
parents: 4471
diff changeset
803 display_height = st->codec->height;
3ef8f4df0a54 store display height without vbi
bcoudurier
parents: 4471
diff changeset
804
4335
e6fb8644af02 write display height/width tags
bcoudurier
parents: 4330
diff changeset
805 mxf_write_local_tag(pb, 4, 0x3208);
4472
3ef8f4df0a54 store display height without vbi
bcoudurier
parents: 4471
diff changeset
806 put_be32(pb, display_height>>sc->interlaced);
4335
e6fb8644af02 write display height/width tags
bcoudurier
parents: 4330
diff changeset
807
4434
a75d42745d16 write component depth and horizontal subsampling best effort local tags
bcoudurier
parents: 4433
diff changeset
808 // component depth
a75d42745d16 write component depth and horizontal subsampling best effort local tags
bcoudurier
parents: 4433
diff changeset
809 mxf_write_local_tag(pb, 4, 0x3301);
a75d42745d16 write component depth and horizontal subsampling best effort local tags
bcoudurier
parents: 4433
diff changeset
810 put_be32(pb, 8);
a75d42745d16 write component depth and horizontal subsampling best effort local tags
bcoudurier
parents: 4433
diff changeset
811
a75d42745d16 write component depth and horizontal subsampling best effort local tags
bcoudurier
parents: 4433
diff changeset
812 // horizontal subsampling
a75d42745d16 write component depth and horizontal subsampling best effort local tags
bcoudurier
parents: 4433
diff changeset
813 mxf_write_local_tag(pb, 4, 0x3302);
a75d42745d16 write component depth and horizontal subsampling best effort local tags
bcoudurier
parents: 4433
diff changeset
814 put_be32(pb, 2);
a75d42745d16 write component depth and horizontal subsampling best effort local tags
bcoudurier
parents: 4433
diff changeset
815
4321
68de70aa392b add frame layout local tag, best effort
bcoudurier
parents: 4320
diff changeset
816 // frame layout
68de70aa392b add frame layout local tag, best effort
bcoudurier
parents: 4320
diff changeset
817 mxf_write_local_tag(pb, 1, 0x320C);
68de70aa392b add frame layout local tag, best effort
bcoudurier
parents: 4320
diff changeset
818 put_byte(pb, sc->interlaced);
68de70aa392b add frame layout local tag, best effort
bcoudurier
parents: 4320
diff changeset
819
4322
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
820 // video line map
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
821 switch (st->codec->height) {
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
822 case 576: f1 = 23; f2 = 336; break;
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
823 case 608: f1 = 7; f2 = 320; break;
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
824 case 480: f1 = 20; f2 = 283; break;
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
825 case 512: f1 = 7; f2 = 270; break;
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
826 case 720: f1 = 26; f2 = 0; break; // progressive
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
827 case 1080: f1 = 21; f2 = 584; break;
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
828 default: f1 = 0; f2 = 0; break;
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
829 }
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
830
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
831 if (!sc->interlaced) {
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
832 f2 = 0;
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
833 f1 *= 2;
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
834 }
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
835
4343
b691846ea95e fix video line map tag size
bcoudurier
parents: 4342
diff changeset
836 mxf_write_local_tag(pb, 12+sc->interlaced*4, 0x320D);
4337
3d3c7fbfd910 do not write f2 if not interlaced
bcoudurier
parents: 4336
diff changeset
837 put_be32(pb, sc->interlaced ? 2 : 1);
3d3c7fbfd910 do not write f2 if not interlaced
bcoudurier
parents: 4336
diff changeset
838 put_be32(pb, 4);
4322
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
839 put_be32(pb, f1);
4337
3d3c7fbfd910 do not write f2 if not interlaced
bcoudurier
parents: 4336
diff changeset
840 if (sc->interlaced)
3d3c7fbfd910 do not write f2 if not interlaced
bcoudurier
parents: 4336
diff changeset
841 put_be32(pb, f2);
4322
0d40ba62d7d7 write best effort video line map
bcoudurier
parents: 4321
diff changeset
842
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
843 mxf_write_local_tag(pb, 8, 0x320E);
4505
da04428a94db fetch display aspect ratio from mpeg-2 essence
bcoudurier
parents: 4504
diff changeset
844 put_be32(pb, sc->aspect_ratio.num);
da04428a94db fetch display aspect ratio from mpeg-2 essence
bcoudurier
parents: 4504
diff changeset
845 put_be32(pb, sc->aspect_ratio.den);
4317
b978795a9e37 local tag 3201 is picture essence coding, so do not write it for wav
bcoudurier
parents: 4316
diff changeset
846
b978795a9e37 local tag 3201 is picture essence coding, so do not write it for wav
bcoudurier
parents: 4316
diff changeset
847 mxf_write_local_tag(pb, 16, 0x3201);
b978795a9e37 local tag 3201 is picture essence coding, so do not write it for wav
bcoudurier
parents: 4316
diff changeset
848 put_buffer(pb, *sc->codec_ul, 16);
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
849 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
850
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
851 static void mxf_write_cdci_desc(AVFormatContext *s, AVStream *st)
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
852 {
4527
3aa54e7973d7 simplify descriptor size computation logic
bcoudurier
parents: 4505
diff changeset
853 mxf_write_cdci_common(s, st, mxf_cdci_descriptor_key, 0);
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
854 }
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
855
4471
bac4bfb54ff7 split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents: 4470
diff changeset
856 static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st)
bac4bfb54ff7 split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents: 4470
diff changeset
857 {
bac4bfb54ff7 split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents: 4470
diff changeset
858 ByteIOContext *pb = s->pb;
5090
f2671cc3467c write profile and level local tag in mpeg descriptor
bcoudurier
parents: 5081
diff changeset
859 int profile_and_level = (st->codec->profile<<4) | st->codec->level;
4471
bac4bfb54ff7 split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents: 4470
diff changeset
860
5090
f2671cc3467c write profile and level local tag in mpeg descriptor
bcoudurier
parents: 5081
diff changeset
861 mxf_write_cdci_common(s, st, mxf_mpegvideo_descriptor_key, 8+5);
4471
bac4bfb54ff7 split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents: 4470
diff changeset
862
bac4bfb54ff7 split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents: 4470
diff changeset
863 // bit rate
bac4bfb54ff7 split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents: 4470
diff changeset
864 mxf_write_local_tag(pb, 4, 0x8000);
bac4bfb54ff7 split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents: 4470
diff changeset
865 put_be32(pb, st->codec->bit_rate);
5090
f2671cc3467c write profile and level local tag in mpeg descriptor
bcoudurier
parents: 5081
diff changeset
866
f2671cc3467c write profile and level local tag in mpeg descriptor
bcoudurier
parents: 5081
diff changeset
867 // profile and level
f2671cc3467c write profile and level local tag in mpeg descriptor
bcoudurier
parents: 5081
diff changeset
868 mxf_write_local_tag(pb, 1, 0x8007);
f2671cc3467c write profile and level local tag in mpeg descriptor
bcoudurier
parents: 5081
diff changeset
869 if (!st->codec->profile)
f2671cc3467c write profile and level local tag in mpeg descriptor
bcoudurier
parents: 5081
diff changeset
870 profile_and_level |= 0x80; // escape bit
f2671cc3467c write profile and level local tag in mpeg descriptor
bcoudurier
parents: 5081
diff changeset
871 put_byte(pb, profile_and_level);
4471
bac4bfb54ff7 split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents: 4470
diff changeset
872 }
bac4bfb54ff7 split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents: 4470
diff changeset
873
bac4bfb54ff7 split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents: 4470
diff changeset
874 static void mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st, const UID key, unsigned size)
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
875 {
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
876 ByteIOContext *pb = s->pb;
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
877
4527
3aa54e7973d7 simplify descriptor size computation logic
bcoudurier
parents: 4505
diff changeset
878 mxf_write_generic_desc(s, st, key, size+5+12+8+8);
4318
a7d69a322311 thanks to interleaving, audio is now locked
bcoudurier
parents: 4317
diff changeset
879
4319
28d38c1fb5fa split wav_desc in generic_sound_desc
bcoudurier
parents: 4318
diff changeset
880 // audio locked
4318
a7d69a322311 thanks to interleaving, audio is now locked
bcoudurier
parents: 4317
diff changeset
881 mxf_write_local_tag(pb, 1, 0x3D02);
a7d69a322311 thanks to interleaving, audio is now locked
bcoudurier
parents: 4317
diff changeset
882 put_byte(pb, 1);
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
883
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
884 // write audio sampling rate
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
885 mxf_write_local_tag(pb, 8, 0x3D03);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
886 put_be32(pb, st->codec->sample_rate);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
887 put_be32(pb, 1);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
888
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
889 mxf_write_local_tag(pb, 4, 0x3D07);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
890 put_be32(pb, st->codec->channels);
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
891
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
892 mxf_write_local_tag(pb, 4, 0x3D01);
4346
0a142b4b841e 24bit pcm support
bcoudurier
parents: 4345
diff changeset
893 put_be32(pb, av_get_bits_per_sample(st->codec->codec_id));
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
894 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
895
4471
bac4bfb54ff7 split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents: 4470
diff changeset
896 static void mxf_write_wav_common(AVFormatContext *s, AVStream *st, const UID key, unsigned size)
4319
28d38c1fb5fa split wav_desc in generic_sound_desc
bcoudurier
parents: 4318
diff changeset
897 {
4339
eaecbe63bcc5 write req local tags for wav
bcoudurier
parents: 4338
diff changeset
898 ByteIOContext *pb = s->pb;
eaecbe63bcc5 write req local tags for wav
bcoudurier
parents: 4338
diff changeset
899
4527
3aa54e7973d7 simplify descriptor size computation logic
bcoudurier
parents: 4505
diff changeset
900 mxf_write_generic_sound_common(s, st, key, size+6+8);
4339
eaecbe63bcc5 write req local tags for wav
bcoudurier
parents: 4338
diff changeset
901
eaecbe63bcc5 write req local tags for wav
bcoudurier
parents: 4338
diff changeset
902 mxf_write_local_tag(pb, 2, 0x3D0A);
eaecbe63bcc5 write req local tags for wav
bcoudurier
parents: 4338
diff changeset
903 put_be16(pb, st->codec->block_align);
eaecbe63bcc5 write req local tags for wav
bcoudurier
parents: 4338
diff changeset
904
eaecbe63bcc5 write req local tags for wav
bcoudurier
parents: 4338
diff changeset
905 // avg bytes per sec
eaecbe63bcc5 write req local tags for wav
bcoudurier
parents: 4338
diff changeset
906 mxf_write_local_tag(pb, 4, 0x3D09);
eaecbe63bcc5 write req local tags for wav
bcoudurier
parents: 4338
diff changeset
907 put_be32(pb, st->codec->block_align*st->codec->sample_rate);
4319
28d38c1fb5fa split wav_desc in generic_sound_desc
bcoudurier
parents: 4318
diff changeset
908 }
28d38c1fb5fa split wav_desc in generic_sound_desc
bcoudurier
parents: 4318
diff changeset
909
4340
ee0bdf4a43b0 factorize common wav local tags
bcoudurier
parents: 4339
diff changeset
910 static void mxf_write_wav_desc(AVFormatContext *s, AVStream *st)
ee0bdf4a43b0 factorize common wav local tags
bcoudurier
parents: 4339
diff changeset
911 {
4527
3aa54e7973d7 simplify descriptor size computation logic
bcoudurier
parents: 4505
diff changeset
912 mxf_write_wav_common(s, st, mxf_wav_descriptor_key, 0);
4340
ee0bdf4a43b0 factorize common wav local tags
bcoudurier
parents: 4339
diff changeset
913 }
ee0bdf4a43b0 factorize common wav local tags
bcoudurier
parents: 4339
diff changeset
914
4320
3524125567f3 add aes3 pcm wrapping and use it by default
bcoudurier
parents: 4319
diff changeset
915 static void mxf_write_aes3_desc(AVFormatContext *s, AVStream *st)
3524125567f3 add aes3 pcm wrapping and use it by default
bcoudurier
parents: 4319
diff changeset
916 {
4527
3aa54e7973d7 simplify descriptor size computation logic
bcoudurier
parents: 4505
diff changeset
917 mxf_write_wav_common(s, st, mxf_aes3_descriptor_key, 0);
4320
3524125567f3 add aes3 pcm wrapping and use it by default
bcoudurier
parents: 4319
diff changeset
918 }
3524125567f3 add aes3 pcm wrapping and use it by default
bcoudurier
parents: 4319
diff changeset
919
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
920 static void mxf_write_generic_sound_desc(AVFormatContext *s, AVStream *st)
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
921 {
4527
3aa54e7973d7 simplify descriptor size computation logic
bcoudurier
parents: 4505
diff changeset
922 mxf_write_generic_sound_common(s, st, mxf_generic_sound_descriptor_key, 0);
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
923 }
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
924
3848
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
925 static void mxf_write_package(AVFormatContext *s, enum MXFMetadataSetType type)
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
926 {
4385
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
927 MXFContext *mxf = s->priv_data;
3848
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
928 ByteIOContext *pb = s->pb;
4529
ade95792aa16 use index 0 for timecode track and write it in source package also
bcoudurier
parents: 4528
diff changeset
929 int i, track_count = s->nb_streams+1;
3848
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
930
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
931 if (type == MaterialPackage) {
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
932 mxf_write_metadata_key(pb, 0x013600);
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
933 PRINT_KEY(s, "Material Package key", pb->buf_ptr - 16);
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
934 klv_encode_ber_length(pb, 92 + 16*track_count);
3848
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
935 } else {
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
936 mxf_write_metadata_key(pb, 0x013700);
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
937 PRINT_KEY(s, "Source Package key", pb->buf_ptr - 16);
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
938 klv_encode_ber_length(pb, 112 + 16*track_count); // 20 bytes length for descriptor reference
3848
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
939 }
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
940
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
941 // write uid
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
942 mxf_write_local_tag(pb, 16, 0x3C0A);
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
943 mxf_write_uuid(pb, type, 0);
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
944 av_log(s,AV_LOG_DEBUG, "package type:%d\n", type);
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
945 PRINT_KEY(s, "package uid", pb->buf_ptr - 16);
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
946
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
947 // write package umid
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
948 mxf_write_local_tag(pb, 32, 0x4401);
4696
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
949 mxf_write_umid(s, type == SourcePackage);
3848
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
950 PRINT_KEY(s, "package umid second part", pb->buf_ptr - 16);
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
951
4385
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
952 // package creation date
3848
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
953 mxf_write_local_tag(pb, 8, 0x4405);
4385
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
954 put_be64(pb, mxf->timestamp);
3848
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
955
4385
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
956 // package modified date
3848
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
957 mxf_write_local_tag(pb, 8, 0x4404);
4385
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
958 put_be64(pb, mxf->timestamp);
3848
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
959
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
960 // write track refs
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
961 mxf_write_local_tag(pb, track_count*16 + 8, 0x4403);
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
962 mxf_write_refs_count(pb, track_count);
4529
ade95792aa16 use index 0 for timecode track and write it in source package also
bcoudurier
parents: 4528
diff changeset
963 mxf_write_uuid(pb, type == MaterialPackage ? Track :
ade95792aa16 use index 0 for timecode track and write it in source package also
bcoudurier
parents: 4528
diff changeset
964 Track + TypeBottom, -1); // timecode track
3848
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
965 for (i = 0; i < s->nb_streams; i++)
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
966 mxf_write_uuid(pb, type == MaterialPackage ? Track : Track + TypeBottom, i);
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
967
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
968 // write multiple descriptor reference
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
969 if (type == SourcePackage) {
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
970 mxf_write_local_tag(pb, 16, 0x4701);
3851
9b3ad7f292a4 do no write multi descriptor when only one track is present
bcoudurier
parents: 3850
diff changeset
971 if (s->nb_streams > 1) {
9b3ad7f292a4 do no write multi descriptor when only one track is present
bcoudurier
parents: 3850
diff changeset
972 mxf_write_uuid(pb, MultipleDescriptor, 0);
9b3ad7f292a4 do no write multi descriptor when only one track is present
bcoudurier
parents: 3850
diff changeset
973 mxf_write_multi_descriptor(s);
9b3ad7f292a4 do no write multi descriptor when only one track is present
bcoudurier
parents: 3850
diff changeset
974 } else
9b3ad7f292a4 do no write multi descriptor when only one track is present
bcoudurier
parents: 3850
diff changeset
975 mxf_write_uuid(pb, SubDescriptor, 0);
3848
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
976 }
1b5106f2b3f4 move mxf_write_package to permit function merge
bcoudurier
parents: 3847
diff changeset
977
4529
ade95792aa16 use index 0 for timecode track and write it in source package also
bcoudurier
parents: 4528
diff changeset
978 // write timecode track
ade95792aa16 use index 0 for timecode track and write it in source package also
bcoudurier
parents: 4528
diff changeset
979 mxf_write_track(s, mxf->timecode_track, type);
ade95792aa16 use index 0 for timecode track and write it in source package also
bcoudurier
parents: 4528
diff changeset
980 mxf_write_sequence(s, mxf->timecode_track, type);
ade95792aa16 use index 0 for timecode track and write it in source package also
bcoudurier
parents: 4528
diff changeset
981 mxf_write_timecode_component(s, mxf->timecode_track, type);
ade95792aa16 use index 0 for timecode track and write it in source package also
bcoudurier
parents: 4528
diff changeset
982
3831
547e11f5924b cosmetics, whitespace
bcoudurier
parents: 3830
diff changeset
983 for (i = 0; i < s->nb_streams; i++) {
3832
f3a099c0fdf8 simplify, pass AVStream directly instead of index
bcoudurier
parents: 3831
diff changeset
984 AVStream *st = s->streams[i];
f3a099c0fdf8 simplify, pass AVStream directly instead of index
bcoudurier
parents: 3831
diff changeset
985 mxf_write_track(s, st, type);
f3a099c0fdf8 simplify, pass AVStream directly instead of index
bcoudurier
parents: 3831
diff changeset
986 mxf_write_sequence(s, st, type);
f3a099c0fdf8 simplify, pass AVStream directly instead of index
bcoudurier
parents: 3831
diff changeset
987 mxf_write_structural_component(s, st, type);
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
988
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
989 if (type == SourcePackage) {
3845
c266530d56b4 merge descriptor write table with essence container uls table and simplify
bcoudurier
parents: 3844
diff changeset
990 MXFStreamContext *sc = st->priv_data;
3846
0ee95f0b4c00 store index in table in MXFStreamContext, simplify
bcoudurier
parents: 3845
diff changeset
991 mxf_essence_container_uls[sc->index].write_desc(s, st);
3743
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
992 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
993 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
994 }
68414dc4c4d1 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3740
diff changeset
995
4279
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
996 static int mxf_write_essence_container_data(AVFormatContext *s)
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
997 {
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
998 ByteIOContext *pb = s->pb;
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
999
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
1000 mxf_write_metadata_key(pb, 0x012300);
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1001 klv_encode_ber_length(pb, 72);
4279
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
1002
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
1003 mxf_write_local_tag(pb, 16, 0x3C0A); // Instance UID
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
1004 mxf_write_uuid(pb, EssenceContainerData, 0);
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
1005
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
1006 mxf_write_local_tag(pb, 32, 0x2701); // Linked Package UID
4696
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1007 mxf_write_umid(s, 1);
4279
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
1008
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
1009 mxf_write_local_tag(pb, 4, 0x3F07); // BodySID
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
1010 put_be32(pb, 1);
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
1011
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1012 mxf_write_local_tag(pb, 4, 0x3F06); // IndexSID
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1013 put_be32(pb, 2);
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1014
4279
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
1015 return 0;
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
1016 }
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
1017
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
1018 static int mxf_write_header_metadata_sets(AVFormatContext *s)
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
1019 {
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
1020 mxf_write_preface(s);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
1021 mxf_write_identification(s);
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
1022 mxf_write_content_storage(s);
3849
9dabc8338517 remove mxf_build_structural_metadata, simplify
bcoudurier
parents: 3848
diff changeset
1023 mxf_write_package(s, MaterialPackage);
9dabc8338517 remove mxf_build_structural_metadata, simplify
bcoudurier
parents: 3848
diff changeset
1024 mxf_write_package(s, SourcePackage);
4279
2402eb8c37ff write essence container data
bcoudurier
parents: 4278
diff changeset
1025 mxf_write_essence_container_data(s);
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
1026 return 0;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
1027 }
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
1028
4397
6d1626886974 only use 2 slices for index, one video(vbr) and one audio(cbr)
bcoudurier
parents: 4396
diff changeset
1029 static unsigned klv_fill_size(uint64_t size)
4393
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
1030 {
4397
6d1626886974 only use 2 slices for index, one video(vbr) and one audio(cbr)
bcoudurier
parents: 4396
diff changeset
1031 unsigned pad = KAG_SIZE - (size & (KAG_SIZE-1));
4469
49cf858ac430 encode klv fill item length in fixed ber 4 bytes
bcoudurier
parents: 4461
diff changeset
1032 if (pad < 20) // smallest fill item possible
4393
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
1033 return pad + KAG_SIZE;
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
1034 else
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
1035 return pad & (KAG_SIZE-1);
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
1036 }
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
1037
4408
94287f131b60 remove useless return
bcoudurier
parents: 4407
diff changeset
1038 static void mxf_write_index_table_segment(AVFormatContext *s)
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1039 {
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1040 MXFContext *mxf = s->priv_data;
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1041 ByteIOContext *pb = s->pb;
4408
94287f131b60 remove useless return
bcoudurier
parents: 4407
diff changeset
1042 int i, j;
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1043 int temporal_reordering = 0;
4446
efe78f986bec fix last keyframe index accross body partitions
bcoudurier
parents: 4445
diff changeset
1044 int key_index = mxf->last_key_index;
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1045
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1046 av_log(s, AV_LOG_DEBUG, "edit units count %d\n", mxf->edit_units_count);
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1047
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1048 if (!mxf->edit_units_count && !mxf->edit_unit_byte_count)
4440
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1049 return;
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1050
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1051 put_buffer(pb, index_table_segment_key, 16);
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1052
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1053 if (mxf->edit_unit_byte_count) {
4531
92ee3219998b do not write slice count when muxing cbr
bcoudurier
parents: 4530
diff changeset
1054 klv_encode_ber_length(pb, 80);
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1055 } else {
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1056 klv_encode_ber_length(pb, 85 + 12+(s->nb_streams+1)*6 +
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1057 12+mxf->edit_units_count*(11+mxf->slice_count*4));
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1058 }
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1059
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1060 // instance id
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1061 mxf_write_local_tag(pb, 16, 0x3C0A);
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1062 mxf_write_uuid(pb, IndexTableSegment, 0);
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1063
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1064 // index edit rate
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1065 mxf_write_local_tag(pb, 8, 0x3F0B);
4574
b330c2e275f9 fix index edit rate, inverse num and den
bcoudurier
parents: 4573
diff changeset
1066 put_be32(pb, mxf->time_base.den);
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1067 put_be32(pb, mxf->time_base.num);
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1068
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1069 // index start position
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1070 mxf_write_local_tag(pb, 8, 0x3F0C);
4440
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1071 put_be64(pb, mxf->last_indexed_edit_unit);
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1072
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1073 // index duration
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1074 mxf_write_local_tag(pb, 8, 0x3F0D);
5092
ad1e45ad8e5e set index duration to 0 for cbr, specifying whole container coverage
bcoudurier
parents: 5091
diff changeset
1075 if (mxf->edit_unit_byte_count)
ad1e45ad8e5e set index duration to 0 for cbr, specifying whole container coverage
bcoudurier
parents: 5091
diff changeset
1076 put_be64(pb, 0); // index table covers whole container
ad1e45ad8e5e set index duration to 0 for cbr, specifying whole container coverage
bcoudurier
parents: 5091
diff changeset
1077 else
ad1e45ad8e5e set index duration to 0 for cbr, specifying whole container coverage
bcoudurier
parents: 5091
diff changeset
1078 put_be64(pb, mxf->edit_units_count);
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1079
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1080 // edit unit byte count
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1081 mxf_write_local_tag(pb, 4, 0x3F05);
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1082 put_be32(pb, mxf->edit_unit_byte_count);
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1083
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1084 // index sid
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1085 mxf_write_local_tag(pb, 4, 0x3F06);
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1086 put_be32(pb, 2);
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1087
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1088 // body sid
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1089 mxf_write_local_tag(pb, 4, 0x3F07);
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1090 put_be32(pb, 1);
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1091
4531
92ee3219998b do not write slice count when muxing cbr
bcoudurier
parents: 4530
diff changeset
1092 if (!mxf->edit_unit_byte_count) {
92ee3219998b do not write slice count when muxing cbr
bcoudurier
parents: 4530
diff changeset
1093 // real slice count - 1
92ee3219998b do not write slice count when muxing cbr
bcoudurier
parents: 4530
diff changeset
1094 mxf_write_local_tag(pb, 1, 0x3F08);
92ee3219998b do not write slice count when muxing cbr
bcoudurier
parents: 4530
diff changeset
1095 put_byte(pb, mxf->slice_count);
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1096
4474
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1097 // delta entry array
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1098 mxf_write_local_tag(pb, 8 + (s->nb_streams+1)*6, 0x3F09);
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1099 put_be32(pb, s->nb_streams+1); // num of entries
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1100 put_be32(pb, 6); // size of one entry
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1101 // write system item delta entry
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1102 put_byte(pb, 0);
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1103 put_byte(pb, 0); // slice entry
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1104 put_be32(pb, 0); // element delta
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1105 for (i = 0; i < s->nb_streams; i++) {
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1106 AVStream *st = s->streams[i];
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1107 MXFStreamContext *sc = st->priv_data;
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1108 put_byte(pb, sc->temporal_reordering);
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1109 if (sc->temporal_reordering)
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1110 temporal_reordering = 1;
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1111 if (i == 0) { // video track
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1112 put_byte(pb, 0); // slice number
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1113 put_be32(pb, KAG_SIZE); // system item size including klv fill
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1114 } else { // audio track
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1115 unsigned audio_frame_size = sc->aic.samples[0]*sc->aic.sample_size;
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1116 audio_frame_size += klv_fill_size(audio_frame_size);
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1117 put_byte(pb, 1);
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1118 put_be32(pb, (i-1)*audio_frame_size); // element delta
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1119 }
4397
6d1626886974 only use 2 slices for index, one video(vbr) and one audio(cbr)
bcoudurier
parents: 4396
diff changeset
1120 }
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1121
4474
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1122 mxf_write_local_tag(pb, 8 + mxf->edit_units_count*(11+mxf->slice_count*4), 0x3F0A);
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1123 put_be32(pb, mxf->edit_units_count); // num of entries
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1124 put_be32(pb, 11+mxf->slice_count*4); // size of one entry
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1125 for (i = 0; i < mxf->edit_units_count; i++) {
5080
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
1126 int temporal_offset = 0;
4474
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1127 if (temporal_reordering) {
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1128 for (j = i+1; j < mxf->edit_units_count; j++) {
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1129 temporal_offset++;
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1130 if (mxf->index_entries[j].flags & 0x10) { // backward prediction
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1131 // next is not b, so is reordered
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1132 if (!(mxf->index_entries[i+1].flags & 0x10)) {
5081
56f6b1d56db9 cosmetics, change case and comments alignment
bcoudurier
parents: 5080
diff changeset
1133 if ((mxf->index_entries[i].flags & 0x11) == 0) // I frame
4474
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1134 temporal_offset = 0;
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1135 else
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1136 temporal_offset = -temporal_offset;
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1137 }
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1138 break;
4344
582124bb2c15 fix temporal offet of ipbb sequences, simplification welcome
bcoudurier
parents: 4343
diff changeset
1139 }
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1140 }
5080
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
1141 }
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
1142 put_byte(pb, temporal_offset);
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
1143
4474
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1144 if (!(mxf->index_entries[i].flags & 0x33)) { // I frame
5080
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
1145 if (mxf->index_entries[i].flags & 0x40 && // seq header
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
1146 (!temporal_reordering || !temporal_offset))
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
1147 mxf->index_entries[i].flags |= 0x80; // random access
4474
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1148 mxf->last_key_index = key_index;
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1149 key_index = i;
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1150 }
5080
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
1151 if ((mxf->index_entries[i].flags & 0x30) == 0x30) { // back and forward prediction
4474
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1152 put_byte(pb, mxf->last_key_index - i);
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1153 } else {
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1154 put_byte(pb, key_index - i); // key frame offset
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1155 if ((mxf->index_entries[i].flags & 0x20) == 0x20) // only forward
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1156 mxf->last_key_index = key_index;
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1157 }
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1158 put_byte(pb, mxf->index_entries[i].flags);
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1159 // stream offset
4481
27fd3af46000 compute body offset and index entry offset correctly
bcoudurier
parents: 4478
diff changeset
1160 put_be64(pb, mxf->index_entries[i].offset);
4474
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1161 if (s->nb_streams > 1)
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1162 put_be32(pb, mxf->index_entries[i].slice_offset);
4378
490fde1dcbe5 fix key frame offset with open gop
bcoudurier
parents: 4376
diff changeset
1163 }
4440
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1164
4474
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1165 mxf->last_key_index = key_index - mxf->edit_units_count;
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1166 mxf->last_indexed_edit_unit += mxf->edit_units_count;
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1167 mxf->edit_units_count = 0;
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1168 }
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1169 }
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1170
4432
f8ba6cf226e7 move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents: 4431
diff changeset
1171 static void mxf_write_klv_fill(AVFormatContext *s)
f8ba6cf226e7 move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents: 4431
diff changeset
1172 {
f8ba6cf226e7 move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents: 4431
diff changeset
1173 unsigned pad = klv_fill_size(url_ftell(s->pb));
f8ba6cf226e7 move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents: 4431
diff changeset
1174 if (pad) {
f8ba6cf226e7 move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents: 4431
diff changeset
1175 put_buffer(s->pb, klv_fill_key, 16);
4469
49cf858ac430 encode klv fill item length in fixed ber 4 bytes
bcoudurier
parents: 4461
diff changeset
1176 pad -= 16 + 4;
49cf858ac430 encode klv fill item length in fixed ber 4 bytes
bcoudurier
parents: 4461
diff changeset
1177 klv_encode_ber4_length(s->pb, pad);
4432
f8ba6cf226e7 move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents: 4431
diff changeset
1178 for (; pad; pad--)
f8ba6cf226e7 move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents: 4431
diff changeset
1179 put_byte(s->pb, 0);
f8ba6cf226e7 move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents: 4431
diff changeset
1180 assert(!(url_ftell(s->pb) & (KAG_SIZE-1)));
f8ba6cf226e7 move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents: 4431
diff changeset
1181 }
f8ba6cf226e7 move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents: 4431
diff changeset
1182 }
f8ba6cf226e7 move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents: 4431
diff changeset
1183
4370
6c34e8045dc7 exactly compute index byte count
bcoudurier
parents: 4363
diff changeset
1184 static void mxf_write_partition(AVFormatContext *s, int bodysid,
4439
4bc3b8687ec2 compute index byte count in mxf_write_partition
bcoudurier
parents: 4438
diff changeset
1185 int indexsid,
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1186 const uint8_t *key, int write_metadata)
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1187 {
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1188 MXFContext *mxf = s->priv_data;
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1189 ByteIOContext *pb = s->pb;
3843
b60ab685d415 remove header_byte_count_offset from context
bcoudurier
parents: 3842
diff changeset
1190 int64_t header_byte_count_offset;
4439
4bc3b8687ec2 compute index byte count in mxf_write_partition
bcoudurier
parents: 4438
diff changeset
1191 unsigned index_byte_count = 0;
4442
85f1c6887bef fix partition offset when only one stream present
bcoudurier
parents: 4441
diff changeset
1192 uint64_t partition_offset = url_ftell(pb);
4439
4bc3b8687ec2 compute index byte count in mxf_write_partition
bcoudurier
parents: 4438
diff changeset
1193
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1194 if (!mxf->edit_unit_byte_count && mxf->edit_units_count)
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1195 index_byte_count = 85 + 12+(s->nb_streams+1)*6 +
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1196 12+mxf->edit_units_count*(11+mxf->slice_count*4);
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1197 else if (mxf->edit_unit_byte_count && indexsid)
4537
6e217e9ca23d fix partition index byte count
bcoudurier
parents: 4536
diff changeset
1198 index_byte_count = 80;
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1199
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1200 if (index_byte_count) {
4439
4bc3b8687ec2 compute index byte count in mxf_write_partition
bcoudurier
parents: 4438
diff changeset
1201 // add encoded ber length
4bc3b8687ec2 compute index byte count in mxf_write_partition
bcoudurier
parents: 4438
diff changeset
1202 index_byte_count += 16 + klv_ber_length(index_byte_count);
4bc3b8687ec2 compute index byte count in mxf_write_partition
bcoudurier
parents: 4438
diff changeset
1203 index_byte_count += klv_fill_size(index_byte_count);
4440
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1204 }
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1205
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1206 if (!memcmp(key, body_partition_key, 16)) {
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1207 mxf->body_partition_offset =
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1208 av_realloc(mxf->body_partition_offset,
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1209 (mxf->body_partitions_count+1)*
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1210 sizeof(*mxf->body_partition_offset));
4442
85f1c6887bef fix partition offset when only one stream present
bcoudurier
parents: 4441
diff changeset
1211 mxf->body_partition_offset[mxf->body_partitions_count++] = partition_offset;
4439
4bc3b8687ec2 compute index byte count in mxf_write_partition
bcoudurier
parents: 4438
diff changeset
1212 }
3812
1db39c874eb7 cosmetics, remove useless braces, move comments where appropriate, remove whitespaces
bcoudurier
parents: 3811
diff changeset
1213
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1214 // write klv
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1215 put_buffer(pb, key, 16);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1216 klv_encode_ber_length(pb, 88 + 16 * mxf->essence_container_count);
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1217
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1218 // write partition value
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1219 put_be16(pb, 1); // majorVersion
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1220 put_be16(pb, 2); // minorVersion
4393
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
1221 put_be32(pb, KAG_SIZE); // KAGSize
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1222
4442
85f1c6887bef fix partition offset when only one stream present
bcoudurier
parents: 4441
diff changeset
1223 put_be64(pb, partition_offset); // ThisPartition
4440
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1224
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1225 if (!memcmp(key, body_partition_key, 16) && mxf->body_partitions_count > 1)
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1226 put_be64(pb, mxf->body_partition_offset[mxf->body_partitions_count-2]); // PreviousPartition
4460
21945a5288cb check body partitions count before writing
bcoudurier
parents: 4449
diff changeset
1227 else if (!memcmp(key, footer_partition_key, 16) && mxf->body_partitions_count)
4440
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1228 put_be64(pb, mxf->body_partition_offset[mxf->body_partitions_count-1]); // PreviousPartition
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1229 else
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1230 put_be64(pb, 0);
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1231
3842
c4e0e02a4832 simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents: 3841
diff changeset
1232 put_be64(pb, mxf->footer_partition_offset); // footerPartition
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1233
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1234 // set offset
3843
b60ab685d415 remove header_byte_count_offset from context
bcoudurier
parents: 3842
diff changeset
1235 header_byte_count_offset = url_ftell(pb);
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1236 put_be64(pb, 0); // headerByteCount, update later
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1237
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1238 // indexTable
4370
6c34e8045dc7 exactly compute index byte count
bcoudurier
parents: 4363
diff changeset
1239 put_be64(pb, index_byte_count); // indexByteCount
4439
4bc3b8687ec2 compute index byte count in mxf_write_partition
bcoudurier
parents: 4438
diff changeset
1240 put_be32(pb, index_byte_count ? indexsid : 0); // indexSID
4440
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1241
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1242 // BodyOffset
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1243 if (bodysid && mxf->edit_units_count && mxf->body_partitions_count) {
4481
27fd3af46000 compute body offset and index entry offset correctly
bcoudurier
parents: 4478
diff changeset
1244 put_be64(pb, mxf->body_offset);
4445
f38371d76e4e fix body offset
bcoudurier
parents: 4442
diff changeset
1245 } else
f38371d76e4e fix body offset
bcoudurier
parents: 4442
diff changeset
1246 put_be64(pb, 0);
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1247
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1248 put_be32(pb, bodysid); // bodySID
4430
d6fe53c5c8d2 correctly set multi track operational pattern
bcoudurier
parents: 4426
diff changeset
1249
d6fe53c5c8d2 correctly set multi track operational pattern
bcoudurier
parents: 4426
diff changeset
1250 // operational pattern
4536
b94bedbb59d7 always use multi track since timecode track is present
bcoudurier
parents: 4535
diff changeset
1251 put_buffer(pb, op1a_ul, 16);
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1252
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1253 // essence container
3821
7a1f6dd123a9 simplify mxf_write_essence_container_refs
bcoudurier
parents: 3820
diff changeset
1254 mxf_write_essence_container_refs(s);
3842
c4e0e02a4832 simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents: 3841
diff changeset
1255
c4e0e02a4832 simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents: 3841
diff changeset
1256 if (write_metadata) {
c4e0e02a4832 simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents: 3841
diff changeset
1257 // mark the start of the headermetadata and calculate metadata size
4433
7ab5a6c4616b fix header byte count
bcoudurier
parents: 4432
diff changeset
1258 int64_t pos, start;
4393
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
1259 unsigned header_byte_count;
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
1260
4432
f8ba6cf226e7 move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents: 4431
diff changeset
1261 mxf_write_klv_fill(s);
4433
7ab5a6c4616b fix header byte count
bcoudurier
parents: 4432
diff changeset
1262 start = url_ftell(s->pb);
3842
c4e0e02a4832 simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents: 3841
diff changeset
1263 mxf_write_primer_pack(s);
c4e0e02a4832 simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents: 3841
diff changeset
1264 mxf_write_header_metadata_sets(s);
c4e0e02a4832 simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents: 3841
diff changeset
1265 pos = url_ftell(s->pb);
4397
6d1626886974 only use 2 slices for index, one video(vbr) and one audio(cbr)
bcoudurier
parents: 4396
diff changeset
1266 header_byte_count = pos - start + klv_fill_size(pos);
4393
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
1267
3842
c4e0e02a4832 simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents: 3841
diff changeset
1268 // update header_byte_count
3843
b60ab685d415 remove header_byte_count_offset from context
bcoudurier
parents: 3842
diff changeset
1269 url_fseek(pb, header_byte_count_offset, SEEK_SET);
4393
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
1270 put_be64(pb, header_byte_count);
3842
c4e0e02a4832 simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents: 3841
diff changeset
1271 url_fseek(pb, pos, SEEK_SET);
c4e0e02a4832 simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents: 3841
diff changeset
1272 }
c4e0e02a4832 simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents: 3841
diff changeset
1273
c4e0e02a4832 simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents: 3841
diff changeset
1274 put_flush_packet(pb);
3760
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1275 }
fde28855a81e Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents: 3759
diff changeset
1276
3833
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1277 static const UID mxf_mpeg2_codec_uls[] = {
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1278 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x10,0x00 }, // MP-ML I-Frame
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1279 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x11,0x00 }, // MP-ML Long GOP
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1280 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x02,0x00 }, // 422P-ML I-Frame
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1281 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x03,0x00 }, // 422P-ML Long GOP
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1282 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x02,0x00 }, // MP-HL I-Frame
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1283 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x03,0x00 }, // MP-HL Long GOP
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1284 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x02,0x00 }, // 422P-HL I-Frame
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1285 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x03,0x00 }, // 422P-HL Long GOP
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1286 };
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1287
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1288 static const UID *mxf_get_mpeg2_codec_ul(AVCodecContext *avctx)
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1289 {
5093
d4cce49ac1f1 fix and simplify long gop mpeg codec ul computation
bcoudurier
parents: 5092
diff changeset
1290 int long_gop = avctx->gop_size > 1 || avctx->has_b_frames;
d4cce49ac1f1 fix and simplify long gop mpeg codec ul computation
bcoudurier
parents: 5092
diff changeset
1291
3833
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1292 if (avctx->profile == 4) { // Main
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1293 if (avctx->level == 8) // Main
5093
d4cce49ac1f1 fix and simplify long gop mpeg codec ul computation
bcoudurier
parents: 5092
diff changeset
1294 return &mxf_mpeg2_codec_uls[0+long_gop];
3833
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1295 else if (avctx->level == 4) // High
5093
d4cce49ac1f1 fix and simplify long gop mpeg codec ul computation
bcoudurier
parents: 5092
diff changeset
1296 return &mxf_mpeg2_codec_uls[4+long_gop];
3833
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1297 } else if (avctx->profile == 0) { // 422
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1298 if (avctx->level == 5) // Main
5093
d4cce49ac1f1 fix and simplify long gop mpeg codec ul computation
bcoudurier
parents: 5092
diff changeset
1299 return &mxf_mpeg2_codec_uls[2+long_gop];
3833
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1300 else if (avctx->level == 2) // High
5093
d4cce49ac1f1 fix and simplify long gop mpeg codec ul computation
bcoudurier
parents: 5092
diff changeset
1301 return &mxf_mpeg2_codec_uls[6+long_gop];
3833
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1302 }
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1303 return NULL;
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1304 }
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1305
4437
9cb07916bf47 retrieve flags from mxf_parse_mpeg2_frame using a param
bcoudurier
parents: 4436
diff changeset
1306 static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt, int *flags)
4313
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1307 {
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1308 MXFStreamContext *sc = st->priv_data;
4449
aaae79b414f3 parse mpeg2 gop header time code and use it
bcoudurier
parents: 4448
diff changeset
1309 MXFContext *mxf = s->priv_data;
4313
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1310 uint32_t c = -1;
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1311 int i;
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1312
4437
9cb07916bf47 retrieve flags from mxf_parse_mpeg2_frame using a param
bcoudurier
parents: 4436
diff changeset
1313 *flags = 0;
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1314
4313
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1315 for(i = 0; i < pkt->size - 4; i++) {
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1316 c = (c<<8) + pkt->data[i];
5081
56f6b1d56db9 cosmetics, change case and comments alignment
bcoudurier
parents: 5080
diff changeset
1317 if (c == 0x1b5) {
4938
d7c5a47fe9c2 remove unneeded length checks
bcoudurier
parents: 4716
diff changeset
1318 if ((pkt->data[i+1] & 0xf0) == 0x10) { // seq ext
4313
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1319 st->codec->profile = pkt->data[i+1] & 0x07;
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1320 st->codec->level = pkt->data[i+2] >> 4;
4314
dfa0afd806c5 parse mpeg2 progressive frame flag
bcoudurier
parents: 4313
diff changeset
1321 } else if (i + 5 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x80) { // pict coding ext
dfa0afd806c5 parse mpeg2 progressive frame flag
bcoudurier
parents: 4313
diff changeset
1322 sc->interlaced = !(pkt->data[i+5] & 0x80); // progressive frame
4313
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1323 break;
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1324 }
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1325 } else if (c == 0x1b8) { // gop
5080
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
1326 if (pkt->data[i+4]>>6 & 0x01) { // closed
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
1327 sc->closed_gop = 1;
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
1328 if (*flags & 0x40) // sequence header present
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
1329 *flags |= 0x80; // random access
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
1330 }
4939
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1331 if (!mxf->header_written) {
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1332 unsigned hours = (pkt->data[i+1]>>2) & 0x1f;
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1333 unsigned minutes = ((pkt->data[i+1] & 0x03) << 4) | (pkt->data[i+2]>>4);
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1334 unsigned seconds = ((pkt->data[i+2] & 0x07) << 3) | (pkt->data[i+3]>>5);
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1335 unsigned frames = ((pkt->data[i+3] & 0x1f) << 1) | (pkt->data[i+4]>>7);
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1336 mxf->timecode_drop_frame = !!(pkt->data[i+1] & 0x80);
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1337 mxf->timecode_start = (hours*3600 + minutes*60 + seconds) *
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1338 mxf->timecode_base + frames;
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1339 if (mxf->timecode_drop_frame) {
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1340 unsigned tminutes = 60 * hours + minutes;
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1341 mxf->timecode_start -= 2 * (tminutes - tminutes / 10);
4449
aaae79b414f3 parse mpeg2 gop header time code and use it
bcoudurier
parents: 4448
diff changeset
1342 }
4939
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1343 av_log(s, AV_LOG_DEBUG, "frame %d %d:%d:%d%c%d\n", mxf->timecode_start,
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1344 hours, minutes, seconds, mxf->timecode_drop_frame ? ';':':', frames);
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1345 }
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1346 } else if (c == 0x1b3) { // seq
4437
9cb07916bf47 retrieve flags from mxf_parse_mpeg2_frame using a param
bcoudurier
parents: 4436
diff changeset
1347 *flags |= 0x40;
4939
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1348 switch ((pkt->data[i+4]>>4) & 0xf) {
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1349 case 2: sc->aspect_ratio = (AVRational){ 4, 3}; break;
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1350 case 3: sc->aspect_ratio = (AVRational){ 16, 9}; break;
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1351 case 4: sc->aspect_ratio = (AVRational){221,100}; break;
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1352 default:
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1353 av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den,
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1354 st->codec->width, st->codec->height, 1024*1024);
d10d934600db reindent
bcoudurier
parents: 4938
diff changeset
1355 }
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1356 } else if (c == 0x100) { // pic
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1357 int pict_type = (pkt->data[i+2]>>3) & 0x07;
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1358 if (pict_type == 2) { // P frame
4437
9cb07916bf47 retrieve flags from mxf_parse_mpeg2_frame using a param
bcoudurier
parents: 4436
diff changeset
1359 *flags |= 0x22;
5080
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
1360 sc->closed_gop = 0; // reset closed gop, don't matter anymore
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1361 } else if (pict_type == 3) { // B frame
5080
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
1362 if (sc->closed_gop)
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
1363 *flags |= 0x13; // only backward prediction
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
1364 else
7c69c9335983 correctly compute frame flags with closed gop
bcoudurier
parents: 4950
diff changeset
1365 *flags |= 0x33;
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1366 sc->temporal_reordering = -1;
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1367 } else if (!pict_type) {
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1368 av_log(s, AV_LOG_ERROR, "error parsing mpeg2 frame\n");
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1369 return 0;
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1370 }
4313
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1371 }
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1372 }
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1373 if (s->oformat != &mxf_d10_muxer)
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1374 sc->codec_ul = mxf_get_mpeg2_codec_ul(st->codec);
4313
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1375 return !!sc->codec_ul;
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1376 }
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1377
4385
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
1378 static uint64_t mxf_parse_timestamp(time_t timestamp)
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
1379 {
4716
7c99a46b3f3d use utc time for timestamp and do not set it if not specified
bcoudurier
parents: 4713
diff changeset
1380 struct tm *time = gmtime(&timestamp);
4385
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
1381 return (uint64_t)(time->tm_year+1900) << 48 |
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
1382 (uint64_t)(time->tm_mon+1) << 40 |
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
1383 (uint64_t) time->tm_mday << 32 |
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
1384 time->tm_hour << 24 |
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
1385 time->tm_min << 16 |
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
1386 time->tm_sec << 8;
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
1387 }
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
1388
4696
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1389 static void mxf_gen_umid(AVFormatContext *s)
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1390 {
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1391 MXFContext *mxf = s->priv_data;
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1392 uint32_t seed = ff_random_get_seed();
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1393 uint64_t umid = seed + 0x5294713400000000LL;
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1394
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1395 AV_WB64(mxf->umid , umid);
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1396 AV_WB64(mxf->umid+8, umid>>8);
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1397
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1398 mxf->instance_number = seed;
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1399 }
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1400
3836
778af58056b6 cosmetics, mux_write -> mxf_write
bcoudurier
parents: 3835
diff changeset
1401 static int mxf_write_header(AVFormatContext *s)
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
1402 {
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
1403 MXFContext *mxf = s->priv_data;
3846
0ee95f0b4c00 store index in table in MXFStreamContext, simplify
bcoudurier
parents: 3845
diff changeset
1404 int i;
4001
fcb9de59245f uses FF_ARRAY_ELEMS() where appropriate
aurel
parents: 3908
diff changeset
1405 uint8_t present[FF_ARRAY_ELEMS(mxf_essence_container_uls)] = {0};
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1406 const int *samples_per_frame = NULL;
3816
50bdbde13ecf move per track code in mxf_write_header to be able to check for unsupported configuration
bcoudurier
parents: 3815
diff changeset
1407
4696
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1408 if (!s->nb_streams)
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1409 return -1;
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1410
3816
50bdbde13ecf move per track code in mxf_write_header to be able to check for unsupported configuration
bcoudurier
parents: 3815
diff changeset
1411 for (i = 0; i < s->nb_streams; i++) {
50bdbde13ecf move per track code in mxf_write_header to be able to check for unsupported configuration
bcoudurier
parents: 3815
diff changeset
1412 AVStream *st = s->streams[i];
3824
f1270349f49f replace sizeof(type) by sizeof *ptr
bcoudurier
parents: 3823
diff changeset
1413 MXFStreamContext *sc = av_mallocz(sizeof(*sc));
3816
50bdbde13ecf move per track code in mxf_write_header to be able to check for unsupported configuration
bcoudurier
parents: 3815
diff changeset
1414 if (!sc)
50bdbde13ecf move per track code in mxf_write_header to be able to check for unsupported configuration
bcoudurier
parents: 3815
diff changeset
1415 return AVERROR(ENOMEM);
50bdbde13ecf move per track code in mxf_write_header to be able to check for unsupported configuration
bcoudurier
parents: 3815
diff changeset
1416 st->priv_data = sc;
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1417
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1418 if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
4396
a34ee37a164e force first track to be video and simplify
bcoudurier
parents: 4395
diff changeset
1419 if (i != 0) {
a34ee37a164e force first track to be video and simplify
bcoudurier
parents: 4395
diff changeset
1420 av_log(s, AV_LOG_ERROR, "video stream must be first track\n");
a34ee37a164e force first track to be video and simplify
bcoudurier
parents: 4395
diff changeset
1421 return -1;
a34ee37a164e force first track to be video and simplify
bcoudurier
parents: 4395
diff changeset
1422 }
4363
8142fb82cd75 be more flexible with frame rate check
bcoudurier
parents: 4351
diff changeset
1423 if (fabs(av_q2d(st->codec->time_base) - 1/25.0) < 0.0001) {
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1424 samples_per_frame = PAL_samples_per_frame;
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1425 mxf->time_base = (AVRational){ 1, 25 };
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
1426 mxf->timecode_base = 25;
4363
8142fb82cd75 be more flexible with frame rate check
bcoudurier
parents: 4351
diff changeset
1427 } else if (fabs(av_q2d(st->codec->time_base) - 1001/30000.0) < 0.0001) {
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1428 samples_per_frame = NTSC_samples_per_frame;
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1429 mxf->time_base = (AVRational){ 1001, 30000 };
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
1430 mxf->timecode_base = 30;
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1431 } else {
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1432 av_log(s, AV_LOG_ERROR, "unsupported video frame rate\n");
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1433 return -1;
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1434 }
4374
1664a812629f use sample rate as audio input time base
bcoudurier
parents: 4370
diff changeset
1435 av_set_pts_info(st, 64, mxf->time_base.num, mxf->time_base.den);
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1436 if (s->oformat == &mxf_d10_muxer) {
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1437 if (st->codec->bit_rate == 50000000)
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1438 if (mxf->time_base.den == 25) sc->index = 3;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1439 else sc->index = 5;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1440 else if (st->codec->bit_rate == 40000000)
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1441 if (mxf->time_base.den == 25) sc->index = 7;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1442 else sc->index = 9;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1443 else if (st->codec->bit_rate == 30000000)
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1444 if (mxf->time_base.den == 25) sc->index = 11;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1445 else sc->index = 13;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1446 else {
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1447 av_log(s, AV_LOG_ERROR, "error MXF D-10 only support 30/40/50 mbit/s\n");
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1448 return -1;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1449 }
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1450
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1451 mxf->edit_unit_byte_count = KAG_SIZE; // system element
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1452 mxf->edit_unit_byte_count += 16 + 4 + (uint64_t)st->codec->bit_rate *
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1453 mxf->time_base.num / (8*mxf->time_base.den);
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1454 mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count);
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1455 mxf->edit_unit_byte_count += 16 + 4 + 4 + samples_per_frame[0]*8*4;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1456 mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count);
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1457 }
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1458 } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1459 if (st->codec->sample_rate != 48000) {
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1460 av_log(s, AV_LOG_ERROR, "only 48khz is implemented\n");
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1461 return -1;
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1462 }
4374
1664a812629f use sample rate as audio input time base
bcoudurier
parents: 4370
diff changeset
1463 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1464 if (s->oformat == &mxf_d10_muxer) {
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1465 if (st->index != 1) {
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1466 av_log(s, AV_LOG_ERROR, "MXF D-10 only support one audio track\n");
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1467 return -1;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1468 }
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1469 if (st->codec->codec_id != CODEC_ID_PCM_S16LE &&
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1470 st->codec->codec_id != CODEC_ID_PCM_S24LE) {
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1471 av_log(s, AV_LOG_ERROR, "MXF D-10 only support 16 or 24 bits le audio\n");
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1472 }
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1473 sc->index = ((MXFStreamContext*)s->streams[0]->priv_data)->index + 1;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1474 } else
4397
6d1626886974 only use 2 slices for index, one video(vbr) and one audio(cbr)
bcoudurier
parents: 4396
diff changeset
1475 mxf->slice_count = 1;
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1476 }
3834
d49f55ab650c set duration to distinguished value
bcoudurier
parents: 3833
diff changeset
1477
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1478 if (!sc->index) {
4474
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1479 sc->index = mxf_get_essence_container_ul_index(st->codec->codec_id);
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1480 if (sc->index == -1) {
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1481 av_log(s, AV_LOG_ERROR, "track %d: could not find essence container ul, "
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1482 "codec not currently supported in container\n", i);
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1483 return -1;
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1484 }
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1485 }
3833
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1486
4313
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1487 sc->codec_ul = &mxf_essence_container_uls[sc->index].codec_ul;
3833
8b3fdbc81f3e correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents: 3832
diff changeset
1488
3846
0ee95f0b4c00 store index in table in MXFStreamContext, simplify
bcoudurier
parents: 3845
diff changeset
1489 memcpy(sc->track_essence_element_key, mxf_essence_container_uls[sc->index].element_ul, 15);
0ee95f0b4c00 store index in table in MXFStreamContext, simplify
bcoudurier
parents: 3845
diff changeset
1490 sc->track_essence_element_key[15] = present[sc->index];
3826
da2d0c162cde introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents: 3825
diff changeset
1491 PRINT_KEY(s, "track essence element key", sc->track_essence_element_key);
4533
23ec193c3e0a start counting track number from 0
bcoudurier
parents: 4532
diff changeset
1492
23ec193c3e0a start counting track number from 0
bcoudurier
parents: 4532
diff changeset
1493 if (!present[sc->index])
23ec193c3e0a start counting track number from 0
bcoudurier
parents: 4532
diff changeset
1494 mxf->essence_container_count++;
23ec193c3e0a start counting track number from 0
bcoudurier
parents: 4532
diff changeset
1495 present[sc->index]++;
3816
50bdbde13ecf move per track code in mxf_write_header to be able to check for unsupported configuration
bcoudurier
parents: 3815
diff changeset
1496 }
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
1497
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1498 if (s->oformat == &mxf_d10_muxer) {
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1499 mxf->essence_container_count = 1;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1500 }
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1501
4716
7c99a46b3f3d use utc time for timestamp and do not set it if not specified
bcoudurier
parents: 4713
diff changeset
1502 if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
4696
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1503 mxf_gen_umid(s);
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1504
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1505 for (i = 0; i < s->nb_streams; i++) {
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1506 MXFStreamContext *sc = s->streams[i]->priv_data;
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1507 // update element count
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1508 sc->track_essence_element_key[13] = present[sc->index];
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1509 sc->order = AV_RB32(sc->track_essence_element_key+12);
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1510 }
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1511
4716
7c99a46b3f3d use utc time for timestamp and do not set it if not specified
bcoudurier
parents: 4713
diff changeset
1512 if (s->timestamp)
7c99a46b3f3d use utc time for timestamp and do not set it if not specified
bcoudurier
parents: 4713
diff changeset
1513 mxf->timestamp = mxf_parse_timestamp(s->timestamp);
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
1514 mxf->duration = -1;
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
1515
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
1516 mxf->timecode_track = av_mallocz(sizeof(*mxf->timecode_track));
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
1517 if (!mxf->timecode_track)
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
1518 return AVERROR(ENOMEM);
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
1519 mxf->timecode_track->priv_data = av_mallocz(sizeof(MXFStreamContext));
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
1520 if (!mxf->timecode_track->priv_data)
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
1521 return AVERROR(ENOMEM);
4529
ade95792aa16 use index 0 for timecode track and write it in source package also
bcoudurier
parents: 4528
diff changeset
1522 mxf->timecode_track->index = -1;
4385
e8e064a00ea5 format timestamp correctly according to specs and set it
bcoudurier
parents: 4384
diff changeset
1523
4327
60bad0ded22a do not use PAL_samples_per_frame in init, to make init independant
bcoudurier
parents: 4326
diff changeset
1524 if (!samples_per_frame)
60bad0ded22a do not use PAL_samples_per_frame in init, to make init independant
bcoudurier
parents: 4326
diff changeset
1525 samples_per_frame = PAL_samples_per_frame;
60bad0ded22a do not use PAL_samples_per_frame in init, to make init independant
bcoudurier
parents: 4326
diff changeset
1526
4374
1664a812629f use sample rate as audio input time base
bcoudurier
parents: 4370
diff changeset
1527 if (ff_audio_interleave_init(s, samples_per_frame, mxf->time_base) < 0)
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1528 return -1;
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1529
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
1530 return 0;
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
1531 }
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
1532
4395
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1533 static const uint8_t system_metadata_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x03,0x01,0x04,0x01,0x01,0x00 };
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1534 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 };
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1535
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1536 static uint32_t ff_framenum_to_12m_time_code(unsigned frame, int drop, int fps)
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1537 {
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1538 return (0 << 31) | // color frame flag
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1539 (0 << 30) | // drop frame flag
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1540 ( ((frame % fps) / 10) << 28) | // tens of frames
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1541 ( ((frame % fps) % 10) << 24) | // units of frames
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1542 (0 << 23) | // field phase (NTSC), b0 (PAL)
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1543 ((((frame / fps) % 60) / 10) << 20) | // tens of seconds
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1544 ((((frame / fps) % 60) % 10) << 16) | // units of seconds
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1545 (0 << 15) | // b0 (NTSC), b2 (PAL)
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1546 ((((frame / (fps * 60)) % 60) / 10) << 12) | // tens of minutes
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1547 ((((frame / (fps * 60)) % 60) % 10) << 8) | // units of minutes
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1548 (0 << 7) | // b1
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1549 (0 << 6) | // b2 (NSC), field phase (PAL)
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1550 ((((frame / (fps * 3600) % 24)) / 10) << 4) | // tens of hours
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1551 ( (frame / (fps * 3600) % 24)) % 10; // units of hours
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1552 }
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1553
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1554 static void mxf_write_system_item(AVFormatContext *s)
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1555 {
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1556 MXFContext *mxf = s->priv_data;
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1557 ByteIOContext *pb = s->pb;
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
1558 unsigned frame;
4395
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1559 uint32_t time_code;
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1560
4449
aaae79b414f3 parse mpeg2 gop header time code and use it
bcoudurier
parents: 4448
diff changeset
1561 frame = mxf->timecode_start + mxf->last_indexed_edit_unit + mxf->edit_units_count;
4395
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1562
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1563 // write system metadata pack
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1564 put_buffer(pb, system_metadata_pack_key, 16);
4470
1c6dd9d7a634 write essence elements klv packets with ber4 length, more interoperable
bcoudurier
parents: 4469
diff changeset
1565 klv_encode_ber4_length(pb, 57);
4395
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1566 put_byte(pb, 0x5c); // UL, user date/time stamp, picture and sound item present
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1567 put_byte(pb, 0x04); // content package rate
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1568 put_byte(pb, 0x00); // content package type
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1569 put_be16(pb, 0x00); // channel handle
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1570 put_be16(pb, frame); // continuity count
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1571 if (mxf->essence_container_count > 1)
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1572 put_buffer(pb, multiple_desc_ul, 16);
4475
fc3806848a49 simplify
bcoudurier
parents: 4474
diff changeset
1573 else {
fc3806848a49 simplify
bcoudurier
parents: 4474
diff changeset
1574 MXFStreamContext *sc = s->streams[0]->priv_data;
fc3806848a49 simplify
bcoudurier
parents: 4474
diff changeset
1575 put_buffer(pb, mxf_essence_container_uls[sc->index].container_ul, 16);
fc3806848a49 simplify
bcoudurier
parents: 4474
diff changeset
1576 }
4395
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1577 put_byte(pb, 0);
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1578 put_be64(pb, 0);
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1579 put_be64(pb, 0); // creation date/time stamp
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1580
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1581 put_byte(pb, 0x81); // SMPTE 12M time code
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
1582 time_code = ff_framenum_to_12m_time_code(frame, mxf->timecode_drop_frame, mxf->timecode_base);
4395
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1583 put_be32(pb, time_code);
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1584 put_be32(pb, 0); // binary group data
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1585 put_be64(pb, 0);
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1586
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1587 // write system metadata package set
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1588 put_buffer(pb, system_metadata_package_set_key, 16);
4470
1c6dd9d7a634 write essence elements klv packets with ber4 length, more interoperable
bcoudurier
parents: 4469
diff changeset
1589 klv_encode_ber4_length(pb, 35);
4395
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1590 put_byte(pb, 0x83); // UMID
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1591 put_be16(pb, 0x20);
4696
ee1ca2a4e43f attempt to try to generate an random umid
bcoudurier
parents: 4574
diff changeset
1592 mxf_write_umid(s, 1);
4395
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1593 }
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1594
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1595 static void mxf_write_d10_video_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt)
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1596 {
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1597 MXFContext *mxf = s->priv_data;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1598 ByteIOContext *pb = s->pb;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1599 int packet_size = (uint64_t)st->codec->bit_rate*mxf->time_base.num /
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1600 (8*mxf->time_base.den); // frame size
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1601 int pad;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1602
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1603 packet_size += 16 + 4;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1604 packet_size += klv_fill_size(packet_size);
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1605
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1606 klv_encode_ber4_length(pb, pkt->size);
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1607 put_buffer(pb, pkt->data, pkt->size);
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1608
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1609 // ensure CBR muxing by padding to correct video frame size
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1610 pad = packet_size - pkt->size - 16 - 4;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1611 if (pad > 20) {
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1612 put_buffer(s->pb, klv_fill_key, 16);
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1613 pad -= 16 + 4;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1614 klv_encode_ber4_length(s->pb, pad);
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1615 for (; pad; pad--)
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1616 put_byte(s->pb, 0);
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1617 assert(!(url_ftell(s->pb) & (KAG_SIZE-1)));
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1618 } else {
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1619 av_log(s, AV_LOG_WARNING, "cannot fill d-10 video packet\n");
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1620 for (; pad > 0; pad--)
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1621 put_byte(s->pb, 0);
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1622 }
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1623 }
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1624
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1625 static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt)
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1626 {
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1627 MXFContext *mxf = s->priv_data;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1628 ByteIOContext *pb = s->pb;
4573
3e1796a40c4d simplify, use codec->block_align
bcoudurier
parents: 4572
diff changeset
1629 int frame_size = pkt->size / st->codec->block_align;
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1630 uint8_t *samples = pkt->data;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1631 uint8_t *end = pkt->data + pkt->size;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1632 int i;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1633
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1634 klv_encode_ber4_length(pb, 4 + frame_size*4*8);
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1635
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1636 put_byte(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1));
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1637 put_le16(pb, frame_size);
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1638 put_byte(pb, (1<<st->codec->channels)-1);
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1639
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1640 while (samples < end) {
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1641 for (i = 0; i < st->codec->channels; i++) {
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1642 uint32_t sample;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1643 if (st->codec->codec_id == CODEC_ID_PCM_S24LE) {
4571
d870b1e4b731 do not set frame start bit since marked as not used and factorize
bcoudurier
parents: 4565
diff changeset
1644 sample = AV_RL24(samples)<< 4;
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1645 samples += 3;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1646 } else {
4571
d870b1e4b731 do not set frame start bit since marked as not used and factorize
bcoudurier
parents: 4565
diff changeset
1647 sample = AV_RL16(samples)<<12;
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1648 samples += 2;
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1649 }
4571
d870b1e4b731 do not set frame start bit since marked as not used and factorize
bcoudurier
parents: 4565
diff changeset
1650 put_le32(pb, sample | i);
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1651 }
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1652 for (; i < 8; i++)
4572
f3b6979fee40 set channel number even for inactive channels
bcoudurier
parents: 4571
diff changeset
1653 put_le32(pb, i);
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1654 }
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1655 }
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1656
3836
778af58056b6 cosmetics, mux_write -> mxf_write
bcoudurier
parents: 3835
diff changeset
1657 static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt)
3778
85d3aca03313 Import more MXF muxer code from the SoC tree
vitor
parents: 3760
diff changeset
1658 {
4313
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1659 MXFContext *mxf = s->priv_data;
3778
85d3aca03313 Import more MXF muxer code from the SoC tree
vitor
parents: 3760
diff changeset
1660 ByteIOContext *pb = s->pb;
85d3aca03313 Import more MXF muxer code from the SoC tree
vitor
parents: 3760
diff changeset
1661 AVStream *st = s->streams[pkt->stream_index];
85d3aca03313 Import more MXF muxer code from the SoC tree
vitor
parents: 3760
diff changeset
1662 MXFStreamContext *sc = st->priv_data;
4437
9cb07916bf47 retrieve flags from mxf_parse_mpeg2_frame using a param
bcoudurier
parents: 4436
diff changeset
1663 int flags = 0;
3778
85d3aca03313 Import more MXF muxer code from the SoC tree
vitor
parents: 3760
diff changeset
1664
4504
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1665 if (!mxf->edit_unit_byte_count && !(mxf->edit_units_count % EDIT_UNITS_PER_BODY)) {
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1666 mxf->index_entries = av_realloc(mxf->index_entries,
4440
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1667 (mxf->edit_units_count + EDIT_UNITS_PER_BODY)*sizeof(*mxf->index_entries));
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1668 if (!mxf->index_entries) {
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1669 av_log(s, AV_LOG_ERROR, "could not allocate index entries\n");
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1670 return -1;
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1671 }
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1672 }
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1673
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1674 if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO) {
4437
9cb07916bf47 retrieve flags from mxf_parse_mpeg2_frame using a param
bcoudurier
parents: 4436
diff changeset
1675 if (!mxf_parse_mpeg2_frame(s, st, pkt, &flags)) {
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1676 av_log(s, AV_LOG_ERROR, "could not get mpeg2 profile and level\n");
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1677 return -1;
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1678 }
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1679 }
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1680
4313
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1681 if (!mxf->header_written) {
4504
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1682 if (mxf->edit_unit_byte_count) {
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1683 mxf_write_partition(s, 1, 2, header_open_partition_key, 1);
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1684 mxf_write_klv_fill(s);
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1685 mxf_write_index_table_segment(s);
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1686 } else {
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1687 mxf_write_partition(s, 0, 0, header_open_partition_key, 1);
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1688 }
4313
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1689 mxf->header_written = 1;
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1690 }
bdb984bfa3ed delay header writing and parse mpeg2 frame
bcoudurier
parents: 4312
diff changeset
1691
4396
a34ee37a164e force first track to be video and simplify
bcoudurier
parents: 4395
diff changeset
1692 if (st->index == 0) {
4504
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1693 if (!mxf->edit_unit_byte_count &&
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1694 (!mxf->edit_units_count || mxf->edit_units_count > EDIT_UNITS_PER_BODY) &&
4440
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1695 !(flags & 0x33)) { // I frame, Gop start
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1696 mxf_write_klv_fill(s);
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1697 mxf_write_partition(s, 1, 2, body_partition_key, 0);
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1698
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1699 mxf_write_klv_fill(s);
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1700 mxf_write_index_table_segment(s);
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1701 }
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1702
4436
98928aca0df9 10l, edit unit offset is after klv fill
bcoudurier
parents: 4435
diff changeset
1703 mxf_write_klv_fill(s);
4395
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1704 mxf_write_system_item(s);
2a72b8b7a69d write system item
bcoudurier
parents: 4393
diff changeset
1705
4504
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1706 if (!mxf->edit_unit_byte_count) {
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1707 mxf->index_entries[mxf->edit_units_count].offset = mxf->body_offset;
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1708 mxf->index_entries[mxf->edit_units_count].flags = flags;
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1709 mxf->body_offset += KAG_SIZE; // size of system element
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1710 }
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1711 mxf->edit_units_count++;
4504
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1712 } else if (!mxf->edit_unit_byte_count && st->index == 1) {
4481
27fd3af46000 compute body offset and index entry offset correctly
bcoudurier
parents: 4478
diff changeset
1713 mxf->index_entries[mxf->edit_units_count-1].slice_offset =
27fd3af46000 compute body offset and index entry offset correctly
bcoudurier
parents: 4478
diff changeset
1714 mxf->body_offset - mxf->index_entries[mxf->edit_units_count-1].offset;
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1715 }
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1716
4435
4f96c60c9561 cosmetics, associate mxf_write_klv_fill to aligned elements
bcoudurier
parents: 4434
diff changeset
1717 mxf_write_klv_fill(s);
3778
85d3aca03313 Import more MXF muxer code from the SoC tree
vitor
parents: 3760
diff changeset
1718 put_buffer(pb, sc->track_essence_element_key, 16); // write key
4504
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1719 if (s->oformat == &mxf_d10_muxer) {
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1720 if (st->codec->codec_type == CODEC_TYPE_VIDEO)
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1721 mxf_write_d10_video_packet(s, st, pkt);
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1722 else
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1723 mxf_write_d10_audio_packet(s, st, pkt);
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1724 } else {
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1725 klv_encode_ber4_length(pb, pkt->size); // write length
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1726 put_buffer(pb, pkt->data, pkt->size);
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1727 mxf->body_offset += 16+4+pkt->size + klv_fill_size(16+4+pkt->size);
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1728 }
3778
85d3aca03313 Import more MXF muxer code from the SoC tree
vitor
parents: 3760
diff changeset
1729
85d3aca03313 Import more MXF muxer code from the SoC tree
vitor
parents: 3760
diff changeset
1730 put_flush_packet(pb);
4481
27fd3af46000 compute body offset and index entry offset correctly
bcoudurier
parents: 4478
diff changeset
1731
3778
85d3aca03313 Import more MXF muxer code from the SoC tree
vitor
parents: 3760
diff changeset
1732 return 0;
85d3aca03313 Import more MXF muxer code from the SoC tree
vitor
parents: 3760
diff changeset
1733 }
85d3aca03313 Import more MXF muxer code from the SoC tree
vitor
parents: 3760
diff changeset
1734
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1735 static void mxf_write_random_index_pack(AVFormatContext *s)
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1736 {
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1737 MXFContext *mxf = s->priv_data;
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1738 ByteIOContext *pb = s->pb;
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1739 uint64_t pos = url_ftell(pb);
4440
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1740 int i;
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1741
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1742 put_buffer(pb, random_index_pack_key, 16);
4440
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1743 klv_encode_ber_length(pb, 28 + 12*mxf->body_partitions_count);
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1744
4528
6495e0111859 fix rip body sid when muxing cbr
bcoudurier
parents: 4527
diff changeset
1745 if (mxf->edit_unit_byte_count)
6495e0111859 fix rip body sid when muxing cbr
bcoudurier
parents: 4527
diff changeset
1746 put_be32(pb, 1); // BodySID of header partition
6495e0111859 fix rip body sid when muxing cbr
bcoudurier
parents: 4527
diff changeset
1747 else
4532
32f00d63e3cd remove redundant comment
bcoudurier
parents: 4531
diff changeset
1748 put_be32(pb, 0);
4440
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1749 put_be64(pb, 0); // offset of header partition
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1750
4440
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1751 for (i = 0; i < mxf->body_partitions_count; i++) {
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1752 put_be32(pb, 1); // BodySID
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1753 put_be64(pb, mxf->body_partition_offset[i]);
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1754 }
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1755
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1756 put_be32(pb, 0); // BodySID of footer partition
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1757 put_be64(pb, mxf->footer_partition_offset);
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1758
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1759 put_be32(pb, url_ftell(pb) - pos + 4);
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1760 }
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1761
3842
c4e0e02a4832 simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents: 3841
diff changeset
1762 static int mxf_write_footer(AVFormatContext *s)
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
1763 {
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
1764 MXFContext *mxf = s->priv_data;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
1765 ByteIOContext *pb = s->pb;
4393
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
1766
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
1767 mxf->duration = mxf->last_indexed_edit_unit + mxf->edit_units_count;
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
1768
4393
87a896580005 use 512 kag size needed for d10
bcoudurier
parents: 4385
diff changeset
1769 mxf_write_klv_fill(s);
3842
c4e0e02a4832 simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents: 3841
diff changeset
1770 mxf->footer_partition_offset = url_ftell(pb);
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1771 if (mxf->edit_unit_byte_count) { // no need to repeat index
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1772 mxf_write_partition(s, 0, 0, footer_partition_key, 0);
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1773 } else {
4474
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1774 mxf_write_partition(s, 0, 2, footer_partition_key, 0);
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1775
4474
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1776 mxf_write_klv_fill(s);
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1777 mxf_write_index_table_segment(s);
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1778 }
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1779
4432
f8ba6cf226e7 move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents: 4431
diff changeset
1780 mxf_write_klv_fill(s);
4341
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1781 mxf_write_random_index_pack(s);
501d1dd19021 write index table and rip, muxer works pretty well now
bcoudurier
parents: 4340
diff changeset
1782
3842
c4e0e02a4832 simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents: 3841
diff changeset
1783 if (!url_is_streamed(s->pb)) {
c4e0e02a4832 simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents: 3841
diff changeset
1784 url_fseek(pb, 0, SEEK_SET);
4504
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1785 if (mxf->edit_unit_byte_count) {
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1786 mxf_write_partition(s, 1, 2, header_closed_partition_key, 1);
4504
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1787 mxf_write_klv_fill(s);
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1788 mxf_write_index_table_segment(s);
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1789 } else {
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1790 mxf_write_partition(s, 0, 0, header_closed_partition_key, 1);
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1791 }
3842
c4e0e02a4832 simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents: 3841
diff changeset
1792 }
4330
f59a2165d042 free audio fifo
bcoudurier
parents: 4328
diff changeset
1793
4530
9ca76e4777db flush pending write in mxf_write_footer
bcoudurier
parents: 4529
diff changeset
1794 put_flush_packet(pb);
9ca76e4777db flush pending write in mxf_write_footer
bcoudurier
parents: 4529
diff changeset
1795
4330
f59a2165d042 free audio fifo
bcoudurier
parents: 4328
diff changeset
1796 ff_audio_interleave_close(s);
f59a2165d042 free audio fifo
bcoudurier
parents: 4328
diff changeset
1797
4402
671d415e1786 free index entries
bcoudurier
parents: 4400
diff changeset
1798 av_freep(&mxf->index_entries);
4440
64f62c9643c3 write body partitions
bcoudurier
parents: 4439
diff changeset
1799 av_freep(&mxf->body_partition_offset);
4448
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
1800 av_freep(&mxf->timecode_track->priv_data);
587ce9359a9b write timecode track
bcoudurier
parents: 4446
diff changeset
1801 av_freep(&mxf->timecode_track);
4402
671d415e1786 free index entries
bcoudurier
parents: 4400
diff changeset
1802
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
1803 mxf_free(s);
4474
cfd03b6fab13 cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents: 4473
diff changeset
1804
3740
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
1805 return 0;
b31821aa2235 Ok-ed parts from patch by zhentan feng.
cehoyos
parents: 3735
diff changeset
1806 }
3749
84ad19dea09f Apply parts of MXF muxer ok'ed by Michael
vitor
parents: 3743
diff changeset
1807
4328
fb0fde31327a change prototype of mxf_interleave_get_packet to make it compatible
bcoudurier
parents: 4327
diff changeset
1808 static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1809 {
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1810 AVPacketList *pktl;
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1811 int stream_count = 0;
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1812 int streams[MAX_STREAMS];
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1813
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1814 memset(streams, 0, sizeof(streams));
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1815 pktl = s->packet_buffer;
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1816 while (pktl) {
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1817 //av_log(s, AV_LOG_DEBUG, "show st:%d dts:%lld\n", pktl->pkt.stream_index, pktl->pkt.dts);
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1818 if (!streams[pktl->pkt.stream_index])
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1819 stream_count++;
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1820 streams[pktl->pkt.stream_index]++;
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1821 pktl = pktl->next;
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1822 }
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1823
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1824 if (stream_count && (s->nb_streams == stream_count || flush)) {
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1825 pktl = s->packet_buffer;
4342
b889db531b8f fix flush and interleaving by edit units
bcoudurier
parents: 4341
diff changeset
1826 if (s->nb_streams != stream_count) {
4461
f21c01140f2d set last packet next pointer to null
bcoudurier
parents: 4460
diff changeset
1827 AVPacketList *last = NULL;
4500
cc4b6d42dcd5 fix mxf interleaving packet purge
bcoudurier
parents: 4481
diff changeset
1828 // find last packet in edit unit
4342
b889db531b8f fix flush and interleaving by edit units
bcoudurier
parents: 4341
diff changeset
1829 while (pktl) {
4500
cc4b6d42dcd5 fix mxf interleaving packet purge
bcoudurier
parents: 4481
diff changeset
1830 if (!stream_count || pktl->pkt.stream_index == 0)
4342
b889db531b8f fix flush and interleaving by edit units
bcoudurier
parents: 4341
diff changeset
1831 break;
4461
f21c01140f2d set last packet next pointer to null
bcoudurier
parents: 4460
diff changeset
1832 last = pktl;
4342
b889db531b8f fix flush and interleaving by edit units
bcoudurier
parents: 4341
diff changeset
1833 pktl = pktl->next;
4500
cc4b6d42dcd5 fix mxf interleaving packet purge
bcoudurier
parents: 4481
diff changeset
1834 stream_count--;
4342
b889db531b8f fix flush and interleaving by edit units
bcoudurier
parents: 4341
diff changeset
1835 }
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1836 // purge packet queue
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1837 while (pktl) {
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1838 AVPacketList *next = pktl->next;
5210
36d130853c9b Improve amortized worst case speed of the muxers packet interleaving code
michael
parents: 5093
diff changeset
1839
36d130853c9b Improve amortized worst case speed of the muxers packet interleaving code
michael
parents: 5093
diff changeset
1840 if(s->streams[pktl->pkt.stream_index]->last_in_packet_buffer == pktl)
36d130853c9b Improve amortized worst case speed of the muxers packet interleaving code
michael
parents: 5093
diff changeset
1841 s->streams[pktl->pkt.stream_index]->last_in_packet_buffer= NULL;
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1842 av_free_packet(&pktl->pkt);
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1843 av_freep(&pktl);
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1844 pktl = next;
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1845 }
4500
cc4b6d42dcd5 fix mxf interleaving packet purge
bcoudurier
parents: 4481
diff changeset
1846 if (last)
cc4b6d42dcd5 fix mxf interleaving packet purge
bcoudurier
parents: 4481
diff changeset
1847 last->next = NULL;
cc4b6d42dcd5 fix mxf interleaving packet purge
bcoudurier
parents: 4481
diff changeset
1848 else {
cc4b6d42dcd5 fix mxf interleaving packet purge
bcoudurier
parents: 4481
diff changeset
1849 s->packet_buffer = NULL;
5210
36d130853c9b Improve amortized worst case speed of the muxers packet interleaving code
michael
parents: 5093
diff changeset
1850 s->packet_buffer_end= NULL;
4342
b889db531b8f fix flush and interleaving by edit units
bcoudurier
parents: 4341
diff changeset
1851 goto out;
4500
cc4b6d42dcd5 fix mxf interleaving packet purge
bcoudurier
parents: 4481
diff changeset
1852 }
cc4b6d42dcd5 fix mxf interleaving packet purge
bcoudurier
parents: 4481
diff changeset
1853 pktl = s->packet_buffer;
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1854 }
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1855
4342
b889db531b8f fix flush and interleaving by edit units
bcoudurier
parents: 4341
diff changeset
1856 *out = pktl->pkt;
b889db531b8f fix flush and interleaving by edit units
bcoudurier
parents: 4341
diff changeset
1857 //av_log(s, AV_LOG_DEBUG, "out st:%d dts:%lld\n", (*out).stream_index, (*out).dts);
b889db531b8f fix flush and interleaving by edit units
bcoudurier
parents: 4341
diff changeset
1858 s->packet_buffer = pktl->next;
5210
36d130853c9b Improve amortized worst case speed of the muxers packet interleaving code
michael
parents: 5093
diff changeset
1859 if(s->streams[pktl->pkt.stream_index]->last_in_packet_buffer == pktl)
36d130853c9b Improve amortized worst case speed of the muxers packet interleaving code
michael
parents: 5093
diff changeset
1860 s->streams[pktl->pkt.stream_index]->last_in_packet_buffer= NULL;
36d130853c9b Improve amortized worst case speed of the muxers packet interleaving code
michael
parents: 5093
diff changeset
1861 if(!s->packet_buffer)
36d130853c9b Improve amortized worst case speed of the muxers packet interleaving code
michael
parents: 5093
diff changeset
1862 s->packet_buffer_end= NULL;
4342
b889db531b8f fix flush and interleaving by edit units
bcoudurier
parents: 4341
diff changeset
1863 av_freep(&pktl);
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1864 return 1;
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1865 } else {
4342
b889db531b8f fix flush and interleaving by edit units
bcoudurier
parents: 4341
diff changeset
1866 out:
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1867 av_init_packet(out);
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1868 return 0;
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1869 }
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1870 }
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1871
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1872 static int mxf_compare_timestamps(AVFormatContext *s, AVPacket *next, AVPacket *pkt)
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1873 {
4374
1664a812629f use sample rate as audio input time base
bcoudurier
parents: 4370
diff changeset
1874 MXFStreamContext *sc = s->streams[pkt ->stream_index]->priv_data;
1664a812629f use sample rate as audio input time base
bcoudurier
parents: 4370
diff changeset
1875 MXFStreamContext *sc2 = s->streams[next->stream_index]->priv_data;
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1876
4374
1664a812629f use sample rate as audio input time base
bcoudurier
parents: 4370
diff changeset
1877 return next->dts > pkt->dts ||
1664a812629f use sample rate as audio input time base
bcoudurier
parents: 4370
diff changeset
1878 (next->dts == pkt->dts && sc->order < sc2->order);
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1879 }
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1880
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1881 static int mxf_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1882 {
4426
7854590fb1fd rename ff_audio_interleave to ff_audio_rechunk_interleave
bcoudurier
parents: 4408
diff changeset
1883 return ff_audio_rechunk_interleave(s, out, pkt, flush,
4400
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents: 4397
diff changeset
1884 mxf_interleave_get_packet, mxf_compare_timestamps);
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1885 }
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1886
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
1887 AVOutputFormat mxf_muxer = {
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
1888 "mxf",
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
1889 NULL_IF_CONFIG_SMALL("Material eXchange Format"),
4476
b9d03c68660b set mime type for mxf
bcoudurier
parents: 4475
diff changeset
1890 "application/mxf",
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
1891 "mxf",
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
1892 sizeof(MXFContext),
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
1893 CODEC_ID_PCM_S16LE,
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
1894 CODEC_ID_MPEG2VIDEO,
3836
778af58056b6 cosmetics, mux_write -> mxf_write
bcoudurier
parents: 3835
diff changeset
1895 mxf_write_header,
778af58056b6 cosmetics, mux_write -> mxf_write
bcoudurier
parents: 3835
diff changeset
1896 mxf_write_packet,
778af58056b6 cosmetics, mux_write -> mxf_write
bcoudurier
parents: 3835
diff changeset
1897 mxf_write_footer,
4350
b7fdb211ba7b mxf does not have timestamps
bcoudurier
parents: 4346
diff changeset
1898 AVFMT_NOTIMESTAMPS,
4312
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1899 NULL,
385b2fdccbbb correctly pack and interleave pcm samples in mxf
bcoudurier
parents: 4279
diff changeset
1900 mxf_interleave,
3721
caecb9f780a1 import ok'd hunks for mxf muxer
bcoudurier
parents:
diff changeset
1901 };
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1902
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1903 AVOutputFormat mxf_d10_muxer = {
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1904 "mxf_d10",
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1905 NULL_IF_CONFIG_SMALL("Material eXchange Format, D-10 Mapping"),
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1906 "application/mxf",
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1907 NULL,
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1908 sizeof(MXFContext),
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1909 CODEC_ID_PCM_S16LE,
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1910 CODEC_ID_MPEG2VIDEO,
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1911 mxf_write_header,
4504
c0803ee07a93 merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents: 4500
diff changeset
1912 mxf_write_packet,
4473
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1913 mxf_write_footer,
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1914 AVFMT_NOTIMESTAMPS,
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1915 NULL,
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1916 mxf_interleave,
9eedb6599102 MXF D-10 muxer
bcoudurier
parents: 4472
diff changeset
1917 };