cellCamera: use g_fxo

This commit is contained in:
Nekotekina 2019-09-18 00:14:36 +03:00
parent a4951ec407
commit 353a7ff8e6
2 changed files with 77 additions and 46 deletions

View file

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

View file

@ -396,6 +396,10 @@ public:
}; };
attr_t attr[500]{}; attr_t attr[500]{};
atomic_t<u32> frame_num; atomic_t<u32> frame_num;
atomic_t<u32> init = 0;
static constexpr auto thread_name = "Camera Thread"sv;
}; };
using camera_thread = named_thread<camera_context>; using camera_thread = named_thread<camera_context>;