annotate swf.c @ 3060:e115b923d23f libavformat

Riff ids for wmapro and wmavoice, this adds support for stream copy of these codecs between asf,avi and wav containers.
author banan
date Sat, 23 Feb 2008 23:30:41 +0000
parents 1b7bf70aab74
children 6f61c3b36632
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * Flash Compatible Streaming Format
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2000 Fabrice Bellard.
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
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 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 #include "avformat.h"
628
8909a59c9461 common.h -> common.h/bitstream.h
michael
parents: 516
diff changeset
23 #include "bitstream.h"
1305
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
24 #include "riff.h" /* for CodecTag */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 /* should have a generic way to indicate probable size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 #define DUMMY_FILE_SIZE (100 * 1024 * 1024)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 #define DUMMY_DURATION 600 /* in seconds */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 #define TAG_END 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 #define TAG_SHOWFRAME 1
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 #define TAG_DEFINESHAPE 2
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 #define TAG_FREECHARACTER 3
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 #define TAG_PLACEOBJECT 4
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 #define TAG_REMOVEOBJECT 5
807
alex
parents: 806
diff changeset
36 #define TAG_STREAMHEAD 18
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 #define TAG_STREAMBLOCK 19
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 #define TAG_JPEG2 21
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
39 #define TAG_PLACEOBJECT2 26
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
40 #define TAG_STREAMHEAD2 45
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
41 #define TAG_VIDEOSTREAM 60
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
42 #define TAG_VIDEOFRAME 61
2955
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
43 #define TAG_FILEATTRIBUTES 69
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 #define TAG_LONG 0x100
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 /* flags for shape definition */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 #define FLAG_MOVETO 0x01
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 #define FLAG_SETFILL0 0x02
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 #define FLAG_SETFILL1 0x04
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
52 #define AUDIO_FIFO_SIZE 65536
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
53
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 /* character id used */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 #define BITMAP_ID 0
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
56 #define VIDEO_ID 0
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 #define SHAPE_ID 1
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58
516
59ddf98a5c65 nonsense removial
michael
parents: 482
diff changeset
59 #undef NDEBUG
59ddf98a5c65 nonsense removial
michael
parents: 482
diff changeset
60 #include <assert.h>
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
61
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 typedef struct {
1638
0c6b7ac24cd7 swf can contain only one audio track, simplify
bcoudurier
parents: 1637
diff changeset
63 int audio_stream_index;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 offset_t duration_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 offset_t tag_pos;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
66
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
67 int samples_per_frame;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
68 int sound_samples;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
69 int swf_frame_number;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
70 int video_frame_number;
1889
e81bae269ae1 fix pts handling
bcoudurier
parents: 1882
diff changeset
71 int frame_rate;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 int tag;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
73
1854
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
74 uint8_t audio_fifo[AUDIO_FIFO_SIZE];
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
75 int audio_in_pos;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
76
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
77 int video_type;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
78 int audio_type;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 } SWFContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80
1677
2a85c82b8538 add codec_id <-> codec_tag tables to AVIn/OutputFormat
michael
parents: 1673
diff changeset
81 static const AVCodecTag swf_codec_tags[] = {
1305
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
82 {CODEC_ID_FLV1, 0x02},
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
83 {CODEC_ID_VP6F, 0x04},
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
84 {0, 0},
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
85 };
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
86
1833
09a67819763e support for adpcm swf, pcm
bcoudurier
parents: 1827
diff changeset
87 static const AVCodecTag swf_audio_codec_tags[] = {
09a67819763e support for adpcm swf, pcm
bcoudurier
parents: 1827
diff changeset
88 {CODEC_ID_PCM_S16LE, 0x00},
09a67819763e support for adpcm swf, pcm
bcoudurier
parents: 1827
diff changeset
89 {CODEC_ID_ADPCM_SWF, 0x01},
09a67819763e support for adpcm swf, pcm
bcoudurier
parents: 1827
diff changeset
90 {CODEC_ID_MP3, 0x02},
09a67819763e support for adpcm swf, pcm
bcoudurier
parents: 1827
diff changeset
91 {CODEC_ID_PCM_S16LE, 0x03},
09a67819763e support for adpcm swf, pcm
bcoudurier
parents: 1827
diff changeset
92 //{CODEC_ID_NELLYMOSER, 0x06},
09a67819763e support for adpcm swf, pcm
bcoudurier
parents: 1827
diff changeset
93 {0, 0},
09a67819763e support for adpcm swf, pcm
bcoudurier
parents: 1827
diff changeset
94 };
09a67819763e support for adpcm swf, pcm
bcoudurier
parents: 1827
diff changeset
95
858
66cc656ea404 Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents: 820
diff changeset
96 #ifdef CONFIG_MUXERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 static void put_swf_tag(AVFormatContext *s, int tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 SWFContext *swf = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
100 ByteIOContext *pb = s->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 swf->tag_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 swf->tag = tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 /* reserve some room for the tag */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 if (tag & TAG_LONG) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 put_le32(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 static void put_swf_end_tag(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 SWFContext *swf = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
116 ByteIOContext *pb = s->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 offset_t pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 int tag_len, tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 tag_len = pos - swf->tag_pos - 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 tag = swf->tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 url_fseek(pb, swf->tag_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 if (tag & TAG_LONG) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 tag &= ~TAG_LONG;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 put_le16(pb, (tag << 6) | 0x3f);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 put_le32(pb, tag_len - 4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 assert(tag_len < 0x3f);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 put_le16(pb, (tag << 6) | tag_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 url_fseek(pb, pos, SEEK_SET);
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 static inline void max_nbits(int *nbits_ptr, int val)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 int n;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 if (val == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 return;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 val = abs(val);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 n = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 while (val != 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 n++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 val >>= 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 if (n > *nbits_ptr)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 *nbits_ptr = n;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
151 static void put_swf_rect(ByteIOContext *pb,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
152 int xmin, int xmax, int ymin, int ymax)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 PutBitContext p;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 5
diff changeset
155 uint8_t buf[256];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 int nbits, mask;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157
276
3dd3646e0164 init_put_bits changed
alex
parents: 241
diff changeset
158 init_put_bits(&p, buf, sizeof(buf));
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
159
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 nbits = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 max_nbits(&nbits, xmin);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 max_nbits(&nbits, xmax);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 max_nbits(&nbits, ymin);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 max_nbits(&nbits, ymax);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 mask = (1 << nbits) - 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 /* rectangle info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 put_bits(&p, 5, nbits);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 put_bits(&p, nbits, xmin & mask);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 put_bits(&p, nbits, xmax & mask);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 put_bits(&p, nbits, ymin & mask);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 put_bits(&p, nbits, ymax & mask);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
173
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 flush_put_bits(&p);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175 put_buffer(pb, buf, pbBufPtr(&p) - p.buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 static void put_swf_line_edge(PutBitContext *pb, int dx, int dy)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180 int nbits, mask;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 put_bits(pb, 1, 1); /* edge */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 put_bits(pb, 1, 1); /* line select */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184 nbits = 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 max_nbits(&nbits, dx);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 max_nbits(&nbits, dy);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 mask = (1 << nbits) - 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 put_bits(pb, 4, nbits - 2); /* 16 bits precision */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 if (dx == 0) {
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
191 put_bits(pb, 1, 0);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
192 put_bits(pb, 1, 1);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
193 put_bits(pb, nbits, dy & mask);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 } else if (dy == 0) {
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
195 put_bits(pb, 1, 0);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
196 put_bits(pb, 1, 0);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
197 put_bits(pb, nbits, dx & mask);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 } else {
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
199 put_bits(pb, 1, 1);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
200 put_bits(pb, nbits, dx & mask);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
201 put_bits(pb, nbits, dy & mask);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 #define FRAC_BITS 16
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
207 /* put matrix */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 static void put_swf_matrix(ByteIOContext *pb,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 int a, int b, int c, int d, int tx, int ty)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 PutBitContext p;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 5
diff changeset
212 uint8_t buf[256];
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
213 int nbits;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214
276
3dd3646e0164 init_put_bits changed
alex
parents: 241
diff changeset
215 init_put_bits(&p, buf, sizeof(buf));
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
216
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 put_bits(&p, 1, 1); /* a, d present */
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
218 nbits = 1;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
219 max_nbits(&nbits, a);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
220 max_nbits(&nbits, d);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
221 put_bits(&p, 5, nbits); /* nb bits */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
222 put_bits(&p, nbits, a);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
223 put_bits(&p, nbits, d);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
224
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 put_bits(&p, 1, 1); /* b, c present */
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
226 nbits = 1;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
227 max_nbits(&nbits, c);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
228 max_nbits(&nbits, b);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
229 put_bits(&p, 5, nbits); /* nb bits */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
230 put_bits(&p, nbits, c);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
231 put_bits(&p, nbits, b);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
233 nbits = 1;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
234 max_nbits(&nbits, tx);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
235 max_nbits(&nbits, ty);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
236 put_bits(&p, 5, nbits); /* nb bits */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
237 put_bits(&p, nbits, tx);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
238 put_bits(&p, nbits, ty);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 flush_put_bits(&p);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 put_buffer(pb, buf, pbBufPtr(&p) - p.buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
244 /* */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 static int swf_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 {
1623
bdb50e314f29 priv_data is allocated/freed internally
bcoudurier
parents: 1620
diff changeset
247 SWFContext *swf = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
248 ByteIOContext *pb = s->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 AVCodecContext *enc, *audio_enc, *video_enc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 PutBitContext p;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 5
diff changeset
251 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
252 int i, width, height, rate, rate_base;
2955
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
253 int is_avm2;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
255 swf->audio_in_pos = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
256 swf->sound_samples = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
257 swf->swf_frame_number = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
258 swf->video_frame_number = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
259
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 video_enc = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 audio_enc = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 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
263 enc = s->streams[i]->codec;
1854
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
264 if (enc->codec_type == CODEC_TYPE_AUDIO) {
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
265 if (enc->codec_id == CODEC_ID_MP3) {
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
266 if (!enc->frame_size) {
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
267 av_log(s, AV_LOG_ERROR, "audio frame size not set\n");
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
268 return -1;
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
269 }
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
270 audio_enc = enc;
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
271 } else {
1865
eef72288a33e use AVFormatContext with av_log
bcoudurier
parents: 1864
diff changeset
272 av_log(s, AV_LOG_ERROR, "SWF muxer only supports MP3\n");
1854
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
273 return -1;
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
274 }
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
275 } else {
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
276 if (enc->codec_id == CODEC_ID_VP6F ||
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
277 enc->codec_id == CODEC_ID_FLV1 ||
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
278 enc->codec_id == CODEC_ID_MJPEG) {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
279 video_enc = enc;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
280 } else {
1865
eef72288a33e use AVFormatContext with av_log
bcoudurier
parents: 1864
diff changeset
281 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
282 return -1;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
283 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
284 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287 if (!video_enc) {
2289
e3fab578269d cosmetics: misc typo fixes
diego
parents: 2274
diff changeset
288 /* currently, cannot work correctly if audio only */
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
289 swf->video_type = 0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290 width = 320;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291 height = 200;
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 65
diff changeset
292 rate = 10;
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 65
diff changeset
293 rate_base= 1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294 } else {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
295 swf->video_type = video_enc->codec_id;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
296 width = video_enc->width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
297 height = video_enc->height;
743
af4e24d6310c switch to native time bases
michael
parents: 628
diff changeset
298 rate = video_enc->time_base.den;
af4e24d6310c switch to native time bases
michael
parents: 628
diff changeset
299 rate_base = video_enc->time_base.num;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
302 if (!audio_enc) {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
303 swf->audio_type = 0;
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
304 swf->samples_per_frame = (44100. * rate_base) / rate;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
305 } else {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
306 swf->audio_type = audio_enc->codec_id;
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
307 swf->samples_per_frame = (audio_enc->sample_rate * rate_base) / rate;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
308 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
309
2955
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
310 is_avm2 = !strcmp("avm2", s->oformat->name);
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
311
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
312 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
313 if (is_avm2) {
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
314 put_byte(pb, 9);
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
315 } else if (video_enc && video_enc->codec_id == CODEC_ID_VP6F) {
1305
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
316 put_byte(pb, 8); /* version (version 8 and above support VP6 codec) */
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
317 } else if (video_enc && video_enc->codec_id == CODEC_ID_FLV1) {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
318 put_byte(pb, 6); /* version (version 6 and above support FLV1 codec) */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
319 } else {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
320 put_byte(pb, 4); /* version (should use 4 for mpeg audio support) */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
321 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
322 put_le32(pb, DUMMY_FILE_SIZE); /* dummy size
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
323 (will be patched if not streamed) */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
324
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
325 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
326 put_le16(pb, (rate * 256) / rate_base); /* frame rate */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327 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
328 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
329
2955
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
330 /* avm2/swf v9 (also v8?) files require a file attribute tag */
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
331 if (is_avm2) {
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
332 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
333 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
334 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
335 }
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
336
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337 /* define a shape with the jpeg inside */
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
338 if (video_enc && (video_enc->codec_id == CODEC_ID_VP6F ||
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
339 video_enc->codec_id == CODEC_ID_FLV1)) {
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
340 } else if (video_enc && video_enc->codec_id == CODEC_ID_MJPEG) {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
341 put_swf_tag(s, TAG_DEFINESHAPE);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
343 put_le16(pb, SHAPE_ID); /* ID of shape */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
344 /* bounding rectangle */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
345 put_swf_rect(pb, 0, width, 0, height);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
346 /* style info */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
347 put_byte(pb, 1); /* one fill style */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
348 put_byte(pb, 0x41); /* clipped bitmap fill */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
349 put_le16(pb, BITMAP_ID); /* bitmap ID */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
350 /* position of the bitmap */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
351 put_swf_matrix(pb, (int)(1.0 * (1 << FRAC_BITS)), 0,
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
352 0, (int)(1.0 * (1 << FRAC_BITS)), 0, 0);
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
353 put_byte(pb, 0); /* no line style */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
354
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
355 /* shape drawing */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
356 init_put_bits(&p, buf1, sizeof(buf1));
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
357 put_bits(&p, 4, 1); /* one fill bit */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
358 put_bits(&p, 4, 0); /* zero line bit */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
359
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
360 put_bits(&p, 1, 0); /* not an edge */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
361 put_bits(&p, 5, FLAG_MOVETO | FLAG_SETFILL0);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
362 put_bits(&p, 5, 1); /* nbits */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
363 put_bits(&p, 1, 0); /* X */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
364 put_bits(&p, 1, 0); /* Y */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
365 put_bits(&p, 1, 1); /* set fill style 1 */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
366
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
367 /* draw the rectangle ! */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
368 put_swf_line_edge(&p, width, 0);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
369 put_swf_line_edge(&p, 0, height);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
370 put_swf_line_edge(&p, -width, 0);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
371 put_swf_line_edge(&p, 0, -height);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
372
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
373 /* end of shape */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
374 put_bits(&p, 1, 0); /* not an edge */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
375 put_bits(&p, 5, 0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
377 flush_put_bits(&p);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
378 put_buffer(pb, buf1, pbBufPtr(&p) - p.buf);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
379
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
380 put_swf_end_tag(s);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
381 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
382
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
383 if (audio_enc && audio_enc->codec_id == CODEC_ID_MP3) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
384 int v;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
385
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
386 /* start sound */
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
387 put_swf_tag(s, TAG_STREAMHEAD2);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
388
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
389 v = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
390 switch(audio_enc->sample_rate) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
391 case 11025:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
392 v |= 1 << 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
393 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
394 case 22050:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
395 v |= 2 << 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
396 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
397 case 44100:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
398 v |= 3 << 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
400 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
401 /* not supported */
2164
3804e39efbfd misc spelling fixes
diego
parents: 2023
diff changeset
402 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
403 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
404 }
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
405 v |= 0x02; /* 16 bit playback */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
406 if (audio_enc->channels == 2)
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
407 v |= 0x01; /* stereo playback */
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
408 put_byte(s->pb, v);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
409 v |= 0x20; /* mp3 compressed */
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
410 put_byte(s->pb, v);
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
411 put_le16(s->pb, swf->samples_per_frame); /* avg samples per frame */
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
412 put_le16(s->pb, 0);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
413
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414 put_swf_end_tag(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
417 put_flush_packet(s->pb);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
419 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
420
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
421 static int swf_write_video(AVFormatContext *s,
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 187
diff changeset
422 AVCodecContext *enc, const uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
423 {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
424 SWFContext *swf = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
425 ByteIOContext *pb = s->pb;
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 /* Flash Player limit */
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
428 if (swf->swf_frame_number == 16000) {
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 360
diff changeset
429 av_log(enc, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n");
359
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
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
432 if (swf->video_type == CODEC_ID_VP6F ||
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
433 swf->video_type == CODEC_ID_FLV1) {
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
434 if (swf->video_frame_number == 0) {
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
435 /* create a new video object */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
436 put_swf_tag(s, TAG_VIDEOSTREAM);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
437 put_le16(pb, VIDEO_ID);
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
438 put_le16(pb, 15000); /* hard flash player limit */
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
439 put_le16(pb, enc->width);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
440 put_le16(pb, enc->height);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
441 put_byte(pb, 0);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
442 put_byte(pb,codec_get_tag(swf_codec_tags,swf->video_type));
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
443 put_swf_end_tag(s);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
444
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
445 /* place the video object for the first time */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
446 put_swf_tag(s, TAG_PLACEOBJECT2);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
447 put_byte(pb, 0x36);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
448 put_le16(pb, 1);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
449 put_le16(pb, VIDEO_ID);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
450 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
451 put_le16(pb, swf->video_frame_number);
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
452 put_byte(pb, 'v');
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
453 put_byte(pb, 'i');
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
454 put_byte(pb, 'd');
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
455 put_byte(pb, 'e');
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
456 put_byte(pb, 'o');
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
457 put_byte(pb, 0x00);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
458 put_swf_end_tag(s);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
459 } else {
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
460 /* mark the character for update */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
461 put_swf_tag(s, TAG_PLACEOBJECT2);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
462 put_byte(pb, 0x11);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
463 put_le16(pb, 1);
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
464 put_le16(pb, swf->video_frame_number);
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
465 put_swf_end_tag(s);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
466 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
467
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
468 /* set video frame data */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
469 put_swf_tag(s, TAG_VIDEOFRAME | TAG_LONG);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
470 put_le16(pb, VIDEO_ID);
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
471 put_le16(pb, swf->video_frame_number++);
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
472 put_buffer(pb, buf, size);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
473 put_swf_end_tag(s);
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
474 } else if (swf->video_type == CODEC_ID_MJPEG) {
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
475 if (swf->swf_frame_number > 0) {
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
476 /* remove the shape */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
477 put_swf_tag(s, TAG_REMOVEOBJECT);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
478 put_le16(pb, SHAPE_ID); /* shape ID */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
479 put_le16(pb, 1); /* depth */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
480 put_swf_end_tag(s);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
481
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
482 /* free the bitmap */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
483 put_swf_tag(s, TAG_FREECHARACTER);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
484 put_le16(pb, BITMAP_ID);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
485 put_swf_end_tag(s);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
486 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
487
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
488 put_swf_tag(s, TAG_JPEG2 | TAG_LONG);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
489
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
490 put_le16(pb, BITMAP_ID); /* ID of the image */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
491
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
492 /* a dummy jpeg header seems to be required */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
493 put_byte(pb, 0xff);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
494 put_byte(pb, 0xd8);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
495 put_byte(pb, 0xff);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
496 put_byte(pb, 0xd9);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
497 /* write the jpeg image */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
498 put_buffer(pb, buf, size);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
499
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
500 put_swf_end_tag(s);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
501
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
502 /* draw the shape */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
503
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
504 put_swf_tag(s, TAG_PLACEOBJECT);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
505 put_le16(pb, SHAPE_ID); /* shape ID */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
506 put_le16(pb, 1); /* depth */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
507 put_swf_matrix(pb, 20 << FRAC_BITS, 0, 0, 20 << FRAC_BITS, 0, 0);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
508 put_swf_end_tag(s);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
509 } else {
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
510 /* invalid codec */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
511 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
512
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
513 swf->swf_frame_number ++;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
514
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
515 /* streaming sound always should be placed just before showframe tags */
1854
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
516 if (swf->audio_type && swf->audio_in_pos) {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
517 put_swf_tag(s, TAG_STREAMBLOCK | TAG_LONG);
1854
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
518 put_le16(pb, swf->sound_samples);
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
519 put_le16(pb, 0); // seek samples
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
520 put_buffer(pb, swf->audio_fifo, swf->audio_in_pos);
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
521 put_swf_end_tag(s);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
522
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
523 /* update FIFO */
1854
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
524 swf->sound_samples = 0;
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
525 swf->audio_in_pos = 0;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
526 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
527
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
528 /* output the frame */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
529 put_swf_tag(s, TAG_SHOWFRAME);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
530 put_swf_end_tag(s);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
531
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
532 put_flush_packet(s->pb);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
533
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
534 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
535 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
536
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
537 static int swf_write_audio(AVFormatContext *s,
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
538 AVCodecContext *enc, const uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
539 {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
540 SWFContext *swf = s->priv_data;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
541
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
542 /* Flash Player limit */
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
543 if (swf->swf_frame_number == 16000) {
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 360
diff changeset
544 av_log(enc, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n");
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
545 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
546
1854
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
547 if (swf->audio_in_pos + size >= AUDIO_FIFO_SIZE) {
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
548 av_log(s, AV_LOG_ERROR, "audio fifo too small to mux audio essence\n");
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
549 return -1;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
550 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
551
1854
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
552 memcpy(swf->audio_fifo + swf->audio_in_pos, buf, size);
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
553 swf->audio_in_pos += size;
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
554 swf->sound_samples += enc->frame_size;
0432f6b969b0 simplify swf muxer
bcoudurier
parents: 1833
diff changeset
555
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
556 /* if audio only stream make sure we add swf frames */
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
557 if (swf->video_type == 0) {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
558 swf_write_video(s, enc, 0, 0);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
559 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
560
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
561 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
562 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
563
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
564 static int swf_write_packet(AVFormatContext *s, AVPacket *pkt)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
565 {
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 807
diff changeset
566 AVCodecContext *codec = s->streams[pkt->stream_index]->codec;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
567 if (codec->codec_type == CODEC_TYPE_AUDIO)
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
568 return swf_write_audio(s, codec, pkt->data, pkt->size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
569 else
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
570 return swf_write_video(s, codec, pkt->data, pkt->size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
571 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
572
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
573 static int swf_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
574 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
575 SWFContext *swf = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
576 ByteIOContext *pb = s->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
577 AVCodecContext *enc, *video_enc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
578 int file_size, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
579
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
580 video_enc = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
581 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
582 enc = s->streams[i]->codec;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
583 if (enc->codec_type == CODEC_TYPE_VIDEO)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
584 video_enc = enc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
585 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
586
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
587 put_swf_tag(s, TAG_END);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
588 put_swf_end_tag(s);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
589
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
590 put_flush_packet(s->pb);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
591
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
592 /* patch file size and number of frames if not streamed */
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
593 if (!url_is_streamed(s->pb) && video_enc) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
594 file_size = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
595 url_fseek(pb, 4, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
596 put_le32(pb, file_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
597 url_fseek(pb, swf->duration_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
598 put_le16(pb, video_enc->frame_number);
1643
20c25a594c49 seek back at the end of file after updating header
bcoudurier
parents: 1642
diff changeset
599 url_fseek(pb, file_size, SEEK_SET);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
600 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
601 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
602 }
858
66cc656ea404 Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents: 820
diff changeset
603 #endif //CONFIG_MUXERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
604
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
605 /*********************************************/
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
606 /* Extract FLV encoded frame and MP3 from swf
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
607 Note that the detection of the real frame
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
608 is inaccurate at this point as it can be
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
609 quite tricky to determine, you almost certainly
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
610 will get a bad audio/video sync */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
611
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
612 static int get_swf_tag(ByteIOContext *pb, int *len_ptr)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
613 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
614 int tag, len;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
615
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
616 if (url_feof(pb))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
617 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
618
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
619 tag = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
620 len = tag & 0x3f;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
621 tag = tag >> 6;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
622 if (len == 0x3f) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
623 len = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
624 }
806
e1007d19f28d tell the user if compressed swf found
alex
parents: 775
diff changeset
625 // av_log(NULL, AV_LOG_DEBUG, "Tag: %d - Len: %d\n", tag, len);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
626 *len_ptr = len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
627 return tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
628 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
629
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
630
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
631 static int swf_probe(AVProbeData *p)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
632 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
633 /* check file header */
806
e1007d19f28d tell the user if compressed swf found
alex
parents: 775
diff changeset
634 if ((p->buf[0] == 'F' || p->buf[0] == 'C') && p->buf[1] == 'W' &&
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
635 p->buf[2] == 'S')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
636 return AVPROBE_SCORE_MAX;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
637 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
638 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
639 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
640
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
641 static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
642 {
1641
ea284c26b0f4 priv_data is allocated internally
bcoudurier
parents: 1640
diff changeset
643 SWFContext *swf = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
644 ByteIOContext *pb = s->pb;
2310
91a6c2b29b7b remove now useless vars
bcoudurier
parents: 2309
diff changeset
645 int nbits, len, tag;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
646
806
e1007d19f28d tell the user if compressed swf found
alex
parents: 775
diff changeset
647 tag = get_be32(pb) & 0xffffff00;
e1007d19f28d tell the user if compressed swf found
alex
parents: 775
diff changeset
648
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
649 if (tag == MKBETAG('C', 'W', 'S', 0)) {
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
650 av_log(s, AV_LOG_ERROR, "Compressed SWF format not supported\n");
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2164
diff changeset
651 return AVERROR(EIO);
806
e1007d19f28d tell the user if compressed swf found
alex
parents: 775
diff changeset
652 }
e1007d19f28d tell the user if compressed swf found
alex
parents: 775
diff changeset
653 if (tag != MKBETAG('F', 'W', 'S', 0))
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2164
diff changeset
654 return AVERROR(EIO);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
655 get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
656 /* skip rectangle size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
657 nbits = get_byte(pb) >> 3;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
658 len = (4 * nbits - 3 + 7) / 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
659 url_fskip(pb, len);
1889
e81bae269ae1 fix pts handling
bcoudurier
parents: 1882
diff changeset
660 swf->frame_rate = get_le16(pb); /* 8.8 fixed */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
661 get_le16(pb); /* frame count */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
662
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
663 swf->samples_per_frame = 0;
2307
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
664 s->ctx_flags |= AVFMTCTX_NOHEADER;
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
665 return 0;
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
666 }
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
667
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
668 static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
669 {
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
670 SWFContext *swf = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2402
diff changeset
671 ByteIOContext *pb = s->pb;
2307
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
672 AVStream *vst = NULL, *ast = NULL, *st = 0;
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
673 int tag, len, i, frame, v;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
674
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
675 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
676 tag = get_swf_tag(pb, &len);
2307
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
677 if (tag < 0)
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
678 return AVERROR(EIO);
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
679 if (tag == TAG_VIDEOSTREAM && !vst) {
1637
50bbf9658436 use ch_id as AVStream id and simplify
bcoudurier
parents: 1636
diff changeset
680 int ch_id = get_le16(pb);
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
681 get_le16(pb);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
682 get_le16(pb);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
683 get_le16(pb);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
684 get_byte(pb);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
685 /* Check for FLV1 */
1637
50bbf9658436 use ch_id as AVStream id and simplify
bcoudurier
parents: 1636
diff changeset
686 vst = av_new_stream(s, ch_id);
2913
f05588003063 check av_new_stream return value
bcoudurier
parents: 2771
diff changeset
687 if (!vst)
f05588003063 check av_new_stream return value
bcoudurier
parents: 2771
diff changeset
688 return -1;
1635
59d2c40950ca always export videostreams
bcoudurier
parents: 1623
diff changeset
689 vst->codec->codec_type = CODEC_TYPE_VIDEO;
59d2c40950ca always export videostreams
bcoudurier
parents: 1623
diff changeset
690 vst->codec->codec_id = codec_get_id(swf_codec_tags, get_byte(pb));
2307
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
691 av_set_pts_info(vst, 64, 256, swf->frame_rate);
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
692 vst->codec->time_base = (AVRational){ 256, swf->frame_rate };
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
693 len -= 10;
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
694 } else if ((tag == TAG_STREAMHEAD || tag == TAG_STREAMHEAD2) && !ast) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
695 /* streaming found */
1642
8b62e4e73069 simplify
bcoudurier
parents: 1641
diff changeset
696 int sample_rate_code;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
697 get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
698 v = get_byte(pb);
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
699 swf->samples_per_frame = get_le16(pb);
1638
0c6b7ac24cd7 swf can contain only one audio track, simplify
bcoudurier
parents: 1637
diff changeset
700 ast = av_new_stream(s, -1); /* -1 to avoid clash with video stream ch_id */
2913
f05588003063 check av_new_stream return value
bcoudurier
parents: 2771
diff changeset
701 if (!ast)
f05588003063 check av_new_stream return value
bcoudurier
parents: 2771
diff changeset
702 return -1;
1638
0c6b7ac24cd7 swf can contain only one audio track, simplify
bcoudurier
parents: 1637
diff changeset
703 swf->audio_stream_index = ast->index;
1636
783969dab069 always export audiostreams
bcoudurier
parents: 1635
diff changeset
704 ast->codec->channels = 1 + (v&1);
783969dab069 always export audiostreams
bcoudurier
parents: 1635
diff changeset
705 ast->codec->codec_type = CODEC_TYPE_AUDIO;
1833
09a67819763e support for adpcm swf, pcm
bcoudurier
parents: 1827
diff changeset
706 ast->codec->codec_id = codec_get_id(swf_audio_codec_tags, (v>>4) & 15);
2023
a3e79d6e4e3c add an enum for need_parsing
aurel
parents: 2001
diff changeset
707 ast->need_parsing = AVSTREAM_PARSE_FULL;
1642
8b62e4e73069 simplify
bcoudurier
parents: 1641
diff changeset
708 sample_rate_code= (v>>2) & 3;
8b62e4e73069 simplify
bcoudurier
parents: 1641
diff changeset
709 if (!sample_rate_code)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2164
diff changeset
710 return AVERROR(EIO);
1642
8b62e4e73069 simplify
bcoudurier
parents: 1641
diff changeset
711 ast->codec->sample_rate = 11025 << (sample_rate_code-1);
1890
04f9a3ae30af seems safer to set pts timebase to sample rate, fix some mp3
bcoudurier
parents: 1889
diff changeset
712 av_set_pts_info(ast, 64, 1, ast->codec->sample_rate);
2307
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
713 len -= 4;
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
714 } else if (tag == TAG_VIDEOFRAME) {
1637
50bbf9658436 use ch_id as AVStream id and simplify
bcoudurier
parents: 1636
diff changeset
715 int ch_id = get_le16(pb);
1639
4740223bfd8e simplify
bcoudurier
parents: 1638
diff changeset
716 len -= 2;
2309
15c426951f7b cosmetics, braces/parenthesis style
bcoudurier
parents: 2308
diff changeset
717 for(i=0; i<s->nb_streams; i++) {
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
718 st = s->streams[i];
1637
50bbf9658436 use ch_id as AVStream id and simplify
bcoudurier
parents: 1636
diff changeset
719 if (st->codec->codec_type == CODEC_TYPE_VIDEO && st->id == ch_id) {
50bbf9658436 use ch_id as AVStream id and simplify
bcoudurier
parents: 1636
diff changeset
720 frame = get_le16(pb);
1639
4740223bfd8e simplify
bcoudurier
parents: 1638
diff changeset
721 av_get_packet(pb, pkt, len-2);
1889
e81bae269ae1 fix pts handling
bcoudurier
parents: 1882
diff changeset
722 pkt->pts = frame;
1637
50bbf9658436 use ch_id as AVStream id and simplify
bcoudurier
parents: 1636
diff changeset
723 pkt->stream_index = st->index;
50bbf9658436 use ch_id as AVStream id and simplify
bcoudurier
parents: 1636
diff changeset
724 return pkt->size;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
725 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
726 }
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
727 } else if (tag == TAG_STREAMBLOCK) {
1638
0c6b7ac24cd7 swf can contain only one audio track, simplify
bcoudurier
parents: 1637
diff changeset
728 st = s->streams[swf->audio_stream_index];
0c6b7ac24cd7 swf can contain only one audio track, simplify
bcoudurier
parents: 1637
diff changeset
729 if (st->codec->codec_id == CODEC_ID_MP3) {
0c6b7ac24cd7 swf can contain only one audio track, simplify
bcoudurier
parents: 1637
diff changeset
730 url_fskip(pb, 4);
0c6b7ac24cd7 swf can contain only one audio track, simplify
bcoudurier
parents: 1637
diff changeset
731 av_get_packet(pb, pkt, len-4);
1833
09a67819763e support for adpcm swf, pcm
bcoudurier
parents: 1827
diff changeset
732 } else { // ADPCM, PCM
09a67819763e support for adpcm swf, pcm
bcoudurier
parents: 1827
diff changeset
733 av_get_packet(pb, pkt, len);
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
734 }
1833
09a67819763e support for adpcm swf, pcm
bcoudurier
parents: 1827
diff changeset
735 pkt->stream_index = st->index;
09a67819763e support for adpcm swf, pcm
bcoudurier
parents: 1827
diff changeset
736 return pkt->size;
1640
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
737 } else if (tag == TAG_JPEG2) {
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
738 for (i=0; i<s->nb_streams; i++) {
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
739 st = s->streams[i];
2307
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
740 if (st->id == -2)
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
741 break;
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
742 }
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
743 if (i == s->nb_streams) {
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
744 vst = av_new_stream(s, -2); /* -2 to avoid clash with video stream and audio stream */
2913
f05588003063 check av_new_stream return value
bcoudurier
parents: 2771
diff changeset
745 if (!vst)
f05588003063 check av_new_stream return value
bcoudurier
parents: 2771
diff changeset
746 return -1;
2307
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
747 vst->codec->codec_type = CODEC_TYPE_VIDEO;
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
748 vst->codec->codec_id = CODEC_ID_MJPEG;
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
749 av_set_pts_info(vst, 64, 256, swf->frame_rate);
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
750 vst->codec->time_base = (AVRational){ 256, swf->frame_rate };
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
751 st = vst;
d5508f387614 add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
bcoudurier
parents: 2289
diff changeset
752 }
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
753 get_le16(pb); /* BITMAP_ID */
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
754 av_new_packet(pkt, len-2);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
755 get_buffer(pb, pkt->data, 4);
2402
8decf7585a94 support swink created files which have soi/eoi broken tags reversed
bcoudurier
parents: 2310
diff changeset
756 if (AV_RB32(pkt->data) == 0xffd8ffd9 ||
8decf7585a94 support swink created files which have soi/eoi broken tags reversed
bcoudurier
parents: 2310
diff changeset
757 AV_RB32(pkt->data) == 0xffd9ffd8) {
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
758 /* old SWF files containing SOI/EOI as data start */
2402
8decf7585a94 support swink created files which have soi/eoi broken tags reversed
bcoudurier
parents: 2310
diff changeset
759 /* files created by swink have reversed tag */
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
760 pkt->size -= 4;
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
761 get_buffer(pb, pkt->data, pkt->size);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
762 } else {
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
763 get_buffer(pb, pkt->data + 4, pkt->size - 4);
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
764 }
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
765 pkt->stream_index = st->index;
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
766 return pkt->size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
767 }
1639
4740223bfd8e simplify
bcoudurier
parents: 1638
diff changeset
768 url_fskip(pb, len);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
769 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
770 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
771 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
772
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
773 static int swf_read_close(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
774 {
2308
c12d367e9246 cosmetics, indentation
bcoudurier
parents: 2307
diff changeset
775 return 0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
776 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
777
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
778 #ifdef CONFIG_SWF_DEMUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
779 AVInputFormat swf_demuxer = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
780 "swf",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
781 "Flash format",
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
782 sizeof(SWFContext),
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
783 swf_probe,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
784 swf_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
785 swf_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
786 swf_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
787 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
788 #endif
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
789 #ifdef CONFIG_SWF_MUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
790 AVOutputFormat swf_muxer = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
791 "swf",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
792 "Flash format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
793 "application/x-shockwave-flash",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
794 "swf",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
795 sizeof(SWFContext),
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
796 CODEC_ID_MP3,
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
797 CODEC_ID_FLV1,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
798 swf_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
799 swf_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
800 swf_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
801 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
802 #endif
2955
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
803 #ifdef CONFIG_AVM2_MUXER
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
804 AVOutputFormat avm2_muxer = {
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
805 "avm2",
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
806 "Flash 9 (AVM2) format",
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
807 "application/x-shockwave-flash",
2959
1b7bf70aab74 unset extension, so code path, and guess format do not choose
bcoudurier
parents: 2955
diff changeset
808 NULL,
2955
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
809 sizeof(SWFContext),
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
810 CODEC_ID_MP3,
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
811 CODEC_ID_FLV1,
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
812 swf_write_header,
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
813 swf_write_packet,
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
814 swf_write_trailer,
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
815 };
b2d1cd7ab383 new avm2 (flash 9) muxer, patch by Paul Egan, paulegan at mail dot com
bcoudurier
parents: 2913
diff changeset
816 #endif