Fix building with newer FFmpeg.
Index: Makefile =================================================================== RCS file: /cvs/ports/emulators/ppsspp/Makefile,v retrieving revision 1.28 diff -u -p -u -p -r1.28 Makefile --- Makefile 9 Jul 2024 14:42:43 -0000 1.28 +++ Makefile 25 Sep 2024 01:56:29 -0000 @@ -5,7 +5,7 @@ COMMENT = Sony PlayStation Portable emul DISTNAME = ppsspp-$V V = 1.17.1 -REVISION = 1 +REVISION = 2 SITES = https://github.com/hrydgard/ppsspp/releases/download/v$V/ @@ -49,6 +49,11 @@ CONFIGURE_ARGS = -DUSE_SYSTEM_FFMPEG=ON -DUSE_DISCORD=OFF \ -DUSE_WAYLAND_WSI=OFF \ -DUSING_EGL=OFF + +# workaround for CMake test, to be removed when fixed +CXXFLAGS += -I${LOCALBASE}/include +LDFLAGS += -L${LOCALBASE}/lib +CONFIGURE_ENV = LDFLAGS="${LDFLAGS}" DEBUG_PACKAGES = ${BUILD_PACKAGES} Index: patches/patch-CMakeLists_txt =================================================================== RCS file: /cvs/ports/emulators/ppsspp/patches/patch-CMakeLists_txt,v retrieving revision 1.15 diff -u -p -u -p -r1.15 patch-CMakeLists_txt --- patches/patch-CMakeLists_txt 27 Apr 2024 10:57:29 -0000 1.15 +++ patches/patch-CMakeLists_txt 25 Sep 2024 01:56:29 -0000 @@ -1,10 +1,21 @@ +- ffmpeg: Improved fix for checking if const AVCodec* is necessary + 930b7f644d74c74d9e58bf8e5300bf9ea9fb78a9 + - Honor CFLAGS and DEBUG - Use system libpng on arm platforms Index: CMakeLists.txt --- CMakeLists.txt.orig +++ CMakeLists.txt -@@ -385,13 +385,13 @@ if(NOT MSVC) +@@ -117,6 +117,7 @@ if(NOT IOS) + endif() + + include(ccache) ++include(CheckCXXSourceCompiles) + include(GNUInstallDirs) + + add_definitions(-DASSETS_DIR="${CMAKE_INSTALL_FULL_DATADIR}/ppsspp/assets/") +@@ -385,13 +386,13 @@ if(NOT MSVC) endif() endif() @@ -22,7 +33,31 @@ Index: CMakeLists.txt set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O2 -g -D_NDEBUG") # Enable checking printf-like format strings (also works for logging functions) -@@ -1147,7 +1147,7 @@ else() +@@ -949,6 +950,23 @@ if(USE_FFMPEG) + endif() + + find_package(FFmpeg REQUIRED avcodec avformat avutil swresample swscale) ++ # Check if we need to use avcodec_(alloc|free)_frame instead of av_frame_(alloc|free) ++ # Check if we need to use const AVCodec ++ set(CMAKE_REQUIRED_LIBRARIES avcodec;avformat) ++ set(CMAKE_REQUIRED_FLAGS "-pedantic -Wall -Werror -Wno-unused-variable") ++ check_cxx_source_compiles("extern \"C\" { ++ #include <libavcodec/avcodec.h> ++ #include <libavformat/avformat.h> ++ } ++ static AVCodecContext *s_codec_context = NULL; ++ int main() { ++ const AVCodec *codec = avcodec_find_encoder(s_codec_context->codec_id); ++ return 0; ++ } ++ " HAVE_LIBAVCODEC_CONST_AVCODEC FAIL_REGEX "invalid conversion") ++ ++ # Check if we need to use avcodec_alloc_context3 instead of stream->codec ++ # Check if we need to use av_frame_get_buffer instead of avcodec_default_get_buffer + endif(USE_FFMPEG) + + find_package(ZLIB) +@@ -1147,7 +1165,7 @@ else() endif() # Arm platforms require at least libpng17. @@ -31,3 +66,21 @@ Index: CMakeLists.txt set(PNG_REQUIRED_VERSION 1.7) else() set(PNG_REQUIRED_VERSION 1.6) +@@ -2020,6 +2038,7 @@ add_library(${CoreLibName} ${CoreLinkType} + Core/ELF/PrxDecrypter.h + Core/ELF/ParamSFO.cpp + Core/ELF/ParamSFO.h ++ Core/FFMPEGCompat.h + Core/FileSystems/tlzrc.cpp + Core/FileSystems/BlobFileSystem.cpp + Core/FileSystems/BlobFileSystem.h +@@ -2354,6 +2373,9 @@ target_compile_features(${CoreLibName} PUBLIC cxx_std_ + + if(FFmpeg_FOUND) + target_compile_definitions(${CoreLibName} PRIVATE USE_FFMPEG=1) ++ if (HAVE_LIBAVCODEC_CONST_AVCODEC) ++ target_compile_definitions(${CoreLibName} PRIVATE HAVE_LIBAVCODEC_CONST_AVCODEC=1) ++ endif() + set_target_properties(${CoreLibName} PROPERTIES NO_SYSTEM_FROM_IMPORTED true) + target_include_directories(${CoreLibName} BEFORE PUBLIC ${FFmpeg_INCLUDE_avcodec}) + target_link_libraries(${CoreLibName} Index: patches/patch-Core_AVIDump_cpp =================================================================== RCS file: patches/patch-Core_AVIDump_cpp diff -N patches/patch-Core_AVIDump_cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-Core_AVIDump_cpp 25 Sep 2024 01:56:29 -0000 @@ -0,0 +1,17 @@ +- ffmpeg: Improved fix for checking if const AVCodec* is necessary + 930b7f644d74c74d9e58bf8e5300bf9ea9fb78a9 + +Index: Core/AVIDump.cpp +--- Core/AVIDump.cpp.orig ++++ Core/AVIDump.cpp +@@ -45,9 +45,7 @@ extern "C" { + #define av_frame_free avcodec_free_frame + #endif + +-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(59, 16, 100) +-#define AVCodec const AVCodec +-#endif ++#include "FFMPEGCompat.h" + + static AVFormatContext *s_format_context = nullptr; + static AVCodecContext *s_codec_context = nullptr; Index: patches/patch-Core_FFMPEGCompat_h =================================================================== RCS file: patches/patch-Core_FFMPEGCompat_h diff -N patches/patch-Core_FFMPEGCompat_h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-Core_FFMPEGCompat_h 25 Sep 2024 01:56:29 -0000 @@ -0,0 +1,15 @@ +- ffmpeg: Improved fix for checking if const AVCodec* is necessary + 930b7f644d74c74d9e58bf8e5300bf9ea9fb78a9 + +Index: Core/FFMPEGCompat.h +--- Core/FFMPEGCompat.h.orig ++++ Core/FFMPEGCompat.h +@@ -0,0 +1,8 @@ ++#ifndef FFMPEG_COMPAT_H ++#define FFMPEG_COMPAT_H ++ ++#ifdef HAVE_LIBAVCODEC_CONST_AVCODEC ++#define AVCodec const AVCodec ++#endif ++ ++#endif // FFMPEG_COMPAT_H Index: patches/patch-Core_HLE_sceAtrac_cpp =================================================================== RCS file: patches/patch-Core_HLE_sceAtrac_cpp diff -N patches/patch-Core_HLE_sceAtrac_cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-Core_HLE_sceAtrac_cpp 25 Sep 2024 01:56:29 -0000 @@ -0,0 +1,18 @@ +- ffmpeg: Improved fix for checking if const AVCodec* is necessary + 930b7f644d74c74d9e58bf8e5300bf9ea9fb78a9 + +Index: Core/HLE/sceAtrac.cpp +--- Core/HLE/sceAtrac.cpp.orig ++++ Core/HLE/sceAtrac.cpp +@@ -129,10 +129,7 @@ extern "C" { + #include "libavcodec/avcodec.h" + #include "libavutil/version.h" + } +- +-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(59, 16, 100) +-#define AVCodec const AVCodec +-#endif ++#include "Core/FFMPEGCompat.h" + + #endif // USE_FFMPEG + Index: patches/patch-Core_HLE_sceMpeg_cpp =================================================================== RCS file: patches/patch-Core_HLE_sceMpeg_cpp diff -N patches/patch-Core_HLE_sceMpeg_cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-Core_HLE_sceMpeg_cpp 25 Sep 2024 01:56:29 -0000 @@ -0,0 +1,17 @@ +- ffmpeg: Improved fix for checking if const AVCodec* is necessary + 930b7f644d74c74d9e58bf8e5300bf9ea9fb78a9 + +Index: Core/HLE/sceMpeg.cpp +--- Core/HLE/sceMpeg.cpp.orig ++++ Core/HLE/sceMpeg.cpp +@@ -113,9 +113,7 @@ extern "C" { + #include "libswscale/swscale.h" + #include "libavcodec/avcodec.h" + } +-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(59, 16, 100) +-#define AVCodec const AVCodec +-#endif ++#include "Core/FFMPEGCompat.h" + static AVPixelFormat pmp_want_pix_fmt; + + #endif Index: patches/patch-Core_HW_MediaEngine_cpp =================================================================== RCS file: patches/patch-Core_HW_MediaEngine_cpp diff -N patches/patch-Core_HW_MediaEngine_cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-Core_HW_MediaEngine_cpp 25 Sep 2024 01:56:29 -0000 @@ -0,0 +1,17 @@ +- ffmpeg: Improved fix for checking if const AVCodec* is necessary + 930b7f644d74c74d9e58bf8e5300bf9ea9fb78a9 + +Index: Core/HW/MediaEngine.cpp +--- Core/HW/MediaEngine.cpp.orig ++++ Core/HW/MediaEngine.cpp +@@ -56,9 +56,7 @@ extern "C" { + + #ifdef USE_FFMPEG + +-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(59, 16, 100) +-#define AVCodec const AVCodec +-#endif ++#include "Core/FFMPEGCompat.h" + + static AVPixelFormat getSwsFormat(int pspFormat) + { Index: patches/patch-Core_HW_SimpleAudioDec_cpp =================================================================== RCS file: patches/patch-Core_HW_SimpleAudioDec_cpp diff -N patches/patch-Core_HW_SimpleAudioDec_cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-Core_HW_SimpleAudioDec_cpp 25 Sep 2024 01:56:29 -0000 @@ -0,0 +1,14 @@ +- ffmpeg: Improved fix for checking if const AVCodec* is necessary + 930b7f644d74c74d9e58bf8e5300bf9ea9fb78a9 + +Index: Core/HW/SimpleAudioDec.cpp +--- Core/HW/SimpleAudioDec.cpp.orig ++++ Core/HW/SimpleAudioDec.cpp +@@ -33,6 +33,7 @@ extern "C" { + #include "libavutil/samplefmt.h" + #include "libavcodec/avcodec.h" + } ++#include "Core/FFMPEGCompat.h" + + #endif // USE_FFMPEG + Index: patches/patch-Core_HW_SimpleAudioDec_h =================================================================== RCS file: patches/patch-Core_HW_SimpleAudioDec_h diff -N patches/patch-Core_HW_SimpleAudioDec_h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-Core_HW_SimpleAudioDec_h 25 Sep 2024 01:56:29 -0000 @@ -0,0 +1,29 @@ +- ffmpeg: Improved fix for checking if const AVCodec* is necessary + 930b7f644d74c74d9e58bf8e5300bf9ea9fb78a9 + +Index: Core/HW/SimpleAudioDec.h +--- Core/HW/SimpleAudioDec.h.orig ++++ Core/HW/SimpleAudioDec.h +@@ -33,12 +33,8 @@ extern "C" { + #include "libavutil/version.h" + }; + +-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(59, 16, 100) +-#define AVCodec const AVCodec + #endif + +-#endif +- + // Wraps FFMPEG for audio decoding in a nice interface. + // Decodes packet by packet - does NOT demux. + +@@ -90,6 +86,9 @@ class SimpleAudio { (private) + int wanted_resample_freq; // wanted resampling rate/frequency + + AVFrame *frame_; ++#if HAVE_LIBAVCODEC_CONST_AVCODEC // USE_FFMPEG is implied ++ const ++#endif + AVCodec *codec_; + AVCodecContext *codecCtx_; + SwrContext *swrCtx_;