attempt
This commit is contained in:
parent
e878866234
commit
3c0b105fbe
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
CameraFrameDumper::CameraFrameDumper(QObject* parent) : QAbstractVideoSurface(parent)
|
CameraFrameDumper::CameraFrameDumper(QObject* parent) : QAbstractVideoSurface(parent)
|
||||||
{
|
{
|
||||||
|
CamList.append((CameraManager*)parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CameraFrameDumper::present(const QVideoFrame& _frame)
|
bool CameraFrameDumper::present(const QVideoFrame& _frame)
|
||||||
|
@ -28,8 +29,11 @@ bool CameraFrameDumper::present(const QVideoFrame& _frame)
|
||||||
QVideoFrame frame(_frame);
|
QVideoFrame frame(_frame);
|
||||||
if (!frame.map(QAbstractVideoBuffer::ReadOnly))
|
if (!frame.map(QAbstractVideoBuffer::ReadOnly))
|
||||||
return false;
|
return false;
|
||||||
printf("FRAMEZORZ!! %d %d %d\n", frame.pixelFormat(), frame.isMapped(), frame.isReadable());
|
if (!frame.isReadable())
|
||||||
//NDS::CamInputFrame(0, (u32*)frame.bits(), frame.width(), frame.height(), false);
|
return false;
|
||||||
|
|
||||||
|
for (CameraManager* cam : CamList)
|
||||||
|
cam->FeedFrame((u32*)frame.bits(), frame.width(), frame.height(), frame.pixelFormat() == QVideoFrame::Format_YUYV);
|
||||||
|
|
||||||
frame.unmap();
|
frame.unmap();
|
||||||
|
|
||||||
|
@ -47,10 +51,14 @@ QList<QVideoFrame::PixelFormat> CameraFrameDumper::supportedPixelFormats(QAbstra
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CameraManager::CameraManager(int num, int width, int height, bool yuv)
|
CameraManager::CameraManager(int num, int width, int height, bool yuv) : QObject()
|
||||||
{
|
{
|
||||||
Num = num;
|
Num = num;
|
||||||
|
|
||||||
|
// QCamera needs to be controlled from the UI thread, hence this
|
||||||
|
connect(this, SIGNAL(CamStartSignal()), this, SLOT(CamStart()));
|
||||||
|
connect(this, SIGNAL(CamStopSignal()), this, SLOT(CamStop()));
|
||||||
|
|
||||||
FrameWidth = width;
|
FrameWidth = width;
|
||||||
FrameHeight = height;
|
FrameHeight = height;
|
||||||
FrameFormatYUV = yuv;
|
FrameFormatYUV = yuv;
|
||||||
|
@ -81,6 +89,12 @@ void CameraManager::Init()
|
||||||
InputType = 0;
|
InputType = 0;
|
||||||
InputType = 1;
|
InputType = 1;
|
||||||
ImagePath = "test.jpg";
|
ImagePath = "test.jpg";
|
||||||
|
if(Num==0)
|
||||||
|
{
|
||||||
|
InputType = 2;
|
||||||
|
const QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
|
||||||
|
CamDeviceName = cameras[0].deviceName();
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// fill the framebuffer with black
|
// fill the framebuffer with black
|
||||||
|
@ -118,21 +132,68 @@ void CameraManager::Init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (InputType == 2)
|
||||||
|
{
|
||||||
|
// physical camera
|
||||||
|
|
||||||
|
CamDevice = new QCamera(CamDeviceName.toUtf8());
|
||||||
|
CamDumper = new CameraFrameDumper(this);
|
||||||
|
CamDevice->setViewfinder(CamDumper);
|
||||||
|
|
||||||
|
/*CamDevice->load();
|
||||||
|
QCameraViewfinderSettings settings;
|
||||||
|
|
||||||
|
auto resolutions = CamDevice->supportedViewfinderResolutions();
|
||||||
|
for (auto& res : resolutions)
|
||||||
|
{
|
||||||
|
printf("RESOLUTION: %d x %d\n", res.width(), res.height());
|
||||||
|
}
|
||||||
|
|
||||||
|
CamDevice->unload();*/
|
||||||
|
|
||||||
|
QCameraViewfinderSettings settings;
|
||||||
|
settings.setResolution(640, 480);
|
||||||
|
settings.setPixelFormat(QVideoFrame::Format_YUYV);
|
||||||
|
CamDevice->setViewfinderSettings(settings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraManager::DeInit()
|
void CameraManager::DeInit()
|
||||||
{
|
{
|
||||||
|
if (InputType == 2)
|
||||||
|
{
|
||||||
|
CamDevice->stop();
|
||||||
|
delete CamDevice;
|
||||||
|
delete CamDumper;
|
||||||
|
}
|
||||||
|
|
||||||
InputType = -1;
|
InputType = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraManager::Start()
|
void CameraManager::Start()
|
||||||
{
|
{
|
||||||
//
|
if (InputType == 2)
|
||||||
|
{
|
||||||
|
emit CamStartSignal();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraManager::Stop()
|
void CameraManager::Stop()
|
||||||
{
|
{
|
||||||
//
|
if (InputType == 2)
|
||||||
|
{
|
||||||
|
emit CamStopSignal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CameraManager::CamStart()
|
||||||
|
{
|
||||||
|
CamDevice->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CameraManager::CamStop()
|
||||||
|
{
|
||||||
|
CamDevice->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraManager::CaptureFrame(u32* frame, int width, int height, bool yuv)
|
void CameraManager::CaptureFrame(u32* frame, int width, int height, bool yuv)
|
||||||
|
@ -147,7 +208,55 @@ void CameraManager::CaptureFrame(u32* frame, int width, int height, bool yuv)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//
|
if (yuv == FrameFormatYUV)
|
||||||
|
{
|
||||||
|
CopyFrame_Straight(FrameBuffer, FrameWidth, FrameHeight,
|
||||||
|
frame, width, height,
|
||||||
|
yuv);
|
||||||
|
}
|
||||||
|
else if (yuv)
|
||||||
|
{
|
||||||
|
CopyFrame_RGBtoYUV(FrameBuffer, FrameWidth, FrameHeight,
|
||||||
|
frame, width, height);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CopyFrame_YUVtoRGB(FrameBuffer, FrameWidth, FrameHeight,
|
||||||
|
frame, width, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FrameMutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CameraManager::FeedFrame(u32* frame, int width, int height, bool yuv)
|
||||||
|
{
|
||||||
|
FrameMutex.lock();
|
||||||
|
|
||||||
|
if (width == FrameWidth && height == FrameHeight && yuv == FrameFormatYUV)
|
||||||
|
{
|
||||||
|
int len = width * height;
|
||||||
|
if (yuv) len /= 2;
|
||||||
|
memcpy(FrameBuffer, frame, len * sizeof(u32));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (yuv == FrameFormatYUV)
|
||||||
|
{
|
||||||
|
CopyFrame_Straight(frame, width, height,
|
||||||
|
FrameBuffer, FrameWidth, FrameHeight,
|
||||||
|
yuv);
|
||||||
|
}
|
||||||
|
else if (yuv)
|
||||||
|
{
|
||||||
|
CopyFrame_RGBtoYUV(frame, width, height,
|
||||||
|
FrameBuffer, FrameWidth, FrameHeight);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CopyFrame_YUVtoRGB(frame, width, height,
|
||||||
|
FrameBuffer, FrameWidth, FrameHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameMutex.unlock();
|
FrameMutex.unlock();
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
class CameraManager;
|
||||||
|
|
||||||
class CameraFrameDumper : public QAbstractVideoSurface
|
class CameraFrameDumper : public QAbstractVideoSurface
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -36,10 +38,15 @@ public:
|
||||||
|
|
||||||
bool present(const QVideoFrame& frame) override;
|
bool present(const QVideoFrame& frame) override;
|
||||||
QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType type = QAbstractVideoBuffer::NoHandle) const override;
|
QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType type = QAbstractVideoBuffer::NoHandle) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<CameraManager*> CamList;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CameraManager
|
class CameraManager : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CameraManager(int num, int width, int height, bool yuv);
|
CameraManager(int num, int width, int height, bool yuv);
|
||||||
~CameraManager();
|
~CameraManager();
|
||||||
|
@ -52,6 +59,16 @@ public:
|
||||||
|
|
||||||
void CaptureFrame(u32* frame, int width, int height, bool yuv);
|
void CaptureFrame(u32* frame, int width, int height, bool yuv);
|
||||||
|
|
||||||
|
void FeedFrame(u32* frame, int width, int height, bool yuv);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void CamStartSignal();
|
||||||
|
void CamStopSignal();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void CamStart();
|
||||||
|
void CamStop();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int Num;
|
int Num;
|
||||||
|
|
||||||
|
@ -59,6 +76,9 @@ private:
|
||||||
QString ImagePath;
|
QString ImagePath;
|
||||||
QString CamDeviceName;
|
QString CamDeviceName;
|
||||||
|
|
||||||
|
QCamera* CamDevice;
|
||||||
|
CameraFrameDumper* CamDumper;
|
||||||
|
|
||||||
int FrameWidth, FrameHeight;
|
int FrameWidth, FrameHeight;
|
||||||
bool FrameFormatYUV;
|
bool FrameFormatYUV;
|
||||||
u32* FrameBuffer;
|
u32* FrameBuffer;
|
||||||
|
|
|
@ -1770,38 +1770,6 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
||||||
const QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
|
const QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
|
||||||
for (const QCameraInfo &cameraInfo : cameras)
|
for (const QCameraInfo &cameraInfo : cameras)
|
||||||
printf("CAMERAFAZIL: %s\n", cameraInfo.deviceName().toStdString().c_str());
|
printf("CAMERAFAZIL: %s\n", cameraInfo.deviceName().toStdString().c_str());
|
||||||
QCamera* camera = new QCamera(cameras[0]);
|
|
||||||
CameraFrameDumper* dumper = new CameraFrameDumper();
|
|
||||||
//QCameraViewfinder* derp = new QCameraViewfinder();
|
|
||||||
printf("PROAON\n");
|
|
||||||
//camera->setCaptureMode(QCamera::CaptureVideo);
|
|
||||||
//camera->setCaptureMode(QCamera::CaptureViewfinder);
|
|
||||||
printf("PROOT\n");
|
|
||||||
//camera->unload();
|
|
||||||
camera->setViewfinder(dumper);
|
|
||||||
//camera->setViewfinder(derp);
|
|
||||||
//camera->load();
|
|
||||||
|
|
||||||
// if (status != QCamera::LoadedStatus || m_camera->state() == QCamera::ActiveState) { return
|
|
||||||
printf("STATUS %d STATE %d\n", camera->status(), camera->state());
|
|
||||||
|
|
||||||
printf("CHIASSE\n");
|
|
||||||
/*QCameraViewfinderSettings settings;
|
|
||||||
auto zorp = camera->supportedViewfinderResolutions(settings);
|
|
||||||
for (auto& res : zorp) printf("RESOLUTION: %d x %d\n", res.width(), res.height());
|
|
||||||
auto zarp = camera->supportedViewfinderPixelFormats(settings);
|
|
||||||
for (auto& pf : zarp) printf("PIXEL FORMAT: %d\n", pf);
|
|
||||||
|
|
||||||
settings.setResolution(640, 480);
|
|
||||||
//settings.setPixelFormat(QVideoFrame::Format_RGB32);
|
|
||||||
settings.setPixelFormat(QVideoFrame::Format_YUYV);
|
|
||||||
printf("PRALIPET\n");
|
|
||||||
camera->setViewfinderSettings(settings);*/
|
|
||||||
printf("PROULON\n");
|
|
||||||
//dumper->start();
|
|
||||||
//QVideoSurfaceFormat blarf(QSize(640,480), QVideoFrame::Format_RGB32);
|
|
||||||
//dumper->start(blarf);
|
|
||||||
camera->start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
|
Loading…
Reference in New Issue