mirror of
https://github.com/nyanmisaka/ffmpeg-rockchip.git
synced 2026-01-24 02:20:56 +01:00
lavc/rkmppdec: refactor RKMPP decoders and extend codecs
Signed-off-by: nyanmisaka <nst799610810@gmail.com>
This commit is contained in:
parent
78421570bf
commit
45400899c0
5 changed files with 969 additions and 504 deletions
9
configure
vendored
9
configure
vendored
|
|
@ -1954,6 +1954,7 @@ HWACCEL_LIBRARY_LIST="
|
|||
mmal
|
||||
omx
|
||||
opencl
|
||||
rkmpp
|
||||
"
|
||||
|
||||
DOCUMENT_LIST="
|
||||
|
|
@ -3215,8 +3216,10 @@ av1_mediacodec_decoder_deps="mediacodec"
|
|||
av1_mediacodec_encoder_deps="mediacodec"
|
||||
av1_nvenc_encoder_deps="nvenc NV_ENC_PIC_PARAMS_AV1"
|
||||
av1_nvenc_encoder_select="atsc_a53"
|
||||
av1_rkmpp_decoder_deps="rkmpp"
|
||||
h263_v4l2m2m_decoder_deps="v4l2_m2m h263_v4l2_m2m"
|
||||
h263_v4l2m2m_encoder_deps="v4l2_m2m h263_v4l2_m2m"
|
||||
h263_rkmpp_decoder_deps="rkmpp"
|
||||
h264_amf_encoder_deps="amf"
|
||||
h264_crystalhd_decoder_select="crystalhd h264_mp4toannexb_bsf h264_parser"
|
||||
h264_cuvid_decoder_deps="cuvid"
|
||||
|
|
@ -3266,6 +3269,7 @@ mjpeg_vaapi_encoder_select="cbs_jpeg jpegtables vaapi_encode"
|
|||
mp3_mf_encoder_deps="mediafoundation"
|
||||
mpeg1_cuvid_decoder_deps="cuvid"
|
||||
mpeg1_v4l2m2m_decoder_deps="v4l2_m2m mpeg1_v4l2_m2m"
|
||||
mpeg1_rkmpp_decoder_deps="rkmpp"
|
||||
mpeg2_crystalhd_decoder_select="crystalhd"
|
||||
mpeg2_cuvid_decoder_deps="cuvid"
|
||||
mpeg2_mmal_decoder_deps="mmal"
|
||||
|
|
@ -3274,6 +3278,7 @@ mpeg2_qsv_decoder_select="qsvdec"
|
|||
mpeg2_qsv_encoder_select="qsvenc"
|
||||
mpeg2_vaapi_encoder_select="cbs_mpeg2 vaapi_encode"
|
||||
mpeg2_v4l2m2m_decoder_deps="v4l2_m2m mpeg2_v4l2_m2m"
|
||||
mpeg2_rkmpp_decoder_deps="rkmpp"
|
||||
mpeg4_crystalhd_decoder_select="crystalhd"
|
||||
mpeg4_cuvid_decoder_deps="cuvid"
|
||||
mpeg4_mediacodec_decoder_deps="mediacodec"
|
||||
|
|
@ -3282,6 +3287,8 @@ mpeg4_mmal_decoder_deps="mmal"
|
|||
mpeg4_omx_encoder_deps="omx"
|
||||
mpeg4_v4l2m2m_decoder_deps="v4l2_m2m mpeg4_v4l2_m2m"
|
||||
mpeg4_v4l2m2m_encoder_deps="v4l2_m2m mpeg4_v4l2_m2m"
|
||||
mpeg4_rkmpp_decoder_deps="rkmpp"
|
||||
mpeg4_rkmpp_decoder_select="mpeg4_unpack_bframes_bsf"
|
||||
msmpeg4_crystalhd_decoder_select="crystalhd"
|
||||
vc1_crystalhd_decoder_select="crystalhd"
|
||||
vc1_cuvid_decoder_deps="cuvid"
|
||||
|
|
@ -3881,7 +3888,7 @@ cws2fws_extralibs="zlib_extralibs"
|
|||
|
||||
# libraries, in any order
|
||||
avcodec_deps="avutil"
|
||||
avcodec_suggest="libm stdatomic"
|
||||
avcodec_suggest="libm stdatomic rkrga"
|
||||
avdevice_deps="avformat avcodec avutil"
|
||||
avdevice_suggest="libm stdatomic"
|
||||
avfilter_deps="avutil"
|
||||
|
|
|
|||
|
|
@ -256,6 +256,7 @@ OBJS-$(CONFIG_AV1_MEDIACODEC_ENCODER) += mediacodecenc.o
|
|||
OBJS-$(CONFIG_AV1_NVENC_ENCODER) += nvenc_av1.o nvenc.o
|
||||
OBJS-$(CONFIG_AV1_QSV_ENCODER) += qsvenc_av1.o
|
||||
OBJS-$(CONFIG_AV1_VAAPI_ENCODER) += vaapi_encode_av1.o av1_levels.o
|
||||
OBJS-$(CONFIG_AV1_RKMPP_DECODER) += rkmppdec.o
|
||||
OBJS-$(CONFIG_AVRN_DECODER) += avrndec.o
|
||||
OBJS-$(CONFIG_AVRP_DECODER) += r210dec.o
|
||||
OBJS-$(CONFIG_AVRP_ENCODER) += r210enc.o
|
||||
|
|
@ -398,6 +399,7 @@ OBJS-$(CONFIG_H263_ENCODER) += mpeg4video.o \
|
|||
h263.o ituh263enc.o h263data.o
|
||||
OBJS-$(CONFIG_H263_V4L2M2M_DECODER) += v4l2_m2m_dec.o
|
||||
OBJS-$(CONFIG_H263_V4L2M2M_ENCODER) += v4l2_m2m_enc.o
|
||||
OBJS-$(CONFIG_H263_RKMPP_DECODER) += rkmppdec.o
|
||||
OBJS-$(CONFIG_H264_DECODER) += h264dec.o h264_cabac.o h264_cavlc.o \
|
||||
h264_direct.o h264_loopfilter.o \
|
||||
h264_mb.o h264_picture.o \
|
||||
|
|
@ -530,6 +532,7 @@ OBJS-$(CONFIG_MPEG1VIDEO_DECODER) += mpeg12dec.o mpeg12.o mpeg12data.o
|
|||
OBJS-$(CONFIG_MPEG1VIDEO_ENCODER) += mpeg12enc.o mpeg12.o
|
||||
OBJS-$(CONFIG_MPEG1_CUVID_DECODER) += cuviddec.o
|
||||
OBJS-$(CONFIG_MPEG1_V4L2M2M_DECODER) += v4l2_m2m_dec.o
|
||||
OBJS-$(CONFIG_MPEG1_RKMPP_DECODER) += rkmppdec.o
|
||||
OBJS-$(CONFIG_MPEG2_MMAL_DECODER) += mmaldec.o
|
||||
OBJS-$(CONFIG_MPEG2_QSV_DECODER) += qsvdec.o
|
||||
OBJS-$(CONFIG_MPEG2_QSV_ENCODER) += qsvenc_mpeg2.o
|
||||
|
|
@ -539,6 +542,7 @@ OBJS-$(CONFIG_MPEG2_CUVID_DECODER) += cuviddec.o
|
|||
OBJS-$(CONFIG_MPEG2_MEDIACODEC_DECODER) += mediacodecdec.o
|
||||
OBJS-$(CONFIG_MPEG2_VAAPI_ENCODER) += vaapi_encode_mpeg2.o
|
||||
OBJS-$(CONFIG_MPEG2_V4L2M2M_DECODER) += v4l2_m2m_dec.o
|
||||
OBJS-$(CONFIG_MPEG2_RKMPP_DECODER) += rkmppdec.o
|
||||
OBJS-$(CONFIG_MPEG4_DECODER) += mpeg4videodsp.o xvididct.o
|
||||
OBJS-$(CONFIG_MPEG4_ENCODER) += mpeg4videoenc.o
|
||||
OBJS-$(CONFIG_MPEG4_CUVID_DECODER) += cuviddec.o
|
||||
|
|
@ -547,6 +551,7 @@ OBJS-$(CONFIG_MPEG4_MEDIACODEC_ENCODER) += mediacodecenc.o
|
|||
OBJS-$(CONFIG_MPEG4_OMX_ENCODER) += omx.o
|
||||
OBJS-$(CONFIG_MPEG4_V4L2M2M_DECODER) += v4l2_m2m_dec.o
|
||||
OBJS-$(CONFIG_MPEG4_V4L2M2M_ENCODER) += v4l2_m2m_enc.o
|
||||
OBJS-$(CONFIG_MPEG4_RKMPP_DECODER) += rkmppdec.o
|
||||
OBJS-$(CONFIG_MPL2_DECODER) += mpl2dec.o ass.o
|
||||
OBJS-$(CONFIG_MSA1_DECODER) += mss3.o
|
||||
OBJS-$(CONFIG_MSCC_DECODER) += mscc.o
|
||||
|
|
|
|||
|
|
@ -150,6 +150,7 @@ extern const FFCodec ff_h263i_decoder;
|
|||
extern const FFCodec ff_h263p_encoder;
|
||||
extern const FFCodec ff_h263p_decoder;
|
||||
extern const FFCodec ff_h263_v4l2m2m_decoder;
|
||||
extern const FFCodec ff_h263_rkmpp_decoder;
|
||||
extern const FFCodec ff_h264_decoder;
|
||||
extern const FFCodec ff_h264_crystalhd_decoder;
|
||||
extern const FFCodec ff_h264_v4l2m2m_decoder;
|
||||
|
|
@ -212,13 +213,16 @@ extern const FFCodec ff_mpeg4_decoder;
|
|||
extern const FFCodec ff_mpeg4_crystalhd_decoder;
|
||||
extern const FFCodec ff_mpeg4_v4l2m2m_decoder;
|
||||
extern const FFCodec ff_mpeg4_mmal_decoder;
|
||||
extern const FFCodec ff_mpeg4_rkmpp_decoder;
|
||||
extern const FFCodec ff_mpegvideo_decoder;
|
||||
extern const FFCodec ff_mpeg1_v4l2m2m_decoder;
|
||||
extern const FFCodec ff_mpeg1_rkmpp_decoder;
|
||||
extern const FFCodec ff_mpeg2_mmal_decoder;
|
||||
extern const FFCodec ff_mpeg2_crystalhd_decoder;
|
||||
extern const FFCodec ff_mpeg2_v4l2m2m_decoder;
|
||||
extern const FFCodec ff_mpeg2_qsv_decoder;
|
||||
extern const FFCodec ff_mpeg2_mediacodec_decoder;
|
||||
extern const FFCodec ff_mpeg2_rkmpp_decoder;
|
||||
extern const FFCodec ff_msa1_decoder;
|
||||
extern const FFCodec ff_mscc_decoder;
|
||||
extern const FFCodec ff_msmpeg4v1_decoder;
|
||||
|
|
@ -846,6 +850,7 @@ extern const FFCodec ff_av1_qsv_decoder;
|
|||
extern const FFCodec ff_av1_qsv_encoder;
|
||||
extern const FFCodec ff_av1_amf_encoder;
|
||||
extern const FFCodec ff_av1_vaapi_encoder;
|
||||
extern const FFCodec ff_av1_rkmpp_decoder;
|
||||
extern const FFCodec ff_libopenh264_encoder;
|
||||
extern const FFCodec ff_libopenh264_decoder;
|
||||
extern const FFCodec ff_h264_amf_encoder;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
153
libavcodec/rkmppdec.h
Normal file
153
libavcodec/rkmppdec.h
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Lionel CHAZALLON
|
||||
* Copyright (c) 2023 Huseyin BIYIK
|
||||
* Copyright (c) 2023 NyanMisaka
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Rockchip MPP (Media Process Platform) video decoder
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_RKMPPDEC_H
|
||||
#define AVCODEC_RKMPPDEC_H
|
||||
|
||||
#include <rockchip/rk_mpi.h>
|
||||
|
||||
#include "codec_internal.h"
|
||||
#include "decode.h"
|
||||
#include "hwconfig.h"
|
||||
#include "internal.h"
|
||||
|
||||
#include "libavutil/hwcontext_rkmpp.h"
|
||||
#include "libavutil/mastering_display_metadata.h"
|
||||
#include "libavutil/opt.h"
|
||||
#include "libavutil/pixdesc.h"
|
||||
|
||||
#define MAX_ERRINFO_COUNT 1000
|
||||
|
||||
typedef struct RKMPPDecContext {
|
||||
AVClass *class;
|
||||
|
||||
MppApi *mapi;
|
||||
MppCtx mctx;
|
||||
MppBufferGroup buf_group;
|
||||
|
||||
AVBufferRef *hwdevice;
|
||||
AVBufferRef *hwframe;
|
||||
|
||||
AVPacket last_pkt;
|
||||
AVFrame last_frame;
|
||||
|
||||
int eof;
|
||||
int info_change;
|
||||
int errinfo_cnt;
|
||||
|
||||
int deint;
|
||||
int afbc;
|
||||
int fast_parse;
|
||||
int buf_mode;
|
||||
} RKMPPDecContext;
|
||||
|
||||
enum {
|
||||
RKMPP_DEC_AFBC_OFF = 0,
|
||||
RKMPP_DEC_AFBC_ON = 1,
|
||||
RKMPP_DEC_AFBC_ON_RGA = 2,
|
||||
};
|
||||
|
||||
enum {
|
||||
RKMPP_DEC_HALF_INTERNAL = 0,
|
||||
RKMPP_DEC_PURE_EXTERNAL = 1,
|
||||
};
|
||||
|
||||
static const AVRational mpp_tb = { 1, 1000000 };
|
||||
|
||||
#define PTS_TO_MPP_PTS(pts, pts_tb) ((pts_tb.num && pts_tb.den) ? \
|
||||
av_rescale_q(pts, pts_tb, mpp_tb) : pts)
|
||||
|
||||
#define MPP_PTS_TO_PTS(mpp_pts, pts_tb) ((pts_tb.num && pts_tb.den) ? \
|
||||
av_rescale_q(mpp_pts, mpp_tb, pts_tb) : mpp_pts)
|
||||
|
||||
#define OFFSET(x) offsetof(RKMPPDecContext, x)
|
||||
#define VD (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
|
||||
|
||||
static const AVOption options[] = {
|
||||
{ "deint", "Enable IEP (Image Enhancement Processor) for de-interlacing", OFFSET(deint), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VD },
|
||||
{ "afbc", "Enable AFBC (Arm Frame Buffer Compression) to save bandwidth", OFFSET(afbc), AV_OPT_TYPE_INT, { .i64 = RKMPP_DEC_AFBC_OFF }, 0, 2, VD, "afbc" },
|
||||
{ "off", "Disable AFBC support", 0, AV_OPT_TYPE_CONST, { .i64 = RKMPP_DEC_AFBC_OFF }, 0, 0, VD, "afbc" },
|
||||
{ "on", "Enable AFBC support", 0, AV_OPT_TYPE_CONST, { .i64 = RKMPP_DEC_AFBC_ON }, 0, 0, VD, "afbc" },
|
||||
{ "rga", "Enable AFBC if capable RGA is available", 0, AV_OPT_TYPE_CONST, { .i64 = RKMPP_DEC_AFBC_ON_RGA }, 0, 0, VD, "afbc" },
|
||||
{ "fast_parse", "Enable fast parsing to improve decoding parallelism", OFFSET(fast_parse), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VD },
|
||||
{ "buf_mode", "Set the buffer mode for MPP decoder", OFFSET(buf_mode), AV_OPT_TYPE_INT, { .i64 = RKMPP_DEC_HALF_INTERNAL }, 0, 1, VD, "buf_mode" },
|
||||
{ "half", "Half internal mode", 0, AV_OPT_TYPE_CONST, { .i64 = RKMPP_DEC_HALF_INTERNAL }, 0, 0, VD, "buf_mode" },
|
||||
{ "ext", "Pure external mode", 0, AV_OPT_TYPE_CONST, { .i64 = RKMPP_DEC_PURE_EXTERNAL }, 0, 0, VD, "buf_mode" },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static const enum AVPixelFormat rkmpp_dec_pix_fmts[] = {
|
||||
AV_PIX_FMT_NV12,
|
||||
AV_PIX_FMT_NV16,
|
||||
AV_PIX_FMT_NV15,
|
||||
AV_PIX_FMT_NV20,
|
||||
AV_PIX_FMT_DRM_PRIME,
|
||||
AV_PIX_FMT_NONE,
|
||||
};
|
||||
|
||||
static const AVCodecHWConfigInternal *const rkmpp_dec_hw_configs[] = {
|
||||
&(const AVCodecHWConfigInternal) {
|
||||
.public = {
|
||||
.pix_fmt = AV_PIX_FMT_DRM_PRIME,
|
||||
.methods = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX |
|
||||
AV_CODEC_HW_CONFIG_METHOD_INTERNAL,
|
||||
.device_type = AV_HWDEVICE_TYPE_RKMPP,
|
||||
},
|
||||
.hwaccel = NULL,
|
||||
},
|
||||
NULL
|
||||
};
|
||||
|
||||
#define DEFINE_RKMPP_DECODER(x, X, bsf_name) \
|
||||
static const AVClass x##_rkmpp_decoder_class = { \
|
||||
.class_name = #x "_rkmpp_decoder", \
|
||||
.item_name = av_default_item_name, \
|
||||
.option = options, \
|
||||
.version = LIBAVUTIL_VERSION_INT, \
|
||||
}; \
|
||||
const FFCodec ff_##x##_rkmpp_decoder = { \
|
||||
.p.name = #x "_rkmpp", \
|
||||
CODEC_LONG_NAME("Rockchip MPP (Media Process Platform) " #X " decoder"), \
|
||||
.p.type = AVMEDIA_TYPE_VIDEO, \
|
||||
.p.id = AV_CODEC_ID_##X, \
|
||||
.priv_data_size = sizeof(RKMPPDecContext), \
|
||||
.p.priv_class = &x##_rkmpp_decoder_class, \
|
||||
.init = rkmpp_decode_init, \
|
||||
.close = rkmpp_decode_close, \
|
||||
FF_CODEC_RECEIVE_FRAME_CB(rkmpp_decode_receive_frame), \
|
||||
.flush = rkmpp_decode_flush, \
|
||||
.bsfs = bsf_name, \
|
||||
.p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | \
|
||||
AV_CODEC_CAP_HARDWARE, \
|
||||
.caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE | \
|
||||
FF_CODEC_CAP_SETS_FRAME_PROPS, \
|
||||
.p.pix_fmts = rkmpp_dec_pix_fmts, \
|
||||
.hw_configs = rkmpp_dec_hw_configs, \
|
||||
.p.wrapper_name = "rkmpp", \
|
||||
};
|
||||
|
||||
#endif /* AVCODEC_RKMPPDEC_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue