History

avcodec/snow: Move encoder-only stuff out of SnowContext

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.

Andreas Rheinhardt committed 3 years ago

Commit 155e7e11 parent 259e1d22 files · +254 −221Browse files

Showing the changes to libavcodec (2 of 2 files). Show all

Unified · Split

2 files
  1. libavcodec/snow.h +2 −25
  2. libavcodec/snowenc.c +252 −196
libavcodec/snow.h+2−25
@@ -24,21 +24,18 @@ · 23 unmodified lines
24 24
25#include "libavutil/motion_vector.h"25#include "libavutil/motion_vector.h"
26 26
27#include "avcodec.h"
27#include "hpeldsp.h"28#include "hpeldsp.h"
28#include "me_cmp.h"
29#include "qpeldsp.h"
30#include "snow_dwt.h"29#include "snow_dwt.h"
31 30
32#include "rangecoder.h"31#include "rangecoder.h"
33#include "mathops.h"32#include "mathops.h"
34 33
35#include "mpegvideo.h"
36#include "h264qpel.h"34#include "h264qpel.h"
35#include "videodsp.h"
37 36
38#define SNOW_MAX_PLANES 437#define SNOW_MAX_PLANES 4
39 38
40#define FF_ME_ITER 3
41
42#define MID_STATE 12839#define MID_STATE 128
43 40
44#define MAX_PLANES 441#define MAX_PLANES 4
@@ -117,12 +114,9 @@ typedef struct SnowContext{ · 72 unmodified lines
117 AVClass *class;114 AVClass *class;
118 AVCodecContext *avctx;115 AVCodecContext *avctx;
119 RangeCoder c;116 RangeCoder c;
120 MECmpContext mecc;
121 HpelDSPContext hdsp;117 HpelDSPContext hdsp;
122 QpelDSPContext qdsp;
123 VideoDSPContext vdsp;118 VideoDSPContext vdsp;
124 H264QpelContext h264qpel;119 H264QpelContext h264qpel;
125 MpegvideoEncDSPContext mpvencdsp;
126 SnowDWTContext dwt;120 SnowDWTContext dwt;
127 AVFrame *input_picture; ///< new_picture with the internal linesizes121 AVFrame *input_picture; ///< new_picture with the internal linesizes
128 AVFrame *current_picture;122 AVFrame *current_picture;
@@ -155,9 +149,6 @@ typedef struct SnowContext{ · 26 unmodified lines
155 int spatial_scalability;149 int spatial_scalability;
156 int qlog;150 int qlog;
157 int last_qlog;151 int last_qlog;
158 int lambda;
159 int lambda2;
160 int pass1_rc;
161 int mv_scale;152 int mv_scale;
162 int last_mv_scale;153 int last_mv_scale;
163 int qbias;154 int qbias;
@@ -170,18 +161,7 @@ typedef struct SnowContext{ · 6 unmodified lines
170 int nb_planes;161 int nb_planes;
171 Plane plane[MAX_PLANES];162 Plane plane[MAX_PLANES];
172 BlockNode *block;163 BlockNode *block;
173#define ME_CACHE_SIZE 1024
174 unsigned me_cache[ME_CACHE_SIZE];
175 unsigned me_cache_generation;
176 slice_buffer sb;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 uint8_t *scratchbuf;166 uint8_t *scratchbuf;
187 uint8_t *emu_edge_buffer;167 uint8_t *emu_edge_buffer;
@@ -189,9 +169,6 @@ typedef struct SnowContext{ · 1 unmodified line
189 AVMotionVector *avmv;169 AVMotionVector *avmv;
190 unsigned avmv_size;170 unsigned avmv_size;
191 int avmv_index;171 int avmv_index;
192 uint64_t encoding_error[SNOW_MAX_PLANES];
193
194 int pred;
195}SnowContext;172}SnowContext;
196 173
197/* Tables */174/* Tables */
libavcodec/snowenc.c+252−196
@@ -30,6 +30,7 @@ · 29 unmodified lines
30#include "internal.h" //For AVCodecInternal.recon_frame30#include "internal.h" //For AVCodecInternal.recon_frame
31#include "me_cmp.h"31#include "me_cmp.h"
32#include "packet_internal.h"32#include "packet_internal.h"
33#include "qpeldsp.h"
33#include "snow_dwt.h"34#include "snow_dwt.h"
34#include "snow.h"35#include "snow.h"
35 36
@@ -39,6 +40,34 @@ · 3 unmodified lines
39#include "mpegvideo.h"40#include "mpegvideo.h"
40#include "h263enc.h"41#include "h263enc.h"
41 42
43#define FF_ME_ITER 3
44
45typedef 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
42static void init_ref(MotionEstContext *c, const uint8_t *const src[3],71static void init_ref(MotionEstContext *c, const uint8_t *const src[3],
43 uint8_t *const ref[3], uint8_t *const ref2[3],72 uint8_t *const ref[3], uint8_t *const ref2[3],
44 int x, int y, int ref_index)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
128static av_cold int encode_init(AVCodecContext *avctx)157static 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 int plane_index, ret;162 int plane_index, ret;
132 int i;163 int i;
133 164
134 if(s->pred == DWT_97165 if (enc->pred == DWT_97
135 && (avctx->flags & AV_CODEC_FLAG_QSCALE)166 && (avctx->flags & AV_CODEC_FLAG_QSCALE)
136 && avctx->global_quality == 0){167 && avctx->global_quality == 0){
137 av_log(avctx, AV_LOG_ERROR, "The 9/7 wavelet is incompatible with lossless mode.\n");168 av_log(avctx, AV_LOG_ERROR, "The 9/7 wavelet is incompatible with lossless mode.\n");
138 return AVERROR(EINVAL);169 return AVERROR(EINVAL);
139 }170 }
140 171
141 s->spatial_decomposition_type= s->pred; //FIXME add decorrelator type r transform_type172 s->spatial_decomposition_type = enc->pred; //FIXME add decorrelator type r transform_type
142 173
143 s->mv_scale = (avctx->flags & AV_CODEC_FLAG_QPEL) ? 2 : 4;174 s->mv_scale = (avctx->flags & AV_CODEC_FLAG_QPEL) ? 2 : 4;
144 s->block_max_depth= (avctx->flags & AV_CODEC_FLAG_4MV ) ? 1 : 0;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#define mcf(dx,dy)\192#define mcf(dx,dy)\
162 s->qdsp.put_qpel_pixels_tab [0][dy+dx/4]=\193 enc->qdsp.put_qpel_pixels_tab [0][dy+dx/4]=\
163 s->qdsp.put_no_rnd_qpel_pixels_tab[0][dy+dx/4]=\194 enc->qdsp.put_no_rnd_qpel_pixels_tab[0][dy+dx/4]=\
164 s->h264qpel.put_h264_qpel_pixels_tab[0][dy+dx/4];\195 s->h264qpel.put_h264_qpel_pixels_tab[0][dy+dx/4];\
165 s->qdsp.put_qpel_pixels_tab [1][dy+dx/4]=\196 enc->qdsp.put_qpel_pixels_tab [1][dy+dx/4]=\
166 s->qdsp.put_no_rnd_qpel_pixels_tab[1][dy+dx/4]=\197 enc->qdsp.put_no_rnd_qpel_pixels_tab[1][dy+dx/4]=\
167 s->h264qpel.put_h264_qpel_pixels_tab[1][dy+dx/4];198 s->h264qpel.put_h264_qpel_pixels_tab[1][dy+dx/4];
168 199
169 mcf( 0, 0)200 mcf( 0, 0)
@@ -183,28 +214,28 @@ static av_cold int encode_init(AVCodecContext *avctx) · 13 unmodified lines
183 mcf( 8,12)214 mcf( 8,12)
184 mcf(12,12)215 mcf(12,12)
185 216
186 ff_me_cmp_init(&s->mecc, avctx);217 ff_me_cmp_init(&enc->mecc, avctx);
187 ff_mpegvideoencdsp_init(&s->mpvencdsp, avctx);218 ff_mpegvideoencdsp_init(&enc->mpvencdsp, avctx);
188 219
189 ff_snow_alloc_blocks(s);220 ff_snow_alloc_blocks(s);
190 221
191 s->version=0;222 s->version=0;
192 223
193 s->m.avctx = avctx;224 mpv->avctx = avctx;
194 s->m.bit_rate= avctx->bit_rate;225 mpv->bit_rate= avctx->bit_rate;
195 s->m.lmin = avctx->mb_lmin;226 mpv->lmin = avctx->mb_lmin;
196 s->m.lmax = avctx->mb_lmax;227 mpv->lmax = avctx->mb_lmax;
197 s->m.mb_num = (avctx->width * avctx->height + 255) / 256; // For ratecontrol228 mpv->mb_num = (avctx->width * avctx->height + 255) / 256; // For ratecontrol
198 229
199 s->m.me.temp =230 mpv->me.temp =
200 s->m.me.scratchpad = av_calloc(avctx->width + 64, 2*16*2*sizeof(uint8_t));231 mpv->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));232 mpv->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));233 mpv->me.map = av_mallocz(2 * ME_MAP_SIZE * sizeof(*mpv->me.map));
203 if (!s->m.me.scratchpad || !s->m.me.map || !s->m.sc.obmc_scratchpad)234 if (!mpv->me.scratchpad || !mpv->me.map || !mpv->sc.obmc_scratchpad)
204 return AVERROR(ENOMEM);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_penalty238 ff_h263_encode_init(mpv); //mv_penalty
208 239
209 s->max_ref_frames = av_clip(avctx->refs, 1, MAX_REF_FRAMES);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 return AVERROR(ENOMEM);247 return AVERROR(ENOMEM);
217 }248 }
218 if((avctx->flags&AV_CODEC_FLAG_PASS2) || !(avctx->flags&AV_CODEC_FLAG_QSCALE)){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 if(ret < 0)251 if(ret < 0)
221 return ret;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 switch(avctx->pix_fmt){256 switch(avctx->pix_fmt){
226 case AV_PIX_FMT_YUV444P:257 case AV_PIX_FMT_YUV444P:
@@ -245,8 +276,8 @@ static av_cold int encode_init(AVCodecContext *avctx) · 18 unmodified lines
245 if (ret)276 if (ret)
246 return ret;277 return ret;
247 278
248 ret = ff_set_cmp(&s->mecc, s->mecc.me_cmp, s->avctx->me_cmp);279 ret = ff_set_cmp(&enc->mecc, enc->mecc.me_cmp, s->avctx->me_cmp);
249 ret |= ff_set_cmp(&s->mecc, s->mecc.me_sub_cmp, s->avctx->me_sub_cmp);280 ret |= ff_set_cmp(&enc->mecc, enc->mecc.me_sub_cmp, s->avctx->me_sub_cmp);
250 if (ret < 0)281 if (ret < 0)
251 return AVERROR(EINVAL);282 return AVERROR(EINVAL);
252 283
@@ -257,7 +288,7 @@ static av_cold int encode_init(AVCodecContext *avctx) · 4 unmodified lines
257 if ((ret = get_encode_buffer(s, s->input_picture)) < 0)288 if ((ret = get_encode_buffer(s, s->input_picture)) < 0)
258 return ret;289 return ret;
259 290
260 if(s->motion_est == FF_ME_ITER){291 if (enc->motion_est == FF_ME_ITER) {
261 int size= s->b_width * s->b_height << 2*s->block_max_depth;292 int size= s->b_width * s->b_height << 2*s->block_max_depth;
262 for(i=0; i<s->max_ref_frames; i++){293 for(i=0; i<s->max_ref_frames; i++){
263 s->ref_mvs[i] = av_calloc(size, sizeof(*s->ref_mvs[i]));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#define P_MV1 P[9]366#define P_MV1 P[9]
336#define FLAG_QPEL 1 //must be 1367#define FLAG_QPEL 1 //must be 1
337 368
338static int encode_q_branch(SnowContext *s, int level, int x, int y){369static 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 uint8_t p_buffer[1024];373 uint8_t p_buffer[1024];
340 uint8_t i_buffer[1024];374 uint8_t i_buffer[1024];
341 uint8_t p_state[sizeof(s->block_state)];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 int16_t last_mv[3][2];406 int16_t last_mv[3][2];
373 int qpel= !!(s->avctx->flags & AV_CODEC_FLAG_QPEL); //unused407 int qpel= !!(s->avctx->flags & AV_CODEC_FLAG_QPEL); //unused
374 const int shift= 1+qpel;408 const int shift= 1+qpel;
375 MotionEstContext *c= &s->m.me;
376 int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref);409 int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref);
377 int mx_context= av_log2(2*FFABS(left->mx - top->mx));410 int mx_context= av_log2(2*FFABS(left->mx - top->mx));
378 int my_context= av_log2(2*FFABS(left->my - top->my));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 last_mv[2][0]= bottom->mx;434 last_mv[2][0]= bottom->mx;
402 last_mv[2][1]= bottom->my;435 last_mv[2][1]= bottom->my;
403 436
404 s->m.mb_stride=2;437 enc->m.mb_stride = 2;
405 s->m.mb_x=438 enc->m.mb_x =
406 s->m.mb_y= 0;439 enc->m.mb_y = 0;
407 c->skip= 0;440 c->skip= 0;
408 441
409 av_assert1(c-> stride == stride);442 av_assert1(c-> stride == stride);
410 av_assert1(c->uvstride == uvstride);443 av_assert1(c->uvstride == uvstride);
411 444
412 c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp);445 c->penalty_factor = get_penalty_factor(enc->lambda, enc->lambda2, c->avctx->me_cmp);
413 c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp);446 c->sub_penalty_factor= get_penalty_factor(enc->lambda, enc->lambda2, c->avctx->me_sub_cmp);
414 c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp);447 c->mb_penalty_factor = get_penalty_factor(enc->lambda, enc->lambda2, c->avctx->mb_cmp);
415 c->current_mv_penalty= c->mv_penalty[s->m.f_code=1] + MAX_DMV;448 c->current_mv_penalty = c->mv_penalty[enc->m.f_code=1] + MAX_DMV;
416 449
417 c->xmin = - x*block_w - 16+3;450 c->xmin = - x*block_w - 16+3;
418 c->ymin = - y*block_w - 16+3;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 for(ref=0; ref<s->ref_frames; ref++){476 for(ref=0; ref<s->ref_frames; ref++){
444 init_ref(c, current_data, s->last_picture[ref]->data, NULL, block_w*x, block_w*y, 0);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 (1<<16)>>shift, level-LOG2_MB_SIZE+4, block_w);480 (1<<16)>>shift, level-LOG2_MB_SIZE+4, block_w);
448 481
449 av_assert2(ref_mx >= c->xmin);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 av_assert2(ref_my >= c->ymin);484 av_assert2(ref_my >= c->ymin);
452 av_assert2(ref_my <= c->ymax);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);487 ref_score= c->sub_motion_search(&enc->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);488 ref_score= ff_get_mb_score(&enc->m, ref_mx, ref_my, 0, 0, level-LOG2_MB_SIZE+4, block_w, 0);
456 ref_score+= 2*av_log2(2*ref)*c->penalty_factor;489 ref_score+= 2*av_log2(2*ref)*c->penalty_factor;
457 if(s->ref_mvs[ref]){490 if(s->ref_mvs[ref]){
458 s->ref_mvs[ref][index][0]= ref_mx;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 put_symbol(&pc, &p_state[128 + 32*(mx_context + 16*!!best_ref)], mx - pmx, 1);517 put_symbol(&pc, &p_state[128 + 32*(mx_context + 16*!!best_ref)], mx - pmx, 1);
485 put_symbol(&pc, &p_state[128 + 32*(my_context + 16*!!best_ref)], my - pmy, 1);518 put_symbol(&pc, &p_state[128 + 32*(my_context + 16*!!best_ref)], my - pmy, 1);
486 p_len= pc.bytestream - pc.bytestream_start;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 block_s= block_w*block_w;522 block_s= block_w*block_w;
490 sum = pix_sum(current_data[0], stride, block_w, block_w);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 put_symbol(&ic, &i_state[96], cr-pcr, 1);548 put_symbol(&ic, &i_state[96], cr-pcr, 1);
516 }549 }
517 i_len= ic.bytestream - ic.bytestream_start;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 av_assert1(iscore >= 0);554 av_assert1(iscore >= 0);
522 av_assert1(l>=0 && l<=255);555 av_assert1(l>=0 && l<=255);
523 av_assert1(pl>=0 && pl<=255);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 if (vard <= 64 || vard < varc)561 if (vard <= 64 || vard < varc)
529 c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc);562 c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc);
530 else563 else
531 c->scene_change_score+= s->m.qscale;564 c->scene_change_score += enc->m.qscale;
532 }565 }
533 566
534 if(level!=s->block_max_depth){567 if(level!=s->block_max_depth){
535 put_rac(&s->c, &s->block_state[4 + s_context], 0);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);569 score2 = encode_q_branch(enc, level+1, 2*x+0, 2*y+0);
537 score2+= encode_q_branch(s, level+1, 2*x+1, 2*y+0);570 score2+= encode_q_branch(enc, level+1, 2*x+1, 2*y+0);
538 score2+= encode_q_branch(s, level+1, 2*x+0, 2*y+1);571 score2+= encode_q_branch(enc, level+1, 2*x+0, 2*y+1);
539 score2+= encode_q_branch(s, level+1, 2*x+1, 2*y+1);572 score2+= encode_q_branch(enc, level+1, 2*x+1, 2*y+1);
540 score2+= s->lambda2>>FF_LAMBDA_SHIFT; //FIXME exact split overhead573 score2+= enc->lambda2>>FF_LAMBDA_SHIFT; //FIXME exact split overhead
541 574
542 if(score2 < score && score2 < iscore)575 if(score2 < score && score2 < iscore)
543 return score2;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
622static int get_dc(SnowContext *s, int mb_x, int mb_y, int plane_index){655static int get_dc(SnowEncContext *enc, int mb_x, int mb_y, int plane_index)
656{
657 SnowContext *const s = &enc->com;
623 int i, x2, y2;658 int i, x2, y2;
624 Plane *p= &s->plane[plane_index];659 Plane *p= &s->plane[plane_index];
625 const int block_size = MB_SIZE >> s->block_max_depth;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 const int obmc_stride= plane_index ? (2*block_size)>>s->chroma_h_shift : 2*block_size;664 const int obmc_stride= plane_index ? (2*block_size)>>s->chroma_h_shift : 2*block_size;
630 const int ref_stride= s->current_picture->linesize[plane_index];665 const int ref_stride= s->current_picture->linesize[plane_index];
631 const uint8_t *src = s->input_picture->data[plane_index];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 unsigned667 IDWTELEM *dst= (IDWTELEM*)enc->m.sc.obmc_scratchpad + plane_index*block_size*block_size*4; //FIXME change to unsigned
633 const int b_stride = s->b_width << s->block_max_depth;668 const int b_stride = s->b_width << s->block_max_depth;
634 const int w= p->width;669 const int w= p->width;
635 const int h= p->height;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
718static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, uint8_t (*obmc_edged)[MB_SIZE * 2]){753static 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 Plane *p= &s->plane[plane_index];757 Plane *p= &s->plane[plane_index];
720 const int block_size = MB_SIZE >> s->block_max_depth;758 const int block_size = MB_SIZE >> s->block_max_depth;
721 const int block_w = plane_index ? block_size>>s->chroma_h_shift : block_size;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 const int ref_stride= s->current_picture->linesize[plane_index];762 const int ref_stride= s->current_picture->linesize[plane_index];
725 uint8_t *dst= s->current_picture->data[plane_index];763 uint8_t *dst= s->current_picture->data[plane_index];
726 const uint8_t *src = s->input_picture->data[plane_index];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 uint8_t *cur = s->scratchbuf;766 uint8_t *cur = s->scratchbuf;
729 uint8_t *tmp = s->emu_edge_buffer;767 uint8_t *tmp = s->emu_edge_buffer;
730 const int b_stride = s->b_width << s->block_max_depth;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 const int h= p->height;771 const int h= p->height;
734 int distortion;772 int distortion;
735 int rate= 0;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 int sx= block_w*mb_x - block_w/2;775 int sx= block_w*mb_x - block_w/2;
738 int sy= block_h*mb_y - block_h/2;776 int sy= block_h*mb_y - block_h/2;
739 int x0= FFMAX(0,-sx);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 * to improve the score of the whole frame, thus iterative motion825 * to improve the score of the whole frame, thus iterative motion
788 * estimation does not always converge. */826 * estimation does not always converge. */
789 if(s->avctx->me_cmp == FF_CMP_W97)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 else if(s->avctx->me_cmp == FF_CMP_W53)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 else{831 else{
794 distortion = 0;832 distortion = 0;
795 for(i=0; i<4; i++){833 for(i=0; i<4; i++){
796 int off = sx+16*(i&1) + (sy+16*(i>>1))*ref_stride;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 }else{838 }else{
801 av_assert2(block_w==8);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 if(plane_index==0){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 return distortion + rate*penalty_factor;854 return distortion + rate*penalty_factor;
817}855}
818 856
819static int get_4block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index){857static int get_4block_rd(SnowEncContext *enc, int mb_x, int mb_y, int plane_index)
858{
859 SnowContext *const s = &enc->com;
820 int i, y2;860 int i, y2;
821 Plane *p= &s->plane[plane_index];861 Plane *p= &s->plane[plane_index];
822 const int block_size = MB_SIZE >> s->block_max_depth;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 const int h= p->height;875 const int h= p->height;
836 int distortion= 0;876 int distortion= 0;
837 int rate= 0;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 av_assert2(s->chroma_h_shift == s->chroma_v_shift); //obmc and square assumtions below880 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 av_assert1(block_w== 8 || block_w==16);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 if(plane_index==0){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// encode_subband_dzr(s, b, src, parent, stride, orientation);1052// encode_subband_dzr(s, b, src, parent, stride, orientation);
1013}1053}
1014 1054
1015static av_always_inline int check_block_intra(SnowContext *s, int mb_x, int mb_y, int p[3],1055static av_always_inline int check_block_intra(SnowEncContext *enc, int mb_x, int mb_y, int p[3],
1016 uint8_t (*obmc_edged)[MB_SIZE * 2], int *best_rd)1056 uint8_t (*obmc_edged)[MB_SIZE * 2], int *best_rd)
1017{1057{
1058 SnowContext *const s = &enc->com;
1018 const int b_stride= s->b_width << s->block_max_depth;1059 const int b_stride= s->b_width << s->block_max_depth;
1019 BlockNode *block= &s->block[mb_x + mb_y * b_stride];1060 BlockNode *block= &s->block[mb_x + mb_y * b_stride];
1020 BlockNode backup= *block;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 block->color[2] = p[2];1069 block->color[2] = p[2];
1029 block->type |= BLOCK_INTRA;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//FIXME chroma1074//FIXME chroma
1034 if(rd < *best_rd){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/* special case for int[2] args we discard afterwards,1084/* special case for int[2] args we discard afterwards,
1044 * fixes compilation problem with gcc 2.95 */1085 * fixes compilation problem with gcc 2.95 */
1045static 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){1086static 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 const int b_stride = s->b_width << s->block_max_depth;1091 const int b_stride = s->b_width << s->block_max_depth;
1047 BlockNode *block = &s->block[mb_x + mb_y * b_stride];1092 BlockNode *block = &s->block[mb_x + mb_y * b_stride];
1048 BlockNode backup = *block;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 av_assert2(mb_x < b_stride);1098 av_assert2(mb_x < b_stride);
1054 1099
1055 index = (p0 + 31 * p1) & (ME_CACHE_SIZE-1);1100 index = (p0 + 31 * p1) & (ME_CACHE_SIZE-1);
1056 value = s->me_cache_generation + (p0 >> 10) + p1 * (1 << 6) + (block->ref << 12);1101 value = enc->me_cache_generation + (p0 >> 10) + p1 * (1 << 6) + (block->ref << 12);
1057 if (s->me_cache[index] == value)1102 if (enc->me_cache[index] == value)
1058 return 0;1103 return 0;
1059 s->me_cache[index] = value;1104 enc->me_cache[index] = value;
1060 1105
1061 block->mx = p0;1106 block->mx = p0;
1062 block->my = p1;1107 block->my = p1;
1063 block->type &= ~BLOCK_INTRA;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//FIXME chroma1112//FIXME chroma
1068 if (rd < *best_rd) {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
1077static av_always_inline int check_4block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, int ref, int *best_rd){1122static 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 const int b_stride= s->b_width << s->block_max_depth;1126 const int b_stride= s->b_width << s->block_max_depth;
1079 BlockNode *block= &s->block[mb_x + mb_y * b_stride];1127 BlockNode *block= &s->block[mb_x + mb_y * b_stride];
1080 BlockNode backup[4];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 av_assert2(((mb_x|mb_y)&1) == 0);1142 av_assert2(((mb_x|mb_y)&1) == 0);
1095 1143
1096 index= (p0 + 31*p1) & (ME_CACHE_SIZE-1);1144 index= (p0 + 31*p1) & (ME_CACHE_SIZE-1);
1097 value= s->me_cache_generation + (p0>>10) + (p1<<6) + (block->ref<<12);1145 value = enc->me_cache_generation + (p0>>10) + (p1<<6) + (block->ref<<12);
1098 if(s->me_cache[index] == value)1146 if (enc->me_cache[index] == value)
1099 return 0;1147 return 0;
1100 s->me_cache[index]= value;1148 enc->me_cache[index] = value;
1101 1149
1102 block->mx= p0;1150 block->mx= p0;
1103 block->my= p1;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 block->type &= ~BLOCK_INTRA;1153 block->type &= ~BLOCK_INTRA;
1106 block[1]= block[b_stride]= block[b_stride+1]= *block;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//FIXME chroma1158//FIXME chroma
1111 if(rd < *best_rd){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
1123static void iterative_me(SnowContext *s){1171static void iterative_me(SnowEncContext *enc)
1172{
1173 SnowContext *const s = &enc->com;
1124 int pass, mb_x, mb_y;1174 int pass, mb_x, mb_y;
1125 const int b_width = s->b_width << s->block_max_depth;1175 const int b_width = s->b_width << s->block_max_depth;
1126 const int b_height= s->b_height << s->block_max_depth;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 memcpy(state, s->block_state, sizeof(s->block_state));1183 memcpy(state, s->block_state, sizeof(s->block_state));
1134 for(mb_y= 0; mb_y<s->b_height; mb_y++)1184 for(mb_y= 0; mb_y<s->b_height; mb_y++)
1135 for(mb_x= 0; mb_x<s->b_width; mb_x++)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 s->c = r;1187 s->c = r;
1138 memcpy(s->block_state, state, sizeof(s->block_state));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 backup= *block;1216 backup= *block;
1167 1217
1168 if(!s->me_cache_generation)1218 if (!enc->me_cache_generation)
1169 memset(s->me_cache, 0, sizeof(s->me_cache));1219 memset(enc->me_cache, 0, sizeof(enc->me_cache));
1170 s->me_cache_generation += 1<<22;1220 enc->me_cache_generation += 1<<22;
1171 1221
1172 //FIXME precalculate1222 //FIXME precalculate
1173 {1223 {
@@ -1223,14 +1273,14 @@ static void iterative_me(SnowContext *s){ · 49 unmodified lines
1223 1273
1224 // intra(black) = neighbors' contribution to the current block1274 // intra(black) = neighbors' contribution to the current block
1225 for(i=0; i < s->nb_planes; i++)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 // get previous score (cannot be cached due to OBMC)1278 // get previous score (cannot be cached due to OBMC)
1229 if(pass > 0 && (block->type&BLOCK_INTRA)){1279 if(pass > 0 && (block->type&BLOCK_INTRA)){
1230 int color0[3]= {block->color[0], block->color[1], block->color[2]};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 }else1282 }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 ref_b= *block;1285 ref_b= *block;
1236 ref_rd= best_rd;1286 ref_rd= best_rd;
@@ -1241,30 +1291,30 @@ static void iterative_me(SnowContext *s){ · 4 unmodified lines
1241 block->ref= ref;1291 block->ref= ref;
1242 best_rd= INT_MAX;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);1294 check_block_inter(enc, 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);1295 check_block_inter(enc, mb_x, mb_y, 0, 0, obmc_edged, &best_rd);
1246 if(tb)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 if(lb)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 if(rb)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 if(bb)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 /* fullpel ME */1305 /* fullpel ME */
1256 //FIXME avoid subpel interpolation / round to nearest integer1306 //FIXME avoid subpel interpolation / round to nearest integer
1257 do{1307 do{
1258 int newx = block->mx;1308 int newx = block->mx;
1259 int newy = block->my;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 dia_change=0;1311 dia_change=0;
1262 for(i=0; i < dia_size; i++){1312 for(i=0; i < dia_size; i++){
1263 for(j=0; j<i; j++){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);1314 dia_change |= check_block_inter(enc, 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);1315 dia_change |= check_block_inter(enc, 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);1316 dia_change |= check_block_inter(enc, 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);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 }while(dia_change);1320 }while(dia_change);
@@ -1273,7 +1323,7 @@ static void iterative_me(SnowContext *s){ · 2 unmodified lines
1273 static const int square[8][2]= {{+1, 0},{-1, 0},{ 0,+1},{ 0,-1},{+1,+1},{-1,-1},{+1,-1},{-1,+1},};1323 static const int square[8][2]= {{+1, 0},{-1, 0},{ 0,+1},{ 0,-1},{+1,+1},{-1,-1},{+1,-1},{-1,+1},};
1274 dia_change=0;1324 dia_change=0;
1275 for(i=0; i<8; i++)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 }while(dia_change);1327 }while(dia_change);
1278 //FIXME or try the standard 2 pass qpel or similar1328 //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 best_rd= ref_rd;1337 best_rd= ref_rd;
1288 *block= ref_b;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 //FIXME RD style color selection1340 //FIXME RD style color selection
1291 if(!same_block(block, &backup)){1341 if(!same_block(block, &backup)){
1292 if(tb ) tb ->type &= ~BLOCK_OPT;1342 if(tb ) tb ->type &= ~BLOCK_OPT;
@@ -1324,20 +1374,20 @@ static void iterative_me(SnowContext *s){ · 31 unmodified lines
1324 same_block(b[0], b[3]))1374 same_block(b[0], b[3]))
1325 continue;1375 continue;
1326 1376
1327 if(!s->me_cache_generation)1377 if (!enc->me_cache_generation)
1328 memset(s->me_cache, 0, sizeof(s->me_cache));1378 memset(enc->me_cache, 0, sizeof(enc->me_cache));
1329 s->me_cache_generation += 1<<22;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 //FIXME more multiref search?1383 //FIXME more multiref search?
1334 check_4block_inter(s, mb_x, mb_y,1384 check_4block_inter(enc, mb_x, mb_y,
1335 (b[0]->mx + b[1]->mx + b[2]->mx + b[3]->mx + 2) >> 2,1385 (b[0]->mx + b[1]->mx + b[2]->mx + b[3]->mx + 2) >> 2,
1336 (b[0]->my + b[1]->my + b[2]->my + b[3]->my + 2) >> 2, 0, &best_rd);1386 (b[0]->my + b[1]->my + b[2]->my + b[3]->my + 2) >> 2, 0, &best_rd);
1337 1387
1338 for(i=0; i<4; i++)1388 for(i=0; i<4; i++)
1339 if(!(b[i]->type&BLOCK_INTRA))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 if(init_rd != best_rd)1392 if(init_rd != best_rd)
1343 change++;1393 change++;
@@ -1347,13 +1397,15 @@ static void iterative_me(SnowContext *s){ · 3 unmodified lines
1347 }1397 }
1348}1398}
1349 1399
1350static void encode_blocks(SnowContext *s, int search){1400static void encode_blocks(SnowEncContext *enc, int search)
1401{
1402 SnowContext *const s = &enc->com;
1351 int x, y;1403 int x, y;
1352 int w= s->b_width;1404 int w= s->b_width;
1353 int h= s->b_height;1405 int h= s->b_height;
1354 1406
1355 if(s->motion_est == FF_ME_ITER && !s->keyframe && search)1407 if (enc->motion_est == FF_ME_ITER && !s->keyframe && search)
1356 iterative_me(s);1408 iterative_me(enc);
1357 1409
1358 for(y=0; y<h; y++){1410 for(y=0; y<h; y++){
1359 if(s->c.bytestream_end - s->c.bytestream < w*MB_SIZE*MB_SIZE*3){ //FIXME nicer limit1411 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 return;1413 return;
1362 }1414 }
1363 for(x=0; x<w; x++){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 encode_q_branch2(s, 0, x, y);1417 encode_q_branch2(s, 0, x, y);
1366 else1418 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 + 61*QROOT/8; ///< 64 > 601663 + 61*QROOT/8; ///< 64 > 60
1612}1664}
1613 1665
1614static int ratecontrol_1pass(SnowContext *s, AVFrame *pict)1666static int ratecontrol_1pass(SnowEncContext *enc, AVFrame *pict)
1615{1667{
1668 SnowContext *const s = &enc->com;
1616 /* Estimate the frame's complexity as a sum of weighted dwt coefficients.1669 /* Estimate the frame's complexity as a sum of weighted dwt coefficients.
1617 * FIXME we know exact mv bits at this point,1670 * FIXME we know exact mv bits at this point,
1618 * but ratecontrol isn't set up to include them. */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 coef_sum = (uint64_t)coef_sum * coef_sum >> 16;1700 coef_sum = (uint64_t)coef_sum * coef_sum >> 16;
1648 1701
1649 if(pict->pict_type == AV_PICTURE_TYPE_I){1702 if(pict->pict_type == AV_PICTURE_TYPE_I){
1650 s->m.mb_var_sum = coef_sum;1703 enc->m.mb_var_sum = coef_sum;
1651 s->m.mc_mb_var_sum = 0;1704 enc->m.mc_mb_var_sum = 0;
1652 }else{1705 }else{
1653 s->m.mc_mb_var_sum = coef_sum;1706 enc->m.mc_mb_var_sum = coef_sum;
1654 s->m.mb_var_sum = 0;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 if (pict->quality < 0)1711 if (pict->quality < 0)
1659 return INT_MIN;1712 return INT_MIN;
1660 s->lambda= pict->quality * 3/2;1713 enc->lambda= pict->quality * 3/2;
1661 delta_qlog= qscale2qlog(pict->quality) - s->qlog;1714 delta_qlog= qscale2qlog(pict->quality) - s->qlog;
1662 s->qlog+= delta_qlog;1715 s->qlog+= delta_qlog;
1663 return delta_qlog;1716 return delta_qlog;
@@ -1696,7 +1749,9 @@ static void calculate_visual_weight(SnowContext *s, Plane *p){ · 32 unmodified lines
1696static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,1749static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
1697 const AVFrame *pict, int *got_packet)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 RangeCoder * const c= &s->c;1755 RangeCoder * const c= &s->c;
1701 AVCodecInternal *avci = avctx->internal;1756 AVCodecInternal *avci = avctx->internal;
1702 AVFrame *pic;1757 AVFrame *pic;
@@ -1719,7 +1774,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 16 unmodified lines
1719 memcpy(&s->input_picture->data[i][y * s->input_picture->linesize[i]],1774 memcpy(&s->input_picture->data[i][y * s->input_picture->linesize[i]],
1720 &pict->data[i][y * pict->linesize[i]],1775 &pict->data[i][y * pict->linesize[i]],
1721 AV_CEIL_RSHIFT(width, hshift));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 AV_CEIL_RSHIFT(width, hshift), AV_CEIL_RSHIFT(height, vshift),1778 AV_CEIL_RSHIFT(width, hshift), AV_CEIL_RSHIFT(height, vshift),
1724 EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift,1779 EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift,
1725 EDGE_TOP | EDGE_BOTTOM);1780 EDGE_TOP | EDGE_BOTTOM);
@@ -1730,45 +1785,45 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 4 unmodified lines
1730 pic->pict_type = pict->pict_type;1785 pic->pict_type = pict->pict_type;
1731 pic->quality = pict->quality;1786 pic->quality = pict->quality;
1732 1787
1733 s->m.picture_number= avctx->frame_num;1788 mpv->picture_number = avctx->frame_num;
1734 if(avctx->flags&AV_CODEC_FLAG_PASS2){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 s->keyframe = pic->pict_type == AV_PICTURE_TYPE_I;1791 s->keyframe = pic->pict_type == AV_PICTURE_TYPE_I;
1737 if(!(avctx->flags&AV_CODEC_FLAG_QSCALE)) {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 if (pic->quality < 0)1794 if (pic->quality < 0)
1740 return -1;1795 return -1;
1741 }1796 }
1742 }else{1797 }else{
1743 s->keyframe= avctx->gop_size==0 || avctx->frame_num % avctx->gop_size == 0;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 pic->quality = 2*FF_QP2LAMBDA;1803 pic->quality = 2*FF_QP2LAMBDA;
1749 if (pic->quality) {1804 if (pic->quality) {
1750 s->qlog = qscale2qlog(pic->quality);1805 s->qlog = qscale2qlog(pic->quality);
1751 s->lambda = pic->quality * 3/2;1806 enc->lambda = pic->quality * 3/2;
1752 }1807 }
1753 if (s->qlog < 0 || (!pic->quality && (avctx->flags & AV_CODEC_FLAG_QSCALE))) {1808 if (s->qlog < 0 || (!pic->quality && (avctx->flags & AV_CODEC_FLAG_QSCALE))) {
1754 s->qlog= LOSSLESS_QLOG;1809 s->qlog= LOSSLESS_QLOG;
1755 s->lambda = 0;1810 enc->lambda = 0;
1756 }//else keep previous frame's qlog until after motion estimation1811 }//else keep previous frame's qlog until after motion estimation
1757 1812
1758 if (s->current_picture->data[0]) {1813 if (s->current_picture->data[0]) {
1759 int w = s->avctx->width;1814 int w = s->avctx->width;
1760 int h = s->avctx->height;1815 int h = s->avctx->height;
1761 1816
1762 s->mpvencdsp.draw_edges(s->current_picture->data[0],1817 enc->mpvencdsp.draw_edges(s->current_picture->data[0],
1763 s->current_picture->linesize[0], w , h ,1818 s->current_picture->linesize[0], w , h ,
1764 EDGE_WIDTH , EDGE_WIDTH , EDGE_TOP | EDGE_BOTTOM);1819 EDGE_WIDTH , EDGE_WIDTH , EDGE_TOP | EDGE_BOTTOM);
1765 if (s->current_picture->data[2]) {1820 if (s->current_picture->data[2]) {
1766 s->mpvencdsp.draw_edges(s->current_picture->data[1],1821 enc->mpvencdsp.draw_edges(s->current_picture->data[1],
1767 s->current_picture->linesize[1], w>>s->chroma_h_shift, h>>s->chroma_v_shift,1822 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);1823 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],1824 enc->mpvencdsp.draw_edges(s->current_picture->data[2],
1770 s->current_picture->linesize[2], w>>s->chroma_h_shift, h>>s->chroma_v_shift,1825 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);1826 EDGE_WIDTH>>s->chroma_h_shift, EDGE_WIDTH>>s->chroma_v_shift, EDGE_TOP | EDGE_BOTTOM);
1772 }1827 }
1773 emms_c();1828 emms_c();
1774 }1829 }
@@ -1778,9 +1833,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 3 unmodified lines
1778 if (ret < 0)1833 if (ret < 0)
1779 return ret;1834 return ret;
1780 1835
1781 s->m.current_picture_ptr= &s->m.current_picture;1836 mpv->current_picture_ptr = &mpv->current_picture;
1782 s->m.current_picture.f = s->current_picture;1837 mpv->current_picture.f = s->current_picture;
1783 s->m.current_picture.f->pts = pict->pts;1838 mpv->current_picture.f->pts = pict->pts;
1784 if(pic->pict_type == AV_PICTURE_TYPE_P){1839 if(pic->pict_type == AV_PICTURE_TYPE_P){
1785 int block_width = (width +15)>>4;1840 int block_width = (width +15)>>4;
1786 int block_height= (height+15)>>4;1841 int block_height= (height+15)>>4;
@@ -1789,40 +1844,40 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 2 unmodified lines
1789 av_assert0(s->current_picture->data[0]);1844 av_assert0(s->current_picture->data[0]);
1790 av_assert0(s->last_picture[0]->data[0]);1845 av_assert0(s->last_picture[0]->data[0]);
1791 1846
1792 s->m.avctx= s->avctx;1847 mpv->avctx = s->avctx;
1793 s->m. last_picture.f = s->last_picture[0];1848 mpv->last_picture.f = s->last_picture[0];
1794 s->m. new_picture = s->input_picture;1849 mpv-> new_picture = s->input_picture;
1795 s->m. last_picture_ptr= &s->m. last_picture;1850 mpv->last_picture_ptr = &mpv->last_picture;
1796 s->m.linesize = stride;1851 mpv->linesize = stride;
1797 s->m.uvlinesize= s->current_picture->linesize[1];1852 mpv->uvlinesize = s->current_picture->linesize[1];
1798 s->m.width = width;1853 mpv->width = width;
1799 s->m.height= height;1854 mpv->height = height;
1800 s->m.mb_width = block_width;1855 mpv->mb_width = block_width;
1801 s->m.mb_height= block_height;1856 mpv->mb_height = block_height;
1802 s->m.mb_stride= s->m.mb_width+1;1857 mpv->mb_stride = mpv->mb_width + 1;
1803 s->m.b8_stride= 2*s->m.mb_width+1;1858 mpv->b8_stride = 2 * mpv->mb_width + 1;
1804 s->m.f_code=1;1859 mpv->f_code = 1;
1805 s->m.pict_type = pic->pict_type;1860 mpv->pict_type = pic->pict_type;
1806 s->m.motion_est= s->motion_est;1861 mpv->motion_est = enc->motion_est;
1807 s->m.me.scene_change_score=0;1862 mpv->me.scene_change_score = 0;
1808 s->m.me.dia_size = avctx->dia_size;1863 mpv->me.dia_size = avctx->dia_size;
1809 s->m.quarter_sample= (s->avctx->flags & AV_CODEC_FLAG_QPEL)!=0;1864 mpv->quarter_sample = (s->avctx->flags & AV_CODEC_FLAG_QPEL)!=0;
1810 s->m.out_format= FMT_H263;1865 mpv->out_format = FMT_H263;
1811 s->m.unrestricted_mv= 1;1866 mpv->unrestricted_mv = 1;
1812 1867
1813 s->m.lambda = s->lambda;1868 mpv->lambda = enc->lambda;
1814 s->m.qscale= (s->m.lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7);1869 mpv->qscale = (mpv->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;1870 enc->lambda2 = mpv->lambda2 = (mpv->lambda*mpv->lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT;
1816 1871
1817 s->m.mecc= s->mecc; //move1872 mpv->mecc = enc->mecc; //move
1818 s->m.qdsp= s->qdsp; //move1873 mpv->qdsp = enc->qdsp; //move
1819 s->m.hdsp = s->hdsp;1874 mpv->hdsp = s->hdsp;
1820 ff_init_me(&s->m);1875 ff_init_me(&enc->m);
1821 s->hdsp = s->m.hdsp;1876 s->hdsp = mpv->hdsp;
1822 s->mecc= s->m.mecc;1877 enc->mecc = mpv->mecc;
1823 }1878 }
1824 1879
1825 if(s->pass1_rc){1880 if (enc->pass1_rc) {
1826 memcpy(rc_header_bak, s->header_state, sizeof(s->header_state));1881 memcpy(rc_header_bak, s->header_state, sizeof(s->header_state));
1827 memcpy(rc_block_bak, s->block_state, sizeof(s->block_state));1882 memcpy(rc_block_bak, s->block_state, sizeof(s->block_state));
1828 }1883 }
@@ -1840,7 +1895,7 @@ redo_frame: · 11 unmodified lines
1840 return AVERROR(EINVAL);1895 return AVERROR(EINVAL);
1841 }1896 }
1842 1897
1843 s->m.pict_type = pic->pict_type;1898 mpv->pict_type = pic->pict_type;
1844 s->qbias = pic->pict_type == AV_PICTURE_TYPE_P ? 2 : 0;1899 s->qbias = pic->pict_type == AV_PICTURE_TYPE_P ? 2 : 0;
1845 1900
1846 ff_snow_common_init_after_header(avctx);1901 ff_snow_common_init_after_header(avctx);
@@ -1852,9 +1907,9 @@ redo_frame: · 5 unmodified lines
1852 }1907 }
1853 1908
1854 encode_header(s);1909 encode_header(s);
1855 s->m.misc_bits = 8*(s->c.bytestream - s->c.bytestream_start);1910 mpv->misc_bits = 8 * (s->c.bytestream - s->c.bytestream_start);
1856 encode_blocks(s, 1);1911 encode_blocks(enc, 1);
1857 s->m.mv_bits = 8*(s->c.bytestream - s->c.bytestream_start) - s->m.misc_bits;1912 mpv->mv_bits = 8 * (s->c.bytestream - s->c.bytestream_start) - mpv->misc_bits;
1858 1913
1859 for(plane_index=0; plane_index < s->nb_planes; plane_index++){1914 for(plane_index=0; plane_index < s->nb_planes; plane_index++){
1860 Plane *p= &s->plane[plane_index];1915 Plane *p= &s->plane[plane_index];
@@ -1863,7 +1918,7 @@ redo_frame: · 2 unmodified lines
1863 int x, y;1918 int x, y;
1864// int bits= put_bits_count(&s->c.pb);1919// int bits= put_bits_count(&s->c.pb);
1865 1920
1866 if (!s->memc_only) {1921 if (!enc->memc_only) {
1867 //FIXME optimize1922 //FIXME optimize
1868 if(pict->data[plane_index]) //FIXME gray hack1923 if(pict->data[plane_index]) //FIXME gray hack
1869 for(y=0; y<h; y++){1924 for(y=0; y<h; y++){
@@ -1876,7 +1931,7 @@ redo_frame: · 6 unmodified lines
1876 if( plane_index==01931 if( plane_index==0
1877 && pic->pict_type == AV_PICTURE_TYPE_P1932 && pic->pict_type == AV_PICTURE_TYPE_P
1878 && !(avctx->flags&AV_CODEC_FLAG_PASS2)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 ff_init_range_encoder(c, pkt->data, pkt->size);1935 ff_init_range_encoder(c, pkt->data, pkt->size);
1881 ff_build_rac_states(c, (1LL<<32)/20, 256-8);1936 ff_build_rac_states(c, (1LL<<32)/20, 256-8);
1882 pic->pict_type= AV_PICTURE_TYPE_I;1937 pic->pict_type= AV_PICTURE_TYPE_I;
@@ -1901,8 +1956,8 @@ redo_frame: · 18 unmodified lines
1901 1956
1902 ff_spatial_dwt(s->spatial_dwt_buffer, s->temp_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count);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){1959 if (enc->pass1_rc && plane_index==0) {
1905 int delta_qlog = ratecontrol_1pass(s, pic);1960 int delta_qlog = ratecontrol_1pass(enc, pic);
1906 if (delta_qlog <= INT_MIN)1961 if (delta_qlog <= INT_MIN)
1907 return -1;1962 return -1;
1908 if(delta_qlog){1963 if(delta_qlog){
@@ -1911,7 +1966,7 @@ redo_frame: · 2 unmodified lines
1911 memcpy(s->header_state, rc_header_bak, sizeof(s->header_state));1966 memcpy(s->header_state, rc_header_bak, sizeof(s->header_state));
1912 memcpy(s->block_state, rc_block_bak, sizeof(s->block_state));1967 memcpy(s->block_state, rc_block_bak, sizeof(s->block_state));
1913 encode_header(s);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 quantize(s, b, b->ibuf, b->buf, b->stride, s->qbias);1977 quantize(s, b, b->ibuf, b->buf, b->stride, s->qbias);
1923 if(orientation==0)1978 if(orientation==0)
1924 decorrelate(s, b, b->ibuf, b->stride, pic->pict_type == AV_PICTURE_TYPE_P, 0);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 encode_subband(s, b, b->ibuf, b->parent ? b->parent->ibuf : NULL, b->stride, orientation);1981 encode_subband(s, b, b->ibuf, b->parent ? b->parent->ibuf : NULL, b->stride, orientation);
1927 av_assert0(b->parent==NULL || b->parent->stride == b->stride*2);1982 av_assert0(b->parent==NULL || b->parent->stride == b->stride*2);
1928 if(orientation==0)1983 if(orientation==0)
@@ -1972,7 +2027,7 @@ redo_frame: · 43 unmodified lines
1972 }2027 }
1973 }2028 }
1974 s->avctx->error[plane_index] += error;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 s->current_picture->pict_type = pic->pict_type;2040 s->current_picture->pict_type = pic->pict_type;
1986 s->current_picture->quality = pic->quality;2041 s->current_picture->quality = pic->quality;
1987 s->m.frame_bits = 8*(s->c.bytestream - s->c.bytestream_start);2042 mpv->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;2043 mpv->p_tex_bits = mpv->frame_bits - mpv->misc_bits - mpv->mv_bits;
1989 s->m.current_picture.display_picture_number =2044 mpv->total_bits += 8*(s->c.bytestream - s->c.bytestream_start);
1990 s->m.current_picture.coded_picture_number = avctx->frame_num;2045 mpv->current_picture.display_picture_number =
1991 s->m.current_picture.f->quality = pic->quality;2046 mpv->current_picture.coded_picture_number = avctx->frame_num;
1992 s->m.total_bits += 8*(s->c.bytestream - s->c.bytestream_start);2047 mpv->current_picture.f->quality = pic->quality;
1993 if(s->pass1_rc)2048 if (enc->pass1_rc)
1994 if (ff_rate_estimate_qscale(&s->m, 0) < 0)2049 if (ff_rate_estimate_qscale(mpv, 0) < 0)
1995 return -1;2050 return -1;
1996 if(avctx->flags&AV_CODEC_FLAG_PASS1)2051 if(avctx->flags&AV_CODEC_FLAG_PASS1)
1997 ff_write_pass1_stats(&s->m);2052 ff_write_pass1_stats(mpv);
1998 s->m.last_pict_type = s->m.pict_type;2053 mpv->last_pict_type = mpv->pict_type;
1999 2054
2000 emms_c();2055 emms_c();
2001 2056
2002 ff_side_data_set_encoder_stats(pkt, s->current_picture->quality,2057 ff_side_data_set_encoder_stats(pkt, s->current_picture->quality,
2003 s->encoding_error,2058 enc->encoding_error,
2004 (s->avctx->flags&AV_CODEC_FLAG_PSNR) ? SNOW_MAX_PLANES : 0,2059 (s->avctx->flags&AV_CODEC_FLAG_PSNR) ? SNOW_MAX_PLANES : 0,
2005 s->current_picture->pict_type);2060 s->current_picture->pict_type);
2006 if (s->avctx->flags & AV_CODEC_FLAG_RECON_FRAME) {2061 if (s->avctx->flags & AV_CODEC_FLAG_RECON_FRAME) {
@@ -2017,10 +2072,11 @@ redo_frame: · 10 unmodified lines
2017 2072
2018static av_cold int encode_end(AVCodecContext *avctx)2073static 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 ff_snow_common_end(s);2078 ff_snow_common_end(s);
2023 ff_rate_control_uninit(&s->m);2079 ff_rate_control_uninit(&enc->m);
2024 av_frame_free(&s->input_picture);2080 av_frame_free(&s->input_picture);
2025 2081
2026 for (int i = 0; i < MAX_REF_FRAMES; i++) {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 av_freep(&s->ref_scores[i]);2084 av_freep(&s->ref_scores[i]);
2029 }2085 }
2030 2086
2031 s->m.me.temp = NULL;2087 enc->m.me.temp = NULL;
2032 av_freep(&s->m.me.scratchpad);2088 av_freep(&enc->m.me.scratchpad);
2033 av_freep(&s->m.me.map);2089 av_freep(&enc->m.me.map);
2034 av_freep(&s->m.sc.obmc_scratchpad);2090 av_freep(&enc->m.sc.obmc_scratchpad);
2035 2091
2036 av_freep(&avctx->stats_out);2092 av_freep(&avctx->stats_out);
2037 2093
2038 return 0;2094 return 0;
2039}2095}
2040 2096
2041#define OFFSET(x) offsetof(SnowContext, x)2097#define OFFSET(x) offsetof(SnowEncContext, x)
2042#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM2098#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
2043static const AVOption options[] = {2099static const AVOption options[] = {
2044 {"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" },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 .p.capabilities = AV_CODEC_CAP_DR1 |2133 .p.capabilities = AV_CODEC_CAP_DR1 |
2078 AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |2134 AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
2079 AV_CODEC_CAP_ENCODER_RECON_FRAME,2135 AV_CODEC_CAP_ENCODER_RECON_FRAME,
2080 .priv_data_size = sizeof(SnowContext),2136 .priv_data_size = sizeof(SnowEncContext),
2081 .init = encode_init,2137 .init = encode_init,
2082 FF_CODEC_ENCODE_CB(encode_frame),2138 FF_CODEC_ENCODE_CB(encode_frame),
2083 .close = encode_end,2139 .close = encode_end,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t