Skip to content

Commit 7786263

Browse files
author
jianfeng.zheng
committed
vaapi: add vaapi_cavs support
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]>
1 parent 8e23ebe commit 7786263

File tree

12 files changed

+669
-62
lines changed

12 files changed

+669
-62
lines changed

configure

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,6 +2463,7 @@ HAVE_LIST="
24632463
xmllint
24642464
zlib_gzip
24652465
openvino2
2466+
va_profile_avs
24662467
"
24672468

24682469
# options emitted with CONFIG_ prefix but not available on the command line
@@ -3202,6 +3203,7 @@ wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
32023203
wmv3_nvdec_hwaccel_select="vc1_nvdec_hwaccel"
32033204
wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
32043205
wmv3_vdpau_hwaccel_select="vc1_vdpau_hwaccel"
3206+
cavs_vaapi_hwaccel_deps="vaapi va_profile_avs VAPictureParameterBufferAVS"
32053207

32063208
# hardware-accelerated codecs
32073209
mediafoundation_deps="mftransform_h MFCreateAlignedMemoryBuffer"
@@ -7175,6 +7177,18 @@ if enabled vaapi; then
71757177
check_type "va/va.h va/va_enc_vp8.h" "VAEncPictureParameterBufferVP8"
71767178
check_type "va/va.h va/va_enc_vp9.h" "VAEncPictureParameterBufferVP9"
71777179
check_type "va/va.h va/va_enc_av1.h" "VAEncPictureParameterBufferAV1"
7180+
7181+
#
7182+
# Using 'VA_CHECK_VERSION' in source codes make things easy. But we have to wait
7183+
# until newly added VAProfile being distributed by VAAPI released version.
7184+
#
7185+
# Before or after that, we can use auto-detection to keep version compatibility.
7186+
# It always works.
7187+
#
7188+
disable va_profile_avs &&
7189+
test_code cc va/va.h "VAProfile p1 = VAProfileAVSJizhun, p2 = VAProfileAVSGuangdian;" &&
7190+
enable va_profile_avs
7191+
enabled va_profile_avs && check_type "va/va.h va/va_dec_avs.h" "VAPictureParameterBufferAVS"
71787192
fi
71797193

71807194
if enabled_all opencl libdrm ; then

libavcodec/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,7 @@ OBJS-$(CONFIG_VP9_VAAPI_HWACCEL) += vaapi_vp9.o
10551055
OBJS-$(CONFIG_VP9_VDPAU_HWACCEL) += vdpau_vp9.o
10561056
OBJS-$(CONFIG_VP9_VIDEOTOOLBOX_HWACCEL) += videotoolbox_vp9.o
10571057
OBJS-$(CONFIG_VP8_QSV_HWACCEL) += qsvdec.o
1058+
OBJS-$(CONFIG_CAVS_VAAPI_HWACCEL) += vaapi_cavs.o
10581059

10591060
# Objects duplicated from other libraries for shared builds
10601061
SHLIBOBJS += log2_tab.o reverse.o

libavcodec/cavs.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,14 @@ av_cold int ff_cavs_init(AVCodecContext *avctx)
810810
if (!h->cur.f || !h->DPB[0].f || !h->DPB[1].f)
811811
return AVERROR(ENOMEM);
812812

813+
h->out[0].f = av_frame_alloc();
814+
h->out[1].f = av_frame_alloc();
815+
h->out[2].f = av_frame_alloc();
816+
if (!h->out[0].f || !h->out[1].f || !h->out[2].f) {
817+
ff_cavs_end(avctx);
818+
return AVERROR(ENOMEM);
819+
}
820+
813821
h->luma_scan[0] = 0;
814822
h->luma_scan[1] = 8;
815823
h->intra_pred_l[INTRA_L_VERT] = intra_pred_vert;
@@ -840,6 +848,10 @@ av_cold int ff_cavs_end(AVCodecContext *avctx)
840848
av_frame_free(&h->DPB[0].f);
841849
av_frame_free(&h->DPB[1].f);
842850

851+
av_frame_free(&h->out[0].f);
852+
av_frame_free(&h->out[1].f);
853+
av_frame_free(&h->out[2].f);
854+
843855
av_freep(&h->top_qp);
844856
av_freep(&h->top_mv[0]);
845857
av_freep(&h->top_mv[1]);

libavcodec/cavs.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@
3939
#define EXT_START_CODE 0x000001b5
4040
#define USER_START_CODE 0x000001b2
4141
#define CAVS_START_CODE 0x000001b0
42+
#define VIDEO_SEQ_END_CODE 0x000001b1
4243
#define PIC_I_START_CODE 0x000001b3
4344
#define PIC_PB_START_CODE 0x000001b6
45+
#define VIDEO_EDIT_CODE 0x000001b7
4446

4547
#define A_AVAIL 1
4648
#define B_AVAIL 2
@@ -164,30 +166,62 @@ struct dec_2dvlc {
164166
typedef struct AVSFrame {
165167
AVFrame *f;
166168
int poc;
169+
int outputed;
170+
171+
AVBufferRef *hwaccel_priv_buf;
172+
void *hwaccel_picture_private;
167173
} AVSFrame;
168174

169175
typedef struct AVSContext {
170176
AVCodecContext *avctx;
177+
int got_pix_fmt;
171178
BlockDSPContext bdsp;
172179
H264ChromaContext h264chroma;
173180
VideoDSPContext vdsp;
174181
CAVSDSPContext cdsp;
175182
GetBitContext gb;
176183
AVSFrame cur; ///< currently decoded frame
177184
AVSFrame DPB[2]; ///< reference frames
185+
AVSFrame out[3]; ///< output queue, size 2 maybe enough
178186
int dist[2]; ///< temporal distances from current frame to ref frames
179187
int low_delay;
180188
int profile, level;
181189
int aspect_ratio;
182190
int mb_width, mb_height;
183191
int width, height;
184192
int stream_revision; ///<0 for samples from 2006, 1 for rm52j encoder
185-
int progressive;
193+
int progressive_seq;
194+
int progressive_frame;
186195
int pic_structure;
196+
int no_forward_ref_flag;
197+
int pb_field_enhanced_flag; ///< only used in GUANGDIAN
187198
int skip_mode_flag; ///< select between skip_count or one skip_flag per MB
188199
int loop_filter_disable;
189200
int alpha_offset, beta_offset;
190201
int ref_flag;
202+
203+
/** \defgroup guangdian profile
204+
* @{
205+
*/
206+
int aec_flag;
207+
int weight_quant_flag;
208+
int chroma_quant_param_delta_cb;
209+
int chroma_quant_param_delta_cr;
210+
uint8_t wqm_8x8[64];
211+
/**@}*/
212+
213+
/** \defgroup slice weighting
214+
* FFmpeg don't support slice weighting natively, but maybe needed for HWaccel.
215+
* @{
216+
*/
217+
uint32_t slice_weight_pred_flag : 1;
218+
uint32_t mb_weight_pred_flag : 1;
219+
uint8_t luma_scale[4];
220+
int8_t luma_shift[4];
221+
uint8_t chroma_scale[4];
222+
int8_t chroma_shift[4];
223+
/**@}*/
224+
191225
int mbx, mby, mbidx; ///< macroblock coordinates
192226
int flags; ///< availability flags of neighbouring macroblocks
193227
int stc; ///< last start code

libavcodec/cavs_parser.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ static int cavs_find_frame_end(ParseContext *pc, const uint8_t *buf,
6565
pc->state=-1;
6666
return i-3;
6767
}
68+
if((state&0xFFFFFF00) == 0x100){
69+
if(state != EXT_START_CODE && state != USER_START_CODE){
70+
state = state >> 8;
71+
break;
72+
}
73+
}
74+
}
75+
for(; i<buf_size; i++){
76+
state= (state<<8) | buf[i];
77+
if((state&0xFFFFFF00) == 0x100){
78+
if(state > SLICE_MAX_START_CODE){
79+
pc->frame_start_found=0;
80+
pc->state=-1;
81+
return i-3;
82+
}
83+
}
6884
}
6985
}
7086
pc->frame_start_found= pic_found;

0 commit comments

Comments
 (0)