00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00028 #include "internal.h"
00029 #include "dsputil.h"
00030 #include "avcodec.h"
00031 #include "mpegvideo.h"
00032 #include "h263.h"
00033 #include "vc1.h"
00034 #include "vc1data.h"
00035 #include "vc1acdata.h"
00036 #include "msmpeg4data.h"
00037 #include "unary.h"
00038 #include "simple_idct.h"
00039 #include "mathops.h"
00040 #include "vdpau_internal.h"
00041
00042 #undef NDEBUG
00043 #include <assert.h>
00044
00045 #define MB_INTRA_VLC_BITS 9
00046 #define DC_VLC_BITS 9
00047 #define AC_VLC_BITS 9
00048 static const uint16_t table_mb_intra[64][2];
00049
00050
00051 static const uint16_t vlc_offs[] = {
00052 0, 520, 552, 616, 1128, 1160, 1224, 1740, 1772, 1836, 1900, 2436,
00053 2986, 3050, 3610, 4154, 4218, 4746, 5326, 5390, 5902, 6554, 7658, 8620,
00054 9262, 10202, 10756, 11310, 12228, 15078
00055 };
00056
00062 static int vc1_init_common(VC1Context *v)
00063 {
00064 static int done = 0;
00065 int i = 0;
00066 static VLC_TYPE vlc_table[15078][2];
00067
00068 v->hrd_rate = v->hrd_buffer = NULL;
00069
00070
00071 if(!done)
00072 {
00073 INIT_VLC_STATIC(&ff_vc1_bfraction_vlc, VC1_BFRACTION_VLC_BITS, 23,
00074 ff_vc1_bfraction_bits, 1, 1,
00075 ff_vc1_bfraction_codes, 1, 1, 1 << VC1_BFRACTION_VLC_BITS);
00076 INIT_VLC_STATIC(&ff_vc1_norm2_vlc, VC1_NORM2_VLC_BITS, 4,
00077 ff_vc1_norm2_bits, 1, 1,
00078 ff_vc1_norm2_codes, 1, 1, 1 << VC1_NORM2_VLC_BITS);
00079 INIT_VLC_STATIC(&ff_vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 64,
00080 ff_vc1_norm6_bits, 1, 1,
00081 ff_vc1_norm6_codes, 2, 2, 556);
00082 INIT_VLC_STATIC(&ff_vc1_imode_vlc, VC1_IMODE_VLC_BITS, 7,
00083 ff_vc1_imode_bits, 1, 1,
00084 ff_vc1_imode_codes, 1, 1, 1 << VC1_IMODE_VLC_BITS);
00085 for (i=0; i<3; i++)
00086 {
00087 ff_vc1_ttmb_vlc[i].table = &vlc_table[vlc_offs[i*3+0]];
00088 ff_vc1_ttmb_vlc[i].table_allocated = vlc_offs[i*3+1] - vlc_offs[i*3+0];
00089 init_vlc(&ff_vc1_ttmb_vlc[i], VC1_TTMB_VLC_BITS, 16,
00090 ff_vc1_ttmb_bits[i], 1, 1,
00091 ff_vc1_ttmb_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
00092 ff_vc1_ttblk_vlc[i].table = &vlc_table[vlc_offs[i*3+1]];
00093 ff_vc1_ttblk_vlc[i].table_allocated = vlc_offs[i*3+2] - vlc_offs[i*3+1];
00094 init_vlc(&ff_vc1_ttblk_vlc[i], VC1_TTBLK_VLC_BITS, 8,
00095 ff_vc1_ttblk_bits[i], 1, 1,
00096 ff_vc1_ttblk_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
00097 ff_vc1_subblkpat_vlc[i].table = &vlc_table[vlc_offs[i*3+2]];
00098 ff_vc1_subblkpat_vlc[i].table_allocated = vlc_offs[i*3+3] - vlc_offs[i*3+2];
00099 init_vlc(&ff_vc1_subblkpat_vlc[i], VC1_SUBBLKPAT_VLC_BITS, 15,
00100 ff_vc1_subblkpat_bits[i], 1, 1,
00101 ff_vc1_subblkpat_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
00102 }
00103 for(i=0; i<4; i++)
00104 {
00105 ff_vc1_4mv_block_pattern_vlc[i].table = &vlc_table[vlc_offs[i*3+9]];
00106 ff_vc1_4mv_block_pattern_vlc[i].table_allocated = vlc_offs[i*3+10] - vlc_offs[i*3+9];
00107 init_vlc(&ff_vc1_4mv_block_pattern_vlc[i], VC1_4MV_BLOCK_PATTERN_VLC_BITS, 16,
00108 ff_vc1_4mv_block_pattern_bits[i], 1, 1,
00109 ff_vc1_4mv_block_pattern_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
00110 ff_vc1_cbpcy_p_vlc[i].table = &vlc_table[vlc_offs[i*3+10]];
00111 ff_vc1_cbpcy_p_vlc[i].table_allocated = vlc_offs[i*3+11] - vlc_offs[i*3+10];
00112 init_vlc(&ff_vc1_cbpcy_p_vlc[i], VC1_CBPCY_P_VLC_BITS, 64,
00113 ff_vc1_cbpcy_p_bits[i], 1, 1,
00114 ff_vc1_cbpcy_p_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
00115 ff_vc1_mv_diff_vlc[i].table = &vlc_table[vlc_offs[i*3+11]];
00116 ff_vc1_mv_diff_vlc[i].table_allocated = vlc_offs[i*3+12] - vlc_offs[i*3+11];
00117 init_vlc(&ff_vc1_mv_diff_vlc[i], VC1_MV_DIFF_VLC_BITS, 73,
00118 ff_vc1_mv_diff_bits[i], 1, 1,
00119 ff_vc1_mv_diff_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
00120 }
00121 for(i=0; i<8; i++){
00122 ff_vc1_ac_coeff_table[i].table = &vlc_table[vlc_offs[i+21]];
00123 ff_vc1_ac_coeff_table[i].table_allocated = vlc_offs[i+22] - vlc_offs[i+21];
00124 init_vlc(&ff_vc1_ac_coeff_table[i], AC_VLC_BITS, vc1_ac_sizes[i],
00125 &vc1_ac_tables[i][0][1], 8, 4,
00126 &vc1_ac_tables[i][0][0], 8, 4, INIT_VLC_USE_NEW_STATIC);
00127 }
00128 done = 1;
00129 }
00130
00131
00132 v->pq = -1;
00133 v->mvrange = 0;
00134
00135 return 0;
00136 }
00137
00138
00149 enum Imode {
00150 IMODE_RAW,
00151 IMODE_NORM2,
00152 IMODE_DIFF2,
00153 IMODE_NORM6,
00154 IMODE_DIFF6,
00155 IMODE_ROWSKIP,
00156 IMODE_COLSKIP
00157 };
00159
00160
00162
00163 static void vc1_put_signed_blocks_clamped(VC1Context *v)
00164 {
00165 MpegEncContext *s = &v->s;
00166
00167
00168
00169
00170
00171
00172
00173
00174 if (!s->first_slice_line) {
00175 if (s->mb_x) {
00176 s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][0],
00177 s->dest[0] - 16 * s->linesize - 16,
00178 s->linesize);
00179 s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][1],
00180 s->dest[0] - 16 * s->linesize - 8,
00181 s->linesize);
00182 s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][2],
00183 s->dest[0] - 8 * s->linesize - 16,
00184 s->linesize);
00185 s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][3],
00186 s->dest[0] - 8 * s->linesize - 8,
00187 s->linesize);
00188 s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][4],
00189 s->dest[1] - 8 * s->uvlinesize - 8,
00190 s->uvlinesize);
00191 s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][5],
00192 s->dest[2] - 8 * s->uvlinesize - 8,
00193 s->uvlinesize);
00194 }
00195 if (s->mb_x == s->mb_width - 1) {
00196 s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][0],
00197 s->dest[0] - 16 * s->linesize,
00198 s->linesize);
00199 s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][1],
00200 s->dest[0] - 16 * s->linesize + 8,
00201 s->linesize);
00202 s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][2],
00203 s->dest[0] - 8 * s->linesize,
00204 s->linesize);
00205 s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][3],
00206 s->dest[0] - 8 * s->linesize + 8,
00207 s->linesize);
00208 s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][4],
00209 s->dest[1] - 8 * s->uvlinesize,
00210 s->uvlinesize);
00211 s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][5],
00212 s->dest[2] - 8 * s->uvlinesize,
00213 s->uvlinesize);
00214 }
00215 }
00216
00217 #define inc_blk_idx(idx) do { \
00218 idx++; \
00219 if (idx >= v->n_allocated_blks) \
00220 idx = 0; \
00221 } while (0)
00222
00223 inc_blk_idx(v->topleft_blk_idx);
00224 inc_blk_idx(v->top_blk_idx);
00225 inc_blk_idx(v->left_blk_idx);
00226 inc_blk_idx(v->cur_blk_idx);
00227 }
00228
00229 static void vc1_loop_filter_iblk(VC1Context *v, int pq)
00230 {
00231 MpegEncContext *s = &v->s;
00232 int j;
00233 if (!s->first_slice_line) {
00234 v->vc1dsp.vc1_v_loop_filter16(s->dest[0], s->linesize, pq);
00235 if (s->mb_x)
00236 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16*s->linesize, s->linesize, pq);
00237 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16*s->linesize+8, s->linesize, pq);
00238 for(j = 0; j < 2; j++){
00239 v->vc1dsp.vc1_v_loop_filter8(s->dest[j+1], s->uvlinesize, pq);
00240 if (s->mb_x)
00241 v->vc1dsp.vc1_h_loop_filter8(s->dest[j+1]-8*s->uvlinesize, s->uvlinesize, pq);
00242 }
00243 }
00244 v->vc1dsp.vc1_v_loop_filter16(s->dest[0] + 8*s->linesize, s->linesize, pq);
00245
00246 if (s->mb_y == s->end_mb_y-1) {
00247 if (s->mb_x) {
00248 v->vc1dsp.vc1_h_loop_filter16(s->dest[0], s->linesize, pq);
00249 v->vc1dsp.vc1_h_loop_filter8(s->dest[1], s->uvlinesize, pq);
00250 v->vc1dsp.vc1_h_loop_filter8(s->dest[2], s->uvlinesize, pq);
00251 }
00252 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] + 8, s->linesize, pq);
00253 }
00254 }
00255
00256 static void vc1_loop_filter_iblk_delayed(VC1Context *v, int pq)
00257 {
00258 MpegEncContext *s = &v->s;
00259 int j;
00260
00261
00262
00263 if (!s->first_slice_line) {
00264 if (s->mb_x) {
00265 if (s->mb_y >= s->start_mb_y + 2) {
00266 v->vc1dsp.vc1_v_loop_filter16(s->dest[0] - 16 * s->linesize - 16, s->linesize, pq);
00267
00268 if (s->mb_x >= 2)
00269 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize - 16, s->linesize, pq);
00270 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize - 8, s->linesize, pq);
00271 for(j = 0; j < 2; j++) {
00272 v->vc1dsp.vc1_v_loop_filter8(s->dest[j+1] - 8 * s->uvlinesize - 8, s->uvlinesize, pq);
00273 if (s->mb_x >= 2) {
00274 v->vc1dsp.vc1_h_loop_filter8(s->dest[j+1] - 16 * s->uvlinesize - 8, s->uvlinesize, pq);
00275 }
00276 }
00277 }
00278 v->vc1dsp.vc1_v_loop_filter16(s->dest[0] - 8 * s->linesize - 16, s->linesize, pq);
00279 }
00280
00281 if (s->mb_x == s->mb_width - 1) {
00282 if (s->mb_y >= s->start_mb_y + 2) {
00283 v->vc1dsp.vc1_v_loop_filter16(s->dest[0] - 16 * s->linesize, s->linesize, pq);
00284
00285 if (s->mb_x)
00286 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize, s->linesize, pq);
00287 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize + 8, s->linesize, pq);
00288 for(j = 0; j < 2; j++) {
00289 v->vc1dsp.vc1_v_loop_filter8(s->dest[j+1] - 8 * s->uvlinesize, s->uvlinesize, pq);
00290 if (s->mb_x >= 2) {
00291 v->vc1dsp.vc1_h_loop_filter8(s->dest[j+1] - 16 * s->uvlinesize, s->uvlinesize, pq);
00292 }
00293 }
00294 }
00295 v->vc1dsp.vc1_v_loop_filter16(s->dest[0] - 8 * s->linesize, s->linesize, pq);
00296 }
00297
00298 if (s->mb_y == s->end_mb_y) {
00299 if (s->mb_x) {
00300 if (s->mb_x >= 2)
00301 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize - 16, s->linesize, pq);
00302 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize - 8, s->linesize, pq);
00303 if (s->mb_x >= 2) {
00304 for(j = 0; j < 2; j++) {
00305 v->vc1dsp.vc1_h_loop_filter8(s->dest[j+1] - 8 * s->uvlinesize - 8, s->uvlinesize, pq);
00306 }
00307 }
00308 }
00309
00310 if (s->mb_x == s->mb_width - 1) {
00311 if (s->mb_x)
00312 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize, s->linesize, pq);
00313 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize + 8, s->linesize, pq);
00314 if (s->mb_x) {
00315 for(j = 0; j < 2; j++) {
00316 v->vc1dsp.vc1_h_loop_filter8(s->dest[j+1] - 8 * s->uvlinesize, s->uvlinesize, pq);
00317 }
00318 }
00319 }
00320 }
00321 }
00322 }
00323
00324 static void vc1_smooth_overlap_filter_iblk(VC1Context *v)
00325 {
00326 MpegEncContext *s = &v->s;
00327 int mb_pos;
00328
00329 if (v->condover == CONDOVER_NONE)
00330 return;
00331
00332 mb_pos = s->mb_x + s->mb_y * s->mb_stride;
00333
00334
00335
00336
00337
00338
00339
00340
00341 if(v->condover == CONDOVER_ALL || v->pq >= 9 || v->over_flags_plane[mb_pos]) {
00342 if(s->mb_x && (v->condover == CONDOVER_ALL || v->pq >= 9 ||
00343 v->over_flags_plane[mb_pos - 1])) {
00344 v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][1],
00345 v->block[v->cur_blk_idx][0]);
00346 v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][3],
00347 v->block[v->cur_blk_idx][2]);
00348 if(!(s->flags & CODEC_FLAG_GRAY)) {
00349 v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][4],
00350 v->block[v->cur_blk_idx][4]);
00351 v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][5],
00352 v->block[v->cur_blk_idx][5]);
00353 }
00354 }
00355 v->vc1dsp.vc1_h_s_overlap(v->block[v->cur_blk_idx][0],
00356 v->block[v->cur_blk_idx][1]);
00357 v->vc1dsp.vc1_h_s_overlap(v->block[v->cur_blk_idx][2],
00358 v->block[v->cur_blk_idx][3]);
00359
00360 if (s->mb_x == s->mb_width - 1) {
00361 if(!s->first_slice_line && (v->condover == CONDOVER_ALL || v->pq >= 9 ||
00362 v->over_flags_plane[mb_pos - s->mb_stride])) {
00363 v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][2],
00364 v->block[v->cur_blk_idx][0]);
00365 v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][3],
00366 v->block[v->cur_blk_idx][1]);
00367 if(!(s->flags & CODEC_FLAG_GRAY)) {
00368 v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][4],
00369 v->block[v->cur_blk_idx][4]);
00370 v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][5],
00371 v->block[v->cur_blk_idx][5]);
00372 }
00373 }
00374 v->vc1dsp.vc1_v_s_overlap(v->block[v->cur_blk_idx][0],
00375 v->block[v->cur_blk_idx][2]);
00376 v->vc1dsp.vc1_v_s_overlap(v->block[v->cur_blk_idx][1],
00377 v->block[v->cur_blk_idx][3]);
00378 }
00379 }
00380 if (s->mb_x && (v->condover == CONDOVER_ALL || v->over_flags_plane[mb_pos - 1])) {
00381 if(!s->first_slice_line && (v->condover == CONDOVER_ALL || v->pq >= 9 ||
00382 v->over_flags_plane[mb_pos - s->mb_stride - 1])) {
00383 v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][2],
00384 v->block[v->left_blk_idx][0]);
00385 v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][3],
00386 v->block[v->left_blk_idx][1]);
00387 if(!(s->flags & CODEC_FLAG_GRAY)) {
00388 v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][4],
00389 v->block[v->left_blk_idx][4]);
00390 v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][5],
00391 v->block[v->left_blk_idx][5]);
00392 }
00393 }
00394 v->vc1dsp.vc1_v_s_overlap(v->block[v->left_blk_idx][0],
00395 v->block[v->left_blk_idx][2]);
00396 v->vc1dsp.vc1_v_s_overlap(v->block[v->left_blk_idx][1],
00397 v->block[v->left_blk_idx][3]);
00398 }
00399 }
00400
00404 static void vc1_mc_1mv(VC1Context *v, int dir)
00405 {
00406 MpegEncContext *s = &v->s;
00407 DSPContext *dsp = &v->s.dsp;
00408 uint8_t *srcY, *srcU, *srcV;
00409 int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
00410
00411 if(!v->s.last_picture.data[0])return;
00412
00413 mx = s->mv[dir][0][0];
00414 my = s->mv[dir][0][1];
00415
00416
00417 if(s->pict_type == AV_PICTURE_TYPE_P) {
00418 s->current_picture.motion_val[1][s->block_index[0]][0] = mx;
00419 s->current_picture.motion_val[1][s->block_index[0]][1] = my;
00420 }
00421 uvmx = (mx + ((mx & 3) == 3)) >> 1;
00422 uvmy = (my + ((my & 3) == 3)) >> 1;
00423 v->luma_mv[s->mb_x][0] = uvmx;
00424 v->luma_mv[s->mb_x][1] = uvmy;
00425 if(v->fastuvmc) {
00426 uvmx = uvmx + ((uvmx<0)?(uvmx&1):-(uvmx&1));
00427 uvmy = uvmy + ((uvmy<0)?(uvmy&1):-(uvmy&1));
00428 }
00429 if(!dir) {
00430 srcY = s->last_picture.data[0];
00431 srcU = s->last_picture.data[1];
00432 srcV = s->last_picture.data[2];
00433 } else {
00434 srcY = s->next_picture.data[0];
00435 srcU = s->next_picture.data[1];
00436 srcV = s->next_picture.data[2];
00437 }
00438
00439 src_x = s->mb_x * 16 + (mx >> 2);
00440 src_y = s->mb_y * 16 + (my >> 2);
00441 uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
00442 uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
00443
00444 if(v->profile != PROFILE_ADVANCED){
00445 src_x = av_clip( src_x, -16, s->mb_width * 16);
00446 src_y = av_clip( src_y, -16, s->mb_height * 16);
00447 uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);
00448 uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);
00449 }else{
00450 src_x = av_clip( src_x, -17, s->avctx->coded_width);
00451 src_y = av_clip( src_y, -18, s->avctx->coded_height + 1);
00452 uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
00453 uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
00454 }
00455
00456 srcY += src_y * s->linesize + src_x;
00457 srcU += uvsrc_y * s->uvlinesize + uvsrc_x;
00458 srcV += uvsrc_y * s->uvlinesize + uvsrc_x;
00459
00460
00461 if(s->flags & CODEC_FLAG_GRAY) {
00462 srcU = s->edge_emu_buffer + 18 * s->linesize;
00463 srcV = s->edge_emu_buffer + 18 * s->linesize;
00464 }
00465
00466 if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
00467 || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 16 - s->mspel*3
00468 || (unsigned)(src_y - s->mspel) > s->v_edge_pos - (my&3) - 16 - s->mspel*3){
00469 uint8_t *uvbuf= s->edge_emu_buffer + 19 * s->linesize;
00470
00471 srcY -= s->mspel * (1 + s->linesize);
00472 s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 17+s->mspel*2, 17+s->mspel*2,
00473 src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, s->v_edge_pos);
00474 srcY = s->edge_emu_buffer;
00475 s->dsp.emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8+1, 8+1,
00476 uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
00477 s->dsp.emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8+1, 8+1,
00478 uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
00479 srcU = uvbuf;
00480 srcV = uvbuf + 16;
00481
00482 if(v->rangeredfrm) {
00483 int i, j;
00484 uint8_t *src, *src2;
00485
00486 src = srcY;
00487 for(j = 0; j < 17 + s->mspel*2; j++) {
00488 for(i = 0; i < 17 + s->mspel*2; i++) src[i] = ((src[i] - 128) >> 1) + 128;
00489 src += s->linesize;
00490 }
00491 src = srcU; src2 = srcV;
00492 for(j = 0; j < 9; j++) {
00493 for(i = 0; i < 9; i++) {
00494 src[i] = ((src[i] - 128) >> 1) + 128;
00495 src2[i] = ((src2[i] - 128) >> 1) + 128;
00496 }
00497 src += s->uvlinesize;
00498 src2 += s->uvlinesize;
00499 }
00500 }
00501
00502 if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
00503 int i, j;
00504 uint8_t *src, *src2;
00505
00506 src = srcY;
00507 for(j = 0; j < 17 + s->mspel*2; j++) {
00508 for(i = 0; i < 17 + s->mspel*2; i++) src[i] = v->luty[src[i]];
00509 src += s->linesize;
00510 }
00511 src = srcU; src2 = srcV;
00512 for(j = 0; j < 9; j++) {
00513 for(i = 0; i < 9; i++) {
00514 src[i] = v->lutuv[src[i]];
00515 src2[i] = v->lutuv[src2[i]];
00516 }
00517 src += s->uvlinesize;
00518 src2 += s->uvlinesize;
00519 }
00520 }
00521 srcY += s->mspel * (1 + s->linesize);
00522 }
00523
00524 if(s->mspel) {
00525 dxy = ((my & 3) << 2) | (mx & 3);
00526 v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] , srcY , s->linesize, v->rnd);
00527 v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8, srcY + 8, s->linesize, v->rnd);
00528 srcY += s->linesize * 8;
00529 v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize , srcY , s->linesize, v->rnd);
00530 v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize + 8, srcY + 8, s->linesize, v->rnd);
00531 } else {
00532 dxy = (my & 2) | ((mx & 2) >> 1);
00533
00534 if(!v->rnd)
00535 dsp->put_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
00536 else
00537 dsp->put_no_rnd_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
00538 }
00539
00540 if(s->flags & CODEC_FLAG_GRAY) return;
00541
00542 uvmx = (uvmx&3)<<1;
00543 uvmy = (uvmy&3)<<1;
00544 if(!v->rnd){
00545 dsp->put_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
00546 dsp->put_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
00547 }else{
00548 v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
00549 v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
00550 }
00551 }
00552
00555 static void vc1_mc_4mv_luma(VC1Context *v, int n)
00556 {
00557 MpegEncContext *s = &v->s;
00558 DSPContext *dsp = &v->s.dsp;
00559 uint8_t *srcY;
00560 int dxy, mx, my, src_x, src_y;
00561 int off;
00562
00563 if(!v->s.last_picture.data[0])return;
00564 mx = s->mv[0][n][0];
00565 my = s->mv[0][n][1];
00566 srcY = s->last_picture.data[0];
00567
00568 off = s->linesize * 4 * (n&2) + (n&1) * 8;
00569
00570 src_x = s->mb_x * 16 + (n&1) * 8 + (mx >> 2);
00571 src_y = s->mb_y * 16 + (n&2) * 4 + (my >> 2);
00572
00573 if(v->profile != PROFILE_ADVANCED){
00574 src_x = av_clip( src_x, -16, s->mb_width * 16);
00575 src_y = av_clip( src_y, -16, s->mb_height * 16);
00576 }else{
00577 src_x = av_clip( src_x, -17, s->avctx->coded_width);
00578 src_y = av_clip( src_y, -18, s->avctx->coded_height + 1);
00579 }
00580
00581 srcY += src_y * s->linesize + src_x;
00582
00583 if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
00584 || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 8 - s->mspel*2
00585 || (unsigned)(src_y - s->mspel) > s->v_edge_pos - (my&3) - 8 - s->mspel*2){
00586 srcY -= s->mspel * (1 + s->linesize);
00587 s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 9+s->mspel*2, 9+s->mspel*2,
00588 src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, s->v_edge_pos);
00589 srcY = s->edge_emu_buffer;
00590
00591 if(v->rangeredfrm) {
00592 int i, j;
00593 uint8_t *src;
00594
00595 src = srcY;
00596 for(j = 0; j < 9 + s->mspel*2; j++) {
00597 for(i = 0; i < 9 + s->mspel*2; i++) src[i] = ((src[i] - 128) >> 1) + 128;
00598 src += s->linesize;
00599 }
00600 }
00601
00602 if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
00603 int i, j;
00604 uint8_t *src;
00605
00606 src = srcY;
00607 for(j = 0; j < 9 + s->mspel*2; j++) {
00608 for(i = 0; i < 9 + s->mspel*2; i++) src[i] = v->luty[src[i]];
00609 src += s->linesize;
00610 }
00611 }
00612 srcY += s->mspel * (1 + s->linesize);
00613 }
00614
00615 if(s->mspel) {
00616 dxy = ((my & 3) << 2) | (mx & 3);
00617 v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize, v->rnd);
00618 } else {
00619 dxy = (my & 2) | ((mx & 2) >> 1);
00620 if(!v->rnd)
00621 dsp->put_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);
00622 else
00623 dsp->put_no_rnd_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);
00624 }
00625 }
00626
00627 static inline int median4(int a, int b, int c, int d)
00628 {
00629 if(a < b) {
00630 if(c < d) return (FFMIN(b, d) + FFMAX(a, c)) / 2;
00631 else return (FFMIN(b, c) + FFMAX(a, d)) / 2;
00632 } else {
00633 if(c < d) return (FFMIN(a, d) + FFMAX(b, c)) / 2;
00634 else return (FFMIN(a, c) + FFMAX(b, d)) / 2;
00635 }
00636 }
00637
00638
00641 static void vc1_mc_4mv_chroma(VC1Context *v)
00642 {
00643 MpegEncContext *s = &v->s;
00644 DSPContext *dsp = &v->s.dsp;
00645 uint8_t *srcU, *srcV;
00646 int uvmx, uvmy, uvsrc_x, uvsrc_y;
00647 int i, idx, tx = 0, ty = 0;
00648 int mvx[4], mvy[4], intra[4];
00649 static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
00650
00651 if(!v->s.last_picture.data[0])return;
00652 if(s->flags & CODEC_FLAG_GRAY) return;
00653
00654 for(i = 0; i < 4; i++) {
00655 mvx[i] = s->mv[0][i][0];
00656 mvy[i] = s->mv[0][i][1];
00657 intra[i] = v->mb_type[0][s->block_index[i]];
00658 }
00659
00660
00661 idx = (intra[3] << 3) | (intra[2] << 2) | (intra[1] << 1) | intra[0];
00662 if(!idx) {
00663 tx = median4(mvx[0], mvx[1], mvx[2], mvx[3]);
00664 ty = median4(mvy[0], mvy[1], mvy[2], mvy[3]);
00665 } else if(count[idx] == 1) {
00666 switch(idx) {
00667 case 0x1:
00668 tx = mid_pred(mvx[1], mvx[2], mvx[3]);
00669 ty = mid_pred(mvy[1], mvy[2], mvy[3]);
00670 break;
00671 case 0x2:
00672 tx = mid_pred(mvx[0], mvx[2], mvx[3]);
00673 ty = mid_pred(mvy[0], mvy[2], mvy[3]);
00674 break;
00675 case 0x4:
00676 tx = mid_pred(mvx[0], mvx[1], mvx[3]);
00677 ty = mid_pred(mvy[0], mvy[1], mvy[3]);
00678 break;
00679 case 0x8:
00680 tx = mid_pred(mvx[0], mvx[1], mvx[2]);
00681 ty = mid_pred(mvy[0], mvy[1], mvy[2]);
00682 break;
00683 }
00684 } else if(count[idx] == 2) {
00685 int t1 = 0, t2 = 0;
00686 for(i=0; i<3;i++) if(!intra[i]) {t1 = i; break;}
00687 for(i= t1+1; i<4; i++)if(!intra[i]) {t2 = i; break;}
00688 tx = (mvx[t1] + mvx[t2]) / 2;
00689 ty = (mvy[t1] + mvy[t2]) / 2;
00690 } else {
00691 s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
00692 s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
00693 v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;
00694 return;
00695 }
00696
00697 s->current_picture.motion_val[1][s->block_index[0]][0] = tx;
00698 s->current_picture.motion_val[1][s->block_index[0]][1] = ty;
00699 uvmx = (tx + ((tx&3) == 3)) >> 1;
00700 uvmy = (ty + ((ty&3) == 3)) >> 1;
00701 v->luma_mv[s->mb_x][0] = uvmx;
00702 v->luma_mv[s->mb_x][1] = uvmy;
00703 if(v->fastuvmc) {
00704 uvmx = uvmx + ((uvmx<0)?(uvmx&1):-(uvmx&1));
00705 uvmy = uvmy + ((uvmy<0)?(uvmy&1):-(uvmy&1));
00706 }
00707
00708 uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
00709 uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
00710
00711 if(v->profile != PROFILE_ADVANCED){
00712 uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);
00713 uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);
00714 }else{
00715 uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
00716 uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
00717 }
00718
00719 srcU = s->last_picture.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;
00720 srcV = s->last_picture.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;
00721 if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
00722 || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 9
00723 || (unsigned)uvsrc_y > (s->v_edge_pos >> 1) - 9){
00724 s->dsp.emulated_edge_mc(s->edge_emu_buffer , srcU, s->uvlinesize, 8+1, 8+1,
00725 uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
00726 s->dsp.emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize, 8+1, 8+1,
00727 uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
00728 srcU = s->edge_emu_buffer;
00729 srcV = s->edge_emu_buffer + 16;
00730
00731
00732 if(v->rangeredfrm) {
00733 int i, j;
00734 uint8_t *src, *src2;
00735
00736 src = srcU; src2 = srcV;
00737 for(j = 0; j < 9; j++) {
00738 for(i = 0; i < 9; i++) {
00739 src[i] = ((src[i] - 128) >> 1) + 128;
00740 src2[i] = ((src2[i] - 128) >> 1) + 128;
00741 }
00742 src += s->uvlinesize;
00743 src2 += s->uvlinesize;
00744 }
00745 }
00746
00747 if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
00748 int i, j;
00749 uint8_t *src, *src2;
00750
00751 src = srcU; src2 = srcV;
00752 for(j = 0; j < 9; j++) {
00753 for(i = 0; i < 9; i++) {
00754 src[i] = v->lutuv[src[i]];
00755 src2[i] = v->lutuv[src2[i]];
00756 }
00757 src += s->uvlinesize;
00758 src2 += s->uvlinesize;
00759 }
00760 }
00761 }
00762
00763
00764 uvmx = (uvmx&3)<<1;
00765 uvmy = (uvmy&3)<<1;
00766 if(!v->rnd){
00767 dsp->put_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
00768 dsp->put_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
00769 }else{
00770 v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
00771 v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
00772 }
00773 }
00774
00775
00786 #define GET_MQUANT() \
00787 if (v->dquantfrm) \
00788 { \
00789 int edges = 0; \
00790 if (v->dqprofile == DQPROFILE_ALL_MBS) \
00791 { \
00792 if (v->dqbilevel) \
00793 { \
00794 mquant = (get_bits1(gb)) ? v->altpq : v->pq; \
00795 } \
00796 else \
00797 { \
00798 mqdiff = get_bits(gb, 3); \
00799 if (mqdiff != 7) mquant = v->pq + mqdiff; \
00800 else mquant = get_bits(gb, 5); \
00801 } \
00802 } \
00803 if(v->dqprofile == DQPROFILE_SINGLE_EDGE) \
00804 edges = 1 << v->dqsbedge; \
00805 else if(v->dqprofile == DQPROFILE_DOUBLE_EDGES) \
00806 edges = (3 << v->dqsbedge) % 15; \
00807 else if(v->dqprofile == DQPROFILE_FOUR_EDGES) \
00808 edges = 15; \
00809 if((edges&1) && !s->mb_x) \
00810 mquant = v->altpq; \
00811 if((edges&2) && s->first_slice_line) \
00812 mquant = v->altpq; \
00813 if((edges&4) && s->mb_x == (s->mb_width - 1)) \
00814 mquant = v->altpq; \
00815 if((edges&8) && s->mb_y == (s->mb_height - 1)) \
00816 mquant = v->altpq; \
00817 }
00818
00826 #define GET_MVDATA(_dmv_x, _dmv_y) \
00827 index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index].table,\
00828 VC1_MV_DIFF_VLC_BITS, 2); \
00829 if (index > 36) \
00830 { \
00831 mb_has_coeffs = 1; \
00832 index -= 37; \
00833 } \
00834 else mb_has_coeffs = 0; \
00835 s->mb_intra = 0; \
00836 if (!index) { _dmv_x = _dmv_y = 0; } \
00837 else if (index == 35) \
00838 { \
00839 _dmv_x = get_bits(gb, v->k_x - 1 + s->quarter_sample); \
00840 _dmv_y = get_bits(gb, v->k_y - 1 + s->quarter_sample); \
00841 } \
00842 else if (index == 36) \
00843 { \
00844 _dmv_x = 0; \
00845 _dmv_y = 0; \
00846 s->mb_intra = 1; \
00847 } \
00848 else \
00849 { \
00850 index1 = index%6; \
00851 if (!s->quarter_sample && index1 == 5) val = 1; \
00852 else val = 0; \
00853 if(size_table[index1] - val > 0) \
00854 val = get_bits(gb, size_table[index1] - val); \
00855 else val = 0; \
00856 sign = 0 - (val&1); \
00857 _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
00858 \
00859 index1 = index/6; \
00860 if (!s->quarter_sample && index1 == 5) val = 1; \
00861 else val = 0; \
00862 if(size_table[index1] - val > 0) \
00863 val = get_bits(gb, size_table[index1] - val); \
00864 else val = 0; \
00865 sign = 0 - (val&1); \
00866 _dmv_y = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
00867 }
00868
00871 static inline void vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y, int mv1, int r_x, int r_y, uint8_t* is_intra)
00872 {
00873 MpegEncContext *s = &v->s;
00874 int xy, wrap, off = 0;
00875 int16_t *A, *B, *C;
00876 int px, py;
00877 int sum;
00878
00879
00880 dmv_x <<= 1 - s->quarter_sample;
00881 dmv_y <<= 1 - s->quarter_sample;
00882
00883 wrap = s->b8_stride;
00884 xy = s->block_index[n];
00885
00886 if(s->mb_intra){
00887 s->mv[0][n][0] = s->current_picture.motion_val[0][xy][0] = 0;
00888 s->mv[0][n][1] = s->current_picture.motion_val[0][xy][1] = 0;
00889 s->current_picture.motion_val[1][xy][0] = 0;
00890 s->current_picture.motion_val[1][xy][1] = 0;
00891 if(mv1) {
00892 s->current_picture.motion_val[0][xy + 1][0] = 0;
00893 s->current_picture.motion_val[0][xy + 1][1] = 0;
00894 s->current_picture.motion_val[0][xy + wrap][0] = 0;
00895 s->current_picture.motion_val[0][xy + wrap][1] = 0;
00896 s->current_picture.motion_val[0][xy + wrap + 1][0] = 0;
00897 s->current_picture.motion_val[0][xy + wrap + 1][1] = 0;
00898 v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;
00899 s->current_picture.motion_val[1][xy + 1][0] = 0;
00900 s->current_picture.motion_val[1][xy + 1][1] = 0;
00901 s->current_picture.motion_val[1][xy + wrap][0] = 0;
00902 s->current_picture.motion_val[1][xy + wrap][1] = 0;
00903 s->current_picture.motion_val[1][xy + wrap + 1][0] = 0;
00904 s->current_picture.motion_val[1][xy + wrap + 1][1] = 0;
00905 }
00906 return;
00907 }
00908
00909 C = s->current_picture.motion_val[0][xy - 1];
00910 A = s->current_picture.motion_val[0][xy - wrap];
00911 if(mv1)
00912 off = (s->mb_x == (s->mb_width - 1)) ? -1 : 2;
00913 else {
00914
00915 switch(n){
00916 case 0:
00917 off = (s->mb_x > 0) ? -1 : 1;
00918 break;
00919 case 1:
00920 off = (s->mb_x == (s->mb_width - 1)) ? -1 : 1;
00921 break;
00922 case 2:
00923 off = 1;
00924 break;
00925 case 3:
00926 off = -1;
00927 }
00928 }
00929 B = s->current_picture.motion_val[0][xy - wrap + off];
00930
00931 if(!s->first_slice_line || (n==2 || n==3)) {
00932 if(s->mb_width == 1) {
00933 px = A[0];
00934 py = A[1];
00935 } else {
00936 px = mid_pred(A[0], B[0], C[0]);
00937 py = mid_pred(A[1], B[1], C[1]);
00938 }
00939 } else if(s->mb_x || (n==1 || n==3)) {
00940 px = C[0];
00941 py = C[1];
00942 } else {
00943 px = py = 0;
00944 }
00945
00946 {
00947 int qx, qy, X, Y;
00948 qx = (s->mb_x << 6) + ((n==1 || n==3) ? 32 : 0);
00949 qy = (s->mb_y << 6) + ((n==2 || n==3) ? 32 : 0);
00950 X = (s->mb_width << 6) - 4;
00951 Y = (s->mb_height << 6) - 4;
00952 if(mv1) {
00953 if(qx + px < -60) px = -60 - qx;
00954 if(qy + py < -60) py = -60 - qy;
00955 } else {
00956 if(qx + px < -28) px = -28 - qx;
00957 if(qy + py < -28) py = -28 - qy;
00958 }
00959 if(qx + px > X) px = X - qx;
00960 if(qy + py > Y) py = Y - qy;
00961 }
00962
00963 if((!s->first_slice_line || (n==2 || n==3)) && (s->mb_x || (n==1 || n==3))) {
00964 if(is_intra[xy - wrap])
00965 sum = FFABS(px) + FFABS(py);
00966 else
00967 sum = FFABS(px - A[0]) + FFABS(py - A[1]);
00968 if(sum > 32) {
00969 if(get_bits1(&s->gb)) {
00970 px = A[0];
00971 py = A[1];
00972 } else {
00973 px = C[0];
00974 py = C[1];
00975 }
00976 } else {
00977 if(is_intra[xy - 1])
00978 sum = FFABS(px) + FFABS(py);
00979 else
00980 sum = FFABS(px - C[0]) + FFABS(py - C[1]);
00981 if(sum > 32) {
00982 if(get_bits1(&s->gb)) {
00983 px = A[0];
00984 py = A[1];
00985 } else {
00986 px = C[0];
00987 py = C[1];
00988 }
00989 }
00990 }
00991 }
00992
00993 s->mv[0][n][0] = s->current_picture.motion_val[0][xy][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
00994 s->mv[0][n][1] = s->current_picture.motion_val[0][xy][1] = ((py + dmv_y + r_y) & ((r_y << 1) - 1)) - r_y;
00995 if(mv1) {
00996 s->current_picture.motion_val[0][xy + 1][0] = s->current_picture.motion_val[0][xy][0];
00997 s->current_picture.motion_val[0][xy + 1][1] = s->current_picture.motion_val[0][xy][1];
00998 s->current_picture.motion_val[0][xy + wrap][0] = s->current_picture.motion_val[0][xy][0];
00999 s->current_picture.motion_val[0][xy + wrap][1] = s->current_picture.motion_val[0][xy][1];
01000 s->current_picture.motion_val[0][xy + wrap + 1][0] = s->current_picture.motion_val[0][xy][0];
01001 s->current_picture.motion_val[0][xy + wrap + 1][1] = s->current_picture.motion_val[0][xy][1];
01002 }
01003 }
01004
01007 static void vc1_interp_mc(VC1Context *v)
01008 {
01009 MpegEncContext *s = &v->s;
01010 DSPContext *dsp = &v->s.dsp;
01011 uint8_t *srcY, *srcU, *srcV;
01012 int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
01013
01014 if(!v->s.next_picture.data[0])return;
01015
01016 mx = s->mv[1][0][0];
01017 my = s->mv[1][0][1];
01018 uvmx = (mx + ((mx & 3) == 3)) >> 1;
01019 uvmy = (my + ((my & 3) == 3)) >> 1;
01020 if(v->fastuvmc) {
01021 uvmx = uvmx + ((uvmx<0)?-(uvmx&1):(uvmx&1));
01022 uvmy = uvmy + ((uvmy<0)?-(uvmy&1):(uvmy&1));
01023 }
01024 srcY = s->next_picture.data[0];
01025 srcU = s->next_picture.data[1];
01026 srcV = s->next_picture.data[2];
01027
01028 src_x = s->mb_x * 16 + (mx >> 2);
01029 src_y = s->mb_y * 16 + (my >> 2);
01030 uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
01031 uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
01032
01033 if(v->profile != PROFILE_ADVANCED){
01034 src_x = av_clip( src_x, -16, s->mb_width * 16);
01035 src_y = av_clip( src_y, -16, s->mb_height * 16);
01036 uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);
01037 uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);
01038 }else{
01039 src_x = av_clip( src_x, -17, s->avctx->coded_width);
01040 src_y = av_clip( src_y, -18, s->avctx->coded_height + 1);
01041 uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
01042 uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
01043 }
01044
01045 srcY += src_y * s->linesize + src_x;
01046 srcU += uvsrc_y * s->uvlinesize + uvsrc_x;
01047 srcV += uvsrc_y * s->uvlinesize + uvsrc_x;
01048
01049
01050 if(s->flags & CODEC_FLAG_GRAY) {
01051 srcU = s->edge_emu_buffer + 18 * s->linesize;
01052 srcV = s->edge_emu_buffer + 18 * s->linesize;
01053 }
01054
01055 if(v->rangeredfrm
01056 || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 16 - s->mspel*3
01057 || (unsigned)(src_y - s->mspel) > s->v_edge_pos - (my&3) - 16 - s->mspel*3){
01058 uint8_t *uvbuf= s->edge_emu_buffer + 19 * s->linesize;
01059
01060 srcY -= s->mspel * (1 + s->linesize);
01061 s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 17+s->mspel*2, 17+s->mspel*2,
01062 src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, s->v_edge_pos);
01063 srcY = s->edge_emu_buffer;
01064 s->dsp.emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8+1, 8+1,
01065 uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
01066 s->dsp.emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8+1, 8+1,
01067 uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
01068 srcU = uvbuf;
01069 srcV = uvbuf + 16;
01070
01071 if(v->rangeredfrm) {
01072 int i, j;
01073 uint8_t *src, *src2;
01074
01075 src = srcY;
01076 for(j = 0; j < 17 + s->mspel*2; j++) {
01077 for(i = 0; i < 17 + s->mspel*2; i++) src[i] = ((src[i] - 128) >> 1) + 128;
01078 src += s->linesize;
01079 }
01080 src = srcU; src2 = srcV;
01081 for(j = 0; j < 9; j++) {
01082 for(i = 0; i < 9; i++) {
01083 src[i] = ((src[i] - 128) >> 1) + 128;
01084 src2[i] = ((src2[i] - 128) >> 1) + 128;
01085 }
01086 src += s->uvlinesize;
01087 src2 += s->uvlinesize;
01088 }
01089 }
01090 srcY += s->mspel * (1 + s->linesize);
01091 }
01092
01093 if(s->mspel) {
01094 dxy = ((my & 3) << 2) | (mx & 3);
01095 v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] , srcY , s->linesize, v->rnd);
01096 v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8, srcY + 8, s->linesize, v->rnd);
01097 srcY += s->linesize * 8;
01098 v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize , srcY , s->linesize, v->rnd);
01099 v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize + 8, srcY + 8, s->linesize, v->rnd);
01100 } else {
01101 dxy = (my & 2) | ((mx & 2) >> 1);
01102
01103 if(!v->rnd)
01104 dsp->avg_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
01105 else
01106 dsp->avg_no_rnd_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
01107 }
01108
01109 if(s->flags & CODEC_FLAG_GRAY) return;
01110
01111 uvmx = (uvmx&3)<<1;
01112 uvmy = (uvmy&3)<<1;
01113 if(!v->rnd){
01114 dsp->avg_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
01115 dsp->avg_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
01116 }else{
01117 v->vc1dsp.avg_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
01118 v->vc1dsp.avg_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
01119 }
01120 }
01121
01122 static av_always_inline int scale_mv(int value, int bfrac, int inv, int qs)
01123 {
01124 int n = bfrac;
01125
01126 #if B_FRACTION_DEN==256
01127 if(inv)
01128 n -= 256;
01129 if(!qs)
01130 return 2 * ((value * n + 255) >> 9);
01131 return (value * n + 128) >> 8;
01132 #else
01133 if(inv)
01134 n -= B_FRACTION_DEN;
01135 if(!qs)
01136 return 2 * ((value * n + B_FRACTION_DEN - 1) / (2 * B_FRACTION_DEN));
01137 return (value * n + B_FRACTION_DEN/2) / B_FRACTION_DEN;
01138 #endif
01139 }
01140
01143 static inline void vc1_b_mc(VC1Context *v, int dmv_x[2], int dmv_y[2], int direct, int mode)
01144 {
01145 if(v->use_ic) {
01146 v->mv_mode2 = v->mv_mode;
01147 v->mv_mode = MV_PMODE_INTENSITY_COMP;
01148 }
01149 if(direct) {
01150 vc1_mc_1mv(v, 0);
01151 vc1_interp_mc(v);
01152 if(v->use_ic) v->mv_mode = v->mv_mode2;
01153 return;
01154 }
01155 if(mode == BMV_TYPE_INTERPOLATED) {
01156 vc1_mc_1mv(v, 0);
01157 vc1_interp_mc(v);
01158 if(v->use_ic) v->mv_mode = v->mv_mode2;
01159 return;
01160 }
01161
01162 if(v->use_ic && (mode == BMV_TYPE_BACKWARD)) v->mv_mode = v->mv_mode2;
01163 vc1_mc_1mv(v, (mode == BMV_TYPE_BACKWARD));
01164 if(v->use_ic) v->mv_mode = v->mv_mode2;
01165 }
01166
01167 static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int direct, int mvtype)
01168 {
01169 MpegEncContext *s = &v->s;
01170 int xy, wrap, off = 0;
01171 int16_t *A, *B, *C;
01172 int px, py;
01173 int sum;
01174 int r_x, r_y;
01175 const uint8_t *is_intra = v->mb_type[0];
01176
01177 r_x = v->range_x;
01178 r_y = v->range_y;
01179
01180 dmv_x[0] <<= 1 - s->quarter_sample;
01181 dmv_y[0] <<= 1 - s->quarter_sample;
01182 dmv_x[1] <<= 1 - s->quarter_sample;
01183 dmv_y[1] <<= 1 - s->quarter_sample;
01184
01185 wrap = s->b8_stride;
01186 xy = s->block_index[0];
01187
01188 if(s->mb_intra) {
01189 s->current_picture.motion_val[0][xy][0] =
01190 s->current_picture.motion_val[0][xy][1] =
01191 s->current_picture.motion_val[1][xy][0] =
01192 s->current_picture.motion_val[1][xy][1] = 0;
01193 return;
01194 }
01195 s->mv[0][0][0] = scale_mv(s->next_picture.motion_val[1][xy][0], v->bfraction, 0, s->quarter_sample);
01196 s->mv[0][0][1] = scale_mv(s->next_picture.motion_val[1][xy][1], v->bfraction, 0, s->quarter_sample);
01197 s->mv[1][0][0] = scale_mv(s->next_picture.motion_val[1][xy][0], v->bfraction, 1, s->quarter_sample);
01198 s->mv[1][0][1] = scale_mv(s->next_picture.motion_val[1][xy][1], v->bfraction, 1, s->quarter_sample);
01199
01200
01201 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));
01202 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));
01203 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));
01204 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));
01205 if(direct) {
01206 s->current_picture.motion_val[0][xy][0] = s->mv[0][0][0];
01207 s->current_picture.motion_val[0][xy][1] = s->mv[0][0][1];
01208 s->current_picture.motion_val[1][xy][0] = s->mv[1][0][0];
01209 s->current_picture.motion_val[1][xy][1] = s->mv[1][0][1];
01210 return;
01211 }
01212
01213 if((mvtype == BMV_TYPE_FORWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) {
01214 C = s->current_picture.motion_val[0][xy - 2];
01215 A = s->current_picture.motion_val[0][xy - wrap*2];
01216 off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
01217 B = s->current_picture.motion_val[0][xy - wrap*2 + off];
01218
01219 if(!s->mb_x) C[0] = C[1] = 0;
01220 if(!s->first_slice_line) {
01221 if(s->mb_width == 1) {
01222 px = A[0];
01223 py = A[1];
01224 } else {
01225 px = mid_pred(A[0], B[0], C[0]);
01226 py = mid_pred(A[1], B[1], C[1]);
01227 }
01228 } else if(s->mb_x) {
01229 px = C[0];
01230 py = C[1];
01231 } else {
01232 px = py = 0;
01233 }
01234
01235 {
01236 int qx, qy, X, Y;
01237 if(v->profile < PROFILE_ADVANCED) {
01238 qx = (s->mb_x << 5);
01239 qy = (s->mb_y << 5);
01240 X = (s->mb_width << 5) - 4;
01241 Y = (s->mb_height << 5) - 4;
01242 if(qx + px < -28) px = -28 - qx;
01243 if(qy + py < -28) py = -28 - qy;
01244 if(qx + px > X) px = X - qx;
01245 if(qy + py > Y) py = Y - qy;
01246 } else {
01247 qx = (s->mb_x << 6);
01248 qy = (s->mb_y << 6);
01249 X = (s->mb_width << 6) - 4;
01250 Y = (s->mb_height << 6) - 4;
01251 if(qx + px < -60) px = -60 - qx;
01252 if(qy + py < -60) py = -60 - qy;
01253 if(qx + px > X) px = X - qx;
01254 if(qy + py > Y) py = Y - qy;
01255 }
01256 }
01257
01258 if(0 && !s->first_slice_line && s->mb_x) {
01259 if(is_intra[xy - wrap])
01260 sum = FFABS(px) + FFABS(py);
01261 else
01262 sum = FFABS(px - A[0]) + FFABS(py - A[1]);
01263 if(sum > 32) {
01264 if(get_bits1(&s->gb)) {
01265 px = A[0];
01266 py = A[1];
01267 } else {
01268 px = C[0];
01269 py = C[1];
01270 }
01271 } else {
01272 if(is_intra[xy - 2])
01273 sum = FFABS(px) + FFABS(py);
01274 else
01275 sum = FFABS(px - C[0]) + FFABS(py - C[1]);
01276 if(sum > 32) {
01277 if(get_bits1(&s->gb)) {
01278 px = A[0];
01279 py = A[1];
01280 } else {
01281 px = C[0];
01282 py = C[1];
01283 }
01284 }
01285 }
01286 }
01287
01288 s->mv[0][0][0] = ((px + dmv_x[0] + r_x) & ((r_x << 1) - 1)) - r_x;
01289 s->mv[0][0][1] = ((py + dmv_y[0] + r_y) & ((r_y << 1) - 1)) - r_y;
01290 }
01291 if((mvtype == BMV_TYPE_BACKWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) {
01292 C = s->current_picture.motion_val[1][xy - 2];
01293 A = s->current_picture.motion_val[1][xy - wrap*2];
01294 off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
01295 B = s->current_picture.motion_val[1][xy - wrap*2 + off];
01296
01297 if(!s->mb_x) C[0] = C[1] = 0;
01298 if(!s->first_slice_line) {
01299 if(s->mb_width == 1) {
01300 px = A[0];
01301 py = A[1];
01302 } else {
01303 px = mid_pred(A[0], B[0], C[0]);
01304 py = mid_pred(A[1], B[1], C[1]);
01305 }
01306 } else if(s->mb_x) {
01307 px = C[0];
01308 py = C[1];
01309 } else {
01310 px = py = 0;
01311 }
01312
01313 {
01314 int qx, qy, X, Y;
01315 if(v->profile < PROFILE_ADVANCED) {
01316 qx = (s->mb_x << 5);
01317 qy = (s->mb_y << 5);
01318 X = (s->mb_width << 5) - 4;
01319 Y = (s->mb_height << 5) - 4;
01320 if(qx + px < -28) px = -28 - qx;
01321 if(qy + py < -28) py = -28 - qy;
01322 if(qx + px > X) px = X - qx;
01323 if(qy + py > Y) py = Y - qy;
01324 } else {
01325 qx = (s->mb_x << 6);
01326 qy = (s->mb_y << 6);
01327 X = (s->mb_width << 6) - 4;
01328 Y = (s->mb_height << 6) - 4;
01329 if(qx + px < -60) px = -60 - qx;
01330 if(qy + py < -60) py = -60 - qy;
01331 if(qx + px > X) px = X - qx;
01332 if(qy + py > Y) py = Y - qy;
01333 }
01334 }
01335
01336 if(0 && !s->first_slice_line && s->mb_x) {
01337 if(is_intra[xy - wrap])
01338 sum = FFABS(px) + FFABS(py);
01339 else
01340 sum = FFABS(px - A[0]) + FFABS(py - A[1]);
01341 if(sum > 32) {
01342 if(get_bits1(&s->gb)) {
01343 px = A[0];
01344 py = A[1];
01345 } else {
01346 px = C[0];
01347 py = C[1];
01348 }
01349 } else {
01350 if(is_intra[xy - 2])
01351 sum = FFABS(px) + FFABS(py);
01352 else
01353 sum = FFABS(px - C[0]) + FFABS(py - C[1]);
01354 if(sum > 32) {
01355 if(get_bits1(&s->gb)) {
01356 px = A[0];
01357 py = A[1];
01358 } else {
01359 px = C[0];
01360 py = C[1];
01361 }
01362 }
01363 }
01364 }
01365
01366
01367 s->mv[1][0][0] = ((px + dmv_x[1] + r_x) & ((r_x << 1) - 1)) - r_x;
01368 s->mv[1][0][1] = ((py + dmv_y[1] + r_y) & ((r_y << 1) - 1)) - r_y;
01369 }
01370 s->current_picture.motion_val[0][xy][0] = s->mv[0][0][0];
01371 s->current_picture.motion_val[0][xy][1] = s->mv[0][0][1];
01372 s->current_picture.motion_val[1][xy][0] = s->mv[1][0][0];
01373 s->current_picture.motion_val[1][xy][1] = s->mv[1][0][1];
01374 }
01375
01385 static inline int vc1_i_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
01386 int16_t **dc_val_ptr, int *dir_ptr)
01387 {
01388 int a, b, c, wrap, pred, scale;
01389 int16_t *dc_val;
01390 static const uint16_t dcpred[32] = {
01391 -1, 1024, 512, 341, 256, 205, 171, 146, 128,
01392 114, 102, 93, 85, 79, 73, 68, 64,
01393 60, 57, 54, 51, 49, 47, 45, 43,
01394 41, 39, 38, 37, 35, 34, 33
01395 };
01396
01397
01398 if (n < 4) scale = s->y_dc_scale;
01399 else scale = s->c_dc_scale;
01400
01401 wrap = s->block_wrap[n];
01402 dc_val= s->dc_val[0] + s->block_index[n];
01403
01404
01405
01406
01407 c = dc_val[ - 1];
01408 b = dc_val[ - 1 - wrap];
01409 a = dc_val[ - wrap];
01410
01411 if (pq < 9 || !overlap)
01412 {
01413
01414 if (s->first_slice_line && (n!=2 && n!=3)) b=a=dcpred[scale];
01415 if (s->mb_x == 0 && (n!=1 && n!=3)) b=c=dcpred[scale];
01416 }
01417 else
01418 {
01419
01420 if (s->first_slice_line && (n!=2 && n!=3)) b=a=0;
01421 if (s->mb_x == 0 && (n!=1 && n!=3)) b=c=0;
01422 }
01423
01424 if (abs(a - b) <= abs(b - c)) {
01425 pred = c;
01426 *dir_ptr = 1;
01427 } else {
01428 pred = a;
01429 *dir_ptr = 0;
01430 }
01431
01432
01433 *dc_val_ptr = &dc_val[0];
01434 return pred;
01435 }
01436
01437
01449 static inline int vc1_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
01450 int a_avail, int c_avail,
01451 int16_t **dc_val_ptr, int *dir_ptr)
01452 {
01453 int a, b, c, wrap, pred;
01454 int16_t *dc_val;
01455 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
01456 int q1, q2 = 0;
01457
01458 wrap = s->block_wrap[n];
01459 dc_val= s->dc_val[0] + s->block_index[n];
01460
01461
01462
01463
01464 c = dc_val[ - 1];
01465 b = dc_val[ - 1 - wrap];
01466 a = dc_val[ - wrap];
01467
01468 q1 = s->current_picture.qscale_table[mb_pos];
01469 if(c_avail && (n!= 1 && n!=3)) {
01470 q2 = s->current_picture.qscale_table[mb_pos - 1];
01471 if(q2 && q2 != q1)
01472 c = (c * s->y_dc_scale_table[q2] * ff_vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18;
01473 }
01474 if(a_avail && (n!= 2 && n!=3)) {
01475 q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
01476 if(q2 && q2 != q1)
01477 a = (a * s->y_dc_scale_table[q2] * ff_vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18;
01478 }
01479 if(a_avail && c_avail && (n!=3)) {
01480 int off = mb_pos;
01481 if(n != 1) off--;
01482 if(n != 2) off -= s->mb_stride;
01483 q2 = s->current_picture.qscale_table[off];
01484 if(q2 && q2 != q1)
01485 b = (b * s->y_dc_scale_table[q2] * ff_vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18;
01486 }
01487
01488 if(a_avail && c_avail) {
01489 if(abs(a - b) <= abs(b - c)) {
01490 pred = c;
01491 *dir_ptr = 1;
01492 } else {
01493 pred = a;
01494 *dir_ptr = 0;
01495 }
01496 } else if(a_avail) {
01497 pred = a;
01498 *dir_ptr = 0;
01499 } else if(c_avail) {
01500 pred = c;
01501 *dir_ptr = 1;
01502 } else {
01503 pred = 0;
01504 *dir_ptr = 1;
01505 }
01506
01507
01508 *dc_val_ptr = &dc_val[0];
01509 return pred;
01510 }
01511
01513
01520 static inline int vc1_coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr)
01521 {
01522 int xy, wrap, pred, a, b, c;
01523
01524 xy = s->block_index[n];
01525 wrap = s->b8_stride;
01526
01527
01528
01529
01530 a = s->coded_block[xy - 1 ];
01531 b = s->coded_block[xy - 1 - wrap];
01532 c = s->coded_block[xy - wrap];
01533
01534 if (b == c) {
01535 pred = a;
01536 } else {
01537 pred = c;
01538 }
01539
01540
01541 *coded_block_ptr = &s->coded_block[xy];
01542
01543 return pred;
01544 }
01545
01555 static void vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip, int *value, int codingset)
01556 {
01557 GetBitContext *gb = &v->s.gb;
01558 int index, escape, run = 0, level = 0, lst = 0;
01559
01560 index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
01561 if (index != vc1_ac_sizes[codingset] - 1) {
01562 run = vc1_index_decode_table[codingset][index][0];
01563 level = vc1_index_decode_table[codingset][index][1];
01564 lst = index >= vc1_last_decode_table[codingset] || get_bits_left(gb) < 0;
01565 if(get_bits1(gb))
01566 level = -level;
01567 } else {
01568 escape = decode210(gb);
01569 if (escape != 2) {
01570 index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
01571 run = vc1_index_decode_table[codingset][index][0];
01572 level = vc1_index_decode_table[codingset][index][1];
01573 lst = index >= vc1_last_decode_table[codingset];
01574 if(escape == 0) {
01575 if(lst)
01576 level += vc1_last_delta_level_table[codingset][run];
01577 else
01578 level += vc1_delta_level_table[codingset][run];
01579 } else {
01580 if(lst)
01581 run += vc1_last_delta_run_table[codingset][level] + 1;
01582 else
01583 run += vc1_delta_run_table[codingset][level] + 1;
01584 }
01585 if(get_bits1(gb))
01586 level = -level;
01587 } else {
01588 int sign;
01589 lst = get_bits1(gb);
01590 if(v->s.esc3_level_length == 0) {
01591 if(v->pq < 8 || v->dquantfrm) {
01592 v->s.esc3_level_length = get_bits(gb, 3);
01593 if(!v->s.esc3_level_length)
01594 v->s.esc3_level_length = get_bits(gb, 2) + 8;
01595 } else {
01596 v->s.esc3_level_length = get_unary(gb, 1, 6) + 2;
01597 }
01598 v->s.esc3_run_length = 3 + get_bits(gb, 2);
01599 }
01600 run = get_bits(gb, v->s.esc3_run_length);
01601 sign = get_bits1(gb);
01602 level = get_bits(gb, v->s.esc3_level_length);
01603 if(sign)
01604 level = -level;
01605 }
01606 }
01607
01608 *last = lst;
01609 *skip = run;
01610 *value = level;
01611 }
01612
01620 static int vc1_decode_i_block(VC1Context *v, DCTELEM block[64], int n, int coded, int codingset)
01621 {
01622 GetBitContext *gb = &v->s.gb;
01623 MpegEncContext *s = &v->s;
01624 int dc_pred_dir = 0;
01625 int i;
01626 int16_t *dc_val;
01627 int16_t *ac_val, *ac_val2;
01628 int dcdiff;
01629
01630
01631 if (n < 4) {
01632 dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
01633 } else {
01634 dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
01635 }
01636 if (dcdiff < 0){
01637 av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
01638 return -1;
01639 }
01640 if (dcdiff)
01641 {
01642 if (dcdiff == 119 )
01643 {
01644
01645 if (v->pq == 1) dcdiff = get_bits(gb, 10);
01646 else if (v->pq == 2) dcdiff = get_bits(gb, 9);
01647 else dcdiff = get_bits(gb, 8);
01648 }
01649 else
01650 {
01651 if (v->pq == 1)
01652 dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
01653 else if (v->pq == 2)
01654 dcdiff = (dcdiff<<1) + get_bits1(gb) - 1;
01655 }
01656 if (get_bits1(gb))
01657 dcdiff = -dcdiff;
01658 }
01659
01660
01661 dcdiff += vc1_i_pred_dc(&v->s, v->overlap, v->pq, n, &dc_val, &dc_pred_dir);
01662 *dc_val = dcdiff;
01663
01664
01665 if (n < 4) {
01666 block[0] = dcdiff * s->y_dc_scale;
01667 } else {
01668 block[0] = dcdiff * s->c_dc_scale;
01669 }
01670
01671 if (!coded) {
01672 goto not_coded;
01673 }
01674
01675
01676 i = 1;
01677
01678 {
01679 int last = 0, skip, value;
01680 const uint8_t *zz_table;
01681 int scale;
01682 int k;
01683
01684 scale = v->pq * 2 + v->halfpq;
01685
01686 if(v->s.ac_pred) {
01687 if(!dc_pred_dir)
01688 zz_table = v->zz_8x8[2];
01689 else
01690 zz_table = v->zz_8x8[3];
01691 } else
01692 zz_table = v->zz_8x8[1];
01693
01694 ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
01695 ac_val2 = ac_val;
01696 if(dc_pred_dir)
01697 ac_val -= 16;
01698 else
01699 ac_val -= 16 * s->block_wrap[n];
01700
01701 while (!last) {
01702 vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
01703 i += skip;
01704 if(i > 63)
01705 break;
01706 block[zz_table[i++]] = value;
01707 }
01708
01709
01710 if(s->ac_pred) {
01711 if(dc_pred_dir) {
01712 for(k = 1; k < 8; k++)
01713 block[k << v->left_blk_sh] += ac_val[k];
01714 } else {
01715 for(k = 1; k < 8; k++)
01716 block[k << v->top_blk_sh] += ac_val[k + 8];
01717 }
01718 }
01719
01720 for(k = 1; k < 8; k++) {
01721 ac_val2[k] = block[k << v->left_blk_sh];
01722 ac_val2[k + 8] = block[k << v->top_blk_sh];
01723 }
01724
01725
01726 for(k = 1; k < 64; k++)
01727 if(block[k]) {
01728 block[k] *= scale;
01729 if(!v->pquantizer)
01730 block[k] += (block[k] < 0) ? -v->pq : v->pq;
01731 }
01732
01733 if(s->ac_pred) i = 63;
01734 }
01735
01736 not_coded:
01737 if(!coded) {
01738 int k, scale;
01739 ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
01740 ac_val2 = ac_val;
01741
01742 i = 0;
01743 scale = v->pq * 2 + v->halfpq;
01744 memset(ac_val2, 0, 16 * 2);
01745 if(dc_pred_dir) {
01746 ac_val -= 16;
01747 if(s->ac_pred)
01748 memcpy(ac_val2, ac_val, 8 * 2);
01749 } else {
01750 ac_val -= 16 * s->block_wrap[n];
01751 if(s->ac_pred)
01752 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
01753 }
01754
01755
01756 if(s->ac_pred) {
01757 if(dc_pred_dir) {
01758 for(k = 1; k < 8; k++) {
01759 block[k << v->left_blk_sh] = ac_val[k] * scale;
01760 if(!v->pquantizer && block[k << v->left_blk_sh])
01761 block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -v->pq : v->pq;
01762 }
01763 } else {
01764 for(k = 1; k < 8; k++) {
01765 block[k << v->top_blk_sh] = ac_val[k + 8] * scale;
01766 if(!v->pquantizer && block[k << v->top_blk_sh])
01767 block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -v->pq : v->pq;
01768 }
01769 }
01770 i = 63;
01771 }
01772 }
01773 s->block_last_index[n] = i;
01774
01775 return 0;
01776 }
01777
01786 static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n, int coded, int codingset, int mquant)
01787 {
01788 GetBitContext *gb = &v->s.gb;
01789 MpegEncContext *s = &v->s;
01790 int dc_pred_dir = 0;
01791 int i;
01792 int16_t *dc_val;
01793 int16_t *ac_val, *ac_val2;
01794 int dcdiff;
01795 int a_avail = v->a_avail, c_avail = v->c_avail;
01796 int use_pred = s->ac_pred;
01797 int scale;
01798 int q1, q2 = 0;
01799 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
01800
01801
01802 if (n < 4) {
01803 dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
01804 } else {
01805 dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
01806 }
01807 if (dcdiff < 0){
01808 av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
01809 return -1;
01810 }
01811 if (dcdiff)
01812 {
01813 if (dcdiff == 119 )
01814 {
01815
01816 if (mquant == 1) dcdiff = get_bits(gb, 10);
01817 else if (mquant == 2) dcdiff = get_bits(gb, 9);
01818 else dcdiff = get_bits(gb, 8);
01819 }
01820 else
01821 {
01822 if (mquant == 1)
01823 dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
01824 else if (mquant == 2)
01825 dcdiff = (dcdiff<<1) + get_bits1(gb) - 1;
01826 }
01827 if (get_bits1(gb))
01828 dcdiff = -dcdiff;
01829 }
01830
01831
01832 dcdiff += vc1_pred_dc(&v->s, v->overlap, mquant, n, v->a_avail, v->c_avail, &dc_val, &dc_pred_dir);
01833 *dc_val = dcdiff;
01834
01835
01836 if (n < 4) {
01837 block[0] = dcdiff * s->y_dc_scale;
01838 } else {
01839 block[0] = dcdiff * s->c_dc_scale;
01840 }
01841
01842
01843 i = 1;
01844
01845
01846 if(!a_avail && !c_avail) use_pred = 0;
01847 ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
01848 ac_val2 = ac_val;
01849
01850 scale = mquant * 2 + ((mquant == v->pq) ? v->halfpq : 0);
01851
01852 if(dc_pred_dir)
01853 ac_val -= 16;
01854 else
01855 ac_val -= 16 * s->block_wrap[n];
01856
01857 q1 = s->current_picture.qscale_table[mb_pos];
01858 if(dc_pred_dir && c_avail && mb_pos) q2 = s->current_picture.qscale_table[mb_pos - 1];
01859 if(!dc_pred_dir && a_avail && mb_pos >= s->mb_stride) q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
01860 if(dc_pred_dir && n==1) q2 = q1;
01861 if(!dc_pred_dir && n==2) q2 = q1;
01862 if(n==3) q2 = q1;
01863
01864 if(coded) {
01865 int last = 0, skip, value;
01866 const uint8_t *zz_table;
01867 int k;
01868
01869 if(v->s.ac_pred) {
01870 if(!dc_pred_dir)
01871 zz_table = v->zz_8x8[2];
01872 else
01873 zz_table = v->zz_8x8[3];
01874 } else
01875 zz_table = v->zz_8x8[1];
01876
01877 while (!last) {
01878 vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
01879 i += skip;
01880 if(i > 63)
01881 break;
01882 block[zz_table[i++]] = value;
01883 }
01884
01885
01886 if(use_pred) {
01887
01888 if(q2 && q1!=q2) {
01889 q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
01890 q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
01891
01892 if(dc_pred_dir) {
01893 for(k = 1; k < 8; k++)
01894 block[k << v->left_blk_sh] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
01895 } else {
01896 for(k = 1; k < 8; k++)
01897 block[k << v->top_blk_sh] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
01898 }
01899 } else {
01900 if(dc_pred_dir) {
01901 for(k = 1; k < 8; k++)
01902 block[k << v->left_blk_sh] += ac_val[k];
01903 } else {
01904 for(k = 1; k < 8; k++)
01905 block[k << v->top_blk_sh] += ac_val[k + 8];
01906 }
01907 }
01908 }
01909
01910 for(k = 1; k < 8; k++) {
01911 ac_val2[k ] = block[k << v->left_blk_sh];
01912 ac_val2[k + 8] = block[k << v->top_blk_sh];
01913 }
01914
01915
01916 for(k = 1; k < 64; k++)
01917 if(block[k]) {
01918 block[k] *= scale;
01919 if(!v->pquantizer)
01920 block[k] += (block[k] < 0) ? -mquant : mquant;
01921 }
01922
01923 if(use_pred) i = 63;
01924 } else {
01925 int k;
01926
01927 memset(ac_val2, 0, 16 * 2);
01928 if(dc_pred_dir) {
01929 if(use_pred) {
01930 memcpy(ac_val2, ac_val, 8 * 2);
01931 if(q2 && q1!=q2) {
01932 q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
01933 q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
01934 for(k = 1; k < 8; k++)
01935 ac_val2[k] = (ac_val2[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
01936 }
01937 }
01938 } else {
01939 if(use_pred) {
01940 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
01941 if(q2 && q1!=q2) {
01942 q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
01943 q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
01944 for(k = 1; k < 8; k++)
01945 ac_val2[k + 8] = (ac_val2[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
01946 }
01947 }
01948 }
01949
01950
01951 if(use_pred) {
01952 if(dc_pred_dir) {
01953 for(k = 1; k < 8; k++) {
01954 block[k << v->left_blk_sh] = ac_val2[k] * scale;
01955 if(!v->pquantizer && block[k << v->left_blk_sh])
01956 block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -mquant : mquant;
01957 }
01958 } else {
01959 for(k = 1; k < 8; k++) {
01960 block[k << v->top_blk_sh] = ac_val2[k + 8] * scale;
01961 if(!v->pquantizer && block[k << v->top_blk_sh])
01962 block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -mquant : mquant;
01963 }
01964 }
01965 i = 63;
01966 }
01967 }
01968 s->block_last_index[n] = i;
01969
01970 return 0;
01971 }
01972
01981 static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, int coded, int mquant, int codingset)
01982 {
01983 GetBitContext *gb = &v->s.gb;
01984 MpegEncContext *s = &v->s;
01985 int dc_pred_dir = 0;
01986 int i;
01987 int16_t *dc_val;
01988 int16_t *ac_val, *ac_val2;
01989 int dcdiff;
01990 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
01991 int a_avail = v->a_avail, c_avail = v->c_avail;
01992 int use_pred = s->ac_pred;
01993 int scale;
01994 int q1, q2 = 0;
01995
01996 s->dsp.clear_block(block);
01997
01998
01999 mquant = (mquant < 1) ? 0 : ( (mquant>31) ? 31 : mquant );
02000
02001
02002 s->y_dc_scale = s->y_dc_scale_table[mquant];
02003 s->c_dc_scale = s->c_dc_scale_table[mquant];
02004
02005
02006 if (n < 4) {
02007 dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
02008 } else {
02009 dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
02010 }
02011 if (dcdiff < 0){
02012 av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
02013 return -1;
02014 }
02015 if (dcdiff)
02016 {
02017 if (dcdiff == 119 )
02018 {
02019
02020 if (mquant == 1) dcdiff = get_bits(gb, 10);
02021 else if (mquant == 2) dcdiff = get_bits(gb, 9);
02022 else dcdiff = get_bits(gb, 8);
02023 }
02024 else
02025 {
02026 if (mquant == 1)
02027 dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
02028 else if (mquant == 2)
02029 dcdiff = (dcdiff<<1) + get_bits1(gb) - 1;
02030 }
02031 if (get_bits1(gb))
02032 dcdiff = -dcdiff;
02033 }
02034
02035
02036 dcdiff += vc1_pred_dc(&v->s, v->overlap, mquant, n, a_avail, c_avail, &dc_val, &dc_pred_dir);
02037 *dc_val = dcdiff;
02038
02039
02040
02041 if (n < 4) {
02042 block[0] = dcdiff * s->y_dc_scale;
02043 } else {
02044 block[0] = dcdiff * s->c_dc_scale;
02045 }
02046
02047
02048 i = 1;
02049
02050
02051 if(!a_avail) dc_pred_dir = 1;
02052 if(!c_avail) dc_pred_dir = 0;
02053 if(!a_avail && !c_avail) use_pred = 0;
02054 ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
02055 ac_val2 = ac_val;
02056
02057 scale = mquant * 2 + v->halfpq;
02058
02059 if(dc_pred_dir)
02060 ac_val -= 16;
02061 else
02062 ac_val -= 16 * s->block_wrap[n];
02063
02064 q1 = s->current_picture.qscale_table[mb_pos];
02065 if(dc_pred_dir && c_avail && mb_pos) q2 = s->current_picture.qscale_table[mb_pos - 1];
02066 if(!dc_pred_dir && a_avail && mb_pos >= s->mb_stride) q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
02067 if(dc_pred_dir && n==1) q2 = q1;
02068 if(!dc_pred_dir && n==2) q2 = q1;
02069 if(n==3) q2 = q1;
02070
02071 if(coded) {
02072 int last = 0, skip, value;
02073 int k;
02074
02075 while (!last) {
02076 vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
02077 i += skip;
02078 if(i > 63)
02079 break;
02080 block[v->zz_8x8[0][i++]] = value;
02081 }
02082
02083
02084 if(use_pred) {
02085
02086 if(q2 && q1!=q2) {
02087 q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
02088 q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
02089
02090 if(dc_pred_dir) {
02091 for(k = 1; k < 8; k++)
02092 block[k << v->left_blk_sh] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
02093 } else {
02094 for(k = 1; k < 8; k++)
02095 block[k << v->top_blk_sh] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
02096 }
02097 } else {
02098 if(dc_pred_dir) {
02099 for(k = 1; k < 8; k++)
02100 block[k << v->left_blk_sh] += ac_val[k];
02101 } else {
02102 for(k = 1; k < 8; k++)
02103 block[k << v->top_blk_sh] += ac_val[k + 8];
02104 }
02105 }
02106 }
02107
02108 for(k = 1; k < 8; k++) {
02109 ac_val2[k ] = block[k << v->left_blk_sh];
02110 ac_val2[k + 8] = block[k << v->top_blk_sh];
02111 }
02112
02113
02114 for(k = 1; k < 64; k++)
02115 if(block[k]) {
02116 block[k] *= scale;
02117 if(!v->pquantizer)
02118 block[k] += (block[k] < 0) ? -mquant : mquant;
02119 }
02120
02121 if(use_pred) i = 63;
02122 } else {
02123 int k;
02124
02125 memset(ac_val2, 0, 16 * 2);
02126 if(dc_pred_dir) {
02127 if(use_pred) {
02128 memcpy(ac_val2, ac_val, 8 * 2);
02129 if(q2 && q1!=q2) {
02130 q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
02131 q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
02132 for(k = 1; k < 8; k++)
02133 ac_val2[k] = (ac_val2[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
02134 }
02135 }
02136 } else {
02137 if(use_pred) {
02138 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
02139 if(q2 && q1!=q2) {
02140 q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
02141 q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
02142 for(k = 1; k < 8; k++)
02143 ac_val2[k + 8] = (ac_val2[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
02144 }
02145 }
02146 }
02147
02148
02149 if(use_pred) {
02150 if(dc_pred_dir) {
02151 for(k = 1; k < 8; k++) {
02152 block[k << v->left_blk_sh] = ac_val2[k] * scale;
02153 if(!v->pquantizer && block[k << v->left_blk_sh])
02154 block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -mquant : mquant;
02155 }
02156 } else {
02157 for(k = 1; k < 8; k++) {
02158 block[k << v->top_blk_sh] = ac_val2[k + 8] * scale;
02159 if(!v->pquantizer && block[k << v->top_blk_sh])
02160 block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -mquant : mquant;
02161 }
02162 }
02163 i = 63;
02164 }
02165 }
02166 s->block_last_index[n] = i;
02167
02168 return 0;
02169 }
02170
02173 static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquant, int ttmb, int first_block,
02174 uint8_t *dst, int linesize, int skip_block, int *ttmb_out)
02175 {
02176 MpegEncContext *s = &v->s;
02177 GetBitContext *gb = &s->gb;
02178 int i, j;
02179 int subblkpat = 0;
02180 int scale, off, idx, last, skip, value;
02181 int ttblk = ttmb & 7;
02182 int pat = 0;
02183
02184 s->dsp.clear_block(block);
02185
02186 if(ttmb == -1) {
02187 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)];
02188 }
02189 if(ttblk == TT_4X4) {
02190 subblkpat = ~(get_vlc2(gb, ff_vc1_subblkpat_vlc[v->tt_index].table, VC1_SUBBLKPAT_VLC_BITS, 1) + 1);
02191 }
02192 if((ttblk != TT_8X8 && ttblk != TT_4X4)
02193 && ((v->ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))
02194 || (!v->res_rtm_flag && !first_block))) {
02195 subblkpat = decode012(gb);
02196 if(subblkpat) subblkpat ^= 3;
02197 if(ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) ttblk = TT_8X4;
02198 if(ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) ttblk = TT_4X8;
02199 }
02200 scale = 2 * mquant + ((v->pq == mquant) ? v->halfpq : 0);
02201
02202
02203 if(ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) {
02204 subblkpat = 2 - (ttblk == TT_8X4_TOP);
02205 ttblk = TT_8X4;
02206 }
02207 if(ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) {
02208 subblkpat = 2 - (ttblk == TT_4X8_LEFT);
02209 ttblk = TT_4X8;
02210 }
02211 switch(ttblk) {
02212 case TT_8X8:
02213 pat = 0xF;
02214 i = 0;
02215 last = 0;
02216 while (!last) {
02217 vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
02218 i += skip;
02219 if(i > 63)
02220 break;
02221 idx = v->zz_8x8[0][i++];
02222 block[idx] = value * scale;
02223 if(!v->pquantizer)
02224 block[idx] += (block[idx] < 0) ? -mquant : mquant;
02225 }
02226 if(!skip_block){
02227 if(i==1)
02228 v->vc1dsp.vc1_inv_trans_8x8_dc(dst, linesize, block);
02229 else{
02230 v->vc1dsp.vc1_inv_trans_8x8(block);
02231 s->dsp.add_pixels_clamped(block, dst, linesize);
02232 }
02233 }
02234 break;
02235 case TT_4X4:
02236 pat = ~subblkpat & 0xF;
02237 for(j = 0; j < 4; j++) {
02238 last = subblkpat & (1 << (3 - j));
02239 i = 0;
02240 off = (j & 1) * 4 + (j & 2) * 16;
02241 while (!last) {
02242 vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
02243 i += skip;
02244 if(i > 15)
02245 break;
02246 idx = ff_vc1_simple_progressive_4x4_zz[i++];
02247 block[idx + off] = value * scale;
02248 if(!v->pquantizer)
02249 block[idx + off] += (block[idx + off] < 0) ? -mquant : mquant;
02250 }
02251 if(!(subblkpat & (1 << (3 - j))) && !skip_block){
02252 if(i==1)
02253 v->vc1dsp.vc1_inv_trans_4x4_dc(dst + (j&1)*4 + (j&2)*2*linesize, linesize, block + off);
02254 else
02255 v->vc1dsp.vc1_inv_trans_4x4(dst + (j&1)*4 + (j&2)*2*linesize, linesize, block + off);
02256 }
02257 }
02258 break;
02259 case TT_8X4:
02260 pat = ~((subblkpat & 2)*6 + (subblkpat & 1)*3) & 0xF;
02261 for(j = 0; j < 2; j++) {
02262 last = subblkpat & (1 << (1 - j));
02263 i = 0;
02264 off = j * 32;
02265 while (!last) {
02266 vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
02267 i += skip;
02268 if(i > 31)
02269 break;
02270 idx = v->zz_8x4[i++]+off;
02271 block[idx] = value * scale;
02272 if(!v->pquantizer)
02273 block[idx] += (block[idx] < 0) ? -mquant : mquant;
02274 }
02275 if(!(subblkpat & (1 << (1 - j))) && !skip_block){
02276 if(i==1)
02277 v->vc1dsp.vc1_inv_trans_8x4_dc(dst + j*4*linesize, linesize, block + off);
02278 else
02279 v->vc1dsp.vc1_inv_trans_8x4(dst + j*4*linesize, linesize, block + off);
02280 }
02281 }
02282 break;
02283 case TT_4X8:
02284 pat = ~(subblkpat*5) & 0xF;
02285 for(j = 0; j < 2; j++) {
02286 last = subblkpat & (1 << (1 - j));
02287 i = 0;
02288 off = j * 4;
02289 while (!last) {
02290 vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
02291 i += skip;
02292 if(i > 31)
02293 break;
02294 idx = v->zz_4x8[i++]+off;
02295 block[idx] = value * scale;
02296 if(!v->pquantizer)
02297 block[idx] += (block[idx] < 0) ? -mquant : mquant;
02298 }
02299 if(!(subblkpat & (1 << (1 - j))) && !skip_block){
02300 if(i==1)
02301 v->vc1dsp.vc1_inv_trans_4x8_dc(dst + j*4, linesize, block + off);
02302 else
02303 v->vc1dsp.vc1_inv_trans_4x8(dst + j*4, linesize, block + off);
02304 }
02305 }
02306 break;
02307 }
02308 if (ttmb_out)
02309 *ttmb_out |= ttblk << (n * 4);
02310 return pat;
02311 }
02312
02314
02315 static const int size_table [6] = { 0, 2, 3, 4, 5, 8 };
02316 static const int offset_table[6] = { 0, 1, 3, 7, 15, 31 };
02317
02318 static av_always_inline void vc1_apply_p_v_loop_filter(VC1Context *v, int block_num)
02319 {
02320 MpegEncContext *s = &v->s;
02321 int mb_cbp = v->cbp[s->mb_x - s->mb_stride],
02322 block_cbp = mb_cbp >> (block_num * 4), bottom_cbp,
02323 mb_is_intra = v->is_intra[s->mb_x - s->mb_stride],
02324 block_is_intra = mb_is_intra >> (block_num * 4), bottom_is_intra;
02325 int idx, linesize = block_num > 3 ? s->uvlinesize : s->linesize, ttblk;
02326 uint8_t *dst;
02327
02328 if(block_num > 3) {
02329 dst = s->dest[block_num - 3];
02330 } else {
02331 dst = s->dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 8) * linesize;
02332 }
02333 if (s->mb_y != s->end_mb_y || block_num < 2) {
02334 int16_t (*mv)[2];
02335 int mv_stride;
02336
02337 if(block_num > 3) {
02338 bottom_cbp = v->cbp[s->mb_x] >> (block_num * 4);
02339 bottom_is_intra = v->is_intra[s->mb_x] >> (block_num * 4);
02340 mv = &v->luma_mv[s->mb_x - s->mb_stride];
02341 mv_stride = s->mb_stride;
02342 } else {
02343 bottom_cbp = (block_num < 2) ? (mb_cbp >> ((block_num + 2) * 4)) :
02344 (v->cbp[s->mb_x] >> ((block_num - 2) * 4));
02345 bottom_is_intra = (block_num < 2) ? (mb_is_intra >> ((block_num + 2) * 4)) :
02346 (v->is_intra[s->mb_x] >> ((block_num - 2) * 4));
02347 mv_stride = s->b8_stride;
02348 mv = &s->current_picture.motion_val[0][s->block_index[block_num] - 2 * mv_stride];
02349 }
02350
02351 if (bottom_is_intra & 1 || block_is_intra & 1 ||
02352 mv[0][0] != mv[mv_stride][0] || mv[0][1] != mv[mv_stride][1]) {
02353 v->vc1dsp.vc1_v_loop_filter8(dst, linesize, v->pq);
02354 } else {
02355 idx = ((bottom_cbp >> 2) | block_cbp) & 3;
02356 if(idx == 3) {
02357 v->vc1dsp.vc1_v_loop_filter8(dst, linesize, v->pq);
02358 } else if (idx) {
02359 if (idx == 1)
02360 v->vc1dsp.vc1_v_loop_filter4(dst + 4, linesize, v->pq);
02361 else
02362 v->vc1dsp.vc1_v_loop_filter4(dst, linesize, v->pq);
02363 }
02364 }
02365 }
02366
02367 dst -= 4 * linesize;
02368 ttblk = (v->ttblk[s->mb_x - s->mb_stride] >> (block_num * 4)) & 0xf;
02369 if (ttblk == TT_4X4 || ttblk == TT_8X4) {
02370 idx = (block_cbp | (block_cbp >> 2)) & 3;
02371 if (idx == 3) {
02372 v->vc1dsp.vc1_v_loop_filter8(dst, linesize, v->pq);
02373 } else if (idx) {
02374 if (idx == 1)
02375 v->vc1dsp.vc1_v_loop_filter4(dst + 4, linesize, v->pq);
02376 else
02377 v->vc1dsp.vc1_v_loop_filter4(dst, linesize, v->pq);
02378 }
02379 }
02380 }
02381
02382 static av_always_inline void vc1_apply_p_h_loop_filter(VC1Context *v, int block_num)
02383 {
02384 MpegEncContext *s = &v->s;
02385 int mb_cbp = v->cbp[s->mb_x - 1 - s->mb_stride],
02386 block_cbp = mb_cbp >> (block_num * 4), right_cbp,
02387 mb_is_intra = v->is_intra[s->mb_x - 1 - s->mb_stride],
02388 block_is_intra = mb_is_intra >> (block_num * 4), right_is_intra;
02389 int idx, linesize = block_num > 3 ? s->uvlinesize : s->linesize, ttblk;
02390 uint8_t *dst;
02391
02392 if (block_num > 3) {
02393 dst = s->dest[block_num - 3] - 8 * linesize;
02394 } else {
02395 dst = s->dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 16) * linesize - 8;
02396 }
02397
02398 if (s->mb_x != s->mb_width || !(block_num & 5)) {
02399 int16_t (*mv)[2];
02400
02401 if(block_num > 3) {
02402 right_cbp = v->cbp[s->mb_x - s->mb_stride] >> (block_num * 4);
02403 right_is_intra = v->is_intra[s->mb_x - s->mb_stride] >> (block_num * 4);
02404 mv = &v->luma_mv[s->mb_x - s->mb_stride - 1];
02405 }else{
02406 right_cbp = (block_num & 1) ? (v->cbp[s->mb_x - s->mb_stride] >> ((block_num - 1) * 4)) :
02407 (mb_cbp >> ((block_num + 1) * 4));
02408 right_is_intra = (block_num & 1) ? (v->is_intra[s->mb_x - s->mb_stride] >> ((block_num - 1) * 4)) :
02409 (mb_is_intra >> ((block_num + 1) * 4));
02410 mv = &s->current_picture.motion_val[0][s->block_index[block_num] - s->b8_stride * 2 - 2];
02411 }
02412 if (block_is_intra & 1 || right_is_intra & 1 || mv[0][0] != mv[1][0] || mv[0][1] != mv[1][1]) {
02413 v->vc1dsp.vc1_h_loop_filter8(dst, linesize, v->pq);
02414 } else {
02415 idx = ((right_cbp >> 1) | block_cbp) & 5;
02416 if (idx == 5) {
02417 v->vc1dsp.vc1_h_loop_filter8(dst, linesize, v->pq);
02418 } else if (idx) {
02419 if (idx == 1)
02420 v->vc1dsp.vc1_h_loop_filter4(dst+4*linesize, linesize, v->pq);
02421 else
02422 v->vc1dsp.vc1_h_loop_filter4(dst, linesize, v->pq);
02423 }
02424 }
02425 }
02426
02427 dst -= 4;
02428 ttblk = (v->ttblk[s->mb_x - s->mb_stride - 1] >> (block_num * 4)) & 0xf;
02429 if (ttblk == TT_4X4 || ttblk == TT_4X8) {
02430 idx = (block_cbp | (block_cbp >> 1)) & 5;
02431 if (idx == 5) {
02432 v->vc1dsp.vc1_h_loop_filter8(dst, linesize, v->pq);
02433 } else if (idx) {
02434 if (idx == 1)
02435 v->vc1dsp.vc1_h_loop_filter4(dst + linesize*4, linesize, v->pq);
02436 else
02437 v->vc1dsp.vc1_h_loop_filter4(dst, linesize, v->pq);
02438 }
02439 }
02440 }
02441
02442 static void vc1_apply_p_loop_filter(VC1Context *v)
02443 {
02444 MpegEncContext *s = &v->s;
02445 int i;
02446
02447 for (i = 0; i < 6; i++) {
02448 vc1_apply_p_v_loop_filter(v, i);
02449 }
02450
02451
02452
02453 if (s->mb_x) {
02454 for (i = 0; i < 6; i++) {
02455 vc1_apply_p_h_loop_filter(v, i);
02456 }
02457 if (s->mb_x == s->mb_width - 1) {
02458 s->mb_x++;
02459 ff_update_block_index(s);
02460 for (i = 0; i < 6; i++) {
02461 vc1_apply_p_h_loop_filter(v, i);
02462 }
02463 }
02464 }
02465 }
02466
02469 static int vc1_decode_p_mb(VC1Context *v)
02470 {
02471 MpegEncContext *s = &v->s;
02472 GetBitContext *gb = &s->gb;
02473 int i, j;
02474 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
02475 int cbp;
02476 int mqdiff, mquant;
02477 int ttmb = v->ttfrm;
02478
02479 int mb_has_coeffs = 1;
02480 int dmv_x, dmv_y;
02481 int index, index1;
02482 int val, sign;
02483 int first_block = 1;
02484 int dst_idx, off;
02485 int skipped, fourmv;
02486 int block_cbp = 0, pat, block_tt = 0, block_intra = 0;
02487
02488 mquant = v->pq;
02489
02490 if (v->mv_type_is_raw)
02491 fourmv = get_bits1(gb);
02492 else
02493 fourmv = v->mv_type_mb_plane[mb_pos];
02494 if (v->skip_is_raw)
02495 skipped = get_bits1(gb);
02496 else
02497 skipped = v->s.mbskip_table[mb_pos];
02498
02499 if (!fourmv)
02500 {
02501 if (!skipped)
02502 {
02503 GET_MVDATA(dmv_x, dmv_y);
02504
02505 if (s->mb_intra) {
02506 s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
02507 s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
02508 }
02509 s->current_picture.mb_type[mb_pos] = s->mb_intra ? MB_TYPE_INTRA : MB_TYPE_16x16;
02510 vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0]);
02511
02512
02513 if (s->mb_intra && !mb_has_coeffs)
02514 {
02515 GET_MQUANT();
02516 s->ac_pred = get_bits1(gb);
02517 cbp = 0;
02518 }
02519 else if (mb_has_coeffs)
02520 {
02521 if (s->mb_intra) s->ac_pred = get_bits1(gb);
02522 cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
02523 GET_MQUANT();
02524 }
02525 else
02526 {
02527 mquant = v->pq;
02528 cbp = 0;
02529 }
02530 s->current_picture.qscale_table[mb_pos] = mquant;
02531
02532 if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)
02533 ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table,
02534 VC1_TTMB_VLC_BITS, 2);
02535 if(!s->mb_intra) vc1_mc_1mv(v, 0);
02536 dst_idx = 0;
02537 for (i=0; i<6; i++)
02538 {
02539 s->dc_val[0][s->block_index[i]] = 0;
02540 dst_idx += i >> 2;
02541 val = ((cbp >> (5 - i)) & 1);
02542 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
02543 v->mb_type[0][s->block_index[i]] = s->mb_intra;
02544 if(s->mb_intra) {
02545
02546 v->a_avail = v->c_avail = 0;
02547 if(i == 2 || i == 3 || !s->first_slice_line)
02548 v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
02549 if(i == 1 || i == 3 || s->mb_x)
02550 v->c_avail = v->mb_type[0][s->block_index[i] - 1];
02551
02552 vc1_decode_intra_block(v, s->block[i], i, val, mquant, (i&4)?v->codingset2:v->codingset);
02553 if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue;
02554 v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
02555 if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1;
02556 s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
02557 if(v->pq >= 9 && v->overlap) {
02558 if(v->c_avail)
02559 v->vc1dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
02560 if(v->a_avail)
02561 v->vc1dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
02562 }
02563 block_cbp |= 0xF << (i << 2);
02564 block_intra |= 1 << i;
02565 } else if(val) {
02566 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), &block_tt);
02567 block_cbp |= pat << (i << 2);
02568 if(!v->ttmbf && ttmb < 8) ttmb = -1;
02569 first_block = 0;
02570 }
02571 }
02572 }
02573 else
02574 {
02575 s->mb_intra = 0;
02576 for(i = 0; i < 6; i++) {
02577 v->mb_type[0][s->block_index[i]] = 0;
02578 s->dc_val[0][s->block_index[i]] = 0;
02579 }
02580 s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP;
02581 s->current_picture.qscale_table[mb_pos] = 0;
02582 vc1_pred_mv(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0]);
02583 vc1_mc_1mv(v, 0);
02584 }
02585 }
02586 else
02587 {
02588 if (!skipped )
02589 {
02590 int intra_count = 0, coded_inter = 0;
02591 int is_intra[6], is_coded[6];
02592
02593 cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
02594 for (i=0; i<6; i++)
02595 {
02596 val = ((cbp >> (5 - i)) & 1);
02597 s->dc_val[0][s->block_index[i]] = 0;
02598 s->mb_intra = 0;
02599 if(i < 4) {
02600 dmv_x = dmv_y = 0;
02601 s->mb_intra = 0;
02602 mb_has_coeffs = 0;
02603 if(val) {
02604 GET_MVDATA(dmv_x, dmv_y);
02605 }
02606 vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0]);
02607 if(!s->mb_intra) vc1_mc_4mv_luma(v, i);
02608 intra_count += s->mb_intra;
02609 is_intra[i] = s->mb_intra;
02610 is_coded[i] = mb_has_coeffs;
02611 }
02612 if(i&4){
02613 is_intra[i] = (intra_count >= 3);
02614 is_coded[i] = val;
02615 }
02616 if(i == 4) vc1_mc_4mv_chroma(v);
02617 v->mb_type[0][s->block_index[i]] = is_intra[i];
02618 if(!coded_inter) coded_inter = !is_intra[i] & is_coded[i];
02619 }
02620
02621 dst_idx = 0;
02622 if(!intra_count && !coded_inter)
02623 goto end;
02624 GET_MQUANT();
02625 s->current_picture.qscale_table[mb_pos] = mquant;
02626
02627 {
02628 int intrapred = 0;
02629 for(i=0; i<6; i++)
02630 if(is_intra[i]) {
02631 if(((!s->first_slice_line || (i==2 || i==3)) && v->mb_type[0][s->block_index[i] - s->block_wrap[i]])
02632 || ((s->mb_x || (i==1 || i==3)) && v->mb_type[0][s->block_index[i] - 1])) {
02633 intrapred = 1;
02634 break;
02635 }
02636 }
02637 if(intrapred)s->ac_pred = get_bits1(gb);
02638 else s->ac_pred = 0;
02639 }
02640 if (!v->ttmbf && coded_inter)
02641 ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
02642 for (i=0; i<6; i++)
02643 {
02644 dst_idx += i >> 2;
02645 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
02646 s->mb_intra = is_intra[i];
02647 if (is_intra[i]) {
02648
02649 v->a_avail = v->c_avail = 0;
02650 if(i == 2 || i == 3 || !s->first_slice_line)
02651 v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
02652 if(i == 1 || i == 3 || s->mb_x)
02653 v->c_avail = v->mb_type[0][s->block_index[i] - 1];
02654
02655 vc1_decode_intra_block(v, s->block[i], i, is_coded[i], mquant, (i&4)?v->codingset2:v->codingset);
02656 if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue;
02657 v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
02658 if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1;
02659 s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize);
02660 if(v->pq >= 9 && v->overlap) {
02661 if(v->c_avail)
02662 v->vc1dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
02663 if(v->a_avail)
02664 v->vc1dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
02665 }
02666 block_cbp |= 0xF << (i << 2);
02667 block_intra |= 1 << i;
02668 } else if(is_coded[i]) {
02669 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), &block_tt);
02670 block_cbp |= pat << (i << 2);
02671 if(!v->ttmbf && ttmb < 8) ttmb = -1;
02672 first_block = 0;
02673 }
02674 }
02675 }
02676 else
02677 {
02678 s->mb_intra = 0;
02679 s->current_picture.qscale_table[mb_pos] = 0;
02680 for (i=0; i<6; i++) {
02681 v->mb_type[0][s->block_index[i]] = 0;
02682 s->dc_val[0][s->block_index[i]] = 0;
02683 }
02684 for (i=0; i<4; i++)
02685 {
02686 vc1_pred_mv(v, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type[0]);
02687 vc1_mc_4mv_luma(v, i);
02688 }
02689 vc1_mc_4mv_chroma(v);
02690 s->current_picture.qscale_table[mb_pos] = 0;
02691 }
02692 }
02693 end:
02694 v->cbp[s->mb_x] = block_cbp;
02695 v->ttblk[s->mb_x] = block_tt;
02696 v->is_intra[s->mb_x] = block_intra;
02697
02698 return 0;
02699 }
02700
02703 static void vc1_decode_b_mb(VC1Context *v)
02704 {
02705 MpegEncContext *s = &v->s;
02706 GetBitContext *gb = &s->gb;
02707 int i, j;
02708 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
02709 int cbp = 0;
02710 int mqdiff, mquant;
02711 int ttmb = v->ttfrm;
02712 int mb_has_coeffs = 0;
02713 int index, index1;
02714 int val, sign;
02715 int first_block = 1;
02716 int dst_idx, off;
02717 int skipped, direct;
02718 int dmv_x[2], dmv_y[2];
02719 int bmvtype = BMV_TYPE_BACKWARD;
02720
02721 mquant = v->pq;
02722 s->mb_intra = 0;
02723
02724 if (v->dmb_is_raw)
02725 direct = get_bits1(gb);
02726 else
02727 direct = v->direct_mb_plane[mb_pos];
02728 if (v->skip_is_raw)
02729 skipped = get_bits1(gb);
02730 else
02731 skipped = v->s.mbskip_table[mb_pos];
02732
02733 dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
02734 for(i = 0; i < 6; i++) {
02735 v->mb_type[0][s->block_index[i]] = 0;
02736 s->dc_val[0][s->block_index[i]] = 0;
02737 }
02738 s->current_picture.qscale_table[mb_pos] = 0;
02739
02740 if (!direct) {
02741 if (!skipped) {
02742 GET_MVDATA(dmv_x[0], dmv_y[0]);
02743 dmv_x[1] = dmv_x[0];
02744 dmv_y[1] = dmv_y[0];
02745 }
02746 if(skipped || !s->mb_intra) {
02747 bmvtype = decode012(gb);
02748 switch(bmvtype) {
02749 case 0:
02750 bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_BACKWARD : BMV_TYPE_FORWARD;
02751 break;
02752 case 1:
02753 bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_FORWARD : BMV_TYPE_BACKWARD;
02754 break;
02755 case 2:
02756 bmvtype = BMV_TYPE_INTERPOLATED;
02757 dmv_x[0] = dmv_y[0] = 0;
02758 }
02759 }
02760 }
02761 for(i = 0; i < 6; i++)
02762 v->mb_type[0][s->block_index[i]] = s->mb_intra;
02763
02764 if (skipped) {
02765 if(direct) bmvtype = BMV_TYPE_INTERPOLATED;
02766 vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
02767 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
02768 return;
02769 }
02770 if (direct) {
02771 cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
02772 GET_MQUANT();
02773 s->mb_intra = 0;
02774 s->current_picture.qscale_table[mb_pos] = mquant;
02775 if(!v->ttmbf)
02776 ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
02777 dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0;
02778 vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
02779 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
02780 } else {
02781 if(!mb_has_coeffs && !s->mb_intra) {
02782
02783 vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
02784 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
02785 return;
02786 }
02787 if(s->mb_intra && !mb_has_coeffs) {
02788 GET_MQUANT();
02789 s->current_picture.qscale_table[mb_pos] = mquant;
02790 s->ac_pred = get_bits1(gb);
02791 cbp = 0;
02792 vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
02793 } else {
02794 if(bmvtype == BMV_TYPE_INTERPOLATED) {
02795 GET_MVDATA(dmv_x[0], dmv_y[0]);
02796 if(!mb_has_coeffs) {
02797
02798 vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
02799 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
02800 return;
02801 }
02802 }
02803 vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
02804 if(!s->mb_intra) {
02805 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
02806 }
02807 if(s->mb_intra)
02808 s->ac_pred = get_bits1(gb);
02809 cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
02810 GET_MQUANT();
02811 s->current_picture.qscale_table[mb_pos] = mquant;
02812 if(!v->ttmbf && !s->mb_intra && mb_has_coeffs)
02813 ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
02814 }
02815 }
02816 dst_idx = 0;
02817 for (i=0; i<6; i++)
02818 {
02819 s->dc_val[0][s->block_index[i]] = 0;
02820 dst_idx += i >> 2;
02821 val = ((cbp >> (5 - i)) & 1);
02822 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
02823 v->mb_type[0][s->block_index[i]] = s->mb_intra;
02824 if(s->mb_intra) {
02825
02826 v->a_avail = v->c_avail = 0;
02827 if(i == 2 || i == 3 || !s->first_slice_line)
02828 v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
02829 if(i == 1 || i == 3 || s->mb_x)
02830 v->c_avail = v->mb_type[0][s->block_index[i] - 1];
02831
02832 vc1_decode_intra_block(v, s->block[i], i, val, mquant, (i&4)?v->codingset2:v->codingset);
02833 if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue;
02834 v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
02835 if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1;
02836 s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
02837 } else if(val) {
02838 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), NULL);
02839 if(!v->ttmbf && ttmb < 8) ttmb = -1;
02840 first_block = 0;
02841 }
02842 }
02843 }
02844
02847 static void vc1_decode_i_blocks(VC1Context *v)
02848 {
02849 int k, j;
02850 MpegEncContext *s = &v->s;
02851 int cbp, val;
02852 uint8_t *coded_val;
02853 int mb_pos;
02854
02855
02856 switch(v->y_ac_table_index){
02857 case 0:
02858 v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
02859 break;
02860 case 1:
02861 v->codingset = CS_HIGH_MOT_INTRA;
02862 break;
02863 case 2:
02864 v->codingset = CS_MID_RATE_INTRA;
02865 break;
02866 }
02867
02868 switch(v->c_ac_table_index){
02869 case 0:
02870 v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
02871 break;
02872 case 1:
02873 v->codingset2 = CS_HIGH_MOT_INTER;
02874 break;
02875 case 2:
02876 v->codingset2 = CS_MID_RATE_INTER;
02877 break;
02878 }
02879
02880
02881 s->y_dc_scale = s->y_dc_scale_table[v->pq];
02882 s->c_dc_scale = s->c_dc_scale_table[v->pq];
02883
02884
02885 s->mb_x = s->mb_y = 0;
02886 s->mb_intra = 1;
02887 s->first_slice_line = 1;
02888 for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
02889 s->mb_x = 0;
02890 ff_init_block_index(s);
02891 for(; s->mb_x < s->mb_width; s->mb_x++) {
02892 uint8_t *dst[6];
02893 ff_update_block_index(s);
02894 dst[0] = s->dest[0];
02895 dst[1] = dst[0] + 8;
02896 dst[2] = s->dest[0] + s->linesize * 8;
02897 dst[3] = dst[2] + 8;
02898 dst[4] = s->dest[1];
02899 dst[5] = s->dest[2];
02900 s->dsp.clear_blocks(s->block[0]);
02901 mb_pos = s->mb_x + s->mb_y * s->mb_width;
02902 s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
02903 s->current_picture.qscale_table[mb_pos] = v->pq;
02904 s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
02905 s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
02906
02907
02908 cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
02909 v->s.ac_pred = get_bits1(&v->s.gb);
02910
02911 for(k = 0; k < 6; k++) {
02912 val = ((cbp >> (5 - k)) & 1);
02913
02914 if (k < 4) {
02915 int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
02916 val = val ^ pred;
02917 *coded_val = val;
02918 }
02919 cbp |= val << (5 - k);
02920
02921 vc1_decode_i_block(v, s->block[k], k, val, (k<4)? v->codingset : v->codingset2);
02922
02923 if (k > 3 && (s->flags & CODEC_FLAG_GRAY)) continue;
02924 v->vc1dsp.vc1_inv_trans_8x8(s->block[k]);
02925 if(v->pq >= 9 && v->overlap) {
02926 if (v->rangeredfrm) for(j = 0; j < 64; j++) s->block[k][j] <<= 1;
02927 s->dsp.put_signed_pixels_clamped(s->block[k], dst[k], k & 4 ? s->uvlinesize : s->linesize);
02928 } else {
02929 if (v->rangeredfrm) for(j = 0; j < 64; j++) s->block[k][j] = (s->block[k][j] - 64) << 1;
02930 s->dsp.put_pixels_clamped(s->block[k], dst[k], k & 4 ? s->uvlinesize : s->linesize);
02931 }
02932 }
02933
02934 if(v->pq >= 9 && v->overlap) {
02935 if(s->mb_x) {
02936 v->vc1dsp.vc1_h_overlap(s->dest[0], s->linesize);
02937 v->vc1dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize, s->linesize);
02938 if(!(s->flags & CODEC_FLAG_GRAY)) {
02939 v->vc1dsp.vc1_h_overlap(s->dest[1], s->uvlinesize);
02940 v->vc1dsp.vc1_h_overlap(s->dest[2], s->uvlinesize);
02941 }
02942 }
02943 v->vc1dsp.vc1_h_overlap(s->dest[0] + 8, s->linesize);
02944 v->vc1dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);
02945 if(!s->first_slice_line) {
02946 v->vc1dsp.vc1_v_overlap(s->dest[0], s->linesize);
02947 v->vc1dsp.vc1_v_overlap(s->dest[0] + 8, s->linesize);
02948 if(!(s->flags & CODEC_FLAG_GRAY)) {
02949 v->vc1dsp.vc1_v_overlap(s->dest[1], s->uvlinesize);
02950 v->vc1dsp.vc1_v_overlap(s->dest[2], s->uvlinesize);
02951 }
02952 }
02953 v->vc1dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize, s->linesize);
02954 v->vc1dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);
02955 }
02956 if(v->s.loop_filter) vc1_loop_filter_iblk(v, v->pq);
02957
02958 if(get_bits_count(&s->gb) > v->bits) {
02959 ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END));
02960 av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits);
02961 return;
02962 }
02963 }
02964 if (!v->s.loop_filter)
02965 ff_draw_horiz_band(s, s->mb_y * 16, 16);
02966 else if (s->mb_y)
02967 ff_draw_horiz_band(s, (s->mb_y-1) * 16, 16);
02968
02969 s->first_slice_line = 0;
02970 }
02971 if (v->s.loop_filter)
02972 ff_draw_horiz_band(s, (s->mb_height-1)*16, 16);
02973 ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
02974 }
02975
02978 static void vc1_decode_i_blocks_adv(VC1Context *v)
02979 {
02980 int k;
02981 MpegEncContext *s = &v->s;
02982 int cbp, val;
02983 uint8_t *coded_val;
02984 int mb_pos;
02985 int mquant = v->pq;
02986 int mqdiff;
02987 GetBitContext *gb = &s->gb;
02988
02989
02990 switch(v->y_ac_table_index){
02991 case 0:
02992 v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
02993 break;
02994 case 1:
02995 v->codingset = CS_HIGH_MOT_INTRA;
02996 break;
02997 case 2:
02998 v->codingset = CS_MID_RATE_INTRA;
02999 break;
03000 }
03001
03002 switch(v->c_ac_table_index){
03003 case 0:
03004 v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
03005 break;
03006 case 1:
03007 v->codingset2 = CS_HIGH_MOT_INTER;
03008 break;
03009 case 2:
03010 v->codingset2 = CS_MID_RATE_INTER;
03011 break;
03012 }
03013
03014
03015 s->mb_x = s->mb_y = 0;
03016 s->mb_intra = 1;
03017 s->first_slice_line = 1;
03018 s->mb_y = s->start_mb_y;
03019 if (s->start_mb_y) {
03020 s->mb_x = 0;
03021 ff_init_block_index(s);
03022 memset(&s->coded_block[s->block_index[0]-s->b8_stride], 0,
03023 (1 + s->b8_stride) * sizeof(*s->coded_block));
03024 }
03025 for(; s->mb_y < s->end_mb_y; s->mb_y++) {
03026 s->mb_x = 0;
03027 ff_init_block_index(s);
03028 for(;s->mb_x < s->mb_width; s->mb_x++) {
03029 DCTELEM (*block)[64] = v->block[v->cur_blk_idx];
03030 ff_update_block_index(s);
03031 s->dsp.clear_blocks(block[0]);
03032 mb_pos = s->mb_x + s->mb_y * s->mb_stride;
03033 s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
03034 s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
03035 s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
03036
03037
03038 cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
03039 if(v->acpred_is_raw)
03040 v->s.ac_pred = get_bits1(&v->s.gb);
03041 else
03042 v->s.ac_pred = v->acpred_plane[mb_pos];
03043
03044 if (v->condover == CONDOVER_SELECT && v->overflg_is_raw)
03045 v->over_flags_plane[mb_pos] = get_bits1(&v->s.gb);
03046
03047 GET_MQUANT();
03048
03049 s->current_picture.qscale_table[mb_pos] = mquant;
03050
03051 s->y_dc_scale = s->y_dc_scale_table[mquant];
03052 s->c_dc_scale = s->c_dc_scale_table[mquant];
03053
03054 for(k = 0; k < 6; k++) {
03055 val = ((cbp >> (5 - k)) & 1);
03056
03057 if (k < 4) {
03058 int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
03059 val = val ^ pred;
03060 *coded_val = val;
03061 }
03062 cbp |= val << (5 - k);
03063
03064 v->a_avail = !s->first_slice_line || (k==2 || k==3);
03065 v->c_avail = !!s->mb_x || (k==1 || k==3);
03066
03067 vc1_decode_i_block_adv(v, block[k], k, val, (k<4)? v->codingset : v->codingset2, mquant);
03068
03069 if (k > 3 && (s->flags & CODEC_FLAG_GRAY)) continue;
03070 v->vc1dsp.vc1_inv_trans_8x8(block[k]);
03071 }
03072
03073 vc1_smooth_overlap_filter_iblk(v);
03074 vc1_put_signed_blocks_clamped(v);
03075 if(v->s.loop_filter) vc1_loop_filter_iblk_delayed(v, v->pq);
03076
03077 if(get_bits_count(&s->gb) > v->bits) {
03078 ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END));
03079 av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits);
03080 return;
03081 }
03082 }
03083 if (!v->s.loop_filter)
03084 ff_draw_horiz_band(s, s->mb_y * 16, 16);
03085 else if (s->mb_y)
03086 ff_draw_horiz_band(s, (s->mb_y-1) * 16, 16);
03087 s->first_slice_line = 0;
03088 }
03089
03090
03091 s->mb_x = 0;
03092 ff_init_block_index(s);
03093 for(;s->mb_x < s->mb_width; s->mb_x++) {
03094 ff_update_block_index(s);
03095 vc1_put_signed_blocks_clamped(v);
03096 if(v->s.loop_filter) vc1_loop_filter_iblk_delayed(v, v->pq);
03097 }
03098 if (v->s.loop_filter)
03099 ff_draw_horiz_band(s, (s->end_mb_y-1)*16, 16);
03100 ff_er_add_slice(s, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, (AC_END|DC_END|MV_END));
03101 }
03102
03103 static void vc1_decode_p_blocks(VC1Context *v)
03104 {
03105 MpegEncContext *s = &v->s;
03106 int apply_loop_filter;
03107
03108
03109 switch(v->c_ac_table_index){
03110 case 0:
03111 v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
03112 break;
03113 case 1:
03114 v->codingset = CS_HIGH_MOT_INTRA;
03115 break;
03116 case 2:
03117 v->codingset = CS_MID_RATE_INTRA;
03118 break;
03119 }
03120
03121 switch(v->c_ac_table_index){
03122 case 0:
03123 v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
03124 break;
03125 case 1:
03126 v->codingset2 = CS_HIGH_MOT_INTER;
03127 break;
03128 case 2:
03129 v->codingset2 = CS_MID_RATE_INTER;
03130 break;
03131 }
03132
03133 apply_loop_filter = s->loop_filter && !(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY);
03134 s->first_slice_line = 1;
03135 memset(v->cbp_base, 0, sizeof(v->cbp_base[0])*2*s->mb_stride);
03136 for(s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
03137 s->mb_x = 0;
03138 ff_init_block_index(s);
03139 for(; s->mb_x < s->mb_width; s->mb_x++) {
03140 ff_update_block_index(s);
03141
03142 vc1_decode_p_mb(v);
03143 if (s->mb_y != s->start_mb_y && apply_loop_filter)
03144 vc1_apply_p_loop_filter(v);
03145 if(get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
03146 ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END));
03147 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);
03148 return;
03149 }
03150 }
03151 memmove(v->cbp_base, v->cbp, sizeof(v->cbp_base[0])*s->mb_stride);
03152 memmove(v->ttblk_base, v->ttblk, sizeof(v->ttblk_base[0])*s->mb_stride);
03153 memmove(v->is_intra_base, v->is_intra, sizeof(v->is_intra_base[0])*s->mb_stride);
03154 memmove(v->luma_mv_base, v->luma_mv, sizeof(v->luma_mv_base[0])*s->mb_stride);
03155 if (s->mb_y != s->start_mb_y) ff_draw_horiz_band(s, (s->mb_y-1) * 16, 16);
03156 s->first_slice_line = 0;
03157 }
03158 if (apply_loop_filter) {
03159 s->mb_x = 0;
03160 ff_init_block_index(s);
03161 for (; s->mb_x < s->mb_width; s->mb_x++) {
03162 ff_update_block_index(s);
03163 vc1_apply_p_loop_filter(v);
03164 }
03165 }
03166 if (s->end_mb_y >= s->start_mb_y)
03167 ff_draw_horiz_band(s, (s->end_mb_y-1) * 16, 16);
03168 ff_er_add_slice(s, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, (AC_END|DC_END|MV_END));
03169 }
03170
03171 static void vc1_decode_b_blocks(VC1Context *v)
03172 {
03173 MpegEncContext *s = &v->s;
03174
03175
03176 switch(v->c_ac_table_index){
03177 case 0:
03178 v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
03179 break;
03180 case 1:
03181 v->codingset = CS_HIGH_MOT_INTRA;
03182 break;
03183 case 2:
03184 v->codingset = CS_MID_RATE_INTRA;
03185 break;
03186 }
03187
03188 switch(v->c_ac_table_index){
03189 case 0:
03190 v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
03191 break;
03192 case 1:
03193 v->codingset2 = CS_HIGH_MOT_INTER;
03194 break;
03195 case 2:
03196 v->codingset2 = CS_MID_RATE_INTER;
03197 break;
03198 }
03199
03200 s->first_slice_line = 1;
03201 for(s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
03202 s->mb_x = 0;
03203 ff_init_block_index(s);
03204 for(; s->mb_x < s->mb_width; s->mb_x++) {
03205 ff_update_block_index(s);
03206
03207 vc1_decode_b_mb(v);
03208 if(get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
03209 ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END));
03210 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);
03211 return;
03212 }
03213 if(v->s.loop_filter) vc1_loop_filter_iblk(v, v->pq);
03214 }
03215 if (!v->s.loop_filter)
03216 ff_draw_horiz_band(s, s->mb_y * 16, 16);
03217 else if (s->mb_y)
03218 ff_draw_horiz_band(s, (s->mb_y-1) * 16, 16);
03219 s->first_slice_line = 0;
03220 }
03221 if (v->s.loop_filter)
03222 ff_draw_horiz_band(s, (s->end_mb_y-1)*16, 16);
03223 ff_er_add_slice(s, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, (AC_END|DC_END|MV_END));
03224 }
03225
03226 static void vc1_decode_skip_blocks(VC1Context *v)
03227 {
03228 MpegEncContext *s = &v->s;
03229
03230 ff_er_add_slice(s, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, (AC_END|DC_END|MV_END));
03231 s->first_slice_line = 1;
03232 for(s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
03233 s->mb_x = 0;
03234 ff_init_block_index(s);
03235 ff_update_block_index(s);
03236 memcpy(s->dest[0], s->last_picture.data[0] + s->mb_y * 16 * s->linesize, s->linesize * 16);
03237 memcpy(s->dest[1], s->last_picture.data[1] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
03238 memcpy(s->dest[2], s->last_picture.data[2] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
03239 ff_draw_horiz_band(s, s->mb_y * 16, 16);
03240 s->first_slice_line = 0;
03241 }
03242 s->pict_type = AV_PICTURE_TYPE_P;
03243 }
03244
03245 static void vc1_decode_blocks(VC1Context *v)
03246 {
03247
03248 v->s.esc3_level_length = 0;
03249 if(v->x8_type){
03250 ff_intrax8_decode_picture(&v->x8, 2*v->pq+v->halfpq, v->pq*(!v->pquantizer) );
03251 }else{
03252 v->cur_blk_idx = 0;
03253 v->left_blk_idx = -1;
03254 v->topleft_blk_idx = 1;
03255 v->top_blk_idx = 2;
03256 switch(v->s.pict_type) {
03257 case AV_PICTURE_TYPE_I:
03258 if(v->profile == PROFILE_ADVANCED)
03259 vc1_decode_i_blocks_adv(v);
03260 else
03261 vc1_decode_i_blocks(v);
03262 break;
03263 case AV_PICTURE_TYPE_P:
03264 if(v->p_frame_skipped)
03265 vc1_decode_skip_blocks(v);
03266 else
03267 vc1_decode_p_blocks(v);
03268 break;
03269 case AV_PICTURE_TYPE_B:
03270 if(v->bi_type){
03271 if(v->profile == PROFILE_ADVANCED)
03272 vc1_decode_i_blocks_adv(v);
03273 else
03274 vc1_decode_i_blocks(v);
03275 }else
03276 vc1_decode_b_blocks(v);
03277 break;
03278 }
03279 }
03280 }
03281
03282 static inline float get_float_val(GetBitContext* gb)
03283 {
03284 return (float)get_bits_long(gb, 30) / (1<<15) - (1<<14);
03285 }
03286
03287 static void vc1_sprite_parse_transform(VC1Context *v, GetBitContext* gb, float c[7])
03288 {
03289 c[1] = c[3] = 0.0f;
03290
03291 switch (get_bits(gb, 2)) {
03292 case 0:
03293 c[0] = 1.0f;
03294 c[2] = get_float_val(gb);
03295 c[4] = 1.0f;
03296 break;
03297 case 1:
03298 c[0] = c[4] = get_float_val(gb);
03299 c[2] = get_float_val(gb);
03300 break;
03301 case 2:
03302 c[0] = get_float_val(gb);
03303 c[2] = get_float_val(gb);
03304 c[4] = get_float_val(gb);
03305 break;
03306 case 3:
03307 av_log_ask_for_sample(v->s.avctx, NULL);
03308 c[0] = get_float_val(gb);
03309 c[1] = get_float_val(gb);
03310 c[2] = get_float_val(gb);
03311 c[3] = get_float_val(gb);
03312 c[4] = get_float_val(gb);
03313 break;
03314 }
03315 c[5] = get_float_val(gb);
03316 if (get_bits1(gb))
03317 c[6] = get_float_val(gb);
03318 else
03319 c[6] = 1.0f;
03320 }
03321
03322 static void vc1_parse_sprites(VC1Context *v, GetBitContext* gb)
03323 {
03324 int effect_type, effect_flag, effect_pcount1, effect_pcount2, i;
03325 float effect_params1[14], effect_params2[10];
03326
03327 float coefs[2][7];
03328 vc1_sprite_parse_transform(v, gb, coefs[0]);
03329 av_log(v->s.avctx, AV_LOG_DEBUG, "S1:");
03330 for (i = 0; i < 7; i++)
03331 av_log(v->s.avctx, AV_LOG_DEBUG, " %.3f", coefs[0][i]);
03332 av_log(v->s.avctx, AV_LOG_DEBUG, "\n");
03333
03334 if (v->two_sprites) {
03335 vc1_sprite_parse_transform(v, gb, coefs[1]);
03336 av_log(v->s.avctx, AV_LOG_DEBUG, "S2:");
03337 for (i = 0; i < 7; i++)
03338 av_log(v->s.avctx, AV_LOG_DEBUG, " %.3f", coefs[1][i]);
03339 av_log(v->s.avctx, AV_LOG_DEBUG, "\n");
03340 }
03341 skip_bits(gb, 2);
03342 if (effect_type = get_bits_long(gb, 30)){
03343 switch (effect_pcount1 = get_bits(gb, 4)) {
03344 case 2:
03345 effect_params1[0] = get_float_val(gb);
03346 effect_params1[1] = get_float_val(gb);
03347 break;
03348 case 7:
03349 vc1_sprite_parse_transform(v, gb, effect_params1);
03350 break;
03351 case 14:
03352 vc1_sprite_parse_transform(v, gb, effect_params1);
03353 vc1_sprite_parse_transform(v, gb, &effect_params1[7]);
03354 break;
03355 default:
03356 av_log_ask_for_sample(v->s.avctx, NULL);
03357 return;
03358 }
03359 if (effect_type != 13 || effect_params1[0] != coefs[0][6]) {
03360
03361 av_log(v->s.avctx, AV_LOG_DEBUG, "Effect: %d; params: ", effect_type);
03362 for (i = 0; i < effect_pcount1; i++)
03363 av_log(v->s.avctx, AV_LOG_DEBUG, " %.3f", effect_params1[i]);
03364 av_log(v->s.avctx, AV_LOG_DEBUG, "\n");
03365 }
03366
03367 effect_pcount2 = get_bits(gb, 16);
03368 if (effect_pcount2 > 10) {
03369 av_log(v->s.avctx, AV_LOG_ERROR, "Too many effect parameters\n");
03370 return;
03371 } else if (effect_pcount2) {
03372 i = 0;
03373 av_log(v->s.avctx, AV_LOG_DEBUG, "Effect params 2: ");
03374 while (i < effect_pcount2){
03375 effect_params2[i] = get_float_val(gb);
03376 av_log(v->s.avctx, AV_LOG_DEBUG, " %.3f", effect_params2[i]);
03377 i++;
03378 }
03379 av_log(v->s.avctx, AV_LOG_DEBUG, "\n");
03380 }
03381 }
03382 if (effect_flag = get_bits1(gb))
03383 av_log(v->s.avctx, AV_LOG_DEBUG, "Effect flag set\n");
03384
03385 if (get_bits_count(gb) >= gb->size_in_bits +
03386 (v->s.avctx->codec_id == CODEC_ID_WMV3 ? 64 : 0))
03387 av_log(v->s.avctx, AV_LOG_ERROR, "Buffer overrun\n");
03388 if (get_bits_count(gb) < gb->size_in_bits - 8)
03389 av_log(v->s.avctx, AV_LOG_WARNING, "Buffer not fully read\n");
03390 }
03391
03396 static av_cold int vc1_decode_init(AVCodecContext *avctx)
03397 {
03398 VC1Context *v = avctx->priv_data;
03399 MpegEncContext *s = &v->s;
03400 GetBitContext gb;
03401 int i, cur_width, cur_height;
03402
03403 if (!avctx->extradata_size || !avctx->extradata) return -1;
03404 if (!(avctx->flags & CODEC_FLAG_GRAY))
03405 avctx->pix_fmt = avctx->get_format(avctx, avctx->codec->pix_fmts);
03406 else
03407 avctx->pix_fmt = PIX_FMT_GRAY8;
03408 avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
03409 v->s.avctx = avctx;
03410 avctx->flags |= CODEC_FLAG_EMU_EDGE;
03411 v->s.flags |= CODEC_FLAG_EMU_EDGE;
03412
03413 if(avctx->idct_algo==FF_IDCT_AUTO){
03414 avctx->idct_algo=FF_IDCT_WMV2;
03415 }
03416
03417 if(ff_msmpeg4_decode_init(avctx) < 0)
03418 return -1;
03419 if (vc1_init_common(v) < 0) return -1;
03420 ff_vc1dsp_init(&v->vc1dsp);
03421
03422 cur_width = avctx->coded_width = avctx->width;
03423 cur_height = avctx->coded_height = avctx->height;
03424 if (avctx->codec_id == CODEC_ID_WMV3)
03425 {
03426 int count = 0;
03427
03428
03429
03430
03431
03432
03433 init_get_bits(&gb, avctx->extradata, avctx->extradata_size*8);
03434
03435 if (vc1_decode_sequence_header(avctx, v, &gb) < 0)
03436 return -1;
03437
03438 count = avctx->extradata_size*8 - get_bits_count(&gb);
03439 if (count>0)
03440 {
03441 av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n",
03442 count, get_bits(&gb, count));
03443 }
03444 else if (count < 0)
03445 {
03446 av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count);
03447 }
03448 } else {
03449 const uint8_t *start = avctx->extradata;
03450 uint8_t *end = avctx->extradata + avctx->extradata_size;
03451 const uint8_t *next;
03452 int size, buf2_size;
03453 uint8_t *buf2 = NULL;
03454 int seq_initialized = 0, ep_initialized = 0;
03455
03456 if(avctx->extradata_size < 16) {
03457 av_log(avctx, AV_LOG_ERROR, "Extradata size too small: %i\n", avctx->extradata_size);
03458 return -1;
03459 }
03460
03461 buf2 = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
03462 start = find_next_marker(start, end);
03463 next = start;
03464 for(; next < end; start = next){
03465 next = find_next_marker(start + 4, end);
03466 size = next - start - 4;
03467 if(size <= 0) continue;
03468 buf2_size = vc1_unescape_buffer(start + 4, size, buf2);
03469 init_get_bits(&gb, buf2, buf2_size * 8);
03470 switch(AV_RB32(start)){
03471 case VC1_CODE_SEQHDR:
03472 if(vc1_decode_sequence_header(avctx, v, &gb) < 0){
03473 av_free(buf2);
03474 return -1;
03475 }
03476 seq_initialized = 1;
03477 break;
03478 case VC1_CODE_ENTRYPOINT:
03479 if(vc1_decode_entry_point(avctx, v, &gb) < 0){
03480 av_free(buf2);
03481 return -1;
03482 }
03483 ep_initialized = 1;
03484 break;
03485 }
03486 }
03487 av_free(buf2);
03488 if(!seq_initialized || !ep_initialized){
03489 av_log(avctx, AV_LOG_ERROR, "Incomplete extradata\n");
03490 return -1;
03491 }
03492 v->res_sprite = (avctx->codec_tag == MKTAG('W','V','P','2'));
03493 }
03494
03495
03496
03497
03498 if (cur_width != avctx->width ||
03499 cur_height != avctx->height) {
03500 MPV_common_end(s);
03501 if(ff_msmpeg4_decode_init(avctx) < 0)
03502 return -1;
03503 avctx->coded_width = avctx->width;
03504 avctx->coded_height = avctx->height;
03505 }
03506
03507 avctx->profile = v->profile;
03508 if (v->profile == PROFILE_ADVANCED)
03509 avctx->level = v->level;
03510
03511 avctx->has_b_frames= !!(avctx->max_b_frames);
03512 s->low_delay = !avctx->has_b_frames;
03513
03514 s->mb_width = (avctx->coded_width+15)>>4;
03515 s->mb_height = (avctx->coded_height+15)>>4;
03516
03517 if (v->profile == PROFILE_ADVANCED || v->res_fasttx) {
03518 for (i = 0; i < 64; i++) {
03519 #define transpose(x) ((x>>3) | ((x&7)<<3))
03520 v->zz_8x8[0][i] = transpose(wmv1_scantable[0][i]);
03521 v->zz_8x8[1][i] = transpose(wmv1_scantable[1][i]);
03522 v->zz_8x8[2][i] = transpose(wmv1_scantable[2][i]);
03523 v->zz_8x8[3][i] = transpose(wmv1_scantable[3][i]);
03524 }
03525 v->left_blk_sh = 0;
03526 v->top_blk_sh = 3;
03527 } else {
03528 memcpy(v->zz_8x8, wmv1_scantable, 4*64);
03529 v->left_blk_sh = 3;
03530 v->top_blk_sh = 0;
03531 }
03532
03533
03534 v->mv_type_mb_plane = av_malloc(s->mb_stride * s->mb_height);
03535 v->direct_mb_plane = av_malloc(s->mb_stride * s->mb_height);
03536 v->acpred_plane = av_malloc(s->mb_stride * s->mb_height);
03537 v->over_flags_plane = av_malloc(s->mb_stride * s->mb_height);
03538
03539 v->n_allocated_blks = s->mb_width + 2;
03540 v->block = av_malloc(sizeof(*v->block) * v->n_allocated_blks);
03541 v->cbp_base = av_malloc(sizeof(v->cbp_base[0]) * 2 * s->mb_stride);
03542 v->cbp = v->cbp_base + s->mb_stride;
03543 v->ttblk_base = av_malloc(sizeof(v->ttblk_base[0]) * 2 * s->mb_stride);
03544 v->ttblk = v->ttblk_base + s->mb_stride;
03545 v->is_intra_base = av_malloc(sizeof(v->is_intra_base[0]) * 2 * s->mb_stride);
03546 v->is_intra = v->is_intra_base + s->mb_stride;
03547 v->luma_mv_base = av_malloc(sizeof(v->luma_mv_base[0]) * 2 * s->mb_stride);
03548 v->luma_mv = v->luma_mv_base + s->mb_stride;
03549
03550
03551 v->mb_type_base = av_malloc(s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2);
03552 v->mb_type[0] = v->mb_type_base + s->b8_stride + 1;
03553 v->mb_type[1] = v->mb_type_base + s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride + 1;
03554 v->mb_type[2] = v->mb_type[1] + s->mb_stride * (s->mb_height + 1);
03555
03556
03557 if (v->profile == PROFILE_ADVANCED)
03558 {
03559
03560
03561
03562
03563 }
03564
03565 ff_intrax8_common_init(&v->x8,s);
03566 return 0;
03567 }
03568
03569
03573 static int vc1_decode_frame(AVCodecContext *avctx,
03574 void *data, int *data_size,
03575 AVPacket *avpkt)
03576 {
03577 const uint8_t *buf = avpkt->data;
03578 int buf_size = avpkt->size, n_slices = 0, i;
03579 VC1Context *v = avctx->priv_data;
03580 MpegEncContext *s = &v->s;
03581 AVFrame *pict = data;
03582 uint8_t *buf2 = NULL;
03583 const uint8_t *buf_start = buf;
03584 struct {
03585 uint8_t *buf;
03586 GetBitContext gb;
03587 int mby_start;
03588 } *slices = NULL;
03589
03590
03591 if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == VC1_CODE_ENDOFSEQ)) {
03592
03593 if (s->low_delay==0 && s->next_picture_ptr) {
03594 *pict= *(AVFrame*)s->next_picture_ptr;
03595 s->next_picture_ptr= NULL;
03596
03597 *data_size = sizeof(AVFrame);
03598 }
03599
03600 return 0;
03601 }
03602
03603
03604
03605 if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){
03606 int i= ff_find_unused_picture(s, 0);
03607 s->current_picture_ptr= &s->picture[i];
03608 }
03609
03610 if (s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU){
03611 if (v->profile < PROFILE_ADVANCED)
03612 avctx->pix_fmt = PIX_FMT_VDPAU_WMV3;
03613 else
03614 avctx->pix_fmt = PIX_FMT_VDPAU_VC1;
03615 }
03616
03617
03618 if (avctx->codec_id == CODEC_ID_VC1) {
03619 int buf_size2 = 0;
03620 buf2 = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
03621
03622 if(IS_MARKER(AV_RB32(buf))){
03623 const uint8_t *start, *end, *next;
03624 int size;
03625
03626 next = buf;
03627 for(start = buf, end = buf + buf_size; next < end; start = next){
03628 next = find_next_marker(start + 4, end);
03629 size = next - start - 4;
03630 if(size <= 0) continue;
03631 switch(AV_RB32(start)){
03632 case VC1_CODE_FRAME:
03633 if (avctx->hwaccel ||
03634 s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
03635 buf_start = start;
03636 buf_size2 = vc1_unescape_buffer(start + 4, size, buf2);
03637 break;
03638 case VC1_CODE_ENTRYPOINT:
03639 buf_size2 = vc1_unescape_buffer(start + 4, size, buf2);
03640 init_get_bits(&s->gb, buf2, buf_size2*8);
03641 vc1_decode_entry_point(avctx, v, &s->gb);
03642 break;
03643 case VC1_CODE_SLICE: {
03644 int buf_size3;
03645 slices = av_realloc(slices, sizeof(*slices) * (n_slices+1));
03646 if (!slices) goto err;
03647 slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
03648 if (!slices[n_slices].buf) goto err;
03649 buf_size3 = vc1_unescape_buffer(start + 4, size,
03650 slices[n_slices].buf);
03651 init_get_bits(&slices[n_slices].gb, slices[n_slices].buf,
03652 buf_size3 << 3);
03653 slices[n_slices].mby_start = get_bits(&slices[n_slices].gb, 9);
03654 n_slices++;
03655 break;
03656 }
03657 }
03658 }
03659 }else if(v->interlace && ((buf[0] & 0xC0) == 0xC0)){
03660 const uint8_t *divider;
03661
03662 divider = find_next_marker(buf, buf + buf_size);
03663 if((divider == (buf + buf_size)) || AV_RB32(divider) != VC1_CODE_FIELD){
03664 av_log(avctx, AV_LOG_ERROR, "Error in WVC1 interlaced frame\n");
03665 goto err;
03666 }
03667
03668 buf_size2 = vc1_unescape_buffer(buf, divider - buf, buf2);
03669
03670 if(!v->warn_interlaced++)
03671 av_log(v->s.avctx, AV_LOG_ERROR, "Interlaced WVC1 support is not implemented\n");
03672 goto err;
03673 }else{
03674 buf_size2 = vc1_unescape_buffer(buf, buf_size, buf2);
03675 }
03676 init_get_bits(&s->gb, buf2, buf_size2*8);
03677 } else
03678 init_get_bits(&s->gb, buf, buf_size*8);
03679
03680 if (v->res_sprite) {
03681 v->new_sprite = !get_bits1(&s->gb);
03682 v->two_sprites = get_bits1(&s->gb);
03683 if (!v->new_sprite)
03684 goto end;
03685 }
03686
03687
03688 if(v->profile < PROFILE_ADVANCED) {
03689 if(vc1_parse_frame_header(v, &s->gb) == -1) {
03690 goto err;
03691 }
03692 } else {
03693 if(vc1_parse_frame_header_adv(v, &s->gb) == -1) {
03694 goto err;
03695 }
03696 }
03697
03698 if (v->res_sprite && s->pict_type!=AV_PICTURE_TYPE_I) {
03699 av_log(v->s.avctx, AV_LOG_WARNING, "Sprite decoder: expected I-frame\n");
03700 }
03701
03702 s->current_picture_ptr->repeat_pict = 0;
03703 if (v->rff){
03704 s->current_picture_ptr->repeat_pict = 1;
03705 }else if (v->rptfrm){
03706 s->current_picture_ptr->repeat_pict = v->rptfrm * 2;
03707 }
03708
03709 s->current_picture_ptr->top_field_first = v->tff;
03710
03711
03712 s->current_picture.pict_type= s->pict_type;
03713 s->current_picture.key_frame= s->pict_type == AV_PICTURE_TYPE_I;
03714
03715
03716 if(s->last_picture_ptr==NULL && (s->pict_type==AV_PICTURE_TYPE_B || s->dropable)){
03717 goto err;
03718 }
03719 if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==AV_PICTURE_TYPE_B)
03720 || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=AV_PICTURE_TYPE_I)
03721 || avctx->skip_frame >= AVDISCARD_ALL) {
03722 goto end;
03723 }
03724
03725 if(s->next_p_frame_damaged){
03726 if(s->pict_type==AV_PICTURE_TYPE_B)
03727 goto end;
03728 else
03729 s->next_p_frame_damaged=0;
03730 }
03731
03732 if(MPV_frame_start(s, avctx) < 0) {
03733 goto err;
03734 }
03735
03736 s->me.qpel_put= s->dsp.put_qpel_pixels_tab;
03737 s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab;
03738
03739 if ((CONFIG_VC1_VDPAU_DECODER)
03740 &&s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
03741 ff_vdpau_vc1_decode_picture(s, buf_start, (buf + buf_size) - buf_start);
03742 else if (avctx->hwaccel) {
03743 if (avctx->hwaccel->start_frame(avctx, buf, buf_size) < 0)
03744 goto err;
03745 if (avctx->hwaccel->decode_slice(avctx, buf_start, (buf + buf_size) - buf_start) < 0)
03746 goto err;
03747 if (avctx->hwaccel->end_frame(avctx) < 0)
03748 goto err;
03749 } else {
03750 ff_er_frame_start(s);
03751
03752 v->bits = buf_size * 8;
03753 for (i = 0; i <= n_slices; i++) {
03754 if (i && get_bits1(&s->gb))
03755 vc1_parse_frame_header_adv(v, &s->gb);
03756 s->start_mb_y = (i == 0) ? 0 : FFMAX(0, slices[i-1].mby_start);
03757 s->end_mb_y = (i == n_slices) ? s->mb_height : FFMIN(s->mb_height, slices[i].mby_start);
03758 vc1_decode_blocks(v);
03759 if (i != n_slices) s->gb = slices[i].gb;
03760 }
03761
03762
03763
03764 ff_er_frame_end(s);
03765 }
03766
03767 MPV_frame_end(s);
03768
03769 assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
03770 assert(s->current_picture.pict_type == s->pict_type);
03771 if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
03772 *pict= *(AVFrame*)s->current_picture_ptr;
03773 } else if (s->last_picture_ptr != NULL) {
03774 *pict= *(AVFrame*)s->last_picture_ptr;
03775 }
03776
03777 if(s->last_picture_ptr || s->low_delay){
03778 *data_size = sizeof(AVFrame);
03779 ff_print_debug_info(s, pict);
03780 }
03781
03782 end:
03783 if (v->res_sprite)
03784 vc1_parse_sprites(v, &s->gb);
03785 av_free(buf2);
03786 for (i = 0; i < n_slices; i++)
03787 av_free(slices[i].buf);
03788 av_free(slices);
03789 return buf_size;
03790
03791 err:
03792 av_free(buf2);
03793 for (i = 0; i < n_slices; i++)
03794 av_free(slices[i].buf);
03795 av_free(slices);
03796 return -1;
03797 }
03798
03799
03803 static av_cold int vc1_decode_end(AVCodecContext *avctx)
03804 {
03805 VC1Context *v = avctx->priv_data;
03806
03807 av_freep(&v->hrd_rate);
03808 av_freep(&v->hrd_buffer);
03809 MPV_common_end(&v->s);
03810 av_freep(&v->mv_type_mb_plane);
03811 av_freep(&v->direct_mb_plane);
03812 av_freep(&v->acpred_plane);
03813 av_freep(&v->over_flags_plane);
03814 av_freep(&v->mb_type_base);
03815 av_freep(&v->block);
03816 av_freep(&v->cbp_base);
03817 av_freep(&v->ttblk_base);
03818 av_freep(&v->is_intra_base);
03819 av_freep(&v->luma_mv_base);
03820 ff_intrax8_common_end(&v->x8);
03821 return 0;
03822 }
03823
03824 static const AVProfile profiles[] = {
03825 { FF_PROFILE_VC1_SIMPLE, "Simple" },
03826 { FF_PROFILE_VC1_MAIN, "Main" },
03827 { FF_PROFILE_VC1_COMPLEX, "Complex" },
03828 { FF_PROFILE_VC1_ADVANCED, "Advanced" },
03829 { FF_PROFILE_UNKNOWN },
03830 };
03831
03832 AVCodec ff_vc1_decoder = {
03833 "vc1",
03834 AVMEDIA_TYPE_VIDEO,
03835 CODEC_ID_VC1,
03836 sizeof(VC1Context),
03837 vc1_decode_init,
03838 NULL,
03839 vc1_decode_end,
03840 vc1_decode_frame,
03841 CODEC_CAP_DR1 | CODEC_CAP_DELAY,
03842 NULL,
03843 .flush = ff_mpeg_flush,
03844 .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1"),
03845 .pix_fmts = ff_hwaccel_pixfmt_list_420,
03846 .profiles = NULL_IF_CONFIG_SMALL(profiles)
03847 };
03848
03849 #if CONFIG_WMV3_DECODER
03850 AVCodec ff_wmv3_decoder = {
03851 "wmv3",
03852 AVMEDIA_TYPE_VIDEO,
03853 CODEC_ID_WMV3,
03854 sizeof(VC1Context),
03855 vc1_decode_init,
03856 NULL,
03857 vc1_decode_end,
03858 vc1_decode_frame,
03859 CODEC_CAP_DR1 | CODEC_CAP_DELAY,
03860 NULL,
03861 .flush = ff_mpeg_flush,
03862 .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9"),
03863 .pix_fmts = ff_hwaccel_pixfmt_list_420,
03864 .profiles = NULL_IF_CONFIG_SMALL(profiles)
03865 };
03866 #endif
03867
03868 #if CONFIG_WMV3_VDPAU_DECODER
03869 AVCodec ff_wmv3_vdpau_decoder = {
03870 "wmv3_vdpau",
03871 AVMEDIA_TYPE_VIDEO,
03872 CODEC_ID_WMV3,
03873 sizeof(VC1Context),
03874 vc1_decode_init,
03875 NULL,
03876 vc1_decode_end,
03877 vc1_decode_frame,
03878 CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
03879 NULL,
03880 .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 VDPAU"),
03881 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_WMV3, PIX_FMT_NONE},
03882 .profiles = NULL_IF_CONFIG_SMALL(profiles)
03883 };
03884 #endif
03885
03886 #if CONFIG_VC1_VDPAU_DECODER
03887 AVCodec ff_vc1_vdpau_decoder = {
03888 "vc1_vdpau",
03889 AVMEDIA_TYPE_VIDEO,
03890 CODEC_ID_VC1,
03891 sizeof(VC1Context),
03892 vc1_decode_init,
03893 NULL,
03894 vc1_decode_end,
03895 vc1_decode_frame,
03896 CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
03897 NULL,
03898 .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1 VDPAU"),
03899 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_VC1, PIX_FMT_NONE},
03900 .profiles = NULL_IF_CONFIG_SMALL(profiles)
03901 };
03902 #endif