Put it into an encoder-specific context with a SnowContext at its front. This also avoids having to include mpegvideo.h in snow.c and snowdec.c.
Unified · Split
| @@ -24,21 +24,18 @@ · 23 unmodified lines | ||
| 24 | 24 | |
| 25 | 25 | #include "libavutil/motion_vector.h" |
| 26 | 26 | |
| 27 | +#include "avcodec.h" | |
| 27 | 28 | #include "hpeldsp.h" |
| 28 | −#include "me_cmp.h" | |
| 29 | −#include "qpeldsp.h" | |
| 30 | 29 | #include "snow_dwt.h" |
| 31 | 30 | |
| 32 | 31 | #include "rangecoder.h" |
| 33 | 32 | #include "mathops.h" |
| 34 | 33 | |
| 35 | −#include "mpegvideo.h" | |
| 36 | 34 | #include "h264qpel.h" |
| 35 | +#include "videodsp.h" | |
| 37 | 36 | |
| 38 | 37 | #define SNOW_MAX_PLANES 4 |
| 39 | 38 | |
| 40 | −#define FF_ME_ITER 3 | |
| 41 | − | |
| 42 | 39 | #define MID_STATE 128 |
| 43 | 40 | |
| 44 | 41 | #define MAX_PLANES 4 |
| @@ -117,12 +114,9 @@ typedef struct SnowContext{ · 72 unmodified lines | ||
| 117 | 114 | AVClass *class; |
| 118 | 115 | AVCodecContext *avctx; |
| 119 | 116 | RangeCoder c; |
| 120 | − MECmpContext mecc; | |
| 121 | 117 | HpelDSPContext hdsp; |
| 122 | − QpelDSPContext qdsp; | |
| 123 | 118 | VideoDSPContext vdsp; |
| 124 | 119 | H264QpelContext h264qpel; |
| 125 | − MpegvideoEncDSPContext mpvencdsp; | |
| 126 | 120 | SnowDWTContext dwt; |
| 127 | 121 | AVFrame *input_picture; ///< new_picture with the internal linesizes |
| 128 | 122 | AVFrame *current_picture; |
| @@ -155,9 +149,6 @@ typedef struct SnowContext{ · 26 unmodified lines | ||
| 155 | 149 | int spatial_scalability; |
| 156 | 150 | int qlog; |
| 157 | 151 | int last_qlog; |
| 158 | − int lambda; | |
| 159 | − int lambda2; | |
| 160 | − int pass1_rc; | |
| 161 | 152 | int mv_scale; |
| 162 | 153 | int last_mv_scale; |
| 163 | 154 | int qbias; |
| @@ -170,18 +161,7 @@ typedef struct SnowContext{ · 6 unmodified lines | ||
| 170 | 161 | int nb_planes; |
| 171 | 162 | Plane plane[MAX_PLANES]; |
| 172 | 163 | BlockNode *block; |
| 173 | −#define ME_CACHE_SIZE 1024 | |
| 174 | − unsigned me_cache[ME_CACHE_SIZE]; | |
| 175 | − unsigned me_cache_generation; | |
| 176 | 164 | slice_buffer sb; |
| 177 | − int memc_only; | |
| 178 | − int no_bitstream; | |
| 179 | − int intra_penalty; | |
| 180 | − int motion_est; | |
| 181 | − int iterative_dia_size; | |
| 182 | − int scenechange_threshold; | |
| 183 | − | |
| 184 | − MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to eventually make the motion estimation independent of MpegEncContext, so this will be removed then (FIXME/XXX) | |
| 185 | 165 | |
| 186 | 166 | uint8_t *scratchbuf; |
| 187 | 167 | uint8_t *emu_edge_buffer; |
| @@ -189,9 +169,6 @@ typedef struct SnowContext{ · 1 unmodified line | ||
| 189 | 169 | AVMotionVector *avmv; |
| 190 | 170 | unsigned avmv_size; |
| 191 | 171 | int avmv_index; |
| 192 | − uint64_t encoding_error[SNOW_MAX_PLANES]; | |
| 193 | − | |
| 194 | − int pred; | |
| 195 | 172 | }SnowContext; |
| 196 | 173 | |
| 197 | 174 | /* Tables */ |
| @@ -30,6 +30,7 @@ · 29 unmodified lines | ||
| 30 | 30 | #include "internal.h" //For AVCodecInternal.recon_frame |
| 31 | 31 | #include "me_cmp.h" |
| 32 | 32 | #include "packet_internal.h" |
| 33 | +#include "qpeldsp.h" | |
| 33 | 34 | #include "snow_dwt.h" |
| 34 | 35 | #include "snow.h" |
| 35 | 36 | |
| @@ -39,6 +40,34 @@ · 3 unmodified lines | ||
| 39 | 40 | #include "mpegvideo.h" |
| 40 | 41 | #include "h263enc.h" |
| 41 | 42 | |
| 43 | +#define FF_ME_ITER 3 | |
| 44 | + | |
| 45 | +typedef struct SnowEncContext { | |
| 46 | + SnowContext com; | |
| 47 | + QpelDSPContext qdsp; | |
| 48 | + MpegvideoEncDSPContext mpvencdsp; | |
| 49 | + | |
| 50 | + int lambda; | |
| 51 | + int lambda2; | |
| 52 | + int pass1_rc; | |
| 53 | + | |
| 54 | + int pred; | |
| 55 | + int memc_only; | |
| 56 | + int no_bitstream; | |
| 57 | + int intra_penalty; | |
| 58 | + int motion_est; | |
| 59 | + int iterative_dia_size; | |
| 60 | + int scenechange_threshold; | |
| 61 | + | |
| 62 | + MECmpContext mecc; | |
| 63 | + MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to eventually make the motion estimation independent of MpegEncContext, so this will be removed then (FIXME/XXX) | |
| 64 | +#define ME_CACHE_SIZE 1024 | |
| 65 | + unsigned me_cache[ME_CACHE_SIZE]; | |
| 66 | + unsigned me_cache_generation; | |
| 67 | + | |
| 68 | + uint64_t encoding_error[SNOW_MAX_PLANES]; | |
| 69 | +} SnowEncContext; | |
| 70 | + | |
| 42 | 71 | static void init_ref(MotionEstContext *c, const uint8_t *const src[3], |
| 43 | 72 | uint8_t *const ref[3], uint8_t *const ref2[3], |
| 44 | 73 | int x, int y, int ref_index) |
| @@ -127,18 +156,20 @@ static int get_encode_buffer(SnowContext *s, AVFrame *frame) · 82 unmodified lines | ||
| 127 | 156 | |
| 128 | 157 | static av_cold int encode_init(AVCodecContext *avctx) |
| 129 | 158 | { |
| 130 | − SnowContext *s = avctx->priv_data; | |
| 159 | + SnowEncContext *const enc = avctx->priv_data; | |
| 160 | + SnowContext *const s = &enc->com; | |
| 161 | + MpegEncContext *const mpv = &enc->m; | |
| 131 | 162 | int plane_index, ret; |
| 132 | 163 | int i; |
| 133 | 164 | |
| 134 | − if(s->pred == DWT_97 | |
| 165 | + if (enc->pred == DWT_97 | |
| 135 | 166 | && (avctx->flags & AV_CODEC_FLAG_QSCALE) |
| 136 | 167 | && avctx->global_quality == 0){ |
| 137 | 168 | av_log(avctx, AV_LOG_ERROR, "The 9/7 wavelet is incompatible with lossless mode.\n"); |
| 138 | 169 | return AVERROR(EINVAL); |
| 139 | 170 | } |
| 140 | 171 | |
| 141 | − s->spatial_decomposition_type= s->pred; //FIXME add decorrelator type r transform_type | |
| 172 | + s->spatial_decomposition_type = enc->pred; //FIXME add decorrelator type r transform_type | |
| 142 | 173 | |
| 143 | 174 | s->mv_scale = (avctx->flags & AV_CODEC_FLAG_QPEL) ? 2 : 4; |
| 144 | 175 | s->block_max_depth= (avctx->flags & AV_CODEC_FLAG_4MV ) ? 1 : 0; |
| @@ -159,11 +190,11 @@ static av_cold int encode_init(AVCodecContext *avctx) · 14 unmodified lines | ||
| 159 | 190 | } |
| 160 | 191 | |
| 161 | 192 | #define mcf(dx,dy)\ |
| 162 | − s->qdsp.put_qpel_pixels_tab [0][dy+dx/4]=\ | |
| 163 | − s->qdsp.put_no_rnd_qpel_pixels_tab[0][dy+dx/4]=\ | |
| 193 | + enc->qdsp.put_qpel_pixels_tab [0][dy+dx/4]=\ | |
| 194 | + enc->qdsp.put_no_rnd_qpel_pixels_tab[0][dy+dx/4]=\ | |
| 164 | 195 | s->h264qpel.put_h264_qpel_pixels_tab[0][dy+dx/4];\ |
| 165 | − s->qdsp.put_qpel_pixels_tab [1][dy+dx/4]=\ | |
| 166 | − s->qdsp.put_no_rnd_qpel_pixels_tab[1][dy+dx/4]=\ | |
| 196 | + enc->qdsp.put_qpel_pixels_tab [1][dy+dx/4]=\ | |
| 197 | + enc->qdsp.put_no_rnd_qpel_pixels_tab[1][dy+dx/4]=\ | |
| 167 | 198 | s->h264qpel.put_h264_qpel_pixels_tab[1][dy+dx/4]; |
| 168 | 199 | |
| 169 | 200 | mcf( 0, 0) |
| @@ -183,28 +214,28 @@ static av_cold int encode_init(AVCodecContext *avctx) · 13 unmodified lines | ||
| 183 | 214 | mcf( 8,12) |
| 184 | 215 | mcf(12,12) |
| 185 | 216 | |
| 186 | − ff_me_cmp_init(&s->mecc, avctx); | |
| 187 | − ff_mpegvideoencdsp_init(&s->mpvencdsp, avctx); | |
| 217 | + ff_me_cmp_init(&enc->mecc, avctx); | |
| 218 | + ff_mpegvideoencdsp_init(&enc->mpvencdsp, avctx); | |
| 188 | 219 | |
| 189 | 220 | ff_snow_alloc_blocks(s); |
| 190 | 221 | |
| 191 | 222 | s->version=0; |
| 192 | 223 | |
| 193 | − s->m.avctx = avctx; | |
| 194 | − s->m.bit_rate= avctx->bit_rate; | |
| 195 | − s->m.lmin = avctx->mb_lmin; | |
| 196 | − s->m.lmax = avctx->mb_lmax; | |
| 197 | − s->m.mb_num = (avctx->width * avctx->height + 255) / 256; // For ratecontrol | |
| 198 | − | |
| 199 | − s->m.me.temp = | |
| 200 | − s->m.me.scratchpad = av_calloc(avctx->width + 64, 2*16*2*sizeof(uint8_t)); | |
| 201 | − s->m.sc.obmc_scratchpad= av_mallocz(MB_SIZE*MB_SIZE*12*sizeof(uint32_t)); | |
| 202 | − s->m.me.map = av_mallocz(2 * ME_MAP_SIZE * sizeof(*s->m.me.map)); | |
| 203 | − if (!s->m.me.scratchpad || !s->m.me.map || !s->m.sc.obmc_scratchpad) | |
| 224 | + mpv->avctx = avctx; | |
| 225 | + mpv->bit_rate= avctx->bit_rate; | |
| 226 | + mpv->lmin = avctx->mb_lmin; | |
| 227 | + mpv->lmax = avctx->mb_lmax; | |
| 228 | + mpv->mb_num = (avctx->width * avctx->height + 255) / 256; // For ratecontrol | |
| 229 | + | |
| 230 | + mpv->me.temp = | |
| 231 | + mpv->me.scratchpad = av_calloc(avctx->width + 64, 2*16*2*sizeof(uint8_t)); | |
| 232 | + mpv->sc.obmc_scratchpad= av_mallocz(MB_SIZE*MB_SIZE*12*sizeof(uint32_t)); | |
| 233 | + mpv->me.map = av_mallocz(2 * ME_MAP_SIZE * sizeof(*mpv->me.map)); | |
| 234 | + if (!mpv->me.scratchpad || !mpv->me.map || !mpv->sc.obmc_scratchpad) | |
| 204 | 235 | return AVERROR(ENOMEM); |
| 205 | − s->m.me.score_map = s->m.me.map + ME_MAP_SIZE; | |
| 236 | + mpv->me.score_map = mpv->me.map + ME_MAP_SIZE; | |
| 206 | 237 | |
| 207 | − ff_h263_encode_init(&s->m); //mv_penalty | |
| 238 | + ff_h263_encode_init(mpv); //mv_penalty | |
| 208 | 239 | |
| 209 | 240 | s->max_ref_frames = av_clip(avctx->refs, 1, MAX_REF_FRAMES); |
| 210 | 241 | |
| @@ -216,11 +247,11 @@ static av_cold int encode_init(AVCodecContext *avctx) · 5 unmodified lines | ||
| 216 | 247 | return AVERROR(ENOMEM); |
| 217 | 248 | } |
| 218 | 249 | if((avctx->flags&AV_CODEC_FLAG_PASS2) || !(avctx->flags&AV_CODEC_FLAG_QSCALE)){ |
| 219 | − ret = ff_rate_control_init(&s->m); | |
| 250 | + ret = ff_rate_control_init(mpv); | |
| 220 | 251 | if(ret < 0) |
| 221 | 252 | return ret; |
| 222 | 253 | } |
| 223 | − s->pass1_rc= !(avctx->flags & (AV_CODEC_FLAG_QSCALE|AV_CODEC_FLAG_PASS2)); | |
| 254 | + enc->pass1_rc = !(avctx->flags & (AV_CODEC_FLAG_QSCALE|AV_CODEC_FLAG_PASS2)); | |
| 224 | 255 | |
| 225 | 256 | switch(avctx->pix_fmt){ |
| 226 | 257 | case AV_PIX_FMT_YUV444P: |
| @@ -245,8 +276,8 @@ static av_cold int encode_init(AVCodecContext *avctx) · 18 unmodified lines | ||
| 245 | 276 | if (ret) |
| 246 | 277 | return ret; |
| 247 | 278 | |
| 248 | − ret = ff_set_cmp(&s->mecc, s->mecc.me_cmp, s->avctx->me_cmp); | |
| 249 | − ret |= ff_set_cmp(&s->mecc, s->mecc.me_sub_cmp, s->avctx->me_sub_cmp); | |
| 279 | + ret = ff_set_cmp(&enc->mecc, enc->mecc.me_cmp, s->avctx->me_cmp); | |
| 280 | + ret |= ff_set_cmp(&enc->mecc, enc->mecc.me_sub_cmp, s->avctx->me_sub_cmp); | |
| 250 | 281 | if (ret < 0) |
| 251 | 282 | return AVERROR(EINVAL); |
| 252 | 283 | |
| @@ -257,7 +288,7 @@ static av_cold int encode_init(AVCodecContext *avctx) · 4 unmodified lines | ||
| 257 | 288 | if ((ret = get_encode_buffer(s, s->input_picture)) < 0) |
| 258 | 289 | return ret; |
| 259 | 290 | |
| 260 | − if(s->motion_est == FF_ME_ITER){ | |
| 291 | + if (enc->motion_est == FF_ME_ITER) { | |
| 261 | 292 | int size= s->b_width * s->b_height << 2*s->block_max_depth; |
| 262 | 293 | for(i=0; i<s->max_ref_frames; i++){ |
| 263 | 294 | s->ref_mvs[i] = av_calloc(size, sizeof(*s->ref_mvs[i])); |
| @@ -335,7 +366,10 @@ static inline int get_penalty_factor(int lambda, int lambda2, int type){ · 71 unmodified lines | ||
| 335 | 366 | #define P_MV1 P[9] |
| 336 | 367 | #define FLAG_QPEL 1 //must be 1 |
| 337 | 368 | |
| 338 | −static int encode_q_branch(SnowContext *s, int level, int x, int y){ | |
| 369 | +static int encode_q_branch(SnowEncContext *enc, int level, int x, int y) | |
| 370 | +{ | |
| 371 | + SnowContext *const s = &enc->com; | |
| 372 | + MotionEstContext *const c = &enc->m.me; | |
| 339 | 373 | uint8_t p_buffer[1024]; |
| 340 | 374 | uint8_t i_buffer[1024]; |
| 341 | 375 | uint8_t p_state[sizeof(s->block_state)]; |
| @@ -372,7 +406,6 @@ static int encode_q_branch(SnowContext *s, int level, int x, int y){ · 30 unmodified lines | ||
| 372 | 406 | int16_t last_mv[3][2]; |
| 373 | 407 | int qpel= !!(s->avctx->flags & AV_CODEC_FLAG_QPEL); //unused |
| 374 | 408 | const int shift= 1+qpel; |
| 375 | − MotionEstContext *c= &s->m.me; | |
| 376 | 409 | int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref); |
| 377 | 410 | int mx_context= av_log2(2*FFABS(left->mx - top->mx)); |
| 378 | 411 | int my_context= av_log2(2*FFABS(left->my - top->my)); |
| @@ -401,18 +434,18 @@ static int encode_q_branch(SnowContext *s, int level, int x, int y){ · 22 unmodified lines | ||
| 401 | 434 | last_mv[2][0]= bottom->mx; |
| 402 | 435 | last_mv[2][1]= bottom->my; |
| 403 | 436 | |
| 404 | − s->m.mb_stride=2; | |
| 405 | − s->m.mb_x= | |
| 406 | − s->m.mb_y= 0; | |
| 437 | + enc->m.mb_stride = 2; | |
| 438 | + enc->m.mb_x = | |
| 439 | + enc->m.mb_y = 0; | |
| 407 | 440 | c->skip= 0; |
| 408 | 441 | |
| 409 | 442 | av_assert1(c-> stride == stride); |
| 410 | 443 | av_assert1(c->uvstride == uvstride); |
| 411 | 444 | |
| 412 | − c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp); | |
| 413 | − c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp); | |
| 414 | − c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp); | |
| 415 | − c->current_mv_penalty= c->mv_penalty[s->m.f_code=1] + MAX_DMV; | |
| 445 | + c->penalty_factor = get_penalty_factor(enc->lambda, enc->lambda2, c->avctx->me_cmp); | |
| 446 | + c->sub_penalty_factor= get_penalty_factor(enc->lambda, enc->lambda2, c->avctx->me_sub_cmp); | |
| 447 | + c->mb_penalty_factor = get_penalty_factor(enc->lambda, enc->lambda2, c->avctx->mb_cmp); | |
| 448 | + c->current_mv_penalty = c->mv_penalty[enc->m.f_code=1] + MAX_DMV; | |
| 416 | 449 | |
| 417 | 450 | c->xmin = - x*block_w - 16+3; |
| 418 | 451 | c->ymin = - y*block_w - 16+3; |
| @@ -443,7 +476,7 @@ static int encode_q_branch(SnowContext *s, int level, int x, int y){ · 24 unmodified lines | ||
| 443 | 476 | for(ref=0; ref<s->ref_frames; ref++){ |
| 444 | 477 | init_ref(c, current_data, s->last_picture[ref]->data, NULL, block_w*x, block_w*y, 0); |
| 445 | 478 | |
| 446 | − ref_score= ff_epzs_motion_search(&s->m, &ref_mx, &ref_my, P, 0, /*ref_index*/ 0, last_mv, | |
| 479 | + ref_score= ff_epzs_motion_search(&enc->m, &ref_mx, &ref_my, P, 0, /*ref_index*/ 0, last_mv, | |
| 447 | 480 | (1<<16)>>shift, level-LOG2_MB_SIZE+4, block_w); |
| 448 | 481 | |
| 449 | 482 | av_assert2(ref_mx >= c->xmin); |
| @@ -451,8 +484,8 @@ static int encode_q_branch(SnowContext *s, int level, int x, int y){ · 1 unmodified line | ||
| 451 | 484 | av_assert2(ref_my >= c->ymin); |
| 452 | 485 | av_assert2(ref_my <= c->ymax); |
| 453 | 486 | |
| 454 | − ref_score= c->sub_motion_search(&s->m, &ref_mx, &ref_my, ref_score, 0, 0, level-LOG2_MB_SIZE+4, block_w); | |
| 455 | − ref_score= ff_get_mb_score(&s->m, ref_mx, ref_my, 0, 0, level-LOG2_MB_SIZE+4, block_w, 0); | |
| 487 | + ref_score= c->sub_motion_search(&enc->m, &ref_mx, &ref_my, ref_score, 0, 0, level-LOG2_MB_SIZE+4, block_w); | |
| 488 | + ref_score= ff_get_mb_score(&enc->m, ref_mx, ref_my, 0, 0, level-LOG2_MB_SIZE+4, block_w, 0); | |
| 456 | 489 | ref_score+= 2*av_log2(2*ref)*c->penalty_factor; |
| 457 | 490 | if(s->ref_mvs[ref]){ |
| 458 | 491 | s->ref_mvs[ref][index][0]= ref_mx; |
| @@ -484,7 +517,7 @@ static int encode_q_branch(SnowContext *s, int level, int x, int y){ · 25 unmodified lines | ||
| 484 | 517 | put_symbol(&pc, &p_state[128 + 32*(mx_context + 16*!!best_ref)], mx - pmx, 1); |
| 485 | 518 | put_symbol(&pc, &p_state[128 + 32*(my_context + 16*!!best_ref)], my - pmy, 1); |
| 486 | 519 | p_len= pc.bytestream - pc.bytestream_start; |
| 487 | − score += (s->lambda2*(get_rac_count(&pc)-base_bits))>>FF_LAMBDA_SHIFT; | |
| 520 | + score += (enc->lambda2*(get_rac_count(&pc)-base_bits))>>FF_LAMBDA_SHIFT; | |
| 488 | 521 | |
| 489 | 522 | block_s= block_w*block_w; |
| 490 | 523 | sum = pix_sum(current_data[0], stride, block_w, block_w); |
| @@ -515,9 +548,9 @@ static int encode_q_branch(SnowContext *s, int level, int x, int y){ · 24 unmodified lines | ||
| 515 | 548 | put_symbol(&ic, &i_state[96], cr-pcr, 1); |
| 516 | 549 | } |
| 517 | 550 | i_len= ic.bytestream - ic.bytestream_start; |
| 518 | − iscore += (s->lambda2*(get_rac_count(&ic)-base_bits))>>FF_LAMBDA_SHIFT; | |
| 551 | + iscore += (enc->lambda2*(get_rac_count(&ic)-base_bits))>>FF_LAMBDA_SHIFT; | |
| 519 | 552 | |
| 520 | − av_assert1(iscore < 255*255*256 + s->lambda2*10); | |
| 553 | + av_assert1(iscore < 255*255*256 + enc->lambda2*10); | |
| 521 | 554 | av_assert1(iscore >= 0); |
| 522 | 555 | av_assert1(l>=0 && l<=255); |
| 523 | 556 | av_assert1(pl>=0 && pl<=255); |
| @@ -528,16 +561,16 @@ static int encode_q_branch(SnowContext *s, int level, int x, int y){ · 4 unmodified lines | ||
| 528 | 561 | if (vard <= 64 || vard < varc) |
| 529 | 562 | c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); |
| 530 | 563 | else |
| 531 | − c->scene_change_score+= s->m.qscale; | |
| 564 | + c->scene_change_score += enc->m.qscale; | |
| 532 | 565 | } |
| 533 | 566 | |
| 534 | 567 | if(level!=s->block_max_depth){ |
| 535 | 568 | put_rac(&s->c, &s->block_state[4 + s_context], 0); |
| 536 | − score2 = encode_q_branch(s, level+1, 2*x+0, 2*y+0); | |
| 537 | − score2+= encode_q_branch(s, level+1, 2*x+1, 2*y+0); | |
| 538 | − score2+= encode_q_branch(s, level+1, 2*x+0, 2*y+1); | |
| 539 | − score2+= encode_q_branch(s, level+1, 2*x+1, 2*y+1); | |
| 540 | − score2+= s->lambda2>>FF_LAMBDA_SHIFT; //FIXME exact split overhead | |
| 569 | + score2 = encode_q_branch(enc, level+1, 2*x+0, 2*y+0); | |
| 570 | + score2+= encode_q_branch(enc, level+1, 2*x+1, 2*y+0); | |
| 571 | + score2+= encode_q_branch(enc, level+1, 2*x+0, 2*y+1); | |
| 572 | + score2+= encode_q_branch(enc, level+1, 2*x+1, 2*y+1); | |
| 573 | + score2+= enc->lambda2>>FF_LAMBDA_SHIFT; //FIXME exact split overhead | |
| 541 | 574 | |
| 542 | 575 | if(score2 < score && score2 < iscore) |
| 543 | 576 | return score2; |
| @@ -619,7 +652,9 @@ static void encode_q_branch2(SnowContext *s, int level, int x, int y){ · 75 unmodified lines | ||
| 619 | 652 | } |
| 620 | 653 | } |
| 621 | 654 | |
| 622 | −static int get_dc(SnowContext *s, int mb_x, int mb_y, int plane_index){ | |
| 655 | +static int get_dc(SnowEncContext *enc, int mb_x, int mb_y, int plane_index) | |
| 656 | +{ | |
| 657 | + SnowContext *const s = &enc->com; | |
| 623 | 658 | int i, x2, y2; |
| 624 | 659 | Plane *p= &s->plane[plane_index]; |
| 625 | 660 | const int block_size = MB_SIZE >> s->block_max_depth; |
| @@ -629,7 +664,7 @@ static int get_dc(SnowContext *s, int mb_x, int mb_y, int plane_index){ · 3 unmodified lines | ||
| 629 | 664 | const int obmc_stride= plane_index ? (2*block_size)>>s->chroma_h_shift : 2*block_size; |
| 630 | 665 | const int ref_stride= s->current_picture->linesize[plane_index]; |
| 631 | 666 | const uint8_t *src = s->input_picture->data[plane_index]; |
| 632 | − IDWTELEM *dst= (IDWTELEM*)s->m.sc.obmc_scratchpad + plane_index*block_size*block_size*4; //FIXME change to unsigned | |
| 667 | + IDWTELEM *dst= (IDWTELEM*)enc->m.sc.obmc_scratchpad + plane_index*block_size*block_size*4; //FIXME change to unsigned | |
| 633 | 668 | const int b_stride = s->b_width << s->block_max_depth; |
| 634 | 669 | const int w= p->width; |
| 635 | 670 | const int h= p->height; |
| @@ -715,7 +750,10 @@ static inline int get_block_bits(SnowContext *s, int x, int y, int w){ · 79 unmodified lines | ||
| 715 | 750 | } |
| 716 | 751 | } |
| 717 | 752 | |
| 718 | −static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, uint8_t (*obmc_edged)[MB_SIZE * 2]){ | |
| 753 | +static int get_block_rd(SnowEncContext *enc, int mb_x, int mb_y, | |
| 754 | + int plane_index, uint8_t (*obmc_edged)[MB_SIZE * 2]) | |
| 755 | +{ | |
| 756 | + SnowContext *const s = &enc->com; | |
| 719 | 757 | Plane *p= &s->plane[plane_index]; |
| 720 | 758 | const int block_size = MB_SIZE >> s->block_max_depth; |
| 721 | 759 | const int block_w = plane_index ? block_size>>s->chroma_h_shift : block_size; |
| @@ -724,7 +762,7 @@ static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, uin · 2 unmodified lines | ||
| 724 | 762 | const int ref_stride= s->current_picture->linesize[plane_index]; |
| 725 | 763 | uint8_t *dst= s->current_picture->data[plane_index]; |
| 726 | 764 | const uint8_t *src = s->input_picture->data[plane_index]; |
| 727 | − IDWTELEM *pred= (IDWTELEM*)s->m.sc.obmc_scratchpad + plane_index*block_size*block_size*4; | |
| 765 | + IDWTELEM *pred= (IDWTELEM*)enc->m.sc.obmc_scratchpad + plane_index*block_size*block_size*4; | |
| 728 | 766 | uint8_t *cur = s->scratchbuf; |
| 729 | 767 | uint8_t *tmp = s->emu_edge_buffer; |
| 730 | 768 | const int b_stride = s->b_width << s->block_max_depth; |
| @@ -733,7 +771,7 @@ static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, uin · 2 unmodified lines | ||
| 733 | 771 | const int h= p->height; |
| 734 | 772 | int distortion; |
| 735 | 773 | int rate= 0; |
| 736 | − const int penalty_factor= get_penalty_factor(s->lambda, s->lambda2, s->avctx->me_cmp); | |
| 774 | + const int penalty_factor = get_penalty_factor(enc->lambda, enc->lambda2, s->avctx->me_cmp); | |
| 737 | 775 | int sx= block_w*mb_x - block_w/2; |
| 738 | 776 | int sy= block_h*mb_y - block_h/2; |
| 739 | 777 | int x0= FFMAX(0,-sx); |
| @@ -787,19 +825,19 @@ static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, uin · 47 unmodified lines | ||
| 787 | 825 | * to improve the score of the whole frame, thus iterative motion |
| 788 | 826 | * estimation does not always converge. */ |
| 789 | 827 | if(s->avctx->me_cmp == FF_CMP_W97) |
| 790 | − distortion = ff_w97_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); | |
| 828 | + distortion = ff_w97_32_c(&enc->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); | |
| 791 | 829 | else if(s->avctx->me_cmp == FF_CMP_W53) |
| 792 | − distortion = ff_w53_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); | |
| 830 | + distortion = ff_w53_32_c(&enc->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); | |
| 793 | 831 | else{ |
| 794 | 832 | distortion = 0; |
| 795 | 833 | for(i=0; i<4; i++){ |
| 796 | 834 | int off = sx+16*(i&1) + (sy+16*(i>>1))*ref_stride; |
| 797 | − distortion += s->mecc.me_cmp[0](&s->m, src + off, dst + off, ref_stride, 16); | |
| 835 | + distortion += enc->mecc.me_cmp[0](&enc->m, src + off, dst + off, ref_stride, 16); | |
| 798 | 836 | } |
| 799 | 837 | } |
| 800 | 838 | }else{ |
| 801 | 839 | av_assert2(block_w==8); |
| 802 | − distortion = s->mecc.me_cmp[0](&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, block_w*2); | |
| 840 | + distortion = enc->mecc.me_cmp[0](&enc->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, block_w*2); | |
| 803 | 841 | } |
| 804 | 842 | |
| 805 | 843 | if(plane_index==0){ |
| @@ -816,7 +854,9 @@ static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, uin · 10 unmodified lines | ||
| 816 | 854 | return distortion + rate*penalty_factor; |
| 817 | 855 | } |
| 818 | 856 | |
| 819 | −static int get_4block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index){ | |
| 857 | +static int get_4block_rd(SnowEncContext *enc, int mb_x, int mb_y, int plane_index) | |
| 858 | +{ | |
| 859 | + SnowContext *const s = &enc->com; | |
| 820 | 860 | int i, y2; |
| 821 | 861 | Plane *p= &s->plane[plane_index]; |
| 822 | 862 | const int block_size = MB_SIZE >> s->block_max_depth; |
| @@ -835,7 +875,7 @@ static int get_4block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index){ · 12 unmodified lines | ||
| 835 | 875 | const int h= p->height; |
| 836 | 876 | int distortion= 0; |
| 837 | 877 | int rate= 0; |
| 838 | − const int penalty_factor= get_penalty_factor(s->lambda, s->lambda2, s->avctx->me_cmp); | |
| 878 | + const int penalty_factor= get_penalty_factor(enc->lambda, enc->lambda2, s->avctx->me_cmp); | |
| 839 | 879 | |
| 840 | 880 | av_assert2(s->chroma_h_shift == s->chroma_v_shift); //obmc and square assumtions below |
| 841 | 881 | |
| @@ -863,7 +903,7 @@ static int get_4block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index){ · 21 unmodified lines | ||
| 863 | 903 | } |
| 864 | 904 | |
| 865 | 905 | av_assert1(block_w== 8 || block_w==16); |
| 866 | − distortion += s->mecc.me_cmp[block_w==8](&s->m, src + x + y*ref_stride, dst + x + y*ref_stride, ref_stride, block_h); | |
| 906 | + distortion += enc->mecc.me_cmp[block_w==8](&enc->m, src + x + y*ref_stride, dst + x + y*ref_stride, ref_stride, block_h); | |
| 867 | 907 | } |
| 868 | 908 | |
| 869 | 909 | if(plane_index==0){ |
| @@ -1012,9 +1052,10 @@ static int encode_subband(SnowContext *s, SubBand *b, const IDWTELEM *src, const · 142 unmodified lines | ||
| 1012 | 1052 | // encode_subband_dzr(s, b, src, parent, stride, orientation); |
| 1013 | 1053 | } |
| 1014 | 1054 | |
| 1015 | −static av_always_inline int check_block_intra(SnowContext *s, int mb_x, int mb_y, int p[3], | |
| 1055 | +static av_always_inline int check_block_intra(SnowEncContext *enc, int mb_x, int mb_y, int p[3], | |
| 1016 | 1056 | uint8_t (*obmc_edged)[MB_SIZE * 2], int *best_rd) |
| 1017 | 1057 | { |
| 1058 | + SnowContext *const s = &enc->com; | |
| 1018 | 1059 | const int b_stride= s->b_width << s->block_max_depth; |
| 1019 | 1060 | BlockNode *block= &s->block[mb_x + mb_y * b_stride]; |
| 1020 | 1061 | BlockNode backup= *block; |
| @@ -1028,7 +1069,7 @@ static av_always_inline int check_block_intra(SnowContext *s, int mb_x, int mb_y · 7 unmodified lines | ||
| 1028 | 1069 | block->color[2] = p[2]; |
| 1029 | 1070 | block->type |= BLOCK_INTRA; |
| 1030 | 1071 | |
| 1031 | − rd = get_block_rd(s, mb_x, mb_y, 0, obmc_edged) + s->intra_penalty; | |
| 1072 | + rd = get_block_rd(enc, mb_x, mb_y, 0, obmc_edged) + enc->intra_penalty; | |
| 1032 | 1073 | |
| 1033 | 1074 | //FIXME chroma |
| 1034 | 1075 | if(rd < *best_rd){ |
| @@ -1042,7 +1083,11 @@ static av_always_inline int check_block_intra(SnowContext *s, int mb_x, int mb_y · 7 unmodified lines | ||
| 1042 | 1083 | |
| 1043 | 1084 | /* special case for int[2] args we discard afterwards, |
| 1044 | 1085 | * fixes compilation problem with gcc 2.95 */ |
| 1045 | −static av_always_inline int check_block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, uint8_t (*obmc_edged)[MB_SIZE * 2], int *best_rd){ | |
| 1086 | +static av_always_inline int check_block_inter(SnowEncContext *enc, | |
| 1087 | + int mb_x, int mb_y, int p0, int p1, | |
| 1088 | + uint8_t (*obmc_edged)[MB_SIZE * 2], int *best_rd) | |
| 1089 | +{ | |
| 1090 | + SnowContext *const s = &enc->com; | |
| 1046 | 1091 | const int b_stride = s->b_width << s->block_max_depth; |
| 1047 | 1092 | BlockNode *block = &s->block[mb_x + mb_y * b_stride]; |
| 1048 | 1093 | BlockNode backup = *block; |
| @@ -1053,16 +1098,16 @@ static av_always_inline int check_block_inter(SnowContext *s, int mb_x, int mb_y · 4 unmodified lines | ||
| 1053 | 1098 | av_assert2(mb_x < b_stride); |
| 1054 | 1099 | |
| 1055 | 1100 | index = (p0 + 31 * p1) & (ME_CACHE_SIZE-1); |
| 1056 | − value = s->me_cache_generation + (p0 >> 10) + p1 * (1 << 6) + (block->ref << 12); | |
| 1057 | − if (s->me_cache[index] == value) | |
| 1101 | + value = enc->me_cache_generation + (p0 >> 10) + p1 * (1 << 6) + (block->ref << 12); | |
| 1102 | + if (enc->me_cache[index] == value) | |
| 1058 | 1103 | return 0; |
| 1059 | − s->me_cache[index] = value; | |
| 1104 | + enc->me_cache[index] = value; | |
| 1060 | 1105 | |
| 1061 | 1106 | block->mx = p0; |
| 1062 | 1107 | block->my = p1; |
| 1063 | 1108 | block->type &= ~BLOCK_INTRA; |
| 1064 | 1109 | |
| 1065 | − rd = get_block_rd(s, mb_x, mb_y, 0, obmc_edged); | |
| 1110 | + rd = get_block_rd(enc, mb_x, mb_y, 0, obmc_edged); | |
| 1066 | 1111 | |
| 1067 | 1112 | //FIXME chroma |
| 1068 | 1113 | if (rd < *best_rd) { |
| @@ -1074,7 +1119,10 @@ static av_always_inline int check_block_inter(SnowContext *s, int mb_x, int mb_y · 5 unmodified lines | ||
| 1074 | 1119 | } |
| 1075 | 1120 | } |
| 1076 | 1121 | |
| 1077 | −static av_always_inline int check_4block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, int ref, int *best_rd){ | |
| 1122 | +static av_always_inline int check_4block_inter(SnowEncContext *enc, int mb_x, int mb_y, | |
| 1123 | + int p0, int p1, int ref, int *best_rd) | |
| 1124 | +{ | |
| 1125 | + SnowContext *const s = &enc->com; | |
| 1078 | 1126 | const int b_stride= s->b_width << s->block_max_depth; |
| 1079 | 1127 | BlockNode *block= &s->block[mb_x + mb_y * b_stride]; |
| 1080 | 1128 | BlockNode backup[4]; |
| @@ -1094,10 +1142,10 @@ static av_always_inline int check_4block_inter(SnowContext *s, int mb_x, int mb_ · 13 unmodified lines | ||
| 1094 | 1142 | av_assert2(((mb_x|mb_y)&1) == 0); |
| 1095 | 1143 | |
| 1096 | 1144 | index= (p0 + 31*p1) & (ME_CACHE_SIZE-1); |
| 1097 | − value= s->me_cache_generation + (p0>>10) + (p1<<6) + (block->ref<<12); | |
| 1098 | − if(s->me_cache[index] == value) | |
| 1145 | + value = enc->me_cache_generation + (p0>>10) + (p1<<6) + (block->ref<<12); | |
| 1146 | + if (enc->me_cache[index] == value) | |
| 1099 | 1147 | return 0; |
| 1100 | − s->me_cache[index]= value; | |
| 1148 | + enc->me_cache[index] = value; | |
| 1101 | 1149 | |
| 1102 | 1150 | block->mx= p0; |
| 1103 | 1151 | block->my= p1; |
| @@ -1105,7 +1153,7 @@ static av_always_inline int check_4block_inter(SnowContext *s, int mb_x, int mb_ · 1 unmodified line | ||
| 1105 | 1153 | block->type &= ~BLOCK_INTRA; |
| 1106 | 1154 | block[1]= block[b_stride]= block[b_stride+1]= *block; |
| 1107 | 1155 | |
| 1108 | − rd= get_4block_rd(s, mb_x, mb_y, 0); | |
| 1156 | + rd = get_4block_rd(enc, mb_x, mb_y, 0); | |
| 1109 | 1157 | |
| 1110 | 1158 | //FIXME chroma |
| 1111 | 1159 | if(rd < *best_rd){ |
| @@ -1120,7 +1168,9 @@ static av_always_inline int check_4block_inter(SnowContext *s, int mb_x, int mb_ · 8 unmodified lines | ||
| 1120 | 1168 | } |
| 1121 | 1169 | } |
| 1122 | 1170 | |
| 1123 | −static void iterative_me(SnowContext *s){ | |
| 1171 | +static void iterative_me(SnowEncContext *enc) | |
| 1172 | +{ | |
| 1173 | + SnowContext *const s = &enc->com; | |
| 1124 | 1174 | int pass, mb_x, mb_y; |
| 1125 | 1175 | const int b_width = s->b_width << s->block_max_depth; |
| 1126 | 1176 | const int b_height= s->b_height << s->block_max_depth; |
| @@ -1133,7 +1183,7 @@ static void iterative_me(SnowContext *s){ · 6 unmodified lines | ||
| 1133 | 1183 | memcpy(state, s->block_state, sizeof(s->block_state)); |
| 1134 | 1184 | for(mb_y= 0; mb_y<s->b_height; mb_y++) |
| 1135 | 1185 | for(mb_x= 0; mb_x<s->b_width; mb_x++) |
| 1136 | − encode_q_branch(s, 0, mb_x, mb_y); | |
| 1186 | + encode_q_branch(enc, 0, mb_x, mb_y); | |
| 1137 | 1187 | s->c = r; |
| 1138 | 1188 | memcpy(s->block_state, state, sizeof(s->block_state)); |
| 1139 | 1189 | } |
| @@ -1165,9 +1215,9 @@ static void iterative_me(SnowContext *s){ · 25 unmodified lines | ||
| 1165 | 1215 | |
| 1166 | 1216 | backup= *block; |
| 1167 | 1217 | |
| 1168 | − if(!s->me_cache_generation) | |
| 1169 | − memset(s->me_cache, 0, sizeof(s->me_cache)); | |
| 1170 | − s->me_cache_generation += 1<<22; | |
| 1218 | + if (!enc->me_cache_generation) | |
| 1219 | + memset(enc->me_cache, 0, sizeof(enc->me_cache)); | |
| 1220 | + enc->me_cache_generation += 1<<22; | |
| 1171 | 1221 | |
| 1172 | 1222 | //FIXME precalculate |
| 1173 | 1223 | { |
| @@ -1223,14 +1273,14 @@ static void iterative_me(SnowContext *s){ · 49 unmodified lines | ||
| 1223 | 1273 | |
| 1224 | 1274 | // intra(black) = neighbors' contribution to the current block |
| 1225 | 1275 | for(i=0; i < s->nb_planes; i++) |
| 1226 | − color[i]= get_dc(s, mb_x, mb_y, i); | |
| 1276 | + color[i]= get_dc(enc, mb_x, mb_y, i); | |
| 1227 | 1277 | |
| 1228 | 1278 | // get previous score (cannot be cached due to OBMC) |
| 1229 | 1279 | if(pass > 0 && (block->type&BLOCK_INTRA)){ |
| 1230 | 1280 | int color0[3]= {block->color[0], block->color[1], block->color[2]}; |
| 1231 | − check_block_intra(s, mb_x, mb_y, color0, obmc_edged, &best_rd); | |
| 1281 | + check_block_intra(enc, mb_x, mb_y, color0, obmc_edged, &best_rd); | |
| 1232 | 1282 | }else |
| 1233 | − check_block_inter(s, mb_x, mb_y, block->mx, block->my, obmc_edged, &best_rd); | |
| 1283 | + check_block_inter(enc, mb_x, mb_y, block->mx, block->my, obmc_edged, &best_rd); | |
| 1234 | 1284 | |
| 1235 | 1285 | ref_b= *block; |
| 1236 | 1286 | ref_rd= best_rd; |
| @@ -1241,30 +1291,30 @@ static void iterative_me(SnowContext *s){ · 4 unmodified lines | ||
| 1241 | 1291 | block->ref= ref; |
| 1242 | 1292 | best_rd= INT_MAX; |
| 1243 | 1293 | |
| 1244 | − check_block_inter(s, mb_x, mb_y, mvr[0][0], mvr[0][1], obmc_edged, &best_rd); | |
| 1245 | − check_block_inter(s, mb_x, mb_y, 0, 0, obmc_edged, &best_rd); | |
| 1294 | + check_block_inter(enc, mb_x, mb_y, mvr[0][0], mvr[0][1], obmc_edged, &best_rd); | |
| 1295 | + check_block_inter(enc, mb_x, mb_y, 0, 0, obmc_edged, &best_rd); | |
| 1246 | 1296 | if(tb) |
| 1247 | − check_block_inter(s, mb_x, mb_y, mvr[-b_stride][0], mvr[-b_stride][1], obmc_edged, &best_rd); | |
| 1297 | + check_block_inter(enc, mb_x, mb_y, mvr[-b_stride][0], mvr[-b_stride][1], obmc_edged, &best_rd); | |
| 1248 | 1298 | if(lb) |
| 1249 | − check_block_inter(s, mb_x, mb_y, mvr[-1][0], mvr[-1][1], obmc_edged, &best_rd); | |
| 1299 | + check_block_inter(enc, mb_x, mb_y, mvr[-1][0], mvr[-1][1], obmc_edged, &best_rd); | |
| 1250 | 1300 | if(rb) |
| 1251 | − check_block_inter(s, mb_x, mb_y, mvr[1][0], mvr[1][1], obmc_edged, &best_rd); | |
| 1301 | + check_block_inter(enc, mb_x, mb_y, mvr[1][0], mvr[1][1], obmc_edged, &best_rd); | |
| 1252 | 1302 | if(bb) |
| 1253 | − check_block_inter(s, mb_x, mb_y, mvr[b_stride][0], mvr[b_stride][1], obmc_edged, &best_rd); | |
| 1303 | + check_block_inter(enc, mb_x, mb_y, mvr[b_stride][0], mvr[b_stride][1], obmc_edged, &best_rd); | |
| 1254 | 1304 | |
| 1255 | 1305 | /* fullpel ME */ |
| 1256 | 1306 | //FIXME avoid subpel interpolation / round to nearest integer |
| 1257 | 1307 | do{ |
| 1258 | 1308 | int newx = block->mx; |
| 1259 | 1309 | int newy = block->my; |
| 1260 | − int dia_size = s->iterative_dia_size ? s->iterative_dia_size : FFMAX(s->avctx->dia_size, 1); | |
| 1310 | + int dia_size = enc->iterative_dia_size ? enc->iterative_dia_size : FFMAX(s->avctx->dia_size, 1); | |
| 1261 | 1311 | dia_change=0; |
| 1262 | 1312 | for(i=0; i < dia_size; i++){ |
| 1263 | 1313 | for(j=0; j<i; j++){ |
| 1264 | − dia_change |= check_block_inter(s, mb_x, mb_y, newx+4*(i-j), newy+(4*j), obmc_edged, &best_rd); | |
| 1265 | − dia_change |= check_block_inter(s, mb_x, mb_y, newx-4*(i-j), newy-(4*j), obmc_edged, &best_rd); | |
| 1266 | − dia_change |= check_block_inter(s, mb_x, mb_y, newx-(4*j), newy+4*(i-j), obmc_edged, &best_rd); | |
| 1267 | − dia_change |= check_block_inter(s, mb_x, mb_y, newx+(4*j), newy-4*(i-j), obmc_edged, &best_rd); | |
| 1314 | + dia_change |= check_block_inter(enc, mb_x, mb_y, newx+4*(i-j), newy+(4*j), obmc_edged, &best_rd); | |
| 1315 | + dia_change |= check_block_inter(enc, mb_x, mb_y, newx-4*(i-j), newy-(4*j), obmc_edged, &best_rd); | |
| 1316 | + dia_change |= check_block_inter(enc, mb_x, mb_y, newx-(4*j), newy+4*(i-j), obmc_edged, &best_rd); | |
| 1317 | + dia_change |= check_block_inter(enc, mb_x, mb_y, newx+(4*j), newy-4*(i-j), obmc_edged, &best_rd); | |
| 1268 | 1318 | } |
| 1269 | 1319 | } |
| 1270 | 1320 | }while(dia_change); |
| @@ -1273,7 +1323,7 @@ static void iterative_me(SnowContext *s){ · 2 unmodified lines | ||
| 1273 | 1323 | static const int square[8][2]= {{+1, 0},{-1, 0},{ 0,+1},{ 0,-1},{+1,+1},{-1,-1},{+1,-1},{-1,+1},}; |
| 1274 | 1324 | dia_change=0; |
| 1275 | 1325 | for(i=0; i<8; i++) |
| 1276 | − dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+square[i][0], block->my+square[i][1], obmc_edged, &best_rd); | |
| 1326 | + dia_change |= check_block_inter(enc, mb_x, mb_y, block->mx+square[i][0], block->my+square[i][1], obmc_edged, &best_rd); | |
| 1277 | 1327 | }while(dia_change); |
| 1278 | 1328 | //FIXME or try the standard 2 pass qpel or similar |
| 1279 | 1329 | |
| @@ -1286,7 +1336,7 @@ static void iterative_me(SnowContext *s){ · 6 unmodified lines | ||
| 1286 | 1336 | } |
| 1287 | 1337 | best_rd= ref_rd; |
| 1288 | 1338 | *block= ref_b; |
| 1289 | − check_block_intra(s, mb_x, mb_y, color, obmc_edged, &best_rd); | |
| 1339 | + check_block_intra(enc, mb_x, mb_y, color, obmc_edged, &best_rd); | |
| 1290 | 1340 | //FIXME RD style color selection |
| 1291 | 1341 | if(!same_block(block, &backup)){ |
| 1292 | 1342 | if(tb ) tb ->type &= ~BLOCK_OPT; |
| @@ -1324,20 +1374,20 @@ static void iterative_me(SnowContext *s){ · 31 unmodified lines | ||
| 1324 | 1374 | same_block(b[0], b[3])) |
| 1325 | 1375 | continue; |
| 1326 | 1376 | |
| 1327 | − if(!s->me_cache_generation) | |
| 1328 | − memset(s->me_cache, 0, sizeof(s->me_cache)); | |
| 1329 | − s->me_cache_generation += 1<<22; | |
| 1377 | + if (!enc->me_cache_generation) | |
| 1378 | + memset(enc->me_cache, 0, sizeof(enc->me_cache)); | |
| 1379 | + enc->me_cache_generation += 1<<22; | |
| 1330 | 1380 | |
| 1331 | − init_rd= best_rd= get_4block_rd(s, mb_x, mb_y, 0); | |
| 1381 | + init_rd = best_rd = get_4block_rd(enc, mb_x, mb_y, 0); | |
| 1332 | 1382 | |
| 1333 | 1383 | //FIXME more multiref search? |
| 1334 | − check_4block_inter(s, mb_x, mb_y, | |
| 1384 | + check_4block_inter(enc, mb_x, mb_y, | |
| 1335 | 1385 | (b[0]->mx + b[1]->mx + b[2]->mx + b[3]->mx + 2) >> 2, |
| 1336 | 1386 | (b[0]->my + b[1]->my + b[2]->my + b[3]->my + 2) >> 2, 0, &best_rd); |
| 1337 | 1387 | |
| 1338 | 1388 | for(i=0; i<4; i++) |
| 1339 | 1389 | if(!(b[i]->type&BLOCK_INTRA)) |
| 1340 | − check_4block_inter(s, mb_x, mb_y, b[i]->mx, b[i]->my, b[i]->ref, &best_rd); | |
| 1390 | + check_4block_inter(enc, mb_x, mb_y, b[i]->mx, b[i]->my, b[i]->ref, &best_rd); | |
| 1341 | 1391 | |
| 1342 | 1392 | if(init_rd != best_rd) |
| 1343 | 1393 | change++; |
| @@ -1347,13 +1397,15 @@ static void iterative_me(SnowContext *s){ · 3 unmodified lines | ||
| 1347 | 1397 | } |
| 1348 | 1398 | } |
| 1349 | 1399 | |
| 1350 | −static void encode_blocks(SnowContext *s, int search){ | |
| 1400 | +static void encode_blocks(SnowEncContext *enc, int search) | |
| 1401 | +{ | |
| 1402 | + SnowContext *const s = &enc->com; | |
| 1351 | 1403 | int x, y; |
| 1352 | 1404 | int w= s->b_width; |
| 1353 | 1405 | int h= s->b_height; |
| 1354 | 1406 | |
| 1355 | − if(s->motion_est == FF_ME_ITER && !s->keyframe && search) | |
| 1356 | − iterative_me(s); | |
| 1407 | + if (enc->motion_est == FF_ME_ITER && !s->keyframe && search) | |
| 1408 | + iterative_me(enc); | |
| 1357 | 1409 | |
| 1358 | 1410 | for(y=0; y<h; y++){ |
| 1359 | 1411 | if(s->c.bytestream_end - s->c.bytestream < w*MB_SIZE*MB_SIZE*3){ //FIXME nicer limit |
| @@ -1361,10 +1413,10 @@ static void encode_blocks(SnowContext *s, int search){ · 1 unmodified line | ||
| 1361 | 1413 | return; |
| 1362 | 1414 | } |
| 1363 | 1415 | for(x=0; x<w; x++){ |
| 1364 | − if(s->motion_est == FF_ME_ITER || !search) | |
| 1416 | + if (enc->motion_est == FF_ME_ITER || !search) | |
| 1365 | 1417 | encode_q_branch2(s, 0, x, y); |
| 1366 | 1418 | else |
| 1367 | − encode_q_branch (s, 0, x, y); | |
| 1419 | + encode_q_branch (enc, 0, x, y); | |
| 1368 | 1420 | } |
| 1369 | 1421 | } |
| 1370 | 1422 | } |
| @@ -1611,8 +1663,9 @@ static int qscale2qlog(int qscale){ · 240 unmodified lines | ||
| 1611 | 1663 | + 61*QROOT/8; ///< 64 > 60 |
| 1612 | 1664 | } |
| 1613 | 1665 | |
| 1614 | −static int ratecontrol_1pass(SnowContext *s, AVFrame *pict) | |
| 1666 | +static int ratecontrol_1pass(SnowEncContext *enc, AVFrame *pict) | |
| 1615 | 1667 | { |
| 1668 | + SnowContext *const s = &enc->com; | |
| 1616 | 1669 | /* Estimate the frame's complexity as a sum of weighted dwt coefficients. |
| 1617 | 1670 | * FIXME we know exact mv bits at this point, |
| 1618 | 1671 | * but ratecontrol isn't set up to include them. */ |
| @@ -1647,17 +1700,17 @@ static int ratecontrol_1pass(SnowContext *s, AVFrame *pict) · 28 unmodified lines | ||
| 1647 | 1700 | coef_sum = (uint64_t)coef_sum * coef_sum >> 16; |
| 1648 | 1701 | |
| 1649 | 1702 | if(pict->pict_type == AV_PICTURE_TYPE_I){ |
| 1650 | − s->m.mb_var_sum = coef_sum; | |
| 1651 | − s->m.mc_mb_var_sum = 0; | |
| 1703 | + enc->m.mb_var_sum = coef_sum; | |
| 1704 | + enc->m.mc_mb_var_sum = 0; | |
| 1652 | 1705 | }else{ |
| 1653 | − s->m.mc_mb_var_sum = coef_sum; | |
| 1654 | − s->m.mb_var_sum = 0; | |
| 1706 | + enc->m.mc_mb_var_sum = coef_sum; | |
| 1707 | + enc->m.mb_var_sum = 0; | |
| 1655 | 1708 | } |
| 1656 | 1709 | |
| 1657 | − pict->quality= ff_rate_estimate_qscale(&s->m, 1); | |
| 1710 | + pict->quality= ff_rate_estimate_qscale(&enc->m, 1); | |
| 1658 | 1711 | if (pict->quality < 0) |
| 1659 | 1712 | return INT_MIN; |
| 1660 | − s->lambda= pict->quality * 3/2; | |
| 1713 | + enc->lambda= pict->quality * 3/2; | |
| 1661 | 1714 | delta_qlog= qscale2qlog(pict->quality) - s->qlog; |
| 1662 | 1715 | s->qlog+= delta_qlog; |
| 1663 | 1716 | return delta_qlog; |
| @@ -1696,7 +1749,9 @@ static void calculate_visual_weight(SnowContext *s, Plane *p){ · 32 unmodified lines | ||
| 1696 | 1749 | static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
| 1697 | 1750 | const AVFrame *pict, int *got_packet) |
| 1698 | 1751 | { |
| 1699 | − SnowContext *s = avctx->priv_data; | |
| 1752 | + SnowEncContext *const enc = avctx->priv_data; | |
| 1753 | + SnowContext *const s = &enc->com; | |
| 1754 | + MpegEncContext *const mpv = &enc->m; | |
| 1700 | 1755 | RangeCoder * const c= &s->c; |
| 1701 | 1756 | AVCodecInternal *avci = avctx->internal; |
| 1702 | 1757 | AVFrame *pic; |
| @@ -1719,7 +1774,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 16 unmodified lines | ||
| 1719 | 1774 | memcpy(&s->input_picture->data[i][y * s->input_picture->linesize[i]], |
| 1720 | 1775 | &pict->data[i][y * pict->linesize[i]], |
| 1721 | 1776 | AV_CEIL_RSHIFT(width, hshift)); |
| 1722 | − s->mpvencdsp.draw_edges(s->input_picture->data[i], s->input_picture->linesize[i], | |
| 1777 | + enc->mpvencdsp.draw_edges(s->input_picture->data[i], s->input_picture->linesize[i], | |
| 1723 | 1778 | AV_CEIL_RSHIFT(width, hshift), AV_CEIL_RSHIFT(height, vshift), |
| 1724 | 1779 | EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift, |
| 1725 | 1780 | EDGE_TOP | EDGE_BOTTOM); |
| @@ -1730,45 +1785,45 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 4 unmodified lines | ||
| 1730 | 1785 | pic->pict_type = pict->pict_type; |
| 1731 | 1786 | pic->quality = pict->quality; |
| 1732 | 1787 | |
| 1733 | − s->m.picture_number= avctx->frame_num; | |
| 1788 | + mpv->picture_number = avctx->frame_num; | |
| 1734 | 1789 | if(avctx->flags&AV_CODEC_FLAG_PASS2){ |
| 1735 | − s->m.pict_type = pic->pict_type = s->m.rc_context.entry[avctx->frame_num].new_pict_type; | |
| 1790 | + mpv->pict_type = pic->pict_type = mpv->rc_context.entry[avctx->frame_num].new_pict_type; | |
| 1736 | 1791 | s->keyframe = pic->pict_type == AV_PICTURE_TYPE_I; |
| 1737 | 1792 | if(!(avctx->flags&AV_CODEC_FLAG_QSCALE)) { |
| 1738 | − pic->quality = ff_rate_estimate_qscale(&s->m, 0); | |
| 1793 | + pic->quality = ff_rate_estimate_qscale(mpv, 0); | |
| 1739 | 1794 | if (pic->quality < 0) |
| 1740 | 1795 | return -1; |
| 1741 | 1796 | } |
| 1742 | 1797 | }else{ |
| 1743 | 1798 | s->keyframe= avctx->gop_size==0 || avctx->frame_num % avctx->gop_size == 0; |
| 1744 | − s->m.pict_type = pic->pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; | |
| 1799 | + mpv->pict_type = pic->pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; | |
| 1745 | 1800 | } |
| 1746 | 1801 | |
| 1747 | − if(s->pass1_rc && avctx->frame_num == 0) | |
| 1802 | + if (enc->pass1_rc && avctx->frame_num == 0) | |
| 1748 | 1803 | pic->quality = 2*FF_QP2LAMBDA; |
| 1749 | 1804 | if (pic->quality) { |
| 1750 | 1805 | s->qlog = qscale2qlog(pic->quality); |
| 1751 | − s->lambda = pic->quality * 3/2; | |
| 1806 | + enc->lambda = pic->quality * 3/2; | |
| 1752 | 1807 | } |
| 1753 | 1808 | if (s->qlog < 0 || (!pic->quality && (avctx->flags & AV_CODEC_FLAG_QSCALE))) { |
| 1754 | 1809 | s->qlog= LOSSLESS_QLOG; |
| 1755 | − s->lambda = 0; | |
| 1810 | + enc->lambda = 0; | |
| 1756 | 1811 | }//else keep previous frame's qlog until after motion estimation |
| 1757 | 1812 | |
| 1758 | 1813 | if (s->current_picture->data[0]) { |
| 1759 | 1814 | int w = s->avctx->width; |
| 1760 | 1815 | int h = s->avctx->height; |
| 1761 | 1816 | |
| 1762 | − s->mpvencdsp.draw_edges(s->current_picture->data[0], | |
| 1763 | − s->current_picture->linesize[0], w , h , | |
| 1764 | − EDGE_WIDTH , EDGE_WIDTH , EDGE_TOP | EDGE_BOTTOM); | |
| 1817 | + enc->mpvencdsp.draw_edges(s->current_picture->data[0], | |
| 1818 | + s->current_picture->linesize[0], w , h , | |
| 1819 | + EDGE_WIDTH , EDGE_WIDTH , EDGE_TOP | EDGE_BOTTOM); | |
| 1765 | 1820 | if (s->current_picture->data[2]) { |
| 1766 | − s->mpvencdsp.draw_edges(s->current_picture->data[1], | |
| 1767 | − s->current_picture->linesize[1], w>>s->chroma_h_shift, h>>s->chroma_v_shift, | |
| 1768 | − EDGE_WIDTH>>s->chroma_h_shift, EDGE_WIDTH>>s->chroma_v_shift, EDGE_TOP | EDGE_BOTTOM); | |
| 1769 | − s->mpvencdsp.draw_edges(s->current_picture->data[2], | |
| 1770 | − s->current_picture->linesize[2], w>>s->chroma_h_shift, h>>s->chroma_v_shift, | |
| 1771 | − EDGE_WIDTH>>s->chroma_h_shift, EDGE_WIDTH>>s->chroma_v_shift, EDGE_TOP | EDGE_BOTTOM); | |
| 1821 | + enc->mpvencdsp.draw_edges(s->current_picture->data[1], | |
| 1822 | + s->current_picture->linesize[1], w>>s->chroma_h_shift, h>>s->chroma_v_shift, | |
| 1823 | + EDGE_WIDTH>>s->chroma_h_shift, EDGE_WIDTH>>s->chroma_v_shift, EDGE_TOP | EDGE_BOTTOM); | |
| 1824 | + enc->mpvencdsp.draw_edges(s->current_picture->data[2], | |
| 1825 | + s->current_picture->linesize[2], w>>s->chroma_h_shift, h>>s->chroma_v_shift, | |
| 1826 | + EDGE_WIDTH>>s->chroma_h_shift, EDGE_WIDTH>>s->chroma_v_shift, EDGE_TOP | EDGE_BOTTOM); | |
| 1772 | 1827 | } |
| 1773 | 1828 | emms_c(); |
| 1774 | 1829 | } |
| @@ -1778,9 +1833,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 3 unmodified lines | ||
| 1778 | 1833 | if (ret < 0) |
| 1779 | 1834 | return ret; |
| 1780 | 1835 | |
| 1781 | − s->m.current_picture_ptr= &s->m.current_picture; | |
| 1782 | − s->m.current_picture.f = s->current_picture; | |
| 1783 | − s->m.current_picture.f->pts = pict->pts; | |
| 1836 | + mpv->current_picture_ptr = &mpv->current_picture; | |
| 1837 | + mpv->current_picture.f = s->current_picture; | |
| 1838 | + mpv->current_picture.f->pts = pict->pts; | |
| 1784 | 1839 | if(pic->pict_type == AV_PICTURE_TYPE_P){ |
| 1785 | 1840 | int block_width = (width +15)>>4; |
| 1786 | 1841 | int block_height= (height+15)>>4; |
| @@ -1789,40 +1844,40 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 2 unmodified lines | ||
| 1789 | 1844 | av_assert0(s->current_picture->data[0]); |
| 1790 | 1845 | av_assert0(s->last_picture[0]->data[0]); |
| 1791 | 1846 | |
| 1792 | − s->m.avctx= s->avctx; | |
| 1793 | − s->m. last_picture.f = s->last_picture[0]; | |
| 1794 | − s->m. new_picture = s->input_picture; | |
| 1795 | − s->m. last_picture_ptr= &s->m. last_picture; | |
| 1796 | − s->m.linesize = stride; | |
| 1797 | − s->m.uvlinesize= s->current_picture->linesize[1]; | |
| 1798 | − s->m.width = width; | |
| 1799 | − s->m.height= height; | |
| 1800 | − s->m.mb_width = block_width; | |
| 1801 | − s->m.mb_height= block_height; | |
| 1802 | − s->m.mb_stride= s->m.mb_width+1; | |
| 1803 | − s->m.b8_stride= 2*s->m.mb_width+1; | |
| 1804 | − s->m.f_code=1; | |
| 1805 | − s->m.pict_type = pic->pict_type; | |
| 1806 | − s->m.motion_est= s->motion_est; | |
| 1807 | − s->m.me.scene_change_score=0; | |
| 1808 | − s->m.me.dia_size = avctx->dia_size; | |
| 1809 | − s->m.quarter_sample= (s->avctx->flags & AV_CODEC_FLAG_QPEL)!=0; | |
| 1810 | − s->m.out_format= FMT_H263; | |
| 1811 | − s->m.unrestricted_mv= 1; | |
| 1812 | − | |
| 1813 | − s->m.lambda = s->lambda; | |
| 1814 | − s->m.qscale= (s->m.lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); | |
| 1815 | − s->lambda2= s->m.lambda2= (s->m.lambda*s->m.lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT; | |
| 1816 | − | |
| 1817 | − s->m.mecc= s->mecc; //move | |
| 1818 | − s->m.qdsp= s->qdsp; //move | |
| 1819 | − s->m.hdsp = s->hdsp; | |
| 1820 | − ff_init_me(&s->m); | |
| 1821 | − s->hdsp = s->m.hdsp; | |
| 1822 | − s->mecc= s->m.mecc; | |
| 1823 | − } | |
| 1824 | − | |
| 1825 | − if(s->pass1_rc){ | |
| 1847 | + mpv->avctx = s->avctx; | |
| 1848 | + mpv->last_picture.f = s->last_picture[0]; | |
| 1849 | + mpv-> new_picture = s->input_picture; | |
| 1850 | + mpv->last_picture_ptr = &mpv->last_picture; | |
| 1851 | + mpv->linesize = stride; | |
| 1852 | + mpv->uvlinesize = s->current_picture->linesize[1]; | |
| 1853 | + mpv->width = width; | |
| 1854 | + mpv->height = height; | |
| 1855 | + mpv->mb_width = block_width; | |
| 1856 | + mpv->mb_height = block_height; | |
| 1857 | + mpv->mb_stride = mpv->mb_width + 1; | |
| 1858 | + mpv->b8_stride = 2 * mpv->mb_width + 1; | |
| 1859 | + mpv->f_code = 1; | |
| 1860 | + mpv->pict_type = pic->pict_type; | |
| 1861 | + mpv->motion_est = enc->motion_est; | |
| 1862 | + mpv->me.scene_change_score = 0; | |
| 1863 | + mpv->me.dia_size = avctx->dia_size; | |
| 1864 | + mpv->quarter_sample = (s->avctx->flags & AV_CODEC_FLAG_QPEL)!=0; | |
| 1865 | + mpv->out_format = FMT_H263; | |
| 1866 | + mpv->unrestricted_mv = 1; | |
| 1867 | + | |
| 1868 | + mpv->lambda = enc->lambda; | |
| 1869 | + mpv->qscale = (mpv->lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); | |
| 1870 | + enc->lambda2 = mpv->lambda2 = (mpv->lambda*mpv->lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT; | |
| 1871 | + | |
| 1872 | + mpv->mecc = enc->mecc; //move | |
| 1873 | + mpv->qdsp = enc->qdsp; //move | |
| 1874 | + mpv->hdsp = s->hdsp; | |
| 1875 | + ff_init_me(&enc->m); | |
| 1876 | + s->hdsp = mpv->hdsp; | |
| 1877 | + enc->mecc = mpv->mecc; | |
| 1878 | + } | |
| 1879 | + | |
| 1880 | + if (enc->pass1_rc) { | |
| 1826 | 1881 | memcpy(rc_header_bak, s->header_state, sizeof(s->header_state)); |
| 1827 | 1882 | memcpy(rc_block_bak, s->block_state, sizeof(s->block_state)); |
| 1828 | 1883 | } |
| @@ -1840,7 +1895,7 @@ redo_frame: · 11 unmodified lines | ||
| 1840 | 1895 | return AVERROR(EINVAL); |
| 1841 | 1896 | } |
| 1842 | 1897 | |
| 1843 | − s->m.pict_type = pic->pict_type; | |
| 1898 | + mpv->pict_type = pic->pict_type; | |
| 1844 | 1899 | s->qbias = pic->pict_type == AV_PICTURE_TYPE_P ? 2 : 0; |
| 1845 | 1900 | |
| 1846 | 1901 | ff_snow_common_init_after_header(avctx); |
| @@ -1852,9 +1907,9 @@ redo_frame: · 5 unmodified lines | ||
| 1852 | 1907 | } |
| 1853 | 1908 | |
| 1854 | 1909 | encode_header(s); |
| 1855 | − s->m.misc_bits = 8*(s->c.bytestream - s->c.bytestream_start); | |
| 1856 | − encode_blocks(s, 1); | |
| 1857 | − s->m.mv_bits = 8*(s->c.bytestream - s->c.bytestream_start) - s->m.misc_bits; | |
| 1910 | + mpv->misc_bits = 8 * (s->c.bytestream - s->c.bytestream_start); | |
| 1911 | + encode_blocks(enc, 1); | |
| 1912 | + mpv->mv_bits = 8 * (s->c.bytestream - s->c.bytestream_start) - mpv->misc_bits; | |
| 1858 | 1913 | |
| 1859 | 1914 | for(plane_index=0; plane_index < s->nb_planes; plane_index++){ |
| 1860 | 1915 | Plane *p= &s->plane[plane_index]; |
| @@ -1863,7 +1918,7 @@ redo_frame: · 2 unmodified lines | ||
| 1863 | 1918 | int x, y; |
| 1864 | 1919 | // int bits= put_bits_count(&s->c.pb); |
| 1865 | 1920 | |
| 1866 | − if (!s->memc_only) { | |
| 1921 | + if (!enc->memc_only) { | |
| 1867 | 1922 | //FIXME optimize |
| 1868 | 1923 | if(pict->data[plane_index]) //FIXME gray hack |
| 1869 | 1924 | for(y=0; y<h; y++){ |
| @@ -1876,7 +1931,7 @@ redo_frame: · 6 unmodified lines | ||
| 1876 | 1931 | if( plane_index==0 |
| 1877 | 1932 | && pic->pict_type == AV_PICTURE_TYPE_P |
| 1878 | 1933 | && !(avctx->flags&AV_CODEC_FLAG_PASS2) |
| 1879 | − && s->m.me.scene_change_score > s->scenechange_threshold){ | |
| 1934 | + && mpv->me.scene_change_score > enc->scenechange_threshold) { | |
| 1880 | 1935 | ff_init_range_encoder(c, pkt->data, pkt->size); |
| 1881 | 1936 | ff_build_rac_states(c, (1LL<<32)/20, 256-8); |
| 1882 | 1937 | pic->pict_type= AV_PICTURE_TYPE_I; |
| @@ -1901,8 +1956,8 @@ redo_frame: · 18 unmodified lines | ||
| 1901 | 1956 | |
| 1902 | 1957 | ff_spatial_dwt(s->spatial_dwt_buffer, s->temp_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); |
| 1903 | 1958 | |
| 1904 | − if(s->pass1_rc && plane_index==0){ | |
| 1905 | − int delta_qlog = ratecontrol_1pass(s, pic); | |
| 1959 | + if (enc->pass1_rc && plane_index==0) { | |
| 1960 | + int delta_qlog = ratecontrol_1pass(enc, pic); | |
| 1906 | 1961 | if (delta_qlog <= INT_MIN) |
| 1907 | 1962 | return -1; |
| 1908 | 1963 | if(delta_qlog){ |
| @@ -1911,7 +1966,7 @@ redo_frame: · 2 unmodified lines | ||
| 1911 | 1966 | memcpy(s->header_state, rc_header_bak, sizeof(s->header_state)); |
| 1912 | 1967 | memcpy(s->block_state, rc_block_bak, sizeof(s->block_state)); |
| 1913 | 1968 | encode_header(s); |
| 1914 | − encode_blocks(s, 0); | |
| 1969 | + encode_blocks(enc, 0); | |
| 1915 | 1970 | } |
| 1916 | 1971 | } |
| 1917 | 1972 | |
| @@ -1922,7 +1977,7 @@ redo_frame: · 4 unmodified lines | ||
| 1922 | 1977 | quantize(s, b, b->ibuf, b->buf, b->stride, s->qbias); |
| 1923 | 1978 | if(orientation==0) |
| 1924 | 1979 | decorrelate(s, b, b->ibuf, b->stride, pic->pict_type == AV_PICTURE_TYPE_P, 0); |
| 1925 | − if (!s->no_bitstream) | |
| 1980 | + if (!enc->no_bitstream) | |
| 1926 | 1981 | encode_subband(s, b, b->ibuf, b->parent ? b->parent->ibuf : NULL, b->stride, orientation); |
| 1927 | 1982 | av_assert0(b->parent==NULL || b->parent->stride == b->stride*2); |
| 1928 | 1983 | if(orientation==0) |
| @@ -1972,7 +2027,7 @@ redo_frame: · 43 unmodified lines | ||
| 1972 | 2027 | } |
| 1973 | 2028 | } |
| 1974 | 2029 | s->avctx->error[plane_index] += error; |
| 1975 | − s->encoding_error[plane_index] = error; | |
| 2030 | + enc->encoding_error[plane_index] = error; | |
| 1976 | 2031 | } |
| 1977 | 2032 | |
| 1978 | 2033 | } |
| @@ -1984,23 +2039,23 @@ redo_frame: · 5 unmodified lines | ||
| 1984 | 2039 | |
| 1985 | 2040 | s->current_picture->pict_type = pic->pict_type; |
| 1986 | 2041 | s->current_picture->quality = pic->quality; |
| 1987 | − s->m.frame_bits = 8*(s->c.bytestream - s->c.bytestream_start); | |
| 1988 | − s->m.p_tex_bits = s->m.frame_bits - s->m.misc_bits - s->m.mv_bits; | |
| 1989 | − s->m.current_picture.display_picture_number = | |
| 1990 | − s->m.current_picture.coded_picture_number = avctx->frame_num; | |
| 1991 | − s->m.current_picture.f->quality = pic->quality; | |
| 1992 | − s->m.total_bits += 8*(s->c.bytestream - s->c.bytestream_start); | |
| 1993 | − if(s->pass1_rc) | |
| 1994 | − if (ff_rate_estimate_qscale(&s->m, 0) < 0) | |
| 2042 | + mpv->frame_bits = 8 * (s->c.bytestream - s->c.bytestream_start); | |
| 2043 | + mpv->p_tex_bits = mpv->frame_bits - mpv->misc_bits - mpv->mv_bits; | |
| 2044 | + mpv->total_bits += 8*(s->c.bytestream - s->c.bytestream_start); | |
| 2045 | + mpv->current_picture.display_picture_number = | |
| 2046 | + mpv->current_picture.coded_picture_number = avctx->frame_num; | |
| 2047 | + mpv->current_picture.f->quality = pic->quality; | |
| 2048 | + if (enc->pass1_rc) | |
| 2049 | + if (ff_rate_estimate_qscale(mpv, 0) < 0) | |
| 1995 | 2050 | return -1; |
| 1996 | 2051 | if(avctx->flags&AV_CODEC_FLAG_PASS1) |
| 1997 | − ff_write_pass1_stats(&s->m); | |
| 1998 | − s->m.last_pict_type = s->m.pict_type; | |
| 2052 | + ff_write_pass1_stats(mpv); | |
| 2053 | + mpv->last_pict_type = mpv->pict_type; | |
| 1999 | 2054 | |
| 2000 | 2055 | emms_c(); |
| 2001 | 2056 | |
| 2002 | 2057 | ff_side_data_set_encoder_stats(pkt, s->current_picture->quality, |
| 2003 | − s->encoding_error, | |
| 2058 | + enc->encoding_error, | |
| 2004 | 2059 | (s->avctx->flags&AV_CODEC_FLAG_PSNR) ? SNOW_MAX_PLANES : 0, |
| 2005 | 2060 | s->current_picture->pict_type); |
| 2006 | 2061 | if (s->avctx->flags & AV_CODEC_FLAG_RECON_FRAME) { |
| @@ -2017,10 +2072,11 @@ redo_frame: · 10 unmodified lines | ||
| 2017 | 2072 | |
| 2018 | 2073 | static av_cold int encode_end(AVCodecContext *avctx) |
| 2019 | 2074 | { |
| 2020 | − SnowContext *s = avctx->priv_data; | |
| 2075 | + SnowEncContext *const enc = avctx->priv_data; | |
| 2076 | + SnowContext *const s = &enc->com; | |
| 2021 | 2077 | |
| 2022 | 2078 | ff_snow_common_end(s); |
| 2023 | − ff_rate_control_uninit(&s->m); | |
| 2079 | + ff_rate_control_uninit(&enc->m); | |
| 2024 | 2080 | av_frame_free(&s->input_picture); |
| 2025 | 2081 | |
| 2026 | 2082 | for (int i = 0; i < MAX_REF_FRAMES; i++) { |
| @@ -2028,17 +2084,17 @@ static av_cold int encode_end(AVCodecContext *avctx) · 1 unmodified line | ||
| 2028 | 2084 | av_freep(&s->ref_scores[i]); |
| 2029 | 2085 | } |
| 2030 | 2086 | |
| 2031 | − s->m.me.temp = NULL; | |
| 2032 | − av_freep(&s->m.me.scratchpad); | |
| 2033 | − av_freep(&s->m.me.map); | |
| 2034 | − av_freep(&s->m.sc.obmc_scratchpad); | |
| 2087 | + enc->m.me.temp = NULL; | |
| 2088 | + av_freep(&enc->m.me.scratchpad); | |
| 2089 | + av_freep(&enc->m.me.map); | |
| 2090 | + av_freep(&enc->m.sc.obmc_scratchpad); | |
| 2035 | 2091 | |
| 2036 | 2092 | av_freep(&avctx->stats_out); |
| 2037 | 2093 | |
| 2038 | 2094 | return 0; |
| 2039 | 2095 | } |
| 2040 | 2096 | |
| 2041 | −#define OFFSET(x) offsetof(SnowContext, x) | |
| 2097 | +#define OFFSET(x) offsetof(SnowEncContext, x) | |
| 2042 | 2098 | #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM |
| 2043 | 2099 | static const AVOption options[] = { |
| 2044 | 2100 | {"motion_est", "motion estimation algorithm", OFFSET(motion_est), AV_OPT_TYPE_INT, {.i64 = FF_ME_EPZS }, FF_ME_ZERO, FF_ME_ITER, VE, "motion_est" }, |
| @@ -2077,7 +2133,7 @@ const FFCodec ff_snow_encoder = { · 32 unmodified lines | ||
| 2077 | 2133 | .p.capabilities = AV_CODEC_CAP_DR1 | |
| 2078 | 2134 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE | |
| 2079 | 2135 | AV_CODEC_CAP_ENCODER_RECON_FRAME, |
| 2080 | − .priv_data_size = sizeof(SnowContext), | |
| 2136 | + .priv_data_size = sizeof(SnowEncContext), | |
| 2081 | 2137 | .init = encode_init, |
| 2082 | 2138 | FF_CODEC_ENCODE_CB(encode_frame), |
| 2083 | 2139 | .close = encode_end, |