Skip to content

Commit

Permalink
vaapi: add vaapi_cavs support
Browse files Browse the repository at this point in the history
see intel/libva#738

[Moore Threads](https://www.mthreads.com) (short for Mthreads) is a
Chinese GPU manufacturer. All our products, like MTTS70/MTTS80/.. ,
support AVS/AVS+ HW decoding at max 2k resolution.

Signed-off-by: jianfeng.zheng <[email protected]>
  • Loading branch information
jianfeng.zheng committed Jan 21, 2024
1 parent 6c4388b commit b6833e3
Show file tree
Hide file tree
Showing 12 changed files with 669 additions and 62 deletions.
14 changes: 14 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -2463,6 +2463,7 @@ HAVE_LIST="
xmllint
zlib_gzip
openvino2
va_profile_avs
"

# options emitted with CONFIG_ prefix but not available on the command line
Expand Down Expand Up @@ -3202,6 +3203,7 @@ wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
wmv3_nvdec_hwaccel_select="vc1_nvdec_hwaccel"
wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
wmv3_vdpau_hwaccel_select="vc1_vdpau_hwaccel"
cavs_vaapi_hwaccel_deps="vaapi va_profile_avs VAPictureParameterBufferAVS"

# hardware-accelerated codecs
mediafoundation_deps="mftransform_h MFCreateAlignedMemoryBuffer"
Expand Down Expand Up @@ -7175,6 +7177,18 @@ if enabled vaapi; then
check_type "va/va.h va/va_enc_vp8.h" "VAEncPictureParameterBufferVP8"
check_type "va/va.h va/va_enc_vp9.h" "VAEncPictureParameterBufferVP9"
check_type "va/va.h va/va_enc_av1.h" "VAEncPictureParameterBufferAV1"

#
# Using 'VA_CHECK_VERSION' in source codes make things easy. But we have to wait
# until newly added VAProfile being distributed by VAAPI released version.
#
# Before or after that, we can use auto-detection to keep version compatibility.
# It always works.
#
disable va_profile_avs &&
test_code cc va/va.h "VAProfile p1 = VAProfileAVSJizhun, p2 = VAProfileAVSGuangdian;" &&
enable va_profile_avs
enabled va_profile_avs && check_type "va/va.h va/va_dec_avs.h" "VAPictureParameterBufferAVS"
fi

if enabled_all opencl libdrm ; then
Expand Down
1 change: 1 addition & 0 deletions libavcodec/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,7 @@ OBJS-$(CONFIG_VP9_VAAPI_HWACCEL) += vaapi_vp9.o
OBJS-$(CONFIG_VP9_VDPAU_HWACCEL) += vdpau_vp9.o
OBJS-$(CONFIG_VP9_VIDEOTOOLBOX_HWACCEL) += videotoolbox_vp9.o
OBJS-$(CONFIG_VP8_QSV_HWACCEL) += qsvdec.o
OBJS-$(CONFIG_CAVS_VAAPI_HWACCEL) += vaapi_cavs.o

# Objects duplicated from other libraries for shared builds
SHLIBOBJS += log2_tab.o reverse.o
Expand Down
12 changes: 12 additions & 0 deletions libavcodec/cavs.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,14 @@ av_cold int ff_cavs_init(AVCodecContext *avctx)
if (!h->cur.f || !h->DPB[0].f || !h->DPB[1].f)
return AVERROR(ENOMEM);

h->out[0].f = av_frame_alloc();
h->out[1].f = av_frame_alloc();
h->out[2].f = av_frame_alloc();
if (!h->out[0].f || !h->out[1].f || !h->out[2].f) {
ff_cavs_end(avctx);
return AVERROR(ENOMEM);
}

h->luma_scan[0] = 0;
h->luma_scan[1] = 8;
h->intra_pred_l[INTRA_L_VERT] = intra_pred_vert;
Expand Down Expand Up @@ -840,6 +848,10 @@ av_cold int ff_cavs_end(AVCodecContext *avctx)
av_frame_free(&h->DPB[0].f);
av_frame_free(&h->DPB[1].f);

av_frame_free(&h->out[0].f);
av_frame_free(&h->out[1].f);
av_frame_free(&h->out[2].f);

av_freep(&h->top_qp);
av_freep(&h->top_mv[0]);
av_freep(&h->top_mv[1]);
Expand Down
36 changes: 35 additions & 1 deletion libavcodec/cavs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
#define EXT_START_CODE 0x000001b5
#define USER_START_CODE 0x000001b2
#define CAVS_START_CODE 0x000001b0
#define VIDEO_SEQ_END_CODE 0x000001b1
#define PIC_I_START_CODE 0x000001b3
#define PIC_PB_START_CODE 0x000001b6
#define VIDEO_EDIT_CODE 0x000001b7

#define A_AVAIL 1
#define B_AVAIL 2
Expand Down Expand Up @@ -164,30 +166,62 @@ struct dec_2dvlc {
typedef struct AVSFrame {
AVFrame *f;
int poc;
int outputed;

AVBufferRef *hwaccel_priv_buf;
void *hwaccel_picture_private;
} AVSFrame;

typedef struct AVSContext {
AVCodecContext *avctx;
int got_pix_fmt;
BlockDSPContext bdsp;
H264ChromaContext h264chroma;
VideoDSPContext vdsp;
CAVSDSPContext cdsp;
GetBitContext gb;
AVSFrame cur; ///< currently decoded frame
AVSFrame DPB[2]; ///< reference frames
AVSFrame out[3]; ///< output queue, size 2 maybe enough
int dist[2]; ///< temporal distances from current frame to ref frames
int low_delay;
int profile, level;
int aspect_ratio;
int mb_width, mb_height;
int width, height;
int stream_revision; ///<0 for samples from 2006, 1 for rm52j encoder
int progressive;
int progressive_seq;
int progressive_frame;
int pic_structure;
int no_forward_ref_flag;
int pb_field_enhanced_flag; ///< only used in GUANGDIAN
int skip_mode_flag; ///< select between skip_count or one skip_flag per MB
int loop_filter_disable;
int alpha_offset, beta_offset;
int ref_flag;

/** \defgroup guangdian profile
* @{
*/
int aec_flag;
int weight_quant_flag;
int chroma_quant_param_delta_cb;
int chroma_quant_param_delta_cr;
uint8_t wqm_8x8[64];
/**@}*/

/** \defgroup slice weighting
* FFmpeg don't support slice weighting natively, but maybe needed for HWaccel.
* @{
*/
uint32_t slice_weight_pred_flag : 1;
uint32_t mb_weight_pred_flag : 1;
uint8_t luma_scale[4];
int8_t luma_shift[4];
uint8_t chroma_scale[4];
int8_t chroma_shift[4];
/**@}*/

int mbx, mby, mbidx; ///< macroblock coordinates
int flags; ///< availability flags of neighbouring macroblocks
int stc; ///< last start code
Expand Down
16 changes: 16 additions & 0 deletions libavcodec/cavs_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ static int cavs_find_frame_end(ParseContext *pc, const uint8_t *buf,
pc->state=-1;
return i-3;
}
if((state&0xFFFFFF00) == 0x100){
if(state != EXT_START_CODE && state != USER_START_CODE){
state = state >> 8;
break;
}
}
}
for(; i<buf_size; i++){
state= (state<<8) | buf[i];
if((state&0xFFFFFF00) == 0x100){
if(state > SLICE_MAX_START_CODE){
pc->frame_start_found=0;
pc->state=-1;
return i-3;
}
}
}
}
pc->frame_start_found= pic_found;
Expand Down
Loading

0 comments on commit b6833e3

Please sign in to comment.