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