Go to the documentation of this file.
45 int16_t *
block,
int n,
int qscale)
48 const uint16_t *quant_matrix;
50 nCoeffs=
s->block_last_index[n];
52 block[0] *= n < 4 ?
s->y_dc_scale :
s->c_dc_scale;
54 quant_matrix =
s->intra_matrix;
55 for(
i=1;
i<=nCoeffs;
i++) {
56 int j=
s->intra_scantable.permutated[
i];
74 int16_t *
block,
int n,
int qscale)
77 const uint16_t *quant_matrix;
79 nCoeffs=
s->block_last_index[n];
81 quant_matrix =
s->inter_matrix;
82 for(
i=0;
i<=nCoeffs;
i++) {
83 int j=
s->intra_scantable.permutated[
i];
89 ((
int) (quant_matrix[j]))) >> 4;
94 ((
int) (quant_matrix[j]))) >> 4;
103 int16_t *
block,
int n,
int qscale)
106 const uint16_t *quant_matrix;
111 if(
s->alternate_scan) nCoeffs= 63;
112 else nCoeffs=
s->block_last_index[n];
114 block[0] *= n < 4 ?
s->y_dc_scale :
s->c_dc_scale;
115 quant_matrix =
s->intra_matrix;
116 for(
i=1;
i<=nCoeffs;
i++) {
117 int j=
s->intra_scantable.permutated[
i];
133 int16_t *
block,
int n,
int qscale)
136 const uint16_t *quant_matrix;
142 if(
s->alternate_scan) nCoeffs= 63;
143 else nCoeffs=
s->block_last_index[n];
145 block[0] *= n < 4 ?
s->y_dc_scale :
s->c_dc_scale;
147 quant_matrix =
s->intra_matrix;
148 for(
i=1;
i<=nCoeffs;
i++) {
149 int j=
s->intra_scantable.permutated[
i];
167 int16_t *
block,
int n,
int qscale)
170 const uint16_t *quant_matrix;
176 if(
s->alternate_scan) nCoeffs= 63;
177 else nCoeffs=
s->block_last_index[n];
179 quant_matrix =
s->inter_matrix;
180 for(
i=0;
i<=nCoeffs;
i++) {
181 int j=
s->intra_scantable.permutated[
i];
187 ((
int) (quant_matrix[j]))) >> 5;
191 ((
int) (quant_matrix[j]))) >> 5;
201 int16_t *
block,
int n,
int qscale)
211 block[0] *= n < 4 ?
s->y_dc_scale :
s->c_dc_scale;
212 qadd = (qscale - 1) | 1;
219 nCoeffs=
s->intra_scantable.raster_end[
s->block_last_index[n] ];
221 for(
i=1;
i<=nCoeffs;
i++) {
235 int16_t *
block,
int n,
int qscale)
242 qadd = (qscale - 1) | 1;
245 nCoeffs=
s->inter_scantable.raster_end[
s->block_last_index[n] ];
247 for(
i=0;
i<=nCoeffs;
i++) {
282 for (
i=0;
i<4;
i++) {
283 s->hdsp.avg_pixels_tab[0][
i] =
gray16;
284 s->hdsp.put_pixels_tab[0][
i] =
gray16;
285 s->hdsp.put_no_rnd_pixels_tab[0][
i] =
gray16;
287 s->hdsp.avg_pixels_tab[1][
i] =
gray8;
288 s->hdsp.put_pixels_tab[1][
i] =
gray8;
289 s->hdsp.put_no_rnd_pixels_tab[1][
i] =
gray8;
302 #if HAVE_INTRINSICS_NEON
322 const uint8_t *src_scantable)
328 for (
int i = 0;
i < 64;
i++) {
329 int j = src_scantable[
i];
334 for (
int i = 0;
i < 64;
i++) {
345 s->idsp.mpeg4_studio_profile =
s->studio_profile;
351 if (
s->alternate_scan) {
359 s->idsp.idct_permutation);
361 s->idsp.idct_permutation);
366 int y_size =
s->b8_stride * (2 *
s->mb_height + 1);
367 int c_size =
s->mb_stride * (
s->mb_height + 1);
368 int yc_size = y_size + 2 * c_size;
371 if (
s->mb_height & 1)
372 yc_size += 2*
s->b8_stride + 2*
s->mb_stride;
380 if (
s->noise_reduction) {
387 s->block =
s->blocks[0];
389 for (
i = 0;
i < 12;
i++) {
390 s->pblocks[
i] = &
s->block[
i];
393 if (
s->avctx->codec_tag ==
AV_RL32(
"VCR2")) {
395 FFSWAP(
void *,
s->pblocks[4],
s->pblocks[5]);
402 s->ac_val[0] =
s->ac_val_base +
s->b8_stride + 1;
403 s->ac_val[1] =
s->ac_val_base + y_size +
s->mb_stride + 1;
404 s->ac_val[2] =
s->ac_val[1] + c_size;
412 int nb_slices =
s->slice_context_count,
ret;
417 for (
int i = 1;
i < nb_slices;
i++) {
419 if (!
s->thread_context[
i])
423 s->thread_context[
i]->start_mb_y =
424 (
s->mb_height * (
i ) + nb_slices / 2) / nb_slices;
425 s->thread_context[
i]->end_mb_y =
426 (
s->mb_height * (
i + 1) + nb_slices / 2) / nb_slices;
429 s->end_mb_y = nb_slices > 1 ? (
s->mb_height + nb_slices / 2) / nb_slices
442 s->sc.rd_scratchpad =
444 s->sc.obmc_scratchpad =
NULL;
448 s->me.score_map =
NULL;
456 for (
int i = 1;
i <
s->slice_context_count;
i++) {
465 #define COPY(a) bak->a = src->a
466 COPY(sc.edge_emu_buffer);
469 COPY(sc.rd_scratchpad);
470 COPY(sc.b_scratchpad);
471 COPY(sc.obmc_scratchpad);
498 for (
i = 0;
i < 12;
i++) {
509 "scratch buffers.\n");
523 s->y_dc_scale_table =
526 s->progressive_frame = 1;
527 s->progressive_sequence = 1;
530 s->coded_picture_number = 0;
531 s->picture_number = 0;
536 s->slice_context_count = 1;
541 int y_size, c_size, yc_size,
i, mb_array_size, mv_table_size, x, y;
544 s->mb_height = (
s->height + 31) / 32 * 2;
546 s->mb_height = (
s->height + 15) / 16;
548 s->mb_width = (
s->width + 15) / 16;
549 s->mb_stride =
s->mb_width + 1;
550 s->b8_stride =
s->mb_width * 2 + 1;
551 mb_array_size =
s->mb_height *
s->mb_stride;
552 mv_table_size = (
s->mb_height + 2) *
s->mb_stride + 1;
556 s->h_edge_pos =
s->mb_width * 16;
557 s->v_edge_pos =
s->mb_height * 16;
559 s->mb_num =
s->mb_width *
s->mb_height;
564 s->block_wrap[3] =
s->b8_stride;
566 s->block_wrap[5] =
s->mb_stride;
568 y_size =
s->b8_stride * (2 *
s->mb_height + 1);
569 c_size =
s->mb_stride * (
s->mb_height + 1);
570 yc_size = y_size + 2 * c_size;
572 if (
s->mb_height & 1)
573 yc_size += 2*
s->b8_stride + 2*
s->mb_stride;
577 for (y = 0; y <
s->mb_height; y++)
578 for (x = 0; x <
s->mb_width; x++)
579 s->mb_index2xy[x + y *
s->mb_width] = x + y *
s->mb_stride;
581 s->mb_index2xy[
s->mb_height *
s->mb_width] = (
s->mb_height - 1) *
s->mb_stride +
s->mb_width;
589 s->p_field_mv_table_base =
tmp;
590 tmp +=
s->mb_stride + 1;
591 for (
int i = 0;
i < 2;
i++) {
592 for (
int j = 0; j < 2; j++) {
593 s->p_field_mv_table[
i][j] =
tmp;
594 tmp += mv_table_size;
601 if (!(
s->coded_block_base =
av_mallocz(y_size + (
s->mb_height&1)*2*
s->b8_stride)) ||
605 s->coded_block =
s->coded_block_base +
s->b8_stride + 1;
608 if (
s->h263_pred ||
s->h263_plus || !
s->encoding) {
613 s->dc_val[0] =
s->dc_val_base +
s->b8_stride + 1;
614 s->dc_val[1] =
s->dc_val_base + y_size +
s->mb_stride + 1;
615 s->dc_val[2] =
s->dc_val[1] + c_size;
616 for (
i = 0;
i < yc_size;
i++)
617 s->dc_val_base[
i] = 1024;
621 if (!(
s->mbskip_table =
av_mallocz(mb_array_size + 2)) ||
623 !(
s->mbintra_table =
av_malloc(mb_array_size)))
625 memset(
s->mbintra_table, 1, mb_array_size);
632 memset(&
s->next_picture, 0,
sizeof(
s->next_picture));
633 memset(&
s->last_picture, 0,
sizeof(
s->last_picture));
634 memset(&
s->current_picture, 0,
sizeof(
s->current_picture));
636 memset(
s->thread_context, 0,
sizeof(
s->thread_context));
639 s->me.score_map =
NULL;
640 s->dct_error_sum =
NULL;
643 memset(
s->pblocks, 0,
sizeof(
s->pblocks));
644 s->ac_val_base =
NULL;
648 s->sc.edge_emu_buffer =
NULL;
649 s->me.scratchpad =
NULL;
651 s->sc.rd_scratchpad =
653 s->sc.obmc_scratchpad =
NULL;
656 s->bitstream_buffer =
NULL;
657 s->allocated_bitstream_buffer_size = 0;
659 s->p_field_mv_table_base =
NULL;
660 for (
int i = 0;
i < 2;
i++)
661 for (
int j = 0; j < 2; j++)
662 s->p_field_mv_table[
i][j] =
NULL;
664 s->dc_val_base =
NULL;
665 s->coded_block_base =
NULL;
666 s->mbintra_table =
NULL;
668 s->pred_dir_table =
NULL;
670 s->mbskip_table =
NULL;
672 s->er.error_status_table =
NULL;
673 s->er.er_temp_buffer =
NULL;
674 s->mb_index2xy =
NULL;
684 int nb_slices = (HAVE_THREADS &&
686 s->avctx->thread_count : 1;
690 if (
s->encoding &&
s->avctx->slices)
691 nb_slices =
s->avctx->slices;
695 "decoding to AV_PIX_FMT_NONE is not supported.\n");
699 if ((
s->width ||
s->height) &&
716 if (!
s->picture[
i].f)
728 if (nb_slices >
MAX_THREADS || (nb_slices >
s->mb_height &&
s->mb_height)) {
735 " reducing to %d\n", nb_slices, max_slices);
736 nb_slices = max_slices;
739 s->context_initialized = 1;
740 memset(
s->thread_context, 0,
sizeof(
s->thread_context));
741 s->thread_context[0] =
s;
742 s->slice_context_count = nb_slices;
763 for (
int i = 0;
i < 2;
i++)
764 for (
int j = 0; j < 2; j++)
765 s->p_field_mv_table[
i][j] =
NULL;
779 s->linesize =
s->uvlinesize = 0;
785 if (
s->slice_context_count > 1)
786 s->slice_context_count = 1;
789 s->allocated_bitstream_buffer_size = 0;
803 s->context_initialized = 0;
804 s->context_reinit = 0;
805 s->last_picture_ptr =
806 s->next_picture_ptr =
807 s->current_picture_ptr =
NULL;
808 s->linesize =
s->uvlinesize = 0;
817 int wrap =
s->b8_stride;
818 int xy =
s->block_index[0];
821 s->dc_val[0][xy + 1 ] =
822 s->dc_val[0][xy +
wrap] =
823 s->dc_val[0][xy + 1 +
wrap] = 1024;
825 memset(
s->ac_val[0][xy ], 0, 32 *
sizeof(int16_t));
826 memset(
s->ac_val[0][xy +
wrap], 0, 32 *
sizeof(int16_t));
827 if (
s->msmpeg4_version>=3) {
828 s->coded_block[xy ] =
829 s->coded_block[xy + 1 ] =
830 s->coded_block[xy +
wrap] =
831 s->coded_block[xy + 1 +
wrap] = 0;
835 xy =
s->mb_x +
s->mb_y *
wrap;
837 s->dc_val[2][xy] = 1024;
839 memset(
s->ac_val[1][xy], 0, 16 *
sizeof(int16_t));
840 memset(
s->ac_val[2][xy], 0, 16 *
sizeof(int16_t));
842 s->mbintra_table[xy]= 0;
846 const int linesize =
s->current_picture.f->linesize[0];
847 const int uvlinesize =
s->current_picture.f->linesize[1];
848 const int width_of_mb = (4 + (
s->avctx->bits_per_raw_sample > 8)) -
s->avctx->lowres;
849 const int height_of_mb = 4 -
s->avctx->lowres;
851 s->block_index[0]=
s->b8_stride*(
s->mb_y*2 ) - 2 +
s->mb_x*2;
852 s->block_index[1]=
s->b8_stride*(
s->mb_y*2 ) - 1 +
s->mb_x*2;
853 s->block_index[2]=
s->b8_stride*(
s->mb_y*2 + 1) - 2 +
s->mb_x*2;
854 s->block_index[3]=
s->b8_stride*(
s->mb_y*2 + 1) - 1 +
s->mb_x*2;
855 s->block_index[4]=
s->mb_stride*(
s->mb_y + 1) +
s->b8_stride*
s->mb_height*2 +
s->mb_x - 1;
856 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;
859 s->dest[0] =
s->current_picture.f->data[0] + (
int)((
s->mb_x - 1
U) << width_of_mb);
860 s->dest[1] =
s->current_picture.f->data[1] + (
int)((
s->mb_x - 1
U) << (width_of_mb -
s->chroma_x_shift));
861 s->dest[2] =
s->current_picture.f->data[2] + (
int)((
s->mb_x - 1
U) << (width_of_mb -
s->chroma_x_shift));
864 s->dest[0] +=
s->mb_y *
linesize << height_of_mb;
865 s->dest[1] +=
s->mb_y * uvlinesize << (height_of_mb -
s->chroma_y_shift);
866 s->dest[2] +=
s->mb_y * uvlinesize << (height_of_mb -
s->chroma_y_shift);
868 s->dest[0] += (
s->mb_y>>1) *
linesize << height_of_mb;
869 s->dest[1] += (
s->mb_y>>1) * uvlinesize << (height_of_mb -
s->chroma_y_shift);
870 s->dest[2] += (
s->mb_y>>1) * uvlinesize << (height_of_mb -
s->chroma_y_shift);
882 else if (qscale > 31)
886 s->chroma_qscale=
s->chroma_qscale_table[qscale];
888 s->y_dc_scale=
s->y_dc_scale_table[ qscale ];
889 s->c_dc_scale=
s->c_dc_scale_table[
s->chroma_qscale ];
#define FF_ALLOCZ_TYPED_ARRAY(p, nelem)
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
#define AV_LOG_WARNING
Something somehow does not look correct.
static void free_duplicate_contexts(MpegEncContext *s)
int ff_mpeg_framesize_alloc(AVCodecContext *avctx, MotionEstContext *me, ScratchpadContext *sc, int linesize)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int ff_mpv_init_context_frame(MpegEncContext *s)
Initialize and allocates MpegEncContext fields dependent on the resolution.
static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src)
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)
const uint8_t ff_mpeg2_non_linear_qscale[32]
void ff_clean_intra_table_entries(MpegEncContext *s)
Clean dc, ac, coded_block for the current non-intra MB.
#define PICT_BOTTOM_FIELD
static int init_duplicate_context(MpegEncContext *s)
av_cold void ff_mpv_common_init_arm(MpegEncContext *s)
void ff_init_block_index(MpegEncContext *s)
struct AVCodecContext * avctx
#define AV_CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
static void free_duplicate_context(MpegEncContext *s)
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
av_cold void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64], const uint8_t permutation[64])
static void dct_unquantize_mpeg1_inter_c(MpegEncContext *s, int16_t *block, int n, int qscale)
ptrdiff_t linesize
line size, in bytes, may be different from width
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.
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
#define MAX_PICTURE_COUNT
static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s, int16_t *block, int n, int qscale)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
void ff_mpv_common_end(MpegEncContext *s)
int16_t(*[12] pblocks)[64]
static void gray16(uint8_t *dst, const uint8_t *src, ptrdiff_t linesize, int h)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
av_cold void ff_blockdsp_init(BlockDSPContext *c)
static const uint8_t *const ff_mpeg1_dc_scale_table
static void dct_unquantize_mpeg2_intra_bitexact(MpegEncContext *s, int16_t *block, int n, int qscale)
void av_cold ff_mpv_picture_free(Picture *pic)
const uint8_t * scantable
av_cold void ff_hpeldsp_init(HpelDSPContext *c, int flags)
av_cold void ff_mpv_idct_init(MpegEncContext *s)
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
const uint8_t ff_alternate_horizontal_scan[64]
static void dct_unquantize_mpeg2_intra_c(MpegEncContext *s, int16_t *block, int n, int qscale)
int ff_mpeg_er_init(MpegEncContext *s)
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
static void dct_unquantize_mpeg2_inter_c(MpegEncContext *s, int16_t *block, int n, int qscale)
static void clear_context(MpegEncContext *s)
av_cold void ff_init_scantable(const uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
static void dct_unquantize_h263_inter_c(MpegEncContext *s, int16_t *block, int n, int qscale)
#define i(width, name, range_min, range_max)
const uint8_t ff_alternate_vertical_scan[64]
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
void ff_mpv_common_init_ppc(MpegEncContext *s)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
void * av_calloc(size_t nmemb, size_t size)
const uint8_t ff_zigzag_direct[64]
#define FFSWAP(type, a, b)
static av_cold int dct_init(MpegEncContext *s)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
void ff_mpv_free_context_frame(MpegEncContext *s)
Frees and resets MpegEncContext fields depending on the resolution as well as the slice thread contex...
int16_t(* block)[64]
points to one of the following blocks
uint8_t * edge_emu_buffer
temporary buffer for if MVs point to out-of-frame data
static void dct_unquantize_h263_intra_c(MpegEncContext *s, int16_t *block, int n, int qscale)
av_cold void ff_mpv_common_init_x86(MpegEncContext *s)
av_cold void ff_mpv_common_init_axp(MpegEncContext *s)
av_cold void ff_mpv_common_init_mips(MpegEncContext *s)
const uint8_t ff_default_chroma_qscale_table[32]
int ff_mpv_init_duplicate_contexts(MpegEncContext *s)
Initialize an MpegEncContext's thread contexts.
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
The exact code depends on how similar the blocks are and how related they are to the block
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_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
av_cold void ff_mpv_common_init_neon(MpegEncContext *s)
static void gray8(uint8_t *dst, const uint8_t *src, ptrdiff_t linesize, int h)