48static void gray16(uint8_t *
dst,
const uint8_t *
src, ptrdiff_t linesize,
int h)
51 memset(
dst +
h*linesize, 128, 16);
54static void gray8(uint8_t *
dst,
const uint8_t *
src, ptrdiff_t linesize,
int h)
57 memset(
dst +
h*linesize, 128, 8);
70 s->hdsp.avg_pixels_tab[0][
i] =
gray16;
71 s->hdsp.put_pixels_tab[0][
i] =
gray16;
72 s->hdsp.put_no_rnd_pixels_tab[0][
i] =
gray16;
74 s->hdsp.avg_pixels_tab[1][
i] =
gray8;
75 s->hdsp.put_pixels_tab[1][
i] =
gray8;
76 s->hdsp.put_no_rnd_pixels_tab[1][
i] =
gray8;
84 s->idsp.mpeg4_studio_profile =
s->studio_profile;
90 if (
s->alternate_scan) {
101 const int nb_slices =
s->slice_context_count;
102 const size_t slice_size =
s->slice_ctx_size;
104 for (
int i = 1;
i < nb_slices;
i++) {
106 if (!
s->thread_context[
i])
108 s->thread_context[
i]->start_mb_y =
109 (
s->mb_height * (
i ) + nb_slices / 2) / nb_slices;
110 s->thread_context[
i]->end_mb_y =
111 (
s->mb_height * (
i + 1) + nb_slices / 2) / nb_slices;
114 s->end_mb_y = nb_slices > 1 ? (
s->mb_height + nb_slices / 2) / nb_slices
126 s->sc.obmc_scratchpad =
NULL;
132 for (
int i = 1;
i <
s->slice_context_count;
i++) {
142 M(ScratchpadContext, sc) \
145 M(int16_t*, dc_val) \
150#define BACKUP(T, member) T member = dst->member;
153#define RESTORE(T, member) dst->member = member;
159 "scratch buffers.\n");
174 s->progressive_frame = 1;
175 s->progressive_sequence = 1;
178 s->slice_context_count = 1;
193 int nb_slices = (HAVE_THREADS &&
195 s->avctx->thread_count : 1;
197 int y_size, c_size, yc_size, mb_array_size, mv_table_size, x, y;
200 if (
s->encoding &&
s->avctx->slices)
201 nb_slices =
s->avctx->slices;
204 s->mb_height = (
s->height + 31) / 32 * 2;
206 s->mb_height = (
s->height + 15) / 16;
208 if (nb_slices >
MAX_THREADS || (nb_slices >
s->mb_height &&
s->mb_height)) {
215 " reducing to %d\n", nb_slices, max_slices);
216 nb_slices = max_slices;
219 s->slice_context_count = nb_slices;
224 mb_height =
s->msmpeg4_version == MSMP4_VC1 ?
227 s->mb_width = (
s->width + 15) / 16;
228 s->mb_stride =
s->mb_width + 1;
229 s->b8_stride =
s->mb_width * 2 + 1;
230 mb_array_size = mb_height *
s->mb_stride;
231 mv_table_size = (mb_height + 2) *
s->mb_stride + 1;
235 s->h_edge_pos =
s->mb_width * 16;
236 s->v_edge_pos =
s->mb_height * 16;
238 s->mb_num =
s->mb_width *
s->mb_height;
243 s->block_wrap[3] =
s->b8_stride;
245 s->block_wrap[5] =
s->mb_stride;
247 y_size =
s->b8_stride * (2 * mb_height + 1);
248 c_size =
s->mb_stride * (mb_height + 1);
249 yc_size = y_size + 2 * c_size;
253 for (y = 0; y <
s->mb_height; y++)
254 for (x = 0; x <
s->mb_width; x++)
255 s->mb_index2xy[x + y *
s->mb_width] = x + y *
s->mb_stride;
257 s->mb_index2xy[
s->mb_height *
s->mb_width] = (
s->mb_height - 1) *
s->mb_stride +
s->mb_width;
259#define ALLOC_POOL(name, size, flags) do { \
260 pools->name ##_pool = av_refstruct_pool_alloc((size), (flags)); \
261 if (!pools->name ##_pool) \
262 return AVERROR(ENOMEM); \
271 s->p_field_mv_table_base =
tmp;
272 tmp +=
s->mb_stride + 1;
273 for (
int i = 0;
i < 2;
i++) {
274 for (
int j = 0; j < 2; j++) {
275 s->p_field_mv_table[
i][j] =
tmp;
276 tmp += mv_table_size;
291 if (
s->msmpeg4_version >= MSMP4_V3) {
293 if (!
s->coded_block_base)
295 s->coded_block =
s->coded_block_base +
s->b8_stride + 1;
298 if (
s->h263_pred ||
s->h263_aic || !
s->encoding) {
302 size_t allslice_yc_size = yc_size * (
s->encoding ? nb_slices : 1);
307 s->ac_val =
s->ac_val_base +
s->b8_stride + 1;
318 allslice_yc_size +=
s->encoding * nb_slices;
321 s->dc_val =
s->dc_val_base +
s->b8_stride + 1;
322 for (
size_t i = 0;
i < allslice_yc_size; ++
i)
323 s->dc_val_base[
i] = 1024;
327 if (!(
s->mbskip_table =
av_mallocz(mb_array_size + 2)) ||
333 ALLOC_POOL(mb_type, mv_table_size *
sizeof(uint32_t), 0);
335 if (
s->out_format ==
FMT_H263 ||
s->encoding ||
337 const int b8_array_size =
s->b8_stride * mb_height * 2;
338 int mv_size = 2 * (b8_array_size + 4) *
sizeof(int16_t);
339 int ref_index_size = 4 * mb_array_size;
365 "decoding to AV_PIX_FMT_NONE is not supported.\n");
369 if ((
s->width ||
s->height) &&
385 s->context_initialized = 1;
386 s->thread_context[0] =
s;
408 for (
int i = 0;
i < 2;
i++)
409 for (
int j = 0; j < 2; j++)
410 s->p_field_mv_table[
i][j] =
NULL;
425 s->linesize =
s->uvlinesize = 0;
431 if (
s->slice_context_count > 1)
432 s->slice_context_count = 1;
438 s->context_initialized = 0;
439 s->context_reinit = 0;
440 s->linesize =
s->uvlinesize = 0;
449 int wrap =
s->b8_stride;
450 int xy =
s->block_index[0];
452 unsigned uxy =
s->block_index[4];
453 unsigned vxy =
s->block_index[5];
454 int16_t *dc_val =
s->dc_val;
456 AV_WN32A(dc_val + xy, 1024 << 16 | 1024);
461 int16_t (*ac_val)[16] =
s->ac_val;
465 memset(ac_val[xy + 1], 0,
sizeof(*ac_val));
466 memset(ac_val[xy +
wrap], 0, 2 *
sizeof(*ac_val));
468 memset(ac_val[uxy], 0,
sizeof(*ac_val));
469 memset(ac_val[vxy], 0,
sizeof(*ac_val));
473 const int linesize =
s->cur_pic.linesize[0];
474 const int uvlinesize =
s->cur_pic.linesize[1];
475 const int width_of_mb = (4 + (
s->avctx->bits_per_raw_sample > 8)) -
s->avctx->lowres;
476 const int height_of_mb = 4 -
s->avctx->lowres;
478 s->block_index[0]=
s->b8_stride*(
s->mb_y*2 ) - 2 +
s->mb_x*2;
479 s->block_index[1]=
s->b8_stride*(
s->mb_y*2 ) - 1 +
s->mb_x*2;
480 s->block_index[2]=
s->b8_stride*(
s->mb_y*2 + 1) - 2 +
s->mb_x*2;
481 s->block_index[3]=
s->b8_stride*(
s->mb_y*2 + 1) - 1 +
s->mb_x*2;
482 s->block_index[4]=
s->mb_stride*(
s->mb_y + 1) +
s->b8_stride*
s->mb_height*2 +
s->mb_x - 1;
483 s->block_index[5]=
s->mb_stride*(
s->mb_y +
s->mb_height + 2) +
s->b8_stride*
s->mb_height*2 +
s->mb_x - 1;
486 s->dest[0] =
s->cur_pic.data[0] + (int)((
s->mb_x - 1U) << width_of_mb);
487 s->dest[1] =
s->cur_pic.data[1] + (int)((
s->mb_x - 1U) << (width_of_mb -
s->chroma_x_shift));
488 s->dest[2] =
s->cur_pic.data[2] + (int)((
s->mb_x - 1U) << (width_of_mb -
s->chroma_x_shift));
491 s->dest[0] +=
s->mb_y * linesize << height_of_mb;
492 s->dest[1] +=
s->mb_y * uvlinesize << (height_of_mb -
s->chroma_y_shift);
493 s->dest[2] +=
s->mb_y * uvlinesize << (height_of_mb -
s->chroma_y_shift);
495 s->dest[0] += (
s->mb_y>>1) * linesize << height_of_mb;
496 s->dest[1] += (
s->mb_y>>1) * uvlinesize << (height_of_mb -
s->chroma_y_shift);
497 s->dest[2] += (
s->mb_y>>1) * uvlinesize << (height_of_mb -
s->chroma_y_shift);
509 else if (qscale > 31)
513 s->chroma_qscale=
s->chroma_qscale_table[qscale];
515 s->y_dc_scale=
s->y_dc_scale_table[ qscale ];
516 s->c_dc_scale=
s->c_dc_scale_table[
s->chroma_qscale ];
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Libavcodec external API header.
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
#define i(width, name, range_min, range_max)
#define AV_CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
#define AV_CODEC_EXPORT_DATA_MVS
Export motion vectors through frame side data.
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
av_cold void ff_blockdsp_init(BlockDSPContext *c)
av_cold void ff_hpeldsp_init(HpelDSPContext *c, int flags)
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
Macro definitions for various function/variable attributes.
common internal API header
#define FF_ALLOC_TYPED_ARRAY(p, nelem)
#define FF_ALLOCZ_TYPED_ARRAY(p, nelem)
const uint8_t ff_zigzag_direct[64]
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
av_cold int ff_mpeg_er_init(MpegEncContext *s)
void ff_mpv_unref_picture(MPVWorkPicture *pic)
int ff_mpv_framesize_alloc(AVCodecContext *avctx, ScratchpadContext *sc, int linesize)
#define PICT_BOTTOM_FIELD
av_cold void ff_mpv_free_context_frame(MpegEncContext *s)
Frees and resets MpegEncContext fields depending on the resolution as well as the slice thread contex...
#define BACKUP(T, member)
static av_cold void free_buffer_pools(BufferPoolContext *pools)
static void gray8(uint8_t *dst, const uint8_t *src, ptrdiff_t linesize, int h)
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
static av_cold void free_duplicate_context(MpegEncContext *s)
static void gray16(uint8_t *dst, const uint8_t *src, ptrdiff_t linesize, int h)
av_cold int ff_mpv_init_duplicate_contexts(MpegEncContext *s)
Initialize an MpegEncContext's thread contexts.
av_cold void ff_mpv_idct_init(MpegEncContext *s)
av_cold void ff_mpv_common_end(MpegEncContext *s)
static av_cold void dsp_init(MpegEncContext *s)
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
av_cold int ff_mpv_init_context_frame(MpegEncContext *s)
Initialize and allocates MpegEncContext fields dependent on the resolution.
void ff_init_block_index(MpegEncContext *s)
#define RESTORE(T, member)
void ff_clean_intra_table_entries(MpegEncContext *s)
Clean dc, ac for the current non-intra MB.
#define ALLOC_POOL(name, size, flags)
static av_cold void free_duplicate_contexts(MpegEncContext *s)
av_cold void ff_mpv_common_defaults(MpegEncContext *s)
Set the given MpegEncContext to common defaults (same for encoding and decoding).
int ff_update_duplicate_context(MpegEncContext *dst, const MpegEncContext *src)
void ff_init_scantable(const uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
const uint8_t ff_default_chroma_qscale_table[32]
const uint8_t ff_alternate_vertical_scan[64]
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
#define AV_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME
If this flag is set, the entries will be zeroed before being returned to the user (after the init or ...
static void av_refstruct_pool_uninit(AVRefStructPool **poolp)
Mark the pool as being available for freeing.
struct AVRefStructPool * mbskip_table_pool
struct AVRefStructPool * mb_type_pool
struct AVRefStructPool * ref_index_pool
struct AVRefStructPool * qscale_table_pool
int alloc_mb_width
mb_width used to allocate tables
struct AVRefStructPool * motion_val_pool
int alloc_mb_stride
mb_stride used to allocate tables
int alloc_mb_height
mb_height used to allocate tables