From 65fd912c67ad76ad7ef6dee1ade7d76d26b08efd Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 19 Sep 2014 17:50:15 +0200 Subject: Add video device argument. --- src/mainwindow.cc | 3 ++- src/mainwindow.h | 3 ++- src/simplertp.cc | 6 +++++- src/v4l.cc | 10 +++++++--- src/v4l.h | 3 ++- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/mainwindow.cc b/src/mainwindow.cc index a0a2986..e4df3f2 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -29,7 +29,8 @@ #include #include -MainWindow::MainWindow() +MainWindow::MainWindow(QString v4ldev) + : v4l(v4ldev) { connect(&v4l, SIGNAL(newImage(QImage)), this, SLOT(newImage(QImage))); setCentralWidget(new QLabel()); diff --git a/src/mainwindow.h b/src/mainwindow.h index 419c302..fb87dae 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -28,13 +28,14 @@ #define __SIMPLERTP_MAINWINDOW_H__ #include +#include #include "v4l.h" class MainWindow : public QMainWindow { Q_OBJECT public: - MainWindow(); + MainWindow(QString v4ldev); public slots: void newImage(QImage img); diff --git a/src/simplertp.cc b/src/simplertp.cc index 6cff1ff..d833cf1 100644 --- a/src/simplertp.cc +++ b/src/simplertp.cc @@ -32,7 +32,11 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - MainWindow wnd; + QString v4ldev = "/dev/video0"; + + if(argc > 1) v4ldev = argv[1]; + + MainWindow wnd(v4ldev); wnd.show(); return app.exec(); diff --git a/src/v4l.cc b/src/v4l.cc index c83da06..e649209 100644 --- a/src/v4l.cc +++ b/src/v4l.cc @@ -66,7 +66,7 @@ struct buffer { size_t length; }; -static const char *dev_name; +static char *dev_name; static enum io_method io = IO_METHOD_MMAP; static int fd = -1; struct buffer *buffers; @@ -788,14 +788,19 @@ int main(int argc, char **argv) } #endif/*0*/ -V4L::V4L() +V4L::V4L(QString device) { + dev_name = strdup(device.toStdString().c_str()); + v4l = this; // Set global V4L object pointer. + start(); } V4L::~V4L() { + free(dev_name); + v4l = NULL; // Unset global V4L object pointer. // TODO: Stop thread.... somehow. @@ -803,7 +808,6 @@ V4L::~V4L() void V4L::run() { - dev_name = "/dev/video0"; force_format = true; open_device(); diff --git a/src/v4l.h b/src/v4l.h index 877843c..2fe474e 100644 --- a/src/v4l.h +++ b/src/v4l.h @@ -29,11 +29,12 @@ #include #include +#include class V4L : public QThread { Q_OBJECT public: - V4L(); + V4L(QString device = "/dev/video0"); ~V4L(); void run(); -- cgit v1.2.3