• Home
  • Raw
  • Download

Lines Matching refs:s

78 static int encode_picture(MpegEncContext *s, int picture_number);
79 static int dct_quantize_refine(MpegEncContext *s, int16_t *block, int16_t *weight, int16_t *orig, i…
80 static int sse_mb(MpegEncContext *s);
81 static void denoise_dct_c(MpegEncContext *s, int16_t *block);
82 static int dct_quantize_trellis_c(MpegEncContext *s, int16_t *block, int n, int qscale, int *overfl…
92 void ff_convert_matrix(MpegEncContext *s, int (*qmat)[64], in ff_convert_matrix() argument
97 FDCTDSPContext *fdsp = &s->fdsp; in ff_convert_matrix()
105 if (s->q_scale_type) qscale2 = ff_mpeg2_non_linear_qscale[qscale]; in ff_convert_matrix()
114 const int j = s->idsp.idct_permutation[i]; in ff_convert_matrix()
126 const int j = s->idsp.idct_permutation[i]; in ff_convert_matrix()
138 const int j = s->idsp.idct_permutation[i]; in ff_convert_matrix()
170 av_log(s->avctx, AV_LOG_INFO, in ff_convert_matrix()
176 static inline void update_qscale(MpegEncContext *s) in update_qscale() argument
178 if (s->q_scale_type == 1 && 0) { in update_qscale()
184 … int diff = FFABS((ff_mpeg2_non_linear_qscale[i]<<(FF_LAMBDA_SHIFT + 6)) - (int)s->lambda * 139); in update_qscale()
185 if (ff_mpeg2_non_linear_qscale[i] < s->avctx->qmin || in update_qscale()
186 (ff_mpeg2_non_linear_qscale[i] > s->avctx->qmax && !s->vbv_ignore_qmax)) in update_qscale()
193 s->qscale = best; in update_qscale()
195 s->qscale = (s->lambda * 139 + FF_LAMBDA_SCALE * 64) >> in update_qscale()
197 s->qscale = av_clip(s->qscale, s->avctx->qmin, s->vbv_ignore_qmax ? 31 : s->avctx->qmax); in update_qscale()
200 s->lambda2 = (s->lambda * s->lambda + FF_LAMBDA_SCALE / 2) >> in update_qscale()
220 void ff_init_qscale_tab(MpegEncContext *s) in ff_init_qscale_tab() argument
222 int8_t * const qscale_table = s->current_picture.qscale_table; in ff_init_qscale_tab()
225 for (i = 0; i < s->mb_num; i++) { in ff_init_qscale_tab()
226 unsigned int lam = s->lambda_table[s->mb_index2xy[i]]; in ff_init_qscale_tab()
228 qscale_table[s->mb_index2xy[i]] = av_clip(qp, s->avctx->qmin, in ff_init_qscale_tab()
229 s->avctx->qmax); in ff_init_qscale_tab()
262 static void mpv_encode_defaults(MpegEncContext *s) in mpv_encode_defaults() argument
266 ff_mpv_common_defaults(s); in mpv_encode_defaults()
270 s->me.mv_penalty = default_mv_penalty; in mpv_encode_defaults()
271 s->fcode_tab = default_fcode_tab; in mpv_encode_defaults()
273 s->input_picture_number = 0; in mpv_encode_defaults()
274 s->picture_in_gop_number = 0; in mpv_encode_defaults()
277 av_cold int ff_dct_encode_init(MpegEncContext *s) in ff_dct_encode_init() argument
280 ff_dct_encode_init_x86(s); in ff_dct_encode_init()
283 ff_h263dsp_init(&s->h263dsp); in ff_dct_encode_init()
284 if (!s->dct_quantize) in ff_dct_encode_init()
285 s->dct_quantize = ff_dct_quantize_c; in ff_dct_encode_init()
286 if (!s->denoise_dct) in ff_dct_encode_init()
287 s->denoise_dct = denoise_dct_c; in ff_dct_encode_init()
288 s->fast_dct_quantize = s->dct_quantize; in ff_dct_encode_init()
289 if (s->avctx->trellis) in ff_dct_encode_init()
290 s->dct_quantize = dct_quantize_trellis_c; in ff_dct_encode_init()
298 MpegEncContext *s = avctx->priv_data; in ff_mpv_encode_init() local
302 mpv_encode_defaults(s); in ff_mpv_encode_init()
356 s->chroma_format = CHROMA_444; in ff_mpv_encode_init()
360 s->chroma_format = CHROMA_422; in ff_mpv_encode_init()
365 s->chroma_format = CHROMA_420; in ff_mpv_encode_init()
374 s->rtp_payload_size = avctx->rtp_payload_size; in ff_mpv_encode_init()
376 s->me_penalty_compensation = avctx->me_penalty_compensation; in ff_mpv_encode_init()
378 s->me_pre = avctx->pre_me; in ff_mpv_encode_init()
382 s->bit_rate = avctx->bit_rate; in ff_mpv_encode_init()
383 s->width = avctx->width; in ff_mpv_encode_init()
384 s->height = avctx->height; in ff_mpv_encode_init()
392 s->gop_size = avctx->gop_size; in ff_mpv_encode_init()
393 s->avctx = avctx; in ff_mpv_encode_init()
399 s->max_b_frames = avctx->max_b_frames; in ff_mpv_encode_init()
400 s->codec_id = avctx->codec->id; in ff_mpv_encode_init()
401 s->strict_std_compliance = avctx->strict_std_compliance; in ff_mpv_encode_init()
402 s->quarter_sample = (avctx->flags & AV_CODEC_FLAG_QPEL) != 0; in ff_mpv_encode_init()
403 s->rtp_mode = !!s->rtp_payload_size; in ff_mpv_encode_init()
404 s->intra_dc_precision = avctx->intra_dc_precision; in ff_mpv_encode_init()
407 if (s->intra_dc_precision < 0) { in ff_mpv_encode_init()
408 s->intra_dc_precision += 8; in ff_mpv_encode_init()
409 } else if (s->intra_dc_precision >= 8) in ff_mpv_encode_init()
410 s->intra_dc_precision -= 8; in ff_mpv_encode_init()
412 if (s->intra_dc_precision < 0) { in ff_mpv_encode_init()
420 s->huffman = 0; in ff_mpv_encode_init()
422 if (s->intra_dc_precision > (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO ? 3 : 0)) { in ff_mpv_encode_init()
426 s->user_specified_pts = AV_NOPTS_VALUE; in ff_mpv_encode_init()
428 if (s->gop_size <= 1) { in ff_mpv_encode_init()
429 s->intra_only = 1; in ff_mpv_encode_init()
430 s->gop_size = 12; in ff_mpv_encode_init()
432 s->intra_only = 0; in ff_mpv_encode_init()
436 s->fixed_qscale = !!(avctx->flags & AV_CODEC_FLAG_QSCALE); in ff_mpv_encode_init()
438 s->adaptive_quant = (avctx->lumi_masking || in ff_mpv_encode_init()
443 s->border_masking || in ff_mpv_encode_init()
444 (s->mpv_flags & FF_MPV_FLAG_QP_RD)) && in ff_mpv_encode_init()
445 !s->fixed_qscale; in ff_mpv_encode_init()
447 s->loop_filter = !!(avctx->flags & AV_CODEC_FLAG_LOOP_FILTER); in ff_mpv_encode_init()
509 if (!s->fixed_qscale && in ff_mpv_encode_init()
523 (s->codec_id == AV_CODEC_ID_MPEG1VIDEO || in ff_mpv_encode_init()
524 s->codec_id == AV_CODEC_ID_MPEG2VIDEO) && in ff_mpv_encode_init()
532 if ((avctx->flags & AV_CODEC_FLAG_4MV) && s->codec_id != AV_CODEC_ID_MPEG4 && in ff_mpv_encode_init()
533 s->codec_id != AV_CODEC_ID_H263 && s->codec_id != AV_CODEC_ID_H263P && in ff_mpv_encode_init()
534 s->codec_id != AV_CODEC_ID_FLV1) { in ff_mpv_encode_init()
539 if (s->obmc && avctx->mb_decision != FF_MB_DECISION_SIMPLE) { in ff_mpv_encode_init()
545 if (s->quarter_sample && s->codec_id != AV_CODEC_ID_MPEG4) { in ff_mpv_encode_init()
550 if (s->max_b_frames && in ff_mpv_encode_init()
551 s->codec_id != AV_CODEC_ID_MPEG4 && in ff_mpv_encode_init()
552 s->codec_id != AV_CODEC_ID_MPEG1VIDEO && in ff_mpv_encode_init()
553 s->codec_id != AV_CODEC_ID_MPEG2VIDEO) { in ff_mpv_encode_init()
557 if (s->max_b_frames < 0) { in ff_mpv_encode_init()
563 if ((s->codec_id == AV_CODEC_ID_MPEG4 || in ff_mpv_encode_init()
564 s->codec_id == AV_CODEC_ID_H263 || in ff_mpv_encode_init()
565 s->codec_id == AV_CODEC_ID_H263P) && in ff_mpv_encode_init()
575 if ((s->codec_id == AV_CODEC_ID_H263 || in ff_mpv_encode_init()
576 s->codec_id == AV_CODEC_ID_H263P) && in ff_mpv_encode_init()
582 if ((s->codec_id == AV_CODEC_ID_H263 || in ff_mpv_encode_init()
583 s->codec_id == AV_CODEC_ID_H263P) && in ff_mpv_encode_init()
590 if (s->codec_id == AV_CODEC_ID_MPEG1VIDEO && in ff_mpv_encode_init()
597 if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && in ff_mpv_encode_init()
604 if (s->codec_id == AV_CODEC_ID_RV10 && in ff_mpv_encode_init()
611 if (s->codec_id == AV_CODEC_ID_RV20 && in ff_mpv_encode_init()
618 if ((s->codec_id == AV_CODEC_ID_WMV1 || in ff_mpv_encode_init()
619 s->codec_id == AV_CODEC_ID_WMV2) && in ff_mpv_encode_init()
626 s->codec_id != AV_CODEC_ID_MPEG4 && s->codec_id != AV_CODEC_ID_MPEG2VIDEO) { in ff_mpv_encode_init()
634 s->mpeg_quant = 1; in ff_mpv_encode_init()
639 if (s->mpeg_quant && ( s->codec_id != AV_CODEC_ID_MPEG4 in ff_mpv_encode_init()
640 && s->codec_id != AV_CODEC_ID_MPEG2VIDEO)) { in ff_mpv_encode_init()
646 if ((s->mpv_flags & FF_MPV_FLAG_CBP_RD) && !avctx->trellis) { in ff_mpv_encode_init()
651 if ((s->mpv_flags & FF_MPV_FLAG_QP_RD) && in ff_mpv_encode_init()
657 if ((s->mpv_flags & FF_MPV_FLAG_QP_RD) && in ff_mpv_encode_init()
658 (s->codec_id == AV_CODEC_ID_AMV || in ff_mpv_encode_init()
659 s->codec_id == AV_CODEC_ID_MJPEG)) { in ff_mpv_encode_init()
669 s->scenechange_threshold = avctx->scenechange_threshold; in ff_mpv_encode_init()
673 if (s->scenechange_threshold < 1000000000 && in ff_mpv_encode_init()
682 if (s->codec_id != AV_CODEC_ID_MPEG2VIDEO && in ff_mpv_encode_init()
683 s->strict_std_compliance >= FF_COMPLIANCE_NORMAL) { in ff_mpv_encode_init()
689 if (s->max_b_frames != 0) { in ff_mpv_encode_init()
696 if (s->q_scale_type == 1) { in ff_mpv_encode_init()
711 s->codec_id != AV_CODEC_ID_MPEG4 && in ff_mpv_encode_init()
712 s->codec_id != AV_CODEC_ID_MPEG1VIDEO && in ff_mpv_encode_init()
713 s->codec_id != AV_CODEC_ID_MPEG2VIDEO && in ff_mpv_encode_init()
714 s->codec_id != AV_CODEC_ID_MJPEG && in ff_mpv_encode_init()
715 (s->codec_id != AV_CODEC_ID_H263P)) { in ff_mpv_encode_init()
736 s->b_frame_strategy = avctx->b_frame_strategy; in ff_mpv_encode_init()
738 s->b_sensitivity = avctx->b_sensitivity; in ff_mpv_encode_init()
742 if (s->b_frame_strategy && (avctx->flags & AV_CODEC_FLAG_PASS2)) { in ff_mpv_encode_init()
745 s->b_frame_strategy = 0; in ff_mpv_encode_init()
756s->mpeg_quant || s->codec_id == AV_CODEC_ID_MPEG1VIDEO || s->codec_id == AV_CODEC_ID_MPEG2VIDEO ||… in ff_mpv_encode_init()
758 s->intra_quant_bias = 3 << (QUANT_BIAS_SHIFT - 3); in ff_mpv_encode_init()
759 s->inter_quant_bias = 0; in ff_mpv_encode_init()
761 s->intra_quant_bias = 0; in ff_mpv_encode_init()
763 s->inter_quant_bias = -(1 << (QUANT_BIAS_SHIFT - 2)); in ff_mpv_encode_init()
771 …tx, AV_LOG_DEBUG, "intra_quant_bias = %d inter_quant_bias = %d\n",s->intra_quant_bias,s->inter_qua… in ff_mpv_encode_init()
782 s->time_increment_bits = av_log2(avctx->time_base.den - 1) + 1; in ff_mpv_encode_init()
786 s->out_format = FMT_MPEG1; in ff_mpv_encode_init()
787 s->low_delay = !!(avctx->flags & AV_CODEC_FLAG_LOW_DELAY); in ff_mpv_encode_init()
788 avctx->delay = s->low_delay ? 0 : (s->max_b_frames + 1); in ff_mpv_encode_init()
791 s->out_format = FMT_MPEG1; in ff_mpv_encode_init()
792 s->low_delay = !!(avctx->flags & AV_CODEC_FLAG_LOW_DELAY); in ff_mpv_encode_init()
793 avctx->delay = s->low_delay ? 0 : (s->max_b_frames + 1); in ff_mpv_encode_init()
794 s->rtp_mode = 1; in ff_mpv_encode_init()
798 s->out_format = FMT_MJPEG; in ff_mpv_encode_init()
799 s->intra_only = 1; /* force intra only for jpeg */ in ff_mpv_encode_init()
802 if ((ret = ff_mjpeg_encode_init(s)) < 0) in ff_mpv_encode_init()
805 s->low_delay = 1; in ff_mpv_encode_init()
808 s->out_format = FMT_SPEEDHQ; in ff_mpv_encode_init()
809 s->intra_only = 1; /* force intra only for SHQ */ in ff_mpv_encode_init()
812 if ((ret = ff_speedhq_encode_init(s)) < 0) in ff_mpv_encode_init()
815 s->low_delay = 1; in ff_mpv_encode_init()
820 if (ff_h261_get_picture_format(s->width, s->height) < 0) { in ff_mpv_encode_init()
824 s->width, s->height); in ff_mpv_encode_init()
827 s->out_format = FMT_H261; in ff_mpv_encode_init()
829 s->low_delay = 1; in ff_mpv_encode_init()
830 s->rtp_mode = 0; /* Sliced encoding not supported */ in ff_mpv_encode_init()
836 s->width, s->height) == 8) { in ff_mpv_encode_init()
841 "Try H.263+.\n", s->width, s->height); in ff_mpv_encode_init()
844 s->out_format = FMT_H263; in ff_mpv_encode_init()
846 s->low_delay = 1; in ff_mpv_encode_init()
849 s->out_format = FMT_H263; in ff_mpv_encode_init()
850 s->h263_plus = 1; in ff_mpv_encode_init()
852 s->h263_aic = (avctx->flags & AV_CODEC_FLAG_AC_PRED) ? 1 : 0; in ff_mpv_encode_init()
853 s->modified_quant = s->h263_aic; in ff_mpv_encode_init()
854 s->loop_filter = (avctx->flags & AV_CODEC_FLAG_LOOP_FILTER) ? 1 : 0; in ff_mpv_encode_init()
855 s->unrestricted_mv = s->obmc || s->loop_filter || s->umvplus; in ff_mpv_encode_init()
860 s->low_delay = 1; in ff_mpv_encode_init()
863 s->out_format = FMT_H263; in ff_mpv_encode_init()
864 s->h263_flv = 2; /* format = 1; 11-bit codes */ in ff_mpv_encode_init()
865 s->unrestricted_mv = 1; in ff_mpv_encode_init()
866 s->rtp_mode = 0; /* don't allow GOB */ in ff_mpv_encode_init()
868 s->low_delay = 1; in ff_mpv_encode_init()
871 s->out_format = FMT_H263; in ff_mpv_encode_init()
873 s->low_delay = 1; in ff_mpv_encode_init()
876 s->out_format = FMT_H263; in ff_mpv_encode_init()
878 s->low_delay = 1; in ff_mpv_encode_init()
879 s->modified_quant = 1; in ff_mpv_encode_init()
880 s->h263_aic = 1; in ff_mpv_encode_init()
881 s->h263_plus = 1; in ff_mpv_encode_init()
882 s->loop_filter = 1; in ff_mpv_encode_init()
883 s->unrestricted_mv = 0; in ff_mpv_encode_init()
886 s->out_format = FMT_H263; in ff_mpv_encode_init()
887 s->h263_pred = 1; in ff_mpv_encode_init()
888 s->unrestricted_mv = 1; in ff_mpv_encode_init()
889 s->low_delay = s->max_b_frames ? 0 : 1; in ff_mpv_encode_init()
890 avctx->delay = s->low_delay ? 0 : (s->max_b_frames + 1); in ff_mpv_encode_init()
893 s->out_format = FMT_H263; in ff_mpv_encode_init()
894 s->h263_pred = 1; in ff_mpv_encode_init()
895 s->unrestricted_mv = 1; in ff_mpv_encode_init()
896 s->msmpeg4_version = 2; in ff_mpv_encode_init()
898 s->low_delay = 1; in ff_mpv_encode_init()
901 s->out_format = FMT_H263; in ff_mpv_encode_init()
902 s->h263_pred = 1; in ff_mpv_encode_init()
903 s->unrestricted_mv = 1; in ff_mpv_encode_init()
904 s->msmpeg4_version = 3; in ff_mpv_encode_init()
905 s->flipflop_rounding = 1; in ff_mpv_encode_init()
907 s->low_delay = 1; in ff_mpv_encode_init()
910 s->out_format = FMT_H263; in ff_mpv_encode_init()
911 s->h263_pred = 1; in ff_mpv_encode_init()
912 s->unrestricted_mv = 1; in ff_mpv_encode_init()
913 s->msmpeg4_version = 4; in ff_mpv_encode_init()
914 s->flipflop_rounding = 1; in ff_mpv_encode_init()
916 s->low_delay = 1; in ff_mpv_encode_init()
919 s->out_format = FMT_H263; in ff_mpv_encode_init()
920 s->h263_pred = 1; in ff_mpv_encode_init()
921 s->unrestricted_mv = 1; in ff_mpv_encode_init()
922 s->msmpeg4_version = 5; in ff_mpv_encode_init()
923 s->flipflop_rounding = 1; in ff_mpv_encode_init()
925 s->low_delay = 1; in ff_mpv_encode_init()
934 s->noise_reduction = avctx->noise_reduction; in ff_mpv_encode_init()
938 avctx->has_b_frames = !s->low_delay; in ff_mpv_encode_init()
940 s->encoding = 1; in ff_mpv_encode_init()
942 s->progressive_frame = in ff_mpv_encode_init()
943 s->progressive_sequence = !(avctx->flags & (AV_CODEC_FLAG_INTERLACED_DCT | in ff_mpv_encode_init()
945 s->alternate_scan); in ff_mpv_encode_init()
948 ff_mpv_idct_init(s); in ff_mpv_encode_init()
949 if ((ret = ff_mpv_common_init(s)) < 0) in ff_mpv_encode_init()
952 ff_fdctdsp_init(&s->fdsp, avctx); in ff_mpv_encode_init()
953 ff_me_cmp_init(&s->mecc, avctx); in ff_mpv_encode_init()
954 ff_mpegvideoencdsp_init(&s->mpvencdsp, avctx); in ff_mpv_encode_init()
955 ff_pixblockdsp_init(&s->pdsp, avctx); in ff_mpv_encode_init()
956 ff_qpeldsp_init(&s->qdsp); in ff_mpv_encode_init()
958 if (s->msmpeg4_version) { in ff_mpv_encode_init()
960 if (!(s->ac_stats = av_mallocz(ac_stats_size))) in ff_mpv_encode_init()
965 !FF_ALLOCZ_TYPED_ARRAY(s->q_intra_matrix, 32) || in ff_mpv_encode_init()
966 !FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix, 32) || in ff_mpv_encode_init()
967 !FF_ALLOCZ_TYPED_ARRAY(s->q_inter_matrix, 32) || in ff_mpv_encode_init()
968 !FF_ALLOCZ_TYPED_ARRAY(s->q_intra_matrix16, 32) || in ff_mpv_encode_init()
969 !FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix16, 32) || in ff_mpv_encode_init()
970 !FF_ALLOCZ_TYPED_ARRAY(s->q_inter_matrix16, 32) || in ff_mpv_encode_init()
971 !FF_ALLOCZ_TYPED_ARRAY(s->input_picture, MAX_PICTURE_COUNT) || in ff_mpv_encode_init()
972 !FF_ALLOCZ_TYPED_ARRAY(s->reordered_input_picture, MAX_PICTURE_COUNT)) in ff_mpv_encode_init()
975 if (s->noise_reduction) { in ff_mpv_encode_init()
976 if (!FF_ALLOCZ_TYPED_ARRAY(s->dct_offset, 2)) in ff_mpv_encode_init()
980 ff_dct_encode_init(s); in ff_mpv_encode_init()
982 if ((CONFIG_H263P_ENCODER || CONFIG_RV20_ENCODER) && s->modified_quant) in ff_mpv_encode_init()
983 s->chroma_qscale_table = ff_h263_chroma_qscale_table; in ff_mpv_encode_init()
985 if (s->slice_context_count > 1) { in ff_mpv_encode_init()
986 s->rtp_mode = 1; in ff_mpv_encode_init()
989 s->h263_slice_structured = 1; in ff_mpv_encode_init()
992 s->quant_precision = 5; in ff_mpv_encode_init()
997 s->frame_skip_threshold = avctx->frame_skip_threshold; in ff_mpv_encode_init()
999 s->frame_skip_factor = avctx->frame_skip_factor; in ff_mpv_encode_init()
1001 s->frame_skip_exp = avctx->frame_skip_exp; in ff_mpv_encode_init()
1003 s->frame_skip_cmp = avctx->frame_skip_cmp; in ff_mpv_encode_init()
1007 ff_set_cmp(&s->mecc, s->mecc.ildct_cmp, avctx->ildct_cmp); in ff_mpv_encode_init()
1008 ff_set_cmp(&s->mecc, s->mecc.frame_skip_cmp, s->frame_skip_cmp); in ff_mpv_encode_init()
1010 if (CONFIG_H261_ENCODER && s->out_format == FMT_H261) in ff_mpv_encode_init()
1011 ff_h261_encode_init(s); in ff_mpv_encode_init()
1012 if (CONFIG_H263_ENCODER && s->out_format == FMT_H263) in ff_mpv_encode_init()
1013 ff_h263_encode_init(s); in ff_mpv_encode_init()
1014 if (CONFIG_MSMPEG4_ENCODER && s->msmpeg4_version) in ff_mpv_encode_init()
1015 ff_msmpeg4_encode_init(s); in ff_mpv_encode_init()
1017 && s->out_format == FMT_MPEG1) in ff_mpv_encode_init()
1018 ff_mpeg1_encode_init(s); in ff_mpv_encode_init()
1022 int j = s->idsp.idct_permutation[i]; in ff_mpv_encode_init()
1023 if (CONFIG_MPEG4_ENCODER && s->codec_id == AV_CODEC_ID_MPEG4 && in ff_mpv_encode_init()
1024 s->mpeg_quant) { in ff_mpv_encode_init()
1025 s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i]; in ff_mpv_encode_init()
1026 s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i]; in ff_mpv_encode_init()
1027 } else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) { in ff_mpv_encode_init()
1028 s->intra_matrix[j] = in ff_mpv_encode_init()
1029 s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; in ff_mpv_encode_init()
1030 } else if (CONFIG_SPEEDHQ_ENCODER && s->codec_id == AV_CODEC_ID_SPEEDHQ) { in ff_mpv_encode_init()
1031 s->intra_matrix[j] = in ff_mpv_encode_init()
1032 s->inter_matrix[j] = ff_mpeg1_default_intra_matrix[i]; in ff_mpv_encode_init()
1035 s->chroma_intra_matrix[j] = in ff_mpv_encode_init()
1036 s->intra_matrix[j] = ff_mpeg1_default_intra_matrix[i]; in ff_mpv_encode_init()
1037 s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; in ff_mpv_encode_init()
1040 s->intra_matrix[j] = avctx->intra_matrix[i]; in ff_mpv_encode_init()
1042 s->inter_matrix[j] = avctx->inter_matrix[i]; in ff_mpv_encode_init()
1047 if (s->out_format != FMT_MJPEG) { in ff_mpv_encode_init()
1048 ff_convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16, in ff_mpv_encode_init()
1049 s->intra_matrix, s->intra_quant_bias, avctx->qmin, in ff_mpv_encode_init()
1051 ff_convert_matrix(s, s->q_inter_matrix, s->q_inter_matrix16, in ff_mpv_encode_init()
1052 s->inter_matrix, s->inter_quant_bias, avctx->qmin, in ff_mpv_encode_init()
1056 if ((ret = ff_rate_control_init(s)) < 0) in ff_mpv_encode_init()
1062 s->brd_scale = avctx->brd_scale; in ff_mpv_encode_init()
1065 s->pred = avctx->prediction_method + 1; in ff_mpv_encode_init()
1069 if (s->b_frame_strategy == 2) { in ff_mpv_encode_init()
1070 for (i = 0; i < s->max_b_frames + 2; i++) { in ff_mpv_encode_init()
1071 s->tmp_frames[i] = av_frame_alloc(); in ff_mpv_encode_init()
1072 if (!s->tmp_frames[i]) in ff_mpv_encode_init()
1075 s->tmp_frames[i]->format = AV_PIX_FMT_YUV420P; in ff_mpv_encode_init()
1076 s->tmp_frames[i]->width = s->width >> s->brd_scale; in ff_mpv_encode_init()
1077 s->tmp_frames[i]->height = s->height >> s->brd_scale; in ff_mpv_encode_init()
1079 ret = av_frame_get_buffer(s->tmp_frames[i], 0); in ff_mpv_encode_init()
1098 MpegEncContext *s = avctx->priv_data; in ff_mpv_encode_end() local
1101 ff_rate_control_uninit(s); in ff_mpv_encode_end()
1103 ff_mpv_common_end(s); in ff_mpv_encode_end()
1105 s->out_format == FMT_MJPEG) in ff_mpv_encode_end()
1106 ff_mjpeg_encode_close(s); in ff_mpv_encode_end()
1110 for (i = 0; i < FF_ARRAY_ELEMS(s->tmp_frames); i++) in ff_mpv_encode_end()
1111 av_frame_free(&s->tmp_frames[i]); in ff_mpv_encode_end()
1113 ff_free_picture_tables(&s->new_picture); in ff_mpv_encode_end()
1114 ff_mpeg_unref_picture(avctx, &s->new_picture); in ff_mpv_encode_end()
1117 av_freep(&s->ac_stats); in ff_mpv_encode_end()
1119 if(s->q_chroma_intra_matrix != s->q_intra_matrix ) av_freep(&s->q_chroma_intra_matrix); in ff_mpv_encode_end()
1120 if(s->q_chroma_intra_matrix16 != s->q_intra_matrix16) av_freep(&s->q_chroma_intra_matrix16); in ff_mpv_encode_end()
1121 s->q_chroma_intra_matrix= NULL; in ff_mpv_encode_end()
1122 s->q_chroma_intra_matrix16= NULL; in ff_mpv_encode_end()
1123 av_freep(&s->q_intra_matrix); in ff_mpv_encode_end()
1124 av_freep(&s->q_inter_matrix); in ff_mpv_encode_end()
1125 av_freep(&s->q_intra_matrix16); in ff_mpv_encode_end()
1126 av_freep(&s->q_inter_matrix16); in ff_mpv_encode_end()
1127 av_freep(&s->input_picture); in ff_mpv_encode_end()
1128 av_freep(&s->reordered_input_picture); in ff_mpv_encode_end()
1129 av_freep(&s->dct_offset); in ff_mpv_encode_end()
1148 static int get_intra_count(MpegEncContext *s, uint8_t *src, in get_intra_count() argument
1154 w = s->width & ~15; in get_intra_count()
1155 h = s->height & ~15; in get_intra_count()
1160 int sad = s->mecc.sad[0](NULL, src + offset, ref + offset, in get_intra_count()
1162 int mean = (s->mpvencdsp.pix_sum(src + offset, stride) + 128) >> 8; in get_intra_count()
1171 static int alloc_picture(MpegEncContext *s, Picture *pic, int shared) in alloc_picture() argument
1173 return ff_alloc_picture(s->avctx, pic, &s->me, &s->sc, shared, 1, in alloc_picture()
1174 s->chroma_x_shift, s->chroma_y_shift, s->out_format, in alloc_picture()
1175 s->mb_stride, s->mb_width, s->mb_height, s->b8_stride, in alloc_picture()
1176 &s->linesize, &s->uvlinesize); in alloc_picture()
1179 static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg) in load_input_picture() argument
1184 int encoding_delay = s->max_b_frames ? s->max_b_frames in load_input_picture()
1185 : (s->low_delay ? 0 : 1); in load_input_picture()
1191 display_picture_number = s->input_picture_number++; in load_input_picture()
1194 if (s->user_specified_pts != AV_NOPTS_VALUE) { in load_input_picture()
1195 int64_t last = s->user_specified_pts; in load_input_picture()
1198 av_log(s->avctx, AV_LOG_ERROR, in load_input_picture()
1204 if (!s->low_delay && display_picture_number == 1) in load_input_picture()
1205 s->dts_delta = pts - last; in load_input_picture()
1207 s->user_specified_pts = pts; in load_input_picture()
1209 if (s->user_specified_pts != AV_NOPTS_VALUE) { in load_input_picture()
1210 s->user_specified_pts = in load_input_picture()
1211 pts = s->user_specified_pts + 1; in load_input_picture()
1212 av_log(s->avctx, AV_LOG_INFO, in load_input_picture()
1221 pic_arg->linesize[0] != s->linesize || in load_input_picture()
1222 pic_arg->linesize[1] != s->uvlinesize || in load_input_picture()
1223 pic_arg->linesize[2] != s->uvlinesize) in load_input_picture()
1225 if ((s->width & 15) || (s->height & 15)) in load_input_picture()
1229 if (s->linesize & (STRIDE_ALIGN-1)) in load_input_picture()
1232 ff_dlog(s->avctx, "%d %d %"PTRDIFF_SPECIFIER" %"PTRDIFF_SPECIFIER"\n", pic_arg->linesize[0], in load_input_picture()
1233 pic_arg->linesize[1], s->linesize, s->uvlinesize); in load_input_picture()
1235 i = ff_find_unused_picture(s->avctx, s->picture, direct); in load_input_picture()
1239 pic = &s->picture[i]; in load_input_picture()
1246 ret = alloc_picture(s, pic, direct); in load_input_picture()
1257 av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, in load_input_picture()
1263 int dst_stride = i ? s->uvlinesize : s->linesize; in load_input_picture()
1266 int w = s->width >> h_shift; in load_input_picture()
1267 int h = s->height >> v_shift; in load_input_picture()
1272 if ( s->codec_id == AV_CODEC_ID_MPEG2VIDEO in load_input_picture()
1273 && !s->progressive_sequence in load_input_picture()
1274 && FFALIGN(s->height, 32) - s->height > 16) in load_input_picture()
1277 if (!s->avctx->rc_buffer_size) in load_input_picture()
1291 if ((s->width & 15) || (s->height & (vpad-1))) { in load_input_picture()
1292 s->mpvencdsp.draw_edges(dst, dst_stride, in load_input_picture()
1312 if (s->input_picture[flush_offset]) in load_input_picture()
1323 s->input_picture[i - flush_offset] = s->input_picture[i]; in load_input_picture()
1325 s->input_picture[encoding_delay] = (Picture*) pic; in load_input_picture()
1330 static int skip_check(MpegEncContext *s, Picture *p, Picture *ref) in skip_check() argument
1339 for (y = 0; y < s->mb_height * bw; y++) { in skip_check()
1340 for (x = 0; x < s->mb_width * bw; x++) { in skip_check()
1344 int v = s->mecc.frame_skip_cmp[1](s, dptr, rptr, stride, 8); in skip_check()
1346 switch (FFABS(s->frame_skip_exp)) { in skip_check()
1360 if (s->frame_skip_exp < 0) in skip_check()
1361 score64 = pow(score64 / (double)(s->mb_width * s->mb_height), in skip_check()
1362 -1.0/s->frame_skip_exp); in skip_check()
1364 if (score64 < s->frame_skip_threshold) in skip_check()
1366 if (score64 < ((s->frame_skip_factor * (int64_t) s->lambda) >> 8)) in skip_check()
1392 static int estimate_best_b_count(MpegEncContext *s) in estimate_best_b_count() argument
1394 const AVCodec *codec = avcodec_find_encoder(s->avctx->codec_id); in estimate_best_b_count()
1396 const int scale = s->brd_scale; in estimate_best_b_count()
1397 int width = s->width >> scale; in estimate_best_b_count()
1398 int height = s->height >> scale; in estimate_best_b_count()
1412 p_lambda = s->last_lambda_for[AV_PICTURE_TYPE_P]; in estimate_best_b_count()
1414 b_lambda = s->last_lambda_for[AV_PICTURE_TYPE_B]; in estimate_best_b_count()
1420 for (i = 0; i < s->max_b_frames + 2; i++) { in estimate_best_b_count()
1421 Picture pre_input, *pre_input_ptr = i ? s->input_picture[i - 1] : in estimate_best_b_count()
1422 s->next_picture_ptr; in estimate_best_b_count()
1425 if (pre_input_ptr && (!i || s->input_picture[i - 1])) { in estimate_best_b_count()
1435 s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[0], in estimate_best_b_count()
1436 s->tmp_frames[i]->linesize[0], in estimate_best_b_count()
1440 s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[1], in estimate_best_b_count()
1441 s->tmp_frames[i]->linesize[1], in estimate_best_b_count()
1445 s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[2], in estimate_best_b_count()
1446 s->tmp_frames[i]->linesize[2], in estimate_best_b_count()
1453 for (j = 0; j < s->max_b_frames + 1; j++) { in estimate_best_b_count()
1457 if (!s->input_picture[j]) in estimate_best_b_count()
1469 c->flags |= s->avctx->flags & AV_CODEC_FLAG_QPEL; in estimate_best_b_count()
1470 c->mb_decision = s->avctx->mb_decision; in estimate_best_b_count()
1471 c->me_cmp = s->avctx->me_cmp; in estimate_best_b_count()
1472 c->mb_cmp = s->avctx->mb_cmp; in estimate_best_b_count()
1473 c->me_sub_cmp = s->avctx->me_sub_cmp; in estimate_best_b_count()
1475 c->time_base = s->avctx->time_base; in estimate_best_b_count()
1476 c->max_b_frames = s->max_b_frames; in estimate_best_b_count()
1483 s->tmp_frames[0]->pict_type = AV_PICTURE_TYPE_I; in estimate_best_b_count()
1484 s->tmp_frames[0]->quality = 1 * FF_QP2LAMBDA; in estimate_best_b_count()
1486 out_size = encode_frame(c, s->tmp_frames[0], pkt); in estimate_best_b_count()
1494 for (i = 0; i < s->max_b_frames + 1; i++) { in estimate_best_b_count()
1495 int is_p = i % (j + 1) == j || i == s->max_b_frames; in estimate_best_b_count()
1497 s->tmp_frames[i + 1]->pict_type = is_p ? in estimate_best_b_count()
1499 s->tmp_frames[i + 1]->quality = is_p ? p_lambda : b_lambda; in estimate_best_b_count()
1501 out_size = encode_frame(c, s->tmp_frames[i + 1], pkt); in estimate_best_b_count()
1539 static int select_input_picture(MpegEncContext *s) in select_input_picture() argument
1544 s->reordered_input_picture[i - 1] = s->reordered_input_picture[i]; in select_input_picture()
1545 s->reordered_input_picture[MAX_PICTURE_COUNT - 1] = NULL; in select_input_picture()
1548 if (!s->reordered_input_picture[0] && s->input_picture[0]) { in select_input_picture()
1549 if (s->frame_skip_threshold || s->frame_skip_factor) { in select_input_picture()
1550 if (s->picture_in_gop_number < s->gop_size && in select_input_picture()
1551 s->next_picture_ptr && in select_input_picture()
1552 skip_check(s, s->input_picture[0], s->next_picture_ptr)) { in select_input_picture()
1554 av_frame_unref(s->input_picture[0]->f); in select_input_picture()
1556 ff_vbv_update(s, 0); in select_input_picture()
1563 !s->next_picture_ptr || s->intra_only) { in select_input_picture()
1564 s->reordered_input_picture[0] = s->input_picture[0]; in select_input_picture()
1565 s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I; in select_input_picture()
1566 s->reordered_input_picture[0]->f->coded_picture_number = in select_input_picture()
1567 s->coded_picture_number++; in select_input_picture()
1571 if (s->avctx->flags & AV_CODEC_FLAG_PASS2) { in select_input_picture()
1572 for (i = 0; i < s->max_b_frames + 1; i++) { in select_input_picture()
1573 int pict_num = s->input_picture[0]->f->display_picture_number + i; in select_input_picture()
1575 if (pict_num >= s->rc_context.num_entries) in select_input_picture()
1577 if (!s->input_picture[i]) { in select_input_picture()
1578 s->rc_context.entry[pict_num - 1].new_pict_type = AV_PICTURE_TYPE_P; in select_input_picture()
1582 s->input_picture[i]->f->pict_type = in select_input_picture()
1583 s->rc_context.entry[pict_num].new_pict_type; in select_input_picture()
1587 if (s->b_frame_strategy == 0) { in select_input_picture()
1588 b_frames = s->max_b_frames; in select_input_picture()
1589 while (b_frames && !s->input_picture[b_frames]) in select_input_picture()
1591 } else if (s->b_frame_strategy == 1) { in select_input_picture()
1592 for (i = 1; i < s->max_b_frames + 1; i++) { in select_input_picture()
1593 if (s->input_picture[i] && in select_input_picture()
1594 s->input_picture[i]->b_frame_score == 0) { in select_input_picture()
1595 s->input_picture[i]->b_frame_score = in select_input_picture()
1596 get_intra_count(s, in select_input_picture()
1597 s->input_picture[i ]->f->data[0], in select_input_picture()
1598 s->input_picture[i - 1]->f->data[0], in select_input_picture()
1599 s->linesize) + 1; in select_input_picture()
1602 for (i = 0; i < s->max_b_frames + 1; i++) { in select_input_picture()
1603 if (!s->input_picture[i] || in select_input_picture()
1604 s->input_picture[i]->b_frame_score - 1 > in select_input_picture()
1605 s->mb_num / s->b_sensitivity) in select_input_picture()
1613 s->input_picture[i]->b_frame_score = 0; in select_input_picture()
1615 } else if (s->b_frame_strategy == 2) { in select_input_picture()
1616 b_frames = estimate_best_b_count(s); in select_input_picture()
1624 int type = s->input_picture[i]->f->pict_type; in select_input_picture()
1628 if (s->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_B && in select_input_picture()
1629 b_frames == s->max_b_frames) { in select_input_picture()
1630 av_log(s->avctx, AV_LOG_ERROR, in select_input_picture()
1634 if (s->picture_in_gop_number + b_frames >= s->gop_size) { in select_input_picture()
1635 if ((s->mpv_flags & FF_MPV_FLAG_STRICT_GOP) && in select_input_picture()
1636 s->gop_size > s->picture_in_gop_number) { in select_input_picture()
1637 b_frames = s->gop_size - s->picture_in_gop_number - 1; in select_input_picture()
1639 if (s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) in select_input_picture()
1641 s->input_picture[b_frames]->f->pict_type = AV_PICTURE_TYPE_I; in select_input_picture()
1645 if ((s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) && b_frames && in select_input_picture()
1646 s->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_I) in select_input_picture()
1649 s->reordered_input_picture[0] = s->input_picture[b_frames]; in select_input_picture()
1650 if (s->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I) in select_input_picture()
1651 s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P; in select_input_picture()
1652 s->reordered_input_picture[0]->f->coded_picture_number = in select_input_picture()
1653 s->coded_picture_number++; in select_input_picture()
1655 s->reordered_input_picture[i + 1] = s->input_picture[i]; in select_input_picture()
1656 s->reordered_input_picture[i + 1]->f->pict_type = in select_input_picture()
1658 s->reordered_input_picture[i + 1]->f->coded_picture_number = in select_input_picture()
1659 s->coded_picture_number++; in select_input_picture()
1664 ff_mpeg_unref_picture(s->avctx, &s->new_picture); in select_input_picture()
1666 if (s->reordered_input_picture[0]) { in select_input_picture()
1667 s->reordered_input_picture[0]->reference = in select_input_picture()
1668 s->reordered_input_picture[0]->f->pict_type != in select_input_picture()
1671 if ((ret = ff_mpeg_ref_picture(s->avctx, &s->new_picture, s->reordered_input_picture[0]))) in select_input_picture()
1674 if (s->reordered_input_picture[0]->shared || s->avctx->rc_buffer_size) { in select_input_picture()
1679 int i = ff_find_unused_picture(s->avctx, s->picture, 0); in select_input_picture()
1682 pic = &s->picture[i]; in select_input_picture()
1684 pic->reference = s->reordered_input_picture[0]->reference; in select_input_picture()
1685 if (alloc_picture(s, pic, 0) < 0) { in select_input_picture()
1689 ret = av_frame_copy_props(pic->f, s->reordered_input_picture[0]->f); in select_input_picture()
1694 av_frame_unref(s->reordered_input_picture[0]->f); in select_input_picture()
1695 s->reordered_input_picture[0]->shared = 0; in select_input_picture()
1697 s->current_picture_ptr = pic; in select_input_picture()
1700 s->current_picture_ptr = s->reordered_input_picture[0]; in select_input_picture()
1702 if (s->new_picture.f->data[i]) in select_input_picture()
1703 s->new_picture.f->data[i] += INPLACE_OFFSET; in select_input_picture()
1706 ff_mpeg_unref_picture(s->avctx, &s->current_picture); in select_input_picture()
1707 if ((ret = ff_mpeg_ref_picture(s->avctx, &s->current_picture, in select_input_picture()
1708 s->current_picture_ptr)) < 0) in select_input_picture()
1711 s->picture_number = s->new_picture.f->display_picture_number; in select_input_picture()
1716 static void frame_end(MpegEncContext *s) in frame_end() argument
1718 if (s->unrestricted_mv && in frame_end()
1719 s->current_picture.reference && in frame_end()
1720 !s->intra_only) { in frame_end()
1721 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt); in frame_end()
1724 s->mpvencdsp.draw_edges(s->current_picture.f->data[0], in frame_end()
1725 s->current_picture.f->linesize[0], in frame_end()
1726 s->h_edge_pos, s->v_edge_pos, in frame_end()
1729 s->mpvencdsp.draw_edges(s->current_picture.f->data[1], in frame_end()
1730 s->current_picture.f->linesize[1], in frame_end()
1731 s->h_edge_pos >> hshift, in frame_end()
1732 s->v_edge_pos >> vshift, in frame_end()
1736 s->mpvencdsp.draw_edges(s->current_picture.f->data[2], in frame_end()
1737 s->current_picture.f->linesize[2], in frame_end()
1738 s->h_edge_pos >> hshift, in frame_end()
1739 s->v_edge_pos >> vshift, in frame_end()
1747 s->last_pict_type = s->pict_type; in frame_end()
1748 s->last_lambda_for [s->pict_type] = s->current_picture_ptr->f->quality; in frame_end()
1749 if (s->pict_type!= AV_PICTURE_TYPE_B) in frame_end()
1750 s->last_non_b_pict_type = s->pict_type; in frame_end()
1754 av_frame_unref(s->avctx->coded_frame); in frame_end()
1755 av_frame_copy_props(s->avctx->coded_frame, s->current_picture.f); in frame_end()
1760 memcpy(s->current_picture.f->error, s->current_picture.encoding_error, in frame_end()
1761 sizeof(s->current_picture.encoding_error)); in frame_end()
1766 static void update_noise_reduction(MpegEncContext *s) in update_noise_reduction() argument
1771 if (s->dct_count[intra] > (1 << 16)) { in update_noise_reduction()
1773 s->dct_error_sum[intra][i] >>= 1; in update_noise_reduction()
1775 s->dct_count[intra] >>= 1; in update_noise_reduction()
1779 s->dct_offset[intra][i] = (s->noise_reduction * in update_noise_reduction()
1780 s->dct_count[intra] + in update_noise_reduction()
1781 s->dct_error_sum[intra][i] / 2) / in update_noise_reduction()
1782 (s->dct_error_sum[intra][i] + 1); in update_noise_reduction()
1787 static int frame_start(MpegEncContext *s) in frame_start() argument
1792 if (s->pict_type != AV_PICTURE_TYPE_B && s->last_picture_ptr && in frame_start()
1793 s->last_picture_ptr != s->next_picture_ptr && in frame_start()
1794 s->last_picture_ptr->f->buf[0]) { in frame_start()
1795 ff_mpeg_unref_picture(s->avctx, s->last_picture_ptr); in frame_start()
1798 s->current_picture_ptr->f->pict_type = s->pict_type; in frame_start()
1799 s->current_picture_ptr->f->key_frame = s->pict_type == AV_PICTURE_TYPE_I; in frame_start()
1801 ff_mpeg_unref_picture(s->avctx, &s->current_picture); in frame_start()
1802 if ((ret = ff_mpeg_ref_picture(s->avctx, &s->current_picture, in frame_start()
1803 s->current_picture_ptr)) < 0) in frame_start()
1806 if (s->pict_type != AV_PICTURE_TYPE_B) { in frame_start()
1807 s->last_picture_ptr = s->next_picture_ptr; in frame_start()
1808 if (!s->droppable) in frame_start()
1809 s->next_picture_ptr = s->current_picture_ptr; in frame_start()
1812 if (s->last_picture_ptr) { in frame_start()
1813 ff_mpeg_unref_picture(s->avctx, &s->last_picture); in frame_start()
1814 if (s->last_picture_ptr->f->buf[0] && in frame_start()
1815 (ret = ff_mpeg_ref_picture(s->avctx, &s->last_picture, in frame_start()
1816 s->last_picture_ptr)) < 0) in frame_start()
1819 if (s->next_picture_ptr) { in frame_start()
1820 ff_mpeg_unref_picture(s->avctx, &s->next_picture); in frame_start()
1821 if (s->next_picture_ptr->f->buf[0] && in frame_start()
1822 (ret = ff_mpeg_ref_picture(s->avctx, &s->next_picture, in frame_start()
1823 s->next_picture_ptr)) < 0) in frame_start()
1827 if (s->picture_structure!= PICT_FRAME) { in frame_start()
1830 if (s->picture_structure == PICT_BOTTOM_FIELD) { in frame_start()
1831 s->current_picture.f->data[i] += in frame_start()
1832 s->current_picture.f->linesize[i]; in frame_start()
1834 s->current_picture.f->linesize[i] *= 2; in frame_start()
1835 s->last_picture.f->linesize[i] *= 2; in frame_start()
1836 s->next_picture.f->linesize[i] *= 2; in frame_start()
1840 if (s->mpeg_quant || s->codec_id == AV_CODEC_ID_MPEG2VIDEO) { in frame_start()
1841 s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra; in frame_start()
1842 s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter; in frame_start()
1843 } else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) { in frame_start()
1844 s->dct_unquantize_intra = s->dct_unquantize_h263_intra; in frame_start()
1845 s->dct_unquantize_inter = s->dct_unquantize_h263_inter; in frame_start()
1847 s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra; in frame_start()
1848 s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter; in frame_start()
1851 if (s->dct_error_sum) { in frame_start()
1852 av_assert2(s->noise_reduction && s->encoding); in frame_start()
1853 update_noise_reduction(s); in frame_start()
1862 MpegEncContext *s = avctx->priv_data; in ff_mpv_encode_picture() local
1864 int context_count = s->slice_context_count; in ff_mpv_encode_picture()
1866 s->vbv_ignore_qmax = 0; in ff_mpv_encode_picture()
1868 s->picture_in_gop_number++; in ff_mpv_encode_picture()
1870 if (load_input_picture(s, pic_arg) < 0) in ff_mpv_encode_picture()
1873 if (select_input_picture(s) < 0) { in ff_mpv_encode_picture()
1878 if (s->new_picture.f->data[0]) { in ff_mpv_encode_picture()
1879 int growing_buffer = context_count == 1 && !pkt->data && !s->data_partitioning; in ff_mpv_encode_picture()
1880 …int pkt_size = growing_buffer ? FFMAX(s->mb_width*s->mb_height*64+10000, avctx->internal->byte_buf… in ff_mpv_encode_picture()
1882 s->mb_width*s->mb_height*(MAX_MB_BYTES+100)+10000; in ff_mpv_encode_picture()
1885 if (s->mb_info) { in ff_mpv_encode_picture()
1886 s->mb_info_ptr = av_packet_new_side_data(pkt, in ff_mpv_encode_picture()
1888 s->mb_width*s->mb_height*12); in ff_mpv_encode_picture()
1889 s->prev_mb_info = s->last_mb_info = s->mb_info_size = 0; in ff_mpv_encode_picture()
1893 int start_y = s->thread_context[i]->start_mb_y; in ff_mpv_encode_picture()
1894 int end_y = s->thread_context[i]-> end_mb_y; in ff_mpv_encode_picture()
1895 int h = s->mb_height; in ff_mpv_encode_picture()
1899 init_put_bits(&s->thread_context[i]->pb, start, end - start); in ff_mpv_encode_picture()
1902 s->pict_type = s->new_picture.f->pict_type; in ff_mpv_encode_picture()
1904 ret = frame_start(s); in ff_mpv_encode_picture()
1908 ret = encode_picture(s, s->picture_number); in ff_mpv_encode_picture()
1910 av_assert0(s->pb.buf == avctx->internal->byte_buffer); in ff_mpv_encode_picture()
1911 pkt->data = s->pb.buf; in ff_mpv_encode_picture()
1919 avctx->header_bits = s->header_bits; in ff_mpv_encode_picture()
1920 avctx->mv_bits = s->mv_bits; in ff_mpv_encode_picture()
1921 avctx->misc_bits = s->misc_bits; in ff_mpv_encode_picture()
1922 avctx->i_tex_bits = s->i_tex_bits; in ff_mpv_encode_picture()
1923 avctx->p_tex_bits = s->p_tex_bits; in ff_mpv_encode_picture()
1924 avctx->i_count = s->i_count; in ff_mpv_encode_picture()
1926 avctx->p_count = s->mb_num - s->i_count - s->skip_count; in ff_mpv_encode_picture()
1927 avctx->skip_count = s->skip_count; in ff_mpv_encode_picture()
1931 frame_end(s); in ff_mpv_encode_picture()
1933 if (CONFIG_MJPEG_ENCODER && s->out_format == FMT_MJPEG) in ff_mpv_encode_picture()
1934 ff_mjpeg_encode_picture_trailer(&s->pb, s->header_bits); in ff_mpv_encode_picture()
1937 RateControlContext *rcc = &s->rc_context; in ff_mpv_encode_picture()
1942 if (put_bits_count(&s->pb) > max_size && in ff_mpv_encode_picture()
1943 s->lambda < s->lmax) { in ff_mpv_encode_picture()
1944 s->next_lambda = FFMAX(s->lambda + min_step, s->lambda * in ff_mpv_encode_picture()
1945 (s->qscale + 1) / s->qscale); in ff_mpv_encode_picture()
1946 if (s->adaptive_quant) { in ff_mpv_encode_picture()
1948 for (i = 0; i < s->mb_height * s->mb_stride; i++) in ff_mpv_encode_picture()
1949 s->lambda_table[i] = in ff_mpv_encode_picture()
1950 FFMAX(s->lambda_table[i] + min_step, in ff_mpv_encode_picture()
1951 s->lambda_table[i] * (s->qscale + 1) / in ff_mpv_encode_picture()
1952 s->qscale); in ff_mpv_encode_picture()
1954 s->mb_skipped = 0; // done in frame_start() in ff_mpv_encode_picture()
1956 if (s->pict_type == AV_PICTURE_TYPE_P) { in ff_mpv_encode_picture()
1957 if (s->flipflop_rounding || in ff_mpv_encode_picture()
1958 s->codec_id == AV_CODEC_ID_H263P || in ff_mpv_encode_picture()
1959 s->codec_id == AV_CODEC_ID_MPEG4) in ff_mpv_encode_picture()
1960 s->no_rounding ^= 1; in ff_mpv_encode_picture()
1962 if (s->pict_type != AV_PICTURE_TYPE_B) { in ff_mpv_encode_picture()
1963 s->time_base = s->last_time_base; in ff_mpv_encode_picture()
1964 s->last_non_b_time = s->time - s->pp_time; in ff_mpv_encode_picture()
1967 PutBitContext *pb = &s->thread_context[i]->pb; in ff_mpv_encode_picture()
1970 s->vbv_ignore_qmax = 1; in ff_mpv_encode_picture()
1979 ff_write_pass1_stats(s); in ff_mpv_encode_picture()
1982 s->current_picture_ptr->encoding_error[i] = s->current_picture.encoding_error[i]; in ff_mpv_encode_picture()
1983 avctx->error[i] += s->current_picture_ptr->encoding_error[i]; in ff_mpv_encode_picture()
1985 ff_side_data_set_encoder_stats(pkt, s->current_picture.f->quality, in ff_mpv_encode_picture()
1986 s->current_picture_ptr->encoding_error, in ff_mpv_encode_picture()
1988 s->pict_type); in ff_mpv_encode_picture()
1991 assert(put_bits_count(&s->pb) == s->header_bits + s->mv_bits + in ff_mpv_encode_picture()
1992 s->misc_bits + s->i_tex_bits + in ff_mpv_encode_picture()
1993 s->p_tex_bits); in ff_mpv_encode_picture()
1994 flush_put_bits(&s->pb); in ff_mpv_encode_picture()
1995 s->frame_bits = put_bits_count(&s->pb); in ff_mpv_encode_picture()
1997 stuffing_count = ff_vbv_update(s, s->frame_bits); in ff_mpv_encode_picture()
1998 s->stuffing_bits = 8*stuffing_count; in ff_mpv_encode_picture()
2000 if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < in ff_mpv_encode_picture()
2006 switch (s->codec_id) { in ff_mpv_encode_picture()
2010 put_bits(&s->pb, 8, 0); in ff_mpv_encode_picture()
2014 put_bits(&s->pb, 16, 0); in ff_mpv_encode_picture()
2015 put_bits(&s->pb, 16, 0x1C3); in ff_mpv_encode_picture()
2018 put_bits(&s->pb, 8, 0xFF); in ff_mpv_encode_picture()
2023 s->stuffing_bits = 0; in ff_mpv_encode_picture()
2025 flush_put_bits(&s->pb); in ff_mpv_encode_picture()
2026 s->frame_bits = put_bits_count(&s->pb); in ff_mpv_encode_picture()
2032 s->out_format == FMT_MPEG1 && in ff_mpv_encode_picture()
2041 int minbits = s->frame_bits - 8 * in ff_mpv_encode_picture()
2042 (s->vbv_delay_ptr - s->pb.buf - 1); in ff_mpv_encode_picture()
2043 double bits = s->rc_context.buffer_index + minbits - inbits; in ff_mpv_encode_picture()
2049 av_assert1(s->repeat_first_field == 0); in ff_mpv_encode_picture()
2059 s->vbv_delay_ptr[0] &= 0xF8; in ff_mpv_encode_picture()
2060 s->vbv_delay_ptr[0] |= vbv_delay >> 13; in ff_mpv_encode_picture()
2061 s->vbv_delay_ptr[1] = vbv_delay >> 5; in ff_mpv_encode_picture()
2062 s->vbv_delay_ptr[2] &= 0x07; in ff_mpv_encode_picture()
2063 s->vbv_delay_ptr[2] |= vbv_delay << 3; in ff_mpv_encode_picture()
2083 s->total_bits += s->frame_bits; in ff_mpv_encode_picture()
2086 avctx->frame_bits = s->frame_bits; in ff_mpv_encode_picture()
2091 pkt->pts = s->current_picture.f->pts; in ff_mpv_encode_picture()
2092 if (!s->low_delay && s->pict_type != AV_PICTURE_TYPE_B) { in ff_mpv_encode_picture()
2093 if (!s->current_picture.f->coded_picture_number) in ff_mpv_encode_picture()
2094 pkt->dts = pkt->pts - s->dts_delta; in ff_mpv_encode_picture()
2096 pkt->dts = s->reordered_pts; in ff_mpv_encode_picture()
2097 s->reordered_pts = pkt->pts; in ff_mpv_encode_picture()
2100 if (s->current_picture.f->key_frame) in ff_mpv_encode_picture()
2102 if (s->mb_info) in ff_mpv_encode_picture()
2103 av_packet_shrink_side_data(pkt, AV_PKT_DATA_H263_MB_INFO, s->mb_info_size); in ff_mpv_encode_picture()
2105 s->frame_bits = 0; in ff_mpv_encode_picture()
2110 if (!s->picture[i].reference) in ff_mpv_encode_picture()
2111 ff_mpeg_unref_picture(avctx, &s->picture[i]); in ff_mpv_encode_picture()
2114 av_assert1((s->frame_bits & 7) == 0); in ff_mpv_encode_picture()
2116 pkt->size = s->frame_bits / 8; in ff_mpv_encode_picture()
2121 static inline void dct_single_coeff_elimination(MpegEncContext *s, in dct_single_coeff_elimination() argument
2137 int16_t *block = s->block[n]; in dct_single_coeff_elimination()
2138 const int last_index = s->block_last_index[n]; in dct_single_coeff_elimination()
2152 const int j = s->intra_scantable.permutated[i]; in dct_single_coeff_elimination()
2168 const int j = s->intra_scantable.permutated[i]; in dct_single_coeff_elimination()
2172 s->block_last_index[n] = 0; in dct_single_coeff_elimination()
2174 s->block_last_index[n] = -1; in dct_single_coeff_elimination()
2177 static inline void clip_coeffs(MpegEncContext *s, int16_t *block, in clip_coeffs() argument
2181 const int maxlevel = s->max_qcoeff; in clip_coeffs()
2182 const int minlevel = s->min_qcoeff; in clip_coeffs()
2185 if (s->mb_intra) { in clip_coeffs()
2191 const int j = s->intra_scantable.permutated[i]; in clip_coeffs()
2205 if (overflow && s->avctx->mb_decision == FF_MB_DECISION_SIMPLE) in clip_coeffs()
2206 av_log(s->avctx, AV_LOG_INFO, in clip_coeffs()
2235 static av_always_inline void encode_mb_internal(MpegEncContext *s, in encode_mb_internal() argument
2243 const int mb_x = s->mb_x; in encode_mb_internal()
2244 const int mb_y = s->mb_y; in encode_mb_internal()
2247 int dct_offset = s->linesize * 8; // default for progressive frames in encode_mb_internal()
2248 int uv_dct_offset = s->uvlinesize * 8; in encode_mb_internal()
2253 skip_dct[i] = s->skipdct; in encode_mb_internal()
2255 if (s->adaptive_quant) { in encode_mb_internal()
2256 const int last_qp = s->qscale; in encode_mb_internal()
2257 const int mb_xy = mb_x + mb_y * s->mb_stride; in encode_mb_internal()
2259 s->lambda = s->lambda_table[mb_xy]; in encode_mb_internal()
2260 update_qscale(s); in encode_mb_internal()
2262 if (!(s->mpv_flags & FF_MPV_FLAG_QP_RD)) { in encode_mb_internal()
2263 s->qscale = s->current_picture_ptr->qscale_table[mb_xy]; in encode_mb_internal()
2264 s->dquant = s->qscale - last_qp; in encode_mb_internal()
2266 if (s->out_format == FMT_H263) { in encode_mb_internal()
2267 s->dquant = av_clip(s->dquant, -2, 2); in encode_mb_internal()
2269 if (s->codec_id == AV_CODEC_ID_MPEG4) { in encode_mb_internal()
2270 if (!s->mb_intra) { in encode_mb_internal()
2271 if (s->pict_type == AV_PICTURE_TYPE_B) { in encode_mb_internal()
2272 if (s->dquant & 1 || s->mv_dir & MV_DIRECT) in encode_mb_internal()
2273 s->dquant = 0; in encode_mb_internal()
2275 if (s->mv_type == MV_TYPE_8X8) in encode_mb_internal()
2276 s->dquant = 0; in encode_mb_internal()
2281 ff_set_qscale(s, last_qp + s->dquant); in encode_mb_internal()
2282 } else if (s->mpv_flags & FF_MPV_FLAG_QP_RD) in encode_mb_internal()
2283 ff_set_qscale(s, s->qscale + s->dquant); in encode_mb_internal()
2285 wrap_y = s->linesize; in encode_mb_internal()
2286 wrap_c = s->uvlinesize; in encode_mb_internal()
2287 ptr_y = s->new_picture.f->data[0] + in encode_mb_internal()
2289 ptr_cb = s->new_picture.f->data[1] + in encode_mb_internal()
2291 ptr_cr = s->new_picture.f->data[2] + in encode_mb_internal()
2294 if((mb_x * 16 + 16 > s->width || mb_y * 16 + 16 > s->height) && s->codec_id != AV_CODEC_ID_AMV){ in encode_mb_internal()
2295 uint8_t *ebuf = s->sc.edge_emu_buffer + 38 * wrap_y; in encode_mb_internal()
2296 int cw = (s->width + s->chroma_x_shift) >> s->chroma_x_shift; in encode_mb_internal()
2297 int ch = (s->height + s->chroma_y_shift) >> s->chroma_y_shift; in encode_mb_internal()
2298 s->vdsp.emulated_edge_mc(ebuf, ptr_y, in encode_mb_internal()
2301 s->width, s->height); in encode_mb_internal()
2303 s->vdsp.emulated_edge_mc(ebuf + 16 * wrap_y, ptr_cb, in encode_mb_internal()
2309 s->vdsp.emulated_edge_mc(ebuf + 16 * wrap_y + 16, ptr_cr, in encode_mb_internal()
2317 if (s->mb_intra) { in encode_mb_internal()
2318 if (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) { in encode_mb_internal()
2321 s->interlaced_dct = 0; in encode_mb_internal()
2322 progressive_score = s->mecc.ildct_cmp[4](s, ptr_y, NULL, wrap_y, 8) + in encode_mb_internal()
2323 s->mecc.ildct_cmp[4](s, ptr_y + wrap_y * 8, in encode_mb_internal()
2327 interlaced_score = s->mecc.ildct_cmp[4](s, ptr_y, in encode_mb_internal()
2329 s->mecc.ildct_cmp[4](s, ptr_y + wrap_y, in encode_mb_internal()
2332 s->interlaced_dct = 1; in encode_mb_internal()
2337 if (s->chroma_format == CHROMA_422 || in encode_mb_internal()
2338 s->chroma_format == CHROMA_444) in encode_mb_internal()
2344 s->pdsp.get_pixels(s->block[0], ptr_y, wrap_y); in encode_mb_internal()
2345 s->pdsp.get_pixels(s->block[1], ptr_y + 8, wrap_y); in encode_mb_internal()
2346 s->pdsp.get_pixels(s->block[2], ptr_y + dct_offset, wrap_y); in encode_mb_internal()
2347 s->pdsp.get_pixels(s->block[3], ptr_y + dct_offset + 8, wrap_y); in encode_mb_internal()
2349 if (s->avctx->flags & AV_CODEC_FLAG_GRAY) { in encode_mb_internal()
2353 s->pdsp.get_pixels(s->block[4], ptr_cb, wrap_c); in encode_mb_internal()
2354 s->pdsp.get_pixels(s->block[5], ptr_cr, wrap_c); in encode_mb_internal()
2355 if (!s->chroma_y_shift && s->chroma_x_shift) { /* 422 */ in encode_mb_internal()
2356 s->pdsp.get_pixels(s->block[6], ptr_cb + uv_dct_offset, wrap_c); in encode_mb_internal()
2357 s->pdsp.get_pixels(s->block[7], ptr_cr + uv_dct_offset, wrap_c); in encode_mb_internal()
2358 } else if (!s->chroma_y_shift && !s->chroma_x_shift) { /* 444 */ in encode_mb_internal()
2359 s->pdsp.get_pixels(s->block[ 6], ptr_cb + 8, wrap_c); in encode_mb_internal()
2360 s->pdsp.get_pixels(s->block[ 7], ptr_cr + 8, wrap_c); in encode_mb_internal()
2361 s->pdsp.get_pixels(s->block[ 8], ptr_cb + uv_dct_offset, wrap_c); in encode_mb_internal()
2362 s->pdsp.get_pixels(s->block[ 9], ptr_cr + uv_dct_offset, wrap_c); in encode_mb_internal()
2363 s->pdsp.get_pixels(s->block[10], ptr_cb + uv_dct_offset + 8, wrap_c); in encode_mb_internal()
2364 s->pdsp.get_pixels(s->block[11], ptr_cr + uv_dct_offset + 8, wrap_c); in encode_mb_internal()
2372 dest_y = s->dest[0]; in encode_mb_internal()
2373 dest_cb = s->dest[1]; in encode_mb_internal()
2374 dest_cr = s->dest[2]; in encode_mb_internal()
2376 if ((!s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) { in encode_mb_internal()
2377 op_pix = s->hdsp.put_pixels_tab; in encode_mb_internal()
2378 op_qpix = s->qdsp.put_qpel_pixels_tab; in encode_mb_internal()
2380 op_pix = s->hdsp.put_no_rnd_pixels_tab; in encode_mb_internal()
2381 op_qpix = s->qdsp.put_no_rnd_qpel_pixels_tab; in encode_mb_internal()
2384 if (s->mv_dir & MV_DIR_FORWARD) { in encode_mb_internal()
2385 ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 0, in encode_mb_internal()
2386 s->last_picture.f->data, in encode_mb_internal()
2388 op_pix = s->hdsp.avg_pixels_tab; in encode_mb_internal()
2389 op_qpix = s->qdsp.avg_qpel_pixels_tab; in encode_mb_internal()
2391 if (s->mv_dir & MV_DIR_BACKWARD) { in encode_mb_internal()
2392 ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 1, in encode_mb_internal()
2393 s->next_picture.f->data, in encode_mb_internal()
2397 if (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) { in encode_mb_internal()
2400 s->interlaced_dct = 0; in encode_mb_internal()
2401 progressive_score = s->mecc.ildct_cmp[0](s, dest_y, ptr_y, wrap_y, 8) + in encode_mb_internal()
2402 s->mecc.ildct_cmp[0](s, dest_y + wrap_y * 8, in encode_mb_internal()
2406 if (s->avctx->ildct_cmp == FF_CMP_VSSE) in encode_mb_internal()
2410 interlaced_score = s->mecc.ildct_cmp[0](s, dest_y, ptr_y, in encode_mb_internal()
2412 s->mecc.ildct_cmp[0](s, dest_y + wrap_y, in encode_mb_internal()
2417 s->interlaced_dct = 1; in encode_mb_internal()
2422 if (s->chroma_format == CHROMA_422) in encode_mb_internal()
2428 s->pdsp.diff_pixels(s->block[0], ptr_y, dest_y, wrap_y); in encode_mb_internal()
2429 s->pdsp.diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y); in encode_mb_internal()
2430 s->pdsp.diff_pixels(s->block[2], ptr_y + dct_offset, in encode_mb_internal()
2432 s->pdsp.diff_pixels(s->block[3], ptr_y + dct_offset + 8, in encode_mb_internal()
2435 if (s->avctx->flags & AV_CODEC_FLAG_GRAY) { in encode_mb_internal()
2439 s->pdsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c); in encode_mb_internal()
2440 s->pdsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c); in encode_mb_internal()
2441 if (!s->chroma_y_shift) { /* 422 */ in encode_mb_internal()
2442 s->pdsp.diff_pixels(s->block[6], ptr_cb + uv_dct_offset, in encode_mb_internal()
2444 s->pdsp.diff_pixels(s->block[7], ptr_cr + uv_dct_offset, in encode_mb_internal()
2449 if (s->current_picture.mc_mb_var[s->mb_stride * mb_y + mb_x] < in encode_mb_internal()
2450 2 * s->qscale * s->qscale) { in encode_mb_internal()
2452 if (s->mecc.sad[1](NULL, ptr_y, dest_y, wrap_y, 8) < 20 * s->qscale) in encode_mb_internal()
2454 if (s->mecc.sad[1](NULL, ptr_y + 8, dest_y + 8, wrap_y, 8) < 20 * s->qscale) in encode_mb_internal()
2456 if (s->mecc.sad[1](NULL, ptr_y + dct_offset, dest_y + dct_offset, in encode_mb_internal()
2457 wrap_y, 8) < 20 * s->qscale) in encode_mb_internal()
2459 if (s->mecc.sad[1](NULL, ptr_y + dct_offset + 8, dest_y + dct_offset + 8, in encode_mb_internal()
2460 wrap_y, 8) < 20 * s->qscale) in encode_mb_internal()
2462 if (s->mecc.sad[1](NULL, ptr_cb, dest_cb, wrap_c, 8) < 20 * s->qscale) in encode_mb_internal()
2464 if (s->mecc.sad[1](NULL, ptr_cr, dest_cr, wrap_c, 8) < 20 * s->qscale) in encode_mb_internal()
2466 if (!s->chroma_y_shift) { /* 422 */ in encode_mb_internal()
2467 if (s->mecc.sad[1](NULL, ptr_cb + uv_dct_offset, in encode_mb_internal()
2469 wrap_c, 8) < 20 * s->qscale) in encode_mb_internal()
2471 if (s->mecc.sad[1](NULL, ptr_cr + uv_dct_offset, in encode_mb_internal()
2473 wrap_c, 8) < 20 * s->qscale) in encode_mb_internal()
2479 if (s->quantizer_noise_shaping) { in encode_mb_internal()
2492 if (!s->chroma_y_shift) { /* 422 */ in encode_mb_internal()
2500 memcpy(orig[0], s->block[0], sizeof(int16_t) * 64 * mb_block_count); in encode_mb_internal()
2504 av_assert2(s->out_format != FMT_MJPEG || s->qscale == 8); in encode_mb_internal()
2509 s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow); in encode_mb_internal()
2516 clip_coeffs(s, s->block[i], s->block_last_index[i]); in encode_mb_internal()
2518 s->block_last_index[i] = -1; in encode_mb_internal()
2520 if (s->quantizer_noise_shaping) { in encode_mb_internal()
2523 s->block_last_index[i] = in encode_mb_internal()
2524 dct_quantize_refine(s, s->block[i], weight[i], in encode_mb_internal()
2525 orig[i], i, s->qscale); in encode_mb_internal()
2530 if (s->luma_elim_threshold && !s->mb_intra) in encode_mb_internal()
2532 dct_single_coeff_elimination(s, i, s->luma_elim_threshold); in encode_mb_internal()
2533 if (s->chroma_elim_threshold && !s->mb_intra) in encode_mb_internal()
2535 dct_single_coeff_elimination(s, i, s->chroma_elim_threshold); in encode_mb_internal()
2537 if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) { in encode_mb_internal()
2539 if (s->block_last_index[i] == -1) in encode_mb_internal()
2540 s->coded_score[i] = INT_MAX / 256; in encode_mb_internal()
2545 if ((s->avctx->flags & AV_CODEC_FLAG_GRAY) && s->mb_intra) { in encode_mb_internal()
2546 s->block_last_index[4] = in encode_mb_internal()
2547 s->block_last_index[5] = 0; in encode_mb_internal()
2548 s->block[4][0] = in encode_mb_internal()
2549 s->block[5][0] = (1024 + s->c_dc_scale / 2) / s->c_dc_scale; in encode_mb_internal()
2550 if (!s->chroma_y_shift) { /* 422 / 444 */ in encode_mb_internal()
2552 s->block_last_index[i] = 0; in encode_mb_internal()
2553 s->block[i][0] = s->block[4][0]; in encode_mb_internal()
2559 if (s->alternate_scan && s->dct_quantize != ff_dct_quantize_c) { in encode_mb_internal()
2562 if (s->block_last_index[i] > 0) { in encode_mb_internal()
2564 if (s->block[i][s->intra_scantable.permutated[j]]) in encode_mb_internal()
2567 s->block_last_index[i] = j; in encode_mb_internal()
2573 switch(s->codec_id){ //FIXME funct ptr could be slightly faster in encode_mb_internal()
2577 ff_mpeg1_encode_mb(s, s->block, motion_x, motion_y); in encode_mb_internal()
2581 ff_mpeg4_encode_mb(s, s->block, motion_x, motion_y); in encode_mb_internal()
2587 ff_msmpeg4_encode_mb(s, s->block, motion_x, motion_y); in encode_mb_internal()
2591 ff_wmv2_encode_mb(s, s->block, motion_x, motion_y); in encode_mb_internal()
2595 ff_h261_encode_mb(s, s->block, motion_x, motion_y); in encode_mb_internal()
2603 ff_h263_encode_mb(s, s->block, motion_x, motion_y); in encode_mb_internal()
2608 ff_mjpeg_encode_mb(s, s->block); in encode_mb_internal()
2612 ff_speedhq_encode_mb(s, s->block); in encode_mb_internal()
2619 static av_always_inline void encode_mb(MpegEncContext *s, int motion_x, int motion_y) in encode_mb() argument
2621 if (s->chroma_format == CHROMA_420) encode_mb_internal(s, motion_x, motion_y, 8, 8, 6); in encode_mb()
2622 else if (s->chroma_format == CHROMA_422) encode_mb_internal(s, motion_x, motion_y, 16, 8, 8); in encode_mb()
2623 else encode_mb_internal(s, motion_x, motion_y, 16, 16, 12); in encode_mb()
2626 static inline void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type){ in copy_context_before_encode() argument
2629 memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster than a loop? in copy_context_before_encode()
2632 d->mb_skip_run= s->mb_skip_run; in copy_context_before_encode()
2634 d->last_dc[i] = s->last_dc[i]; in copy_context_before_encode()
2637 d->mv_bits= s->mv_bits; in copy_context_before_encode()
2638 d->i_tex_bits= s->i_tex_bits; in copy_context_before_encode()
2639 d->p_tex_bits= s->p_tex_bits; in copy_context_before_encode()
2640 d->i_count= s->i_count; in copy_context_before_encode()
2641 d->f_count= s->f_count; in copy_context_before_encode()
2642 d->b_count= s->b_count; in copy_context_before_encode()
2643 d->skip_count= s->skip_count; in copy_context_before_encode()
2644 d->misc_bits= s->misc_bits; in copy_context_before_encode()
2648 d->qscale= s->qscale; in copy_context_before_encode()
2649 d->dquant= s->dquant; in copy_context_before_encode()
2651 d->esc3_level_length= s->esc3_level_length; in copy_context_before_encode()
2654 static inline void copy_context_after_encode(MpegEncContext *d, MpegEncContext *s, int type){ in copy_context_after_encode() argument
2657 memcpy(d->mv, s->mv, 2*4*2*sizeof(int)); in copy_context_after_encode()
2658 memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster than a loop? in copy_context_after_encode()
2661 d->mb_skip_run= s->mb_skip_run; in copy_context_after_encode()
2663 d->last_dc[i] = s->last_dc[i]; in copy_context_after_encode()
2666 d->mv_bits= s->mv_bits; in copy_context_after_encode()
2667 d->i_tex_bits= s->i_tex_bits; in copy_context_after_encode()
2668 d->p_tex_bits= s->p_tex_bits; in copy_context_after_encode()
2669 d->i_count= s->i_count; in copy_context_after_encode()
2670 d->f_count= s->f_count; in copy_context_after_encode()
2671 d->b_count= s->b_count; in copy_context_after_encode()
2672 d->skip_count= s->skip_count; in copy_context_after_encode()
2673 d->misc_bits= s->misc_bits; in copy_context_after_encode()
2675 d->mb_intra= s->mb_intra; in copy_context_after_encode()
2676 d->mb_skipped= s->mb_skipped; in copy_context_after_encode()
2677 d->mv_type= s->mv_type; in copy_context_after_encode()
2678 d->mv_dir= s->mv_dir; in copy_context_after_encode()
2679 d->pb= s->pb; in copy_context_after_encode()
2680 if(s->data_partitioning){ in copy_context_after_encode()
2681 d->pb2= s->pb2; in copy_context_after_encode()
2682 d->tex_pb= s->tex_pb; in copy_context_after_encode()
2684 d->block= s->block; in copy_context_after_encode()
2686 d->block_last_index[i]= s->block_last_index[i]; in copy_context_after_encode()
2687 d->interlaced_dct= s->interlaced_dct; in copy_context_after_encode()
2688 d->qscale= s->qscale; in copy_context_after_encode()
2690 d->esc3_level_length= s->esc3_level_length; in copy_context_after_encode()
2693 static inline void encode_mb_hq(MpegEncContext *s, MpegEncContext *backup, MpegEncContext *best, in… in encode_mb_hq() argument
2700 copy_context_before_encode(s, backup, type); in encode_mb_hq()
2702 s->block= s->blocks[*next_block]; in encode_mb_hq()
2703 s->pb= pb[*next_block]; in encode_mb_hq()
2704 if(s->data_partitioning){ in encode_mb_hq()
2705 s->pb2 = pb2 [*next_block]; in encode_mb_hq()
2706 s->tex_pb= tex_pb[*next_block]; in encode_mb_hq()
2710 memcpy(dest_backup, s->dest, sizeof(s->dest)); in encode_mb_hq()
2711 s->dest[0] = s->sc.rd_scratchpad; in encode_mb_hq()
2712 s->dest[1] = s->sc.rd_scratchpad + 16*s->linesize; in encode_mb_hq()
2713 s->dest[2] = s->sc.rd_scratchpad + 16*s->linesize + 8; in encode_mb_hq()
2714 av_assert0(s->linesize >= 32); //FIXME in encode_mb_hq()
2717 encode_mb(s, motion_x, motion_y); in encode_mb_hq()
2719 score= put_bits_count(&s->pb); in encode_mb_hq()
2720 if(s->data_partitioning){ in encode_mb_hq()
2721 score+= put_bits_count(&s->pb2); in encode_mb_hq()
2722 score+= put_bits_count(&s->tex_pb); in encode_mb_hq()
2725 if(s->avctx->mb_decision == FF_MB_DECISION_RD){ in encode_mb_hq()
2726 ff_mpv_reconstruct_mb(s, s->block); in encode_mb_hq()
2728 score *= s->lambda2; in encode_mb_hq()
2729 score += sse_mb(s) << FF_LAMBDA_SHIFT; in encode_mb_hq()
2733 memcpy(s->dest, dest_backup, sizeof(s->dest)); in encode_mb_hq()
2740 copy_context_after_encode(best, s, type); in encode_mb_hq()
2744 static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride){ in sse() argument
2750 return s->mecc.sse[0](NULL, src1, src2, stride, 16); in sse()
2752 return s->mecc.sse[1](NULL, src1, src2, stride, 8); in sse()
2765 static int sse_mb(MpegEncContext *s){ in sse_mb() argument
2769 if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16; in sse_mb()
2770 if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16; in sse_mb()
2773 if(s->avctx->mb_cmp == FF_CMP_NSSE){ in sse_mb()
2774 …return s->mecc.nsse[0](s, s->new_picture.f->data[0] + s->mb_x * 16 + s->mb_y * s->linesize * 16,… in sse_mb()
2775s->mecc.nsse[1](s, s->new_picture.f->data[1] + s->mb_x * 8 + s->mb_y * s->uvlinesize * 8, s->des… in sse_mb()
2776s->mecc.nsse[1](s, s->new_picture.f->data[2] + s->mb_x * 8 + s->mb_y * s->uvlinesize * 8, s->des… in sse_mb()
2778 …return s->mecc.sse[0](NULL, s->new_picture.f->data[0] + s->mb_x * 16 + s->mb_y * s->linesize * 1… in sse_mb()
2779s->mecc.sse[1](NULL, s->new_picture.f->data[1] + s->mb_x * 8 + s->mb_y * s->uvlinesize * 8, s->d… in sse_mb()
2780s->mecc.sse[1](NULL, s->new_picture.f->data[2] + s->mb_x * 8 + s->mb_y * s->uvlinesize * 8, s->d… in sse_mb()
2783 …return sse(s, s->new_picture.f->data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], w, h, in sse_mb()
2784 …+sse(s, s->new_picture.f->data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], w>>1, h>>1, s in sse_mb()
2785 …+sse(s, s->new_picture.f->data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], w>>1, h>>1, s in sse_mb()
2789 MpegEncContext *s= *(void**)arg; in pre_estimate_motion_thread() local
2792 s->me.pre_pass=1; in pre_estimate_motion_thread()
2793 s->me.dia_size= s->avctx->pre_dia_size; in pre_estimate_motion_thread()
2794 s->first_slice_line=1; in pre_estimate_motion_thread()
2795 for(s->mb_y= s->end_mb_y-1; s->mb_y >= s->start_mb_y; s->mb_y--) { in pre_estimate_motion_thread()
2796 for(s->mb_x=s->mb_width-1; s->mb_x >=0 ;s->mb_x--) { in pre_estimate_motion_thread()
2797 ff_pre_estimate_p_frame_motion(s, s->mb_x, s->mb_y); in pre_estimate_motion_thread()
2799 s->first_slice_line=0; in pre_estimate_motion_thread()
2802 s->me.pre_pass=0; in pre_estimate_motion_thread()
2808 MpegEncContext *s= *(void**)arg; in estimate_motion_thread() local
2810 s->me.dia_size= s->avctx->dia_size; in estimate_motion_thread()
2811 s->first_slice_line=1; in estimate_motion_thread()
2812 for(s->mb_y= s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) { in estimate_motion_thread()
2813 s->mb_x=0; //for block init below in estimate_motion_thread()
2814 ff_init_block_index(s); in estimate_motion_thread()
2815 for(s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) { in estimate_motion_thread()
2816 s->block_index[0]+=2; in estimate_motion_thread()
2817 s->block_index[1]+=2; in estimate_motion_thread()
2818 s->block_index[2]+=2; in estimate_motion_thread()
2819 s->block_index[3]+=2; in estimate_motion_thread()
2822 if(s->pict_type==AV_PICTURE_TYPE_B) in estimate_motion_thread()
2823 ff_estimate_b_frame_motion(s, s->mb_x, s->mb_y); in estimate_motion_thread()
2825 ff_estimate_p_frame_motion(s, s->mb_x, s->mb_y); in estimate_motion_thread()
2827 s->first_slice_line=0; in estimate_motion_thread()
2833 MpegEncContext *s= *(void**)arg; in mb_var_thread() local
2836 for(mb_y=s->start_mb_y; mb_y < s->end_mb_y; mb_y++) { in mb_var_thread()
2837 for(mb_x=0; mb_x < s->mb_width; mb_x++) { in mb_var_thread()
2840 uint8_t *pix = s->new_picture.f->data[0] + (yy * s->linesize) + xx; in mb_var_thread()
2842 int sum = s->mpvencdsp.pix_sum(pix, s->linesize); in mb_var_thread()
2844 varc = (s->mpvencdsp.pix_norm1(pix, s->linesize) - in mb_var_thread()
2847 s->current_picture.mb_var [s->mb_stride * mb_y + mb_x] = varc; in mb_var_thread()
2848 s->current_picture.mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8; in mb_var_thread()
2849 s->me.mb_var_sum_temp += varc; in mb_var_thread()
2855 static void write_slice_end(MpegEncContext *s){ in write_slice_end() argument
2856 if(CONFIG_MPEG4_ENCODER && s->codec_id==AV_CODEC_ID_MPEG4){ in write_slice_end()
2857 if(s->partitioned_frame){ in write_slice_end()
2858 ff_mpeg4_merge_partitions(s); in write_slice_end()
2861 ff_mpeg4_stuffing(&s->pb); in write_slice_end()
2862 }else if(CONFIG_MJPEG_ENCODER && s->out_format == FMT_MJPEG){ in write_slice_end()
2863 ff_mjpeg_encode_stuffing(s); in write_slice_end()
2864 } else if (CONFIG_SPEEDHQ_ENCODER && s->out_format == FMT_SPEEDHQ) { in write_slice_end()
2865 ff_speedhq_end_slice(s); in write_slice_end()
2868 flush_put_bits(&s->pb); in write_slice_end()
2870 if ((s->avctx->flags & AV_CODEC_FLAG_PASS1) && !s->partitioned_frame) in write_slice_end()
2871 s->misc_bits+= get_bits_diff(s); in write_slice_end()
2874 static void write_mb_info(MpegEncContext *s) in write_mb_info() argument
2876 uint8_t *ptr = s->mb_info_ptr + s->mb_info_size - 12; in write_mb_info()
2877 int offset = put_bits_count(&s->pb); in write_mb_info()
2878 int mba = s->mb_x + s->mb_width * (s->mb_y % s->gob_index); in write_mb_info()
2879 int gobn = s->mb_y / s->gob_index; in write_mb_info()
2882 ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y); in write_mb_info()
2884 bytestream_put_byte(&ptr, s->qscale); in write_mb_info()
2894 static void update_mb_info(MpegEncContext *s, int startcode) in update_mb_info() argument
2896 if (!s->mb_info) in update_mb_info()
2898 if (put_bits_count(&s->pb) - s->prev_mb_info*8 >= s->mb_info*8) { in update_mb_info()
2899 s->mb_info_size += 12; in update_mb_info()
2900 s->prev_mb_info = s->last_mb_info; in update_mb_info()
2903 s->prev_mb_info = put_bits_count(&s->pb)/8; in update_mb_info()
2911 s->last_mb_info = put_bits_count(&s->pb)/8; in update_mb_info()
2912 if (!s->mb_info_size) in update_mb_info()
2913 s->mb_info_size += 12; in update_mb_info()
2914 write_mb_info(s); in update_mb_info()
2917 int ff_mpv_reallocate_putbitbuffer(MpegEncContext *s, size_t threshold, size_t size_increase) in ff_mpv_reallocate_putbitbuffer() argument
2919 if ( s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < threshold in ff_mpv_reallocate_putbitbuffer()
2920 && s->slice_context_count == 1 in ff_mpv_reallocate_putbitbuffer()
2921 && s->pb.buf == s->avctx->internal->byte_buffer) { in ff_mpv_reallocate_putbitbuffer()
2922 int lastgob_pos = s->ptr_lastgob - s->pb.buf; in ff_mpv_reallocate_putbitbuffer()
2923 int vbv_pos = s->vbv_delay_ptr - s->pb.buf; in ff_mpv_reallocate_putbitbuffer()
2928 if ((s->avctx->internal->byte_buffer_size + size_increase) >= INT_MAX/8) { in ff_mpv_reallocate_putbitbuffer()
2929 av_log(s->avctx, AV_LOG_ERROR, "Cannot reallocate putbit buffer\n"); in ff_mpv_reallocate_putbitbuffer()
2936 s->avctx->internal->byte_buffer_size + size_increase); in ff_mpv_reallocate_putbitbuffer()
2940 memcpy(new_buffer, s->avctx->internal->byte_buffer, s->avctx->internal->byte_buffer_size); in ff_mpv_reallocate_putbitbuffer()
2941 av_free(s->avctx->internal->byte_buffer); in ff_mpv_reallocate_putbitbuffer()
2942 s->avctx->internal->byte_buffer = new_buffer; in ff_mpv_reallocate_putbitbuffer()
2943 s->avctx->internal->byte_buffer_size = new_buffer_size; in ff_mpv_reallocate_putbitbuffer()
2944 rebase_put_bits(&s->pb, new_buffer, new_buffer_size); in ff_mpv_reallocate_putbitbuffer()
2945 s->ptr_lastgob = s->pb.buf + lastgob_pos; in ff_mpv_reallocate_putbitbuffer()
2946 s->vbv_delay_ptr = s->pb.buf + vbv_pos; in ff_mpv_reallocate_putbitbuffer()
2948 if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < threshold) in ff_mpv_reallocate_putbitbuffer()
2954 MpegEncContext *s= *(void**)arg; in encode_thread() local
2956 int chr_h= 16>>s->chroma_y_shift; in encode_thread()
2970 s->last_bits= put_bits_count(&s->pb); in encode_thread()
2971 s->mv_bits=0; in encode_thread()
2972 s->misc_bits=0; in encode_thread()
2973 s->i_tex_bits=0; in encode_thread()
2974 s->p_tex_bits=0; in encode_thread()
2975 s->i_count=0; in encode_thread()
2976 s->f_count=0; in encode_thread()
2977 s->b_count=0; in encode_thread()
2978 s->skip_count=0; in encode_thread()
2983 s->last_dc[i] = 128 << s->intra_dc_precision; in encode_thread()
2985 s->current_picture.encoding_error[i] = 0; in encode_thread()
2987 if(s->codec_id==AV_CODEC_ID_AMV){ in encode_thread()
2988 s->last_dc[0] = 128*8/13; in encode_thread()
2989 s->last_dc[1] = 128*8/14; in encode_thread()
2990 s->last_dc[2] = 128*8/14; in encode_thread()
2992 s->mb_skip_run = 0; in encode_thread()
2993 memset(s->last_mv, 0, sizeof(s->last_mv)); in encode_thread()
2995 s->last_mv_dir = 0; in encode_thread()
2997 switch(s->codec_id){ in encode_thread()
3002 s->gob_index = H263_GOB_HEIGHT(s->height); in encode_thread()
3005 if(CONFIG_MPEG4_ENCODER && s->partitioned_frame) in encode_thread()
3006 ff_mpeg4_init_partitions(s); in encode_thread()
3010 s->resync_mb_x=0; in encode_thread()
3011 s->resync_mb_y=0; in encode_thread()
3012 s->first_slice_line = 1; in encode_thread()
3013 s->ptr_lastgob = s->pb.buf; in encode_thread()
3014 for (mb_y_order = s->start_mb_y; mb_y_order < s->end_mb_y; mb_y_order++) { in encode_thread()
3015 if (CONFIG_SPEEDHQ_ENCODER && s->codec_id == AV_CODEC_ID_SPEEDHQ) { in encode_thread()
3017 mb_y = ff_speedhq_mb_y_order_to_mb(mb_y_order, s->mb_height, &first_in_slice); in encode_thread()
3018 if (first_in_slice && mb_y_order != s->start_mb_y) in encode_thread()
3019 ff_speedhq_end_slice(s); in encode_thread()
3020 s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 1024 << s->intra_dc_precision; in encode_thread()
3024 s->mb_x=0; in encode_thread()
3025 s->mb_y= mb_y; in encode_thread()
3027 ff_set_qscale(s, s->qscale); in encode_thread()
3028 ff_init_block_index(s); in encode_thread()
3030 for(mb_x=0; mb_x < s->mb_width; mb_x++) { in encode_thread()
3031 int xy= mb_y*s->mb_stride + mb_x; // removed const, H261 needs to adjust this in encode_thread()
3032 int mb_type= s->mb_type[xy]; in encode_thread()
3036 int size_increase = s->avctx->internal->byte_buffer_size/4 in encode_thread()
3037 + s->mb_width*MAX_MB_BYTES; in encode_thread()
3039 ff_mpv_reallocate_putbitbuffer(s, MAX_MB_BYTES, size_increase); in encode_thread()
3040 if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < MAX_MB_BYTES){ in encode_thread()
3041 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); in encode_thread()
3044 if(s->data_partitioning){ in encode_thread()
3045 … if( s->pb2 .buf_end - s->pb2 .buf - (put_bits_count(&s-> pb2)>>3) < MAX_MB_BYTES in encode_thread()
3046 … || s->tex_pb.buf_end - s->tex_pb.buf - (put_bits_count(&s->tex_pb )>>3) < MAX_MB_BYTES){ in encode_thread()
3047 av_log(s->avctx, AV_LOG_ERROR, "encoded partitioned frame too large\n"); in encode_thread()
3052 s->mb_x = mb_x; in encode_thread()
3053 s->mb_y = mb_y; // moved into loop, can get changed by H.261 in encode_thread()
3054 ff_update_block_index(s); in encode_thread()
3056 if(CONFIG_H261_ENCODER && s->codec_id == AV_CODEC_ID_H261){ in encode_thread()
3057 ff_h261_reorder_mb_index(s); in encode_thread()
3058 xy= s->mb_y*s->mb_stride + s->mb_x; in encode_thread()
3059 mb_type= s->mb_type[xy]; in encode_thread()
3063 if(s->rtp_mode){ in encode_thread()
3066 current_packet_size= ((put_bits_count(&s->pb)+7)>>3) - (s->ptr_lastgob - s->pb.buf); in encode_thread()
3068 is_gob_start = s->rtp_payload_size && in encode_thread()
3069 current_packet_size >= s->rtp_payload_size && in encode_thread()
3072 if(s->start_mb_y == mb_y && mb_y > 0 && mb_x==0) is_gob_start=1; in encode_thread()
3074 switch(s->codec_id){ in encode_thread()
3077 if(!s->h263_slice_structured) in encode_thread()
3078 if(s->mb_x || s->mb_y%s->gob_index) is_gob_start=0; in encode_thread()
3081 if(s->mb_x==0 && s->mb_y!=0) is_gob_start=1; in encode_thread()
3083 if(s->mb_skip_run) is_gob_start=0; in encode_thread()
3086 if(s->mb_x==0 && s->mb_y!=0) is_gob_start=1; in encode_thread()
3091 if(s->start_mb_y != mb_y || mb_x!=0){ in encode_thread()
3092 write_slice_end(s); in encode_thread()
3094 … if(CONFIG_MPEG4_ENCODER && s->codec_id==AV_CODEC_ID_MPEG4 && s->partitioned_frame){ in encode_thread()
3095 ff_mpeg4_init_partitions(s); in encode_thread()
3099 av_assert2((put_bits_count(&s->pb)&7) == 0); in encode_thread()
3100 current_packet_size= put_bits_ptr(&s->pb) - s->ptr_lastgob; in encode_thread()
3102 if (s->error_rate && s->resync_mb_x + s->resync_mb_y > 0) { in encode_thread()
3103 … int r= put_bits_count(&s->pb)/8 + s->picture_number + 16 + s->mb_x + s->mb_y; in encode_thread()
3104 int d = 100 / s->error_rate; in encode_thread()
3107 s->pb.buf_ptr= s->ptr_lastgob; in encode_thread()
3108 av_assert1(put_bits_ptr(&s->pb) == s->ptr_lastgob); in encode_thread()
3114 if (s->avctx->rtp_callback){ in encode_thread()
3115 int number_mb = (mb_y - s->resync_mb_y)*s->mb_width + mb_x - s->resync_mb_x; in encode_thread()
3116s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, current_packet_size, number_mb); in encode_thread()
3120 update_mb_info(s, 1); in encode_thread()
3122 switch(s->codec_id){ in encode_thread()
3125 ff_mpeg4_encode_video_packet_header(s); in encode_thread()
3126 ff_mpeg4_clean_buffers(s); in encode_thread()
3132 ff_mpeg1_encode_slice_header(s); in encode_thread()
3133 ff_mpeg1_clean_buffers(s); in encode_thread()
3139 ff_h263_encode_gob_header(s, mb_y); in encode_thread()
3143 if (s->avctx->flags & AV_CODEC_FLAG_PASS1) { in encode_thread()
3144 int bits= put_bits_count(&s->pb); in encode_thread()
3145 s->misc_bits+= bits - s->last_bits; in encode_thread()
3146 s->last_bits= bits; in encode_thread()
3149 s->ptr_lastgob += current_packet_size; in encode_thread()
3150 s->first_slice_line=1; in encode_thread()
3151 s->resync_mb_x=mb_x; in encode_thread()
3152 s->resync_mb_y=mb_y; in encode_thread()
3156 if( (s->resync_mb_x == s->mb_x) in encode_thread()
3157 && s->resync_mb_y+1 == s->mb_y){ in encode_thread()
3158 s->first_slice_line=0; in encode_thread()
3161 s->mb_skipped=0; in encode_thread()
3162 s->dquant=0; //only for QP_RD in encode_thread()
3164 update_mb_info(s, 0); in encode_thread()
3166 …if (mb_type & (mb_type-1) || (s->mpv_flags & FF_MPV_FLAG_QP_RD)) { // more than 1 MB type possible… in encode_thread()
3170 copy_context_before_encode(&backup_s, s, -1); in encode_thread()
3171 backup_s.pb= s->pb; in encode_thread()
3172 best_s.data_partitioning= s->data_partitioning; in encode_thread()
3173 best_s.partitioned_frame= s->partitioned_frame; in encode_thread()
3174 if(s->data_partitioning){ in encode_thread()
3175 backup_s.pb2= s->pb2; in encode_thread()
3176 backup_s.tex_pb= s->tex_pb; in encode_thread()
3180 s->mv_dir = MV_DIR_FORWARD; in encode_thread()
3181 s->mv_type = MV_TYPE_16X16; in encode_thread()
3182 s->mb_intra= 0; in encode_thread()
3183 s->mv[0][0][0] = s->p_mv_table[xy][0]; in encode_thread()
3184 s->mv[0][0][1] = s->p_mv_table[xy][1]; in encode_thread()
3185 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER, pb, pb2, tex_pb, in encode_thread()
3186 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); in encode_thread()
3189 s->mv_dir = MV_DIR_FORWARD; in encode_thread()
3190 s->mv_type = MV_TYPE_FIELD; in encode_thread()
3191 s->mb_intra= 0; in encode_thread()
3193 j= s->field_select[0][i] = s->p_field_select_table[i][xy]; in encode_thread()
3194 s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0]; in encode_thread()
3195 s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1]; in encode_thread()
3197 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER_I, pb, pb2, tex_pb, in encode_thread()
3201 s->mv_dir = MV_DIR_FORWARD; in encode_thread()
3202 s->mv_type = MV_TYPE_16X16; in encode_thread()
3203 s->mb_intra= 0; in encode_thread()
3204 s->mv[0][0][0] = 0; in encode_thread()
3205 s->mv[0][0][1] = 0; in encode_thread()
3206 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_SKIPPED, pb, pb2, tex_pb, in encode_thread()
3207 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); in encode_thread()
3210 s->mv_dir = MV_DIR_FORWARD; in encode_thread()
3211 s->mv_type = MV_TYPE_8X8; in encode_thread()
3212 s->mb_intra= 0; in encode_thread()
3214 s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0]; in encode_thread()
3215 s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1]; in encode_thread()
3217 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER4V, pb, pb2, tex_pb, in encode_thread()
3221 s->mv_dir = MV_DIR_FORWARD; in encode_thread()
3222 s->mv_type = MV_TYPE_16X16; in encode_thread()
3223 s->mb_intra= 0; in encode_thread()
3224 s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; in encode_thread()
3225 s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; in encode_thread()
3226 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD, pb, pb2, tex_pb, in encode_thread()
3227 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); in encode_thread()
3230 s->mv_dir = MV_DIR_BACKWARD; in encode_thread()
3231 s->mv_type = MV_TYPE_16X16; in encode_thread()
3232 s->mb_intra= 0; in encode_thread()
3233 s->mv[1][0][0] = s->b_back_mv_table[xy][0]; in encode_thread()
3234 s->mv[1][0][1] = s->b_back_mv_table[xy][1]; in encode_thread()
3235 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD, pb, pb2, tex_pb, in encode_thread()
3236 &dmin, &next_block, s->mv[1][0][0], s->mv[1][0][1]); in encode_thread()
3239 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; in encode_thread()
3240 s->mv_type = MV_TYPE_16X16; in encode_thread()
3241 s->mb_intra= 0; in encode_thread()
3242 s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; in encode_thread()
3243 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; in encode_thread()
3244 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; in encode_thread()
3245 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; in encode_thread()
3246 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR, pb, pb2, tex_pb, in encode_thread()
3250 s->mv_dir = MV_DIR_FORWARD; in encode_thread()
3251 s->mv_type = MV_TYPE_FIELD; in encode_thread()
3252 s->mb_intra= 0; in encode_thread()
3254 j= s->field_select[0][i] = s->b_field_select_table[0][i][xy]; in encode_thread()
3255 s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0]; in encode_thread()
3256 s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1]; in encode_thread()
3258 … encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD_I, pb, pb2, tex_pb, in encode_thread()
3262 s->mv_dir = MV_DIR_BACKWARD; in encode_thread()
3263 s->mv_type = MV_TYPE_FIELD; in encode_thread()
3264 s->mb_intra= 0; in encode_thread()
3266 j= s->field_select[1][i] = s->b_field_select_table[1][i][xy]; in encode_thread()
3267 s->mv[1][i][0] = s->b_field_mv_table[1][i][j][xy][0]; in encode_thread()
3268 s->mv[1][i][1] = s->b_field_mv_table[1][i][j][xy][1]; in encode_thread()
3270 … encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD_I, pb, pb2, tex_pb, in encode_thread()
3274 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; in encode_thread()
3275 s->mv_type = MV_TYPE_FIELD; in encode_thread()
3276 s->mb_intra= 0; in encode_thread()
3279 j= s->field_select[dir][i] = s->b_field_select_table[dir][i][xy]; in encode_thread()
3280 s->mv[dir][i][0] = s->b_field_mv_table[dir][i][j][xy][0]; in encode_thread()
3281 s->mv[dir][i][1] = s->b_field_mv_table[dir][i][j][xy][1]; in encode_thread()
3284 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR_I, pb, pb2, tex_pb, in encode_thread()
3288 s->mv_dir = 0; in encode_thread()
3289 s->mv_type = MV_TYPE_16X16; in encode_thread()
3290 s->mb_intra= 1; in encode_thread()
3291 s->mv[0][0][0] = 0; in encode_thread()
3292 s->mv[0][0][1] = 0; in encode_thread()
3293 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTRA, pb, pb2, tex_pb, in encode_thread()
3295 if(s->h263_pred || s->h263_aic){ in encode_thread()
3297 s->mbintra_table[mb_x + mb_y*s->mb_stride]=1; in encode_thread()
3299 ff_clean_intra_table_entries(s); //old mode? in encode_thread()
3303 if ((s->mpv_flags & FF_MPV_FLAG_QP_RD) && dmin < INT_MAX) { in encode_thread()
3310 int storecoefs = s->mb_intra && s->dc_val[0]; in encode_thread()
3315 s->mv_dir= best_s.mv_dir; in encode_thread()
3316 s->mv_type = MV_TYPE_16X16; in encode_thread()
3317 s->mb_intra= best_s.mb_intra; in encode_thread()
3318 s->mv[0][0][0] = best_s.mv[0][0][0]; in encode_thread()
3319 s->mv[0][0][1] = best_s.mv[0][0][1]; in encode_thread()
3320 s->mv[1][0][0] = best_s.mv[1][0][0]; in encode_thread()
3321 s->mv[1][0][1] = best_s.mv[1][0][1]; in encode_thread()
3323 qpi = s->pict_type == AV_PICTURE_TYPE_B ? 2 : 0; in encode_thread()
3327 if(qp < s->avctx->qmin || qp > s->avctx->qmax) in encode_thread()
3332 dc[i]= s->dc_val[0][ s->block_index[i] ]; in encode_thread()
3333 … memcpy(ac[i], s->ac_val[0][s->block_index[i]], sizeof(int16_t)*16); in encode_thread()
3337 …encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER /* wrong but unused */, pb, pb2, tex_p… in encode_thread()
3338 … &dmin, &next_block, s->mv[mvdir][0][0], s->mv[mvdir][0][1]); in encode_thread()
3342 s->dc_val[0][ s->block_index[i] ]= dc[i]; in encode_thread()
3343 … memcpy(s->ac_val[0][s->block_index[i]], ac[i], sizeof(int16_t)*16); in encode_thread()
3351 int mx= s->b_direct_mv_table[xy][0]; in encode_thread()
3352 int my= s->b_direct_mv_table[xy][1]; in encode_thread()
3355 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; in encode_thread()
3356 s->mb_intra= 0; in encode_thread()
3357 ff_mpeg4_set_direct_mv(s, mx, my); in encode_thread()
3358 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb, in encode_thread()
3363 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; in encode_thread()
3364 s->mb_intra= 0; in encode_thread()
3365 ff_mpeg4_set_direct_mv(s, 0, 0); in encode_thread()
3366 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb, in encode_thread()
3369 if (!best_s.mb_intra && s->mpv_flags & FF_MPV_FLAG_SKIP_RD) { in encode_thread()
3372 coded |= s->block_last_index[i]; in encode_thread()
3375 memcpy(s->mv, best_s.mv, sizeof(s->mv)); in encode_thread()
3378 ff_mpeg4_set_direct_mv(s, mx, my); in encode_thread()
3380 mx= s->mv[1][0][0]; in encode_thread()
3381 my= s->mv[1][0][1]; in encode_thread()
3383 mx= s->mv[0][0][0]; in encode_thread()
3384 my= s->mv[0][0][1]; in encode_thread()
3387 s->mv_dir= best_s.mv_dir; in encode_thread()
3388 s->mv_type = best_s.mv_type; in encode_thread()
3389 s->mb_intra= 0; in encode_thread()
3395 s->skipdct=1; in encode_thread()
3396 …encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER /* wrong but unused */, pb, pb2, tex_p… in encode_thread()
3398 s->skipdct=0; in encode_thread()
3402 s->current_picture.qscale_table[xy] = best_s.qscale; in encode_thread()
3404 copy_context_after_encode(s, &best_s, -1); in encode_thread()
3406 pb_bits_count= put_bits_count(&s->pb); in encode_thread()
3407 flush_put_bits(&s->pb); in encode_thread()
3409 s->pb= backup_s.pb; in encode_thread()
3411 if(s->data_partitioning){ in encode_thread()
3412 pb2_bits_count= put_bits_count(&s->pb2); in encode_thread()
3413 flush_put_bits(&s->pb2); in encode_thread()
3415 s->pb2= backup_s.pb2; in encode_thread()
3417 tex_pb_bits_count= put_bits_count(&s->tex_pb); in encode_thread()
3418 flush_put_bits(&s->tex_pb); in encode_thread()
3420 s->tex_pb= backup_s.tex_pb; in encode_thread()
3422 s->last_bits= put_bits_count(&s->pb); in encode_thread()
3425 s->out_format == FMT_H263 && s->pict_type!=AV_PICTURE_TYPE_B) in encode_thread()
3426 ff_h263_update_motion_val(s); in encode_thread()
3429s->hdsp.put_pixels_tab[0][0](s->dest[0], s->sc.rd_scratchpad , s->linesize ,1… in encode_thread()
3430s->hdsp.put_pixels_tab[1][0](s->dest[1], s->sc.rd_scratchpad + 16*s->linesize , s->uvlinesize, … in encode_thread()
3431s->hdsp.put_pixels_tab[1][0](s->dest[2], s->sc.rd_scratchpad + 16*s->linesize + 8, s->uvlinesize, … in encode_thread()
3434 if(s->avctx->mb_decision == FF_MB_DECISION_BITS) in encode_thread()
3435 ff_mpv_reconstruct_mb(s, s->block); in encode_thread()
3438 s->mv_type=MV_TYPE_16X16; in encode_thread()
3443 s->mv_dir = 0; in encode_thread()
3444 s->mb_intra= 1; in encode_thread()
3445 motion_x= s->mv[0][0][0] = 0; in encode_thread()
3446 motion_y= s->mv[0][0][1] = 0; in encode_thread()
3449 s->mv_dir = MV_DIR_FORWARD; in encode_thread()
3450 s->mb_intra= 0; in encode_thread()
3451 motion_x= s->mv[0][0][0] = s->p_mv_table[xy][0]; in encode_thread()
3452 motion_y= s->mv[0][0][1] = s->p_mv_table[xy][1]; in encode_thread()
3455 s->mv_dir = MV_DIR_FORWARD; in encode_thread()
3456 s->mv_type = MV_TYPE_FIELD; in encode_thread()
3457 s->mb_intra= 0; in encode_thread()
3459 j= s->field_select[0][i] = s->p_field_select_table[i][xy]; in encode_thread()
3460 s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0]; in encode_thread()
3461 s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1]; in encode_thread()
3465 s->mv_dir = MV_DIR_FORWARD; in encode_thread()
3466 s->mv_type = MV_TYPE_8X8; in encode_thread()
3467 s->mb_intra= 0; in encode_thread()
3469 s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0]; in encode_thread()
3470 s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1]; in encode_thread()
3475 s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD|MV_DIRECT; in encode_thread()
3476 s->mb_intra= 0; in encode_thread()
3477 motion_x=s->b_direct_mv_table[xy][0]; in encode_thread()
3478 motion_y=s->b_direct_mv_table[xy][1]; in encode_thread()
3479 ff_mpeg4_set_direct_mv(s, motion_x, motion_y); in encode_thread()
3484 s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD|MV_DIRECT; in encode_thread()
3485 s->mb_intra= 0; in encode_thread()
3486 ff_mpeg4_set_direct_mv(s, 0, 0); in encode_thread()
3490 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; in encode_thread()
3491 s->mb_intra= 0; in encode_thread()
3492 s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; in encode_thread()
3493 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; in encode_thread()
3494 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; in encode_thread()
3495 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; in encode_thread()
3498 s->mv_dir = MV_DIR_BACKWARD; in encode_thread()
3499 s->mb_intra= 0; in encode_thread()
3500 motion_x= s->mv[1][0][0] = s->b_back_mv_table[xy][0]; in encode_thread()
3501 motion_y= s->mv[1][0][1] = s->b_back_mv_table[xy][1]; in encode_thread()
3504 s->mv_dir = MV_DIR_FORWARD; in encode_thread()
3505 s->mb_intra= 0; in encode_thread()
3506 motion_x= s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; in encode_thread()
3507 motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; in encode_thread()
3510 s->mv_dir = MV_DIR_FORWARD; in encode_thread()
3511 s->mv_type = MV_TYPE_FIELD; in encode_thread()
3512 s->mb_intra= 0; in encode_thread()
3514 j= s->field_select[0][i] = s->b_field_select_table[0][i][xy]; in encode_thread()
3515 s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0]; in encode_thread()
3516 s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1]; in encode_thread()
3520 s->mv_dir = MV_DIR_BACKWARD; in encode_thread()
3521 s->mv_type = MV_TYPE_FIELD; in encode_thread()
3522 s->mb_intra= 0; in encode_thread()
3524 j= s->field_select[1][i] = s->b_field_select_table[1][i][xy]; in encode_thread()
3525 s->mv[1][i][0] = s->b_field_mv_table[1][i][j][xy][0]; in encode_thread()
3526 s->mv[1][i][1] = s->b_field_mv_table[1][i][j][xy][1]; in encode_thread()
3530 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; in encode_thread()
3531 s->mv_type = MV_TYPE_FIELD; in encode_thread()
3532 s->mb_intra= 0; in encode_thread()
3535 j= s->field_select[dir][i] = s->b_field_select_table[dir][i][xy]; in encode_thread()
3536 s->mv[dir][i][0] = s->b_field_mv_table[dir][i][j][xy][0]; in encode_thread()
3537 s->mv[dir][i][1] = s->b_field_mv_table[dir][i][j][xy][1]; in encode_thread()
3542 av_log(s->avctx, AV_LOG_ERROR, "illegal MB type\n"); in encode_thread()
3545 encode_mb(s, motion_x, motion_y); in encode_thread()
3548 s->last_mv_dir = s->mv_dir; in encode_thread()
3551 s->out_format == FMT_H263 && s->pict_type!=AV_PICTURE_TYPE_B) in encode_thread()
3552 ff_h263_update_motion_val(s); in encode_thread()
3554 ff_mpv_reconstruct_mb(s, s->block); in encode_thread()
3558 if(s->mb_intra /* && I,P,S_TYPE */){ in encode_thread()
3559 s->p_mv_table[xy][0]=0; in encode_thread()
3560 s->p_mv_table[xy][1]=0; in encode_thread()
3563 if (s->avctx->flags & AV_CODEC_FLAG_PSNR) { in encode_thread()
3567 if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16; in encode_thread()
3568 if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16; in encode_thread()
3570 s->current_picture.encoding_error[0] += sse( in encode_thread()
3571 s, s->new_picture.f->data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, in encode_thread()
3572 s->dest[0], w, h, s->linesize); in encode_thread()
3573 s->current_picture.encoding_error[1] += sse( in encode_thread()
3574 s, s->new_picture.f->data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*chr_h, in encode_thread()
3575 s->dest[1], w>>1, h>>s->chroma_y_shift, s->uvlinesize); in encode_thread()
3576 s->current_picture.encoding_error[2] += sse( in encode_thread()
3577 s, s->new_picture.f->data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*chr_h, in encode_thread()
3578 s->dest[2], w>>1, h>>s->chroma_y_shift, s->uvlinesize); in encode_thread()
3580 if(s->loop_filter){ in encode_thread()
3581 if(CONFIG_H263_ENCODER && s->out_format == FMT_H263) in encode_thread()
3582 ff_h263_loop_filter(s); in encode_thread()
3584 ff_dlog(s->avctx, "MB %d %d bits\n", in encode_thread()
3585 s->mb_x + s->mb_y * s->mb_stride, put_bits_count(&s->pb)); in encode_thread()
3590 …if (CONFIG_MSMPEG4_ENCODER && s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == AV_PIC… in encode_thread()
3591 ff_msmpeg4_encode_ext_header(s); in encode_thread()
3593 write_slice_end(s); in encode_thread()
3598 if (s->avctx->rtp_callback) { in encode_thread()
3599 int number_mb = (mb_y - s->resync_mb_y)*s->mb_width - s->resync_mb_x; in encode_thread()
3600 int pdif = put_bits_ptr(&s->pb) - s->ptr_lastgob; in encode_thread()
3603 s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, pdif, number_mb); in encode_thread()
3650 static int estimate_qp(MpegEncContext *s, int dry_run){ in estimate_qp() argument
3651 if (s->next_lambda){ in estimate_qp()
3652 s->current_picture_ptr->f->quality = in estimate_qp()
3653 s->current_picture.f->quality = s->next_lambda; in estimate_qp()
3654 if(!dry_run) s->next_lambda= 0; in estimate_qp()
3655 } else if (!s->fixed_qscale) { in estimate_qp()
3656 int quality = ff_rate_estimate_qscale(s, dry_run); in estimate_qp()
3657 s->current_picture_ptr->f->quality = in estimate_qp()
3658 s->current_picture.f->quality = quality; in estimate_qp()
3659 if (s->current_picture.f->quality < 0) in estimate_qp()
3663 if(s->adaptive_quant){ in estimate_qp()
3664 switch(s->codec_id){ in estimate_qp()
3667 ff_clean_mpeg4_qscales(s); in estimate_qp()
3673 ff_clean_h263_qscales(s); in estimate_qp()
3676 ff_init_qscale_tab(s); in estimate_qp()
3679 s->lambda= s->lambda_table[0]; in estimate_qp()
3682 s->lambda = s->current_picture.f->quality; in estimate_qp()
3683 update_qscale(s); in estimate_qp()
3688 static void set_frame_distances(MpegEncContext * s){ in set_frame_distances() argument
3689 av_assert1(s->current_picture_ptr->f->pts != AV_NOPTS_VALUE); in set_frame_distances()
3690 s->time = s->current_picture_ptr->f->pts * s->avctx->time_base.num; in set_frame_distances()
3692 if(s->pict_type==AV_PICTURE_TYPE_B){ in set_frame_distances()
3693 s->pb_time= s->pp_time - (s->last_non_b_time - s->time); in set_frame_distances()
3694 av_assert1(s->pb_time > 0 && s->pb_time < s->pp_time); in set_frame_distances()
3696 s->pp_time= s->time - s->last_non_b_time; in set_frame_distances()
3697 s->last_non_b_time= s->time; in set_frame_distances()
3698 av_assert1(s->picture_number==0 || s->pp_time > 0); in set_frame_distances()
3702 static int encode_picture(MpegEncContext *s, int picture_number) in encode_picture() argument
3706 int context_count = s->slice_context_count; in encode_picture()
3708 s->picture_number = picture_number; in encode_picture()
3711 s->me.mb_var_sum_temp = in encode_picture()
3712 s->me.mc_mb_var_sum_temp = 0; in encode_picture()
3716 …if (s->codec_id == AV_CODEC_ID_MPEG1VIDEO || s->codec_id == AV_CODEC_ID_MPEG2VIDEO || (s->h263_pre… in encode_picture()
3717 set_frame_distances(s); in encode_picture()
3718 if(CONFIG_MPEG4_ENCODER && s->codec_id == AV_CODEC_ID_MPEG4) in encode_picture()
3719 ff_set_mpeg4_time(s); in encode_picture()
3721 s->me.scene_change_score=0; in encode_picture()
3725 if(s->pict_type==AV_PICTURE_TYPE_I){ in encode_picture()
3726 if(s->msmpeg4_version >= 3) s->no_rounding=1; in encode_picture()
3727 else s->no_rounding=0; in encode_picture()
3728 }else if(s->pict_type!=AV_PICTURE_TYPE_B){ in encode_picture()
3729 … if(s->flipflop_rounding || s->codec_id == AV_CODEC_ID_H263P || s->codec_id == AV_CODEC_ID_MPEG4) in encode_picture()
3730 s->no_rounding ^= 1; in encode_picture()
3733 if (s->avctx->flags & AV_CODEC_FLAG_PASS2) { in encode_picture()
3734 if (estimate_qp(s,1) < 0) in encode_picture()
3736 ff_get_2pass_fcode(s); in encode_picture()
3737 } else if (!(s->avctx->flags & AV_CODEC_FLAG_QSCALE)) { in encode_picture()
3738 if(s->pict_type==AV_PICTURE_TYPE_B) in encode_picture()
3739 s->lambda= s->last_lambda_for[s->pict_type]; in encode_picture()
3741 s->lambda= s->last_lambda_for[s->last_non_b_pict_type]; in encode_picture()
3742 update_qscale(s); in encode_picture()
3745 if(s->codec_id != AV_CODEC_ID_AMV && s->codec_id != AV_CODEC_ID_MJPEG){ in encode_picture()
3746 if(s->q_chroma_intra_matrix != s->q_intra_matrix ) av_freep(&s->q_chroma_intra_matrix); in encode_picture()
3747 if(s->q_chroma_intra_matrix16 != s->q_intra_matrix16) av_freep(&s->q_chroma_intra_matrix16); in encode_picture()
3748 s->q_chroma_intra_matrix = s->q_intra_matrix; in encode_picture()
3749 s->q_chroma_intra_matrix16 = s->q_intra_matrix16; in encode_picture()
3752 s->mb_intra=0; //for the rate distortion & bit compare functions in encode_picture()
3754 ret = ff_update_duplicate_context(s->thread_context[i], s); in encode_picture()
3759 if(ff_init_me(s)<0) in encode_picture()
3763 if(s->pict_type != AV_PICTURE_TYPE_I){ in encode_picture()
3764 s->lambda = (s->lambda * s->me_penalty_compensation + 128) >> 8; in encode_picture()
3765 s->lambda2 = (s->lambda2 * (int64_t) s->me_penalty_compensation + 128) >> 8; in encode_picture()
3766 if (s->pict_type != AV_PICTURE_TYPE_B) { in encode_picture()
3767 if ((s->me_pre && s->last_non_b_pict_type == AV_PICTURE_TYPE_I) || in encode_picture()
3768 s->me_pre == 2) { in encode_picture()
3769s->avctx->execute(s->avctx, pre_estimate_motion_thread, &s->thread_context[0], NULL, context_count… in encode_picture()
3773s->avctx->execute(s->avctx, estimate_motion_thread, &s->thread_context[0], NULL, context_count, si… in encode_picture()
3776 for(i=0; i<s->mb_stride*s->mb_height; i++) in encode_picture()
3777 s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA; in encode_picture()
3779 if(!s->fixed_qscale){ in encode_picture()
3781s->avctx->execute(s->avctx, mb_var_thread, &s->thread_context[0], NULL, context_count, sizeof(void… in encode_picture()
3785 merge_context_after_me(s, s->thread_context[i]); in encode_picture()
3787s->current_picture.mc_mb_var_sum= s->current_picture_ptr->mc_mb_var_sum= s->me.mc_mb_var_sum_temp; in encode_picture()
3788s->current_picture. mb_var_sum= s->current_picture_ptr-> mb_var_sum= s->me. mb_var_sum_temp; in encode_picture()
3791 if (s->me.scene_change_score > s->scenechange_threshold && in encode_picture()
3792 s->pict_type == AV_PICTURE_TYPE_P) { in encode_picture()
3793 s->pict_type= AV_PICTURE_TYPE_I; in encode_picture()
3794 for(i=0; i<s->mb_stride*s->mb_height; i++) in encode_picture()
3795 s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA; in encode_picture()
3796 if(s->msmpeg4_version >= 3) in encode_picture()
3797 s->no_rounding=1; in encode_picture()
3798 ff_dlog(s, "Scene change detected, encoding as I Frame %"PRId64" %"PRId64"\n", in encode_picture()
3799 s->current_picture.mb_var_sum, s->current_picture.mc_mb_var_sum); in encode_picture()
3802 if(!s->umvplus){ in encode_picture()
3803 if(s->pict_type==AV_PICTURE_TYPE_P || s->pict_type==AV_PICTURE_TYPE_S) { in encode_picture()
3804 s->f_code= ff_get_best_fcode(s, s->p_mv_table, CANDIDATE_MB_TYPE_INTER); in encode_picture()
3806 if (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME) { in encode_picture()
3808 …a= ff_get_best_fcode(s, s->p_field_mv_table[0][0], CANDIDATE_MB_TYPE_INTER_I); //FIXME field_select in encode_picture()
3809 b= ff_get_best_fcode(s, s->p_field_mv_table[1][1], CANDIDATE_MB_TYPE_INTER_I); in encode_picture()
3810 s->f_code= FFMAX3(s->f_code, a, b); in encode_picture()
3813 … ff_fix_long_p_mvs(s, s->intra_penalty ? CANDIDATE_MB_TYPE_INTER : CANDIDATE_MB_TYPE_INTRA); in encode_picture()
3814 …ff_fix_long_mvs(s, NULL, 0, s->p_mv_table, s->f_code, CANDIDATE_MB_TYPE_INTER, !!s->intra_penalty); in encode_picture()
3815 if (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME) { in encode_picture()
3819 ff_fix_long_mvs(s, s->p_field_select_table[i], j, in encode_picture()
3820s->p_field_mv_table[i][j], s->f_code, CANDIDATE_MB_TYPE_INTER_I, !!s->intra_penalty); in encode_picture()
3825 if(s->pict_type==AV_PICTURE_TYPE_B){ in encode_picture()
3828 a = ff_get_best_fcode(s, s->b_forw_mv_table, CANDIDATE_MB_TYPE_FORWARD); in encode_picture()
3829 b = ff_get_best_fcode(s, s->b_bidir_forw_mv_table, CANDIDATE_MB_TYPE_BIDIR); in encode_picture()
3830 s->f_code = FFMAX(a, b); in encode_picture()
3832 a = ff_get_best_fcode(s, s->b_back_mv_table, CANDIDATE_MB_TYPE_BACKWARD); in encode_picture()
3833 b = ff_get_best_fcode(s, s->b_bidir_back_mv_table, CANDIDATE_MB_TYPE_BIDIR); in encode_picture()
3834 s->b_code = FFMAX(a, b); in encode_picture()
3836 … ff_fix_long_mvs(s, NULL, 0, s->b_forw_mv_table, s->f_code, CANDIDATE_MB_TYPE_FORWARD, 1); in encode_picture()
3837 … ff_fix_long_mvs(s, NULL, 0, s->b_back_mv_table, s->b_code, CANDIDATE_MB_TYPE_BACKWARD, 1); in encode_picture()
3838 … ff_fix_long_mvs(s, NULL, 0, s->b_bidir_forw_mv_table, s->f_code, CANDIDATE_MB_TYPE_BIDIR, 1); in encode_picture()
3839 … ff_fix_long_mvs(s, NULL, 0, s->b_bidir_back_mv_table, s->b_code, CANDIDATE_MB_TYPE_BIDIR, 1); in encode_picture()
3840 if (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME) { in encode_picture()
3847 ff_fix_long_mvs(s, s->b_field_select_table[dir][i], j, in encode_picture()
3848s->b_field_mv_table[dir][i][j], dir ? s->b_code : s->f_code, type, 1); in encode_picture()
3856 if (estimate_qp(s, 0) < 0) in encode_picture()
3859 if (s->qscale < 3 && s->max_qcoeff <= 128 && in encode_picture()
3860 s->pict_type == AV_PICTURE_TYPE_I && in encode_picture()
3861 !(s->avctx->flags & AV_CODEC_FLAG_QSCALE)) in encode_picture()
3862 s->qscale= 3; //reduce clipping problems in encode_picture()
3864 if (s->out_format == FMT_MJPEG) { in encode_picture()
3868 if (s->avctx->intra_matrix) { in encode_picture()
3870 luma_matrix = s->avctx->intra_matrix; in encode_picture()
3872 if (s->avctx->chroma_intra_matrix) in encode_picture()
3873 chroma_matrix = s->avctx->chroma_intra_matrix; in encode_picture()
3877 int j = s->idsp.idct_permutation[i]; in encode_picture()
3879 s->chroma_intra_matrix[j] = av_clip_uint8((chroma_matrix[i] * s->qscale) >> 3); in encode_picture()
3880 s-> intra_matrix[j] = av_clip_uint8(( luma_matrix[i] * s->qscale) >> 3); in encode_picture()
3882 s->y_dc_scale_table= in encode_picture()
3883 s->c_dc_scale_table= ff_mpeg2_dc_scale_table[s->intra_dc_precision]; in encode_picture()
3884 s->chroma_intra_matrix[0] = in encode_picture()
3885 s->intra_matrix[0] = ff_mpeg2_dc_scale_table[s->intra_dc_precision][8]; in encode_picture()
3886 ff_convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16, in encode_picture()
3887 s->intra_matrix, s->intra_quant_bias, 8, 8, 1); in encode_picture()
3888 ff_convert_matrix(s, s->q_chroma_intra_matrix, s->q_chroma_intra_matrix16, in encode_picture()
3889 s->chroma_intra_matrix, s->intra_quant_bias, 8, 8, 1); in encode_picture()
3890 s->qscale= 8; in encode_picture()
3892 if(s->codec_id == AV_CODEC_ID_AMV){ in encode_picture()
3896 int j= s->idsp.idct_permutation[ff_zigzag_direct[i]]; in encode_picture()
3898 s->intra_matrix[j] = sp5x_qscale_five_quant_table[0][i]; in encode_picture()
3899 s->chroma_intra_matrix[j] = sp5x_qscale_five_quant_table[1][i]; in encode_picture()
3901 s->y_dc_scale_table= y; in encode_picture()
3902 s->c_dc_scale_table= c; in encode_picture()
3903 s->intra_matrix[0] = 13; in encode_picture()
3904 s->chroma_intra_matrix[0] = 14; in encode_picture()
3905 ff_convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16, in encode_picture()
3906 s->intra_matrix, s->intra_quant_bias, 8, 8, 1); in encode_picture()
3907 ff_convert_matrix(s, s->q_chroma_intra_matrix, s->q_chroma_intra_matrix16, in encode_picture()
3908 s->chroma_intra_matrix, s->intra_quant_bias, 8, 8, 1); in encode_picture()
3909 s->qscale= 8; in encode_picture()
3912 if (s->out_format == FMT_SPEEDHQ) { in encode_picture()
3913 s->y_dc_scale_table= in encode_picture()
3914 s->c_dc_scale_table= ff_mpeg2_dc_scale_table[3]; in encode_picture()
3918 s->current_picture_ptr->f->key_frame = in encode_picture()
3919 s->current_picture.f->key_frame = s->pict_type == AV_PICTURE_TYPE_I; //FIXME pic_ptr in encode_picture()
3920 s->current_picture_ptr->f->pict_type = in encode_picture()
3921 s->current_picture.f->pict_type = s->pict_type; in encode_picture()
3923 if (s->current_picture.f->key_frame) in encode_picture()
3924 s->picture_in_gop_number=0; in encode_picture()
3926 s->mb_x = s->mb_y = 0; in encode_picture()
3927 s->last_bits= put_bits_count(&s->pb); in encode_picture()
3928 switch(s->out_format) { in encode_picture()
3930 if (CONFIG_MJPEG_ENCODER && s->huffman != HUFFMAN_TABLE_OPTIMAL) in encode_picture()
3931 ff_mjpeg_encode_picture_header(s->avctx, &s->pb, &s->intra_scantable, in encode_picture()
3932 s->pred, s->intra_matrix, s->chroma_intra_matrix); in encode_picture()
3936 ff_speedhq_encode_picture_header(s); in encode_picture()
3940 ff_h261_encode_picture_header(s, picture_number); in encode_picture()
3943 if (CONFIG_WMV2_ENCODER && s->codec_id == AV_CODEC_ID_WMV2) in encode_picture()
3944 ff_wmv2_encode_picture_header(s, picture_number); in encode_picture()
3945 else if (CONFIG_MSMPEG4_ENCODER && s->msmpeg4_version) in encode_picture()
3946 ff_msmpeg4_encode_picture_header(s, picture_number); in encode_picture()
3947 else if (CONFIG_MPEG4_ENCODER && s->h263_pred) { in encode_picture()
3948 ret = ff_mpeg4_encode_picture_header(s, picture_number); in encode_picture()
3951 } else if (CONFIG_RV10_ENCODER && s->codec_id == AV_CODEC_ID_RV10) { in encode_picture()
3952 ret = ff_rv10_encode_picture_header(s, picture_number); in encode_picture()
3956 else if (CONFIG_RV20_ENCODER && s->codec_id == AV_CODEC_ID_RV20) in encode_picture()
3957 ff_rv20_encode_picture_header(s, picture_number); in encode_picture()
3958 else if (CONFIG_FLV_ENCODER && s->codec_id == AV_CODEC_ID_FLV1) in encode_picture()
3959 ff_flv_encode_picture_header(s, picture_number); in encode_picture()
3961 ff_h263_encode_picture_header(s, picture_number); in encode_picture()
3965 ff_mpeg1_encode_picture_header(s, picture_number); in encode_picture()
3970 bits= put_bits_count(&s->pb); in encode_picture()
3971 s->header_bits= bits - s->last_bits; in encode_picture()
3974 update_duplicate_context_after_me(s->thread_context[i], s); in encode_picture()
3976s->avctx->execute(s->avctx, encode_thread, &s->thread_context[0], NULL, context_count, sizeof(void… in encode_picture()
3978 if (s->pb.buf_end == s->thread_context[i]->pb.buf) in encode_picture()
3979 …set_put_bits_buffer_size(&s->pb, FFMIN(s->thread_context[i]->pb.buf_end - s->pb.buf, INT_MAX/8-BUF… in encode_picture()
3980 merge_context_after_encode(s, s->thread_context[i]); in encode_picture()
3986 static void denoise_dct_c(MpegEncContext *s, int16_t *block){ in denoise_dct_c() argument
3987 const int intra= s->mb_intra; in denoise_dct_c()
3990 s->dct_count[intra]++; in denoise_dct_c()
3997 s->dct_error_sum[intra][i] += level; in denoise_dct_c()
3998 level -= s->dct_offset[intra][i]; in denoise_dct_c()
4001 s->dct_error_sum[intra][i] -= level; in denoise_dct_c()
4002 level += s->dct_offset[intra][i]; in denoise_dct_c()
4010 static int dct_quantize_trellis_c(MpegEncContext *s, in dct_quantize_trellis_c() argument
4032 const int esc_length= s->ac_esc_length; in dct_quantize_trellis_c()
4035 const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6); in dct_quantize_trellis_c()
4038 s->fdsp.fdct(block); in dct_quantize_trellis_c()
4040 if(s->dct_error_sum) in dct_quantize_trellis_c()
4041 s->denoise_dct(s, block); in dct_quantize_trellis_c()
4045 if (s->q_scale_type) mpeg2_qscale = ff_mpeg2_non_linear_qscale[qscale]; in dct_quantize_trellis_c()
4048 if (s->mb_intra) { in dct_quantize_trellis_c()
4050 scantable= s->intra_scantable.scantable; in dct_quantize_trellis_c()
4051 perm_scantable= s->intra_scantable.permutated; in dct_quantize_trellis_c()
4052 if (!s->h263_aic) { in dct_quantize_trellis_c()
4054 q = s->y_dc_scale; in dct_quantize_trellis_c()
4056 q = s->c_dc_scale; in dct_quantize_trellis_c()
4068 qmat = n < 4 ? s->q_intra_matrix[qscale] : s->q_chroma_intra_matrix[qscale]; in dct_quantize_trellis_c()
4069 matrix = n < 4 ? s->intra_matrix : s->chroma_intra_matrix; in dct_quantize_trellis_c()
4070 if(s->mpeg_quant || s->out_format == FMT_MPEG1 || s->out_format == FMT_MJPEG) in dct_quantize_trellis_c()
4073 if (n > 3 && s->intra_chroma_ac_vlc_length) { in dct_quantize_trellis_c()
4074 length = s->intra_chroma_ac_vlc_length; in dct_quantize_trellis_c()
4075 last_length= s->intra_chroma_ac_vlc_last_length; in dct_quantize_trellis_c()
4077 length = s->intra_ac_vlc_length; in dct_quantize_trellis_c()
4078 last_length= s->intra_ac_vlc_last_length; in dct_quantize_trellis_c()
4081 scantable= s->inter_scantable.scantable; in dct_quantize_trellis_c()
4082 perm_scantable= s->inter_scantable.permutated; in dct_quantize_trellis_c()
4085 qmat = s->q_inter_matrix[qscale]; in dct_quantize_trellis_c()
4086 matrix = s->inter_matrix; in dct_quantize_trellis_c()
4087 length = s->inter_ac_vlc_length; in dct_quantize_trellis_c()
4088 last_length= s->inter_ac_vlc_last_length; in dct_quantize_trellis_c()
4132 *overflow= s->max_qcoeff < max; //overflow might have happened in dct_quantize_trellis_c()
4148 if (s->fdsp.fdct == ff_fdct_ifast) in dct_quantize_trellis_c()
4160 if(s->out_format == FMT_H263 || s->out_format == FMT_H261){ in dct_quantize_trellis_c()
4162 } else if(s->out_format == FMT_MJPEG) { in dct_quantize_trellis_c()
4163 j = s->idsp.idct_permutation[scantable[i]]; in dct_quantize_trellis_c()
4166 j = s->idsp.idct_permutation[scantable[i]]; // FIXME: optimize in dct_quantize_trellis_c()
4167 if(s->mb_intra){ in dct_quantize_trellis_c()
4192 if(s->out_format == FMT_H263 || s->out_format == FMT_H261){ in dct_quantize_trellis_c()
4218 if(s->out_format == FMT_H263 || s->out_format == FMT_H261){ in dct_quantize_trellis_c()
4251 if(s->out_format != FMT_H263 && s->out_format != FMT_H261){ in dct_quantize_trellis_c()
4267 s->coded_score[n] = last_score; in dct_quantize_trellis_c()
4285 if(s->out_format == FMT_H263 || s->out_format == FMT_H261){ in dct_quantize_trellis_c()
4305 s->coded_score[n] = best_score - dc*dc; in dct_quantize_trellis_c()
4332 double s= 0.25*(1<<BASIS_SHIFT); in build_basis() local
4335 if(i==0) s*= sqrt(0.5); in build_basis()
4336 if(j==0) s*= sqrt(0.5); in build_basis()
4337 … basis[perm_index][8*x + y]= lrintf(s * cos((M_PI/8.0)*i*(x+0.5)) * cos((M_PI/8.0)*j*(y+0.5))); in build_basis()
4344 static int dct_quantize_refine(MpegEncContext *s, //FIXME breaks denoise? in dct_quantize_refine() argument
4363 build_basis(s->idsp.idct_permutation); in dct_quantize_refine()
4367 if (s->mb_intra) { in dct_quantize_refine()
4368 scantable= s->intra_scantable.scantable; in dct_quantize_refine()
4369 perm_scantable= s->intra_scantable.permutated; in dct_quantize_refine()
4370 if (!s->h263_aic) { in dct_quantize_refine()
4372 q = s->y_dc_scale; in dct_quantize_refine()
4374 q = s->c_dc_scale; in dct_quantize_refine()
4387 if (n > 3 && s->intra_chroma_ac_vlc_length) { in dct_quantize_refine()
4388 length = s->intra_chroma_ac_vlc_length; in dct_quantize_refine()
4389 last_length= s->intra_chroma_ac_vlc_last_length; in dct_quantize_refine()
4391 length = s->intra_ac_vlc_length; in dct_quantize_refine()
4392 last_length= s->intra_ac_vlc_last_length; in dct_quantize_refine()
4395 scantable= s->inter_scantable.scantable; in dct_quantize_refine()
4396 perm_scantable= s->inter_scantable.permutated; in dct_quantize_refine()
4399 length = s->inter_ac_vlc_length; in dct_quantize_refine()
4400 last_length= s->inter_ac_vlc_last_length; in dct_quantize_refine()
4402 last_non_zero = s->block_last_index[n]; in dct_quantize_refine()
4425 lambda= sum*(uint64_t)s->lambda2 >> (FF_LAMBDA_SHIFT - 6 + 6 + 6 + 6); in dct_quantize_refine()
4440 s->mpvencdsp.add_8x8basis(rem, basis[j], coeff); in dct_quantize_refine()
4447 int best_score = s->mpvencdsp.try_8x8basis(rem, weight, basis[0], 0); in dct_quantize_refine()
4451 analyze_gradient = last_non_zero > 2 || s->quantizer_noise_shaping >= 3; in dct_quantize_refine()
4459 s->fdsp.fdct(d1); in dct_quantize_refine()
4466 av_assert2(s->mb_intra); in dct_quantize_refine()
4478 score = s->mpvencdsp.try_8x8basis(rem, weight, basis[0], in dct_quantize_refine()
4500 if(s->quantizer_noise_shaping < 3 && i > last_non_zero + 1) in dct_quantize_refine()
4518 if(s->quantizer_noise_shaping < 2 && FFABS(new_level) > FFABS(level)) in dct_quantize_refine()
4602 score += s->mpvencdsp.try_8x8basis(rem, weight, basis[j], in dct_quantize_refine()
4651 s->mpvencdsp.add_8x8basis(rem, basis[j], best_unquant_change); in dct_quantize_refine()
4696 int ff_dct_quantize_c(MpegEncContext *s, in ff_dct_quantize_c() argument
4707 s->fdsp.fdct(block); in ff_dct_quantize_c()
4709 if(s->dct_error_sum) in ff_dct_quantize_c()
4710 s->denoise_dct(s, block); in ff_dct_quantize_c()
4712 if (s->mb_intra) { in ff_dct_quantize_c()
4713 scantable= s->intra_scantable.scantable; in ff_dct_quantize_c()
4714 if (!s->h263_aic) { in ff_dct_quantize_c()
4716 q = s->y_dc_scale; in ff_dct_quantize_c()
4718 q = s->c_dc_scale; in ff_dct_quantize_c()
4728 qmat = n < 4 ? s->q_intra_matrix[qscale] : s->q_chroma_intra_matrix[qscale]; in ff_dct_quantize_c()
4729 bias= s->intra_quant_bias*(1<<(QMAT_SHIFT - QUANT_BIAS_SHIFT)); in ff_dct_quantize_c()
4731 scantable= s->inter_scantable.scantable; in ff_dct_quantize_c()
4734 qmat = s->q_inter_matrix[qscale]; in ff_dct_quantize_c()
4735 bias= s->inter_quant_bias*(1<<(QMAT_SHIFT - QUANT_BIAS_SHIFT)); in ff_dct_quantize_c()
4769 *overflow= s->max_qcoeff < max; //overflow might have happened in ff_dct_quantize_c()
4772 if (s->idsp.perm_type != FF_IDCT_PERM_NONE) in ff_dct_quantize_c()
4773 ff_block_permute(block, s->idsp.idct_permutation, in ff_dct_quantize_c()