avcodec/mpegvideo_dec: Add close function for mpegvideo-decoders

Currently identical to the H.261 and H.263 close functions
(which it replaces). It will be extended in future commits.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2024-04-28 17:40:58 +02:00
parent b90b676409
commit 99d26939af
16 changed files with 43 additions and 53 deletions

View File

@ -24,7 +24,7 @@
#include "flvdec.h"
#include "h263dec.h"
#include "mpegvideo.h"
#include "mpegvideodata.h"
#include "mpegvideodec.h"
int ff_flv_decode_picture_header(MpegEncContext *s)
{
@ -118,8 +118,8 @@ const FFCodec ff_flv_decoder = {
.p.id = AV_CODEC_ID_FLV1,
.priv_data_size = sizeof(MpegEncContext),
.init = ff_h263_decode_init,
.close = ff_h263_decode_end,
FF_CODEC_DECODE_CB(ff_h263_decode_frame),
.close = ff_mpv_decode_close,
.p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
.p.max_lowres = 3,

View File

@ -660,15 +660,6 @@ static int h261_decode_frame(AVCodecContext *avctx, AVFrame *pict,
return get_consumed_bytes(s, buf_size);
}
static av_cold int h261_decode_end(AVCodecContext *avctx)
{
H261DecContext *const h = avctx->priv_data;
MpegEncContext *s = &h->s;
ff_mpv_common_end(s);
return 0;
}
const FFCodec ff_h261_decoder = {
.p.name = "h261",
CODEC_LONG_NAME("H.261"),
@ -676,8 +667,8 @@ const FFCodec ff_h261_decoder = {
.p.id = AV_CODEC_ID_H261,
.priv_data_size = sizeof(H261DecContext),
.init = h261_decode_init,
.close = h261_decode_end,
FF_CODEC_DECODE_CB(h261_decode_frame),
.close = ff_mpv_decode_close,
.p.capabilities = AV_CODEC_CAP_DR1,
.p.max_lowres = 3,
};

View File

@ -159,14 +159,6 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
return 0;
}
av_cold int ff_h263_decode_end(AVCodecContext *avctx)
{
MpegEncContext *s = avctx->priv_data;
ff_mpv_common_end(s);
return 0;
}
/**
* Return the number of bytes consumed for building the current frame.
*/
@ -702,8 +694,8 @@ const FFCodec ff_h263_decoder = {
.p.id = AV_CODEC_ID_H263,
.priv_data_size = sizeof(MpegEncContext),
.init = ff_h263_decode_init,
.close = ff_h263_decode_end,
FF_CODEC_DECODE_CB(ff_h263_decode_frame),
.close = ff_mpv_decode_close,
.p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
AV_CODEC_CAP_DELAY,
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
@ -719,8 +711,8 @@ const FFCodec ff_h263p_decoder = {
.p.id = AV_CODEC_ID_H263P,
.priv_data_size = sizeof(MpegEncContext),
.init = ff_h263_decode_init,
.close = ff_h263_decode_end,
FF_CODEC_DECODE_CB(ff_h263_decode_frame),
.close = ff_mpv_decode_close,
.p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
AV_CODEC_CAP_DELAY,
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,

View File

@ -47,7 +47,6 @@ int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code);
int ff_h263_decode_init(AVCodecContext *avctx);
int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *frame,
int *got_frame, AVPacket *avpkt);
int ff_h263_decode_end(AVCodecContext *avctx);
void ff_h263_decode_init_vlc(void);
int ff_h263_decode_picture_header(MpegEncContext *s);
int ff_h263_decode_gob_header(MpegEncContext *s);

View File

@ -132,8 +132,8 @@ const FFCodec ff_h263i_decoder = {
.p.id = AV_CODEC_ID_H263I,
.priv_data_size = sizeof(MpegEncContext),
.init = ff_h263_decode_init,
.close = ff_h263_decode_end,
FF_CODEC_DECODE_CB(ff_h263_decode_frame),
.close = ff_mpv_decode_close,
.p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
};

View File

@ -2595,9 +2595,8 @@ static av_cold int mpeg_decode_end(AVCodecContext *avctx)
{
Mpeg1Context *s = avctx->priv_data;
ff_mpv_common_end(&s->mpeg_enc_ctx);
av_buffer_unref(&s->a53_buf_ref);
return 0;
return ff_mpv_decode_close(avctx);
}
const FFCodec ff_mpeg1video_decoder = {

View File

@ -3862,8 +3862,8 @@ const FFCodec ff_mpeg4_decoder = {
.p.id = AV_CODEC_ID_MPEG4,
.priv_data_size = sizeof(Mpeg4DecContext),
.init = decode_init,
.close = ff_h263_decode_end,
FF_CODEC_DECODE_CB(ff_h263_decode_frame),
.close = ff_mpv_decode_close,
.p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
AV_CODEC_CAP_DELAY | AV_CODEC_CAP_FRAME_THREADS,
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,

View File

@ -173,6 +173,14 @@ do {\
return 0;
}
int ff_mpv_decode_close(AVCodecContext *avctx)
{
MpegEncContext *s = avctx->priv_data;
ff_mpv_common_end(s);
return 0;
}
int ff_mpv_common_frame_size_change(MpegEncContext *s)
{
int err = 0;

View File

@ -63,6 +63,7 @@ int ff_mpv_export_qp_table(const MpegEncContext *s, AVFrame *f,
int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src);
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h);
void ff_mpeg_flush(AVCodecContext *avctx);
int ff_mpv_decode_close(AVCodecContext *avctx);
void ff_print_debug_info(const MpegEncContext *s, const MPVPicture *p, AVFrame *pict);

View File

@ -28,6 +28,7 @@
#include "codec_internal.h"
#include "mpegutils.h"
#include "mpegvideo.h"
#include "mpegvideodec.h"
#include "msmpeg4.h"
#include "msmpeg4dec.h"
#include "libavutil/imgutils.h"
@ -848,8 +849,8 @@ const FFCodec ff_msmpeg4v1_decoder = {
.p.id = AV_CODEC_ID_MSMPEG4V1,
.priv_data_size = sizeof(MpegEncContext),
.init = ff_msmpeg4_decode_init,
.close = ff_h263_decode_end,
FF_CODEC_DECODE_CB(ff_h263_decode_frame),
.close = ff_mpv_decode_close,
.p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
.p.max_lowres = 3,
@ -862,8 +863,8 @@ const FFCodec ff_msmpeg4v2_decoder = {
.p.id = AV_CODEC_ID_MSMPEG4V2,
.priv_data_size = sizeof(MpegEncContext),
.init = ff_msmpeg4_decode_init,
.close = ff_h263_decode_end,
FF_CODEC_DECODE_CB(ff_h263_decode_frame),
.close = ff_mpv_decode_close,
.p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
.p.max_lowres = 3,
@ -876,8 +877,8 @@ const FFCodec ff_msmpeg4v3_decoder = {
.p.id = AV_CODEC_ID_MSMPEG4V3,
.priv_data_size = sizeof(MpegEncContext),
.init = ff_msmpeg4_decode_init,
.close = ff_h263_decode_end,
FF_CODEC_DECODE_CB(ff_h263_decode_frame),
.close = ff_mpv_decode_close,
.p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
.p.max_lowres = 3,
@ -890,8 +891,8 @@ const FFCodec ff_wmv1_decoder = {
.p.id = AV_CODEC_ID_WMV1,
.priv_data_size = sizeof(MpegEncContext),
.init = ff_msmpeg4_decode_init,
.close = ff_h263_decode_end,
FF_CODEC_DECODE_CB(ff_h263_decode_frame),
.close = ff_mpv_decode_close,
.p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
.p.max_lowres = 3,

View File

@ -416,14 +416,6 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
return 0;
}
static av_cold int rv10_decode_end(AVCodecContext *avctx)
{
MpegEncContext *s = avctx->priv_data;
ff_mpv_common_end(s);
return 0;
}
static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf,
int buf_size, int buf_size2, int whole_size)
{
@ -666,8 +658,8 @@ const FFCodec ff_rv10_decoder = {
.p.id = AV_CODEC_ID_RV10,
.priv_data_size = sizeof(RVDecContext),
.init = rv10_decode_init,
.close = rv10_decode_end,
FF_CODEC_DECODE_CB(rv10_decode_frame),
.close = ff_mpv_decode_close,
.p.capabilities = AV_CODEC_CAP_DR1,
.p.max_lowres = 3,
};
@ -679,8 +671,8 @@ const FFCodec ff_rv20_decoder = {
.p.id = AV_CODEC_ID_RV20,
.priv_data_size = sizeof(RVDecContext),
.init = rv10_decode_init,
.close = rv10_decode_end,
FF_CODEC_DECODE_CB(rv10_decode_frame),
.close = ff_mpv_decode_close,
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
.flush = ff_mpeg_flush,
.p.max_lowres = 3,

View File

@ -302,6 +302,7 @@ const FFCodec ff_rv30_decoder = {
FF_CODEC_DECODE_CB(ff_rv34_decode_frame),
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
AV_CODEC_CAP_FRAME_THREADS,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
.flush = ff_mpeg_flush,
UPDATE_THREAD_CONTEXT(ff_rv34_decode_update_thread_context),
};

View File

@ -1522,10 +1522,9 @@ av_cold int ff_rv34_decode_init(AVCodecContext *avctx)
ff_h264_pred_init(&r->h, AV_CODEC_ID_RV40, 8, 1);
if ((ret = rv34_decoder_alloc(r)) < 0) {
ff_mpv_common_end(&r->s);
ret = rv34_decoder_alloc(r);
if (ret < 0)
return ret;
}
ff_thread_once(&init_static_once, rv34_init_tables);
@ -1823,8 +1822,7 @@ av_cold int ff_rv34_decode_end(AVCodecContext *avctx)
{
RV34DecContext *r = avctx->priv_data;
ff_mpv_common_end(&r->s);
rv34_decoder_free(r);
return 0;
return ff_mpv_decode_close(avctx);
}

View File

@ -580,6 +580,7 @@ const FFCodec ff_rv40_decoder = {
FF_CODEC_DECODE_CB(ff_rv34_decode_frame),
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
AV_CODEC_CAP_FRAME_THREADS,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
.flush = ff_mpeg_flush,
UPDATE_THREAD_CONTEXT(ff_rv34_decode_update_thread_context),
};

View File

@ -449,6 +449,8 @@ static enum AVPixelFormat vc1_get_format(AVCodecContext *avctx)
return ff_get_format(avctx, vc1_hwaccel_pixfmt_list_420);
}
static void vc1_decode_reset(AVCodecContext *avctx);
av_cold int ff_vc1_decode_init(AVCodecContext *avctx)
{
VC1Context *const v = avctx->priv_data;
@ -477,7 +479,7 @@ av_cold int ff_vc1_decode_init(AVCodecContext *avctx)
ret = vc1_decode_init_alloc_tables(v);
if (ret < 0) {
ff_vc1_decode_end(avctx);
vc1_decode_reset(avctx);
return ret;
}
return 0;
@ -774,10 +776,7 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx)
return 0;
}
/** Close a VC1/WMV3 decoder
* @warning Initial try at using MpegEncContext stuff
*/
av_cold int ff_vc1_decode_end(AVCodecContext *avctx)
static av_cold void vc1_decode_reset(AVCodecContext *avctx)
{
VC1Context *v = avctx->priv_data;
int i;
@ -803,9 +802,16 @@ av_cold int ff_vc1_decode_end(AVCodecContext *avctx)
av_freep(&v->is_intra_base); // FIXME use v->mb_type[]
av_freep(&v->luma_mv_base);
ff_intrax8_common_end(&v->x8);
return 0;
}
/**
* Close a MSS2/VC1/WMV3 decoder
*/
av_cold int ff_vc1_decode_end(AVCodecContext *avctx)
{
vc1_decode_reset(avctx);
return ff_mpv_decode_close(avctx);
}
/** Decode a VC1/WMV3 frame
* @todo TODO: Handle VC-1 IDUs (Transport level?)

View File

@ -27,6 +27,7 @@
#include "mathops.h"
#include "mpegutils.h"
#include "mpegvideo.h"
#include "mpegvideodec.h"
#include "msmpeg4.h"
#include "msmpeg4_vc1_data.h"
#include "msmpeg4dec.h"
@ -584,7 +585,7 @@ static av_cold int wmv2_decode_end(AVCodecContext *avctx)
WMV2DecContext *const w = avctx->priv_data;
ff_intrax8_common_end(&w->x8);
return ff_h263_decode_end(avctx);
return ff_mpv_decode_close(avctx);
}
const FFCodec ff_wmv2_decoder = {