annotate gxfenc.c @ 6118:6780dc315f36 libavformat

Remove support for pre-Haiku, non-POSIX, non-C99 BeOS variants. BeOS support has been broken for many years and the "maintainer" of the port has not reacted to countless requests to get the port fixed. approved by Mans
author diego
date Thu, 10 Jun 2010 16:51:14 +0000
parents 536e5527c1e0
children e8dfc68ad182
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
1 /*
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
2 * GXF muxer.
4251
77e0c7511d41 cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 4098
diff changeset
3 * Copyright (c) 2006 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1322
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1322
diff changeset
6 *
2252
708e6e93d6f2 Smartjog granted permission to relicense as LGPL 2.1
bcoudurier
parents: 2251
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
708e6e93d6f2 Smartjog granted permission to relicense as LGPL 2.1
bcoudurier
parents: 2251
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
708e6e93d6f2 Smartjog granted permission to relicense as LGPL 2.1
bcoudurier
parents: 2251
diff changeset
9 * License as published by the Free Software Foundation; either
708e6e93d6f2 Smartjog granted permission to relicense as LGPL 2.1
bcoudurier
parents: 2251
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1322
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2252
708e6e93d6f2 Smartjog granted permission to relicense as LGPL 2.1
bcoudurier
parents: 2251
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
708e6e93d6f2 Smartjog granted permission to relicense as LGPL 2.1
bcoudurier
parents: 2251
diff changeset
15 * Lesser General Public License for more details.
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
16 *
2252
708e6e93d6f2 Smartjog granted permission to relicense as LGPL 2.1
bcoudurier
parents: 2251
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
708e6e93d6f2 Smartjog granted permission to relicense as LGPL 2.1
bcoudurier
parents: 2251
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1322
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
20 */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
21
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
22 #include "avformat.h"
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
23 #include "gxf.h"
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
24 #include "riff.h"
4401
880838781e34 use new audio interleaving generic code
bcoudurier
parents: 4329
diff changeset
25 #include "audiointerleave.h"
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
26
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
27 #define GXF_AUDIO_PACKET_SIZE 65536
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
28
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
29 typedef struct GXFStreamContext {
4401
880838781e34 use new audio interleaving generic code
bcoudurier
parents: 4329
diff changeset
30 AudioInterleaveContext aic;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
31 uint32_t track_type;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
32 uint32_t sample_size;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
33 uint32_t sample_rate;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
34 uint16_t media_type;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
35 uint16_t media_info;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
36 int frame_rate_index;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
37 int lines_index;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
38 int fields;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
39 int iframes;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
40 int pframes;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
41 int bframes;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
42 int p_per_gop;
4456
833d30447d64 rename wrongly named b_per_gop to b_per_i_or_p according to specs
bcoudurier
parents: 4426
diff changeset
43 int b_per_i_or_p; ///< number of B frames per I frame or P frame
1261
e03e8ce942e8 rename closed_gop to first_gop_closed
bcoudurier
parents: 1260
diff changeset
44 int first_gop_closed;
4677
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
45 unsigned order; ///< interleaving order
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
46 } GXFStreamContext;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
47
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
48 typedef struct GXFContext {
4479
4e18c9ac9b10 cosmetics, rename nb_frames to nb_fields
bcoudurier
parents: 4457
diff changeset
49 uint32_t nb_fields;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
50 uint16_t audio_tracks;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
51 uint16_t mpeg_tracks;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
52 int64_t creation_time;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
53 uint32_t umf_start_offset;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
54 uint32_t umf_track_offset;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
55 uint32_t umf_media_offset;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
56 uint32_t umf_length;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
57 uint16_t umf_track_size;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
58 uint16_t umf_media_size;
4677
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
59 AVRational time_base;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
60 int flags;
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
61 GXFStreamContext timecode_track;
4678
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
62 unsigned *flt_entries; ///< offsets of packets /1024, starts after 2nd video field
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
63 unsigned flt_entries_nb;
4679
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
64 uint64_t *map_offsets; ///< offset of map packets
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
65 unsigned map_offsets_nb;
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
66 unsigned packet_count;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
67 } GXFContext;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
68
4680
aa231ba489df merge struct declaration and definition
bcoudurier
parents: 4679
diff changeset
69 static const struct {
aa231ba489df merge struct declaration and definition
bcoudurier
parents: 4679
diff changeset
70 int height, index;
aa231ba489df merge struct declaration and definition
bcoudurier
parents: 4679
diff changeset
71 } gxf_lines_tab[] = {
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
72 { 480, 1 }, /* NTSC */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
73 { 512, 1 }, /* NTSC + VBI */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
74 { 576, 2 }, /* PAL */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
75 { 608, 2 }, /* PAL + VBI */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
76 { 1080, 4 },
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
77 { 720, 6 },
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
78 };
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
79
1677
2a85c82b8538 add codec_id <-> codec_tag tables to AVIn/OutputFormat
michael
parents: 1542
diff changeset
80 static const AVCodecTag gxf_media_types[] = {
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
81 { CODEC_ID_MJPEG , 3 }, /* NTSC */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
82 { CODEC_ID_MJPEG , 4 }, /* PAL */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
83 { CODEC_ID_PCM_S24LE , 9 },
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
84 { CODEC_ID_PCM_S16LE , 10 },
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
85 { CODEC_ID_MPEG2VIDEO, 11 }, /* NTSC */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
86 { CODEC_ID_MPEG2VIDEO, 12 }, /* PAL */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
87 { CODEC_ID_DVVIDEO , 13 }, /* NTSC */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
88 { CODEC_ID_DVVIDEO , 14 }, /* PAL */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
89 { CODEC_ID_DVVIDEO , 15 }, /* 50M NTSC */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
90 { CODEC_ID_DVVIDEO , 16 }, /* 50M PAL */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
91 { CODEC_ID_AC3 , 17 },
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
92 //{ CODEC_ID_NONE, , 18 }, /* Non compressed 24 bit audio */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
93 { CODEC_ID_MPEG2VIDEO, 20 }, /* MPEG HD */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
94 { CODEC_ID_MPEG1VIDEO, 22 }, /* NTSC */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
95 { CODEC_ID_MPEG1VIDEO, 23 }, /* PAL */
5290
0d5653941bf9 Make AVCodecTag.id enum CodecID and use CODEC_ID_NONE instead of 0.
cehoyos
parents: 5058
diff changeset
96 { CODEC_ID_NONE, 0 },
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
97 };
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
98
4681
83c634df5c79 change path pattern to be similar to existing files, and remove useless buffer
bcoudurier
parents: 4680
diff changeset
99 #define SERVER_PATH "EXT:/PDR/default/"
83c634df5c79 change path pattern to be similar to existing files, and remove useless buffer
bcoudurier
parents: 4680
diff changeset
100 #define ES_NAME_PATTERN "EXT:/PDR/default/ES."
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
101
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
102 static int gxf_find_lines_index(AVStream *st)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
103 {
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
104 GXFStreamContext *sc = st->priv_data;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
105 int i;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
106
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
107 for (i = 0; i < 6; ++i) {
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
108 if (st->codec->height == gxf_lines_tab[i].height) {
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
109 sc->lines_index = gxf_lines_tab[i].index;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
110 return 0;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
111 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
112 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
113 return -1;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
114 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
115
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
116 static void gxf_write_padding(ByteIOContext *pb, int64_t to_pad)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
117 {
1213
fe9ebf4ce09e negative to_pad won't provoke infinite loop
bcoudurier
parents: 1212
diff changeset
118 for (; to_pad > 0; to_pad--) {
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
119 put_byte(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
120 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
121 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
122
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
123 static int64_t updatePacketSize(ByteIOContext *pb, int64_t pos)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
124 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
125 int64_t curpos;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
126 int size;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
127
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
128 size = url_ftell(pb) - pos;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
129 if (size % 4) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
130 gxf_write_padding(pb, 4 - size % 4);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
131 size = url_ftell(pb) - pos;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
132 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
133 curpos = url_ftell(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
134 url_fseek(pb, pos + 6, SEEK_SET);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
135 put_be32(pb, size);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
136 url_fseek(pb, curpos, SEEK_SET);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
137 return curpos - pos;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
138 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
139
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
140 static int64_t updateSize(ByteIOContext *pb, int64_t pos)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
141 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
142 int64_t curpos;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
143
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
144 curpos = url_ftell(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
145 url_fseek(pb, pos, SEEK_SET);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
146 put_be16(pb, curpos - pos - 2);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
147 url_fseek(pb, curpos, SEEK_SET);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
148 return curpos - pos;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
149 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
150
4098
10d52cda08dd Avoid _t in gxf enum type names
reimar
parents: 3973
diff changeset
151 static void gxf_write_packet_header(ByteIOContext *pb, GXFPktType type)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
152 {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
153 put_be32(pb, 0); /* packet leader for synchro */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
154 put_byte(pb, 1);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
155 put_byte(pb, type); /* map packet */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
156 put_be32(pb, 0); /* size */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
157 put_be32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
158 put_byte(pb, 0xE1); /* trailer 1 */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
159 put_byte(pb, 0xE2); /* trailer 2 */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
160 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
161
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
162 static int gxf_write_mpeg_auxiliary(ByteIOContext *pb, AVStream *st)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
163 {
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
164 GXFStreamContext *sc = st->priv_data;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
165 char buffer[1024];
4261
af29578c3d77 set correct value for starting line
bcoudurier
parents: 4260
diff changeset
166 int size, starting_line;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
167
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
168 if (sc->iframes) {
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
169 sc->p_per_gop = sc->pframes / sc->iframes;
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
170 if (sc->pframes % sc->iframes)
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
171 sc->p_per_gop++;
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
172 if (sc->pframes) {
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
173 sc->b_per_i_or_p = sc->bframes / sc->pframes;
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
174 if (sc->bframes % sc->pframes)
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
175 sc->b_per_i_or_p++;
4457
6ed62b8257dd compute b_per_i_or_p value correctly, patch by Thierry Foucu, tfoucu at gmail dot com
bcoudurier
parents: 4456
diff changeset
176 }
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
177 if (sc->p_per_gop > 9)
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
178 sc->p_per_gop = 9; /* ensure value won't take more than one char */
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
179 if (sc->b_per_i_or_p > 9)
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
180 sc->b_per_i_or_p = 9; /* ensure value won't take more than one char */
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
181 }
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
182 if (st->codec->height == 512 || st->codec->height == 608)
4261
af29578c3d77 set correct value for starting line
bcoudurier
parents: 4260
diff changeset
183 starting_line = 7; // VBI
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
184 else if (st->codec->height == 480)
4261
af29578c3d77 set correct value for starting line
bcoudurier
parents: 4260
diff changeset
185 starting_line = 20;
af29578c3d77 set correct value for starting line
bcoudurier
parents: 4260
diff changeset
186 else
af29578c3d77 set correct value for starting line
bcoudurier
parents: 4260
diff changeset
187 starting_line = 23; // default PAL
af29578c3d77 set correct value for starting line
bcoudurier
parents: 4260
diff changeset
188
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
189 size = snprintf(buffer, 1024, "Ver 1\nBr %.6f\nIpg 1\nPpi %d\nBpiop %d\n"
4261
af29578c3d77 set correct value for starting line
bcoudurier
parents: 4260
diff changeset
190 "Pix 0\nCf %d\nCg %d\nSl %d\nnl16 %d\nVi 1\nf1 1\n",
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
191 (float)st->codec->bit_rate, sc->p_per_gop, sc->b_per_i_or_p,
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
192 st->codec->pix_fmt == PIX_FMT_YUV422P ? 2 : 1, sc->first_gop_closed == 1,
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
193 starting_line, st->codec->height / 16);
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
194 put_byte(pb, TRACK_MPG_AUX);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
195 put_byte(pb, size + 1);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
196 put_buffer(pb, (uint8_t *)buffer, size + 1);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
197 return size + 3;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
198 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
199
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
200 static int gxf_write_timecode_auxiliary(ByteIOContext *pb, GXFStreamContext *sc)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
201 {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
202 put_byte(pb, 0); /* fields */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
203 put_byte(pb, 0); /* seconds */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
204 put_byte(pb, 0); /* minutes */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
205 put_byte(pb, 0); /* flags + hours */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
206 /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
207 put_be32(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
208 return 8;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
209 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
210
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
211 static int gxf_write_track_description(AVFormatContext *s, GXFStreamContext *sc, int index)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
212 {
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
213 ByteIOContext *pb = s->pb;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
214 int64_t pos;
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
215 int mpeg = sc->track_type == 4 || sc->track_type == 9;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
216
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
217 /* track description section */
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
218 put_byte(pb, sc->media_type + 0x80);
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
219 put_byte(pb, index + 0xC0);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
220
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
221 pos = url_ftell(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
222 put_be16(pb, 0); /* size */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
223
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
224 /* media file name */
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
225 put_byte(pb, TRACK_NAME);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
226 put_byte(pb, strlen(ES_NAME_PATTERN) + 3);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
227 put_tag(pb, ES_NAME_PATTERN);
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
228 put_be16(pb, sc->media_info);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
229 put_byte(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
230
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
231 if (!mpeg) {
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
232 /* auxiliary information */
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
233 put_byte(pb, TRACK_AUX);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
234 put_byte(pb, 8);
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
235 if (sc->track_type == 3)
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
236 gxf_write_timecode_auxiliary(pb, sc);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
237 else
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
238 put_le64(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
239 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
240
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
241 /* file system version */
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
242 put_byte(pb, TRACK_VER);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
243 put_byte(pb, 4);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
244 put_be32(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
245
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
246 if (mpeg)
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
247 gxf_write_mpeg_auxiliary(pb, s->streams[index]);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
248
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
249 /* frame rate */
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
250 put_byte(pb, TRACK_FPS);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
251 put_byte(pb, 4);
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
252 put_be32(pb, sc->frame_rate_index);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
253
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
254 /* lines per frame */
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
255 put_byte(pb, TRACK_LINES);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
256 put_byte(pb, 4);
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
257 put_be32(pb, sc->lines_index);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
258
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
259 /* fields per frame */
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
260 put_byte(pb, TRACK_FPF);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
261 put_byte(pb, 4);
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
262 put_be32(pb, sc->fields);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
263
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
264 return updateSize(pb, pos);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
265 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
266
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
267 static int gxf_write_material_data_section(AVFormatContext *s)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
268 {
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
269 GXFContext *gxf = s->priv_data;
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
270 ByteIOContext *pb = s->pb;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
271 int64_t pos;
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
272 const char *filename = strrchr(s->filename, '/');
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
273
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
274 pos = url_ftell(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
275 put_be16(pb, 0); /* size */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
276
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
277 /* name */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
278 if (filename)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
279 filename++;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
280 else
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
281 filename = s->filename;
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
282 put_byte(pb, MAT_NAME);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
283 put_byte(pb, strlen(SERVER_PATH) + strlen(filename) + 1);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
284 put_tag(pb, SERVER_PATH);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
285 put_tag(pb, filename);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
286 put_byte(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
287
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
288 /* first field */
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
289 put_byte(pb, MAT_FIRST_FIELD);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
290 put_byte(pb, 4);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
291 put_be32(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
292
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
293 /* last field */
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
294 put_byte(pb, MAT_LAST_FIELD);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
295 put_byte(pb, 4);
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
296 put_be32(pb, gxf->nb_fields);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
297
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
298 /* reserved */
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
299 put_byte(pb, MAT_MARK_IN);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
300 put_byte(pb, 4);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
301 put_be32(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
302
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
303 put_byte(pb, MAT_MARK_OUT);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
304 put_byte(pb, 4);
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
305 put_be32(pb, gxf->nb_fields);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
306
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
307 /* estimated size */
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
308 put_byte(pb, MAT_SIZE);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
309 put_byte(pb, 4);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
310 put_be32(pb, url_fsize(pb) / 1024);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
311
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
312 return updateSize(pb, pos);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
313 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
314
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
315 static int gxf_write_track_description_section(AVFormatContext *s)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
316 {
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
317 GXFContext *gxf = s->priv_data;
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
318 ByteIOContext *pb = s->pb;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
319 int64_t pos;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
320 int i;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
321
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
322 pos = url_ftell(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
323 put_be16(pb, 0); /* size */
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
324 for (i = 0; i < s->nb_streams; ++i)
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
325 gxf_write_track_description(s, s->streams[i]->priv_data, i);
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
326
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
327 gxf_write_track_description(s, &gxf->timecode_track, s->nb_streams);
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
328
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
329 return updateSize(pb, pos);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
330 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
331
4679
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
332 static int gxf_write_map_packet(AVFormatContext *s, int rewrite)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
333 {
4679
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
334 GXFContext *gxf = s->priv_data;
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
335 ByteIOContext *pb = s->pb;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
336 int64_t pos = url_ftell(pb);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
337
4679
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
338 if (!rewrite) {
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
339 if (!(gxf->map_offsets_nb % 30)) {
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
340 gxf->map_offsets = av_realloc(gxf->map_offsets,
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
341 (gxf->map_offsets_nb+30)*sizeof(*gxf->map_offsets));
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
342 if (!gxf->map_offsets) {
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
343 av_log(s, AV_LOG_ERROR, "could not realloc map offsets\n");
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
344 return -1;
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
345 }
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
346 }
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
347 gxf->map_offsets[gxf->map_offsets_nb++] = pos; // do not increment here
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
348 }
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
349
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
350 gxf_write_packet_header(pb, PKT_MAP);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
351
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
352 /* preamble */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
353 put_byte(pb, 0xE0); /* version */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
354 put_byte(pb, 0xFF); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
355
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
356 gxf_write_material_data_section(s);
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
357 gxf_write_track_description_section(s);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
358
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
359 return updatePacketSize(pb, pos);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
360 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
361
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
362 static int gxf_write_flt_packet(AVFormatContext *s)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
363 {
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
364 GXFContext *gxf = s->priv_data;
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
365 ByteIOContext *pb = s->pb;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
366 int64_t pos = url_ftell(pb);
4678
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
367 int fields_per_flt = (gxf->nb_fields+1) / 1000 + 1;
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
368 int flt_entries = gxf->nb_fields / fields_per_flt - 1;
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
369 int i = 0;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
370
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
371 gxf_write_packet_header(pb, PKT_FLT);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
372
4678
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
373 put_le32(pb, fields_per_flt); /* number of fields */
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
374 put_le32(pb, flt_entries); /* number of active flt entries */
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
375
4678
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
376 if (gxf->flt_entries) {
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
377 for (i = 0; i < flt_entries; i++)
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
378 put_le32(pb, gxf->flt_entries[(i*fields_per_flt)>>1]);
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
379 }
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
380
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
381 for (; i < 1000; i++)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
382 put_le32(pb, 0);
4678
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
383
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
384 return updatePacketSize(pb, pos);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
385 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
386
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
387 static int gxf_write_umf_material_description(AVFormatContext *s)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
388 {
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
389 GXFContext *gxf = s->priv_data;
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
390 ByteIOContext *pb = s->pb;
4677
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
391 int timecode_base = gxf->time_base.den == 60000 ? 60 : 50;
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
392
4260
40528f55532c fix gxf time code mark out value
bcoudurier
parents: 4251
diff changeset
393 // XXX drop frame
40528f55532c fix gxf time code mark out value
bcoudurier
parents: 4251
diff changeset
394 uint32_t timecode =
4677
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
395 gxf->nb_fields / (timecode_base * 3600) % 24 << 24 | // hours
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
396 gxf->nb_fields / (timecode_base * 60) % 60 << 16 | // minutes
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
397 gxf->nb_fields / timecode_base % 60 << 8 | // seconds
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
398 gxf->nb_fields % timecode_base; // fields
4260
40528f55532c fix gxf time code mark out value
bcoudurier
parents: 4251
diff changeset
399
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
400 put_le32(pb, gxf->flags);
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
401 put_le32(pb, gxf->nb_fields); /* length of the longest track */
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
402 put_le32(pb, gxf->nb_fields); /* length of the shortest track */
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
403 put_le32(pb, 0); /* mark in */
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
404 put_le32(pb, gxf->nb_fields); /* mark out */
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
405 put_le32(pb, 0); /* timecode mark in */
4260
40528f55532c fix gxf time code mark out value
bcoudurier
parents: 4251
diff changeset
406 put_le32(pb, timecode); /* timecode mark out */
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
407 put_le64(pb, s->timestamp); /* modification time */
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
408 put_le64(pb, s->timestamp); /* creation time */
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
409 put_le16(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
410 put_le16(pb, 0); /* reserved */
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
411 put_le16(pb, gxf->audio_tracks);
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
412 put_le16(pb, 1); /* timecode track count */
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
413 put_le16(pb, 0); /* reserved */
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
414 put_le16(pb, gxf->mpeg_tracks);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
415 return 48;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
416 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
417
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
418 static int gxf_write_umf_payload(AVFormatContext *s)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
419 {
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
420 GXFContext *gxf = s->priv_data;
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
421 ByteIOContext *pb = s->pb;
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
422
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
423 put_le32(pb, gxf->umf_length); /* total length of the umf data */
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
424 put_le32(pb, 3); /* version */
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
425 put_le32(pb, s->nb_streams+1);
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
426 put_le32(pb, gxf->umf_track_offset); /* umf track section offset */
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
427 put_le32(pb, gxf->umf_track_size);
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
428 put_le32(pb, s->nb_streams+1);
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
429 put_le32(pb, gxf->umf_media_offset);
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
430 put_le32(pb, gxf->umf_media_size);
4673
c8161db9d863 remove unneeded and empty user data
bcoudurier
parents: 4672
diff changeset
431 put_le32(pb, gxf->umf_length); /* user data offset */
c8161db9d863 remove unneeded and empty user data
bcoudurier
parents: 4672
diff changeset
432 put_le32(pb, 0); /* user data size */
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
433 put_le32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
434 put_le32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
435 return 48;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
436 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
437
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
438 static int gxf_write_umf_track_description(AVFormatContext *s)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
439 {
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
440 ByteIOContext *pb = s->pb;
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
441 GXFContext *gxf = s->priv_data;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
442 int64_t pos = url_ftell(pb);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
443 int i;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
444
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
445 gxf->umf_track_offset = pos - gxf->umf_start_offset;
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
446 for (i = 0; i < s->nb_streams; ++i) {
4675
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
447 GXFStreamContext *sc = s->streams[i]->priv_data;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
448 put_le16(pb, sc->media_info);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
449 put_le16(pb, 1);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
450 }
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
451
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
452 put_le16(pb, gxf->timecode_track.media_info);
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
453 put_le16(pb, 1);
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
454
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
455 return url_ftell(pb) - pos;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
456 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
457
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
458 static int gxf_write_umf_media_mpeg(ByteIOContext *pb, AVStream *st)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
459 {
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
460 GXFStreamContext *sc = st->priv_data;
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
461
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
462 if (st->codec->pix_fmt == PIX_FMT_YUV422P)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
463 put_le32(pb, 2);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
464 else
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
465 put_le32(pb, 1); /* default to 420 */
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
466 put_le32(pb, sc->first_gop_closed == 1); /* closed = 1, open = 0, unknown = 255 */
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
467 put_le32(pb, 3); /* top = 1, bottom = 2, frame = 3, unknown = 0 */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
468 put_le32(pb, 1); /* I picture per GOP */
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
469 put_le32(pb, sc->p_per_gop);
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
470 put_le32(pb, sc->b_per_i_or_p);
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
471 if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
472 put_le32(pb, 2);
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
473 else if (st->codec->codec_id == CODEC_ID_MPEG1VIDEO)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
474 put_le32(pb, 1);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
475 else
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
476 put_le32(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
477 put_le32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
478 return 32;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
479 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
480
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
481 static int gxf_write_umf_media_timecode(ByteIOContext *pb, GXFStreamContext *sc)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
482 {
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
483 put_le32(pb, 1); /* non drop frame */
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
484 put_le32(pb, 0); /* reserved */
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
485 put_le32(pb, 0); /* reserved */
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
486 put_le32(pb, 0); /* reserved */
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
487 put_le32(pb, 0); /* reserved */
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
488 put_le32(pb, 0); /* reserved */
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
489 put_le32(pb, 0); /* reserved */
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
490 put_le32(pb, 0); /* reserved */
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
491 return 32;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
492 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
493
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
494 static int gxf_write_umf_media_dv(ByteIOContext *pb, GXFStreamContext *sc)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
495 {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
496 int i;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
497
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
498 for (i = 0; i < 8; i++) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
499 put_be32(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
500 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
501 return 32;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
502 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
503
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
504 static int gxf_write_umf_media_audio(ByteIOContext *pb, GXFStreamContext *sc)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
505 {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
506 put_le64(pb, av_dbl2int(1)); /* sound level to begin to */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
507 put_le64(pb, av_dbl2int(1)); /* sound level to begin to */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
508 put_le32(pb, 0); /* number of fields over which to ramp up sound level */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
509 put_le32(pb, 0); /* number of fields over which to ramp down sound level */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
510 put_le32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
511 put_le32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
512 return 32;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
513 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
514
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
515 #if 0
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
516 static int gxf_write_umf_media_mjpeg(ByteIOContext *pb, GXFStreamContext *sc)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
517 {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
518 put_be64(pb, 0); /* FIXME FLOAT max chroma quant level */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
519 put_be64(pb, 0); /* FIXME FLOAT max luma quant level */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
520 put_be64(pb, 0); /* FIXME FLOAT min chroma quant level */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
521 put_be64(pb, 0); /* FIXME FLOAT min luma quant level */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
522 return 32;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
523 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
524 #endif
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
525
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
526 static int gxf_write_umf_media_description(AVFormatContext *s)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
527 {
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
528 GXFContext *gxf = s->priv_data;
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
529 ByteIOContext *pb = s->pb;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
530 int64_t pos;
4681
83c634df5c79 change path pattern to be similar to existing files, and remove useless buffer
bcoudurier
parents: 4680
diff changeset
531 int i, j;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
532
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
533 pos = url_ftell(pb);
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
534 gxf->umf_media_offset = pos - gxf->umf_start_offset;
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
535 for (i = 0; i <= s->nb_streams; ++i) {
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
536 GXFStreamContext *sc;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
537 int64_t startpos, curpos;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
538
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
539 if (i == s->nb_streams)
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
540 sc = &gxf->timecode_track;
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
541 else
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
542 sc = s->streams[i]->priv_data;
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
543
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
544 startpos = url_ftell(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
545 put_le16(pb, 0); /* length */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
546 put_le16(pb, sc->media_info);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
547 put_le16(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
548 put_le16(pb, 0); /* reserved */
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
549 put_le32(pb, gxf->nb_fields);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
550 put_le32(pb, 0); /* attributes rw, ro */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
551 put_le32(pb, 0); /* mark in */
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
552 put_le32(pb, gxf->nb_fields); /* mark out */
4681
83c634df5c79 change path pattern to be similar to existing files, and remove useless buffer
bcoudurier
parents: 4680
diff changeset
553 put_buffer(pb, ES_NAME_PATTERN, sizeof(ES_NAME_PATTERN));
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
554 put_be16(pb, sc->media_info);
4681
83c634df5c79 change path pattern to be similar to existing files, and remove useless buffer
bcoudurier
parents: 4680
diff changeset
555 for (j = sizeof(ES_NAME_PATTERN)+2; j < 88; j++)
83c634df5c79 change path pattern to be similar to existing files, and remove useless buffer
bcoudurier
parents: 4680
diff changeset
556 put_byte(pb, 0);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
557 put_le32(pb, sc->track_type);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
558 put_le32(pb, sc->sample_rate);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
559 put_le32(pb, sc->sample_size);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
560 put_le32(pb, 0); /* reserved */
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
561
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
562 if (sc == &gxf->timecode_track)
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
563 gxf_write_umf_media_timecode(pb, sc); /* 8 0bytes */
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
564 else {
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
565 AVStream *st = s->streams[i];
4682
c12f591bf750 reindent
bcoudurier
parents: 4681
diff changeset
566 switch (st->codec->codec_id) {
c12f591bf750 reindent
bcoudurier
parents: 4681
diff changeset
567 case CODEC_ID_MPEG2VIDEO:
c12f591bf750 reindent
bcoudurier
parents: 4681
diff changeset
568 gxf_write_umf_media_mpeg(pb, st);
c12f591bf750 reindent
bcoudurier
parents: 4681
diff changeset
569 break;
c12f591bf750 reindent
bcoudurier
parents: 4681
diff changeset
570 case CODEC_ID_PCM_S16LE:
c12f591bf750 reindent
bcoudurier
parents: 4681
diff changeset
571 gxf_write_umf_media_audio(pb, sc);
c12f591bf750 reindent
bcoudurier
parents: 4681
diff changeset
572 break;
c12f591bf750 reindent
bcoudurier
parents: 4681
diff changeset
573 case CODEC_ID_DVVIDEO:
c12f591bf750 reindent
bcoudurier
parents: 4681
diff changeset
574 gxf_write_umf_media_dv(pb, sc);
c12f591bf750 reindent
bcoudurier
parents: 4681
diff changeset
575 break;
c12f591bf750 reindent
bcoudurier
parents: 4681
diff changeset
576 }
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
577 }
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
578
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
579 curpos = url_ftell(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
580 url_fseek(pb, startpos, SEEK_SET);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
581 put_le16(pb, curpos - startpos);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
582 url_fseek(pb, curpos, SEEK_SET);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
583 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
584 return url_ftell(pb) - pos;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
585 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
586
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
587 static int gxf_write_umf_packet(AVFormatContext *s)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
588 {
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
589 GXFContext *gxf = s->priv_data;
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
590 ByteIOContext *pb = s->pb;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
591 int64_t pos = url_ftell(pb);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
592
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
593 gxf_write_packet_header(pb, PKT_UMF);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
594
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
595 /* preamble */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
596 put_byte(pb, 3); /* first and last (only) packet */
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
597 put_be32(pb, gxf->umf_length); /* data length */
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
598
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
599 gxf->umf_start_offset = url_ftell(pb);
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
600 gxf_write_umf_payload(s);
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
601 gxf_write_umf_material_description(s);
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
602 gxf->umf_track_size = gxf_write_umf_track_description(s);
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
603 gxf->umf_media_size = gxf_write_umf_media_description(s);
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
604 gxf->umf_length = url_ftell(pb) - gxf->umf_start_offset;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
605 return updatePacketSize(pb, pos);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
606 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
607
4401
880838781e34 use new audio interleaving generic code
bcoudurier
parents: 4329
diff changeset
608 static const int GXF_samples_per_frame[] = { 32768, 0 };
880838781e34 use new audio interleaving generic code
bcoudurier
parents: 4329
diff changeset
609
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
610 static void gxf_init_timecode_track(GXFStreamContext *sc, GXFStreamContext *vsc)
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
611 {
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
612 if (!vsc)
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
613 return;
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
614
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
615 sc->media_type = vsc->sample_rate == 60 ? 7 : 8;
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
616 sc->sample_rate = vsc->sample_rate;
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
617 sc->media_info = ('T'<<8) | '0';
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
618 sc->track_type = 3;
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
619 sc->frame_rate_index = vsc->frame_rate_index;
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
620 sc->lines_index = vsc->lines_index;
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
621 sc->sample_size = 16;
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
622 sc->fields = vsc->fields;
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
623 }
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
624
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
625 static int gxf_write_header(AVFormatContext *s)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
626 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2337
diff changeset
627 ByteIOContext *pb = s->pb;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
628 GXFContext *gxf = s->priv_data;
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
629 GXFStreamContext *vsc = NULL;
4675
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
630 uint8_t tracks[255] = {0};
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
631 int i, media_info = 0;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
632
4679
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
633 if (url_is_streamed(pb)) {
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
634 av_log(s, AV_LOG_ERROR, "gxf muxer does not support streamed output, patch welcome");
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
635 return -1;
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
636 }
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
637
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
638 gxf->flags |= 0x00080000; /* material is simple clip */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
639 for (i = 0; i < s->nb_streams; ++i) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
640 AVStream *st = s->streams[i];
4329
bd49910ad4a0 use st->priv_data to store per stream context
bcoudurier
parents: 4304
diff changeset
641 GXFStreamContext *sc = av_mallocz(sizeof(*sc));
bd49910ad4a0 use st->priv_data to store per stream context
bcoudurier
parents: 4304
diff changeset
642 if (!sc)
bd49910ad4a0 use st->priv_data to store per stream context
bcoudurier
parents: 4304
diff changeset
643 return AVERROR(ENOMEM);
bd49910ad4a0 use st->priv_data to store per stream context
bcoudurier
parents: 4304
diff changeset
644 st->priv_data = sc;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
645
5058
33a244b7ca65 Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents: 4950
diff changeset
646 sc->media_type = ff_codec_get_tag(gxf_media_types, st->codec->codec_id);
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5290
diff changeset
647 if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
648 if (st->codec->codec_id != CODEC_ID_PCM_S16LE) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
649 av_log(s, AV_LOG_ERROR, "only 16 BIT PCM LE allowed for now\n");
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
650 return -1;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
651 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
652 if (st->codec->sample_rate != 48000) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
653 av_log(s, AV_LOG_ERROR, "only 48000hz sampling rate is allowed\n");
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
654 return -1;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
655 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
656 if (st->codec->channels != 1) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
657 av_log(s, AV_LOG_ERROR, "only mono tracks are allowed\n");
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
658 return -1;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
659 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
660 sc->track_type = 2;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
661 sc->sample_rate = st->codec->sample_rate;
1253
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
662 av_set_pts_info(st, 64, 1, sc->sample_rate);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
663 sc->sample_size = 16;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
664 sc->frame_rate_index = -2;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
665 sc->lines_index = -2;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
666 sc->fields = -2;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
667 gxf->audio_tracks++;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
668 gxf->flags |= 0x04000000; /* audio is 16 bit pcm */
4675
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
669 media_info = 'A';
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5290
diff changeset
670 } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
4677
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
671 if (i != 0) {
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
672 av_log(s, AV_LOG_ERROR, "video stream must be the first track\n");
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
673 return -1;
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
674 }
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
675 /* FIXME check from time_base ? */
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
676 if (st->codec->height == 480 || st->codec->height == 512) { /* NTSC or NTSC+VBI */
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
677 sc->frame_rate_index = 5;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
678 sc->sample_rate = 60;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
679 gxf->flags |= 0x00000080;
4677
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
680 gxf->time_base = (AVRational){ 1001, 60000 };
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
681 } else { /* assume PAL */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
682 sc->frame_rate_index = 6;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
683 sc->media_type++;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
684 sc->sample_rate = 50;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
685 gxf->flags |= 0x00000040;
4677
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
686 gxf->time_base = (AVRational){ 1, 50 };
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
687 }
4677
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
688 av_set_pts_info(st, 64, gxf->time_base.num, gxf->time_base.den);
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
689 if (gxf_find_lines_index(st) < 0)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
690 sc->lines_index = -1;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
691 sc->sample_size = st->codec->bit_rate;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
692 sc->fields = 2; /* interlaced */
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
693
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
694 vsc = sc;
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
695
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
696 switch (st->codec->codec_id) {
4675
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
697 case CODEC_ID_MJPEG:
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
698 sc->track_type = 1;
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
699 gxf->flags |= 0x00004000;
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
700 media_info = 'J';
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
701 break;
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
702 case CODEC_ID_MPEG1VIDEO:
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
703 sc->track_type = 9;
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
704 gxf->mpeg_tracks++;
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
705 media_info = 'L';
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
706 break;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
707 case CODEC_ID_MPEG2VIDEO:
1262
8da1b141e83a set correct first gop closed value
bcoudurier
parents: 1261
diff changeset
708 sc->first_gop_closed = -1;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
709 sc->track_type = 4;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
710 gxf->mpeg_tracks++;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
711 gxf->flags |= 0x00008000;
4675
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
712 media_info = 'M';
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
713 break;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
714 case CODEC_ID_DVVIDEO:
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
715 if (st->codec->pix_fmt == PIX_FMT_YUV422P) {
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
716 sc->media_type += 2;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
717 sc->track_type = 6;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
718 gxf->flags |= 0x00002000;
4675
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
719 media_info = 'E';
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
720 } else {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
721 sc->track_type = 5;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
722 gxf->flags |= 0x00001000;
4675
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
723 media_info = 'D';
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
724 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
725 break;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
726 default:
1401
e4a89160a011 use AVFormatContext to log
bcoudurier
parents: 1398
diff changeset
727 av_log(s, AV_LOG_ERROR, "video codec not supported\n");
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
728 return -1;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
729 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
730 }
4675
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
731 /* FIXME first 10 audio tracks are 0 to 9 next 22 are A to V */
f036a151abf8 compute media info in write_header
bcoudurier
parents: 4674
diff changeset
732 sc->media_info = media_info<<8 | ('0'+tracks[media_info]++);
4677
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
733 sc->order = s->nb_streams - st->index;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
734 }
4401
880838781e34 use new audio interleaving generic code
bcoudurier
parents: 4329
diff changeset
735
880838781e34 use new audio interleaving generic code
bcoudurier
parents: 4329
diff changeset
736 if (ff_audio_interleave_init(s, GXF_samples_per_frame, (AVRational){ 1, 48000 }) < 0)
880838781e34 use new audio interleaving generic code
bcoudurier
parents: 4329
diff changeset
737 return -1;
880838781e34 use new audio interleaving generic code
bcoudurier
parents: 4329
diff changeset
738
4676
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
739 gxf_init_timecode_track(&gxf->timecode_track, vsc);
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
740 gxf->flags |= 0x200000; // time code track is non-drop frame
0e45c20bbb9e write timecode track in gxf
bcoudurier
parents: 4675
diff changeset
741
4679
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
742 gxf_write_map_packet(s, 0);
4678
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
743 gxf_write_flt_packet(s);
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
744 gxf_write_umf_packet(s);
4679
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
745
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
746 gxf->packet_count = 3;
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
747
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
748 put_flush_packet(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
749 return 0;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
750 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
751
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
752 static int gxf_write_eos_packet(ByteIOContext *pb)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
753 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
754 int64_t pos = url_ftell(pb);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
755
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
756 gxf_write_packet_header(pb, PKT_EOS);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
757 return updatePacketSize(pb, pos);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
758 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
759
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
760 static int gxf_write_trailer(AVFormatContext *s)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
761 {
4678
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
762 GXFContext *gxf = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2337
diff changeset
763 ByteIOContext *pb = s->pb;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
764 int64_t end;
4679
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
765 int i;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
766
4401
880838781e34 use new audio interleaving generic code
bcoudurier
parents: 4329
diff changeset
767 ff_audio_interleave_close(s);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
768
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
769 gxf_write_eos_packet(pb);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
770 end = url_ftell(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
771 url_fseek(pb, 0, SEEK_SET);
4678
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
772 /* overwrite map, flt and umf packets with new values */
4679
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
773 gxf_write_map_packet(s, 1);
4678
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
774 gxf_write_flt_packet(s);
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
775 gxf_write_umf_packet(s);
4679
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
776 put_flush_packet(pb);
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
777 /* update duration in all map packets */
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
778 for (i = 1; i < gxf->map_offsets_nb; i++) {
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
779 url_fseek(pb, gxf->map_offsets[i], SEEK_SET);
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
780 gxf_write_map_packet(s, 1);
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
781 put_flush_packet(pb);
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
782 }
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
783
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
784 url_fseek(pb, end, SEEK_SET);
4678
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
785
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
786 av_freep(&gxf->flt_entries);
4679
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
787 av_freep(&gxf->map_offsets);
4678
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
788
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
789 return 0;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
790 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
791
1247
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
792 static int gxf_parse_mpeg_frame(GXFStreamContext *sc, const uint8_t *buf, int size)
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
793 {
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
794 uint32_t c=-1;
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
795 int i;
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
796 for(i=0; i<size-4 && c!=0x100; i++){
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
797 c = (c<<8) + buf[i];
1262
8da1b141e83a set correct first gop closed value
bcoudurier
parents: 1261
diff changeset
798 if(c == 0x1B8 && sc->first_gop_closed == -1) /* GOP start code */
1261
e03e8ce942e8 rename closed_gop to first_gop_closed
bcoudurier
parents: 1260
diff changeset
799 sc->first_gop_closed= (buf[i+4]>>6)&1;
1247
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
800 }
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
801 return (buf[i+1]>>3)&7;
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
802 }
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
803
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
804 static int gxf_write_media_preamble(AVFormatContext *s, AVPacket *pkt, int size)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
805 {
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
806 GXFContext *gxf = s->priv_data;
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
807 ByteIOContext *pb = s->pb;
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
808 AVStream *st = s->streams[pkt->stream_index];
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
809 GXFStreamContext *sc = st->priv_data;
4480
b88326454853 use correct field number for video according to specs, patch by Thierry Foucu, tfoucu at gmail dot com
bcoudurier
parents: 4479
diff changeset
810 unsigned field_nb;
b88326454853 use correct field number for video according to specs, patch by Thierry Foucu, tfoucu at gmail dot com
bcoudurier
parents: 4479
diff changeset
811 /* If the video is frame-encoded, the frame numbers shall be represented by
b88326454853 use correct field number for video according to specs, patch by Thierry Foucu, tfoucu at gmail dot com
bcoudurier
parents: 4479
diff changeset
812 * even field numbers.
b88326454853 use correct field number for video according to specs, patch by Thierry Foucu, tfoucu at gmail dot com
bcoudurier
parents: 4479
diff changeset
813 * see SMPTE360M-2004 6.4.2.1.3 Media field number */
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5290
diff changeset
814 if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
815 field_nb = gxf->nb_fields;
4480
b88326454853 use correct field number for video according to specs, patch by Thierry Foucu, tfoucu at gmail dot com
bcoudurier
parents: 4479
diff changeset
816 } else {
4677
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
817 field_nb = av_rescale_rnd(pkt->dts, gxf->time_base.den,
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
818 (int64_t)48000*gxf->time_base.num, AV_ROUND_UP);
4480
b88326454853 use correct field number for video according to specs, patch by Thierry Foucu, tfoucu at gmail dot com
bcoudurier
parents: 4479
diff changeset
819 }
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
820
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
821 put_byte(pb, sc->media_type);
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
822 put_byte(pb, st->index);
4480
b88326454853 use correct field number for video according to specs, patch by Thierry Foucu, tfoucu at gmail dot com
bcoudurier
parents: 4479
diff changeset
823 put_be32(pb, field_nb);
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5290
diff changeset
824 if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
825 put_be16(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
826 put_be16(pb, size / 2);
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
827 } else if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO) {
1247
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
828 int frame_type = gxf_parse_mpeg_frame(sc, pkt->data, pkt->size);
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
829 if (frame_type == FF_I_TYPE) {
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
830 put_byte(pb, 0x0d);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
831 sc->iframes++;
1247
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
832 } else if (frame_type == FF_B_TYPE) {
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
833 put_byte(pb, 0x0f);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
834 sc->bframes++;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
835 } else {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
836 put_byte(pb, 0x0e);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
837 sc->pframes++;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
838 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
839 put_be24(pb, size);
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
840 } else if (st->codec->codec_id == CODEC_ID_DVVIDEO) {
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
841 put_byte(pb, size / 4096);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
842 put_be24(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
843 } else
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
844 put_be32(pb, size);
4480
b88326454853 use correct field number for video according to specs, patch by Thierry Foucu, tfoucu at gmail dot com
bcoudurier
parents: 4479
diff changeset
845 put_be32(pb, field_nb);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
846 put_byte(pb, 1); /* flags */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
847 put_byte(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
848 return 16;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
849 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
850
4674
c727d4a90177 factorize write packet
bcoudurier
parents: 4673
diff changeset
851 static int gxf_write_packet(AVFormatContext *s, AVPacket *pkt)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
852 {
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
853 GXFContext *gxf = s->priv_data;
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
854 ByteIOContext *pb = s->pb;
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
855 AVStream *st = s->streams[pkt->stream_index];
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
856 int64_t pos = url_ftell(pb);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
857 int padding = 0;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
858
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
859 gxf_write_packet_header(pb, PKT_MEDIA);
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
860 if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO && pkt->size % 4) /* MPEG-2 frames must be padded */
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
861 padding = 4 - pkt->size % 4;
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5290
diff changeset
862 else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
1212
b4f48eb1f411 avoid reading beyond packet size
bcoudurier
parents: 1183
diff changeset
863 padding = GXF_AUDIO_PACKET_SIZE - pkt->size;
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
864 gxf_write_media_preamble(s, pkt, pkt->size + padding);
1212
b4f48eb1f411 avoid reading beyond packet size
bcoudurier
parents: 1183
diff changeset
865 put_buffer(pb, pkt->data, pkt->size);
b4f48eb1f411 avoid reading beyond packet size
bcoudurier
parents: 1183
diff changeset
866 gxf_write_padding(pb, padding);
4262
f146ce39977a Do not use avctx->frame_number which might not be set,
bcoudurier
parents: 4261
diff changeset
867
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5290
diff changeset
868 if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
4678
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
869 if (!(gxf->flt_entries_nb % 500)) {
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
870 gxf->flt_entries = av_realloc(gxf->flt_entries,
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
871 (gxf->flt_entries_nb+500)*sizeof(*gxf->flt_entries));
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
872 if (!gxf->flt_entries) {
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
873 av_log(s, AV_LOG_ERROR, "could not reallocate flt entries\n");
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
874 return -1;
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
875 }
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
876 }
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
877 gxf->flt_entries[gxf->flt_entries_nb++] = url_ftell(pb) / 1024;
4672
f5d61e72fec5 uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents: 4671
diff changeset
878 gxf->nb_fields += 2; // count fields
4678
65036104b950 write flt packet, might need some tweaking but it works
bcoudurier
parents: 4677
diff changeset
879 }
4262
f146ce39977a Do not use avctx->frame_number which might not be set,
bcoudurier
parents: 4261
diff changeset
880
4679
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
881 updatePacketSize(pb, pos);
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
882
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
883 gxf->packet_count++;
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
884 if (gxf->packet_count == 100) {
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
885 gxf_write_map_packet(s, 0);
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
886 gxf->packet_count = 0;
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
887 }
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
888
4674
c727d4a90177 factorize write packet
bcoudurier
parents: 4673
diff changeset
889 put_flush_packet(pb);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
890
4679
697b6a0366a6 write map packet every 100 packets according to specs
bcoudurier
parents: 4678
diff changeset
891 return 0;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
892 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
893
4677
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
894 static int gxf_compare_field_nb(AVFormatContext *s, AVPacket *next, AVPacket *cur)
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
895 {
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
896 GXFContext *gxf = s->priv_data;
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
897 AVPacket *pkt[2] = { cur, next };
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
898 int i, field_nb[2];
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
899 GXFStreamContext *sc[2];
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
900
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
901 for (i = 0; i < 2; i++) {
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
902 AVStream *st = s->streams[pkt[i]->stream_index];
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
903 sc[i] = st->priv_data;
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5290
diff changeset
904 if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
4677
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
905 field_nb[i] = av_rescale_rnd(pkt[i]->dts, gxf->time_base.den,
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
906 (int64_t)48000*gxf->time_base.num, AV_ROUND_UP);
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
907 field_nb[i] &= ~1; // compare against even field number because audio must be before video
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
908 } else
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
909 field_nb[i] = pkt[i]->dts; // dts are field based
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
910 }
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
911
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
912 return field_nb[1] > field_nb[0] ||
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
913 (field_nb[1] == field_nb[0] && sc[1]->order > sc[0]->order);
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
914 }
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
915
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
916 static int gxf_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
917 {
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5290
diff changeset
918 if (pkt && s->streams[pkt->stream_index]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
4677
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
919 pkt->duration = 2; // enforce 2 fields
4426
7854590fb1fd rename ff_audio_interleave to ff_audio_rechunk_interleave
bcoudurier
parents: 4401
diff changeset
920 return ff_audio_rechunk_interleave(s, out, pkt, flush,
4677
96c24e93b7d8 correctly interleave audio and video according to specs
bcoudurier
parents: 4676
diff changeset
921 av_interleave_packet_per_dts, gxf_compare_field_nb);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
922 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
923
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
924 AVOutputFormat gxf_muxer = {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
925 "gxf",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3368
diff changeset
926 NULL_IF_CONFIG_SMALL("GXF format"),
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
927 NULL,
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
928 "gxf",
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
929 sizeof(GXFContext),
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
930 CODEC_ID_PCM_S16LE,
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
931 CODEC_ID_MPEG2VIDEO,
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
932 gxf_write_header,
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
933 gxf_write_packet,
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
934 gxf_write_trailer,
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
935 0,
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
936 NULL,
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
937 gxf_interleave_packet,
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
938 };