diff --git a/rpcs3/Emu/Cell/Modules/cellCamera.cpp b/rpcs3/Emu/Cell/Modules/cellCamera.cpp index 64160f2e26..6fa4077017 100644 --- a/rpcs3/Emu/Cell/Modules/cellCamera.cpp +++ b/rpcs3/Emu/Cell/Modules/cellCamera.cpp @@ -277,9 +277,11 @@ s32 cellCameraInit() cellCamera.todo("cellCameraInit()"); // Start camera thread - const auto g_camera = fxm::make("Camera Thread"); + const auto g_camera = g_fxo->get(); - if (!g_camera) + std::lock_guard lock(g_camera->mutex); + + if (g_camera->init) { return CELL_CAMERA_ERROR_ALREADY_INIT; } @@ -289,8 +291,6 @@ s32 cellCameraInit() return CELL_OK; } - std::lock_guard lock(g_camera->mutex); - switch (g_cfg.io.camera_type) { case fake_camera_type::eyetoy: @@ -342,6 +342,8 @@ s32 cellCameraInit() g_camera->is_attached = true; } + g_camera->init = 1; + return CELL_OK; } @@ -349,9 +351,11 @@ s32 cellCameraEnd() { cellCamera.todo("cellCameraEnd()"); - const auto g_camera = fxm::withdraw(); + const auto g_camera = g_fxo->get(); - if (!g_camera) + std::lock_guard lock(g_camera->mutex); + + if (!g_camera->init) { return CELL_CAMERA_ERROR_NOT_INIT; } @@ -363,8 +367,8 @@ s32 cellCameraEnd() // return res; //} - // Join thread - g_camera->operator()(); + // TODO + g_camera->init = 0; return CELL_OK; } @@ -414,7 +418,7 @@ s32 cellCameraOpenEx(s32 dev_num, vm::ptr info) return CELL_CAMERA_ERROR_PARAM; } - const auto g_camera = fxm::get(); + const auto g_camera = g_fxo->get(); // we know g_camera is valid here (cellCameraSetAttribute above checks for it) if (g_camera->is_open) @@ -463,9 +467,9 @@ s32 cellCameraClose(s32 dev_num) return CELL_CAMERA_ERROR_PARAM; } - const auto g_camera = fxm::get(); + const auto g_camera = g_fxo->get(); - if (!g_camera) + if (!g_camera->init) { return CELL_CAMERA_ERROR_NOT_INIT; } @@ -504,9 +508,9 @@ s32 cellCameraGetDeviceGUID(s32 dev_num, vm::ptr guid) { cellCamera.todo("cellCameraGetDeviceGUID(dev_num=%d, guid=*0x%x)", dev_num, guid); - const auto g_camera = fxm::get(); + const auto g_camera = g_fxo->get(); - if (!g_camera) + if (!g_camera->init) { return CELL_CAMERA_ERROR_NOT_INIT; } @@ -522,9 +526,9 @@ s32 cellCameraGetType(s32 dev_num, vm::ptr type) { cellCamera.todo("cellCameraGetType(dev_num=%d, type=*0x%x)", dev_num, type); - const auto g_camera = fxm::get(); + const auto g_camera = g_fxo->get(); - if (!g_camera) + if (!g_camera->init) { return CELL_CAMERA_ERROR_NOT_INIT; } @@ -564,9 +568,14 @@ s32 cellCameraIsAvailable(s32 dev_num) return false; } - const auto g_camera = fxm::get(); + const auto g_camera = g_fxo->get(); - if (!g_camera || !check_dev_num(dev_num)) + if (!g_camera->init) + { + return false; + } + + if (!check_dev_num(dev_num)) { return false; } @@ -583,9 +592,14 @@ s32 cellCameraIsAttached(s32 dev_num) return false; } - const auto g_camera = fxm::get(); + const auto g_camera = g_fxo->get(); - if (!g_camera || !check_dev_num(dev_num)) + if (!g_camera->init) + { + return false; + } + + if (!check_dev_num(dev_num)) { return false; } @@ -617,9 +631,14 @@ s32 cellCameraIsOpen(s32 dev_num) return false; } - const auto g_camera = fxm::get(); + const auto g_camera = g_fxo->get(); - if (!g_camera || !check_dev_num(dev_num)) + if (!g_camera->init) + { + return false; + } + + if (!check_dev_num(dev_num)) { return false; } @@ -638,9 +657,14 @@ s32 cellCameraIsStarted(s32 dev_num) return false; } - const auto g_camera = fxm::get(); + const auto g_camera = g_fxo->get(); - if (!g_camera || !check_dev_num(dev_num)) + if (!g_camera->init) + { + return false; + } + + if (!check_dev_num(dev_num)) { return false; } @@ -655,9 +679,9 @@ s32 cellCameraGetAttribute(s32 dev_num, s32 attrib, vm::ptr arg1, vm::ptr(); + const auto g_camera = g_fxo->get(); - if (!g_camera) + if (!g_camera->init) { return CELL_CAMERA_ERROR_NOT_INIT; } @@ -702,9 +726,9 @@ s32 cellCameraSetAttribute(s32 dev_num, s32 attrib, u32 arg1, u32 arg2) const auto attr_name = get_camera_attr_name(attrib); cellCamera.todo("cellCameraSetAttribute(dev_num=%d, attrib=%d=%s, arg1=%d, arg2=%d)", dev_num, attrib, attr_name, arg1, arg2); - const auto g_camera = fxm::get(); + const auto g_camera = g_fxo->get(); - if (!g_camera) + if (!g_camera->init) { return CELL_CAMERA_ERROR_NOT_INIT; } @@ -740,9 +764,9 @@ s32 cellCameraGetBufferSize(s32 dev_num, vm::ptr info) { cellCamera.todo("cellCameraGetBufferSize(dev_num=%d, info=*0x%x)", dev_num, info); - const auto g_camera = fxm::get(); + const auto g_camera = g_fxo->get(); - if (!g_camera) + if (!g_camera->init) { return CELL_CAMERA_ERROR_NOT_INIT; } @@ -809,9 +833,9 @@ s32 cellCameraGetBufferInfoEx(s32 dev_num, vm::ptr info) // the following should be moved to cellCameraGetBufferInfo - const auto g_camera = fxm::get(); + const auto g_camera = g_fxo->get(); - if (!g_camera) + if (!g_camera->init) { return CELL_CAMERA_ERROR_NOT_INIT; } @@ -883,9 +907,9 @@ s32 cellCameraReset(s32 dev_num) return CELL_CAMERA_ERROR_PARAM; } - const auto g_camera = fxm::get(); + const auto g_camera = g_fxo->get(); - if (!g_camera) + if (!g_camera->init) { return CELL_CAMERA_ERROR_NOT_INIT; } @@ -931,9 +955,9 @@ s32 cellCameraStart(s32 dev_num) return CELL_CAMERA_ERROR_PARAM; } - const auto g_camera = fxm::get(); + const auto g_camera = g_fxo->get(); - if (!g_camera) + if (!g_camera->init) { return CELL_CAMERA_ERROR_NOT_INIT; } @@ -1009,9 +1033,9 @@ s32 cellCameraReadEx(s32 dev_num, vm::ptr read) { cellCamera.todo("cellCameraReadEx(dev_num=%d, read=0x%x)", dev_num, read); - const auto g_camera = fxm::get(); + const auto g_camera = g_fxo->get(); - if (!g_camera) + if (!g_camera->init) { return CELL_CAMERA_ERROR_NOT_INIT; } @@ -1075,9 +1099,9 @@ s32 cellCameraStop(s32 dev_num) return CELL_CAMERA_ERROR_PARAM; } - const auto g_camera = fxm::get(); + const auto g_camera = g_fxo->get(); - if (!g_camera) + if (!g_camera->init) { return CELL_CAMERA_ERROR_NOT_INIT; } @@ -1126,8 +1150,9 @@ s32 cellCameraSetNotifyEventQueue(u64 key) { cellCamera.todo("cellCameraSetNotifyEventQueue(key=0x%x)", key); - const auto g_camera = fxm::get(); - if (!g_camera) + const auto g_camera = g_fxo->get(); + + if (!g_camera->init) { return CELL_CAMERA_ERROR_NOT_INIT; } @@ -1151,8 +1176,9 @@ s32 cellCameraRemoveNotifyEventQueue(u64 key) return CELL_OK; } - const auto g_camera = fxm::get(); - if (!g_camera) + const auto g_camera = g_fxo->get(); + + if (!g_camera->init) { return CELL_CAMERA_ERROR_NOT_INIT; } @@ -1171,8 +1197,9 @@ s32 cellCameraSetNotifyEventQueue2(u64 key, u64 source, u64 flag) return CELL_OK; } - const auto g_camera = fxm::get(); - if (!g_camera) + const auto g_camera = g_fxo->get(); + + if (!g_camera->init) { return CELL_CAMERA_ERROR_NOT_INIT; } @@ -1244,7 +1271,7 @@ DECLARE(ppu_module_manager::cellCamera)("cellCamera", []() void camera_context::operator()() { - while (fxm::check() == this && !Emu.IsStopped()) + while (thread_ctrl::state() != thread_state::aborting && !Emu.IsStopped()) { const s32 fps = info.framerate; diff --git a/rpcs3/Emu/Cell/Modules/cellCamera.h b/rpcs3/Emu/Cell/Modules/cellCamera.h index 7bb78a118c..bb5aa21eae 100644 --- a/rpcs3/Emu/Cell/Modules/cellCamera.h +++ b/rpcs3/Emu/Cell/Modules/cellCamera.h @@ -396,6 +396,10 @@ public: }; attr_t attr[500]{}; atomic_t frame_num; + + atomic_t init = 0; + + static constexpr auto thread_name = "Camera Thread"sv; }; using camera_thread = named_thread;