annotate flashsv.c @ 9476:2b2bac59038e libavcodec

Remove 2 useless assignments from ff_rate_control_init() found by CSA.
author michael
date Fri, 17 Apr 2009 17:52:58 +0000
parents 0dce4fe6e6f3
children 38cfe222e1a4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
1 /*
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
2 * Flash Screen Video decoder
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
3 * Copyright (C) 2004 Alex Beregszaszi
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
4 * Copyright (C) 2006 Benjamin Larsson
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
5 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3329
diff changeset
6 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3329
diff changeset
7 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3329
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3329
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
12 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3329
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
16 * Lesser General Public License for more details.
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
17 *
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3329
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
21 */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
22
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
23 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 8210
diff changeset
24 * @file libavcodec/flashsv.c
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
25 * Flash Screen Video decoder
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
26 * @author Alex Beregszaszi
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
27 * @author Benjamin Larsson
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
28 */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
29
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
30 /* Bitstream description
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
31 * The picture is divided into blocks that are zlib compressed.
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
32 *
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
33 * The decoder is fed complete frames, the frameheader contains:
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
34 * 4bits of block width
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
35 * 12bits of frame width
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
36 * 4bits of block height
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
37 * 12bits of frame height
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
38 *
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
39 * Directly after the header are the compressed blocks. The blocks
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
40 * have their compressed size represented with 16bits in the beginnig.
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
41 * If the size = 0 then the block is unchanged from the previous frame.
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
42 * All blocks are decompressed until the buffer is consumed.
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
43 *
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
44 * Encoding ideas, a basic encoder would just use a fixed block size.
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
45 * Block sizes can be multipels of 16, from 16 to 256. The blocks don't
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
46 * have to be quadratic. A brute force search with a set of diffrent
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
47 * block sizes should give a better result then to just use a fixed size.
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
48 */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
49
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
50 #include <stdio.h>
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
51 #include <stdlib.h>
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
52
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
53 #include "avcodec.h"
9428
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents: 9355
diff changeset
54 #include "get_bits.h"
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
55
4372
9abacee8d312 Really fix my never ending mistakes.
banan
parents: 4371
diff changeset
56 #include <zlib.h>
9abacee8d312 Really fix my never ending mistakes.
banan
parents: 4371
diff changeset
57
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
58 typedef struct FlashSVContext {
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
59 AVCodecContext *avctx;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
60 AVFrame frame;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
61 int image_width, image_height;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
62 int block_width, block_height;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
63 uint8_t* tmpblock;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
64 int block_size;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
65 z_stream zstream;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
66 } FlashSVContext;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
67
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
68
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
69 static void copy_region(uint8_t *sptr, uint8_t *dptr,
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
70 int dx, int dy, int h, int w, int stride)
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
71 {
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
72 int i;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
73
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
74 for (i = dx+h; i > dx; i--)
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
75 {
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
76 memcpy(dptr+(i*stride)+dy*3, sptr, w*3);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
77 sptr += w*3;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
78 }
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
79 }
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
80
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
81
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6236
diff changeset
82 static av_cold int flashsv_decode_init(AVCodecContext *avctx)
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
83 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4801
diff changeset
84 FlashSVContext *s = avctx->priv_data;
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
85 int zret; // Zlib return code
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
86
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
87 s->avctx = avctx;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
88 s->zstream.zalloc = Z_NULL;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
89 s->zstream.zfree = Z_NULL;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
90 s->zstream.opaque = Z_NULL;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
91 zret = inflateInit(&(s->zstream));
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
92 if (zret != Z_OK) {
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
93 av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
94 return 1;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
95 }
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
96 avctx->pix_fmt = PIX_FMT_BGR24;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
97 s->frame.data[0] = NULL;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
98
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
99 return 0;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
100 }
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
101
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
102
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
103 static int flashsv_decode_frame(AVCodecContext *avctx,
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
104 void *data, int *data_size,
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
105 AVPacket *avpkt)
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
106 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
107 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
108 int buf_size = avpkt->size;
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4801
diff changeset
109 FlashSVContext *s = avctx->priv_data;
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
110 int h_blocks, v_blocks, h_part, v_part, i, j;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
111 GetBitContext gb;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
112
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
113 /* no supplementary picture */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
114 if (buf_size == 0)
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
115 return 0;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
116
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
117 if(s->frame.data[0])
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
118 avctx->release_buffer(avctx, &s->frame);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
119
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
120 init_get_bits(&gb, buf, buf_size * 8);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
121
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
122 /* start to parse the bitstream */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
123 s->block_width = 16* (get_bits(&gb, 4)+1);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
124 s->image_width = get_bits(&gb,12);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
125 s->block_height= 16* (get_bits(&gb, 4)+1);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
126 s->image_height= get_bits(&gb,12);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
127
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
128 /* calculate amount of blocks and the size of the border blocks */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
129 h_blocks = s->image_width / s->block_width;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
130 h_part = s->image_width % s->block_width;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
131 v_blocks = s->image_height / s->block_height;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
132 v_part = s->image_height % s->block_height;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
133
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
134 /* the block size could change between frames, make sure the buffer
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
135 * is large enough, if not, get a larger one */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
136 if(s->block_size < s->block_width*s->block_height) {
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
137 if (s->tmpblock != NULL)
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
138 av_free(s->tmpblock);
4370
e6eb67453d94 The block_size might be used incorrectly if it is not updated.
banan
parents: 4367
diff changeset
139 if ((s->tmpblock = av_malloc(3*s->block_width*s->block_height)) == NULL) {
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
140 av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
141 return -1;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
142 }
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
143 }
4370
e6eb67453d94 The block_size might be used incorrectly if it is not updated.
banan
parents: 4367
diff changeset
144 s->block_size = s->block_width*s->block_height;
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
145
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
146 /* init the image size once */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
147 if((avctx->width==0) && (avctx->height==0)){
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
148 avctx->width = s->image_width;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
149 avctx->height = s->image_height;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
150 }
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
151
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
152 /* check for changes of image width and image height */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
153 if ((avctx->width != s->image_width) || (avctx->height != s->image_height)) {
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
154 av_log(avctx, AV_LOG_ERROR, "Frame width or height differs from first frames!\n");
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
155 av_log(avctx, AV_LOG_ERROR, "fh = %d, fv %d vs ch = %d, cv = %d\n",avctx->height,
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
156 avctx->width,s->image_height,s->image_width);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
157 return -1;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
158 }
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
159
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
160 av_log(avctx, AV_LOG_DEBUG, "image: %dx%d block: %dx%d num: %dx%d part: %dx%d\n",
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
161 s->image_width, s->image_height, s->block_width, s->block_height,
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
162 h_blocks, v_blocks, h_part, v_part);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
163
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
164 s->frame.reference = 1;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
165 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
166 if (avctx->get_buffer(avctx, &s->frame) < 0) {
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
167 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
168 return -1;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
169 }
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
170
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
171 /* loop over all block columns */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
172 for (j = 0; j < v_blocks + (v_part?1:0); j++)
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
173 {
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
174
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
175 int hp = j*s->block_height; // horiz position in frame
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
176 int hs = (j<v_blocks)?s->block_height:v_part; // size of block
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
177
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
178
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
179 /* loop over all block rows */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
180 for (i = 0; i < h_blocks + (h_part?1:0); i++)
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
181 {
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
182 int wp = i*s->block_width; // vert position in frame
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
183 int ws = (i<h_blocks)?s->block_width:h_part; // size of block
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
184
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
185 /* get the size of the compressed zlib chunk */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
186 int size = get_bits(&gb, 16);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
187
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
188 if (size == 0) {
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
189 /* no change, don't do anything */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
190 } else {
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
191 /* decompress block */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
192 int ret = inflateReset(&(s->zstream));
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
193 if (ret != Z_OK)
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
194 {
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
195 av_log(avctx, AV_LOG_ERROR, "error in decompression (reset) of block %dx%d\n", i, j);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
196 /* return -1; */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
197 }
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
198 s->zstream.next_in = buf+(get_bits_count(&gb)/8);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
199 s->zstream.avail_in = size;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
200 s->zstream.next_out = s->tmpblock;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
201 s->zstream.avail_out = s->block_size*3;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
202 ret = inflate(&(s->zstream), Z_FINISH);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
203 if (ret == Z_DATA_ERROR)
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
204 {
6524
01647ac078a7 typo: occured --> occurred
diego
parents: 6517
diff changeset
205 av_log(avctx, AV_LOG_ERROR, "Zlib resync occurred\n");
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
206 inflateSync(&(s->zstream));
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
207 ret = inflate(&(s->zstream), Z_FINISH);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
208 }
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
209
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
210 if ((ret != Z_OK) && (ret != Z_STREAM_END))
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
211 {
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
212 av_log(avctx, AV_LOG_ERROR, "error in decompression of block %dx%d: %d\n", i, j, ret);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
213 /* return -1; */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
214 }
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
215 copy_region(s->tmpblock, s->frame.data[0], s->image_height-(hp+hs+1), wp, hs, ws, s->frame.linesize[0]);
8210
e1f9d8919cb5 flashsv: use skip_bits_long() where required
mru
parents: 7040
diff changeset
216 skip_bits_long(&gb, 8*size); /* skip the consumed bits */
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
217 }
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
218 }
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
219 }
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
220
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
221 *data_size = sizeof(AVFrame);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
222 *(AVFrame*)data = s->frame;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
223
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
224 if ((get_bits_count(&gb)/8) != buf_size)
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
225 av_log(avctx, AV_LOG_ERROR, "buffer not fully consumed (%d != %d)\n",
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
226 buf_size, (get_bits_count(&gb)/8));
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
227
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
228 /* report that the buffer was completely consumed */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
229 return buf_size;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
230 }
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
231
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
232
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6236
diff changeset
233 static av_cold int flashsv_decode_end(AVCodecContext *avctx)
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
234 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4801
diff changeset
235 FlashSVContext *s = avctx->priv_data;
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
236 inflateEnd(&(s->zstream));
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
237 /* release the frame if needed */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
238 if (s->frame.data[0])
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
239 avctx->release_buffer(avctx, &s->frame);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
240
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
241 /* free the tmpblock */
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
242 if (s->tmpblock != NULL)
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
243 av_free(s->tmpblock);
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
244
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
245 return 0;
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
246 }
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
247
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
248
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
249 AVCodec flashsv_decoder = {
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
250 "flashsv",
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
251 CODEC_TYPE_VIDEO,
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
252 CODEC_ID_FLASHSV,
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
253 sizeof(FlashSVContext),
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
254 flashsv_decode_init,
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
255 NULL,
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
256 flashsv_decode_end,
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
257 flashsv_decode_frame,
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
258 CODEC_CAP_DR1,
6788
e1302edb0f69 Replace some occurrences of -1 with PIX_FMT_NONE.
cehoyos
parents: 6731
diff changeset
259 .pix_fmts = (enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_NONE},
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6788
diff changeset
260 .long_name = NULL_IF_CONFIG_SMALL("Flash Screen Video v1"),
3329
726ab1038351 Flash Screen Video decoder (fourcc:FSV1)
banan
parents:
diff changeset
261 };