- If you are deploying libav, build and runtime environments are different. Using --enable-vaapi can might cause to fail on the execution. - This is an optional feature to check the execution environment in the runtime. It can prevent to fail.
- Added new configure option(--enable-runtimedetect-vaapi) to supports backward compatibility. Added new function(ff_vaapi_probe()) to check libva availability. Modified avcodec_register_all() function to determine whether AVHWAccel is registered or not. Signed-off-by: Kim Gunsoo <[email protected]> --- configure | 17 ++++++++++----- libavcodec/Makefile | 2 ++ libavcodec/allcodecs.c | 23 ++++++++++++++----- libavcodec/vaapi.c | 51 +++++++++++++++++++++++++++++++++++++++++++ libavcodec/vaapi_internal.h | 4 ++++ 5 files changed, 86 insertions(+), 11 deletions(-) diff --git a/configure b/configure index ed8316f..7d46d33 100755 --- a/configure +++ b/configure @@ -135,6 +135,7 @@ Component options: Hardware accelerators: --enable-dxva2 enable DXVA2 code --enable-vaapi enable VAAPI code + --enable-runtimedetect-vaapi enable runtime-detect-VAAPI code --enable-vda enable VDA code --enable-vdpau enable VDPAU code @@ -1197,6 +1198,7 @@ FEATURE_LIST=" HWACCEL_LIST=" dxva2 vaapi + runtimedetect_vaapi vda vdpau " @@ -1939,17 +1941,19 @@ zmbv_encoder_deps="zlib" # hardware accelerators dxva2_deps="dxva2api_h" vaapi_deps="va_va_h" +runtimedetect_vaapi_deps="va_va_h" + vda_deps="VideoDecodeAcceleration_VDADecoder_h pthreads" vda_extralibs="-framework CoreFoundation -framework VideoDecodeAcceleration -framework QuartzCore" vdpau_deps="vdpau_vdpau_h vdpau_vdpau_x11_h" -h263_vaapi_hwaccel_deps="vaapi" +h263_vaapi_hwaccel_deps_any="vaapi runtimedetect_vaapi" h263_vaapi_hwaccel_select="h263_decoder" h263_vdpau_hwaccel_deps="vdpau" h263_vdpau_hwaccel_select="h263_decoder" h264_dxva2_hwaccel_deps="dxva2" h264_dxva2_hwaccel_select="h264_decoder" -h264_vaapi_hwaccel_deps="vaapi" +h264_vaapi_hwaccel_deps_any="vaapi runtimedetect_vaapi" h264_vaapi_hwaccel_select="h264_decoder" h264_vda_hwaccel_deps="vda" h264_vda_hwaccel_select="h264_decoder" @@ -1961,17 +1965,17 @@ mpeg1_vdpau_hwaccel_deps="vdpau" mpeg1_vdpau_hwaccel_select="mpeg1video_decoder" mpeg2_dxva2_hwaccel_deps="dxva2" mpeg2_dxva2_hwaccel_select="mpeg2video_decoder" -mpeg2_vaapi_hwaccel_deps="vaapi" +mpeg2_vaapi_hwaccel_deps_any="vaapi runtimedetect_vaapi" mpeg2_vaapi_hwaccel_select="mpeg2video_decoder" mpeg2_vdpau_hwaccel_deps="vdpau" mpeg2_vdpau_hwaccel_select="mpeg2video_decoder" -mpeg4_vaapi_hwaccel_deps="vaapi" +mpeg4_vaapi_hwaccel_deps_any="vaapi runtimedetect_vaapi" mpeg4_vaapi_hwaccel_select="mpeg4_decoder" mpeg4_vdpau_hwaccel_deps="vdpau" mpeg4_vdpau_hwaccel_select="mpeg4_decoder" vc1_dxva2_hwaccel_deps="dxva2" vc1_dxva2_hwaccel_select="vc1_decoder" -vc1_vaapi_hwaccel_deps="vaapi" +vc1_vaapi_hwaccel_deps_any="vaapi runtimedetect_vaapi" vc1_vaapi_hwaccel_select="vc1_decoder" vc1_vdpau_hwaccel_deps="vdpau" vc1_vdpau_hwaccel_select="vc1_decoder" @@ -4162,6 +4166,9 @@ disabled bzlib || check_lib2 bzlib.h BZ2_bzlibVersion -lbz2 || disable bzlib check_lib math.h sin -lm && LIBM="-lm" enabled vaapi && require vaapi va/va.h vaInitialize -lva +enabled runtimedetect_vaapi && { { check_header va/va.h && require dl dlfcn.h dlopen -ldl; } || + die "ERROR: va.h header not found, or libdl not found"; } +enabled vaapi && enabled runtimedetect_vaapi && die "ERROR: You MUST select one of these(vaapi, runtimedetect_vaapi) or none" atan2f_args=2 ldexpf_args=2 diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 66aa0ce..960ed5a 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -544,6 +544,7 @@ OBJS-$(CONFIG_ADPCM_YAMAHA_ENCODER) += adpcmenc.o adpcm_data.o # hardware accelerators OBJS-$(CONFIG_DXVA2) += dxva2.o OBJS-$(CONFIG_VAAPI) += vaapi.o +OBJS-$(CONFIG_RUNTIMEDETECT_VAAPI) += vaapi.o OBJS-$(CONFIG_VDA) += vda.o OBJS-$(CONFIG_VDPAU) += vdpau.o @@ -711,6 +712,7 @@ SKIPHEADERS-$(CONFIG_DXVA2) += dxva2.h dxva2_internal.h SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h SKIPHEADERS-$(CONFIG_MPEG_XVMC_DECODER) += xvmc.h SKIPHEADERS-$(CONFIG_VAAPI) += vaapi_internal.h +SKIPHEADERS-$(CONFIG_RUNTIMEDETECT_VAAPI) += vaapi_internal.h SKIPHEADERS-$(CONFIG_VDA) += vda.h vda_internal.h SKIPHEADERS-$(CONFIG_VDPAU) += vdpau.h vdpau_internal.h diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 6a71b2c..6325fc4 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -65,33 +65,44 @@ av_register_bitstream_filter(&ff_##x##_bsf); \ } +#if CONFIG_RUNTIMEDETECT_VAAPI +extern int ff_vaapi_probe(void); +#endif void avcodec_register_all(void) { static int initialized; + int is_vaapi_probed; if (initialized) return; initialized = 1; /* hardware accelerators */ - REGISTER_HWACCEL(H263_VAAPI, h263_vaapi); +#if CONFIG_RUNTIMEDETECT_VAAPI + is_vaapi_probed = ff_vaapi_probe(); +#else + is_vaapi_probed = 1; +#endif + if (is_vaapi_probed) { + REGISTER_HWACCEL(H263_VAAPI, h263_vaapi); + REGISTER_HWACCEL(H264_VAAPI, h264_vaapi); + REGISTER_HWACCEL(MPEG2_VAAPI, mpeg2_vaapi); + REGISTER_HWACCEL(MPEG4_VAAPI, mpeg4_vaapi); + REGISTER_HWACCEL(VC1_VAAPI, vc1_vaapi); + REGISTER_HWACCEL(WMV3_VAAPI, wmv3_vaapi); + } REGISTER_HWACCEL(H263_VDPAU, h263_vdpau); REGISTER_HWACCEL(H264_DXVA2, h264_dxva2); - REGISTER_HWACCEL(H264_VAAPI, h264_vaapi); REGISTER_HWACCEL(H264_VDA, h264_vda); REGISTER_HWACCEL(H264_VDA_OLD, h264_vda_old); REGISTER_HWACCEL(H264_VDPAU, h264_vdpau); REGISTER_HWACCEL(MPEG1_VDPAU, mpeg1_vdpau); REGISTER_HWACCEL(MPEG2_DXVA2, mpeg2_dxva2); - REGISTER_HWACCEL(MPEG2_VAAPI, mpeg2_vaapi); REGISTER_HWACCEL(MPEG2_VDPAU, mpeg2_vdpau); - REGISTER_HWACCEL(MPEG4_VAAPI, mpeg4_vaapi); REGISTER_HWACCEL(MPEG4_VDPAU, mpeg4_vdpau); REGISTER_HWACCEL(VC1_DXVA2, vc1_dxva2); - REGISTER_HWACCEL(VC1_VAAPI, vc1_vaapi); REGISTER_HWACCEL(VC1_VDPAU, vc1_vdpau); REGISTER_HWACCEL(WMV3_DXVA2, wmv3_dxva2); - REGISTER_HWACCEL(WMV3_VAAPI, wmv3_vaapi); REGISTER_HWACCEL(WMV3_VDPAU, wmv3_vdpau); /* video codecs */ diff --git a/libavcodec/vaapi.c b/libavcodec/vaapi.c index fcc6243..cf8ead1 100644 --- a/libavcodec/vaapi.c +++ b/libavcodec/vaapi.c @@ -24,6 +24,57 @@ #include "h264.h" #include "vaapi_internal.h" +#if CONFIG_RUNTIMEDETECT_VAAPI +#include "dlfcn.h" + +VAStatus (*func_vaCreateBuffer)(VADisplay, VAContextID, VABufferType, + unsigned int, unsigned int, void *, VABufferID *); +VAStatus (*func_vaDestroyBuffer)(VADisplay, VABufferID); +VAStatus (*func_vaMapBuffer)(VADisplay, VABufferID, void **); +VAStatus (*func_vaUnmapBuffer)(VADisplay, VABufferID); +VAStatus (*func_vaBeginPicture)(VADisplay, VAContextID, VASurfaceID); +VAStatus (*func_vaRenderPicture)(VADisplay, VAContextID, VABufferID *, int); +VAStatus (*func_vaEndPicture)(VADisplay, VAContextID); + +#define DLSYM(x) \ + { \ + func_##x = dlsym(handle, #x); \ + if (!func_##x) \ + goto error; \ + } + +int ff_vaapi_probe(void) +{ + + void *handle = NULL; + handle = dlopen("libva.so.1", RTLD_NOW); + if (!handle) + goto error; + + DLSYM(vaCreateBuffer); + DLSYM(vaDestroyBuffer); + DLSYM(vaMapBuffer); + DLSYM(vaUnmapBuffer); + DLSYM(vaBeginPicture); + DLSYM(vaRenderPicture); + DLSYM(vaEndPicture); + + return 1; + +error: + av_log(NULL, AV_LOG_DEBUG, "libva.so.1 load failed : %s\n", dlerror()); + return 0; +} + +#define vaCreateBuffer func_vaCreateBuffer +#define vaDestroyBuffer func_vaDestroyBuffer +#define vaMapBuffer func_vaMapBuffer +#define vaUnmapBuffer func_vaUnmapBuffer +#define vaBeginPicture func_vaBeginPicture +#define vaRenderPicture func_vaRenderPicture +#define vaEndPicture func_vaEndPicture +#endif + /** * @addtogroup VAAPI_Decoding * diff --git a/libavcodec/vaapi_internal.h b/libavcodec/vaapi_internal.h index d0fa7ae..1542854 100644 --- a/libavcodec/vaapi_internal.h +++ b/libavcodec/vaapi_internal.h @@ -67,6 +67,10 @@ int ff_vaapi_mpeg_end_frame(AVCodecContext *avctx); int ff_vaapi_commit_slices(struct vaapi_context *vactx); int ff_vaapi_render_picture(struct vaapi_context *vactx, VASurfaceID surface); +#if CONFIG_RUNTIMEDETECT_VAAPI +/** Probe VAAPI to check vaapi availability in runtime environment */ +int ff_vaapi_probe(void); +#endif /* @} */ #endif /* AVCODEC_VAAPI_INTERNAL_H */ -- 1.7.9.5 _______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
