last_pict_type, last_non_b_pict_type and last_lambda_for are only used by the encoder's main thread.
Unified · Split
| @@ -185,10 +185,7 @@ typedef struct MpegEncContext { · 184 unmodified lines | |||
| 185 | int adaptive_quant; ///< use adaptive quantization | 185 | int adaptive_quant; ///< use adaptive quantization |
| 186 | int dquant; ///< qscale difference to prev qscale | 186 | int dquant; ///< qscale difference to prev qscale |
| 187 | int pict_type; ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ... | 187 | 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 | ||
| 190 | int droppable; | 188 | int droppable; |
| 191 | int last_lambda_for[5]; ///< last lambda for a specific pict type | ||
| 192 | int skipdct; ///< skip dct and code zero residual | 189 | int skipdct; ///< skip dct and code zero residual |
| 193 | 190 | ||
| 194 | /* motion compensation */ | 191 | /* motion compensation */ |
| @@ -1515,9 +1515,9 @@ static int estimate_best_b_count(MPVMainEncContext *const m) · 1514 unmodified lines | |||
| 1515 | return AVERROR(ENOMEM); | 1515 | return AVERROR(ENOMEM); |
| 1516 | 1516 | ||
| 1517 | //emms_c(); | 1517 | //emms_c(); |
| 1518 | p_lambda = s->last_lambda_for[AV_PICTURE_TYPE_P]; | 1518 | p_lambda = m->last_lambda_for[AV_PICTURE_TYPE_P]; |
| 1519 | //p_lambda * FFABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset; | 1519 | //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]; |
| 1521 | if (!b_lambda) // FIXME we should do this somewhere else | 1521 | if (!b_lambda) // FIXME we should do this somewhere else |
| 1522 | b_lambda = p_lambda; | 1522 | b_lambda = p_lambda; |
| 1523 | lambda2 = (b_lambda * b_lambda + (1 << FF_LAMBDA_SHIFT) / 2) >> | 1523 | lambda2 = (b_lambda * b_lambda + (1 << FF_LAMBDA_SHIFT) / 2) >> |
| @@ -1871,10 +1871,10 @@ static void frame_end(MPVMainEncContext *const m) · 347 unmodified lines | |||
| 1871 | 1871 | ||
| 1872 | emms_c(); | 1872 | emms_c(); |
| 1873 | 1873 | ||
| 1874 | s->last_pict_type = s->pict_type; | 1874 | m->last_pict_type = s->pict_type; |
| 1875 | s->last_lambda_for [s->pict_type] = s->cur_pic.ptr->f->quality; | 1875 | m->last_lambda_for[s->pict_type] = s->cur_pic.ptr->f->quality; |
| 1876 | if (s->pict_type!= AV_PICTURE_TYPE_B) | 1876 | 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; |
| 1878 | } | 1878 | } |
| 1879 | 1879 | ||
| 1880 | static void update_noise_reduction(MPVMainEncContext *const m) | 1880 | 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 | |||
| 3702 | ff_get_2pass_fcode(m); | 3702 | ff_get_2pass_fcode(m); |
| 3703 | } else if (!(s->avctx->flags & AV_CODEC_FLAG_QSCALE)) { | 3703 | } else if (!(s->avctx->flags & AV_CODEC_FLAG_QSCALE)) { |
| 3704 | if(s->pict_type==AV_PICTURE_TYPE_B) | 3704 | 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]; |
| 3706 | else | 3706 | 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]; |
| 3708 | update_qscale(m); | 3708 | update_qscale(m); |
| 3709 | } | 3709 | } |
| 3710 | 3710 | ||
| @@ -3735,7 +3735,7 @@ static int encode_picture(MPVMainEncContext *const m, const AVPacket *pkt) · 24 unmodified lines | |||
| 3735 | s->lambda = (s->lambda * s->me_penalty_compensation + 128) >> 8; | 3735 | s->lambda = (s->lambda * s->me_penalty_compensation + 128) >> 8; |
| 3736 | s->lambda2 = (s->lambda2 * (int64_t) s->me_penalty_compensation + 128) >> 8; | 3736 | s->lambda2 = (s->lambda2 * (int64_t) s->me_penalty_compensation + 128) >> 8; |
| 3737 | if (s->pict_type != AV_PICTURE_TYPE_B) { | 3737 | 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) || |
| 3739 | s->me_pre == 2) { | 3739 | s->me_pre == 2) { |
| 3740 | s->avctx->execute(s->avctx, pre_estimate_motion_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); | 3740 | s->avctx->execute(s->avctx, pre_estimate_motion_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); |
| 3741 | } | 3741 | } |
| @@ -96,6 +96,9 @@ typedef struct MPVMainEncContext { · 95 unmodified lines | |||
| 96 | int stuffing_bits; ///< bits used for stuffing | 96 | int stuffing_bits; ///< bits used for stuffing |
| 97 | int next_lambda; ///< next lambda used for retrying to encode a frame | 97 | int next_lambda; ///< next lambda used for retrying to encode a frame |
| 98 | int fixed_qscale; ///< fixed qscale if non zero | 98 | 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 | ||
| 99 | RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c | 102 | RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c |
| 100 | 103 | ||
| 101 | int64_t mb_var_sum; ///< sum of MB variance for current frame | 104 | int64_t mb_var_sum; ///< sum of MB variance for current frame |
| @@ -203,8 +203,8 @@ static void find_best_tables(MSMPEG4EncContext *ms) · 202 unmodified lines | |||
| 203 | ms->rl_table_index = best; | 203 | ms->rl_table_index = best; |
| 204 | ms->rl_chroma_table_index = chroma_best; | 204 | ms->rl_chroma_table_index = chroma_best; |
| 205 | 205 | ||
| 206 | if(s->pict_type != s->last_non_b_pict_type){ | 206 | if (s->pict_type != ms->m.last_non_b_pict_type) { |
| 207 | ms->rl_table_index = 2; | 207 | ms->rl_table_index= 2; |
| 208 | if(s->pict_type==AV_PICTURE_TYPE_I) | 208 | if(s->pict_type==AV_PICTURE_TYPE_I) |
| 209 | ms->rl_chroma_table_index = 1; | 209 | ms->rl_chroma_table_index = 1; |
| 210 | else | 210 | else |
| @@ -940,10 +940,10 @@ float ff_rate_estimate_qscale(MPVMainEncContext *const m, int dry_run) · 939 unmodified lines | |||
| 940 | /* update predictors */ | 940 | /* update predictors */ |
| 941 | if (picture_number > 2 && !dry_run) { | 941 | if (picture_number > 2 && !dry_run) { |
| 942 | const int64_t last_var = | 942 | 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 |
| 944 | : rcc->last_mc_mb_var_sum; | 944 | : rcc->last_mc_mb_var_sum; |
| 945 | av_assert1(m->frame_bits >= m->stuffing_bits); | 945 | 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], |
| 947 | rcc->last_qscale, | 947 | rcc->last_qscale, |
| 948 | sqrt(last_var), | 948 | sqrt(last_var), |
| 949 | m->frame_bits - m->stuffing_bits); | 949 | m->frame_bits - m->stuffing_bits); |
| @@ -2058,7 +2058,7 @@ redo_frame: · 2057 unmodified lines | |||
| 2058 | } | 2058 | } |
| 2059 | if(avctx->flags&AV_CODEC_FLAG_PASS1) | 2059 | if(avctx->flags&AV_CODEC_FLAG_PASS1) |
| 2060 | ff_write_pass1_stats(&enc->m); | 2060 | ff_write_pass1_stats(&enc->m); |
| 2061 | mpv->last_pict_type = mpv->pict_type; | 2061 | enc->m.last_pict_type = mpv->pict_type; |
| 2062 | 2062 | ||
| 2063 | emms_c(); | 2063 | emms_c(); |
| 2064 | 2064 | ||