This file is indexed.

/usr/share/psychtoolbox-3/PsychDemos/VideoIPWebcamCaptureDemo.m is in psychtoolbox-3-common 3.0.14.20170103+git6-g605ff5c.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
215
216
217
218
219
220
function VideoIPWebcamCaptureDemo(videourl, fullscreen, fullsize, moviename)
% Demonstrate use of built-in video capture engine with the Android IPWebcam app.
%
% VideoIPWebcamCaptureDemo([videourl='http://192.168.178.22:8080/videofeed'][fullscreen=0][, fullsize=1][, moviename])
%
% VideoIPWebcamCaptureDemo connects to a IP web video stream streamed
% from an Android device by the Android IPWebcam application, available
% from the Google Play Store here:
%
% https://play.google.com/store/apps/details?id=com.pas.webcam&hl=en
%
% It then shows its video stream in a Psychtoolbox window.
% A press of the ESCape key ends the demo.
%
% This demo has been successfully tested on Ubuntu Linux 14.04.5-LTS,
% but should likely work with OSX and Windows as well if the installed
% GStreamer framework provides the needed plugins.
%
%
% Optional parameters:
%
% 'videourl' If not set, defaults to 'http://192.168.178.22:8080/videofeed'.
%
% '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.
%
% '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. 'help VideoRecording' for more info about video recording.
%
% One application of such a custom setup can be seen in the discussion thread
% containing message #20942 on the Psychtoolbox forum.
%
%
% This section is referring to an alternative way of getting video, which
% can be significantly higher performance and more flexible, but only works
% on Linux. As of this release it has not been tested with IPWebcam!
%
% See the following GitHub project for an elegant solution on Linux:
%
% https://github.com/bluezio/ipwebcam-gst
%
% More background information:
%
% Loopback setup on Linux for use with new GStreamer-1 video backend:
%
% This specific configuration was shown to work at least on Ubuntu 14.04
% LTS with a Sony PAL-DV firewire camera. After following the setup steps,
% demos like our standard VideoCaptureDemo, VideoRecordingDemo, ... worked
% without any special configuration or treatment of DV cameras.
%
% Here you need to install a Video4Linux2 loopback kernel module. It will
% allow to create virtual video sources, from which Psychtoolbox can
% read/capture/process record live video. Then some external application
% can feed video into those virtual sources. You then attach an external
% command line DV capture session as video source.
%
% 1. Install the package "v4l2loopback-dkms" to get the kernel module installed and
%    loaded. A "sudo apt-get install v4l2loopback-dkms" on Ubuntu 14.04-LTS
%    and later distributions should do the trick. The package is probably
%    also available on Debian, other Debian/Ubuntu derived distros etc. Or
%    you get the most recent version to compile and install from source
%    code from the homepage of the project:
%    https://github.com/umlaeute/v4l2loopback
%
% 2. You may or may not need to "sudo modprobe v4l2loopback" on first use.
%
% 3. Then you use a GStreamer video capture pipeline launched from a terminal
%    window to connect to your DV camera, capture live video and feed it
%    into the virtual video loopback device. An example launch line can
%    look like this:
%
%    gst-launch dv1394src ! dvdemux ! dvdec ! v4l2sink device=/dev/video0
%
%    This would make live video from the first connected DV camera
%    available on /dev/video0. See
%    https://github.com/umlaeute/v4l2loopback/wiki for more detailed
%    instructions.
%
%    If this doesn't work for you with GStreamer-1 you may need to install
%    good old GStreamer-0.10 in addition to the already installed
%    GStreamer-1 and instead use the gst-launch-0.10 command instead of the
%    gst-launch command to select for the old implementation.
%
% 4. Psychtoolbox video capture functions should now report and be able to
%    use a new virtual video capture device with a name like "Dummy video
%    device 0000" or some name defined by you. Psychtoolbox should be able
%    to video capture or record video from that device aka your DV video
%    camera.
%
%    The Wiki of v4l2loopback describes more elaborate setups, e.g., for
%    capturing from multiple video DV cameras.
%

% History:
% 07-Sep-2016  mk  Derived from VideoDVCamCaptureDemo.

PsychDefaultSetup(2);

if nargin < 1 || isempty(videourl)
    videourl = 'http://192.168.178.22:8080/videofeed'
end

if nargin < 2 || isempty(fullscreen)
    fullscreen = 0;
end

if nargin < 3 || isempty(fullsize)
    fullsize = 1;
end

if nargin < 4
    moviename = [];
end

screenid=max(Screen('Screens'));

try
    PsychImaging('PrepareConfiguration');
    PsychImaging('AddTask','General','UseVirtualFramebuffer');
    if fullscreen < 1
        win = PsychImaging('OpenWindow', screenid, 0, [0 0 800 600]);
    else
        win = PsychImaging('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);

    capturebinspec = sprintf('souphttpsrc location="%s" do-timestamp=true is-live=true ! multipartdemux ! jpegdec ! videoconvert name=ptbdvsource', videourl);

    % 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;

    % Only depth format 6 YUV seems to work at Android app default settings:
    depth = 6;
    recordingflags = 0;

    % ROI is auto-detected:
    roi = [];

    % Open camera: We always use engineId 3 for GStreamer, as only GStreamer supports these cameras atm.:
    grabber = Screen('OpenVideoCapture', win, deviceId, roi, depth, [], [], moviename, recordingflags, 3);

    % We refrain from setting target fps here, as such cameras do have a fixed fps. Instead
    % we use the "do what you think is right" 'realmax' joker.
    Screen('StartVideoCapture', grabber, realmax, 1);

    dstRect = [];
    oldpts = 0;
    vcount = 0;
    scount = 0;
    t=GetSecs;

    % Run for at most 600 seconds or until keypress:
    while (GetSecs - t) < 600
        if KbCheck(-1)
            break;
        end

        [tex, pts, nrdropped, intensity] = Screen('GetCapturedImage', win, grabber, 0); %#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 && (vcount == 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);
                fprintf('Video image size is %i x %i pixels.\n', RectWidth(texrect), RectHeight(texrect));
            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 - t), 0, 20, 255);
            if vcount > 0
                % Compute delta:
                delta = (pts - oldpts) * 1000;
                oldpts = pts;
                Screen('DrawText', win, sprintf('%.4f', delta), 0, 40, 255);
            end

            % Show it.
            Screen('Close', tex);
            vcount = vcount + 1;
        end

        Screen('FillRect', win, 1, [0 0 mod(scount, RectWidth(winrect)), 10]);
        Screen('Flip', win, [], 1);
        scount = scount + 1;
    end

    telapsed = GetSecs - t %#ok<NOPRT>

    Screen('StopVideoCapture', grabber);
    Screen('CloseVideoCapture', grabber);

    sca;
    avgvfps = vcount / telapsed;
    avgsfps = scount / telapsed;
    fprintf('Average fps video feed: %f , stimulation %f\n', avgvfps, avgsfps);
catch %#ok<CTCH>
    sca;
end