yinjie luo
yinjie luo

Reputation: 19

How to keep my camera alive when I use Cannon EDSDK in my C++ code?

I think it is essential to send a message to the camera per some minutes ,so I initialize my camera and send message to camera every once in a while in my main thread , and in the other thread I open the liveview to process my other jobs, but in the liveview thread , it wait time out when sending this message :

EdsSetPropertyData(theCamera, kEdsPropID_Evf_Mode, 0, sizeof(evfMode), &evfMode)

I never met this when all jobs handled in just one thread, I don't know why it happends like this , could someone help me ? Here is some of my code.

my main thread : (I don't send keepalive message in the thread,but also timeout when starting liveview !)

CanonCameraWrapper& wrapper = param->wrapper;
bool setup_ok = wrapper.setup(0);
if (!setup_ok)
{
    wrapper.destroy();
}
wrapper.setDownloadPath("img");
pthread_t camera_thread;
pthread_create(&camera_thread, NULL, camera_thread_func, (void *)(param));
pthread_join(camera_thread, NULL);

the other thread

void * camera_thread_func(void * arg)
{
    global_param* param = (global_param*)arg;
    CanonCameraWrapper& wrapper = param->wrapper;
    wrapper.beginLiveView();//**//it wait time out here!!!**
    ...
}

Upvotes: 0

Views: 277

Answers (1)

JBildstein
JBildstein

Reputation: 1079

I believe there are two things you have to be aware of. One is this notice in the Canon SDK documentation:

When creating applications that run under Windows, a COM initialization is required for each thread in order to access a camera from a thread other than the main thread. To create a user thread and access the camera from that thread, be sure to execute CoInitializeEx( NULL, COINIT_APARTMENTTHREADED ) at the start of the thread and CoUnInitialize() at the end. Sample code is shown below. This is the same when controlling EdsVolumeRef or EdsDirectoryItemRef objects from another thread, not just with EdsCameraRef

The other thing is: you cannot access (most of) the SDK at the same time. So if you are using multiple threads you have to be careful about this

Upvotes: 1

Related Questions