File ppsspp-PR18670.patch of Package ppsspp
From 402f9acb5ea4111d784d535db87d49681857f390 Mon Sep 17 00:00:00 2001
From: Andrew Udvare <audvare@gmail.com>
Date: Sun, 7 Jan 2024 01:41:04 -0500
Subject: [PATCH] Fix compilation with newer ffmpeg versions
---
Core/AVIDump.cpp | 4 ++++
Core/HLE/sceAtrac.cpp | 8 +++++++-
Core/HLE/sceMpeg.cpp | 4 ++++
Core/HW/MediaEngine.cpp | 17 ++++++++++++++---
Core/HW/SimpleAudioDec.cpp | 1 +
Core/HW/SimpleAudioDec.h | 12 ++++++++++++
6 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/Core/AVIDump.cpp b/Core/AVIDump.cpp
index 99c74af7bfba..7c9576d2922b 100644
--- a/Core/AVIDump.cpp
+++ b/Core/AVIDump.cpp
@@ -45,6 +45,10 @@ 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
+
static AVFormatContext *s_format_context = nullptr;
static AVCodecContext *s_codec_context = nullptr;
static AVStream *s_stream = nullptr;
diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp
index 86017681b681..2bef0b43276f 100644
--- a/Core/HLE/sceAtrac.cpp
+++ b/Core/HLE/sceAtrac.cpp
@@ -126,8 +126,14 @@ extern "C" {
#include "libavformat/avformat.h"
#include "libswresample/swresample.h"
#include "libavutil/samplefmt.h"
+#include "libavcodec/avcodec.h"
+#include "libavutil/version.h"
}
+#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(59, 16, 100)
+#define AVCodec const AVCodec
+#endif
+
#endif // USE_FFMPEG
enum AtracDecodeResult {
@@ -1858,7 +1864,7 @@ int __AtracSetContext(Atrac *atrac) {
atrac->ReleaseFFMPEGContext();
}
- const AVCodec *codec = avcodec_find_decoder(ff_codec);
+ AVCodec *codec = avcodec_find_decoder(ff_codec);
atrac->codecCtx_ = avcodec_alloc_context3(codec);
if (atrac->codecType_ == PSP_MODE_AT_3) {
diff --git a/Core/HLE/sceMpeg.cpp b/Core/HLE/sceMpeg.cpp
index 8e4586a6d0b7..7672eb2471ca 100644
--- a/Core/HLE/sceMpeg.cpp
+++ b/Core/HLE/sceMpeg.cpp
@@ -111,7 +111,11 @@ extern "C" {
#include "libavformat/avformat.h"
#include "libavutil/imgutils.h"
#include "libswscale/swscale.h"
+#include "libavcodec/avcodec.h"
}
+#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(59, 16, 100)
+#define AVCodec const AVCodec
+#endif
static AVPixelFormat pmp_want_pix_fmt;
#endif
diff --git a/Core/HW/MediaEngine.cpp b/Core/HW/MediaEngine.cpp
index fa4b8191c417..3e4c187aa2fe 100644
--- a/Core/HW/MediaEngine.cpp
+++ b/Core/HW/MediaEngine.cpp
@@ -42,6 +42,11 @@ extern "C" {
#endif // USE_FFMPEG
#ifdef USE_FFMPEG
+
+#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(59, 16, 100)
+#define AVCodec const AVCodec
+#endif
+
static AVPixelFormat getSwsFormat(int pspFormat)
{
switch (pspFormat)
@@ -394,7 +399,7 @@ bool MediaEngine::addVideoStream(int streamNum, int streamId) {
// no need to add an existing stream.
if ((u32)streamNum < m_pFormatCtx->nb_streams)
return true;
- const AVCodec *h264_codec = avcodec_find_decoder(AV_CODEC_ID_H264);
+ AVCodec *h264_codec = avcodec_find_decoder(AV_CODEC_ID_H264);
if (!h264_codec)
return false;
AVStream *stream = avformat_new_stream(m_pFormatCtx, h264_codec);
@@ -409,14 +414,20 @@ bool MediaEngine::addVideoStream(int streamNum, int streamId) {
stream->codecpar->codec_id = AV_CODEC_ID_H264;
#else
stream->request_probe = 0;
-#endif
stream->need_parsing = AVSTREAM_PARSE_FULL;
+#endif
// We could set the width here, but we don't need to.
if (streamNum >= m_expectedVideoStreams) {
++m_expectedVideoStreams;
}
- m_codecsToClose.push_back(stream->codec);
+#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(59, 16, 100)
+ AVCodec *codec = avcodec_find_decoder(stream->codecpar->codec_id);
+ AVCodecContext *codecCtx = avcodec_alloc_context3(codec);
+#else
+ AVCodecContext *codecCtx = stream->codec;
+#endif
+ m_codecsToClose.push_back(codecCtx);
return true;
}
}
diff --git a/Core/HW/SimpleAudioDec.cpp b/Core/HW/SimpleAudioDec.cpp
index 8f250abdd80c..7994a7f4027a 100644
--- a/Core/HW/SimpleAudioDec.cpp
+++ b/Core/HW/SimpleAudioDec.cpp
@@ -31,6 +31,7 @@ extern "C" {
#include "libavformat/avformat.h"
#include "libswresample/swresample.h"
#include "libavutil/samplefmt.h"
+#include "libavcodec/avcodec.h"
}
#endif // USE_FFMPEG
diff --git a/Core/HW/SimpleAudioDec.h b/Core/HW/SimpleAudioDec.h
index ec792c90314d..52a78bf3b411 100644
--- a/Core/HW/SimpleAudioDec.h
+++ b/Core/HW/SimpleAudioDec.h
@@ -27,6 +27,18 @@ struct AVCodec;
struct AVCodecContext;
struct SwrContext;
+#ifdef USE_FFMPEG
+
+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.