void ScreenCapture::cleanup()
{
	sleep(2);

	qDebug() << "all done, shutting down...\n";

	_err = CAMERA_EOK;
    if (_doMovie) {
    	_err = camera_stop_video_viewfinder(_handle);

		if (_err != EOK) {
			qDebug() << "error stopping viewfinder: " << strerror(_err) << "\n";
		} else {
			qDebug() << "stopped viewfinder\n";
			_doMovie = false;
		}
    }

	if (_cameraOpen) {
		camera_close(_handle);

		_cameraOpen = false;

		qDebug() << "closed camera: " << _handle << "\n";
	}
}
Ejemplo n.º 2
0
    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);
        }
    }