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