You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-04 22:03:09 +02:00
avcodec/mpeg12dec: Don't use MPVContext.block
Instead add the necessary blocks directly into Mpeg12SliceContext. This allows to completely remove MPVContext.block. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@ -73,6 +73,8 @@ enum Mpeg2ClosedCaptionsFormat {
|
|||||||
typedef struct Mpeg12SliceContext {
|
typedef struct Mpeg12SliceContext {
|
||||||
MPVContext c;
|
MPVContext c;
|
||||||
GetBitContext gb;
|
GetBitContext gb;
|
||||||
|
|
||||||
|
DECLARE_ALIGNED_32(int16_t, block)[12][64];
|
||||||
} Mpeg12SliceContext;
|
} Mpeg12SliceContext;
|
||||||
|
|
||||||
typedef struct Mpeg1Context {
|
typedef struct Mpeg1Context {
|
||||||
@ -472,10 +474,10 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
|
|||||||
ff_tlog(s->c.avctx, "mb_type=%x\n", mb_type);
|
ff_tlog(s->c.avctx, "mb_type=%x\n", mb_type);
|
||||||
// motion_type = 0; /* avoid warning */
|
// motion_type = 0; /* avoid warning */
|
||||||
if (IS_INTRA(mb_type)) {
|
if (IS_INTRA(mb_type)) {
|
||||||
s->c.bdsp.clear_blocks(s->c.block[0]);
|
s->c.bdsp.clear_blocks(s->block[0]);
|
||||||
|
|
||||||
if (!s->c.chroma_y_shift)
|
if (!s->c.chroma_y_shift)
|
||||||
s->c.bdsp.clear_blocks(s->c.block[6]);
|
s->c.bdsp.clear_blocks(s->block[6]);
|
||||||
|
|
||||||
/* compute DCT type */
|
/* compute DCT type */
|
||||||
// FIXME: add an interlaced_dct coded var?
|
// FIXME: add an interlaced_dct coded var?
|
||||||
@ -509,14 +511,14 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
|
|||||||
|
|
||||||
if (s->c.codec_id == AV_CODEC_ID_MPEG2VIDEO) {
|
if (s->c.codec_id == AV_CODEC_ID_MPEG2VIDEO) {
|
||||||
for (i = 0; i < mb_block_count; i++)
|
for (i = 0; i < mb_block_count; i++)
|
||||||
if ((ret = mpeg2_decode_block_intra(s, s->c.block[i], i)) < 0)
|
if ((ret = mpeg2_decode_block_intra(s, s->block[i], i)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
ret = ff_mpeg1_decode_block_intra(&s->gb,
|
ret = ff_mpeg1_decode_block_intra(&s->gb,
|
||||||
s->c.intra_matrix,
|
s->c.intra_matrix,
|
||||||
s->c.intra_scantable.permutated,
|
s->c.intra_scantable.permutated,
|
||||||
s->c.last_dc, s->c.block[i],
|
s->c.last_dc, s->block[i],
|
||||||
i, s->c.qscale);
|
i, s->c.qscale);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
av_log(s->c.avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n",
|
av_log(s->c.avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n",
|
||||||
@ -714,13 +716,13 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
|
|||||||
s->c.mb_intra = 0;
|
s->c.mb_intra = 0;
|
||||||
s->c.last_dc[0] = s->c.last_dc[1] = s->c.last_dc[2] = 128 << s->c.intra_dc_precision;
|
s->c.last_dc[0] = s->c.last_dc[1] = s->c.last_dc[2] = 128 << s->c.intra_dc_precision;
|
||||||
if (HAS_CBP(mb_type)) {
|
if (HAS_CBP(mb_type)) {
|
||||||
s->c.bdsp.clear_blocks(s->c.block[0]);
|
s->c.bdsp.clear_blocks(s->block[0]);
|
||||||
|
|
||||||
cbp = get_vlc2(&s->gb, ff_mb_pat_vlc, MB_PAT_VLC_BITS, 1);
|
cbp = get_vlc2(&s->gb, ff_mb_pat_vlc, MB_PAT_VLC_BITS, 1);
|
||||||
if (mb_block_count > 6) {
|
if (mb_block_count > 6) {
|
||||||
cbp *= 1 << mb_block_count - 6;
|
cbp *= 1 << mb_block_count - 6;
|
||||||
cbp |= get_bits(&s->gb, mb_block_count - 6);
|
cbp |= get_bits(&s->gb, mb_block_count - 6);
|
||||||
s->c.bdsp.clear_blocks(s->c.block[6]);
|
s->c.bdsp.clear_blocks(s->block[6]);
|
||||||
}
|
}
|
||||||
if (cbp <= 0) {
|
if (cbp <= 0) {
|
||||||
av_log(s->c.avctx, AV_LOG_ERROR,
|
av_log(s->c.avctx, AV_LOG_ERROR,
|
||||||
@ -733,7 +735,7 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
|
|||||||
|
|
||||||
for (i = 0; i < mb_block_count; i++) {
|
for (i = 0; i < mb_block_count; i++) {
|
||||||
if (cbp & (1 << 11)) {
|
if (cbp & (1 << 11)) {
|
||||||
if ((ret = mpeg2_decode_block_non_intra(s, s->c.block[i], i)) < 0)
|
if ((ret = mpeg2_decode_block_non_intra(s, s->block[i], i)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
s->c.block_last_index[i] = -1;
|
s->c.block_last_index[i] = -1;
|
||||||
@ -743,7 +745,7 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
|
|||||||
} else {
|
} else {
|
||||||
for (i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
if (cbp & 32) {
|
if (cbp & 32) {
|
||||||
if ((ret = mpeg1_decode_block_inter(s, s->c.block[i], i)) < 0)
|
if ((ret = mpeg1_decode_block_inter(s, s->block[i], i)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
s->c.block_last_index[i] = -1;
|
s->c.block_last_index[i] = -1;
|
||||||
@ -1498,7 +1500,7 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
|
|||||||
s->c.dest[1] +=(16 >> lowres) >> s->c.chroma_x_shift;
|
s->c.dest[1] +=(16 >> lowres) >> s->c.chroma_x_shift;
|
||||||
s->c.dest[2] +=(16 >> lowres) >> s->c.chroma_x_shift;
|
s->c.dest[2] +=(16 >> lowres) >> s->c.chroma_x_shift;
|
||||||
|
|
||||||
ff_mpv_reconstruct_mb(&s->c, s->c.block);
|
ff_mpv_reconstruct_mb(&s->c, s->block);
|
||||||
|
|
||||||
if (++s->c.mb_x >= s->c.mb_width) {
|
if (++s->c.mb_x >= s->c.mb_width) {
|
||||||
const int mb_size = 16 >> s->c.avctx->lowres;
|
const int mb_size = 16 >> s->c.avctx->lowres;
|
||||||
@ -2755,7 +2757,6 @@ typedef struct IPUContext {
|
|||||||
Mpeg12SliceContext m;
|
Mpeg12SliceContext m;
|
||||||
|
|
||||||
int flags;
|
int flags;
|
||||||
DECLARE_ALIGNED(32, int16_t, block)[6][64];
|
|
||||||
} IPUContext;
|
} IPUContext;
|
||||||
|
|
||||||
static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
|
static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
|
||||||
@ -2764,6 +2765,7 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
|
|||||||
IPUContext *s = avctx->priv_data;
|
IPUContext *s = avctx->priv_data;
|
||||||
MPVContext *const m = &s->m.c;
|
MPVContext *const m = &s->m.c;
|
||||||
GetBitContext *const gb = &s->m.gb;
|
GetBitContext *const gb = &s->m.gb;
|
||||||
|
int16_t (*const block)[64] = s->m.block;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
// Check for minimal intra MB size (considering mb header, luma & chroma dc VLC, ac EOB VLC)
|
// Check for minimal intra MB size (considering mb header, luma & chroma dc VLC, ac EOB VLC)
|
||||||
@ -2813,17 +2815,17 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
|
|||||||
if (intraquant)
|
if (intraquant)
|
||||||
m->qscale = mpeg_get_qscale(gb, m->q_scale_type);
|
m->qscale = mpeg_get_qscale(gb, m->q_scale_type);
|
||||||
|
|
||||||
memset(s->block, 0, sizeof(s->block));
|
memset(block, 0, 6 * sizeof(*block));
|
||||||
|
|
||||||
for (int n = 0; n < 6; n++) {
|
for (int n = 0; n < 6; n++) {
|
||||||
if (s->flags & 0x80) {
|
if (s->flags & 0x80) {
|
||||||
ret = ff_mpeg1_decode_block_intra(gb,
|
ret = ff_mpeg1_decode_block_intra(gb,
|
||||||
m->intra_matrix,
|
m->intra_matrix,
|
||||||
m->intra_scantable.permutated,
|
m->intra_scantable.permutated,
|
||||||
m->last_dc, s->block[n],
|
m->last_dc, block[n],
|
||||||
n, m->qscale);
|
n, m->qscale);
|
||||||
} else {
|
} else {
|
||||||
ret = mpeg2_decode_block_intra(&s->m, s->block[n], n);
|
ret = mpeg2_decode_block_intra(&s->m, block[n], n);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -2831,17 +2833,17 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
|
|||||||
}
|
}
|
||||||
|
|
||||||
m->idsp.idct_put(frame->data[0] + y * frame->linesize[0] + x,
|
m->idsp.idct_put(frame->data[0] + y * frame->linesize[0] + x,
|
||||||
frame->linesize[0], s->block[0]);
|
frame->linesize[0], block[0]);
|
||||||
m->idsp.idct_put(frame->data[0] + y * frame->linesize[0] + x + 8,
|
m->idsp.idct_put(frame->data[0] + y * frame->linesize[0] + x + 8,
|
||||||
frame->linesize[0], s->block[1]);
|
frame->linesize[0], block[1]);
|
||||||
m->idsp.idct_put(frame->data[0] + (y + 8) * frame->linesize[0] + x,
|
m->idsp.idct_put(frame->data[0] + (y + 8) * frame->linesize[0] + x,
|
||||||
frame->linesize[0], s->block[2]);
|
frame->linesize[0], block[2]);
|
||||||
m->idsp.idct_put(frame->data[0] + (y + 8) * frame->linesize[0] + x + 8,
|
m->idsp.idct_put(frame->data[0] + (y + 8) * frame->linesize[0] + x + 8,
|
||||||
frame->linesize[0], s->block[3]);
|
frame->linesize[0], block[3]);
|
||||||
m->idsp.idct_put(frame->data[1] + (y >> 1) * frame->linesize[1] + (x >> 1),
|
m->idsp.idct_put(frame->data[1] + (y >> 1) * frame->linesize[1] + (x >> 1),
|
||||||
frame->linesize[1], s->block[4]);
|
frame->linesize[1], block[4]);
|
||||||
m->idsp.idct_put(frame->data[2] + (y >> 1) * frame->linesize[2] + (x >> 1),
|
m->idsp.idct_put(frame->data[2] + (y >> 1) * frame->linesize[2] + (x >> 1),
|
||||||
frame->linesize[2], s->block[5]);
|
frame->linesize[2], block[5]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3830,7 +3830,6 @@ static av_cold void clear_context(MpegEncContext *s)
|
|||||||
|
|
||||||
memset(s->thread_context, 0, sizeof(s->thread_context));
|
memset(s->thread_context, 0, sizeof(s->thread_context));
|
||||||
|
|
||||||
s->block = NULL;
|
|
||||||
s->ac_val_base = NULL;
|
s->ac_val_base = NULL;
|
||||||
s->ac_val = NULL;
|
s->ac_val = NULL;
|
||||||
memset(&s->sc, 0, sizeof(s->sc));
|
memset(&s->sc, 0, sizeof(s->sc));
|
||||||
|
@ -115,31 +115,15 @@ av_cold void ff_mpv_idct_init(MpegEncContext *s)
|
|||||||
s->idsp.idct_permutation);
|
s->idsp.idct_permutation);
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold int init_duplicate_context(MpegEncContext *s)
|
|
||||||
{
|
|
||||||
if (!s->encoding) {
|
|
||||||
s->block = av_mallocz(12 * sizeof(*s->block));
|
|
||||||
if (!s->block)
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
av_cold int ff_mpv_init_duplicate_contexts(MpegEncContext *s)
|
av_cold int ff_mpv_init_duplicate_contexts(MpegEncContext *s)
|
||||||
{
|
{
|
||||||
int nb_slices = s->slice_context_count, ret;
|
const int nb_slices = s->slice_context_count;
|
||||||
const size_t slice_size = s->slice_ctx_size;
|
const size_t slice_size = s->slice_ctx_size;
|
||||||
|
|
||||||
/* We initialize the copies before the original so that
|
|
||||||
* fields allocated in init_duplicate_context are NULL after
|
|
||||||
* copying. This prevents double-frees upon allocation error. */
|
|
||||||
for (int i = 1; i < nb_slices; i++) {
|
for (int i = 1; i < nb_slices; i++) {
|
||||||
s->thread_context[i] = av_memdup(s, slice_size);
|
s->thread_context[i] = av_memdup(s, slice_size);
|
||||||
if (!s->thread_context[i])
|
if (!s->thread_context[i])
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
if ((ret = init_duplicate_context(s->thread_context[i])) < 0)
|
|
||||||
return ret;
|
|
||||||
s->thread_context[i]->start_mb_y =
|
s->thread_context[i]->start_mb_y =
|
||||||
(s->mb_height * (i ) + nb_slices / 2) / nb_slices;
|
(s->mb_height * (i ) + nb_slices / 2) / nb_slices;
|
||||||
s->thread_context[i]->end_mb_y =
|
s->thread_context[i]->end_mb_y =
|
||||||
@ -148,7 +132,7 @@ av_cold int ff_mpv_init_duplicate_contexts(MpegEncContext *s)
|
|||||||
s->start_mb_y = 0;
|
s->start_mb_y = 0;
|
||||||
s->end_mb_y = nb_slices > 1 ? (s->mb_height + nb_slices / 2) / nb_slices
|
s->end_mb_y = nb_slices > 1 ? (s->mb_height + nb_slices / 2) / nb_slices
|
||||||
: s->mb_height;
|
: s->mb_height;
|
||||||
return init_duplicate_context(s);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold void free_duplicate_context(MpegEncContext *s)
|
static av_cold void free_duplicate_context(MpegEncContext *s)
|
||||||
@ -160,8 +144,6 @@ static av_cold void free_duplicate_context(MpegEncContext *s)
|
|||||||
av_freep(&s->sc.scratchpad_buf);
|
av_freep(&s->sc.scratchpad_buf);
|
||||||
s->sc.obmc_scratchpad = NULL;
|
s->sc.obmc_scratchpad = NULL;
|
||||||
s->sc.linesize = 0;
|
s->sc.linesize = 0;
|
||||||
|
|
||||||
av_freep(&s->block);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold void free_duplicate_contexts(MpegEncContext *s)
|
static av_cold void free_duplicate_contexts(MpegEncContext *s)
|
||||||
@ -177,7 +159,6 @@ int ff_update_duplicate_context(MpegEncContext *dst, const MpegEncContext *src)
|
|||||||
{
|
{
|
||||||
#define COPY(M) \
|
#define COPY(M) \
|
||||||
M(ScratchpadContext, sc) \
|
M(ScratchpadContext, sc) \
|
||||||
M(void*, block) \
|
|
||||||
M(int, start_mb_y) \
|
M(int, start_mb_y) \
|
||||||
M(int, end_mb_y) \
|
M(int, end_mb_y) \
|
||||||
M(int16_t*, dc_val) \
|
M(int16_t*, dc_val) \
|
||||||
|
@ -302,8 +302,6 @@ typedef struct MpegEncContext {
|
|||||||
int interlaced_dct;
|
int interlaced_dct;
|
||||||
int first_field; ///< is 1 for the first field of a field picture 0 otherwise
|
int first_field; ///< is 1 for the first field of a field picture 0 otherwise
|
||||||
|
|
||||||
int16_t (*block)[64];
|
|
||||||
|
|
||||||
#define SLICE_OK 0
|
#define SLICE_OK 0
|
||||||
#define SLICE_ERROR -1
|
#define SLICE_ERROR -1
|
||||||
#define SLICE_END -2 ///<end marker found
|
#define SLICE_END -2 ///<end marker found
|
||||||
|
Reference in New Issue
Block a user