annotate swf.c @ 1677:2a85c82b8538 libavformat

add codec_id <-> codec_tag tables to AVIn/OutputFormat
author michael
date Sun, 21 Jan 2007 01:39:17 +0000
parents a782462e2497
children 6b76db126b72
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
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 #define TAG_LONG 0x100
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 /* flags for shape definition */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 #define FLAG_MOVETO 0x01
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 #define FLAG_SETFILL0 0x02
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 #define FLAG_SETFILL1 0x04
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
51 #define AUDIO_FIFO_SIZE 65536
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
52
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 /* character id used */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 #define BITMAP_ID 0
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
55 #define VIDEO_ID 0
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 #define SHAPE_ID 1
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57
516
59ddf98a5c65 nonsense removial
michael
parents: 482
diff changeset
58 #undef NDEBUG
59ddf98a5c65 nonsense removial
michael
parents: 482
diff changeset
59 #include <assert.h>
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
60
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 typedef struct {
1638
0c6b7ac24cd7 swf can contain only one audio track, simplify
bcoudurier
parents: 1637
diff changeset
62 int audio_stream_index;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 offset_t duration_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 offset_t tag_pos;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
65
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
66 int samples_per_frame;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
67 int sound_samples;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
68 int video_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;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
71 int ms_per_frame;
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
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
74 uint8_t *audio_fifo;
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 int audio_out_pos;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
77 int audio_size;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
78
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
79 int video_type;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
80 int audio_type;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 } SWFContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82
1677
2a85c82b8538 add codec_id <-> codec_tag tables to AVIn/OutputFormat
michael
parents: 1673
diff changeset
83 static const AVCodecTag swf_codec_tags[] = {
1305
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
84 {CODEC_ID_FLV1, 0x02},
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
85 {CODEC_ID_VP6F, 0x04},
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
86 {0, 0},
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
87 };
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
88
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
89 static const int sSampleRates[3][4] = {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
90 {44100, 48000, 32000, 0},
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
91 {22050, 24000, 16000, 0},
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
92 {11025, 12000, 8000, 0},
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
93 };
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
94
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
95 static const int sBitRates[2][3][15] = {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
96 { { 0, 32, 64, 96,128,160,192,224,256,288,320,352,384,416,448},
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
97 { 0, 32, 48, 56, 64, 80, 96,112,128,160,192,224,256,320,384},
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
98 { 0, 32, 40, 48, 56, 64, 80, 96,112,128,160,192,224,256,320}
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
99 },
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
100 { { 0, 32, 48, 56, 64, 80, 96,112,128,144,160,176,192,224,256},
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
101 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160},
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
102 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160}
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
103 },
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
104 };
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
105
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
106 static const int sSamplesPerFrame[3][3] =
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
107 {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
108 { 384, 1152, 1152 },
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
109 { 384, 1152, 576 },
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
110 { 384, 1152, 576 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
111 };
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
112
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
113 static const int sBitsPerSlot[3] = {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
114 32,
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
115 8,
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
116 8
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
117 };
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
118
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
119 static int swf_mp3_info(void *data, int *byteSize, int *samplesPerFrame, int *sampleRate, int *isMono )
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
120 {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
121 uint8_t *dataTmp = (uint8_t *)data;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
122 uint32_t header = ( (uint32_t)dataTmp[0] << 24 ) | ( (uint32_t)dataTmp[1] << 16 ) | ( (uint32_t)dataTmp[2] << 8 ) | (uint32_t)dataTmp[3];
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
123 int layerID = 3 - ((header >> 17) & 0x03);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
124 int bitRateID = ((header >> 12) & 0x0f);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
125 int sampleRateID = ((header >> 10) & 0x03);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
126 int bitRate = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
127 int bitsPerSlot = sBitsPerSlot[layerID];
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
128 int isPadded = ((header >> 9) & 0x01);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
129
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
130 if ( (( header >> 21 ) & 0x7ff) != 0x7ff ) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
131 return 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
132 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
133
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
134 *isMono = ((header >> 6) & 0x03) == 0x03;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
135
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
136 if ( (header >> 19 ) & 0x01 ) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
137 *sampleRate = sSampleRates[0][sampleRateID];
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
138 bitRate = sBitRates[0][layerID][bitRateID] * 1000;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
139 *samplesPerFrame = sSamplesPerFrame[0][layerID];
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
140 } else {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
141 if ( (header >> 20) & 0x01 ) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
142 *sampleRate = sSampleRates[1][sampleRateID];
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
143 bitRate = sBitRates[1][layerID][bitRateID] * 1000;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
144 *samplesPerFrame = sSamplesPerFrame[1][layerID];
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
145 } else {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
146 *sampleRate = sSampleRates[2][sampleRateID];
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
147 bitRate = sBitRates[1][layerID][bitRateID] * 1000;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
148 *samplesPerFrame = sSamplesPerFrame[2][layerID];
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
149 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
150 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
151
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
152 *byteSize = ( ( ( ( *samplesPerFrame * (bitRate / bitsPerSlot) ) / *sampleRate ) + isPadded ) );
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
153
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
154 return 1;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
155 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
156
858
66cc656ea404 Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents: 820
diff changeset
157 #ifdef CONFIG_MUXERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 static void put_swf_tag(AVFormatContext *s, int tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 SWFContext *swf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 swf->tag_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 swf->tag = tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 /* reserve some room for the tag */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166 if (tag & TAG_LONG) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 put_le32(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 static void put_swf_end_tag(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 SWFContext *swf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 offset_t pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 int tag_len, tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181 pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 tag_len = pos - swf->tag_pos - 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 tag = swf->tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184 url_fseek(pb, swf->tag_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 if (tag & TAG_LONG) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 tag &= ~TAG_LONG;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 put_le16(pb, (tag << 6) | 0x3f);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 put_le32(pb, tag_len - 4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 assert(tag_len < 0x3f);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 put_le16(pb, (tag << 6) | tag_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 url_fseek(pb, pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 static inline void max_nbits(int *nbits_ptr, int val)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 int n;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 if (val == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 return;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 val = abs(val);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 n = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 while (val != 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 n++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 val >>= 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 if (n > *nbits_ptr)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 *nbits_ptr = n;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
212 static void put_swf_rect(ByteIOContext *pb,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 int xmin, int xmax, int ymin, int ymax)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 PutBitContext p;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 5
diff changeset
216 uint8_t buf[256];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 int nbits, mask;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218
276
3dd3646e0164 init_put_bits changed
alex
parents: 241
diff changeset
219 init_put_bits(&p, buf, sizeof(buf));
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
220
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221 nbits = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 max_nbits(&nbits, xmin);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 max_nbits(&nbits, xmax);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 max_nbits(&nbits, ymin);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 max_nbits(&nbits, ymax);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 mask = (1 << nbits) - 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 /* rectangle info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 put_bits(&p, 5, nbits);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 put_bits(&p, nbits, xmin & mask);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 put_bits(&p, nbits, xmax & mask);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 put_bits(&p, nbits, ymin & mask);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 put_bits(&p, nbits, ymax & mask);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
234
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235 flush_put_bits(&p);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 put_buffer(pb, buf, pbBufPtr(&p) - p.buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 static void put_swf_line_edge(PutBitContext *pb, int dx, int dy)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 int nbits, mask;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 put_bits(pb, 1, 1); /* edge */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244 put_bits(pb, 1, 1); /* line select */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 nbits = 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 max_nbits(&nbits, dx);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 max_nbits(&nbits, dy);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 mask = (1 << nbits) - 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 put_bits(pb, 4, nbits - 2); /* 16 bits precision */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 if (dx == 0) {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
252 put_bits(pb, 1, 0);
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
253 put_bits(pb, 1, 1);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 put_bits(pb, nbits, dy & mask);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 } else if (dy == 0) {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
256 put_bits(pb, 1, 0);
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
257 put_bits(pb, 1, 0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 put_bits(pb, nbits, dx & mask);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 } else {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
260 put_bits(pb, 1, 1);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 put_bits(pb, nbits, dx & mask);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 put_bits(pb, nbits, dy & mask);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 #define FRAC_BITS 16
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
268 /* put matrix */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 static void put_swf_matrix(ByteIOContext *pb,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
270 int a, int b, int c, int d, int tx, int ty)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
272 PutBitContext p;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 5
diff changeset
273 uint8_t buf[256];
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
274 int nbits;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275
276
3dd3646e0164 init_put_bits changed
alex
parents: 241
diff changeset
276 init_put_bits(&p, buf, sizeof(buf));
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
277
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 put_bits(&p, 1, 1); /* a, d present */
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
279 nbits = 1;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
280 max_nbits(&nbits, a);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
281 max_nbits(&nbits, d);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
282 put_bits(&p, 5, nbits); /* nb bits */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
283 put_bits(&p, nbits, a);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
284 put_bits(&p, nbits, d);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
285
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 put_bits(&p, 1, 1); /* b, c present */
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
287 nbits = 1;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
288 max_nbits(&nbits, c);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
289 max_nbits(&nbits, b);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
290 put_bits(&p, 5, nbits); /* nb bits */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
291 put_bits(&p, nbits, c);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
292 put_bits(&p, nbits, b);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
293
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
294 nbits = 1;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
295 max_nbits(&nbits, tx);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
296 max_nbits(&nbits, ty);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
297 put_bits(&p, 5, nbits); /* nb bits */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
298 put_bits(&p, nbits, tx);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
299 put_bits(&p, nbits, ty);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301 flush_put_bits(&p);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
302 put_buffer(pb, buf, pbBufPtr(&p) - p.buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
304
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
305 /* */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
306 static int swf_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
307 {
1623
bdb50e314f29 priv_data is allocated/freed internally
bcoudurier
parents: 1620
diff changeset
308 SWFContext *swf = s->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
309 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
310 AVCodecContext *enc, *audio_enc, *video_enc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
311 PutBitContext p;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 5
diff changeset
312 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
313 int i, width, height, rate, rate_base;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
314
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
315 swf->audio_in_pos = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
316 swf->audio_out_pos = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
317 swf->audio_size = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
318 swf->audio_fifo = av_malloc(AUDIO_FIFO_SIZE);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
319 swf->sound_samples = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
320 swf->video_samples = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
321 swf->swf_frame_number = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
322 swf->video_frame_number = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
323
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
324 video_enc = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
325 audio_enc = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
326 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
327 enc = s->streams[i]->codec;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328 if (enc->codec_type == CODEC_TYPE_AUDIO)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
329 audio_enc = enc;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
330 else {
1305
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
331 if ( enc->codec_id == CODEC_ID_VP6F ||
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
332 enc->codec_id == CODEC_ID_FLV1 ||
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
333 enc->codec_id == CODEC_ID_MJPEG ) {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
334 video_enc = enc;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
335 } else {
1305
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
336 av_log(enc, AV_LOG_ERROR, "SWF only supports VP6, FLV1 and MJPEG\n");
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
337 return -1;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
338 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
339 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
340 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
341
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342 if (!video_enc) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343 /* currenty, cannot work correctly if audio only */
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
344 swf->video_type = 0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
345 width = 320;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
346 height = 200;
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 65
diff changeset
347 rate = 10;
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 65
diff changeset
348 rate_base= 1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349 } else {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
350 swf->video_type = video_enc->codec_id;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
351 width = video_enc->width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 height = video_enc->height;
743
af4e24d6310c switch to native time bases
michael
parents: 628
diff changeset
353 rate = video_enc->time_base.den;
af4e24d6310c switch to native time bases
michael
parents: 628
diff changeset
354 rate_base = video_enc->time_base.num;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
355 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
356
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
357 if (!audio_enc ) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
358 swf->audio_type = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
359 swf->samples_per_frame = ( 44100. * rate_base ) / rate;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
360 } else {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
361 swf->audio_type = audio_enc->codec_id;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
362 swf->samples_per_frame = ( ( audio_enc->sample_rate ) * rate_base ) / rate;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
363 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
364
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
365 put_tag(pb, "FWS");
1305
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
366 if ( video_enc && video_enc->codec_id == CODEC_ID_VP6F ) {
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
367 put_byte(pb, 8); /* version (version 8 and above support VP6 codec) */
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
368 } 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
369 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
370 } else {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
371 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
372 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
373 put_le32(pb, DUMMY_FILE_SIZE); /* dummy size
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
374 (will be patched if not streamed) */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
375
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
376 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
377 put_le16(pb, (rate * 256) / rate_base); /* frame rate */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
378 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
379 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
380
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
381 /* define a shape with the jpeg inside */
1305
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
382 if ( video_enc && (video_enc->codec_id == CODEC_ID_VP6F ||
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
383 video_enc->codec_id == CODEC_ID_FLV1 )) {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
384 } else if ( video_enc && video_enc->codec_id == CODEC_ID_MJPEG ) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
385 put_swf_tag(s, TAG_DEFINESHAPE);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
386
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
387 put_le16(pb, SHAPE_ID); /* ID of shape */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
388 /* bounding rectangle */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
389 put_swf_rect(pb, 0, width, 0, height);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
390 /* style info */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
391 put_byte(pb, 1); /* one fill style */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
392 put_byte(pb, 0x41); /* clipped bitmap fill */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
393 put_le16(pb, BITMAP_ID); /* bitmap ID */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
394 /* position of the bitmap */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
395 put_swf_matrix(pb, (int)(1.0 * (1 << FRAC_BITS)), 0,
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
396 0, (int)(1.0 * (1 << FRAC_BITS)), 0, 0);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
397 put_byte(pb, 0); /* no line style */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
398
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
399 /* shape drawing */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
400 init_put_bits(&p, buf1, sizeof(buf1));
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
401 put_bits(&p, 4, 1); /* one fill bit */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
402 put_bits(&p, 4, 0); /* zero line bit */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
403
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
404 put_bits(&p, 1, 0); /* not an edge */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
405 put_bits(&p, 5, FLAG_MOVETO | FLAG_SETFILL0);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
406 put_bits(&p, 5, 1); /* nbits */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
407 put_bits(&p, 1, 0); /* X */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
408 put_bits(&p, 1, 0); /* Y */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
409 put_bits(&p, 1, 1); /* set fill style 1 */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
410
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
411 /* draw the rectangle ! */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
412 put_swf_line_edge(&p, width, 0);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
413 put_swf_line_edge(&p, 0, height);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
414 put_swf_line_edge(&p, -width, 0);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
415 put_swf_line_edge(&p, 0, -height);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
416
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
417 /* end of shape */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
418 put_bits(&p, 1, 0); /* not an edge */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
419 put_bits(&p, 5, 0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
420
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
421 flush_put_bits(&p);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
422 put_buffer(pb, buf1, pbBufPtr(&p) - p.buf);
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 put_swf_end_tag(s);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
425 }
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 if (audio_enc && audio_enc->codec_id == CODEC_ID_MP3 ) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
428 int v;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
429
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
430 /* start sound */
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
431 put_swf_tag(s, TAG_STREAMHEAD2);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
432
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
433 v = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
434 switch(audio_enc->sample_rate) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435 case 11025:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 v |= 1 << 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 case 22050:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439 v |= 2 << 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441 case 44100:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 v |= 3 << 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445 /* not supported */
1519
f57c7614ff98 print error when unsupported sample rate is used with swf
bcoudurier
parents: 1417
diff changeset
446 av_log(s, AV_LOG_ERROR, "swf doesnt support that sample rate, choose from (44100, 22050, 11025)\n");
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
447 av_free(swf->audio_fifo);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449 }
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
450 v |= 0x02; /* 16 bit playback */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451 if (audio_enc->channels == 2)
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
452 v |= 0x01; /* stereo playback */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
453 put_byte(&s->pb, v);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
454 v |= 0x20; /* mp3 compressed */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
455 put_byte(&s->pb, v);
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
456 put_le16(&s->pb, swf->samples_per_frame); /* avg samples per frame */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
457 put_le16(&s->pb, 0);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
458
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
459 put_swf_end_tag(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
460 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
461
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
462 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
463 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
464 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
465
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
466 static int swf_write_video(AVFormatContext *s,
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 187
diff changeset
467 AVCodecContext *enc, const uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468 {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
469 SWFContext *swf = s->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
470 ByteIOContext *pb = &s->pb;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
471 int c = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
472 int outSize = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
473 int outSamples = 0;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
474
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
475 /* Flash Player limit */
360
81e90b91f457 no limits!, warning is enough
michael
parents: 359
diff changeset
476 if ( swf->swf_frame_number == 16000 ) {
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 360
diff changeset
477 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
478 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
479
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
480 if ( swf->audio_type ) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
481 /* Prescan audio data for this swf frame */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
482 retry_swf_audio_packet:
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
483 if ( ( swf->audio_size-outSize ) >= 4 ) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
484 int mp3FrameSize = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
485 int mp3SampleRate = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
486 int mp3IsMono = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
487 int mp3SamplesPerFrame = 0;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
488
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
489 /* copy out mp3 header from ring buffer */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
490 uint8_t header[4];
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
491 for (c=0; c<4; c++) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
492 header[c] = swf->audio_fifo[(swf->audio_in_pos+outSize+c) % AUDIO_FIFO_SIZE];
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
493 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
494
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
495 if ( swf_mp3_info(header,&mp3FrameSize,&mp3SamplesPerFrame,&mp3SampleRate,&mp3IsMono) ) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
496 if ( ( swf->audio_size-outSize ) >= mp3FrameSize ) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
497 outSize += mp3FrameSize;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
498 outSamples += mp3SamplesPerFrame;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
499 if ( ( swf->sound_samples + outSamples + swf->samples_per_frame ) < swf->video_samples ) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
500 goto retry_swf_audio_packet;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
501 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
502 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
503 } else {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
504 /* invalid mp3 data, skip forward
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
505 we need to do this since the Flash Player
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
506 does not like custom headers */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
507 swf->audio_in_pos ++;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
508 swf->audio_size --;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
509 swf->audio_in_pos %= AUDIO_FIFO_SIZE;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
510 goto retry_swf_audio_packet;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
511 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
512 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
513
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
514 /* audio stream is behind video stream, bail */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
515 if ( ( swf->sound_samples + outSamples + swf->samples_per_frame ) < swf->video_samples ) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
516 return 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
517 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
518 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
519
1305
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
520 if ( swf->video_type == CODEC_ID_VP6F ||
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
521 swf->video_type == CODEC_ID_FLV1 ) {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
522 if ( swf->video_frame_number == 0 ) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
523 /* create a new video object */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
524 put_swf_tag(s, TAG_VIDEOSTREAM);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
525 put_le16(pb, VIDEO_ID);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
526 put_le16(pb, 15000 ); /* hard flash player limit */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
527 put_le16(pb, enc->width);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
528 put_le16(pb, enc->height);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
529 put_byte(pb, 0);
1305
541f4aa12efc VP5 and VP6 video decoder
aurel
parents: 1169
diff changeset
530 put_byte(pb,codec_get_tag(swf_codec_tags,swf->video_type));
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
531 put_swf_end_tag(s);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
532
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
533 /* place the video object for the first time */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
534 put_swf_tag(s, TAG_PLACEOBJECT2);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
535 put_byte(pb, 0x36);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
536 put_le16(pb, 1);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
537 put_le16(pb, VIDEO_ID);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
538 put_swf_matrix(pb, 1 << FRAC_BITS, 0, 0, 1 << FRAC_BITS, 0, 0);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
539 put_le16(pb, swf->video_frame_number );
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
540 put_byte(pb, 'v');
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
541 put_byte(pb, 'i');
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
542 put_byte(pb, 'd');
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
543 put_byte(pb, 'e');
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
544 put_byte(pb, 'o');
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
545 put_byte(pb, 0x00);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
546 put_swf_end_tag(s);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
547 } else {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
548 /* mark the character for update */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
549 put_swf_tag(s, TAG_PLACEOBJECT2);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
550 put_byte(pb, 0x11);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
551 put_le16(pb, 1);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
552 put_le16(pb, swf->video_frame_number );
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
553 put_swf_end_tag(s);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
554 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
555
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
556 /* set video frame data */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
557 put_swf_tag(s, TAG_VIDEOFRAME | TAG_LONG);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
558 put_le16(pb, VIDEO_ID);
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
559 put_le16(pb, swf->video_frame_number++ );
516
59ddf98a5c65 nonsense removial
michael
parents: 482
diff changeset
560 put_buffer(pb, buf, size);
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
561 put_swf_end_tag(s);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
562 } else if ( swf->video_type == CODEC_ID_MJPEG ) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
563 if (swf->swf_frame_number > 0) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
564 /* remove the shape */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
565 put_swf_tag(s, TAG_REMOVEOBJECT);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
566 put_le16(pb, SHAPE_ID); /* shape ID */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
567 put_le16(pb, 1); /* depth */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
568 put_swf_end_tag(s);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
569
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
570 /* free the bitmap */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
571 put_swf_tag(s, TAG_FREECHARACTER);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
572 put_le16(pb, BITMAP_ID);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
573 put_swf_end_tag(s);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
574 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
575
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
576 put_swf_tag(s, TAG_JPEG2 | TAG_LONG);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
577
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
578 put_le16(pb, BITMAP_ID); /* ID of the image */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
579
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
580 /* a dummy jpeg header seems to be required */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
581 put_byte(pb, 0xff);
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
582 put_byte(pb, 0xd8);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
583 put_byte(pb, 0xff);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
584 put_byte(pb, 0xd9);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
585 /* write the jpeg image */
516
59ddf98a5c65 nonsense removial
michael
parents: 482
diff changeset
586 put_buffer(pb, buf, size);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
587
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
588 put_swf_end_tag(s);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
589
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
590 /* draw the shape */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
591
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
592 put_swf_tag(s, TAG_PLACEOBJECT);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
593 put_le16(pb, SHAPE_ID); /* shape ID */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
594 put_le16(pb, 1); /* depth */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
595 put_swf_matrix(pb, 20 << FRAC_BITS, 0, 0, 20 << FRAC_BITS, 0, 0);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
596 put_swf_end_tag(s);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
597 } else {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
598 /* invalid codec */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
599 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
600
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
601 swf->swf_frame_number ++;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
602
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
603 swf->video_samples += swf->samples_per_frame;
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 /* streaming sound always should be placed just before showframe tags */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
606 if ( outSize > 0 ) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
607 put_swf_tag(s, TAG_STREAMBLOCK | TAG_LONG);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
608 put_le16(pb, outSamples);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
609 put_le16(pb, 0);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
610 for (c=0; c<outSize; c++) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
611 put_byte(pb,swf->audio_fifo[(swf->audio_in_pos+c) % AUDIO_FIFO_SIZE]);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
612 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
613 put_swf_end_tag(s);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
614
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
615 /* update FIFO */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
616 swf->sound_samples += outSamples;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
617 swf->audio_in_pos += outSize;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
618 swf->audio_size -= outSize;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
619 swf->audio_in_pos %= AUDIO_FIFO_SIZE;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
620 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
621
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
622 /* output the frame */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
623 put_swf_tag(s, TAG_SHOWFRAME);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
624 put_swf_end_tag(s);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
625
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
626 put_flush_packet(&s->pb);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
627
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
628 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
629 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
630
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
631 static int swf_write_audio(AVFormatContext *s,
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
632 AVCodecContext *enc, const uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
633 {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
634 SWFContext *swf = s->priv_data;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
635 int c = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
636
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
637 /* Flash Player limit */
360
81e90b91f457 no limits!, warning is enough
michael
parents: 359
diff changeset
638 if ( swf->swf_frame_number == 16000 ) {
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 360
diff changeset
639 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
640 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
641
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
642 if (enc->codec_id == CODEC_ID_MP3 ) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
643 for (c=0; c<size; c++) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
644 swf->audio_fifo[(swf->audio_out_pos+c)%AUDIO_FIFO_SIZE] = buf[c];
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
645 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
646 swf->audio_size += size;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
647 swf->audio_out_pos += size;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
648 swf->audio_out_pos %= AUDIO_FIFO_SIZE;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
649 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
650
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
651 /* if audio only stream make sure we add swf frames */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
652 if ( swf->video_type == 0 ) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
653 swf_write_video(s, enc, 0, 0);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
654 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
655
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
656 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
657 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
658
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
659 static int swf_write_packet(AVFormatContext *s, AVPacket *pkt)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
660 {
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 807
diff changeset
661 AVCodecContext *codec = s->streams[pkt->stream_index]->codec;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
662 if (codec->codec_type == CODEC_TYPE_AUDIO)
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
663 return swf_write_audio(s, codec, pkt->data, pkt->size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
664 else
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
665 return swf_write_video(s, codec, pkt->data, pkt->size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
666 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
667
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
668 static int swf_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
669 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
670 SWFContext *swf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
671 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
672 AVCodecContext *enc, *video_enc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
673 int file_size, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
674
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
675 video_enc = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
676 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
677 enc = s->streams[i]->codec;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
678 if (enc->codec_type == CODEC_TYPE_VIDEO)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
679 video_enc = enc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
680 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
681
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
682 put_swf_tag(s, TAG_END);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
683 put_swf_end_tag(s);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
684
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
685 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
686
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
687 /* patch file size and number of frames if not streamed */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
688 if (!url_is_streamed(&s->pb) && video_enc) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
689 file_size = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
690 url_fseek(pb, 4, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
691 put_le32(pb, file_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
692 url_fseek(pb, swf->duration_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
693 put_le16(pb, video_enc->frame_number);
1643
20c25a594c49 seek back at the end of file after updating header
bcoudurier
parents: 1642
diff changeset
694 url_fseek(pb, file_size, SEEK_SET);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
695 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
696
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
697 av_free(swf->audio_fifo);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
698
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
699 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
700 }
858
66cc656ea404 Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents: 820
diff changeset
701 #endif //CONFIG_MUXERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
702
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
703 /*********************************************/
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
704 /* Extract FLV encoded frame and MP3 from swf
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
705 Note that the detection of the real frame
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
706 is inaccurate at this point as it can be
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
707 quite tricky to determine, you almost certainly
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
708 will get a bad audio/video sync */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
709
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
710 static int get_swf_tag(ByteIOContext *pb, int *len_ptr)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
711 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
712 int tag, len;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
713
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
714 if (url_feof(pb))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
715 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
716
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
717 tag = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
718 len = tag & 0x3f;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
719 tag = tag >> 6;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
720 if (len == 0x3f) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
721 len = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
722 }
806
e1007d19f28d tell the user if compressed swf found
alex
parents: 775
diff changeset
723 // av_log(NULL, AV_LOG_DEBUG, "Tag: %d - Len: %d\n", tag, len);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
724 *len_ptr = len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
725 return tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
726 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
727
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
728
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
729 static int swf_probe(AVProbeData *p)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
730 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
731 /* check file header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
732 if (p->buf_size <= 16)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
733 return 0;
806
e1007d19f28d tell the user if compressed swf found
alex
parents: 775
diff changeset
734 if ((p->buf[0] == 'F' || p->buf[0] == 'C') && p->buf[1] == 'W' &&
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
735 p->buf[2] == 'S')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
736 return AVPROBE_SCORE_MAX;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
737 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
738 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
739 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
740
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
741 static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
742 {
1641
ea284c26b0f4 priv_data is allocated internally
bcoudurier
parents: 1640
diff changeset
743 SWFContext *swf = s->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
744 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
745 int nbits, len, frame_rate, tag, v;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
746 offset_t firstTagOff;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
747 AVStream *ast = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
748 AVStream *vst = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
749
806
e1007d19f28d tell the user if compressed swf found
alex
parents: 775
diff changeset
750 tag = get_be32(pb) & 0xffffff00;
e1007d19f28d tell the user if compressed swf found
alex
parents: 775
diff changeset
751
e1007d19f28d tell the user if compressed swf found
alex
parents: 775
diff changeset
752 if (tag == MKBETAG('C', 'W', 'S', 0))
e1007d19f28d tell the user if compressed swf found
alex
parents: 775
diff changeset
753 {
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
754 av_log(s, AV_LOG_ERROR, "Compressed SWF format not supported\n");
806
e1007d19f28d tell the user if compressed swf found
alex
parents: 775
diff changeset
755 return AVERROR_IO;
e1007d19f28d tell the user if compressed swf found
alex
parents: 775
diff changeset
756 }
e1007d19f28d tell the user if compressed swf found
alex
parents: 775
diff changeset
757 if (tag != MKBETAG('F', 'W', 'S', 0))
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 468
diff changeset
758 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
759 get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
760 /* skip rectangle size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
761 nbits = get_byte(pb) >> 3;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
762 len = (4 * nbits - 3 + 7) / 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
763 url_fskip(pb, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
764 frame_rate = get_le16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
765 get_le16(pb); /* frame count */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
766
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
767 /* The Flash Player converts 8.8 frame rates
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
768 to milliseconds internally. Do the same to get
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
769 a correct framerate */
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
770 swf->ms_per_frame = ( 1000 * 256 ) / frame_rate;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
771 swf->samples_per_frame = 0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
772
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
773 firstTagOff = url_ftell(pb);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
774 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
775 tag = get_swf_tag(pb, &len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
776 if (tag < 0) {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
777 if ( ast || vst ) {
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
778 if ( vst && ast ) {
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 807
diff changeset
779 vst->codec->time_base.den = ast->codec->sample_rate / swf->samples_per_frame;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 807
diff changeset
780 vst->codec->time_base.num = 1;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
781 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
782 break;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
783 }
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 360
diff changeset
784 av_log(s, AV_LOG_ERROR, "No media found in SWF\n");
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 468
diff changeset
785 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
786 }
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
787 if ( tag == TAG_VIDEOSTREAM && !vst) {
1637
50bbf9658436 use ch_id as AVStream id and simplify
bcoudurier
parents: 1636
diff changeset
788 int ch_id = get_le16(pb);
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
789 get_le16(pb);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
790 get_le16(pb);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
791 get_le16(pb);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
792 get_byte(pb);
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
793 /* Check for FLV1 */
1637
50bbf9658436 use ch_id as AVStream id and simplify
bcoudurier
parents: 1636
diff changeset
794 vst = av_new_stream(s, ch_id);
1635
59d2c40950ca always export videostreams
bcoudurier
parents: 1623
diff changeset
795 av_set_pts_info(vst, 24, 1, 1000); /* 24 bit pts in ms */
59d2c40950ca always export videostreams
bcoudurier
parents: 1623
diff changeset
796 vst->codec->codec_type = CODEC_TYPE_VIDEO;
59d2c40950ca always export videostreams
bcoudurier
parents: 1623
diff changeset
797 vst->codec->codec_id = codec_get_id(swf_codec_tags, get_byte(pb));
59d2c40950ca always export videostreams
bcoudurier
parents: 1623
diff changeset
798 if (swf->samples_per_frame) {
59d2c40950ca always export videostreams
bcoudurier
parents: 1623
diff changeset
799 vst->codec->time_base.den = 1000. / swf->ms_per_frame;
59d2c40950ca always export videostreams
bcoudurier
parents: 1623
diff changeset
800 vst->codec->time_base.num = 1;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
801 }
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
802 } else if ( ( tag == TAG_STREAMHEAD || tag == TAG_STREAMHEAD2 ) && !ast) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
803 /* streaming found */
1642
8b62e4e73069 simplify
bcoudurier
parents: 1641
diff changeset
804 int sample_rate_code;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
805 get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
806 v = get_byte(pb);
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
807 swf->samples_per_frame = get_le16(pb);
1638
0c6b7ac24cd7 swf can contain only one audio track, simplify
bcoudurier
parents: 1637
diff changeset
808 ast = av_new_stream(s, -1); /* -1 to avoid clash with video stream ch_id */
1636
783969dab069 always export audiostreams
bcoudurier
parents: 1635
diff changeset
809 av_set_pts_info(ast, 24, 1, 1000); /* 24 bit pts in ms */
1638
0c6b7ac24cd7 swf can contain only one audio track, simplify
bcoudurier
parents: 1637
diff changeset
810 swf->audio_stream_index = ast->index;
1636
783969dab069 always export audiostreams
bcoudurier
parents: 1635
diff changeset
811 ast->codec->channels = 1 + (v&1);
783969dab069 always export audiostreams
bcoudurier
parents: 1635
diff changeset
812 ast->codec->codec_type = CODEC_TYPE_AUDIO;
783969dab069 always export audiostreams
bcoudurier
parents: 1635
diff changeset
813 if (v & 0x20)
783969dab069 always export audiostreams
bcoudurier
parents: 1635
diff changeset
814 ast->codec->codec_id = CODEC_ID_MP3;
783969dab069 always export audiostreams
bcoudurier
parents: 1635
diff changeset
815 ast->need_parsing = 1;
1642
8b62e4e73069 simplify
bcoudurier
parents: 1641
diff changeset
816 sample_rate_code= (v>>2) & 3;
8b62e4e73069 simplify
bcoudurier
parents: 1641
diff changeset
817 if (!sample_rate_code)
1636
783969dab069 always export audiostreams
bcoudurier
parents: 1635
diff changeset
818 return AVERROR_IO;
1642
8b62e4e73069 simplify
bcoudurier
parents: 1641
diff changeset
819 ast->codec->sample_rate = 11025 << (sample_rate_code-1);
1619
b95cdbfc2d16 dont skip too many bytes if tag is TAG_STREAMHEAD2 and mp3
bcoudurier
parents: 1519
diff changeset
820 if (len > 4)
325
e1d4300bf783 SWF sanity check patch by (Glyn Kennington <glyn dot kennington at ox dot compsoc dot net>)
michael
parents: 277
diff changeset
821 url_fskip(pb,len-4);
5
39c4c4336486 cleanup
michaelni
parents: 0
diff changeset
822
1640
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
823 } else if (tag == TAG_JPEG2 && !vst) {
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
824 vst = av_new_stream(s, -2); /* -2 to avoid clash with video stream and audio stream */
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
825 av_set_pts_info(vst, 24, 1, 1000); /* 24 bit pts in ms */
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
826 vst->codec->codec_type = CODEC_TYPE_VIDEO;
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
827 vst->codec->codec_id = CODEC_ID_MJPEG;
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
828 if (swf->samples_per_frame) {
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
829 vst->codec->time_base.den = 1000. / swf->ms_per_frame;
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
830 vst->codec->time_base.num = 1;
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
831 }
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
832 url_fskip(pb, len);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
833 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
834 url_fskip(pb, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
835 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
836 }
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
837 url_fseek(pb, firstTagOff, SEEK_SET);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
838
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
839 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
840 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
841
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
842 static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
843 {
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
844 SWFContext *swf = s->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
845 ByteIOContext *pb = &s->pb;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
846 AVStream *st = 0;
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
847 int tag, len, i, frame;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
848
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
849 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
850 tag = get_swf_tag(pb, &len);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
851 if (tag < 0)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 468
diff changeset
852 return AVERROR_IO;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
853 if (tag == TAG_VIDEOFRAME) {
1637
50bbf9658436 use ch_id as AVStream id and simplify
bcoudurier
parents: 1636
diff changeset
854 int ch_id = get_le16(pb);
1639
4740223bfd8e simplify
bcoudurier
parents: 1638
diff changeset
855 len -= 2;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
856 for( i=0; i<s->nb_streams; i++ ) {
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
857 st = s->streams[i];
1637
50bbf9658436 use ch_id as AVStream id and simplify
bcoudurier
parents: 1636
diff changeset
858 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
859 frame = get_le16(pb);
1639
4740223bfd8e simplify
bcoudurier
parents: 1638
diff changeset
860 av_get_packet(pb, pkt, len-2);
1637
50bbf9658436 use ch_id as AVStream id and simplify
bcoudurier
parents: 1636
diff changeset
861 pkt->pts = frame * swf->ms_per_frame;
50bbf9658436 use ch_id as AVStream id and simplify
bcoudurier
parents: 1636
diff changeset
862 pkt->stream_index = st->index;
50bbf9658436 use ch_id as AVStream id and simplify
bcoudurier
parents: 1636
diff changeset
863 return pkt->size;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
864 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
865 }
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
866 } else if (tag == TAG_STREAMBLOCK) {
1638
0c6b7ac24cd7 swf can contain only one audio track, simplify
bcoudurier
parents: 1637
diff changeset
867 st = s->streams[swf->audio_stream_index];
0c6b7ac24cd7 swf can contain only one audio track, simplify
bcoudurier
parents: 1637
diff changeset
868 if (st->codec->codec_id == CODEC_ID_MP3) {
0c6b7ac24cd7 swf can contain only one audio track, simplify
bcoudurier
parents: 1637
diff changeset
869 url_fskip(pb, 4);
0c6b7ac24cd7 swf can contain only one audio track, simplify
bcoudurier
parents: 1637
diff changeset
870 av_get_packet(pb, pkt, len-4);
0c6b7ac24cd7 swf can contain only one audio track, simplify
bcoudurier
parents: 1637
diff changeset
871 pkt->stream_index = st->index;
0c6b7ac24cd7 swf can contain only one audio track, simplify
bcoudurier
parents: 1637
diff changeset
872 return pkt->size;
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
873 }
1640
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
874 } else if (tag == TAG_JPEG2) {
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
875 for (i=0; i<s->nb_streams; i++) {
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
876 st = s->streams[i];
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
877 if (st->id == -2) {
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
878 get_le16(pb); /* BITMAP_ID */
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
879 av_new_packet(pkt, len-2);
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
880 get_buffer(pb, pkt->data, 4);
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1643
diff changeset
881 if (AV_RB32(pkt->data) == 0xffd8ffd9) {
1640
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
882 /* old SWF files containing SOI/EOI as data start */
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
883 pkt->size -= 4;
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
884 get_buffer(pb, pkt->data, pkt->size);
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
885 } else {
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
886 get_buffer(pb, pkt->data + 4, pkt->size - 4);
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
887 }
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
888 pkt->stream_index = st->index;
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
889 return pkt->size;
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
890 }
ec1236a03504 enable mjpeg in swf
bcoudurier
parents: 1639
diff changeset
891 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
892 }
1639
4740223bfd8e simplify
bcoudurier
parents: 1638
diff changeset
893 url_fskip(pb, len);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
894 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
895 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
896 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
897
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
898 static int swf_read_close(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
899 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
900 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
901 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
902
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
903 #ifdef CONFIG_SWF_DEMUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
904 AVInputFormat swf_demuxer = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
905 "swf",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
906 "Flash format",
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
907 sizeof(SWFContext),
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
908 swf_probe,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
909 swf_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
910 swf_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
911 swf_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
912 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
913 #endif
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
914 #ifdef CONFIG_SWF_MUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
915 AVOutputFormat swf_muxer = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
916 "swf",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
917 "Flash format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
918 "application/x-shockwave-flash",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
919 "swf",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
920 sizeof(SWFContext),
359
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
921 CODEC_ID_MP3,
e9232aa21976 - made --extra-cflags option work on darwin
michael
parents: 325
diff changeset
922 CODEC_ID_FLV1,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
923 swf_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
924 swf_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
925 swf_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
926 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
927 #endif