summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Narr the Reg2022-06-28 19:35:51 -0500
committerGravatar german772022-07-23 19:40:25 -0500
commit403bdc4dafe89a463f3d93b9a389a1010ca5ff16 (patch)
tree88df3fada076b04c2ab2da8972d1d785f492b520
parentservice: irs: Move to IRS namespace and minor fixes (diff)
downloadyuzu-403bdc4dafe89a463f3d93b9a389a1010ca5ff16.tar.gz
yuzu-403bdc4dafe89a463f3d93b9a389a1010ca5ff16.tar.xz
yuzu-403bdc4dafe89a463f3d93b9a389a1010ca5ff16.zip
yuzu: Add webcam support and rebase to latest master
Diffstat (limited to '')
-rw-r--r--src/common/settings.h4
-rw-r--r--src/core/hle/service/hid/errors.h4
-rw-r--r--src/core/hle/service/hid/irs.cpp2
-rw-r--r--src/core/hle/service/hid/irs.h2
-rw-r--r--src/yuzu/bootmanager.cpp19
-rw-r--r--src/yuzu/bootmanager.h2
-rw-r--r--src/yuzu/configuration/configure_camera.cpp24
-rw-r--r--src/yuzu/configuration/configure_camera.h2
8 files changed, 43 insertions, 16 deletions
diff --git a/src/common/settings.h b/src/common/settings.h
index 20959ec89..1079cf8cb 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -503,8 +503,8 @@ struct Values {
503 Setting<bool> enable_ring_controller{true, "enable_ring_controller"}; 503 Setting<bool> enable_ring_controller{true, "enable_ring_controller"};
504 RingconRaw ringcon_analogs; 504 RingconRaw ringcon_analogs;
505 505
506 BasicSetting<bool> enable_ir_sensor{false, "enable_ir_sensor"}; 506 Setting<bool> enable_ir_sensor{false, "enable_ir_sensor"};
507 BasicSetting<std::string> ir_sensor_device{"auto", "ir_sensor_device"}; 507 Setting<std::string> ir_sensor_device{"auto", "ir_sensor_device"};
508 508
509 // Data Storage 509 // Data Storage
510 Setting<bool> use_virtual_sd{true, "use_virtual_sd"}; 510 Setting<bool> use_virtual_sd{true, "use_virtual_sd"};
diff --git a/src/core/hle/service/hid/errors.h b/src/core/hle/service/hid/errors.h
index accc2b646..4613a4e60 100644
--- a/src/core/hle/service/hid/errors.h
+++ b/src/core/hle/service/hid/errors.h
@@ -22,7 +22,7 @@ constexpr Result NpadNotConnected{ErrorModule::HID, 710};
22 22
23namespace Service::IRS { 23namespace Service::IRS {
24 24
25constexpr ResultCode InvalidProcessorState{ErrorModule::Irsensor, 78}; 25constexpr Result InvalidProcessorState{ErrorModule::Irsensor, 78};
26constexpr ResultCode InvalidIrCameraHandle{ErrorModule::Irsensor, 204}; 26constexpr Result InvalidIrCameraHandle{ErrorModule::Irsensor, 204};
27 27
28} // namespace Service::IRS 28} // namespace Service::IRS
diff --git a/src/core/hle/service/hid/irs.cpp b/src/core/hle/service/hid/irs.cpp
index b6e7c0792..d5107e41f 100644
--- a/src/core/hle/service/hid/irs.cpp
+++ b/src/core/hle/service/hid/irs.cpp
@@ -529,7 +529,7 @@ void IRS::ActivateIrsensorWithFunctionLevel(Kernel::HLERequestContext& ctx) {
529 rb.Push(ResultSuccess); 529 rb.Push(ResultSuccess);
530} 530}
531 531
532ResultCode IRS::IsIrCameraHandleValid(const Core::IrSensor::IrCameraHandle& camera_handle) const { 532Result IRS::IsIrCameraHandleValid(const Core::IrSensor::IrCameraHandle& camera_handle) const {
533 if (camera_handle.npad_id > 533 if (camera_handle.npad_id >
534 static_cast<u8>(NpadIdTypeToIndex(Core::HID::NpadIdType::Handheld))) { 534 static_cast<u8>(NpadIdTypeToIndex(Core::HID::NpadIdType::Handheld))) {
535 return InvalidIrCameraHandle; 535 return InvalidIrCameraHandle;
diff --git a/src/core/hle/service/hid/irs.h b/src/core/hle/service/hid/irs.h
index 516620b4d..2e6115c73 100644
--- a/src/core/hle/service/hid/irs.h
+++ b/src/core/hle/service/hid/irs.h
@@ -57,7 +57,7 @@ private:
57 void StopImageProcessorAsync(Kernel::HLERequestContext& ctx); 57 void StopImageProcessorAsync(Kernel::HLERequestContext& ctx);
58 void ActivateIrsensorWithFunctionLevel(Kernel::HLERequestContext& ctx); 58 void ActivateIrsensorWithFunctionLevel(Kernel::HLERequestContext& ctx);
59 59
60 ResultCode IsIrCameraHandleValid(const Core::IrSensor::IrCameraHandle& camera_handle) const; 60 Result IsIrCameraHandleValid(const Core::IrSensor::IrCameraHandle& camera_handle) const;
61 Core::IrSensor::DeviceFormat& GetIrCameraSharedMemoryDeviceEntry( 61 Core::IrSensor::DeviceFormat& GetIrCameraSharedMemoryDeviceEntry(
62 const Core::IrSensor::IrCameraHandle& camera_handle); 62 const Core::IrSensor::IrCameraHandle& camera_handle);
63 63
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp
index 774085809..0ee3820a2 100644
--- a/src/yuzu/bootmanager.cpp
+++ b/src/yuzu/bootmanager.cpp
@@ -830,6 +830,10 @@ void GRenderWindow::InitializeCamera() {
830 camera->unload(); 830 camera->unload();
831 camera->setCaptureMode(QCamera::CaptureViewfinder); 831 camera->setCaptureMode(QCamera::CaptureViewfinder);
832 camera->load(); 832 camera->load();
833 camera->start();
834
835 pending_camera_snapshots = 0;
836 is_virtual_camera = false;
833 837
834 camera_timer = std::make_unique<QTimer>(); 838 camera_timer = std::make_unique<QTimer>();
835 connect(camera_timer.get(), &QTimer::timeout, [this] { RequestCameraCapture(); }); 839 connect(camera_timer.get(), &QTimer::timeout, [this] { RequestCameraCapture(); });
@@ -851,11 +855,17 @@ void GRenderWindow::RequestCameraCapture() {
851 return; 855 return;
852 } 856 }
853 857
854 // Idealy one should only call capture but Qt refuses to take a second capture without 858 // If the camera doesn't capture, test for virtual cameras
855 // stopping the camera 859 if (pending_camera_snapshots > 5) {
856 camera->stop(); 860 is_virtual_camera = true;
857 camera->start(); 861 }
862 // Virtual cameras like obs need to reset the camera every capture
863 if (is_virtual_camera) {
864 camera->stop();
865 camera->start();
866 }
858 867
868 pending_camera_snapshots++;
859 camera_capture->capture(); 869 camera_capture->capture();
860} 870}
861 871
@@ -870,6 +880,7 @@ void GRenderWindow::OnCameraCapture(int requestId, const QImage& img) {
870 camera_data.resize(camera_width * camera_height); 880 camera_data.resize(camera_width * camera_height);
871 std::memcpy(camera_data.data(), converted.bits(), camera_width * camera_height * sizeof(u32)); 881 std::memcpy(camera_data.data(), converted.bits(), camera_width * camera_height * sizeof(u32));
872 input_subsystem->GetCamera()->SetCameraData(camera_width, camera_height, camera_data); 882 input_subsystem->GetCamera()->SetCameraData(camera_width, camera_height, camera_data);
883 pending_camera_snapshots = 0;
873} 884}
874 885
875bool GRenderWindow::event(QEvent* event) { 886bool GRenderWindow::event(QEvent* event) {
diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h
index 346201768..b4781e697 100644
--- a/src/yuzu/bootmanager.h
+++ b/src/yuzu/bootmanager.h
@@ -240,6 +240,8 @@ private:
240 bool first_frame = false; 240 bool first_frame = false;
241 InputCommon::TasInput::TasState last_tas_state; 241 InputCommon::TasInput::TasState last_tas_state;
242 242
243 bool is_virtual_camera;
244 int pending_camera_snapshots;
243 std::unique_ptr<QCamera> camera; 245 std::unique_ptr<QCamera> camera;
244 std::unique_ptr<QCameraImageCapture> camera_capture; 246 std::unique_ptr<QCameraImageCapture> camera_capture;
245 std::unique_ptr<QTimer> camera_timer; 247 std::unique_ptr<QTimer> camera_timer;
diff --git a/src/yuzu/configuration/configure_camera.cpp b/src/yuzu/configuration/configure_camera.cpp
index 97febb33c..73cdcf3f2 100644
--- a/src/yuzu/configuration/configure_camera.cpp
+++ b/src/yuzu/configuration/configure_camera.cpp
@@ -39,8 +39,8 @@ void ConfigureCamera::PreviewCamera() {
39 for (const QCameraInfo& cameraInfo : cameras) { 39 for (const QCameraInfo& cameraInfo : cameras) {
40 if (input_devices[index] == cameraInfo.deviceName().toStdString() || 40 if (input_devices[index] == cameraInfo.deviceName().toStdString() ||
41 input_devices[index] == "Auto") { 41 input_devices[index] == "Auto") {
42 LOG_ERROR(Frontend, "Selected Camera {} {}", cameraInfo.description().toStdString(), 42 LOG_INFO(Frontend, "Selected Camera {} {}", cameraInfo.description().toStdString(),
43 cameraInfo.deviceName().toStdString()); 43 cameraInfo.deviceName().toStdString());
44 camera = std::make_unique<QCamera>(cameraInfo); 44 camera = std::make_unique<QCamera>(cameraInfo);
45 camera_found = true; 45 camera_found = true;
46 break; 46 break;
@@ -62,12 +62,23 @@ void ConfigureCamera::PreviewCamera() {
62 camera->unload(); 62 camera->unload();
63 camera->setCaptureMode(QCamera::CaptureViewfinder); 63 camera->setCaptureMode(QCamera::CaptureViewfinder);
64 camera->load(); 64 camera->load();
65 camera->start();
66
67 pending_snapshots = 0;
68 is_virtual_camera = false;
65 69
66 camera_timer = std::make_unique<QTimer>(); 70 camera_timer = std::make_unique<QTimer>();
67 connect(camera_timer.get(), &QTimer::timeout, [this] { 71 connect(camera_timer.get(), &QTimer::timeout, [this] {
68 camera->stop(); 72 // If the camera doesn't capture, test for virtual cameras
69 camera->start(); 73 if (pending_snapshots > 5) {
70 74 is_virtual_camera = true;
75 }
76 // Virtual cameras like obs need to reset the camera every capture
77 if (is_virtual_camera) {
78 camera->stop();
79 camera->start();
80 }
81 pending_snapshots++;
71 camera_capture->capture(); 82 camera_capture->capture();
72 }); 83 });
73 84
@@ -75,10 +86,11 @@ void ConfigureCamera::PreviewCamera() {
75} 86}
76 87
77void ConfigureCamera::DisplayCapturedFrame(int requestId, const QImage& img) { 88void ConfigureCamera::DisplayCapturedFrame(int requestId, const QImage& img) {
78 LOG_ERROR(Frontend, "ImageCaptured {} {}", img.width(), img.height()); 89 LOG_INFO(Frontend, "ImageCaptured {} {}", img.width(), img.height());
79 const auto converted = img.scaled(320, 240, Qt::AspectRatioMode::IgnoreAspectRatio, 90 const auto converted = img.scaled(320, 240, Qt::AspectRatioMode::IgnoreAspectRatio,
80 Qt::TransformationMode::SmoothTransformation); 91 Qt::TransformationMode::SmoothTransformation);
81 ui->preview_box->setPixmap(QPixmap::fromImage(converted)); 92 ui->preview_box->setPixmap(QPixmap::fromImage(converted));
93 pending_snapshots = 0;
82} 94}
83 95
84void ConfigureCamera::changeEvent(QEvent* event) { 96void ConfigureCamera::changeEvent(QEvent* event) {
diff --git a/src/yuzu/configuration/configure_camera.h b/src/yuzu/configuration/configure_camera.h
index af7551c03..db9833b5c 100644
--- a/src/yuzu/configuration/configure_camera.h
+++ b/src/yuzu/configuration/configure_camera.h
@@ -44,6 +44,8 @@ private:
44 44
45 InputCommon::InputSubsystem* input_subsystem; 45 InputCommon::InputSubsystem* input_subsystem;
46 46
47 bool is_virtual_camera;
48 int pending_snapshots;
47 std::unique_ptr<QCamera> camera; 49 std::unique_ptr<QCamera> camera;
48 std::unique_ptr<QCameraImageCapture> camera_capture; 50 std::unique_ptr<QCameraImageCapture> camera_capture;
49 std::unique_ptr<QTimer> camera_timer; 51 std::unique_ptr<QTimer> camera_timer;