| @@ -305,45 +305,40 @@ static int zero_cmp(MpegEncContext *s, const uint8_t *a, const uint8_t *b, · 304 unmodified lines |
| 305 | 305 | static void zero_hpel(uint8_t *a, const uint8_t *b, ptrdiff_t stride, int h){ |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | | −int ff_init_me(MpegEncContext *s){ |
| 309 | | − MotionEstContext * const c= &s->me; |
| 310 | | − int cache_size= FFMIN(ME_MAP_SIZE>>ME_MAP_SHIFT, 1<<ME_MAP_SHIFT); |
| 311 | | − int dia_size= FFMAX(FFABS(s->avctx->dia_size)&255, FFABS(s->avctx->pre_dia_size)&255); |
| 308 | +av_cold int ff_me_init(MotionEstContext *c, AVCodecContext *avctx, MECmpContext *mecc) |
| 309 | +{ |
| 310 | + int cache_size = FFMIN(ME_MAP_SIZE>>ME_MAP_SHIFT, 1<<ME_MAP_SHIFT); |
| 311 | + int dia_size = FFMAX(FFABS(avctx->dia_size) & 255, FFABS(avctx->pre_dia_size) & 255); |
| 312 | 312 | int ret; |
| 313 | 313 | |
| 314 | | − if(FFMIN(s->avctx->dia_size, s->avctx->pre_dia_size) < -FFMIN(ME_MAP_SIZE, MAX_SAB_SIZE)){ |
| 315 | | − av_log(s->avctx, AV_LOG_ERROR, "ME_MAP size is too small for SAB diamond\n"); |
| 316 | | − return -1; |
| 314 | + if (FFMIN(avctx->dia_size, avctx->pre_dia_size) < -FFMIN(ME_MAP_SIZE, MAX_SAB_SIZE)) { |
| 315 | + av_log(avctx, AV_LOG_ERROR, "ME_MAP size is too small for SAB diamond\n"); |
| 316 | + return AVERROR(EINVAL); |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | | − c->avctx= s->avctx; |
| 319 | + c->avctx = avctx; |
| 320 | 320 | |
| 321 | | − if(s->codec_id == AV_CODEC_ID_H261) |
| 322 | | − c->avctx->me_sub_cmp = c->avctx->me_cmp; |
| 321 | + if (avctx->codec_id == AV_CODEC_ID_H261) |
| 322 | + avctx->me_sub_cmp = avctx->me_cmp; |
| 323 | 323 | |
| 324 | | − if(cache_size < 2*dia_size && !c->stride){ |
| 325 | | − av_log(s->avctx, AV_LOG_INFO, "ME_MAP size may be a little small for the selected diamond size\n"); |
| 326 | | − } |
| 324 | + if (cache_size < 2 * dia_size) |
| 325 | + av_log(avctx, AV_LOG_INFO, "ME_MAP size may be a little small for the selected diamond size\n"); |
| 327 | 326 | |
| 328 | | − ret = ff_set_cmp(&s->mecc, s->mecc.me_pre_cmp, c->avctx->me_pre_cmp); |
| 329 | | − ret |= ff_set_cmp(&s->mecc, s->mecc.me_cmp, c->avctx->me_cmp); |
| 330 | | − ret |= ff_set_cmp(&s->mecc, s->mecc.me_sub_cmp, c->avctx->me_sub_cmp); |
| 331 | | − ret |= ff_set_cmp(&s->mecc, s->mecc.mb_cmp, c->avctx->mb_cmp); |
| 327 | + ret = ff_set_cmp(mecc, mecc->me_pre_cmp, avctx->me_pre_cmp); |
| 328 | + ret |= ff_set_cmp(mecc, mecc->me_cmp, avctx->me_cmp); |
| 329 | + ret |= ff_set_cmp(mecc, mecc->me_sub_cmp, avctx->me_sub_cmp); |
| 330 | + ret |= ff_set_cmp(mecc, mecc->mb_cmp, avctx->mb_cmp); |
| 332 | 331 | if (ret < 0) |
| 333 | 332 | return ret; |
| 334 | 333 | |
| 335 | | − c->flags = get_flags(c, 0, c->avctx->me_cmp &FF_CMP_CHROMA); |
| 336 | | − c->sub_flags= get_flags(c, 0, c->avctx->me_sub_cmp&FF_CMP_CHROMA); |
| 337 | | − c->mb_flags = get_flags(c, 0, c->avctx->mb_cmp &FF_CMP_CHROMA); |
| 334 | + c->flags = get_flags(c, 0, avctx->me_cmp & FF_CMP_CHROMA); |
| 335 | + c->sub_flags = get_flags(c, 0, avctx->me_sub_cmp & FF_CMP_CHROMA); |
| 336 | + c->mb_flags = get_flags(c, 0, avctx->mb_cmp & FF_CMP_CHROMA); |
| 338 | 337 | |
| 339 | | −/*FIXME s->no_rounding b_type*/ |
| 340 | | − if (s->avctx->flags & AV_CODEC_FLAG_QPEL) { |
| 338 | + if (avctx->codec_id == AV_CODEC_ID_H261) { |
| 339 | + c->sub_motion_search = no_sub_motion_search; |
| 340 | + } else if (avctx->flags & AV_CODEC_FLAG_QPEL) { |
| 341 | 341 | c->sub_motion_search= qpel_motion_search; |
| 342 | | − c->qpel_avg = s->qdsp.avg_qpel_pixels_tab; |
| 343 | | − if (s->no_rounding) |
| 344 | | − c->qpel_put = s->qdsp.put_no_rnd_qpel_pixels_tab; |
| 345 | | − else |
| 346 | | − c->qpel_put = s->qdsp.put_qpel_pixels_tab; |
| 347 | 342 | }else{ |
| 348 | 343 | if(c->avctx->me_sub_cmp&FF_CMP_CHROMA) |
| 349 | 344 | c->sub_motion_search= hpel_motion_search; |
| @@ -354,6 +349,32 @@ int ff_init_me(MpegEncContext *s){ · 4 unmodified lines |
| 354 | 349 | else |
| 355 | 350 | c->sub_motion_search= hpel_motion_search; |
| 356 | 351 | } |
| 352 | + |
| 353 | + /* 8x8 fullpel search would need a 4x4 chroma compare, which we do |
| 354 | + * not have yet, and even if we had, the motion estimation code |
| 355 | + * does not expect it. */ |
| 356 | + if (avctx->codec_id != AV_CODEC_ID_SNOW) { |
| 357 | + if ((avctx->me_cmp & FF_CMP_CHROMA) /* && !s->mecc.me_cmp[2] */) |
| 358 | + mecc->me_cmp[2] = zero_cmp; |
| 359 | + if ((avctx->me_sub_cmp & FF_CMP_CHROMA) && !mecc->me_sub_cmp[2]) |
| 360 | + mecc->me_sub_cmp[2] = zero_cmp; |
| 361 | + } |
| 362 | + |
| 363 | + return 0; |
| 364 | +} |
| 365 | + |
| 366 | +void ff_me_init_pic(MpegEncContext *s) |
| 367 | +{ |
| 368 | + MotionEstContext * const c= &s->me; |
| 369 | + |
| 370 | +/*FIXME s->no_rounding b_type*/ |
| 371 | + if (s->avctx->flags & AV_CODEC_FLAG_QPEL) { |
| 372 | + c->qpel_avg = s->qdsp.avg_qpel_pixels_tab; |
| 373 | + if (s->no_rounding) |
| 374 | + c->qpel_put = s->qdsp.put_no_rnd_qpel_pixels_tab; |
| 375 | + else |
| 376 | + c->qpel_put = s->qdsp.put_qpel_pixels_tab; |
| 377 | + } |
| 357 | 378 | c->hpel_avg = s->hdsp.avg_pixels_tab; |
| 358 | 379 | if (s->no_rounding) |
| 359 | 380 | c->hpel_put = s->hdsp.put_no_rnd_pixels_tab; |
| @@ -367,24 +388,10 @@ int ff_init_me(MpegEncContext *s){ · 7 unmodified lines |
| 367 | 388 | c->stride = 16*s->mb_width + 32; |
| 368 | 389 | c->uvstride= 8*s->mb_width + 16; |
| 369 | 390 | } |
| 370 | | − |
| 371 | | − /* 8x8 fullpel search would need a 4x4 chroma compare, which we do |
| 372 | | − * not have yet, and even if we had, the motion estimation code |
| 373 | | − * does not expect it. */ |
| 374 | 391 | if (s->codec_id != AV_CODEC_ID_SNOW) { |
| 375 | | − if ((c->avctx->me_cmp & FF_CMP_CHROMA) /* && !s->mecc.me_cmp[2] */) |
| 376 | | − s->mecc.me_cmp[2] = zero_cmp; |
| 377 | | − if ((c->avctx->me_sub_cmp & FF_CMP_CHROMA) && !s->mecc.me_sub_cmp[2]) |
| 378 | | − s->mecc.me_sub_cmp[2] = zero_cmp; |
| 379 | 392 | c->hpel_put[2][0]= c->hpel_put[2][1]= |
| 380 | 393 | c->hpel_put[2][2]= c->hpel_put[2][3]= zero_hpel; |
| 381 | 394 | } |
| 382 | | − |
| 383 | | − if(s->codec_id == AV_CODEC_ID_H261){ |
| 384 | | − c->sub_motion_search= no_sub_motion_search; |
| 385 | | − } |
| 386 | | − |
| 387 | | − return 0; |
| 388 | 395 | } |
| 389 | 396 | |
| 390 | 397 | #define CHECK_SAD_HALF_MV(suffix, x, y) \ |