2015-05-29 19:44:05 +01:00
|
|
|
/*
|
|
|
|
|
* Motion estimation
|
|
|
|
|
*
|
2015-06-01 01:30:01 +02:00
|
|
|
* This file is part of FFmpeg.
|
2015-05-29 19:44:05 +01:00
|
|
|
*
|
2015-06-01 01:30:01 +02:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2015-05-29 19:44:05 +01:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
2015-06-01 01:30:01 +02:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2015-05-29 19:44:05 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2015-06-01 01:30:01 +02:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2015-05-29 19:44:05 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
*/
|
|
|
|
|
|
2016-01-28 18:25:13 -08:00
|
|
|
#ifndef AVCODEC_MOTION_EST_H
|
|
|
|
|
#define AVCODEC_MOTION_EST_H
|
2015-05-29 19:44:05 +01:00
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
#include "avcodec.h"
|
|
|
|
|
#include "hpeldsp.h"
|
2024-05-12 18:09:22 +02:00
|
|
|
#include "me_cmp.h"
|
2015-05-29 19:44:05 +01:00
|
|
|
#include "qpeldsp.h"
|
|
|
|
|
|
avcodec/mpegvideoenc: Add MPVEncContext
Many of the fields of MpegEncContext (which is also used by decoders)
are actually only used by encoders. Therefore this commit adds
a new encoder-only structure and moves all of the encoder-only
fields to it except for those which require more explicit
synchronisation between the main slice context and the other
slice contexts. This synchronisation is currently mainly provided
by ff_update_thread_context() which simply copies most of
the main slice context over the other slice contexts. Fields
which are moved to the new MPVEncContext no longer participate
in this (which is desired, because it is horrible and for the
fields b) below wasteful) which means that some fields can only
be moved when explicit synchronisation code is added in later commits.
More explicitly, this commit moves the following fields:
a) Fields not copied by ff_update_duplicate_context():
dct_error_sum and dct_count; the former does not need synchronisation,
the latter is synchronised in merge_context_after_encode().
b) Fields which do not change after initialisation (these fields
could also be put into MPVMainEncContext at the cost of
an indirection to access them): lambda_table, adaptive_quant,
{luma,chroma}_elim_threshold, new_pic, fdsp, mpvencdsp, pdsp,
{p,b_forw,b_back,b_bidir_forw,b_bidir_back,b_direct,b_field}_mv_table,
[pb]_field_select_table, mb_{type,var,mean}, mc_mb_var, {min,max}_qcoeff,
{inter,intra}_quant_bias, ac_esc_length, the *_vlc_length fields,
the q_{intra,inter,chroma_intra}_matrix{,16}, dct_offset, mb_info,
mjpeg_ctx, rtp_mode, rtp_payload_size, encode_mb, all function
pointers, mpv_flags, quantizer_noise_shaping,
frame_reconstruction_bitfield, error_rate and intra_penalty.
c) Fields which are already (re)set explicitly: The PutBitContexts
pb, tex_pb, pb2; dquant, skipdct, encoding_error, the statistics
fields {mv,i_tex,p_tex,misc,last}_bits and i_count; last_mv_dir,
esc_pos (reset when writing the header).
d) Fields which are only used by encoders not supporting slice
threading for which synchronisation doesn't matter: esc3_level_length
and the remaining mb_info fields.
e) coded_score: This field is only really used when FF_MPV_FLAG_CBP_RD
is set (which implies trellis) and even then it is only used for
non-intra blocks. For these blocks dct_quantize_trellis_c() either
sets coded_score[n] or returns a last_non_zero value of -1
in which case coded_score will be reset in encode_mb_internal().
Therefore no old values are ever used.
The MotionEstContext has not been moved yet.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-19 08:11:01 +01:00
|
|
|
typedef struct MPVEncContext MPVEncContext;
|
2022-02-07 10:24:38 +01:00
|
|
|
typedef struct MPVMainEncContext MPVMainEncContext;
|
2015-05-29 19:44:05 +01:00
|
|
|
|
2016-01-15 23:58:51 +01:00
|
|
|
#if ARCH_IA64 // Limit static arrays to avoid gcc failing "short data segment overflowed"
|
|
|
|
|
#define MAX_MV 1024
|
|
|
|
|
#else
|
2015-06-01 01:30:01 +02:00
|
|
|
#define MAX_MV 4096
|
2016-01-15 23:58:51 +01:00
|
|
|
#endif
|
2016-01-05 14:41:04 +01:00
|
|
|
#define MAX_DMV (2*MAX_MV)
|
2015-09-12 15:58:47 +02:00
|
|
|
#define ME_MAP_SIZE 64
|
2015-05-29 19:44:05 +01:00
|
|
|
|
2015-07-07 01:20:43 +01:00
|
|
|
#define FF_ME_ZERO 0
|
|
|
|
|
#define FF_ME_EPZS 1
|
|
|
|
|
#define FF_ME_XONE 2
|
|
|
|
|
|
2015-05-29 19:44:05 +01:00
|
|
|
/**
|
|
|
|
|
* Motion estimation context.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct MotionEstContext {
|
|
|
|
|
AVCodecContext *avctx;
|
2025-03-19 00:48:33 +01:00
|
|
|
int motion_est; ///< ME algorithm
|
2015-05-29 19:44:05 +01:00
|
|
|
int skip; ///< set if ME is skipped for the current MB
|
|
|
|
|
int co_located_mv[4][2]; ///< mv from last P-frame for direct mode ME
|
|
|
|
|
int direct_basis_mv[4][2];
|
|
|
|
|
uint8_t *scratchpad; /**< data area for the ME algo, so that
|
|
|
|
|
* the ME does not need to malloc/free. */
|
|
|
|
|
uint8_t *temp;
|
|
|
|
|
unsigned map_generation;
|
|
|
|
|
int pre_penalty_factor;
|
|
|
|
|
int penalty_factor; /**< an estimate of the bits required to
|
|
|
|
|
* code a given mv value, e.g. (1,0) takes
|
|
|
|
|
* more bits than (0,0). We have to
|
|
|
|
|
* estimate whether any reduction in
|
|
|
|
|
* residual is worth the extra bits. */
|
|
|
|
|
int sub_penalty_factor;
|
|
|
|
|
int mb_penalty_factor;
|
|
|
|
|
int flags;
|
|
|
|
|
int sub_flags;
|
|
|
|
|
int mb_flags;
|
|
|
|
|
int pre_pass; ///< = 1 for the pre pass
|
|
|
|
|
int dia_size;
|
2025-06-19 15:35:20 +02:00
|
|
|
int unrestricted_mv; ///< mv can point outside of the coded picture
|
2015-05-29 19:44:05 +01:00
|
|
|
int xmin;
|
|
|
|
|
int xmax;
|
|
|
|
|
int ymin;
|
|
|
|
|
int ymax;
|
|
|
|
|
int pred_x;
|
|
|
|
|
int pred_y;
|
2022-07-26 08:36:11 +02:00
|
|
|
const uint8_t *src[4][4];
|
|
|
|
|
const uint8_t *ref[4][4];
|
2015-05-29 19:44:05 +01:00
|
|
|
int stride;
|
|
|
|
|
int uvstride;
|
|
|
|
|
/* temp variables for picture complexity calculation */
|
2015-06-01 01:30:01 +02:00
|
|
|
int64_t mc_mb_var_sum_temp;
|
|
|
|
|
int64_t mb_var_sum_temp;
|
2015-05-29 19:44:05 +01:00
|
|
|
int scene_change_score;
|
|
|
|
|
|
2024-05-12 18:47:25 +02:00
|
|
|
me_cmp_func me_pre_cmp[6];
|
|
|
|
|
me_cmp_func me_cmp[6];
|
|
|
|
|
me_cmp_func me_sub_cmp[6];
|
|
|
|
|
me_cmp_func mb_cmp[6];
|
|
|
|
|
|
2024-05-12 23:51:41 +02:00
|
|
|
me_cmp_func pix_abs[2][4];
|
|
|
|
|
me_cmp_func sse;
|
|
|
|
|
|
2015-05-29 19:44:05 +01:00
|
|
|
op_pixels_func(*hpel_put)[4];
|
|
|
|
|
op_pixels_func(*hpel_avg)[4];
|
|
|
|
|
qpel_mc_func(*qpel_put)[16];
|
|
|
|
|
qpel_mc_func(*qpel_avg)[16];
|
2020-12-09 04:16:48 +01:00
|
|
|
const uint8_t (*mv_penalty)[MAX_DMV * 2 + 1]; ///< bit amount needed to encode a MV
|
|
|
|
|
const uint8_t *current_mv_penalty;
|
avcodec/mpegvideoenc: Add MPVEncContext
Many of the fields of MpegEncContext (which is also used by decoders)
are actually only used by encoders. Therefore this commit adds
a new encoder-only structure and moves all of the encoder-only
fields to it except for those which require more explicit
synchronisation between the main slice context and the other
slice contexts. This synchronisation is currently mainly provided
by ff_update_thread_context() which simply copies most of
the main slice context over the other slice contexts. Fields
which are moved to the new MPVEncContext no longer participate
in this (which is desired, because it is horrible and for the
fields b) below wasteful) which means that some fields can only
be moved when explicit synchronisation code is added in later commits.
More explicitly, this commit moves the following fields:
a) Fields not copied by ff_update_duplicate_context():
dct_error_sum and dct_count; the former does not need synchronisation,
the latter is synchronised in merge_context_after_encode().
b) Fields which do not change after initialisation (these fields
could also be put into MPVMainEncContext at the cost of
an indirection to access them): lambda_table, adaptive_quant,
{luma,chroma}_elim_threshold, new_pic, fdsp, mpvencdsp, pdsp,
{p,b_forw,b_back,b_bidir_forw,b_bidir_back,b_direct,b_field}_mv_table,
[pb]_field_select_table, mb_{type,var,mean}, mc_mb_var, {min,max}_qcoeff,
{inter,intra}_quant_bias, ac_esc_length, the *_vlc_length fields,
the q_{intra,inter,chroma_intra}_matrix{,16}, dct_offset, mb_info,
mjpeg_ctx, rtp_mode, rtp_payload_size, encode_mb, all function
pointers, mpv_flags, quantizer_noise_shaping,
frame_reconstruction_bitfield, error_rate and intra_penalty.
c) Fields which are already (re)set explicitly: The PutBitContexts
pb, tex_pb, pb2; dquant, skipdct, encoding_error, the statistics
fields {mv,i_tex,p_tex,misc,last}_bits and i_count; last_mv_dir,
esc_pos (reset when writing the header).
d) Fields which are only used by encoders not supporting slice
threading for which synchronisation doesn't matter: esc3_level_length
and the remaining mb_info fields.
e) coded_score: This field is only really used when FF_MPV_FLAG_CBP_RD
is set (which implies trellis) and even then it is only used for
non-intra blocks. For these blocks dct_quantize_trellis_c() either
sets coded_score[n] or returns a last_non_zero value of -1
in which case coded_score will be reset in encode_mb_internal().
Therefore no old values are ever used.
The MotionEstContext has not been moved yet.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-19 08:11:01 +01:00
|
|
|
int (*sub_motion_search)(MPVEncContext *s,
|
2015-05-29 19:44:05 +01:00
|
|
|
int *mx_ptr, int *my_ptr, int dmin,
|
|
|
|
|
int src_index, int ref_index,
|
|
|
|
|
int size, int h);
|
2025-03-25 03:23:13 +01:00
|
|
|
|
|
|
|
|
uint32_t map[ME_MAP_SIZE]; ///< map to avoid duplicate evaluations
|
|
|
|
|
uint32_t score_map[ME_MAP_SIZE];///< map to store the scores
|
2015-05-29 19:44:05 +01:00
|
|
|
} MotionEstContext;
|
|
|
|
|
|
2024-05-12 18:09:22 +02:00
|
|
|
/**
|
|
|
|
|
* Performs one-time initialization of the MotionEstContext.
|
|
|
|
|
*/
|
|
|
|
|
int ff_me_init(MotionEstContext *c, struct AVCodecContext *avctx,
|
2024-05-12 23:15:46 +02:00
|
|
|
const struct MECmpContext *mecc, int mpvenc);
|
2024-05-12 18:09:22 +02:00
|
|
|
|
avcodec/mpegvideoenc: Add MPVEncContext
Many of the fields of MpegEncContext (which is also used by decoders)
are actually only used by encoders. Therefore this commit adds
a new encoder-only structure and moves all of the encoder-only
fields to it except for those which require more explicit
synchronisation between the main slice context and the other
slice contexts. This synchronisation is currently mainly provided
by ff_update_thread_context() which simply copies most of
the main slice context over the other slice contexts. Fields
which are moved to the new MPVEncContext no longer participate
in this (which is desired, because it is horrible and for the
fields b) below wasteful) which means that some fields can only
be moved when explicit synchronisation code is added in later commits.
More explicitly, this commit moves the following fields:
a) Fields not copied by ff_update_duplicate_context():
dct_error_sum and dct_count; the former does not need synchronisation,
the latter is synchronised in merge_context_after_encode().
b) Fields which do not change after initialisation (these fields
could also be put into MPVMainEncContext at the cost of
an indirection to access them): lambda_table, adaptive_quant,
{luma,chroma}_elim_threshold, new_pic, fdsp, mpvencdsp, pdsp,
{p,b_forw,b_back,b_bidir_forw,b_bidir_back,b_direct,b_field}_mv_table,
[pb]_field_select_table, mb_{type,var,mean}, mc_mb_var, {min,max}_qcoeff,
{inter,intra}_quant_bias, ac_esc_length, the *_vlc_length fields,
the q_{intra,inter,chroma_intra}_matrix{,16}, dct_offset, mb_info,
mjpeg_ctx, rtp_mode, rtp_payload_size, encode_mb, all function
pointers, mpv_flags, quantizer_noise_shaping,
frame_reconstruction_bitfield, error_rate and intra_penalty.
c) Fields which are already (re)set explicitly: The PutBitContexts
pb, tex_pb, pb2; dquant, skipdct, encoding_error, the statistics
fields {mv,i_tex,p_tex,misc,last}_bits and i_count; last_mv_dir,
esc_pos (reset when writing the header).
d) Fields which are only used by encoders not supporting slice
threading for which synchronisation doesn't matter: esc3_level_length
and the remaining mb_info fields.
e) coded_score: This field is only really used when FF_MPV_FLAG_CBP_RD
is set (which implies trellis) and even then it is only used for
non-intra blocks. For these blocks dct_quantize_trellis_c() either
sets coded_score[n] or returns a last_non_zero value of -1
in which case coded_score will be reset in encode_mb_internal().
Therefore no old values are ever used.
The MotionEstContext has not been moved yet.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-19 08:11:01 +01:00
|
|
|
void ff_me_init_pic(MPVEncContext *s);
|
2015-05-29 19:44:05 +01:00
|
|
|
|
avcodec/mpegvideoenc: Add MPVEncContext
Many of the fields of MpegEncContext (which is also used by decoders)
are actually only used by encoders. Therefore this commit adds
a new encoder-only structure and moves all of the encoder-only
fields to it except for those which require more explicit
synchronisation between the main slice context and the other
slice contexts. This synchronisation is currently mainly provided
by ff_update_thread_context() which simply copies most of
the main slice context over the other slice contexts. Fields
which are moved to the new MPVEncContext no longer participate
in this (which is desired, because it is horrible and for the
fields b) below wasteful) which means that some fields can only
be moved when explicit synchronisation code is added in later commits.
More explicitly, this commit moves the following fields:
a) Fields not copied by ff_update_duplicate_context():
dct_error_sum and dct_count; the former does not need synchronisation,
the latter is synchronised in merge_context_after_encode().
b) Fields which do not change after initialisation (these fields
could also be put into MPVMainEncContext at the cost of
an indirection to access them): lambda_table, adaptive_quant,
{luma,chroma}_elim_threshold, new_pic, fdsp, mpvencdsp, pdsp,
{p,b_forw,b_back,b_bidir_forw,b_bidir_back,b_direct,b_field}_mv_table,
[pb]_field_select_table, mb_{type,var,mean}, mc_mb_var, {min,max}_qcoeff,
{inter,intra}_quant_bias, ac_esc_length, the *_vlc_length fields,
the q_{intra,inter,chroma_intra}_matrix{,16}, dct_offset, mb_info,
mjpeg_ctx, rtp_mode, rtp_payload_size, encode_mb, all function
pointers, mpv_flags, quantizer_noise_shaping,
frame_reconstruction_bitfield, error_rate and intra_penalty.
c) Fields which are already (re)set explicitly: The PutBitContexts
pb, tex_pb, pb2; dquant, skipdct, encoding_error, the statistics
fields {mv,i_tex,p_tex,misc,last}_bits and i_count; last_mv_dir,
esc_pos (reset when writing the header).
d) Fields which are only used by encoders not supporting slice
threading for which synchronisation doesn't matter: esc3_level_length
and the remaining mb_info fields.
e) coded_score: This field is only really used when FF_MPV_FLAG_CBP_RD
is set (which implies trellis) and even then it is only used for
non-intra blocks. For these blocks dct_quantize_trellis_c() either
sets coded_score[n] or returns a last_non_zero value of -1
in which case coded_score will be reset in encode_mb_internal().
Therefore no old values are ever used.
The MotionEstContext has not been moved yet.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-19 08:11:01 +01:00
|
|
|
void ff_estimate_p_frame_motion(MPVEncContext *s, int mb_x, int mb_y);
|
|
|
|
|
void ff_estimate_b_frame_motion(MPVEncContext *s, int mb_x, int mb_y);
|
2015-05-29 19:44:05 +01:00
|
|
|
|
avcodec/mpegvideoenc: Add MPVEncContext
Many of the fields of MpegEncContext (which is also used by decoders)
are actually only used by encoders. Therefore this commit adds
a new encoder-only structure and moves all of the encoder-only
fields to it except for those which require more explicit
synchronisation between the main slice context and the other
slice contexts. This synchronisation is currently mainly provided
by ff_update_thread_context() which simply copies most of
the main slice context over the other slice contexts. Fields
which are moved to the new MPVEncContext no longer participate
in this (which is desired, because it is horrible and for the
fields b) below wasteful) which means that some fields can only
be moved when explicit synchronisation code is added in later commits.
More explicitly, this commit moves the following fields:
a) Fields not copied by ff_update_duplicate_context():
dct_error_sum and dct_count; the former does not need synchronisation,
the latter is synchronised in merge_context_after_encode().
b) Fields which do not change after initialisation (these fields
could also be put into MPVMainEncContext at the cost of
an indirection to access them): lambda_table, adaptive_quant,
{luma,chroma}_elim_threshold, new_pic, fdsp, mpvencdsp, pdsp,
{p,b_forw,b_back,b_bidir_forw,b_bidir_back,b_direct,b_field}_mv_table,
[pb]_field_select_table, mb_{type,var,mean}, mc_mb_var, {min,max}_qcoeff,
{inter,intra}_quant_bias, ac_esc_length, the *_vlc_length fields,
the q_{intra,inter,chroma_intra}_matrix{,16}, dct_offset, mb_info,
mjpeg_ctx, rtp_mode, rtp_payload_size, encode_mb, all function
pointers, mpv_flags, quantizer_noise_shaping,
frame_reconstruction_bitfield, error_rate and intra_penalty.
c) Fields which are already (re)set explicitly: The PutBitContexts
pb, tex_pb, pb2; dquant, skipdct, encoding_error, the statistics
fields {mv,i_tex,p_tex,misc,last}_bits and i_count; last_mv_dir,
esc_pos (reset when writing the header).
d) Fields which are only used by encoders not supporting slice
threading for which synchronisation doesn't matter: esc3_level_length
and the remaining mb_info fields.
e) coded_score: This field is only really used when FF_MPV_FLAG_CBP_RD
is set (which implies trellis) and even then it is only used for
non-intra blocks. For these blocks dct_quantize_trellis_c() either
sets coded_score[n] or returns a last_non_zero value of -1
in which case coded_score will be reset in encode_mb_internal().
Therefore no old values are ever used.
The MotionEstContext has not been moved yet.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-19 08:11:01 +01:00
|
|
|
int ff_pre_estimate_p_frame_motion(MPVEncContext *s,
|
2015-05-29 19:44:05 +01:00
|
|
|
int mb_x, int mb_y);
|
|
|
|
|
|
avcodec/mpegvideoenc: Add MPVEncContext
Many of the fields of MpegEncContext (which is also used by decoders)
are actually only used by encoders. Therefore this commit adds
a new encoder-only structure and moves all of the encoder-only
fields to it except for those which require more explicit
synchronisation between the main slice context and the other
slice contexts. This synchronisation is currently mainly provided
by ff_update_thread_context() which simply copies most of
the main slice context over the other slice contexts. Fields
which are moved to the new MPVEncContext no longer participate
in this (which is desired, because it is horrible and for the
fields b) below wasteful) which means that some fields can only
be moved when explicit synchronisation code is added in later commits.
More explicitly, this commit moves the following fields:
a) Fields not copied by ff_update_duplicate_context():
dct_error_sum and dct_count; the former does not need synchronisation,
the latter is synchronised in merge_context_after_encode().
b) Fields which do not change after initialisation (these fields
could also be put into MPVMainEncContext at the cost of
an indirection to access them): lambda_table, adaptive_quant,
{luma,chroma}_elim_threshold, new_pic, fdsp, mpvencdsp, pdsp,
{p,b_forw,b_back,b_bidir_forw,b_bidir_back,b_direct,b_field}_mv_table,
[pb]_field_select_table, mb_{type,var,mean}, mc_mb_var, {min,max}_qcoeff,
{inter,intra}_quant_bias, ac_esc_length, the *_vlc_length fields,
the q_{intra,inter,chroma_intra}_matrix{,16}, dct_offset, mb_info,
mjpeg_ctx, rtp_mode, rtp_payload_size, encode_mb, all function
pointers, mpv_flags, quantizer_noise_shaping,
frame_reconstruction_bitfield, error_rate and intra_penalty.
c) Fields which are already (re)set explicitly: The PutBitContexts
pb, tex_pb, pb2; dquant, skipdct, encoding_error, the statistics
fields {mv,i_tex,p_tex,misc,last}_bits and i_count; last_mv_dir,
esc_pos (reset when writing the header).
d) Fields which are only used by encoders not supporting slice
threading for which synchronisation doesn't matter: esc3_level_length
and the remaining mb_info fields.
e) coded_score: This field is only really used when FF_MPV_FLAG_CBP_RD
is set (which implies trellis) and even then it is only used for
non-intra blocks. For these blocks dct_quantize_trellis_c() either
sets coded_score[n] or returns a last_non_zero value of -1
in which case coded_score will be reset in encode_mb_internal().
Therefore no old values are ever used.
The MotionEstContext has not been moved yet.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-19 08:11:01 +01:00
|
|
|
int ff_epzs_motion_search(MPVEncContext *s, int *mx_ptr, int *my_ptr,
|
2015-05-29 19:44:05 +01:00
|
|
|
int P[10][2], int src_index, int ref_index,
|
2022-01-31 01:03:04 +01:00
|
|
|
const int16_t (*last_mv)[2], int ref_mv_scale,
|
|
|
|
|
int size, int h);
|
2015-05-29 19:44:05 +01:00
|
|
|
|
avcodec/mpegvideoenc: Add MPVEncContext
Many of the fields of MpegEncContext (which is also used by decoders)
are actually only used by encoders. Therefore this commit adds
a new encoder-only structure and moves all of the encoder-only
fields to it except for those which require more explicit
synchronisation between the main slice context and the other
slice contexts. This synchronisation is currently mainly provided
by ff_update_thread_context() which simply copies most of
the main slice context over the other slice contexts. Fields
which are moved to the new MPVEncContext no longer participate
in this (which is desired, because it is horrible and for the
fields b) below wasteful) which means that some fields can only
be moved when explicit synchronisation code is added in later commits.
More explicitly, this commit moves the following fields:
a) Fields not copied by ff_update_duplicate_context():
dct_error_sum and dct_count; the former does not need synchronisation,
the latter is synchronised in merge_context_after_encode().
b) Fields which do not change after initialisation (these fields
could also be put into MPVMainEncContext at the cost of
an indirection to access them): lambda_table, adaptive_quant,
{luma,chroma}_elim_threshold, new_pic, fdsp, mpvencdsp, pdsp,
{p,b_forw,b_back,b_bidir_forw,b_bidir_back,b_direct,b_field}_mv_table,
[pb]_field_select_table, mb_{type,var,mean}, mc_mb_var, {min,max}_qcoeff,
{inter,intra}_quant_bias, ac_esc_length, the *_vlc_length fields,
the q_{intra,inter,chroma_intra}_matrix{,16}, dct_offset, mb_info,
mjpeg_ctx, rtp_mode, rtp_payload_size, encode_mb, all function
pointers, mpv_flags, quantizer_noise_shaping,
frame_reconstruction_bitfield, error_rate and intra_penalty.
c) Fields which are already (re)set explicitly: The PutBitContexts
pb, tex_pb, pb2; dquant, skipdct, encoding_error, the statistics
fields {mv,i_tex,p_tex,misc,last}_bits and i_count; last_mv_dir,
esc_pos (reset when writing the header).
d) Fields which are only used by encoders not supporting slice
threading for which synchronisation doesn't matter: esc3_level_length
and the remaining mb_info fields.
e) coded_score: This field is only really used when FF_MPV_FLAG_CBP_RD
is set (which implies trellis) and even then it is only used for
non-intra blocks. For these blocks dct_quantize_trellis_c() either
sets coded_score[n] or returns a last_non_zero value of -1
in which case coded_score will be reset in encode_mb_internal().
Therefore no old values are ever used.
The MotionEstContext has not been moved yet.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-19 08:11:01 +01:00
|
|
|
int ff_get_mb_score(MPVEncContext *s, int mx, int my, int src_index,
|
2015-05-29 19:44:05 +01:00
|
|
|
int ref_index, int size, int h, int add_rate);
|
|
|
|
|
|
2022-02-07 10:24:38 +01:00
|
|
|
int ff_get_best_fcode(MPVMainEncContext *m,
|
2022-01-31 01:03:04 +01:00
|
|
|
const int16_t (*mv_table)[2], int type);
|
2015-05-29 19:44:05 +01:00
|
|
|
|
avcodec/mpegvideoenc: Add MPVEncContext
Many of the fields of MpegEncContext (which is also used by decoders)
are actually only used by encoders. Therefore this commit adds
a new encoder-only structure and moves all of the encoder-only
fields to it except for those which require more explicit
synchronisation between the main slice context and the other
slice contexts. This synchronisation is currently mainly provided
by ff_update_thread_context() which simply copies most of
the main slice context over the other slice contexts. Fields
which are moved to the new MPVEncContext no longer participate
in this (which is desired, because it is horrible and for the
fields b) below wasteful) which means that some fields can only
be moved when explicit synchronisation code is added in later commits.
More explicitly, this commit moves the following fields:
a) Fields not copied by ff_update_duplicate_context():
dct_error_sum and dct_count; the former does not need synchronisation,
the latter is synchronised in merge_context_after_encode().
b) Fields which do not change after initialisation (these fields
could also be put into MPVMainEncContext at the cost of
an indirection to access them): lambda_table, adaptive_quant,
{luma,chroma}_elim_threshold, new_pic, fdsp, mpvencdsp, pdsp,
{p,b_forw,b_back,b_bidir_forw,b_bidir_back,b_direct,b_field}_mv_table,
[pb]_field_select_table, mb_{type,var,mean}, mc_mb_var, {min,max}_qcoeff,
{inter,intra}_quant_bias, ac_esc_length, the *_vlc_length fields,
the q_{intra,inter,chroma_intra}_matrix{,16}, dct_offset, mb_info,
mjpeg_ctx, rtp_mode, rtp_payload_size, encode_mb, all function
pointers, mpv_flags, quantizer_noise_shaping,
frame_reconstruction_bitfield, error_rate and intra_penalty.
c) Fields which are already (re)set explicitly: The PutBitContexts
pb, tex_pb, pb2; dquant, skipdct, encoding_error, the statistics
fields {mv,i_tex,p_tex,misc,last}_bits and i_count; last_mv_dir,
esc_pos (reset when writing the header).
d) Fields which are only used by encoders not supporting slice
threading for which synchronisation doesn't matter: esc3_level_length
and the remaining mb_info fields.
e) coded_score: This field is only really used when FF_MPV_FLAG_CBP_RD
is set (which implies trellis) and even then it is only used for
non-intra blocks. For these blocks dct_quantize_trellis_c() either
sets coded_score[n] or returns a last_non_zero value of -1
in which case coded_score will be reset in encode_mb_internal().
Therefore no old values are ever used.
The MotionEstContext has not been moved yet.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-19 08:11:01 +01:00
|
|
|
void ff_fix_long_p_mvs(MPVEncContext *s, int type);
|
|
|
|
|
void ff_fix_long_mvs(MPVEncContext *s, uint8_t *field_select_table,
|
2015-05-29 19:44:05 +01:00
|
|
|
int field_select, int16_t (*mv_table)[2], int f_code,
|
|
|
|
|
int type, int truncate);
|
|
|
|
|
|
2016-01-28 18:25:13 -08:00
|
|
|
#endif /* AVCODEC_MOTION_EST_H */
|