简体   繁体   中英

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!!!**
    ...
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM