From: Jean-Baptiste Mardelle Date: Wed, 27 Oct 2010 20:21:45 +0000 (+0000) Subject: Display webcam pixel format in wizard X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=25a898e070fd76a2e26c9eb5de42918e2859aa51;p=kdenlive Display webcam pixel format in wizard svn path=/trunk/kdenlive/; revision=5054 --- diff --git a/src/blackmagic/capture.cpp b/src/blackmagic/capture.cpp index cb953b82..505c0858 100644 --- a/src/blackmagic/capture.cpp +++ b/src/blackmagic/capture.cpp @@ -492,9 +492,9 @@ BmdCaptureHandler::BmdCaptureHandler(QVBoxLayout *lay, QWidget *parent): { } -QString BmdCaptureHandler::getDeviceName(QString, int *, int *) +QStringList BmdCaptureHandler::getDeviceName(QString) { - return QString(); + return QStringList(); } void BmdCaptureHandler::startPreview(int deviceId, int captureMode, bool audio) diff --git a/src/blackmagic/capture.h b/src/blackmagic/capture.h index db716c80..1a7942ec 100644 --- a/src/blackmagic/capture.h +++ b/src/blackmagic/capture.h @@ -59,7 +59,7 @@ public: void showOverlay(QImage img, bool transparent = true); void hideOverlay(); void hidePreview(bool hide); - QString getDeviceName(QString, int *, int *); + QStringList getDeviceName(QString); private: IDeckLinkIterator *deckLinkIterator; diff --git a/src/kdenlivesettingsdialog.cpp b/src/kdenlivesettingsdialog.cpp index f17c9f75..946a5bdf 100644 --- a/src/kdenlivesettingsdialog.cpp +++ b/src/kdenlivesettingsdialog.cpp @@ -83,15 +83,13 @@ KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent) : m_configCapture.setupUi(p4); V4lCaptureHandler v4l(NULL); - int width; - int height; // Video 4 Linux device detection for (int i = 0; i < 10; i++) { QString path = "/dev/video" + QString::number(i); if (QFile::exists(path)) { - QString deviceName = v4l.getDeviceName(path.toUtf8().constData(), &width, &height); - m_configCapture.kcfg_detectedv4ldevices->addItem(deviceName, path); - if (width > 0) m_configCapture.kcfg_detectedv4ldevices->setItemData(m_configCapture.kcfg_detectedv4ldevices->count() - 1, QString("%1x%2").arg(width).arg(height), Qt::UserRole + 1); + QStringList deviceInfo = v4l.getDeviceName(path); + m_configCapture.kcfg_detectedv4ldevices->addItem(deviceInfo.at(0), path); + m_configCapture.kcfg_detectedv4ldevices->setItemData(m_configCapture.kcfg_detectedv4ldevices->count() - 1, deviceInfo.at(1), Qt::UserRole + 1); } } connect(m_configCapture.kcfg_detectedv4ldevices, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdatev4lDevice())); diff --git a/src/stopmotion/capturehandler.h b/src/stopmotion/capturehandler.h index f43fddae..342a2510 100644 --- a/src/stopmotion/capturehandler.h +++ b/src/stopmotion/capturehandler.h @@ -38,7 +38,7 @@ public: virtual void showOverlay(QImage img, bool transparent = true) = 0; virtual void hideOverlay() = 0; virtual void hidePreview(bool hide) = 0; - virtual QString getDeviceName(QString input, int *width, int *height) = 0; + virtual QStringList getDeviceName(QString input) = 0; static void yuv2rgb(unsigned char *yuv_buffer, unsigned char *rgb_buffer, int width, int height); protected: diff --git a/src/stopmotion/stopmotion.cpp b/src/stopmotion/stopmotion.cpp index e4e89f05..a2485a91 100644 --- a/src/stopmotion/stopmotion.cpp +++ b/src/stopmotion/stopmotion.cpp @@ -191,7 +191,7 @@ StopmotionWidget::StopmotionWidget(KUrl projectFolder, const QList< QAction * > } if (QFile::exists(KdenliveSettings::video4vdevice())) { if (m_bmCapture == NULL) m_bmCapture = new V4lCaptureHandler(m_layout); - capture_device->addItem(m_bmCapture->getDeviceName(KdenliveSettings::video4vdevice(), 0, 0), "v4l"); + capture_device->addItem(m_bmCapture->getDeviceName(KdenliveSettings::video4vdevice()).at(0), "v4l"); } connect(m_bmCapture, SIGNAL(frameSaved(const QString)), this, SLOT(slotNewThumb(const QString))); diff --git a/src/v4l/src.c b/src/v4l/src.c index 96bb64cf..391b121c 100644 --- a/src/v4l/src.c +++ b/src/v4l/src.c @@ -79,10 +79,10 @@ int src_open(src_t *src, char *source) return 0; } -const char *src_query(src_t *src, char *source, int *width, int *height) +const char *src_query(src_t *src, char *source, int *width, int *height, char **pixelformat) { src->source = source; - return src_v4l2.query(src, width, height); + return src_v4l2.query(src, width, height, pixelformat); } int src_close(src_t *src) diff --git a/src/v4l/src.h b/src/v4l/src.h index 011a9519..ae228a4b 100644 --- a/src/v4l/src.h +++ b/src/v4l/src.h @@ -119,7 +119,7 @@ typedef struct { int (*open)(src_t *); int (*close)(src_t *); int (*grab)(src_t *); - const char *(*query)(src_t *, int*, int*); + const char *(*query)(src_t *, int*, int*, char **); } src_mod_t; @@ -207,7 +207,7 @@ typedef struct { extern int src_open(src_t *src, char *source); extern int src_close(src_t *src); extern int src_grab(src_t *src); -extern const char *src_query(src_t *src, char *source, int *width, int *height); +extern const char *src_query(src_t *src, char *source, int *width, int *height, char **pixelformat); extern int src_set_option(src_option_t ***options, char *name, char *value); extern int src_get_option_by_number(src_option_t **opt, int number, char **name, char **value); diff --git a/src/v4l/src_v4l2.c b/src/v4l/src_v4l2.c index 641913f6..6c37abdf 100644 --- a/src/v4l/src_v4l2.c +++ b/src/v4l/src_v4l2.c @@ -802,7 +802,7 @@ int src_v4l2_set_read(src_t *src) return(0); } -static const char *src_v4l2_query(src_t *src, int *width, int *height) +static const char *src_v4l2_query(src_t *src, int *width, int *height, char **pixelformat) { if(!src->source) { @@ -836,10 +836,10 @@ static const char *src_v4l2_query(src_t *src, int *width, int *height) fprintf(stderr, "Cannot get capabilities."); return NULL; } - char * res = (char*) s->cap.card; + char *res = (char*) s->cap.card; if(!s->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) { - width = 0; - height = 0; + *width = 0; + *height = 0; } else { struct v4l2_format format; @@ -851,8 +851,17 @@ static const char *src_v4l2_query(src_t *src, int *width, int *height) else { *width = format.fmt.pix.width; *height = format.fmt.pix.height; - fprintf(stderr, "Size: %d, %d.", width, height); } + struct v4l2_fmtdesc fmt; + memset(&fmt,0,sizeof(fmt)); + fmt.index = 0; + fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + if (ioctl(s->fd, VIDIOC_ENUM_FMT, &fmt) != -1) + { + *pixelformat = fmt.description; + fprintf(stderr, "format: %s", fmt.description); + } + else *pixelformat = ""; } src_v4l2_close(src); return res; diff --git a/src/v4l/v4lcapture.cpp b/src/v4l/v4lcapture.cpp index 013a7c80..c067a3a2 100644 --- a/src/v4l/v4lcapture.cpp +++ b/src/v4l/v4lcapture.cpp @@ -96,7 +96,7 @@ V4lCaptureHandler::V4lCaptureHandler(QVBoxLayout *lay, QWidget *parent): lay->addWidget(m_display); } -QString V4lCaptureHandler::getDeviceName(QString input, int *width, int *height) +QStringList V4lCaptureHandler::getDeviceName(QString input) { fswebcam_config_t *config; /* Prepare the configuration structure. */ @@ -104,7 +104,7 @@ QString V4lCaptureHandler::getDeviceName(QString input, int *width, int *height) if (!config) { /*WARN("Out of memory.");*/ fprintf(stderr, "Out of MEM...."); - return input; + return QStringList() << input; } /* Set the defaults. */ @@ -154,9 +154,13 @@ QString V4lCaptureHandler::getDeviceName(QString input, int *width, int *height) v4lsrc.fps = config->fps; v4lsrc.option = config->option; char *source = config->device; - QString deviceName = src_query(&v4lsrc, source, width, height); - kDebug() << "DEVIE NAME: " << deviceName << "."; - return deviceName.isEmpty() ? input : deviceName; + int width = 0; + int height = 0; + char *pixelformat; + QString deviceName = src_query(&v4lsrc, source, &width, &height, &pixelformat); + QStringList result; + result << (deviceName.isEmpty() ? input : deviceName) << (width == 0 ? QString() : QString("%1x%2").arg(width).arg(height)) << QString(pixelformat); + return result; } void V4lCaptureHandler::startPreview(int /*deviceId*/, int /*captureMode*/, bool) diff --git a/src/v4l/v4lcapture.h b/src/v4l/v4lcapture.h index ffa35b93..464bfa59 100644 --- a/src/v4l/v4lcapture.h +++ b/src/v4l/v4lcapture.h @@ -44,7 +44,7 @@ public: void showOverlay(QImage img, bool transparent = true); void hideOverlay(); void hidePreview(bool hide); - QString getDeviceName(QString input, int *width, int *height); + QStringList getDeviceName(QString input); private: bool m_update; diff --git a/src/wizard.cpp b/src/wizard.cpp index ad6a9e11..c88f9a01 100644 --- a/src/wizard.cpp +++ b/src/wizard.cpp @@ -150,18 +150,14 @@ void Wizard::slotDetectWebcam() // Video 4 Linux device detection V4lCaptureHandler v4l(NULL); - int width = 0; - int height = 0; for (int i = 0; i < 10; i++) { QString path = "/dev/video" + QString::number(i); if (QFile::exists(path)) { - QString deviceName = v4l.getDeviceName(path.toUtf8().constData(), &width, &height); - QString captureSize; - if (width > 0) captureSize = QString::number(width) + "x" + QString::number(height); - if (!deviceName.isEmpty()) { - QTreeWidgetItem *item = new QTreeWidgetItem(m_capture.device_list, QStringList() << deviceName << captureSize); + QStringList deviceInfo = v4l.getDeviceName(path.toUtf8().constData()); + if (!deviceInfo.isEmpty()) { + QTreeWidgetItem *item = new QTreeWidgetItem(m_capture.device_list, QStringList() << deviceInfo.at(0) << "(" + deviceInfo.at(1) + ") " + deviceInfo.at(2)); item->setData(0, Qt::UserRole, path); - if (!captureSize.isEmpty()) item->setData(0, Qt::UserRole + 1, captureSize); + item->setData(0, Qt::UserRole + 1, deviceInfo.at(1)); } } }