2001-07-22 14:18:56 +00:00
|
|
|
/*
|
|
|
|
|
* Generic DCT based hybrid video encoder
|
2009-01-19 15:46:40 +00:00
|
|
|
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
|
2004-01-10 16:04:55 +00:00
|
|
|
* Copyright (c) 2002-2004 Michael Niedermayer
|
2001-07-22 14:18:56 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
|
*
|
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2002-05-25 22:45:33 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 15:30:46 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2001-07-22 14:18:56 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2001-07-22 14:18:56 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2002-05-25 22:45:33 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
2001-07-22 14:18:56 +00:00
|
|
|
*
|
2002-05-25 22:45:33 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-10-07 15:30:46 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-12 22:43:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-07-22 14:18:56 +00:00
|
|
|
*/
|
|
|
|
|
|
2003-03-06 11:32:04 +00:00
|
|
|
/**
|
2010-04-20 14:45:34 +00:00
|
|
|
* @file
|
2003-03-06 11:32:04 +00:00
|
|
|
* mpegvideo header.
|
|
|
|
|
*/
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2008-08-31 07:39:47 +00:00
|
|
|
#ifndef AVCODEC_MPEGVIDEO_H
|
|
|
|
|
#define AVCODEC_MPEGVIDEO_H
|
2002-05-27 16:42:14 +00:00
|
|
|
|
2014-01-14 10:33:47 +01:00
|
|
|
#include "blockdsp.h"
|
2013-02-02 20:42:07 +01:00
|
|
|
#include "error_resilience.h"
|
2013-02-07 13:09:35 +01:00
|
|
|
#include "h264chroma.h"
|
2013-11-05 08:11:47 +01:00
|
|
|
#include "h263dsp.h"
|
2013-03-10 13:55:07 -07:00
|
|
|
#include "hpeldsp.h"
|
2014-01-24 11:55:16 +01:00
|
|
|
#include "idctdsp.h"
|
2015-06-08 13:00:49 +01:00
|
|
|
#include "mpegpicture.h"
|
2014-01-08 14:00:10 +01:00
|
|
|
#include "qpeldsp.h"
|
2012-12-15 09:46:02 -08:00
|
|
|
#include "videodsp.h"
|
2003-02-10 09:35:32 +00:00
|
|
|
|
2012-05-07 20:08:56 +02:00
|
|
|
#define MAX_THREADS 32
|
2002-03-22 02:21:17 +00:00
|
|
|
|
2022-10-20 06:03:27 +02:00
|
|
|
/**
|
|
|
|
|
* Scantable.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct ScanTable {
|
|
|
|
|
const uint8_t *scantable;
|
|
|
|
|
uint8_t permutated[64];
|
|
|
|
|
uint8_t raster_end[64];
|
|
|
|
|
} ScanTable;
|
|
|
|
|
|
2023-10-15 23:27:24 +02:00
|
|
|
enum OutputFormat {
|
|
|
|
|
FMT_MPEG1,
|
|
|
|
|
FMT_H261,
|
|
|
|
|
FMT_H263,
|
|
|
|
|
FMT_MJPEG,
|
|
|
|
|
FMT_SPEEDHQ,
|
|
|
|
|
};
|
|
|
|
|
|
2003-03-06 14:37:37 +00:00
|
|
|
/**
|
|
|
|
|
* MpegEncContext.
|
|
|
|
|
*/
|
2001-07-22 14:18:56 +00:00
|
|
|
typedef struct MpegEncContext {
|
2011-08-27 08:26:14 +02:00
|
|
|
AVClass *class;
|
2013-12-05 21:14:40 +01:00
|
|
|
|
|
|
|
|
int y_dc_scale, c_dc_scale;
|
|
|
|
|
int ac_pred;
|
|
|
|
|
int block_last_index[12]; ///< last non zero coefficient in block
|
2016-04-27 13:45:23 -04:00
|
|
|
int h263_aic; ///< Advanced INTRA Coding (AIC)
|
2013-12-05 21:14:40 +01:00
|
|
|
|
|
|
|
|
/* scantables */
|
2016-04-27 13:45:23 -04:00
|
|
|
ScanTable inter_scantable; ///< if inter == intra then intra should be used to reduce the cache usage
|
2013-12-05 21:14:40 +01:00
|
|
|
|
|
|
|
|
/* WARNING: changes above this line require updates to hardcoded
|
2016-04-27 13:45:23 -04:00
|
|
|
* offsets used in ASM. */
|
2013-12-05 21:14:40 +01:00
|
|
|
|
2022-10-20 18:33:55 +02:00
|
|
|
ScanTable intra_scantable;
|
2022-10-20 19:03:01 +02:00
|
|
|
uint8_t permutated_intra_h_scantable[64];
|
|
|
|
|
uint8_t permutated_intra_v_scantable[64];
|
2022-10-20 18:33:55 +02:00
|
|
|
|
2001-08-15 13:12:23 +00:00
|
|
|
struct AVCodecContext *avctx;
|
2022-01-27 22:05:41 +01:00
|
|
|
/* The following pointer is intended for codecs sharing code
|
|
|
|
|
* between decoder and encoder and in need of a common context to do so. */
|
|
|
|
|
void *private_ctx;
|
2001-07-22 14:18:56 +00:00
|
|
|
/* the following parameters must be initialized before encoding */
|
2005-12-17 18:14:38 +00:00
|
|
|
int width, height;///< picture size. must be a multiple of 16
|
|
|
|
|
enum OutputFormat out_format; ///< output format
|
2016-04-27 13:45:23 -04:00
|
|
|
int h263_pred; ///< use MPEG-4/H.263 ac/dc predictions
|
2002-04-27 12:30:26 +00:00
|
|
|
|
2012-08-05 11:11:04 +02:00
|
|
|
enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */
|
2005-12-17 18:14:38 +00:00
|
|
|
int encoding; ///< true if we are encoding (vs decoding)
|
|
|
|
|
int workaround_bugs; ///< workaround bugs in encoders which cannot be detected automatically
|
2006-11-07 09:46:57 +00:00
|
|
|
int codec_tag; ///< internal codec_tag upper case converted from avctx codec_tag
|
2001-07-22 14:18:56 +00:00
|
|
|
/* the following fields are managed internally by the encoder */
|
|
|
|
|
|
|
|
|
|
/* sequence parameters */
|
|
|
|
|
int context_initialized;
|
2005-12-17 18:14:38 +00:00
|
|
|
int mb_width, mb_height; ///< number of MBs horizontally & vertically
|
2005-06-17 15:02:53 +00:00
|
|
|
int mb_stride; ///< mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11
|
|
|
|
|
int b8_stride; ///< 2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
|
|
|
|
|
int h_edge_pos, v_edge_pos;///< horizontal / vertical position of the right/bottom edge (pixel replication)
|
2005-12-17 18:14:38 +00:00
|
|
|
int mb_num; ///< number of MBs of a picture
|
2013-09-27 20:13:59 -04:00
|
|
|
ptrdiff_t linesize; ///< line size, in bytes, may be different from width
|
|
|
|
|
ptrdiff_t uvlinesize; ///< line size, for chroma in bytes, may be different from width
|
2024-10-15 22:37:56 +02:00
|
|
|
struct AVRefStructPool *picture_pool; ///< Pool for MPVPictures
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2022-08-08 21:03:27 +02:00
|
|
|
BufferPoolContext buffer_pools;
|
|
|
|
|
|
2004-02-13 17:54:10 +00:00
|
|
|
int start_mb_y; ///< start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
|
|
|
|
|
int end_mb_y; ///< end mb_y of this thread (so current thread should process start_mb_y <= row < end_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
|
|
|
union {
|
|
|
|
|
struct MpegEncContext *thread_context[MAX_THREADS];
|
2025-06-19 20:59:14 +02:00
|
|
|
struct Mpeg12SliceContext *mpeg12_contexts[MAX_THREADS];
|
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
|
|
|
struct MPVEncContext *enc_contexts[MAX_THREADS];
|
|
|
|
|
};
|
2012-01-01 20:24:24 +01:00
|
|
|
int slice_context_count; ///< number of used thread_contexts
|
2005-12-17 18:14:38 +00:00
|
|
|
|
|
|
|
|
/**
|
2003-03-16 20:22:22 +00:00
|
|
|
* copy of the previous picture structure.
|
|
|
|
|
* note, linesize & data, might not match the previous picture (for field pictures)
|
|
|
|
|
*/
|
2023-10-08 12:25:07 +02:00
|
|
|
MPVWorkPicture last_pic;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
|
|
|
|
/**
|
2003-03-16 20:22:22 +00:00
|
|
|
* copy of the next picture structure.
|
|
|
|
|
* note, linesize & data, might not match the next picture (for field pictures)
|
|
|
|
|
*/
|
2023-10-08 12:25:07 +02:00
|
|
|
MPVWorkPicture next_pic;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
|
|
|
|
/**
|
2003-03-16 20:22:22 +00:00
|
|
|
* copy of the current picture structure.
|
|
|
|
|
* note, linesize & data, might not match the current picture (for field pictures)
|
|
|
|
|
*/
|
2023-10-08 12:25:07 +02:00
|
|
|
MPVWorkPicture cur_pic;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2016-04-27 13:45:23 -04:00
|
|
|
int last_dc[3]; ///< last DC values for MPEG-1
|
2006-09-27 22:13:44 +00:00
|
|
|
int16_t *dc_val_base;
|
2005-12-17 18:14:38 +00:00
|
|
|
const uint8_t *y_dc_scale_table; ///< qscale -> y_dc_scale table
|
|
|
|
|
const uint8_t *c_dc_scale_table; ///< qscale -> c_dc_scale table
|
2016-04-27 13:45:23 -04:00
|
|
|
const uint8_t *chroma_qscale_table; ///< qscale -> chroma_qscale (H.263)
|
2004-04-16 01:01:45 +00:00
|
|
|
uint8_t *coded_block_base;
|
2003-03-06 14:37:37 +00:00
|
|
|
uint8_t *coded_block; ///< used for coded block pattern prediction (msmpeg4v3, wmv1)
|
2004-04-16 01:01:45 +00:00
|
|
|
int16_t (*ac_val_base)[16];
|
2025-06-13 08:51:11 +02:00
|
|
|
int16_t *dc_val; ///< used for H.263 AIC/MPEG-4 DC prediction and ER
|
2025-06-13 05:59:53 +02:00
|
|
|
int16_t (*ac_val)[16]; ///< used for H.263 AIC, MPEG-4 AC prediction
|
2005-12-17 18:14:38 +00:00
|
|
|
int mb_skipped; ///< MUST BE SET only during DECODING
|
|
|
|
|
uint8_t *mbskip_table; /**< used to avoid copy if macroblock skipped (for black regions for example)
|
2016-04-27 13:45:23 -04:00
|
|
|
and used for B-frame encoding & decoding (contains skip table of next P-frame) */
|
2005-12-17 18:14:38 +00:00
|
|
|
uint8_t *mbintra_table; ///< used to avoid setting {ac, dc, cbp}-pred stuff to zero on inter MB decoding
|
|
|
|
|
uint8_t *cbp_table; ///< used to store cbp, ac_pred for partitioned decoding
|
|
|
|
|
uint8_t *pred_dir_table; ///< used to store pred_dir for partitioned decoding
|
2015-05-31 15:49:52 +02:00
|
|
|
|
|
|
|
|
ScratchpadContext sc;
|
2001-07-22 14:18:56 +00:00
|
|
|
|
2005-12-17 18:14:38 +00:00
|
|
|
int qscale; ///< QP
|
|
|
|
|
int chroma_qscale; ///< chroma QP
|
2011-04-28 01:40:44 +02:00
|
|
|
int pict_type; ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
|
2012-12-07 10:25:27 +01:00
|
|
|
int droppable;
|
2004-03-01 14:55:21 +00:00
|
|
|
|
2014-01-14 10:33:47 +01:00
|
|
|
BlockDSPContext bdsp;
|
2013-02-07 13:09:35 +01:00
|
|
|
H264ChromaContext h264chroma;
|
2013-03-10 13:55:07 -07:00
|
|
|
HpelDSPContext hdsp;
|
2014-01-24 11:55:16 +01:00
|
|
|
IDCTDSPContext idsp;
|
2014-01-08 14:00:10 +01:00
|
|
|
QpelDSPContext qdsp;
|
2012-12-15 09:46:02 -08:00
|
|
|
VideoDSPContext vdsp;
|
2013-11-05 08:11:47 +01:00
|
|
|
H263DSPContext h263dsp;
|
2021-12-13 01:22:04 +01:00
|
|
|
int16_t (*p_field_mv_table_base)[2];
|
2016-04-27 13:45:23 -04:00
|
|
|
int16_t (*p_field_mv_table[2][2])[2]; ///< MV table (2MV per MB) interlaced P-frame encoding
|
avcodec/mpegpicture: Move mb_var, mc_mb_var and mb_mean to MpegEncCtx
These tables are only used by encoders and only for the current picture;
ergo they need not be put into the picture at all, but rather into
the encoder's context. They also don't need to be refcounted,
because there is only one owner.
In contrast to this, the earlier code refcounts them which
incurs unnecessary overhead. These references are not unreferenced
in ff_mpeg_unref_picture() (they are kept in order to have something
like a buffer pool), so that several buffers are kept at the same
time, although only one is needed, thereby wasting memory.
The code also propagates references to other pictures not part of
the pictures array (namely the copy of the current/next/last picture
in the MpegEncContext which get references of their own). These
references are not unreferenced in ff_mpeg_unref_picture() (the
buffers are probably kept in order to have something like a pool),
yet if the current picture is a B-frame, it gets unreferenced
at the end of ff_mpv_encode_picture() and its slot in the picture
array will therefore be reused the next time; but the copy of the
current picture also still has its references and therefore
these buffers will be made duplicated in order to make them writable
in the next call to ff_mpv_encode_picture(). This is of course
unnecessary.
Finally, ff_find_unused_picture() is supposed to just return
any unused picture and the code is supposed to work with it;
yet for the vsynth*-mpeg4-adap tests the result depends upon
the content of these buffers; given that this patchset
changes the content of these buffers (the initial content is now
the state of these buffers after encoding the last frame;
before this patch the buffers used came from the last picture
that occupied the same slot in the picture array) their ref-files
needed to be changed. This points to a bug somewhere (if one removes
the initialization, one gets uninitialized reads in
adaptive_quantization in ratecontrol.c).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-08-07 09:02:51 +02:00
|
|
|
|
2001-07-22 14:18:56 +00:00
|
|
|
int mv_dir;
|
2007-08-01 22:12:52 +00:00
|
|
|
#define MV_DIR_FORWARD 1
|
|
|
|
|
#define MV_DIR_BACKWARD 2
|
2016-04-27 13:45:23 -04:00
|
|
|
#define MV_DIRECT 4 ///< bidirectional mode where the difference equals the MV of the last P/S/I-Frame (MPEG-4)
|
2001-07-22 14:18:56 +00:00
|
|
|
int mv_type;
|
2005-12-17 18:14:38 +00:00
|
|
|
#define MV_TYPE_16X16 0 ///< 1 vector for the whole mb
|
2016-04-27 13:45:23 -04:00
|
|
|
#define MV_TYPE_8X8 1 ///< 4 vectors (H.263, MPEG-4 4MV)
|
2005-12-17 18:14:38 +00:00
|
|
|
#define MV_TYPE_16X8 2 ///< 2 vectors, one per 16x8 block
|
|
|
|
|
#define MV_TYPE_FIELD 3 ///< 2 vectors, one per field
|
|
|
|
|
#define MV_TYPE_DMV 4 ///< 2 vectors, special mpeg2 Dual Prime Vectors
|
|
|
|
|
/**motion vectors for a macroblock
|
2001-07-22 14:18:56 +00:00
|
|
|
first coordinate : 0 = forward 1 = backward
|
|
|
|
|
second " : depend on type
|
|
|
|
|
third " : 0 = x, 1 = y
|
|
|
|
|
*/
|
|
|
|
|
int mv[2][4][2];
|
|
|
|
|
int field_select[2][2];
|
2016-04-27 13:45:23 -04:00
|
|
|
int last_mv[2][2][2]; ///< last MV, used for MV prediction in MPEG-1 & B-frame MPEG-4
|
2006-04-03 07:52:24 +00:00
|
|
|
int16_t direct_scale_mv[2][64]; ///< precomputed to avoid divisions in ff_mpeg4_set_direct_mv
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2016-04-27 13:45:23 -04:00
|
|
|
int no_rounding; /**< apply no rounding to motion compensation (MPEG-4, msmpeg4, ...)
|
|
|
|
|
for B-frames rounding mode is always 0 */
|
2001-07-22 14:18:56 +00:00
|
|
|
|
|
|
|
|
/* macroblock layer */
|
|
|
|
|
int mb_x, mb_y;
|
|
|
|
|
int mb_intra;
|
2006-12-21 15:20:02 +00:00
|
|
|
|
2003-03-06 14:37:37 +00:00
|
|
|
int block_index[6]; ///< index to current MB in block based arrays with edges
|
2002-03-15 14:57:17 +00:00
|
|
|
int block_wrap[6];
|
2003-07-29 02:09:12 +00:00
|
|
|
uint8_t *dest[3];
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2003-04-10 13:18:38 +00:00
|
|
|
int *mb_index2xy; ///< mb_index -> mb_x + mb_y*mb_stride
|
2002-03-15 14:57:17 +00:00
|
|
|
|
2003-03-06 14:37:37 +00:00
|
|
|
/** matrix transmitted in the bitstream */
|
2003-02-11 16:35:48 +00:00
|
|
|
uint16_t intra_matrix[64];
|
|
|
|
|
uint16_t chroma_intra_matrix[64];
|
|
|
|
|
uint16_t inter_matrix[64];
|
|
|
|
|
uint16_t chroma_inter_matrix[64];
|
2014-07-22 11:10:13 -07:00
|
|
|
|
2002-06-02 12:20:39 +00:00
|
|
|
/* error concealment / resync */
|
2005-12-17 18:14:38 +00:00
|
|
|
int resync_mb_x; ///< x position of last resync marker
|
|
|
|
|
int resync_mb_y; ///< y position of last resync marker
|
|
|
|
|
|
2001-11-12 05:19:55 +00:00
|
|
|
/* H.263 specific */
|
2003-11-29 08:37:51 +00:00
|
|
|
int obmc; ///< overlapped block motion compensation
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2001-08-31 06:21:27 +00:00
|
|
|
/* H.263+ specific */
|
2003-12-07 01:33:45 +00:00
|
|
|
int h263_aic_dir; ///< AIC direction: 0 = left, 1 = top
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2016-04-27 13:45:23 -04:00
|
|
|
/* MPEG-4 specific */
|
2017-12-29 15:42:14 +00:00
|
|
|
int studio_profile;
|
2002-04-17 04:32:12 +00:00
|
|
|
int last_time_base;
|
2005-12-17 18:14:38 +00:00
|
|
|
int time_base; ///< time in seconds of last I,P,S Frame
|
|
|
|
|
int64_t time; ///< time of current frame
|
2003-02-11 16:35:48 +00:00
|
|
|
int64_t last_non_b_time;
|
2005-12-17 18:14:38 +00:00
|
|
|
uint16_t pp_time; ///< time distance between the last 2 p,s,i frames
|
|
|
|
|
uint16_t pb_time; ///< time distance between the last b and p,s,i frame
|
2003-02-11 16:35:48 +00:00
|
|
|
uint16_t pp_field_time;
|
2005-12-17 18:14:38 +00:00
|
|
|
uint16_t pb_field_time; ///< like above, just for interlaced
|
2002-03-07 13:27:15 +00:00
|
|
|
int mcsel;
|
2005-12-17 18:14:38 +00:00
|
|
|
int quarter_sample; ///< 1->qpel, 0->half pel ME/MC
|
2016-04-27 13:45:23 -04:00
|
|
|
int low_delay; ///< no reordering needed / has no B-frames
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2001-07-22 14:18:56 +00:00
|
|
|
/* MSMPEG4 specific */
|
2016-04-27 13:45:23 -04:00
|
|
|
int first_slice_line; ///< used in MPEG-4 too to handle resync markers
|
2024-04-28 23:18:35 +02:00
|
|
|
enum {
|
|
|
|
|
MSMP4_UNUSED,
|
|
|
|
|
MSMP4_V1,
|
|
|
|
|
MSMP4_V2,
|
|
|
|
|
MSMP4_V3,
|
|
|
|
|
MSMP4_WMV1,
|
|
|
|
|
MSMP4_WMV2,
|
|
|
|
|
MSMP4_VC1, ///< for VC1 (image), WMV3 (image) and MSS2.
|
|
|
|
|
} msmpeg4_version;
|
2002-07-07 08:34:46 +00:00
|
|
|
int inter_intra_pred;
|
2002-12-27 23:51:46 +00:00
|
|
|
int mspel;
|
2002-06-18 00:50:20 +00:00
|
|
|
|
2009-03-02 05:41:55 +00:00
|
|
|
/* MPEG-2-specific - I wished not to have to support this mess. */
|
2001-07-22 14:18:56 +00:00
|
|
|
int progressive_sequence;
|
|
|
|
|
int mpeg_f_code[2][2];
|
2014-02-28 13:40:54 +01:00
|
|
|
|
|
|
|
|
// picture structure defines are loaded from mpegutils.h
|
2001-07-22 14:18:56 +00:00
|
|
|
int picture_structure;
|
|
|
|
|
|
|
|
|
|
int intra_dc_precision;
|
|
|
|
|
int frame_pred_frame_dct;
|
|
|
|
|
int top_field_first;
|
|
|
|
|
int concealment_motion_vectors;
|
|
|
|
|
int q_scale_type;
|
|
|
|
|
int intra_vlc_format;
|
|
|
|
|
int alternate_scan;
|
|
|
|
|
int repeat_first_field;
|
|
|
|
|
int chroma_420_type;
|
2004-03-01 14:55:21 +00:00
|
|
|
int chroma_format;
|
|
|
|
|
#define CHROMA_420 1
|
|
|
|
|
#define CHROMA_422 2
|
|
|
|
|
#define CHROMA_444 3
|
2004-06-11 07:59:12 +00:00
|
|
|
int chroma_x_shift;//depend on pix_format, that depend on chroma_format
|
|
|
|
|
int chroma_y_shift;
|
2004-03-01 14:55:21 +00:00
|
|
|
|
2001-07-22 14:18:56 +00:00
|
|
|
int progressive_frame;
|
2011-10-24 01:34:38 +02:00
|
|
|
int full_pel[2];
|
2001-07-22 14:18:56 +00:00
|
|
|
int interlaced_dct;
|
2003-08-22 14:59:04 +00:00
|
|
|
int first_field; ///< is 1 for the first field of a field picture 0 otherwise
|
2003-12-07 01:33:45 +00:00
|
|
|
|
2016-04-27 13:45:23 -04:00
|
|
|
void (*dct_unquantize_intra)(struct MpegEncContext *s, // unquantizer to use (MPEG-4 can use both)
|
2013-01-20 01:02:29 +01:00
|
|
|
int16_t *block/*align 16*/, int n, int qscale);
|
2016-04-27 13:45:23 -04:00
|
|
|
void (*dct_unquantize_inter)(struct MpegEncContext *s, // unquantizer to use (MPEG-4 can use both)
|
2013-01-20 01:02:29 +01:00
|
|
|
int16_t *block/*align 16*/, int n, int qscale);
|
2025-03-01 01:48:08 +01:00
|
|
|
|
2012-09-18 15:48:14 +02:00
|
|
|
/* flag to indicate a reinitialization is required, e.g. after
|
|
|
|
|
* a frame size change */
|
|
|
|
|
int context_reinit;
|
2013-02-02 20:42:07 +01:00
|
|
|
|
2025-03-16 14:52:36 +01:00
|
|
|
/// If set, ff_mpv_common_init() will allocate slice contexts of this size
|
|
|
|
|
unsigned slice_ctx_size;
|
|
|
|
|
|
2013-02-02 20:42:07 +01:00
|
|
|
ERContext er;
|
2001-07-22 14:18:56 +00:00
|
|
|
} MpegEncContext;
|
|
|
|
|
|
2025-06-15 23:06:40 +02:00
|
|
|
typedef MpegEncContext MPVContext;
|
2012-02-27 12:12:19 +01:00
|
|
|
|
2012-08-04 00:50:21 +01:00
|
|
|
/**
|
|
|
|
|
* Set the given MpegEncContext to common defaults (same for encoding
|
|
|
|
|
* and decoding). The changed fields will not depend upon the prior
|
|
|
|
|
* state of the MpegEncContext.
|
|
|
|
|
*/
|
2014-08-10 08:25:12 -07:00
|
|
|
void ff_mpv_common_defaults(MpegEncContext *s);
|
|
|
|
|
|
|
|
|
|
int ff_mpv_common_init(MpegEncContext *s);
|
2021-12-24 00:23:00 +01:00
|
|
|
/**
|
|
|
|
|
* Initialize an MpegEncContext's thread contexts. Presumes that
|
|
|
|
|
* slice_context_count is already set and that all the fields
|
|
|
|
|
* that are freed/reset in free_duplicate_context() are NULL.
|
|
|
|
|
*/
|
|
|
|
|
int ff_mpv_init_duplicate_contexts(MpegEncContext *s);
|
|
|
|
|
/**
|
|
|
|
|
* Initialize and allocates MpegEncContext fields dependent on the resolution.
|
|
|
|
|
*/
|
|
|
|
|
int ff_mpv_init_context_frame(MpegEncContext *s);
|
|
|
|
|
/**
|
|
|
|
|
* Frees and resets MpegEncContext fields depending on the resolution
|
|
|
|
|
* as well as the slice thread contexts.
|
|
|
|
|
* Is used during resolution changes to avoid a full reinitialization of the
|
|
|
|
|
* codec.
|
|
|
|
|
*/
|
|
|
|
|
void ff_mpv_free_context_frame(MpegEncContext *s);
|
2014-08-10 08:25:12 -07:00
|
|
|
|
|
|
|
|
void ff_mpv_common_end(MpegEncContext *s);
|
|
|
|
|
|
2002-06-02 12:20:39 +00:00
|
|
|
void ff_clean_intra_table_entries(MpegEncContext *s);
|
2013-03-15 14:33:24 +01:00
|
|
|
|
2022-01-31 05:24:02 +01:00
|
|
|
int ff_update_duplicate_context(MpegEncContext *dst, const MpegEncContext *src);
|
2010-03-06 22:36:52 +00:00
|
|
|
void ff_set_qscale(MpegEncContext * s, int qscale);
|
2002-12-17 11:25:29 +00:00
|
|
|
|
2014-08-08 08:11:20 -07:00
|
|
|
void ff_mpv_idct_init(MpegEncContext *s);
|
2022-10-20 06:03:27 +02:00
|
|
|
void ff_init_scantable(const uint8_t *permutation, ScanTable *st,
|
|
|
|
|
const uint8_t *src_scantable);
|
2003-07-29 02:09:12 +00:00
|
|
|
void ff_init_block_index(MpegEncContext *s);
|
2002-10-13 13:16:04 +00:00
|
|
|
|
2014-08-10 08:25:12 -07:00
|
|
|
void ff_mpv_motion(MpegEncContext *s,
|
2012-08-04 00:50:21 +01:00
|
|
|
uint8_t *dest_y, uint8_t *dest_cb,
|
|
|
|
|
uint8_t *dest_cr, int dir,
|
2022-07-26 08:55:32 +02:00
|
|
|
uint8_t *const *ref_picture,
|
2023-10-04 21:33:18 +02:00
|
|
|
const op_pixels_func (*pix_op)[4],
|
|
|
|
|
const qpel_mc_func (*qpix_op)[16]);
|
2012-08-04 00:50:21 +01:00
|
|
|
|
2022-07-26 20:02:25 +02:00
|
|
|
static inline void ff_update_block_index(MpegEncContext *s, int bits_per_raw_sample,
|
|
|
|
|
int lowres, int chroma_x_shift)
|
|
|
|
|
{
|
|
|
|
|
const int bytes_per_pixel = 1 + (bits_per_raw_sample > 8);
|
|
|
|
|
const int block_size = (8 * bytes_per_pixel) >> lowres;
|
2004-09-25 23:18:58 +00:00
|
|
|
|
2002-10-13 13:16:04 +00:00
|
|
|
s->block_index[0]+=2;
|
|
|
|
|
s->block_index[1]+=2;
|
|
|
|
|
s->block_index[2]+=2;
|
|
|
|
|
s->block_index[3]+=2;
|
|
|
|
|
s->block_index[4]++;
|
|
|
|
|
s->block_index[5]++;
|
2004-09-25 23:18:58 +00:00
|
|
|
s->dest[0]+= 2*block_size;
|
2022-07-26 20:02:25 +02:00
|
|
|
s->dest[1] += (2 >> chroma_x_shift) * block_size;
|
|
|
|
|
s->dest[2] += (2 >> chroma_x_shift) * block_size;
|
2002-10-13 13:16:04 +00:00
|
|
|
}
|
|
|
|
|
|
2008-08-31 07:39:47 +00:00
|
|
|
#endif /* AVCODEC_MPEGVIDEO_H */
|