Skip to content

Commit

Permalink
Merge pull request kylemcdonald#10 from roymacdonald/fix-2.12
Browse files Browse the repository at this point in the history
Fix 2.12
  • Loading branch information
kylemcdonald committed Sep 8, 2013
2 parents 31d5a96 + 81f0e05 commit c926ea4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
38 changes: 37 additions & 1 deletion src/ofxEdsdk.cpp
Expand Up @@ -9,7 +9,13 @@
2 frames.
*/
#define OFX_EDSDK_BUFFER_SIZE 4

#define OFX_EDSDK_LIVE_DELAY 100
#ifdef TARGET_OSX
#include <Cocoa/Cocoa.h>
#elif TARGET_WIN32
#define _WIN32_DCOM
#include <objbase.h>
#endif
namespace ofxEdsdk {

EdsError EDSCALLBACK Camera::handleObjectEvent(EdsObjectEvent event, EdsBaseRef object, EdsVoid* context) {
Expand Down Expand Up @@ -58,6 +64,9 @@ namespace ofxEdsdk {
photoDataReady(false),
needToSendKeepAlive(false),
needToDownloadImage(false),
#ifdef TARGET_OSX
bTryInitLiveView(false),
#endif
resetIntervalMinutes(15) {
liveBufferMiddle.resize(OFX_EDSDK_BUFFER_SIZE);
for(int i = 0; i < liveBufferMiddle.maxSize(); i++) {
Expand Down Expand Up @@ -105,6 +114,7 @@ namespace ofxEdsdk {
EdsDeviceInfo info;
Eds::GetDeviceInfo(camera, &info);
Eds::SafeRelease(cameraList);
ofLogVerbose("ofxEdsdk::setup") << "connected camera model: " << info.szDeviceDescription << " " << info.szPortName << endl;

startThread(true, false);
return true;
Expand All @@ -118,6 +128,15 @@ namespace ofxEdsdk {
}

void Camera::update() {
if(connected){
#ifdef TARGET_OSX
if (bTryInitLiveView) {
if (ofGetElapsedTimeMillis() - initTime > OFX_EDSDK_LIVE_DELAY) {
bTryInitLiveView = false;
resetLiveView();
}
}
#endif
lock();
if(liveBufferMiddle.size() > 0) {
// decoding the jpeg in the main thread allows the capture thread to run in a tighter loop.
Expand All @@ -138,6 +157,7 @@ namespace ofxEdsdk {
} else {
unlock();
}
}
}

bool Camera::isFrameNew() {
Expand Down Expand Up @@ -275,11 +295,22 @@ namespace ofxEdsdk {
}

void Camera::threadedFunction() {
#ifdef TARGET_OSX

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
#elif TARGET_WIN32
CoInitializeEx( NULL, 0x0);// OINIT_MULTITHREADED );
#endif
lock();
try {
Eds::OpenSession(camera);
connected = true;
#ifdef TARGET_OSX
bTryInitLiveView = true;
initTime = ofGetElapsedTimeMillis();
#else
Eds::StartLiveview(camera);
#endif
} catch (Eds::Exception& e) {
ofLogError() << "There was an error opening the camera, or starting live view: " << e.what();
return;
Expand Down Expand Up @@ -349,5 +380,10 @@ namespace ofxEdsdk {
// the t2i can run at 30 fps = 33 ms, so this might cause frame drops
ofSleepMillis(5);
}
#ifdef TARGET_OSX
[pool drain];
#elif TARGET_WIN32
CoUninitialize();
#endif
}
}
6 changes: 5 additions & 1 deletion src/ofxEdsdk.h
Expand Up @@ -35,7 +35,7 @@ namespace ofxEdsdk {
bool savePhoto(string filename); // .jpg only
ofPixels& getPhotoPixels();
ofTexture& getPhotoTexture();

protected:
EdsCameraRef camera;

Expand Down Expand Up @@ -97,5 +97,9 @@ namespace ofxEdsdk {
void setSendKeepAlive();

EdsDirectoryItemRef directoryItem;
#ifdef TARGET_OSX
int initTime;
bool bTryInitLiveView;
#endif
};
}

0 comments on commit c926ea4

Please sign in to comment.