FFmpeg: libavformat/swfdec.c Source File
Go to the documentation of this file. 1 /*
2 * Flash Compatible Streaming Format demuxer
3 * Copyright (c) 2000 Fabrice Bellard
4 * Copyright (c) 2003 Tinic Uro
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "config.h"
24
25 #if CONFIG_ZLIB
26 #include <zlib.h>
27 #endif
28
38
42 #if CONFIG_ZLIB
43 #define ZBUF_SIZE 4096
45 uint8_t *zbuf_in;
46 uint8_t *zbuf_out;
47 z_stream zstream;
48 #endif
50
58 };
59
61 {
63
66
72 }
75 }
76
77
79 {
81 int len, xmin, xmax, ymin, ymax;
82
84 return 0;
85
86 /* check file header */
89 return 0;
90
94
96 return 0;
97
100 return 0;
105 if (xmin || ymin || !xmax || !ymax)
106 return 0;
107
108 if (p->
buf[3] >= 20 || xmax < 16 || ymax < 16)
110
112 }
113
114 #if CONFIG_ZLIB
115 static int zlib_refill(void *opaque, uint8_t *buf, int buf_size)
116 {
119 z_stream *z = &swf->zstream;
121
122 retry:
123 if (!z->avail_in) {
124 int n =
avio_read(
s->pb, swf->zbuf_in, ZBUF_SIZE);
125 if (n < 0)
126 return n;
127 z->next_in = swf->zbuf_in;
128 z->avail_in = n;
129 }
130
131 z->next_out = buf;
132 z->avail_out = buf_size;
133
135 if (
ret == Z_STREAM_END)
139
140 if (buf_size - z->avail_out == 0)
141 goto retry;
142
143 return buf_size - z->avail_out;
144 }
145
147 #endif
148
150 {
154
157
160 #if CONFIG_ZLIB
161 if (inflateInit(&swf->zstream) != Z_OK) {
164 }
165 if (!(swf->zbuf_in =
av_malloc(ZBUF_SIZE)) ||
166 !(swf->zbuf_out =
av_malloc(ZBUF_SIZE)) ||
171 }
172 swf->zpb->seekable = 0;
173 pb = swf->zpb;
174 #else
177 #endif
180 /* skip rectangle size */
182 len = (4 * nbits - 3 + 7) / 8;
186
189 return 0;
190 }
191
193 {
194 int sample_rate_code, sample_size_code;
196 if (!ast)
203 sample_rate_code =
info>>2 & 3;
204 sample_size_code =
info>>1 & 1;
209 return ast;
210 }
211
213 {
218
219 #if CONFIG_ZLIB
220 if (swf->zpb)
221 pb = swf->zpb;
222 #endif
223
224 for(;;) {
232 }
236
237 for (
i=0;
i<
s->nb_streams;
i++) {
240 goto skip;
241 }
242
247 /* Check for FLV1 */
249 if (!vst)
257 /* streaming found */
258
259 for (
i=0;
i<
s->nb_streams;
i++) {
262 goto skip;
263 }
264
269 if (!ast)
273 /* audio stream */
275
276 for (
i=0;
i<
s->nb_streams;
i++) {
279 goto skip;
280 }
281
282 // FIXME: The entire audio stream is stored in a single chunk/tag. Normally,
283 // these are smaller audio streams in DEFINESOUND tags, but it's technically
284 // possible they could be huge. Break it up into multiple packets if it's big.
287 if (!ast)
289 ast->duration =
avio_rl32(pb);
// number of samples
290 if (((v>>4) & 15) == 2) { // MP3 sound data record
293 }
296 return res;
303 for(
i=0;
i<
s->nb_streams;
i++) {
306 int pkt_flags = 0;
310 goto skip;
315 goto skip;
317 }
319 return res;
325 }
326 }
328 #if CONFIG_ZLIB
329 long out_len;
330 uint8_t *buf =
NULL, *zbuf =
NULL, *pal;
333 const int colormapbpp = 3 + alpha_bmp;
334 int linesize, colormapsize = 0;
335
337 const int bmp_fmt =
avio_r8(pb);
341
343
344 switch (bmp_fmt) {
345 case 3: // PAL-8
347 colormapsize =
avio_r8(pb) + 1;
349 break;
350 case 4: // RGB15
351 linesize =
width * 2;
352 break;
353 case 5: // RGB24 (0RGB)
354 linesize =
width * 4;
355 break;
356 default:
358 goto bitmap_end_skip;
359 }
360
361 linesize =
FFALIGN(linesize, 4);
362
364 linesize >= INT_MAX /
height ||
365 linesize *
height >= INT_MAX - colormapsize * colormapbpp) {
367 goto bitmap_end_skip;
368 }
369
370 out_len = colormapsize * colormapbpp + linesize *
height;
371
372 ff_dlog(
s,
"bitmap: ch=%d fmt=%d %dx%d (linesize=%d) len=%d->%ld pal=%d\n",
373 ch_id, bmp_fmt,
width,
height, linesize,
len, out_len, colormapsize);
374
375 if (
len * 17373LL < out_len)
376 goto bitmap_end_skip;
377
379 if (!zbuf) {
381 goto bitmap_end;
382 }
383
386 goto bitmap_end_skip;
387
389 if (!buf) {
391 goto bitmap_end;
392 }
393 if ((res = uncompress(buf, &out_len, zbuf,
len)) != Z_OK) {
395 goto bitmap_end_skip;
396 }
397
398 for (
i = 0;
i <
s->nb_streams;
i++) {
401 break;
402 }
403 if (
i ==
s->nb_streams) {
405 if (!vst) {
407 goto bitmap_end;
408 }
409 vst->
id = -3;
/* -3 to avoid clash with video stream and audio stream */
413 st = vst;
414 }
415
417 goto bitmap_end;
418 if (!st->codecpar->width && !st->codecpar->height) {
420 st->codecpar->height =
height;
421 } else {
423 }
426
429 goto bitmap_end;
430 }
431
432 switch (bmp_fmt) {
433 case 3:
435 for (
i = 0;
i < colormapsize;
i++)
436 if (alpha_bmp) colormap[
i] = buf[3]<<24 |
AV_RB24(buf + 4*
i);
437 else colormap[
i] = 0xff
U <<24 |
AV_RB24(buf + 3*
i);
439 if (!pal) {
441 goto bitmap_end;
442 }
444 break;
445 case 4:
447 break;
448 case 5:
450 break;
451 default:
453 }
456 } else
457 st->codecpar->format =
pix_fmt;
458
459 memcpy(
pkt->
data, buf + colormapsize*colormapbpp, linesize *
height);
460
462
463 bitmap_end:
466 return res;
467 bitmap_end_skip:
470 #else
472 #endif
474 for (
i = 0;
i <
s->nb_streams;
i++) {
481 goto skip;
483 return res;
484 } else { // ADPCM, PCM
486 goto skip;
488 return res;
489 }
493 }
494 }
496 for (
i=0;
i<
s->nb_streams;
i++) {
499 break;
500 }
501 if (
i ==
s->nb_streams) {
503 if (!vst)
505 vst->
id = -2;
/* -2 to avoid clash with video stream and audio stream */
509 st = vst;
510 }
514 goto skip;
516 return res;
519 }
522 /* old SWF files containing SOI/EOI as data start */
523 /* files created by swink have reversed tag */
527 } else {
529 if (res >= 0)
530 res += 4;
531 }
533 if (res < 0) {
534 return res;
535 }
537 }
538
542 } else {
544 }
545 skip:
550 }
551 }
552
553 #if CONFIG_ZLIB
555 {
557 inflateEnd(&
s->zstream);
561 return 0;
562 }
563 #endif
564
572 #if CONFIG_ZLIB
574 #endif
575 };
#define AV_LOG_WARNING
Something somehow does not look correct.
int skip_samples
Number of samples to skip at the start of the frame decoded from the next packet.
static int swf_read_header(AVFormatContext *s)
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
enum AVMediaType codec_type
General type of the encoded data.
#define AVERROR_EOF
End of file.
void avio_context_free(AVIOContext **s)
Free the supplied IO context and everything associated with it.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
@ AV_PKT_DATA_PALETTE
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.
@ FLV_FRAME_KEY
key frame (for AVC, a seekable frame)
static const AVCodecTag swf_audio_codec_tags[]
int buf_size
Size of buf except extra allocated bytes.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
static void inflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord, int maxc)
static av_cold int read_close(AVFormatContext *ctx)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
unsigned int avio_rl16(AVIOContext *s)
unsigned int avio_rb32(AVIOContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
const AVCodecTag ff_swf_codec_tags[]
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static enum AVPixelFormat pix_fmt
#define FLV_VIDEO_FRAMETYPE_MASK
enum AVStreamParseType need_parsing
AVCodecParameters * codecpar
Codec parameters associated with this stream.
static int read_header(FFV1Context *f)
This structure contains the data a format has to probe a file.
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
AVChannelLayout ch_layout
Audio only.
int sample_rate
Audio only.
unsigned int avio_rl32(AVIOContext *s)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int ff_add_param_change(AVPacket *pkt, int32_t channels, uint64_t channel_layout, int32_t sample_rate, int32_t width, int32_t height)
Add side data to a packet for changing parameters to the given values.
static int get_swf_tag(AVIOContext *pb, int *len_ptr)
#define MKBETAG(a, b, c, d)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
int avio_r8(AVIOContext *s)
int flags
A combination of AV_PKT_FLAG values.
#define AV_LOG_INFO
Standard information.
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_PIX_FMT_RGB555
AVIOContext * avio_alloc_context(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Allocate and initialize an AVIOContext for buffered I/O.
static int swf_probe(const AVProbeData *p)
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
int id
Format-specific stream ID.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static AVStream * create_new_audio_stream(AVFormatContext *s, int id, int info)
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
@ TAG_DEFINEBITSLOSSLESS2
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
int64_t pos
byte position in stream, -1 if unknown
const AVInputFormat ff_swf_demuxer
#define flags(name, subs,...)
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
void * priv_data
Format private data.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Generated on Wed Aug 24 2022 21:42:20 for FFmpeg by
doxygen
1.8.17