annotate swf.c @ 517:543990301444 libavformat

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