Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List devices + static to track if sdk intialised #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 39 additions & 19 deletions example/src/testApp.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,57 @@
#include "testApp.h"

#define FOREACH_CAMERA for (int iCam=0; iCam<2; ++iCam)

void testApp::setup() {
ofSetLogLevel(OF_LOG_VERBOSE);
camera.setup();

//ofxEdsdk::Camera::listDevices();

intialised[0]=false;
intialised[1]=false;
}

void testApp::update() {
camera.update();
if(camera.isFrameNew()) {
// process the live view with camera.getLivePixels()
}
if(camera.isPhotoNew()) {
// process the photo with camera.getPhotoPixels()
// or just save the photo to disk (jpg only):
camera.savePhoto(ofToString(ofGetFrameNum()) + ".jpg");
FOREACH_CAMERA {
camera[iCam].update();
if(camera[iCam].isFrameNew()) {
// process the live view with camera.getLivePixels()
}
if(camera[iCam].isPhotoNew()) {
// process the photo with camera.getPhotoPixels()
// or just save the photo to disk (jpg only):
camera[iCam].savePhoto(ofToString(ofGetFrameNum()) + ".jpg");
}
}
}

void testApp::draw() {
camera.draw(0, 0);
// camera.drawPhoto(0, 0, 432, 288);

if(camera.isLiveReady()) {
stringstream status;
status << camera.getWidth() << "x" << camera.getHeight() << " @ " <<
(int) ofGetFrameRate() << " app-fps " << " / " <<
(int) camera.getFrameRate() << " cam-fps";
ofDrawBitmapString(status.str(), 10, 20);
FOREACH_CAMERA {
camera[iCam].draw(iCam * camera[0].getWidth()/2, 0, camera[iCam].getWidth() / 2, camera[iCam].getHeight() / 2);
// camera.drawPhoto(0, 0, 432, 288);

if(camera[iCam].isLiveReady()) {
stringstream status;
status << camera[iCam].getWidth() << "x" << camera[iCam].getHeight() << " @ " <<
(int) ofGetFrameRate() << " app-fps " << " / " <<
(int) camera[iCam].getFrameRate() << " cam-fps";
ofDrawBitmapString(status.str(), 10 + camera[0].getWidth()/2 * iCam, 20);
}
}
}

void testApp::keyPressed(int key) {
if(key == ' ') {
camera.takePhoto();
FOREACH_CAMERA
camera[iCam].takePhoto();
}

if(key == '1' || key == '0')
{
if (!intialised[key-'0'])
{
camera[key - '0'].setup();
intialised[key-'0'] = true;
}
}
}
4 changes: 3 additions & 1 deletion example/src/testApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ class testApp : public ofBaseApp {
void draw();
void keyPressed(int key);

ofxEdsdk::Camera camera;
ofxEdsdk::Camera camera[2];

int intialised[2];
};
3 changes: 2 additions & 1 deletion src/EdsWrapper/EdsWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ namespace Eds {
void SetObjectEventHandler(EdsCameraRef inCameraRef, EdsObjectEvent inEvnet, EdsObjectEventHandler inObjectEventHandler, EdsVoid* inContext);
void SetCameraStateEventHandler(EdsCameraRef inCameraRef, EdsStateEvent inEvnet, EdsStateEventHandler inStateEventHandler, EdsVoid* inContext);
void CreateStream(EdsIStream* inStream, EdsStreamRef* outStreamRef);
void GetEvent();
void GetEvent();

}
67 changes: 63 additions & 4 deletions src/ofxEdsdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,61 @@ namespace ofxEdsdk {
}
try {
Eds::CloseSession(camera);
Eds::TerminateSDK();
} catch (Eds::Exception& e) {
ofLogError() << "There was an error destroying ofxEds::Camera: " << e.what();
}
}
terminate();
unlock();
for(int i = 0; i < liveBufferMiddle.maxSize(); i++) {
delete liveBufferMiddle[i];
}
}

void Camera::listDevices(string* s) {
try {
stringstream ss;

initialize();

EdsCameraListRef cameraList;
Eds::GetCameraList(&cameraList);

UInt32 cameraCount;
Eds::GetChildCount(cameraList, &cameraCount);

EdsDeviceInfo info;
EdsCameraRef camera;
ss << "ofxEdsdk found " << cameraCount << "cameras:" << endl;
ss << setw(10) << "Device ID" << setw(25) << "Description" << setw(6) << "Port " << setw(11) << "Reserved" << endl;
for(EdsInt32 i=0;i<cameraCount;++i) {
Eds::GetChildAtIndex(cameraList, i, &camera);
Eds::GetDeviceInfo(camera, &info);

ss << setw(10) << i;
ss << setw(25) << info.szDeviceDescription;
ss << setw(6) << info.szPortName;
ss << setw(11) << info.reserved << endl;

Eds::SafeRelease(camera);
}
terminate();

Eds::SafeRelease(cameraList);

if (s==0) {
cout << ss.str() << endl;
} else {
*s = ss.str();
}
} catch (Eds::Exception& e) {
ofLogError() << "There was an error during Camera::listDevices(): " << e.what();
}
}

bool Camera::setup(int deviceId) {
try {
Eds::InitializeSDK();
initialize();

EdsCameraListRef cameraList;
Eds::GetCameraList(&cameraList);
Expand Down Expand Up @@ -128,7 +169,7 @@ namespace ofxEdsdk {
frameNew = true;
if(liveTexture.getWidth() != livePixels.getWidth() ||
liveTexture.getHeight() != livePixels.getHeight()) {
liveTexture.allocate(livePixels.getWidth(), livePixels.getHeight(), GL_RGB8);
liveTexture.allocate(livePixels.getWidth(), livePixels.getHeight(), GL_RGB);
}
liveTexture.loadData(livePixels);
lock();
Expand Down Expand Up @@ -220,7 +261,7 @@ namespace ofxEdsdk {
if(needToUpdatePhoto) {
if(photoTexture.getWidth() != photoPixels.getWidth() ||
photoTexture.getHeight() != photoPixels.getHeight()) {
photoTexture.allocate(photoPixels.getWidth(), photoPixels.getHeight(), GL_RGB8);
photoTexture.allocate(photoPixels.getWidth(), photoPixels.getHeight(), GL_RGB);
}
photoTexture.loadData(photoPixels);
needToUpdatePhoto = false;
Expand Down Expand Up @@ -263,6 +304,7 @@ namespace ofxEdsdk {
Eds::StartLiveview(camera);
} catch (Eds::Exception& e) {
ofLogError() << "There was an error opening the camera, or starting live view: " << e.what();
unlock();
return;
}
unlock();
Expand Down Expand Up @@ -323,4 +365,21 @@ namespace ofxEdsdk {
}
}
}

bool Camera::sdkInitialized = false;

void Camera::initialize() {
if (!sdkInitialized) {
Eds::InitializeSDK();
sdkInitialized = true;
}
}

void Camera::terminate() {
if (sdkInitialized) {
Eds::TerminateSDK();
sdkInitialized = false;
}
}

}
5 changes: 5 additions & 0 deletions src/ofxEdsdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace ofxEdsdk {
public:
Camera();
~Camera();
static void listDevices(string* s=0);
bool setup(int deviceId = 0);

void update();
Expand All @@ -35,6 +36,10 @@ namespace ofxEdsdk {
ofPixels& getPhotoPixels();

protected:
static void initialize();
static void terminate();

static bool sdkInitialized;
EdsCameraRef camera;

RateTimer fps;
Expand Down