From 9c997a3ccf3bfa0a85ad15ea4c126cb069d9d578 Mon Sep 17 00:00:00 2001 From: zhangyichix Date: Thu, 12 Oct 2023 15:58:03 +0800 Subject: [PATCH 01/16] Fixed av1 color aspects issues * Add the return of videoSignal value in av1 Tracked-On: OAM-112687 Signed-off-by: zhangyichix --- _studio/mfx_lib/decode/av1/src/mfx_av1_dec_decode.cpp | 10 ++++++++++ .../shared/umc/codec/av1_dec/include/umc_av1_decoder.h | 1 + .../shared/umc/codec/av1_dec/src/umc_av1_decoder.cpp | 1 + 3 files changed, 12 insertions(+) diff --git a/_studio/mfx_lib/decode/av1/src/mfx_av1_dec_decode.cpp b/_studio/mfx_lib/decode/av1/src/mfx_av1_dec_decode.cpp index 9a385381..2374108b 100755 --- a/_studio/mfx_lib/decode/av1/src/mfx_av1_dec_decode.cpp +++ b/_studio/mfx_lib/decode/av1/src/mfx_av1_dec_decode.cpp @@ -1241,6 +1241,16 @@ mfxStatus VideoDECODEAV1::FillVideoParam(UMC_AV1_DECODER::AV1DecoderParams const || par->mfx.FrameInfo.FourCC == MFX_FOURCC_Y416) par->mfx.FrameInfo.Shift = 1; + // video signal section + mfxExtVideoSignalInfo * videoSignal = (mfxExtVideoSignalInfo *)GetExtendedBuffer(par->ExtParam, par->NumExtParam, MFX_EXTBUFF_VIDEO_SIGNAL_INFO); + if (videoSignal) + { + videoSignal->VideoFullRange = vp->color_config.color_range; + videoSignal->ColourPrimaries = vp->color_config.color_primaries; + videoSignal->TransferCharacteristics = vp->color_config.transfer_characteristics; + videoSignal->MatrixCoefficients = vp->color_config.matrix_coefficients; + } + return MFX_ERR_NONE; } diff --git a/_studio/shared/umc/codec/av1_dec/include/umc_av1_decoder.h b/_studio/shared/umc/codec/av1_dec/include/umc_av1_decoder.h index 89b6d1f2..fdc14969 100755 --- a/_studio/shared/umc/codec/av1_dec/include/umc_av1_decoder.h +++ b/_studio/shared/umc/codec/av1_dec/include/umc_av1_decoder.h @@ -72,6 +72,7 @@ namespace UMC_AV1_DECODER bool anchors_loaded; uint32_t skip_first_frames; mfxFrameSurface1** pre_loaded_anchors; + ColorConfig color_config; }; class ReportItem // adopted from HEVC/AVC decoders diff --git a/_studio/shared/umc/codec/av1_dec/src/umc_av1_decoder.cpp b/_studio/shared/umc/codec/av1_dec/src/umc_av1_decoder.cpp index f593a583..3e8026e1 100755 --- a/_studio/shared/umc/codec/av1_dec/src/umc_av1_decoder.cpp +++ b/_studio/shared/umc/codec/av1_dec/src/umc_av1_decoder.cpp @@ -1103,6 +1103,7 @@ namespace UMC_AV1_DECODER par.lFlags = 0; par.film_grain = sh.film_grain_param_present; + par.color_config = sh.color_config; return UMC::UMC_OK; } From 166ffa928e469f5a6eaf1c27f37bc1eb9773ba71 Mon Sep 17 00:00:00 2001 From: zhangyichix Date: Tue, 21 Jun 2022 02:28:50 +0000 Subject: [PATCH 02/16] Ignore reserved units for av1 decoder case:android.mediav2.cts.AdaptivePlaybackTest#testAdaptivePlayback Some av1 videos may contain reserved units. We should ignore it instead of returning an error. Reference source: https://aomediacodec.github.io/av1-spec/av1-spec.pdf Section 6.2.6: Reserved units are for future use and shall be ignored by AV1 decoder. Tracked-On: OAM-102526 Signed-off-by: zhangyichix --- _studio/shared/umc/codec/av1_dec/include/umc_av1_dec_defs.h | 1 + _studio/shared/umc/codec/av1_dec/src/umc_av1_bitstream.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/_studio/shared/umc/codec/av1_dec/include/umc_av1_dec_defs.h b/_studio/shared/umc/codec/av1_dec/include/umc_av1_dec_defs.h index a03177cc..3a0d1c12 100644 --- a/_studio/shared/umc/codec/av1_dec/include/umc_av1_dec_defs.h +++ b/_studio/shared/umc/codec/av1_dec/include/umc_av1_dec_defs.h @@ -104,6 +104,7 @@ namespace UMC_AV1_DECODER enum AV1_OBU_TYPE { + OBU_Reserved = 0, OBU_SEQUENCE_HEADER = 1, OBU_TEMPORAL_DELIMITER = 2, OBU_FRAME_HEADER = 3, diff --git a/_studio/shared/umc/codec/av1_dec/src/umc_av1_bitstream.cpp b/_studio/shared/umc/codec/av1_dec/src/umc_av1_bitstream.cpp index 8be3ea77..ddcb06f1 100644 --- a/_studio/shared/umc/codec/av1_dec/src/umc_av1_bitstream.cpp +++ b/_studio/shared/umc/codec/av1_dec/src/umc_av1_bitstream.cpp @@ -1211,7 +1211,8 @@ namespace UMC_AV1_DECODER if (info.header.obu_has_size_field) av1_read_obu_size(*this, obu_size, sizeFieldLength); - else if (info.header.obu_type != OBU_TEMPORAL_DELIMITER) + // Av1-spec section 6.2.2: Reserved units are for future use and shall be ignored by AV1 decoder. + else if (info.header.obu_type != OBU_TEMPORAL_DELIMITER && info.header.obu_type != OBU_Reserved) throw av1_exception(UMC::UMC_ERR_NOT_IMPLEMENTED); // no support for OBUs w/o size field so far info.size = headerSize + sizeFieldLength + obu_size; From 9c1340b5679d1b9a0317bf34e04ac227ad93e894 Mon Sep 17 00:00:00 2001 From: zhangyichix Date: Thu, 25 Apr 2024 14:33:14 +0800 Subject: [PATCH 03/16] Add Android.mk and fix compilation issues Tracked-On:OAM-117146 Signed-off-by: zhepeng.xu Signed-off-by: zhangyichix --- Android.mk | 4 + _studio/Android.mk | 3 + _studio/enctools/aenc/Android.mk | 26 ++ _studio/mfx_lib/Android.mk | 343 ++++++++++++++++++ .../ext/mpeg2/include/mfx_mpeg2_encode_hw.h | 2 +- .../ext/mpeg2/src/mfx_mpeg2_encode_hw.cpp | 4 +- _studio/mfx_lib/shared/src/libmfxsw.cpp | 2 +- _studio/shared/Android.mk | 3 + _studio/shared/asc/Android.mk | 92 +++++ _studio/shared/include/mfx_config.h | 12 +- _studio/shared/mfx_logging/Android.mk | 24 ++ _studio/shared/mfx_trace/Android.mk | 23 ++ _studio/shared/src/libmfx_core_vaapi.cpp | 2 +- _studio/shared/umc/Android.mk | 3 + _studio/shared/umc/codec/Android.mk | 83 +++++ _studio/shared/umc/core/Android.mk | 40 ++ _studio/shared/umc/io/Android.mk | 35 ++ android/Android.bp | 10 + android/Android.mk | 12 + android/include/mfx_android_config.h | 24 ++ android/include/mfx_android_defs.h | 57 +++ android/mfx_defs.mk | 115 ++++++ android/mfx_defs_internal.mk | 51 +++ 23 files changed, 962 insertions(+), 8 deletions(-) create mode 100644 Android.mk create mode 100644 _studio/Android.mk create mode 100644 _studio/enctools/aenc/Android.mk create mode 100644 _studio/mfx_lib/Android.mk create mode 100644 _studio/shared/Android.mk create mode 100644 _studio/shared/asc/Android.mk create mode 100644 _studio/shared/mfx_logging/Android.mk create mode 100644 _studio/shared/mfx_trace/Android.mk create mode 100644 _studio/shared/umc/Android.mk create mode 100644 _studio/shared/umc/codec/Android.mk create mode 100644 _studio/shared/umc/core/Android.mk create mode 100644 _studio/shared/umc/io/Android.mk create mode 100644 android/Android.bp create mode 100644 android/Android.mk create mode 100644 android/include/mfx_android_config.h create mode 100644 android/include/mfx_android_defs.h create mode 100644 android/mfx_defs.mk create mode 100644 android/mfx_defs_internal.mk diff --git a/Android.mk b/Android.mk new file mode 100644 index 00000000..bfaab8be --- /dev/null +++ b/Android.mk @@ -0,0 +1,4 @@ +MFX_HOME:= $(call my-dir) + +# Recursively call sub-folder Android.mk +include $(call all-subdir-makefiles) diff --git a/_studio/Android.mk b/_studio/Android.mk new file mode 100644 index 00000000..86c9b78c --- /dev/null +++ b/_studio/Android.mk @@ -0,0 +1,3 @@ +# Recursively call sub-folder Android.mk + +include $(call all-subdir-makefiles) \ No newline at end of file diff --git a/_studio/enctools/aenc/Android.mk b/_studio/enctools/aenc/Android.mk new file mode 100644 index 00000000..0642b0dc --- /dev/null +++ b/_studio/enctools/aenc/Android.mk @@ -0,0 +1,26 @@ +include $(CLEAR_VARS) +include $(MFX_HOME)/android/mfx_defs.mk + +LOCAL_SRC_FILES := $(addprefix src/, aenc.cpp \ + hevc_asc_apq_tree.cpp \ + av1_asc_agop_tree.cpp \ + av1_asc_tree.cpp \ + hevc_asc_agop_tree.cpp \ + av1_asc.cpp) + +LOCAL_C_INCLUDES := \ + $(MFX_INCLUDES_INTERNAL_HW) \ + $(MFX_HOME)/_studio/enctools/aenc/include/ + +LOCAL_CFLAGS := \ + $(MFX_CFLAGS_INTERNAL_HW) \ + -mavx2 \ + -Wno-error \ + -Wno-unused-parameter + +LOCAL_CFLAGS_32 := $(MFX_CFLAGS_INTERNAL_32) +LOCAL_CFLAGS_64 := $(MFX_CFLAGS_INTERNAL_64) + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := libmfx_aenc +include $(BUILD_STATIC_LIBRARY) diff --git a/_studio/mfx_lib/Android.mk b/_studio/mfx_lib/Android.mk new file mode 100644 index 00000000..74faa19d --- /dev/null +++ b/_studio/mfx_lib/Android.mk @@ -0,0 +1,343 @@ + +LOCAL_PATH:= $(MFX_HOME)/_studio + +# ============================================================================= + +MFX_LOCAL_DECODERS := h265 h264 vc1 mjpeg vp8 vp9 av1 +MFX_LOCAL_ENCODERS := h264 mpeg2 mjpeg vp9 + +# Setting subdirectories to march thru +MFX_LOCAL_DIRS := \ + scheduler/linux \ + +MFX_LOCAL_DIRS_IMPL := \ + $(addprefix decode/, $(MFX_LOCAL_DECODERS)) \ + vpp + +MFX_LOCAL_DIRS_HW := \ + $(addprefix encode_hw/, $(MFX_LOCAL_ENCODERS)) \ + mctf_package/mctf \ + cmrt_cross_platform + +#scheduler/linux/src +MFX_LOCAL_SRC_FILES := \ + $(patsubst $(LOCAL_PATH)/%, %, $(foreach dir, $(MFX_LOCAL_DIRS), $(wildcard $(LOCAL_PATH)/mfx_lib/$(dir)/src/*.cpp))) + +#decode/h265 h264 vc1 mjpeg vp8 vp9 av1/src +MFX_LOCAL_SRC_FILES_IMPL := \ + $(patsubst $(LOCAL_PATH)/%, %, $(foreach dir, $(MFX_LOCAL_DIRS_IMPL), $(wildcard $(LOCAL_PATH)/mfx_lib/$(dir)/src/*.cpp))) + +#encode_hw/h264 mpeg2 mjpeg vp9/src +MFX_LOCAL_SRC_FILES_HW := \ + $(MFX_LOCAL_SRC_FILES_IMPL) \ + $(patsubst $(LOCAL_PATH)/%, %, $(foreach dir, $(MFX_LOCAL_DIRS_HW), $(wildcard $(LOCAL_PATH)/mfx_lib/$(dir)/src/*.cpp))) + +#mpeg2 hw decoder +MFX_LOCAL_SRC_FILES_HW += $(addprefix mfx_lib/decode/mpeg2/hw/src/, \ + mfx_mpeg2_decode.cpp) + +MFX_LOCAL_SRC_FILES_HW += $(addprefix mfx_lib/ext/genx/h264_encode/isa/, \ + genx_simple_me_gen12lp_isa.cpp \ + genx_histogram_gen12lp_isa.cpp) + +MFX_LOCAL_SRC_FILES_HW += \ + mfx_lib/encode_hw/av1/av1ehw_disp.cpp \ + mfx_lib/encode_hw/av1/agnostic/av1ehw_base.cpp \ + mfx_lib/encode_hw/av1/linux/base/av1ehw_base_lin.cpp \ + mfx_lib/encode_hw/av1/linux/base/av1ehw_base_va_lin.cpp \ + mfx_lib/encode_hw/av1/linux/base/av1ehw_base_va_packer_lin.cpp \ + mfx_lib/encode_hw/av1/linux/base/av1ehw_base_max_frame_size_lin.cpp \ + mfx_lib/encode_hw/av1/agnostic/Xe_HPM/av1ehw_xe_hpm_segmentation.cpp \ + mfx_lib/encode_hw/av1/linux/Xe_HPM/av1ehw_xe_hpm_lin.cpp \ + mfx_lib/encode_hw/av1/linux/Xe_LPM_plus/av1ehw_xe_lpm_plus_lin.cpp \ + mfx_lib/encode_hw/av1/agnostic/base/av1ehw_base_alloc.cpp \ + mfx_lib/encode_hw/av1/agnostic/base/av1ehw_base_constraints.cpp \ + mfx_lib/encode_hw/av1/agnostic/base/av1ehw_base_qmatrix.cpp \ + mfx_lib/encode_hw/av1/agnostic/base/av1ehw_base_enctools_com.cpp \ + mfx_lib/encode_hw/av1/agnostic/base/av1ehw_base_general.cpp \ + mfx_lib/encode_hw/av1/agnostic/base/av1ehw_base_general_defaults.cpp \ + mfx_lib/encode_hw/av1/agnostic/base/av1ehw_base_impl.cpp \ + mfx_lib/encode_hw/av1/agnostic/base/av1ehw_base_packer.cpp \ + mfx_lib/encode_hw/av1/agnostic/base/av1ehw_base_query_impl_desc.cpp \ + mfx_lib/encode_hw/av1/agnostic/base/av1ehw_base_segmentation.cpp \ + mfx_lib/encode_hw/av1/agnostic/base/av1ehw_base_task.cpp \ + mfx_lib/encode_hw/av1/agnostic/base/av1ehw_base_tile.cpp \ + mfx_lib/encode_hw/av1/agnostic/base/av1ehw_base_encoded_frame_info.cpp \ + mfx_lib/encode_hw/av1/agnostic/base/av1ehw_base_max_frame_size.cpp \ + mfx_lib/encode_hw/av1/agnostic/base/av1ehw_base_enctools.cpp \ + mfx_lib/encode_hw/av1/agnostic/base/av1ehw_base_hdr.cpp \ + +MFX_LOCAL_SRC_FILES_HW += \ + mfx_lib/encode_hw/hevc/hevcehw_disp.cpp \ + mfx_lib/encode_hw/hevc/agnostic/hevcehw_base.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_impl.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_alloc.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_enctools_com.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_constraints.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_dirty_rect.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_encoded_frame_info.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_encode_stats.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_enctools.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_ext_brc.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_hdr_sei.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_hrd.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_scc.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_interlace.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_legacy.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_legacy_defaults.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_max_frame_size.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_packer.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_parser.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_recon_info.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_rext.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_roi.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_task.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_query_impl_desc.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_weighted_prediction.cpp \ + mfx_lib/encode_hw/hevc/agnostic/g12/hevcehw_g12_caps.cpp \ + mfx_lib/encode_hw/hevc/linux/base/hevcehw_base_interlace_lin.cpp \ + mfx_lib/encode_hw/hevc/linux/base/hevcehw_base_lin.cpp \ + mfx_lib/encode_hw/hevc/linux/base/hevcehw_base_dirty_rect_lin.cpp \ + mfx_lib/encode_hw/hevc/linux/base/hevcehw_base_max_frame_size_lin.cpp \ + mfx_lib/encode_hw/hevc/linux/base/hevcehw_base_enctools_qmatrix_lin.cpp \ + mfx_lib/encode_hw/hevc/linux/base/hevcehw_base_roi_lin.cpp \ + mfx_lib/encode_hw/hevc/linux/base/hevcehw_base_va_lin.cpp \ + mfx_lib/encode_hw/hevc/linux/base/hevcehw_base_rext_lin.cpp \ + mfx_lib/encode_hw/hevc/linux/base/hevcehw_base_va_packer_lin.cpp \ + mfx_lib/encode_hw/hevc/linux/base/hevcehw_base_qp_modulation_lin.cpp \ + mfx_lib/encode_hw/hevc/linux/base/hevcehw_base_weighted_prediction_lin.cpp \ + mfx_lib/encode_hw/hevc/linux/g12/hevcehw_g12_lin.cpp \ + mfx_lib/encode_hw/hevc/linux/xe_hpm/hevcehw_xe_hpm_lin.cpp \ + mfx_lib/encode_hw/hevc/linux/xe_lpm_plus/hevcehw_xe_lpm_plus_lin.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_extddi.cpp \ + mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_caps.cpp \ + mfx_lib/encode_hw/shared/ehw_resources_pool.cpp \ + mfx_lib/encode_hw/shared/ehw_task_manager.cpp \ + mfx_lib/encode_hw/shared/ehw_device_vaapi.cpp \ + mfx_lib/encode_hw/shared/ehw_utils_vaapi.cpp \ + mfx_lib/ext/cmrt_cross_platform/src/cm_mem_copy.cpp \ + mfx_lib/ext/cmrt_cross_platform/src/cmrt_cross_platform.cpp \ + mfx_lib/ext/cmrt_cross_platform/src/cmrt_utility.cpp \ + mfx_lib/ext/asc/src/asc_cm.cpp \ + mfx_lib/ext/genx/h264_encode/src/genx_simple_me_proto.cpp \ + +#scheduler/linux/include +MFX_LOCAL_INCLUDES := \ + $(foreach dir, $(MFX_LOCAL_DIRS), $(wildcard $(LOCAL_PATH)/mfx_lib/$(dir)/include)) + +#decode/h265 h264 vc1 mjpeg vp8 vp9 av1/include +MFX_LOCAL_INCLUDES_IMPL := \ + $(MFX_LOCAL_INCLUDES) \ + $(foreach dir, $(MFX_LOCAL_DIRS_IMPL), $(wildcard $(LOCAL_PATH)/mfx_lib/$(dir)/include)) + +#decode/mpeg2/hw/include +MFX_LOCAL_INCLUDES_IMPL += \ + $(MFX_HOME)/_studio/mfx_lib/decode/mpeg2/hw/include + +#encode_hw/h264 mpeg2 mjpeg vp9/include +MFX_LOCAL_INCLUDES_IMPL += \ + $(foreach dir, $(MFX_LOCAL_DIRS_HW), $(wildcard $(LOCAL_PATH)/mfx_lib/$(dir)/include)) + +MFX_LOCAL_INCLUDES_HW := \ + $(MFX_LOCAL_INCLUDES_IMPL) \ + $(MFX_HOME)/_studio/mfx_lib/ext/asc/include \ + $(MFX_HOME)/_studio/mfx_lib/ext/genx/h264_encode/isa \ + $(MFX_HOME)/_studio/mfx_lib/ext/genx/field_copy/isa \ + $(MFX_HOME)/_studio/mfx_lib/ext/genx/copy_kernels/isa \ + $(MFX_HOME)/_studio/mfx_lib/ext/cmrt_cross_platform/include \ + $(MFX_HOME)/_studio/mfx_lib/ext/genx/mctf/isa \ + $(MFX_HOME)/_studio/mfx_lib/ext/genx/asc/isa \ + $(MFX_HOME)/_studio/mfx_lib/ext/h264/include \ + $(MFX_HOME)/_studio/mfx_lib/ext/mpeg2/include \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/av1 \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/av1/agnostic \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/av1/agnostic/base \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/av1/agnostic/Xe_HPM \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/av1/agnostic/Xe_LPM_plus \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/av1/linux \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/av1/linux/base \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/av1/linux/Xe_HPM \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/av1/linux/Xe_LPM_plus \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/hevc \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/hevc/agnostic \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/hevc/agnostic/base \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/hevc/agnostic/g12 \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/hevc/linux \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/hevc/linux/base \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/hevc/linux/g12 \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/hevc/linux/xe_hpm \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/hevc/linux/xe_lpm_plus \ + $(MFX_HOME)/_studio/mfx_lib/encode_hw/shared \ + $(MFX_HOME)/_studio/mfx_lib/shared/include/feature_blocks \ + $(MFX_HOME)/_studio/mfx_lib/scheduler/linux/include \ + $(MFX_HOME)/_studio/shared/asc/include + +MFX_LOCAL_STATIC_LIBRARIES_HW := \ + libmfx_core_hw \ + libumc_codecs_hw \ + libumc_brc \ + libumc_va \ + libumc_core_hw \ + libmfx_gen_trace \ + libmfx_asc \ + libmfx_logging + +MFX_LOCAL_LDFLAGS_HW := \ + $(MFX_LDFLAGS) \ + -Wl,--version-script=$(LOCAL_PATH)/mfx_lib/libmfx-gen.map + +# ============================================================================= + +UMC_DIRS := \ + h264_enc \ + brc + +UMC_DIRS_IMPL := \ + h265_dec h264_dec mpeg2_dec vc1_dec jpeg_dec vp9_dec av1_dec \ + vc1_common jpeg_common color_space_converter + +UMC_LOCAL_INCLUDES := \ + $(foreach dir, $(UMC_DIRS), $(wildcard $(MFX_HOME)/_studio/shared/umc/codec/$(dir)/include)) + +UMC_LOCAL_INCLUDES_IMPL := \ + $(UMC_LOCAL_INCLUDES) \ + $(foreach dir, $(UMC_DIRS_IMPL), $(wildcard $(MFX_HOME)/_studio/shared/umc/codec/$(dir)/include)) + +UMC_LOCAL_INCLUDES_HW := \ + $(UMC_LOCAL_INCLUDES_IMPL) + +# ============================================================================= + +MFX_SHARED_FILES_IMPL := $(addprefix mfx_lib/shared/src/, \ + mfx_feature_blocks_base.cpp \ + mfx_brc_common.cpp \ + mfx_common_decode_int.cpp \ + mfx_common_int.cpp \ + mfx_enc_common.cpp \ + mfx_log.cpp \ + mfx_enc_enctools_common.cpp \ + mfx_mpeg2_dec_common.cpp \ + mfx_vc1_dec_common.cpp \ + mfx_ddi_enc_dump.cpp \ + mfx_vpx_dec_common.cpp) + +MFX_SHARED_FILES_HW := \ + $(MFX_SHARED_FILES_IMPL) + +MFX_SHARED_FILES_HW += $(addprefix mfx_lib/ext/genx/asc/isa/, \ + genx_scd_gen12lp_isa.cpp) + +MFX_SHARED_FILES_HW += $(addprefix mfx_lib/ext/genx/copy_kernels/isa/, \ + genx_copy_kernel_gen12lp_isa.cpp) + +MFX_SHARED_FILES_HW += $(addprefix mfx_lib/ext/genx/field_copy/isa/, \ + genx_fcopy_gen12lp_isa.cpp) + +MFX_SHARED_FILES_HW += $(addprefix mfx_lib/ext/genx/mctf/isa/, \ + genx_me_gen12lp_isa.cpp \ + genx_mc_gen12lp_isa.cpp \ + genx_sd_gen12lp_isa.cpp) + +MFX_SHARED_FILES_HW += $(addprefix mfx_lib/ext/mpeg2/src/, \ + mfx_mpeg2_encode_debug_hw.cpp \ + mfx_mpeg2_encode_full_hw.cpp \ + mfx_mpeg2_encode_hw.cpp \ + mfx_mpeg2_encode_utils_hw.cpp \ + mfx_mpeg2_encode_vaapi.cpp \ + mfx_mpeg2_encode_factory.cpp \ + mfx_mpeg2_enc_common_hw.cpp) + +MFX_SHARED_FILES_HW += $(addprefix mfx_lib/ext/h264/src/, \ + mfx_h264_encode_cm.cpp) + +MFX_LIB_SHARED_FILES_1 := $(addprefix mfx_lib/shared/src/, \ + libmfxsw.cpp \ + libmfxsw_async.cpp \ + libmfxsw_decode.cpp \ + libmfxsw_decode_vp.cpp \ + libmfxsw_functions.cpp \ + libmfxsw_enc.cpp \ + libmfxsw_encode.cpp \ + libmfxsw_pak.cpp \ + libmfxsw_plugin.cpp \ + libmfxsw_query.cpp \ + libmfxsw_session.cpp \ + libmfxsw_vpp.cpp \ + mfx_session.cpp \ + mfx_critical_error_handler.cpp) + +MFX_LIB_SHARED_FILES_2 := $(addprefix shared/src/, \ + fast_copy.cpp \ + fast_copy_c_impl.cpp \ + fast_copy_sse4_impl.cpp \ + mfx_vpp_vaapi.cpp \ + mfx_vpp_helper.cpp \ + libmfx_allocator.cpp \ + libmfx_allocator_vaapi.cpp \ + libmfx_core.cpp \ + libmfx_core_hw.cpp \ + libmfx_core_factory.cpp \ + libmfx_core_vaapi.cpp \ + mfx_umc_alloc_wrapper.cpp \ + mfx_umc_mjpeg_vpp.cpp) + +# ============================================================================= + +include $(CLEAR_VARS) +include $(MFX_HOME)/android/mfx_defs.mk + +LOCAL_SRC_FILES := \ + $(MFX_LOCAL_SRC_FILES) \ + $(MFX_LOCAL_SRC_FILES_HW) \ + $(MFX_SHARED_FILES_HW) + +LOCAL_C_INCLUDES := \ + $(MFX_LOCAL_INCLUDES_HW) \ + $(UMC_LOCAL_INCLUDES_HW) \ + $(MFX_INCLUDES_INTERNAL_HW) + +LOCAL_CPPFLAGS += -std=c++14 + +LOCAL_CFLAGS := \ + $(MFX_CFLAGS_INTERNAL_HW) \ + -Wno-error -Wno-unused-parameter -Wno-implicit-fallthrough + +LOCAL_CFLAGS_32 := $(MFX_CFLAGS_INTERNAL_32) +LOCAL_CFLAGS_64 := $(MFX_CFLAGS_INTERNAL_64) + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := libmfx_core_hw +LOCAL_SHARED_LIBRARIES := liblog libcutils + +include $(BUILD_STATIC_LIBRARY) + +# ============================================================================= + +include $(CLEAR_VARS) +include $(MFX_HOME)/android/mfx_defs.mk + +LOCAL_SRC_FILES := $(MFX_LIB_SHARED_FILES_1) $(MFX_LIB_SHARED_FILES_2) + +LOCAL_C_INCLUDES := \ + $(MFX_LOCAL_INCLUDES_HW) \ + $(UMC_LOCAL_INCLUDES_HW) \ + $(MFX_INCLUDES_INTERNAL_HW) + +LOCAL_CFLAGS := \ + $(MFX_CFLAGS_INTERNAL_HW) \ + -Wno-error -Wno-unused-parameter -Wno-implicit-fallthrough + +LOCAL_CFLAGS_32 := $(MFX_CFLAGS_INTERNAL_32) +LOCAL_CFLAGS_64 := $(MFX_CFLAGS_INTERNAL_64) + +LOCAL_LDFLAGS := $(MFX_LOCAL_LDFLAGS_HW) + +LOCAL_CPPFLAGS += -std=c++14 + +LOCAL_WHOLE_STATIC_LIBRARIES := $(MFX_LOCAL_STATIC_LIBRARIES_HW) +LOCAL_SHARED_LIBRARIES := libva liblog libcutils libdrm + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := libmfx-gen + +include $(BUILD_SHARED_LIBRARY) diff --git a/_studio/mfx_lib/ext/mpeg2/include/mfx_mpeg2_encode_hw.h b/_studio/mfx_lib/ext/mpeg2/include/mfx_mpeg2_encode_hw.h index faa60ea9..2fc1abe8 100644 --- a/_studio/mfx_lib/ext/mpeg2/include/mfx_mpeg2_encode_hw.h +++ b/_studio/mfx_lib/ext/mpeg2/include/mfx_mpeg2_encode_hw.h @@ -187,7 +187,7 @@ class MFXVideoENCODEMPEG2_HW : public VideoENCODE }; -MFX_PROPAGATE_GetSurface_VideoENCODE_Impl(MFXVideoENCODEMPEG2_HW); + #endif // MFX_ENABLE_MPEG2_VIDEO_ENCODE #endif diff --git a/_studio/mfx_lib/ext/mpeg2/src/mfx_mpeg2_encode_hw.cpp b/_studio/mfx_lib/ext/mpeg2/src/mfx_mpeg2_encode_hw.cpp index 23d53b40..e1eaac0f 100644 --- a/_studio/mfx_lib/ext/mpeg2/src/mfx_mpeg2_encode_hw.cpp +++ b/_studio/mfx_lib/ext/mpeg2/src/mfx_mpeg2_encode_hw.cpp @@ -21,13 +21,13 @@ #include #include "mfx_common.h" - +#include "mfx_mpeg2_encode_hw.h" #if defined (MFX_ENABLE_MPEG2_VIDEO_ENCODE) #include "mfx_mpeg2_encode_utils_hw.h" - +MFX_PROPAGATE_GetSurface_VideoENCODE_Impl(MFXVideoENCODEMPEG2_HW); diff --git a/_studio/mfx_lib/shared/src/libmfxsw.cpp b/_studio/mfx_lib/shared/src/libmfxsw.cpp index 93d74430..d3cff5f4 100644 --- a/_studio/mfx_lib/shared/src/libmfxsw.cpp +++ b/_studio/mfx_lib/shared/src/libmfxsw.cpp @@ -31,7 +31,7 @@ #include #include #include -#include "va/va_drm.h" +#include "va/drm/va_drm.h" #include "mediasdk_version.h" #include "libmfx_core_factory.h" diff --git a/_studio/shared/Android.mk b/_studio/shared/Android.mk new file mode 100644 index 00000000..86c9b78c --- /dev/null +++ b/_studio/shared/Android.mk @@ -0,0 +1,3 @@ +# Recursively call sub-folder Android.mk + +include $(call all-subdir-makefiles) \ No newline at end of file diff --git a/_studio/shared/asc/Android.mk b/_studio/shared/asc/Android.mk new file mode 100644 index 00000000..03c8063a --- /dev/null +++ b/_studio/shared/asc/Android.mk @@ -0,0 +1,92 @@ +LOCAL_PATH:= $(call my-dir) + +# ============================================================================= + +include $(CLEAR_VARS) +include $(MFX_HOME)/android/mfx_defs.mk + +LOCAL_SRC_FILES := $(addprefix src/, asc_avx2_impl.cpp) + +LOCAL_C_INCLUDES := \ + $(MFX_INCLUDES_INTERNAL_HW) \ + $(MFX_HOME)/_studio/mfx_lib/cmrt_cross_platform/include \ + $(MFX_HOME)/_studio/mfx_lib/ext/genx/asc/isa + +LOCAL_CFLAGS := \ + $(MFX_CFLAGS_INTERNAL_HW) \ + -mavx2 \ + -Wno-error \ + -Wno-unused-parameter + +LOCAL_CFLAGS += -I $(MFX_HOME)/_studio/shared/asc/include/ + +LOCAL_CFLAGS_32 := $(MFX_CFLAGS_INTERNAL_32) +LOCAL_CFLAGS_64 := $(MFX_CFLAGS_INTERNAL_64) + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := libmfx_asc_avx2 +include $(BUILD_STATIC_LIBRARY) + +# ============================================================================= + +include $(CLEAR_VARS) +include $(MFX_HOME)/android/mfx_defs.mk + +LOCAL_SRC_FILES := $(addprefix src/, asc_sse4_impl.cpp) + +LOCAL_C_INCLUDES := \ + $(MFX_INCLUDES_INTERNAL_HW) \ + $(MFX_HOME)/_studio/mfx_lib/cmrt_cross_platform/include \ + $(MFX_HOME)/_studio/mfx_lib/ext/genx/asc/isa + +LOCAL_CFLAGS := \ + $(MFX_CFLAGS_INTERNAL_HW) \ + -msse4.1 \ + -Wno-error \ + -Wno-unused-parameter + +LOCAL_CFLAGS_32 := $(MFX_CFLAGS_INTERNAL_32) +LOCAL_CFLAGS_64 := $(MFX_CFLAGS_INTERNAL_64) + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := libmfx_asc_sse4 +include $(BUILD_STATIC_LIBRARY) + +# ============================================================================= + +include $(CLEAR_VARS) +include $(MFX_HOME)/android/mfx_defs.mk + +ASC_SRC_FILES := $(addprefix src/, \ + asc.cpp \ + asc_c_impl.cpp \ + iofunctions.cpp \ + motion_estimation_engine.cpp \ + tree.cpp) + +LOCAL_SRC_FILES := $(ASC_SRC_FILES) + +LOCAL_C_INCLUDES := \ + $(MFX_INCLUDES_INTERNAL_HW) \ + $(MFX_HOME)/_studio/mfx_lib/cmrt_cross_platform/include \ + $(MFX_HOME)/_studio/mfx_lib/ext/genx/asc/isa + +LOCAL_STATIC_LIBRARIES := \ + libmfx_asc_avx2 \ + libmfx_asc_sse4 + +LOCAL_CFLAGS := \ + $(MFX_CFLAGS_INTERNAL_HW) \ + -msse4.1 \ + -Wno-error \ + -Wno-unused-parameter + +LOCAL_CFLAGS_32 := $(MFX_CFLAGS_INTERNAL_32) +LOCAL_CFLAGS_64 := $(MFX_CFLAGS_INTERNAL_64) + +LOCAL_WHOLE_STATIC_LIBRARIES := $(LOCAL_STATIC_LIBRARIES) + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := libmfx_asc + +include $(BUILD_STATIC_LIBRARY) diff --git a/_studio/shared/include/mfx_config.h b/_studio/shared/include/mfx_config.h index 2bab8e13..fa35c62c 100644 --- a/_studio/shared/include/mfx_config.h +++ b/_studio/shared/include/mfx_config.h @@ -29,9 +29,15 @@ #define UMC_VA_LINUX -// mfx_features.h is auto-generated file containing mediasdk per-component -// enable defines -#include "mfx_features.h" +#if defined(ANDROID) + // we don't support config auto-generation on Android and have hardcoded + // definition instead + #include "mfx_android_defs.h" +#else + // mfxconfig.h is auto-generated file containing mediasdk per-component + // enable defines + #include "mfx_features.h" +#endif #define SYNCHRONIZATION_BY_VA_MAP_BUFFER #if !defined(SYNCHRONIZATION_BY_VA_SYNC_SURFACE) diff --git a/_studio/shared/mfx_logging/Android.mk b/_studio/shared/mfx_logging/Android.mk new file mode 100644 index 00000000..93f6fc38 --- /dev/null +++ b/_studio/shared/mfx_logging/Android.mk @@ -0,0 +1,24 @@ +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) +include $(MFX_HOME)/android/mfx_defs.mk + +LOCAL_SRC_FILES := $(addprefix src/, $(notdir $(wildcard $(LOCAL_PATH)/src/*.cpp))) + +LOCAL_C_INCLUDES := \ + $(MFX_INCLUDES_INTERNAL_HW) \ + $(MFX_HOME)/api/mediasdk_structures + +LOCAL_CFLAGS := \ + $(MFX_CFLAGS_INTERNAL_HW) \ + -Wno-error \ + -Wno-unused-parameter + +LOCAL_CFLAGS_32 := $(MFX_CFLAGS_INTERNAL_32) +LOCAL_CFLAGS_64 := $(MFX_CFLAGS_INTERNAL_64) + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := libmfx_logging + +include $(BUILD_STATIC_LIBRARY) + diff --git a/_studio/shared/mfx_trace/Android.mk b/_studio/shared/mfx_trace/Android.mk new file mode 100644 index 00000000..93c71ffd --- /dev/null +++ b/_studio/shared/mfx_trace/Android.mk @@ -0,0 +1,23 @@ +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) +include $(MFX_HOME)/android/mfx_defs.mk + +LOCAL_SRC_FILES := $(addprefix src/, $(notdir $(wildcard $(LOCAL_PATH)/src/*.cpp))) + +LOCAL_C_INCLUDES := \ + $(MFX_INCLUDES_INTERNAL_HW) \ + $(MFX_HOME)/api/mediasdk_structures + +LOCAL_CFLAGS := \ + $(MFX_CFLAGS_INTERNAL_HW) \ + -Wno-error \ + -Wno-unused-parameter + +LOCAL_CFLAGS_32 := $(MFX_CFLAGS_INTERNAL_32) +LOCAL_CFLAGS_64 := $(MFX_CFLAGS_INTERNAL_64) + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := libmfx_gen_trace + +include $(BUILD_STATIC_LIBRARY) diff --git a/_studio/shared/src/libmfx_core_vaapi.cpp b/_studio/shared/src/libmfx_core_vaapi.cpp index fd5fc269..6c95c79f 100644 --- a/_studio/shared/src/libmfx_core_vaapi.cpp +++ b/_studio/shared/src/libmfx_core_vaapi.cpp @@ -44,7 +44,7 @@ #include "va/va.h" #include -#include "va/va_drm.h" +#include "va/drm/va_drm.h" #include #include diff --git a/_studio/shared/umc/Android.mk b/_studio/shared/umc/Android.mk new file mode 100644 index 00000000..86c9b78c --- /dev/null +++ b/_studio/shared/umc/Android.mk @@ -0,0 +1,3 @@ +# Recursively call sub-folder Android.mk + +include $(call all-subdir-makefiles) \ No newline at end of file diff --git a/_studio/shared/umc/codec/Android.mk b/_studio/shared/umc/codec/Android.mk new file mode 100644 index 00000000..7e4cf270 --- /dev/null +++ b/_studio/shared/umc/codec/Android.mk @@ -0,0 +1,83 @@ +LOCAL_PATH:= $(call my-dir) + +# Setting subdirectories to march thru +MFX_CODEC_LOCAL_DIRS := \ + vc1_common \ + jpeg_common \ + color_space_converter \ + mpeg2_dec \ + h265_dec \ + h264_dec \ + vc1_dec \ + jpeg_dec \ + vp9_dec \ + av1_dec + +MFX_CODEC_LOCAL_SRC_FILES := \ + $(patsubst $(LOCAL_PATH)/%, %, $(foreach dir, $(MFX_CODEC_LOCAL_DIRS), $(wildcard $(LOCAL_PATH)/$(dir)/src/*.cpp))) + +# ============================================================================= + +include $(CLEAR_VARS) +include $(MFX_HOME)/android/mfx_defs.mk + +LOCAL_SRC_FILES := \ + brc/src/umc_brc.cpp \ + brc/src/umc_h264_brc.cpp \ + brc/src/umc_mpeg2_brc.cpp \ + brc/src/umc_video_brc.cpp + +LOCAL_C_INCLUDES := \ + $(LOCAL_PATH)/brc/include \ + $(MFX_INCLUDES_INTERNAL_HW) + +LOCAL_CFLAGS := \ + $(MFX_CFLAGS_INTERNAL_HW) \ + -Wno-error \ + -Wno-unused-parameter \ + -Wno-deprecated-declarations + +LOCAL_CFLAGS_32 := $(MFX_CFLAGS_INTERNAL_32) +LOCAL_CFLAGS_64 := $(MFX_CFLAGS_INTERNAL_64) + +LOCAL_SHARED_LIBRARIES := liblog libcutils + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := libumc_brc + +include $(BUILD_STATIC_LIBRARY) + +# ============================================================================= + +include $(CLEAR_VARS) +include $(MFX_HOME)/android/mfx_defs.mk + +LOCAL_SRC_FILES := $(MFX_CODEC_LOCAL_SRC_FILES) + +LOCAL_C_INCLUDES := \ + $(LOCAL_PATH)/av1_dec/include \ + $(LOCAL_PATH)/color_space_converter/include \ + $(LOCAL_PATH)/h264_dec/include \ + $(LOCAL_PATH)/h265_dec/include \ + $(LOCAL_PATH)/jpeg_common/include \ + $(LOCAL_PATH)/jpeg_dec/include \ + $(LOCAL_PATH)/mpeg2_dec/include \ + $(LOCAL_PATH)/vc1_common/include \ + $(LOCAL_PATH)/vc1_dec/include \ + $(LOCAL_PATH)/vp9_dec/include \ + $(MFX_INCLUDES_INTERNAL_HW) + +LOCAL_CFLAGS := \ + $(MFX_CFLAGS_INTERNAL_HW) \ + -Wno-error \ + -Wno-unused-parameter + +LOCAL_CFLAGS_32 := $(MFX_CFLAGS_INTERNAL_32) +LOCAL_CFLAGS_64 := $(MFX_CFLAGS_INTERNAL_64) + +LOCAL_SHARED_LIBRARIES := liblog libcutils + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := libumc_codecs_hw + +include $(BUILD_STATIC_LIBRARY) diff --git a/_studio/shared/umc/core/Android.mk b/_studio/shared/umc/core/Android.mk new file mode 100644 index 00000000..aedbfe82 --- /dev/null +++ b/_studio/shared/umc/core/Android.mk @@ -0,0 +1,40 @@ +LOCAL_PATH:= $(call my-dir) + +# Setting subdirectories to march thru +MFX_LOCAL_DIRS := \ + vm \ + vm_plus \ + umc + +MFX_LOCAL_SRC_FILES := \ + $(patsubst $(LOCAL_PATH)/%, %, $(foreach dir, $(MFX_LOCAL_DIRS), $(wildcard $(LOCAL_PATH)/$(dir)/src/*.c))) \ + $(patsubst $(LOCAL_PATH)/%, %, $(foreach dir, $(MFX_LOCAL_DIRS), $(wildcard $(LOCAL_PATH)/$(dir)/src/*.cpp))) + +MFX_LOCAL_INCLUDES := \ + $(foreach dir, $(MFX_LOCAL_DIRS), $(wildcard $(LOCAL_PATH)/$(dir)/include)) + +# ============================================================================= + +include $(CLEAR_VARS) +include $(MFX_HOME)/android/mfx_defs.mk + +LOCAL_SRC_FILES := $(MFX_LOCAL_SRC_FILES) + +LOCAL_C_INCLUDES := \ + $(MFX_LOCAL_INCLUDES) \ + $(MFX_INCLUDES_INTERNAL_HW) + +LOCAL_CFLAGS := \ + $(MFX_CFLAGS_INTERNAL_HW) \ + -Wno-error \ + -Wno-unused-parameter + +LOCAL_CFLAGS_32 := $(MFX_CFLAGS_INTERNAL_32) +LOCAL_CFLAGS_64 := $(MFX_CFLAGS_INTERNAL_64) + +LOCAL_STATIC_LIBRARIES += libmfx_logging + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := libumc_core_hw + +include $(BUILD_STATIC_LIBRARY) diff --git a/_studio/shared/umc/io/Android.mk b/_studio/shared/umc/io/Android.mk new file mode 100644 index 00000000..0baf70d8 --- /dev/null +++ b/_studio/shared/umc/io/Android.mk @@ -0,0 +1,35 @@ +LOCAL_PATH:= $(call my-dir) + +MFX_LOCAL_DIRS_HW := \ + umc_va + +MFX_LOCAL_SRC_FILES_HW := \ + $(patsubst $(LOCAL_PATH)/%, %, $(foreach dir, $(MFX_LOCAL_DIRS_HW), $(wildcard $(LOCAL_PATH)/$(dir)/src/*.cpp))) + +MFX_LOCAL_INCLUDES_HW := \ + $(foreach dir, $(MFX_LOCAL_DIRS_HW), $(wildcard $(LOCAL_PATH)/$(dir)/include)) + +# ============================================================================= + +include $(CLEAR_VARS) +include $(MFX_HOME)/android/mfx_defs.mk + +LOCAL_SRC_FILES := $(MFX_LOCAL_SRC_FILES_HW) + +LOCAL_C_INCLUDES := \ + $(MFX_LOCAL_INCLUDES_HW) \ + $(MFX_INCLUDES_INTERNAL_HW) + +LOCAL_CFLAGS := \ + $(MFX_CFLAGS_INTERNAL_HW) \ + -Wno-error \ + -Wno-unused-parameter \ + -Wno-implicit-fallthrough + +LOCAL_CFLAGS_32 := $(MFX_CFLAGS_INTERNAL_32) +LOCAL_CFLAGS_64 := $(MFX_CFLAGS_INTERNAL_64) + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := libumc_va + +include $(BUILD_STATIC_LIBRARY) \ No newline at end of file diff --git a/android/Android.bp b/android/Android.bp new file mode 100644 index 00000000..746bac2f --- /dev/null +++ b/android/Android.bp @@ -0,0 +1,10 @@ + +cc_library_headers { + + name: "libmfx_android_headers", + export_include_dirs: [ + "include", + ], + + vendor: true, +} \ No newline at end of file diff --git a/android/Android.mk b/android/Android.mk new file mode 100644 index 00000000..579d3285 --- /dev/null +++ b/android/Android.mk @@ -0,0 +1,12 @@ +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := libmfx_gen_headers +LOCAL_EXPORT_C_INCLUDE_DIRS := \ + $(MFX_HOME)/api/vpl \ + $(MFX_HOME)/api/vpl/private \ + $(MFX_HOME)/api/mediasdk_structures \ + $(MFX_HOME)/android/include + +include $(BUILD_HEADER_LIBRARY) \ No newline at end of file diff --git a/android/include/mfx_android_config.h b/android/include/mfx_android_config.h new file mode 100644 index 00000000..1ee3135b --- /dev/null +++ b/android/include/mfx_android_config.h @@ -0,0 +1,24 @@ +/******************************************************************************** + +INTEL CORPORATION PROPRIETARY INFORMATION +This software is supplied under the terms of a license agreement or nondisclosure +agreement with Intel Corporation and may not be copied or disclosed except in +accordance with the terms of that agreement +Copyright(c) 2011-2018 Intel Corporation. All Rights Reserved. + +*********************************************************************************/ + +#ifndef __MFX_CONFIG_H__ +#define __MFX_CONFIG_H__ + +/* Google versions of Android */ +#define MFX_O 0x06 +#define MFX_O_MR1 0x07 +#define MFX_P 0x08 +#define MFX_Q 0x09 +#define MFX_R 0x0a +#define MFX_S 0x0b +#define MFX_T 0x0c +#define MFX_U 0x0d + +#endif // #ifndef __MFX_CONFIG_H__ diff --git a/android/include/mfx_android_defs.h b/android/include/mfx_android_defs.h new file mode 100644 index 00000000..7052485a --- /dev/null +++ b/android/include/mfx_android_defs.h @@ -0,0 +1,57 @@ +// Copyright (c) 2017-2018 Intel Corporation +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#ifndef __MFX_ANDROID_DEFS_H__ +#define __MFX_ANDROID_DEFS_H__ + + #define MFX_ENABLE_ASC + #define MFX_ENABLE_CPLIB + + #define MFX_ENABLE_VPP + + #define MFX_ENABLE_VC1_VIDEO_DECODE + + #define MFX_ENABLE_H265_VIDEO_DECODE + #define MFX_ENABLE_H265_VIDEO_ENCODE + + #define MFX_ENABLE_H264_VIDEO_DECODE + #define MFX_ENABLE_H264_VIDEO_ENCODE + + #define MFX_ENABLE_MJPEG_VIDEO_DECODE + #define MFX_ENABLE_MJPEG_VIDEO_ENCODE + + #define MFX_ENABLE_MPEG2_VIDEO_ENCODE + #define MFX_ENABLE_MPEG2_VIDEO_DECODE + + #define MFX_ENABLE_VP8_VIDEO_DECODE + + #define MFX_ENABLE_VP9_VIDEO_DECODE + #define MFX_ENABLE_VP9_VIDEO_ENCODE + + #define MFX_ENABLE_AV1_VIDEO_DECODE + #define MFX_ENABLE_AV1_VIDEO_ENCODE + + #define MFX_ENABLE_EXT + +#if MFX_ANDROID_VERSION >= MFX_P + #define MFX_ENABLE_KERNELS +#endif + +#endif // #ifndef __MFX_ANDROID_DEFS_H__ diff --git a/android/mfx_defs.mk b/android/mfx_defs.mk new file mode 100644 index 00000000..bf103599 --- /dev/null +++ b/android/mfx_defs.mk @@ -0,0 +1,115 @@ +# Purpose: +# Defines include paths, compilation flags, etc. to build Media SDK targets. +# +# Defined variables: +# MFX_CFLAGS - common flags for all targets +# MFX_CFLAGS_LIBVA - LibVA support flags (to build apps with or without LibVA support) +# MFX_INCLUDES - common include paths for all targets +# libva_headers - include paths to LibVA headers +# MFX_LDFLAGS - common link flags for all targets + +# ============================================================================= +# Common definitions + +MFX_CFLAGS := -DANDROID + +#Media Version +MEDIA_VERSION := 24.1.5 +MEDIA_VERSION_EXTRA := "" +MEDIA_VERSION_ALL := $(MEDIA_VERSION).pre$(MEDIA_VERSION_EXTRA) + +MFX_CFLAGS += -DMEDIA_VERSION_STR=\"\\\"${MEDIA_VERSION}\\\"\" +MFX_CFLAGS += -DONEVPL_EXPERIMENTAL + +# Android version preference: +ifneq ($(filter 14 14.% U% ,$(PLATFORM_VERSION)),) + MFX_ANDROID_VERSION:= MFX_U +endif +ifneq ($(filter 13 13.% T% ,$(PLATFORM_VERSION)),) + MFX_ANDROID_VERSION:= MFX_T +endif +ifneq ($(filter 12 12.% S ,$(PLATFORM_VERSION)),) + MFX_ANDROID_VERSION:= MFX_S +endif +ifneq ($(filter 11 11.% R ,$(PLATFORM_VERSION)),) + MFX_ANDROID_VERSION:= MFX_R +endif +ifneq ($(filter 10 10.% Q ,$(PLATFORM_VERSION)),) + MFX_ANDROID_VERSION:= MFX_Q +endif +ifneq ($(filter 9 9.% P ,$(PLATFORM_VERSION)),) + MFX_ANDROID_VERSION:= MFX_P +endif +ifneq ($(filter 8.% O ,$(PLATFORM_VERSION)),) + ifneq ($(filter 8.0.%,$(PLATFORM_VERSION)),) + MFX_ANDROID_VERSION:= MFX_O + else + MFX_ANDROID_VERSION:= MFX_O_MR1 + endif +endif + +# Passing Android-dependency information to the code +MFX_CFLAGS += \ + -DMFX_ANDROID_VERSION=$(MFX_ANDROID_VERSION) \ + -include mfx_android_config.h + +MFX_CFLAGS += \ + -DMFX_VERSION=2009 + +MFX_CFLAGS += \ + -DMFX_FILE_VERSION=\"`echo $(MFX_VERSION) | cut -f 1 -d.``date +.%-y.%-m.%-d`\" \ + -DMFX_PRODUCT_VERSION=\"$(MFX_VERSION)\" + +# Security +MFX_CFLAGS += \ + -fstack-protector \ + -fPIE -fPIC -pie \ + -O2 -D_FORTIFY_SOURCE=2 \ + -Wformat -Wformat-security \ + -fexceptions -frtti -msse4.1 \ + -Wno-non-virtual-dtor \ + -Wunused-command-line-argument \ + -mavx2 + +# Enable feature with output decoded frames without latency regarding +# SPS.VUI.max_num_reorder_frames +ifeq ($(ENABLE_MAX_NUM_REORDER_FRAMES_OUTPUT),) + ENABLE_MAX_NUM_REORDER_FRAMES_OUTPUT:= true +endif + +ifeq ($(ENABLE_MAX_NUM_REORDER_FRAMES_OUTPUT),true) + MFX_CFLAGS += -DENABLE_MAX_NUM_REORDER_FRAMES_OUTPUT +endif + +# LibVA support. +MFX_CFLAGS_LIBVA := -DLIBVA_SUPPORT -DLIBVA_ANDROID_SUPPORT + +ifneq ($(filter $(MFX_ANDROID_VERSION), MFX_O),) + MFX_CFLAGS_LIBVA += -DANDROID_O +endif + +# Setting usual paths to include files +MFX_INCLUDES := $(LOCAL_PATH)/include + +LOCAL_HEADER_LIBRARIES := libmfx_gen_headers libva_headers + +# Setting usual link flags +MFX_LDFLAGS := \ + -z noexecstack \ + -z relro -z now + +# Setting vendor +LOCAL_MODULE_OWNER := intel + +# Moving executables to proprietary location +LOCAL_PROPRIETARY_MODULE := true + +LOCAL_CPPFLAGS := -Wno-deprecated-declarations \ + -Wno-missing-field-initializers \ + -Wno-implicit-fallthrough + + +# ============================================================================= + +# Definitions specific to Media SDK internal things (do not apply for samples) +include $(MFX_HOME)/android/mfx_defs_internal.mk diff --git a/android/mfx_defs_internal.mk b/android/mfx_defs_internal.mk new file mode 100644 index 00000000..334d2cbb --- /dev/null +++ b/android/mfx_defs_internal.mk @@ -0,0 +1,51 @@ +# Purpose: +# Defines include paths, compilation flags, etc. to build Media SDK +# internal targets (libraries, test applications, etc.). +# +# Defined variables: +# MFX_CFLAGS_INTERNAL - all flags needed to build MFX targets +# MFX_CFLAGS_INTERNAL_HW - all flags needed to build MFX HW targets +# MFX_INCLUDES_INTERNAL - all include paths needed to build MFX targets +# MFX_INCLUDES_INTERNAL_HW - all include paths needed to build MFX HW targets + +MFX_CFLAGS_INTERNAL := $(MFX_CFLAGS) +MFX_CFLAGS_INTERNAL_HW := \ + $(MFX_CFLAGS_INTERNAL) \ + -DMFX_VA \ + -DMFX_ONEVPL \ + -DMFX_VERSION_USE_LATEST \ + -DMFX_DEPRECATED_OFF \ + -DONEVPL_EXPERIMENTAL \ + -DSYNCHRONIZATION_BY_VA_SYNC_SURFACE \ + -D_FILE_OFFSET_BITS=64 \ + -D__USE_LARGEFILE64 \ + -DMFX_GIT_COMMIT=\"c6573984\" \ + -DMFX_API_VERSION=\"2.9+\" \ + -DNDEBUG \ + -DMSDK_BUILD=\"\" + +MFX_CFLAGS_INTERNAL_32 := -DLINUX32 +MFX_CFLAGS_INTERNAL_64 := -DLINUX32 -DLINUX64 + +MFX_INCLUDES_INTERNAL := \ + $(MFX_INCLUDES) \ + $(MFX_HOME)/_studio/shared/include \ + $(MFX_HOME)/_studio/shared/umc/codec/av1_dec/include \ + $(MFX_HOME)/_studio/shared/umc/codec/h265_dec/include \ + $(MFX_HOME)/_studio/shared/umc/codec/h264_dec/include \ + $(MFX_HOME)/_studio/shared/umc/codec/vp9_dec/include \ + $(MFX_HOME)/_studio/shared/umc/core/umc/include \ + $(MFX_HOME)/_studio/shared/umc/core/vm/include \ + $(MFX_HOME)/_studio/shared/umc/core/vm_plus/include \ + $(MFX_HOME)/_studio/shared/umc/io/umc_va/include \ + $(MFX_HOME)/_studio/shared/mfx_logging/include \ + $(MFX_HOME)/_studio/shared/mfx_trace/include \ + $(MFX_HOME)/_studio/shared/mfx_trace/include/sys \ + $(MFX_HOME)/_studio/mfx_lib/shared/include \ + $(MFX_HOME)/_studio/shared/include \ + $(MFX_HOME)/_studio/enctools/aenc/include \ + $(MFX_HOME)/_studio/enctools/include \ + $(MFX_HOME)/contrib/ipp/include + +MFX_INCLUDES_INTERNAL_HW := \ + $(MFX_INCLUDES_INTERNAL) \ From eeadd67acc565ee40a6e07fe85c3e67c40721bf3 Mon Sep 17 00:00:00 2001 From: sjshweta Date: Wed, 8 May 2024 12:56:00 +0530 Subject: [PATCH 04/16] Added github workflows for CI --- .github/ISSUE_TEMPLATE/1-bug.yml | 83 ------ .github/ISSUE_TEMPLATE/2-feature.yml | 46 ---- .github/workflows/run_ci_checks.yaml | 15 ++ .github/workflows/ubuntu.yml | 363 --------------------------- 4 files changed, 15 insertions(+), 492 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/1-bug.yml delete mode 100644 .github/ISSUE_TEMPLATE/2-feature.yml create mode 100644 .github/workflows/run_ci_checks.yaml delete mode 100644 .github/workflows/ubuntu.yml diff --git a/.github/ISSUE_TEMPLATE/1-bug.yml b/.github/ISSUE_TEMPLATE/1-bug.yml deleted file mode 100644 index d3e19d8a..00000000 --- a/.github/ISSUE_TEMPLATE/1-bug.yml +++ /dev/null @@ -1,83 +0,0 @@ -name: Bug Issue -description: Use template to submit a Bug -title: "[Bug]: " -assignees: - - yefeizhou -body: -- type: dropdown - id: component - attributes: - label: Which component impacted? - multiple: true - options: - - Decode - - Encode - - Video Processing - - Build - - Not sure -- type: dropdown - id: regression - attributes: - label: Is it regression? Good in old configuration? - multiple: false - options: - - Yes, it's good in old version - - No, this issue exist a long time -- type: textarea - attributes: - label: What happened? - description: | - Please provide reproduce steps and sample cmdline if possible which help us to debug it. - If it's regression, please provide good/bad commit/configuration. - placeholder: | - 1. In Linux or Windows or Browser or Applications... - 2. With libva/libva-utils/gmmlib/media-driver version... - 3. Run '...' - 4. See error... - validations: - required: true -- type: dropdown - id: usage - attributes: - label: What's the usage scenario when you are seeing the problem? - multiple: true - options: - - Transcode for media delivery - - Playback - - Web browser - - Cloud Gaming - - Video Analytics - - Video Conference - - Immersive Media - - Content Creation - - Game Streaming - - Others - validations: - required: true -- type: textarea - attributes: - label: What impacted? - description: Any program or milestone would be impacted if issue yet resolved? Please provide the information as detail as possible to help us understand and prioritize the issues. - placeholder: If you select "Others" for above usage, please describe your usage scenario here to help us understand the impact. - validations: - required: false -- type: textarea - attributes: - label: Debug Information - description: | - Please provide debug information as detail as possible to accelerate issue resolved. - 1. What's libva/libva-utils/gmmlib/media-driver version? - 2. Could you confirm whether GPU hardware exist or not by `ls /dev/dri`? - 3. Could you provide vainfo log by `vainfo >vainfo.log 2>&1`? - 4. Could you provide libva trace log? Run cmd `export LIBVA_TRACE=/tmp/libva_trace.log` first then execute the case. - 5. Could you attach dmesg log if GPU hang by `dmesg >dmesg.log 2>&1`? - validations: - required: false -- type: dropdown - id: contribute - attributes: - label: Do you want to contribute a patch to fix the issue? - multiple: false - options: - - Yes, I'm glad to submit a patch to fix it - - No. diff --git a/.github/ISSUE_TEMPLATE/2-feature.yml b/.github/ISSUE_TEMPLATE/2-feature.yml deleted file mode 100644 index 9812490e..00000000 --- a/.github/ISSUE_TEMPLATE/2-feature.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Feature Request -description: Use template to request a new feature -title: "[Feature]: " -labels: ["Feature Request"] -assignees: - - yefeizhou -body: -- type: textarea - attributes: - label: What Feature? - description: Please describe what feature you request and more background why you need this feature. - validations: - required: true -- type: dropdown - id: usage - attributes: - label: What's the usage scenario would be benifited? - multiple: true - options: - - Transcode for media delivery - - Playback - - Web browser - - Cloud Gaming - - Video Analytics - - Video Conference - - Immersive Media - - Content Creation - - Game Streaming - - Others - validations: - required: true -- type: textarea - attributes: - label: What impacted? - description: Any program or milestone would be benifited once the feature is enabled. Please provide the information as detail as possible to help us understand and prioritize the feature request. - placeholder: If you select "Others" for above usage, please describe your usage scenario here to help us understand the impact. - validations: - required: false -- type: dropdown - id: contribute - attributes: - label: Do you want to contribute a patch to develop this feature? - multiple: false - options: - - Yes, I'm glad to submit a patch for it - - No. \ No newline at end of file diff --git a/.github/workflows/run_ci_checks.yaml b/.github/workflows/run_ci_checks.yaml new file mode 100644 index 00000000..30c59f16 --- /dev/null +++ b/.github/workflows/run_ci_checks.yaml @@ -0,0 +1,15 @@ +--- +name: Run CI checks +on: + pull_request: + types: "**" + branches: "**" + pull_request_review: + types: "**" + branches: "**" +permissions: read-all +jobs: + TriggerWorkfows: + uses: projectceladon/celadonworkflows/.github/workflows/trigger_ci.yml@v1.0 + with: + EVENT: ${{ toJSON(github.event) }} \ No newline at end of file diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml deleted file mode 100644 index 7191349a..00000000 --- a/.github/workflows/ubuntu.yml +++ /dev/null @@ -1,363 +0,0 @@ -name: ci - -on: [ push, pull_request ] - -env: - CFLAGS: -O2 -Wformat -Wformat-security -Wall -Werror -D_FORTIFY_SOURCE=2 -fstack-protector-strong - LDFLAGS: -Wl,--as-needed - -jobs: - clang14: - runs-on: ubuntu-22.04 - env: - CC: /usr/bin/clang-14 - CXX: /usr/bin/clang++-14 - ASM: /usr/bin/clang-14 - steps: - - name: checkout libmfxgen - uses: actions/checkout@v2 - with: - path: libmfxgen - - name: checkout libva - uses: actions/checkout@v2 - with: - repository: intel/libva - path: libva - - name: install toolchain - run: | - if [[ -e $CC && -e $CXX ]]; then \ - echo "clang-14 already presents in the image"; \ - else \ - echo "clang-14 missed in the image, installing from llvm"; \ - echo "deb [trusted=yes] https://apt.llvm.org/jammy/ llvm-toolchain-jammy-14 main" | sudo tee -a /etc/apt/sources.list; \ - sudo apt-get update; \ - sudo apt-get install -y --no-install-recommends clang-14; \ - fi - - name: install prerequisites - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - cmake \ - libdrm-dev \ - libegl1-mesa-dev \ - libgl1-mesa-dev \ - libx11-dev \ - libx11-xcb-dev \ - libxcb-dri3-dev \ - libxcb-present-dev \ - libxext-dev \ - libxfixes-dev \ - libwayland-dev \ - ninja-build \ - make - - name: print tools versions - run: | - cmake --version - $CC --version - $CXX --version - - name: build libva - run: | - cd libva - ./autogen.sh --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu - make -j$(nproc) - sudo make install - - name: build libmfxgen - run: | - cd libmfxgen - mkdir build && cd build - cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DMFX_ENABLE_PXP=ON -DCMAKE_C_FLAGS_RELEASE="$CFLAGS" -DCMAKE_CXX_FLAGS_RELEASE="$CFLAGS" .. - ninja - sudo ninja install - - clang14-enctools-full: - runs-on: ubuntu-22.04 - env: - CC: /usr/bin/clang-14 - CXX: /usr/bin/clang++-14 - ASM: /usr/bin/clang-14 - steps: - - name: checkout libmfxgen - uses: actions/checkout@v2 - with: - path: libmfxgen - - name: checkout libva - uses: actions/checkout@v2 - with: - repository: intel/libva - path: libva - - name: install toolchain - run: | - if [[ -e $CC && -e $CXX ]]; then \ - echo "clang-14 already presents in the image"; \ - else \ - echo "clang-14 missed in the image, installing from llvm"; \ - echo "deb [trusted=yes] https://apt.llvm.org/jammy/ llvm-toolchain-jammy-14 main" | sudo tee -a /etc/apt/sources.list; \ - sudo apt-get update; \ - sudo apt-get install -y --no-install-recommends clang-14; \ - fi - - name: install prerequisites - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - cmake \ - libdrm-dev \ - libegl1-mesa-dev \ - libgl1-mesa-dev \ - libx11-dev \ - libx11-xcb-dev \ - libxcb-dri3-dev \ - libxcb-present-dev \ - libxext-dev \ - libxfixes-dev \ - libwayland-dev \ - ninja-build \ - make - - name: print tools versions - run: | - cmake --version - $CC --version - $CXX --version - - name: build libva - run: | - cd libva - ./autogen.sh --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu - make -j$(nproc) - sudo make install - - name: build libmfxgen - run: | - cd libmfxgen - mkdir build && cd build - cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE="$CFLAGS" -DCMAKE_CXX_FLAGS_RELEASE="$CFLAGS" \ - -DMFX_ENABLE_USER_ENCTOOLS=ON -DMFX_ENABLE_AENC=ON -DMFX_ENABLE_PXP=ON \ - .. - ninja - sudo ninja install - - clang14-enctools-noaenc: - runs-on: ubuntu-22.04 - env: - CC: /usr/bin/clang-14 - CXX: /usr/bin/clang++-14 - ASM: /usr/bin/clang-14 - steps: - - name: checkout libmfxgen - uses: actions/checkout@v2 - with: - path: libmfxgen - - name: checkout libva - uses: actions/checkout@v2 - with: - repository: intel/libva - path: libva - - name: install toolchain - run: | - if [[ -e $CC && -e $CXX ]]; then \ - echo "clang-14 already presents in the image"; \ - else \ - echo "clang-14 missed in the image, installing from llvm"; \ - echo "deb [trusted=yes] https://apt.llvm.org/jammy/ llvm-toolchain-jammy-14 main" | sudo tee -a /etc/apt/sources.list; \ - sudo apt-get update; \ - sudo apt-get install -y --no-install-recommends clang-14; \ - fi - - name: install prerequisites - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - cmake \ - libdrm-dev \ - libegl1-mesa-dev \ - libgl1-mesa-dev \ - libx11-dev \ - libx11-xcb-dev \ - libxcb-dri3-dev \ - libxcb-present-dev \ - libxext-dev \ - libxfixes-dev \ - libwayland-dev \ - ninja-build \ - make - - name: print tools versions - run: | - cmake --version - $CC --version - $CXX --version - - name: build libva - run: | - cd libva - ./autogen.sh --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu - make -j$(nproc) - sudo make install - - name: build libmfxgen - run: | - cd libmfxgen - mkdir build && cd build - cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE="$CFLAGS" -DCMAKE_CXX_FLAGS_RELEASE="$CFLAGS" \ - -DMFX_ENABLE_USER_ENCTOOLS=ON -DMFX_ENABLE_AENC=OFF -DMFX_ENABLE_PXP=ON \ - .. - ninja - sudo ninja install - - clang12: - runs-on: ubuntu-20.04 - env: - CC: /usr/bin/clang-12 - CXX: /usr/bin/clang++-12 - ASM: /usr/bin/clang-12 - steps: - - name: checkout libmfxgen - uses: actions/checkout@v2 - with: - path: libmfxgen - - name: checkout libva - uses: actions/checkout@v2 - with: - repository: intel/libva - path: libva - - name: install prerequisites - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - cmake \ - libdrm-dev \ - libegl1-mesa-dev \ - libgl1-mesa-dev \ - libx11-dev \ - libx11-xcb-dev \ - libxcb-dri3-dev \ - libxcb-present-dev \ - libxext-dev \ - libxfixes-dev \ - libwayland-dev \ - ninja-build \ - make - - name: print tools versions - run: | - cmake --version - $CC --version - $CXX --version - - name: build libva - run: | - cd libva - ./autogen.sh --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu - make -j$(nproc) - sudo make install - - name: build libmfxgen - run: | - cd libmfxgen - mkdir build && cd build - cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DMFX_ENABLE_PXP=ON -DCMAKE_C_FLAGS_RELEASE="$CFLAGS" -DCMAKE_CXX_FLAGS_RELEASE="$CFLAGS" .. - ninja - sudo ninja install - - gcc11: - runs-on: ubuntu-22.04 - env: - CC: /usr/bin/gcc-11 - CXX: /usr/bin/g++-11 - ASM: /usr/bin/gcc-11 - # TODO: mind no -Werror - # We stepped into https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100366 - # gcc-11 throws -Wstringop-overflow on some std:: operations - CFLAGS: -O2 -Wformat -Wformat-security -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong - steps: - - name: checkout libmfxgen - uses: actions/checkout@v2 - with: - path: libmfxgen - - name: checkout libva - uses: actions/checkout@v2 - with: - repository: intel/libva - path: libva - - name: install prerequisites - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - automake \ - cmake \ - gcc \ - g++ \ - libtool \ - libdrm-dev \ - libegl1-mesa-dev \ - libgl1-mesa-dev \ - libx11-dev \ - libx11-xcb-dev \ - libxcb-dri3-dev \ - libxcb-present-dev \ - libxext-dev \ - libxfixes-dev \ - libwayland-dev \ - ninja-build \ - pkg-config \ - make - - name: print tools versions - run: | - cmake --version - $CC --version - $CXX --version - - name: build libva - run: | - cd libva - ./autogen.sh --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu - make -j$(nproc) - sudo make install - - name: build libmfxgen - run: | - cd libmfxgen - mkdir build && cd build - cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DMFX_ENABLE_PXP=ON -DCMAKE_C_FLAGS_RELEASE="$CFLAGS" -DCMAKE_CXX_FLAGS_RELEASE="$CFLAGS" .. - ninja - sudo ninja install - - gcc10: - runs-on: ubuntu-20.04 - env: - CC: /usr/bin/gcc-10 - CXX: /usr/bin/g++-10 - ASM: /usr/bin/gcc-10 - steps: - - name: checkout libmfxgen - uses: actions/checkout@v2 - with: - path: libmfxgen - - name: checkout libva - uses: actions/checkout@v2 - with: - repository: intel/libva - path: libva - - name: install prerequisites - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - cmake \ - libdrm-dev \ - libegl1-mesa-dev \ - libgl1-mesa-dev \ - libx11-dev \ - libx11-xcb-dev \ - libxcb-dri3-dev \ - libxcb-present-dev \ - libxext-dev \ - libxfixes-dev \ - libwayland-dev \ - ninja-build \ - make - - name: print tools versions - run: | - cmake --version - $CC --version - $CXX --version - - name: build libva - run: | - cd libva - ./autogen.sh --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu - make -j$(nproc) - sudo make install - - name: build libmfxgen - run: | - cd libmfxgen - mkdir build && cd build - cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DMFX_ENABLE_PXP=ON -DCMAKE_C_FLAGS_RELEASE="$CFLAGS" -DCMAKE_CXX_FLAGS_RELEASE="$CFLAGS" .. - ninja - sudo ninja install From 68bbe35a6f52312e53344f44a26e97c9a196971d Mon Sep 17 00:00:00 2001 From: Lina Sun Date: Fri, 31 May 2024 03:00:06 +0000 Subject: [PATCH 05/16] [encode] Allow GPB set to off for HEVC encode Some CTS tests of android.videocodec.cts.VideoEncoderMaxBFrameTest# testMaxBFrameSupport failed with "Number of BFrames in a SubGOP exceeds maximum number of BFrames configured". Cause is for HEVC encode, CO3->GPB is set to "on" by default, which makes GPB frames are used instead of P frames. In CTS test, GPB frames are considered B frames. Solution is for HEVC encode, set CO3->GPB to "off" in mediasdk_c2 to use P frames not GPB frames. But in onevpl-intel-gpu, HEVC encode caps did not enable "GPB off" before, change HEVC encode caps to enable it. Tracked-On: OAM-118626 Signed-off-by: Lina Sun --- .../encode_hw/hevc/agnostic/base/hevcehw_base_iddi_packer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_studio/mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_iddi_packer.h b/_studio/mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_iddi_packer.h index 32bd38cb..92f49d5c 100644 --- a/_studio/mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_iddi_packer.h +++ b/_studio/mfx_lib/encode_hw/hevc/agnostic/base/hevcehw_base_iddi_packer.h @@ -61,7 +61,7 @@ class IDDIPacker void HardcodeCapsCommon(EncodeCapsHevc& caps, const mfxVideoParam& par) { caps.SliceIPOnly = IsOn(par.mfx.LowPower); - caps.msdk.PSliceSupport = false; + caps.msdk.PSliceSupport = true; } }; From eb33d91148bcb0e8497c57fe35f96ba6492814e8 Mon Sep 17 00:00:00 2001 From: Nana Zhang Date: Fri, 21 Jun 2024 16:56:29 +0000 Subject: [PATCH 06/16] Fix Cts avc profile level test Value: MFX_LEVEL_AVC_1:10 MFX_LEVEL_AVC_1b:9 The functions `GetLevelLimitByDpbSize()`, `GetLevelLimitByFrameSize()`, `GetLevelLimitByMbps()`, and `GetLevelLimitByMaxBitrate()` return the minimum level according to the frame size, FPS and profile. Since the capability of level MFX_LEVEL_AVC_1b is greater than level MFX_LEVEL_AVC_1, the CodecLevel should not be updated in this case. Cases: 1.android.media.recorder.cts.MediaRecorderTest#testProfileAvcBaselineLevel1 2.android.mediav2.cts.EncoderProfileLevelTest#testValidateProfileLevel [8_c2.intel.avc.encoder_video/avc_128kbps_176x144_15fps_yuv420flexible_2_0-bframes] 3.android.mediav2.cts.EncoderProfileLevelTest#testValidateProfileLevel [10_c2.intel.avc.encoder_video/avc_128kbps_176x144_15fps_yuv420flexible_2_2-bframes] Tracked-On: OAM-119037 Signed-off-by: Nana Zhang --- .../h264/src/mfx_h264_enc_common_hw.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/_studio/mfx_lib/encode_hw/h264/src/mfx_h264_enc_common_hw.cpp b/_studio/mfx_lib/encode_hw/h264/src/mfx_h264_enc_common_hw.cpp index 90cca8a3..3fcb8fa3 100644 --- a/_studio/mfx_lib/encode_hw/h264/src/mfx_h264_enc_common_hw.cpp +++ b/_studio/mfx_lib/encode_hw/h264/src/mfx_h264_enc_common_hw.cpp @@ -3056,7 +3056,7 @@ mfxStatus MfxHwH264Encode::CheckVideoParamQueryLike( par.mfx.CodecLevel = GetMaxSupportedLevel(); } } - else if (par.mfx.CodecLevel != 0 && par.mfx.CodecLevel < minLevel) + else if (par.mfx.CodecLevel != 0 && (par.mfx.CodecLevel != MFX_LEVEL_AVC_1b || minLevel != MFX_LEVEL_AVC_1) && par.mfx.CodecLevel < minLevel) { if (extBits->SPSBuffer) MFX_RETURN(Error(MFX_ERR_INCOMPATIBLE_VIDEO_PARAM)); @@ -3086,7 +3086,7 @@ mfxStatus MfxHwH264Encode::CheckVideoParamQueryLike( par.mfx.CodecLevel = GetMaxSupportedLevel(); } } - else if (par.mfx.CodecLevel != 0 && par.mfx.CodecLevel < minLevel) + else if (par.mfx.CodecLevel != 0 && (par.mfx.CodecLevel != MFX_LEVEL_AVC_1b || minLevel != MFX_LEVEL_AVC_1) && par.mfx.CodecLevel < minLevel) { if (extBits->SPSBuffer) MFX_RETURN(Error(MFX_ERR_INCOMPATIBLE_VIDEO_PARAM)); @@ -3110,7 +3110,7 @@ mfxStatus MfxHwH264Encode::CheckVideoParamQueryLike( par.mfx.CodecLevel = MFX_LEVEL_AVC_52; par.mfx.NumRefFrame = GetMaxNumRefFrame(par); } - else if (par.mfx.CodecLevel != 0 && par.mfx.CodecLevel < minLevel) + else if (par.mfx.CodecLevel != 0 && (par.mfx.CodecLevel != MFX_LEVEL_AVC_1b || minLevel != MFX_LEVEL_AVC_1) && par.mfx.CodecLevel < minLevel) { if (extBits->SPSBuffer) MFX_RETURN(Error(MFX_ERR_INCOMPATIBLE_VIDEO_PARAM)); @@ -3482,7 +3482,7 @@ mfxStatus MfxHwH264Encode::CheckVideoParamQueryLike( { if (mfxU16 minLevel = GetLevelLimitByMaxBitrate(profile, par.calcParam.targetKbps)) { - if (par.mfx.CodecLevel != 0 && par.mfx.CodecProfile != 0 && par.mfx.CodecLevel < minLevel) + if (par.mfx.CodecLevel != 0 && par.mfx.CodecProfile != 0 && (par.mfx.CodecLevel != MFX_LEVEL_AVC_1b || minLevel != MFX_LEVEL_AVC_1) && par.mfx.CodecLevel < minLevel) { if (extBits->SPSBuffer) MFX_RETURN(Error(MFX_ERR_INCOMPATIBLE_VIDEO_PARAM)); @@ -3554,7 +3554,7 @@ mfxStatus MfxHwH264Encode::CheckVideoParamQueryLike( { if (mfxU16 minLevel = GetLevelLimitByMaxBitrate(profile, par.calcParam.maxKbps)) { - if (par.mfx.CodecLevel != 0 && par.mfx.CodecProfile != 0 && par.mfx.CodecLevel < minLevel) + if (par.mfx.CodecLevel != 0 && par.mfx.CodecProfile != 0 && (par.mfx.CodecLevel != MFX_LEVEL_AVC_1b || minLevel != MFX_LEVEL_AVC_1) && par.mfx.CodecLevel < minLevel) { if (extBits->SPSBuffer) MFX_RETURN(Error(MFX_ERR_INCOMPATIBLE_VIDEO_PARAM)); @@ -3644,7 +3644,7 @@ mfxStatus MfxHwH264Encode::CheckVideoParamQueryLike( { if (mfxU16 minLevel = GetLevelLimitByBufferSize(profile, par.calcParam.bufferSizeInKB)) { - if (par.mfx.CodecLevel != 0 && par.mfx.CodecProfile != 0 && par.mfx.CodecLevel < minLevel) + if (par.mfx.CodecLevel != 0 && par.mfx.CodecProfile != 0 && (par.mfx.CodecLevel != MFX_LEVEL_AVC_1b || minLevel != MFX_LEVEL_AVC_1) && par.mfx.CodecLevel < minLevel) { if (extBits->SPSBuffer) MFX_RETURN(Error(MFX_ERR_INCOMPATIBLE_VIDEO_PARAM)); @@ -3698,7 +3698,7 @@ mfxStatus MfxHwH264Encode::CheckVideoParamQueryLike( { if (mfxU16 minLevel = GetLevelLimitByMaxBitrate(profile, par.calcParam.decorativeHrdParam.targetKbps)) { - if (par.mfx.CodecLevel != 0 && par.mfx.CodecProfile != 0 && par.mfx.CodecLevel < minLevel) + if (par.mfx.CodecLevel != 0 && par.mfx.CodecProfile != 0 && (par.mfx.CodecLevel != MFX_LEVEL_AVC_1b || minLevel != MFX_LEVEL_AVC_1) && par.mfx.CodecLevel < minLevel) { changed = true; par.mfx.CodecLevel = minLevel; @@ -3728,7 +3728,7 @@ mfxStatus MfxHwH264Encode::CheckVideoParamQueryLike( { if (mfxU16 minLevel = GetLevelLimitByMaxBitrate(profile, par.calcParam.decorativeHrdParam.maxKbps)) { - if (par.mfx.CodecLevel != 0 && par.mfx.CodecProfile != 0 && par.mfx.CodecLevel < minLevel) + if (par.mfx.CodecLevel != 0 && par.mfx.CodecProfile != 0 && (par.mfx.CodecLevel != MFX_LEVEL_AVC_1b || minLevel != MFX_LEVEL_AVC_1) && par.mfx.CodecLevel < minLevel) { changed = true; par.mfx.CodecLevel = minLevel; @@ -3752,7 +3752,7 @@ mfxStatus MfxHwH264Encode::CheckVideoParamQueryLike( { if (mfxU16 minLevel = GetLevelLimitByBufferSize(profile, par.calcParam.decorativeHrdParam.bufferSizeInKB)) { - if (par.mfx.CodecLevel != 0 && par.mfx.CodecProfile != 0 && par.mfx.CodecLevel < minLevel) + if (par.mfx.CodecLevel != 0 && par.mfx.CodecProfile != 0 && (par.mfx.CodecLevel != MFX_LEVEL_AVC_1b || minLevel != MFX_LEVEL_AVC_1) && par.mfx.CodecLevel < minLevel) { changed = true; par.mfx.CodecLevel = minLevel; From 184fadde35863c845a2349fdfd90b63858808ca0 Mon Sep 17 00:00:00 2001 From: "Zhang, YichiX" Date: Thu, 20 Jun 2024 09:41:30 +0000 Subject: [PATCH 07/16] Fixed an issue where opening renderD129 will cause a crash Temporarily change to only open renderD128. Tracked-On: OAM-121112 Signed-off-by: Zhang, YichiX --- _studio/mfx_lib/Android.mk | 2 +- _studio/mfx_lib/shared/src/libmfxsw.cpp | 113 ++++++++++++------------ 2 files changed, 58 insertions(+), 57 deletions(-) diff --git a/_studio/mfx_lib/Android.mk b/_studio/mfx_lib/Android.mk index 74faa19d..a8c0f06e 100644 --- a/_studio/mfx_lib/Android.mk +++ b/_studio/mfx_lib/Android.mk @@ -335,7 +335,7 @@ LOCAL_LDFLAGS := $(MFX_LOCAL_LDFLAGS_HW) LOCAL_CPPFLAGS += -std=c++14 LOCAL_WHOLE_STATIC_LIBRARIES := $(MFX_LOCAL_STATIC_LIBRARIES_HW) -LOCAL_SHARED_LIBRARIES := libva liblog libcutils libdrm +LOCAL_SHARED_LIBRARIES := libva liblog libcutils libdrm libva-android LOCAL_MODULE_TAGS := optional LOCAL_MODULE := libmfx-gen diff --git a/_studio/mfx_lib/shared/src/libmfxsw.cpp b/_studio/mfx_lib/shared/src/libmfxsw.cpp index d3cff5f4..1aead1cf 100644 --- a/_studio/mfx_lib/shared/src/libmfxsw.cpp +++ b/_studio/mfx_lib/shared/src/libmfxsw.cpp @@ -32,6 +32,9 @@ #include #include #include "va/drm/va_drm.h" +#include +#include "va/va_backend.h" +#include "va_drmcommon.h" #include "mediasdk_version.h" #include "libmfx_core_factory.h" @@ -610,82 +613,80 @@ GetAdapterInfo(mfxU64 adapterId) return result; } +#define MFX_VA_ANDROID_DISPLAY_ID 0x18c34078 + static bool QueryImplCaps(std::function < bool (VideoCORE&, mfxU32, mfxU32 , mfxU64, const std::vector& ) > QueryImpls) { - for (int i = 0; i < 64; ++i) - { - std::string path; - - { - mfxU32 vendorId = 0; + std::string path; - path = std::string("/sys/class/drm/renderD") + std::to_string(128 + i) + "/device/vendor"; - FILE* file = fopen(path.c_str(), "r"); + { + mfxU32 vendorId = 0; - if (!file) - break; + path = std::string("/sys/class/drm/renderD128/device/vendor"); + FILE* file = fopen(path.c_str(), "r"); - int nread = fscanf(file, "%x", &vendorId); - fclose(file); + if (!file) + return false; - if (nread != 1 || vendorId != 0x8086) - continue; - } + int nread = fscanf(file, "%x", &vendorId); + fclose(file); - mfxU32 deviceId = 0; - { - path = std::string("/sys/class/drm/renderD") + std::to_string(128 + i) + "/device/device"; - - FILE* file = fopen(path.c_str(), "r"); - if (!file) - break; + if (nread != 1 || vendorId != 0x8086) + return false; + } - int nread = fscanf(file, "%x", &deviceId); - fclose(file); + mfxU32 deviceId = 0; + { + path = std::string("/sys/class/drm/renderD128/device/device"); - if (nread != 1) - break; - } + FILE* file = fopen(path.c_str(), "r"); + if (!file) + return false; - path = std::string("/dev/dri/renderD") + std::to_string(128 + i); + int nread = fscanf(file, "%x", &deviceId); + fclose(file); - int fd = open(path.c_str(), O_RDWR); - if (fd < 0) - continue; + if (nread != 1) + return false; + } - std::shared_ptr closeFile(&fd, [fd](int*) { close(fd); }); + { + unsigned int displayId = MFX_VA_ANDROID_DISPLAY_ID; + VADisplay vaDisplay = vaGetDisplay(&displayId); + if (vaDisplay == nullptr) + return false; - { - auto displ = vaGetDisplayDRM(fd); + VADisplayContextP ctx = (VADisplayContextP)vaDisplay; + drm_state* drm = (drm_state*)ctx->pDriverContext->drm_state; + int fd = drm->fd; - int vamajor = 0, vaminor = 0; - if (VA_STATUS_SUCCESS != vaInitialize(displ, &vamajor, &vaminor)) - continue; + int vamajor = 0, vaminor = 0; + if (VA_STATUS_SUCCESS != vaInitialize(vaDisplay, &vamajor, &vaminor)) + return false; - std::shared_ptr closeVA(&displ, [displ](VADisplay*) { vaTerminate(displ); }); + std::shared_ptr closeVA(&vaDisplay, [vaDisplay](VADisplay*) { vaTerminate(vaDisplay); }); - VADisplayAttribute attr = {}; - attr.type = VADisplayAttribSubDevice; - auto sts = vaGetDisplayAttributes(displ, &attr, 1); - std::ignore = MFX_STS_TRACE(sts); + VADisplayAttribute attr = {}; + attr.type = VADisplayAttribSubDevice; + auto sts = vaGetDisplayAttributes(vaDisplay, &attr, 1); + std::ignore = MFX_STS_TRACE(sts); - VADisplayAttribValSubDevice out = {}; - out.value = attr.value; + VADisplayAttribValSubDevice out = {}; + out.value = attr.value; - std::vector subDevMask(VA_STATUS_SUCCESS == sts ? out.bits.sub_device_count : 0); - for (std::size_t id = 0; id < subDevMask.size(); ++id) - { - subDevMask[id] = !!((1 << id) & out.bits.sub_device_mask); - } - { - std::unique_ptr pCore(FactoryCORE::CreateCORE(MFX_HW_VAAPI, 0, {}, 0)); + std::vector subDevMask(VA_STATUS_SUCCESS == sts ? out.bits.sub_device_count : 0); + for (std::size_t id = 0; id < subDevMask.size(); ++id) + { + subDevMask[id] = !!((1 << id) & out.bits.sub_device_mask); + } + { + std::unique_ptr pCore(FactoryCORE::CreateCORE(MFX_HW_VAAPI, 0, {}, 0)); - if (pCore->SetHandle(MFX_HANDLE_VA_DISPLAY, (mfxHDL)displ)) - continue; + if (pCore->SetHandle(MFX_HANDLE_VA_DISPLAY, (mfxHDL)vaDisplay)) + return false; - if (!QueryImpls(*pCore, deviceId, i, fd, subDevMask)) - return false; - } + if (!QueryImpls(*pCore, deviceId, 0, fd, subDevMask)) + return false; } } return true; From 95122739e7ff99105af0d8dcabf03ac5cc17e55d Mon Sep 17 00:00:00 2001 From: "Zhang, YichiX" Date: Wed, 10 Jul 2024 02:33:44 +0000 Subject: [PATCH 08/16] Revert "[Decode] Complete cur frame in child thread to unlock res (#6509)" This reverts commit c40736a486913e4e604dbdbae042fde3d2226387. Tracked-On: OAM-118913 Signed-off-by: Shaofeng Tang --- .../decode/vp9/src/mfx_vp9_dec_decode_hw.cpp | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/_studio/mfx_lib/decode/vp9/src/mfx_vp9_dec_decode_hw.cpp b/_studio/mfx_lib/decode/vp9/src/mfx_vp9_dec_decode_hw.cpp index c248fd7f..1c88f219 100644 --- a/_studio/mfx_lib/decode/vp9/src/mfx_vp9_dec_decode_hw.cpp +++ b/_studio/mfx_lib/decode/vp9/src/mfx_vp9_dec_decode_hw.cpp @@ -276,18 +276,6 @@ class FrameStorage } } - void CompleteCurFrame(UMC::FrameMemID frameId) - { - auto find_it = std::find_if(m_submittedFrames.begin(), m_submittedFrames.end(), - [frameId](const UMC_VP9_DECODER::VP9DecoderFrame & item) { return item.currFrame == frameId; }); - - if (find_it != m_submittedFrames.end() && find_it->isDecoded) - { - UnLockResources(*find_it); - m_submittedFrames.erase(find_it); - } - } - void CompleteFrames() { for (auto it = m_submittedFrames.begin(); it != m_submittedFrames.end(); ) @@ -935,7 +923,6 @@ mfxStatus MFX_CDECL VP9DECODERoutine(void *p_state, void * /* pp_param */, mfxU3 decoder.m_surface_source->SetFreeSurfaceAllowedFlag(false); } decoder.m_framesStorage->DecodeFrame(data.currFrameId); - decoder.m_framesStorage->CompleteCurFrame(data.currFrameId); return MFX_ERR_NONE; } @@ -973,7 +960,6 @@ mfxStatus MFX_CDECL VP9DECODERoutine(void *p_state, void * /* pp_param */, mfxU3 if (data.currFrameId != -1) decoder.m_surface_source->DecreaseReference(data.currFrameId); decoder.m_framesStorage->DecodeFrame(data.currFrameId); - decoder.m_framesStorage->CompleteCurFrame(data.currFrameId); return MFX_TASK_DONE; } From dfae408d86b18d1927e1e6a1b8cfdbce3a45f3c3 Mon Sep 17 00:00:00 2001 From: "Zhang, YichiX" Date: Tue, 25 Jun 2024 13:55:48 +0000 Subject: [PATCH 09/16] Make decoding output bit format configurable In order to pass Cts#testDefaultOutputColorFormat, we need to determine the output bit format by mfxparam instead of bitstream. Tracked-On: OAM-119832 Signed-off-by: Zhang, YichiX --- .../decode/av1/src/mfx_av1_dec_decode.cpp | 1 + .../decode/vp9/src/mfx_vp9_dec_decode_hw.cpp | 5 +++++ .../codec/av1_dec/include/umc_av1_va_packer.h | 3 +++ .../codec/av1_dec/src/umc_av1_decoder_va.cpp | 1 + .../av1_dec/src/umc_av1_va_packer_vaapi.cpp | 3 +-- .../platform/umc_h265_va_packer_vaapi_g9.hpp | 7 +++++-- .../h265_dec/include/umc_h265_dec_defs.h | 21 +++++++++++++++++++ .../h265_dec/include/umc_h265_task_supplier.h | 8 ++++++- .../h265_dec/include/umc_h265_va_supplier.h | 8 ++++--- .../h265_dec/src/umc_h265_task_supplier.cpp | 11 +++++----- .../h265_dec/src/umc_h265_va_supplier.cpp | 7 ++++--- 11 files changed, 59 insertions(+), 16 deletions(-) diff --git a/_studio/mfx_lib/decode/av1/src/mfx_av1_dec_decode.cpp b/_studio/mfx_lib/decode/av1/src/mfx_av1_dec_decode.cpp index 2374108b..b41adef2 100755 --- a/_studio/mfx_lib/decode/av1/src/mfx_av1_dec_decode.cpp +++ b/_studio/mfx_lib/decode/av1/src/mfx_av1_dec_decode.cpp @@ -293,6 +293,7 @@ mfxStatus VideoDECODEAV1::Init(mfxVideoParam* par) m_core->GetVA((mfxHDL*)&m_va, MFX_MEMTYPE_FROM_DECODE); vp.pVideoAccelerator = m_va; + vp.color_config.BitDepth = FourCcBitDepth(par->mfx.FrameInfo.FourCC); ConvertMFXParamsToUMC(par, &vp); vp.info.profile = av1_mfx_profile_to_native_profile(par->mfx.CodecProfile); diff --git a/_studio/mfx_lib/decode/vp9/src/mfx_vp9_dec_decode_hw.cpp b/_studio/mfx_lib/decode/vp9/src/mfx_vp9_dec_decode_hw.cpp index 1c88f219..8d422e8f 100644 --- a/_studio/mfx_lib/decode/vp9/src/mfx_vp9_dec_decode_hw.cpp +++ b/_studio/mfx_lib/decode/vp9/src/mfx_vp9_dec_decode_hw.cpp @@ -1141,6 +1141,11 @@ mfxStatus VideoDECODEVP9_HW::DecodeFrameCheck(mfxBitstream *bs, mfxFrameSurface1 VP9DecoderFrame frameInfo = m_frameInfo; sts = DecodeFrameHeader(bs, frameInfo); + + // XXX: Overwrite profile and bit_depth from mfxparam so that we can configure + // the output bit format. + frameInfo.profile = m_vPar.mfx.CodecProfile - 1; + frameInfo.bit_depth = m_vPar.mfx.FrameInfo.BitDepthLuma; MFX_CHECK_STS(sts); MFX_VP9_Utility::FillVideoParam(m_core->GetPlatformType(), frameInfo, m_vPar); diff --git a/_studio/shared/umc/codec/av1_dec/include/umc_av1_va_packer.h b/_studio/shared/umc/codec/av1_dec/include/umc_av1_va_packer.h index c2cf35b3..93c9ccdc 100644 --- a/_studio/shared/umc/codec/av1_dec/include/umc_av1_va_packer.h +++ b/_studio/shared/umc/codec/av1_dec/include/umc_av1_va_packer.h @@ -53,12 +53,15 @@ class Packer virtual void PackAU(std::vector&, AV1DecoderFrame const&, bool) = 0; virtual void RegisterAnchor(UMC::FrameMemID) = 0; + mfxU16 GetBitDepth() { return m_bitDepth; } + void SetBitDepth(mfxU16 bitDepth) { m_bitDepth = bitDepth; } static Packer* CreatePacker(UMC::VideoAccelerator * va); protected: UMC::VideoAccelerator *m_va; + mfxU16 m_bitDepth = 8; }; } // namespace UMC_AV1_DECODER diff --git a/_studio/shared/umc/codec/av1_dec/src/umc_av1_decoder_va.cpp b/_studio/shared/umc/codec/av1_dec/src/umc_av1_decoder_va.cpp index d24d85a2..5db8170b 100755 --- a/_studio/shared/umc/codec/av1_dec/src/umc_av1_decoder_va.cpp +++ b/_studio/shared/umc/codec/av1_dec/src/umc_av1_decoder_va.cpp @@ -57,6 +57,7 @@ namespace UMC_AV1_DECODER va = dp->pVideoAccelerator; packer.reset(Packer::CreatePacker(va)); + packer->SetBitDepth(dp->color_config.BitDepth); uint32_t dpb_size = std::max(params.async_depth + TOTAL_REFS, 8u); diff --git a/_studio/shared/umc/codec/av1_dec/src/umc_av1_va_packer_vaapi.cpp b/_studio/shared/umc/codec/av1_dec/src/umc_av1_va_packer_vaapi.cpp index 07e681fd..b42f864e 100755 --- a/_studio/shared/umc/codec/av1_dec/src/umc_av1_va_packer_vaapi.cpp +++ b/_studio/shared/umc/codec/av1_dec/src/umc_av1_va_packer_vaapi.cpp @@ -180,8 +180,7 @@ namespace UMC_AV1_DECODER seqInfo.film_grain_params_present = sh.film_grain_param_present; picParam.matrix_coefficients = sh.color_config.matrix_coefficients; - picParam.bit_depth_idx = (sh.color_config.BitDepth == 10) ? 1 : - (sh.color_config.BitDepth == 12) ? 2 : 0; + picParam.bit_depth_idx = (m_bitDepth == 10) ? 1 : (m_bitDepth == 12) ? 2 : 0; picParam.order_hint_bits_minus_1 = (uint8_t)sh.order_hint_bits_minus1; // fill pic params diff --git a/_studio/shared/umc/codec/h265_dec/include/platform/umc_h265_va_packer_vaapi_g9.hpp b/_studio/shared/umc/codec/h265_dec/include/platform/umc_h265_va_packer_vaapi_g9.hpp index fdfe92cd..6178cdcc 100644 --- a/_studio/shared/umc/codec/h265_dec/include/platform/umc_h265_va_packer_vaapi_g9.hpp +++ b/_studio/shared/umc/codec/h265_dec/include/platform/umc_h265_va_packer_vaapi_g9.hpp @@ -181,8 +181,6 @@ namespace UMC_HEVC_DECODER pic_fields.NoBiPredFlag = 0; pp->sps_max_dec_pic_buffering_minus1 = (uint8_t)(sps->sps_max_dec_pic_buffering[sh->nuh_temporal_id] - 1); - pp->bit_depth_luma_minus8 = (uint8_t)(sps->bit_depth_luma - 8); - pp->bit_depth_chroma_minus8 = (uint8_t)(sps->bit_depth_chroma - 8); pp->pcm_sample_bit_depth_luma_minus1 = (uint8_t)(sps->pcm_sample_bit_depth_luma - 1); pp->pcm_sample_bit_depth_chroma_minus1 = (uint8_t)(sps->pcm_sample_bit_depth_chroma - 1); pp->log2_min_luma_coding_block_size_minus3 = (uint8_t)(sps->log2_min_luma_coding_block_size- 3); @@ -441,6 +439,11 @@ namespace UMC_HEVC_DECODER VAPictureParameterBufferHEVC* pp = nullptr; PeekParamsBuffer(m_va, &pp); + // XXX: Get bit_depth from mfxParam instead of bitstream so that we can configure + // the output bit format. + pp->bit_depth_luma_minus8 = color_format2bit_depth(supplier->GetColorformat()) - 8; + pp->bit_depth_chroma_minus8 = color_format2bit_depth(supplier->GetColorformat()) - 8; + PackPicHeader(m_va, frame, dpb, pp); } diff --git a/_studio/shared/umc/codec/h265_dec/include/umc_h265_dec_defs.h b/_studio/shared/umc/codec/h265_dec/include/umc_h265_dec_defs.h index 11ddc4ea..73de7a26 100644 --- a/_studio/shared/umc/codec/h265_dec/include/umc_h265_dec_defs.h +++ b/_studio/shared/umc/codec/h265_dec/include/umc_h265_dec_defs.h @@ -1492,6 +1492,27 @@ inline size_t CalculateSuggestedSize(const H265SeqParamSet * sps) return 2*size; } +inline +mfxU16 color_format2bit_depth(UMC::ColorFormat format) +{ + switch (format) + { + case UMC::NV12: + case UMC::YUY2: + case UMC::AYUV: return 8; + + case UMC::P010: + case UMC::Y210: + case UMC::Y410: return 10; + + case UMC::P016: + case UMC::Y216: + case UMC::Y416: return 12; + + default: return 0; + } +} + } // end namespace UMC_HEVC_DECODER #endif // H265_GLOBAL_ROM_H diff --git a/_studio/shared/umc/codec/h265_dec/include/umc_h265_task_supplier.h b/_studio/shared/umc/codec/h265_dec/include/umc_h265_task_supplier.h index 8bd51d1a..2fe8d652 100644 --- a/_studio/shared/umc/codec/h265_dec/include/umc_h265_task_supplier.h +++ b/_studio/shared/umc/codec/h265_dec/include/umc_h265_task_supplier.h @@ -374,6 +374,11 @@ class TaskSupplier_H265 : public Skipping_H265, public AU_Splitter_H265, public return &m_ObjHeap; } + UMC::ColorFormat GetColorformat() + { + return m_initializationParams.info.color_format; + } + protected: // Include a new slice into a set of frame slices @@ -412,7 +417,8 @@ class TaskSupplier_H265 : public Skipping_H265, public AU_Splitter_H265, public virtual UMC::Status AddOneFrame(UMC::MediaData * pSource); // Allocate frame internals - virtual UMC::Status AllocateFrameData(H265DecoderFrame * pFrame, mfxSize dimensions, const H265SeqParamSet* pSeqParamSet, const H265PicParamSet *pPicParamSet); + virtual UMC::Status AllocateFrameData(H265DecoderFrame * pFrame, mfxSize dimensions, + const H265SeqParamSet* pSeqParamSet, const H265PicParamSet *pPicParamSet, UMC::ColorFormat colorFormat); // Decode a bitstream header NAL unit virtual UMC::Status DecodeHeaders(UMC::MediaDataEx *nalUnit); diff --git a/_studio/shared/umc/codec/h265_dec/include/umc_h265_va_supplier.h b/_studio/shared/umc/codec/h265_dec/include/umc_h265_va_supplier.h index 9be27b94..717d1ee3 100644 --- a/_studio/shared/umc/codec/h265_dec/include/umc_h265_va_supplier.h +++ b/_studio/shared/umc/codec/h265_dec/include/umc_h265_va_supplier.h @@ -59,7 +59,8 @@ class VATaskSupplier : protected: - virtual UMC::Status AllocateFrameData(H265DecoderFrame * pFrame, mfxSize dimensions, const H265SeqParamSet* pSeqParamSet, const H265PicParamSet *pPicParamSet); + virtual UMC::Status AllocateFrameData(H265DecoderFrame * pFrame, mfxSize dimensions, const H265SeqParamSet* pSeqParamSet, + const H265PicParamSet *pPicParamSet, UMC::ColorFormat colorFormat); virtual void InitFrameCounter(H265DecoderFrame * pFrame, const H265Slice *pSlice); @@ -92,9 +93,10 @@ class VATaskSupplierBigSurfacePool: protected: - virtual UMC::Status AllocateFrameData(H265DecoderFrame * pFrame, mfxSize dimensions, const H265SeqParamSet* pSeqParamSet, const H265PicParamSet * pps) + virtual UMC::Status AllocateFrameData(H265DecoderFrame * pFrame, mfxSize dimensions, const H265SeqParamSet* pSeqParamSet, + const H265PicParamSet * pps, UMC::ColorFormat colorFormat) { - UMC::Status ret = BaseClass::AllocateFrameData(pFrame, dimensions, pSeqParamSet, pps); + UMC::Status ret = BaseClass::AllocateFrameData(pFrame, dimensions, pSeqParamSet, pps, colorFormat); if (ret == UMC::UMC_OK) { diff --git a/_studio/shared/umc/codec/h265_dec/src/umc_h265_task_supplier.cpp b/_studio/shared/umc/codec/h265_dec/src/umc_h265_task_supplier.cpp index 83d55488..492dec59 100755 --- a/_studio/shared/umc/codec/h265_dec/src/umc_h265_task_supplier.cpp +++ b/_studio/shared/umc/codec/h265_dec/src/umc_h265_task_supplier.cpp @@ -2454,12 +2454,12 @@ UMC::Status TaskSupplier_H265::InitFreeFrame(H265DecoderFrame * pFrame, const H2 } // Allocate frame internals -UMC::Status TaskSupplier_H265::AllocateFrameData(H265DecoderFrame * pFrame, mfxSize dimensions, const H265SeqParamSet* pSeqParamSet, const H265PicParamSet *pPicParamSet) +UMC::Status TaskSupplier_H265::AllocateFrameData(H265DecoderFrame * pFrame, mfxSize dimensions, const H265SeqParamSet* pSeqParamSet, + const H265PicParamSet *pPicParamSet, UMC::ColorFormat colorFormat) { - UMC::ColorFormat color_format = pFrame->GetColorFormat(); - //(ColorFormat) pSeqParamSet->chroma_format_idc; + UMC::ColorFormat color_format = colorFormat; UMC::VideoDataInfo info; - int32_t bit_depth = pSeqParamSet->need16bitOutput ? 10 : 8; + int32_t bit_depth = color_format2bit_depth(color_format); info.Init(dimensions.width, dimensions.height, color_format, bit_depth); UMC::FrameMemID frmMID; @@ -2520,7 +2520,8 @@ H265DecoderFrame * TaskSupplier_H265::AllocateNewFrame(const H265Slice *pSlice) return 0; } - umcRes = AllocateFrameData(pFrame, pFrame->lumaSize(), pSlice->GetSeqParam(), pSlice->GetPicParam()); + umcRes = AllocateFrameData(pFrame, pFrame->lumaSize(), pSlice->GetSeqParam(), pSlice->GetPicParam(), + m_initializationParams.info.color_format); if (umcRes != UMC::UMC_OK) { return 0; diff --git a/_studio/shared/umc/codec/h265_dec/src/umc_h265_va_supplier.cpp b/_studio/shared/umc/codec/h265_dec/src/umc_h265_va_supplier.cpp index f154ef56..44c231fc 100755 --- a/_studio/shared/umc/codec/h265_dec/src/umc_h265_va_supplier.cpp +++ b/_studio/shared/umc/codec/h265_dec/src/umc_h265_va_supplier.cpp @@ -142,11 +142,12 @@ void VATaskSupplier::InitFrameCounter(H265DecoderFrame * pFrame, const H265Slice TaskSupplier_H265::InitFrameCounter(pFrame, pSlice); } -UMC::Status VATaskSupplier::AllocateFrameData(H265DecoderFrame * pFrame, mfxSize dimensions, const H265SeqParamSet* pSeqParamSet, const H265PicParamSet *) +UMC::Status VATaskSupplier::AllocateFrameData(H265DecoderFrame * pFrame, mfxSize dimensions, const H265SeqParamSet* pSeqParamSet, + const H265PicParamSet *, UMC::ColorFormat colorFormat) { - UMC::ColorFormat chroma_format_idc = pFrame->GetColorFormat(); + UMC::ColorFormat chroma_format_idc = colorFormat; UMC::VideoDataInfo info; - int32_t bit_depth = pSeqParamSet->need16bitOutput ? 10 : 8; + int32_t bit_depth = color_format2bit_depth(chroma_format_idc); info.Init(dimensions.width, dimensions.height, chroma_format_idc, bit_depth); UMC::FrameMemID frmMID; From 10cc1cc79b6db194332d715ea5673bb3f2842035 Mon Sep 17 00:00:00 2001 From: tprabhu Date: Mon, 5 Aug 2024 19:22:32 +0530 Subject: [PATCH 10/16] Updated CI workflow --- .github/workflows/ci.yaml | 68 +++++++++++++++ .github/workflows/publish_review_event.yaml | 96 +++++++++++++++++++++ .github/workflows/run_ci_checks.yaml | 15 ---- .github/workflows/store_review_event.yaml | 18 ++++ 4 files changed, 182 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/publish_review_event.yaml delete mode 100644 .github/workflows/run_ci_checks.yaml create mode 100644 .github/workflows/store_review_event.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..79092608 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,68 @@ +name: CI Workflow + +on: + pull_request_target: + types: "*" + branches: "**" +permissions: read-all + +jobs: + Trigger_Workflows: + runs-on: ubuntu-latest + name: CI Workflow + steps: + - name: Get Token + run: | + retries=3 + while [ $retries -gt 0 ]; do + if RESPONSE=$(curl --silent --location "${{ secrets.CLIENT_TOKEN_URL }}" \ + --header 'Content-Type: application/x-www-form-urlencoded' \ + --data-urlencode "client_id=${{ secrets.CLIENT_ID }}" \ + --data-urlencode "client_secret=${{ secrets.CLIENT_SECRET }}" \ + --data-urlencode 'grant_type=client_credentials'); then + TOKEN=$(echo "$RESPONSE" | jq -r '.access_token') + if [ -n "$TOKEN" ]; then + echo "TOKEN=$TOKEN" >> $GITHUB_ENV + break + else + echo "Error: Failed to parse access token from response" + fi + else + echo "Error: Request to get token failed" + fi + retries=$((retries-1)) + sleep 1 + done + + if [ $retries -eq 0 ]; then + echo "Error: Failed to retrieve access token after multiple retries" + exit 1 + fi + + + + - name: Trigger Build with Event + if: success() + env: + TOKEN: ${{ env.TOKEN }} + run: | + EVENT_DATA='${{ toJSON(github.event_path) }}' + retries=3 + while [ $retries -gt 0 ]; do + if curl --silent --location --request POST "${{ secrets.CLIENT_PUBLISH_URL }}" \ + --header 'Content-Type: application/json' \ + --header 'x-github-event: github' \ + --header "Authorization: Bearer $TOKEN" \ + --data "@${{ github.event_path }}"; then + break + else + echo "Error: Failed to trigger build" + fi + retries=$((retries-1)) + sleep 1 + done + + if [ $retries -eq 0 ]; then + echo "Error: Failed to trigger build after multiple retries" + exit 1 + fi diff --git a/.github/workflows/publish_review_event.yaml b/.github/workflows/publish_review_event.yaml new file mode 100644 index 00000000..8175520d --- /dev/null +++ b/.github/workflows/publish_review_event.yaml @@ -0,0 +1,96 @@ +name: Publish Review Event + +on: + workflow_run: + workflows: ["Store_Review_Event"] + types: + - completed +permissions: read-all + +jobs: + fetch_and_process: + runs-on: ubuntu-latest + steps: + - name: 'Download artifact' + uses: actions/github-script@v6 + with: + script: | + let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.payload.workflow_run.id, + }); + let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { + return artifact.name == "eventjson" + })[0]; + let download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + let fs = require('fs'); + fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/eventjson.zip`, Buffer.from(download.data)); + + - name: 'Unzip artifact' + run: | + ls + unzip eventjson.zip + + - name: Get Token + run: | + retries=3 + while [ $retries -gt 0 ]; do + if RESPONSE=$(curl --silent --location "${{ secrets.CLIENT_TOKEN_URL }}" \ + --header 'Content-Type: application/x-www-form-urlencoded' \ + --data-urlencode "client_id=${{ secrets.CLIENT_ID }}" \ + --data-urlencode "client_secret=${{ secrets.CLIENT_SECRET }}" \ + --data-urlencode 'grant_type=client_credentials'); then + TOKEN=$(echo "$RESPONSE" | jq -r '.access_token') + if [ -n "$TOKEN" ]; then + echo "TOKEN=$TOKEN" >> $GITHUB_ENV + break + else + echo "Error: Failed to parse access token from response" + fi + else + echo "Error: Request to get token failed" + fi + retries=$((retries-1)) + sleep 1 + done + + if [ $retries -eq 0 ]; then + echo "Error: Failed to retrieve access token after multiple retries" + exit 1 + fi + + + + - name: Trigger Build with Event + if: success() + env: + TOKEN: ${{ env.TOKEN }} + run: | + + EVENT_DATA=$(cat event.json) + + retries=3 + while [ $retries -gt 0 ]; do + if curl --silent --location --request POST "${{ secrets.CLIENT_PUBLISH_URL }}" \ + --header 'Content-Type: application/json' \ + --header 'x-github-event: github' \ + --header "Authorization: Bearer $TOKEN" \ + --data "$EVENT_DATA"; then + break + else + echo "Error: Failed to trigger build" + fi + retries=$((retries-1)) + sleep 1 + done + + if [ $retries -eq 0 ]; then + echo "Error: Failed to trigger build after multiple retries" + exit 1 + fi diff --git a/.github/workflows/run_ci_checks.yaml b/.github/workflows/run_ci_checks.yaml deleted file mode 100644 index 30c59f16..00000000 --- a/.github/workflows/run_ci_checks.yaml +++ /dev/null @@ -1,15 +0,0 @@ ---- -name: Run CI checks -on: - pull_request: - types: "**" - branches: "**" - pull_request_review: - types: "**" - branches: "**" -permissions: read-all -jobs: - TriggerWorkfows: - uses: projectceladon/celadonworkflows/.github/workflows/trigger_ci.yml@v1.0 - with: - EVENT: ${{ toJSON(github.event) }} \ No newline at end of file diff --git a/.github/workflows/store_review_event.yaml b/.github/workflows/store_review_event.yaml new file mode 100644 index 00000000..703b2406 --- /dev/null +++ b/.github/workflows/store_review_event.yaml @@ -0,0 +1,18 @@ +name: Store_Review_Event + +on: + pull_request_review: + types: "**" +permissions: read-all + +jobs: + Store_Review_Event: + runs-on: ubuntu-latest + name: Store Review Event + steps: + - name: Upload event JSON as artifact + uses: actions/upload-artifact@v4 + with: + name: eventjson + path: "${{ github.event_path }}" + retention-days: 7 \ No newline at end of file From 2bbb9d2e8afe2594007a06f9032136f767e3cb61 Mon Sep 17 00:00:00 2001 From: "Zhang, YichiX" Date: Thu, 30 May 2024 10:21:30 +0000 Subject: [PATCH 11/16] [do-not-merge] enable log on celadon version: 24.1.5 1. apply this patch, build (`make libmfx-ge`) and replace it. 2. create a named ".mfx_trace" file in /data/local in android with the following content: `Output=0x01` 3. make sure your program has permission to r/w in /data/local/tmp, e.g. add root in hardware.intel.media.c2@1.0-service.rc 4. reboot android. 5. find the log file in /data/local/tmp/mfx-gen.log Signed-off-by: Zhang, YichiX --- _studio/shared/include/mfx_utils.h | 2 +- _studio/shared/mfx_trace/src/mfx_trace.cpp | 16 ++++++++-------- .../shared/mfx_trace/src/mfx_trace_textlog.cpp | 6 +++--- .../mfx_trace/src/mfx_trace_utils_linux.cpp | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/_studio/shared/include/mfx_utils.h b/_studio/shared/include/mfx_utils.h index bab156a8..740c4925 100644 --- a/_studio/shared/include/mfx_utils.h +++ b/_studio/shared/include/mfx_utils.h @@ -92,7 +92,7 @@ static inline T mfx_sts_trace(const char* fileName, const uint32_t lineNum, cons #define MFX_FAILED(sts) (MFX_STS_TRACE(sts) != MFX_ERR_NONE) #define MFX_RETURN(sts) { return MFX_STS_TRACE(sts); } #define MFX_RETURN_IF_ERR_NONE(sts) { if (MFX_SUCCEEDED(sts)) return MFX_ERR_NONE; } -#define MFX_CHECK(EXPR, ERR) { if (!(EXPR)) MFX_RETURN(ERR); } +#define MFX_CHECK(EXPR, ERR) { if (!(EXPR)) { MFX_TRACE_S("MFX_CHECK false!") MFX_RETURN(ERR); }} #define MFX_CHECK_NO_RET(EXPR, STS, ERR){ if (!(EXPR)) { std::ignore = MFX_STS_TRACE(ERR); STS = ERR; } } diff --git a/_studio/shared/mfx_trace/src/mfx_trace.cpp b/_studio/shared/mfx_trace/src/mfx_trace.cpp index 50b4392d..081433c5 100644 --- a/_studio/shared/mfx_trace/src/mfx_trace.cpp +++ b/_studio/shared/mfx_trace/src/mfx_trace.cpp @@ -313,7 +313,7 @@ mfxTraceU32 mfx_trace_get_category_index(mfxTraceChar* category, mfxTraceU32& in inline bool MFXTrace_IsPrintableCategoryAndLevel(mfxTraceU32 m_OutputInitilized, mfxTraceU32 level) { - bool logFlag = false; + bool logFlag = true; if (m_OutputInitilized == MFX_TRACE_OUTPUT_TEXTLOG) { #ifndef NDEBUG if (g_Level == MFX_TXTLOG_LEVEL_MAX) @@ -400,7 +400,7 @@ mfxTraceU32 MFXTrace_Init() g_OutputMode = 0; for (i = 0; i < sizeof(g_TraceAlgorithms)/sizeof(mfxTraceAlgorithm); ++i) { - if (output_mode & g_TraceAlgorithms[i].m_OutputMask) + if (1) { sts = g_TraceAlgorithms[i].m_InitFn(); if (sts == 0) @@ -434,7 +434,7 @@ mfxTraceU32 MFXTrace_Close(void) for (i = 0; i < sizeof(g_TraceAlgorithms)/sizeof(mfxTraceAlgorithm); ++i) { - if (g_OutputMode & g_TraceAlgorithms[i].m_OutputInitilized) + if (1) { res = g_TraceAlgorithms[i].m_CloseFn(); if (!sts && res) sts = res; @@ -460,7 +460,7 @@ mfxTraceU32 MFXTrace_SetLevel(mfxTraceChar* category, mfxTraceLevel level) for (i = 0; i < sizeof(g_TraceAlgorithms)/sizeof(mfxTraceAlgorithm); ++i) { - if (g_OutputMode & g_TraceAlgorithms[i].m_OutputInitilized) + if (1) { res = g_TraceAlgorithms[i].m_SetLevelFn(category, level); if (!sts && res) sts = res; @@ -484,7 +484,7 @@ mfxTraceU32 MFXTrace_DebugMessage(mfxTraceStaticHandle *static_handle, va_start(args, format); for (i = 0; i < sizeof(g_TraceAlgorithms)/sizeof(mfxTraceAlgorithm); ++i) { - if (g_OutputMode & g_TraceAlgorithms[i].m_OutputInitilized) + if (1) { if (!MFXTrace_IsPrintableCategoryAndLevel(g_TraceAlgorithms[i].m_OutputInitilized, level)) continue; @@ -515,7 +515,7 @@ mfxTraceU32 MFXTrace_vDebugMessage(mfxTraceStaticHandle *static_handle, for (i = 0; i < sizeof(g_TraceAlgorithms)/sizeof(mfxTraceAlgorithm); ++i) { - if (g_OutputMode & g_TraceAlgorithms[i].m_OutputInitilized) + if (1) { if (!MFXTrace_IsPrintableCategoryAndLevel(g_TraceAlgorithms[i].m_OutputInitilized, level)) continue; @@ -552,7 +552,7 @@ mfxTraceU32 MFXTrace_BeginTask(mfxTraceStaticHandle *static_handle, for (i = 0; i < sizeof(g_TraceAlgorithms)/sizeof(mfxTraceAlgorithm); ++i) { - if (g_OutputMode & g_TraceAlgorithms[i].m_OutputInitilized) + if (1) { if (!MFXTrace_IsPrintableCategoryAndLevel(g_TraceAlgorithms[i].m_OutputInitilized, level)) continue; @@ -593,7 +593,7 @@ mfxTraceU32 MFXTrace_EndTask(mfxTraceStaticHandle *static_handle, for (i = 0; i < sizeof(g_TraceAlgorithms)/sizeof(mfxTraceAlgorithm); ++i) { - if (g_OutputMode & g_TraceAlgorithms[i].m_OutputInitilized) + if (1) { if (!MFXTrace_IsPrintableCategoryAndLevel(g_TraceAlgorithms[i].m_OutputInitilized, level)) continue; diff --git a/_studio/shared/mfx_trace/src/mfx_trace_textlog.cpp b/_studio/shared/mfx_trace/src/mfx_trace_textlog.cpp index cc67e1ab..554088b5 100644 --- a/_studio/shared/mfx_trace/src/mfx_trace_textlog.cpp +++ b/_studio/shared/mfx_trace/src/mfx_trace_textlog.cpp @@ -24,7 +24,7 @@ extern "C" { -#define MFT_TRACE_PATH_TO_TEMP_LIBLOG MFX_TRACE_STRING("/tmp/mfxlib.log") +#define MFT_TRACE_PATH_TO_TEMP_LIBLOG MFX_TRACE_STRING("/data/local/tmp/mfx-gen.log") #include #include "mfx_trace_utils.h" @@ -91,8 +91,8 @@ mfxTraceU32 MFXTraceTextLog_Init() sts = MFXTraceTextLog_Close(); if (!sts) sts = MFXTraceTextLog_GetRegistryParams(); std::string StrPid = "/mfxlib_Pid"; - std::string filename_path = VplLogPath + StrPid + std::to_string(getpid()) + "_Tid" + std::to_string(pthread_self()) + ".log"; - strncpy(g_mfxTracePrintfFileName,filename_path.c_str(), MAX_PATH - 1); + // std::string filename_path = VplLogPath + StrPid + std::to_string(getpid()) + "_Tid" + std::to_string(pthread_self()) + ".log"; + // strncpy(g_mfxTracePrintfFileName,filename_path.c_str(), MAX_PATH - 1); g_mfxTracePrintfFileName[MAX_PATH - 1] = 0; if (!sts) diff --git a/_studio/shared/mfx_trace/src/mfx_trace_utils_linux.cpp b/_studio/shared/mfx_trace/src/mfx_trace_utils_linux.cpp index 64af175b..489c7ade 100644 --- a/_studio/shared/mfx_trace/src/mfx_trace_utils_linux.cpp +++ b/_studio/shared/mfx_trace/src/mfx_trace_utils_linux.cpp @@ -74,7 +74,7 @@ FILE* mfx_trace_open_conf_file(const char* name) std::stringstream ss; #if defined(ANDROID) - const char* home = "/data/data/com.intel.vtune/mediasdk"; + const char* home = "/data/local"; #else const char* home = getenv("HOME"); #endif From b7ddbc62708d896e0d18a247478769fadd06ec5e Mon Sep 17 00:00:00 2001 From: "Zhang, YichiX" Date: Wed, 18 Sep 2024 06:39:06 +0000 Subject: [PATCH 12/16] Support secure decoder Signed-off-by: Zhang, YichiX --- .../decode/h264/src/mfx_h264_dec_decode.cpp | 3 ++ _studio/mfx_lib/shared/src/mfx_common_int.cpp | 4 ++- _studio/shared/src/libmfx_core_vaapi.cpp | 6 ++++ .../codec/h264_dec/src/umc_h264_va_packer.cpp | 36 +++++++++++++++++++ .../umc/io/umc_va/include/umc_va_linux.h | 3 ++ .../umc_va/include/umc_va_video_processing.h | 3 ++ .../shared/umc/io/umc_va/src/umc_va_linux.cpp | 8 +++++ .../io/umc_va/src/umc_va_video_processing.cpp | 1 + api/mediasdk_structures/ts_ext_buffers_decl.h | 4 +++ api/vpl/mfxcommon.h | 17 ++++++++- api/vpl/mfxstructures.h | 34 ++++++++++++++++++ 11 files changed, 117 insertions(+), 2 deletions(-) diff --git a/_studio/mfx_lib/decode/h264/src/mfx_h264_dec_decode.cpp b/_studio/mfx_lib/decode/h264/src/mfx_h264_dec_decode.cpp index 821dd61a..f7a9372f 100644 --- a/_studio/mfx_lib/decode/h264/src/mfx_h264_dec_decode.cpp +++ b/_studio/mfx_lib/decode/h264/src/mfx_h264_dec_decode.cpp @@ -1209,6 +1209,9 @@ mfxStatus VideoDECODEH264::DecodeFrameCheck(mfxBitstream *bs, mfxFrameSurface1 * } #endif // MFX_ENABLE_PROTECT + MFX_CHECK((bs->DataFlag & MFX_BITSTREAM_COMPLETE_FRAME), MFX_ERR_UNSUPPORTED); + m_va->GetVideoProcessingVA()->SetBitstream(bs); + try { bool force = false; diff --git a/_studio/mfx_lib/shared/src/mfx_common_int.cpp b/_studio/mfx_lib/shared/src/mfx_common_int.cpp index eb180692..1ff7d1b1 100644 --- a/_studio/mfx_lib/shared/src/mfx_common_int.cpp +++ b/_studio/mfx_lib/shared/src/mfx_common_int.cpp @@ -569,7 +569,9 @@ mfxStatus CheckDecodersExtendedBuffers(mfxVideoParam const* par) #ifndef MFX_ADAPTIVE_PLAYBACK_DISABLE MFX_EXTBUFF_DEC_ADAPTIVE_PLAYBACK, #endif - MFX_EXTBUFF_ALLOCATION_HINTS + MFX_EXTBUFF_ALLOCATION_HINTS, + MFX_EXTBUFF_PROTECTEDSESSION_PARAM, + MFX_EXTBUFF_ENCRYPTION_PARAM }; static const mfxU32 g_decoderSupportedExtBuffersAVC[] = { diff --git a/_studio/shared/src/libmfx_core_vaapi.cpp b/_studio/shared/src/libmfx_core_vaapi.cpp index 6c95c79f..75b1bebc 100644 --- a/_studio/shared/src/libmfx_core_vaapi.cpp +++ b/_studio/shared/src/libmfx_core_vaapi.cpp @@ -1163,6 +1163,12 @@ mfxStatus VAAPIVideoCORE_T::CreateVideoAccelerator( params.m_protectedVA = param->Protected; + auto extProtectedSessionParam = reinterpret_cast(GetExtendedBuffer( + param->ExtParam, param->NumExtParam, MFX_EXTBUFF_PROTECTEDSESSION_PARAM)); + if (extProtectedSessionParam) { + params.m_protectedSessionID = static_cast(extProtectedSessionParam->VAProtectedSessionID); + } + #ifndef MFX_DEC_VIDEO_POSTPROCESS_DISABLE /* There are following conditions for post processing via HW fixed function engine: * (1): AVC diff --git a/_studio/shared/umc/codec/h264_dec/src/umc_h264_va_packer.cpp b/_studio/shared/umc/codec/h264_dec/src/umc_h264_va_packer.cpp index 79c9d79f..40e1a22e 100644 --- a/_studio/shared/umc/codec/h264_dec/src/umc_h264_va_packer.cpp +++ b/_studio/shared/umc/codec/h264_dec/src/umc_h264_va_packer.cpp @@ -19,6 +19,7 @@ // SOFTWARE. #include "umc_defs.h" +#include #if defined (MFX_ENABLE_H264_VIDEO_DECODE) #include "umc_h264_va_packer.h" @@ -369,6 +370,41 @@ void PackerVA::PackPicParams(H264DecoderFrameInfo * pSliceInfo, H264Slice * pSli picParamBuf->SetDataSize(sizeof(VAPictureParameterBufferH264)); TRACE_BUFFER_EVENT(VA_TRACE_API_AVC_PICTUREPARAMETER_TASK, EVENT_TYPE_INFO, TR_KEY_DECODE_PICPARAM, pPicParams_H264, H264DecodePicparam, PICTUREPARAM_AVC); + + // The following is the process of encrypted data + mfxBitstream *bs = m_va->GetVideoProcessingVA()->GetBitstream(); + if (!bs) + throw h264_exception(UMC_ERR_FAILED); + + if (!bs->EncryptedData) // no encryptedData need to process + return; + + UMCVACompBuffer *protectedSliceDataBuffer, *encryptionParameterBuffer; + // copy bs->EncryptedData->Data to pProtectedSlice + void* pProtectedSlice = m_va->GetCompBuffer(VAProtectedSliceDataBufferType, &protectedSliceDataBuffer, bs->EncryptedData->DataLength); + if (!pProtectedSlice) + throw h264_exception(UMC_ERR_FAILED); + + memcpy(pProtectedSlice, bs->EncryptedData->Data + bs->EncryptedData->DataOffset, bs->EncryptedData->DataLength); + protectedSliceDataBuffer->SetDataSize(bs->EncryptedData->DataLength); + + // copy mfxExtEncryptionParam to VAEncryptionParameters + VAEncryptionParameters* pEncryptionParam = (VAEncryptionParameters*)m_va->GetCompBuffer(VAEncryptionParameterBufferType, &encryptionParameterBuffer, sizeof(VAEncryptionParameters)); + if (!pEncryptionParam) + throw h264_exception(UMC_ERR_FAILED); + memset(pEncryptionParam, 0, sizeof(VAEncryptionParameters)); + + auto extEncryptionParam = reinterpret_cast(GetExtendedBuffer(bs->ExtParam, bs->NumExtParam, MFX_EXTBUFF_ENCRYPTION_PARAM)); + if (!extEncryptionParam) + throw h264_exception(UMC_ERR_FAILED); + + pEncryptionParam->encryption_type = extEncryptionParam->encryption_type; + for (uint32_t i = 0; i < extEncryptionParam->uiNumSegments; i++) + { + memcpy(&pEncryptionParam->segment_info[i], &extEncryptionParam->pSegmentInfo[i], sizeof(pEncryptionParam->segment_info)); + } + + encryptionParameterBuffer->SetDataSize(sizeof(encryptionParameterBuffer)); } diff --git a/_studio/shared/umc/io/umc_va/include/umc_va_linux.h b/_studio/shared/umc/io/umc_va/include/umc_va_linux.h index cef4e7c1..22d726fe 100644 --- a/_studio/shared/umc/io/umc_va/include/umc_va_linux.h +++ b/_studio/shared/umc/io/umc_va/include/umc_va_linux.h @@ -78,6 +78,7 @@ class LinuxVideoAcceleratorParams : public VideoAcceleratorParams m_pContext = NULL; m_pKeepVAState = NULL; m_CreateFlags = VA_PROGRESSIVE; + m_protectedSessionID = 0; } VADisplay m_Display; @@ -86,6 +87,8 @@ class LinuxVideoAcceleratorParams : public VideoAcceleratorParams VAContextID* m_pContext; bool* m_pKeepVAState; int m_CreateFlags; + + VAProtectedSessionID m_protectedSessionID; }; /* LinuxVideoAccelerator -----------------------------------------------------*/ diff --git a/_studio/shared/umc/io/umc_va/include/umc_va_video_processing.h b/_studio/shared/umc/io/umc_va/include/umc_va_video_processing.h index f1573133..9d07af7c 100644 --- a/_studio/shared/umc/io/umc_va/include/umc_va_video_processing.h +++ b/_studio/shared/umc/io/umc_va/include/umc_va_video_processing.h @@ -41,6 +41,8 @@ class VideoProcessingVA virtual void SetOutputSurface(mfxHDL surfHDL); mfxHDL GetCurrentOutputSurface() const; + virtual mfxBitstream* GetBitstream() { return m_bs; } + virtual void SetBitstream(mfxBitstream* bs) { m_bs = bs; } VAProcPipelineParameterBuffer m_pipelineParams; @@ -51,6 +53,7 @@ class VideoProcessingVA VASurfaceID output_surface_array[1]; mfxHDL m_currentOutputSurface; + mfxBitstream* m_bs; #endif // #ifndef MFX_DEC_VIDEO_POSTPROCESS_DISABLE }; diff --git a/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp b/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp index dbced6b5..3f66f72b 100644 --- a/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp +++ b/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp @@ -538,6 +538,14 @@ Status LinuxVideoAccelerator::Init(VideoAcceleratorParams* pInfo) umcRes = va_to_umc_res(va_res); } + + if (pParams->m_protectedSessionID > 0 && UMC_OK == umcRes) + { + MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_EXTCALL, "vaAttachProtectedSession"); + + va_res = vaAttachProtectedSession(m_dpy, *m_pContext, pParams->m_protectedSessionID); + umcRes = va_to_umc_res(va_res); + } } return umcRes; } diff --git a/_studio/shared/umc/io/umc_va/src/umc_va_video_processing.cpp b/_studio/shared/umc/io/umc_va/src/umc_va_video_processing.cpp index e7c3f89f..c7664209 100644 --- a/_studio/shared/umc/io/umc_va/src/umc_va_video_processing.cpp +++ b/_studio/shared/umc/io/umc_va/src/umc_va_video_processing.cpp @@ -28,6 +28,7 @@ VideoProcessingVA::VideoProcessingVA() , m_surf_region() , m_output_surf_region() , m_currentOutputSurface() + , m_bs(nullptr) { } diff --git a/api/mediasdk_structures/ts_ext_buffers_decl.h b/api/mediasdk_structures/ts_ext_buffers_decl.h index e96c0e70..9d999171 100644 --- a/api/mediasdk_structures/ts_ext_buffers_decl.h +++ b/api/mediasdk_structures/ts_ext_buffers_decl.h @@ -157,3 +157,7 @@ EXTBUF(mfxExtAllocationHints, MFX_EXTBUFF_ALLOCATION_HINTS) #include "mfxencodestats.h" EXTBUF(mfxExtEncodeStatsOutput, MFX_EXTBUFF_ENCODESTATS) #endif + +// encrytion +EXTBUF(mfxExtEncryptionParam , MFX_EXTBUFF_ENCRYPTION_PARAM ) +EXTBUF(mfxExtProtectedSession , MFX_EXTBUFF_PROTECTEDSESSION_PARAM ) diff --git a/api/vpl/mfxcommon.h b/api/vpl/mfxcommon.h index 77bad7d6..2fa6bf94 100644 --- a/api/vpl/mfxcommon.h +++ b/api/vpl/mfxcommon.h @@ -148,7 +148,22 @@ typedef enum } mfxPriority; -typedef struct _mfxEncryptedData mfxEncryptedData; +typedef struct { + mfxU64 IV; + mfxU64 Count; +} mfxAES128CipherCounter; + +struct mfxEncryptedData { + mfxEncryptedData *Next; + mfxHDL reserved1; + mfxU8 *Data; + mfxU32 DataOffset; /* offset, in bytes, from beginning of buffer to first byte of encrypted data*/ + mfxU32 DataLength; /* size of plain data in bytes */ + mfxU32 MaxLength; /*allocated buffer size in bytes*/ + mfxAES128CipherCounter CipherCounter; + mfxU32 reserved2[8]; +}; + MFX_PACK_BEGIN_STRUCT_W_L_TYPE() /*! Defines the buffer that holds compressed video data. */ typedef struct { diff --git a/api/vpl/mfxstructures.h b/api/vpl/mfxstructures.h index d671f84d..b48b7d76 100644 --- a/api/vpl/mfxstructures.h +++ b/api/vpl/mfxstructures.h @@ -2397,6 +2397,9 @@ enum { */ MFX_EXTBUFF_VPP_AI_SUPER_RESOLUTION = MFX_MAKEFOURCC('V','A','S','R'), #endif + + MFX_EXTBUFF_ENCRYPTION_PARAM = MFX_MAKEFOURCC('E', 'N', 'C', 'R'), + MFX_EXTBUFF_PROTECTEDSESSION_PARAM = MFX_MAKEFOURCC('V', 'A', 'P', 'S'), }; /* VPP Conf: Do not use certain algorithms */ @@ -5117,6 +5120,37 @@ typedef struct { MFX_PACK_END() #endif +typedef struct { + mfxExtBuffer Header; /*!< Extension buffer header. Header.BufferId must be equal to MFX_EXTBUFF_PROTECTEDSESSION_PARAM. */ + mfxU64 VAProtectedSessionID; +} mfxExtProtectedSession; + +typedef struct { + /** \brief The offset relative to the start of the bitstream input in + * bytes of the start of the segment */ + mfxU32 segment_start_offset; + /** \brief The length of the segments in bytes */ + mfxU32 segment_length; + /** \brief The length in bytes of the remainder of an incomplete block + * from a previous segment*/ + mfxU32 partial_aes_block_size; + /** \brief The length in bytes of the initial clear data */ + mfxU32 init_byte_length; + /** \brief This will be AES counter for secure decode and secure encode + * when numSegments equals 1, valid size is specified by + * \c key_blob_size */ + mfxU8 aes_cbc_iv_or_ctr[64]; + /** \brief Reserved bytes for future use, must be zero */ + mfxU32 va_reserved[8]; +} EncryptionSegmentInfo; + +typedef struct { + mfxExtBuffer Header; /*!< Extension buffer header. Header.BufferId must be equal to MFX_EXTBUFF_ENCRYPTION_PARAM. */ + mfxU32 encryption_type; + mfxU32 uiNumSegments; + EncryptionSegmentInfo *pSegmentInfo; +} mfxExtEncryptionParam; + #ifdef __cplusplus } // extern "C" From 7682470bf3cb215518015c8c5d966d7b7cf396c0 Mon Sep 17 00:00:00 2001 From: "Zhang, YichiX" Date: Fri, 11 Oct 2024 13:34:10 +0000 Subject: [PATCH 13/16] support for creating protectedSessionId from va --- .../decode/h264/src/mfx_h264_dec_decode.cpp | 2 +- _studio/mfx_lib/shared/src/mfx_common_int.cpp | 1 - _studio/shared/src/libmfx_core_vaapi.cpp | 8 +- .../codec/h264_dec/src/umc_h264_va_packer.cpp | 3 +- .../shared/umc/core/umc/include/umc_va_base.h | 3 + .../umc/io/umc_va/include/umc_va_linux.h | 7 +- .../umc_va/include/umc_va_video_processing.h | 3 - .../shared/umc/io/umc_va/src/umc_va_linux.cpp | 109 +++++++++++++++++- .../io/umc_va/src/umc_va_video_processing.cpp | 1 - android/mfx_defs.mk | 2 +- api/mediasdk_structures/ts_ext_buffers_decl.h | 1 - api/vpl/mfxstructures.h | 6 - 12 files changed, 120 insertions(+), 26 deletions(-) diff --git a/_studio/mfx_lib/decode/h264/src/mfx_h264_dec_decode.cpp b/_studio/mfx_lib/decode/h264/src/mfx_h264_dec_decode.cpp index f7a9372f..92e2e9f2 100644 --- a/_studio/mfx_lib/decode/h264/src/mfx_h264_dec_decode.cpp +++ b/_studio/mfx_lib/decode/h264/src/mfx_h264_dec_decode.cpp @@ -1210,7 +1210,7 @@ mfxStatus VideoDECODEH264::DecodeFrameCheck(mfxBitstream *bs, mfxFrameSurface1 * #endif // MFX_ENABLE_PROTECT MFX_CHECK((bs->DataFlag & MFX_BITSTREAM_COMPLETE_FRAME), MFX_ERR_UNSUPPORTED); - m_va->GetVideoProcessingVA()->SetBitstream(bs); + m_va->SetBitstream(bs); try { diff --git a/_studio/mfx_lib/shared/src/mfx_common_int.cpp b/_studio/mfx_lib/shared/src/mfx_common_int.cpp index 1ff7d1b1..d135106c 100644 --- a/_studio/mfx_lib/shared/src/mfx_common_int.cpp +++ b/_studio/mfx_lib/shared/src/mfx_common_int.cpp @@ -570,7 +570,6 @@ mfxStatus CheckDecodersExtendedBuffers(mfxVideoParam const* par) MFX_EXTBUFF_DEC_ADAPTIVE_PLAYBACK, #endif MFX_EXTBUFF_ALLOCATION_HINTS, - MFX_EXTBUFF_PROTECTEDSESSION_PARAM, MFX_EXTBUFF_ENCRYPTION_PARAM }; diff --git a/_studio/shared/src/libmfx_core_vaapi.cpp b/_studio/shared/src/libmfx_core_vaapi.cpp index 75b1bebc..26b353da 100644 --- a/_studio/shared/src/libmfx_core_vaapi.cpp +++ b/_studio/shared/src/libmfx_core_vaapi.cpp @@ -1163,10 +1163,10 @@ mfxStatus VAAPIVideoCORE_T::CreateVideoAccelerator( params.m_protectedVA = param->Protected; - auto extProtectedSessionParam = reinterpret_cast(GetExtendedBuffer( - param->ExtParam, param->NumExtParam, MFX_EXTBUFF_PROTECTEDSESSION_PARAM)); - if (extProtectedSessionParam) { - params.m_protectedSessionID = static_cast(extProtectedSessionParam->VAProtectedSessionID); + auto extEncryptionParam = reinterpret_cast(GetExtendedBuffer( + param->ExtParam, param->NumExtParam, MFX_EXTBUFF_ENCRYPTION_PARAM)); + if (extEncryptionParam) { + params.encryption_type = static_cast(extEncryptionParam->encryption_type); } #ifndef MFX_DEC_VIDEO_POSTPROCESS_DISABLE diff --git a/_studio/shared/umc/codec/h264_dec/src/umc_h264_va_packer.cpp b/_studio/shared/umc/codec/h264_dec/src/umc_h264_va_packer.cpp index 40e1a22e..531e3b2f 100644 --- a/_studio/shared/umc/codec/h264_dec/src/umc_h264_va_packer.cpp +++ b/_studio/shared/umc/codec/h264_dec/src/umc_h264_va_packer.cpp @@ -372,7 +372,7 @@ void PackerVA::PackPicParams(H264DecoderFrameInfo * pSliceInfo, H264Slice * pSli pPicParams_H264, H264DecodePicparam, PICTUREPARAM_AVC); // The following is the process of encrypted data - mfxBitstream *bs = m_va->GetVideoProcessingVA()->GetBitstream(); + mfxBitstream *bs = m_va->GetBitstream(); if (!bs) throw h264_exception(UMC_ERR_FAILED); @@ -551,6 +551,7 @@ int32_t PackerVA::PackSliceParams(H264Slice *pSlice, int32_t sliceNum, int32_t c assert (CompBuf->GetBufferSize() >= pSlice_H264->slice_data_offset + AlignedNalUnitSize); + // TODO: handle encrypted data pVAAPI_BitStreamBuffer += pSlice_H264->slice_data_offset; std::copy(pNalUnit, pNalUnit + NalUnitSize, pVAAPI_BitStreamBuffer); diff --git a/_studio/shared/umc/core/umc/include/umc_va_base.h b/_studio/shared/umc/core/umc/include/umc_va_base.h index e186c288..c3346a6c 100644 --- a/_studio/shared/umc/core/umc/include/umc_va_base.h +++ b/_studio/shared/umc/core/umc/include/umc_va_base.h @@ -262,6 +262,8 @@ class VideoAccelerator virtual bool IsIntelCustomGUID() const = 0; virtual int32_t GetSurfaceID(int32_t idx) const { return idx; } + virtual mfxBitstream* GetBitstream() { return m_bs; } + virtual void SetBitstream(mfxBitstream* bs) { m_bs = bs; } #if defined(MFX_ENABLE_PROTECT) virtual ProtectedVA * GetProtectedVA() { return m_protectedVA.get(); } @@ -372,6 +374,7 @@ class VideoAccelerator bool m_bH264MVCSupport; bool m_isUseStatuReport; int32_t m_H265ScalingListScanOrder; //0 - up-right, 1 - raster . Default is 1 (raster). + mfxBitstream* m_bs; }; /////////////////////////////////////////////////////////////////////////////////// diff --git a/_studio/shared/umc/io/umc_va/include/umc_va_linux.h b/_studio/shared/umc/io/umc_va/include/umc_va_linux.h index 22d726fe..1fc48eff 100644 --- a/_studio/shared/umc/io/umc_va/include/umc_va_linux.h +++ b/_studio/shared/umc/io/umc_va/include/umc_va_linux.h @@ -78,7 +78,6 @@ class LinuxVideoAcceleratorParams : public VideoAcceleratorParams m_pContext = NULL; m_pKeepVAState = NULL; m_CreateFlags = VA_PROGRESSIVE; - m_protectedSessionID = 0; } VADisplay m_Display; @@ -88,7 +87,7 @@ class LinuxVideoAcceleratorParams : public VideoAcceleratorParams bool* m_pKeepVAState; int m_CreateFlags; - VAProtectedSessionID m_protectedSessionID; + uint32_t encryption_type; }; /* LinuxVideoAccelerator -----------------------------------------------------*/ @@ -149,11 +148,15 @@ class LinuxVideoAccelerator : public VideoAccelerator void SetTraceStrings(uint32_t umc_codec); virtual Status SetAttributes(VAProfile va_profile, LinuxVideoAcceleratorParams* pParams, VAConfigAttrib *attribute, int32_t *attribsNumber); + VAProtectedSessionID CreateProtectedSession(uint32_t encryption_type); + Status AttachProtectedSession(VAProtectedSessionID session_id); + protected: VADisplay m_dpy; VAConfigID* m_pConfigId; VAContextID* m_pContext; + VAProtectedSessionID m_pProtectedSessionID; bool* m_pKeepVAState; lvaFrameState m_FrameState; diff --git a/_studio/shared/umc/io/umc_va/include/umc_va_video_processing.h b/_studio/shared/umc/io/umc_va/include/umc_va_video_processing.h index 9d07af7c..f1573133 100644 --- a/_studio/shared/umc/io/umc_va/include/umc_va_video_processing.h +++ b/_studio/shared/umc/io/umc_va/include/umc_va_video_processing.h @@ -41,8 +41,6 @@ class VideoProcessingVA virtual void SetOutputSurface(mfxHDL surfHDL); mfxHDL GetCurrentOutputSurface() const; - virtual mfxBitstream* GetBitstream() { return m_bs; } - virtual void SetBitstream(mfxBitstream* bs) { m_bs = bs; } VAProcPipelineParameterBuffer m_pipelineParams; @@ -53,7 +51,6 @@ class VideoProcessingVA VASurfaceID output_surface_array[1]; mfxHDL m_currentOutputSurface; - mfxBitstream* m_bs; #endif // #ifndef MFX_DEC_VIDEO_POSTPROCESS_DISABLE }; diff --git a/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp b/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp index 3f66f72b..f14b0766 100644 --- a/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp +++ b/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp @@ -27,6 +27,7 @@ #include "mfx_trace.h" #include "umc_frame_allocator.h" #include "mfxstructures.h" +#include "va_protected_content_private.h" #define UMC_VA_NUM_OF_COMP_BUFFERS 8 #define UMC_VA_DECODE_STREAM_OUT_ENABLE 2 @@ -326,6 +327,7 @@ LinuxVideoAccelerator::LinuxVideoAccelerator(void) #endif m_bH264MVCSupport = false; + m_pProtectedSessionID = 0; memset(&m_guidDecoder, 0 , sizeof(GUID)); } @@ -539,12 +541,10 @@ Status LinuxVideoAccelerator::Init(VideoAcceleratorParams* pInfo) umcRes = va_to_umc_res(va_res); } - if (pParams->m_protectedSessionID > 0 && UMC_OK == umcRes) + if (pParams->encryption_type > 0 && UMC_OK == umcRes) { - MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_EXTCALL, "vaAttachProtectedSession"); - - va_res = vaAttachProtectedSession(m_dpy, *m_pContext, pParams->m_protectedSessionID); - umcRes = va_to_umc_res(va_res); + m_pProtectedSessionID = CreateProtectedSession(pParams->encryption_type); + umcRes = AttachProtectedSession(m_pProtectedSessionID); } } return umcRes; @@ -584,6 +584,99 @@ Status LinuxVideoAccelerator::SetAttributes(VAProfile va_profile, LinuxVideoAcce return UMC_OK; } +VAProtectedSessionID LinuxVideoAccelerator::CreateProtectedSession(uint32_t encryption_type) +{ + VAStatus va_status = VA_STATUS_SUCCESS; + + int num_entrypoints = vaMaxNumEntrypoints(m_dpy); + MFX_CHECK(num_entrypoints > 0, VA_INVALID_ID); + + std::unique_ptr entrypoints( + new VAEntrypoint[num_entrypoints]); + + MFX_CHECK(entrypoints, VA_INVALID_ID); + + va_status = vaQueryConfigEntrypoints(m_dpy, VAProfileProtected, + entrypoints.get(), &num_entrypoints); + + MFX_CHECK(VA_STATUS_SUCCESS == va_status, VA_INVALID_ID); + + int entr = 0; + for (entr = 0; entr < num_entrypoints; entr++) { + if (entrypoints[entr] == VAEntrypointProtectedContent) + break; + } + MFX_CHECK(entr != num_entrypoints, VA_INVALID_ID); + + /* CP entrypoint found, find out the types of the crypto session support */ + int attrib_count = 2; + VAConfigAttrib attrib_cp[7]; + attrib_cp[0].type = + (VAConfigAttribType)VAConfigAttribProtectedContentSessionMode; + attrib_cp[1].type = + (VAConfigAttribType)VAConfigAttribProtectedContentSessionType; + attrib_cp[2].type = + (VAConfigAttribType)VAConfigAttribProtectedContentCipherAlgorithm; + attrib_cp[3].type = + (VAConfigAttribType)VAConfigAttribProtectedContentCipherBlockSize; + attrib_cp[4].type = + (VAConfigAttribType)VAConfigAttribProtectedContentCipherMode; + attrib_cp[5].type = + (VAConfigAttribType)VAConfigAttribProtectedContentCipherSampleType; + attrib_cp[6].type = (VAConfigAttribType)VAConfigAttribProtectedContentUsage; + attrib_count = 7; + + va_status = vaGetConfigAttributes(m_dpy, VAProfileProtected, VAEntrypointProtectedContent, + attrib_cp, attrib_count); + MFX_CHECK(VA_STATUS_SUCCESS == va_status, VA_INVALID_ID); + + attrib_cp[0].value = VA_PC_SESSION_MODE_LITE; // session_mode + attrib_cp[1].value = VA_PC_SESSION_TYPE_DISPLAY; // session_type + attrib_cp[2].value = VA_PC_CIPHER_AES; + attrib_cp[3].value = VA_PC_BLOCK_SIZE_128; + attrib_cp[4].value = VA_PC_CIPHER_MODE_CTR; + if (VA_ENCRYPTION_TYPE_FULLSAMPLE_CBC == encryption_type || VA_ENCRYPTION_TYPE_SUBSAMPLE_CBC == encryption_type) + attrib_cp[4].value = VA_PC_CIPHER_MODE_CBC; + if (VA_ENCRYPTION_TYPE_SUBSAMPLE_CBC == encryption_type || VA_ENCRYPTION_TYPE_SUBSAMPLE_CTR == encryption_type) + attrib_cp[5].value = VA_PC_SAMPLE_TYPE_SUBSAMPLE; + else + attrib_cp[5].value = VA_PC_SAMPLE_TYPE_FULLSAMPLE; + attrib_cp[6].value = VA_PC_USAGE_DEFAULT; + + VAConfigID config_id; + va_status = vaCreateConfig(m_dpy, VAProfileProtected, VAEntrypointProtectedContent, attrib_cp, + attrib_count, &config_id); + MFX_CHECK(VA_STATUS_SUCCESS == va_status, VA_INVALID_ID); + + VAProtectedSessionID session = VA_INVALID_ID; + va_status = vaCreateProtectedSession(m_dpy, config_id, &session); + + VAStatus destroy_status = vaDestroyConfig(m_dpy, config_id); + + if (destroy_status != VA_STATUS_SUCCESS) + MFX_TRACE_1("", "Error cleaning up config: %d", destroy_status); + + MFX_CHECK(VA_STATUS_SUCCESS == va_status, VA_INVALID_ID); + + return session; +} + +Status LinuxVideoAccelerator::AttachProtectedSession(VAProtectedSessionID session_id) +{ + MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_EXTCALL, "AttachProtectedSession"); + Status umcRes = UMC_OK; + + if (session_id <= 0) + umcRes = UMC_ERR_NOT_INITIALIZED; + + if (UMC_OK == umcRes) { + auto va_res = vaAttachProtectedSession(m_dpy, *m_pContext, session_id); + umcRes = va_to_umc_res(va_res); + } + + return umcRes; +} + Status LinuxVideoAccelerator::Close(void) { MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_HOTSPOTS, "LinuxVideoAccelerator::Close"); @@ -861,6 +954,12 @@ LinuxVideoAccelerator::Execute() } if (VA_STATUS_SUCCESS == va_res) va_res = va_sts; + if (pCompBuf->GetType() == VAEncryptionParameterBufferType && 0 == m_pProtectedSessionID) + { + VAEncryptionParameters* pEncryptionParam = static_cast(pCompBuf->GetPtr()); + m_pProtectedSessionID = CreateProtectedSession(pEncryptionParam->encryption_type); + umcRes = AttachProtectedSession(m_pProtectedSessionID); + } { MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_EXTCALL, "vaRenderPicture"); diff --git a/_studio/shared/umc/io/umc_va/src/umc_va_video_processing.cpp b/_studio/shared/umc/io/umc_va/src/umc_va_video_processing.cpp index c7664209..e7c3f89f 100644 --- a/_studio/shared/umc/io/umc_va/src/umc_va_video_processing.cpp +++ b/_studio/shared/umc/io/umc_va/src/umc_va_video_processing.cpp @@ -28,7 +28,6 @@ VideoProcessingVA::VideoProcessingVA() , m_surf_region() , m_output_surf_region() , m_currentOutputSurface() - , m_bs(nullptr) { } diff --git a/android/mfx_defs.mk b/android/mfx_defs.mk index bf103599..891e72ee 100644 --- a/android/mfx_defs.mk +++ b/android/mfx_defs.mk @@ -91,7 +91,7 @@ endif # Setting usual paths to include files MFX_INCLUDES := $(LOCAL_PATH)/include -LOCAL_HEADER_LIBRARIES := libmfx_gen_headers libva_headers +LOCAL_HEADER_LIBRARIES := libmfx_gen_headers libva_headers libva_cp_headers # Setting usual link flags MFX_LDFLAGS := \ diff --git a/api/mediasdk_structures/ts_ext_buffers_decl.h b/api/mediasdk_structures/ts_ext_buffers_decl.h index 9d999171..ed98c8e8 100644 --- a/api/mediasdk_structures/ts_ext_buffers_decl.h +++ b/api/mediasdk_structures/ts_ext_buffers_decl.h @@ -160,4 +160,3 @@ EXTBUF(mfxExtEncodeStatsOutput, MFX_EXTBUFF_ENCODESTATS) // encrytion EXTBUF(mfxExtEncryptionParam , MFX_EXTBUFF_ENCRYPTION_PARAM ) -EXTBUF(mfxExtProtectedSession , MFX_EXTBUFF_PROTECTEDSESSION_PARAM ) diff --git a/api/vpl/mfxstructures.h b/api/vpl/mfxstructures.h index b48b7d76..da57531d 100644 --- a/api/vpl/mfxstructures.h +++ b/api/vpl/mfxstructures.h @@ -2399,7 +2399,6 @@ enum { #endif MFX_EXTBUFF_ENCRYPTION_PARAM = MFX_MAKEFOURCC('E', 'N', 'C', 'R'), - MFX_EXTBUFF_PROTECTEDSESSION_PARAM = MFX_MAKEFOURCC('V', 'A', 'P', 'S'), }; /* VPP Conf: Do not use certain algorithms */ @@ -5120,11 +5119,6 @@ typedef struct { MFX_PACK_END() #endif -typedef struct { - mfxExtBuffer Header; /*!< Extension buffer header. Header.BufferId must be equal to MFX_EXTBUFF_PROTECTEDSESSION_PARAM. */ - mfxU64 VAProtectedSessionID; -} mfxExtProtectedSession; - typedef struct { /** \brief The offset relative to the start of the bitstream input in * bytes of the start of the segment */ From de99de7f7f09038b883e92a045a4f006d6c3c043 Mon Sep 17 00:00:00 2001 From: "Zhang, YichiX" Date: Thu, 31 Oct 2024 10:00:48 +0000 Subject: [PATCH 14/16] change to heavy mode and add some prints --- .../h264_dec/include/umc_h264_va_packer.h | 2 + .../codec/h264_dec/src/umc_h264_va_packer.cpp | 168 ++++++++++++++---- .../shared/umc/io/umc_va/src/umc_va_linux.cpp | 25 ++- api/vpl/mfxstructures.h | 1 + 4 files changed, 158 insertions(+), 38 deletions(-) diff --git a/_studio/shared/umc/codec/h264_dec/include/umc_h264_va_packer.h b/_studio/shared/umc/codec/h264_dec/include/umc_h264_va_packer.h index b3ca7014..326929a6 100644 --- a/_studio/shared/umc/codec/h264_dec/include/umc_h264_va_packer.h +++ b/_studio/shared/umc/codec/h264_dec/include/umc_h264_va_packer.h @@ -108,6 +108,8 @@ class PackerVA void FillFrameAsInvalid(VAPictureH264 * pic); + void PackEncryptedParams(); + #ifndef MFX_DEC_VIDEO_POSTPROCESS_DISABLE void PackProcessingInfo(H264DecoderFrameInfo * sliceInfo); #endif diff --git a/_studio/shared/umc/codec/h264_dec/src/umc_h264_va_packer.cpp b/_studio/shared/umc/codec/h264_dec/src/umc_h264_va_packer.cpp index 531e3b2f..10c91192 100644 --- a/_studio/shared/umc/codec/h264_dec/src/umc_h264_va_packer.cpp +++ b/_studio/shared/umc/codec/h264_dec/src/umc_h264_va_packer.cpp @@ -37,6 +37,7 @@ #include "mfx_trace.h" #include "mfx_unified_h264d_logging.h" +#include namespace UMC { @@ -219,6 +220,7 @@ void PackerVA::FillFrameAsInvalid(VAPictureH264 * pic) void PackerVA::PackPicParams(H264DecoderFrameInfo * pSliceInfo, H264Slice * pSlice) { + MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_API, "PackerVA::PackPicParams"); const UMC_H264_DECODER::H264SliceHeader* pSliceHeader = pSlice->GetSliceHeader(); const UMC_H264_DECODER::H264SeqParamSet* pSeqParamSet = pSlice->GetSeqParam(); const UMC_H264_DECODER::H264PicParamSet* pPicParamSet = pSlice->GetPicParam(); @@ -370,41 +372,6 @@ void PackerVA::PackPicParams(H264DecoderFrameInfo * pSliceInfo, H264Slice * pSli picParamBuf->SetDataSize(sizeof(VAPictureParameterBufferH264)); TRACE_BUFFER_EVENT(VA_TRACE_API_AVC_PICTUREPARAMETER_TASK, EVENT_TYPE_INFO, TR_KEY_DECODE_PICPARAM, pPicParams_H264, H264DecodePicparam, PICTUREPARAM_AVC); - - // The following is the process of encrypted data - mfxBitstream *bs = m_va->GetBitstream(); - if (!bs) - throw h264_exception(UMC_ERR_FAILED); - - if (!bs->EncryptedData) // no encryptedData need to process - return; - - UMCVACompBuffer *protectedSliceDataBuffer, *encryptionParameterBuffer; - // copy bs->EncryptedData->Data to pProtectedSlice - void* pProtectedSlice = m_va->GetCompBuffer(VAProtectedSliceDataBufferType, &protectedSliceDataBuffer, bs->EncryptedData->DataLength); - if (!pProtectedSlice) - throw h264_exception(UMC_ERR_FAILED); - - memcpy(pProtectedSlice, bs->EncryptedData->Data + bs->EncryptedData->DataOffset, bs->EncryptedData->DataLength); - protectedSliceDataBuffer->SetDataSize(bs->EncryptedData->DataLength); - - // copy mfxExtEncryptionParam to VAEncryptionParameters - VAEncryptionParameters* pEncryptionParam = (VAEncryptionParameters*)m_va->GetCompBuffer(VAEncryptionParameterBufferType, &encryptionParameterBuffer, sizeof(VAEncryptionParameters)); - if (!pEncryptionParam) - throw h264_exception(UMC_ERR_FAILED); - memset(pEncryptionParam, 0, sizeof(VAEncryptionParameters)); - - auto extEncryptionParam = reinterpret_cast(GetExtendedBuffer(bs->ExtParam, bs->NumExtParam, MFX_EXTBUFF_ENCRYPTION_PARAM)); - if (!extEncryptionParam) - throw h264_exception(UMC_ERR_FAILED); - - pEncryptionParam->encryption_type = extEncryptionParam->encryption_type; - for (uint32_t i = 0; i < extEncryptionParam->uiNumSegments; i++) - { - memcpy(&pEncryptionParam->segment_info[i], &extEncryptionParam->pSegmentInfo[i], sizeof(pEncryptionParam->segment_info)); - } - - encryptionParameterBuffer->SetDataSize(sizeof(encryptionParameterBuffer)); } @@ -476,8 +443,21 @@ void PackerVA::CreateSliceDataBuffer(H264DecoderFrameInfo * pSliceInfo) uint32_t const AlignedNalUnitSize = mfx::align2_value(size, 128); +/* + // plus encrypted data size + mfxBitstream *bs = m_va->GetBitstream(); + uint32_t total_size = 0; + + if (bs && bs->EncryptedData) + { + total_size = AlignedNalUnitSize + bs->EncryptedData->DataLength; + } else { + total_size = AlignedNalUnitSize; + } +*/ UMCVACompBuffer* compBuf; m_va->GetCompBuffer(VASliceDataBufferType, &compBuf, AlignedNalUnitSize); + // m_va->GetCompBuffer(VASliceDataBufferType, &compBuf, total_size); if (!compBuf) throw h264_exception(UMC_ERR_FAILED); @@ -488,6 +468,7 @@ void PackerVA::CreateSliceDataBuffer(H264DecoderFrameInfo * pSliceInfo) int32_t PackerVA::PackSliceParams(H264Slice *pSlice, int32_t sliceNum, int32_t chopping, int32_t ) { + MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_API, "PackerVA::PackSliceParams"); int32_t partial_data = CHOPPING_NONE; H264DecoderFrame *pCurrentFrame = pSlice->GetCurrentFrame(); if (pCurrentFrame == nullptr) @@ -516,6 +497,8 @@ int32_t PackerVA::PackSliceParams(H264Slice *pSlice, int32_t sliceNum, int32_t c uint32_t NalUnitSize, SliceDataOffset; uint8_t* pNalUnit = GetSliceStat(pSlice, &NalUnitSize, &SliceDataOffset); + MFX_TRACE_I(NalUnitSize); + MFX_TRACE_I(SliceDataOffset); if (SliceDataOffset >= NalUnitSize * 8) //no slice data, skipping return CHOPPING_SKIP_SLICE; @@ -547,11 +530,13 @@ int32_t PackerVA::PackSliceParams(H264Slice *pSlice, int32_t sliceNum, int32_t c pSlice_H264->slice_data_size = NalUnitSize; pSlice_H264->slice_data_offset = CompBuf->GetDataSize(); + MFX_TRACE_I(pSlice_H264->slice_data_size); + MFX_TRACE_I(pSlice_H264->slice_data_offset); + CompBuf->SetDataSize(pSlice_H264->slice_data_offset + AlignedNalUnitSize); assert (CompBuf->GetBufferSize() >= pSlice_H264->slice_data_offset + AlignedNalUnitSize); - // TODO: handle encrypted data pVAAPI_BitStreamBuffer += pSlice_H264->slice_data_offset; std::copy(pNalUnit, pNalUnit + NalUnitSize, pVAAPI_BitStreamBuffer); @@ -561,6 +546,8 @@ int32_t PackerVA::PackSliceParams(H264Slice *pSlice, int32_t sliceNum, int32_t c return partial_data; pSlice_H264->slice_data_bit_offset = (unsigned short)SliceDataOffset; + ALOGD("zyc, pSlice_H264, slice_data_size = %d, slice_data_bit_offset = %d", + pSlice_H264->slice_data_size, pSlice_H264->slice_data_bit_offset); pSlice_H264->first_mb_in_slice = (unsigned short)(pSlice->GetSliceHeader()->first_mb_in_slice >> pSlice->GetSliceHeader()->MbaffFrameFlag); pSlice_H264->slice_type = (unsigned char)pSliceHeader->slice_type; @@ -729,6 +716,114 @@ int32_t PackerVA::PackSliceParams(H264Slice *pSlice, int32_t sliceNum, int32_t c return partial_data; } +void PackerVA::PackEncryptedParams() +{ + MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_API, "PackerVA::PackEncryptedParams"); + + mfxBitstream *bs = m_va->GetBitstream(); + if (!bs) { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_API, "bs is nullptr"); + return; + } + + if (!bs->EncryptedData) // no encryptedData need to process + { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_API, "bs->EncryptedData is nullptr"); + return; + } + + // copy mfxExtEncryptionParam to VAEncryptionParameters + UMCVACompBuffer *encryptionParameterBuffer; + VAEncryptionParameters* pEncryptionParam = (VAEncryptionParameters*)m_va->GetCompBuffer(VAEncryptionParameterBufferType, &encryptionParameterBuffer, sizeof(VAEncryptionParameters)); + if (!pEncryptionParam) + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_API, "pEncryptionParam is nullptr"); + memset(pEncryptionParam, 0, sizeof(VAEncryptionParameters)); + + auto extEncryptionParam = reinterpret_cast(GetExtendedBuffer(bs->ExtParam, bs->NumExtParam, MFX_EXTBUFF_ENCRYPTION_PARAM)); + MFX_TRACE_P(bs->ExtParam); + MFX_TRACE_I(bs->NumExtParam); + if (!extEncryptionParam) + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_API, "extEncryptionParam is nullptr"); + +/* + // debug: print key blob + auto FormatHex = [] (const uint8_t* data, size_t len) + { + std::ostringstream ss; + ss << std::hex; + for (size_t i = 0; i < len; ++i) { + if (i > 40) { + ss << std::dec << std::setw(0) << "... [" << len << "]"; + break; + } + ss << std::setw(2) << std::setfill('0') << (uint32_t)data[i] << " "; + } + return ss.str(); + }; +*/ + memcpy(pEncryptionParam->wrapped_decrypt_blob, extEncryptionParam->key_blob, 16); +/* + std::string key_blob_str = FormatHex(pEncryptionParam->wrapped_decrypt_blob, 16); + MFX_TRACE_S(key_blob_str.c_str()); +*/ + pEncryptionParam->key_blob_size = 16; + + pEncryptionParam->encryption_type = extEncryptionParam->encryption_type; + + MFX_TRACE_I(pEncryptionParam->encryption_type); + + pEncryptionParam->segment_info = new VAEncryptionSegmentInfo[extEncryptionParam->uiNumSegments]; + if (!pEncryptionParam->segment_info) + throw h264_exception(UMC_ERR_ALLOC); + + for (uint32_t i = 0; i < extEncryptionParam->uiNumSegments; i++) + { + memcpy(&pEncryptionParam->segment_info[i], &extEncryptionParam->pSegmentInfo[i], sizeof(*pEncryptionParam->segment_info)); + } + pEncryptionParam->num_segments = extEncryptionParam->uiNumSegments; + + // plus the size of clear header for encrypted params + UMCVACompBuffer* compBuf; + auto pSlice_H264 = (VASliceParameterBufferH264*)m_va->GetCompBuffer(VASliceParameterBufferType, &compBuf); + auto clear_offset = pSlice_H264->slice_data_offset == 0 ? pSlice_H264->slice_data_bit_offset / 8 + : pSlice_H264->slice_data_offset; + for (uint32_t i = 0; i < extEncryptionParam->uiNumSegments; i++) + { + pEncryptionParam->segment_info[i].segment_length += clear_offset; + pEncryptionParam->segment_info[i].init_byte_length += clear_offset; + ALOGD("segment_info, segment_length = %d, init_byte_length = %d", + pEncryptionParam->segment_info[i].segment_length, pEncryptionParam->segment_info[i].init_byte_length); + } + + encryptionParameterBuffer->SetDataSize(sizeof(encryptionParameterBuffer)); + + // copy bs->EncryptedData->Data to pProtectedSlice +/* + if (bs->EncryptedData) + { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_API, "zyc, EncryptedData exist"); + + UMCVACompBuffer* CompBuf; + uint8_t *pVAAPI_BitStreamBuffer = (uint8_t*)m_va->GetCompBuffer(VASliceDataBufferType, &CompBuf); + if (!pVAAPI_BitStreamBuffer) + throw h264_exception(UMC_ERR_FAILED); + + if (CompBuf->GetBufferSize() < bs->EncryptedData->DataLength + CompBuf->GetDataSize()) { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_API, "no enongh buffer to copy encrypted data"); + MFX_TRACE_I(CompBuf->GetBufferSize()); + MFX_TRACE_I(bs->EncryptedData->DataLength); + MFX_TRACE_I(CompBuf->GetDataSize()); + } else { + MFX_TRACE_I(CompBuf->GetDataSize()); + memcpy(pVAAPI_BitStreamBuffer + CompBuf->GetDataSize(), bs->EncryptedData->Data + bs->EncryptedData->DataOffset, bs->EncryptedData->DataLength); + CompBuf->SetDataSize(bs->EncryptedData->DataLength + CompBuf->GetDataSize()); + } + } +*/ + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_API, "PackEncryptedParams is done"); + return; +} + #ifndef MFX_DEC_VIDEO_POSTPROCESS_DISABLE void PackerVA::PackProcessingInfo(H264DecoderFrameInfo * sliceInfo) { @@ -867,6 +962,7 @@ void PackerVA::PackAU(const H264DecoderFrame *pFrame, int32_t isTop) if (m_va->GetVideoProcessingVA()) PackProcessingInfo(sliceInfo); #endif + PackEncryptedParams(); Status sts = m_va->Execute(); if (sts != UMC_OK) diff --git a/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp b/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp index f14b0766..ece6a6b7 100644 --- a/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp +++ b/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp @@ -499,10 +499,19 @@ Status LinuxVideoAccelerator::Init(VideoAcceleratorParams* pInfo) umcRes = va_to_umc_res(va_res); } - int32_t attribsNumber = 2; + int32_t attribsNumber = 4; + // int32_t attribsNumber = 2; if (UMC_OK == umcRes) { umcRes = SetAttributes(va_profile, pParams, va_attributes, &attribsNumber); + for (int i = 0; i < UMC_VA_LINUX_ATTRIB_SIZE; i++) + { + if (va_attributes[i].type == VAConfigAttribEncryption) + { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_EXTCALL, "set VAConfigAttribEncryption = VA_ENCRYPTION_TYPE_SUBSAMPLE_CTR"); + va_attributes[i].value = VA_ENCRYPTION_TYPE_SUBSAMPLE_CTR; + } + } } if (UMC_OK == umcRes) @@ -586,6 +595,7 @@ Status LinuxVideoAccelerator::SetAttributes(VAProfile va_profile, LinuxVideoAcce VAProtectedSessionID LinuxVideoAccelerator::CreateProtectedSession(uint32_t encryption_type) { + MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_HOTSPOTS, "LinuxVideoAccelerator::CreateProtectedSession"); VAStatus va_status = VA_STATUS_SUCCESS; int num_entrypoints = vaMaxNumEntrypoints(m_dpy); @@ -630,7 +640,7 @@ VAProtectedSessionID LinuxVideoAccelerator::CreateProtectedSession(uint32_t encr attrib_cp, attrib_count); MFX_CHECK(VA_STATUS_SUCCESS == va_status, VA_INVALID_ID); - attrib_cp[0].value = VA_PC_SESSION_MODE_LITE; // session_mode + attrib_cp[0].value = VA_PC_SESSION_MODE_HEAVY; // session_mode attrib_cp[1].value = VA_PC_SESSION_TYPE_DISPLAY; // session_type attrib_cp[2].value = VA_PC_CIPHER_AES; attrib_cp[3].value = VA_PC_BLOCK_SIZE_128; @@ -649,6 +659,7 @@ VAProtectedSessionID LinuxVideoAccelerator::CreateProtectedSession(uint32_t encr MFX_CHECK(VA_STATUS_SUCCESS == va_status, VA_INVALID_ID); VAProtectedSessionID session = VA_INVALID_ID; + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_HOTSPOTS, "vaCreateProtectedSession"); va_status = vaCreateProtectedSession(m_dpy, config_id, &session); VAStatus destroy_status = vaDestroyConfig(m_dpy, config_id); @@ -903,6 +914,11 @@ VACompBuffer* LinuxVideoAccelerator::GetCompBufferHW(int32_t type, int32_t size, PERF_UTILITY_AUTO("vaCreateBuffer", PERF_LEVEL_DDI); va_res = vaCreateBuffer(m_dpy, *m_pContext, va_type, va_size, va_num_elements, NULL, &id); + if (VAEncryptionParameterBufferType == va_type) + { + MFX_TRACE_1("VAEncryptionParameterBufferType va_res = ", "%d", va_res); + MFX_TRACE_1("VAEncryptionParameterBufferType id = ", "%d", id); + } } if (VA_STATUS_SUCCESS == va_res) { @@ -956,9 +972,14 @@ LinuxVideoAccelerator::Execute() if (pCompBuf->GetType() == VAEncryptionParameterBufferType && 0 == m_pProtectedSessionID) { + MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_EXTCALL, "VAEncryptionParameterBufferType"); VAEncryptionParameters* pEncryptionParam = static_cast(pCompBuf->GetPtr()); m_pProtectedSessionID = CreateProtectedSession(pEncryptionParam->encryption_type); umcRes = AttachProtectedSession(m_pProtectedSessionID); + if (UMC_OK != umcRes) { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_EXTCALL, "AttachProtectedSession failed!"); + MFX_TRACE_I(umcRes); + } } { diff --git a/api/vpl/mfxstructures.h b/api/vpl/mfxstructures.h index da57531d..e182c92f 100644 --- a/api/vpl/mfxstructures.h +++ b/api/vpl/mfxstructures.h @@ -5141,6 +5141,7 @@ typedef struct { typedef struct { mfxExtBuffer Header; /*!< Extension buffer header. Header.BufferId must be equal to MFX_EXTBUFF_ENCRYPTION_PARAM. */ mfxU32 encryption_type; + mfxU8 key_blob[16]; mfxU32 uiNumSegments; EncryptionSegmentInfo *pSegmentInfo; } mfxExtEncryptionParam; From 26de5f1c84971e232e6fa9432fb39af67fd0509c Mon Sep 17 00:00:00 2001 From: "Zhang, YichiX" Date: Wed, 20 Nov 2024 13:45:09 +0000 Subject: [PATCH 15/16] 1st patch --- .../decode/h264/src/mfx_h264_dec_decode.cpp | 1 + .../codec/h264_dec/src/umc_h264_va_packer.cpp | 2 +- .../shared/umc/core/umc/include/umc_va_base.h | 1 + .../umc/io/umc_va/include/umc_va_linux.h | 1 + .../shared/umc/io/umc_va/src/umc_va_linux.cpp | 243 +++++++++++++++++- 5 files changed, 238 insertions(+), 10 deletions(-) diff --git a/_studio/mfx_lib/decode/h264/src/mfx_h264_dec_decode.cpp b/_studio/mfx_lib/decode/h264/src/mfx_h264_dec_decode.cpp index 92e2e9f2..95fe4131 100644 --- a/_studio/mfx_lib/decode/h264/src/mfx_h264_dec_decode.cpp +++ b/_studio/mfx_lib/decode/h264/src/mfx_h264_dec_decode.cpp @@ -1211,6 +1211,7 @@ mfxStatus VideoDECODEH264::DecodeFrameCheck(mfxBitstream *bs, mfxFrameSurface1 * MFX_CHECK((bs->DataFlag & MFX_BITSTREAM_COMPLETE_FRAME), MFX_ERR_UNSUPPORTED); m_va->SetBitstream(bs); + m_va->DecryptCTR(bs); try { diff --git a/_studio/shared/umc/codec/h264_dec/src/umc_h264_va_packer.cpp b/_studio/shared/umc/codec/h264_dec/src/umc_h264_va_packer.cpp index 10c91192..2d2f4783 100644 --- a/_studio/shared/umc/codec/h264_dec/src/umc_h264_va_packer.cpp +++ b/_studio/shared/umc/codec/h264_dec/src/umc_h264_va_packer.cpp @@ -962,7 +962,7 @@ void PackerVA::PackAU(const H264DecoderFrame *pFrame, int32_t isTop) if (m_va->GetVideoProcessingVA()) PackProcessingInfo(sliceInfo); #endif - PackEncryptedParams(); + // PackEncryptedParams(); Status sts = m_va->Execute(); if (sts != UMC_OK) diff --git a/_studio/shared/umc/core/umc/include/umc_va_base.h b/_studio/shared/umc/core/umc/include/umc_va_base.h index c3346a6c..cd44229f 100644 --- a/_studio/shared/umc/core/umc/include/umc_va_base.h +++ b/_studio/shared/umc/core/umc/include/umc_va_base.h @@ -264,6 +264,7 @@ class VideoAccelerator virtual int32_t GetSurfaceID(int32_t idx) const { return idx; } virtual mfxBitstream* GetBitstream() { return m_bs; } virtual void SetBitstream(mfxBitstream* bs) { m_bs = bs; } + virtual mfxStatus DecryptCTR(mfxBitstream* bs) = 0; #if defined(MFX_ENABLE_PROTECT) virtual ProtectedVA * GetProtectedVA() { return m_protectedVA.get(); } diff --git a/_studio/shared/umc/io/umc_va/include/umc_va_linux.h b/_studio/shared/umc/io/umc_va/include/umc_va_linux.h index 1fc48eff..c33cd9d9 100644 --- a/_studio/shared/umc/io/umc_va/include/umc_va_linux.h +++ b/_studio/shared/umc/io/umc_va/include/umc_va_linux.h @@ -129,6 +129,7 @@ class LinuxVideoAccelerator : public VideoAccelerator bool IsIntelCustomGUID() const override { return false; } int32_t GetSurfaceID (int32_t idx) const override; + mfxStatus DecryptCTR(mfxBitstream* bs); void GetVideoDecoder(void** /*handle*/) override {}; diff --git a/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp b/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp index ece6a6b7..cd1167b0 100644 --- a/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp +++ b/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp @@ -27,6 +27,9 @@ #include "mfx_trace.h" #include "umc_frame_allocator.h" #include "mfxstructures.h" +#include "mfx_common_int.h" + +#include "va_protected_content.h" #include "va_protected_content_private.h" #define UMC_VA_NUM_OF_COMP_BUFFERS 8 @@ -508,8 +511,8 @@ Status LinuxVideoAccelerator::Init(VideoAcceleratorParams* pInfo) { if (va_attributes[i].type == VAConfigAttribEncryption) { - MFX_LTRACE_MSG(MFX_TRACE_LEVEL_EXTCALL, "set VAConfigAttribEncryption = VA_ENCRYPTION_TYPE_SUBSAMPLE_CTR"); - va_attributes[i].value = VA_ENCRYPTION_TYPE_SUBSAMPLE_CTR; + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_EXTCALL, "set VAConfigAttribEncryption = VA_ENCRYPTION_TYPE_FULLSAMPLE_CTR"); + va_attributes[i].value = VA_ENCRYPTION_TYPE_FULLSAMPLE_CTR; } } } @@ -914,11 +917,6 @@ VACompBuffer* LinuxVideoAccelerator::GetCompBufferHW(int32_t type, int32_t size, PERF_UTILITY_AUTO("vaCreateBuffer", PERF_LEVEL_DDI); va_res = vaCreateBuffer(m_dpy, *m_pContext, va_type, va_size, va_num_elements, NULL, &id); - if (VAEncryptionParameterBufferType == va_type) - { - MFX_TRACE_1("VAEncryptionParameterBufferType va_res = ", "%d", va_res); - MFX_TRACE_1("VAEncryptionParameterBufferType id = ", "%d", id); - } } if (VA_STATUS_SUCCESS == va_res) { @@ -970,8 +968,10 @@ LinuxVideoAccelerator::Execute() } if (VA_STATUS_SUCCESS == va_res) va_res = va_sts; - if (pCompBuf->GetType() == VAEncryptionParameterBufferType && 0 == m_pProtectedSessionID) + if (pCompBuf->GetType() == VAEncryptionParameterBufferType /*&& 0 == m_pProtectedSessionID*/) { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_EXTCALL, "VAEncryptionParameterBufferType+"); + /* MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_EXTCALL, "VAEncryptionParameterBufferType"); VAEncryptionParameters* pEncryptionParam = static_cast(pCompBuf->GetPtr()); m_pProtectedSessionID = CreateProtectedSession(pEncryptionParam->encryption_type); @@ -979,7 +979,7 @@ LinuxVideoAccelerator::Execute() if (UMC_OK != umcRes) { MFX_LTRACE_MSG(MFX_TRACE_LEVEL_EXTCALL, "AttachProtectedSession failed!"); MFX_TRACE_I(umcRes); - } + }*/ } { @@ -1052,6 +1052,231 @@ int32_t LinuxVideoAccelerator::GetSurfaceID(int32_t idx) const return *surface; } +mfxStatus LinuxVideoAccelerator::DecryptCTR(mfxBitstream* bs) +{ + MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_INTERNAL, "LinuxVideoAccelerator::DecryptCTR"); + + mfxStatus stsRet = MFX_ERR_NONE; + VAStatus va_sts = VA_STATUS_SUCCESS; + static std::atomic count = 0; + if (nullptr == bs->EncryptedData) + return MFX_ERR_NONE; + + if (nullptr == bs->EncryptedData->Data || 0 == bs->EncryptedData->DataLength) + return MFX_ERR_NONE; + + auto extEncryptionParam = reinterpret_cast(GetExtendedBuffer(bs->ExtParam, + bs->NumExtParam, MFX_EXTBUFF_ENCRYPTION_PARAM)); + + if (nullptr == extEncryptionParam) + return MFX_ERR_INVALID_HANDLE; + + if (0 == m_pProtectedSessionID) + { + m_pProtectedSessionID = CreateProtectedSession(extEncryptionParam->encryption_type); + Status umcRes = AttachProtectedSession(m_pProtectedSessionID); + if (UMC_OK != umcRes) { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_EXTCALL, "AttachProtectedSession failed!"); + MFX_TRACE_I(umcRes); + } + } + + // commit a surface to receive decrypted slice headers + // setup VACencStatusBuf + VASurfaceID decryptedSurface = VA_INVALID_ID; + constexpr size_t kDecryptQuerySizeAndAlignment = 4096; + constexpr size_t kVaQueryCencBufferSize = 2048; + constexpr int kCencStatusSurfaceDimension = 64; + void* res = nullptr; + posix_memalign(&res, kDecryptQuerySizeAndAlignment, kDecryptQuerySizeAndAlignment); + std::unique_ptr output_surface_buf((uint8_t*)res); + auto cencStatusBuf = reinterpret_cast(output_surface_buf.get()); + auto slice_param_buf = std::make_unique(); + auto queryCencBuffer = std::make_unique(kVaQueryCencBufferSize); + { + cencStatusBuf->status = VA_ENCRYPTION_STATUS_INCOMPLETE; + cencStatusBuf->buf = queryCencBuffer.get(); + cencStatusBuf->buf_size = kVaQueryCencBufferSize; + cencStatusBuf->slice_buf_type = VaCencSliceBufParamter; + cencStatusBuf->slice_buf_size = sizeof(VACencSliceParameterBufferH264); + cencStatusBuf->slice_buf = slice_param_buf.get(); + + std::vector va_attribs(2); + va_attribs[0].flags = VA_SURFACE_ATTRIB_SETTABLE; + va_attribs[0].type = VASurfaceAttribMemoryType; + va_attribs[0].value.type = VAGenericValueTypeInteger; + va_attribs[0].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_USER_PTR; + + auto buffer_ptr_alloc = std::make_unique(); + uintptr_t* buffer_ptr = buffer_ptr_alloc.get(); + buffer_ptr[0] = reinterpret_cast(output_surface_buf.get()); + + VASurfaceAttribExternalBuffers va_attrib_extbuf{}; + va_attrib_extbuf.num_planes = 3; + va_attrib_extbuf.buffers = buffer_ptr; + va_attrib_extbuf.data_size = 3 * kCencStatusSurfaceDimension * kCencStatusSurfaceDimension; + va_attrib_extbuf.num_buffers = 1u; + va_attrib_extbuf.width = kCencStatusSurfaceDimension; + va_attrib_extbuf.height = kCencStatusSurfaceDimension; + va_attrib_extbuf.offsets[0] = 0; + va_attrib_extbuf.offsets[1] = kCencStatusSurfaceDimension; + va_attrib_extbuf.offsets[2] = kCencStatusSurfaceDimension * 2; + std::fill(va_attrib_extbuf.pitches, va_attrib_extbuf.pitches + 3, kCencStatusSurfaceDimension); + va_attrib_extbuf.pixel_format = VA_FOURCC_RGBP; + + va_attribs[1].flags = VA_SURFACE_ATTRIB_SETTABLE; + va_attribs[1].type = VASurfaceAttribExternalBufferDescriptor; + va_attribs[1].value.type = VAGenericValueTypePointer; + va_attribs[1].value.value.p = &va_attrib_extbuf; + + va_sts = vaCreateSurfaces(m_dpy, VA_RT_FORMAT_RGBP, kCencStatusSurfaceDimension, kCencStatusSurfaceDimension, + &decryptedSurface, 1, &va_attribs[0], va_attribs.size()); + MFX_TRACE_1("vaCreateSurfaces() failed va_sts = ", "%d", va_sts); + if (VA_STATUS_SUCCESS != va_sts) + { + return MFX_ERR_UNKNOWN; + } + } + + // protectedSliceData + VABufferID protectedSliceData = VA_INVALID_ID; + mfxU8* buffer = nullptr; + if (VA_STATUS_SUCCESS != vaCreateBuffer(m_dpy, *m_pContext, VAProtectedSliceDataBufferType, + bs->EncryptedData->DataLength, 1, NULL, &protectedSliceData)) + return MFX_ERR_UNKNOWN; + if (VA_STATUS_SUCCESS != vaMapBuffer(m_dpy, protectedSliceData, (void**)&buffer)) + return MFX_ERR_UNKNOWN; + if (buffer == nullptr) + return MFX_ERR_MEMORY_ALLOC; + + std::copy(bs->EncryptedData->Data, bs->EncryptedData->Data + bs->EncryptedData->DataLength, buffer); + vaUnmapBuffer(m_dpy, protectedSliceData); + + // encryptionParameterBuffer + UMCVACompBuffer *encryptionParameterBuffer; + VAEncryptionParameters* pEncryptionParam = (VAEncryptionParameters*)GetCompBuffer(VAEncryptionParameterBufferType, + &encryptionParameterBuffer, sizeof(VAEncryptionParameters), -1); + if (!pEncryptionParam) + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_API, "pEncryptionParam is nullptr"); + memset(pEncryptionParam, 0, sizeof(VAEncryptionParameters)); + + memcpy(pEncryptionParam->wrapped_decrypt_blob, extEncryptionParam->key_blob, 16); + + pEncryptionParam->key_blob_size = 16; + + pEncryptionParam->encryption_type = extEncryptionParam->encryption_type; + + MFX_TRACE_I(pEncryptionParam->encryption_type); + + pEncryptionParam->segment_info = new VAEncryptionSegmentInfo[extEncryptionParam->uiNumSegments]; + if (!pEncryptionParam->segment_info) + return MFX_ERR_NOT_ENOUGH_BUFFER; + + for (uint32_t i = 0; i < extEncryptionParam->uiNumSegments; i++) + { + memcpy(&pEncryptionParam->segment_info[i], &extEncryptionParam->pSegmentInfo[i], sizeof(*pEncryptionParam->segment_info)); + } + + pEncryptionParam->num_segments = extEncryptionParam->uiNumSegments; + pEncryptionParam->status_report_index = ++count; + MFX_TRACE_I(pEncryptionParam->num_segments); + + for (uint32_t i = 0; i < pEncryptionParam->num_segments; i++) + { + pEncryptionParam->segment_info[i].segment_start_offset = 0; + pEncryptionParam->segment_info[i].segment_length = bs->EncryptedData->DataLength; + pEncryptionParam->segment_info[i].init_byte_length = 0; + MFX_TRACE_I(pEncryptionParam->segment_info[i].segment_length); + } + + // Submit data and handle results + { + va_sts = vaBeginPicture(m_dpy, *m_pContext, decryptedSurface); + MFX_TRACE_1("vaBeginPicture() va_sts = ", "%d", va_sts); + if (VA_STATUS_SUCCESS != va_sts) + { + MFX_TRACE_1("vaBeginPicture() failed va_sts = ", "%d", va_sts); + return MFX_ERR_UNKNOWN; + } + + std::vector buffers; + auto vaCompBuffer = dynamic_cast(encryptionParameterBuffer); + if (nullptr == vaCompBuffer) + { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_EXTCALL, "encryptionParameterBuffer is not VACompBuffer!"); + return MFX_ERR_UNKNOWN; + } + buffers.push_back(vaCompBuffer->GetID()); + buffers.push_back(protectedSliceData); + + va_sts = vaRenderPicture(m_dpy, *m_pContext, buffers.data(), buffers.size()); + MFX_TRACE_1("vaRenderPicture() va_sts = ", "%d", va_sts); + if (VA_STATUS_SUCCESS != va_sts) + { + MFX_TRACE_1("vaRenderPicture() failed va_sts = ", "%d", va_sts); + return MFX_ERR_UNKNOWN; + } + + va_sts = vaEndPicture(m_dpy, *m_pContext); + MFX_TRACE_1("vaEndPicture() va_sts = ", "%d", va_sts); + if (VA_STATUS_SUCCESS != va_sts) + { + MFX_TRACE_1("vaEndPicture() failed va_sts = ", "%d", va_sts); + stsRet = MFX_ERR_UNKNOWN; + } + + if (VA_ENCRYPTION_STATUS_SUCCESSFUL != cencStatusBuf->status) + { + MFX_TRACE_I(cencStatusBuf->status); + } + MFX_TRACE_I(cencStatusBuf->status_report_index_feedback); + + // release resources manually + if (MFX_ERR_NONE != CheckAndDestroyVAbuffer(m_dpy, buffers[0])) + { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_EXTCALL, "CheckAndDestroyVAbuffer failed"); + stsRet = MFX_ERR_UNKNOWN; + } + if (MFX_ERR_NONE != CheckAndDestroyVAbuffer(m_dpy, buffers[1])) + { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_EXTCALL, "CheckAndDestroyVAbuffer failed"); + stsRet = MFX_ERR_UNKNOWN; + } + + for (uint32_t i = 0; i < m_uiCompBuffersUsed; ++i) + { + if (m_pCompBuffers[i]->GetType() == VAEncryptionParameterBufferType) + { + UMC_DELETE(m_pCompBuffers[i]); + m_uiCompBuffersUsed--; + } + } + } + + // check decryption status and results + if (cencStatusBuf->status != VA_ENCRYPTION_STATUS_SUCCESSFUL) + { + MFX_TRACE_1("cencStatusBuf->status is not successful status = ", "%d", cencStatusBuf->status); + stsRet = MFX_ERR_UNKNOWN; + } + MFX_TRACE_I(slice_param_buf->nal_ref_idc); + MFX_TRACE_I(slice_param_buf->idr_pic_flag); + MFX_TRACE_I(slice_param_buf->slice_type); + MFX_TRACE_I(slice_param_buf->field_frame_flag); + MFX_TRACE_I(slice_param_buf->frame_number); + MFX_TRACE_I(slice_param_buf->idr_pic_id); + MFX_TRACE_I(slice_param_buf->pic_order_cnt_lsb); + MFX_TRACE_I(slice_param_buf->delta_pic_order_cnt_bottom); + MFX_TRACE_I(slice_param_buf->delta_pic_order_cnt[0]); + MFX_TRACE_I(slice_param_buf->delta_pic_order_cnt[1]); + MFX_TRACE_I(slice_param_buf->ref_pic_fields.bits.no_output_of_prior_pics_flag); + MFX_TRACE_I(slice_param_buf->ref_pic_fields.bits.long_term_reference_flag); + MFX_TRACE_I(slice_param_buf->ref_pic_fields.bits.adaptive_ref_pic_marking_mode_flag); + MFX_TRACE_I(slice_param_buf->ref_pic_fields.bits.dec_ref_pic_marking_count); + + return stsRet; +} + uint16_t LinuxVideoAccelerator::GetDecodingError(VASurfaceID *surface) { MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_EXTCALL, "GetDecodingError"); From 0966feb5a97eeb27db055734d09c81dd803ce87f Mon Sep 17 00:00:00 2001 From: "Zhang, YichiX" Date: Mon, 2 Dec 2024 13:54:04 +0000 Subject: [PATCH 16/16] 2nd patch --- .../decode/h264/src/mfx_h264_dec_decode.cpp | 2 + _studio/shared/include/mfx_trace.h | 15 + _studio/shared/umc/io/Android.mk | 2 + .../umc/io/umc_va/include/umc_va_linux.h | 19 +- .../shared/umc/io/umc_va/src/umc_va_linux.cpp | 562 +++++++++++++++++- api/vpl/mfxstructures.h | 1 + 6 files changed, 582 insertions(+), 19 deletions(-) diff --git a/_studio/mfx_lib/decode/h264/src/mfx_h264_dec_decode.cpp b/_studio/mfx_lib/decode/h264/src/mfx_h264_dec_decode.cpp index 95fe4131..5c030b98 100644 --- a/_studio/mfx_lib/decode/h264/src/mfx_h264_dec_decode.cpp +++ b/_studio/mfx_lib/decode/h264/src/mfx_h264_dec_decode.cpp @@ -1210,6 +1210,7 @@ mfxStatus VideoDECODEH264::DecodeFrameCheck(mfxBitstream *bs, mfxFrameSurface1 * #endif // MFX_ENABLE_PROTECT MFX_CHECK((bs->DataFlag & MFX_BITSTREAM_COMPLETE_FRAME), MFX_ERR_UNSUPPORTED); + MFX_TRACE_I(bs->NumExtParam); m_va->SetBitstream(bs); m_va->DecryptCTR(bs); @@ -1221,6 +1222,7 @@ mfxStatus VideoDECODEH264::DecodeFrameCheck(mfxBitstream *bs, mfxFrameSurface1 * MFXMediaDataAdapter src(bs); + MFX_TRACE_I(bs->NumExtParam); mfxExtBuffer* extbuf = (bs) ? GetExtendedBuffer(bs->ExtParam, bs->NumExtParam, MFX_EXTBUFF_DECODE_ERROR_REPORT) : NULL; if (extbuf) diff --git a/_studio/shared/include/mfx_trace.h b/_studio/shared/include/mfx_trace.h index 792aece3..4d5c16fe 100644 --- a/_studio/shared/include/mfx_trace.h +++ b/_studio/shared/include/mfx_trace.h @@ -55,6 +55,21 @@ typedef unsigned int mfxTraceU32; typedef __UINT64 mfxTraceU64; + +inline std::string FormatHex(const uint8_t* data, size_t len) +{ + std::ostringstream ss; + ss << std::hex; + for (size_t i = 0; i < len; ++i) { + if (i > 40) { + ss << std::dec << std::setw(0) << "... [" << len << "]"; + break; + } + ss << std::setw(2) << std::setfill('0') << (uint32_t)data[i] << " "; + } + return ss.str(); +}; + /*------------------------------------------------------------------------------*/ extern mfxTraceU64 EventCfg; extern mfxTraceU32 LogConfig; diff --git a/_studio/shared/umc/io/Android.mk b/_studio/shared/umc/io/Android.mk index 0baf70d8..0422be8d 100644 --- a/_studio/shared/umc/io/Android.mk +++ b/_studio/shared/umc/io/Android.mk @@ -29,6 +29,8 @@ LOCAL_CFLAGS := \ LOCAL_CFLAGS_32 := $(MFX_CFLAGS_INTERNAL_32) LOCAL_CFLAGS_64 := $(MFX_CFLAGS_INTERNAL_64) +LOCAL_SHARED_LIBRARIES += liblog + LOCAL_MODULE_TAGS := optional LOCAL_MODULE := libumc_va diff --git a/_studio/shared/umc/io/umc_va/include/umc_va_linux.h b/_studio/shared/umc/io/umc_va/include/umc_va_linux.h index c33cd9d9..3964b187 100644 --- a/_studio/shared/umc/io/umc_va/include/umc_va_linux.h +++ b/_studio/shared/umc/io/umc_va/include/umc_va_linux.h @@ -26,6 +26,7 @@ #include #include +#include namespace UMC { @@ -149,15 +150,29 @@ class LinuxVideoAccelerator : public VideoAccelerator void SetTraceStrings(uint32_t umc_codec); virtual Status SetAttributes(VAProfile va_profile, LinuxVideoAcceleratorParams* pParams, VAConfigAttrib *attribute, int32_t *attribsNumber); - VAProtectedSessionID CreateProtectedSession(uint32_t encryption_type); + VAProtectedSessionID CreateProtectedSession(uint32_t session_mode, + uint32_t session_type, + VAEntrypoint entrypoint, + uint32_t encryption_type); Status AttachProtectedSession(VAProtectedSessionID session_id); + bool InitKey(); + bool PassThrough(void* input, size_t input_size, void* output, size_t output_size); + bool SelectKey(); + bool QueryKeyInfo(const uint8_t key, size_t key_size); + bool SetStreamKey(); + + bool DecryptionBlt(uint8_t* iv, const uint8_t* src, uint8_t* dst, size_t data_length, size_t clear_bytes, size_t encrypt_bytes); protected: VADisplay m_dpy; VAConfigID* m_pConfigId; VAContextID* m_pContext; - VAProtectedSessionID m_pProtectedSessionID; + VAProtectedSessionID m_protectedSessionID; + VAProtectedSessionID m_heci_sessionID; + std::array m_selectKey; + std::pair, bool> m_key_blob; + uint32_t m_key_session; bool* m_pKeepVAState; lvaFrameState m_FrameState; diff --git a/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp b/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp index cd1167b0..300e0ff5 100644 --- a/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp +++ b/_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp @@ -19,7 +19,8 @@ // SOFTWARE. #include - +#include +#include #include "umc_defs.h" #include "umc_va_linux.h" @@ -31,10 +32,55 @@ #include "va_protected_content.h" #include "va_protected_content_private.h" +#include #define UMC_VA_NUM_OF_COMP_BUFFERS 8 #define UMC_VA_DECODE_STREAM_OUT_ENABLE 2 +union pavp_header_stream_t { + uint32_t dw; + struct { + uint32_t pavp_session_index : 7; + uint32_t app_type : 1; + uint32_t reserved : 23; + uint32_t valid : 1; + } fields; +}; +union pavp_42_header_stream_t { + uint32_t dw; + struct { + uint32_t valid : 1; + uint32_t app_type : 1; + uint32_t stream_id : 16; + uint32_t reserved : 14; + } fields; +}; + +constexpr uint32_t FIRMWARE_API_VERSION_2_1 = ((2 << 16) | (1)); +constexpr uint32_t FIRMWARE_API_VERSION_4_2 = ((4 << 16) | (2)); + +struct pavp_cmd_header_t { + uint32_t api_version = FIRMWARE_API_VERSION_2_1; + uint32_t command_id; + union { + uint32_t status; + pavp_header_stream_t stream_id; + pavp_42_header_stream_t stream_id_42; + }; + uint32_t buffer_len; +}; + +struct wv20_select_key_in { + pavp_cmd_header_t header; + uint32_t session_id; + uint32_t key_id_size; + uint8_t key_id[]; +}; +struct wv20_select_key_out { + pavp_cmd_header_t header; +}; +constexpr u_int32_t wv20_select_key = 0x00C2000D; + UMC::Status va_to_umc_res(VAStatus va_res) { UMC::Status umcRes = UMC::UMC_OK; @@ -330,7 +376,11 @@ LinuxVideoAccelerator::LinuxVideoAccelerator(void) #endif m_bH264MVCSupport = false; - m_pProtectedSessionID = 0; + m_protectedSessionID = VA_INVALID_ID; + m_heci_sessionID = VA_INVALID_ID; + memset(m_key_blob.first.data(), 0, 16); + m_key_blob.second = false; + m_key_session = -1; memset(&m_guidDecoder, 0 , sizeof(GUID)); } @@ -555,8 +605,9 @@ Status LinuxVideoAccelerator::Init(VideoAcceleratorParams* pInfo) if (pParams->encryption_type > 0 && UMC_OK == umcRes) { - m_pProtectedSessionID = CreateProtectedSession(pParams->encryption_type); - umcRes = AttachProtectedSession(m_pProtectedSessionID); + m_protectedSessionID = CreateProtectedSession(VA_PC_SESSION_MODE_LITE, + VA_PC_SESSION_TYPE_DISPLAY, VAEntrypointProtectedContent, pParams->encryption_type); + umcRes = AttachProtectedSession(m_protectedSessionID); } } return umcRes; @@ -596,7 +647,10 @@ Status LinuxVideoAccelerator::SetAttributes(VAProfile va_profile, LinuxVideoAcce return UMC_OK; } -VAProtectedSessionID LinuxVideoAccelerator::CreateProtectedSession(uint32_t encryption_type) +VAProtectedSessionID LinuxVideoAccelerator::CreateProtectedSession(uint32_t session_mode, + uint32_t session_type, + VAEntrypoint entrypoint, + uint32_t encryption_type) { MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_HOTSPOTS, "LinuxVideoAccelerator::CreateProtectedSession"); VAStatus va_status = VA_STATUS_SUCCESS; @@ -616,7 +670,7 @@ VAProtectedSessionID LinuxVideoAccelerator::CreateProtectedSession(uint32_t encr int entr = 0; for (entr = 0; entr < num_entrypoints; entr++) { - if (entrypoints[entr] == VAEntrypointProtectedContent) + if (entrypoints[entr] == entrypoint) break; } MFX_CHECK(entr != num_entrypoints, VA_INVALID_ID); @@ -639,12 +693,12 @@ VAProtectedSessionID LinuxVideoAccelerator::CreateProtectedSession(uint32_t encr attrib_cp[6].type = (VAConfigAttribType)VAConfigAttribProtectedContentUsage; attrib_count = 7; - va_status = vaGetConfigAttributes(m_dpy, VAProfileProtected, VAEntrypointProtectedContent, + va_status = vaGetConfigAttributes(m_dpy, VAProfileProtected, entrypoint, attrib_cp, attrib_count); MFX_CHECK(VA_STATUS_SUCCESS == va_status, VA_INVALID_ID); - attrib_cp[0].value = VA_PC_SESSION_MODE_HEAVY; // session_mode - attrib_cp[1].value = VA_PC_SESSION_TYPE_DISPLAY; // session_type + attrib_cp[0].value = session_mode; + attrib_cp[1].value = session_type; attrib_cp[2].value = VA_PC_CIPHER_AES; attrib_cp[3].value = VA_PC_BLOCK_SIZE_128; attrib_cp[4].value = VA_PC_CIPHER_MODE_CTR; @@ -657,18 +711,27 @@ VAProtectedSessionID LinuxVideoAccelerator::CreateProtectedSession(uint32_t encr attrib_cp[6].value = VA_PC_USAGE_DEFAULT; VAConfigID config_id; - va_status = vaCreateConfig(m_dpy, VAProfileProtected, VAEntrypointProtectedContent, attrib_cp, + va_status = vaCreateConfig(m_dpy, VAProfileProtected, entrypoint, attrib_cp, attrib_count, &config_id); - MFX_CHECK(VA_STATUS_SUCCESS == va_status, VA_INVALID_ID); + if (va_status != VA_STATUS_SUCCESS) + { + MFX_TRACE_1("vaCreateConfig failed: ", "%d", va_status); + return VA_INVALID_ID; + } VAProtectedSessionID session = VA_INVALID_ID; MFX_LTRACE_MSG(MFX_TRACE_LEVEL_HOTSPOTS, "vaCreateProtectedSession"); va_status = vaCreateProtectedSession(m_dpy, config_id, &session); + if (va_status != VA_STATUS_SUCCESS) + { + MFX_TRACE_1("vaCreateProtectedSession failed: ", "%d", va_status); + return VA_INVALID_ID; + } - VAStatus destroy_status = vaDestroyConfig(m_dpy, config_id); + va_status = vaDestroyConfig(m_dpy, config_id); - if (destroy_status != VA_STATUS_SUCCESS) - MFX_TRACE_1("", "Error cleaning up config: %d", destroy_status); + if (va_status != VA_STATUS_SUCCESS) + MFX_TRACE_1("vaDestroyConfig: ", "%d", va_status); MFX_CHECK(VA_STATUS_SUCCESS == va_status, VA_INVALID_ID); @@ -691,6 +754,305 @@ Status LinuxVideoAccelerator::AttachProtectedSession(VAProtectedSessionID sessio return umcRes; } +bool LinuxVideoAccelerator::InitKey() +{ + MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_EXTCALL, "LinuxVideoAccelerator::InitKey"); + if (VA_INVALID_ID == m_protectedSessionID) + return false; + // Get App id + uint32_t app_id = 0xFF; + VABufferID buffer = 0; + VAProtectedSessionExecuteBuffer execBuff = {0}; + VAStatus va_status; + + execBuff.function_id = VA_TEE_EXEC_GPU_FUNCID_GET_SESSION_ID; + execBuff.input.data_size = 0; + execBuff.input.data = nullptr; + execBuff.output.data_size = sizeof(uint32_t); + execBuff.output.data = (void*)&app_id; + + va_status = vaCreateBuffer(m_dpy, m_protectedSessionID, + VAProtectedSessionExecuteBufferType, + sizeof(execBuff), 1, &execBuff, &buffer); + if (va_status) { + MFX_TRACE_1("vaCreateBuffer() failed va_sts = ", "%d", va_status); + return false; + } + + ALOGD("zyc, vaProtectedSessionExecute + line: %d", __LINE__); + va_status = vaProtectedSessionExecute(m_dpy, m_protectedSessionID, buffer); + vaDestroyBuffer(m_dpy, buffer); + if (va_status) { + MFX_TRACE_1("vaProtectedSessionExecute fail va_status = ", "%d", va_status); + return false; + } + + app_id = app_id & 0x7F; // remove bit7 for app_type information + MFX_TRACE_I(app_id); + + // GetWrappedTitleKey + constexpr uint32_t wv20_get_wrapped_title_keys = 0x00C20022; + + struct wv20_get_wrapped_title_keys_in { + pavp_cmd_header_t header; + uint32_t session_id; + } cmd_in; + + struct wv20_get_wrapped_title_keys_out { + pavp_cmd_header_t header; + uint32_t num_keys; + uint32_t title_key_obj_offset; + uint32_t buffer_size; + uint8_t buffer[]; + }; + + constexpr uint32_t PAVP_HECI_IO_BUFFER_SIZE = 16 * 1024; + cmd_in.header.command_id = wv20_get_wrapped_title_keys; // command id + cmd_in.header.stream_id_42.fields.valid = 1; + cmd_in.header.stream_id_42.fields.app_type = 0; // pavp::PAVP_APPTYPE_DISPLAYABLE + cmd_in.header.stream_id_42.fields.stream_id = app_id; + cmd_in.header.buffer_len = sizeof(wv20_get_wrapped_title_keys_in) - sizeof(pavp_cmd_header_t); + cmd_in.session_id = m_key_session; + MFX_TRACE_I(cmd_in.session_id); + + auto pCmd_out = std::make_unique(PAVP_HECI_IO_BUFFER_SIZE + sizeof(wv20_get_wrapped_title_keys_out)); + auto cmd_out = reinterpret_cast(pCmd_out.get()); + cmd_out->buffer_size = PAVP_HECI_IO_BUFFER_SIZE; + + PassThrough(&cmd_in, sizeof(wv20_get_wrapped_title_keys_in), cmd_out, PAVP_HECI_IO_BUFFER_SIZE + sizeof(wv20_get_wrapped_title_keys_out)); + + struct wrapped_title_key_t { + uint32_t key_id_size; + uint32_t key_id_offset; + uint32_t enc_title_key_offset; + }; + + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_HOTSPOTS, "get title key +"); + const wrapped_title_key_t* wtk = reinterpret_cast( + cmd_out->buffer + cmd_out->title_key_obj_offset); + MFX_TRACE_I(cmd_out->title_key_obj_offset); + MFX_TRACE_I(wtk->key_id_size); + for (uint32_t i = 0; i < cmd_out->num_keys; i++, wtk++) + { + if ((uint64_t)wtk->key_id_offset + wtk->key_id_size > cmd_out->buffer_size) + { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_HOTSPOTS, "Offset points past end of buffer"); + return false; + } + const uint8_t* key_id_to_compare = cmd_out->buffer + wtk->key_id_offset; + + MFX_TRACE_1("select_key = ", "%s", FormatHex(m_selectKey.data(), 16).c_str()); + MFX_TRACE_1("got key id = ", "%s", FormatHex(key_id_to_compare, wtk->key_id_size).c_str()); + + if (memcmp(m_selectKey.data(), key_id_to_compare, wtk->key_id_size) == 0) + { + // key blob + uint8_t* key_blob_start = cmd_out->buffer + wtk->enc_title_key_offset; + std::copy(key_blob_start, key_blob_start + 16, m_key_blob.first.begin()); + MFX_TRACE_1("got key_blob = ", "%s", FormatHex(m_key_blob.first.begin(), 16).c_str()); + m_key_blob.second = true; + break; + } + } + + if (!m_key_blob.second) + { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_HOTSPOTS, "Cannot find right key blob!"); + return false; + } + + return true; +} + +bool LinuxVideoAccelerator::PassThrough(void* input, size_t input_size, void* output, size_t output_size) +{ + MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_EXTCALL, "LinuxVideoAccelerator::PassThrough"); + if (VA_INVALID_ID == m_heci_sessionID) + { + // create HECI session + m_heci_sessionID = CreateProtectedSession(VA_PC_SESSION_MODE_NONE, VA_PC_SESSION_TYPE_NONE, + VAEntrypointProtectedTEEComm, VA_ENCRYPTION_TYPE_FULLSAMPLE_CTR); + if (m_heci_sessionID == VA_INVALID_ID) { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_EXTCALL,"Create HECI session fails"); + return false; + } + } + + if (output_size == 16) + { + auto p = reinterpret_cast(output); + MFX_TRACE_I(p->header.api_version); + } + + VABufferID buffer; + VAProtectedSessionExecuteBuffer execBuff = {0}; + execBuff.function_id = VA_TEE_EXECUTE_FUNCTION_ID_PASS_THROUGH; + execBuff.input.data_size = input_size; + execBuff.input.data = input; + execBuff.output.data_size = output_size; + execBuff.output.data = output; + + VAStatus va_status = vaCreateBuffer(m_dpy, m_heci_sessionID, VAProtectedSessionExecuteBufferType, + sizeof(execBuff), 1, &execBuff, &buffer); + if (va_status) { + MFX_TRACE_1("vaCreateBuffer() failed va_sts = ", "%d", va_status); + return false; + } + + ALOGD("zyc, vaProtectedSessionExecute + line: %d", __LINE__); + va_status = vaProtectedSessionExecute(m_dpy, m_heci_sessionID, buffer); + pavp_cmd_header_t* pIHeader = static_cast(input); + pavp_cmd_header_t* pOHeader = static_cast(output); + vaDestroyBuffer(m_dpy, buffer); + if (va_status || pOHeader->status) { + MFX_TRACE_3("PassThrough failed ", "command id = %d, va_status = %d, pOHeader->status = %d", + pIHeader->command_id, va_status, pOHeader->status); + return false; + } + + return true; +} + +bool LinuxVideoAccelerator::SelectKey() +{ + MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_EXTCALL, "LinuxVideoAccelerator::SelectKey"); + + // Get a session id + constexpr uint32_t wv20_open_session = 0x00C20003; + struct wv20_open_session_in { + pavp_cmd_header_t header; + }; + + struct wv20_open_session_out { + pavp_cmd_header_t header; + uint32_t session_id; + }; + + if (m_key_session < 0) + { + wv20_open_session_in open_session_in {}; + wv20_open_session_out open_session_out {}; + open_session_in.header.command_id = wv20_open_session; + open_session_in.header.status = 0; + open_session_in.header.buffer_len = sizeof(wv20_open_session_in) - sizeof(pavp_cmd_header_t); + if (!PassThrough(&open_session_in, sizeof(wv20_open_session_in), &open_session_out, sizeof(wv20_open_session_out))) + { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_HOTSPOTS, "PassThrough failed!"); + return false; + } + MFX_TRACE_1("Got session id = ", "%d", open_session_out.session_id); + m_key_session = open_session_out.session_id; + } + size_t input_size = m_selectKey.size() + sizeof(wv20_select_key_in); + auto pCmd_in = std::make_unique(m_selectKey.size() + sizeof(wv20_select_key_in)); + auto select_key_in = reinterpret_cast(pCmd_in.get()); + + select_key_in->session_id = m_key_session; + select_key_in->header.api_version = FIRMWARE_API_VERSION_2_1; + select_key_in->header.command_id = wv20_select_key; // command id + select_key_in->header.buffer_len = input_size - sizeof(pavp_cmd_header_t); + select_key_in->key_id_size = m_selectKey.size(); + memcpy(select_key_in->key_id, m_selectKey.data(), m_selectKey.size()); + + wv20_select_key_out select_key_out{}; + + ALOGD("zyc, select key pass +"); + if (!PassThrough(select_key_in, input_size, &select_key_out, sizeof(wv20_select_key_out))) + { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_HOTSPOTS, "PassThrough failed!"); + return false; + } + ALOGD("zyc, select key pass -"); + + m_key_blob.second = false; + return true; +} + +bool LinuxVideoAccelerator::QueryKeyInfo(const uint8_t key, size_t key_size) +{ + MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_HOTSPOTS, "LinuxVideoAccelerator::QueryKeyInfo"); + + constexpr uint32_t wv20_query_key_control = 0x00C2000C; + + struct wv20_query_key_control_in { + pavp_cmd_header_t header; + uint32_t session_id; + uint32_t content_key_id_size; + uint8_t content_key_id[]; + }; + + struct wv20_query_key_control_out { + pavp_cmd_header_t header; + uint32_t key_control_block_size; + uint8_t key_control_block[]; + }; + + auto pCmd_in = std::make_unique(sizeof(wv20_query_key_control_in) + key_size); + auto cmd_in = reinterpret_cast(pCmd_in.get()); + cmd_in->header.api_version = FIRMWARE_API_VERSION_2_1; + cmd_in->header.command_id = wv20_query_key_control; + cmd_in->header.status = 0; + cmd_in->header.buffer_len = sizeof(wv20_query_key_control_in) + key_size - sizeof(pavp_cmd_header_t); + + auto pCmd_out = std::make_unique(sizeof(wv20_query_key_control_out) + 16); + auto cmd_out = reinterpret_cast(pCmd_out.get()); + + return true; +} + +bool LinuxVideoAccelerator::SetStreamKey() +{ + MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_HOTSPOTS, "LinuxVideoAccelerator::SetStreamKey"); + + VABufferID buffer = 0; + VAProtectedSessionExecuteBuffer execBuff = {0}; + VAStatus va_status; + + struct PAVP_SET_STREAM_KEY_PARAMS { + uint32_t StreamType; + uint32_t EncryptedDecryptKey[4]; + union { + uint32_t EncryptedEncryptKey[4]; + uint32_t EncryptedDecryptRotationKey[4]; + }; + } SetStreamKeyParams; + SetStreamKeyParams.StreamType = 0; // PAVP_SET_KEY_DECRYPT = 1 + if (sizeof(SetStreamKeyParams.EncryptedDecryptKey) != m_key_blob.first.size()) + { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_HOTSPOTS, "SetStreamKeyParams.EncryptedDecryptKey size incorrect"); + return false; + } + memcpy(SetStreamKeyParams.EncryptedDecryptKey, m_key_blob.first.begin(), m_key_blob.first.size()); + + execBuff = {}; + execBuff.function_id = VA_TEE_EXEC_GPU_FUNCID_SET_STREAM_KEY; + execBuff.input.data_size = sizeof(SetStreamKeyParams); + execBuff.input.data = &SetStreamKeyParams; + execBuff.output.data_size = 0; + execBuff.output.data = nullptr; + + MFX_TRACE_1("SetStreamKeyParams.EncryptedDecryptKey = ", "%s", FormatHex((uint8_t*)SetStreamKeyParams.EncryptedDecryptKey, 16).c_str()); + + buffer = 0; + va_status = vaCreateBuffer(m_dpy, m_protectedSessionID, + VAProtectedSessionExecuteBufferType, + sizeof(execBuff), 1, &execBuff, &buffer); + if (va_status) { + MFX_TRACE_1("FATAL:SetStreamKey: CreateBuffer fail ", "%d", va_status); + return false; + } + + ALOGD("zyc, vaProtectedSessionExecute + line: %d", __LINE__); + va_status = vaProtectedSessionExecute(m_dpy, m_protectedSessionID, buffer); + vaDestroyBuffer(m_dpy, buffer); + if (va_status) { + MFX_TRACE_1("FATAL:SetStreamKey: ProtectedSessionExecute fail ", "%d", va_status); + return false; + } + + return true; +} + Status LinuxVideoAccelerator::Close(void) { MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_HOTSPOTS, "LinuxVideoAccelerator::Close"); @@ -1071,16 +1433,126 @@ mfxStatus LinuxVideoAccelerator::DecryptCTR(mfxBitstream* bs) if (nullptr == extEncryptionParam) return MFX_ERR_INVALID_HANDLE; - if (0 == m_pProtectedSessionID) + if (VA_INVALID_ID == m_protectedSessionID) { - m_pProtectedSessionID = CreateProtectedSession(extEncryptionParam->encryption_type); - Status umcRes = AttachProtectedSession(m_pProtectedSessionID); + m_protectedSessionID = CreateProtectedSession(VA_PC_SESSION_MODE_LITE, + VA_PC_SESSION_TYPE_DISPLAY, VAEntrypointProtectedContent, extEncryptionParam->encryption_type); + Status umcRes = AttachProtectedSession(m_protectedSessionID); if (UMC_OK != umcRes) { MFX_LTRACE_MSG(MFX_TRACE_LEVEL_EXTCALL, "AttachProtectedSession failed!"); MFX_TRACE_I(umcRes); } } + m_key_session = extEncryptionParam->session; + MFX_TRACE_1("selectKey from c2 = ", "%s", FormatHex(extEncryptionParam->key_blob, 16).c_str()); + if (memcmp(m_selectKey.data(), extEncryptionParam->key_blob, 16) != 0) + { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_EXTCALL, "select changed, need to update"); + std::copy(extEncryptionParam->key_blob, extEncryptionParam->key_blob + 16, m_selectKey.data()); + m_key_blob.second = false; + } + + // Get session & Select Key + /* + if (memcmp(extEncryptionParam->key_blob, m_selectKey.data(), 16) != 0) + { + if (!SelectKey()) + { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_EXTCALL, "SelectKey failed!"); + return MFX_ERR_UNKNOWN; + } + }*/ + + if (!m_key_blob.second) + { + if (!InitKey()) + { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_EXTCALL, "InitKey failed!"); + return MFX_ERR_UNKNOWN; + } + } + + if (!SetStreamKey()) + { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_EXTCALL, "SetStreamKey failed!"); + return MFX_ERR_UNKNOWN; + } + + auto dst = std::make_unique(bs->EncryptedData->DataLength); + memset(dst.get(), 0, bs->EncryptedData->DataLength); + size_t clear_bytes = bs->DataLength - bs->EncryptedData->DataLength; + + MFX_TRACE_1("bs->EncryptedData->Data = ", "%s", FormatHex(bs->EncryptedData->Data, 100).c_str()); + MFX_TRACE_I(bs->EncryptedData->DataLength); + + auto increment_ctr_be = [](std::array& iv) { + for (auto i = 16 - 1; i >= 16 / 2; i--) { + iv[i]++; + + // check for overflow + if (iv[i]) + break; + } + }; + + auto block_offset = extEncryptionParam->pSegmentInfo[0].partial_aes_block_size; + auto to_decrypted_length = bs->EncryptedData->DataLength; + auto to_decrypted_start = bs->EncryptedData->Data; + std::array current_iv = {}; + std::copy(extEncryptionParam->pSegmentInfo[0].aes_cbc_iv_or_ctr, + extEncryptionParam->pSegmentInfo[0].aes_cbc_iv_or_ctr + 16, current_iv.begin()); + + MFX_TRACE_1("IV = ", "%s", FormatHex(current_iv.data(), 16).c_str()); + + size_t dst_offset = 0; + + if (block_offset) + { + MFX_TRACE_I(block_offset); + uint8_t temp_buffer[16]; + if (!DecryptionBlt(current_iv.data(), to_decrypted_start - block_offset, temp_buffer, 16, 0, 0)) + { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_EXTCALL, "DecryptionBlt error!"); + return MFX_ERR_UNKNOWN; + } + size_t len = 16 - block_offset; + if (len > to_decrypted_length) { + len = to_decrypted_length; + } else { + // increment iv + increment_ctr_be(current_iv); + } + memcpy(dst.get(), temp_buffer + block_offset, len); + + to_decrypted_start += len; + dst_offset += len; + to_decrypted_length -= len; + } + + DecryptionBlt(current_iv.data(), to_decrypted_start, dst.get() + dst_offset, to_decrypted_length, 0, 0); + + if (bs->DataLength < clear_bytes + bs->EncryptedData->DataLength) + { + MFX_LTRACE_MSG(MFX_TRACE_LEVEL_EXTCALL, "bs->DataLength is not enough to copy!"); + return MFX_ERR_UNKNOWN; + } + std::copy(dst.get(), dst.get() + bs->EncryptedData->DataLength, bs->EncryptedData->Data); + + MFX_TRACE_1("dst = ", "%s", FormatHex(dst.get(), 500).c_str()); + //static int once = 0; + //if (once++ == 0) + //{ + FILE * file = fopen("/data/local/tmp/onevpl_decryped_data.txt", "a+"); + if (file != nullptr) + { + fwrite(bs->Data, bs->DataLength, 1, file); + fclose(file); + } + //} + + return stsRet; + // commit a surface to receive decrypted slice headers // setup VACencStatusBuf VASurfaceID decryptedSurface = VA_INVALID_ID; @@ -1277,6 +1749,62 @@ mfxStatus LinuxVideoAccelerator::DecryptCTR(mfxBitstream* bs) return stsRet; } +bool LinuxVideoAccelerator::DecryptionBlt(uint8_t* iv, + const uint8_t* src, + uint8_t* dst, + size_t data_length, + size_t clear_bytes, + size_t encrypt_bytes) { + MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_INTERNAL, "LinuxVideoAccelerator::DecryptionBlt"); + VAStatus va_status; + VABufferID buffer; + VAProtectedSessionExecuteBuffer execBuff = {0}; + VAEncryptionSegmentInfo segmentInfo = {0}; + VAEncryptionParameters encParams = {0}; + VA_PROTECTED_BLT_PARAMS DecryptionBltParams = {0}; + + if (m_protectedSessionID == VA_INVALID_ID) { + MFX_TRACE_1("FATAL:DecryptionBlt: cp session id invalid, mode = ", "%d", m_protectedSessionID); + return false; + } + + encParams.num_segments = 1; + encParams.segment_info = &segmentInfo; + DecryptionBltParams.enc_params = &encParams; + memcpy(segmentInfo.aes_cbc_iv_or_ctr, iv, 16/*CP_CRYPTO_AES_IV_SIZE*/); + segmentInfo.init_byte_length = clear_bytes; + segmentInfo.segment_length = clear_bytes + encrypt_bytes; + + DecryptionBltParams.src_resource = const_cast(src); + DecryptionBltParams.dst_resource = dst; + DecryptionBltParams.width = data_length; + DecryptionBltParams.height = 1; + + execBuff.function_id = VA_TEE_EXEC_GPU_FUNCID_DECRYPTION_BLT; + execBuff.input.data_size = sizeof(DecryptionBltParams); + execBuff.input.data = &DecryptionBltParams; + + va_status = vaCreateBuffer(m_dpy, m_protectedSessionID, + VAProtectedSessionExecuteBufferType, + sizeof(execBuff), 1, &execBuff, &buffer); + if (va_status) { + MFX_TRACE_1("FATAL:DecryptionBlt: CreateBuffer fail ", "%d", va_status); + return false; + } + + ALOGD("zyc, vaProtectedSessionExecute + line: %d", __LINE__); + va_status = vaProtectedSessionExecute(m_dpy, m_protectedSessionID, buffer); + MFX_TRACE_1("vaProtectedSessionExecute va_status = ", "%d", va_status); + vaDestroyBuffer(m_dpy, buffer); + if (va_status) { + MFX_TRACE_1("FATAL:DecryptionBlt: vaProtectedSessionExecute fail ", "%d", va_status); + return false; + } + + // Return true for successful SecPassThru + return true; +} + uint16_t LinuxVideoAccelerator::GetDecodingError(VASurfaceID *surface) { MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_EXTCALL, "GetDecodingError"); diff --git a/api/vpl/mfxstructures.h b/api/vpl/mfxstructures.h index e182c92f..403fa8fe 100644 --- a/api/vpl/mfxstructures.h +++ b/api/vpl/mfxstructures.h @@ -5142,6 +5142,7 @@ typedef struct { mfxExtBuffer Header; /*!< Extension buffer header. Header.BufferId must be equal to MFX_EXTBUFF_ENCRYPTION_PARAM. */ mfxU32 encryption_type; mfxU8 key_blob[16]; + mfxU32 session; mfxU32 uiNumSegments; EncryptionSegmentInfo *pSegmentInfo; } mfxExtEncryptionParam;