This file is indexed.

/usr/share/psychtoolbox-3/PsychDemos/VideoDVCamCaptureDemo.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
function VideoDVCamCaptureDemo(fullscreen, fullsize, roi, depth, deviceId, moviename)
% Demonstrate simple use of built-in video capture engine with DV consumer cameras.
%
% VideoDVCamCaptureDemo([fullscreen=0][, fullsize=0][, roi][, depth][,deviceId=0][, moviename])
%
% VideoDVCamCaptureDemo initializes the first attached and supported DV firewire
% consumer camera, then shows its video image in a Psychtoolbox window.
% A press of the ESCape key ends the demo.
%
% Optional parameters:
%
% 'fullscreen' If set to non-zero value, the image is displayed in a
% fullscreen window, as usual, otherwise a normal GUI window is used.
%
% 'fullsize' If set to 1, the cameras image is scaled up to full screen
% resolution, ie. so it fills the maximum amount of display area, but
% preserving the original aspect ratio.
%
% 'roi' Set to [0 0 720 576] for a PAL-DV camera and [0 0 720 480] for a NTSC-DV camera.
% Default is PAL if omitted.
%
% 'deviceId' Device index of video capture device. Defaults to system default. You can
% also specify a gst-launch style string to define a videosource here. Or you can set
% the special string deviceId = 'X' so builtin spec strings suitable for each operating
% system will be used.
%
% 'moviename' Name string for selection of filename of a target movie file to
% which video should be recorded. Defaults to none,ie., no video recording.
%

% History:
% 27-Dec-1013  mk  Written.

PsychDefaultSetup(1);

if nargin < 1
    fullscreen=[];
end

if isempty(fullscreen)
    fullscreen=0;
end

if nargin < 2
    fullsize=[];
end

if isempty(fullsize)
    fullsize=0;
end

if nargin < 3 || isempty(roi)
    % Must set explicit roi with video resolution. Only two options,
    % 720 x 576 for PAL DV cameras, and 720 x 480 for NTSC DV cameras.
    % We choose PAL:
    roi = [0 0 720 576];
end

if nargin < 4
    depth = [];
end

if nargin < 5
    deviceId = [];
end

if nargin < 6
    moviename = [];
end

recordingflags = 0;
if ~isempty(moviename)
  % For movie recording, also enable audio recording.
  % Note: Audio is *not* actually recorded from the DV
  % camera, but from the systems soundcard, or whatever
  % was selected via video recording settings.
  % However, enabling use of audio recording seems to sometimes
  % avoid hangs of DV recording at least on Linux on repeated
  % sessions, so this is essentially a hack, even if no audio is
  % needed:
  recordingflags = 2;
 end
 
screenid=max(Screen('Screens'));

try
    if fullscreen<1
        win=Screen('OpenWindow', screenid, 0, [0 0 800 600]);
    else
        win=Screen('OpenWindow', screenid, 0);
    end;
    
    % Initial flip to a blank screen:
    Screen('Flip',win);
    
    % Set text size for info text to 24 pixels.
    Screen('TextSize', win, 24);
    
    % Use of a gst-launch style spec for a video source requested? A deviceId which
    % is actually a character string would signal this:
    if ischar(deviceId)
      % Yes. Meaningful spec string, or only a single dummy character?
      if length(deviceId) < 2
        % Dummy: Replace by hard-coded "known to work" example string:
        
        if IsLinux
          % Any of these work on Linux:
          capturebinspec = 'dv1394src ! dvdemux ! dvdec name=ptbdvsource';
          %capturebinspec = 'dv1394src ! video/x-dv ! dvdemux ! dvdec name=ptbdvsource';
          %capturebinspec = 'dv1394src ! dvdemux ! ffdec_dvvideo name=ptbdvsource';
        end
        
        if IsWin
          % This should work on MS-Windows if Matthew Edmundson is right:
          capturebinspec = 'dshowvideosrc ! video/x-dv ! dvdemux ! dvdec name=ptbdvsource';
        end
        
        if IsOSX
          % This should work on OSX, if at all. If this doesn't work then game-over (Untested):
          capturebinspec = 'qtkitvideosrc name=ptbdvsource';
        end
      else
        % Real string: Use it.
        capturebinspec = deviceId;
      end

      if isempty(roi)
        error('You *must* specify a roi of [0 0 720 576] for PAL-DV or [0 0 720 480] for NTSC-DV if you define your own video capture source via deviceId as a string!');
      end
      
      % Assign capturebinspec as gst-launch style capture bin spec for use as video source:
      Screen('SetVideoCaptureParameter', -1, sprintf('SetNextCaptureBinSpec=%s', capturebinspec));
      
      % Signal to Screen() that spec string should be used. This via special deviceId -9:
      deviceId = -9;
    end
    
    % Open DV camera: We always use engineId 3 for GStreamer, as only GStreamer supports DV cameras atm.:
    grabber = Screen('OpenVideoCapture', win, deviceId, roi, depth, [], [], moviename, recordingflags, 3);

    if IsWin || IsOSX || (IsLinux && ~isempty(getenv('PSYCH_FORCE_CAMERABIN2')))
      % If user-specified video source string is in use, then we refrain from setting
      % fps here, but use the "do what you think is right" 'realmax' joker. This one only
      % works with the GStreamer camerabin2 video capture plugin. We use camerabin2
      % on Apple/OSX and MS-Windows by default, but only optionally on Linux, so only
      % do this if we are on Windows, OSX or Linux with camerabin2 enabled:
      Screen('StartVideoCapture', grabber, realmax, 1);      
    else
      % For DV cameras you *must* specify the exact capture framerate of which the
      % camera is capable of. For PAL DV cams this is 25 fps, for NTSC DV cams this
      % is probably either 30 fps or 30000/1001 fps. Any other framerate setting *will fail* !
      if RectHeight(roi) == 576
        % PAL-DV:
        Screen('StartVideoCapture', grabber, 25, 1);
      else
        % NTSC-DV:
        Screen('StartVideoCapture', grabber, 30000/1001, 1);
      end
    end
    
    dstRect = [];
    oldpts = 0;
    count = 0;
    t=GetSecs;
    
    while (GetSecs - t) < 600
        if KbCheck
            break;
        end;
        
        [tex pts nrdropped,intensity]=Screen('GetCapturedImage', win, grabber, 1); %#ok<ASGLU,NASGU>
        % fprintf('tex = %i  pts = %f nrdropped = %i\n', tex, pts, nrdropped);
        
        if (tex>0)
            % Perform first-time setup of transformations, if needed:
            if fullsize && (count == 0)
                texrect = Screen('Rect', tex);
                winrect = Screen('Rect', win);
                sf = min([RectWidth(winrect) / RectWidth(texrect) , RectHeight(winrect) / RectHeight(texrect)]);
                dstRect = CenterRect(ScaleRect(texrect, sf, sf) , winrect);
            end
            
            % texinfo = Screen('Getwindowinfo', tex)
            % outintens = intensity
            
            % Draw new texture from framegrabber.
            Screen('DrawTexture', win, tex, [], dstRect);
            
            % Print pts:
            Screen('DrawText', win, sprintf('%.4f', pts), 0, 0, 255);
            if count>0
                % Compute delta:
                delta = (pts - oldpts) * 1000;
                oldpts = pts;
                Screen('DrawText', win, sprintf('%.4f', delta), 0, 20, 255);
            end;
            
            % Show it.
            Screen('Flip', win);
            Screen('Close', tex);
        end
        count = count + 1;
    end
    telapsed = GetSecs - t %#ok<NOPRT>
    
    Screen('StopVideoCapture', grabber);
    Screen('CloseVideoCapture', grabber);
    
    Screen('CloseAll');
    avgfps = count / telapsed %#ok<NOPRT,NASGU>
    
catch %#ok<CTCH>
    Screen('CloseAll');
end