Beispiel #1
0
MmalVideoCamera::MmalVideoCamera(int imageWidth, int imageHeight, int frameRate) :
	m_imageWidth(imageWidth),
	m_imageHeight(imageHeight),
	m_frameRate(frameRate),
	m_imagePreviewWidth(VCOS_ALIGN_UP(imageWidth, 32)),
	m_imagePreviewHeight(VCOS_ALIGN_UP(imageHeight, 16)),
	m_callbackData(NULL),
	m_cs(),
	m_camera(NULL),
	m_pool(NULL),
	m_videoPort(NULL),
	m_stillPort(NULL),
	m_previewPort(NULL),
	m_videoPortEnabled(false)
{
	std::cout << "Creating callback data..." << std::endl;

	m_callbackData = new MmalVideoCallbackData(m_imageWidth, m_imageHeight, 3);

	std::cout << "Creating camera..." << std::endl;

	createCameraComponent();

	std::cout << "Created camera" << std::endl;

	std::cout << "Target Image Width: " << m_imageWidth << std::endl;
	std::cout << "Target Image Height: " << m_imageHeight << std::endl;

	createBufferPool();

	std::cout << "Initialized camera" << std::endl;
}
/**
 * Start the streaming of buffers in a video device
 *
 * This called is allowed in the following states:
 * - CONFIGURED
 * - PREPARED
 *
 * If the current state is PREPARED then we create the active
 * buffer pool and we activate it.
 * In case we are in state POPULATED we only need to re-activate it (i.e. enqueu
 * again the buffers to the device)
 *
 * Finally call the stream on IOCTL
 *
 * \param buffer_count size of the active buffer pool
 * \param initial_skips number of frames that will be marked as corrupted when
 * we start grabbing frames from the device.
 *
 */
int V4L2VideoNode::start(int buffer_count, int initial_skips)
{
    LOG1("@%s, device = %s", __FUNCTION__, mName.string());
    int ret(0);

    if ((mState != DEVICE_POPULATED) &&
        (mState != DEVICE_PREPARED)) {
        ALOGE("%s: Invalid state to start %d", __FUNCTION__, mState);
        return -1;
    }

    if (mBufferPool.isEmpty()) {
        ret = createBufferPool(buffer_count);
        if (ret < 0) {
            destroyBufferPool();
            return ret;
        }
    }

    //Qbuf
    ret = activateBufferPool();
    if (ret < 0)
        return ret;

    //stream on
    enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    ret = ioctl(mFd, VIDIOC_STREAMON, &type);
    if (ret < 0) {
        ALOGE("VIDIOC_STREAMON returned: %d (%s)", ret, strerror(errno));
        return ret;
    }

    mFrameCounter = 0;
    mState = DEVICE_STARTED;
    mInitialSkips = initial_skips;

    PERFORMANCE_TRACES_BREAKDOWN_STEP_PARAM("DeviceId:", mDeviceId);
    return ret;
}