annotate gxfenc.c @ 4356:459c0242194e libavformat

cosmetics: indentation
author aurel
date Mon, 02 Feb 2009 22:14:28 +0000
parents bd49910ad4a0
children 880838781e34
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
1 /*
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
2 * GXF muxer.
4251
77e0c7511d41 cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 4098
diff changeset
3 * Copyright (c) 2006 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1322
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1322
diff changeset
6 *
2252
708e6e93d6f2 Smartjog granted permission to relicense as LGPL 2.1
bcoudurier
parents: 2251
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
708e6e93d6f2 Smartjog granted permission to relicense as LGPL 2.1
bcoudurier
parents: 2251
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
708e6e93d6f2 Smartjog granted permission to relicense as LGPL 2.1
bcoudurier
parents: 2251
diff changeset
9 * License as published by the Free Software Foundation; either
708e6e93d6f2 Smartjog granted permission to relicense as LGPL 2.1
bcoudurier
parents: 2251
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1322
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2252
708e6e93d6f2 Smartjog granted permission to relicense as LGPL 2.1
bcoudurier
parents: 2251
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
708e6e93d6f2 Smartjog granted permission to relicense as LGPL 2.1
bcoudurier
parents: 2251
diff changeset
15 * Lesser General Public License for more details.
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
16 *
2252
708e6e93d6f2 Smartjog granted permission to relicense as LGPL 2.1
bcoudurier
parents: 2251
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
708e6e93d6f2 Smartjog granted permission to relicense as LGPL 2.1
bcoudurier
parents: 2251
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1322
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
20 */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
21
3286
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 2771
diff changeset
22 #include "libavutil/fifo.h"
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
23 #include "avformat.h"
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
24 #include "gxf.h"
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
25 #include "riff.h"
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
26
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
27 #define GXF_AUDIO_PACKET_SIZE 65536
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
28
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
29 typedef struct GXFStreamContext {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
30 AVCodecContext *codec;
1322
95f56c7b24eb * Moving FifoBuffer out of libavformat/avformat.h and
romansh
parents: 1262
diff changeset
31 AVFifoBuffer audio_buffer;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
32 uint32_t track_type;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
33 uint32_t sample_size;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
34 uint32_t sample_rate;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
35 uint16_t media_type;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
36 uint16_t media_info;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
37 uint8_t index;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
38 int frame_rate_index;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
39 int lines_index;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
40 int fields;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
41 int iframes;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
42 int pframes;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
43 int bframes;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
44 int p_per_gop;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
45 int b_per_gop;
1261
e03e8ce942e8 rename closed_gop to first_gop_closed
bcoudurier
parents: 1260
diff changeset
46 int first_gop_closed;
1253
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
47 int64_t current_dts;
1542
98ef8d631737 readjust dts if negative
bcoudurier
parents: 1401
diff changeset
48 int dts_delay;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
49 } GXFStreamContext;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
50
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
51 typedef struct GXFContext {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
52 uint32_t nb_frames;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
53 uint32_t material_flags;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
54 uint16_t audio_tracks;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
55 uint16_t mpeg_tracks;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
56 int64_t creation_time;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
57 uint32_t umf_start_offset;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
58 uint32_t umf_track_offset;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
59 uint32_t umf_media_offset;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
60 uint32_t umf_user_data_offset;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
61 uint32_t umf_user_data_size;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
62 uint32_t umf_length;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
63 uint16_t umf_track_size;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
64 uint16_t umf_media_size;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
65 int audio_written;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
66 int sample_rate;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
67 int flags;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
68 AVFormatContext *fc;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
69 } GXFContext;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
70
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
71 typedef struct GXF_Lines {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
72 int height;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
73 int index;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
74 } GXF_Lines;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
75
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
76
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
77 /* FIXME check if it is relevant */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
78 static const GXF_Lines gxf_lines_tab[] = {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
79 { 480, 1 }, /* NTSC */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
80 { 512, 1 }, /* NTSC + VBI */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
81 { 576, 2 }, /* PAL */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
82 { 608, 2 }, /* PAL + VBI */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
83 { 1080, 4 },
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
84 { 720, 6 },
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
85 };
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
86
1677
2a85c82b8538 add codec_id <-> codec_tag tables to AVIn/OutputFormat
michael
parents: 1542
diff changeset
87 static const AVCodecTag gxf_media_types[] = {
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
88 { CODEC_ID_MJPEG , 3 }, /* NTSC */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
89 { CODEC_ID_MJPEG , 4 }, /* PAL */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
90 { CODEC_ID_PCM_S24LE , 9 },
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
91 { CODEC_ID_PCM_S16LE , 10 },
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
92 { CODEC_ID_MPEG2VIDEO, 11 }, /* NTSC */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
93 { CODEC_ID_MPEG2VIDEO, 12 }, /* PAL */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
94 { CODEC_ID_DVVIDEO , 13 }, /* NTSC */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
95 { CODEC_ID_DVVIDEO , 14 }, /* PAL */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
96 { CODEC_ID_DVVIDEO , 15 }, /* 50M NTSC */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
97 { CODEC_ID_DVVIDEO , 16 }, /* 50M PAL */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
98 { CODEC_ID_AC3 , 17 },
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
99 //{ CODEC_ID_NONE, , 18 }, /* Non compressed 24 bit audio */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
100 { CODEC_ID_MPEG2VIDEO, 20 }, /* MPEG HD */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
101 { CODEC_ID_MPEG1VIDEO, 22 }, /* NTSC */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
102 { CODEC_ID_MPEG1VIDEO, 23 }, /* PAL */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
103 { 0, 0 },
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
104 };
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
105
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
106 #define SERVER_PATH "/space/"
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
107 #define ES_NAME_PATTERN "ES."
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
108
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
109 static int gxf_find_lines_index(GXFStreamContext *ctx)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
110 {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
111 int i;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
112
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
113 for (i = 0; i < 6; ++i) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
114 if (ctx->codec->height == gxf_lines_tab[i].height) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
115 ctx->lines_index = gxf_lines_tab[i].index;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
116 return 0;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
117 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
118 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
119 return -1;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
120 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
121
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
122 static void gxf_write_padding(ByteIOContext *pb, int64_t to_pad)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
123 {
1213
fe9ebf4ce09e negative to_pad won't provoke infinite loop
bcoudurier
parents: 1212
diff changeset
124 for (; to_pad > 0; to_pad--) {
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
125 put_byte(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
126 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
127 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
128
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
129 static int64_t updatePacketSize(ByteIOContext *pb, int64_t pos)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
130 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
131 int64_t curpos;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
132 int size;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
133
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
134 size = url_ftell(pb) - pos;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
135 if (size % 4) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
136 gxf_write_padding(pb, 4 - size % 4);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
137 size = url_ftell(pb) - pos;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
138 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
139 curpos = url_ftell(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
140 url_fseek(pb, pos + 6, SEEK_SET);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
141 put_be32(pb, size);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
142 url_fseek(pb, curpos, SEEK_SET);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
143 return curpos - pos;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
144 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
145
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
146 static int64_t updateSize(ByteIOContext *pb, int64_t pos)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
147 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
148 int64_t curpos;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
149
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
150 curpos = url_ftell(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
151 url_fseek(pb, pos, SEEK_SET);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
152 put_be16(pb, curpos - pos - 2);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
153 url_fseek(pb, curpos, SEEK_SET);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
154 return curpos - pos;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
155 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
156
4098
10d52cda08dd Avoid _t in gxf enum type names
reimar
parents: 3973
diff changeset
157 static void gxf_write_packet_header(ByteIOContext *pb, GXFPktType type)
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
158 {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
159 put_be32(pb, 0); /* packet leader for synchro */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
160 put_byte(pb, 1);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
161 put_byte(pb, type); /* map packet */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
162 put_be32(pb, 0); /* size */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
163 put_be32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
164 put_byte(pb, 0xE1); /* trailer 1 */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
165 put_byte(pb, 0xE2); /* trailer 2 */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
166 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
167
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
168 static int gxf_write_mpeg_auxiliary(ByteIOContext *pb, GXFStreamContext *ctx)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
169 {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
170 char buffer[1024];
4261
af29578c3d77 set correct value for starting line
bcoudurier
parents: 4260
diff changeset
171 int size, starting_line;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
172
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
173 if (ctx->iframes) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
174 ctx->p_per_gop = ctx->pframes / ctx->iframes;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
175 if (ctx->pframes % ctx->iframes)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
176 ctx->p_per_gop++;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
177 if (ctx->pframes)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
178 ctx->b_per_gop = ctx->bframes / ctx->pframes;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
179 if (ctx->p_per_gop > 9)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
180 ctx->p_per_gop = 9; /* ensure value won't take more than one char */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
181 if (ctx->b_per_gop > 9)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
182 ctx->b_per_gop = 9; /* ensure value won't take more than one char */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
183 }
4261
af29578c3d77 set correct value for starting line
bcoudurier
parents: 4260
diff changeset
184 if (ctx->codec->height == 512 || ctx->codec->height == 608)
af29578c3d77 set correct value for starting line
bcoudurier
parents: 4260
diff changeset
185 starting_line = 7; // VBI
af29578c3d77 set correct value for starting line
bcoudurier
parents: 4260
diff changeset
186 else if (ctx->codec->height == 480)
af29578c3d77 set correct value for starting line
bcoudurier
parents: 4260
diff changeset
187 starting_line = 20;
af29578c3d77 set correct value for starting line
bcoudurier
parents: 4260
diff changeset
188 else
af29578c3d77 set correct value for starting line
bcoudurier
parents: 4260
diff changeset
189 starting_line = 23; // default PAL
af29578c3d77 set correct value for starting line
bcoudurier
parents: 4260
diff changeset
190
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
191 size = snprintf(buffer, 1024, "Ver 1\nBr %.6f\nIpg 1\nPpi %d\nBpiop %d\n"
4261
af29578c3d77 set correct value for starting line
bcoudurier
parents: 4260
diff changeset
192 "Pix 0\nCf %d\nCg %d\nSl %d\nnl16 %d\nVi 1\nf1 1\n",
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
193 (float)ctx->codec->bit_rate, ctx->p_per_gop, ctx->b_per_gop,
1262
8da1b141e83a set correct first gop closed value
bcoudurier
parents: 1261
diff changeset
194 ctx->codec->pix_fmt == PIX_FMT_YUV422P ? 2 : 1, ctx->first_gop_closed == 1,
4261
af29578c3d77 set correct value for starting line
bcoudurier
parents: 4260
diff changeset
195 starting_line, ctx->codec->height / 16);
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
196 put_byte(pb, TRACK_MPG_AUX);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
197 put_byte(pb, size + 1);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
198 put_buffer(pb, (uint8_t *)buffer, size + 1);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
199 return size + 3;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
200 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
201
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
202 static int gxf_write_timecode_auxiliary(ByteIOContext *pb, GXFStreamContext *ctx)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
203 {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
204 /* FIXME implement that */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
205 put_byte(pb, 0); /* fields */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
206 put_byte(pb, 0); /* seconds */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
207 put_byte(pb, 0); /* minutes */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
208 put_byte(pb, 0); /* flags + hours */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
209 /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
210 put_be32(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
211 return 8;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
212 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
213
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
214 static int gxf_write_track_description(ByteIOContext *pb, GXFStreamContext *stream)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
215 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
216 int64_t pos;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
217
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
218 /* track description section */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
219 put_byte(pb, stream->media_type + 0x80);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
220 put_byte(pb, stream->index + 0xC0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
221
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
222 pos = url_ftell(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
223 put_be16(pb, 0); /* size */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
224
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
225 /* media file name */
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
226 put_byte(pb, TRACK_NAME);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
227 put_byte(pb, strlen(ES_NAME_PATTERN) + 3);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
228 put_tag(pb, ES_NAME_PATTERN);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
229 put_be16(pb, stream->media_info);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
230 put_byte(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
231
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
232 if (stream->codec->codec_id != CODEC_ID_MPEG2VIDEO) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
233 /* auxiliary information */
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
234 put_byte(pb, TRACK_AUX);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
235 put_byte(pb, 8);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
236 if (stream->codec->codec_id == CODEC_ID_NONE)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
237 gxf_write_timecode_auxiliary(pb, stream);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
238 else
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
239 put_le64(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
240 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
241
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
242 /* file system version */
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
243 put_byte(pb, TRACK_VER);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
244 put_byte(pb, 4);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
245 put_be32(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
246
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
247 if (stream->codec->codec_id == CODEC_ID_MPEG2VIDEO)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
248 gxf_write_mpeg_auxiliary(pb, stream);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
249
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
250 /* frame rate */
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
251 put_byte(pb, TRACK_FPS);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
252 put_byte(pb, 4);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
253 put_be32(pb, stream->frame_rate_index);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
254
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
255 /* lines per frame */
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
256 put_byte(pb, TRACK_LINES);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
257 put_byte(pb, 4);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
258 put_be32(pb, stream->lines_index);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
259
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
260 /* fields per frame */
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
261 put_byte(pb, TRACK_FPF);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
262 put_byte(pb, 4);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
263 put_be32(pb, stream->fields);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
264
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
265 return updateSize(pb, pos);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
266 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
267
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
268 static int gxf_write_material_data_section(ByteIOContext *pb, GXFContext *ctx)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
269 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
270 int64_t pos;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
271 const char *filename = strrchr(ctx->fc->filename, '/');
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
272
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
273 pos = url_ftell(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
274 put_be16(pb, 0); /* size */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
275
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
276 /* name */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
277 if (filename)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
278 filename++;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
279 else
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
280 filename = ctx->fc->filename;
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
281 put_byte(pb, MAT_NAME);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
282 put_byte(pb, strlen(SERVER_PATH) + strlen(filename) + 1);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
283 put_tag(pb, SERVER_PATH);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
284 put_tag(pb, filename);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
285 put_byte(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
286
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
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
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
289 put_byte(pb, 4);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
290 put_be32(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
291
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
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
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
294 put_byte(pb, 4);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
295 put_be32(pb, ctx->nb_frames);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
296
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
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
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
299 put_byte(pb, 4);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
300 put_be32(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
301
2282
47f5906c30cc replaces hardcoded values by the equivalent enum definitions
aurel
parents: 2252
diff changeset
302 put_byte(pb, MAT_MARK_OUT);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
303 put_byte(pb, 4);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
304 put_be32(pb, ctx->nb_frames);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
305
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
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
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
308 put_byte(pb, 4);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
309 put_be32(pb, url_fsize(pb) / 1024);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
310
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
311 return updateSize(pb, pos);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
312 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
313
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
314 static int gxf_write_track_description_section(ByteIOContext *pb, GXFContext *ctx)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
315 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
316 int64_t pos;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
317 int i;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
318
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
319 pos = url_ftell(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
320 put_be16(pb, 0); /* size */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
321 for (i = 0; i < ctx->fc->nb_streams; ++i)
4329
bd49910ad4a0 use st->priv_data to store per stream context
bcoudurier
parents: 4304
diff changeset
322 gxf_write_track_description(pb, ctx->fc->streams[i]->priv_data);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
323 return updateSize(pb, pos);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
324 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
325
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
326 static int gxf_write_map_packet(ByteIOContext *pb, GXFContext *ctx)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
327 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
328 int64_t pos = url_ftell(pb);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
329
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
330 gxf_write_packet_header(pb, PKT_MAP);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
331
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
332 /* preamble */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
333 put_byte(pb, 0xE0); /* version */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
334 put_byte(pb, 0xFF); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
335
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
336 gxf_write_material_data_section(pb, ctx);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
337 gxf_write_track_description_section(pb, ctx);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
338
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
339 return updatePacketSize(pb, pos);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
340 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
341
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
342 #if 0
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
343 static int gxf_write_flt_packet(ByteIOContext *pb, GXFContext *ctx)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
344 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
345 int64_t pos = url_ftell(pb);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
346 int i;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
347
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
348 gxf_write_packet_header(pb, PKT_FLT);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
349
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
350 put_le32(pb, 1000); /* number of fields */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
351 put_le32(pb, 0); /* number of active flt entries */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
352
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
353 for (i = 0; i < 1000; ++i) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
354 put_le32(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
355 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
356 return updatePacketSize(pb, pos);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
357 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
358 #endif
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
359
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
360 static int gxf_write_umf_material_description(ByteIOContext *pb, GXFContext *ctx)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
361 {
4260
40528f55532c fix gxf time code mark out value
bcoudurier
parents: 4251
diff changeset
362 // XXX drop frame
40528f55532c fix gxf time code mark out value
bcoudurier
parents: 4251
diff changeset
363 uint32_t timecode =
4304
8880764c2012 second try fixing time code in gxf
bcoudurier
parents: 4276
diff changeset
364 ctx->nb_frames / (ctx->sample_rate * 3600) % 24 << 24 | // hours
8880764c2012 second try fixing time code in gxf
bcoudurier
parents: 4276
diff changeset
365 ctx->nb_frames / (ctx->sample_rate * 60) % 60 << 16 | // minutes
8880764c2012 second try fixing time code in gxf
bcoudurier
parents: 4276
diff changeset
366 ctx->nb_frames / ctx->sample_rate % 60 << 8 | // seconds
4276
d9c25a41b461 fix endianness of time code, and calculate it in fields, according to specs
bcoudurier
parents: 4262
diff changeset
367 ctx->nb_frames % ctx->sample_rate; // fields
4260
40528f55532c fix gxf time code mark out value
bcoudurier
parents: 4251
diff changeset
368
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
369 put_le32(pb, ctx->flags);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
370 put_le32(pb, ctx->nb_frames); /* length of the longest track */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
371 put_le32(pb, ctx->nb_frames); /* length of the shortest track */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
372 put_le32(pb, 0); /* mark in */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
373 put_le32(pb, ctx->nb_frames); /* mark out */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
374 put_le32(pb, 0); /* timecode mark in */
4260
40528f55532c fix gxf time code mark out value
bcoudurier
parents: 4251
diff changeset
375 put_le32(pb, timecode); /* timecode mark out */
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
376 put_le64(pb, ctx->fc->timestamp); /* modification time */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
377 put_le64(pb, ctx->fc->timestamp); /* creation time */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
378 put_le16(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
379 put_le16(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
380 put_le16(pb, ctx->audio_tracks);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
381 put_le16(pb, 0); /* timecode track count */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
382 put_le16(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
383 put_le16(pb, ctx->mpeg_tracks);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
384 return 48;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
385 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
386
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
387 static int gxf_write_umf_payload(ByteIOContext *pb, GXFContext *ctx)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
388 {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
389 put_le32(pb, ctx->umf_length); /* total length of the umf data */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
390 put_le32(pb, 3); /* version */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
391 put_le32(pb, ctx->fc->nb_streams);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
392 put_le32(pb, ctx->umf_track_offset); /* umf track section offset */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
393 put_le32(pb, ctx->umf_track_size);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
394 put_le32(pb, ctx->fc->nb_streams);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
395 put_le32(pb, ctx->umf_media_offset);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
396 put_le32(pb, ctx->umf_media_size);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
397 put_le32(pb, ctx->umf_user_data_offset); /* user data offset */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
398 put_le32(pb, ctx->umf_user_data_size); /* user data size */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
399 put_le32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
400 put_le32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
401 return 48;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
402 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
403
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
404 static int gxf_write_umf_track_description(ByteIOContext *pb, GXFContext *ctx)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
405 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
406 int64_t pos = url_ftell(pb);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
407 int tracks[255]={0};
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
408 int i;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
409
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
410 ctx->umf_track_offset = pos - ctx->umf_start_offset;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
411 for (i = 0; i < ctx->fc->nb_streams; ++i) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
412 AVStream *st = ctx->fc->streams[i];
4329
bd49910ad4a0 use st->priv_data to store per stream context
bcoudurier
parents: 4304
diff changeset
413 GXFStreamContext *sc = st->priv_data;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
414 int id = 0;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
415
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
416 switch (st->codec->codec_id) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
417 case CODEC_ID_MPEG1VIDEO: id= 'L'; break;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
418 case CODEC_ID_MPEG2VIDEO: id= 'M'; break;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
419 case CODEC_ID_PCM_S16LE: id= 'A'; break;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
420 case CODEC_ID_DVVIDEO: id= sc->track_type == 6 ? 'E' : 'D'; break;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
421 case CODEC_ID_MJPEG: id= 'V'; break;
1361
37baab7af15a quiet gcc about enum value not handled in switch
bcoudurier
parents: 1358
diff changeset
422 default: break;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
423 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
424 sc->media_info= id << 8;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
425 /* FIXME first 10 audio tracks are 0 to 9 next 22 are A to V */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
426 sc->media_info |= '0' + (tracks[id]++);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
427 put_le16(pb, sc->media_info);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
428 put_le16(pb, 1);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
429 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
430 return url_ftell(pb) - pos;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
431 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
432
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
433 static int gxf_write_umf_media_mpeg(ByteIOContext *pb, GXFStreamContext *stream)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
434 {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
435 if (stream->codec->pix_fmt == PIX_FMT_YUV422P)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
436 put_le32(pb, 2);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
437 else
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
438 put_le32(pb, 1); /* default to 420 */
1262
8da1b141e83a set correct first gop closed value
bcoudurier
parents: 1261
diff changeset
439 put_le32(pb, stream->first_gop_closed == 1); /* closed = 1, open = 0, unknown = 255 */
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
440 put_le32(pb, 3); /* top = 1, bottom = 2, frame = 3, unknown = 0 */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
441 put_le32(pb, 1); /* I picture per GOP */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
442 put_le32(pb, stream->p_per_gop);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
443 put_le32(pb, stream->b_per_gop);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
444 if (stream->codec->codec_id == CODEC_ID_MPEG2VIDEO)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
445 put_le32(pb, 2);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
446 else if (stream->codec->codec_id == CODEC_ID_MPEG1VIDEO)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
447 put_le32(pb, 1);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
448 else
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
449 put_le32(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
450 put_le32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
451 return 32;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
452 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
453
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
454 static int gxf_write_umf_media_timecode(ByteIOContext *pb, GXFStreamContext *track)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
455 {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
456 /* FIXME implement */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
457 put_be32(pb, 0); /* drop frame flag */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
458 put_be32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
459 put_be32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
460 put_be32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
461 put_be32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
462 put_be32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
463 put_be32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
464 put_be32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
465 return 32;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
466 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
467
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
468 static int gxf_write_umf_media_dv(ByteIOContext *pb, GXFStreamContext *track)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
469 {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
470 int i;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
471
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
472 for (i = 0; i < 8; i++) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
473 put_be32(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
474 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
475 return 32;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
476 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
477
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
478 static int gxf_write_umf_media_audio(ByteIOContext *pb, GXFStreamContext *track)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
479 {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
480 put_le64(pb, av_dbl2int(1)); /* sound level to begin to */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
481 put_le64(pb, av_dbl2int(1)); /* sound level to begin to */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
482 put_le32(pb, 0); /* number of fields over which to ramp up sound level */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
483 put_le32(pb, 0); /* number of fields over which to ramp down sound level */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
484 put_le32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
485 put_le32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
486 return 32;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
487 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
488
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
489 #if 0
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
490 static int gxf_write_umf_media_mjpeg(ByteIOContext *pb, GXFStreamContext *track)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
491 {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
492 put_be64(pb, 0); /* FIXME FLOAT max chroma quant level */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
493 put_be64(pb, 0); /* FIXME FLOAT max luma quant level */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
494 put_be64(pb, 0); /* FIXME FLOAT min chroma quant level */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
495 put_be64(pb, 0); /* FIXME FLOAT min luma quant level */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
496 return 32;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
497 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
498 #endif
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
499
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
500 static int gxf_write_umf_media_description(ByteIOContext *pb, GXFContext *ctx)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
501 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
502 int64_t pos;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
503 int i;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
504
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
505 pos = url_ftell(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
506 ctx->umf_media_offset = pos - ctx->umf_start_offset;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
507 for (i = 0; i < ctx->fc->nb_streams; ++i) {
4329
bd49910ad4a0 use st->priv_data to store per stream context
bcoudurier
parents: 4304
diff changeset
508 GXFStreamContext *sc = ctx->fc->streams[i]->priv_data;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
509 char buffer[88];
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
510 int64_t startpos, curpos;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
511 int path_size = strlen(ES_NAME_PATTERN);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
512
1260
ac77a4dc27dd init buffer
bcoudurier
parents: 1253
diff changeset
513 memset(buffer, 0, 88);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
514 startpos = url_ftell(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
515 put_le16(pb, 0); /* length */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
516 put_le16(pb, sc->media_info);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
517 put_le16(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
518 put_le16(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
519 put_le32(pb, ctx->nb_frames);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
520 put_le32(pb, 0); /* attributes rw, ro */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
521 put_le32(pb, 0); /* mark in */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
522 put_le32(pb, ctx->nb_frames); /* mark out */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
523 strncpy(buffer, ES_NAME_PATTERN, path_size);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
524 put_buffer(pb, (uint8_t *)buffer, path_size);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
525 put_be16(pb, sc->media_info);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
526 put_buffer(pb, (uint8_t *)buffer + path_size + 2, 88 - path_size - 2);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
527 put_le32(pb, sc->track_type);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
528 put_le32(pb, sc->sample_rate);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
529 put_le32(pb, sc->sample_size);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
530 put_le32(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
531 switch (sc->codec->codec_id) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
532 case CODEC_ID_MPEG2VIDEO:
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
533 gxf_write_umf_media_mpeg(pb, sc);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
534 break;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
535 case CODEC_ID_PCM_S16LE:
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
536 gxf_write_umf_media_audio(pb, sc);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
537 break;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
538 case CODEC_ID_DVVIDEO:
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
539 gxf_write_umf_media_dv(pb, sc);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
540 break;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
541 default:
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
542 gxf_write_umf_media_timecode(pb, sc); /* 8 0bytes */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
543 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
544 curpos = url_ftell(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
545 url_fseek(pb, startpos, SEEK_SET);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
546 put_le16(pb, curpos - startpos);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
547 url_fseek(pb, curpos, SEEK_SET);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
548 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
549 return url_ftell(pb) - pos;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
550 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
551
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
552 static int gxf_write_umf_user_data(ByteIOContext *pb, GXFContext *ctx)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
553 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
554 int64_t pos = url_ftell(pb);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
555 ctx->umf_user_data_offset = pos - ctx->umf_start_offset;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
556 put_le32(pb, 20);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
557 put_le32(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
558 put_le16(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
559 put_le16(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
560 put_le32(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
561 put_byte(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
562 put_byte(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
563 put_byte(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
564 put_byte(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
565 return 20;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
566 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
567
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
568 static int gxf_write_umf_packet(ByteIOContext *pb, GXFContext *ctx)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
569 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
570 int64_t pos = url_ftell(pb);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
571
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
572 gxf_write_packet_header(pb, PKT_UMF);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
573
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
574 /* preamble */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
575 put_byte(pb, 3); /* first and last (only) packet */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
576 put_be32(pb, ctx->umf_length); /* data length */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
577
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
578 ctx->umf_start_offset = url_ftell(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
579 gxf_write_umf_payload(pb, ctx);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
580 gxf_write_umf_material_description(pb, ctx);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
581 ctx->umf_track_size = gxf_write_umf_track_description(pb, ctx);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
582 ctx->umf_media_size = gxf_write_umf_media_description(pb, ctx);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
583 ctx->umf_user_data_size = gxf_write_umf_user_data(pb, ctx);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
584 ctx->umf_length = url_ftell(pb) - ctx->umf_start_offset;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
585 return updatePacketSize(pb, pos);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
586 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
587
1794
11c57b75bccd fix dts adjusting
bcoudurier
parents: 1698
diff changeset
588 #define GXF_NODELAY -5000
11c57b75bccd fix dts adjusting
bcoudurier
parents: 1698
diff changeset
589
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
590 static int gxf_write_header(AVFormatContext *s)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
591 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2337
diff changeset
592 ByteIOContext *pb = s->pb;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
593 GXFContext *gxf = s->priv_data;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
594 int i;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
595
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
596 gxf->fc = s;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
597 gxf->flags |= 0x00080000; /* material is simple clip */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
598 for (i = 0; i < s->nb_streams; ++i) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
599 AVStream *st = s->streams[i];
4329
bd49910ad4a0 use st->priv_data to store per stream context
bcoudurier
parents: 4304
diff changeset
600 GXFStreamContext *sc = av_mallocz(sizeof(*sc));
bd49910ad4a0 use st->priv_data to store per stream context
bcoudurier
parents: 4304
diff changeset
601 if (!sc)
bd49910ad4a0 use st->priv_data to store per stream context
bcoudurier
parents: 4304
diff changeset
602 return AVERROR(ENOMEM);
bd49910ad4a0 use st->priv_data to store per stream context
bcoudurier
parents: 4304
diff changeset
603 st->priv_data = sc;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
604
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
605 sc->codec = st->codec;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
606 sc->index = i;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
607 sc->media_type = codec_get_tag(gxf_media_types, sc->codec->codec_id);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
608 if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
609 if (st->codec->codec_id != CODEC_ID_PCM_S16LE) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
610 av_log(s, AV_LOG_ERROR, "only 16 BIT PCM LE allowed for now\n");
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
611 return -1;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
612 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
613 if (st->codec->sample_rate != 48000) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
614 av_log(s, AV_LOG_ERROR, "only 48000hz sampling rate is allowed\n");
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
615 return -1;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
616 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
617 if (st->codec->channels != 1) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
618 av_log(s, AV_LOG_ERROR, "only mono tracks are allowed\n");
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
619 return -1;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
620 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
621 sc->track_type = 2;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
622 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
623 av_set_pts_info(st, 64, 1, sc->sample_rate);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
624 sc->sample_size = 16;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
625 sc->frame_rate_index = -2;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
626 sc->lines_index = -2;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
627 sc->fields = -2;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
628 gxf->audio_tracks++;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
629 gxf->flags |= 0x04000000; /* audio is 16 bit pcm */
1322
95f56c7b24eb * Moving FifoBuffer out of libavformat/avformat.h and
romansh
parents: 1262
diff changeset
630 av_fifo_init(&sc->audio_buffer, 3*GXF_AUDIO_PACKET_SIZE);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
631 } else if (sc->codec->codec_type == CODEC_TYPE_VIDEO) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
632 /* FIXME check from time_base ? */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
633 if (sc->codec->height == 480 || sc->codec->height == 512) { /* NTSC or NTSC+VBI */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
634 sc->frame_rate_index = 5;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
635 sc->sample_rate = 60;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
636 gxf->flags |= 0x00000080;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
637 } else { /* assume PAL */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
638 sc->frame_rate_index = 6;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
639 sc->media_type++;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
640 sc->sample_rate = 50;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
641 gxf->flags |= 0x00000040;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
642 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
643 gxf->sample_rate = sc->sample_rate;
1794
11c57b75bccd fix dts adjusting
bcoudurier
parents: 1698
diff changeset
644 av_set_pts_info(st, 64, 1, st->codec->time_base.den);
11c57b75bccd fix dts adjusting
bcoudurier
parents: 1698
diff changeset
645 sc->dts_delay = GXF_NODELAY;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
646 if (gxf_find_lines_index(sc) < 0)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
647 sc->lines_index = -1;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
648 sc->sample_size = st->codec->bit_rate;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
649 sc->fields = 2; /* interlaced */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
650 switch (sc->codec->codec_id) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
651 case CODEC_ID_MPEG2VIDEO:
1262
8da1b141e83a set correct first gop closed value
bcoudurier
parents: 1261
diff changeset
652 sc->first_gop_closed = -1;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
653 sc->track_type = 4;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
654 gxf->mpeg_tracks++;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
655 gxf->flags |= 0x00008000;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
656 break;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
657 case CODEC_ID_DVVIDEO:
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
658 if (sc->codec->pix_fmt == PIX_FMT_YUV422P) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
659 sc->media_type += 2;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
660 sc->track_type = 6;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
661 gxf->flags |= 0x00002000;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
662 } else {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
663 sc->track_type = 5;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
664 gxf->flags |= 0x00001000;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
665 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
666 break;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
667 default:
1401
e4a89160a011 use AVFormatContext to log
bcoudurier
parents: 1398
diff changeset
668 av_log(s, AV_LOG_ERROR, "video codec not supported\n");
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
669 return -1;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
670 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
671 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
672 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
673 gxf_write_map_packet(pb, gxf);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
674 //gxf_write_flt_packet(pb, gxf);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
675 gxf_write_umf_packet(pb, gxf);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
676 put_flush_packet(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
677 return 0;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
678 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
679
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
680 static int gxf_write_eos_packet(ByteIOContext *pb, GXFContext *ctx)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
681 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
682 int64_t pos = url_ftell(pb);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
683
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
684 gxf_write_packet_header(pb, PKT_EOS);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
685 return updatePacketSize(pb, pos);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
686 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
687
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
688 static int gxf_write_trailer(AVFormatContext *s)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
689 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2337
diff changeset
690 ByteIOContext *pb = s->pb;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
691 GXFContext *gxf = s->priv_data;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
692 int64_t end;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
693 int i;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
694
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
695 for (i = 0; i < s->nb_streams; ++i) {
4329
bd49910ad4a0 use st->priv_data to store per stream context
bcoudurier
parents: 4304
diff changeset
696 AVStream *st = s->streams[i];
bd49910ad4a0 use st->priv_data to store per stream context
bcoudurier
parents: 4304
diff changeset
697 if (st->codec->codec_type == CODEC_TYPE_AUDIO)
bd49910ad4a0 use st->priv_data to store per stream context
bcoudurier
parents: 4304
diff changeset
698 av_fifo_free(&((GXFStreamContext*)st->priv_data)->audio_buffer);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
699 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
700
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
701 gxf_write_eos_packet(pb, gxf);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
702 end = url_ftell(pb);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
703 url_fseek(pb, 0, SEEK_SET);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
704 /* overwrite map and umf packets with new values */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
705 gxf_write_map_packet(pb, gxf);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
706 //gxf_write_flt_packet(pb, gxf);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
707 gxf_write_umf_packet(pb, gxf);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
708 url_fseek(pb, end, SEEK_SET);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
709 return 0;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
710 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
711
1247
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
712 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
713 {
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
714 uint32_t c=-1;
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
715 int i;
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
716 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
717 c = (c<<8) + buf[i];
1262
8da1b141e83a set correct first gop closed value
bcoudurier
parents: 1261
diff changeset
718 if(c == 0x1B8 && sc->first_gop_closed == -1) /* GOP start code */
1261
e03e8ce942e8 rename closed_gop to first_gop_closed
bcoudurier
parents: 1260
diff changeset
719 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
720 }
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
721 return (buf[i+1]>>3)&7;
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
722 }
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
723
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
724 static int gxf_write_media_preamble(ByteIOContext *pb, GXFContext *ctx, AVPacket *pkt, int size)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
725 {
4329
bd49910ad4a0 use st->priv_data to store per stream context
bcoudurier
parents: 4304
diff changeset
726 GXFStreamContext *sc = ctx->fc->streams[pkt->stream_index]->priv_data;
2251
b7950418654d round timestamps up, k2 broadcast server seems to need it
bcoudurier
parents: 1794
diff changeset
727 int64_t dts = av_rescale_rnd(pkt->dts, ctx->sample_rate, sc->codec->time_base.den, AV_ROUND_UP);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
728
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
729 put_byte(pb, sc->media_type);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
730 put_byte(pb, sc->index);
1253
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
731 put_be32(pb, dts);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
732 if (sc->codec->codec_type == CODEC_TYPE_AUDIO) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
733 put_be16(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
734 put_be16(pb, size / 2);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
735 } else if (sc->codec->codec_id == CODEC_ID_MPEG2VIDEO) {
1247
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
736 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
737 if (frame_type == FF_I_TYPE) {
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
738 put_byte(pb, 0x0d);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
739 sc->iframes++;
1247
2f118b3e65c6 parse mpeg frame to get pict type and closed gop flag
bcoudurier
parents: 1213
diff changeset
740 } else if (frame_type == FF_B_TYPE) {
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
741 put_byte(pb, 0x0f);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
742 sc->bframes++;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
743 } else {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
744 put_byte(pb, 0x0e);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
745 sc->pframes++;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
746 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
747 put_be24(pb, size);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
748 } else if (sc->codec->codec_id == CODEC_ID_DVVIDEO) {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
749 put_byte(pb, size / 4096);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
750 put_be24(pb, 0);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
751 } else
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
752 put_be32(pb, size);
1253
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
753 put_be32(pb, dts);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
754 put_byte(pb, 1); /* flags */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
755 put_byte(pb, 0); /* reserved */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
756 return 16;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
757 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
758
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
759 static int gxf_write_media_packet(ByteIOContext *pb, GXFContext *ctx, AVPacket *pkt)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
760 {
4329
bd49910ad4a0 use st->priv_data to store per stream context
bcoudurier
parents: 4304
diff changeset
761 GXFStreamContext *sc = ctx->fc->streams[pkt->stream_index]->priv_data;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3424
diff changeset
762 int64_t pos = url_ftell(pb);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
763 int padding = 0;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
764
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
765 gxf_write_packet_header(pb, PKT_MEDIA);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
766 if (sc->codec->codec_id == CODEC_ID_MPEG2VIDEO && pkt->size % 4) /* MPEG-2 frames must be padded */
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
767 padding = 4 - pkt->size % 4;
1212
b4f48eb1f411 avoid reading beyond packet size
bcoudurier
parents: 1183
diff changeset
768 else if (sc->codec->codec_type == CODEC_TYPE_AUDIO)
b4f48eb1f411 avoid reading beyond packet size
bcoudurier
parents: 1183
diff changeset
769 padding = GXF_AUDIO_PACKET_SIZE - pkt->size;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
770 gxf_write_media_preamble(pb, ctx, pkt, pkt->size + padding);
1212
b4f48eb1f411 avoid reading beyond packet size
bcoudurier
parents: 1183
diff changeset
771 put_buffer(pb, pkt->data, pkt->size);
b4f48eb1f411 avoid reading beyond packet size
bcoudurier
parents: 1183
diff changeset
772 gxf_write_padding(pb, padding);
4262
f146ce39977a Do not use avctx->frame_number which might not be set,
bcoudurier
parents: 4261
diff changeset
773
f146ce39977a Do not use avctx->frame_number which might not be set,
bcoudurier
parents: 4261
diff changeset
774 if (sc->codec->codec_type == CODEC_TYPE_VIDEO)
f146ce39977a Do not use avctx->frame_number which might not be set,
bcoudurier
parents: 4261
diff changeset
775 ctx->nb_frames += 2; // count fields
f146ce39977a Do not use avctx->frame_number which might not be set,
bcoudurier
parents: 4261
diff changeset
776
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
777 return updatePacketSize(pb, pos);
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
778 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
779
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
780 static int gxf_write_packet(AVFormatContext *s, AVPacket *pkt)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
781 {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
782 GXFContext *gxf = s->priv_data;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
783
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2337
diff changeset
784 gxf_write_media_packet(s->pb, gxf, pkt);
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2337
diff changeset
785 put_flush_packet(s->pb);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
786 return 0;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
787 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
788
1253
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
789 static int gxf_new_audio_packet(GXFContext *gxf, GXFStreamContext *sc, AVPacket *pkt, int flush)
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
790 {
1322
95f56c7b24eb * Moving FifoBuffer out of libavformat/avformat.h and
romansh
parents: 1262
diff changeset
791 int size = flush ? av_fifo_size(&sc->audio_buffer) : GXF_AUDIO_PACKET_SIZE;
1253
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
792
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
793 if (!size)
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
794 return 0;
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
795 av_new_packet(pkt, size);
1322
95f56c7b24eb * Moving FifoBuffer out of libavformat/avformat.h and
romansh
parents: 1262
diff changeset
796 av_fifo_read(&sc->audio_buffer, pkt->data, size);
1253
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
797 pkt->stream_index = sc->index;
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
798 pkt->dts = sc->current_dts;
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
799 sc->current_dts += size / 2; /* we only support 16 bit pcm mono for now */
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
800 return size;
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
801 }
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
802
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
803 static int gxf_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
804 {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
805 GXFContext *gxf = s->priv_data;
1253
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
806 AVPacket new_pkt;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
807 int i;
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
808
1253
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
809 for (i = 0; i < s->nb_streams; i++) {
1542
98ef8d631737 readjust dts if negative
bcoudurier
parents: 1401
diff changeset
810 AVStream *st = s->streams[i];
4329
bd49910ad4a0 use st->priv_data to store per stream context
bcoudurier
parents: 4304
diff changeset
811 GXFStreamContext *sc = st->priv_data;
1542
98ef8d631737 readjust dts if negative
bcoudurier
parents: 1401
diff changeset
812 if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
1253
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
813 if (pkt && pkt->stream_index == i) {
3368
4a233106ccd0 use av_fifo_generic_write, old func is deprecated
bcoudurier
parents: 3286
diff changeset
814 av_fifo_generic_write(&sc->audio_buffer, pkt->data, pkt->size, NULL);
1253
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
815 pkt = NULL;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
816 }
1322
95f56c7b24eb * Moving FifoBuffer out of libavformat/avformat.h and
romansh
parents: 1262
diff changeset
817 if (flush || av_fifo_size(&sc->audio_buffer) >= GXF_AUDIO_PACKET_SIZE) {
1398
303e9fb547c7 avoid overwriting pkt
bcoudurier
parents: 1361
diff changeset
818 if (!pkt && gxf_new_audio_packet(gxf, sc, &new_pkt, flush) > 0) {
1253
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
819 pkt = &new_pkt;
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
820 break; /* add pkt right now into list */
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
821 }
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
822 }
1794
11c57b75bccd fix dts adjusting
bcoudurier
parents: 1698
diff changeset
823 } else if (pkt && pkt->stream_index == i) {
11c57b75bccd fix dts adjusting
bcoudurier
parents: 1698
diff changeset
824 if (sc->dts_delay == GXF_NODELAY) /* adjust dts if needed */
11c57b75bccd fix dts adjusting
bcoudurier
parents: 1698
diff changeset
825 sc->dts_delay = pkt->dts;
1542
98ef8d631737 readjust dts if negative
bcoudurier
parents: 1401
diff changeset
826 pkt->dts -= sc->dts_delay;
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
827 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
828 }
1253
f3d5e1c49875 use packet dts as correct media field number and use av_interleave_pkt_per_dts
bcoudurier
parents: 1247
diff changeset
829 return av_interleave_packet_per_dts(s, out, pkt, flush);
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
830 }
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
831
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
832 AVOutputFormat gxf_muxer = {
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
833 "gxf",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3368
diff changeset
834 NULL_IF_CONFIG_SMALL("GXF format"),
1183
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
835 NULL,
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
836 "gxf",
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
837 sizeof(GXFContext),
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
838 CODEC_ID_PCM_S16LE,
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
839 CODEC_ID_MPEG2VIDEO,
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
840 gxf_write_header,
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
841 gxf_write_packet,
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
842 gxf_write_trailer,
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
843 0,
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
844 NULL,
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
845 gxf_interleave_packet,
5b04d98e11bb GXF muxer
bcoudurier
parents:
diff changeset
846 };