diff --git a/.gitmodules b/.gitmodules index 0a5f83fb7..72b53a34b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -28,3 +28,7 @@ [submodule "3rdparty/stb"] path = 3rdparty/stb url = https://github.com/nothings/stb.git +[submodule "3rdparty/FFmpeg"] + path = 3rdparty/FFmpeg + url = https://github.com/FFmpeg/FFmpeg.git + shallow = true diff --git a/3rdparty/FFmpeg b/3rdparty/FFmpeg new file mode 160000 index 000000000..291f96f79 --- /dev/null +++ b/3rdparty/FFmpeg @@ -0,0 +1 @@ +Subproject commit 291f96f7929f5837dc900adef3720025516e8584 diff --git a/core/libs/prx/libSceVideodec2/CMakeLists.txt b/core/libs/prx/libSceVideodec2/CMakeLists.txt index 65d3b882c..a1c809a52 100644 --- a/core/libs/prx/libSceVideodec2/CMakeLists.txt +++ b/core/libs/prx/libSceVideodec2/CMakeLists.txt @@ -5,15 +5,75 @@ add_library(libSceVideodec2 SHARED EXCLUDE_FROM_ALL target_include_directories(libSceVideodec2 PRIVATE ${LIBS_INCLUDE_DIR}) configure_windows_unwind(libSceVideodec2) -find_package(PkgConfig QUIET) -if(PKG_CONFIG_FOUND) - pkg_check_modules(VIDEODEC2_FFMPEG QUIET IMPORTED_TARGET libavcodec libavutil libswscale) -endif() -if(VIDEODEC2_FFMPEG_FOUND) - target_link_libraries(libSceVideodec2 PRIVATE PkgConfig::VIDEODEC2_FFMPEG) +option(ANYPS5_ENABLE_FFMPEG "Build FFmpeg from 3rdparty/FFmpeg for H.264 decoding in libSceVideodec2" ON) + +set(VIDEODEC2_FFMPEG_SOURCE_DIR ${CMAKE_SOURCE_DIR}/3rdparty/FFmpeg) +find_program(VIDEODEC2_SH sh) +find_program(VIDEODEC2_MAKE NAMES make mingw32-make) + +if(ANYPS5_ENABLE_FFMPEG AND EXISTS ${VIDEODEC2_FFMPEG_SOURCE_DIR}/configure AND VIDEODEC2_SH AND VIDEODEC2_MAKE) + include(ExternalProject) + + set(VIDEODEC2_FFMPEG_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/ffmpeg) + set(VIDEODEC2_FFMPEG_INCLUDE_DIR ${VIDEODEC2_FFMPEG_PREFIX}/include) + set(VIDEODEC2_FFMPEG_LIB_DIR ${VIDEODEC2_FFMPEG_PREFIX}/lib) + set(VIDEODEC2_FFMPEG_LIBS + ${VIDEODEC2_FFMPEG_LIB_DIR}/libavcodec.a + ${VIDEODEC2_FFMPEG_LIB_DIR}/libswscale.a + ${VIDEODEC2_FFMPEG_LIB_DIR}/libavutil.a + ) + + set(VIDEODEC2_FFMPEG_OPTIONS + --prefix=${VIDEODEC2_FFMPEG_PREFIX} + --enable-static + --disable-shared + --enable-pic + --disable-autodetect + --disable-everything + --disable-programs + --disable-doc + --disable-network + --disable-avdevice + --disable-avformat + --disable-avfilter + --disable-swresample + --enable-avcodec + --enable-avutil + --enable-swscale + --enable-decoder=h264 + ) + if(CMAKE_C_COMPILER) + list(APPEND VIDEODEC2_FFMPEG_OPTIONS --cc=${CMAKE_C_COMPILER}) + endif() + find_program(VIDEODEC2_NASM nasm) + if(NOT VIDEODEC2_NASM) + list(APPEND VIDEODEC2_FFMPEG_OPTIONS --disable-x86asm) + endif() + + cmake_host_system_information(RESULT VIDEODEC2_JOBS QUERY NUMBER_OF_LOGICAL_CORES) + + ExternalProject_Add(ffmpeg_h264 + SOURCE_DIR ${VIDEODEC2_FFMPEG_SOURCE_DIR} + PREFIX ${VIDEODEC2_FFMPEG_PREFIX} + BINARY_DIR ${VIDEODEC2_FFMPEG_PREFIX}/build + CONFIGURE_COMMAND ${VIDEODEC2_SH} ${VIDEODEC2_FFMPEG_SOURCE_DIR}/configure ${VIDEODEC2_FFMPEG_OPTIONS} + BUILD_COMMAND ${VIDEODEC2_MAKE} -j${VIDEODEC2_JOBS} + INSTALL_COMMAND ${VIDEODEC2_MAKE} install + BUILD_BYPRODUCTS ${VIDEODEC2_FFMPEG_LIBS} + EXCLUDE_FROM_ALL ON + ) + file(MAKE_DIRECTORY ${VIDEODEC2_FFMPEG_INCLUDE_DIR}) + + add_dependencies(libSceVideodec2 ffmpeg_h264) + target_include_directories(libSceVideodec2 SYSTEM PRIVATE ${VIDEODEC2_FFMPEG_INCLUDE_DIR}) + target_link_libraries(libSceVideodec2 PRIVATE ${VIDEODEC2_FFMPEG_LIBS}) + if(NOT WIN32) + target_link_libraries(libSceVideodec2 PRIVATE m) + endif() + target_link_options(libSceVideodec2 PRIVATE -Wl,--exclude-libs,ALL) target_compile_definitions(libSceVideodec2 PRIVATE APS5_HAVE_FFMPEG=1) set(VIDEODEC2_HAS_FFMPEG ON PARENT_SCOPE) - message(STATUS "libSceVideodec2: H.264 decoding with FFmpeg ${VIDEODEC2_FFMPEG_libavcodec_VERSION}") + message(STATUS "libSceVideodec2: H.264 decoding with FFmpeg from 3rdparty/FFmpeg") else() - message(STATUS "libSceVideodec2: FFmpeg not found, decoders return black pictures") + message(STATUS "libSceVideodec2: FFmpeg disabled or 3rdparty/FFmpeg missing, decoders return black pictures") endif() diff --git a/docs/dev/TechnicalDebt.md b/docs/dev/TechnicalDebt.md index 42cb70360..4bcc59cc6 100644 --- a/docs/dev/TechnicalDebt.md +++ b/docs/dev/TechnicalDebt.md @@ -13,6 +13,7 @@ Throughout the project, every function at every stage either **does exactly what it's supposed to or throws an exception**. Everywhere... except: - [libSceSaveDataDialog.native](../../core/libs/prx/libSceSaveDataDialog.native/Export.cpp) - [libSceCommonDialog](../../core/libs/prx/libSceCommonDialog/Export.cpp) +- [libSceVideodec2](../../core/libs/prx/libSceVideodec2/Export.cpp) returns black pictures for every codec except H.264, and for H.264 too when [FFmpeg](../../3rdparty/FFmpeg) is not built (`ANYPS5_ENABLE_FFMPEG=OFF`, or no `sh`/`make`, as with a plain MinGW setup) - The shader recompiler [skips baryctric coordinates](../../core/shader/recompiler/Recompiler.cpp) (is not even passed to SpirvTargetOptions at row 212). ### Unknown function info