You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
avcodec/mpegvideo: Partially check for being encoder at compile-time
Whether lowres is in use or not is inlined in mpv_reconstruct_mb_internal(), so one can use the fact that lowres is always zero during encoding to evaluate the checks for whether one is encoding or not at compile-time when one is in lowres mode. Also reorder the main check to check for whether it is an encoder first to shortcircuit it in the common case of a decoder. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@@ -1961,6 +1961,7 @@ static av_always_inline
|
|||||||
void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
|
void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
|
||||||
int lowres_flag, int is_mpeg12)
|
int lowres_flag, int is_mpeg12)
|
||||||
{
|
{
|
||||||
|
#define IS_ENCODER(s) (CONFIG_MPEGVIDEOENC && !lowres_flag && (s)->encoding)
|
||||||
const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
|
const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
|
||||||
|
|
||||||
s->current_picture.qscale_table[mb_xy] = s->qscale;
|
s->current_picture.qscale_table[mb_xy] = s->qscale;
|
||||||
@@ -1979,8 +1980,8 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
|
|||||||
else if (!is_mpeg12 && (s->h263_pred || s->h263_aic))
|
else if (!is_mpeg12 && (s->h263_pred || s->h263_aic))
|
||||||
s->mbintra_table[mb_xy]=1;
|
s->mbintra_table[mb_xy]=1;
|
||||||
|
|
||||||
if ((s->avctx->flags & AV_CODEC_FLAG_PSNR) || s->frame_skip_threshold || s->frame_skip_factor ||
|
if (!IS_ENCODER(s) || (s->avctx->flags & AV_CODEC_FLAG_PSNR) || s->frame_skip_threshold || s->frame_skip_factor ||
|
||||||
!(s->encoding && (s->intra_only || s->pict_type == AV_PICTURE_TYPE_B) &&
|
!((s->intra_only || s->pict_type == AV_PICTURE_TYPE_B) &&
|
||||||
s->avctx->mb_decision != FF_MB_DECISION_RD)) { // FIXME precalc
|
s->avctx->mb_decision != FF_MB_DECISION_RD)) { // FIXME precalc
|
||||||
uint8_t *dest_y, *dest_cb, *dest_cr;
|
uint8_t *dest_y, *dest_cb, *dest_cr;
|
||||||
int dct_linesize, dct_offset;
|
int dct_linesize, dct_offset;
|
||||||
@@ -1988,12 +1989,12 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
|
|||||||
qpel_mc_func (*op_qpix)[16];
|
qpel_mc_func (*op_qpix)[16];
|
||||||
const int linesize = s->current_picture.f->linesize[0]; //not s->linesize as this would be wrong for field pics
|
const int linesize = s->current_picture.f->linesize[0]; //not s->linesize as this would be wrong for field pics
|
||||||
const int uvlinesize = s->current_picture.f->linesize[1];
|
const int uvlinesize = s->current_picture.f->linesize[1];
|
||||||
const int readable= s->pict_type != AV_PICTURE_TYPE_B || s->encoding || s->avctx->draw_horiz_band || lowres_flag;
|
const int readable = s->pict_type != AV_PICTURE_TYPE_B || IS_ENCODER(s) || s->avctx->draw_horiz_band || lowres_flag;
|
||||||
const int block_size= lowres_flag ? 8>>s->avctx->lowres : 8;
|
const int block_size= lowres_flag ? 8>>s->avctx->lowres : 8;
|
||||||
|
|
||||||
/* avoid copy if macroblock skipped in last frame too */
|
/* avoid copy if macroblock skipped in last frame too */
|
||||||
/* skip only during decoding as we might trash the buffers during encoding a bit */
|
/* skip only during decoding as we might trash the buffers during encoding a bit */
|
||||||
if(!s->encoding){
|
if (!IS_ENCODER(s)) {
|
||||||
uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy];
|
uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy];
|
||||||
|
|
||||||
if (s->mb_skipped) {
|
if (s->mb_skipped) {
|
||||||
@@ -2023,7 +2024,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
|
|||||||
if (!s->mb_intra) {
|
if (!s->mb_intra) {
|
||||||
/* motion handling */
|
/* motion handling */
|
||||||
/* decoding or more than one mb_type (MC was already done otherwise) */
|
/* decoding or more than one mb_type (MC was already done otherwise) */
|
||||||
if(!s->encoding){
|
if (!IS_ENCODER(s)) {
|
||||||
|
|
||||||
if(HAVE_THREADS && s->avctx->active_thread_type&FF_THREAD_FRAME) {
|
if(HAVE_THREADS && s->avctx->active_thread_type&FF_THREAD_FRAME) {
|
||||||
if (s->mv_dir & MV_DIR_FORWARD) {
|
if (s->mv_dir & MV_DIR_FORWARD) {
|
||||||
@@ -2075,7 +2076,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* add dct residue */
|
/* add dct residue */
|
||||||
if(s->encoding || !( s->msmpeg4_version || s->codec_id==AV_CODEC_ID_MPEG1VIDEO || s->codec_id==AV_CODEC_ID_MPEG2VIDEO
|
if (IS_ENCODER(s) || !(s->msmpeg4_version || s->codec_id == AV_CODEC_ID_MPEG1VIDEO || s->codec_id == AV_CODEC_ID_MPEG2VIDEO
|
||||||
|| (s->codec_id==AV_CODEC_ID_MPEG4 && !s->mpeg_quant))){
|
|| (s->codec_id==AV_CODEC_ID_MPEG4 && !s->mpeg_quant))){
|
||||||
add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
|
add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
|
||||||
add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
|
add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
|
||||||
@@ -2182,7 +2183,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* dct only in intra block */
|
/* dct only in intra block */
|
||||||
else if(s->encoding || !(s->codec_id==AV_CODEC_ID_MPEG1VIDEO || s->codec_id==AV_CODEC_ID_MPEG2VIDEO)){
|
else if (IS_ENCODER(s) || !(s->codec_id == AV_CODEC_ID_MPEG1VIDEO || s->codec_id == AV_CODEC_ID_MPEG2VIDEO)) {
|
||||||
put_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
|
put_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
|
||||||
put_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
|
put_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
|
||||||
put_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
|
put_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
|
||||||
|
Reference in New Issue
Block a user