/usr/share/psychtoolbox-3/PsychVideoCapture/PsychGetCamIdForSpec.m is in psychtoolbox-3-common 3.0.11.20131230.dfsg1-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | function [devid, dev] = PsychGetCamIdForSpec(className, inputNameOrPort, instance, engineId)
% Return deviceIndex of a specified camera, one that matches given criteria.
%
% [deviceIndex, dev] = PsychGetCamIdForSpec([className][, inputNameOrPort][, instance][, engineId]);
%
% Searches for video sources which match given criteria. A handle to the
% first source that satisfies the criteria is returned in argument
% 'deviceIndex' - You can open a connection to the source via
% Screen('OpenVideoCapture', windowPtr, deviceIndex, ...);
%
% The 2nd optional return argument contains the complete 'dev'ice
% description struct, as returned by Screen().
%
% Returns empty variables if no match can be made.
%
% Optional criteria:
%
% 'className' Index or name of video input device class: Default is to
% accept any class. This matches against the 'ClassName' property of the
% list returned by Screen('VideoCaptureDevices').
%
% 'inputNameOrPort' selects the i'th input device of a matching class if an
% index is given (zero-based), or a specific named device, e.g., 'iSight'
% for the builtin iSight camera of Apple hardware.
%
% 'instance' If multiple devices match, take the i'th device where i ==
% instance. By default, the first device (instance == 0) is assigned.
%
% 'engineId' Enumerate for video capture engine 'engineId'. By default, the
% default videocapture engine is used.
%
%
% History:
% 9.5.2009 mk Written.
if nargin < 1
className = [];
end
if nargin < 2
inputNameOrPort = [];
end
if nargin < 3
instance = [];
end
if isempty(instance)
instance = 0;
end
if nargin < 4
engineId = [];
end
cams = Screen('VideoCaptureDevices', engineId);
devid = [];
dev = [];
curinst = -1;
for i=1:length(cams)
if ~isempty(className)
if isnumeric(className)
if cams(i).ClassIndex ~= className
% ClassIndex doesn't match: Reject.
continue;
end
else
if isempty(strfind(cams(i).ClassName, className))
% Classname doesn't match: Reject.
continue;
end
end
end
if ~isempty(inputNameOrPort)
if isnumeric(inputNameOrPort)
if cams(i).InputIndex ~= inputNameOrPort
% InputIndex doesn't match: Reject.
continue;
end
else
if isfield(cams(i), 'InputName') && isempty(strfind(cams(i).InputName, inputNameOrPort))
% InputName doesn't match: Reject.
continue;
end
if isfield(cams(i), 'DeviceName') && isempty(strfind(cams(i).DeviceName, inputNameOrPort))
% InputName doesn't match: Reject.
continue;
end
end
end
% Matching criteria satisfied. Matching instance?
curinst = curinst + 1;
if curinst == instance
% Assign deviceIndex for matched device:
devid = cams(i).DeviceIndex;
dev = cams(i);
break;
end
end
% Ok, either devid is empty if no matching device could be found, or we
% have a unique deviceIndex for use with Screen('OpenVideoCapture').
return;
|