elliotwoods / ofxCanon

openFrameworks addon for control and capture from Canon DSLR's via the EDSDK
37 stars 11 forks source link

multicamera #10

Open natxopedreira opened 3 years ago

natxopedreira commented 3 years ago

Hello!!!

Thanks for your addon i used several times.

This time i need to use two cameras, and i found that even the lib detect 2 cameras conected the data is the same for both (i mean for example the description) so you must change this line https://github.com/elliotwoods/ofxCanon/blob/d4c15a7ae0597c5acafb1b5babdf95f11cb5d2bb/src/ofxCanon/Device.cpp#L715

And set the index instead of 0 if not is allways the same camera

ERROR_GOTO_FAIL(EdsGetChildAtIndex(cameraList, i, &camera), "Get the camera device");

I think is so small to do a request so put here.

Buuuuut withe the simple class im not able to take a photo, let me explain, in the moment i call the setup() method for the second class instance the first one stops making photos... just no error on console but also no pixels... nada, if i press to make another one this time i get an error about busy device.

Without using the simple class it works as expected but i will preffer to use it threaded so i wanted to use the simple class.

Any clue of what can be happening here?

Best!

natxopedreira commented 3 years ago

I noticed ofxedsdk works but is crashing on exit so not a solution, comparing the two approach i see something that maybe is related.... only maybe :)

In the simple class, setup method, you initialize the sdk in the main thread https://github.com/elliotwoods/ofxCanon/blob/e4ca12797837779b83239cbd68c48c2f5c0e70a6/src/ofxCanon/Simple.cpp#L47

But later inside the instance thread you call listDevices https://github.com/elliotwoods/ofxCanon/blob/e4ca12797837779b83239cbd68c48c2f5c0e70a6/src/ofxCanon/Simple.cpp#L58

And inside listDevices code you initialize again https://github.com/elliotwoods/ofxCanon/blob/4d5e3963efb81e7a484a5e6d4d14e20d25d4aee3/src/ofxCanon/Device.cpp#L702

And finally looking in initializer, the method called closes the sdk if opened and reopens again https://github.com/elliotwoods/ofxCanon/blob/851a3d485815ddf06ffaa9377a6ce80d31ce0fcd/src/ofxCanon/Initializer.cpp

So you in resume on simple class setup method i think that you first init sdk in main thread but later inside the thread when you call listDevices the sdk is closed and init again inside that thread

And in ofxedsdk only the sdk is inited in main thread https://github.com/elliotwoods/ofxEdsdk/blob/dd534e6f463470ed5caab0b9f39b019cdbd06a1e/src/ofxEdsdk.cpp#L106

I hope that all makes sense!!!

natxopedreira commented 3 years ago

I found a workarround

Problem i sure related to threading and how that works on canon sdk

To use multiples cameras on a "external thread" so dont block of main i made a Dual camera simple class based on current one but implementing N instances of Device inside the CameraThread class and works perfect. I mention here so maybe someone in a future will find that usefull

I also implemented a method to reset live view so you wont loose liveView if connected more that 15 minutes.

Whould you accept a pull request with the resetLiveView method and the small correction on listDevices¿

elliotwoods commented 3 years ago

Hello @natxopedreira Thank you for finding these issues.

I don't think that I'm re-initialising the SDK as you suspect. Since the instance is created static:

https://github.com/elliotwoods/ofxCanon/blob/master/src/ofxCanon/Initializer.cpp#L11

The constructor is only called the first time you call to X() and not thereafter. And since init is only ever called from the constructor, it will only be called once (so it won't be reinitialised). I might be wrong there, so maybe you can simply try putting a breakpoint in the init() function and see if it really is called twice or not.

You're absolutely right about

ERROR_GOTO_FAIL(EdsGetChildAtIndex(cameraList, i, &camera)

Feel free to make a PR with a correction to that + your resetLiveView function.

Concerning multiple cameras, It somewhat makes sense that the SDK might require them both to operate from the same thread (although that would be disappointing). I haven't tried this myself yet.

I have heard of people using multiple cameras with this addon, but I'm not sure if they were using the Simple utility class or not.

natxopedreira commented 3 years ago

ah ok i dont notice it was static sorry, muticamera works but not with the simple class, i think must be something related that as is threaded must be init all in the same one or similar... dont know. But you are right using the device class directly works in multicamera but as im using also liveview fps drop a lot.

Will clone the repo and do a pr

Thank you