Skip to content

Commit

Permalink
FPS with QVideoProbe (seems to work on linux only)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaak committed Dec 23, 2017
1 parent a35e247 commit 64e504b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
8 changes: 0 additions & 8 deletions cameramanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ CameraManager::CameraManager(QObject *parent)
QList<QCameraInfo> CameraManager::listCameras()
{
return QCameraInfo::availableCameras();

//// if (cameraInfo.deviceName() == "mycamera")
// camera = new QCamera(QCameraInfo::defaultCamera());

// camera->setViewfinder(ui->cameraViewFinder);
// camera->start();

// ui->statusBar->showMessage("Aaaaa");
}

QSharedPointer<QCamera> CameraManager::getCameraByDeviceName(const QString &deviceName)
Expand Down
27 changes: 26 additions & 1 deletion mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
cameraManager(new CameraManager)
cameraManager(new CameraManager(this)),
fpsTimer(new QTimer(this)),
fpsProbe(new QVideoProbe(this))
{
ui->setupUi(this);
Console::setOutputControl(ui->consoleOutput);
Expand All @@ -20,6 +22,9 @@ MainWindow::MainWindow(QWidget *parent) :
connect(cameraComboBox, SIGNAL(activated(QVariant)), cameraManager, SLOT(changeSelectedCamera(QVariant)));
connect(cameraManager, SIGNAL(changedSelectedCamera(QSharedPointer<QCamera>)), this, SLOT(onCameraChanged(QSharedPointer<QCamera>)));

connect(fpsTimer, SIGNAL(timeout()), this, SLOT(updateFps()));
connect(fpsProbe, SIGNAL(videoFrameProbed(QVideoFrame)), this, SLOT(processFrame(QVideoFrame)));

//ui->consoleDockWidget->setVisible(false);

detectCameras();
Expand Down Expand Up @@ -65,14 +70,34 @@ void MainWindow::toggleCamera(bool enable)
QCameraInfo cameraInfo = cameraManager->getSelectedCameraInfo();

if (enable) {
fpsProbe->setSource(camera); // Returns true, hopefully.

Console::log(QString("Starting camera %1").arg(cameraInfo.description()));
camera->load();
camera->start();
fpsTimer->start(1000);

qDebug() << "MainWindow::toggleCamera" << camera->supportedViewfinderResolutions();
qDebug() << "MainWindow::toggleCamera" << camera->supportedViewfinderPixelFormats();
} else {
Console::log(QString("Stopping camera %1").arg(cameraInfo.description()));
camera->stop();
fpsTimer->stop();
ui->statusBar->clearMessage();
}
}

void MainWindow::processFrame(const QVideoFrame &frame)
{
++framesInCurrentSecond;
//qDebug() << frame.width() << "x" << frame.height();

// frame.map(QAbstractVideoBuffer::WriteOnly);
// frame.unmap();
}

void MainWindow::updateFps()
{
ui->statusBar->showMessage(QString("%1 FPS").arg(framesInCurrentSecond));
framesInCurrentSecond = 0;
}
7 changes: 7 additions & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#include <QCameraViewfinder>
#include <QComboBox>
#include <QSpacerItem>
#include <QTimer>
#include <QVariant>
#include <QVideoProbe>
#include "cameramanager.h"
#include "dataawarecombobox.h"

Expand All @@ -29,12 +31,17 @@ class MainWindow : public QMainWindow
CameraManager *cameraManager;
DataAwareComboBox *cameraComboBox;
QAction *cameraComboBoxAction;
QTimer *fpsTimer;
QVideoProbe *fpsProbe;

void detectCameras();
unsigned int framesInCurrentSecond = 0;

private slots:
void toggleCamera(bool enable);
void processFrame(const QVideoFrame &frame);
void onCameraChanged(const QSharedPointer<QCamera> &cameraPtr);
void updateFps();
};

#endif // MAINWINDOW_H

0 comments on commit 64e504b

Please sign in to comment.