annotate swfenc.c @ 5228:a59767d33928 libavformat

Correctly print number of remaining bytes in oggparsevorbis instead of always with inverted sign.
author reimar
date Wed, 23 Sep 2009 09:18:23 +0000
parents 33a244b7ca65
children 536e5527c1e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
3356
7e144933facd cosmetics, remove useless dot
bcoudurier
parents: 3304
diff changeset
2 * Flash Compatible Streaming Format muxer
4251
77e0c7511d41 cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 4206
diff changeset
3 * Copyright (c) 2000 Fabrice Bellard
77e0c7511d41 cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 4206
diff changeset
4 * Copyright (c) 2003 Tinic Uro
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1305
diff changeset
6 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1305
diff changeset
7 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1305
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1305
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1305
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1305
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 887
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 */
3286
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 2959
diff changeset
22
4864
7aa7c5853bb6 Split bitstream.h, put the bitstream writer stuff in the new file
stefano
parents: 4689
diff changeset
23 #include "libavcodec/put_bits.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 #include "avformat.h"
3302
171f5664d129 split swf de/muxer
bcoudurier
parents: 3286
diff changeset
25 #include "swf.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 static void put_swf_tag(AVFormatContext *s, int tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 SWFContext *swf = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
30 ByteIOContext *pb = s->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 swf->tag_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 swf->tag = tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 /* reserve some room for the tag */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 if (tag & TAG_LONG) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 put_le32(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 static void put_swf_end_tag(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 SWFContext *swf = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
46 ByteIOContext *pb = s->pb;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3591
diff changeset
47 int64_t pos;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 int tag_len, tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 tag_len = pos - swf->tag_pos - 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 tag = swf->tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 url_fseek(pb, swf->tag_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 if (tag & TAG_LONG) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 tag &= ~TAG_LONG;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 put_le16(pb, (tag << 6) | 0x3f);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 put_le32(pb, tag_len - 4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 assert(tag_len < 0x3f);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 put_le16(pb, (tag << 6) | tag_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 url_fseek(pb, pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 static inline void max_nbits(int *nbits_ptr, int val)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 int n;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 if (val == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 return;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 val = abs(val);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 n = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 while (val != 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 n++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 val >>= 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 if (n > *nbits_ptr)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 *nbits_ptr = n;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
81 static void put_swf_rect(ByteIOContext *pb,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 int xmin, int xmax, int ymin, int ymax)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 PutBitContext p;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 5
diff changeset
85 uint8_t buf[256];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 int nbits, mask;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87
276
3dd3646e0164 init_put_bits changed
alex
parents: 241
diff changeset
88 init_put_bits(&p, buf, sizeof(buf));
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
89
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 nbits = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 max_nbits(&nbits, xmin);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 max_nbits(&nbits, xmax);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 max_nbits(&nbits, ymin);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 max_nbits(&nbits, ymax);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 mask = (1 << nbits) - 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 /* rectangle info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 put_bits(&p, 5, nbits);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 put_bits(&p, nbits, xmin & mask);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 put_bits(&p, nbits, xmax & mask);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 put_bits(&p, nbits, ymin & mask);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 put_bits(&p, nbits, ymax & mask);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
103
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 flush_put_bits(&p);
4873
1800b33b2c15 Rename pbBufPtr() to put_bits_ptr().
stefano
parents: 4864
diff changeset
105 put_buffer(pb, buf, put_bits_ptr(&p) - p.buf);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 static void put_swf_line_edge(PutBitContext *pb, int dx, int dy)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 int nbits, mask;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 put_bits(pb, 1, 1); /* edge */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 put_bits(pb, 1, 1); /* line select */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 nbits = 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 max_nbits(&nbits, dx);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 max_nbits(&nbits, dy);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 mask = (1 << nbits) - 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 put_bits(pb, 4, nbits - 2); /* 16 bits precision */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 if (dx == 0) {
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
121 put_bits(pb, 1, 0);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
122 put_bits(pb, 1, 1);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
123 put_bits(pb, nbits, dy & mask);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 } else if (dy == 0) {
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
125 put_bits(pb, 1, 0);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
126 put_bits(pb, 1, 0);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
127 put_bits(pb, nbits, dx & mask);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 } else {
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
129 put_bits(pb, 1, 1);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
130 put_bits(pb, nbits, dx & mask);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
131 put_bits(pb, nbits, dy & mask);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 #define FRAC_BITS 16
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 static void put_swf_matrix(ByteIOContext *pb,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138 int a, int b, int c, int d, int tx, int ty)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 PutBitContext p;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 5
diff changeset
141 uint8_t buf[256];
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
142 int nbits;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143
276
3dd3646e0164 init_put_bits changed
alex
parents: 241
diff changeset
144 init_put_bits(&p, buf, sizeof(buf));
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
145
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 put_bits(&p, 1, 1); /* a, d present */
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
147 nbits = 1;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
148 max_nbits(&nbits, a);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
149 max_nbits(&nbits, d);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
150 put_bits(&p, 5, nbits); /* nb bits */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
151 put_bits(&p, nbits, a);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
152 put_bits(&p, nbits, d);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
153
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 put_bits(&p, 1, 1); /* b, c present */
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
155 nbits = 1;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
156 max_nbits(&nbits, c);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
157 max_nbits(&nbits, b);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
158 put_bits(&p, 5, nbits); /* nb bits */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
159 put_bits(&p, nbits, c);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
160 put_bits(&p, nbits, b);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
162 nbits = 1;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
163 max_nbits(&nbits, tx);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
164 max_nbits(&nbits, ty);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
165 put_bits(&p, 5, nbits); /* nb bits */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
166 put_bits(&p, nbits, tx);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
167 put_bits(&p, nbits, ty);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 flush_put_bits(&p);
4873
1800b33b2c15 Rename pbBufPtr() to put_bits_ptr().
stefano
parents: 4864
diff changeset
170 put_buffer(pb, buf, put_bits_ptr(&p) - p.buf);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173 static int swf_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 {
1623
bdb50e314f29 priv_data is allocated/freed internally
bcoudurier
parents: 1620
diff changeset
175 SWFContext *swf = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
176 ByteIOContext *pb = s->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 PutBitContext p;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 5
diff changeset
178 uint8_t buf1[256];
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 65
diff changeset
179 int i, width, height, rate, rate_base;
3372
d0bf0a1a99c7 simplify and use version instead
bcoudurier
parents: 3371
diff changeset
180 int version;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
182 swf->sound_samples = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
183 swf->swf_frame_number = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
184 swf->video_frame_number = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
185
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 for(i=0;i<s->nb_streams;i++) {
3379
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
187 AVCodecContext *enc = s->streams[i]->codec;
1854
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
188 if (enc->codec_type == CODEC_TYPE_AUDIO) {
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
189 if (enc->codec_id == CODEC_ID_MP3) {
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
190 if (!enc->frame_size) {
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
191 av_log(s, AV_LOG_ERROR, "audio frame size not set\n");
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
192 return -1;
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
193 }
3379
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
194 swf->audio_enc = enc;
4669
d6eb19c43e99 Allocate AVFifoBuffer through the fifo API to reduce future API/ABI issues.
michael
parents: 4398
diff changeset
195 swf->audio_fifo= av_fifo_alloc(AUDIO_FIFO_SIZE);
4947
41d709e71f5f check av_fifo_alloc return
bcoudurier
parents: 4873
diff changeset
196 if (!swf->audio_fifo)
41d709e71f5f check av_fifo_alloc return
bcoudurier
parents: 4873
diff changeset
197 return AVERROR(ENOMEM);
1854
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
198 } else {
1865
eef72288a33e use AVFormatContext with av_log
bcoudurier
parents: 1864
diff changeset
199 av_log(s, AV_LOG_ERROR, "SWF muxer only supports MP3\n");
1854
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
200 return -1;
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
201 }
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
202 } else {
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
203 if (enc->codec_id == CODEC_ID_VP6F ||
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
204 enc->codec_id == CODEC_ID_FLV1 ||
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
205 enc->codec_id == CODEC_ID_MJPEG) {
3379
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
206 swf->video_enc = enc;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
207 } else {
1865
eef72288a33e use AVFormatContext with av_log
bcoudurier
parents: 1864
diff changeset
208 av_log(s, AV_LOG_ERROR, "SWF muxer only supports VP6, FLV1 and MJPEG\n");
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
209 return -1;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
210 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
211 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213
3379
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
214 if (!swf->video_enc) {
2289
e3fab578269d cosmetics: misc typo fixes
diego
parents: 2274
diff changeset
215 /* currently, cannot work correctly if audio only */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 width = 320;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 height = 200;
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 65
diff changeset
218 rate = 10;
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 65
diff changeset
219 rate_base= 1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 } else {
3379
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
221 width = swf->video_enc->width;
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
222 height = swf->video_enc->height;
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
223 rate = swf->video_enc->time_base.den;
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
224 rate_base = swf->video_enc->time_base.num;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226
3379
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
227 if (!swf->audio_enc)
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
228 swf->samples_per_frame = (44100. * rate_base) / rate;
3379
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
229 else
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
230 swf->samples_per_frame = (swf->audio_enc->sample_rate * rate_base) / rate;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
231
3372
d0bf0a1a99c7 simplify and use version instead
bcoudurier
parents: 3371
diff changeset
232 put_tag(pb, "FWS");
2955
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
233
3372
d0bf0a1a99c7 simplify and use version instead
bcoudurier
parents: 3371
diff changeset
234 if (!strcmp("avm2", s->oformat->name))
d0bf0a1a99c7 simplify and use version instead
bcoudurier
parents: 3371
diff changeset
235 version = 9;
3379
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
236 else if (swf->video_enc && swf->video_enc->codec_id == CODEC_ID_VP6F)
3372
d0bf0a1a99c7 simplify and use version instead
bcoudurier
parents: 3371
diff changeset
237 version = 8; /* version 8 and above support VP6 codec */
3379
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
238 else if (swf->video_enc && swf->video_enc->codec_id == CODEC_ID_FLV1)
3372
d0bf0a1a99c7 simplify and use version instead
bcoudurier
parents: 3371
diff changeset
239 version = 6; /* version 6 and above support FLV1 codec */
3369
026b8ba58408 cosmetics, remove useless cases and braces
bcoudurier
parents: 3356
diff changeset
240 else
3372
d0bf0a1a99c7 simplify and use version instead
bcoudurier
parents: 3371
diff changeset
241 version = 4; /* version 4 for mpeg audio support */
d0bf0a1a99c7 simplify and use version instead
bcoudurier
parents: 3371
diff changeset
242 put_byte(pb, version);
d0bf0a1a99c7 simplify and use version instead
bcoudurier
parents: 3371
diff changeset
243
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
244 put_le32(pb, DUMMY_FILE_SIZE); /* dummy size
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
245 (will be patched if not streamed) */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
247 put_swf_rect(pb, 0, width * 20, 0, height * 20);
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 65
diff changeset
248 put_le16(pb, (rate * 256) / rate_base); /* frame rate */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 swf->duration_pos = url_ftell(pb);
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 65
diff changeset
250 put_le16(pb, (uint16_t)(DUMMY_DURATION * (int64_t)rate / rate_base)); /* frame count */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
251
2955
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
252 /* avm2/swf v9 (also v8?) files require a file attribute tag */
3372
d0bf0a1a99c7 simplify and use version instead
bcoudurier
parents: 3371
diff changeset
253 if (version == 9) {
2955
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
254 put_swf_tag(s, TAG_FILEATTRIBUTES);
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
255 put_le32(pb, 1<<3); /* set ActionScript v3/AVM2 flag */
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
256 put_swf_end_tag(s);
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
257 }
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
258
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 /* define a shape with the jpeg inside */
3379
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
260 if (swf->video_enc && swf->video_enc->codec_id == CODEC_ID_MJPEG) {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
261 put_swf_tag(s, TAG_DEFINESHAPE);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
263 put_le16(pb, SHAPE_ID); /* ID of shape */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
264 /* bounding rectangle */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
265 put_swf_rect(pb, 0, width, 0, height);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
266 /* style info */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
267 put_byte(pb, 1); /* one fill style */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
268 put_byte(pb, 0x41); /* clipped bitmap fill */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
269 put_le16(pb, BITMAP_ID); /* bitmap ID */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
270 /* position of the bitmap */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
271 put_swf_matrix(pb, (int)(1.0 * (1 << FRAC_BITS)), 0,
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
272 0, (int)(1.0 * (1 << FRAC_BITS)), 0, 0);
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
273 put_byte(pb, 0); /* no line style */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
274
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
275 /* shape drawing */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
276 init_put_bits(&p, buf1, sizeof(buf1));
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
277 put_bits(&p, 4, 1); /* one fill bit */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
278 put_bits(&p, 4, 0); /* zero line bit */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
279
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
280 put_bits(&p, 1, 0); /* not an edge */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
281 put_bits(&p, 5, FLAG_MOVETO | FLAG_SETFILL0);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
282 put_bits(&p, 5, 1); /* nbits */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
283 put_bits(&p, 1, 0); /* X */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
284 put_bits(&p, 1, 0); /* Y */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
285 put_bits(&p, 1, 1); /* set fill style 1 */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
286
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
287 /* draw the rectangle ! */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
288 put_swf_line_edge(&p, width, 0);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
289 put_swf_line_edge(&p, 0, height);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
290 put_swf_line_edge(&p, -width, 0);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
291 put_swf_line_edge(&p, 0, -height);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
292
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
293 /* end of shape */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
294 put_bits(&p, 1, 0); /* not an edge */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
295 put_bits(&p, 5, 0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
296
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
297 flush_put_bits(&p);
4873
1800b33b2c15 Rename pbBufPtr() to put_bits_ptr().
stefano
parents: 4864
diff changeset
298 put_buffer(pb, buf1, put_bits_ptr(&p) - p.buf);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
299
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
300 put_swf_end_tag(s);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
301 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
302
3379
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
303 if (swf->audio_enc && swf->audio_enc->codec_id == CODEC_ID_MP3) {
3373
196d3d425f5a merge init and declaration
bcoudurier
parents: 3372
diff changeset
304 int v = 0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
305
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
306 /* start sound */
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
307 put_swf_tag(s, TAG_STREAMHEAD2);
3379
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
308 switch(swf->audio_enc->sample_rate) {
3374
67b57431ac20 cosmetics
bcoudurier
parents: 3373
diff changeset
309 case 11025: v |= 1 << 2; break;
67b57431ac20 cosmetics
bcoudurier
parents: 3373
diff changeset
310 case 22050: v |= 2 << 2; break;
67b57431ac20 cosmetics
bcoudurier
parents: 3373
diff changeset
311 case 44100: v |= 3 << 2; break;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
312 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
313 /* not supported */
2164
3804e39efbfd misc spelling fixes
diego
parents: 2023
diff changeset
314 av_log(s, AV_LOG_ERROR, "swf does not support that sample rate, choose from (44100, 22050, 11025).\n");
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
315 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
316 }
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
317 v |= 0x02; /* 16 bit playback */
3379
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
318 if (swf->audio_enc->channels == 2)
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
319 v |= 0x01; /* stereo playback */
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
320 put_byte(s->pb, v);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
321 v |= 0x20; /* mp3 compressed */
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
322 put_byte(s->pb, v);
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
323 put_le16(s->pb, swf->samples_per_frame); /* avg samples per frame */
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
324 put_le16(s->pb, 0);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
325
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
326 put_swf_end_tag(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
329 put_flush_packet(s->pb);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
330 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
331 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
333 static int swf_write_video(AVFormatContext *s,
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 187
diff changeset
334 AVCodecContext *enc, const uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
335 {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
336 SWFContext *swf = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
337 ByteIOContext *pb = s->pb;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
338
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
339 /* Flash Player limit */
3369
026b8ba58408 cosmetics, remove useless cases and braces
bcoudurier
parents: 3356
diff changeset
340 if (swf->swf_frame_number == 16000)
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 360
diff changeset
341 av_log(enc, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n");
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342
3379
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
343 if (enc->codec_id == CODEC_ID_VP6F ||
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
344 enc->codec_id == CODEC_ID_FLV1) {
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
345 if (swf->video_frame_number == 0) {
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
346 /* create a new video object */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
347 put_swf_tag(s, TAG_VIDEOSTREAM);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
348 put_le16(pb, VIDEO_ID);
3591
aa6e8ff72d9e update swf video frame number when muxing done, fix #439
bcoudurier
parents: 3424
diff changeset
349 swf->vframes_pos = url_ftell(pb);
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
350 put_le16(pb, 15000); /* hard flash player limit */
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
351 put_le16(pb, enc->width);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
352 put_le16(pb, enc->height);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
353 put_byte(pb, 0);
5058
33a244b7ca65 Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents: 4947
diff changeset
354 put_byte(pb,ff_codec_get_tag(swf_codec_tags,enc->codec_id));
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
355 put_swf_end_tag(s);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
356
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
357 /* place the video object for the first time */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
358 put_swf_tag(s, TAG_PLACEOBJECT2);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
359 put_byte(pb, 0x36);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
360 put_le16(pb, 1);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
361 put_le16(pb, VIDEO_ID);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
362 put_swf_matrix(pb, 1 << FRAC_BITS, 0, 0, 1 << FRAC_BITS, 0, 0);
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
363 put_le16(pb, swf->video_frame_number);
3370
c1736a1cf27b simplify
bcoudurier
parents: 3369
diff changeset
364 put_tag(pb, "video");
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
365 put_byte(pb, 0x00);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
366 put_swf_end_tag(s);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
367 } else {
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
368 /* mark the character for update */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
369 put_swf_tag(s, TAG_PLACEOBJECT2);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
370 put_byte(pb, 0x11);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
371 put_le16(pb, 1);
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
372 put_le16(pb, swf->video_frame_number);
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
373 put_swf_end_tag(s);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
374 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
375
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
376 /* set video frame data */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
377 put_swf_tag(s, TAG_VIDEOFRAME | TAG_LONG);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
378 put_le16(pb, VIDEO_ID);
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
379 put_le16(pb, swf->video_frame_number++);
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
380 put_buffer(pb, buf, size);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
381 put_swf_end_tag(s);
3379
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
382 } else if (enc->codec_id == CODEC_ID_MJPEG) {
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
383 if (swf->swf_frame_number > 0) {
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
384 /* remove the shape */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
385 put_swf_tag(s, TAG_REMOVEOBJECT);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
386 put_le16(pb, SHAPE_ID); /* shape ID */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
387 put_le16(pb, 1); /* depth */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
388 put_swf_end_tag(s);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
389
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
390 /* free the bitmap */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
391 put_swf_tag(s, TAG_FREECHARACTER);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
392 put_le16(pb, BITMAP_ID);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
393 put_swf_end_tag(s);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
394 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
395
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
396 put_swf_tag(s, TAG_JPEG2 | TAG_LONG);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
397
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
398 put_le16(pb, BITMAP_ID); /* ID of the image */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
399
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
400 /* a dummy jpeg header seems to be required */
3371
7a8c6c4eef16 simplify
bcoudurier
parents: 3370
diff changeset
401 put_be32(pb, 0xffd8ffd9);
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
402 /* write the jpeg image */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
403 put_buffer(pb, buf, size);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
404
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
405 put_swf_end_tag(s);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
406
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
407 /* draw the shape */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
408
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
409 put_swf_tag(s, TAG_PLACEOBJECT);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
410 put_le16(pb, SHAPE_ID); /* shape ID */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
411 put_le16(pb, 1); /* depth */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
412 put_swf_matrix(pb, 20 << FRAC_BITS, 0, 0, 20 << FRAC_BITS, 0, 0);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
413 put_swf_end_tag(s);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
414 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
415
3381
10201d222e76 cosmetics
bcoudurier
parents: 3379
diff changeset
416 swf->swf_frame_number++;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
418 /* streaming sound always should be placed just before showframe tags */
4669
d6eb19c43e99 Allocate AVFifoBuffer through the fifo API to reduce future API/ABI issues.
michael
parents: 4398
diff changeset
419 if (swf->audio_enc && av_fifo_size(swf->audio_fifo)) {
d6eb19c43e99 Allocate AVFifoBuffer through the fifo API to reduce future API/ABI issues.
michael
parents: 4398
diff changeset
420 int frame_size = av_fifo_size(swf->audio_fifo);
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
421 put_swf_tag(s, TAG_STREAMBLOCK | TAG_LONG);
1854
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
422 put_le16(pb, swf->sound_samples);
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
423 put_le16(pb, 0); // seek samples
4689
fc0a165de804 Reorder arguments for av_fifo_generic_read to be more logical and
reimar
parents: 4669
diff changeset
424 av_fifo_generic_read(swf->audio_fifo, pb, frame_size, &put_buffer);
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
425 put_swf_end_tag(s);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
426
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
427 /* update FIFO */
1854
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
428 swf->sound_samples = 0;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
429 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
430
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
431 /* output the frame */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
432 put_swf_tag(s, TAG_SHOWFRAME);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
433 put_swf_end_tag(s);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
434
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
435 put_flush_packet(s->pb);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
436
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
440 static int swf_write_audio(AVFormatContext *s,
4398
043d314bb216 Remove const qualifier from function argument to eliminate the warning
diego
parents: 4251
diff changeset
441 AVCodecContext *enc, uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
443 SWFContext *swf = s->priv_data;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
444
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
445 /* Flash Player limit */
3369
026b8ba58408 cosmetics, remove useless cases and braces
bcoudurier
parents: 3356
diff changeset
446 if (swf->swf_frame_number == 16000)
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 360
diff changeset
447 av_log(enc, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n");
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448
4669
d6eb19c43e99 Allocate AVFifoBuffer through the fifo API to reduce future API/ABI issues.
michael
parents: 4398
diff changeset
449 if (av_fifo_size(swf->audio_fifo) + size > AUDIO_FIFO_SIZE) {
1854
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
450 av_log(s, AV_LOG_ERROR, "audio fifo too small to mux audio essence\n");
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
451 return -1;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
452 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
453
4669
d6eb19c43e99 Allocate AVFifoBuffer through the fifo API to reduce future API/ABI issues.
michael
parents: 4398
diff changeset
454 av_fifo_generic_write(swf->audio_fifo, buf, size, NULL);
1854
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
455 swf->sound_samples += enc->frame_size;
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
456
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
457 /* if audio only stream make sure we add swf frames */
3379
b3827117c786 simplify, use pointer to codec context in struct instead of only id
bcoudurier
parents: 3375
diff changeset
458 if (!swf->video_enc)
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
459 swf_write_video(s, enc, 0, 0);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
460
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
461 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
462 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
463
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
464 static int swf_write_packet(AVFormatContext *s, AVPacket *pkt)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
465 {
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 807
diff changeset
466 AVCodecContext *codec = s->streams[pkt->stream_index]->codec;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
467 if (codec->codec_type == CODEC_TYPE_AUDIO)
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
468 return swf_write_audio(s, codec, pkt->data, pkt->size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469 else
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
470 return swf_write_video(s, codec, pkt->data, pkt->size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
471 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
472
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
473 static int swf_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
474 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
475 SWFContext *swf = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
476 ByteIOContext *pb = s->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
477 AVCodecContext *enc, *video_enc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
478 int file_size, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
479
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
480 video_enc = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
481 for(i=0;i<s->nb_streams;i++) {
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 807
diff changeset
482 enc = s->streams[i]->codec;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
483 if (enc->codec_type == CODEC_TYPE_VIDEO)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
484 video_enc = enc;
3375
9877da0d8be3 use AVFifoBuffer
bcoudurier
parents: 3374
diff changeset
485 else
4669
d6eb19c43e99 Allocate AVFifoBuffer through the fifo API to reduce future API/ABI issues.
michael
parents: 4398
diff changeset
486 av_fifo_free(swf->audio_fifo);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
487 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
488
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
489 put_swf_tag(s, TAG_END);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
490 put_swf_end_tag(s);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
491
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
492 put_flush_packet(s->pb);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
493
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
494 /* patch file size and number of frames if not streamed */
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
495 if (!url_is_streamed(s->pb) && video_enc) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
496 file_size = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
497 url_fseek(pb, 4, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
498 put_le32(pb, file_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
499 url_fseek(pb, swf->duration_pos, SEEK_SET);
3382
45da68497603 use internal video frame number
bcoudurier
parents: 3381
diff changeset
500 put_le16(pb, swf->video_frame_number);
3591
aa6e8ff72d9e update swf video frame number when muxing done, fix #439
bcoudurier
parents: 3424
diff changeset
501 url_fseek(pb, swf->vframes_pos, SEEK_SET);
aa6e8ff72d9e update swf video frame number when muxing done, fix #439
bcoudurier
parents: 3424
diff changeset
502 put_le16(pb, swf->video_frame_number);
1643
20c25a594c49 seek back at the end of file after updating header
bcoudurier
parents: 1642
diff changeset
503 url_fseek(pb, file_size, SEEK_SET);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
504 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
505 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
506 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
507
4206
c3102b189cb6 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 3973
diff changeset
508 #if CONFIG_SWF_MUXER
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
509 AVOutputFormat swf_muxer = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
510 "swf",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3382
diff changeset
511 NULL_IF_CONFIG_SMALL("Flash format"),
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
512 "application/x-shockwave-flash",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
513 "swf",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
514 sizeof(SWFContext),
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
515 CODEC_ID_MP3,
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
516 CODEC_ID_FLV1,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
517 swf_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
518 swf_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
519 swf_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
520 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
521 #endif
4206
c3102b189cb6 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 3973
diff changeset
522 #if CONFIG_AVM2_MUXER
2955
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
523 AVOutputFormat avm2_muxer = {
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
524 "avm2",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3382
diff changeset
525 NULL_IF_CONFIG_SMALL("Flash 9 (AVM2) format"),
2955
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
526 "application/x-shockwave-flash",
2959
1b7bf70aab74 unset extension, so code path, and guess format do not choose
bcoudurier
parents: 2955
diff changeset
527 NULL,
2955
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
528 sizeof(SWFContext),
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
529 CODEC_ID_MP3,
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
530 CODEC_ID_FLV1,
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
531 swf_write_header,
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
532 swf_write_packet,
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
533 swf_write_trailer,
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
534 };
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
535 #endif