From 6093ee03a5dbd0d8b6ed7894f096024b1bcf6376 Mon Sep 17 00:00:00 2001 From: capitalistspz Date: Thu, 5 Sep 2024 16:44:27 +0100 Subject: [PATCH] Only convert upon successful capture --- src/Cafe/OS/libs/camera/camera.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Cafe/OS/libs/camera/camera.cpp b/src/Cafe/OS/libs/camera/camera.cpp index f661cb16..be01ed7b 100644 --- a/src/Cafe/OS/libs/camera/camera.cpp +++ b/src/Cafe/OS/libs/camera/camera.cpp @@ -158,13 +158,16 @@ namespace camera { if (!m_opened) { - std::this_thread::sleep_for(std::chrono::milliseconds(2)); + std::this_thread::sleep_for(std::chrono::milliseconds(20)); std::this_thread::yield(); continue; } - Cap_captureFrame(m_capCtx, stream, rgbBuffer.get(), rgbBufferSize); - std::scoped_lock lock(m_callbackMutex); - Rgb2Nv12(rgbBuffer.get(), g_width, g_height, m_capNv12Buffer.get(), g_pitch); + auto res = Cap_captureFrame(m_capCtx, stream, rgbBuffer.get(), rgbBufferSize); + if (res == CAPRESULT_OK) + { + std::scoped_lock lock(m_callbackMutex); + Rgb2Nv12(rgbBuffer.get(), g_width, g_height, m_capNv12Buffer.get(), g_pitch); + } } Cap_closeStream(m_capCtx, stream); } @@ -209,7 +212,7 @@ namespace camera return CAMError::NotReady; if (!m_targetSurfaceQueue.Push(surface)) return CAMError::SurfaceQueueFull; - cemuLog_logDebug(LogType::Force, "camera: surface submitted"); + cemuLog_logDebug(LogType::Force, "camera: surface {} submitted", surface->surfacePtr); return CAMError::Success; }