Пример #1
0
VideoRecorder::VideoRecorder(QDeclarativeItem *parent) :
    QDeclarativeItem(parent)
{
    m_camera = new QCamera(this);
    connect(m_camera, SIGNAL(stateChanged(QCamera::State)), SLOT(cameraStateChanged(QCamera::State)));
    connect(m_camera, SIGNAL(statusChanged(QCamera::Status)), SLOT(cameraStatusChanged(QCamera::Status)));
    connect(m_camera, SIGNAL(error(QCamera::Error)), SLOT(cameraError(QCamera::Error)));

    m_viewFinder = new QGraphicsVideoItem(this);
    m_viewFinder->setAspectRatioMode(Qt::IgnoreAspectRatio);
    m_camera->setViewfinder(m_viewFinder);
    m_camera->setCaptureMode(QCamera::CaptureVideo);

    m_recorder = new QMediaRecorder(m_camera, this);
    connect(m_recorder, SIGNAL(stateChanged(QMediaRecorder::State)), SLOT(recorderStateChanged(QMediaRecorder::State)));
    connect(m_recorder, SIGNAL(error(QMediaRecorder::Error)), SLOT(recorderError(QMediaRecorder::Error)));
    connect(m_recorder, SIGNAL(durationChanged(qint64)), SLOT(videoDurationChanged(qint64)));
}
Пример #2
0
void V4L1Preview::start(unsigned int format, QSize size, int framerate)
{
    Q_UNUSED(format);
    Q_UNUSED(size);
    Q_UNUSED(framerate);

    wc->frames = 0;
    wc->currentFrame = 0;

    if (!wc->open())
        emit cameraError(QtopiaCamera::FatalError, QString("cannot open device"));

    notifier = new QSocketNotifier(wc->fd, QSocketNotifier::Read , this);
    notifier->setEnabled(false);
    connect(notifier, SIGNAL(activated(int)), this, SLOT(captureFrame()));

    struct video_picture pict;
    memset( &pict, 0, sizeof( pict ) );
    ioctl( wc->fd, VIDIOCGPICT, &pict );
    pict.palette = VIDEO_PALETTE_RGB24;
    if ( ioctl( wc->fd, VIDIOCSPICT, &pict ) < 0 ) {
        qWarning( "%s: could not set the picture mode", V4L_VIDEO_DEVICE );
        emit cameraError(QtopiaCamera::FatalError, QString("VIDIOCSPICT"));
        wc->close( );
        return;
    }

    current_format = QtopiaCamera::RGB32;
    // Set the new capture window.
    struct video_window wind;
    memset( &wind, 0, sizeof( wind ) );

    wind.x = 0;
    wind.y = 0;
    wind.width = wc->current_resolution.width();
    wind.height = wc->current_resolution.height();
    if ( ioctl( wc->fd, VIDIOCSWIN, &wind ) < 0 ) {
        emit cameraError(QtopiaCamera::FatalError, QString("could not set the capture window"));
        wc->close();
        return;
    }

    // Enable mmap-based access to the camera.
    memset( &wc->mbuf, 0, sizeof( wc->mbuf ) );
    if ( ioctl( wc->fd, VIDIOCGMBUF, &wc->mbuf ) < 0 ) {
        emit cameraError(QtopiaCamera::FatalError, QString("mmap-based camera access is not available"));
        wc->close( );
        return;
    }

    // Mmap the designated memory region.
    wc->frames = (unsigned char *)mmap( 0, wc->mbuf.size, PROT_READ | PROT_WRITE,
                                    MAP_SHARED, wc->fd, 0 );
    if ( !wc->frames || wc->frames == (unsigned char *)(long)(-1) ) {
        emit cameraError(QtopiaCamera::FatalError, QString("could not mmap the device"));
        wc->close( );
        return;
    }
    preview_buffer_bytesused = wc->mbuf.size;
    startCapture();
    preview_active = true;
}
Пример #3
0
V4L1Preview::V4L1Preview(V4L1Webcam* w) : wc(w)
{
    current_format = QtopiaCamera::RGB32;
    connect(this, SIGNAL(cameraError(QtopiaCamera::CameraError,QString)),
        wc, SIGNAL(cameraError(QtopiaCamera::CameraError,QString)));
}