
#? *** Simple Video Capture Demos


(libload "video4linux/v4l")

#? (v4l-demo-rgb <in> <width> <height>)
;; monitors NTSC video captured from /dev/video on
;; on a Lush graphic screen.
;; <in> is the card's input from which the video
;; will be captured (=1 for composite input, 
;; =2 for S-video input on some bttv cards).
;;.CODE
;;  (v4l-demo-rgb 1 320 240)
;;.P
;; bug: the function must be interrupted with CTRL-C.
;;.P
;; feature: the function is 6 lines of lush.
(de v4l-demo-rgb (in swidth sheight)
  (when (not window) (new-window))
  (let* ((bg (ubyte-matrix sheight swidth 3))
	 (vdev (new v4ldevice "/dev/video" "NTSC" in swidth sheight)))
    (while t
      (==> vdev grab-into-rgb bg)
      (rgb-draw-matrix 2 2 bg))))

;; same as above, but capture into an RGBA image
(de v4l-demo-rgba (in swidth sheight)
  (when (not window) (new-window))
  (let* ((bg (ubyte-matrix sheight swidth 4))
	 (vdev (new v4ldevice "/dev/video" "NTSC" in swidth sheight)))
    (while t
      (==> vdev grab-into-rgba bg 255)
      (rgb-draw-matrix 2 2 bg))))


#? (v4l-demo2 <in1> <in2> <width> <height>)
;; play captured videos on a Lush graphic screen
;; from two video source simultaneously.
;; This assumes that two video capture devices
;; are present in the computer.
;; <in1> and <in2> are the card's inputs from which the videos
;; will be captured (=2 for S-video input on some bttv cards).
;;.CODE
;;  (v4l-demo2 2 2 320 240)
;;.P
;; bug: the function must be interrupted with CTRL-C.
(de v4l-demo2 (in1 in2 swidth sheight)
  (when (not window) (new-window))
  (let* ((im0 (ubyte-matrix sheight swidth 4))
	 (im1 (ubyte-matrix sheight swidth 4))
	 (vdev0 (new v4ldevice "/dev/video0" "NTSC" in1 swidth sheight))
	 (vdev1 (new v4ldevice "/dev/video1" "NTSC" in2 swidth sheight)))
    (while t
      (==> vdev0 grab-into-rgba im0 255)
      (==> vdev1 grab-into-rgba im1 255)
      (graphics-batch
       (rgb-draw-matrix 10 10 im0)
       (rgb-draw-matrix 10 (+ 20 sheight) im1)))))
