00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00028 #include "avcodec.h"
00029 #include "bitstream.h"
00030 #include "golomb.h"
00031 #include "mathops.h"
00032 #include "cavs.h"
00033 #include "cavsdata.h"
00034
00035
00036
00037
00038
00039
00040
00041 static inline int get_bs(cavs_vector *mvP, cavs_vector *mvQ, int b) {
00042 if((mvP->ref == REF_INTRA) || (mvQ->ref == REF_INTRA))
00043 return 2;
00044 if( (abs(mvP->x - mvQ->x) >= 4) || (abs(mvP->y - mvQ->y) >= 4) )
00045 return 1;
00046 if(b){
00047 mvP += MV_BWD_OFFS;
00048 mvQ += MV_BWD_OFFS;
00049 if( (abs(mvP->x - mvQ->x) >= 4) || (abs(mvP->y - mvQ->y) >= 4) )
00050 return 1;
00051 }else{
00052 if(mvP->ref != mvQ->ref)
00053 return 1;
00054 }
00055 return 0;
00056 }
00057
00058 #define SET_PARAMS \
00059 alpha = alpha_tab[av_clip(qp_avg + h->alpha_offset,0,63)]; \
00060 beta = beta_tab[av_clip(qp_avg + h->beta_offset, 0,63)]; \
00061 tc = tc_tab[av_clip(qp_avg + h->alpha_offset,0,63)];
00062
00075 void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type) {
00076 DECLARE_ALIGNED_8(uint8_t, bs[8]);
00077 int qp_avg, alpha, beta, tc;
00078 int i;
00079
00080
00081 h->topleft_border_y = h->top_border_y[h->mbx*16+15];
00082 h->topleft_border_u = h->top_border_u[h->mbx*10+8];
00083 h->topleft_border_v = h->top_border_v[h->mbx*10+8];
00084 memcpy(&h->top_border_y[h->mbx*16], h->cy + 15* h->l_stride,16);
00085 memcpy(&h->top_border_u[h->mbx*10+1], h->cu + 7* h->c_stride,8);
00086 memcpy(&h->top_border_v[h->mbx*10+1], h->cv + 7* h->c_stride,8);
00087 for(i=0;i<8;i++) {
00088 h->left_border_y[i*2+1] = *(h->cy + 15 + (i*2+0)*h->l_stride);
00089 h->left_border_y[i*2+2] = *(h->cy + 15 + (i*2+1)*h->l_stride);
00090 h->left_border_u[i+1] = *(h->cu + 7 + i*h->c_stride);
00091 h->left_border_v[i+1] = *(h->cv + 7 + i*h->c_stride);
00092 }
00093 if(!h->loop_filter_disable) {
00094
00095 if(mb_type == I_8X8)
00096 *((uint64_t *)bs) = 0x0202020202020202ULL;
00097 else{
00098 *((uint64_t *)bs) = 0;
00099 if(ff_cavs_partition_flags[mb_type] & SPLITV){
00100 bs[2] = get_bs(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X1], mb_type > P_8X8);
00101 bs[3] = get_bs(&h->mv[MV_FWD_X2], &h->mv[MV_FWD_X3], mb_type > P_8X8);
00102 }
00103 if(ff_cavs_partition_flags[mb_type] & SPLITH){
00104 bs[6] = get_bs(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X2], mb_type > P_8X8);
00105 bs[7] = get_bs(&h->mv[MV_FWD_X1], &h->mv[MV_FWD_X3], mb_type > P_8X8);
00106 }
00107 bs[0] = get_bs(&h->mv[MV_FWD_A1], &h->mv[MV_FWD_X0], mb_type > P_8X8);
00108 bs[1] = get_bs(&h->mv[MV_FWD_A3], &h->mv[MV_FWD_X2], mb_type > P_8X8);
00109 bs[4] = get_bs(&h->mv[MV_FWD_B2], &h->mv[MV_FWD_X0], mb_type > P_8X8);
00110 bs[5] = get_bs(&h->mv[MV_FWD_B3], &h->mv[MV_FWD_X1], mb_type > P_8X8);
00111 }
00112 if( *((uint64_t *)bs) ) {
00113 if(h->flags & A_AVAIL) {
00114 qp_avg = (h->qp + h->left_qp + 1) >> 1;
00115 SET_PARAMS;
00116 h->s.dsp.cavs_filter_lv(h->cy,h->l_stride,alpha,beta,tc,bs[0],bs[1]);
00117 h->s.dsp.cavs_filter_cv(h->cu,h->c_stride,alpha,beta,tc,bs[0],bs[1]);
00118 h->s.dsp.cavs_filter_cv(h->cv,h->c_stride,alpha,beta,tc,bs[0],bs[1]);
00119 }
00120 qp_avg = h->qp;
00121 SET_PARAMS;
00122 h->s.dsp.cavs_filter_lv(h->cy + 8,h->l_stride,alpha,beta,tc,bs[2],bs[3]);
00123 h->s.dsp.cavs_filter_lh(h->cy + 8*h->l_stride,h->l_stride,alpha,beta,tc,
00124 bs[6],bs[7]);
00125
00126 if(h->flags & B_AVAIL) {
00127 qp_avg = (h->qp + h->top_qp[h->mbx] + 1) >> 1;
00128 SET_PARAMS;
00129 h->s.dsp.cavs_filter_lh(h->cy,h->l_stride,alpha,beta,tc,bs[4],bs[5]);
00130 h->s.dsp.cavs_filter_ch(h->cu,h->c_stride,alpha,beta,tc,bs[4],bs[5]);
00131 h->s.dsp.cavs_filter_ch(h->cv,h->c_stride,alpha,beta,tc,bs[4],bs[5]);
00132 }
00133 }
00134 }
00135 h->left_qp = h->qp;
00136 h->top_qp[h->mbx] = h->qp;
00137 }
00138
00139 #undef SET_PARAMS
00140
00141
00142
00143
00144
00145
00146
00147 void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top,
00148 uint8_t **left, int block) {
00149 int i;
00150
00151 switch(block) {
00152 case 0:
00153 *left = h->left_border_y;
00154 h->left_border_y[0] = h->left_border_y[1];
00155 memset(&h->left_border_y[17],h->left_border_y[16],9);
00156 memcpy(&top[1],&h->top_border_y[h->mbx*16],16);
00157 top[17] = top[16];
00158 top[0] = top[1];
00159 if((h->flags & A_AVAIL) && (h->flags & B_AVAIL))
00160 h->left_border_y[0] = top[0] = h->topleft_border_y;
00161 break;
00162 case 1:
00163 *left = h->intern_border_y;
00164 for(i=0;i<8;i++)
00165 h->intern_border_y[i+1] = *(h->cy + 7 + i*h->l_stride);
00166 memset(&h->intern_border_y[9],h->intern_border_y[8],9);
00167 h->intern_border_y[0] = h->intern_border_y[1];
00168 memcpy(&top[1],&h->top_border_y[h->mbx*16+8],8);
00169 if(h->flags & C_AVAIL)
00170 memcpy(&top[9],&h->top_border_y[(h->mbx + 1)*16],8);
00171 else
00172 memset(&top[9],top[8],9);
00173 top[17] = top[16];
00174 top[0] = top[1];
00175 if(h->flags & B_AVAIL)
00176 h->intern_border_y[0] = top[0] = h->top_border_y[h->mbx*16+7];
00177 break;
00178 case 2:
00179 *left = &h->left_border_y[8];
00180 memcpy(&top[1],h->cy + 7*h->l_stride,16);
00181 top[17] = top[16];
00182 top[0] = top[1];
00183 if(h->flags & A_AVAIL)
00184 top[0] = h->left_border_y[8];
00185 break;
00186 case 3:
00187 *left = &h->intern_border_y[8];
00188 for(i=0;i<8;i++)
00189 h->intern_border_y[i+9] = *(h->cy + 7 + (i+8)*h->l_stride);
00190 memset(&h->intern_border_y[17],h->intern_border_y[16],9);
00191 memcpy(&top[0],h->cy + 7 + 7*h->l_stride,9);
00192 memset(&top[9],top[8],9);
00193 break;
00194 }
00195 }
00196
00197 void ff_cavs_load_intra_pred_chroma(AVSContext *h) {
00198
00199 h->left_border_u[9] = h->left_border_u[8];
00200 h->left_border_v[9] = h->left_border_v[8];
00201 h->top_border_u[h->mbx*10+9] = h->top_border_u[h->mbx*10+8];
00202 h->top_border_v[h->mbx*10+9] = h->top_border_v[h->mbx*10+8];
00203 if(h->mbx && h->mby) {
00204 h->top_border_u[h->mbx*10] = h->left_border_u[0] = h->topleft_border_u;
00205 h->top_border_v[h->mbx*10] = h->left_border_v[0] = h->topleft_border_v;
00206 } else {
00207 h->left_border_u[0] = h->left_border_u[1];
00208 h->left_border_v[0] = h->left_border_v[1];
00209 h->top_border_u[h->mbx*10] = h->top_border_u[h->mbx*10+1];
00210 h->top_border_v[h->mbx*10] = h->top_border_v[h->mbx*10+1];
00211 }
00212 }
00213
00214 static void intra_pred_vert(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
00215 int y;
00216 uint64_t a = AV_RN64(&top[1]);
00217 for(y=0;y<8;y++) {
00218 *((uint64_t *)(d+y*stride)) = a;
00219 }
00220 }
00221
00222 static void intra_pred_horiz(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
00223 int y;
00224 uint64_t a;
00225 for(y=0;y<8;y++) {
00226 a = left[y+1] * 0x0101010101010101ULL;
00227 *((uint64_t *)(d+y*stride)) = a;
00228 }
00229 }
00230
00231 static void intra_pred_dc_128(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
00232 int y;
00233 uint64_t a = 0x8080808080808080ULL;
00234 for(y=0;y<8;y++)
00235 *((uint64_t *)(d+y*stride)) = a;
00236 }
00237
00238 static void intra_pred_plane(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
00239 int x,y,ia;
00240 int ih = 0;
00241 int iv = 0;
00242 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
00243
00244 for(x=0; x<4; x++) {
00245 ih += (x+1)*(top[5+x]-top[3-x]);
00246 iv += (x+1)*(left[5+x]-left[3-x]);
00247 }
00248 ia = (top[8]+left[8])<<4;
00249 ih = (17*ih+16)>>5;
00250 iv = (17*iv+16)>>5;
00251 for(y=0; y<8; y++)
00252 for(x=0; x<8; x++)
00253 d[y*stride+x] = cm[(ia+(x-3)*ih+(y-3)*iv+16)>>5];
00254 }
00255
00256 #define LOWPASS(ARRAY,INDEX) \
00257 (( ARRAY[(INDEX)-1] + 2*ARRAY[(INDEX)] + ARRAY[(INDEX)+1] + 2) >> 2)
00258
00259 static void intra_pred_lp(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
00260 int x,y;
00261 for(y=0; y<8; y++)
00262 for(x=0; x<8; x++)
00263 d[y*stride+x] = (LOWPASS(top,x+1) + LOWPASS(left,y+1)) >> 1;
00264 }
00265
00266 static void intra_pred_down_left(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
00267 int x,y;
00268 for(y=0; y<8; y++)
00269 for(x=0; x<8; x++)
00270 d[y*stride+x] = (LOWPASS(top,x+y+2) + LOWPASS(left,x+y+2)) >> 1;
00271 }
00272
00273 static void intra_pred_down_right(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
00274 int x,y;
00275 for(y=0; y<8; y++)
00276 for(x=0; x<8; x++)
00277 if(x==y)
00278 d[y*stride+x] = (left[1]+2*top[0]+top[1]+2)>>2;
00279 else if(x>y)
00280 d[y*stride+x] = LOWPASS(top,x-y);
00281 else
00282 d[y*stride+x] = LOWPASS(left,y-x);
00283 }
00284
00285 static void intra_pred_lp_left(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
00286 int x,y;
00287 for(y=0; y<8; y++)
00288 for(x=0; x<8; x++)
00289 d[y*stride+x] = LOWPASS(left,y+1);
00290 }
00291
00292 static void intra_pred_lp_top(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
00293 int x,y;
00294 for(y=0; y<8; y++)
00295 for(x=0; x<8; x++)
00296 d[y*stride+x] = LOWPASS(top,x+1);
00297 }
00298
00299 #undef LOWPASS
00300
00301 void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv) {
00302
00303 h->pred_mode_Y[3] = h->pred_mode_Y[5];
00304 h->pred_mode_Y[6] = h->pred_mode_Y[8];
00305 h->top_pred_Y[h->mbx*2+0] = h->pred_mode_Y[7];
00306 h->top_pred_Y[h->mbx*2+1] = h->pred_mode_Y[8];
00307
00308
00309 if(!(h->flags & A_AVAIL)) {
00310 modify_pred(ff_left_modifier_l, &h->pred_mode_Y[4] );
00311 modify_pred(ff_left_modifier_l, &h->pred_mode_Y[7] );
00312 modify_pred(ff_left_modifier_c, pred_mode_uv );
00313 }
00314 if(!(h->flags & B_AVAIL)) {
00315 modify_pred(ff_top_modifier_l, &h->pred_mode_Y[4] );
00316 modify_pred(ff_top_modifier_l, &h->pred_mode_Y[5] );
00317 modify_pred(ff_top_modifier_c, pred_mode_uv );
00318 }
00319 }
00320
00321
00322
00323
00324
00325
00326
00327 static inline void mc_dir_part(AVSContext *h,Picture *pic,int square,
00328 int chroma_height,int delta,int list,uint8_t *dest_y,
00329 uint8_t *dest_cb,uint8_t *dest_cr,int src_x_offset,
00330 int src_y_offset,qpel_mc_func *qpix_op,
00331 h264_chroma_mc_func chroma_op,cavs_vector *mv){
00332 MpegEncContext * const s = &h->s;
00333 const int mx= mv->x + src_x_offset*8;
00334 const int my= mv->y + src_y_offset*8;
00335 const int luma_xy= (mx&3) + ((my&3)<<2);
00336 uint8_t * src_y = pic->data[0] + (mx>>2) + (my>>2)*h->l_stride;
00337 uint8_t * src_cb= pic->data[1] + (mx>>3) + (my>>3)*h->c_stride;
00338 uint8_t * src_cr= pic->data[2] + (mx>>3) + (my>>3)*h->c_stride;
00339 int extra_width= 0;
00340 int extra_height= extra_width;
00341 int emu=0;
00342 const int full_mx= mx>>2;
00343 const int full_my= my>>2;
00344 const int pic_width = 16*h->mb_width;
00345 const int pic_height = 16*h->mb_height;
00346
00347 if(!pic->data[0])
00348 return;
00349 if(mx&7) extra_width -= 3;
00350 if(my&7) extra_height -= 3;
00351
00352 if( full_mx < 0-extra_width
00353 || full_my < 0-extra_height
00354 || full_mx + 16 > pic_width + extra_width
00355 || full_my + 16 > pic_height + extra_height){
00356 ff_emulated_edge_mc(s->edge_emu_buffer, src_y - 2 - 2*h->l_stride, h->l_stride,
00357 16+5, 16+5, full_mx-2, full_my-2, pic_width, pic_height);
00358 src_y= s->edge_emu_buffer + 2 + 2*h->l_stride;
00359 emu=1;
00360 }
00361
00362 qpix_op[luma_xy](dest_y, src_y, h->l_stride);
00363 if(!square){
00364 qpix_op[luma_xy](dest_y + delta, src_y + delta, h->l_stride);
00365 }
00366
00367 if(emu){
00368 ff_emulated_edge_mc(s->edge_emu_buffer, src_cb, h->c_stride,
00369 9, 9, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
00370 src_cb= s->edge_emu_buffer;
00371 }
00372 chroma_op(dest_cb, src_cb, h->c_stride, chroma_height, mx&7, my&7);
00373
00374 if(emu){
00375 ff_emulated_edge_mc(s->edge_emu_buffer, src_cr, h->c_stride,
00376 9, 9, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
00377 src_cr= s->edge_emu_buffer;
00378 }
00379 chroma_op(dest_cr, src_cr, h->c_stride, chroma_height, mx&7, my&7);
00380 }
00381
00382 static inline void mc_part_std(AVSContext *h,int square,int chroma_height,int delta,
00383 uint8_t *dest_y,uint8_t *dest_cb,uint8_t *dest_cr,
00384 int x_offset, int y_offset,qpel_mc_func *qpix_put,
00385 h264_chroma_mc_func chroma_put,qpel_mc_func *qpix_avg,
00386 h264_chroma_mc_func chroma_avg, cavs_vector *mv){
00387 qpel_mc_func *qpix_op= qpix_put;
00388 h264_chroma_mc_func chroma_op= chroma_put;
00389
00390 dest_y += 2*x_offset + 2*y_offset*h->l_stride;
00391 dest_cb += x_offset + y_offset*h->c_stride;
00392 dest_cr += x_offset + y_offset*h->c_stride;
00393 x_offset += 8*h->mbx;
00394 y_offset += 8*h->mby;
00395
00396 if(mv->ref >= 0){
00397 Picture *ref= &h->DPB[mv->ref];
00398 mc_dir_part(h, ref, square, chroma_height, delta, 0,
00399 dest_y, dest_cb, dest_cr, x_offset, y_offset,
00400 qpix_op, chroma_op, mv);
00401
00402 qpix_op= qpix_avg;
00403 chroma_op= chroma_avg;
00404 }
00405
00406 if((mv+MV_BWD_OFFS)->ref >= 0){
00407 Picture *ref= &h->DPB[0];
00408 mc_dir_part(h, ref, square, chroma_height, delta, 1,
00409 dest_y, dest_cb, dest_cr, x_offset, y_offset,
00410 qpix_op, chroma_op, mv+MV_BWD_OFFS);
00411 }
00412 }
00413
00414 void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type) {
00415 if(ff_cavs_partition_flags[mb_type] == 0){
00416 mc_part_std(h, 1, 8, 0, h->cy, h->cu, h->cv, 0, 0,
00417 h->s.dsp.put_cavs_qpel_pixels_tab[0],
00418 h->s.dsp.put_h264_chroma_pixels_tab[0],
00419 h->s.dsp.avg_cavs_qpel_pixels_tab[0],
00420 h->s.dsp.avg_h264_chroma_pixels_tab[0],&h->mv[MV_FWD_X0]);
00421 }else{
00422 mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 0, 0,
00423 h->s.dsp.put_cavs_qpel_pixels_tab[1],
00424 h->s.dsp.put_h264_chroma_pixels_tab[1],
00425 h->s.dsp.avg_cavs_qpel_pixels_tab[1],
00426 h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X0]);
00427 mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 4, 0,
00428 h->s.dsp.put_cavs_qpel_pixels_tab[1],
00429 h->s.dsp.put_h264_chroma_pixels_tab[1],
00430 h->s.dsp.avg_cavs_qpel_pixels_tab[1],
00431 h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X1]);
00432 mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 0, 4,
00433 h->s.dsp.put_cavs_qpel_pixels_tab[1],
00434 h->s.dsp.put_h264_chroma_pixels_tab[1],
00435 h->s.dsp.avg_cavs_qpel_pixels_tab[1],
00436 h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X2]);
00437 mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 4, 4,
00438 h->s.dsp.put_cavs_qpel_pixels_tab[1],
00439 h->s.dsp.put_h264_chroma_pixels_tab[1],
00440 h->s.dsp.avg_cavs_qpel_pixels_tab[1],
00441 h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X3]);
00442 }
00443 }
00444
00445
00446
00447
00448
00449
00450
00451 static inline void scale_mv(AVSContext *h, int *d_x, int *d_y, cavs_vector *src, int distp) {
00452 int den = h->scale_den[src->ref];
00453
00454 *d_x = (src->x*distp*den + 256 + (src->x>>31)) >> 9;
00455 *d_y = (src->y*distp*den + 256 + (src->y>>31)) >> 9;
00456 }
00457
00458 static inline void mv_pred_median(AVSContext *h, cavs_vector *mvP,
00459 cavs_vector *mvA, cavs_vector *mvB, cavs_vector *mvC) {
00460 int ax, ay, bx, by, cx, cy;
00461 int len_ab, len_bc, len_ca, len_mid;
00462
00463
00464 scale_mv(h, &ax, &ay, mvA, mvP->dist);
00465 scale_mv(h, &bx, &by, mvB, mvP->dist);
00466 scale_mv(h, &cx, &cy, mvC, mvP->dist);
00467
00468 len_ab = abs(ax - bx) + abs(ay - by);
00469 len_bc = abs(bx - cx) + abs(by - cy);
00470 len_ca = abs(cx - ax) + abs(cy - ay);
00471 len_mid = mid_pred(len_ab, len_bc, len_ca);
00472 if(len_mid == len_ab) {
00473 mvP->x = cx;
00474 mvP->y = cy;
00475 } else if(len_mid == len_bc) {
00476 mvP->x = ax;
00477 mvP->y = ay;
00478 } else {
00479 mvP->x = bx;
00480 mvP->y = by;
00481 }
00482 }
00483
00484 void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC,
00485 enum cavs_mv_pred mode, enum cavs_block size, int ref) {
00486 cavs_vector *mvP = &h->mv[nP];
00487 cavs_vector *mvA = &h->mv[nP-1];
00488 cavs_vector *mvB = &h->mv[nP-4];
00489 cavs_vector *mvC = &h->mv[nC];
00490 const cavs_vector *mvP2 = NULL;
00491
00492 mvP->ref = ref;
00493 mvP->dist = h->dist[mvP->ref];
00494 if(mvC->ref == NOT_AVAIL)
00495 mvC = &h->mv[nP-5];
00496 if((mode == MV_PRED_PSKIP) &&
00497 ((mvA->ref == NOT_AVAIL) || (mvB->ref == NOT_AVAIL) ||
00498 ((mvA->x | mvA->y | mvA->ref) == 0) ||
00499 ((mvB->x | mvB->y | mvB->ref) == 0) )) {
00500 mvP2 = &ff_cavs_un_mv;
00501
00502 } else if((mvA->ref >= 0) && (mvB->ref < 0) && (mvC->ref < 0)) {
00503 mvP2= mvA;
00504 } else if((mvA->ref < 0) && (mvB->ref >= 0) && (mvC->ref < 0)) {
00505 mvP2= mvB;
00506 } else if((mvA->ref < 0) && (mvB->ref < 0) && (mvC->ref >= 0)) {
00507 mvP2= mvC;
00508 } else if(mode == MV_PRED_LEFT && mvA->ref == ref){
00509 mvP2= mvA;
00510 } else if(mode == MV_PRED_TOP && mvB->ref == ref){
00511 mvP2= mvB;
00512 } else if(mode == MV_PRED_TOPRIGHT && mvC->ref == ref){
00513 mvP2= mvC;
00514 }
00515 if(mvP2){
00516 mvP->x = mvP2->x;
00517 mvP->y = mvP2->y;
00518 }else
00519 mv_pred_median(h, mvP, mvA, mvB, mvC);
00520
00521 if(mode < MV_PRED_PSKIP) {
00522 mvP->x += get_se_golomb(&h->s.gb);
00523 mvP->y += get_se_golomb(&h->s.gb);
00524 }
00525 set_mvs(mvP,size);
00526 }
00527
00528
00529
00530
00531
00532
00533
00537 void ff_cavs_init_mb(AVSContext *h) {
00538 int i;
00539
00540
00541 for(i=0;i<3;i++) {
00542 h->mv[MV_FWD_B2+i] = h->top_mv[0][h->mbx*2+i];
00543 h->mv[MV_BWD_B2+i] = h->top_mv[1][h->mbx*2+i];
00544 }
00545 h->pred_mode_Y[1] = h->top_pred_Y[h->mbx*2+0];
00546 h->pred_mode_Y[2] = h->top_pred_Y[h->mbx*2+1];
00547
00548 if(!(h->flags & B_AVAIL)) {
00549 h->mv[MV_FWD_B2] = ff_cavs_un_mv;
00550 h->mv[MV_FWD_B3] = ff_cavs_un_mv;
00551 h->mv[MV_BWD_B2] = ff_cavs_un_mv;
00552 h->mv[MV_BWD_B3] = ff_cavs_un_mv;
00553 h->pred_mode_Y[1] = h->pred_mode_Y[2] = NOT_AVAIL;
00554 h->flags &= ~(C_AVAIL|D_AVAIL);
00555 } else if(h->mbx) {
00556 h->flags |= D_AVAIL;
00557 }
00558 if(h->mbx == h->mb_width-1)
00559 h->flags &= ~C_AVAIL;
00560
00561 if(!(h->flags & C_AVAIL)) {
00562 h->mv[MV_FWD_C2] = ff_cavs_un_mv;
00563 h->mv[MV_BWD_C2] = ff_cavs_un_mv;
00564 }
00565
00566 if(!(h->flags & D_AVAIL)) {
00567 h->mv[MV_FWD_D3] = ff_cavs_un_mv;
00568 h->mv[MV_BWD_D3] = ff_cavs_un_mv;
00569 }
00570 }
00571
00577 int ff_cavs_next_mb(AVSContext *h) {
00578 int i;
00579
00580 h->flags |= A_AVAIL;
00581 h->cy += 16;
00582 h->cu += 8;
00583 h->cv += 8;
00584
00585 for(i=0;i<=20;i+=4)
00586 h->mv[i] = h->mv[i+2];
00587
00588 h->top_mv[0][h->mbx*2+0] = h->mv[MV_FWD_X2];
00589 h->top_mv[0][h->mbx*2+1] = h->mv[MV_FWD_X3];
00590 h->top_mv[1][h->mbx*2+0] = h->mv[MV_BWD_X2];
00591 h->top_mv[1][h->mbx*2+1] = h->mv[MV_BWD_X3];
00592
00593 h->mbidx++;
00594 h->mbx++;
00595 if(h->mbx == h->mb_width) {
00596 h->flags = B_AVAIL|C_AVAIL;
00597
00598 h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
00599
00600 for(i=0;i<=20;i+=4)
00601 h->mv[i] = ff_cavs_un_mv;
00602 h->mbx = 0;
00603 h->mby++;
00604
00605 h->cy = h->picture.data[0] + h->mby*16*h->l_stride;
00606 h->cu = h->picture.data[1] + h->mby*8*h->c_stride;
00607 h->cv = h->picture.data[2] + h->mby*8*h->c_stride;
00608 if(h->mby == h->mb_height) {
00609 return 0;
00610 }
00611 }
00612 return 1;
00613 }
00614
00615
00616
00617
00618
00619
00620
00621 void ff_cavs_init_pic(AVSContext *h) {
00622 int i;
00623
00624
00625 for(i=0;i<=20;i+=4)
00626 h->mv[i] = ff_cavs_un_mv;
00627 h->mv[MV_BWD_X0] = ff_cavs_dir_mv;
00628 set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
00629 h->mv[MV_FWD_X0] = ff_cavs_dir_mv;
00630 set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
00631 h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
00632 h->cy = h->picture.data[0];
00633 h->cu = h->picture.data[1];
00634 h->cv = h->picture.data[2];
00635 h->l_stride = h->picture.linesize[0];
00636 h->c_stride = h->picture.linesize[1];
00637 h->luma_scan[2] = 8*h->l_stride;
00638 h->luma_scan[3] = 8*h->l_stride+8;
00639 h->mbx = h->mby = h->mbidx = 0;
00640 h->flags = 0;
00641 }
00642
00643
00644
00645
00646
00647
00648
00654 void ff_cavs_init_top_lines(AVSContext *h) {
00655
00656 h->top_qp = av_malloc( h->mb_width);
00657 h->top_mv[0] = av_malloc((h->mb_width*2+1)*sizeof(cavs_vector));
00658 h->top_mv[1] = av_malloc((h->mb_width*2+1)*sizeof(cavs_vector));
00659 h->top_pred_Y = av_malloc( h->mb_width*2*sizeof(*h->top_pred_Y));
00660 h->top_border_y = av_malloc((h->mb_width+1)*16);
00661 h->top_border_u = av_malloc((h->mb_width)*10);
00662 h->top_border_v = av_malloc((h->mb_width)*10);
00663
00664
00665 h->col_mv = av_malloc( h->mb_width*h->mb_height*4*sizeof(cavs_vector));
00666 h->col_type_base = av_malloc(h->mb_width*h->mb_height);
00667 h->block = av_mallocz(64*sizeof(DCTELEM));
00668 }
00669
00670 av_cold int ff_cavs_init(AVCodecContext *avctx) {
00671 AVSContext *h = avctx->priv_data;
00672 MpegEncContext * const s = &h->s;
00673
00674 MPV_decode_defaults(s);
00675 s->avctx = avctx;
00676
00677 avctx->pix_fmt= PIX_FMT_YUV420P;
00678
00679 h->luma_scan[0] = 0;
00680 h->luma_scan[1] = 8;
00681 h->intra_pred_l[ INTRA_L_VERT] = intra_pred_vert;
00682 h->intra_pred_l[ INTRA_L_HORIZ] = intra_pred_horiz;
00683 h->intra_pred_l[ INTRA_L_LP] = intra_pred_lp;
00684 h->intra_pred_l[ INTRA_L_DOWN_LEFT] = intra_pred_down_left;
00685 h->intra_pred_l[INTRA_L_DOWN_RIGHT] = intra_pred_down_right;
00686 h->intra_pred_l[ INTRA_L_LP_LEFT] = intra_pred_lp_left;
00687 h->intra_pred_l[ INTRA_L_LP_TOP] = intra_pred_lp_top;
00688 h->intra_pred_l[ INTRA_L_DC_128] = intra_pred_dc_128;
00689 h->intra_pred_c[ INTRA_C_LP] = intra_pred_lp;
00690 h->intra_pred_c[ INTRA_C_HORIZ] = intra_pred_horiz;
00691 h->intra_pred_c[ INTRA_C_VERT] = intra_pred_vert;
00692 h->intra_pred_c[ INTRA_C_PLANE] = intra_pred_plane;
00693 h->intra_pred_c[ INTRA_C_LP_LEFT] = intra_pred_lp_left;
00694 h->intra_pred_c[ INTRA_C_LP_TOP] = intra_pred_lp_top;
00695 h->intra_pred_c[ INTRA_C_DC_128] = intra_pred_dc_128;
00696 h->mv[ 7] = ff_cavs_un_mv;
00697 h->mv[19] = ff_cavs_un_mv;
00698 return 0;
00699 }
00700
00701 av_cold int ff_cavs_end(AVCodecContext *avctx) {
00702 AVSContext *h = avctx->priv_data;
00703
00704 av_free(h->top_qp);
00705 av_free(h->top_mv[0]);
00706 av_free(h->top_mv[1]);
00707 av_free(h->top_pred_Y);
00708 av_free(h->top_border_y);
00709 av_free(h->top_border_u);
00710 av_free(h->top_border_v);
00711 av_free(h->col_mv);
00712 av_free(h->col_type_base);
00713 av_free(h->block);
00714 return 0;
00715 }