Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Commit

Permalink
Release 2021.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
akwrobel committed Apr 1, 2021
1 parent 71504c6 commit 07b524f
Show file tree
Hide file tree
Showing 57 changed files with 4,215 additions and 988 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ set(CMAKE_NO_SYSTEM_FROM_IMPORTED

file(STRINGS "version.txt" version_txt)
project(oneVPL-cpu VERSION ${version_txt})
if(NOT "${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
message(FATAL_ERROR "Unsupported architecture: only 64-bit supported")
endif()

#
# Project configuration options
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ which includes the following features:
- H.264/AVC encode (using x264 and libavcodec)
- VPP - Crop, Resize, CSC (using libavfilter/ FFmpeg filters)

Note: H.265/HEVC, H.264, and AV1 are not avalible in 32-bit builds.

---

**NOTE** Use of this implementation requires installation of the loader provided
Expand Down Expand Up @@ -90,6 +92,8 @@ for more information.
pacman --needed -Sy mingw-w64-x86_64-cmake git python-pip
pacman --needed -Sy mingw-w64-x86_64-meson mingw-w64-x86_64-ninja
# For 32-bit builds you will also need a 32-bit toolchain
pacman --needed -Sy mingw-w64-i686-toolchain
---
**NOTE** While the msys2 shell is used in initial setup, it is not otherwise
Expand Down
13 changes: 12 additions & 1 deletion cmake/CompileOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,25 @@
#
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-D_DEBUG)
if(UNIX)
set(CMAKE_CXX_FLAGS "-O0 -g ${CMAKE_CXX_FLAGS}")
endif(UNIX)
endif()

if(MSVC)
add_link_options("/DYNAMICBASE")
add_link_options("/HIGHENTROPYVA")
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
add_link_options("/HIGHENTROPYVA")
endif()
add_link_options("/LARGEADDRESSAWARE")
add_link_options("/NXCOMPAT")
add_compile_options("/GS")
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D \"SAFESEH:NO\"")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")
endif()
else()
add_compile_options("-Wformat")
add_compile_options("-Wformat-security")
Expand Down
10 changes: 8 additions & 2 deletions cmake/oneAPIInstallDirs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@
# Set installation directories
#

set(CMAKE_INSTALL_BINDIR bin)
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
set(CMAKE_INSTALL_BINDIR bin32)
set(CMAKE_INSTALL_LIBDIR lib32)
else()
set(CMAKE_INSTALL_BINDIR bin)
set(CMAKE_INSTALL_LIBDIR lib)
endif()

set(CMAKE_INSTALL_INCLUDEDIR include)
set(CMAKE_INSTALL_LIBDIR lib)
set(CMAKE_INSTALL_DOCDIR documentation)
set(CMAKE_INSTALL_ENVDIR env)
set(CMAKE_INSTALL_MODDIR modulefiles)
Expand Down
4 changes: 4 additions & 0 deletions cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ endif()
find_package(VPL REQUIRED COMPONENTS api)
target_link_libraries(${TARGET} PUBLIC VPL::api)

if(BUILD_GPL_X264)
add_definitions("-DENABLE_ENCODER_H264")
endif(BUILD_GPL_X264)

add_subdirectory(ext/ffmpeg-svt)

target_link_libraries(${TARGET} PRIVATE ffmpeg-svt)
Expand Down
145 changes: 98 additions & 47 deletions cpu/ext/ffmpeg-svt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ set(TARGET ffmpeg-svt)
add_library(${TARGET} INTERFACE)

if(NOT DEFINED ENV{VPL_BUILD_DEPENDENCIES})
message(FATAL_ERROR "VPL_BUILD_DEPENDENCIES not defined in environment")
set(VPL_DEP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../_deps)
message(STATUS "Using default destination located at ${VPL_DEP_DIR}")
else()
set(VPL_DEP_DIR $ENV{VPL_BUILD_DEPENDENCIES})
message(STATUS "Using VPL_BUILD_DEPENDENCIES located at ${VPL_DEP_DIR}")
endif()

option(BUILD_GPL_X264 "Build X264 with GPL License" OFF)

set(SVTHEVCENC_LIB ${VPL_DEP_DIR}/lib/libSvtHevcEnc.a)
set(SVTAV1ENC_LIB ${VPL_DEP_DIR}/lib/libSvtAv1Enc.a)
set(DAV1D_LIB ${VPL_DEP_DIR}/lib/libdav1d.a)
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
set(SVTHEVCENC_LIB ${VPL_DEP_DIR}/lib/libSvtHevcEnc.a)
set(SVTAV1ENC_LIB ${VPL_DEP_DIR}/lib/libSvtAv1Enc.a)
set(DAV1D_LIB ${VPL_DEP_DIR}/lib/libdav1d.a)
endif()
set(AVCODEC_LIB ${VPL_DEP_DIR}/lib/libavcodec.a)
set(AVUTIL_LIB ${VPL_DEP_DIR}/lib/libavutil.a)
set(AVFILTER_LIB ${VPL_DEP_DIR}/lib/libavfilter.a)
Expand All @@ -33,10 +36,15 @@ if(BUILD_GPL_X264)
endif()
endif(BUILD_GPL_X264)

if(NOT EXISTS ${SVTHEVCENC_LIB}
OR NOT EXISTS ${SVTHEVCENC_LIB}
OR NOT EXISTS ${DAV1D_LIB}
OR NOT EXISTS ${AVCODEC_LIB}
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
if(NOT EXISTS ${SVTHEVCENC_LIB}
OR NOT EXISTS ${SVTHEVCENC_LIB}
OR NOT EXISTS ${DAV1D_LIB})
message(FATAL_ERROR "Could not find expected FFmpeg libraries")
endif()
endif()

if(NOT EXISTS ${AVCODEC_LIB}
OR NOT EXISTS ${AVUTIL_LIB}
OR NOT EXISTS ${AVFILTER_LIB}
OR NOT EXISTS ${SWSCALE_LIB})
Expand All @@ -50,30 +58,60 @@ if(MSVC)
else()
set(MSYS_ROOT $ENV{MSYS_ROOT})
endif()
execute_process(COMMAND ${MSYS_ROOT}/mingw64/bin/gcc.exe --version

message(STATUS "${CMAKE_SIZEOF_VOID_P}")
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
message(STATUS "64 bit")
set(mingw_name mingw64)
set(gcc_name x86_64-w64-mingw32)
elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
message(STATUS "32 bit")
set(mingw_name mingw32)
set(gcc_name i686-w64-mingw32)
else()
message(STATUS "${CMAKE_SIZEOF_VOID_P} * 8 bit")
message(FATAL_ERROR "Cannot identify library folder")
endif()

execute_process(COMMAND ${MSYS_ROOT}/${mingw_name}/bin/gcc.exe --version
OUTPUT_VARIABLE gcc_version_text)
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" gcc_version ${gcc_version_text})

set(GCC_LIB
${MSYS_ROOT}/mingw64/lib/gcc/x86_64-w64-mingw32/${gcc_version}/libgcc.a)
${MSYS_ROOT}/${mingw_name}/lib/gcc/${gcc_name}/${gcc_version}/libgcc.a)
set(GCC_EH_LIB
${MSYS_ROOT}/mingw64/lib/gcc/x86_64-w64-mingw32/${gcc_version}/libgcc_eh.a
)
set(BCRYPT_LIB ${MSYS_ROOT}/mingw64/x86_64-w64-mingw32/lib/libbcrypt.a)
set(MINGW32_LIB ${MSYS_ROOT}/mingw64/x86_64-w64-mingw32/lib/libmingw32.a)
set(MINGWEX_LIB ${MSYS_ROOT}/mingw64/x86_64-w64-mingw32/lib/libmingwex.a)
${MSYS_ROOT}/${mingw_name}/lib/gcc/${gcc_name}/${gcc_version}/libgcc_eh.a)
set(BCRYPT_LIB ${MSYS_ROOT}/${mingw_name}/${gcc_name}/lib/libbcrypt.a)
set(MINGW32_LIB ${MSYS_ROOT}/${mingw_name}/${gcc_name}/lib/libmingw32.a)
set(MINGWEX_LIB ${MSYS_ROOT}/${mingw_name}/${gcc_name}/lib/libmingwex.a)
set(PTHREAD_IMPLIB
${MSYS_ROOT}/mingw64/x86_64-w64-mingw32/lib/libpthread.dll.a)
set(PTHREAD_DLL ${MSYS_ROOT}/mingw64/bin/libwinpthread-1.dll)

if(NOT EXISTS ${GCC_LIB}
OR NOT EXISTS ${GCC_EH_LIB}
OR NOT EXISTS ${BCRYPT_LIB}
OR NOT EXISTS ${MINGW32_LIB}
OR NOT EXISTS ${MINGWEX_LIB}
OR NOT EXISTS ${PTHREAD_DLL})
message(FATAL_ERROR "Could not find expected MinGW runtime libraries")
${MSYS_ROOT}/${mingw_name}/${gcc_name}/lib/libpthread.dll.a)
set(PTHREAD_DLL ${MSYS_ROOT}/${mingw_name}/bin/libwinpthread-1.dll)

if(NOT EXISTS ${GCC_LIB})
message(FATAL_ERROR "Could not find expected MinGW GCC runtime libraries")
endif()
if(NOT EXISTS ${GCC_EH_LIB})
message(
FATAL_ERROR "Could not find expected MinGW GCC EH runtime libraries")
endif()
if(NOT EXISTS ${BCRYPT_LIB})
message(
FATAL_ERROR "Could not find expected MinGW BCrypt runtime libraries")
endif()
if(NOT EXISTS ${MINGW32_LIB})
message(
FATAL_ERROR "Could not find expected MinGW MinGW32 runtime libraries")
endif()
if(NOT EXISTS ${MINGWEX_LIB})
message(
FATAL_ERROR "Could not find expected MinGW MinGWEX runtime libraries")
endif()
if(NOT EXISTS ${PTHREAD_DLL})
message(
FATAL_ERROR "Could not find expected MinGW PThread runtime libraries")
endif()

target_link_libraries(
${TARGET} INTERFACE ${GCC_LIB} ${GCC_EH_LIB} ${BCRYPT_LIB} ${MINGW32_LIB}
${MINGWEX_LIB})
Expand Down Expand Up @@ -105,34 +143,47 @@ set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)

if(MSVC)
target_link_libraries(
${TARGET}
INTERFACE ${AVCODEC_LIB}
${AVUTIL_LIB}
${AVFILTER_LIB}
${SWSCALE_LIB}
${SVTHEVCENC_LIB}
${SVTAV1ENC_LIB}
${DAV1D_LIB}
Threads::Threads)
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
target_link_libraries(
${TARGET} INTERFACE ${AVCODEC_LIB} ${AVUTIL_LIB} ${AVFILTER_LIB}
${SWSCALE_LIB} Threads::Threads)
elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
target_link_libraries(
${TARGET}
INTERFACE ${AVCODEC_LIB}
${AVUTIL_LIB}
${AVFILTER_LIB}
${SWSCALE_LIB}
${SVTHEVCENC_LIB}
${SVTAV1ENC_LIB}
${DAV1D_LIB}
Threads::Threads)
endif()
else()
target_link_libraries(
${TARGET}
INTERFACE ${AVCODEC_LIB}
${AVUTIL_LIB}
${AVFILTER_LIB}
${SWSCALE_LIB}
${SVTHEVCENC_LIB}
${SVTAV1ENC_LIB}
${DAV1D_LIB}
Threads::Threads
dl)
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
target_link_libraries(
${TARGET} INTERFACE ${AVCODEC_LIB} ${AVUTIL_LIB} ${AVFILTER_LIB}
${SWSCALE_LIB} Threads::Threads ${CMAKE_DL_LIBS})
elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
target_link_libraries(
${TARGET}
INTERFACE ${AVCODEC_LIB}
${AVUTIL_LIB}
${AVFILTER_LIB}
${SWSCALE_LIB}
${SVTHEVCENC_LIB}
${SVTAV1ENC_LIB}
${DAV1D_LIB}
Threads::Threads
${CMAKE_DL_LIBS})
endif()
endif()

if(BUILD_GPL_X264)
if(MSVC)
target_link_libraries(${TARGET} INTERFACE ${X264_LIB} Threads::Threads)
else()
target_link_libraries(${TARGET} INTERFACE ${X264_LIB} Threads::Threads dl)
target_link_libraries(${TARGET} INTERFACE ${X264_LIB} Threads::Threads
${CMAKE_DL_LIBS})
endif()
endif(BUILD_GPL_X264)
69 changes: 69 additions & 0 deletions cpu/src/cpu_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ mfxStatus CpuDecode::InitDecode(mfxVideoParam *par, mfxBitstream *bs) {
m_avDecContext->thread_count = 0;
#endif

if (!bs) {
if (m_avDecCodec->id == AV_CODEC_ID_AV1) {
if (par->mfx.FilmGrain == 0) { // disable film-grain denoise
int ret = av_opt_set_int(m_avDecContext->priv_data,
"filmgrain",
par->mfx.FilmGrain,
AV_OPT_SEARCH_CHILDREN);
if (ret != 0)
return MFX_ERR_INVALID_VIDEO_PARAM;
}
}
}

if (avcodec_open2(m_avDecContext, m_avDecCodec, NULL) < 0) {
return MFX_ERR_INVALID_VIDEO_PARAM;
}
Expand Down Expand Up @@ -340,6 +353,62 @@ mfxStatus CpuDecode::DecodeFrame(mfxBitstream *bs,
return MFX_ERR_ABORTED;
}
}

if (m_avDecContext->codec_id == AV_CODEC_ID_AV1) {
// profile
switch (m_avDecContext->profile) {
case 0:
m_param.mfx.CodecProfile = MFX_PROFILE_AV1_MAIN;
break;
case 1:
m_param.mfx.CodecProfile = MFX_PROFILE_AV1_HIGH;
break;
case 2:
m_param.mfx.CodecProfile = MFX_PROFILE_AV1_PRO;
break;
default:
return MFX_ERR_ABORTED;
}

// level
//
// codes when decoder sets level of context from av1 sequence header
//
// c->level = ((p->seq_hdr->operating_points[0].major_level - 2) << 2)
// | p->seq_hdr->operating_points[0].minor_level;
//
int major_level = (m_avDecContext->level >> 2) + 2;
int minor_level = m_avDecContext->level - ((major_level - 2) << 2);

if (major_level < 2 || major_level > 7 || minor_level < 0 || minor_level > 3)
return MFX_ERR_ABORTED;

// in mfxstructure.h
// enum
// MFX_LEVEL_AV1_2 = 20,
// MFX_LEVEL_AV1_21 = 21,
// ...
// MFX_LEVEL_AV1_72 = 72,
// MFX_LEVEL_AV1_73 = 73,
//
int mfx_level = (major_level * 10) + minor_level;

m_param.mfx.CodecLevel = mfx_level;

int ret;
int64_t optval;
ret = av_opt_get_int(m_avDecContext->priv_data,
"filmgrain",
AV_OPT_SEARCH_CHILDREN,
&optval);
if (ret == 0) {
m_param.mfx.FilmGrain = (mfxU16)optval;
}
else {
m_param.mfx.FilmGrain = 0;
}
}

if (m_param.mfx.FrameInfo.Width != m_avDecContext->width ||
m_param.mfx.FrameInfo.Height != m_avDecContext->height) {
m_param.mfx.FrameInfo.Width = m_avDecContext->width;
Expand Down
Loading

0 comments on commit 07b524f

Please sign in to comment.