Formatting and cleanup

This commit is contained in:
capitalistspz 2026-04-15 01:59:41 +01:00
parent e586389ae9
commit aff12540a6
3 changed files with 40 additions and 40 deletions

View File

@ -213,9 +213,9 @@ namespace camera
if (camHandle != CAM_HANDLE) if (camHandle != CAM_HANDLE)
return CAM_STATUS_INVALID_HANDLE; return CAM_STATUS_INVALID_HANDLE;
CafeLockGuard lock(s_cameraMutex); CafeLockGuard lock(s_cameraMutex);
if (!s_instance.initialized || !s_instance.isOpen) if (!s_instance.initialized || !s_instance.isOpen)
return CAM_STATUS_UNINITIALIZED; return CAM_STATUS_UNINITIALIZED;
s_instance.isOpen = false; s_instance.isOpen = false;
CameraManager::Close(); CameraManager::Close();
return CAM_STATUS_SUCCESS; return CAM_STATUS_SUCCESS;
} }
@ -290,7 +290,6 @@ namespace camera
{ {
if (reason == coreinit::RplEntryReason::Loaded) if (reason == coreinit::RplEntryReason::Loaded)
{ {
} }
else if (reason == coreinit::RplEntryReason::Unloaded) else if (reason == coreinit::RplEntryReason::Unloaded)
{ {

View File

@ -13,18 +13,18 @@
namespace CameraManager namespace CameraManager
{ {
std::mutex s_mutex; static std::mutex s_mutex;
CapContext s_ctx; static CapContext s_ctx;
std::optional<CapDeviceID> s_device; static std::optional<CapDeviceID> s_device;
std::optional<CapStream> s_stream; static std::optional<CapStream> s_stream;
uint8_t* s_rgbBuffer; static uint8_t* s_rgbBuffer;
uint8_t* s_nv12Buffer; static uint8_t* s_nv12Buffer;
int s_refCount = 0; static int s_refCount = 0;
std::thread s_captureThread; static std::thread s_captureThread;
std::atomic_bool s_capturing = false; static std::atomic_bool s_capturing = false;
std::atomic_bool s_running = false; static std::atomic_bool s_running = false;
std::string FourCC(uint32le value) static std::string FourCC(uint32le value)
{ {
return { return {
static_cast<char>((value >> 0) & 0xFF), static_cast<char>((value >> 0) & 0xFF),
@ -34,12 +34,12 @@ namespace CameraManager
}; };
} }
void CaptureLogFunction(uint32_t level, const char* string) static void CaptureLogFunction(uint32_t level, const char* string)
{ {
cemuLog_log(LogType::InputAPI, "OpenPNPCapture: {}: {}", level, string); cemuLog_log(LogType::InputAPI, "openpnp-capture: {}: {}", level, string);
} }
std::optional<CapFormatID> FindCorrectFormat() static std::optional<CapFormatID> FindCorrectFormat()
{ {
const auto device = *s_device; const auto device = *s_device;
cemuLog_log(LogType::InputAPI, "Video capture device '{}' available formats:", cemuLog_log(LogType::InputAPI, "Video capture device '{}' available formats:",
@ -62,7 +62,7 @@ namespace CameraManager
return std::nullopt; return std::nullopt;
} }
void CaptureWorker() static void CaptureWorkerFunc()
{ {
SetThreadName("CameraManager"); SetThreadName("CameraManager");
while (s_running) while (s_running)
@ -81,7 +81,7 @@ namespace CameraManager
} }
} }
void OpenStream() static void OpenStream()
{ {
const auto formatId = FindCorrectFormat(); const auto formatId = FindCorrectFormat();
if (!formatId) if (!formatId)
@ -93,7 +93,7 @@ namespace CameraManager
s_stream = stream; s_stream = stream;
} }
void CloseStream() static void CloseStream()
{ {
s_capturing = false; s_capturing = false;
if (s_stream) if (s_stream)
@ -103,7 +103,7 @@ namespace CameraManager
} }
} }
void ResetBuffers() static void ResetBuffers()
{ {
std::fill_n(s_rgbBuffer, CAMERA_RGB_BUFFER_SIZE, 0); std::fill_n(s_rgbBuffer, CAMERA_RGB_BUFFER_SIZE, 0);
constexpr static auto PIXEL_COUNT = CAMERA_HEIGHT * CAMERA_PITCH; constexpr static auto PIXEL_COUNT = CAMERA_HEIGHT * CAMERA_PITCH;
@ -111,7 +111,7 @@ namespace CameraManager
std::ranges::fill_n(s_nv12Buffer + PIXEL_COUNT, (PIXEL_COUNT / 2), 128); std::ranges::fill_n(s_nv12Buffer + PIXEL_COUNT, (PIXEL_COUNT / 2), 128);
} }
std::vector<DeviceInfo> InternalEnumerateDevices() static std::vector<DeviceInfo> InternalEnumerateDevices()
{ {
std::vector<DeviceInfo> infos; std::vector<DeviceInfo> infos;
const auto deviceCount = Cap_getDeviceCount(s_ctx); const auto deviceCount = Cap_getDeviceCount(s_ctx);
@ -133,7 +133,7 @@ namespace CameraManager
return infos; return infos;
} }
void Init() static void Init()
{ {
s_running = true; s_running = true;
s_ctx = Cap_createContext(); s_ctx = Cap_createContext();
@ -142,7 +142,7 @@ namespace CameraManager
s_rgbBuffer = new uint8[CAMERA_RGB_BUFFER_SIZE]; s_rgbBuffer = new uint8[CAMERA_RGB_BUFFER_SIZE];
s_nv12Buffer = new uint8[CAMERA_NV12_BUFFER_SIZE]; s_nv12Buffer = new uint8[CAMERA_NV12_BUFFER_SIZE];
s_captureThread = std::thread(&CaptureWorker); s_captureThread = std::thread(&CaptureWorkerFunc);
const auto uniqueId = GetConfig().camera_id.GetValue(); const auto uniqueId = GetConfig().camera_id.GetValue();
if (!uniqueId.empty()) if (!uniqueId.empty())
@ -160,7 +160,7 @@ namespace CameraManager
ResetBuffers(); ResetBuffers();
} }
void Deinit() static void Deinit()
{ {
CloseStream(); CloseStream();
Cap_releaseContext(s_ctx); Cap_releaseContext(s_ctx);

View File

@ -6,17 +6,18 @@
class CameraSettingsWindow : public wxDialog class CameraSettingsWindow : public wxDialog
{ {
wxChoice* m_cameraChoice; wxChoice* m_cameraChoice;
wxButton* m_refreshButton; wxButton* m_refreshButton;
wxWindow* m_imageWindow; wxWindow* m_imageWindow;
wxBitmap m_imageBitmap; wxBitmap m_imageBitmap;
wxTimer m_imageUpdateTimer; wxTimer m_imageUpdateTimer;
std::vector<uint8> m_imageBuffer; std::vector<uint8> m_imageBuffer;
public:
explicit CameraSettingsWindow(wxWindow* parent); public:
void OnSelectCameraChoice(wxCommandEvent&); explicit CameraSettingsWindow(wxWindow* parent);
void OnRefreshPressed(wxCommandEvent&); void OnSelectCameraChoice(wxCommandEvent&);
void UpdateImage(const wxTimerEvent&); void OnRefreshPressed(wxCommandEvent&);
void DrawImage(const wxPaintEvent&); void UpdateImage(const wxTimerEvent&);
void OnClose(wxCloseEvent& event); void DrawImage(const wxPaintEvent&);
}; void OnClose(wxCloseEvent& event);
};