Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1Backported from <https://github.com/hrydgard/ppsspp/commit/930b7f644d74c74d9e58bf8e5300bf9ea9fb78a9>. 2 3Original author: Andrew Udvare <audvare@gmail.com> 4 5diff --git a/CMakeLists.txt b/CMakeLists.txt 6index bfd5e69035..f7c43800fa 100644 7--- a/CMakeLists.txt 8+++ b/CMakeLists.txt 9@@ -117,6 +117,7 @@ 10 endif() 11 12 include(ccache) 13+include(CheckCXXSourceCompiles) 14 include(GNUInstallDirs) 15 16 add_definitions(-DASSETS_DIR="${CMAKE_INSTALL_FULL_DATADIR}/ppsspp/assets/") 17@@ -949,6 +950,23 @@ 18 endif() 19 20 find_package(FFmpeg REQUIRED avcodec avformat avutil swresample swscale) 21+ # Check if we need to use avcodec_(alloc|free)_frame instead of av_frame_(alloc|free) 22+ # Check if we need to use const AVCodec 23+ set(CMAKE_REQUIRED_LIBRARIES avcodec;avformat) 24+ set(CMAKE_REQUIRED_FLAGS "-pedantic -Wall -Werror -Wno-unused-variable") 25+ check_cxx_source_compiles("extern \"C\" { 26+ #include <libavcodec/avcodec.h> 27+ #include <libavformat/avformat.h> 28+ } 29+ static AVCodecContext *s_codec_context = NULL; 30+ int main() { 31+ const AVCodec *codec = avcodec_find_encoder(s_codec_context->codec_id); 32+ return 0; 33+ } 34+ " HAVE_LIBAVCODEC_CONST_AVCODEC FAIL_REGEX "invalid conversion") 35+ 36+ # Check if we need to use avcodec_alloc_context3 instead of stream->codec 37+ # Check if we need to use av_frame_get_buffer instead of avcodec_default_get_buffer 38 endif(USE_FFMPEG) 39 40 find_package(ZLIB) 41@@ -2020,6 +2038,7 @@ 42 Core/ELF/PrxDecrypter.h 43 Core/ELF/ParamSFO.cpp 44 Core/ELF/ParamSFO.h 45+ Core/FFMPEGCompat.h 46 Core/FileSystems/tlzrc.cpp 47 Core/FileSystems/BlobFileSystem.cpp 48 Core/FileSystems/BlobFileSystem.h 49@@ -2354,6 +2373,9 @@ 50 51 if(FFmpeg_FOUND) 52 target_compile_definitions(${CoreLibName} PRIVATE USE_FFMPEG=1) 53+ if (HAVE_LIBAVCODEC_CONST_AVCODEC) 54+ target_compile_definitions(${CoreLibName} PRIVATE HAVE_LIBAVCODEC_CONST_AVCODEC=1) 55+ endif() 56 set_target_properties(${CoreLibName} PROPERTIES NO_SYSTEM_FROM_IMPORTED true) 57 target_include_directories(${CoreLibName} BEFORE PUBLIC ${FFmpeg_INCLUDE_avcodec}) 58 target_link_libraries(${CoreLibName} 59diff --git a/Core/AVIDump.cpp b/Core/AVIDump.cpp 60index 7c9576d292..aa81165031 100644 61--- a/Core/AVIDump.cpp 62+++ b/Core/AVIDump.cpp 63@@ -45,9 +45,7 @@ 64 #define av_frame_free avcodec_free_frame 65 #endif 66 67-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(59, 16, 100) 68-#define AVCodec const AVCodec 69-#endif 70+#include "FFMPEGCompat.h" 71 72 static AVFormatContext *s_format_context = nullptr; 73 static AVCodecContext *s_codec_context = nullptr; 74diff --git a/Core/FFMPEGCompat.h b/Core/FFMPEGCompat.h 75new file mode 100644 76index 0000000000..fed3b1c853 77--- /dev/null 78+++ b/Core/FFMPEGCompat.h 79@@ -1,0 +1,8 @@ 80+#ifndef FFMPEG_COMPAT_H 81+#define FFMPEG_COMPAT_H 82+ 83+#ifdef HAVE_LIBAVCODEC_CONST_AVCODEC 84+#define AVCodec const AVCodec 85+#endif 86+ 87+#endif // FFMPEG_COMPAT_H 88diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp 89index fe0e8a54de..f83d9ffdf1 100644 90--- a/Core/HLE/sceAtrac.cpp 91+++ b/Core/HLE/sceAtrac.cpp 92@@ -129,10 +129,7 @@ 93 #include "libavcodec/avcodec.h" 94 #include "libavutil/version.h" 95 } 96- 97-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(59, 16, 100) 98-#define AVCodec const AVCodec 99-#endif 100+#include "Core/FFMPEGCompat.h" 101 102 #endif // USE_FFMPEG 103 104diff --git a/Core/HLE/sceMpeg.cpp b/Core/HLE/sceMpeg.cpp 105index d050d62f3d..8be78c73e0 100644 106--- a/Core/HLE/sceMpeg.cpp 107+++ b/Core/HLE/sceMpeg.cpp 108@@ -113,9 +113,7 @@ 109 #include "libswscale/swscale.h" 110 #include "libavcodec/avcodec.h" 111 } 112-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(59, 16, 100) 113-#define AVCodec const AVCodec 114-#endif 115+#include "Core/FFMPEGCompat.h" 116 static AVPixelFormat pmp_want_pix_fmt; 117 118 #endif 119diff --git a/Core/HW/MediaEngine.cpp b/Core/HW/MediaEngine.cpp 120index 0ed957edfd..7e8b37d4dc 100644 121--- a/Core/HW/MediaEngine.cpp 122+++ b/Core/HW/MediaEngine.cpp 123@@ -56,9 +56,7 @@ 124 125 #ifdef USE_FFMPEG 126 127-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(59, 16, 100) 128-#define AVCodec const AVCodec 129-#endif 130+#include "Core/FFMPEGCompat.h" 131 132 static AVPixelFormat getSwsFormat(int pspFormat) 133 { 134diff --git a/Core/HW/SimpleAudioDec.cpp b/Core/HW/SimpleAudioDec.cpp 135index 7994a7f402..80397bf6da 100644 136--- a/Core/HW/SimpleAudioDec.cpp 137+++ b/Core/HW/SimpleAudioDec.cpp 138@@ -33,6 +33,7 @@ 139 #include "libavutil/samplefmt.h" 140 #include "libavcodec/avcodec.h" 141 } 142+#include "Core/FFMPEGCompat.h" 143 144 #endif // USE_FFMPEG 145 146diff --git a/Core/HW/SimpleAudioDec.h b/Core/HW/SimpleAudioDec.h 147index 52a78bf3b4..9bf2427a4a 100644 148--- a/Core/HW/SimpleAudioDec.h 149+++ b/Core/HW/SimpleAudioDec.h 150@@ -33,10 +33,6 @@ 151 #include "libavutil/version.h" 152 }; 153 154-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(59, 16, 100) 155-#define AVCodec const AVCodec 156-#endif 157- 158 #endif 159 160 // Wraps FFMPEG for audio decoding in a nice interface. 161@@ -90,6 +86,9 @@ 162 int wanted_resample_freq; // wanted resampling rate/frequency 163 164 AVFrame *frame_; 165+#if HAVE_LIBAVCODEC_CONST_AVCODEC // USE_FFMPEG is implied 166+ const 167+#endif 168 AVCodec *codec_; 169 AVCodecContext *codecCtx_; 170 SwrContext *swrCtx_;