bool CanonTaskDownload::execute() {
  if(canon->isLegacy()) {
    canon->lockUI();
  }

  EdsError err = EDS_ERR_OK;
  EdsStreamRef stream = NULL;
  EdsDirectoryItemInfo dir_item_info;
  bool result = true;
  
  err = EdsGetDirectoryItemInfo(item, &dir_item_info);
  if(err != EDS_ERR_OK) {
    CANON_ERROR(err);
    result = false;
    goto done;
  }

  err = EdsCreateFileStream(dir_item_info.szFileName, kEdsFileCreateDisposition_CreateAlways, kEdsAccess_ReadWrite, &stream);
  if(err != EDS_ERR_OK) {
    CANON_ERROR(err);
    result = false;
    goto done;
  }

  err = EdsSetProgressCallback(stream, canon_download_progress, kEdsProgressOption_Periodically, (EdsVoid*) this);
  if(err != EDS_ERR_OK) {
    CANON_ERROR(err);
    result = false;
    goto done;
  }

  err = EdsDownload(item, dir_item_info.size, stream);
  if(err == EDS_ERR_OK) {
    err = EdsDownloadComplete(item);
    if(err != EDS_ERR_OK) {
      CANON_ERROR(err);
      result = false;
      goto done;
    }
  }
  else {
    CANON_ERROR(err);
  }

 done:
  if(canon->isLegacy()) {
    canon->unlockUI();
  }

  if(stream) {
    EdsRelease(stream);
    stream = NULL;
  }
  return result;
}
Exemplo n.º 2
0
EdsError downloadImage(EdsDirectoryItemRef directoryItem, char* filename)
{
	EdsError err = EDS_ERR_OK;
	EdsStreamRef stream = NULL;
	// Get directory item information
	EdsDirectoryItemInfo dirItemInfo;
	err = EdsGetDirectoryItemInfo(directoryItem, & dirItemInfo);
	//printf("err EdsGetDirectoryItemInfo: %d\n", err);
	// Create file stream for transfer destination
	if(err == EDS_ERR_OK)
	{
		err = EdsCreateFileStream( theFileName,
			kEdsFileCreateDisposition_CreateAlways,
			kEdsAccess_ReadWrite, &stream);
	   //printf("err EdsCreateFileStream: %X\n", err);
	}
	// Download image
	if(err == EDS_ERR_OK)
	{
		err = EdsDownload( directoryItem, dirItemInfo.size, stream);
	//printf("err EdsDownload: %d\n", err);

	}
	// Issue notification that download is complete
	char* buf = NULL;
	if(err == EDS_ERR_OK)
	{
		err = EdsDownloadComplete(directoryItem);
		//printf("err EdsDownloadComplete: %d\n", err);
		buf = new char [strlen(theFileName)+1];
		strcpy_s(buf, strlen(theFileName)+1, theFileName);
		theFileName[0] = '\0';
	}
	// Release stream
	if( stream != NULL)
	{
		EdsRelease(stream);
		stream = NULL;
	}
	pictureProgress = CAMERA_COMPLETE;
	resetPictureTaking();

	// Notify done downloading
	if (buf) {
		/*std::cout << "snapped " << buf << std::endl;
		std::flush(std::cout);*/
		delete [] buf; buf = NULL;
	}
	return err;
}
    //---------------------------------------------------------------------
    bool CanonCameraWrapper::downloadImage(EdsDirectoryItemRef directoryItem){
        if( !downloadEnabled ) return false;

        EdsError err = EDS_ERR_OK;
        EdsStreamRef stream = NULL;
        EdsDirectoryItemInfo dirItemInfo;

        bool success = false;
        string imageName;
        string imagePath;

        int timeStart = ofGetElapsedTimeMillis();

        err = EdsGetDirectoryItemInfo(directoryItem, &dirItemInfo);
        if(err == EDS_ERR_OK){

            imageName = dirItemInfo.szFileName;
            imagePath = downloadPath + imageName;

            printf("Downloading image %s to %s\n", imageName.c_str(), imagePath.c_str());
            err = EdsCreateFileStream( ofToDataPath( imagePath ).c_str(), kEdsFileCreateDisposition_CreateAlways, kEdsAccess_ReadWrite, &stream);
        }

        if(err == EDS_ERR_OK){
            err = EdsDownload( directoryItem, dirItemInfo.size, stream);
        }

        if(err == EDS_ERR_OK){

            lastImageName = imageName;
            lastImagePath = imagePath;

            printf("Image downloaded in %ims\n", ofGetElapsedTimeMillis()-timeStart);

            err = EdsDownloadComplete(directoryItem);
            if( bDeleteAfterDownload ){
                printf("Image deleted\n");
                EdsDeleteDirectoryItem(directoryItem);
            }
            success = true;
        }

        easyRelease(stream);

		if (success)
			evtImageDownloaded.notify(this, getLastImagePath());

        return success;
    }
    //---------------------------------------------------------------------
    bool CanonCameraWrapper::saveImageFromLiveView(string saveName){
        EdsError err                = EDS_ERR_OK;
        EdsEvfImageRef evfImage     = NULL;
		EdsStreamRef stream         = NULL;

		if( evfMode == 0 ){
            printf("Live view needs to be enabled first\n");
            return false;
		}

        //save the file stream to disk
		err = EdsCreateFileStream( ( ofToDataPath(saveName) ).c_str(), kEdsFileCreateDisposition_CreateAlways, kEdsAccess_ReadWrite, &stream);

		// Create EvfImageRef.
		if (err == EDS_ERR_OK){
			err = EdsCreateEvfImageRef(stream, &evfImage);
		}

		// Download live view image data.
		if (err == EDS_ERR_OK){
			err = EdsDownloadEvfImage(theCamera, evfImage);
		}

        if (err == EDS_ERR_OK){
            printf("Got live view frame %i \n", liveViewCurrentFrame);
            liveViewCurrentFrame++;
        }

        easyRelease(stream);
        easyRelease(evfImage);

		//Notification of error
		if(err != EDS_ERR_OK){
			if(err == EDS_ERR_OBJECT_NOTREADY){
			    printf("saveImageFromLiveView - not ready\n");
			}else if(err == EDS_ERR_DEVICE_BUSY){
                printf("saveImageFromLiveView - device is busy\n");
			}
            else{
                printf("saveImageFromLiveView - some other error\n");
            }
            return false;
		}

		return true;
    }
 void Camera::requestDownloadFile(const CameraFileRef& file, const QDir& destinationFolderPath, const std::function<void(EdsError error, QString outputFilePath)>& callback) {
     // check if destination exists and create if not
     if ( !destinationFolderPath.exists() ) {
         bool status = destinationFolderPath.mkpath(".");
         if (!status) {
             std::cerr << "ERROR - failed to create destination folder path '" << destinationFolderPath.dirName().toStdString() << "'" << std::endl;
             return callback(EDS_ERR_INTERNAL_ERROR, NULL);
         }
     }
     
     QString filePath = destinationFolderPath.filePath(QString::fromStdString(file->getName()));
     
     EdsStreamRef stream = NULL;
     EdsError error = EdsCreateFileStream(filePath.toStdString().c_str(), kEdsFileCreateDisposition_CreateAlways, kEdsAccess_ReadWrite, &stream);
     if (error != EDS_ERR_OK) {
         std::cerr << "ERROR - failed to create file stream" << std::endl;
         goto download_cleanup;
     }
     
     error = EdsDownload(file->mDirectoryItem, file->getSize(), stream);
     if (error != EDS_ERR_OK) {
         std::cerr << "ERROR - failed to download" << std::endl;
         goto download_cleanup;
     }
     
     error = EdsDownloadComplete(file->mDirectoryItem);
     if (error != EDS_ERR_OK) {
         std::cerr << "ERROR - failed to mark download as complete" << std::endl;
         goto download_cleanup;
     }
     
 download_cleanup:
     if (stream) {
         EdsRelease(stream);
     }
     
     callback(error, filePath);
 }