]> git.sesse.net Git - kdenlive/blobdiff - src/v4l/v4lcapture.cpp
Complete rewrite of the video4linux capture to use MLT, in progress.
[kdenlive] / src / v4l / v4lcapture.cpp
index 8ede6e3fc426254256af8fd1ffb1c7fa56fb98e4..530fe8143eae704540a38eea25237b8009852442 100644 (file)
 #include "kdenlivesettings.h"
 
 
-static src_t v4lsrc;
-
-class MyDisplay : public QLabel
-{
-public:
-    MyDisplay(QWidget *parent = 0);
-    void setImage(QImage img);
-    virtual void paintEvent(QPaintEvent *);
-    virtual void resizeEvent(QResizeEvent *);
-
-private:
-    QImage m_img;
-    bool m_clear;
-};
-
-MyDisplay::MyDisplay(QWidget *parent):
-    QLabel(parent)
-    , m_clear(false)
+V4lCaptureHandler::V4lCaptureHandler()
 {
-    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
-    setAttribute(Qt::WA_PaintOnScreen);
-    setAttribute(Qt::WA_OpaquePaintEvent);
 }
 
-void MyDisplay::resizeEvent(QResizeEvent *)
-{
-    m_clear = true;
-}
+//static
 
-void MyDisplay::paintEvent(QPaintEvent *)
+QStringList V4lCaptureHandler::getDeviceName(QString input)
 {
-    QPainter p(this);
-    if (m_clear) {
-        // widget resized, cleanup
-        p.fillRect(0, 0, width(), height(), palette().background());
-        m_clear = false;
-    }
-    if (m_img.isNull()) return;
-    QImage img = m_img.scaled(width(), height(), Qt::KeepAspectRatio);
-    p.drawImage((width() - img.width()) / 2, (height() - img.height()) / 2, img);
-    p.end();
-}
-
-void MyDisplay::setImage(QImage img)
-{
-    m_img = img;
-    update();
-}
-
-
-
-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*/, bool)
-{
-    m_display->setHidden(false);
-    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;
-    }
-
-    /* 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(KdenliveSettings::video4vdevice().toUtf8().constData());
-    config->input = NULL;
-    config->tuner = 0;
-    config->frequency = 0;
-    config->delay = 0;
-    config->use_read = 0;
-    config->list = 0;
-    config->width = KdenliveSettings::video4size().section("x", 0, 0).toInt();/*384;*/
-    config->height = KdenliveSettings::video4size().section("x", -1).toInt();/*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;
+    src_t v4lsrc;
 
-    /* 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.input      = NULL;
+    v4lsrc.tuner      = 0;
+    v4lsrc.frequency  = 0;
+    v4lsrc.delay      = 0;
     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;
-
-    if (src_open(&v4lsrc, source) != 0) return;
-    m_update = true;
-    QTimer::singleShot(200, this, SLOT(slotUpdate()));
-}
-
-V4lCaptureHandler::~V4lCaptureHandler()
-{
-    stopCapture();
+    v4lsrc.use_read   = 0;
+    v4lsrc.list       = 0;
+    v4lsrc.palette    = SRC_PAL_ANY;
+    v4lsrc.width      = 384;
+    v4lsrc.height     = 288;
+    v4lsrc.fps        = 0;
+    v4lsrc.option     = NULL;
+    v4lsrc.source     = strdup(input.toUtf8().constData());
+    char *pixelformatdescription;
+    pixelformatdescription = (char *) calloc(2048, sizeof(char));
+    QString deviceName(query_v4ldevice(&v4lsrc, &pixelformatdescription));
+    QString info(pixelformatdescription);
+    free (pixelformatdescription);
+    QStringList result;
+    result << (deviceName.isEmpty() ? input : deviceName) << info;
+    return result;
 }
 
-void V4lCaptureHandler::slotUpdate()
-{
-    if (!m_update) return;
-    src_grab(&v4lsrc);
-    uint8_t *img = (uint8_t *) v4lsrc.img;
-    uint32_t i = v4lsrc.width * v4lsrc.height;
-
-    if (v4lsrc.length << 2 < i) return;
 
-    QImage qimg(v4lsrc.width, v4lsrc.height, QImage::Format_RGB32);
-    //Format_ARGB32_Premultiplied
-    //convert from uyvy422 to rgba
-    CaptureHandler::yuv2rgb((uchar *)img, (uchar *)qimg.bits(), v4lsrc.width, v4lsrc.height);
-    if (!m_captureFramePath.isEmpty()) {
-        qimg.save(m_captureFramePath);
-        emit frameSaved(m_captureFramePath);
-        m_captureFramePath.clear();
-    }
-    if (!m_overlayImage.isNull()) {
-        // overlay image
-        QPainter p(&qimg);
-        p.setOpacity(0.5);
-        p.drawImage(0, 0, m_overlayImage);
-        p.end();
-    }
-    m_display->setImage(qimg);
-    if (m_update) QTimer::singleShot(200, this, SLOT(slotUpdate()));
-}
-
-void V4lCaptureHandler::startCapture(const QString &/*path*/)
-{
-}
-
-void V4lCaptureHandler::stopCapture()
-{
-}
 
-void V4lCaptureHandler::captureFrame(const QString &fname)
-{
-    m_captureFramePath = fname;
-}
-
-void V4lCaptureHandler::showOverlay(QImage img, bool /*transparent*/)
-{
-    m_overlayImage = img;
-}
-
-void V4lCaptureHandler::hideOverlay()
-{
-    m_overlayImage = QImage();
-}
-
-void V4lCaptureHandler::hidePreview(bool hide)
-{
-    m_display->setHidden(hide);
-}
-
-void V4lCaptureHandler::stopPreview()
-{
-    if (!m_update) return;
-    m_update = false;
-    src_close(&v4lsrc);
-}