svq3.c 46.8 KB
Newer Older
M
Michael Niedermayer 已提交
1
/*
2
 * Copyright (c) 2003 The Libav Project
M
Michael Niedermayer 已提交
3
 *
4
 * This file is part of Libav.
5
 *
6
 * Libav is free software; you can redistribute it and/or
M
Michael Niedermayer 已提交
7 8
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
M
Michael Niedermayer 已提交
10
 *
11
 * Libav is distributed in the hope that it will be useful,
M
Michael Niedermayer 已提交
12 13 14 15 16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with Libav; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 20 21
 */

/*
M
Michael Niedermayer 已提交
22 23
 * How to use this decoder:
 * SVQ3 data is transported within Apple Quicktime files. Quicktime files
24 25 26 27 28 29
 * have stsd atoms to describe media trak properties. A stsd atom for a
 * video trak contains 1 or more ImageDescription atoms. These atoms begin
 * with the 4-byte length of the atom followed by the codec fourcc. Some
 * decoders need information in this atom to operate correctly. Such
 * is the case with SVQ3. In order to get the best use out of this decoder,
 * the calling app must make the SVQ3 ImageDescription atom available
M
Michael Niedermayer 已提交
30 31
 * via the AVCodecContext's extradata[_size] field:
 *
32
 * AVCodecContext.extradata = pointer to ImageDescription, first characters
33
 * are expected to be 'S', 'V', 'Q', and '3', NOT the 4-byte atom length
34 35
 * AVCodecContext.extradata_size = size of ImageDescription atom memory
 * buffer (which will be the same as the ImageDescription atom size field
36 37 38 39
 * from the QT file, minus 4 bytes since the length is missing)
 *
 * You will know you have these parameters passed correctly when the decoder
 * correctly decodes this file:
40
 *  http://samples.libav.org/V-codecs/SVQ3/Vertical400kbit.sorenson3.mov
M
Michael Niedermayer 已提交
41
 */
42 43

#include "libavutil/attributes.h"
44 45 46 47 48
#include "internal.h"
#include "avcodec.h"
#include "mpegvideo.h"
#include "h264.h"

D
Diego Biurrun 已提交
49
#include "h264data.h" // FIXME FIXME FIXME
50

51
#include "h264_mvpred.h"
52
#include "golomb.h"
53
#include "hpeldsp.h"
54 55
#include "rectangle.h"

56
#if CONFIG_ZLIB
57 58 59
#include <zlib.h>
#endif

60
#include "svq1.h"
61
#include "svq3.h"
62

M
Michael Niedermayer 已提交
63
/**
64
 * @file
M
Michael Niedermayer 已提交
65 66 67
 * svq3 decoder.
 */

68 69
typedef struct {
    H264Context h;
70
    HpelDSPContext hdsp;
A
Anton Khirnov 已提交
71 72 73
    Picture *cur_pic;
    Picture *next_pic;
    Picture *last_pic;
74 75 76 77 78
    int halfpel_flag;
    int thirdpel_flag;
    int unknown_flag;
    int next_slice_index;
    uint32_t watermark_key;
A
Anton Khirnov 已提交
79 80 81 82 83
    int adaptive_quant;
    int next_p_frame_damaged;
    int h_edge_pos;
    int v_edge_pos;
    int last_frame_output;
84 85
} SVQ3Context;

86 87
#define FULLPEL_MODE  1
#define HALFPEL_MODE  2
M
Michael Niedermayer 已提交
88
#define THIRDPEL_MODE 3
89
#define PREDICT_MODE  4
90

M
Michael Niedermayer 已提交
91
/* dual scan (from some older h264 draft)
D
Diego Biurrun 已提交
92 93 94 95 96 97 98 99
 * o-->o-->o   o
 *         |  /|
 * o   o   o / o
 * | / |   |/  |
 * o   o   o   o
 *   /
 * o-->o-->o-->o
 */
100
static const uint8_t svq3_scan[16] = {
D
Diego Biurrun 已提交
101 102 103 104
    0 + 0 * 4, 1 + 0 * 4, 2 + 0 * 4, 2 + 1 * 4,
    2 + 2 * 4, 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4,
    0 + 1 * 4, 0 + 2 * 4, 1 + 1 * 4, 1 + 2 * 4,
    0 + 3 * 4, 1 + 3 * 4, 2 + 3 * 4, 3 + 3 * 4,
M
Michael Niedermayer 已提交
105 106 107
};

static const uint8_t svq3_pred_0[25][2] = {
108 109 110 111 112 113 114 115 116
    { 0, 0 },
    { 1, 0 }, { 0, 1 },
    { 0, 2 }, { 1, 1 }, { 2, 0 },
    { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 },
    { 0, 4 }, { 1, 3 }, { 2, 2 }, { 3, 1 }, { 4, 0 },
    { 4, 1 }, { 3, 2 }, { 2, 3 }, { 1, 4 },
    { 2, 4 }, { 3, 3 }, { 4, 2 },
    { 4, 3 }, { 3, 4 },
    { 4, 4 }
M
Michael Niedermayer 已提交
117 118 119
};

static const int8_t svq3_pred_1[6][6][5] = {
D
Diego Biurrun 已提交
120 121 122 123 124 125 126 127 128 129 130 131
    { { 2, -1, -1, -1, -1 }, { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 },
      { 2,  1, -1, -1, -1 }, { 1, 2, -1, -1, -1 }, { 1, 2, -1, -1, -1 } },
    { { 0,  2, -1, -1, -1 }, { 0, 2,  1,  4,  3 }, { 0, 1,  2,  4,  3 },
      { 0,  2,  1,  4,  3 }, { 2, 0,  1,  3,  4 }, { 0, 4,  2,  1,  3 } },
    { { 2,  0, -1, -1, -1 }, { 2, 1,  0,  4,  3 }, { 1, 2,  4,  0,  3 },
      { 2,  1,  0,  4,  3 }, { 2, 1,  4,  3,  0 }, { 1, 2,  4,  0,  3 } },
    { { 2,  0, -1, -1, -1 }, { 2, 0,  1,  4,  3 }, { 1, 2,  0,  4,  3 },
      { 2,  1,  0,  4,  3 }, { 2, 1,  3,  4,  0 }, { 2, 4,  1,  0,  3 } },
    { { 0,  2, -1, -1, -1 }, { 0, 2,  1,  3,  4 }, { 1, 2,  3,  0,  4 },
      { 2,  0,  1,  3,  4 }, { 2, 1,  3,  0,  4 }, { 2, 0,  4,  3,  1 } },
    { { 0,  2, -1, -1, -1 }, { 0, 2,  4,  1,  3 }, { 1, 4,  2,  0,  3 },
      { 4,  2,  0,  1,  3 }, { 2, 0,  1,  4,  3 }, { 4, 2,  1,  0,  3 } },
M
Michael Niedermayer 已提交
132 133
};

D
Diego Biurrun 已提交
134 135 136 137
static const struct {
    uint8_t run;
    uint8_t level;
} svq3_dct_tables[2][16] = {
138 139 140 141
    { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 },
      { 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } },
    { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
      { 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } }
M
Michael Niedermayer 已提交
142 143 144
};

static const uint32_t svq3_dequant_coeff[32] = {
D
Diego Biurrun 已提交
145 146 147 148
     3881,  4351,  4890,  5481,   6154,   6914,   7761,   8718,
     9781, 10987, 12339, 13828,  15523,  17435,  19561,  21873,
    24552, 27656, 30847, 34870,  38807,  43747,  49103,  54683,
    61694, 68745, 77615, 89113, 100253, 109366, 126635, 141533
M
Michael Niedermayer 已提交
149 150
};

D
Diego Biurrun 已提交
151
void ff_svq3_luma_dc_dequant_idct_c(int16_t *output, int16_t *input, int qp)
D
Diego Biurrun 已提交
152
{
153
    const int qmul = svq3_dequant_coeff[qp];
M
Michael Niedermayer 已提交
154 155 156
#define stride 16
    int i;
    int temp[16];
D
Diego Biurrun 已提交
157 158 159 160 161 162 163 164 165 166 167 168
    static const uint8_t x_offset[4] = { 0, 1 * stride, 4 * stride, 5 * stride };

    for (i = 0; i < 4; i++) {
        const int z0 = 13 * (input[4 * i + 0] +      input[4 * i + 2]);
        const int z1 = 13 * (input[4 * i + 0] -      input[4 * i + 2]);
        const int z2 =  7 *  input[4 * i + 1] - 17 * input[4 * i + 3];
        const int z3 = 17 *  input[4 * i + 1] +  7 * input[4 * i + 3];

        temp[4 * i + 0] = z0 + z3;
        temp[4 * i + 1] = z1 + z2;
        temp[4 * i + 2] = z1 - z2;
        temp[4 * i + 3] = z0 - z3;
M
Michael Niedermayer 已提交
169 170
    }

D
Diego Biurrun 已提交
171 172 173 174 175 176 177
    for (i = 0; i < 4; i++) {
        const int offset = x_offset[i];
        const int z0     = 13 * (temp[4 * 0 + i] +      temp[4 * 2 + i]);
        const int z1     = 13 * (temp[4 * 0 + i] -      temp[4 * 2 + i]);
        const int z2     =  7 *  temp[4 * 1 + i] - 17 * temp[4 * 3 + i];
        const int z3     = 17 *  temp[4 * 1 + i] +  7 * temp[4 * 3 + i];

178 179 180 181
        output[stride *  0 + offset] = (z0 + z3) * qmul + 0x80000 >> 20;
        output[stride *  2 + offset] = (z1 + z2) * qmul + 0x80000 >> 20;
        output[stride *  8 + offset] = (z1 - z2) * qmul + 0x80000 >> 20;
        output[stride * 10 + offset] = (z0 - z3) * qmul + 0x80000 >> 20;
M
Michael Niedermayer 已提交
182 183 184 185
    }
}
#undef stride

D
Diego Biurrun 已提交
186
void ff_svq3_add_idct_c(uint8_t *dst, int16_t *block,
D
Diego Biurrun 已提交
187
                        int stride, int qp, int dc)
188
{
189
    const int qmul = svq3_dequant_coeff[qp];
M
Michael Niedermayer 已提交
190 191 192
    int i;

    if (dc) {
193 194
        dc       = 13 * 13 * (dc == 1 ? 1538 * block[0]
                                      : qmul * (block[0] >> 3) / 2);
M
Michael Niedermayer 已提交
195 196 197
        block[0] = 0;
    }

198
    for (i = 0; i < 4; i++) {
D
Diego Biurrun 已提交
199 200 201 202 203 204 205 206 207
        const int z0 = 13 * (block[0 + 4 * i] +      block[2 + 4 * i]);
        const int z1 = 13 * (block[0 + 4 * i] -      block[2 + 4 * i]);
        const int z2 =  7 *  block[1 + 4 * i] - 17 * block[3 + 4 * i];
        const int z3 = 17 *  block[1 + 4 * i] +  7 * block[3 + 4 * i];

        block[0 + 4 * i] = z0 + z3;
        block[1 + 4 * i] = z1 + z2;
        block[2 + 4 * i] = z1 - z2;
        block[3 + 4 * i] = z0 - z3;
M
Michael Niedermayer 已提交
208 209
    }

210
    for (i = 0; i < 4; i++) {
D
Diego Biurrun 已提交
211 212 213 214
        const int z0 = 13 * (block[i + 4 * 0] +      block[i + 4 * 2]);
        const int z1 = 13 * (block[i + 4 * 0] -      block[i + 4 * 2]);
        const int z2 =  7 *  block[i + 4 * 1] - 17 * block[i + 4 * 3];
        const int z3 = 17 *  block[i + 4 * 1] +  7 * block[i + 4 * 3];
215 216
        const int rr = (dc + 0x80000);

217 218 219 220
        dst[i + stride * 0] = av_clip_uint8(dst[i + stride * 0] + ((z0 + z3) * qmul + rr >> 20));
        dst[i + stride * 1] = av_clip_uint8(dst[i + stride * 1] + ((z1 + z2) * qmul + rr >> 20));
        dst[i + stride * 2] = av_clip_uint8(dst[i + stride * 2] + ((z1 - z2) * qmul + rr >> 20));
        dst[i + stride * 3] = av_clip_uint8(dst[i + stride * 3] + ((z0 - z3) * qmul + rr >> 20));
M
Michael Niedermayer 已提交
221
    }
222 223

    memset(block, 0, 16 * sizeof(int16_t));
M
Michael Niedermayer 已提交
224 225
}

D
Diego Biurrun 已提交
226
static inline int svq3_decode_block(GetBitContext *gb, int16_t *block,
227 228
                                    int index, const int type)
{
229 230
    static const uint8_t *const scan_patterns[4] =
    { luma_dc_zigzag_scan, zigzag_scan, svq3_scan, chroma_dc_scan };
M
Michael Niedermayer 已提交
231

232 233
    int run, level, limit;
    unsigned vlc;
234
    const int intra           = 3 * type >> 2;
235
    const uint8_t *const scan = scan_patterns[type];
M
Michael Niedermayer 已提交
236

237 238
    for (limit = (16 >> intra); index < 16; index = limit, limit += 8) {
        for (; (vlc = svq3_get_ue_golomb(gb)) != 0; index++) {
239 240
            int sign = (vlc & 1) ? 0 : -1;
            vlc      = vlc + 1 >> 1;
D
Diego Biurrun 已提交
241 242 243 244 245 246 247 248 249

            if (type == 3) {
                if (vlc < 3) {
                    run   = 0;
                    level = vlc;
                } else if (vlc < 4) {
                    run   = 1;
                    level = 1;
                } else {
250 251
                    run   = vlc & 0x3;
                    level = (vlc + 9 >> 2) - run;
D
Diego Biurrun 已提交
252 253 254 255 256 257
                }
            } else {
                if (vlc < 16) {
                    run   = svq3_dct_tables[intra][vlc].run;
                    level = svq3_dct_tables[intra][vlc].level;
                } else if (intra) {
258
                    run   = vlc & 0x7;
D
Diego Biurrun 已提交
259 260 261
                    level = (vlc >> 3) +
                            ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));
                } else {
262
                    run   = vlc & 0xF;
D
Diego Biurrun 已提交
263 264 265 266
                    level = (vlc >> 4) +
                            ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0)));
                }
            }
M
Michael Niedermayer 已提交
267

D
Diego Biurrun 已提交
268 269 270 271
            if ((index += run) >= limit)
                return -1;

            block[scan[index]] = (level ^ sign) - sign;
272
        }
M
Michael Niedermayer 已提交
273

274 275 276
        if (type != 2) {
            break;
        }
M
Michael Niedermayer 已提交
277 278
    }

279
    return 0;
M
Michael Niedermayer 已提交
280 281
}

A
Anton Khirnov 已提交
282
static inline void svq3_mc_dir_part(SVQ3Context *s,
283 284 285 286
                                    int x, int y, int width, int height,
                                    int mx, int my, int dxy,
                                    int thirdpel, int dir, int avg)
{
A
Anton Khirnov 已提交
287 288
    H264Context *h     = &s->h;
    const Picture *pic = (dir == 0) ? s->last_pic : s->next_pic;
289 290
    uint8_t *src, *dest;
    int i, emu = 0;
D
Diego Biurrun 已提交
291
    int blocksize = 2 - (width >> 3); // 16->0, 8->1, 4->2
292 293 294

    mx += x;
    my += y;
M
Michael Niedermayer 已提交
295

296 297
    if (mx < 0 || mx >= s->h_edge_pos - width  - 1 ||
        my < 0 || my >= s->v_edge_pos - height - 1) {
298
        emu = 1;
299 300
        mx = av_clip(mx, -16, s->h_edge_pos - width  + 15);
        my = av_clip(my, -16, s->v_edge_pos - height + 15);
M
Michael Niedermayer 已提交
301 302
    }

303
    /* form component predictions */
A
Anton Khirnov 已提交
304 305
    dest = h->cur_pic.f.data[0] + x + y * h->linesize;
    src  = pic->f.data[0] + mx + my * h->linesize;
306 307

    if (emu) {
A
Anton Khirnov 已提交
308
        h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src, h->linesize,
R
Ronald S. Bultje 已提交
309 310
                                 width + 1, height + 1,
                                 mx, my, s->h_edge_pos, s->v_edge_pos);
A
Anton Khirnov 已提交
311
        src = h->edge_emu_buffer;
M
Michael Niedermayer 已提交
312
    }
313
    if (thirdpel)
A
Anton Khirnov 已提交
314 315
        (avg ? h->dsp.avg_tpel_pixels_tab
             : h->dsp.put_tpel_pixels_tab)[dxy](dest, src, h->linesize,
D
Diego Biurrun 已提交
316
                                                width, height);
317
    else
318 319 320
        (avg ? s->hdsp.avg_pixels_tab
             : s->hdsp.put_pixels_tab)[blocksize][dxy](dest, src, h->linesize,
                                                       height);
321

A
Anton Khirnov 已提交
322
    if (!(h->flags & CODEC_FLAG_GRAY)) {
323 324 325 326
        mx     = mx + (mx < (int) x) >> 1;
        my     = my + (my < (int) y) >> 1;
        width  = width  >> 1;
        height = height >> 1;
327 328 329
        blocksize++;

        for (i = 1; i < 3; i++) {
A
Anton Khirnov 已提交
330 331
            dest = h->cur_pic.f.data[i] + (x >> 1) + (y >> 1) * h->uvlinesize;
            src  = pic->f.data[i] + mx + my * h->uvlinesize;
332 333

            if (emu) {
A
Anton Khirnov 已提交
334
                h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src, h->uvlinesize,
R
Ronald S. Bultje 已提交
335 336 337
                                         width + 1, height + 1,
                                         mx, my, (s->h_edge_pos >> 1),
                                         s->v_edge_pos >> 1);
A
Anton Khirnov 已提交
338
                src = h->edge_emu_buffer;
339 340
            }
            if (thirdpel)
A
Anton Khirnov 已提交
341 342 343
                (avg ? h->dsp.avg_tpel_pixels_tab
                     : h->dsp.put_tpel_pixels_tab)[dxy](dest, src,
                                                        h->uvlinesize,
D
Diego Biurrun 已提交
344
                                                        width, height);
345
            else
346 347 348 349
                (avg ? s->hdsp.avg_pixels_tab
                     : s->hdsp.put_pixels_tab)[blocksize][dxy](dest, src,
                                                               h->uvlinesize,
                                                               height);
350 351
        }
    }
M
Michael Niedermayer 已提交
352 353
}

A
Anton Khirnov 已提交
354
static inline int svq3_mc_dir(SVQ3Context *s, int size, int mode,
D
Diego Biurrun 已提交
355
                              int dir, int avg)
356
{
357
    int i, j, k, mx, my, dx, dy, x, y;
A
Anton Khirnov 已提交
358
    H264Context *h          = &s->h;
D
Diego Biurrun 已提交
359 360 361 362 363 364 365
    const int part_width    = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
    const int part_height   = 16 >> ((unsigned)(size + 1) / 3);
    const int extra_width   = (mode == PREDICT_MODE) ? -16 * 6 : 0;
    const int h_edge_pos    = 6 * (s->h_edge_pos - part_width)  - extra_width;
    const int v_edge_pos    = 6 * (s->v_edge_pos - part_height) - extra_width;

    for (i = 0; i < 16; i += part_height)
366
        for (j = 0; j < 16; j += part_width) {
A
Anton Khirnov 已提交
367 368
            const int b_xy = (4 * h->mb_x + (j >> 2)) +
                             (4 * h->mb_y + (i >> 2)) * h->b_stride;
369
            int dxy;
A
Anton Khirnov 已提交
370 371
            x = 16 * h->mb_x + j;
            y = 16 * h->mb_y + i;
372 373
            k = (j >> 2 & 1) + (i >> 1 & 2) +
                (j >> 1 & 4) + (i      & 8);
374 375

            if (mode != PREDICT_MODE) {
376
                pred_motion(h, k, part_width >> 2, dir, 1, &mx, &my);
377
            } else {
378 379
                mx = s->next_pic->motion_val[0][b_xy][0] << 1;
                my = s->next_pic->motion_val[0][b_xy][1] << 1;
380 381

                if (dir == 0) {
382 383 384 385
                    mx = mx * h->frame_num_offset /
                         h->prev_frame_num_offset + 1 >> 1;
                    my = my * h->frame_num_offset /
                         h->prev_frame_num_offset + 1 >> 1;
386
                } else {
387 388 389 390
                    mx = mx * (h->frame_num_offset - h->prev_frame_num_offset) /
                         h->prev_frame_num_offset + 1 >> 1;
                    my = my * (h->frame_num_offset - h->prev_frame_num_offset) /
                         h->prev_frame_num_offset + 1 >> 1;
391 392 393 394
                }
            }

            /* clip motion vector prediction to frame border */
D
Diego Biurrun 已提交
395 396
            mx = av_clip(mx, extra_width - 6 * x, h_edge_pos - 6 * x);
            my = av_clip(my, extra_width - 6 * y, v_edge_pos - 6 * y);
397 398 399 400 401

            /* get (optional) motion vector differential */
            if (mode == PREDICT_MODE) {
                dx = dy = 0;
            } else {
A
Anton Khirnov 已提交
402 403
                dy = svq3_get_se_golomb(&h->gb);
                dx = svq3_get_se_golomb(&h->gb);
404 405

                if (dx == INVALID_VLC || dy == INVALID_VLC) {
A
Anton Khirnov 已提交
406
                    av_log(h->avctx, AV_LOG_ERROR, "invalid MV vlc\n");
407 408 409 410 411 412 413
                    return -1;
                }
            }

            /* compute motion vector */
            if (mode == THIRDPEL_MODE) {
                int fx, fy;
414 415 416 417
                mx  = (mx + 1 >> 1) + dx;
                my  = (my + 1 >> 1) + dy;
                fx  = (unsigned)(mx + 0x3000) / 3 - 0x1000;
                fy  = (unsigned)(my + 0x3000) / 3 - 0x1000;
D
Diego Biurrun 已提交
418 419 420 421
                dxy = (mx - 3 * fx) + 4 * (my - 3 * fy);

                svq3_mc_dir_part(s, x, y, part_width, part_height,
                                 fx, fy, dxy, 1, dir, avg);
422 423 424
                mx += mx;
                my += my;
            } else if (mode == HALFPEL_MODE || mode == PREDICT_MODE) {
425 426
                mx  = (unsigned)(mx + 1 + 0x3000) / 3 + dx - 0x1000;
                my  = (unsigned)(my + 1 + 0x3000) / 3 + dy - 0x1000;
D
Diego Biurrun 已提交
427
                dxy = (mx & 1) + 2 * (my & 1);
428

D
Diego Biurrun 已提交
429 430
                svq3_mc_dir_part(s, x, y, part_width, part_height,
                                 mx >> 1, my >> 1, dxy, 0, dir, avg);
431 432 433
                mx *= 3;
                my *= 3;
            } else {
434 435
                mx = (unsigned)(mx + 3 + 0x6000) / 6 + dx - 0x1000;
                my = (unsigned)(my + 3 + 0x6000) / 6 + dy - 0x1000;
436

D
Diego Biurrun 已提交
437 438
                svq3_mc_dir_part(s, x, y, part_width, part_height,
                                 mx, my, 0, 0, dir, avg);
439 440 441 442 443 444
                mx *= 6;
                my *= 6;
            }

            /* update mv_cache */
            if (mode != PREDICT_MODE) {
D
Diego Biurrun 已提交
445
                int32_t mv = pack16to32(mx, my);
446 447

                if (part_height == 8 && i < 8) {
D
Diego Biurrun 已提交
448
                    AV_WN32A(h->mv_cache[dir][scan8[k] + 1 * 8], mv);
449

D
Diego Biurrun 已提交
450 451
                    if (part_width == 8 && j < 8)
                        AV_WN32A(h->mv_cache[dir][scan8[k] + 1 + 1 * 8], mv);
452
                }
D
Diego Biurrun 已提交
453
                if (part_width == 8 && j < 8)
454
                    AV_WN32A(h->mv_cache[dir][scan8[k] + 1], mv);
D
Diego Biurrun 已提交
455
                if (part_width == 4 || part_height == 4)
456
                    AV_WN32A(h->mv_cache[dir][scan8[k]], mv);
457 458 459
            }

            /* write back motion vectors */
460
            fill_rectangle(h->cur_pic.motion_val[dir][b_xy],
D
Diego Biurrun 已提交
461 462
                           part_width >> 2, part_height >> 2, h->b_stride,
                           pack16to32(mx, my), 4);
463
        }
464

465
    return 0;
466 467
}

A
Anton Khirnov 已提交
468
static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type)
469
{
A
Anton Khirnov 已提交
470
    H264Context *h = &s->h;
471 472 473 474
    int i, j, k, m, dir, mode;
    int cbp = 0;
    uint32_t vlc;
    int8_t *top, *left;
D
Diego Biurrun 已提交
475
    const int mb_xy         = h->mb_xy;
A
Anton Khirnov 已提交
476
    const int b_xy          = 4 * h->mb_x + 4 * h->mb_y * h->b_stride;
477

A
Anton Khirnov 已提交
478 479
    h->top_samples_available      = (h->mb_y == 0) ? 0x33FF : 0xFFFF;
    h->left_samples_available     = (h->mb_x == 0) ? 0x5F5F : 0xFFFF;
480 481 482
    h->topright_samples_available = 0xFFFF;

    if (mb_type == 0) {           /* SKIP */
A
Anton Khirnov 已提交
483
        if (h->pict_type == AV_PICTURE_TYPE_P ||
484
            s->next_pic->mb_type[mb_xy] == -1) {
A
Anton Khirnov 已提交
485
            svq3_mc_dir_part(s, 16 * h->mb_x, 16 * h->mb_y, 16, 16,
D
Diego Biurrun 已提交
486
                             0, 0, 0, 0, 0, 0);
487

A
Anton Khirnov 已提交
488 489
            if (h->pict_type == AV_PICTURE_TYPE_B)
                svq3_mc_dir_part(s, 16 * h->mb_x, 16 * h->mb_y, 16, 16,
D
Diego Biurrun 已提交
490
                                 0, 0, 0, 0, 1, 1);
491 492 493

            mb_type = MB_TYPE_SKIP;
        } else {
494
            mb_type = FFMIN(s->next_pic->mb_type[mb_xy], 6);
A
Anton Khirnov 已提交
495
            if (svq3_mc_dir(s, mb_type, PREDICT_MODE, 0, 0) < 0)
496
                return -1;
A
Anton Khirnov 已提交
497
            if (svq3_mc_dir(s, mb_type, PREDICT_MODE, 1, 1) < 0)
498
                return -1;
M
Michael Niedermayer 已提交
499

500
            mb_type = MB_TYPE_16x16;
501
        }
502
    } else if (mb_type < 8) {     /* INTER */
A
Anton Khirnov 已提交
503
        if (s->thirdpel_flag && s->halfpel_flag == !get_bits1(&h->gb))
504
            mode = THIRDPEL_MODE;
A
Anton Khirnov 已提交
505 506
        else if (s->halfpel_flag &&
                 s->thirdpel_flag == !get_bits1(&h->gb))
507
            mode = HALFPEL_MODE;
D
Diego Biurrun 已提交
508
        else
509
            mode = FULLPEL_MODE;
M
Michael Niedermayer 已提交
510

511 512
        /* fill caches */
        /* note ref_cache should contain here:
D
Diego Biurrun 已提交
513 514 515 516 517 518
         *  ????????
         *  ???11111
         *  N??11111
         *  N??11111
         *  N??11111
         */
519 520

        for (m = 0; m < 2; m++) {
A
Anton Khirnov 已提交
521
            if (h->mb_x > 0 && h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - 1] + 6] != -1) {
D
Diego Biurrun 已提交
522 523
                for (i = 0; i < 4; i++)
                    AV_COPY32(h->mv_cache[m][scan8[0] - 1 + i * 8],
524
                              h->cur_pic.motion_val[m][b_xy - 1 + i * h->b_stride]);
525
            } else {
D
Diego Biurrun 已提交
526 527
                for (i = 0; i < 4; i++)
                    AV_ZERO32(h->mv_cache[m][scan8[0] - 1 + i * 8]);
528
            }
A
Anton Khirnov 已提交
529
            if (h->mb_y > 0) {
D
Diego Biurrun 已提交
530
                memcpy(h->mv_cache[m][scan8[0] - 1 * 8],
531
                       h->cur_pic.motion_val[m][b_xy - h->b_stride],
D
Diego Biurrun 已提交
532 533
                       4 * 2 * sizeof(int16_t));
                memset(&h->ref_cache[m][scan8[0] - 1 * 8],
A
Anton Khirnov 已提交
534
                       (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - h->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1, 4);
535

A
Anton Khirnov 已提交
536
                if (h->mb_x < h->mb_width - 1) {
D
Diego Biurrun 已提交
537
                    AV_COPY32(h->mv_cache[m][scan8[0] + 4 - 1 * 8],
538
                              h->cur_pic.motion_val[m][b_xy - h->b_stride + 4]);
D
Diego Biurrun 已提交
539
                    h->ref_cache[m][scan8[0] + 4 - 1 * 8] =
A
Anton Khirnov 已提交
540 541
                        (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - h->mb_stride + 1] + 6] == -1 ||
                         h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - h->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1;
D
Diego Biurrun 已提交
542 543
                } else
                    h->ref_cache[m][scan8[0] + 4 - 1 * 8] = PART_NOT_AVAILABLE;
A
Anton Khirnov 已提交
544
                if (h->mb_x > 0) {
D
Diego Biurrun 已提交
545
                    AV_COPY32(h->mv_cache[m][scan8[0] - 1 - 1 * 8],
546
                              h->cur_pic.motion_val[m][b_xy - h->b_stride - 1]);
D
Diego Biurrun 已提交
547
                    h->ref_cache[m][scan8[0] - 1 - 1 * 8] =
A
Anton Khirnov 已提交
548
                        (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - h->mb_stride - 1] + 3] == -1) ? PART_NOT_AVAILABLE : 1;
D
Diego Biurrun 已提交
549 550 551 552 553
                } else
                    h->ref_cache[m][scan8[0] - 1 - 1 * 8] = PART_NOT_AVAILABLE;
            } else
                memset(&h->ref_cache[m][scan8[0] - 1 * 8 - 1],
                       PART_NOT_AVAILABLE, 8);
554

A
Anton Khirnov 已提交
555
            if (h->pict_type != AV_PICTURE_TYPE_B)
556
                break;
557
        }
M
Michael Niedermayer 已提交
558

559
        /* decode motion vector(s) and form prediction(s) */
A
Anton Khirnov 已提交
560 561
        if (h->pict_type == AV_PICTURE_TYPE_P) {
            if (svq3_mc_dir(s, mb_type - 1, mode, 0, 0) < 0)
562
                return -1;
563
        } else {        /* AV_PICTURE_TYPE_B */
M
Matti Hamalainen 已提交
564
            if (mb_type != 2) {
A
Anton Khirnov 已提交
565
                if (svq3_mc_dir(s, 0, mode, 0, 0) < 0)
566
                    return -1;
M
Matti Hamalainen 已提交
567
            } else {
D
Diego Biurrun 已提交
568
                for (i = 0; i < 4; i++)
569
                    memset(h->cur_pic.motion_val[0][b_xy + i * h->b_stride],
D
Diego Biurrun 已提交
570
                           0, 4 * 2 * sizeof(int16_t));
M
Matti Hamalainen 已提交
571 572
            }
            if (mb_type != 1) {
A
Anton Khirnov 已提交
573
                if (svq3_mc_dir(s, 0, mode, 1, mb_type == 3) < 0)
574
                    return -1;
M
Matti Hamalainen 已提交
575
            } else {
D
Diego Biurrun 已提交
576
                for (i = 0; i < 4; i++)
577
                    memset(h->cur_pic.motion_val[1][b_xy + i * h->b_stride],
D
Diego Biurrun 已提交
578
                           0, 4 * 2 * sizeof(int16_t));
M
Matti Hamalainen 已提交
579
            }
580
        }
M
Michael Niedermayer 已提交
581

582 583
        mb_type = MB_TYPE_16x16;
    } else if (mb_type == 8 || mb_type == 33) {   /* INTRA4x4 */
D
Diego Biurrun 已提交
584
        memset(h->intra4x4_pred_mode_cache, -1, 8 * 5 * sizeof(int8_t));
585 586

        if (mb_type == 8) {
A
Anton Khirnov 已提交
587
            if (h->mb_x > 0) {
D
Diego Biurrun 已提交
588 589 590
                for (i = 0; i < 4; i++)
                    h->intra4x4_pred_mode_cache[scan8[0] - 1 + i * 8] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - 1] + 6 - i];
                if (h->intra4x4_pred_mode_cache[scan8[0] - 1] == -1)
591 592
                    h->left_samples_available = 0x5F5F;
            }
A
Anton Khirnov 已提交
593 594 595 596 597
            if (h->mb_y > 0) {
                h->intra4x4_pred_mode_cache[4 + 8 * 0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - h->mb_stride] + 0];
                h->intra4x4_pred_mode_cache[5 + 8 * 0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - h->mb_stride] + 1];
                h->intra4x4_pred_mode_cache[6 + 8 * 0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - h->mb_stride] + 2];
                h->intra4x4_pred_mode_cache[7 + 8 * 0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - h->mb_stride] + 3];
598

D
Diego Biurrun 已提交
599
                if (h->intra4x4_pred_mode_cache[4 + 8 * 0] == -1)
600 601 602 603
                    h->top_samples_available = 0x33FF;
            }

            /* decode prediction codes for luma blocks */
D
Diego Biurrun 已提交
604
            for (i = 0; i < 16; i += 2) {
A
Anton Khirnov 已提交
605
                vlc = svq3_get_ue_golomb(&h->gb);
606

D
Diego Biurrun 已提交
607
                if (vlc >= 25) {
A
Anton Khirnov 已提交
608
                    av_log(h->avctx, AV_LOG_ERROR, "luma prediction:%d\n", vlc);
609 610 611
                    return -1;
                }

D
Diego Biurrun 已提交
612 613
                left = &h->intra4x4_pred_mode_cache[scan8[i] - 1];
                top  = &h->intra4x4_pred_mode_cache[scan8[i] - 8];
614 615 616 617

                left[1] = svq3_pred_1[top[0] + 1][left[0] + 1][svq3_pred_0[vlc][0]];
                left[2] = svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];

D
Diego Biurrun 已提交
618
                if (left[1] == -1 || left[2] == -1) {
A
Anton Khirnov 已提交
619
                    av_log(h->avctx, AV_LOG_ERROR, "weird prediction\n");
620 621 622 623
                    return -1;
                }
            }
        } else {    /* mb_type == 33, DC_128_PRED block type */
D
Diego Biurrun 已提交
624 625
            for (i = 0; i < 4; i++)
                memset(&h->intra4x4_pred_mode_cache[scan8[0] + 8 * i], DC_PRED, 4);
626
        }
M
Michael Niedermayer 已提交
627

628
        write_back_intra_pred_mode(h);
M
Michael Niedermayer 已提交
629

630
        if (mb_type == 8) {
631
            ff_h264_check_intra4x4_pred_mode(h);
632

A
Anton Khirnov 已提交
633 634
            h->top_samples_available  = (h->mb_y == 0) ? 0x33FF : 0xFFFF;
            h->left_samples_available = (h->mb_x == 0) ? 0x5F5F : 0xFFFF;
635
        } else {
D
Diego Biurrun 已提交
636 637
            for (i = 0; i < 4; i++)
                memset(&h->intra4x4_pred_mode_cache[scan8[0] + 8 * i], DC_128_PRED, 4);
638

639 640 641
            h->top_samples_available  = 0x33FF;
            h->left_samples_available = 0x5F5F;
        }
642

643 644 645
        mb_type = MB_TYPE_INTRA4x4;
    } else {                      /* INTRA16x16 */
        dir = i_mb_type_info[mb_type - 8].pred_mode;
D
Diego Biurrun 已提交
646
        dir = (dir >> 1) ^ 3 * (dir & 1) ^ 1;
M
Michael Niedermayer 已提交
647

D
Diego Biurrun 已提交
648
        if ((h->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(h, dir, 0)) == -1) {
A
Anton Khirnov 已提交
649
            av_log(h->avctx, AV_LOG_ERROR, "check_intra_pred_mode = -1\n");
650 651
            return -1;
        }
M
Michael Niedermayer 已提交
652

D
Diego Biurrun 已提交
653
        cbp     = i_mb_type_info[mb_type - 8].cbp;
654
        mb_type = MB_TYPE_INTRA16x16;
655
    }
M
Michael Niedermayer 已提交
656

A
Anton Khirnov 已提交
657
    if (!IS_INTER(mb_type) && h->pict_type != AV_PICTURE_TYPE_I) {
D
Diego Biurrun 已提交
658
        for (i = 0; i < 4; i++)
659
            memset(h->cur_pic.motion_val[0][b_xy + i * h->b_stride],
D
Diego Biurrun 已提交
660
                   0, 4 * 2 * sizeof(int16_t));
A
Anton Khirnov 已提交
661
        if (h->pict_type == AV_PICTURE_TYPE_B) {
D
Diego Biurrun 已提交
662
            for (i = 0; i < 4; i++)
663
                memset(h->cur_pic.motion_val[1][b_xy + i * h->b_stride],
D
Diego Biurrun 已提交
664
                       0, 4 * 2 * sizeof(int16_t));
665
        }
M
Michael Niedermayer 已提交
666
    }
667
    if (!IS_INTRA4x4(mb_type)) {
D
Diego Biurrun 已提交
668
        memset(h->intra4x4_pred_mode + h->mb2br_xy[mb_xy], DC_PRED, 8);
669
    }
A
Anton Khirnov 已提交
670
    if (!IS_SKIP(mb_type) || h->pict_type == AV_PICTURE_TYPE_B) {
D
Diego Biurrun 已提交
671
        memset(h->non_zero_count_cache + 8, 0, 14 * 8 * sizeof(uint8_t));
672
    }
673

D
Diego Biurrun 已提交
674
    if (!IS_INTRA16x16(mb_type) &&
A
Anton Khirnov 已提交
675 676 677
        (!IS_SKIP(mb_type) || h->pict_type == AV_PICTURE_TYPE_B)) {
        if ((vlc = svq3_get_ue_golomb(&h->gb)) >= 48) {
            av_log(h->avctx, AV_LOG_ERROR, "cbp_vlc=%d\n", vlc);
678 679
            return -1;
        }
M
Michael Niedermayer 已提交
680

D
Diego Biurrun 已提交
681 682
        cbp = IS_INTRA(mb_type) ? golomb_to_intra4x4_cbp[vlc]
                                : golomb_to_inter_cbp[vlc];
683
    }
D
Diego Biurrun 已提交
684
    if (IS_INTRA16x16(mb_type) ||
A
Anton Khirnov 已提交
685 686
        (h->pict_type != AV_PICTURE_TYPE_I && s->adaptive_quant && cbp)) {
        h->qscale += svq3_get_se_golomb(&h->gb);
M
Michael Niedermayer 已提交
687

A
Anton Khirnov 已提交
688 689
        if (h->qscale > 31u) {
            av_log(h->avctx, AV_LOG_ERROR, "qscale:%d\n", h->qscale);
690 691
            return -1;
        }
M
Michael Niedermayer 已提交
692
    }
693
    if (IS_INTRA16x16(mb_type)) {
D
Diego Biurrun 已提交
694 695
        AV_ZERO128(h->mb_luma_dc[0] + 0);
        AV_ZERO128(h->mb_luma_dc[0] + 8);
A
Anton Khirnov 已提交
696 697
        if (svq3_decode_block(&h->gb, h->mb_luma_dc[0], 0, 1)) {
            av_log(h->avctx, AV_LOG_ERROR,
D
Diego Biurrun 已提交
698
                   "error while decoding intra luma dc\n");
699
            return -1;
700
        }
701
    }
M
Michael Niedermayer 已提交
702

703 704
    if (cbp) {
        const int index = IS_INTRA16x16(mb_type) ? 1 : 0;
A
Anton Khirnov 已提交
705
        const int type  = ((h->qscale < 24 && IS_INTRA4x4(mb_type)) ? 2 : 1);
706

D
Diego Biurrun 已提交
707
        for (i = 0; i < 4; i++)
708 709
            if ((cbp & (1 << i))) {
                for (j = 0; j < 4; j++) {
D
Diego Biurrun 已提交
710 711 712 713 714
                    k = index ? (1 * (j & 1) + 2 * (i & 1) +
                                 2 * (j & 2) + 4 * (i & 2))
                              : (4 * i + j);
                    h->non_zero_count_cache[scan8[k]] = 1;

A
Anton Khirnov 已提交
715 716
                    if (svq3_decode_block(&h->gb, &h->mb[16 * k], index, type)) {
                        av_log(h->avctx, AV_LOG_ERROR,
D
Diego Biurrun 已提交
717
                               "error while decoding block\n");
718 719 720 721
                        return -1;
                    }
                }
            }
M
Michael Niedermayer 已提交
722

723
        if ((cbp & 0x30)) {
D
Diego Biurrun 已提交
724
            for (i = 1; i < 3; ++i)
A
Anton Khirnov 已提交
725 726
                if (svq3_decode_block(&h->gb, &h->mb[16 * 16 * i], 0, 3)) {
                    av_log(h->avctx, AV_LOG_ERROR,
D
Diego Biurrun 已提交
727 728 729
                           "error while decoding chroma dc block\n");
                    return -1;
                }
730 731

            if ((cbp & 0x20)) {
732 733
                for (i = 1; i < 3; i++) {
                    for (j = 0; j < 4; j++) {
D
Diego Biurrun 已提交
734 735
                        k                                 = 16 * i + j;
                        h->non_zero_count_cache[scan8[k]] = 1;
736

A
Anton Khirnov 已提交
737 738
                        if (svq3_decode_block(&h->gb, &h->mb[16 * k], 1, 1)) {
                            av_log(h->avctx, AV_LOG_ERROR,
D
Diego Biurrun 已提交
739
                                   "error while decoding chroma ac block\n");
740 741
                            return -1;
                        }
742 743 744
                    }
                }
            }
745
        }
M
Michael Niedermayer 已提交
746 747
    }

D
Diego Biurrun 已提交
748
    h->cbp                              = cbp;
749
    h->cur_pic.mb_type[mb_xy] = mb_type;
M
Michael Niedermayer 已提交
750

D
Diego Biurrun 已提交
751
    if (IS_INTRA(mb_type))
752
        h->chroma_pred_mode = ff_h264_check_intra_pred_mode(h, DC_PRED8x8, 1);
M
Michael Niedermayer 已提交
753

754
    return 0;
M
Michael Niedermayer 已提交
755 756
}

757
static int svq3_decode_slice_header(AVCodecContext *avctx)
758
{
A
Anton Khirnov 已提交
759 760
    SVQ3Context *s = avctx->priv_data;
    H264Context *h    = &s->h;
D
Diego Biurrun 已提交
761
    const int mb_xy   = h->mb_xy;
762
    int i, header;
763
    unsigned slice_id;
764

A
Anton Khirnov 已提交
765
    header = get_bits(&h->gb, 8);
766

767 768
    if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
        /* TODO: what? */
769
        av_log(avctx, AV_LOG_ERROR, "unsupported slice header (%02X)\n", header);
770 771
        return -1;
    } else {
772
        int length = header >> 5 & 3;
773

A
Anton Khirnov 已提交
774 775 776
        s->next_slice_index = get_bits_count(&h->gb) +
                              8 * show_bits(&h->gb, 8 * length) +
                              8 * length;
777

A
Anton Khirnov 已提交
778
        if (s->next_slice_index > h->gb.size_in_bits) {
779
            av_log(avctx, AV_LOG_ERROR, "slice after bitstream end\n");
780
            return -1;
D
Diego Biurrun 已提交
781
        }
782

A
Anton Khirnov 已提交
783 784
        h->gb.size_in_bits = s->next_slice_index - 8 * (length - 1);
        skip_bits(&h->gb, 8);
785

A
Anton Khirnov 已提交
786 787 788 789
        if (s->watermark_key) {
            uint32_t header = AV_RL32(&h->gb.buffer[(get_bits_count(&h->gb) >> 3) + 1]);
            AV_WL32(&h->gb.buffer[(get_bits_count(&h->gb) >> 3) + 1],
                    header ^ s->watermark_key);
790 791
        }
        if (length > 0) {
A
Anton Khirnov 已提交
792 793
            memcpy((uint8_t *) &h->gb.buffer[get_bits_count(&h->gb) >> 3],
                   &h->gb.buffer[h->gb.size_in_bits >> 3], length - 1);
794
        }
A
Anton Khirnov 已提交
795
        skip_bits_long(&h->gb, 0);
796 797
    }

A
Anton Khirnov 已提交
798 799
    if ((slice_id = svq3_get_ue_golomb(&h->gb)) >= 3) {
        av_log(h->avctx, AV_LOG_ERROR, "illegal slice type %d \n", slice_id);
800 801
        return -1;
    }
802

803
    h->slice_type = golomb_to_pict_type[slice_id];
804

805
    if ((header & 0x9F) == 2) {
A
Anton Khirnov 已提交
806 807 808
        i              = (h->mb_num < 64) ? 6 : (1 + av_log2(h->mb_num - 1));
        h->mb_skip_run = get_bits(&h->gb, i) -
                         (h->mb_y * h->mb_width + h->mb_x);
809
    } else {
A
Anton Khirnov 已提交
810 811
        skip_bits1(&h->gb);
        h->mb_skip_run = 0;
812
    }
813

A
Anton Khirnov 已提交
814 815 816
    h->slice_num      = get_bits(&h->gb, 8);
    h->qscale         = get_bits(&h->gb, 5);
    s->adaptive_quant = get_bits1(&h->gb);
817

818
    /* unknown fields */
A
Anton Khirnov 已提交
819
    skip_bits1(&h->gb);
820

A
Anton Khirnov 已提交
821 822
    if (s->unknown_flag)
        skip_bits1(&h->gb);
823

A
Anton Khirnov 已提交
824 825
    skip_bits1(&h->gb);
    skip_bits(&h->gb, 2);
826

A
Anton Khirnov 已提交
827 828
    while (get_bits1(&h->gb))
        skip_bits(&h->gb, 8);
829

830
    /* reset intra predictors and invalidate motion vector references */
A
Anton Khirnov 已提交
831
    if (h->mb_x > 0) {
D
Diego Biurrun 已提交
832 833
        memset(h->intra4x4_pred_mode + h->mb2br_xy[mb_xy - 1] + 3,
               -1, 4 * sizeof(int8_t));
A
Anton Khirnov 已提交
834 835
        memset(h->intra4x4_pred_mode + h->mb2br_xy[mb_xy - h->mb_x],
               -1, 8 * sizeof(int8_t) * h->mb_x);
836
    }
A
Anton Khirnov 已提交
837 838 839
    if (h->mb_y > 0) {
        memset(h->intra4x4_pred_mode + h->mb2br_xy[mb_xy - h->mb_stride],
               -1, 8 * sizeof(int8_t) * (h->mb_width - h->mb_x));
840

A
Anton Khirnov 已提交
841 842
        if (h->mb_x > 0)
            h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - h->mb_stride - 1] + 3] = -1;
843 844
    }

845
    return 0;
846 847
}

848
static av_cold int svq3_decode_init(AVCodecContext *avctx)
849
{
A
Anton Khirnov 已提交
850 851
    SVQ3Context *s = avctx->priv_data;
    H264Context *h = &s->h;
852
    int m;
853
    unsigned char *extradata;
854
    unsigned char *extradata_end;
855
    unsigned int size;
856
    int marker_found = 0;
857

A
Anton Khirnov 已提交
858 859 860 861 862 863 864 865 866 867
    s->cur_pic  = av_mallocz(sizeof(*s->cur_pic));
    s->last_pic = av_mallocz(sizeof(*s->last_pic));
    s->next_pic = av_mallocz(sizeof(*s->next_pic));
    if (!s->next_pic || !s->last_pic || !s->cur_pic) {
        av_freep(&s->cur_pic);
        av_freep(&s->last_pic);
        av_freep(&s->next_pic);
        return AVERROR(ENOMEM);
    }

868
    if (ff_h264_decode_init(avctx) < 0)
869 870
        return -1;

871
    ff_hpeldsp_init(&s->hdsp, avctx->flags);
A
Anton Khirnov 已提交
872
    h->flags           = avctx->flags;
D
Diego Biurrun 已提交
873
    h->is_complex      = 1;
A
Anton Khirnov 已提交
874
    h->picture_structure = PICT_FRAME;
D
Diego Biurrun 已提交
875
    avctx->pix_fmt     = avctx->codec->pix_fmts[0];
876

A
Anton Khirnov 已提交
877
    h->chroma_qp[0] = h->chroma_qp[1] = 4;
A
Anton Khirnov 已提交
878
    h->chroma_x_shift = h->chroma_y_shift = 1;
A
Anton Khirnov 已提交
879

A
Anton Khirnov 已提交
880 881 882
    s->halfpel_flag  = 1;
    s->thirdpel_flag = 1;
    s->unknown_flag  = 0;
A
Anton Khirnov 已提交
883 884 885 886 887 888 889 890 891

    /* prowl for the "SEQH" marker in the extradata */
    extradata     = (unsigned char *)avctx->extradata;
    extradata_end = avctx->extradata + avctx->extradata_size;
    if (extradata) {
        for (m = 0; m + 8 < avctx->extradata_size; m++) {
            if (!memcmp(extradata, "SEQH", 4)) {
                marker_found = 1;
                break;
892
            }
A
Anton Khirnov 已提交
893
            extradata++;
894
        }
A
Anton Khirnov 已提交
895
    }
M
Michael Niedermayer 已提交
896

A
Anton Khirnov 已提交
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942
    /* if a match was found, parse the extra data */
    if (marker_found) {
        GetBitContext gb;
        int frame_size_code;

        size = AV_RB32(&extradata[4]);
        if (size > extradata_end - extradata - 8)
            return AVERROR_INVALIDDATA;
        init_get_bits(&gb, extradata + 8, size * 8);

        /* 'frame size code' and optional 'width, height' */
        frame_size_code = get_bits(&gb, 3);
        switch (frame_size_code) {
        case 0:
            avctx->width  = 160;
            avctx->height = 120;
            break;
        case 1:
            avctx->width  = 128;
            avctx->height =  96;
            break;
        case 2:
            avctx->width  = 176;
            avctx->height = 144;
            break;
        case 3:
            avctx->width  = 352;
            avctx->height = 288;
            break;
        case 4:
            avctx->width  = 704;
            avctx->height = 576;
            break;
        case 5:
            avctx->width  = 240;
            avctx->height = 180;
            break;
        case 6:
            avctx->width  = 320;
            avctx->height = 240;
            break;
        case 7:
            avctx->width  = get_bits(&gb, 12);
            avctx->height = get_bits(&gb, 12);
            break;
        }
M
Michael Niedermayer 已提交
943

A
Anton Khirnov 已提交
944 945
        s->halfpel_flag  = get_bits1(&gb);
        s->thirdpel_flag = get_bits1(&gb);
M
Michael Niedermayer 已提交
946

A
Anton Khirnov 已提交
947 948 949 950 951
        /* unknown fields */
        skip_bits1(&gb);
        skip_bits1(&gb);
        skip_bits1(&gb);
        skip_bits1(&gb);
M
Michael Niedermayer 已提交
952

A
Anton Khirnov 已提交
953
        h->low_delay = get_bits1(&gb);
954

A
Anton Khirnov 已提交
955 956
        /* unknown field */
        skip_bits1(&gb);
957

A
Anton Khirnov 已提交
958 959
        while (get_bits1(&gb))
            skip_bits(&gb, 8);
960

A
Anton Khirnov 已提交
961 962 963
        s->unknown_flag  = get_bits1(&gb);
        avctx->has_b_frames = !h->low_delay;
        if (s->unknown_flag) {
964
#if CONFIG_ZLIB
A
Anton Khirnov 已提交
965 966 967 968 969 970 971 972 973 974 975 976 977
            unsigned watermark_width  = svq3_get_ue_golomb(&gb);
            unsigned watermark_height = svq3_get_ue_golomb(&gb);
            int u1                    = svq3_get_ue_golomb(&gb);
            int u2                    = get_bits(&gb, 8);
            int u3                    = get_bits(&gb, 2);
            int u4                    = svq3_get_ue_golomb(&gb);
            unsigned long buf_len     = watermark_width *
                                        watermark_height * 4;
            int offset                = get_bits_count(&gb) + 7 >> 3;
            uint8_t *buf;

            if ((uint64_t)watermark_width * 4 > UINT_MAX / watermark_height)
                return -1;
978

A
Anton Khirnov 已提交
979 980 981 982 983 984 985 986
            buf = av_malloc(buf_len);
            av_log(avctx, AV_LOG_DEBUG, "watermark size: %dx%d\n",
                   watermark_width, watermark_height);
            av_log(avctx, AV_LOG_DEBUG,
                   "u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n",
                   u1, u2, u3, u4, offset);
            if (uncompress(buf, &buf_len, extradata + 8 + offset,
                           size - offset) != Z_OK) {
D
Diego Biurrun 已提交
987
                av_log(avctx, AV_LOG_ERROR,
A
Anton Khirnov 已提交
988 989
                       "could not uncompress watermark logo\n");
                av_free(buf);
990 991
                return -1;
            }
A
Anton Khirnov 已提交
992 993
            s->watermark_key = ff_svq1_packet_checksum(buf, buf_len, 0);
            s->watermark_key = s->watermark_key << 16 | s->watermark_key;
A
Anton Khirnov 已提交
994
            av_log(avctx, AV_LOG_DEBUG,
A
Anton Khirnov 已提交
995
                   "watermark key %#x\n", s->watermark_key);
A
Anton Khirnov 已提交
996 997 998 999 1000 1001
            av_free(buf);
#else
            av_log(avctx, AV_LOG_ERROR,
                   "this svq3 file contains watermark which need zlib support compiled in\n");
            return -1;
#endif
1002
        }
A
Anton Khirnov 已提交
1003
    }
1004

A
Anton Khirnov 已提交
1005 1006 1007 1008 1009 1010 1011 1012 1013
    h->width  = avctx->width;
    h->height = avctx->height;
    h->mb_width  = (h->width + 15) / 16;
    h->mb_height = (h->height + 15) / 16;
    h->mb_stride = h->mb_width + 1;
    h->mb_num    = h->mb_width * h->mb_height;
    h->b_stride = 4 * h->mb_width;
    s->h_edge_pos = h->mb_width * 16;
    s->v_edge_pos = h->mb_height * 16;
1014

A
Anton Khirnov 已提交
1015 1016 1017
    if (ff_h264_alloc_tables(h) < 0) {
        av_log(avctx, AV_LOG_ERROR, "svq3 memory allocation failed\n");
        return AVERROR(ENOMEM);
1018
    }
1019

1020 1021 1022
    return 0;
}

1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034
static void free_picture(AVCodecContext *avctx, Picture *pic)
{
    int i;
    for (i = 0; i < 2; i++) {
        av_buffer_unref(&pic->motion_val_buf[i]);
        av_buffer_unref(&pic->ref_index_buf[i]);
    }
    av_buffer_unref(&pic->mb_type_buf);

    av_frame_unref(&pic->f);
}

A
Anton Khirnov 已提交
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044
static int get_buffer(AVCodecContext *avctx, Picture *pic)
{
    SVQ3Context *s = avctx->priv_data;
    H264Context *h = &s->h;
    const int big_mb_num    = h->mb_stride * (h->mb_height + 1) + 1;
    const int mb_array_size = h->mb_stride * h->mb_height;
    const int b4_stride     = h->mb_width * 4 + 1;
    const int b4_array_size = b4_stride * h->mb_height * 4;
    int ret;

1045
    if (!pic->motion_val_buf[0]) {
A
Anton Khirnov 已提交
1046 1047
        int i;

1048 1049
        pic->mb_type_buf = av_buffer_allocz((big_mb_num + h->mb_stride) * sizeof(uint32_t));
        if (!pic->mb_type_buf)
A
Anton Khirnov 已提交
1050
            return AVERROR(ENOMEM);
1051
        pic->mb_type = (uint32_t*)pic->mb_type_buf->data + 2 * h->mb_stride + 1;
A
Anton Khirnov 已提交
1052 1053

        for (i = 0; i < 2; i++) {
1054 1055 1056 1057 1058 1059
            pic->motion_val_buf[i] = av_buffer_allocz(2 * (b4_array_size + 4) * sizeof(int16_t));
            pic->ref_index_buf[i]  = av_buffer_allocz(4 * mb_array_size);
            if (!pic->motion_val_buf[i] || !pic->ref_index_buf[i]) {
                ret = AVERROR(ENOMEM);
                goto fail;
            }
A
Anton Khirnov 已提交
1060

1061 1062
            pic->motion_val[i] = (int16_t (*)[2])pic->motion_val_buf[i]->data + 4;
            pic->ref_index[i]  = pic->ref_index_buf[i]->data;
A
Anton Khirnov 已提交
1063 1064
        }
    }
1065 1066 1067 1068 1069 1070
    pic->reference = !(h->pict_type == AV_PICTURE_TYPE_B);

    ret = ff_get_buffer(avctx, &pic->f,
                        pic->reference ? AV_GET_BUFFER_FLAG_REF : 0);
    if (ret < 0)
        goto fail;
A
Anton Khirnov 已提交
1071

1072 1073 1074 1075 1076
    if (!h->edge_emu_buffer) {
        h->edge_emu_buffer = av_mallocz(pic->f.linesize[0] * 17);
        if (!h->edge_emu_buffer)
            return AVERROR(ENOMEM);
    }
A
Anton Khirnov 已提交
1077 1078 1079 1080

    h->linesize   = pic->f.linesize[0];
    h->uvlinesize = pic->f.linesize[1];

1081 1082 1083
    return 0;
fail:
    free_picture(avctx, pic);
A
Anton Khirnov 已提交
1084 1085 1086
    return ret;
}

D
Diego Biurrun 已提交
1087
static int svq3_decode_frame(AVCodecContext *avctx, void *data,
1088
                             int *got_frame, AVPacket *avpkt)
1089
{
1090
    const uint8_t *buf = avpkt->data;
A
Anton Khirnov 已提交
1091 1092
    SVQ3Context *s     = avctx->priv_data;
    H264Context *h     = &s->h;
D
Diego Biurrun 已提交
1093
    int buf_size       = avpkt->size;
A
Anton Khirnov 已提交
1094
    int ret, m, i;
1095

1096 1097
    /* special case for last picture */
    if (buf_size == 0) {
A
Anton Khirnov 已提交
1098
        if (s->next_pic->f.data[0] && !h->low_delay && !s->last_frame_output) {
1099 1100 1101
            ret = av_frame_ref(data, &s->next_pic->f);
            if (ret < 0)
                return ret;
A
Anton Khirnov 已提交
1102
            s->last_frame_output = 1;
1103
            *got_frame          = 1;
1104 1105
        }
        return 0;
1106
    }
M
Michael Niedermayer 已提交
1107

A
Anton Khirnov 已提交
1108
    init_get_bits(&h->gb, buf, 8 * buf_size);
M
Michael Niedermayer 已提交
1109

A
Anton Khirnov 已提交
1110
    h->mb_x = h->mb_y = h->mb_xy = 0;
M
Michael Niedermayer 已提交
1111

1112
    if (svq3_decode_slice_header(avctx))
1113
        return -1;
M
Michael Niedermayer 已提交
1114

A
Anton Khirnov 已提交
1115
    h->pict_type = h->slice_type;
M
Michael Niedermayer 已提交
1116

A
Anton Khirnov 已提交
1117 1118 1119
    if (h->pict_type != AV_PICTURE_TYPE_B)
        FFSWAP(Picture*, s->next_pic, s->last_pic);

1120
    av_frame_unref(&s->cur_pic->f);
M
Michael Niedermayer 已提交
1121

1122
    /* for skipping the frame */
A
Anton Khirnov 已提交
1123 1124
    s->cur_pic->f.pict_type = h->pict_type;
    s->cur_pic->f.key_frame = (h->pict_type == AV_PICTURE_TYPE_I);
1125

A
Anton Khirnov 已提交
1126 1127 1128 1129 1130
    ret = get_buffer(avctx, s->cur_pic);
    if (ret < 0)
        return ret;

    h->cur_pic_ptr = s->cur_pic;
1131
    av_frame_unref(&h->cur_pic.f);
A
Anton Khirnov 已提交
1132
    h->cur_pic     = *s->cur_pic;
1133 1134 1135
    ret = av_frame_ref(&h->cur_pic.f, &s->cur_pic->f);
    if (ret < 0)
        return ret;
A
Anton Khirnov 已提交
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182

    for (i = 0; i < 16; i++) {
        h->block_offset[i]           = (4 * ((scan8[i] - scan8[0]) & 7)) + 4 * h->linesize * ((scan8[i] - scan8[0]) >> 3);
        h->block_offset[48 + i]      = (4 * ((scan8[i] - scan8[0]) & 7)) + 8 * h->linesize * ((scan8[i] - scan8[0]) >> 3);
    }
    for (i = 0; i < 16; i++) {
        h->block_offset[16 + i]      =
        h->block_offset[32 + i]      = (4 * ((scan8[i] - scan8[0]) & 7)) + 4 * h->uvlinesize * ((scan8[i] - scan8[0]) >> 3);
        h->block_offset[48 + 16 + i] =
        h->block_offset[48 + 32 + i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 8 * h->uvlinesize * ((scan8[i] - scan8[0]) >> 3);
    }

    if (h->pict_type != AV_PICTURE_TYPE_I) {
        if (!s->last_pic->f.data[0]) {
            av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
            ret = get_buffer(avctx, s->last_pic);
            if (ret < 0)
                return ret;
            memset(s->last_pic->f.data[0], 0, avctx->height * s->last_pic->f.linesize[0]);
            memset(s->last_pic->f.data[1], 0x80, (avctx->height / 2) *
                   s->last_pic->f.linesize[1]);
            memset(s->last_pic->f.data[2], 0x80, (avctx->height / 2) *
                   s->last_pic->f.linesize[2]);
        }

        if (h->pict_type == AV_PICTURE_TYPE_B && !s->next_pic->f.data[0]) {
            av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
            ret = get_buffer(avctx, s->next_pic);
            if (ret < 0)
                return ret;
            memset(s->next_pic->f.data[0], 0, avctx->height * s->next_pic->f.linesize[0]);
            memset(s->next_pic->f.data[1], 0x80, (avctx->height / 2) *
                   s->next_pic->f.linesize[1]);
            memset(s->next_pic->f.data[2], 0x80, (avctx->height / 2) *
                   s->next_pic->f.linesize[2]);
        }
    }

    if (avctx->debug & FF_DEBUG_PICT_INFO)
        av_log(h->avctx, AV_LOG_DEBUG,
               "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n",
               av_get_picture_type_char(h->pict_type),
               s->halfpel_flag, s->thirdpel_flag,
               s->adaptive_quant, h->qscale, h->slice_num);

    if (avctx->skip_frame >= AVDISCARD_NONREF && h->pict_type == AV_PICTURE_TYPE_B ||
        avctx->skip_frame >= AVDISCARD_NONKEY && h->pict_type != AV_PICTURE_TYPE_I ||
1183
        avctx->skip_frame >= AVDISCARD_ALL)
1184 1185 1186
        return 0;

    if (s->next_p_frame_damaged) {
A
Anton Khirnov 已提交
1187
        if (h->pict_type == AV_PICTURE_TYPE_B)
1188 1189 1190 1191
            return 0;
        else
            s->next_p_frame_damaged = 0;
    }
1192

A
Anton Khirnov 已提交
1193
    if (h->pict_type == AV_PICTURE_TYPE_B) {
1194
        h->frame_num_offset = h->slice_num - h->prev_frame_num;
M
Michael Niedermayer 已提交
1195

D
Diego Biurrun 已提交
1196
        if (h->frame_num_offset < 0)
1197
            h->frame_num_offset += 256;
D
Diego Biurrun 已提交
1198 1199
        if (h->frame_num_offset == 0 ||
            h->frame_num_offset >= h->prev_frame_num_offset) {
A
Anton Khirnov 已提交
1200
            av_log(h->avctx, AV_LOG_ERROR, "error in B-frame picture id\n");
1201 1202 1203
            return -1;
        }
    } else {
D
Diego Biurrun 已提交
1204 1205
        h->prev_frame_num        = h->frame_num;
        h->frame_num             = h->slice_num;
1206
        h->prev_frame_num_offset = h->frame_num - h->prev_frame_num;
1207

D
Diego Biurrun 已提交
1208
        if (h->prev_frame_num_offset < 0)
1209
            h->prev_frame_num_offset += 256;
1210 1211
    }

D
Diego Biurrun 已提交
1212
    for (m = 0; m < 2; m++) {
1213
        int i;
D
Diego Biurrun 已提交
1214
        for (i = 0; i < 4; i++) {
1215 1216
            int j;
            for (j = -1; j < 4; j++)
D
Diego Biurrun 已提交
1217
                h->ref_cache[m][scan8[0] + 8 * i + j] = 1;
1218
            if (i < 3)
D
Diego Biurrun 已提交
1219
                h->ref_cache[m][scan8[0] + 8 * i + j] = PART_NOT_AVAILABLE;
1220
        }
1221 1222
    }

A
Anton Khirnov 已提交
1223 1224
    for (h->mb_y = 0; h->mb_y < h->mb_height; h->mb_y++) {
        for (h->mb_x = 0; h->mb_x < h->mb_width; h->mb_x++) {
1225
            unsigned mb_type;
A
Anton Khirnov 已提交
1226
            h->mb_xy = h->mb_x + h->mb_y * h->mb_stride;
1227

A
Anton Khirnov 已提交
1228 1229 1230 1231 1232
            if ((get_bits_count(&h->gb) + 7) >= h->gb.size_in_bits &&
                ((get_bits_count(&h->gb) & 7) == 0 ||
                 show_bits(&h->gb, -get_bits_count(&h->gb) & 7) == 0)) {
                skip_bits(&h->gb, s->next_slice_index - get_bits_count(&h->gb));
                h->gb.size_in_bits = 8 * buf_size;
1233

1234
                if (svq3_decode_slice_header(avctx))
1235
                    return -1;
1236

1237 1238
                /* TODO: support s->mb_skip_run */
            }
1239

A
Anton Khirnov 已提交
1240
            mb_type = svq3_get_ue_golomb(&h->gb);
1241

A
Anton Khirnov 已提交
1242
            if (h->pict_type == AV_PICTURE_TYPE_I)
1243
                mb_type += 8;
A
Anton Khirnov 已提交
1244
            else if (h->pict_type == AV_PICTURE_TYPE_B && mb_type >= 4)
1245
                mb_type += 4;
A
Anton Khirnov 已提交
1246 1247 1248
            if (mb_type > 33 || svq3_decode_mb(s, mb_type)) {
                av_log(h->avctx, AV_LOG_ERROR,
                       "error while decoding MB %d %d\n", h->mb_x, h->mb_y);
1249 1250
                return -1;
            }
M
Michael Niedermayer 已提交
1251

D
Diego Biurrun 已提交
1252 1253
            if (mb_type != 0)
                ff_h264_hl_decode_mb(h);
M
Michael Niedermayer 已提交
1254

A
Anton Khirnov 已提交
1255
            if (h->pict_type != AV_PICTURE_TYPE_B && !h->low_delay)
1256
                h->cur_pic.mb_type[h->mb_x + h->mb_y * h->mb_stride] =
A
Anton Khirnov 已提交
1257
                    (h->pict_type == AV_PICTURE_TYPE_P && mb_type < 8) ? (mb_type - 1) : -1;
1258
        }
1259

1260 1261
        ff_draw_horiz_band(avctx, NULL, s->cur_pic, s->last_pic->f.data[0] ? s->last_pic : NULL,
                           16 * h->mb_y, 16, h->picture_structure, 0, 0,
A
Anton Khirnov 已提交
1262
                           h->low_delay, h->mb_height * 16, h->mb_width * 16);
M
Michael Niedermayer 已提交
1263
    }
M
Michael Niedermayer 已提交
1264

A
Anton Khirnov 已提交
1265
    if (h->pict_type == AV_PICTURE_TYPE_B || h->low_delay)
1266 1267 1268 1269 1270
        ret = av_frame_ref(data, &s->cur_pic->f);
    else if (s->last_pic->f.data[0])
        ret = av_frame_ref(data, &s->last_pic->f);
    if (ret < 0)
        return ret;
1271

1272
    /* Do not output the last pic after seeking. */
A
Anton Khirnov 已提交
1273
    if (s->last_pic->f.data[0] || h->low_delay)
1274
        *got_frame = 1;
1275

A
Anton Khirnov 已提交
1276 1277
    if (h->pict_type != AV_PICTURE_TYPE_B) {
        FFSWAP(Picture*, s->cur_pic, s->next_pic);
1278 1279
    } else {
        av_frame_unref(&s->cur_pic->f);
A
Anton Khirnov 已提交
1280 1281
    }

1282
    return buf_size;
M
Michael Niedermayer 已提交
1283 1284
}

1285
static av_cold int svq3_decode_end(AVCodecContext *avctx)
1286
{
A
Anton Khirnov 已提交
1287 1288
    SVQ3Context *s = avctx->priv_data;
    H264Context *h = &s->h;
1289

A
Anton Khirnov 已提交
1290 1291 1292
    free_picture(avctx, s->cur_pic);
    free_picture(avctx, s->next_pic);
    free_picture(avctx, s->last_pic);
1293 1294 1295 1296 1297
    av_freep(&s->cur_pic);
    av_freep(&s->next_pic);
    av_freep(&s->last_pic);

    av_frame_unref(&h->cur_pic.f);
1298

A
Anton Khirnov 已提交
1299
    ff_h264_free_context(h);
1300 1301 1302

    return 0;
}
M
Michael Niedermayer 已提交
1303

1304
AVCodec ff_svq3_decoder = {
1305 1306
    .name           = "svq3",
    .type           = AVMEDIA_TYPE_VIDEO,
1307
    .id             = AV_CODEC_ID_SVQ3,
1308 1309 1310 1311
    .priv_data_size = sizeof(SVQ3Context),
    .init           = svq3_decode_init,
    .close          = svq3_decode_end,
    .decode         = svq3_decode_frame,
D
Diego Biurrun 已提交
1312 1313
    .capabilities   = CODEC_CAP_DRAW_HORIZ_BAND |
                      CODEC_CAP_DR1             |
1314 1315
                      CODEC_CAP_DELAY,
    .long_name      = NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 3 / Sorenson Video 3 / SVQ3"),
D
Diego Biurrun 已提交
1316 1317
    .pix_fmts       = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUVJ420P,
                                                     AV_PIX_FMT_NONE},
M
Michael Niedermayer 已提交
1318
};