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

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
2424
2525 #include "libavutil/motion_vector.h"
2626
27+#include "avcodec.h"
2728 #include "hpeldsp.h"
28−#include "me_cmp.h"
29−#include "qpeldsp.h"
3029 #include "snow_dwt.h"
3130
3231 #include "rangecoder.h"
3332 #include "mathops.h"
3433
35−#include "mpegvideo.h"
3634 #include "h264qpel.h"
35+#include "videodsp.h"
3736
3837 #define SNOW_MAX_PLANES 4
3938
40−#define FF_ME_ITER 3
41−
4239 #define MID_STATE 128
4340
4441 #define MAX_PLANES 4
@@ -117,12 +114,9 @@ typedef struct SnowContext{ · 72 unmodified lines
117114 AVClass *class;
118115 AVCodecContext *avctx;
119116 RangeCoder c;
120− MECmpContext mecc;
121117 HpelDSPContext hdsp;
122− QpelDSPContext qdsp;
123118 VideoDSPContext vdsp;
124119 H264QpelContext h264qpel;
125− MpegvideoEncDSPContext mpvencdsp;
126120 SnowDWTContext dwt;
127121 AVFrame *input_picture; ///< new_picture with the internal linesizes
128122 AVFrame *current_picture;
@@ -155,9 +149,6 @@ typedef struct SnowContext{ · 26 unmodified lines
155149 int spatial_scalability;
156150 int qlog;
157151 int last_qlog;
158− int lambda;
159− int lambda2;
160− int pass1_rc;
161152 int mv_scale;
162153 int last_mv_scale;
163154 int qbias;
@@ -170,18 +161,7 @@ typedef struct SnowContext{ · 6 unmodified lines
170161 int nb_planes;
171162 Plane plane[MAX_PLANES];
172163 BlockNode *block;
173−#define ME_CACHE_SIZE 1024
174− unsigned me_cache[ME_CACHE_SIZE];
175− unsigned me_cache_generation;
176164 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)
185165
186166 uint8_t *scratchbuf;
187167 uint8_t *emu_edge_buffer;
@@ -189,9 +169,6 @@ typedef struct SnowContext{ · 1 unmodified line
189169 AVMotionVector *avmv;
190170 unsigned avmv_size;
191171 int avmv_index;
192− uint64_t encoding_error[SNOW_MAX_PLANES];
193−
194− int pred;
195172 }SnowContext;
196173
197174 /* Tables */
libavcodec/snowenc.c+252−196
@@ -30,6 +30,7 @@ · 29 unmodified lines
3030 #include "internal.h" //For AVCodecInternal.recon_frame
3131 #include "me_cmp.h"
3232 #include "packet_internal.h"
33+#include "qpeldsp.h"
3334 #include "snow_dwt.h"
3435 #include "snow.h"
3536
@@ -39,6 +40,34 @@ · 3 unmodified lines
3940 #include "mpegvideo.h"
4041 #include "h263enc.h"
4142
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+
4271 static void init_ref(MotionEstContext *c, const uint8_t *const src[3],
4372 uint8_t *const ref[3], uint8_t *const ref2[3],
4473 int x, int y, int ref_index)
@@ -127,18 +156,20 @@ static int get_encode_buffer(SnowContext *s, AVFrame *frame) · 82 unmodified lines
127156
128157 static av_cold int encode_init(AVCodecContext *avctx)
129158 {
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;
131162 int plane_index, ret;
132163 int i;
133164
134− if(s->pred == DWT_97
165+ if (enc->pred == DWT_97
135166 && (avctx->flags & AV_CODEC_FLAG_QSCALE)
136167 && avctx->global_quality == 0){
137168 av_log(avctx, AV_LOG_ERROR, "The 9/7 wavelet is incompatible with lossless mode.\n");
138169 return AVERROR(EINVAL);
139170 }
140171
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
142173
143174 s->mv_scale = (avctx->flags & AV_CODEC_FLAG_QPEL) ? 2 : 4;
144175 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
159190 }
160191
161192 #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]=\
164195 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]=\
167198 s->h264qpel.put_h264_qpel_pixels_tab[1][dy+dx/4];
168199
169200 mcf( 0, 0)
@@ -183,28 +214,28 @@ static av_cold int encode_init(AVCodecContext *avctx) · 13 unmodified lines
183214 mcf( 8,12)
184215 mcf(12,12)
185216
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);
188219
189220 ff_snow_alloc_blocks(s);
190221
191222 s->version=0;
192223
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)
204235 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;
206237
207− ff_h263_encode_init(&s->m); //mv_penalty
238+ ff_h263_encode_init(mpv); //mv_penalty
208239
209240 s->max_ref_frames = av_clip(avctx->refs, 1, MAX_REF_FRAMES);
210241
@@ -216,11 +247,11 @@ static av_cold int encode_init(AVCodecContext *avctx) · 5 unmodified lines
216247 return AVERROR(ENOMEM);
217248 }
218249 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);
220251 if(ret < 0)
221252 return ret;
222253 }
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));
224255
225256 switch(avctx->pix_fmt){
226257 case AV_PIX_FMT_YUV444P:
@@ -245,8 +276,8 @@ static av_cold int encode_init(AVCodecContext *avctx) · 18 unmodified lines
245276 if (ret)
246277 return ret;
247278
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);
250281 if (ret < 0)
251282 return AVERROR(EINVAL);
252283
@@ -257,7 +288,7 @@ static av_cold int encode_init(AVCodecContext *avctx) · 4 unmodified lines
257288 if ((ret = get_encode_buffer(s, s->input_picture)) < 0)
258289 return ret;
259290
260− if(s->motion_est == FF_ME_ITER){
291+ if (enc->motion_est == FF_ME_ITER) {
261292 int size= s->b_width * s->b_height << 2*s->block_max_depth;
262293 for(i=0; i<s->max_ref_frames; i++){
263294 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
335366 #define P_MV1 P[9]
336367 #define FLAG_QPEL 1 //must be 1
337368
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;
339373 uint8_t p_buffer[1024];
340374 uint8_t i_buffer[1024];
341375 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
372406 int16_t last_mv[3][2];
373407 int qpel= !!(s->avctx->flags & AV_CODEC_FLAG_QPEL); //unused
374408 const int shift= 1+qpel;
375− MotionEstContext *c= &s->m.me;
376409 int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref);
377410 int mx_context= av_log2(2*FFABS(left->mx - top->mx));
378411 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
401434 last_mv[2][0]= bottom->mx;
402435 last_mv[2][1]= bottom->my;
403436
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;
407440 c->skip= 0;
408441
409442 av_assert1(c-> stride == stride);
410443 av_assert1(c->uvstride == uvstride);
411444
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;
416449
417450 c->xmin = - x*block_w - 16+3;
418451 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
443476 for(ref=0; ref<s->ref_frames; ref++){
444477 init_ref(c, current_data, s->last_picture[ref]->data, NULL, block_w*x, block_w*y, 0);
445478
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,
447480 (1<<16)>>shift, level-LOG2_MB_SIZE+4, block_w);
448481
449482 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
451484 av_assert2(ref_my >= c->ymin);
452485 av_assert2(ref_my <= c->ymax);
453486
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);
456489 ref_score+= 2*av_log2(2*ref)*c->penalty_factor;
457490 if(s->ref_mvs[ref]){
458491 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
484517 put_symbol(&pc, &p_state[128 + 32*(mx_context + 16*!!best_ref)], mx - pmx, 1);
485518 put_symbol(&pc, &p_state[128 + 32*(my_context + 16*!!best_ref)], my - pmy, 1);
486519 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;
488521
489522 block_s= block_w*block_w;
490523 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
515548 put_symbol(&ic, &i_state[96], cr-pcr, 1);
516549 }
517550 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;
519552
520− av_assert1(iscore < 255*255*256 + s->lambda2*10);
553+ av_assert1(iscore < 255*255*256 + enc->lambda2*10);
521554 av_assert1(iscore >= 0);
522555 av_assert1(l>=0 && l<=255);
523556 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
528561 if (vard <= 64 || vard < varc)
529562 c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc);
530563 else
531− c->scene_change_score+= s->m.qscale;
564+ c->scene_change_score += enc->m.qscale;
532565 }
533566
534567 if(level!=s->block_max_depth){
535568 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
541574
542575 if(score2 < score && score2 < iscore)
543576 return score2;
@@ -619,7 +652,9 @@ static void encode_q_branch2(SnowContext *s, int level, int x, int y){ · 75 unmodified lines
619652 }
620653 }
621654
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;
623658 int i, x2, y2;
624659 Plane *p= &s->plane[plane_index];
625660 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
629664 const int obmc_stride= plane_index ? (2*block_size)>>s->chroma_h_shift : 2*block_size;
630665 const int ref_stride= s->current_picture->linesize[plane_index];
631666 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
633668 const int b_stride = s->b_width << s->block_max_depth;
634669 const int w= p->width;
635670 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
715750 }
716751 }
717752
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;
719757 Plane *p= &s->plane[plane_index];
720758 const int block_size = MB_SIZE >> s->block_max_depth;
721759 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
724762 const int ref_stride= s->current_picture->linesize[plane_index];
725763 uint8_t *dst= s->current_picture->data[plane_index];
726764 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;
728766 uint8_t *cur = s->scratchbuf;
729767 uint8_t *tmp = s->emu_edge_buffer;
730768 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
733771 const int h= p->height;
734772 int distortion;
735773 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);
737775 int sx= block_w*mb_x - block_w/2;
738776 int sy= block_h*mb_y - block_h/2;
739777 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
787825 * to improve the score of the whole frame, thus iterative motion
788826 * estimation does not always converge. */
789827 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);
791829 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);
793831 else{
794832 distortion = 0;
795833 for(i=0; i<4; i++){
796834 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);
798836 }
799837 }
800838 }else{
801839 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);
803841 }
804842
805843 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
816854 return distortion + rate*penalty_factor;
817855 }
818856
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;
820860 int i, y2;
821861 Plane *p= &s->plane[plane_index];
822862 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
835875 const int h= p->height;
836876 int distortion= 0;
837877 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);
839879
840880 av_assert2(s->chroma_h_shift == s->chroma_v_shift); //obmc and square assumtions below
841881
@@ -863,7 +903,7 @@ static int get_4block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index){ · 21 unmodified lines
863903 }
864904
865905 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);
867907 }
868908
869909 if(plane_index==0){
@@ -1012,9 +1052,10 @@ static int encode_subband(SnowContext *s, SubBand *b, const IDWTELEM *src, const · 142 unmodified lines
10121052 // encode_subband_dzr(s, b, src, parent, stride, orientation);
10131053 }
10141054
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],
10161056 uint8_t (*obmc_edged)[MB_SIZE * 2], int *best_rd)
10171057 {
1058+ SnowContext *const s = &enc->com;
10181059 const int b_stride= s->b_width << s->block_max_depth;
10191060 BlockNode *block= &s->block[mb_x + mb_y * b_stride];
10201061 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
10281069 block->color[2] = p[2];
10291070 block->type |= BLOCK_INTRA;
10301071
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;
10321073
10331074 //FIXME chroma
10341075 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
10421083
10431084 /* special case for int[2] args we discard afterwards,
10441085 * 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;
10461091 const int b_stride = s->b_width << s->block_max_depth;
10471092 BlockNode *block = &s->block[mb_x + mb_y * b_stride];
10481093 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
10531098 av_assert2(mb_x < b_stride);
10541099
10551100 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)
10581103 return 0;
1059− s->me_cache[index] = value;
1104+ enc->me_cache[index] = value;
10601105
10611106 block->mx = p0;
10621107 block->my = p1;
10631108 block->type &= ~BLOCK_INTRA;
10641109
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);
10661111
10671112 //FIXME chroma
10681113 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
10741119 }
10751120 }
10761121
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;
10781126 const int b_stride= s->b_width << s->block_max_depth;
10791127 BlockNode *block= &s->block[mb_x + mb_y * b_stride];
10801128 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
10941142 av_assert2(((mb_x|mb_y)&1) == 0);
10951143
10961144 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)
10991147 return 0;
1100− s->me_cache[index]= value;
1148+ enc->me_cache[index] = value;
11011149
11021150 block->mx= p0;
11031151 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
11051153 block->type &= ~BLOCK_INTRA;
11061154 block[1]= block[b_stride]= block[b_stride+1]= *block;
11071155
1108− rd= get_4block_rd(s, mb_x, mb_y, 0);
1156+ rd = get_4block_rd(enc, mb_x, mb_y, 0);
11091157
11101158 //FIXME chroma
11111159 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
11201168 }
11211169 }
11221170
1123−static void iterative_me(SnowContext *s){
1171+static void iterative_me(SnowEncContext *enc)
1172+{
1173+ SnowContext *const s = &enc->com;
11241174 int pass, mb_x, mb_y;
11251175 const int b_width = s->b_width << s->block_max_depth;
11261176 const int b_height= s->b_height << s->block_max_depth;
@@ -1133,7 +1183,7 @@ static void iterative_me(SnowContext *s){ · 6 unmodified lines
11331183 memcpy(state, s->block_state, sizeof(s->block_state));
11341184 for(mb_y= 0; mb_y<s->b_height; mb_y++)
11351185 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);
11371187 s->c = r;
11381188 memcpy(s->block_state, state, sizeof(s->block_state));
11391189 }
@@ -1165,9 +1215,9 @@ static void iterative_me(SnowContext *s){ · 25 unmodified lines
11651215
11661216 backup= *block;
11671217
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;
11711221
11721222 //FIXME precalculate
11731223 {
@@ -1223,14 +1273,14 @@ static void iterative_me(SnowContext *s){ · 49 unmodified lines
12231273
12241274 // intra(black) = neighbors' contribution to the current block
12251275 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);
12271277
12281278 // get previous score (cannot be cached due to OBMC)
12291279 if(pass > 0 && (block->type&BLOCK_INTRA)){
12301280 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);
12321282 }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);
12341284
12351285 ref_b= *block;
12361286 ref_rd= best_rd;
@@ -1241,30 +1291,30 @@ static void iterative_me(SnowContext *s){ · 4 unmodified lines
12411291 block->ref= ref;
12421292 best_rd= INT_MAX;
12431293
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);
12461296 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);
12481298 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);
12501300 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);
12521302 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);
12541304
12551305 /* fullpel ME */
12561306 //FIXME avoid subpel interpolation / round to nearest integer
12571307 do{
12581308 int newx = block->mx;
12591309 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);
12611311 dia_change=0;
12621312 for(i=0; i < dia_size; i++){
12631313 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);
12681318 }
12691319 }
12701320 }while(dia_change);
@@ -1273,7 +1323,7 @@ static void iterative_me(SnowContext *s){ · 2 unmodified lines
12731323 static const int square[8][2]= {{+1, 0},{-1, 0},{ 0,+1},{ 0,-1},{+1,+1},{-1,-1},{+1,-1},{-1,+1},};
12741324 dia_change=0;
12751325 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);
12771327 }while(dia_change);
12781328 //FIXME or try the standard 2 pass qpel or similar
12791329
@@ -1286,7 +1336,7 @@ static void iterative_me(SnowContext *s){ · 6 unmodified lines
12861336 }
12871337 best_rd= ref_rd;
12881338 *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);
12901340 //FIXME RD style color selection
12911341 if(!same_block(block, &backup)){
12921342 if(tb ) tb ->type &= ~BLOCK_OPT;
@@ -1324,20 +1374,20 @@ static void iterative_me(SnowContext *s){ · 31 unmodified lines
13241374 same_block(b[0], b[3]))
13251375 continue;
13261376
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;
13301380
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);
13321382
13331383 //FIXME more multiref search?
1334− check_4block_inter(s, mb_x, mb_y,
1384+ check_4block_inter(enc, mb_x, mb_y,
13351385 (b[0]->mx + b[1]->mx + b[2]->mx + b[3]->mx + 2) >> 2,
13361386 (b[0]->my + b[1]->my + b[2]->my + b[3]->my + 2) >> 2, 0, &best_rd);
13371387
13381388 for(i=0; i<4; i++)
13391389 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);
13411391
13421392 if(init_rd != best_rd)
13431393 change++;
@@ -1347,13 +1397,15 @@ static void iterative_me(SnowContext *s){ · 3 unmodified lines
13471397 }
13481398 }
13491399
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;
13511403 int x, y;
13521404 int w= s->b_width;
13531405 int h= s->b_height;
13541406
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);
13571409
13581410 for(y=0; y<h; y++){
13591411 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
13611413 return;
13621414 }
13631415 for(x=0; x<w; x++){
1364− if(s->motion_est == FF_ME_ITER || !search)
1416+ if (enc->motion_est == FF_ME_ITER || !search)
13651417 encode_q_branch2(s, 0, x, y);
13661418 else
1367− encode_q_branch (s, 0, x, y);
1419+ encode_q_branch (enc, 0, x, y);
13681420 }
13691421 }
13701422 }
@@ -1611,8 +1663,9 @@ static int qscale2qlog(int qscale){ · 240 unmodified lines
16111663 + 61*QROOT/8; ///< 64 > 60
16121664 }
16131665
1614−static int ratecontrol_1pass(SnowContext *s, AVFrame *pict)
1666+static int ratecontrol_1pass(SnowEncContext *enc, AVFrame *pict)
16151667 {
1668+ SnowContext *const s = &enc->com;
16161669 /* Estimate the frame's complexity as a sum of weighted dwt coefficients.
16171670 * FIXME we know exact mv bits at this point,
16181671 * but ratecontrol isn't set up to include them. */
@@ -1647,17 +1700,17 @@ static int ratecontrol_1pass(SnowContext *s, AVFrame *pict) · 28 unmodified lines
16471700 coef_sum = (uint64_t)coef_sum * coef_sum >> 16;
16481701
16491702 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;
16521705 }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;
16551708 }
16561709
1657− pict->quality= ff_rate_estimate_qscale(&s->m, 1);
1710+ pict->quality= ff_rate_estimate_qscale(&enc->m, 1);
16581711 if (pict->quality < 0)
16591712 return INT_MIN;
1660− s->lambda= pict->quality * 3/2;
1713+ enc->lambda= pict->quality * 3/2;
16611714 delta_qlog= qscale2qlog(pict->quality) - s->qlog;
16621715 s->qlog+= delta_qlog;
16631716 return delta_qlog;
@@ -1696,7 +1749,9 @@ static void calculate_visual_weight(SnowContext *s, Plane *p){ · 32 unmodified lines
16961749 static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
16971750 const AVFrame *pict, int *got_packet)
16981751 {
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;
17001755 RangeCoder * const c= &s->c;
17011756 AVCodecInternal *avci = avctx->internal;
17021757 AVFrame *pic;
@@ -1719,7 +1774,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 16 unmodified lines
17191774 memcpy(&s->input_picture->data[i][y * s->input_picture->linesize[i]],
17201775 &pict->data[i][y * pict->linesize[i]],
17211776 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],
17231778 AV_CEIL_RSHIFT(width, hshift), AV_CEIL_RSHIFT(height, vshift),
17241779 EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift,
17251780 EDGE_TOP | EDGE_BOTTOM);
@@ -1730,45 +1785,45 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 4 unmodified lines
17301785 pic->pict_type = pict->pict_type;
17311786 pic->quality = pict->quality;
17321787
1733− s->m.picture_number= avctx->frame_num;
1788+ mpv->picture_number = avctx->frame_num;
17341789 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;
17361791 s->keyframe = pic->pict_type == AV_PICTURE_TYPE_I;
17371792 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);
17391794 if (pic->quality < 0)
17401795 return -1;
17411796 }
17421797 }else{
17431798 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;
17451800 }
17461801
1747− if(s->pass1_rc && avctx->frame_num == 0)
1802+ if (enc->pass1_rc && avctx->frame_num == 0)
17481803 pic->quality = 2*FF_QP2LAMBDA;
17491804 if (pic->quality) {
17501805 s->qlog = qscale2qlog(pic->quality);
1751− s->lambda = pic->quality * 3/2;
1806+ enc->lambda = pic->quality * 3/2;
17521807 }
17531808 if (s->qlog < 0 || (!pic->quality && (avctx->flags & AV_CODEC_FLAG_QSCALE))) {
17541809 s->qlog= LOSSLESS_QLOG;
1755− s->lambda = 0;
1810+ enc->lambda = 0;
17561811 }//else keep previous frame's qlog until after motion estimation
17571812
17581813 if (s->current_picture->data[0]) {
17591814 int w = s->avctx->width;
17601815 int h = s->avctx->height;
17611816
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);
17651820 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);
17721827 }
17731828 emms_c();
17741829 }
@@ -1778,9 +1833,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 3 unmodified lines
17781833 if (ret < 0)
17791834 return ret;
17801835
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;
17841839 if(pic->pict_type == AV_PICTURE_TYPE_P){
17851840 int block_width = (width +15)>>4;
17861841 int block_height= (height+15)>>4;
@@ -1789,40 +1844,40 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 2 unmodified lines
17891844 av_assert0(s->current_picture->data[0]);
17901845 av_assert0(s->last_picture[0]->data[0]);
17911846
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) {
18261881 memcpy(rc_header_bak, s->header_state, sizeof(s->header_state));
18271882 memcpy(rc_block_bak, s->block_state, sizeof(s->block_state));
18281883 }
@@ -1840,7 +1895,7 @@ redo_frame: · 11 unmodified lines
18401895 return AVERROR(EINVAL);
18411896 }
18421897
1843− s->m.pict_type = pic->pict_type;
1898+ mpv->pict_type = pic->pict_type;
18441899 s->qbias = pic->pict_type == AV_PICTURE_TYPE_P ? 2 : 0;
18451900
18461901 ff_snow_common_init_after_header(avctx);
@@ -1852,9 +1907,9 @@ redo_frame: · 5 unmodified lines
18521907 }
18531908
18541909 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;
18581913
18591914 for(plane_index=0; plane_index < s->nb_planes; plane_index++){
18601915 Plane *p= &s->plane[plane_index];
@@ -1863,7 +1918,7 @@ redo_frame: · 2 unmodified lines
18631918 int x, y;
18641919 // int bits= put_bits_count(&s->c.pb);
18651920
1866− if (!s->memc_only) {
1921+ if (!enc->memc_only) {
18671922 //FIXME optimize
18681923 if(pict->data[plane_index]) //FIXME gray hack
18691924 for(y=0; y<h; y++){
@@ -1876,7 +1931,7 @@ redo_frame: · 6 unmodified lines
18761931 if( plane_index==0
18771932 && pic->pict_type == AV_PICTURE_TYPE_P
18781933 && !(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) {
18801935 ff_init_range_encoder(c, pkt->data, pkt->size);
18811936 ff_build_rac_states(c, (1LL<<32)/20, 256-8);
18821937 pic->pict_type= AV_PICTURE_TYPE_I;
@@ -1901,8 +1956,8 @@ redo_frame: · 18 unmodified lines
19011956
19021957 ff_spatial_dwt(s->spatial_dwt_buffer, s->temp_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count);
19031958
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);
19061961 if (delta_qlog <= INT_MIN)
19071962 return -1;
19081963 if(delta_qlog){
@@ -1911,7 +1966,7 @@ redo_frame: · 2 unmodified lines
19111966 memcpy(s->header_state, rc_header_bak, sizeof(s->header_state));
19121967 memcpy(s->block_state, rc_block_bak, sizeof(s->block_state));
19131968 encode_header(s);
1914− encode_blocks(s, 0);
1969+ encode_blocks(enc, 0);
19151970 }
19161971 }
19171972
@@ -1922,7 +1977,7 @@ redo_frame: · 4 unmodified lines
19221977 quantize(s, b, b->ibuf, b->buf, b->stride, s->qbias);
19231978 if(orientation==0)
19241979 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)
19261981 encode_subband(s, b, b->ibuf, b->parent ? b->parent->ibuf : NULL, b->stride, orientation);
19271982 av_assert0(b->parent==NULL || b->parent->stride == b->stride*2);
19281983 if(orientation==0)
@@ -1972,7 +2027,7 @@ redo_frame: · 43 unmodified lines
19722027 }
19732028 }
19742029 s->avctx->error[plane_index] += error;
1975− s->encoding_error[plane_index] = error;
2030+ enc->encoding_error[plane_index] = error;
19762031 }
19772032
19782033 }
@@ -1984,23 +2039,23 @@ redo_frame: · 5 unmodified lines
19842039
19852040 s->current_picture->pict_type = pic->pict_type;
19862041 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)
19952050 return -1;
19962051 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;
19992054
20002055 emms_c();
20012056
20022057 ff_side_data_set_encoder_stats(pkt, s->current_picture->quality,
2003− s->encoding_error,
2058+ enc->encoding_error,
20042059 (s->avctx->flags&AV_CODEC_FLAG_PSNR) ? SNOW_MAX_PLANES : 0,
20052060 s->current_picture->pict_type);
20062061 if (s->avctx->flags & AV_CODEC_FLAG_RECON_FRAME) {
@@ -2017,10 +2072,11 @@ redo_frame: · 10 unmodified lines
20172072
20182073 static av_cold int encode_end(AVCodecContext *avctx)
20192074 {
2020− SnowContext *s = avctx->priv_data;
2075+ SnowEncContext *const enc = avctx->priv_data;
2076+ SnowContext *const s = &enc->com;
20212077
20222078 ff_snow_common_end(s);
2023− ff_rate_control_uninit(&s->m);
2079+ ff_rate_control_uninit(&enc->m);
20242080 av_frame_free(&s->input_picture);
20252081
20262082 for (int i = 0; i < MAX_REF_FRAMES; i++) {
@@ -2028,17 +2084,17 @@ static av_cold int encode_end(AVCodecContext *avctx) · 1 unmodified line
20282084 av_freep(&s->ref_scores[i]);
20292085 }
20302086
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);
20352091
20362092 av_freep(&avctx->stats_out);
20372093
20382094 return 0;
20392095 }
20402096
2041−#define OFFSET(x) offsetof(SnowContext, x)
2097+#define OFFSET(x) offsetof(SnowEncContext, x)
20422098 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
20432099 static const AVOption options[] = {
20442100 {"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
20772133 .p.capabilities = AV_CODEC_CAP_DR1 |
20782134 AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
20792135 AV_CODEC_CAP_ENCODER_RECON_FRAME,
2080− .priv_data_size = sizeof(SnowContext),
2136+ .priv_data_size = sizeof(SnowEncContext),
20812137 .init = encode_init,
20822138 FF_CODEC_ENCODE_CB(encode_frame),
20832139 .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