port camera stuff

This commit is contained in:
Arisotura 2024-05-26 13:08:41 +02:00
parent a203d06c24
commit de18f029a6
7 changed files with 56 additions and 50 deletions

View File

@ -23,6 +23,8 @@
using namespace melonDS;
const char* kCamConfigPath[] = {"DSi.Camera0", "DSi.Camera1"};
#if QT_VERSION >= 0x060000
CameraFrameDumper::CameraFrameDumper(QObject* parent) : QVideoSink(parent)
@ -116,10 +118,11 @@ QList<QVideoFrame::PixelFormat> CameraFrameDumper::supportedPixelFormats(QAbstra
#endif
CameraManager::CameraManager(int num, int width, int height, bool yuv) : QObject()
CameraManager::CameraManager(int num, int width, int height, bool yuv)
: QObject(),
num(num),
config(Config::GetGlobalTable().GetTable(kCamConfigPath[num]))
{
this->num = num;
startNum = 0;
// QCamera needs to be controlled from the UI thread, hence this
@ -136,7 +139,7 @@ CameraManager::CameraManager(int num, int width, int height, bool yuv) : QObject
tempFrameBuffer = new u32[fbsize];
inputType = -1;
xFlip = false;
xFlip = config.GetBool("XFlip");
init();
}
@ -157,9 +160,9 @@ void CameraManager::init()
startNum = 0;
inputType = Config::Camera[num].InputType;
imagePath = QString::fromStdString(Config::Camera[num].ImagePath);
camDeviceName = QString::fromStdString(Config::Camera[num].CamDeviceName);
inputType = config.GetInt("InputType");
imagePath = config.GetQString("ImagePath");
camDeviceName = config.GetQString("DeviceName");
camDevice = nullptr;

View File

@ -33,6 +33,7 @@
#include <QMutex>
#include "types.h"
#include "Config.h"
class CameraManager;
@ -80,6 +81,8 @@ public:
CameraManager(int num, int width, int height, bool yuv);
~CameraManager();
Config::Table& getConfig() { return config; }
void init();
void deInit();
@ -106,6 +109,8 @@ private slots:
private:
int num;
Config::Table config;
int startNum;
int inputType;

View File

@ -22,6 +22,7 @@
#include <QPainter>
#include "types.h"
#include "main.h"
#include "CameraSettingsDialog.h"
#include "ui_CameraSettingsDialog.h"
@ -71,9 +72,16 @@ CameraSettingsDialog::CameraSettingsDialog(QWidget* parent) : QDialog(parent), u
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
emuInstance = ((MainWindow*)parent)->getEmuInstance();
for (int i = 0; i < 2; i++)
{
oldCamSettings[i] = Config::Camera[i];
auto& cfg = camManager[i]->getConfig();
oldCamSettings[i].InputType = cfg.GetInt("InputType");
oldCamSettings[i].ImagePath = cfg.GetString("ImagePath");
oldCamSettings[i].CamDeviceName = cfg.GetString("DeviceName");
oldCamSettings[i].XFlip = cfg.GetBool("XFlip");
}
ui->cbCameraSel->addItem("DSi outer camera");
@ -161,7 +169,13 @@ void CameraSettingsDialog::on_CameraSettingsDialog_rejected()
{
camManager[i]->stop();
camManager[i]->deInit();
Config::Camera[i] = oldCamSettings[i];
auto& cfg = camManager[i]->getConfig();
cfg.SetInt("InputType", oldCamSettings[i].InputType);
cfg.SetString("ImagePath", oldCamSettings[i].ImagePath);
cfg.SetString("DeviceName", oldCamSettings[i].CamDeviceName);
cfg.SetBool("XFlip", oldCamSettings[i].XFlip);
camManager[i]->init();
}
@ -178,7 +192,7 @@ void CameraSettingsDialog::on_cbCameraSel_currentIndexChanged(int id)
}
currentId = id;
currentCfg = &Config::Camera[id];
currentCfg = &camManager[id]->getConfig();
//currentCam = camManager[id];
currentCam = nullptr;
populateCamControls(id);
@ -198,16 +212,16 @@ void CameraSettingsDialog::onChangeInputType(int type)
currentCam->deInit();
}
currentCfg->InputType = type;
currentCfg->SetInt("InputType", type);
ui->txtSrcImagePath->setEnabled(type == 1);
ui->btnSrcImageBrowse->setEnabled(type == 1);
ui->cbPhysicalCamera->setEnabled((type == 2) && (ui->cbPhysicalCamera->count()>0));
currentCfg->ImagePath = ui->txtSrcImagePath->text().toStdString();
currentCfg->SetQString("ImagePath", ui->txtSrcImagePath->text());
if (ui->cbPhysicalCamera->count() > 0)
currentCfg->CamDeviceName = ui->cbPhysicalCamera->currentData().toString().toStdString();
currentCfg->SetQString("DeviceName", ui->cbPhysicalCamera->currentData().toString());
if (currentCam)
{
@ -226,7 +240,7 @@ void CameraSettingsDialog::on_txtSrcImagePath_textChanged()
currentCam->deInit();
}
currentCfg->ImagePath = ui->txtSrcImagePath->text().toStdString();
currentCfg->SetQString("ImagePath", ui->txtSrcImagePath->text());
if (currentCam)
{
@ -257,7 +271,7 @@ void CameraSettingsDialog::on_cbPhysicalCamera_currentIndexChanged(int id)
currentCam->deInit();
}
currentCfg->CamDeviceName = ui->cbPhysicalCamera->itemData(id).toString().toStdString();
currentCfg->SetQString("DeviceName", ui->cbPhysicalCamera->itemData(id).toString());
if (currentCam)
{
@ -268,16 +282,16 @@ void CameraSettingsDialog::on_cbPhysicalCamera_currentIndexChanged(int id)
void CameraSettingsDialog::populateCamControls(int id)
{
Config::CameraConfig& cfg = Config::Camera[id];
Config::Table& cfg = camManager[id]->getConfig();
int type = cfg.InputType;
int type = cfg.GetInt("InputType");
if (type < 0 || type >= grpInputType->buttons().count()) type = 0;
grpInputType->button(type)->setChecked(true);
ui->txtSrcImagePath->setText(QString::fromStdString(cfg.ImagePath));
ui->txtSrcImagePath->setText(cfg.GetQString("ImagePath"));
bool deviceset = false;
QString device = QString::fromStdString(cfg.CamDeviceName);
QString device = cfg.GetQString("DeviceName");
for (int i = 0; i < ui->cbPhysicalCamera->count(); i++)
{
QString itemdev = ui->cbPhysicalCamera->itemData(i).toString();
@ -293,13 +307,14 @@ void CameraSettingsDialog::populateCamControls(int id)
onChangeInputType(type);
ui->chkFlipPicture->setChecked(cfg.XFlip);
ui->chkFlipPicture->setChecked(cfg.GetBool("XFlip"));
}
void CameraSettingsDialog::on_chkFlipPicture_clicked()
{
if (!currentCfg) return;
currentCfg->XFlip = ui->chkFlipPicture->isChecked();
if (currentCam) currentCam->setXFlip(currentCfg->XFlip);
bool xflip = ui->chkFlipPicture->isChecked();
currentCfg->SetBool("XFlip", xflip);
if (currentCam) currentCam->setXFlip(xflip);
}

View File

@ -28,6 +28,8 @@
namespace Ui { class CameraSettingsDialog; }
class CameraSettingsDialog;
class EmuInstance;
class CameraPreviewPanel : public QWidget
{
Q_OBJECT
@ -92,15 +94,22 @@ private slots:
private:
Ui::CameraSettingsDialog* ui;
EmuInstance* emuInstance;
QButtonGroup* grpInputType;
CameraPreviewPanel* previewPanel;
int currentId;
Config::CameraConfig* currentCfg;
Config::Table* currentCfg;
CameraManager* currentCam;
Config::CameraConfig oldCamSettings[2];
struct
{
int InputType; // 0=blank 1=image 2=camera
std::string ImagePath;
std::string CamDeviceName;
bool XFlip;
} oldCamSettings[2];
void populateCamControls(int id);
};

View File

@ -48,8 +48,6 @@ int GL_ScaleFactor;
bool GL_BetterPolygons;
bool GL_HiresCoordinates;
CameraConfig Camera[2];
const char* kConfigFile = "melonDS.toml";

View File

@ -25,9 +25,6 @@
#include <unordered_map>
#include <tuple>
//#define TOML_HEADER_ONLY 0
//#include "toml/toml.hpp"
#ifndef TOML11_VALUE_HPP
namespace toml
{
@ -46,23 +43,6 @@ struct LegacyEntry
bool InstanceUnique; // whether the setting can exist individually for each instance in multiplayer
};
struct ConfigEntry
{
char Name[32];
int Type; // 0=int 1=bool 2=string 3=64bit int
void* Value; // pointer to the value variable
std::variant<int, bool, std::string, int64_t> Default;
bool InstanceUnique; // whether the setting can exist individually for each instance in multiplayer
};
struct CameraConfig
{
int InputType; // 0=blank 1=image 2=camera
std::string ImagePath;
std::string CamDeviceName;
bool XFlip;
};
template<typename T>
using DefaultList = std::unordered_map<std::string, T>;
@ -162,8 +142,6 @@ extern int GL_ScaleFactor;
extern bool GL_BetterPolygons;
extern bool GL_HiresCoordinates;
extern CameraConfig Camera[2];
bool Load();
void Save();

View File

@ -324,8 +324,6 @@ int main(int argc, char** argv)
camStarted[1] = false;
camManager[0] = new CameraManager(0, 640, 480, true);
camManager[1] = new CameraManager(1, 640, 480, true);
camManager[0]->setXFlip(Config::Camera[0].XFlip);
camManager[1]->setXFlip(Config::Camera[1].XFlip);
systemThemeName = new QString(QApplication::style()->objectName());