fix crash if attemp record and thread stopped + try to find good camera to record instead of index 0 , finally use blacklist
This commit is contained in:
@ -57,7 +57,7 @@ void ProcessWebcamThread::Execute() {
|
||||
if (temp_pause || !temp_record_frame)
|
||||
Platform::Get().Sleep(10);
|
||||
else{
|
||||
InputVideo->read(*im);
|
||||
InputVideo->read(*im);
|
||||
outputVideo->write(*im);
|
||||
|
||||
lutFile.write(reinterpret_cast<const char*>(¤t_frame_clock),sizeof(float));
|
||||
@ -97,12 +97,27 @@ HRESULT EnumerateDevices(REFGUID category, IEnumMoniker **ppEnum)
|
||||
return hr;
|
||||
}
|
||||
|
||||
int DisplayDeviceInformation(IEnumMoniker *pEnum)
|
||||
std::string BstrToString(BSTR bstr)
|
||||
{
|
||||
if (!bstr) return std::string();
|
||||
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, bstr, -1, NULL, 0, NULL, NULL);
|
||||
if (len <= 0) return std::string();
|
||||
|
||||
std::string result(len - 1, '\0'); // -1 pour exclure le \0 final
|
||||
WideCharToMultiByte(CP_UTF8, 0, bstr, -1, &result[0], len, NULL, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::vector<int> DisplayDeviceInformation(IEnumMoniker *pEnum)
|
||||
{
|
||||
IMoniker *pMoniker = NULL;
|
||||
int return_id_device = -1;
|
||||
int counter_device = 0;
|
||||
|
||||
std::vector<int> camera_ids;
|
||||
|
||||
while (pEnum->Next(1, &pMoniker, NULL) == S_OK)
|
||||
{
|
||||
IPropertyBag *pPropBag;
|
||||
@ -124,10 +139,24 @@ int DisplayDeviceInformation(IEnumMoniker *pEnum)
|
||||
}
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
printf("%S\n", var.bstrVal);
|
||||
|
||||
if (wcscmp(var.bstrVal, L"MMP SDK") != 0 && wcscmp(var.bstrVal, L"Oculus Rift") != 0 && wcscmp(var.bstrVal, L"HTC Vive") != 0)
|
||||
std::string name = BstrToString(var.bstrVal);
|
||||
|
||||
printf("%S\n", var.bstrVal);
|
||||
__LOG_CAM__<<"FOUND CAM ID "<<counter_device<<" NAME "<<name.c_str()<<"\n";
|
||||
if (
|
||||
wcsstr(var.bstrVal, L"MMP SDK") == nullptr &&
|
||||
wcsstr(var.bstrVal, L"Oculus Rift") == nullptr &&
|
||||
wcsstr(var.bstrVal, L"HTC Vive") == nullptr &&
|
||||
wcsstr(var.bstrVal, L"RealSense") == nullptr &&
|
||||
wcsstr(var.bstrVal, L"OBS") == nullptr
|
||||
){
|
||||
camera_ids.push_back(counter_device);
|
||||
return_id_device = counter_device;
|
||||
}
|
||||
|
||||
|
||||
__LOG_CAM__<<"RETURN DEVICE ID "<<return_id_device<<"\n";
|
||||
|
||||
VariantClear(&var);
|
||||
}
|
||||
@ -154,7 +183,8 @@ int DisplayDeviceInformation(IEnumMoniker *pEnum)
|
||||
pMoniker->Release();
|
||||
++counter_device;
|
||||
}
|
||||
return return_id_device;
|
||||
|
||||
return camera_ids;
|
||||
}
|
||||
|
||||
|
||||
@ -172,7 +202,7 @@ bool Webcam::Open(int width_, int height_) {
|
||||
height = height_;
|
||||
|
||||
|
||||
int id_device = -1;
|
||||
std::vector<int> id_devices;
|
||||
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
@ -181,23 +211,38 @@ bool Webcam::Open(int width_, int height_) {
|
||||
hr = EnumerateDevices(CLSID_VideoInputDeviceCategory, &pEnum);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
id_device = DisplayDeviceInformation(pEnum);
|
||||
id_devices = DisplayDeviceInformation(pEnum);
|
||||
pEnum->Release();
|
||||
}
|
||||
|
||||
CoUninitialize();
|
||||
}
|
||||
if (id_device == -1)
|
||||
|
||||
if (id_devices.size() == 0)
|
||||
return false;
|
||||
|
||||
InputVideo = new VideoCapture(0);
|
||||
|
||||
InputVideo = new VideoCapture();
|
||||
int device_id = -1;
|
||||
for (int i = 0; i < id_devices.size(); i++)
|
||||
{
|
||||
InputVideo->open(id_devices[i]);
|
||||
if(InputVideo->isOpened()){
|
||||
device_id = id_devices[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(device_id == -1)
|
||||
return false;
|
||||
|
||||
__LOG_CAM__ << "OPEN CAM ID "<<device_id <<"\n";
|
||||
|
||||
InputVideo->set(CV_CAP_PROP_FRAME_WIDTH, width);
|
||||
InputVideo->set(CV_CAP_PROP_FRAME_HEIGHT, height);
|
||||
InputVideo->set(CAP_PROP_FPS, webcam_fps);
|
||||
|
||||
if (!InputVideo->isOpened())
|
||||
return false;
|
||||
|
||||
outputVideo = new VideoWriter;
|
||||
ReplayInputVideo = new VideoCapture();
|
||||
|
||||
@ -220,6 +265,8 @@ void Webcam::Reset(bool _reset_video) {
|
||||
}
|
||||
|
||||
void Webcam::RecordFrame(float _clock) {
|
||||
if (!thread_process)
|
||||
return;
|
||||
thread_process->mutex_record_frame.Lock();
|
||||
thread_process->record_frame = true;
|
||||
thread_process->current_frame_clock = _clock;
|
||||
|
||||
Reference in New Issue
Block a user