-void V4lCaptureHandler::setDevice(const QString input, QString size)
-{
- m_device = input;
- if (!size.isEmpty()) {
- m_width = size.section('x', 0, 0).toInt();
- m_height = size.section('x', -1).toInt();
-
- }
-}
-
-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(m_device.toUtf8().constData());
- config->input = NULL;
- config->tuner = 0;
- config->frequency = 0;
- config->delay = 0;
- config->use_read = 0;
- config->list = 0;
- if (m_width > 0) config->width = m_width;
- else config->width = KdenliveSettings::video4size().section("x", 0, 0).toInt();/*384;*/
- if (m_height > 0) config->height = m_height;
- else 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;
-
- /* 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;
-
- if (src_open(&v4lsrc, source) != 0) return;
- m_update = true;
- free(config);
- QTimer::singleShot(200, this, SLOT(slotUpdate()));
-}
-
-V4lCaptureHandler::~V4lCaptureHandler()
-{
- stopCapture();
-}
-
-void V4lCaptureHandler::slotUpdate()
-{
- if (!m_update) return;
- src_grab(&v4lsrc);
- QImage qimg(v4lsrc.width, v4lsrc.height, QImage::Format_RGB888);
- switch (v4lsrc.palette) {
- case SRC_PAL_PNG:
- qimg = add_image_png(&v4lsrc);
- break;
- case SRC_PAL_JPEG:
- case SRC_PAL_MJPEG:
- qimg = add_image_jpeg(&v4lsrc);
- break;
- case SRC_PAL_S561:
- fswc_add_image_s561(qimg.bits(), (uchar *)v4lsrc.img, v4lsrc.length, v4lsrc.width, v4lsrc.height, v4lsrc.palette);
- break;
- case SRC_PAL_RGB32:
- fswc_add_image_rgb32(&v4lsrc, qimg.bits());
- break;
- case SRC_PAL_BGR32:
- fswc_add_image_bgr32(&v4lsrc, qimg.bits());
- break;
- case SRC_PAL_RGB24:
- fswc_add_image_rgb24(&v4lsrc, qimg.bits());
- break;
- case SRC_PAL_BGR24:
- fswc_add_image_bgr24(&v4lsrc, qimg.bits());
- break;
- case SRC_PAL_BAYER:
- case SRC_PAL_SGBRG8:
- case SRC_PAL_SGRBG8:
- fswc_add_image_bayer(qimg.bits(), (uchar *)v4lsrc.img, v4lsrc.length, v4lsrc.width, v4lsrc.height, v4lsrc.palette);
- break;
- case SRC_PAL_YUYV:
- case SRC_PAL_UYVY:
- fswc_add_image_yuyv(&v4lsrc, (avgbmp_t *)qimg.bits());
- break;
- case SRC_PAL_YUV420P:
- fswc_add_image_yuv420p(&v4lsrc, qimg.bits());
- break;
- case SRC_PAL_NV12MB:
- fswc_add_image_nv12mb(&v4lsrc, qimg.bits());
- break;
- case SRC_PAL_RGB565:
- fswc_add_image_rgb565(&v4lsrc, qimg.bits());
- break;
- case SRC_PAL_RGB555:
- fswc_add_image_rgb555(&v4lsrc, qimg.bits());
- break;
- case SRC_PAL_Y16:
- fswc_add_image_y16(&v4lsrc, qimg.bits());
- break;
- case SRC_PAL_GREY:
- fswc_add_image_grey(&v4lsrc, qimg.bits());
- break;
- }
- if (m_analyseFrame) {
- emit gotFrame(qimg);
- }
- 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(50, 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()
-{
- m_display->setHidden(true);
- if (!m_update) return;
- m_update = false;
- src_close(&v4lsrc);
-}