EdsError Camera::requestOpenSession(const Settings &settings) { if (mHasOpenSession) { return EDS_ERR_SESSION_ALREADY_OPEN; } EdsError error = EdsOpenSession(mCamera); if (error != EDS_ERR_OK) { std::cerr << "ERROR - failed to open camera session" << std::endl; return error; } mHasOpenSession = true; mShouldKeepAlive = settings.getShouldKeepAlive(); EdsUInt32 saveTo = settings.getPictureSaveLocation(); error = EdsSetPropertyData(mCamera, kEdsPropID_SaveTo, 0, sizeof(saveTo) , &saveTo); if (error != EDS_ERR_OK) { std::cerr << "ERROR - failed to set save destination host/device" << std::endl; return error; } //UI lock if (error == EDS_ERR_OK) { error = EdsSendStatusCommand(mCamera, kEdsCameraStatusCommand_UILock, 0); } if (error == EDS_ERR_OK) { mIsLocked = true; } if (saveTo == kEdsSaveTo_Host) { // ??? - requires UI lock? EdsCapacity capacity = {0x7FFFFFFF, 0x1000, 1}; error = EdsSetCapacity(mCamera, capacity); if (error != EDS_ERR_OK) { std::cerr << "ERROR - failed to set capacity of host" << std::endl; return error; } } //It releases it when locked if (mIsLocked) { EdsSendStatusCommand(mCamera, kEdsCameraStatusCommand_UIUnLock, 0); } return EDS_ERR_OK; }
bool CanonTaskOpenSession::execute() { if(canon->isLegacy()) { RX_ERROR("We did not implement and tested the canon video capture implementation for legacy devices (<30D)"); ::exit(EXIT_FAILURE); } if(canon->getState() != Canon::STATE_NONE) { RX_ERROR("The device hasn't been opened so we cannot open the session either"); return false; } EdsError err = EdsOpenSession(canon->getCameraRef()); if(err != EDS_ERR_OK) { CANON_ERROR(err); return false; } EdsUInt32 save_to = kEdsSaveTo_Host; err = EdsSetPropertyData(canon->getCameraRef(), kEdsPropID_SaveTo, 0, sizeof(save_to), &save_to); if(err != EDS_ERR_OK) { CANON_ERROR(err); return false; } if(!canon->lockUI()) { return false; } EdsCapacity capacity = {0x7FFFFFFF, 0x1000, 1}; err = EdsSetCapacity(canon->getCameraRef(), capacity); if(err != EDS_ERR_OK) { CANON_ERROR(err); return false; } if(!canon->unlockUI()) { return false; } canon->setStateOpened(); return true; }
bool Controller::setPropertyCommand( int property, int newValue, int parameter ) { if( camera->handle() == 0 ) { return( false ); } /* * Check camera model to ensure the new value is different * from the current value. */ bool done = false; switch( property ) { case kEdsPropID_AEModeSelect: done = (newValue == camera->getShootingMode()); break; case kEdsPropID_Av: done = (newValue == camera->getAv()); break; case kEdsPropID_Tv: done = (newValue == camera->getTv()); break; case kEdsPropID_ISOSpeed: done = (newValue == camera->getISO()); break; case kEdsPropID_MeteringMode: done = (newValue == camera->getMeteringMode()); break; case kEdsPropID_DriveMode: done = (newValue == camera->getDriveMode()); break; case kEdsPropID_AFMode: done = (newValue == camera->getAFMode()); break; case kEdsPropID_WhiteBalance: done = (newValue == camera->getWhiteBalance()); break; case kEdsPropID_ColorSpace: done = (newValue == camera->getColorSpace()); break; case kEdsPropID_PictureStyle: done = (newValue == camera->getPictureStyle()); break; case kEdsPropID_ImageQuality: done = (newValue == camera->getImageQuality()); break; case kEdsPropID_Evf_Zoom: done = (newValue == camera->getEvfZoom()); break; case kEdsPropID_Evf_AFMode: done = (newValue == camera->getEvfAFMode()); break; case kEdsPropID_Evf_DepthOfFieldPreview: done = (newValue == camera->getEvfDepthOfFieldPreview()); break; case kEdsPropID_ExposureCompensation: done = (newValue == camera->getExposureComp()); break; case kEdsPropID_SaveTo: done = (newValue == camera->getSaveTo()); break; case kEdsPropID_CFn: switch( parameter ) { case CFn_ExposureLevelIncrements: done = (newValue == camera->getExposureLevelIncrements()); break; case CFn_FlashSyncSpeedInAvMode: done = (newValue == camera->getFlashSyncSpeedInAvMode()); break; case CFn_LongExposureNoiseReduction: done = (newValue == camera->getLongExposureNoiseReduction()); break; case CFn_HighISOSpeedNoiseReduction: done = (newValue == camera->getHighISOSpeedNoiseReduction()); break; case CFn_AutoFocusAssistBeamFiring: done = (newValue == camera->getAutoFocusAssistBeamFiring()); break; case CFn_MirrorLockup: done = (newValue == camera->getMirrorLockup()); break; case CFn_ShutterAELockButton: done = (newValue == camera->getShutterAELockButton()); break; } break; default: emit eventReport( new Event( Event::SetPropertyUnhandled, property ) ); return( false ); } if( done ) { return( true ); } int result = EDS_ERR_OK; /* * Retry if camera device is busy. */ do { /* * Send the command to the camera. */ result = EdsSetPropertyData( camera->handle(), property, parameter, sizeof(newValue), &newValue ); /* * Commands are not accepted for a while when depth * of field preview has been released. */ if( (result == EDS_ERR_OK) && (property == kEdsPropID_Evf_DepthOfFieldPreview) ) { Sleep( 500 ); // milliseconds } /* * If retry is required, the camera may become unstable if multiple * commands are issued in succession without an intervening interval. * So, put a delay in before command is reissued. */ if( result == EDS_ERR_DEVICE_BUSY ) { emit eventReport( new Event( Event::CameraBusy, 0, QString( "setProperty" ) ) ); QCoreApplication::processEvents(); Sleep( 500 ); // milliseconds } } while( result == EDS_ERR_DEVICE_BUSY ); if( result != EDS_ERR_OK ) { emit eventReport( new Event( Event::SetPropertyFailure, property, "setProperty" ) ); return( false ); } /* * Set the capacity of the computer (false values are used). * * typedef struct * { * EdsInt32 numberOfFreeClusters; * EdsInt32 bytesPerSector; * EdsBool reset; * } EdsCapacity; */ if( (result == EDS_ERR_OK) && (property == kEdsPropID_SaveTo) && ((newValue == kEdsSaveTo_Host) || (newValue == kEdsSaveTo_Both)) ) { EdsCapacity capacity = {0x7FFFFFFF, 0x1000, 1}; result = EdsSetCapacity( camera->handle(), capacity ); } /* * Update the camera model. */ if( result == EDS_ERR_OK ) { switch( property ) { case kEdsPropID_AEModeSelect: camera->setShootingMode( newValue ); break; case kEdsPropID_Av: camera->setAv( newValue ); break; case kEdsPropID_Tv: camera->setTv( newValue ); break; case kEdsPropID_ISOSpeed: camera->setISO( newValue ); break; case kEdsPropID_MeteringMode: camera->setMeteringMode( newValue ); break; case kEdsPropID_DriveMode: camera->setDriveMode( newValue ); break; case kEdsPropID_AFMode: camera->setAFMode( newValue ); break; case kEdsPropID_WhiteBalance: camera->setWhiteBalance( newValue ); break; case kEdsPropID_ColorSpace: camera->setColorSpace( newValue ); break; case kEdsPropID_PictureStyle: camera->setPictureStyle( newValue ); break; case kEdsPropID_ImageQuality: camera->setImageQuality( newValue ); break; case kEdsPropID_Evf_Zoom: camera->setEvfZoom( newValue ); break; case kEdsPropID_Evf_AFMode: camera->setEvfAFMode( newValue ); break; case kEdsPropID_Evf_DepthOfFieldPreview: camera->setEvfDepthOfFieldPreview( newValue ); break; case kEdsPropID_ExposureCompensation: camera->setExposureComp( newValue ); break; case kEdsPropID_SaveTo: camera->setSaveTo( newValue ); break; case kEdsPropID_CFn: switch( parameter ) { case CFn_ExposureLevelIncrements: camera->setExposureLevelIncrements( newValue ); break; case CFn_FlashSyncSpeedInAvMode: camera->setFlashSyncSpeedInAvMode( newValue ); break; case CFn_LongExposureNoiseReduction: camera->setLongExposureNoiseReduction( newValue ); break; case CFn_HighISOSpeedNoiseReduction: camera->setHighISOSpeedNoiseReduction( newValue ); break; case CFn_AutoFocusAssistBeamFiring: camera->setAutoFocusAssistBeamFiring( newValue ); break; case CFn_MirrorLockup: camera->setMirrorLockup( newValue ); break; case CFn_ShutterAELockButton: camera->setShutterAELockButton( newValue ); break; } break; } } return( true ); }
void Camera::captureLoop() { if(liveViewReady) { if(Eds::DownloadEvfData(camera, *liveBufferBack)) { lock(); fps.tick(); bytesPerFrame = ofLerp(bytesPerFrame, liveBufferBack->size(), .01); swap(liveBufferBack, liveBufferMiddle.back()); liveBufferMiddle.push(); unlock(); } } if(needToTakePhoto) { try { if (shootNoCard) { EdsUInt32 saveTo = kEdsSaveTo_Host; EdsSetPropertyData(camera, kEdsPropID_SaveTo, 0, sizeof(saveTo), &saveTo); EdsCapacity maxCapacity = {0x7FFFFFFF, 0x1000, 1}; EdsSetCapacity(camera, maxCapacity ); } else { EdsUInt32 saveTo = kEdsSaveTo_Camera; EdsSetPropertyData(camera, kEdsPropID_SaveTo, 0, sizeof(saveTo), &saveTo); } Eds::SendCommand(camera, kEdsCameraCommand_TakePicture, 0); lock(); needToTakePhoto = false; unlock(); //ofSendMessage("test"); } catch (Eds::Exception& e) { ofLogError() << "Error while taking a picture: " << e.what(); //ofSendMessage("Error: " + ofToString(e.what())); } } if(needToStartRecording) { try { EdsUInt32 saveTo = kEdsSaveTo_Camera; EdsSetPropertyData(camera, kEdsPropID_SaveTo, 0, sizeof(saveTo) , &saveTo); EdsUInt32 record_start = 4; // Begin movie shooting EdsSetPropertyData(camera, kEdsPropID_Record, 0, sizeof(record_start), &record_start); lock(); needToStartRecording = false; unlock(); } catch (Eds::Exception& e) { ofLogError() << "Error while beginning to record: " << e.what(); } } if(needToStopRecording) { try { EdsUInt32 record_stop = 0; // End movie shooting EdsSetPropertyData(camera, kEdsPropID_Record, 0, sizeof(record_stop), &record_stop); lock(); needToStopRecording = false; unlock(); } catch (Eds::Exception& e) { ofLogError() << "Error while stopping to record: " << e.what(); } } if(needToSendKeepAlive) { try { // always causes EDS_ERR_DEVICE_BUSY, even with live view disabled or a delay // but if it's not here, then the camera shuts down after 5 minutes. Eds::SendStatusCommand(camera, kEdsCameraCommand_ExtendShutDownTimer, 0); } catch (Eds::Exception& e) { ofLogError() << "Error while sending kEdsCameraCommand_ExtendShutDownTimer with Eds::SendStatusCommand: " << e.what(); } lock(); needToSendKeepAlive = false; unlock(); } if(needToDownloadImage) { try { EdsDirectoryItemInfo dirItemInfo = Eds::DownloadImage(directoryItem, photoBuffer); ofLogVerbose() << "Downloaded item: " << (int) (photoBuffer.size() / 1024) << " KB"; lock(); photoDataReady = true; needToDecodePhoto = true; needToUpdatePhoto = true; needToDownloadImage = false; if (dirItemInfo.format == OFX_EDSDK_JPG_FORMAT) { photoNew = true; } else if (dirItemInfo.format == OFX_EDSDK_MOV_FORMAT) { movieNew = true; } unlock(); } catch (Eds::Exception& e) { ofLogError() << "Error while downloading item: " << e.what(); } } float timeSinceLastReset = ofGetElapsedTimef() - lastResetTime; if(timeSinceLastReset > resetIntervalMinutes * 60) { resetLiveView(); } }
boolean connectToFirstCamera(){ EdsError err = EDS_ERR_OK; // Initialize SDK err = EdsInitializeSDK(); if ( err == EDS_ERR_OK ) isSDKLoaded = true; /* // Get first camera if(err == EDS_ERR_OK) { err = getFirstCamera(); }*/ EdsCameraListRef cameraList = NULL; EdsUInt32 count = 0; // Get camera list err = EdsGetCameraList(&cameraList); // Get number of cameras if(err == EDS_ERR_OK) { err = EdsGetChildCount(cameraList, &count); if(count == 0) { err = EDS_ERR_DEVICE_NOT_FOUND; } } // Get first camera retrieved if(err == EDS_ERR_OK) { err = EdsGetChildAtIndex(cameraList , 0 , &camera); } // Release camera list if(cameraList != NULL) { EdsRelease(cameraList); cameraList = NULL; } //Open Session if(err == EDS_ERR_OK) { err = EdsOpenSession(camera); } //Set save to host if (err == EDS_ERR_OK ) { EdsUInt32 wkSaveTo = kEdsSaveTo_Host ; do { err = EdsSetPropertyData ( camera, kEdsPropID_SaveTo, 0, 4, (void*)&wkSaveTo ) ; if (err != EDS_ERR_OK) { std::cout << "warning: camera busy, waiting..." << std::endl; std::flush(std::cout); Sleep(100); } } while (err != EDS_ERR_OK); } // Set host capacity EdsCapacity capacity = {0x7FFFFFFF, 0x1000, 1}; err = EdsSetCapacity ( camera, capacity ); return err == EDS_ERR_OK; }