From 5b3be0d720752fb32eb54d4eaebc422b29f1873f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 10 Apr 2024 18:40:02 +0200 Subject: [PATCH] Update USE_FFMPEG checks --- Core/HLE/sceMpeg.cpp | 2 ++ Core/HW/SimpleAudioDec.cpp | 11 ++++++++++- Windows/CaptureDevice.cpp | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Core/HLE/sceMpeg.cpp b/Core/HLE/sceMpeg.cpp index 8be78c73e0..b4e252208f 100644 --- a/Core/HLE/sceMpeg.cpp +++ b/Core/HLE/sceMpeg.cpp @@ -97,7 +97,9 @@ static const int MPEG_HEADER_BUFFER_MINIMUM_SIZE = 2048; // For PMP media static u32 pmp_videoSource = 0; //pointer to the video source (SceMpegLLi structure) static int pmp_nBlocks = 0; //number of blocks received in the last sceMpegBasePESpacketCopy call +#ifdef USE_FFMPEG static std::list pmp_queue; //list of pmp video frames have been decoded and will be played +#endif static std::list pmp_ContextList; //list of pmp media contexts static bool pmp_oldStateLoaded = false; // for dostate diff --git a/Core/HW/SimpleAudioDec.cpp b/Core/HW/SimpleAudioDec.cpp index 89ef22fed0..b6da4d59ff 100644 --- a/Core/HW/SimpleAudioDec.cpp +++ b/Core/HW/SimpleAudioDec.cpp @@ -38,6 +38,15 @@ extern "C" { #include "Core/FFMPEGCompat.h" } +#else + +extern "C" { + struct AVCodec; + struct AVCodecContext; + struct SwrContext; + struct AVFrame; +} + #endif // USE_FFMPEG // FFMPEG-based decoder. TODO: Replace with individual codecs. @@ -77,7 +86,7 @@ private: #if HAVE_LIBAVCODEC_CONST_AVCODEC // USE_FFMPEG is implied const #endif - AVCodec *codec_; + AVCodec *codec_; AVCodecContext *codecCtx_; SwrContext *swrCtx_; diff --git a/Windows/CaptureDevice.cpp b/Windows/CaptureDevice.cpp index 7b61fa6fa0..3e36c7eb7f 100644 --- a/Windows/CaptureDevice.cpp +++ b/Windows/CaptureDevice.cpp @@ -114,12 +114,14 @@ HRESULT GetDefaultStride(IMFMediaType *pType, LONG *plStride); ReaderCallback::ReaderCallback(WindowsCaptureDevice *_device) : device(_device) {} ReaderCallback::~ReaderCallback() { +#ifdef USE_FFMPEG if (img_convert_ctx) { sws_freeContext(img_convert_ctx); } if (resample_ctx) { swr_free(&resample_ctx); } +#endif } HRESULT ReaderCallback::QueryInterface(REFIID riid, void** ppv) @@ -179,6 +181,7 @@ HRESULT ReaderCallback::OnReadSample( srcPadding = device->deviceParam.default_stride - lStride; if (SUCCEEDED(hr)) { +#ifdef USE_FFMPEG // Convert image to RGB24 if (lStride > 0) { imgConvert( @@ -203,6 +206,7 @@ HRESULT ReaderCallback::OnReadSample( dstH, 3, device->imageRGB); +#endif } Camera::pushCameraImage(imgJpegSize, device->imageJpeg); } @@ -278,12 +282,14 @@ void ReaderCallback::imgConvert( unsigned char *dst, unsigned int &dstW, unsigned int &dstH, int dstLineSizes[4], unsigned char *src, const unsigned int &srcW, const unsigned int &srcH, const GUID &srcFormat, const int &srcPadding) { +#ifdef USE_FFMPEG int srcLineSizes[4] = { 0, 0, 0, 0 }; unsigned char *pSrc[4]; unsigned char *pDst[4]; AVPixelFormat srcAVFormat = getAVVideoFormatbyMFVideoFormat(srcFormat); + av_image_fill_linesizes(srcLineSizes, srcAVFormat, srcW); // Is this correct? @@ -322,9 +328,11 @@ void ReaderCallback::imgConvert( dstLineSizes ); } +#endif } void ReaderCallback::imgInvert(unsigned char *dst, unsigned char *src, const int &srcW, const int &srcH, const GUID &srcFormat, const int &srcStride) { +#ifdef USE_FFMPEG AVPixelFormat srcAvFormat = getAVVideoFormatbyMFVideoFormat(srcFormat); int dstLineSizes[4] = { 0, 0, 0, 0 }; @@ -338,6 +346,7 @@ void ReaderCallback::imgInvert(unsigned char *dst, unsigned char *src, const int imgInvertYUY2(dst, dstLineSizes[0], src, srcStride, srcH); else if (srcFormat == MFVideoFormat_NV12) imgInvertNV12(dst, dstLineSizes[0], src, srcStride, srcH);; +#endif } void ReaderCallback::imgInvertRGBA(unsigned char *dst, int &dstStride, unsigned char *src, const int &srcStride, const int &h) { @@ -392,6 +401,7 @@ void ReaderCallback::imgInvertNV12(unsigned char *dst, int &dstStride, unsigned } u32 ReaderCallback::doResample(u8 **dst, u32 &dstSampleRate, u32 &dstChannels, u32 *dstSize, u8 *src, const u32 &srcSampleRate, const u32 &srcChannels, const GUID &srcFormat, const u32& srcSize, const u32& srcBitsPerSample) { +#ifdef USE_FFMPEG AVSampleFormat srcAVFormat = getAVAudioFormatbyMFAudioFormat(srcFormat, srcBitsPerSample); int outSamplesCount = 0; if (resample_ctx == nullptr) { @@ -427,6 +437,9 @@ u32 ReaderCallback::doResample(u8 **dst, u32 &dstSampleRate, u32 &dstChannels, u if (outSamplesCount < 0) return 0; return av_samples_get_buffer_size(nullptr, dstChannels, outSamplesCount, AV_SAMPLE_FMT_S16, 0); +#else + return 0; +#endif } WindowsCaptureDevice::WindowsCaptureDevice(CAPTUREDEVIDE_TYPE _type) : @@ -450,6 +463,7 @@ WindowsCaptureDevice::WindowsCaptureDevice(CAPTUREDEVIDE_TYPE _type) : } WindowsCaptureDevice::~WindowsCaptureDevice() { +#ifdef USE_FFMPEG switch (type) { case CAPTUREDEVIDE_TYPE::VIDEO: av_freep(&imageRGB); @@ -459,6 +473,7 @@ WindowsCaptureDevice::~WindowsCaptureDevice() { av_freep(&resampleBuf); break; } +#endif } void WindowsCaptureDevice::CheckDevices() { @@ -555,6 +570,7 @@ bool WindowsCaptureDevice::start(void *startParam) { targetMediaParam.height = resolution->at(1); delete resolution; } +#ifdef USE_FFMPEG av_freep(&imageRGB); av_freep(&imageJpeg); @@ -562,6 +578,7 @@ bool WindowsCaptureDevice::start(void *startParam) { imgJpegSize = av_image_get_buffer_size(AV_PIX_FMT_YUVJ411P, targetMediaParam.width, targetMediaParam.height, 1); imageJpeg = (unsigned char*)av_malloc(imgJpegSize); av_image_fill_linesizes(imgRGBLineSizes, AV_PIX_FMT_RGB24, targetMediaParam.width); +#endif for (DWORD i = 0; ; i++) { hr = m_pReader->GetNativeMediaType(