Mercurial > libavformat.hg
annotate gxfenc.c @ 4675:f036a151abf8 libavformat
compute media info in write_header
author | bcoudurier |
---|---|
date | Sun, 08 Mar 2009 22:23:44 +0000 |
parents | c727d4a90177 |
children | 0e45c20bbb9e |
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 i; |
420 | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
421 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
|
422 for (i = 0; i < s->nb_streams; ++i) { |
4675 | 423 GXFStreamContext *sc = s->streams[i]->priv_data; |
1183 | 424 put_le16(pb, sc->media_info); |
425 put_le16(pb, 1); | |
426 } | |
427 return url_ftell(pb) - pos; | |
428 } | |
429 | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
430 static int gxf_write_umf_media_mpeg(ByteIOContext *pb, AVStream *st) |
1183 | 431 { |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
432 GXFStreamContext *sc = st->priv_data; |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
433 |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
434 if (st->codec->pix_fmt == PIX_FMT_YUV422P) |
1183 | 435 put_le32(pb, 2); |
436 else | |
437 put_le32(pb, 1); /* default to 420 */ | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
438 put_le32(pb, sc->first_gop_closed == 1); /* closed = 1, open = 0, unknown = 255 */ |
1183 | 439 put_le32(pb, 3); /* top = 1, bottom = 2, frame = 3, unknown = 0 */ |
440 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
|
441 put_le32(pb, sc->p_per_gop); |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
442 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
|
443 if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO) |
1183 | 444 put_le32(pb, 2); |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
445 else if (st->codec->codec_id == CODEC_ID_MPEG1VIDEO) |
1183 | 446 put_le32(pb, 1); |
447 else | |
448 put_le32(pb, 0); | |
449 put_le32(pb, 0); /* reserved */ | |
450 return 32; | |
451 } | |
452 | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
453 static int gxf_write_umf_media_timecode(ByteIOContext *pb, GXFStreamContext *sc) |
1183 | 454 { |
455 /* FIXME implement */ | |
456 put_be32(pb, 0); /* drop frame flag */ | |
457 put_be32(pb, 0); /* reserved */ | |
458 put_be32(pb, 0); /* reserved */ | |
459 put_be32(pb, 0); /* reserved */ | |
460 put_be32(pb, 0); /* reserved */ | |
461 put_be32(pb, 0); /* reserved */ | |
462 put_be32(pb, 0); /* reserved */ | |
463 put_be32(pb, 0); /* reserved */ | |
464 return 32; | |
465 } | |
466 | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
467 static int gxf_write_umf_media_dv(ByteIOContext *pb, GXFStreamContext *sc) |
1183 | 468 { |
469 int i; | |
470 | |
471 for (i = 0; i < 8; i++) { | |
472 put_be32(pb, 0); | |
473 } | |
474 return 32; | |
475 } | |
476 | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
477 static int gxf_write_umf_media_audio(ByteIOContext *pb, GXFStreamContext *sc) |
1183 | 478 { |
479 put_le64(pb, av_dbl2int(1)); /* sound level to begin to */ | |
480 put_le64(pb, av_dbl2int(1)); /* sound level to begin to */ | |
481 put_le32(pb, 0); /* number of fields over which to ramp up sound level */ | |
482 put_le32(pb, 0); /* number of fields over which to ramp down sound level */ | |
483 put_le32(pb, 0); /* reserved */ | |
484 put_le32(pb, 0); /* reserved */ | |
485 return 32; | |
486 } | |
487 | |
488 #if 0 | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
489 static int gxf_write_umf_media_mjpeg(ByteIOContext *pb, GXFStreamContext *sc) |
1183 | 490 { |
491 put_be64(pb, 0); /* FIXME FLOAT max chroma quant level */ | |
492 put_be64(pb, 0); /* FIXME FLOAT max luma quant level */ | |
493 put_be64(pb, 0); /* FIXME FLOAT min chroma quant level */ | |
494 put_be64(pb, 0); /* FIXME FLOAT min luma quant level */ | |
495 return 32; | |
496 } | |
497 #endif | |
498 | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
499 static int gxf_write_umf_media_description(AVFormatContext *s) |
1183 | 500 { |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
501 GXFContext *gxf = s->priv_data; |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
502 ByteIOContext *pb = s->pb; |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3424
diff
changeset
|
503 int64_t pos; |
1183 | 504 int i; |
505 | |
506 pos = url_ftell(pb); | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
507 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
|
508 for (i = 0; i < s->nb_streams; ++i) { |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
509 AVStream *st = s->streams[i]; |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
510 GXFStreamContext *sc = st->priv_data; |
1183 | 511 char buffer[88]; |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3424
diff
changeset
|
512 int64_t startpos, curpos; |
1183 | 513 int path_size = strlen(ES_NAME_PATTERN); |
514 | |
1260 | 515 memset(buffer, 0, 88); |
1183 | 516 startpos = url_ftell(pb); |
517 put_le16(pb, 0); /* length */ | |
518 put_le16(pb, sc->media_info); | |
519 put_le16(pb, 0); /* reserved */ | |
520 put_le16(pb, 0); /* reserved */ | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
521 put_le32(pb, gxf->nb_fields); |
1183 | 522 put_le32(pb, 0); /* attributes rw, ro */ |
523 put_le32(pb, 0); /* mark in */ | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
524 put_le32(pb, gxf->nb_fields); /* mark out */ |
1183 | 525 strncpy(buffer, ES_NAME_PATTERN, path_size); |
526 put_buffer(pb, (uint8_t *)buffer, path_size); | |
527 put_be16(pb, sc->media_info); | |
528 put_buffer(pb, (uint8_t *)buffer + path_size + 2, 88 - path_size - 2); | |
529 put_le32(pb, sc->track_type); | |
530 put_le32(pb, sc->sample_rate); | |
531 put_le32(pb, sc->sample_size); | |
532 put_le32(pb, 0); /* reserved */ | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
533 switch (st->codec->codec_id) { |
1183 | 534 case CODEC_ID_MPEG2VIDEO: |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
535 gxf_write_umf_media_mpeg(pb, st); |
1183 | 536 break; |
537 case CODEC_ID_PCM_S16LE: | |
538 gxf_write_umf_media_audio(pb, sc); | |
539 break; | |
540 case CODEC_ID_DVVIDEO: | |
541 gxf_write_umf_media_dv(pb, sc); | |
542 break; | |
543 default: | |
544 gxf_write_umf_media_timecode(pb, sc); /* 8 0bytes */ | |
545 } | |
546 curpos = url_ftell(pb); | |
547 url_fseek(pb, startpos, SEEK_SET); | |
548 put_le16(pb, curpos - startpos); | |
549 url_fseek(pb, curpos, SEEK_SET); | |
550 } | |
551 return url_ftell(pb) - pos; | |
552 } | |
553 | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
554 static int gxf_write_umf_packet(AVFormatContext *s) |
1183 | 555 { |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
556 GXFContext *gxf = s->priv_data; |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
557 ByteIOContext *pb = s->pb; |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3424
diff
changeset
|
558 int64_t pos = url_ftell(pb); |
1183 | 559 |
560 gxf_write_packet_header(pb, PKT_UMF); | |
561 | |
562 /* preamble */ | |
563 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
|
564 put_be32(pb, gxf->umf_length); /* data length */ |
1183 | 565 |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
566 gxf->umf_start_offset = url_ftell(pb); |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
567 gxf_write_umf_payload(s); |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
568 gxf_write_umf_material_description(s); |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
569 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
|
570 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
|
571 gxf->umf_length = url_ftell(pb) - gxf->umf_start_offset; |
1183 | 572 return updatePacketSize(pb, pos); |
573 } | |
574 | |
4401 | 575 static const int GXF_samples_per_frame[] = { 32768, 0 }; |
576 | |
1183 | 577 static int gxf_write_header(AVFormatContext *s) |
578 { | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2337
diff
changeset
|
579 ByteIOContext *pb = s->pb; |
1183 | 580 GXFContext *gxf = s->priv_data; |
4675 | 581 uint8_t tracks[255] = {0}; |
582 int i, media_info = 0; | |
1183 | 583 |
584 gxf->flags |= 0x00080000; /* material is simple clip */ | |
585 for (i = 0; i < s->nb_streams; ++i) { | |
586 AVStream *st = s->streams[i]; | |
4329 | 587 GXFStreamContext *sc = av_mallocz(sizeof(*sc)); |
588 if (!sc) | |
589 return AVERROR(ENOMEM); | |
590 st->priv_data = sc; | |
1183 | 591 |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
592 sc->media_type = codec_get_tag(gxf_media_types, st->codec->codec_id); |
1183 | 593 if (st->codec->codec_type == CODEC_TYPE_AUDIO) { |
594 if (st->codec->codec_id != CODEC_ID_PCM_S16LE) { | |
595 av_log(s, AV_LOG_ERROR, "only 16 BIT PCM LE allowed for now\n"); | |
596 return -1; | |
597 } | |
598 if (st->codec->sample_rate != 48000) { | |
599 av_log(s, AV_LOG_ERROR, "only 48000hz sampling rate is allowed\n"); | |
600 return -1; | |
601 } | |
602 if (st->codec->channels != 1) { | |
603 av_log(s, AV_LOG_ERROR, "only mono tracks are allowed\n"); | |
604 return -1; | |
605 } | |
606 sc->track_type = 2; | |
607 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
|
608 av_set_pts_info(st, 64, 1, sc->sample_rate); |
1183 | 609 sc->sample_size = 16; |
610 sc->frame_rate_index = -2; | |
611 sc->lines_index = -2; | |
612 sc->fields = -2; | |
613 gxf->audio_tracks++; | |
614 gxf->flags |= 0x04000000; /* audio is 16 bit pcm */ | |
4675 | 615 media_info = 'A'; |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
616 } else if (st->codec->codec_type == CODEC_TYPE_VIDEO) { |
1183 | 617 /* FIXME check from time_base ? */ |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
618 if (st->codec->height == 480 || st->codec->height == 512) { /* NTSC or NTSC+VBI */ |
1183 | 619 sc->frame_rate_index = 5; |
620 sc->sample_rate = 60; | |
621 gxf->flags |= 0x00000080; | |
622 } else { /* assume PAL */ | |
623 sc->frame_rate_index = 6; | |
624 sc->media_type++; | |
625 sc->sample_rate = 50; | |
626 gxf->flags |= 0x00000040; | |
627 } | |
628 gxf->sample_rate = sc->sample_rate; | |
1794 | 629 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
|
630 if (gxf_find_lines_index(st) < 0) |
1183 | 631 sc->lines_index = -1; |
632 sc->sample_size = st->codec->bit_rate; | |
633 sc->fields = 2; /* interlaced */ | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
634 switch (st->codec->codec_id) { |
4675 | 635 case CODEC_ID_MJPEG: |
636 sc->track_type = 1; | |
637 gxf->flags |= 0x00004000; | |
638 media_info = 'J'; | |
639 break; | |
640 case CODEC_ID_MPEG1VIDEO: | |
641 sc->track_type = 9; | |
642 gxf->mpeg_tracks++; | |
643 media_info = 'L'; | |
644 break; | |
1183 | 645 case CODEC_ID_MPEG2VIDEO: |
1262 | 646 sc->first_gop_closed = -1; |
1183 | 647 sc->track_type = 4; |
648 gxf->mpeg_tracks++; | |
649 gxf->flags |= 0x00008000; | |
4675 | 650 media_info = 'M'; |
1183 | 651 break; |
652 case CODEC_ID_DVVIDEO: | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
653 if (st->codec->pix_fmt == PIX_FMT_YUV422P) { |
1183 | 654 sc->media_type += 2; |
655 sc->track_type = 6; | |
656 gxf->flags |= 0x00002000; | |
4675 | 657 media_info = 'E'; |
1183 | 658 } else { |
659 sc->track_type = 5; | |
660 gxf->flags |= 0x00001000; | |
4675 | 661 media_info = 'D'; |
1183 | 662 } |
663 break; | |
664 default: | |
1401 | 665 av_log(s, AV_LOG_ERROR, "video codec not supported\n"); |
1183 | 666 return -1; |
667 } | |
668 } | |
4675 | 669 /* FIXME first 10 audio tracks are 0 to 9 next 22 are A to V */ |
670 sc->media_info = media_info<<8 | ('0'+tracks[media_info]++); | |
1183 | 671 } |
4401 | 672 |
673 if (ff_audio_interleave_init(s, GXF_samples_per_frame, (AVRational){ 1, 48000 }) < 0) | |
674 return -1; | |
675 | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
676 gxf_write_map_packet(s); |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
677 //gxf_write_flt_packet(s); |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
678 gxf_write_umf_packet(s); |
1183 | 679 put_flush_packet(pb); |
680 return 0; | |
681 } | |
682 | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
683 static int gxf_write_eos_packet(ByteIOContext *pb) |
1183 | 684 { |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3424
diff
changeset
|
685 int64_t pos = url_ftell(pb); |
1183 | 686 |
687 gxf_write_packet_header(pb, PKT_EOS); | |
688 return updatePacketSize(pb, pos); | |
689 } | |
690 | |
691 static int gxf_write_trailer(AVFormatContext *s) | |
692 { | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2337
diff
changeset
|
693 ByteIOContext *pb = s->pb; |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3424
diff
changeset
|
694 int64_t end; |
1183 | 695 |
4401 | 696 ff_audio_interleave_close(s); |
1183 | 697 |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
698 gxf_write_eos_packet(pb); |
1183 | 699 end = url_ftell(pb); |
700 url_fseek(pb, 0, SEEK_SET); | |
701 /* 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
|
702 gxf_write_map_packet(s); |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
703 //gxf_write_flt_packet(s); |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
704 gxf_write_umf_packet(s); |
1183 | 705 url_fseek(pb, end, SEEK_SET); |
706 return 0; | |
707 } | |
708 | |
1247
2f118b3e65c6
parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents:
1213
diff
changeset
|
709 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
|
710 { |
2f118b3e65c6
parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents:
1213
diff
changeset
|
711 uint32_t c=-1; |
2f118b3e65c6
parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents:
1213
diff
changeset
|
712 int i; |
2f118b3e65c6
parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents:
1213
diff
changeset
|
713 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
|
714 c = (c<<8) + buf[i]; |
1262 | 715 if(c == 0x1B8 && sc->first_gop_closed == -1) /* GOP start code */ |
1261 | 716 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
|
717 } |
2f118b3e65c6
parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents:
1213
diff
changeset
|
718 return (buf[i+1]>>3)&7; |
2f118b3e65c6
parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents:
1213
diff
changeset
|
719 } |
2f118b3e65c6
parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents:
1213
diff
changeset
|
720 |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
721 static int gxf_write_media_preamble(AVFormatContext *s, AVPacket *pkt, int size) |
1183 | 722 { |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
723 GXFContext *gxf = s->priv_data; |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
724 ByteIOContext *pb = s->pb; |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
725 AVStream *st = s->streams[pkt->stream_index]; |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
726 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
|
727 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
|
728 /* 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
|
729 * 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
|
730 * 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
|
731 if (st->codec->codec_type == CODEC_TYPE_VIDEO) { |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
732 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
|
733 } else { |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
734 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
|
735 } |
1183 | 736 |
737 put_byte(pb, sc->media_type); | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
738 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
|
739 put_be32(pb, field_nb); |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
740 if (st->codec->codec_type == CODEC_TYPE_AUDIO) { |
1183 | 741 put_be16(pb, 0); |
742 put_be16(pb, size / 2); | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
743 } 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
|
744 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
|
745 if (frame_type == FF_I_TYPE) { |
1183 | 746 put_byte(pb, 0x0d); |
747 sc->iframes++; | |
1247
2f118b3e65c6
parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents:
1213
diff
changeset
|
748 } else if (frame_type == FF_B_TYPE) { |
1183 | 749 put_byte(pb, 0x0f); |
750 sc->bframes++; | |
751 } else { | |
752 put_byte(pb, 0x0e); | |
753 sc->pframes++; | |
754 } | |
755 put_be24(pb, size); | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
756 } else if (st->codec->codec_id == CODEC_ID_DVVIDEO) { |
1183 | 757 put_byte(pb, size / 4096); |
758 put_be24(pb, 0); | |
759 } else | |
760 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
|
761 put_be32(pb, field_nb); |
1183 | 762 put_byte(pb, 1); /* flags */ |
763 put_byte(pb, 0); /* reserved */ | |
764 return 16; | |
765 } | |
766 | |
4674 | 767 static int gxf_write_packet(AVFormatContext *s, AVPacket *pkt) |
1183 | 768 { |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
769 GXFContext *gxf = s->priv_data; |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
770 ByteIOContext *pb = s->pb; |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
771 AVStream *st = s->streams[pkt->stream_index]; |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3424
diff
changeset
|
772 int64_t pos = url_ftell(pb); |
1183 | 773 int padding = 0; |
774 | |
775 gxf_write_packet_header(pb, PKT_MEDIA); | |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
776 if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO && pkt->size % 4) /* MPEG-2 frames must be padded */ |
1183 | 777 padding = 4 - pkt->size % 4; |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
778 else if (st->codec->codec_type == CODEC_TYPE_AUDIO) |
1212 | 779 padding = GXF_AUDIO_PACKET_SIZE - pkt->size; |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
780 gxf_write_media_preamble(s, pkt, pkt->size + padding); |
1212 | 781 put_buffer(pb, pkt->data, pkt->size); |
782 gxf_write_padding(pb, padding); | |
4262
f146ce39977a
Do not use avctx->frame_number which might not be set,
bcoudurier
parents:
4261
diff
changeset
|
783 |
4672
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
784 if (st->codec->codec_type == CODEC_TYPE_VIDEO) |
f5d61e72fec5
uniformize variable names and remove duplicating fields in private structs
bcoudurier
parents:
4671
diff
changeset
|
785 gxf->nb_fields += 2; // count fields |
4262
f146ce39977a
Do not use avctx->frame_number which might not be set,
bcoudurier
parents:
4261
diff
changeset
|
786 |
4674 | 787 put_flush_packet(pb); |
1183 | 788 |
4674 | 789 return updatePacketSize(pb, pos); |
1183 | 790 } |
791 | |
792 static int gxf_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) | |
793 { | |
4426
7854590fb1fd
rename ff_audio_interleave to ff_audio_rechunk_interleave
bcoudurier
parents:
4401
diff
changeset
|
794 return ff_audio_rechunk_interleave(s, out, pkt, flush, |
4401 | 795 av_interleave_packet_per_dts, ff_interleave_compare_dts); |
1183 | 796 } |
797 | |
798 AVOutputFormat gxf_muxer = { | |
799 "gxf", | |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3368
diff
changeset
|
800 NULL_IF_CONFIG_SMALL("GXF format"), |
1183 | 801 NULL, |
802 "gxf", | |
803 sizeof(GXFContext), | |
804 CODEC_ID_PCM_S16LE, | |
805 CODEC_ID_MPEG2VIDEO, | |
806 gxf_write_header, | |
807 gxf_write_packet, | |
808 gxf_write_trailer, | |
809 0, | |
810 NULL, | |
811 gxf_interleave_packet, | |
812 }; |