History

avcodec/mpegvideo: Move last-pic information to MPVMainEncContext

last_pict_type, last_non_b_pict_type and last_lambda_for are only used by the encoder's main thread.

Andreas Rheinhardt committed 4 years ago

Commit fa630b41 parent f293f956 files · +16 −16Browse files

Unified · Split

6 files
  1. libavcodec/mpegvideo.h +0 −3
  2. libavcodec/mpegvideo_enc.c +8 −8
  3. libavcodec/mpegvideoenc.h +3 −0
  4. libavcodec/msmpeg4enc.c +2 −2
  5. libavcodec/ratecontrol.c +2 −2
  6. libavcodec/snowenc.c +1 −1
libavcodec/mpegvideo.h+0−3
@@ -185,10 +185,7 @@ typedef struct MpegEncContext { · 184 unmodified lines
185185 int adaptive_quant; ///< use adaptive quantization
186186 int dquant; ///< qscale difference to prev qscale
187187 int pict_type; ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
188− int last_pict_type; //FIXME removes
189− int last_non_b_pict_type; ///< used for MPEG-4 gmc B-frames & ratecontrol
190188 int droppable;
191− int last_lambda_for[5]; ///< last lambda for a specific pict type
192189 int skipdct; ///< skip dct and code zero residual
193190
194191 /* motion compensation */
libavcodec/mpegvideo_enc.c+8−8
@@ -1515,9 +1515,9 @@ static int estimate_best_b_count(MPVMainEncContext *const m) · 1514 unmodified lines
15151515 return AVERROR(ENOMEM);
15161516
15171517 //emms_c();
1518− p_lambda = s->last_lambda_for[AV_PICTURE_TYPE_P];
1518+ p_lambda = m->last_lambda_for[AV_PICTURE_TYPE_P];
15191519 //p_lambda * FFABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset;
1520− b_lambda = s->last_lambda_for[AV_PICTURE_TYPE_B];
1520+ b_lambda = m->last_lambda_for[AV_PICTURE_TYPE_B];
15211521 if (!b_lambda) // FIXME we should do this somewhere else
15221522 b_lambda = p_lambda;
15231523 lambda2 = (b_lambda * b_lambda + (1 << FF_LAMBDA_SHIFT) / 2) >>
@@ -1871,10 +1871,10 @@ static void frame_end(MPVMainEncContext *const m) · 347 unmodified lines
18711871
18721872 emms_c();
18731873
1874− s->last_pict_type = s->pict_type;
1875− s->last_lambda_for [s->pict_type] = s->cur_pic.ptr->f->quality;
1874+ m->last_pict_type = s->pict_type;
1875+ m->last_lambda_for[s->pict_type] = s->cur_pic.ptr->f->quality;
18761876 if (s->pict_type!= AV_PICTURE_TYPE_B)
1877− s->last_non_b_pict_type = s->pict_type;
1877+ m->last_non_b_pict_type = s->pict_type;
18781878 }
18791879
18801880 static void update_noise_reduction(MPVMainEncContext *const m)
@@ -3702,9 +3702,9 @@ static int encode_picture(MPVMainEncContext *const m, const AVPacket *pkt) · 1821 unmodified lines
37023702 ff_get_2pass_fcode(m);
37033703 } else if (!(s->avctx->flags & AV_CODEC_FLAG_QSCALE)) {
37043704 if(s->pict_type==AV_PICTURE_TYPE_B)
3705− s->lambda= s->last_lambda_for[s->pict_type];
3705+ s->lambda = m->last_lambda_for[s->pict_type];
37063706 else
3707− s->lambda= s->last_lambda_for[s->last_non_b_pict_type];
3707+ s->lambda = m->last_lambda_for[m->last_non_b_pict_type];
37083708 update_qscale(m);
37093709 }
37103710
@@ -3735,7 +3735,7 @@ static int encode_picture(MPVMainEncContext *const m, const AVPacket *pkt) · 24 unmodified lines
37353735 s->lambda = (s->lambda * s->me_penalty_compensation + 128) >> 8;
37363736 s->lambda2 = (s->lambda2 * (int64_t) s->me_penalty_compensation + 128) >> 8;
37373737 if (s->pict_type != AV_PICTURE_TYPE_B) {
3738− if ((s->me_pre && s->last_non_b_pict_type == AV_PICTURE_TYPE_I) ||
3738+ if ((s->me_pre && m->last_non_b_pict_type == AV_PICTURE_TYPE_I) ||
37393739 s->me_pre == 2) {
37403740 s->avctx->execute(s->avctx, pre_estimate_motion_thread, &s->thread_context[0], NULL, context_count, sizeof(void*));
37413741 }
libavcodec/mpegvideoenc.h+3−0
@@ -96,6 +96,9 @@ typedef struct MPVMainEncContext { · 95 unmodified lines
9696 int stuffing_bits; ///< bits used for stuffing
9797 int next_lambda; ///< next lambda used for retrying to encode a frame
9898 int fixed_qscale; ///< fixed qscale if non zero
99+ int last_lambda_for[5]; ///< last lambda for a specific pict type
100+ int last_pict_type; //FIXME removes
101+ int last_non_b_pict_type; ///< used for MPEG-4 gmc B-frames & ratecontrol
99102 RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c
100103
101104 int64_t mb_var_sum; ///< sum of MB variance for current frame
libavcodec/msmpeg4enc.c+2−2
@@ -203,8 +203,8 @@ static void find_best_tables(MSMPEG4EncContext *ms) · 202 unmodified lines
203203 ms->rl_table_index = best;
204204 ms->rl_chroma_table_index = chroma_best;
205205
206− if(s->pict_type != s->last_non_b_pict_type){
207− ms->rl_table_index = 2;
206+ if (s->pict_type != ms->m.last_non_b_pict_type) {
207+ ms->rl_table_index= 2;
208208 if(s->pict_type==AV_PICTURE_TYPE_I)
209209 ms->rl_chroma_table_index = 1;
210210 else
libavcodec/ratecontrol.c+2−2
@@ -940,10 +940,10 @@ float ff_rate_estimate_qscale(MPVMainEncContext *const m, int dry_run) · 939 unmodified lines
940940 /* update predictors */
941941 if (picture_number > 2 && !dry_run) {
942942 const int64_t last_var =
943− s->last_pict_type == AV_PICTURE_TYPE_I ? rcc->last_mb_var_sum
943+ m->last_pict_type == AV_PICTURE_TYPE_I ? rcc->last_mb_var_sum
944944 : rcc->last_mc_mb_var_sum;
945945 av_assert1(m->frame_bits >= m->stuffing_bits);
946− update_predictor(&rcc->pred[s->last_pict_type],
946+ update_predictor(&rcc->pred[m->last_pict_type],
947947 rcc->last_qscale,
948948 sqrt(last_var),
949949 m->frame_bits - m->stuffing_bits);
libavcodec/snowenc.c+1−1
@@ -2058,7 +2058,7 @@ redo_frame: · 2057 unmodified lines
20582058 }
20592059 if(avctx->flags&AV_CODEC_FLAG_PASS1)
20602060 ff_write_pass1_stats(&enc->m);
2061− mpv->last_pict_type = mpv->pict_type;
2061+ enc->m.last_pict_type = mpv->pict_type;
20622062
20632063 emms_c();
20642064

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