From: Jean-Baptiste Mardelle Date: Sun, 24 Oct 2010 19:36:31 +0000 (+0000) Subject: webcam capture: Try to get webcam name instead of displaying /dev/video0 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=86eab79c8c7e116c56c39c05f8d97058d55c6ad1;p=kdenlive webcam capture: Try to get webcam name instead of displaying /dev/video0 svn path=/trunk/kdenlive/; revision=5043 --- diff --git a/src/blackmagic/capture.cpp b/src/blackmagic/capture.cpp index 03aac813..6aa13cad 100644 --- a/src/blackmagic/capture.cpp +++ b/src/blackmagic/capture.cpp @@ -479,6 +479,11 @@ BmdCaptureHandler::BmdCaptureHandler(QVBoxLayout *lay, QWidget *parent): { } +QString BmdCaptureHandler::getDeviceName(QString) +{ + return QString(); +} + void BmdCaptureHandler::startPreview(int deviceId, int captureMode) { deckLinkIterator = CreateDeckLinkIteratorInstance(); diff --git a/src/blackmagic/capture.h b/src/blackmagic/capture.h index 4ccd5424..dcf68f81 100644 --- a/src/blackmagic/capture.h +++ b/src/blackmagic/capture.h @@ -53,6 +53,7 @@ public: void showOverlay(QImage img, bool transparent = true); void hideOverlay(); void hidePreview(bool hide); + QString getDeviceName(QString); private: IDeckLinkIterator *deckLinkIterator; diff --git a/src/kdenlivesettings.kcfg b/src/kdenlivesettings.kcfg index f7ac5bc1..c7a5bc15 100644 --- a/src/kdenlivesettings.kcfg +++ b/src/kdenlivesettings.kcfg @@ -247,6 +247,11 @@ false + + + 0 + + video4linux2 diff --git a/src/kdenlivesettingsdialog.cpp b/src/kdenlivesettingsdialog.cpp index e4959223..97861f63 100644 --- a/src/kdenlivesettingsdialog.cpp +++ b/src/kdenlivesettingsdialog.cpp @@ -19,6 +19,7 @@ #include "kdenlivesettingsdialog.h" #include "profilesdialog.h" +#include "v4l/v4lcapture.h" #include "blackmagic/devices.h" #include "kdenlivesettings.h" @@ -80,6 +81,18 @@ KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent) : QWidget *p4 = new QWidget; m_configCapture.setupUi(p4); + + V4lCaptureHandler v4l(NULL); + // Video 4 Linux device detection + for (int i = 0; i < 10; i++) { + QString path = "/dev/video" + QString::number(i); + if (QFile::exists(path)) { + m_configCapture.kcfg_detectedv4ldevices->addItem(v4l.getDeviceName(path.toUtf8().constData()), path); + } + } + connect(m_configCapture.kcfg_detectedv4ldevices, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdatev4lDevice())); + + m_page4 = addPage(p4, i18n("Capture"), "media-record"); m_configCapture.tabWidget->setCurrentIndex(KdenliveSettings::defaultcapture()); #ifdef Q_WS_MAC @@ -625,6 +638,11 @@ bool KdenliveSettingsDialog::hasChanged() return KConfigDialog::hasChanged(); } +void KdenliveSettingsDialog::slotUpdatev4lDevice() +{ + QString device = m_configCapture.kcfg_detectedv4ldevices->itemData(m_configCapture.kcfg_detectedv4ldevices->currentIndex()).toString(); + if (!device.isEmpty()) m_configCapture.kcfg_video4vdevice->setText(device); +} #include "kdenlivesettingsdialog.moc" diff --git a/src/kdenlivesettingsdialog.h b/src/kdenlivesettingsdialog.h index 2e265e47..05f01c0c 100644 --- a/src/kdenlivesettingsdialog.h +++ b/src/kdenlivesettingsdialog.h @@ -67,6 +67,7 @@ private slots: void slotDialogModified(); void slotEnableCaptureFolder(); void slotUpdateHDMIModes(); + void slotUpdatev4lDevice(); private: KPageWidgetItem *m_page1; diff --git a/src/stopmotion/capturehandler.h b/src/stopmotion/capturehandler.h index 29deea04..e8b755ba 100644 --- a/src/stopmotion/capturehandler.h +++ b/src/stopmotion/capturehandler.h @@ -38,6 +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) = 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 d6d6786d..40372969 100644 --- a/src/stopmotion/stopmotion.cpp +++ b/src/stopmotion/stopmotion.cpp @@ -182,7 +182,7 @@ StopmotionWidget::StopmotionWidget(KUrl projectFolder, QWidget *parent) : } if (QFile::exists(KdenliveSettings::video4vdevice())) { if (m_bmCapture == NULL) m_bmCapture = new V4lCaptureHandler(m_layout); - capture_device->addItem(KdenliveSettings::video4vdevice(), "v4l"); + capture_device->addItem(m_bmCapture->getDeviceName(KdenliveSettings::video4vdevice()), "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 a6360cd0..7aadb6cd 100644 --- a/src/v4l/src.c +++ b/src/v4l/src.c @@ -53,8 +53,6 @@ src_palette_t src_palette[] = { int src_open(src_t *src, char *source) { int i = 0; - size_t sl; - char *s; struct stat st; if(!source) @@ -62,15 +60,6 @@ int src_open(src_t *src, char *source) fprintf(stderr, "No source was specified......."); return(-1); } - - sl = strlen(source) + 1; - s = malloc(sl); - if(!s) - { - fprintf(stderr, "Out of memory."); - return(-1); - } - src->source = source; i = 0; @@ -90,6 +79,12 @@ int src_open(src_t *src, char *source) return 0; } +const char *src_query(src_t *src, char *source) +{ + src->source = source; + return src_v4l2.query(src); +} + int src_close(src_t *src) { int r; diff --git a/src/v4l/src.h b/src/v4l/src.h index cd259c2e..5f9aba54 100644 --- a/src/v4l/src.h +++ b/src/v4l/src.h @@ -119,6 +119,7 @@ typedef struct { int (*open)(src_t *); int (*close)(src_t *); int (*grab)(src_t *); + const char *(*query)(src_t *); } src_mod_t; @@ -206,6 +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); 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 bc4072e4..56c4dbad 100644 --- a/src/v4l/src_v4l2.c +++ b/src/v4l/src_v4l2.c @@ -82,7 +82,7 @@ int src_v4l2_get_capability(src_t *src) /*ERROR("%s: Not a V4L2 device?", src->source);*/ return(-1); } - + fprintf(stderr, "cap.card: \"%s\"", s->cap.card); /*DEBUG("%s information:", src->source); DEBUG("cap.driver: \"%s\"", s->cap.driver); DEBUG("cap.card: \"%s\"", s->cap.card); @@ -802,6 +802,45 @@ int src_v4l2_set_read(src_t *src) return(0); } +static const char *src_v4l2_query(src_t *src) +{ + if(!src->source) + { + /*ERROR("No device name specified.");*/ + fprintf(stderr, "No device name specified."); + return NULL; + } + src_v4l2_t *s; + + /* Allocate memory for the state structure. */ + s = calloc(sizeof(src_v4l2_t), 1); + if(!s) + { + fprintf(stderr, "Out of memory."); + return NULL; + } + + src->state = (void *) s; + + /* Open the device. */ + s->fd = open(src->source, O_RDWR | O_NONBLOCK); + if(s->fd < 0) + { + fprintf(stderr, "Cannot open device."); + free(s); + return NULL; + } + + if(ioctl(s->fd, VIDIOC_QUERYCAP, &s->cap) < 0) { + src_v4l2_close(src); + fprintf(stderr, "Cannot get capabilities."); + return NULL; + } + char * res = (char*) s->cap.card; + src_v4l2_close(src); + return res; +} + static int src_v4l2_open(src_t *src) { src_v4l2_t *s; @@ -989,7 +1028,8 @@ src_mod_t src_v4l2 = { "v4l2", SRC_TYPE_DEVICE, src_v4l2_open, src_v4l2_close, - src_v4l2_grab + src_v4l2_grab, + src_v4l2_query }; #else /* #ifdef HAVE_V4L2 */ @@ -998,7 +1038,8 @@ src_mod_t src_v4l2 = { "", SRC_TYPE_NONE, NULL, NULL, - NULL + NULL, + NULL }; #endif /* #ifdef HAVE_V4L2 */ diff --git a/src/v4l/v4lcapture.cpp b/src/v4l/v4lcapture.cpp index 09ba96ba..51b1993d 100644 --- a/src/v4l/v4lcapture.cpp +++ b/src/v4l/v4lcapture.cpp @@ -91,10 +91,75 @@ V4lCaptureHandler::V4lCaptureHandler(QVBoxLayout *lay, QWidget *parent): CaptureHandler(lay, parent) , m_update(false) { + if (lay == NULL) return; m_display = new MyDisplay; lay->addWidget(m_display); } +QString V4lCaptureHandler::getDeviceName(QString input) +{ + fswebcam_config_t *config; + /* Prepare the configuration structure. */ + config = (fswebcam_config_t *) calloc(sizeof(fswebcam_config_t), 1); + if (!config) { + /*WARN("Out of memory.");*/ + fprintf(stderr, "Out of MEM...."); + return input; + } + + /* Set the defaults. */ + config->loop = 0; + config->offset = 0; + config->background = 0; + config->pidfile = NULL; + config->logfile = NULL; + config->gmt = 0; + config->start = 0; + config->device = strdup(input.toUtf8().constData()); + config->input = NULL; + config->tuner = 0; + config->frequency = 0; + config->delay = 0; + config->use_read = 0; + config->list = 0; + config->width = 384; + config->height = 288; + config->fps = 0; + config->frames = 1; + config->skipframes = 0; + config->palette = SRC_PAL_ANY; + config->option = NULL; + config->dumpframe = NULL; + config->jobs = 0; + config->job = NULL; + + /* Set defaults and parse the command line. */ + /*if(fswc_getopts(config, argc, argv)) return(-1);*/ + + + /* Record the start time. */ + config->start = time(NULL); + /* Set source options... */ + memset(&v4lsrc, 0, sizeof(v4lsrc)); + v4lsrc.input = config->input; + v4lsrc.tuner = config->tuner; + v4lsrc.frequency = config->frequency; + v4lsrc.delay = config->delay; + v4lsrc.timeout = 10; /* seconds */ + v4lsrc.use_read = config->use_read; + v4lsrc.list = config->list; + v4lsrc.palette = config->palette; + v4lsrc.width = config->width; + v4lsrc.height = config->height; + v4lsrc.fps = config->fps; + v4lsrc.option = config->option; + char *source = config->device; + + QString deviceName = src_query(&v4lsrc, source); + kDebug() << "DEVIE NAME: " << deviceName << "."; + return deviceName.isEmpty() ? input : deviceName; +} + void V4lCaptureHandler::startPreview(int /*deviceId*/, int /*captureMode*/) { m_display->setHidden(false); diff --git a/src/v4l/v4lcapture.h b/src/v4l/v4lcapture.h index 36bf28d0..bbcbf883 100644 --- a/src/v4l/v4lcapture.h +++ b/src/v4l/v4lcapture.h @@ -44,6 +44,7 @@ public: void showOverlay(QImage img, bool transparent = true); void hideOverlay(); void hidePreview(bool hide); + QString getDeviceName(QString input); private: bool m_update; diff --git a/src/widgets/configcapture_ui.ui b/src/widgets/configcapture_ui.ui index 66bc1530..b8657a80 100644 --- a/src/widgets/configcapture_ui.ui +++ b/src/widgets/configcapture_ui.ui @@ -175,7 +175,7 @@ Video4Linux - + Video @@ -262,7 +262,7 @@ - + Audio @@ -315,7 +315,7 @@ - + Container @@ -344,7 +344,7 @@ - + @@ -357,7 +357,7 @@ - + @@ -367,7 +367,7 @@ - + @@ -380,10 +380,10 @@ - + - + Qt::Vertical @@ -396,6 +396,22 @@ + + + + + Select device in list + + + + + + + + Detected devices + + +