ofTheo / videoInput

A video capture library for windows.
http://muonics.net/school/spring05/videoInput/
357 stars 175 forks source link

Fix potential index mismatch in the deviceNames and deviceUniqueNames arrays for the same device #56

Closed Ivan-Grebennikov closed 1 year ago

Ivan-Grebennikov commented 1 year ago

Hi, @ofTheo!

The issue is - even if "FriendlyName" query fails deviceCounter is increased, but deviceUniqueNames size remains the same - so we could face an index mismatch for the same device in the two arrays.

The solution is we should add string to deviceUniqueNames array regardless of "FriendlyName" query status.

deviceNames is a vector of FriendlyNames and is initialized with 255 empty strings:

https://github.com/ofTheo/videoInput/blob/870dbabda79470736e5d5294038ae5676ebb238a/videoInputSrcAndDemos/libs/videoInput/videoInput.cpp#L770

So we have initially 255 devices whose FriendlyNames are updated after listDevices() is called. And we just skip device in deviceNames if FriendlyName query is failed leaving it empty, but deviceUniqueNames size is not increased for this device, and we have index mismatch, and the methods:

https://github.com/ofTheo/videoInput/blob/870dbabda79470736e5d5294038ae5676ebb238a/videoInputSrcAndDemos/libs/videoInput/videoInput.cpp#L786

and

https://github.com/ofTheo/videoInput/blob/870dbabda79470736e5d5294038ae5676ebb238a/videoInputSrcAndDemos/libs/videoInput/videoInput.cpp#L812

may not return same index for the same device afterwards.

ofTheo commented 1 year ago

Happy to merge this, but wondering if maybe we should just set the unique name to the friendly name if no unique name exists?

Maybe more useful than an empty string?

Ivan-Grebennikov commented 1 year ago

I think it would be the great decision!

Have made neccesary changes.

ofTheo commented 1 year ago

Great - thank you @Ivan-Grebennikov!