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
39
43 #if CONFIG_ZLIB
44 #define ZBUF_SIZE 4096
46 uint8_t *zbuf_in;
47 uint8_t *zbuf_out;
48 z_stream zstream;
49 #endif
51
59 };
60
62 {
64
67
73 }
76 }
77
78
80 {
82 int len, xmin, xmax, ymin, ymax;
83
85 return 0;
86
87 /* check file header */
90 return 0;
91
95
97 return 0;
98
101 return 0;
106 if (xmin || ymin || !xmax || !ymax)
107 return 0;
108
109 if (
p->buf[3] >= 20 || xmax < 16 || ymax < 16)
111
113 }
114
115 #if CONFIG_ZLIB
116 static int zlib_refill(void *opaque, uint8_t *buf, int buf_size)
117 {
120 z_stream *z = &swf->zstream;
122
123 retry:
124 if (!z->avail_in) {
125 int n =
avio_read(
s->pb, swf->zbuf_in, ZBUF_SIZE);
126 if (n < 0)
127 return n;
128 z->next_in = swf->zbuf_in;
129 z->avail_in = n;
130 }
131
132 z->next_out = buf;
133 z->avail_out = buf_size;
134
136 if (
ret == Z_STREAM_END)
140
141 if (buf_size - z->avail_out == 0)
142 goto retry;
143
144 return buf_size - z->avail_out;
145 }
146
148 #endif
149
151 {
155
158
161 #if CONFIG_ZLIB
162 if (inflateInit(&swf->zstream) != Z_OK) {
165 }
166 if (!(swf->zbuf_in =
av_malloc(ZBUF_SIZE)) ||
167 !(swf->zbuf_out =
av_malloc(ZBUF_SIZE)) ||
172 }
173 swf->zpb->seekable = 0;
174 pb = swf->zpb;
175 #else
178 #endif
181 /* skip rectangle size */
183 len = (4 * nbits - 3 + 7) / 8;
187
190 return 0;
191 }
192
194 {
195 int sample_rate_code, sample_size_code;
197 if (!ast)
204 sample_rate_code =
info>>2 & 3;
205 sample_size_code =
info>>1 & 1;
210 return ast;
211 }
212
214 {
219
220 #if CONFIG_ZLIB
221 if (swf->zpb)
222 pb = swf->zpb;
223 #endif
224
225 for(;;) {
233 }
237
238 for (
i=0;
i<
s->nb_streams;
i++) {
242 }
243
248 /* Check for FLV1 */
250 if (!vst)
258 /* streaming found */
259
260 for (
i=0;
i<
s->nb_streams;
i++) {
264 }
265
270 if (!ast)
274 /* audio stream */
276
277 for (
i=0;
i<
s->nb_streams;
i++) {
281 }
282
283 // FIXME: The entire audio stream is stored in a single chunk/tag. Normally,
284 // these are smaller audio streams in DEFINESOUND tags, but it's technically
285 // possible they could be huge. Break it up into multiple packets if it's big.
288 if (!ast)
290 ast->duration =
avio_rl32(pb);
// number of samples
291 if (((v>>4) & 15) == 2) { // MP3 sound data record
294 }
297 return res;
304 for(
i=0;
i<
s->nb_streams;
i++) {
307 int pkt_flags = 0;
318 }
320 return res;
326 }
327 }
329 #if CONFIG_ZLIB
330 long out_len;
331 uint8_t *buf =
NULL, *zbuf =
NULL, *pal;
334 const int colormapbpp = 3 + alpha_bmp;
335 int linesize, colormapsize = 0;
336
338 const int bmp_fmt =
avio_r8(pb);
342
344
345 switch (bmp_fmt) {
346 case 3: // PAL-8
348 colormapsize =
avio_r8(pb) + 1;
350 break;
351 case 4: // RGB15
352 linesize =
width * 2;
353 break;
354 case 5: // RGB24 (0RGB)
355 linesize =
width * 4;
356 break;
357 default:
359 goto bitmap_end_skip;
360 }
361
362 linesize =
FFALIGN(linesize, 4);
363
365 linesize >= INT_MAX /
height ||
366 linesize *
height >= INT_MAX - colormapsize * colormapbpp) {
368 goto bitmap_end_skip;
369 }
370
371 out_len = colormapsize * colormapbpp + linesize *
height;
372
373 ff_dlog(
s,
"bitmap: ch=%d fmt=%d %dx%d (linesize=%d) len=%d->%ld pal=%d\n",
374 ch_id, bmp_fmt,
width,
height, linesize,
len, out_len, colormapsize);
375
376 if (
len * 17373LL < out_len)
377 goto bitmap_end_skip;
378
380 if (!zbuf) {
382 goto bitmap_end;
383 }
384
387 goto bitmap_end_skip;
388
390 if (!buf) {
392 goto bitmap_end;
393 }
394 if ((res = uncompress(buf, &out_len, zbuf,
len)) != Z_OK) {
396 goto bitmap_end_skip;
397 }
398
399 for (
i = 0;
i <
s->nb_streams;
i++) {
402 break;
403 }
404 if (
i ==
s->nb_streams) {
406 if (!vst) {
408 goto bitmap_end;
409 }
410 vst->
id = -3;
/* -3 to avoid clash with video stream and audio stream */
414 st = vst;
415 }
416
418 goto bitmap_end;
419 if (!st->codecpar->width && !st->codecpar->height) {
421 st->codecpar->height =
height;
422 } else {
424 }
427
430 goto bitmap_end;
431 }
432
433 switch (bmp_fmt) {
434 case 3:
436 for (
i = 0;
i < colormapsize;
i++)
437 if (alpha_bmp) colormap[
i] = buf[3]<<24 |
AV_RB24(buf + 4*
i);
438 else colormap[
i] = 0xff
U <<24 |
AV_RB24(buf + 3*
i);
440 if (!pal) {
442 goto bitmap_end;
443 }
445 break;
446 case 4:
448 break;
449 case 5:
451 break;
452 default:
454 }
457 } else
458 st->codecpar->format =
pix_fmt;
459
460 memcpy(
pkt->
data, buf + colormapsize*colormapbpp, linesize *
height);
461
463
464 bitmap_end:
467 return res;
468 bitmap_end_skip:
471 #else
473 #endif
475 for (
i = 0;
i <
s->nb_streams;
i++) {
484 return res;
485 } else { // ADPCM, PCM
489 return res;
490 }
494 }
495 }
497 for (
i=0;
i<
s->nb_streams;
i++) {
500 break;
501 }
502 if (
i ==
s->nb_streams) {
504 if (!vst)
506 vst->
id = -2;
/* -2 to avoid clash with video stream and audio stream */
510 st = vst;
511 }
517 return res;
520 }
523 /* old SWF files containing SOI/EOI as data start */
524 /* files created by swink have reversed tag */
528 } else {
530 if (res >= 0)
531 res += 4;
532 }
534 if (res < 0) {
535 return res;
536 }
538 }
539
543 } else {
545 }
551 }
552 }
553
554 #if CONFIG_ZLIB
556 {
558 inflateEnd(&
s->zstream);
562 return 0;
563 }
564 #endif
565
573 #if CONFIG_ZLIB
575 #endif
576 };
#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
enum AVMediaType codec_type
General type of the encoded data.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#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.
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, const 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 const AVCodecTag swf_audio_codec_tags[]
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
@ AV_PKT_DATA_PALETTE
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.
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 read_packet(void *opaque, uint8_t *buf, int buf_size)
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[]
static enum AVPixelFormat pix_fmt
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define FLV_VIDEO_FRAMETYPE_MASK
enum AVStreamParseType need_parsing
AVCodecParameters * codecpar
Codec parameters associated with this stream.
This structure contains the data a format has to probe a file.
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.
static int read_header(FFV1Context *f, RangeCoder *c)
@ TAG_DEFINEBITSLOSSLESS2
#define AV_LOG_INFO
Standard information.
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
#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
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.
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
@ FLV_FRAME_KEY
key frame (for AVC, a seekable 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)
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
const FFInputFormat ff_swf_demuxer
static int read_probe(const AVProbeData *p)
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
@ 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.
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Generated on Fri Oct 17 2025 19:23:32 for FFmpeg by
doxygen
1.8.17