void ScreenCapture::startViewfinder()
{
	if (_configured) {
		_err = camera_set_videovf_property(_handle,
										  CAMERA_IMGPROP_FORMAT, _vfFrameType,
										  CAMERA_IMGPROP_WIDTH, _vfWidth,
										  CAMERA_IMGPROP_HEIGHT, _vfHeight,
										  CAMERA_IMGPROP_ROTATION, _vfRotationAngle,
										  CAMERA_IMGPROP_FRAMERATE, _vfFrameRate);

		if (_err != EOK) {
			qDebug() << "error configuring viewfinder: " << strerror(_err) << "\n";
		}

		// this should be off for screen capture
		_videoStabilization = 0;

		_err = camera_set_video_property(_handle,
				CAMERA_IMGPROP_WIDTH, _vfWidth,
				CAMERA_IMGPROP_HEIGHT, _vfHeight,
				CAMERA_IMGPROP_STABILIZATION, _videoStabilization);

		if (_err != EOK) {
			qDebug() << "error configuring video stabilization\n";
		}

		// try to start viewfinder
		_err = camera_start_video_viewfinder(_handle,
											&vf_callback,
											&status_callback,
											this);
		if (_err != EOK) {
			qDebug() << "error starting viewfinder: " << strerror(_err) << "\n";
		}

		_doMovie = true;

		qDebug() << "Started video viewfinder successfully\n";
	}
}
    void ActionRecordVideo::executeCameraAction(ExecutionState* state, std::string action,
            std::string cameraUnitString, std::string appendTime, std::string outFile)
    {
        DataModelLogger* RUNLOG = state->getLogger();

        camera_unit_t cameraUnit;
        if (cameraUnitString == "BACK") {
            cameraUnit = CAMERA_UNIT_REAR;
        } else if (cameraUnitString == "FRONT") {
            cameraUnit = CAMERA_UNIT_FRONT;
        } else if (cameraUnitString == "DESKTOP_PRIMARY") {
            cameraUnit = CAMERA_UNIT_DESKTOP;
        } else if (cameraUnitString == "DESKTOP_SECONDARY") {
            cameraUnit = CAMERA_UNIT_SECONDARY_DESKTOP;
        } else {
            LOG->warning(SSTR("Unknown source selected: " << cameraUnitString));
            RUNLOG->error("Unknown source selected");
            return;
        }

        if (action == "START") {
            if (!state->getRuntimeResources()->isCameraOk(
                    state->getRuntimeResources()->setupCamera(cameraUnit, CAMERA_MODE_RW))) {
                LOG->error("Failed to get camera");
                RUNLOG->error("Failed to get camera");
                return;
            }
            camera_handle_t camera = state->getRuntimeResources()->getCamera();
            if (!state->getRuntimeResources()->isCameraOk(
                    _camera_set_videovf_property(camera, CAMERA_IMGPROP_END))) {
                LOG->error("Failed to set video frame properties");
                RUNLOG->error("Failed to set video frame properties");
                return;
            }
            if (!state->getRuntimeResources()->isCameraOk(
                    _camera_set_video_property(camera, CAMERA_IMGPROP_END))) {
                LOG->error("Failed to set video properties");
                RUNLOG->error("Failed to set video properties");
                return;
            }
            state->getRuntimeResources()->callbackReset();
            if (!state->getRuntimeResources()->isCameraOk(
                    camera_start_video_viewfinder(camera, NULL, viewFinderStatusCallback,
                            (void*) state->getRuntimeResources()))) {
                LOG->error("Failed to start video viewfinder");
                RUNLOG->error("Failed to start video viewfinder");
                return;
            }
            if (!state->getRuntimeResources()->callbackWait(5000)) {
                LOG->warning("Timed out waiting for view finder to start");
            }
            std::string filename;
            if (Statement::isValueTrue(appendTime)) {
                filename = state->getRuntimeResources()->uniqueFilename(outFile);
            } else {
                filename = outFile;
            }
            state->setUserProperty("VIDEO_FILENAME", filename);
            state->getRuntimeResources()->callbackReset();
            if (!state->getRuntimeResources()->isCameraOk(
                    camera_start_video(camera, filename.c_str(), NULL, videoRecordingStatusCallback,
                            (void*) state->getRuntimeResources()))) {
                LOG->error("Failed to start video recording");
                RUNLOG->error("Failed to start video recording");
                return;
            }
            if (!state->getRuntimeResources()->callbackWait(5000)) {
                LOG->warning("Timed out waiting for recording to start");
            }
            RUNLOG->debug("Started video recording");
        } else if (action == "STOP") {
            camera_handle_t camera = state->getRuntimeResources()->getCamera();
            if (!state->getRuntimeResources()->isCameraOk(camera_stop_video(camera))) {
                LOG->error("Failed to stop video recording");
                RUNLOG->error("Failed to stop video recording");
                return;
            }
            if (!state->getRuntimeResources()->isCameraOk(camera_stop_video_viewfinder(camera))) {
                LOG->error("Failed to stop video viewfinder");
                RUNLOG->error("Failed to stop video viewfinder");
                return;
            }
            state->getRuntimeResources()->destroyCamera();
            RUNLOG->debug("Stopped video recording");
        } else {
            RUNLOG->error("Unknown action: " + action);
        }
    }