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
int getNumberOfImages_sub(EdsDirectoryItemRef directoryItem) {

	EdsUInt32 numChildren;
	EdsGetChildCount(directoryItem, &numChildren);
	EdsDirectoryItemInfo directoryItemInfo;
	EdsGetDirectoryItemInfo(directoryItem, &directoryItemInfo);
	int numFiles = 0;
	EdsDirectoryItemRef childItem;
	EdsDirectoryItemInfo childItemInfo;
	for (int iter = 0; iter < numChildren; ++iter) {
		EdsGetChildAtIndex(directoryItem, iter, &childItem);
		EdsGetDirectoryItemInfo(childItem, &childItemInfo);
		if (childItemInfo.isFolder == true) {
			numFiles += getNumberOfImages_sub(childItem);
		} else {
			++numFiles;
		}
		EdsRelease(childItem);
	}
	return numFiles;
}
 CameraFile::CameraFile(const EdsDirectoryItemRef& directoryItem) {
     if (!directoryItem) {
         throw std::runtime_error("");
     }
     
     EdsRetain(directoryItem);
     mDirectoryItem = directoryItem;
     
     EdsError error = EdsGetDirectoryItemInfo(mDirectoryItem, &mDirectoryItemInfo);
     if (error != EDS_ERR_OK) {
         std::cerr << "ERROR - failed to get directory item info" << std::endl;
         throw std::runtime_error("ERROR - failed to get directory item info");
     }
 }
Exemplo n.º 4
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::downloadLastImage(){
        preCommand();

        EdsVolumeRef 		theVolumeRef	    = NULL ;
        EdsDirectoryItemRef	dirItemRef_DCIM	    = NULL;
        EdsDirectoryItemRef	dirItemRef_Sub	    = NULL;
        EdsDirectoryItemRef	dirItemRef_Image    = NULL;

        EdsDirectoryItemInfo dirItemInfo_Image;

        EdsError err    = EDS_ERR_OK;
        EdsUInt32 Count = 0;
        bool success    = false;

        //get the number of memory devices
        err = EdsGetChildCount( theCamera, &Count );
        if( Count == 0 ){
            printf("Memory device not found\n");
            err = EDS_ERR_DEVICE_NOT_FOUND;
            return false;
        }

        // Download Card No.0 contents
        err = EdsGetChildAtIndex( theCamera, 0, &theVolumeRef );
//        if ( err == EDS_ERR_OK ){
//            printf("getting volume info\n");
//            //err = EdsGetVolumeInfo( theVolumeRef, &volumeInfo ) ;
//        }

        //Now lets find out how many Folders the volume has
        if ( err == EDS_ERR_OK ){
            err = EdsGetChildCount( theVolumeRef, &Count );

            if ( err == EDS_ERR_OK ){

                //Lets find the folder called DCIM
                bool bFoundDCIM = false;
                for(int i = 0; i < Count; i++){
                    err = EdsGetChildAtIndex( theVolumeRef, i, &dirItemRef_DCIM ) ;
                    if ( err == EDS_ERR_OK ){
                        EdsDirectoryItemInfo dirItemInfo;
                        err = EdsGetDirectoryItemInfo( dirItemRef_DCIM, &dirItemInfo );
                        if( err == EDS_ERR_OK){
                            string folderName = dirItemInfo.szFileName;
                            if( folderName == "DCIM" ){
                                bFoundDCIM = true;
                                printf("Found the DCIM folder at index %i\n", i);
                                break;
                            }
                        }
                    }
                    //we want to release the directories that don't match
                    easyRelease(dirItemRef_DCIM);
                }

                //This is a bit silly.
                //Essentially we traverse into the DCIM folder, then we go into the last folder in there, then we
                //get the last image in last folder.
                if( bFoundDCIM && dirItemRef_DCIM != NULL){
                    //now we are going to look for the last folder in DCIM
                    Count = 0;
                    err = EdsGetChildCount(dirItemRef_DCIM, &Count);

                    bool foundLastFolder = false;
                    if( Count > 0 ){
                        int lastIndex = Count-1;

                        EdsDirectoryItemInfo dirItemInfo_Sub;

                        err = EdsGetChildAtIndex( dirItemRef_DCIM, lastIndex, &dirItemRef_Sub ) ;
                        err = EdsGetDirectoryItemInfo( dirItemRef_Sub, &dirItemInfo_Sub);

                        printf("Last Folder is %s \n", dirItemInfo_Sub.szFileName);

                        EdsUInt32 jpgCount = 0;
                        err = EdsGetChildCount(dirItemRef_Sub, &jpgCount );

                        if( jpgCount > 0 ){
                            int latestJpg = jpgCount-1;

                            err = EdsGetChildAtIndex(dirItemRef_Sub, latestJpg, &dirItemRef_Image ) ;
                            err = EdsGetDirectoryItemInfo(dirItemRef_Image, &dirItemInfo_Image);

                            printf("Latest image is %s \n", dirItemInfo_Image.szFileName);
                            success = true;
                        }else{
                            printf("Error - No jpegs inside %s\n", dirItemInfo_Image.szFileName);
                        }
                    }else{
                        printf("Error - No subfolders inside DCIM!\n");
                    }
                }
            }
        }
        if( success ){
            success = downloadImage(dirItemRef_Image);
        }

        easyRelease(theVolumeRef);
        easyRelease(dirItemRef_DCIM);
        easyRelease(dirItemRef_Sub);
        easyRelease(dirItemRef_Image);

        postCommand();

        return success;
    }
Exemplo n.º 7
0
EdsError EDSCALLBACK CanonEDCamera::handleObjectEvent( EdsObjectEvent event, EdsBaseRef  object, EdsVoid * context) 
{ 
   printf ("Object Event triggered\n");

   CanonEDCamera* mmCanon = (CanonEDCamera*) g_Self;
  
   switch(event) 
   { 
      case kEdsObjectEvent_DirItemRequestTransfer: 
         {
            EdsError err = EDS_ERR_OK;
            EdsStreamRef stream = NULL;

            EdsDirectoryItemInfo dirItemInfo;
            err = EdsGetDirectoryItemInfo(object, &dirItemInfo);

            // do we need to notify the camera?
            /*
             if (err == EDS_ERR_OK)
             {
             CameraEvent e("DownloadStart");
             _model->notifyObservers(&e);
             }
             */

            if (err == EDS_ERR_OK)
            {
               //err = EdsCreateFileStream(dirItemInfo.szFileName, kEdsFileCreateDisposition_CreateAlways, kEdsAccess_ReadWrite, &stream);
               err = EdsCreateMemoryStream(0, &stream);
            }

            // Set Progress Callback???

            // Download Image
            if (err == EDS_ERR_OK)
            {
               err = EdsDownload(object,  dirItemInfo.size, stream);
            }

            if (err == EDS_ERR_OK)
            {
               err = EdsDownloadComplete(object);
            }

            EdsImageRef imageRef = NULL;

            if (err == EDS_ERR_OK)
            {
               err = EdsCreateImageRef(stream, &imageRef);
            }

            EdsImageInfo imageInfo;

            if (err == EDS_ERR_OK)
            {
               err = EdsGetImageInfo(imageRef, kEdsImageSrc_FullView, &imageInfo);
            }
            if (err == EDS_ERR_OK)
            {
               printf ("Image Width: %d\n", imageInfo.width);
            }


         }
         break; 
        
         default: 
          
         break; 
      } 
    
 
   // Object must be released 
   if(object) 
   { 
      EdsRelease(object); 
   } 
}