2
* VC-1 and WMV3 decoder
3
* Copyright (c) 2006-2007 Konstantin Shishkov
4
* Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
6
* This file is part of FFmpeg.
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.
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.
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
25
* VC-1 and WMV3 decoder
31
#include "mpegvideo.h"
35
#include "vc1acdata.h"
36
#include "msmpeg4data.h"
38
#include "simple_idct.h"
40
#include "vdpau_internal.h"
45
#define MB_INTRA_VLC_BITS 9
48
static const uint16_t table_mb_intra[64][2];
51
static const uint16_t vlc_offs[] = {
52
0, 520, 552, 616, 1128, 1160, 1224, 1740, 1772, 1836, 1900, 2436,
53
2986, 3050, 3610, 4154, 4218, 4746, 5326, 5390, 5902, 6554, 7658, 8620,
54
9262, 10202, 10756, 11310, 12228, 15078
58
* Init VC-1 specific tables and VC1Context members
59
* @param v The VC1Context to initialize
62
static int vc1_init_common(VC1Context *v)
66
static VLC_TYPE vlc_table[15078][2];
68
v->hrd_rate = v->hrd_buffer = NULL;
73
INIT_VLC_STATIC(&ff_vc1_bfraction_vlc, VC1_BFRACTION_VLC_BITS, 23,
74
ff_vc1_bfraction_bits, 1, 1,
75
ff_vc1_bfraction_codes, 1, 1, 1 << VC1_BFRACTION_VLC_BITS);
76
INIT_VLC_STATIC(&ff_vc1_norm2_vlc, VC1_NORM2_VLC_BITS, 4,
77
ff_vc1_norm2_bits, 1, 1,
78
ff_vc1_norm2_codes, 1, 1, 1 << VC1_NORM2_VLC_BITS);
79
INIT_VLC_STATIC(&ff_vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 64,
80
ff_vc1_norm6_bits, 1, 1,
81
ff_vc1_norm6_codes, 2, 2, 556);
82
INIT_VLC_STATIC(&ff_vc1_imode_vlc, VC1_IMODE_VLC_BITS, 7,
83
ff_vc1_imode_bits, 1, 1,
84
ff_vc1_imode_codes, 1, 1, 1 << VC1_IMODE_VLC_BITS);
87
ff_vc1_ttmb_vlc[i].table = &vlc_table[vlc_offs[i*3+0]];
88
ff_vc1_ttmb_vlc[i].table_allocated = vlc_offs[i*3+1] - vlc_offs[i*3+0];
89
init_vlc(&ff_vc1_ttmb_vlc[i], VC1_TTMB_VLC_BITS, 16,
90
ff_vc1_ttmb_bits[i], 1, 1,
91
ff_vc1_ttmb_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
92
ff_vc1_ttblk_vlc[i].table = &vlc_table[vlc_offs[i*3+1]];
93
ff_vc1_ttblk_vlc[i].table_allocated = vlc_offs[i*3+2] - vlc_offs[i*3+1];
94
init_vlc(&ff_vc1_ttblk_vlc[i], VC1_TTBLK_VLC_BITS, 8,
95
ff_vc1_ttblk_bits[i], 1, 1,
96
ff_vc1_ttblk_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
97
ff_vc1_subblkpat_vlc[i].table = &vlc_table[vlc_offs[i*3+2]];
98
ff_vc1_subblkpat_vlc[i].table_allocated = vlc_offs[i*3+3] - vlc_offs[i*3+2];
99
init_vlc(&ff_vc1_subblkpat_vlc[i], VC1_SUBBLKPAT_VLC_BITS, 15,
100
ff_vc1_subblkpat_bits[i], 1, 1,
101
ff_vc1_subblkpat_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
105
ff_vc1_4mv_block_pattern_vlc[i].table = &vlc_table[vlc_offs[i*3+9]];
106
ff_vc1_4mv_block_pattern_vlc[i].table_allocated = vlc_offs[i*3+10] - vlc_offs[i*3+9];
107
init_vlc(&ff_vc1_4mv_block_pattern_vlc[i], VC1_4MV_BLOCK_PATTERN_VLC_BITS, 16,
108
ff_vc1_4mv_block_pattern_bits[i], 1, 1,
109
ff_vc1_4mv_block_pattern_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
110
ff_vc1_cbpcy_p_vlc[i].table = &vlc_table[vlc_offs[i*3+10]];
111
ff_vc1_cbpcy_p_vlc[i].table_allocated = vlc_offs[i*3+11] - vlc_offs[i*3+10];
112
init_vlc(&ff_vc1_cbpcy_p_vlc[i], VC1_CBPCY_P_VLC_BITS, 64,
113
ff_vc1_cbpcy_p_bits[i], 1, 1,
114
ff_vc1_cbpcy_p_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
115
ff_vc1_mv_diff_vlc[i].table = &vlc_table[vlc_offs[i*3+11]];
116
ff_vc1_mv_diff_vlc[i].table_allocated = vlc_offs[i*3+12] - vlc_offs[i*3+11];
117
init_vlc(&ff_vc1_mv_diff_vlc[i], VC1_MV_DIFF_VLC_BITS, 73,
118
ff_vc1_mv_diff_bits[i], 1, 1,
119
ff_vc1_mv_diff_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
122
ff_vc1_ac_coeff_table[i].table = &vlc_table[vlc_offs[i+21]];
123
ff_vc1_ac_coeff_table[i].table_allocated = vlc_offs[i+22] - vlc_offs[i+21];
124
init_vlc(&ff_vc1_ac_coeff_table[i], AC_VLC_BITS, vc1_ac_sizes[i],
125
&vc1_ac_tables[i][0][1], 8, 4,
126
&vc1_ac_tables[i][0][0], 8, 4, INIT_VLC_USE_NEW_STATIC);
133
v->mvrange = 0; /* 7.1.1.18, p80 */
138
/***********************************************************************/
140
* @defgroup vc1bitplane VC-1 Bitplane decoding
158
/** @} */ //imode defines
161
/** @} */ //Bitplane group
163
static void vc1_loop_filter_iblk(MpegEncContext *s, int pq)
166
if (!s->first_slice_line) {
167
s->dsp.vc1_v_loop_filter16(s->dest[0], s->linesize, pq);
169
s->dsp.vc1_h_loop_filter16(s->dest[0] - 16*s->linesize, s->linesize, pq);
170
s->dsp.vc1_h_loop_filter16(s->dest[0] - 16*s->linesize+8, s->linesize, pq);
171
for(j = 0; j < 2; j++){
172
s->dsp.vc1_v_loop_filter8(s->dest[j+1], s->uvlinesize, pq);
174
s->dsp.vc1_h_loop_filter8(s->dest[j+1]-8*s->uvlinesize, s->uvlinesize, pq);
177
s->dsp.vc1_v_loop_filter16(s->dest[0] + 8*s->linesize, s->linesize, pq);
179
if (s->mb_y == s->mb_height-1) {
181
s->dsp.vc1_h_loop_filter16(s->dest[0], s->linesize, pq);
182
s->dsp.vc1_h_loop_filter8(s->dest[1], s->uvlinesize, pq);
183
s->dsp.vc1_h_loop_filter8(s->dest[2], s->uvlinesize, pq);
185
s->dsp.vc1_h_loop_filter16(s->dest[0] + 8, s->linesize, pq);
189
/** Put block onto picture
191
static void vc1_put_block(VC1Context *v, DCTELEM block[6][64])
195
DSPContext *dsp = &v->s.dsp;
199
for(k = 0; k < 6; k++)
200
for(j = 0; j < 8; j++)
201
for(i = 0; i < 8; i++)
202
block[k][i + j*8] = ((block[k][i + j*8] - 128) << 1) + 128;
205
ys = v->s.current_picture.linesize[0];
206
us = v->s.current_picture.linesize[1];
207
vs = v->s.current_picture.linesize[2];
210
dsp->put_pixels_clamped(block[0], Y, ys);
211
dsp->put_pixels_clamped(block[1], Y + 8, ys);
213
dsp->put_pixels_clamped(block[2], Y, ys);
214
dsp->put_pixels_clamped(block[3], Y + 8, ys);
216
if(!(v->s.flags & CODEC_FLAG_GRAY)) {
217
dsp->put_pixels_clamped(block[4], v->s.dest[1], us);
218
dsp->put_pixels_clamped(block[5], v->s.dest[2], vs);
222
/** Do motion compensation over 1 macroblock
223
* Mostly adapted hpel_motion and qpel_motion from mpegvideo.c
225
static void vc1_mc_1mv(VC1Context *v, int dir)
227
MpegEncContext *s = &v->s;
228
DSPContext *dsp = &v->s.dsp;
229
uint8_t *srcY, *srcU, *srcV;
230
int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
232
if(!v->s.last_picture.data[0])return;
234
mx = s->mv[dir][0][0];
235
my = s->mv[dir][0][1];
237
// store motion vectors for further use in B frames
238
if(s->pict_type == FF_P_TYPE) {
239
s->current_picture.motion_val[1][s->block_index[0]][0] = mx;
240
s->current_picture.motion_val[1][s->block_index[0]][1] = my;
242
uvmx = (mx + ((mx & 3) == 3)) >> 1;
243
uvmy = (my + ((my & 3) == 3)) >> 1;
245
uvmx = uvmx + ((uvmx<0)?(uvmx&1):-(uvmx&1));
246
uvmy = uvmy + ((uvmy<0)?(uvmy&1):-(uvmy&1));
249
srcY = s->last_picture.data[0];
250
srcU = s->last_picture.data[1];
251
srcV = s->last_picture.data[2];
253
srcY = s->next_picture.data[0];
254
srcU = s->next_picture.data[1];
255
srcV = s->next_picture.data[2];
258
src_x = s->mb_x * 16 + (mx >> 2);
259
src_y = s->mb_y * 16 + (my >> 2);
260
uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
261
uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
263
if(v->profile != PROFILE_ADVANCED){
264
src_x = av_clip( src_x, -16, s->mb_width * 16);
265
src_y = av_clip( src_y, -16, s->mb_height * 16);
266
uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);
267
uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);
269
src_x = av_clip( src_x, -17, s->avctx->coded_width);
270
src_y = av_clip( src_y, -18, s->avctx->coded_height + 1);
271
uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
272
uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
275
srcY += src_y * s->linesize + src_x;
276
srcU += uvsrc_y * s->uvlinesize + uvsrc_x;
277
srcV += uvsrc_y * s->uvlinesize + uvsrc_x;
279
/* for grayscale we should not try to read from unknown area */
280
if(s->flags & CODEC_FLAG_GRAY) {
281
srcU = s->edge_emu_buffer + 18 * s->linesize;
282
srcV = s->edge_emu_buffer + 18 * s->linesize;
285
if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
286
|| (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 16 - s->mspel*3
287
|| (unsigned)(src_y - s->mspel) > s->v_edge_pos - (my&3) - 16 - s->mspel*3){
288
uint8_t *uvbuf= s->edge_emu_buffer + 19 * s->linesize;
290
srcY -= s->mspel * (1 + s->linesize);
291
ff_emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 17+s->mspel*2, 17+s->mspel*2,
292
src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, s->v_edge_pos);
293
srcY = s->edge_emu_buffer;
294
ff_emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8+1, 8+1,
295
uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
296
ff_emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8+1, 8+1,
297
uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
300
/* if we deal with range reduction we need to scale source blocks */
306
for(j = 0; j < 17 + s->mspel*2; j++) {
307
for(i = 0; i < 17 + s->mspel*2; i++) src[i] = ((src[i] - 128) >> 1) + 128;
310
src = srcU; src2 = srcV;
311
for(j = 0; j < 9; j++) {
312
for(i = 0; i < 9; i++) {
313
src[i] = ((src[i] - 128) >> 1) + 128;
314
src2[i] = ((src2[i] - 128) >> 1) + 128;
316
src += s->uvlinesize;
317
src2 += s->uvlinesize;
320
/* if we deal with intensity compensation we need to scale source blocks */
321
if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
326
for(j = 0; j < 17 + s->mspel*2; j++) {
327
for(i = 0; i < 17 + s->mspel*2; i++) src[i] = v->luty[src[i]];
330
src = srcU; src2 = srcV;
331
for(j = 0; j < 9; j++) {
332
for(i = 0; i < 9; i++) {
333
src[i] = v->lutuv[src[i]];
334
src2[i] = v->lutuv[src2[i]];
336
src += s->uvlinesize;
337
src2 += s->uvlinesize;
340
srcY += s->mspel * (1 + s->linesize);
344
dxy = ((my & 3) << 2) | (mx & 3);
345
dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] , srcY , s->linesize, v->rnd);
346
dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8, srcY + 8, s->linesize, v->rnd);
347
srcY += s->linesize * 8;
348
dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize , srcY , s->linesize, v->rnd);
349
dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize + 8, srcY + 8, s->linesize, v->rnd);
350
} else { // hpel mc - always used for luma
351
dxy = (my & 2) | ((mx & 2) >> 1);
354
dsp->put_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
356
dsp->put_no_rnd_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
359
if(s->flags & CODEC_FLAG_GRAY) return;
360
/* Chroma MC always uses qpel bilinear */
364
dsp->put_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
365
dsp->put_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
367
dsp->put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
368
dsp->put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
372
/** Do motion compensation for 4-MV macroblock - luminance block
374
static void vc1_mc_4mv_luma(VC1Context *v, int n)
376
MpegEncContext *s = &v->s;
377
DSPContext *dsp = &v->s.dsp;
379
int dxy, mx, my, src_x, src_y;
382
if(!v->s.last_picture.data[0])return;
385
srcY = s->last_picture.data[0];
387
off = s->linesize * 4 * (n&2) + (n&1) * 8;
389
src_x = s->mb_x * 16 + (n&1) * 8 + (mx >> 2);
390
src_y = s->mb_y * 16 + (n&2) * 4 + (my >> 2);
392
if(v->profile != PROFILE_ADVANCED){
393
src_x = av_clip( src_x, -16, s->mb_width * 16);
394
src_y = av_clip( src_y, -16, s->mb_height * 16);
396
src_x = av_clip( src_x, -17, s->avctx->coded_width);
397
src_y = av_clip( src_y, -18, s->avctx->coded_height + 1);
400
srcY += src_y * s->linesize + src_x;
402
if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
403
|| (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 8 - s->mspel*2
404
|| (unsigned)(src_y - s->mspel) > s->v_edge_pos - (my&3) - 8 - s->mspel*2){
405
srcY -= s->mspel * (1 + s->linesize);
406
ff_emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 9+s->mspel*2, 9+s->mspel*2,
407
src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, s->v_edge_pos);
408
srcY = s->edge_emu_buffer;
409
/* if we deal with range reduction we need to scale source blocks */
415
for(j = 0; j < 9 + s->mspel*2; j++) {
416
for(i = 0; i < 9 + s->mspel*2; i++) src[i] = ((src[i] - 128) >> 1) + 128;
420
/* if we deal with intensity compensation we need to scale source blocks */
421
if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
426
for(j = 0; j < 9 + s->mspel*2; j++) {
427
for(i = 0; i < 9 + s->mspel*2; i++) src[i] = v->luty[src[i]];
431
srcY += s->mspel * (1 + s->linesize);
435
dxy = ((my & 3) << 2) | (mx & 3);
436
dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize, v->rnd);
437
} else { // hpel mc - always used for luma
438
dxy = (my & 2) | ((mx & 2) >> 1);
440
dsp->put_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);
442
dsp->put_no_rnd_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);
446
static inline int median4(int a, int b, int c, int d)
449
if(c < d) return (FFMIN(b, d) + FFMAX(a, c)) / 2;
450
else return (FFMIN(b, c) + FFMAX(a, d)) / 2;
452
if(c < d) return (FFMIN(a, d) + FFMAX(b, c)) / 2;
453
else return (FFMIN(a, c) + FFMAX(b, d)) / 2;
458
/** Do motion compensation for 4-MV macroblock - both chroma blocks
460
static void vc1_mc_4mv_chroma(VC1Context *v)
462
MpegEncContext *s = &v->s;
463
DSPContext *dsp = &v->s.dsp;
464
uint8_t *srcU, *srcV;
465
int uvmx, uvmy, uvsrc_x, uvsrc_y;
466
int i, idx, tx = 0, ty = 0;
467
int mvx[4], mvy[4], intra[4];
468
static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
470
if(!v->s.last_picture.data[0])return;
471
if(s->flags & CODEC_FLAG_GRAY) return;
473
for(i = 0; i < 4; i++) {
474
mvx[i] = s->mv[0][i][0];
475
mvy[i] = s->mv[0][i][1];
476
intra[i] = v->mb_type[0][s->block_index[i]];
479
/* calculate chroma MV vector from four luma MVs */
480
idx = (intra[3] << 3) | (intra[2] << 2) | (intra[1] << 1) | intra[0];
481
if(!idx) { // all blocks are inter
482
tx = median4(mvx[0], mvx[1], mvx[2], mvx[3]);
483
ty = median4(mvy[0], mvy[1], mvy[2], mvy[3]);
484
} else if(count[idx] == 1) { // 3 inter blocks
487
tx = mid_pred(mvx[1], mvx[2], mvx[3]);
488
ty = mid_pred(mvy[1], mvy[2], mvy[3]);
491
tx = mid_pred(mvx[0], mvx[2], mvx[3]);
492
ty = mid_pred(mvy[0], mvy[2], mvy[3]);
495
tx = mid_pred(mvx[0], mvx[1], mvx[3]);
496
ty = mid_pred(mvy[0], mvy[1], mvy[3]);
499
tx = mid_pred(mvx[0], mvx[1], mvx[2]);
500
ty = mid_pred(mvy[0], mvy[1], mvy[2]);
503
} else if(count[idx] == 2) {
505
for(i=0; i<3;i++) if(!intra[i]) {t1 = i; break;}
506
for(i= t1+1; i<4; i++)if(!intra[i]) {t2 = i; break;}
507
tx = (mvx[t1] + mvx[t2]) / 2;
508
ty = (mvy[t1] + mvy[t2]) / 2;
510
s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
511
s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
512
return; //no need to do MC for inter blocks
515
s->current_picture.motion_val[1][s->block_index[0]][0] = tx;
516
s->current_picture.motion_val[1][s->block_index[0]][1] = ty;
517
uvmx = (tx + ((tx&3) == 3)) >> 1;
518
uvmy = (ty + ((ty&3) == 3)) >> 1;
520
uvmx = uvmx + ((uvmx<0)?(uvmx&1):-(uvmx&1));
521
uvmy = uvmy + ((uvmy<0)?(uvmy&1):-(uvmy&1));
524
uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
525
uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
527
if(v->profile != PROFILE_ADVANCED){
528
uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);
529
uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);
531
uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
532
uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
535
srcU = s->last_picture.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;
536
srcV = s->last_picture.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;
537
if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
538
|| (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 9
539
|| (unsigned)uvsrc_y > (s->v_edge_pos >> 1) - 9){
540
ff_emulated_edge_mc(s->edge_emu_buffer , srcU, s->uvlinesize, 8+1, 8+1,
541
uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
542
ff_emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize, 8+1, 8+1,
543
uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
544
srcU = s->edge_emu_buffer;
545
srcV = s->edge_emu_buffer + 16;
547
/* if we deal with range reduction we need to scale source blocks */
552
src = srcU; src2 = srcV;
553
for(j = 0; j < 9; j++) {
554
for(i = 0; i < 9; i++) {
555
src[i] = ((src[i] - 128) >> 1) + 128;
556
src2[i] = ((src2[i] - 128) >> 1) + 128;
558
src += s->uvlinesize;
559
src2 += s->uvlinesize;
562
/* if we deal with intensity compensation we need to scale source blocks */
563
if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
567
src = srcU; src2 = srcV;
568
for(j = 0; j < 9; j++) {
569
for(i = 0; i < 9; i++) {
570
src[i] = v->lutuv[src[i]];
571
src2[i] = v->lutuv[src2[i]];
573
src += s->uvlinesize;
574
src2 += s->uvlinesize;
579
/* Chroma MC always uses qpel bilinear */
583
dsp->put_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
584
dsp->put_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
586
dsp->put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
587
dsp->put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
591
/***********************************************************************/
593
* @defgroup vc1block VC-1 Block-level functions
594
* @see 7.1.4, p91 and 8.1.1.7, p(1)04
600
* @brief Get macroblock-level quantizer scale
602
#define GET_MQUANT() \
606
if (v->dqprofile == DQPROFILE_ALL_MBS) \
610
mquant = (get_bits1(gb)) ? v->altpq : v->pq; \
614
mqdiff = get_bits(gb, 3); \
615
if (mqdiff != 7) mquant = v->pq + mqdiff; \
616
else mquant = get_bits(gb, 5); \
619
if(v->dqprofile == DQPROFILE_SINGLE_EDGE) \
620
edges = 1 << v->dqsbedge; \
621
else if(v->dqprofile == DQPROFILE_DOUBLE_EDGES) \
622
edges = (3 << v->dqsbedge) % 15; \
623
else if(v->dqprofile == DQPROFILE_FOUR_EDGES) \
625
if((edges&1) && !s->mb_x) \
627
if((edges&2) && s->first_slice_line) \
629
if((edges&4) && s->mb_x == (s->mb_width - 1)) \
631
if((edges&8) && s->mb_y == (s->mb_height - 1)) \
636
* @def GET_MVDATA(_dmv_x, _dmv_y)
637
* @brief Get MV differentials
638
* @see MVDATA decoding from 8.3.5.2, p(1)20
639
* @param _dmv_x Horizontal differential for decoded MV
640
* @param _dmv_y Vertical differential for decoded MV
642
#define GET_MVDATA(_dmv_x, _dmv_y) \
643
index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index].table,\
644
VC1_MV_DIFF_VLC_BITS, 2); \
650
else mb_has_coeffs = 0; \
652
if (!index) { _dmv_x = _dmv_y = 0; } \
653
else if (index == 35) \
655
_dmv_x = get_bits(gb, v->k_x - 1 + s->quarter_sample); \
656
_dmv_y = get_bits(gb, v->k_y - 1 + s->quarter_sample); \
658
else if (index == 36) \
667
if (!s->quarter_sample && index1 == 5) val = 1; \
669
if(size_table[index1] - val > 0) \
670
val = get_bits(gb, size_table[index1] - val); \
672
sign = 0 - (val&1); \
673
_dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
676
if (!s->quarter_sample && index1 == 5) val = 1; \
678
if(size_table[index1] - val > 0) \
679
val = get_bits(gb, size_table[index1] - val); \
681
sign = 0 - (val&1); \
682
_dmv_y = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
685
/** Predict and set motion vector
687
static inline void vc1_pred_mv(MpegEncContext *s, int n, int dmv_x, int dmv_y, int mv1, int r_x, int r_y, uint8_t* is_intra)
689
int xy, wrap, off = 0;
694
/* scale MV difference to be quad-pel */
695
dmv_x <<= 1 - s->quarter_sample;
696
dmv_y <<= 1 - s->quarter_sample;
699
xy = s->block_index[n];
702
s->mv[0][n][0] = s->current_picture.motion_val[0][xy][0] = 0;
703
s->mv[0][n][1] = s->current_picture.motion_val[0][xy][1] = 0;
704
s->current_picture.motion_val[1][xy][0] = 0;
705
s->current_picture.motion_val[1][xy][1] = 0;
706
if(mv1) { /* duplicate motion data for 1-MV block */
707
s->current_picture.motion_val[0][xy + 1][0] = 0;
708
s->current_picture.motion_val[0][xy + 1][1] = 0;
709
s->current_picture.motion_val[0][xy + wrap][0] = 0;
710
s->current_picture.motion_val[0][xy + wrap][1] = 0;
711
s->current_picture.motion_val[0][xy + wrap + 1][0] = 0;
712
s->current_picture.motion_val[0][xy + wrap + 1][1] = 0;
713
s->current_picture.motion_val[1][xy + 1][0] = 0;
714
s->current_picture.motion_val[1][xy + 1][1] = 0;
715
s->current_picture.motion_val[1][xy + wrap][0] = 0;
716
s->current_picture.motion_val[1][xy + wrap][1] = 0;
717
s->current_picture.motion_val[1][xy + wrap + 1][0] = 0;
718
s->current_picture.motion_val[1][xy + wrap + 1][1] = 0;
723
C = s->current_picture.motion_val[0][xy - 1];
724
A = s->current_picture.motion_val[0][xy - wrap];
726
off = (s->mb_x == (s->mb_width - 1)) ? -1 : 2;
728
//in 4-MV mode different blocks have different B predictor position
731
off = (s->mb_x > 0) ? -1 : 1;
734
off = (s->mb_x == (s->mb_width - 1)) ? -1 : 1;
743
B = s->current_picture.motion_val[0][xy - wrap + off];
745
if(!s->first_slice_line || (n==2 || n==3)) { // predictor A is not out of bounds
746
if(s->mb_width == 1) {
750
px = mid_pred(A[0], B[0], C[0]);
751
py = mid_pred(A[1], B[1], C[1]);
753
} else if(s->mb_x || (n==1 || n==3)) { // predictor C is not out of bounds
759
/* Pullback MV as specified in 8.3.5.3.4 */
762
qx = (s->mb_x << 6) + ((n==1 || n==3) ? 32 : 0);
763
qy = (s->mb_y << 6) + ((n==2 || n==3) ? 32 : 0);
764
X = (s->mb_width << 6) - 4;
765
Y = (s->mb_height << 6) - 4;
767
if(qx + px < -60) px = -60 - qx;
768
if(qy + py < -60) py = -60 - qy;
770
if(qx + px < -28) px = -28 - qx;
771
if(qy + py < -28) py = -28 - qy;
773
if(qx + px > X) px = X - qx;
774
if(qy + py > Y) py = Y - qy;
776
/* Calculate hybrid prediction as specified in 8.3.5.3.5 */
777
if((!s->first_slice_line || (n==2 || n==3)) && (s->mb_x || (n==1 || n==3))) {
778
if(is_intra[xy - wrap])
779
sum = FFABS(px) + FFABS(py);
781
sum = FFABS(px - A[0]) + FFABS(py - A[1]);
783
if(get_bits1(&s->gb)) {
792
sum = FFABS(px) + FFABS(py);
794
sum = FFABS(px - C[0]) + FFABS(py - C[1]);
796
if(get_bits1(&s->gb)) {
806
/* store MV using signed modulus of MV range defined in 4.11 */
807
s->mv[0][n][0] = s->current_picture.motion_val[0][xy][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
808
s->mv[0][n][1] = s->current_picture.motion_val[0][xy][1] = ((py + dmv_y + r_y) & ((r_y << 1) - 1)) - r_y;
809
if(mv1) { /* duplicate motion data for 1-MV block */
810
s->current_picture.motion_val[0][xy + 1][0] = s->current_picture.motion_val[0][xy][0];
811
s->current_picture.motion_val[0][xy + 1][1] = s->current_picture.motion_val[0][xy][1];
812
s->current_picture.motion_val[0][xy + wrap][0] = s->current_picture.motion_val[0][xy][0];
813
s->current_picture.motion_val[0][xy + wrap][1] = s->current_picture.motion_val[0][xy][1];
814
s->current_picture.motion_val[0][xy + wrap + 1][0] = s->current_picture.motion_val[0][xy][0];
815
s->current_picture.motion_val[0][xy + wrap + 1][1] = s->current_picture.motion_val[0][xy][1];
819
/** Motion compensation for direct or interpolated blocks in B-frames
821
static void vc1_interp_mc(VC1Context *v)
823
MpegEncContext *s = &v->s;
824
DSPContext *dsp = &v->s.dsp;
825
uint8_t *srcY, *srcU, *srcV;
826
int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
828
if(!v->s.next_picture.data[0])return;
832
uvmx = (mx + ((mx & 3) == 3)) >> 1;
833
uvmy = (my + ((my & 3) == 3)) >> 1;
835
uvmx = uvmx + ((uvmx<0)?-(uvmx&1):(uvmx&1));
836
uvmy = uvmy + ((uvmy<0)?-(uvmy&1):(uvmy&1));
838
srcY = s->next_picture.data[0];
839
srcU = s->next_picture.data[1];
840
srcV = s->next_picture.data[2];
842
src_x = s->mb_x * 16 + (mx >> 2);
843
src_y = s->mb_y * 16 + (my >> 2);
844
uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
845
uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
847
if(v->profile != PROFILE_ADVANCED){
848
src_x = av_clip( src_x, -16, s->mb_width * 16);
849
src_y = av_clip( src_y, -16, s->mb_height * 16);
850
uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);
851
uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);
853
src_x = av_clip( src_x, -17, s->avctx->coded_width);
854
src_y = av_clip( src_y, -18, s->avctx->coded_height + 1);
855
uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
856
uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
859
srcY += src_y * s->linesize + src_x;
860
srcU += uvsrc_y * s->uvlinesize + uvsrc_x;
861
srcV += uvsrc_y * s->uvlinesize + uvsrc_x;
863
/* for grayscale we should not try to read from unknown area */
864
if(s->flags & CODEC_FLAG_GRAY) {
865
srcU = s->edge_emu_buffer + 18 * s->linesize;
866
srcV = s->edge_emu_buffer + 18 * s->linesize;
870
|| (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 16 - s->mspel*3
871
|| (unsigned)(src_y - s->mspel) > s->v_edge_pos - (my&3) - 16 - s->mspel*3){
872
uint8_t *uvbuf= s->edge_emu_buffer + 19 * s->linesize;
874
srcY -= s->mspel * (1 + s->linesize);
875
ff_emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 17+s->mspel*2, 17+s->mspel*2,
876
src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, s->v_edge_pos);
877
srcY = s->edge_emu_buffer;
878
ff_emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8+1, 8+1,
879
uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
880
ff_emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8+1, 8+1,
881
uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
884
/* if we deal with range reduction we need to scale source blocks */
890
for(j = 0; j < 17 + s->mspel*2; j++) {
891
for(i = 0; i < 17 + s->mspel*2; i++) src[i] = ((src[i] - 128) >> 1) + 128;
894
src = srcU; src2 = srcV;
895
for(j = 0; j < 9; j++) {
896
for(i = 0; i < 9; i++) {
897
src[i] = ((src[i] - 128) >> 1) + 128;
898
src2[i] = ((src2[i] - 128) >> 1) + 128;
900
src += s->uvlinesize;
901
src2 += s->uvlinesize;
904
srcY += s->mspel * (1 + s->linesize);
908
dxy = ((my & 3) << 2) | (mx & 3);
909
dsp->avg_vc1_mspel_pixels_tab[dxy](s->dest[0] , srcY , s->linesize, v->rnd);
910
dsp->avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8, srcY + 8, s->linesize, v->rnd);
911
srcY += s->linesize * 8;
912
dsp->avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize , srcY , s->linesize, v->rnd);
913
dsp->avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize + 8, srcY + 8, s->linesize, v->rnd);
915
dxy = (my & 2) | ((mx & 2) >> 1);
918
dsp->avg_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
920
dsp->avg_no_rnd_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
923
if(s->flags & CODEC_FLAG_GRAY) return;
924
/* Chroma MC always uses qpel blilinear */
928
dsp->avg_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
929
dsp->avg_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
931
dsp->avg_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
932
dsp->avg_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
936
static av_always_inline int scale_mv(int value, int bfrac, int inv, int qs)
940
#if B_FRACTION_DEN==256
944
return 2 * ((value * n + 255) >> 9);
945
return (value * n + 128) >> 8;
950
return 2 * ((value * n + B_FRACTION_DEN - 1) / (2 * B_FRACTION_DEN));
951
return (value * n + B_FRACTION_DEN/2) / B_FRACTION_DEN;
955
/** Reconstruct motion vector for B-frame and do motion compensation
957
static inline void vc1_b_mc(VC1Context *v, int dmv_x[2], int dmv_y[2], int direct, int mode)
960
v->mv_mode2 = v->mv_mode;
961
v->mv_mode = MV_PMODE_INTENSITY_COMP;
966
if(v->use_ic) v->mv_mode = v->mv_mode2;
969
if(mode == BMV_TYPE_INTERPOLATED) {
972
if(v->use_ic) v->mv_mode = v->mv_mode2;
976
if(v->use_ic && (mode == BMV_TYPE_BACKWARD)) v->mv_mode = v->mv_mode2;
977
vc1_mc_1mv(v, (mode == BMV_TYPE_BACKWARD));
978
if(v->use_ic) v->mv_mode = v->mv_mode2;
981
static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int direct, int mvtype)
983
MpegEncContext *s = &v->s;
984
int xy, wrap, off = 0;
989
const uint8_t *is_intra = v->mb_type[0];
993
/* scale MV difference to be quad-pel */
994
dmv_x[0] <<= 1 - s->quarter_sample;
995
dmv_y[0] <<= 1 - s->quarter_sample;
996
dmv_x[1] <<= 1 - s->quarter_sample;
997
dmv_y[1] <<= 1 - s->quarter_sample;
1000
xy = s->block_index[0];
1003
s->current_picture.motion_val[0][xy][0] =
1004
s->current_picture.motion_val[0][xy][1] =
1005
s->current_picture.motion_val[1][xy][0] =
1006
s->current_picture.motion_val[1][xy][1] = 0;
1009
s->mv[0][0][0] = scale_mv(s->next_picture.motion_val[1][xy][0], v->bfraction, 0, s->quarter_sample);
1010
s->mv[0][0][1] = scale_mv(s->next_picture.motion_val[1][xy][1], v->bfraction, 0, s->quarter_sample);
1011
s->mv[1][0][0] = scale_mv(s->next_picture.motion_val[1][xy][0], v->bfraction, 1, s->quarter_sample);
1012
s->mv[1][0][1] = scale_mv(s->next_picture.motion_val[1][xy][1], v->bfraction, 1, s->quarter_sample);
1014
/* Pullback predicted motion vectors as specified in 8.4.5.4 */
1015
s->mv[0][0][0] = av_clip(s->mv[0][0][0], -60 - (s->mb_x << 6), (s->mb_width << 6) - 4 - (s->mb_x << 6));
1016
s->mv[0][0][1] = av_clip(s->mv[0][0][1], -60 - (s->mb_y << 6), (s->mb_height << 6) - 4 - (s->mb_y << 6));
1017
s->mv[1][0][0] = av_clip(s->mv[1][0][0], -60 - (s->mb_x << 6), (s->mb_width << 6) - 4 - (s->mb_x << 6));
1018
s->mv[1][0][1] = av_clip(s->mv[1][0][1], -60 - (s->mb_y << 6), (s->mb_height << 6) - 4 - (s->mb_y << 6));
1020
s->current_picture.motion_val[0][xy][0] = s->mv[0][0][0];
1021
s->current_picture.motion_val[0][xy][1] = s->mv[0][0][1];
1022
s->current_picture.motion_val[1][xy][0] = s->mv[1][0][0];
1023
s->current_picture.motion_val[1][xy][1] = s->mv[1][0][1];
1027
if((mvtype == BMV_TYPE_FORWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) {
1028
C = s->current_picture.motion_val[0][xy - 2];
1029
A = s->current_picture.motion_val[0][xy - wrap*2];
1030
off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
1031
B = s->current_picture.motion_val[0][xy - wrap*2 + off];
1033
if(!s->mb_x) C[0] = C[1] = 0;
1034
if(!s->first_slice_line) { // predictor A is not out of bounds
1035
if(s->mb_width == 1) {
1039
px = mid_pred(A[0], B[0], C[0]);
1040
py = mid_pred(A[1], B[1], C[1]);
1042
} else if(s->mb_x) { // predictor C is not out of bounds
1048
/* Pullback MV as specified in 8.3.5.3.4 */
1051
if(v->profile < PROFILE_ADVANCED) {
1052
qx = (s->mb_x << 5);
1053
qy = (s->mb_y << 5);
1054
X = (s->mb_width << 5) - 4;
1055
Y = (s->mb_height << 5) - 4;
1056
if(qx + px < -28) px = -28 - qx;
1057
if(qy + py < -28) py = -28 - qy;
1058
if(qx + px > X) px = X - qx;
1059
if(qy + py > Y) py = Y - qy;
1061
qx = (s->mb_x << 6);
1062
qy = (s->mb_y << 6);
1063
X = (s->mb_width << 6) - 4;
1064
Y = (s->mb_height << 6) - 4;
1065
if(qx + px < -60) px = -60 - qx;
1066
if(qy + py < -60) py = -60 - qy;
1067
if(qx + px > X) px = X - qx;
1068
if(qy + py > Y) py = Y - qy;
1071
/* Calculate hybrid prediction as specified in 8.3.5.3.5 */
1072
if(0 && !s->first_slice_line && s->mb_x) {
1073
if(is_intra[xy - wrap])
1074
sum = FFABS(px) + FFABS(py);
1076
sum = FFABS(px - A[0]) + FFABS(py - A[1]);
1078
if(get_bits1(&s->gb)) {
1086
if(is_intra[xy - 2])
1087
sum = FFABS(px) + FFABS(py);
1089
sum = FFABS(px - C[0]) + FFABS(py - C[1]);
1091
if(get_bits1(&s->gb)) {
1101
/* store MV using signed modulus of MV range defined in 4.11 */
1102
s->mv[0][0][0] = ((px + dmv_x[0] + r_x) & ((r_x << 1) - 1)) - r_x;
1103
s->mv[0][0][1] = ((py + dmv_y[0] + r_y) & ((r_y << 1) - 1)) - r_y;
1105
if((mvtype == BMV_TYPE_BACKWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) {
1106
C = s->current_picture.motion_val[1][xy - 2];
1107
A = s->current_picture.motion_val[1][xy - wrap*2];
1108
off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
1109
B = s->current_picture.motion_val[1][xy - wrap*2 + off];
1111
if(!s->mb_x) C[0] = C[1] = 0;
1112
if(!s->first_slice_line) { // predictor A is not out of bounds
1113
if(s->mb_width == 1) {
1117
px = mid_pred(A[0], B[0], C[0]);
1118
py = mid_pred(A[1], B[1], C[1]);
1120
} else if(s->mb_x) { // predictor C is not out of bounds
1126
/* Pullback MV as specified in 8.3.5.3.4 */
1129
if(v->profile < PROFILE_ADVANCED) {
1130
qx = (s->mb_x << 5);
1131
qy = (s->mb_y << 5);
1132
X = (s->mb_width << 5) - 4;
1133
Y = (s->mb_height << 5) - 4;
1134
if(qx + px < -28) px = -28 - qx;
1135
if(qy + py < -28) py = -28 - qy;
1136
if(qx + px > X) px = X - qx;
1137
if(qy + py > Y) py = Y - qy;
1139
qx = (s->mb_x << 6);
1140
qy = (s->mb_y << 6);
1141
X = (s->mb_width << 6) - 4;
1142
Y = (s->mb_height << 6) - 4;
1143
if(qx + px < -60) px = -60 - qx;
1144
if(qy + py < -60) py = -60 - qy;
1145
if(qx + px > X) px = X - qx;
1146
if(qy + py > Y) py = Y - qy;
1149
/* Calculate hybrid prediction as specified in 8.3.5.3.5 */
1150
if(0 && !s->first_slice_line && s->mb_x) {
1151
if(is_intra[xy - wrap])
1152
sum = FFABS(px) + FFABS(py);
1154
sum = FFABS(px - A[0]) + FFABS(py - A[1]);
1156
if(get_bits1(&s->gb)) {
1164
if(is_intra[xy - 2])
1165
sum = FFABS(px) + FFABS(py);
1167
sum = FFABS(px - C[0]) + FFABS(py - C[1]);
1169
if(get_bits1(&s->gb)) {
1179
/* store MV using signed modulus of MV range defined in 4.11 */
1181
s->mv[1][0][0] = ((px + dmv_x[1] + r_x) & ((r_x << 1) - 1)) - r_x;
1182
s->mv[1][0][1] = ((py + dmv_y[1] + r_y) & ((r_y << 1) - 1)) - r_y;
1184
s->current_picture.motion_val[0][xy][0] = s->mv[0][0][0];
1185
s->current_picture.motion_val[0][xy][1] = s->mv[0][0][1];
1186
s->current_picture.motion_val[1][xy][0] = s->mv[1][0][0];
1187
s->current_picture.motion_val[1][xy][1] = s->mv[1][0][1];
1190
/** Get predicted DC value for I-frames only
1191
* prediction dir: left=0, top=1
1192
* @param s MpegEncContext
1193
* @param overlap flag indicating that overlap filtering is used
1194
* @param pq integer part of picture quantizer
1195
* @param[in] n block index in the current MB
1196
* @param dc_val_ptr Pointer to DC predictor
1197
* @param dir_ptr Prediction direction for use in AC prediction
1199
static inline int vc1_i_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
1200
int16_t **dc_val_ptr, int *dir_ptr)
1202
int a, b, c, wrap, pred, scale;
1204
static const uint16_t dcpred[32] = {
1205
-1, 1024, 512, 341, 256, 205, 171, 146, 128,
1206
114, 102, 93, 85, 79, 73, 68, 64,
1207
60, 57, 54, 51, 49, 47, 45, 43,
1208
41, 39, 38, 37, 35, 34, 33
1211
/* find prediction - wmv3_dc_scale always used here in fact */
1212
if (n < 4) scale = s->y_dc_scale;
1213
else scale = s->c_dc_scale;
1215
wrap = s->block_wrap[n];
1216
dc_val= s->dc_val[0] + s->block_index[n];
1222
b = dc_val[ - 1 - wrap];
1223
a = dc_val[ - wrap];
1225
if (pq < 9 || !overlap)
1227
/* Set outer values */
1228
if (s->first_slice_line && (n!=2 && n!=3)) b=a=dcpred[scale];
1229
if (s->mb_x == 0 && (n!=1 && n!=3)) b=c=dcpred[scale];
1233
/* Set outer values */
1234
if (s->first_slice_line && (n!=2 && n!=3)) b=a=0;
1235
if (s->mb_x == 0 && (n!=1 && n!=3)) b=c=0;
1238
if (abs(a - b) <= abs(b - c)) {
1246
/* update predictor */
1247
*dc_val_ptr = &dc_val[0];
1252
/** Get predicted DC value
1253
* prediction dir: left=0, top=1
1254
* @param s MpegEncContext
1255
* @param overlap flag indicating that overlap filtering is used
1256
* @param pq integer part of picture quantizer
1257
* @param[in] n block index in the current MB
1258
* @param a_avail flag indicating top block availability
1259
* @param c_avail flag indicating left block availability
1260
* @param dc_val_ptr Pointer to DC predictor
1261
* @param dir_ptr Prediction direction for use in AC prediction
1263
static inline int vc1_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
1264
int a_avail, int c_avail,
1265
int16_t **dc_val_ptr, int *dir_ptr)
1267
int a, b, c, wrap, pred;
1269
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
1272
wrap = s->block_wrap[n];
1273
dc_val= s->dc_val[0] + s->block_index[n];
1279
b = dc_val[ - 1 - wrap];
1280
a = dc_val[ - wrap];
1281
/* scale predictors if needed */
1282
q1 = s->current_picture.qscale_table[mb_pos];
1283
if(c_avail && (n!= 1 && n!=3)) {
1284
q2 = s->current_picture.qscale_table[mb_pos - 1];
1286
c = (c * s->y_dc_scale_table[q2] * ff_vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18;
1288
if(a_avail && (n!= 2 && n!=3)) {
1289
q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
1291
a = (a * s->y_dc_scale_table[q2] * ff_vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18;
1293
if(a_avail && c_avail && (n!=3)) {
1296
if(n != 2) off -= s->mb_stride;
1297
q2 = s->current_picture.qscale_table[off];
1299
b = (b * s->y_dc_scale_table[q2] * ff_vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18;
1302
if(a_avail && c_avail) {
1303
if(abs(a - b) <= abs(b - c)) {
1310
} else if(a_avail) {
1313
} else if(c_avail) {
1321
/* update predictor */
1322
*dc_val_ptr = &dc_val[0];
1326
/** @} */ // Block group
1329
* @defgroup vc1_std_mb VC1 Macroblock-level functions in Simple/Main Profiles
1330
* @see 7.1.4, p91 and 8.1.1.7, p(1)04
1334
static inline int vc1_coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr)
1336
int xy, wrap, pred, a, b, c;
1338
xy = s->block_index[n];
1339
wrap = s->b8_stride;
1344
a = s->coded_block[xy - 1 ];
1345
b = s->coded_block[xy - 1 - wrap];
1346
c = s->coded_block[xy - wrap];
1355
*coded_block_ptr = &s->coded_block[xy];
1361
* Decode one AC coefficient
1362
* @param v The VC1 context
1363
* @param last Last coefficient
1364
* @param skip How much zero coefficients to skip
1365
* @param value Decoded AC coefficient value
1366
* @param codingset set of VLC to decode data
1369
static void vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip, int *value, int codingset)
1371
GetBitContext *gb = &v->s.gb;
1372
int index, escape, run = 0, level = 0, lst = 0;
1374
index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
1375
if (index != vc1_ac_sizes[codingset] - 1) {
1376
run = vc1_index_decode_table[codingset][index][0];
1377
level = vc1_index_decode_table[codingset][index][1];
1378
lst = index >= vc1_last_decode_table[codingset];
1382
escape = decode210(gb);
1384
index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
1385
run = vc1_index_decode_table[codingset][index][0];
1386
level = vc1_index_decode_table[codingset][index][1];
1387
lst = index >= vc1_last_decode_table[codingset];
1390
level += vc1_last_delta_level_table[codingset][run];
1392
level += vc1_delta_level_table[codingset][run];
1395
run += vc1_last_delta_run_table[codingset][level] + 1;
1397
run += vc1_delta_run_table[codingset][level] + 1;
1403
lst = get_bits1(gb);
1404
if(v->s.esc3_level_length == 0) {
1405
if(v->pq < 8 || v->dquantfrm) { // table 59
1406
v->s.esc3_level_length = get_bits(gb, 3);
1407
if(!v->s.esc3_level_length)
1408
v->s.esc3_level_length = get_bits(gb, 2) + 8;
1410
v->s.esc3_level_length = get_unary(gb, 1, 6) + 2;
1412
v->s.esc3_run_length = 3 + get_bits(gb, 2);
1414
run = get_bits(gb, v->s.esc3_run_length);
1415
sign = get_bits1(gb);
1416
level = get_bits(gb, v->s.esc3_level_length);
1427
/** Decode intra block in intra frames - should be faster than decode_intra_block
1428
* @param v VC1Context
1429
* @param block block to decode
1430
* @param[in] n subblock index
1431
* @param coded are AC coeffs present or not
1432
* @param codingset set of VLC to decode data
1434
static int vc1_decode_i_block(VC1Context *v, DCTELEM block[64], int n, int coded, int codingset)
1436
GetBitContext *gb = &v->s.gb;
1437
MpegEncContext *s = &v->s;
1438
int dc_pred_dir = 0; /* Direction of the DC prediction used */
1441
int16_t *ac_val, *ac_val2;
1444
/* Get DC differential */
1446
dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
1448
dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
1451
av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
1456
if (dcdiff == 119 /* ESC index value */)
1458
/* TODO: Optimize */
1459
if (v->pq == 1) dcdiff = get_bits(gb, 10);
1460
else if (v->pq == 2) dcdiff = get_bits(gb, 9);
1461
else dcdiff = get_bits(gb, 8);
1466
dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
1467
else if (v->pq == 2)
1468
dcdiff = (dcdiff<<1) + get_bits1(gb) - 1;
1475
dcdiff += vc1_i_pred_dc(&v->s, v->overlap, v->pq, n, &dc_val, &dc_pred_dir);
1478
/* Store the quantized DC coeff, used for prediction */
1480
block[0] = dcdiff * s->y_dc_scale;
1482
block[0] = dcdiff * s->c_dc_scale;
1493
int last = 0, skip, value;
1494
const uint8_t *zz_table;
1498
scale = v->pq * 2 + v->halfpq;
1502
zz_table = wmv1_scantable[2];
1504
zz_table = wmv1_scantable[3];
1506
zz_table = wmv1_scantable[1];
1508
ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
1510
if(dc_pred_dir) //left
1513
ac_val -= 16 * s->block_wrap[n];
1516
vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
1520
block[zz_table[i++]] = value;
1523
/* apply AC prediction if needed */
1525
if(dc_pred_dir) { //left
1526
for(k = 1; k < 8; k++)
1527
block[k << 3] += ac_val[k];
1529
for(k = 1; k < 8; k++)
1530
block[k] += ac_val[k + 8];
1533
/* save AC coeffs for further prediction */
1534
for(k = 1; k < 8; k++) {
1535
ac_val2[k] = block[k << 3];
1536
ac_val2[k + 8] = block[k];
1539
/* scale AC coeffs */
1540
for(k = 1; k < 64; k++)
1544
block[k] += (block[k] < 0) ? -v->pq : v->pq;
1547
if(s->ac_pred) i = 63;
1553
ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
1557
scale = v->pq * 2 + v->halfpq;
1558
memset(ac_val2, 0, 16 * 2);
1559
if(dc_pred_dir) {//left
1562
memcpy(ac_val2, ac_val, 8 * 2);
1564
ac_val -= 16 * s->block_wrap[n];
1566
memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
1569
/* apply AC prediction if needed */
1571
if(dc_pred_dir) { //left
1572
for(k = 1; k < 8; k++) {
1573
block[k << 3] = ac_val[k] * scale;
1574
if(!v->pquantizer && block[k << 3])
1575
block[k << 3] += (block[k << 3] < 0) ? -v->pq : v->pq;
1578
for(k = 1; k < 8; k++) {
1579
block[k] = ac_val[k + 8] * scale;
1580
if(!v->pquantizer && block[k])
1581
block[k] += (block[k] < 0) ? -v->pq : v->pq;
1587
s->block_last_index[n] = i;
1592
/** Decode intra block in intra frames - should be faster than decode_intra_block
1593
* @param v VC1Context
1594
* @param block block to decode
1595
* @param[in] n subblock number
1596
* @param coded are AC coeffs present or not
1597
* @param codingset set of VLC to decode data
1598
* @param mquant quantizer value for this macroblock
1600
static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n, int coded, int codingset, int mquant)
1602
GetBitContext *gb = &v->s.gb;
1603
MpegEncContext *s = &v->s;
1604
int dc_pred_dir = 0; /* Direction of the DC prediction used */
1607
int16_t *ac_val, *ac_val2;
1609
int a_avail = v->a_avail, c_avail = v->c_avail;
1610
int use_pred = s->ac_pred;
1613
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
1615
/* Get DC differential */
1617
dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
1619
dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
1622
av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
1627
if (dcdiff == 119 /* ESC index value */)
1629
/* TODO: Optimize */
1630
if (mquant == 1) dcdiff = get_bits(gb, 10);
1631
else if (mquant == 2) dcdiff = get_bits(gb, 9);
1632
else dcdiff = get_bits(gb, 8);
1637
dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
1638
else if (mquant == 2)
1639
dcdiff = (dcdiff<<1) + get_bits1(gb) - 1;
1646
dcdiff += vc1_pred_dc(&v->s, v->overlap, mquant, n, v->a_avail, v->c_avail, &dc_val, &dc_pred_dir);
1649
/* Store the quantized DC coeff, used for prediction */
1651
block[0] = dcdiff * s->y_dc_scale;
1653
block[0] = dcdiff * s->c_dc_scale;
1659
/* check if AC is needed at all */
1660
if(!a_avail && !c_avail) use_pred = 0;
1661
ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
1664
scale = mquant * 2 + ((mquant == v->pq) ? v->halfpq : 0);
1666
if(dc_pred_dir) //left
1669
ac_val -= 16 * s->block_wrap[n];
1671
q1 = s->current_picture.qscale_table[mb_pos];
1672
if(dc_pred_dir && c_avail && mb_pos) q2 = s->current_picture.qscale_table[mb_pos - 1];
1673
if(!dc_pred_dir && a_avail && mb_pos >= s->mb_stride) q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
1674
if(dc_pred_dir && n==1) q2 = q1;
1675
if(!dc_pred_dir && n==2) q2 = q1;
1679
int last = 0, skip, value;
1680
const uint8_t *zz_table;
1685
zz_table = wmv1_scantable[2];
1687
zz_table = wmv1_scantable[3];
1689
zz_table = wmv1_scantable[1];
1692
vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
1696
block[zz_table[i++]] = value;
1699
/* apply AC prediction if needed */
1701
/* scale predictors if needed*/
1703
q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
1704
q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
1706
if(dc_pred_dir) { //left
1707
for(k = 1; k < 8; k++)
1708
block[k << 3] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
1710
for(k = 1; k < 8; k++)
1711
block[k] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
1714
if(dc_pred_dir) { //left
1715
for(k = 1; k < 8; k++)
1716
block[k << 3] += ac_val[k];
1718
for(k = 1; k < 8; k++)
1719
block[k] += ac_val[k + 8];
1723
/* save AC coeffs for further prediction */
1724
for(k = 1; k < 8; k++) {
1725
ac_val2[k] = block[k << 3];
1726
ac_val2[k + 8] = block[k];
1729
/* scale AC coeffs */
1730
for(k = 1; k < 64; k++)
1734
block[k] += (block[k] < 0) ? -mquant : mquant;
1737
if(use_pred) i = 63;
1738
} else { // no AC coeffs
1741
memset(ac_val2, 0, 16 * 2);
1742
if(dc_pred_dir) {//left
1744
memcpy(ac_val2, ac_val, 8 * 2);
1746
q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
1747
q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
1748
for(k = 1; k < 8; k++)
1749
ac_val2[k] = (ac_val2[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
1754
memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
1756
q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
1757
q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
1758
for(k = 1; k < 8; k++)
1759
ac_val2[k + 8] = (ac_val2[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
1764
/* apply AC prediction if needed */
1766
if(dc_pred_dir) { //left
1767
for(k = 1; k < 8; k++) {
1768
block[k << 3] = ac_val2[k] * scale;
1769
if(!v->pquantizer && block[k << 3])
1770
block[k << 3] += (block[k << 3] < 0) ? -mquant : mquant;
1773
for(k = 1; k < 8; k++) {
1774
block[k] = ac_val2[k + 8] * scale;
1775
if(!v->pquantizer && block[k])
1776
block[k] += (block[k] < 0) ? -mquant : mquant;
1782
s->block_last_index[n] = i;
1787
/** Decode intra block in inter frames - more generic version than vc1_decode_i_block
1788
* @param v VC1Context
1789
* @param block block to decode
1790
* @param[in] n subblock index
1791
* @param coded are AC coeffs present or not
1792
* @param mquant block quantizer
1793
* @param codingset set of VLC to decode data
1795
static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, int coded, int mquant, int codingset)
1797
GetBitContext *gb = &v->s.gb;
1798
MpegEncContext *s = &v->s;
1799
int dc_pred_dir = 0; /* Direction of the DC prediction used */
1802
int16_t *ac_val, *ac_val2;
1804
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
1805
int a_avail = v->a_avail, c_avail = v->c_avail;
1806
int use_pred = s->ac_pred;
1810
s->dsp.clear_block(block);
1812
/* XXX: Guard against dumb values of mquant */
1813
mquant = (mquant < 1) ? 0 : ( (mquant>31) ? 31 : mquant );
1815
/* Set DC scale - y and c use the same */
1816
s->y_dc_scale = s->y_dc_scale_table[mquant];
1817
s->c_dc_scale = s->c_dc_scale_table[mquant];
1819
/* Get DC differential */
1821
dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
1823
dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
1826
av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
1831
if (dcdiff == 119 /* ESC index value */)
1833
/* TODO: Optimize */
1834
if (mquant == 1) dcdiff = get_bits(gb, 10);
1835
else if (mquant == 2) dcdiff = get_bits(gb, 9);
1836
else dcdiff = get_bits(gb, 8);
1841
dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
1842
else if (mquant == 2)
1843
dcdiff = (dcdiff<<1) + get_bits1(gb) - 1;
1850
dcdiff += vc1_pred_dc(&v->s, v->overlap, mquant, n, a_avail, c_avail, &dc_val, &dc_pred_dir);
1853
/* Store the quantized DC coeff, used for prediction */
1856
block[0] = dcdiff * s->y_dc_scale;
1858
block[0] = dcdiff * s->c_dc_scale;
1864
/* check if AC is needed at all and adjust direction if needed */
1865
if(!a_avail) dc_pred_dir = 1;
1866
if(!c_avail) dc_pred_dir = 0;
1867
if(!a_avail && !c_avail) use_pred = 0;
1868
ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
1871
scale = mquant * 2 + v->halfpq;
1873
if(dc_pred_dir) //left
1876
ac_val -= 16 * s->block_wrap[n];
1878
q1 = s->current_picture.qscale_table[mb_pos];
1879
if(dc_pred_dir && c_avail && mb_pos) q2 = s->current_picture.qscale_table[mb_pos - 1];
1880
if(!dc_pred_dir && a_avail && mb_pos >= s->mb_stride) q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
1881
if(dc_pred_dir && n==1) q2 = q1;
1882
if(!dc_pred_dir && n==2) q2 = q1;
1886
int last = 0, skip, value;
1887
const uint8_t *zz_table;
1890
zz_table = wmv1_scantable[0];
1893
vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
1897
block[zz_table[i++]] = value;
1900
/* apply AC prediction if needed */
1902
/* scale predictors if needed*/
1904
q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
1905
q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
1907
if(dc_pred_dir) { //left
1908
for(k = 1; k < 8; k++)
1909
block[k << 3] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
1911
for(k = 1; k < 8; k++)
1912
block[k] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
1915
if(dc_pred_dir) { //left
1916
for(k = 1; k < 8; k++)
1917
block[k << 3] += ac_val[k];
1919
for(k = 1; k < 8; k++)
1920
block[k] += ac_val[k + 8];
1924
/* save AC coeffs for further prediction */
1925
for(k = 1; k < 8; k++) {
1926
ac_val2[k] = block[k << 3];
1927
ac_val2[k + 8] = block[k];
1930
/* scale AC coeffs */
1931
for(k = 1; k < 64; k++)
1935
block[k] += (block[k] < 0) ? -mquant : mquant;
1938
if(use_pred) i = 63;
1939
} else { // no AC coeffs
1942
memset(ac_val2, 0, 16 * 2);
1943
if(dc_pred_dir) {//left
1945
memcpy(ac_val2, ac_val, 8 * 2);
1947
q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
1948
q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
1949
for(k = 1; k < 8; k++)
1950
ac_val2[k] = (ac_val2[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
1955
memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
1957
q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
1958
q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
1959
for(k = 1; k < 8; k++)
1960
ac_val2[k + 8] = (ac_val2[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
1965
/* apply AC prediction if needed */
1967
if(dc_pred_dir) { //left
1968
for(k = 1; k < 8; k++) {
1969
block[k << 3] = ac_val2[k] * scale;
1970
if(!v->pquantizer && block[k << 3])
1971
block[k << 3] += (block[k << 3] < 0) ? -mquant : mquant;
1974
for(k = 1; k < 8; k++) {
1975
block[k] = ac_val2[k + 8] * scale;
1976
if(!v->pquantizer && block[k])
1977
block[k] += (block[k] < 0) ? -mquant : mquant;
1983
s->block_last_index[n] = i;
1990
static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquant, int ttmb, int first_block,
1991
uint8_t *dst, int linesize, int skip_block, int apply_filter, int cbp_top, int cbp_left)
1993
MpegEncContext *s = &v->s;
1994
GetBitContext *gb = &s->gb;
1997
int scale, off, idx, last, skip, value;
1998
int ttblk = ttmb & 7;
2001
s->dsp.clear_block(block);
2004
ttblk = ff_vc1_ttblk_to_tt[v->tt_index][get_vlc2(gb, ff_vc1_ttblk_vlc[v->tt_index].table, VC1_TTBLK_VLC_BITS, 1)];
2006
if(ttblk == TT_4X4) {
2007
subblkpat = ~(get_vlc2(gb, ff_vc1_subblkpat_vlc[v->tt_index].table, VC1_SUBBLKPAT_VLC_BITS, 1) + 1);
2009
if((ttblk != TT_8X8 && ttblk != TT_4X4)
2010
&& ((v->ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))
2011
|| (!v->res_rtm_flag && !first_block))) {
2012
subblkpat = decode012(gb);
2013
if(subblkpat) subblkpat ^= 3; //swap decoded pattern bits
2014
if(ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) ttblk = TT_8X4;
2015
if(ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) ttblk = TT_4X8;
2017
scale = 2 * mquant + ((v->pq == mquant) ? v->halfpq : 0);
2019
// convert transforms like 8X4_TOP to generic TT and SUBBLKPAT
2020
if(ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) {
2021
subblkpat = 2 - (ttblk == TT_8X4_TOP);
2024
if(ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) {
2025
subblkpat = 2 - (ttblk == TT_4X8_LEFT);
2034
vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
2038
idx = wmv1_scantable[0][i++];
2039
block[idx] = value * scale;
2041
block[idx] += (block[idx] < 0) ? -mquant : mquant;
2045
s->dsp.vc1_inv_trans_8x8_dc(dst, linesize, block);
2047
s->dsp.vc1_inv_trans_8x8(block);
2048
s->dsp.add_pixels_clamped(block, dst, linesize);
2050
if(apply_filter && cbp_top & 0xC)
2051
s->dsp.vc1_v_loop_filter8(dst, linesize, v->pq);
2052
if(apply_filter && cbp_left & 0xA)
2053
s->dsp.vc1_h_loop_filter8(dst, linesize, v->pq);
2057
pat = ~subblkpat & 0xF;
2058
for(j = 0; j < 4; j++) {
2059
last = subblkpat & (1 << (3 - j));
2061
off = (j & 1) * 4 + (j & 2) * 16;
2063
vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
2067
idx = ff_vc1_simple_progressive_4x4_zz[i++];
2068
block[idx + off] = value * scale;
2070
block[idx + off] += (block[idx + off] < 0) ? -mquant : mquant;
2072
if(!(subblkpat & (1 << (3 - j))) && !skip_block){
2074
s->dsp.vc1_inv_trans_4x4_dc(dst + (j&1)*4 + (j&2)*2*linesize, linesize, block + off);
2076
s->dsp.vc1_inv_trans_4x4(dst + (j&1)*4 + (j&2)*2*linesize, linesize, block + off);
2077
if(apply_filter && (j&2 ? pat & (1<<(j-2)) : (cbp_top & (1 << (j + 2)))))
2078
s->dsp.vc1_v_loop_filter4(dst + (j&1)*4 + (j&2)*2*linesize, linesize, v->pq);
2079
if(apply_filter && (j&1 ? pat & (1<<(j-1)) : (cbp_left & (1 << (j + 1)))))
2080
s->dsp.vc1_h_loop_filter4(dst + (j&1)*4 + (j&2)*2*linesize, linesize, v->pq);
2085
pat = ~((subblkpat & 2)*6 + (subblkpat & 1)*3) & 0xF;
2086
for(j = 0; j < 2; j++) {
2087
last = subblkpat & (1 << (1 - j));
2091
vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
2095
idx = v->zz_8x4[i++]+off;
2096
block[idx] = value * scale;
2098
block[idx] += (block[idx] < 0) ? -mquant : mquant;
2100
if(!(subblkpat & (1 << (1 - j))) && !skip_block){
2102
s->dsp.vc1_inv_trans_8x4_dc(dst + j*4*linesize, linesize, block + off);
2104
s->dsp.vc1_inv_trans_8x4(dst + j*4*linesize, linesize, block + off);
2105
if(apply_filter && j ? pat & 0x3 : (cbp_top & 0xC))
2106
s->dsp.vc1_v_loop_filter8(dst + j*4*linesize, linesize, v->pq);
2107
if(apply_filter && cbp_left & (2 << j))
2108
s->dsp.vc1_h_loop_filter4(dst + j*4*linesize, linesize, v->pq);
2113
pat = ~(subblkpat*5) & 0xF;
2114
for(j = 0; j < 2; j++) {
2115
last = subblkpat & (1 << (1 - j));
2119
vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
2123
idx = v->zz_4x8[i++]+off;
2124
block[idx] = value * scale;
2126
block[idx] += (block[idx] < 0) ? -mquant : mquant;
2128
if(!(subblkpat & (1 << (1 - j))) && !skip_block){
2130
s->dsp.vc1_inv_trans_4x8_dc(dst + j*4, linesize, block + off);
2132
s->dsp.vc1_inv_trans_4x8(dst + j*4, linesize, block + off);
2133
if(apply_filter && cbp_top & (2 << j))
2134
s->dsp.vc1_v_loop_filter4(dst + j*4, linesize, v->pq);
2135
if(apply_filter && j ? pat & 0x5 : (cbp_left & 0xA))
2136
s->dsp.vc1_h_loop_filter8(dst + j*4, linesize, v->pq);
2144
/** @} */ // Macroblock group
2146
static const int size_table [6] = { 0, 2, 3, 4, 5, 8 };
2147
static const int offset_table[6] = { 0, 1, 3, 7, 15, 31 };
2149
/** Decode one P-frame MB (in Simple/Main profile)
2151
static int vc1_decode_p_mb(VC1Context *v)
2153
MpegEncContext *s = &v->s;
2154
GetBitContext *gb = &s->gb;
2156
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
2157
int cbp; /* cbp decoding stuff */
2158
int mqdiff, mquant; /* MB quantization */
2159
int ttmb = v->ttfrm; /* MB Transform type */
2161
int mb_has_coeffs = 1; /* last_flag */
2162
int dmv_x, dmv_y; /* Differential MV components */
2163
int index, index1; /* LUT indexes */
2164
int val, sign; /* temp values */
2165
int first_block = 1;
2167
int skipped, fourmv;
2168
int block_cbp = 0, pat;
2169
int apply_loop_filter;
2171
mquant = v->pq; /* Loosy initialization */
2173
if (v->mv_type_is_raw)
2174
fourmv = get_bits1(gb);
2176
fourmv = v->mv_type_mb_plane[mb_pos];
2178
skipped = get_bits1(gb);
2180
skipped = v->s.mbskip_table[mb_pos];
2182
apply_loop_filter = s->loop_filter && !(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY);
2183
if (!fourmv) /* 1MV mode */
2187
GET_MVDATA(dmv_x, dmv_y);
2190
s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
2191
s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
2193
s->current_picture.mb_type[mb_pos] = s->mb_intra ? MB_TYPE_INTRA : MB_TYPE_16x16;
2194
vc1_pred_mv(s, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0]);
2196
/* FIXME Set DC val for inter block ? */
2197
if (s->mb_intra && !mb_has_coeffs)
2200
s->ac_pred = get_bits1(gb);
2203
else if (mb_has_coeffs)
2205
if (s->mb_intra) s->ac_pred = get_bits1(gb);
2206
cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
2214
s->current_picture.qscale_table[mb_pos] = mquant;
2216
if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)
2217
ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table,
2218
VC1_TTMB_VLC_BITS, 2);
2219
if(!s->mb_intra) vc1_mc_1mv(v, 0);
2223
s->dc_val[0][s->block_index[i]] = 0;
2225
val = ((cbp >> (5 - i)) & 1);
2226
off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
2227
v->mb_type[0][s->block_index[i]] = s->mb_intra;
2229
/* check if prediction blocks A and C are available */
2230
v->a_avail = v->c_avail = 0;
2231
if(i == 2 || i == 3 || !s->first_slice_line)
2232
v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
2233
if(i == 1 || i == 3 || s->mb_x)
2234
v->c_avail = v->mb_type[0][s->block_index[i] - 1];
2236
vc1_decode_intra_block(v, s->block[i], i, val, mquant, (i&4)?v->codingset2:v->codingset);
2237
if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue;
2238
s->dsp.vc1_inv_trans_8x8(s->block[i]);
2239
if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1;
2240
s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
2241
if(v->pq >= 9 && v->overlap) {
2243
s->dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
2245
s->dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
2247
if(apply_loop_filter && s->mb_x && s->mb_x != (s->mb_width - 1) && s->mb_y && s->mb_y != (s->mb_height - 1)){
2248
int left_cbp, top_cbp;
2250
left_cbp = v->cbp[s->mb_x - 1] >> (i * 4);
2251
top_cbp = v->cbp[s->mb_x - s->mb_stride] >> (i * 4);
2253
left_cbp = (i & 1) ? (cbp >> ((i-1)*4)) : (v->cbp[s->mb_x - 1] >> ((i+1)*4));
2254
top_cbp = (i & 2) ? (cbp >> ((i-2)*4)) : (v->cbp[s->mb_x - s->mb_stride] >> ((i+2)*4));
2257
s->dsp.vc1_v_loop_filter8(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize, v->pq);
2259
s->dsp.vc1_h_loop_filter8(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize, v->pq);
2261
block_cbp |= 0xF << (i << 2);
2263
int left_cbp = 0, top_cbp = 0, filter = 0;
2264
if(apply_loop_filter && s->mb_x && s->mb_x != (s->mb_width - 1) && s->mb_y && s->mb_y != (s->mb_height - 1)){
2267
left_cbp = v->cbp[s->mb_x - 1] >> (i * 4);
2268
top_cbp = v->cbp[s->mb_x - s->mb_stride] >> (i * 4);
2270
left_cbp = (i & 1) ? (cbp >> ((i-1)*4)) : (v->cbp[s->mb_x - 1] >> ((i+1)*4));
2271
top_cbp = (i & 2) ? (cbp >> ((i-2)*4)) : (v->cbp[s->mb_x - s->mb_stride] >> ((i+2)*4));
2274
s->dsp.vc1_v_loop_filter8(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize, v->pq);
2276
s->dsp.vc1_h_loop_filter8(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize, v->pq);
2278
pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize, (i&4) && (s->flags & CODEC_FLAG_GRAY), filter, left_cbp, top_cbp);
2279
block_cbp |= pat << (i << 2);
2280
if(!v->ttmbf && ttmb < 8) ttmb = -1;
2288
for(i = 0; i < 6; i++) {
2289
v->mb_type[0][s->block_index[i]] = 0;
2290
s->dc_val[0][s->block_index[i]] = 0;
2292
s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP;
2293
s->current_picture.qscale_table[mb_pos] = 0;
2294
vc1_pred_mv(s, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0]);
2301
if (!skipped /* unskipped MB */)
2303
int intra_count = 0, coded_inter = 0;
2304
int is_intra[6], is_coded[6];
2306
cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
2309
val = ((cbp >> (5 - i)) & 1);
2310
s->dc_val[0][s->block_index[i]] = 0;
2317
GET_MVDATA(dmv_x, dmv_y);
2319
vc1_pred_mv(s, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0]);
2320
if(!s->mb_intra) vc1_mc_4mv_luma(v, i);
2321
intra_count += s->mb_intra;
2322
is_intra[i] = s->mb_intra;
2323
is_coded[i] = mb_has_coeffs;
2326
is_intra[i] = (intra_count >= 3);
2329
if(i == 4) vc1_mc_4mv_chroma(v);
2330
v->mb_type[0][s->block_index[i]] = is_intra[i];
2331
if(!coded_inter) coded_inter = !is_intra[i] & is_coded[i];
2333
// if there are no coded blocks then don't do anything more
2334
if(!intra_count && !coded_inter) return 0;
2337
s->current_picture.qscale_table[mb_pos] = mquant;
2338
/* test if block is intra and has pred */
2343
if(((!s->first_slice_line || (i==2 || i==3)) && v->mb_type[0][s->block_index[i] - s->block_wrap[i]])
2344
|| ((s->mb_x || (i==1 || i==3)) && v->mb_type[0][s->block_index[i] - 1])) {
2349
if(intrapred)s->ac_pred = get_bits1(gb);
2350
else s->ac_pred = 0;
2352
if (!v->ttmbf && coded_inter)
2353
ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
2357
off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
2358
s->mb_intra = is_intra[i];
2360
/* check if prediction blocks A and C are available */
2361
v->a_avail = v->c_avail = 0;
2362
if(i == 2 || i == 3 || !s->first_slice_line)
2363
v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
2364
if(i == 1 || i == 3 || s->mb_x)
2365
v->c_avail = v->mb_type[0][s->block_index[i] - 1];
2367
vc1_decode_intra_block(v, s->block[i], i, is_coded[i], mquant, (i&4)?v->codingset2:v->codingset);
2368
if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue;
2369
s->dsp.vc1_inv_trans_8x8(s->block[i]);
2370
if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1;
2371
s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize);
2372
if(v->pq >= 9 && v->overlap) {
2374
s->dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
2376
s->dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
2378
if(v->s.loop_filter && s->mb_x && s->mb_x != (s->mb_width - 1) && s->mb_y && s->mb_y != (s->mb_height - 1)){
2379
int left_cbp, top_cbp;
2381
left_cbp = v->cbp[s->mb_x - 1] >> (i * 4);
2382
top_cbp = v->cbp[s->mb_x - s->mb_stride] >> (i * 4);
2384
left_cbp = (i & 1) ? (cbp >> ((i-1)*4)) : (v->cbp[s->mb_x - 1] >> ((i+1)*4));
2385
top_cbp = (i & 2) ? (cbp >> ((i-2)*4)) : (v->cbp[s->mb_x - s->mb_stride] >> ((i+2)*4));
2388
s->dsp.vc1_v_loop_filter8(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize, v->pq);
2390
s->dsp.vc1_h_loop_filter8(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize, v->pq);
2392
block_cbp |= 0xF << (i << 2);
2393
} else if(is_coded[i]) {
2394
int left_cbp = 0, top_cbp = 0, filter = 0;
2395
if(v->s.loop_filter && s->mb_x && s->mb_x != (s->mb_width - 1) && s->mb_y && s->mb_y != (s->mb_height - 1)){
2398
left_cbp = v->cbp[s->mb_x - 1] >> (i * 4);
2399
top_cbp = v->cbp[s->mb_x - s->mb_stride] >> (i * 4);
2401
left_cbp = (i & 1) ? (cbp >> ((i-1)*4)) : (v->cbp[s->mb_x - 1] >> ((i+1)*4));
2402
top_cbp = (i & 2) ? (cbp >> ((i-2)*4)) : (v->cbp[s->mb_x - s->mb_stride] >> ((i+2)*4));
2405
s->dsp.vc1_v_loop_filter8(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize, v->pq);
2407
s->dsp.vc1_h_loop_filter8(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize, v->pq);
2409
pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize, (i&4) && (s->flags & CODEC_FLAG_GRAY), filter, left_cbp, top_cbp);
2410
block_cbp |= pat << (i << 2);
2411
if(!v->ttmbf && ttmb < 8) ttmb = -1;
2420
s->current_picture.qscale_table[mb_pos] = 0;
2421
for (i=0; i<6; i++) {
2422
v->mb_type[0][s->block_index[i]] = 0;
2423
s->dc_val[0][s->block_index[i]] = 0;
2427
vc1_pred_mv(s, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type[0]);
2428
vc1_mc_4mv_luma(v, i);
2430
vc1_mc_4mv_chroma(v);
2431
s->current_picture.qscale_table[mb_pos] = 0;
2435
v->cbp[s->mb_x] = block_cbp;
2437
/* Should never happen */
2441
/** Decode one B-frame MB (in Main profile)
2443
static void vc1_decode_b_mb(VC1Context *v)
2445
MpegEncContext *s = &v->s;
2446
GetBitContext *gb = &s->gb;
2448
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
2449
int cbp = 0; /* cbp decoding stuff */
2450
int mqdiff, mquant; /* MB quantization */
2451
int ttmb = v->ttfrm; /* MB Transform type */
2452
int mb_has_coeffs = 0; /* last_flag */
2453
int index, index1; /* LUT indexes */
2454
int val, sign; /* temp values */
2455
int first_block = 1;
2457
int skipped, direct;
2458
int dmv_x[2], dmv_y[2];
2459
int bmvtype = BMV_TYPE_BACKWARD;
2461
mquant = v->pq; /* Loosy initialization */
2465
direct = get_bits1(gb);
2467
direct = v->direct_mb_plane[mb_pos];
2469
skipped = get_bits1(gb);
2471
skipped = v->s.mbskip_table[mb_pos];
2473
dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
2474
for(i = 0; i < 6; i++) {
2475
v->mb_type[0][s->block_index[i]] = 0;
2476
s->dc_val[0][s->block_index[i]] = 0;
2478
s->current_picture.qscale_table[mb_pos] = 0;
2482
GET_MVDATA(dmv_x[0], dmv_y[0]);
2483
dmv_x[1] = dmv_x[0];
2484
dmv_y[1] = dmv_y[0];
2486
if(skipped || !s->mb_intra) {
2487
bmvtype = decode012(gb);
2490
bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_BACKWARD : BMV_TYPE_FORWARD;
2493
bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_FORWARD : BMV_TYPE_BACKWARD;
2496
bmvtype = BMV_TYPE_INTERPOLATED;
2497
dmv_x[0] = dmv_y[0] = 0;
2501
for(i = 0; i < 6; i++)
2502
v->mb_type[0][s->block_index[i]] = s->mb_intra;
2505
if(direct) bmvtype = BMV_TYPE_INTERPOLATED;
2506
vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
2507
vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
2511
cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
2514
s->current_picture.qscale_table[mb_pos] = mquant;
2516
ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
2517
dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0;
2518
vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
2519
vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
2521
if(!mb_has_coeffs && !s->mb_intra) {
2522
/* no coded blocks - effectively skipped */
2523
vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
2524
vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
2527
if(s->mb_intra && !mb_has_coeffs) {
2529
s->current_picture.qscale_table[mb_pos] = mquant;
2530
s->ac_pred = get_bits1(gb);
2532
vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
2534
if(bmvtype == BMV_TYPE_INTERPOLATED) {
2535
GET_MVDATA(dmv_x[0], dmv_y[0]);
2536
if(!mb_has_coeffs) {
2537
/* interpolated skipped block */
2538
vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
2539
vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
2543
vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
2545
vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
2548
s->ac_pred = get_bits1(gb);
2549
cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
2551
s->current_picture.qscale_table[mb_pos] = mquant;
2552
if(!v->ttmbf && !s->mb_intra && mb_has_coeffs)
2553
ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
2559
s->dc_val[0][s->block_index[i]] = 0;
2561
val = ((cbp >> (5 - i)) & 1);
2562
off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
2563
v->mb_type[0][s->block_index[i]] = s->mb_intra;
2565
/* check if prediction blocks A and C are available */
2566
v->a_avail = v->c_avail = 0;
2567
if(i == 2 || i == 3 || !s->first_slice_line)
2568
v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
2569
if(i == 1 || i == 3 || s->mb_x)
2570
v->c_avail = v->mb_type[0][s->block_index[i] - 1];
2572
vc1_decode_intra_block(v, s->block[i], i, val, mquant, (i&4)?v->codingset2:v->codingset);
2573
if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue;
2574
s->dsp.vc1_inv_trans_8x8(s->block[i]);
2575
if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1;
2576
s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
2578
vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize, (i&4) && (s->flags & CODEC_FLAG_GRAY), 0, 0, 0);
2579
if(!v->ttmbf && ttmb < 8) ttmb = -1;
2585
/** Decode blocks of I-frame
2587
static void vc1_decode_i_blocks(VC1Context *v)
2590
MpegEncContext *s = &v->s;
2595
/* select codingmode used for VLC tables selection */
2596
switch(v->y_ac_table_index){
2598
v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
2601
v->codingset = CS_HIGH_MOT_INTRA;
2604
v->codingset = CS_MID_RATE_INTRA;
2608
switch(v->c_ac_table_index){
2610
v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
2613
v->codingset2 = CS_HIGH_MOT_INTER;
2616
v->codingset2 = CS_MID_RATE_INTER;
2620
/* Set DC scale - y and c use the same */
2621
s->y_dc_scale = s->y_dc_scale_table[v->pq];
2622
s->c_dc_scale = s->c_dc_scale_table[v->pq];
2625
s->mb_x = s->mb_y = 0;
2627
s->first_slice_line = 1;
2628
for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
2630
ff_init_block_index(s);
2631
for(; s->mb_x < s->mb_width; s->mb_x++) {
2632
ff_update_block_index(s);
2633
s->dsp.clear_blocks(s->block[0]);
2634
mb_pos = s->mb_x + s->mb_y * s->mb_width;
2635
s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
2636
s->current_picture.qscale_table[mb_pos] = v->pq;
2637
s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
2638
s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
2640
// do actual MB decoding and displaying
2641
cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
2642
v->s.ac_pred = get_bits1(&v->s.gb);
2644
for(k = 0; k < 6; k++) {
2645
val = ((cbp >> (5 - k)) & 1);
2648
int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
2652
cbp |= val << (5 - k);
2654
vc1_decode_i_block(v, s->block[k], k, val, (k<4)? v->codingset : v->codingset2);
2656
s->dsp.vc1_inv_trans_8x8(s->block[k]);
2657
if(v->pq >= 9 && v->overlap) {
2658
for(j = 0; j < 64; j++) s->block[k][j] += 128;
2662
vc1_put_block(v, s->block);
2663
if(v->pq >= 9 && v->overlap) {
2665
s->dsp.vc1_h_overlap(s->dest[0], s->linesize);
2666
s->dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize, s->linesize);
2667
if(!(s->flags & CODEC_FLAG_GRAY)) {
2668
s->dsp.vc1_h_overlap(s->dest[1], s->uvlinesize);
2669
s->dsp.vc1_h_overlap(s->dest[2], s->uvlinesize);
2672
s->dsp.vc1_h_overlap(s->dest[0] + 8, s->linesize);
2673
s->dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);
2674
if(!s->first_slice_line) {
2675
s->dsp.vc1_v_overlap(s->dest[0], s->linesize);
2676
s->dsp.vc1_v_overlap(s->dest[0] + 8, s->linesize);
2677
if(!(s->flags & CODEC_FLAG_GRAY)) {
2678
s->dsp.vc1_v_overlap(s->dest[1], s->uvlinesize);
2679
s->dsp.vc1_v_overlap(s->dest[2], s->uvlinesize);
2682
s->dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize, s->linesize);
2683
s->dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);
2685
if(v->s.loop_filter) vc1_loop_filter_iblk(s, v->pq);
2687
if(get_bits_count(&s->gb) > v->bits) {
2688
ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END));
2689
av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits);
2693
if (!v->s.loop_filter)
2694
ff_draw_horiz_band(s, s->mb_y * 16, 16);
2696
ff_draw_horiz_band(s, (s->mb_y-1) * 16, 16);
2698
s->first_slice_line = 0;
2700
if (v->s.loop_filter)
2701
ff_draw_horiz_band(s, (s->mb_height-1)*16, 16);
2702
ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
2705
/** Decode blocks of I-frame for advanced profile
2707
static void vc1_decode_i_blocks_adv(VC1Context *v)
2710
MpegEncContext *s = &v->s;
2717
GetBitContext *gb = &s->gb;
2719
/* select codingmode used for VLC tables selection */
2720
switch(v->y_ac_table_index){
2722
v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
2725
v->codingset = CS_HIGH_MOT_INTRA;
2728
v->codingset = CS_MID_RATE_INTRA;
2732
switch(v->c_ac_table_index){
2734
v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
2737
v->codingset2 = CS_HIGH_MOT_INTER;
2740
v->codingset2 = CS_MID_RATE_INTER;
2745
s->mb_x = s->mb_y = 0;
2747
s->first_slice_line = 1;
2748
for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
2750
ff_init_block_index(s);
2751
for(;s->mb_x < s->mb_width; s->mb_x++) {
2752
ff_update_block_index(s);
2753
s->dsp.clear_blocks(s->block[0]);
2754
mb_pos = s->mb_x + s->mb_y * s->mb_stride;
2755
s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
2756
s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
2757
s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
2759
// do actual MB decoding and displaying
2760
cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
2761
if(v->acpred_is_raw)
2762
v->s.ac_pred = get_bits1(&v->s.gb);
2764
v->s.ac_pred = v->acpred_plane[mb_pos];
2766
if(v->condover == CONDOVER_SELECT) {
2767
if(v->overflg_is_raw)
2768
overlap = get_bits1(&v->s.gb);
2770
overlap = v->over_flags_plane[mb_pos];
2772
overlap = (v->condover == CONDOVER_ALL);
2776
s->current_picture.qscale_table[mb_pos] = mquant;
2777
/* Set DC scale - y and c use the same */
2778
s->y_dc_scale = s->y_dc_scale_table[mquant];
2779
s->c_dc_scale = s->c_dc_scale_table[mquant];
2781
for(k = 0; k < 6; k++) {
2782
val = ((cbp >> (5 - k)) & 1);
2785
int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
2789
cbp |= val << (5 - k);
2791
v->a_avail = !s->first_slice_line || (k==2 || k==3);
2792
v->c_avail = !!s->mb_x || (k==1 || k==3);
2794
vc1_decode_i_block_adv(v, s->block[k], k, val, (k<4)? v->codingset : v->codingset2, mquant);
2796
s->dsp.vc1_inv_trans_8x8(s->block[k]);
2797
for(j = 0; j < 64; j++) s->block[k][j] += 128;
2800
vc1_put_block(v, s->block);
2803
s->dsp.vc1_h_overlap(s->dest[0], s->linesize);
2804
s->dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize, s->linesize);
2805
if(!(s->flags & CODEC_FLAG_GRAY)) {
2806
s->dsp.vc1_h_overlap(s->dest[1], s->uvlinesize);
2807
s->dsp.vc1_h_overlap(s->dest[2], s->uvlinesize);
2810
s->dsp.vc1_h_overlap(s->dest[0] + 8, s->linesize);
2811
s->dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);
2812
if(!s->first_slice_line) {
2813
s->dsp.vc1_v_overlap(s->dest[0], s->linesize);
2814
s->dsp.vc1_v_overlap(s->dest[0] + 8, s->linesize);
2815
if(!(s->flags & CODEC_FLAG_GRAY)) {
2816
s->dsp.vc1_v_overlap(s->dest[1], s->uvlinesize);
2817
s->dsp.vc1_v_overlap(s->dest[2], s->uvlinesize);
2820
s->dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize, s->linesize);
2821
s->dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);
2823
if(v->s.loop_filter) vc1_loop_filter_iblk(s, v->pq);
2825
if(get_bits_count(&s->gb) > v->bits) {
2826
ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END));
2827
av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits);
2831
if (!v->s.loop_filter)
2832
ff_draw_horiz_band(s, s->mb_y * 16, 16);
2834
ff_draw_horiz_band(s, (s->mb_y-1) * 16, 16);
2835
s->first_slice_line = 0;
2837
if (v->s.loop_filter)
2838
ff_draw_horiz_band(s, (s->mb_height-1)*16, 16);
2839
ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
2842
static void vc1_decode_p_blocks(VC1Context *v)
2844
MpegEncContext *s = &v->s;
2846
/* select codingmode used for VLC tables selection */
2847
switch(v->c_ac_table_index){
2849
v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
2852
v->codingset = CS_HIGH_MOT_INTRA;
2855
v->codingset = CS_MID_RATE_INTRA;
2859
switch(v->c_ac_table_index){
2861
v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
2864
v->codingset2 = CS_HIGH_MOT_INTER;
2867
v->codingset2 = CS_MID_RATE_INTER;
2871
s->first_slice_line = 1;
2872
memset(v->cbp_base, 0, sizeof(v->cbp_base[0])*2*s->mb_stride);
2873
for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
2875
ff_init_block_index(s);
2876
for(; s->mb_x < s->mb_width; s->mb_x++) {
2877
ff_update_block_index(s);
2880
if(get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
2881
ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END));
2882
av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), v->bits,s->mb_x,s->mb_y);
2886
memmove(v->cbp_base, v->cbp, sizeof(v->cbp_base[0])*s->mb_stride);
2887
ff_draw_horiz_band(s, s->mb_y * 16, 16);
2888
s->first_slice_line = 0;
2890
ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
2893
static void vc1_decode_b_blocks(VC1Context *v)
2895
MpegEncContext *s = &v->s;
2897
/* select codingmode used for VLC tables selection */
2898
switch(v->c_ac_table_index){
2900
v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
2903
v->codingset = CS_HIGH_MOT_INTRA;
2906
v->codingset = CS_MID_RATE_INTRA;
2910
switch(v->c_ac_table_index){
2912
v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
2915
v->codingset2 = CS_HIGH_MOT_INTER;
2918
v->codingset2 = CS_MID_RATE_INTER;
2922
s->first_slice_line = 1;
2923
for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
2925
ff_init_block_index(s);
2926
for(; s->mb_x < s->mb_width; s->mb_x++) {
2927
ff_update_block_index(s);
2930
if(get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
2931
ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END));
2932
av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), v->bits,s->mb_x,s->mb_y);
2935
if(v->s.loop_filter) vc1_loop_filter_iblk(s, v->pq);
2937
if (!v->s.loop_filter)
2938
ff_draw_horiz_band(s, s->mb_y * 16, 16);
2940
ff_draw_horiz_band(s, (s->mb_y-1) * 16, 16);
2941
s->first_slice_line = 0;
2943
if (v->s.loop_filter)
2944
ff_draw_horiz_band(s, (s->mb_height-1)*16, 16);
2945
ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
2948
static void vc1_decode_skip_blocks(VC1Context *v)
2950
MpegEncContext *s = &v->s;
2952
ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
2953
s->first_slice_line = 1;
2954
for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
2956
ff_init_block_index(s);
2957
ff_update_block_index(s);
2958
memcpy(s->dest[0], s->last_picture.data[0] + s->mb_y * 16 * s->linesize, s->linesize * 16);
2959
memcpy(s->dest[1], s->last_picture.data[1] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
2960
memcpy(s->dest[2], s->last_picture.data[2] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
2961
ff_draw_horiz_band(s, s->mb_y * 16, 16);
2962
s->first_slice_line = 0;
2964
s->pict_type = FF_P_TYPE;
2967
static void vc1_decode_blocks(VC1Context *v)
2970
v->s.esc3_level_length = 0;
2972
ff_intrax8_decode_picture(&v->x8, 2*v->pq+v->halfpq, v->pq*(!v->pquantizer) );
2975
switch(v->s.pict_type) {
2977
if(v->profile == PROFILE_ADVANCED)
2978
vc1_decode_i_blocks_adv(v);
2980
vc1_decode_i_blocks(v);
2983
if(v->p_frame_skipped)
2984
vc1_decode_skip_blocks(v);
2986
vc1_decode_p_blocks(v);
2990
if(v->profile == PROFILE_ADVANCED)
2991
vc1_decode_i_blocks_adv(v);
2993
vc1_decode_i_blocks(v);
2995
vc1_decode_b_blocks(v);
3001
/** Initialize a VC1/WMV3 decoder
3002
* @todo TODO: Handle VC-1 IDUs (Transport level?)
3003
* @todo TODO: Decypher remaining bits in extra_data
3005
static av_cold int vc1_decode_init(AVCodecContext *avctx)
3007
VC1Context *v = avctx->priv_data;
3008
MpegEncContext *s = &v->s;
3011
if (!avctx->extradata_size || !avctx->extradata) return -1;
3012
if (!(avctx->flags & CODEC_FLAG_GRAY))
3013
avctx->pix_fmt = avctx->get_format(avctx, avctx->codec->pix_fmts);
3015
avctx->pix_fmt = PIX_FMT_GRAY8;
3016
avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
3018
avctx->flags |= CODEC_FLAG_EMU_EDGE;
3019
v->s.flags |= CODEC_FLAG_EMU_EDGE;
3021
if(avctx->idct_algo==FF_IDCT_AUTO){
3022
avctx->idct_algo=FF_IDCT_WMV2;
3025
if(ff_msmpeg4_decode_init(avctx) < 0)
3027
if (vc1_init_common(v) < 0) return -1;
3029
avctx->coded_width = avctx->width;
3030
avctx->coded_height = avctx->height;
3031
if (avctx->codec_id == CODEC_ID_WMV3)
3035
// looks like WMV3 has a sequence header stored in the extradata
3036
// advanced sequence header may be before the first frame
3037
// the last byte of the extradata is a version number, 1 for the
3038
// samples we can decode
3040
init_get_bits(&gb, avctx->extradata, avctx->extradata_size*8);
3042
if (vc1_decode_sequence_header(avctx, v, &gb) < 0)
3045
count = avctx->extradata_size*8 - get_bits_count(&gb);
3048
av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n",
3049
count, get_bits(&gb, count));
3053
av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count);
3055
} else { // VC1/WVC1
3056
const uint8_t *start = avctx->extradata;
3057
uint8_t *end = avctx->extradata + avctx->extradata_size;
3058
const uint8_t *next;
3059
int size, buf2_size;
3060
uint8_t *buf2 = NULL;
3061
int seq_initialized = 0, ep_initialized = 0;
3063
if(avctx->extradata_size < 16) {
3064
av_log(avctx, AV_LOG_ERROR, "Extradata size too small: %i\n", avctx->extradata_size);
3068
buf2 = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
3069
start = find_next_marker(start, end); // in WVC1 extradata first byte is its size, but can be 0 in mkv
3071
for(; next < end; start = next){
3072
next = find_next_marker(start + 4, end);
3073
size = next - start - 4;
3074
if(size <= 0) continue;
3075
buf2_size = vc1_unescape_buffer(start + 4, size, buf2);
3076
init_get_bits(&gb, buf2, buf2_size * 8);
3077
switch(AV_RB32(start)){
3078
case VC1_CODE_SEQHDR:
3079
if(vc1_decode_sequence_header(avctx, v, &gb) < 0){
3083
seq_initialized = 1;
3085
case VC1_CODE_ENTRYPOINT:
3086
if(vc1_decode_entry_point(avctx, v, &gb) < 0){
3095
if(!seq_initialized || !ep_initialized){
3096
av_log(avctx, AV_LOG_ERROR, "Incomplete extradata\n");
3100
avctx->has_b_frames= !!(avctx->max_b_frames);
3101
s->low_delay = !avctx->has_b_frames;
3103
s->mb_width = (avctx->coded_width+15)>>4;
3104
s->mb_height = (avctx->coded_height+15)>>4;
3106
/* Allocate mb bitplanes */
3107
v->mv_type_mb_plane = av_malloc(s->mb_stride * s->mb_height);
3108
v->direct_mb_plane = av_malloc(s->mb_stride * s->mb_height);
3109
v->acpred_plane = av_malloc(s->mb_stride * s->mb_height);
3110
v->over_flags_plane = av_malloc(s->mb_stride * s->mb_height);
3112
v->cbp_base = av_malloc(sizeof(v->cbp_base[0]) * 2 * s->mb_stride);
3113
v->cbp = v->cbp_base + s->mb_stride;
3115
/* allocate block type info in that way so it could be used with s->block_index[] */
3116
v->mb_type_base = av_malloc(s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2);
3117
v->mb_type[0] = v->mb_type_base + s->b8_stride + 1;
3118
v->mb_type[1] = v->mb_type_base + s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride + 1;
3119
v->mb_type[2] = v->mb_type[1] + s->mb_stride * (s->mb_height + 1);
3121
/* Init coded blocks info */
3122
if (v->profile == PROFILE_ADVANCED)
3124
// if (alloc_bitplane(&v->over_flags_plane, s->mb_width, s->mb_height) < 0)
3126
// if (alloc_bitplane(&v->ac_pred_plane, s->mb_width, s->mb_height) < 0)
3130
ff_intrax8_common_init(&v->x8,s);
3135
/** Decode a VC1/WMV3 frame
3136
* @todo TODO: Handle VC-1 IDUs (Transport level?)
3138
static int vc1_decode_frame(AVCodecContext *avctx,
3139
void *data, int *data_size,
3142
const uint8_t *buf = avpkt->data;
3143
int buf_size = avpkt->size;
3144
VC1Context *v = avctx->priv_data;
3145
MpegEncContext *s = &v->s;
3146
AVFrame *pict = data;
3147
uint8_t *buf2 = NULL;
3148
const uint8_t *buf_start = buf;
3150
/* no supplementary picture */
3151
if (buf_size == 0) {
3152
/* special case for last picture */
3153
if (s->low_delay==0 && s->next_picture_ptr) {
3154
*pict= *(AVFrame*)s->next_picture_ptr;
3155
s->next_picture_ptr= NULL;
3157
*data_size = sizeof(AVFrame);
3163
/* We need to set current_picture_ptr before reading the header,
3164
* otherwise we cannot store anything in there. */
3165
if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){
3166
int i= ff_find_unused_picture(s, 0);
3167
s->current_picture_ptr= &s->picture[i];
3170
if (s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU){
3171
if (v->profile < PROFILE_ADVANCED)
3172
avctx->pix_fmt = PIX_FMT_VDPAU_WMV3;
3174
avctx->pix_fmt = PIX_FMT_VDPAU_VC1;
3177
//for advanced profile we may need to parse and unescape data
3178
if (avctx->codec_id == CODEC_ID_VC1) {
3180
buf2 = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
3182
if(IS_MARKER(AV_RB32(buf))){ /* frame starts with marker and needs to be parsed */
3183
const uint8_t *start, *end, *next;
3187
for(start = buf, end = buf + buf_size; next < end; start = next){
3188
next = find_next_marker(start + 4, end);
3189
size = next - start - 4;
3190
if(size <= 0) continue;
3191
switch(AV_RB32(start)){
3192
case VC1_CODE_FRAME:
3193
if (avctx->hwaccel ||
3194
s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
3196
buf_size2 = vc1_unescape_buffer(start + 4, size, buf2);
3198
case VC1_CODE_ENTRYPOINT: /* it should be before frame data */
3199
buf_size2 = vc1_unescape_buffer(start + 4, size, buf2);
3200
init_get_bits(&s->gb, buf2, buf_size2*8);
3201
vc1_decode_entry_point(avctx, v, &s->gb);
3203
case VC1_CODE_SLICE:
3204
av_log(avctx, AV_LOG_ERROR, "Sliced decoding is not implemented (yet)\n");
3209
}else if(v->interlace && ((buf[0] & 0xC0) == 0xC0)){ /* WVC1 interlaced stores both fields divided by marker */
3210
const uint8_t *divider;
3212
divider = find_next_marker(buf, buf + buf_size);
3213
if((divider == (buf + buf_size)) || AV_RB32(divider) != VC1_CODE_FIELD){
3214
av_log(avctx, AV_LOG_ERROR, "Error in WVC1 interlaced frame\n");
3219
buf_size2 = vc1_unescape_buffer(buf, divider - buf, buf2);
3221
if(!v->warn_interlaced++)
3222
av_log(v->s.avctx, AV_LOG_ERROR, "Interlaced WVC1 support is not implemented\n");
3223
av_free(buf2);return -1;
3225
buf_size2 = vc1_unescape_buffer(buf, buf_size, buf2);
3227
init_get_bits(&s->gb, buf2, buf_size2*8);
3229
init_get_bits(&s->gb, buf, buf_size*8);
3230
// do parse frame header
3231
if(v->profile < PROFILE_ADVANCED) {
3232
if(vc1_parse_frame_header(v, &s->gb) == -1) {
3237
if(vc1_parse_frame_header_adv(v, &s->gb) == -1) {
3243
if(v->res_sprite && (s->pict_type!=FF_I_TYPE)){
3249
s->current_picture.pict_type= s->pict_type;
3250
s->current_picture.key_frame= s->pict_type == FF_I_TYPE;
3252
/* skip B-frames if we don't have reference frames */
3253
if(s->last_picture_ptr==NULL && (s->pict_type==FF_B_TYPE || s->dropable)){
3255
return -1;//buf_size;
3257
/* skip b frames if we are in a hurry */
3258
if(avctx->hurry_up && s->pict_type==FF_B_TYPE) return -1;//buf_size;
3259
if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==FF_B_TYPE)
3260
|| (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=FF_I_TYPE)
3261
|| avctx->skip_frame >= AVDISCARD_ALL) {
3265
/* skip everything if we are in a hurry>=5 */
3266
if(avctx->hurry_up>=5) {
3268
return -1;//buf_size;
3271
if(s->next_p_frame_damaged){
3272
if(s->pict_type==FF_B_TYPE)
3275
s->next_p_frame_damaged=0;
3278
if(MPV_frame_start(s, avctx) < 0) {
3283
s->me.qpel_put= s->dsp.put_qpel_pixels_tab;
3284
s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab;
3286
if ((CONFIG_VC1_VDPAU_DECODER)
3287
&&s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
3288
ff_vdpau_vc1_decode_picture(s, buf_start, (buf + buf_size) - buf_start);
3289
else if (avctx->hwaccel) {
3290
if (avctx->hwaccel->start_frame(avctx, buf, buf_size) < 0)
3292
if (avctx->hwaccel->decode_slice(avctx, buf_start, (buf + buf_size) - buf_start) < 0)
3294
if (avctx->hwaccel->end_frame(avctx) < 0)
3297
ff_er_frame_start(s);
3299
v->bits = buf_size * 8;
3300
vc1_decode_blocks(v);
3301
//av_log(s->avctx, AV_LOG_INFO, "Consumed %i/%i bits\n", get_bits_count(&s->gb), buf_size*8);
3302
// if(get_bits_count(&s->gb) > buf_size * 8)
3309
assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
3310
assert(s->current_picture.pict_type == s->pict_type);
3311
if (s->pict_type == FF_B_TYPE || s->low_delay) {
3312
*pict= *(AVFrame*)s->current_picture_ptr;
3313
} else if (s->last_picture_ptr != NULL) {
3314
*pict= *(AVFrame*)s->last_picture_ptr;
3317
if(s->last_picture_ptr || s->low_delay){
3318
*data_size = sizeof(AVFrame);
3319
ff_print_debug_info(s, pict);
3327
/** Close a VC1/WMV3 decoder
3328
* @warning Initial try at using MpegEncContext stuff
3330
static av_cold int vc1_decode_end(AVCodecContext *avctx)
3332
VC1Context *v = avctx->priv_data;
3334
av_freep(&v->hrd_rate);
3335
av_freep(&v->hrd_buffer);
3336
MPV_common_end(&v->s);
3337
av_freep(&v->mv_type_mb_plane);
3338
av_freep(&v->direct_mb_plane);
3339
av_freep(&v->acpred_plane);
3340
av_freep(&v->over_flags_plane);
3341
av_freep(&v->mb_type_base);
3342
av_freep(&v->cbp_base);
3343
ff_intrax8_common_end(&v->x8);
3348
AVCodec vc1_decoder = {
3357
CODEC_CAP_DR1 | CODEC_CAP_DELAY,
3359
.long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1"),
3360
.pix_fmts = ff_hwaccel_pixfmt_list_420
3363
#if CONFIG_WMV3_DECODER
3364
AVCodec wmv3_decoder = {
3373
CODEC_CAP_DR1 | CODEC_CAP_DELAY,
3375
.long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9"),
3376
.pix_fmts = ff_hwaccel_pixfmt_list_420
3380
#if CONFIG_WMV3_VDPAU_DECODER
3381
AVCodec wmv3_vdpau_decoder = {
3390
CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
3392
.long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 VDPAU"),
3393
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_WMV3, PIX_FMT_NONE}
3397
#if CONFIG_VC1_VDPAU_DECODER
3398
AVCodec vc1_vdpau_decoder = {
3407
CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
3409
.long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1 VDPAU"),
3410
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_VC1, PIX_FMT_NONE}