Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 27.09 KB | None | 0 0
  1. {  vfp -- pascal units for support of video for linux devices
  2.    Version 0.5b
  3.    Copyright (C) 1999-2002  Stefan Ziegenbalg
  4.  
  5.    This program is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU General Public License
  7.    as published by the Free Software Foundation; either version
  8.    2 of the License, or (at your option) any later version.
  9.  
  10.    This software is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public
  16.    License along with this program; if not, write to the
  17.    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  18.    Boston, MA  02111-1307, USA.
  19. !}
  20.  
  21. unit videodev;
  22.  
  23. {$PACKRECORDS C}
  24.  
  25. //define[_IOC_NRBITS][8];
  26. //define[_IOC_TYPEBITS][8];
  27. //define[_IOC_SIZEBITS][14];
  28. //define[_IOC_DIRBITS][2];
  29.  
  30. //define[_IOC_NRSHIFT][0]
  31. //define[_IOC_TYPESHIFT][(_IOC_NRSHIFT+_IOC_NRBITS)]
  32. //define[_IOC_SIZESHIFT][(_IOC_TYPESHIFT+_IOC_TYPEBITS)]
  33. //define[_IOC_DIRSHIFT][(_IOC_SIZESHIFT+_IOC_SIZEBITS)]
  34.  
  35. //define[_IOC(][,#1,#2,#3);][((#0 shl _IOC_DIRSHIFT) or (#1 shl _IOC_TYPESHIFT) or (#2 shl _IOC_NRSHIFT) or (#3 shl _IOC_SIZESHIFT))]
  36.  
  37. //define[_IOW(][,#1,#2)][_IOC(1,ord('#0'),#1,sizeof(#2));]
  38. //define[_IOR(][,#1,#2)][_IOC(2,ord('#0'),#1,sizeof(#2));]
  39. //define[_IOWR(][,#1,#2)][_IOC(3,ord('#0'),#1,sizeof(#2));]
  40.  
  41.  
  42. { *********************************************************************** }
  43. { ******* INTERFACE ***************************************************** }
  44. { *********************************************************************** }
  45. interface
  46.  
  47. { ******* video_capability ******************************************* }
  48. const VID_TYPE_CAPTURE    = 1;       { Can capture }
  49.       VID_TYPE_TUNER      = 2;       { Can tune }
  50.       VID_TYPE_TELETEXT   = 4;       { Does teletext }
  51.       VID_TYPE_OVERLAY    = 8;       { Overlay onto frame buffer }
  52.       VID_TYPE_CHROMAKEY  = 16;      { Overlay by chromakey }
  53.       VID_TYPE_CLIPPING   = 32;      { Can clip }
  54.       VID_TYPE_FRAMERAM   = 64;      { Uses the frame buffer memory }
  55.       VID_TYPE_SCALES     = 128;     { Scalable }
  56.       VID_TYPE_MONOCHROME = 256;     { Monochrome only }
  57.       VID_TYPE_SUBCAPTURE = 512;     { Can capture subareas of the image }
  58.  
  59. type video_capability = record
  60.         name      : array[0..31] of char;
  61.         typ       : longint;     { see VID_TYPE_* }
  62.         channels  : longint;     { Number of  channels }
  63.         audios    : longint;     { Number of audio devices }
  64.         maxwidth  : longint;     { Supported width }
  65.         maxheight : longint;     { Supported height }
  66.         minwidth  : longint;     { Supported width }
  67.         minheight : longint;     { Supported height }
  68.         end;
  69.  
  70. procedure get_video_capability(fd:longint; var vc:video_capability);   { fd : file descriptor }
  71. function vid_type_str(i:longint):string;
  72.  
  73. { ******* video_channel ********************************************** }
  74. const VIDEO_VC_TUNER    = 1;   { Channel has a tuner }
  75.       VIDEO_VC_AUDIO    = 2;   { Channel has audio }
  76.       VIDEO_TYPE_TV     = 1;
  77.       VIDEO_TYPE_CAMERA = 2;
  78.       VIDEO_MODE_PAL    = 0;
  79.       VIDEO_MODE_NTSC   = 1;
  80.       VIDEO_MODE_SECAM  = 2;
  81.       VIDEO_MODE_AUTO   = 3;
  82.  
  83. type video_channel = record
  84.         channel : longint;
  85.         name    : array[0..31] of char;
  86.         tuners  : longint;
  87.         flags   : dword;        { see VIDEO_VC_* }
  88.         typ     : word;         { see VIDEO_TYPE_* }
  89.         norm    : word;         { Norm set by channel, see VIDEO_MODE_* }
  90.         end;
  91.  
  92. procedure get_video_channel(fd,c:longint; var vc:video_channel);     { fd : file decsriptor, c:channel }
  93. procedure set_video_channel(fd:longint; var vc:video_channel);       { fd : file descriptor }
  94. function video_vc_str(i:longint):string;
  95. function video_type_str(i:longint):string;
  96. function video_mode_str(i:longint):string[15];
  97.  
  98. { ******* video_tuner ************************************************ }
  99. const VIDEO_TUNER_PAL       = 1;
  100.       VIDEO_TUNER_NTSC      = 2;
  101.       VIDEO_TUNER_SECAM     = 4;
  102.       VIDEO_TUNER_LOW       = 8;      { Uses KHz not MHz }
  103.       VIDEO_TUNER_NORM      = 16;     { Tuner can set norm }
  104.       VIDEO_TUNER_STEREO_ON = 128;    { Tuner is seeing stereo }
  105.       VIDEO_TUNER_RDS_ON    = 256;    { Tuner is seeing an RDS datastream }
  106.       VIDEO_TUNER_MBS_ON    = 512;    { Tuner is seeing an MBS datastream }
  107.  
  108. type video_tuner = record
  109.        tuner              : longint;
  110.        name               : array[0..31] of char;
  111.        rangelow,rangehigh : dword;    { Tuner range }
  112.        flags              : dword;    { see VIDEO_TUNER_* }
  113.        mode               : word;     { see VIDEO_MODE_* }
  114.        signal             : word;     { Signal strength 16bit scale }
  115.        end;
  116.  
  117. procedure get_video_tuner(fd,c:longint; var t:video_tuner); { fd : file decsriptor, c : tuner }
  118. procedure set_video_tuner(fd:longint; var t:video_tuner);   { fd : file descriptor }
  119. function video_tuner_str(i:longint):string;
  120. procedure setfreq(fd:longint; f:dword);                     { fd : file descriptor, f : frequency }
  121. function getfreq(fd:longint):dword;                         { fd : file descriptor, result : frequency }
  122.  
  123. { ******* video_picture *********************************************** }
  124. const VIDEO_PALETTE_GREY      = 1;      { Linear greyscale }
  125.       VIDEO_PALETTE_HI240     = 2;      { High 240 cube (BT848) }
  126.       VIDEO_PALETTE_RGB565    = 3;      { 565 16 bit RGB }
  127.       VIDEO_PALETTE_RGB24     = 4;      { 24bit RGB }
  128.       VIDEO_PALETTE_RGB32     = 5;      { 32bit RGB }
  129.       VIDEO_PALETTE_RGB555    = 6;      { 555 15bit RGB }
  130.       VIDEO_PALETTE_YUV422    = 7;      { YUV422 capture }
  131.       VIDEO_PALETTE_YUYV      = 8;
  132.       VIDEO_PALETTE_UYVY      = 9;      { The great thing about standards is ... }
  133.       VIDEO_PALETTE_YUV420    = 10;
  134.       VIDEO_PALETTE_YUV411    = 11;     { YUV411 capture }
  135.       VIDEO_PALETTE_RAW       = 12;     { RAW capture (BT848) }
  136.       VIDEO_PALETTE_YUV422P   = 13;     { YUV 4:2:2 Planar }
  137.       VIDEO_PALETTE_YUV411P   = 14;     { YUV 4:1:1 Planar }
  138.       VIDEO_PALETTE_YUV420P   = 15;     { YUV 4:2:0 Planar }
  139.       VIDEO_PALETTE_YUV410P   = 16;     { YUV 4:1:0 Planar }
  140.       VIDEO_PALETTE_PLANAR    = 13;     { start of planar entries }
  141.       VIDEO_PALETTE_COMPONENT = 7;      { start of component entries }
  142.  
  143. type video_picture=record
  144.        brightness : word;
  145.        hue        : word;
  146.        colour     : word;
  147.        contrast   : word;
  148.        whiteness  : word;    { b/w only }
  149.        depth      : word;    { capture depth }
  150.        palette    : word;    { see VIDEO_PALETTE_* }
  151.        end;
  152.  
  153. procedure get_video_picture(fd:longint; var vp:video_picture);   { fd : file descriptor }
  154. procedure set_video_picture(fd:longint; var vp:video_picture);   { fd : file descriptor }
  155. function video_palette_str(i:longint):string[15];
  156.  
  157.  
  158. { ******* video_audio *********************************************** }
  159. const VIDEO_AUDIO_MUTE = 1;
  160.       VIDEO_AUDIO_MUTABLE = 2;
  161.       VIDEO_AUDIO_VOLUME = 4;
  162.       VIDEO_AUDIO_BASS = 8;
  163.       VIDEO_AUDIO_TREBLE = 16;
  164.       VIDEO_SOUND_MONO = 1;
  165.       VIDEO_SOUND_STEREO = 2;
  166.       VIDEO_SOUND_LANG1 = 4;
  167.       VIDEO_SOUND_LANG2 = 8;
  168.  
  169. type video_audio = record
  170.        audio       : longint;     { audio channel }
  171.        volume      : word;        { if settable }
  172.        bass,treble : word;
  173.        flags       : dword;       { see VIDEO_AUDIO }
  174.        name        : array[0..15] of char;
  175.        mode        : word;        { see VIDEO_SOUND }
  176.        balance     : word;        { Stereo balance }
  177.        step        : word;        { Step actual volume uses }
  178.        end;
  179.  
  180. procedure get_video_audio(fd:longint; var va:video_audio);   { fd : file descriptor }
  181. procedure set_video_audio(fd:longint; var va:video_audio);   { fd : file descriptor }
  182. function video_audio_str(i:longint):string[15];
  183. function video_sound_str(i:longint):string[15];
  184.  
  185. { ******* video_windows *********************************************** }
  186. const VIDEO_WINDOW_INTERLACE = 1;
  187.       VIDEO_CLIP_BITMAP      = -1;   { bitmap is 1024x625, a '1' bit represents a clipped pixel }
  188.       VIDEO_CLIPMAP_SIZE     = (128 * 625);
  189.  
  190. type video_clip=record               { clip area }
  191.       x,y          : longint;
  192.       width,height : longint;
  193.       next         : ^video_clip;
  194.       end;
  195.  
  196. type video_window=record
  197.       x,y          : dword;          { Position of window }
  198.       width,height : dword;          { Its size }
  199.       chromakey    : dword;
  200.       flags        : dword;
  201.       clips        : ^video_clip;    { Set only }
  202.       clipcount    : longint;
  203.       end;
  204.  
  205. procedure get_video_window(fd:longint; var w:video_window);   { fd : file descriptor }
  206. procedure set_video_window(fd:longint; var w:video_window);   { fd : file descriptor }
  207.  
  208.  
  209. { ******* video_capture ********************************************* }
  210. const VIDEO_CAPTURE_ODD  = 0;
  211.       VIDEO_CAPTURE_EVEN = 1;
  212.  
  213. type video_capture=record
  214.        x,y          : dword;
  215.        width,height : dword;
  216.        decimation   : word;
  217.        flags        : word;
  218.        end;
  219.  
  220. procedure get_video_capture(fd:longint;var c:video_capture);     { fd : file descriptor }
  221. procedure set_video_capture(fd:longint;var c:video_capture);     { fd : file descriptor }
  222.  
  223. { ******* video_buffer *********************************************** }
  224. type video_buffer=record         { frame buffer of the video card }
  225.         base          : pointer;
  226.         height        : longint;
  227.         width         : longint;
  228.         depth         : longint;
  229.         bytesperline  : longint;
  230.         end;
  231.  
  232. procedure get_video_buffer(fd:longint;var vb:video_buffer); { fd : file descriptor }
  233. procedure set_video_buffer(fd:longint;var vb:video_buffer); { fd : file descriptor }
  234.  
  235. { ******* video_mmap ************************************************* }
  236. type video_mmap = record           { for grabbing one frame }
  237.        frame        : longint;     { frame to grab (0 - video_mbuf.frames-1) }
  238.        height,width : longint;     { image size }
  239.        format       : longint;     { see VIDEO_PALETTE_* }
  240.        end;
  241.  
  242. procedure grab_video_mmap(fd:longint; mmap:video_mmap);    { fd : file descriptor}
  243.  
  244. { ******* video_key ************************************************** }
  245. type video_key = record
  246.       key   : array[0..7] of byte;
  247.       flags : dword;
  248.       end;
  249.  
  250. procedure get_video_key(fd:longint; key:video_key);
  251.  
  252. { ******* video_mbuf ************************************************* }
  253. const VIDEO_MAX_FRAME = 32;
  254.  
  255. type video_mbuf = record        { info about the mmap memory for grabbing }
  256.        size    : longint;       { total memory to map }
  257.        frames  : longint;       { frames }
  258.        offsets : array[0..VIDEO_MAX_FRAME-1] of longint;
  259.        end;
  260.  
  261. procedure get_video_mbuf(fd:longint; var mb:video_mbuf);   { fd : file descriptor }
  262.  
  263. { ******* video_unit ************************************************* }
  264. type video_unit = record
  265.       video    : longint;   { Video minor }
  266.       vbi      : longint;   { VBI minor }
  267.       radio    : longint;   { Radio minor }
  268.       audio    : longint;   { Audio minor }
  269.       teletext : longint;   { Teletext minor }
  270.       end;
  271.  
  272. procedure get_video_unit(fd:longint; var vu:video_unit);   { fd : file descriptor }
  273.  
  274. { ******* video ioctl comands **************************************** }
  275. const
  276. { vfp class     } { declaration                                     } { description }
  277. {---------------------------------------------------------------------------------- }
  278. { CVideo        } VIDIOCGCAP     = _IOR(v,1,video_capability);        { Get capabilities }
  279. { CVFPP_channel } VIDIOCGCHAN    = _IOWR(v,2,video_channel);          { Get channel info (sources) }
  280. { CVFPP_channel } VIDIOCSCHAN    = _IOW(v,3,video_channel);           { Set channel }
  281. { CVFPP_tuner   } VIDIOCGTUNER   = _IOWR(v,4,video_tuner);            { Get tuner abilities }
  282. { CVFPP_tuner   } VIDIOCSTUNER   = _IOW(v,5,video_tuner);             { Tune the tuner for the current channel }
  283. { CVFPP_grab    } VIDIOCGPICT    = _IOR(v,6,video_picture);           { Get picture properties }
  284. { CVFPP_grab    } VIDIOCSPICT    = _IOW(v,7,video_picture);           { Set picture properties }
  285. { CVFPP_overlay } VIDIOCCAPTURE  = _IOW(v,8,longint);                 { Start, stop overlay }
  286. { CFFPP_window  } VIDIOCGWIN     = _IOR(v,9,video_window);            { Set the video overlay window }
  287. { CVFPP_window  } VIDIOCSWIN     = _IOW(v,10,video_window);           { Set the video overlay window - passes clip list for hardware smarts , chromakey etc }
  288. { CVFPP_overlay } VIDIOCGFBUF    = _IOR(v,11,video_buffer);           { Get frame buffer (of graphic card for for overlaying) }
  289. { CVFPP_overlay } VIDIOCSFBUF    = _IOW(v,12,video_buffer);           { Set frame buffer (of graphic card for overlaying) - root only }
  290.  
  291.                   VIDIOCKEY      = _IOR(v,13,video_key);              { Video key event - to dev 255 is to all - cuts capture on all DMA windows with this key (0xFFFFFFFF == all) }
  292.                   VIDIOCGFREQ    = _IOR(v,14,dword);                  { Get tuner }
  293.                   VIDIOCSFREQ    = _IOW(v,15,dword);                  { Set tuner }
  294.                   VIDIOCGAUDIO   = _IOR(v,16,video_audio);            { Get audio info }
  295.                   VIDIOCSAUDIO   = _IOW(v,17,video_audio);            { Audio source, mute etc }
  296. { CVFPP_grab    } VIDIOCSYNC     = _IOW(v,18,longint);                { Sync with mmap grabbing }
  297. { CVFPP_grab    } VIDIOCMCAPTURE = _IOW(v,19,video_mmap);             { Grab frames via mmap }
  298. { CVFPP_grab    } VIDIOCGMBUF    = _IOR(v,20,video_mbuf);             { Memory map (mmap) buffer info }
  299. { CVideo        } VIDIOCGUNIT    = _IOR(v,21,video_unit);             { Get attached units }
  300. { CVFPP_capture } VIDIOCGCAPTURE = _IOR(v,22,video_capture);          { Get capture params }
  301. { CVFPP_capture } VIDIOCSCAPTURE = _IOW(v,23,video_capture);          { Set capture params}
  302.  
  303.  
  304. procedure video_sync(fd:longint;frame:longint);           { fd: file descriptor; frame: frame (0 - video.mbuf-1) for wait }
  305. procedure video_startoverlay(fd:longint);                 { fd: file descriptor }
  306. procedure video_stopoverlay(fd:longint);                  { fd: file descriptor }
  307.  
  308. { ******* video_mmbuf ************************************************ }
  309. type video_mmbuf = record
  310.        map     : ^byte;     { pointer to mapped memory }
  311.        size    : longint;   { rest like video_mbuf }
  312.        frames  : longint;
  313.        offsets : array[0..VIDEO_MAX_FRAME-1] of dword;
  314.        end;
  315.  
  316. procedure get_video_mmbuf(fd:longint; var mmb:video_mmbuf);         { fd : file descriptor; get the mapped memory }
  317. procedure free_video_mmbuf(var mmb:video_mmbuf);
  318.  
  319. { ******* error routines ************************************************ }
  320. var videodev_error,videodev_warning : procedure(s:ansistring);      { error routines; s : error message }
  321.  
  322.  
  323. { *********************************************************************** }
  324. { ******* IMPLEMENTATION ************************************************ }
  325. { *********************************************************************** }
  326. implementation
  327. uses
  328. {$ifdef VER0}
  329. linux
  330. {$else}
  331. {$ifdef VER1_0}
  332. linux
  333. {$else}
  334. unix
  335. {$endif}
  336. {$endif}
  337. ;
  338.  
  339. { ******* error routines ************************************************ }
  340. procedure stdwarning(s:ansistring);
  341. begin
  342. writeln(stderr,'Warning: ',s);
  343. end;
  344. procedure stderror(s:ansistring);
  345. begin
  346. writeln(stderr,'Error: ',s);
  347. halt(1);
  348. end;
  349.  
  350. { ******* video_capability ******************************************* }
  351. procedure get_video_capability(fd:longint;var vc:video_capability);
  352. begin
  353. if fd<0 then videodev_error('get_video_capability: invalid handle');
  354. if not ioctl(fd,VIDIOCGCAP,@vc) then videodev_error('get_video_capability: ioctl error');
  355. end;
  356.  
  357. function vid_type_str(i:longint):string;
  358. begin
  359. vid_type_str:='';
  360. if i and VID_TYPE_CAPTURE >0 then vid_type_str+=', Capture';
  361. if i and VID_TYPE_TUNER >0 then vid_type_str+=', Tuner';
  362. if i and VID_TYPE_TELETEXT >0 then vid_type_str+=', Teletext';
  363. if i and VID_TYPE_OVERLAY >0 then vid_type_str+=', Overlay';
  364. if i and VID_TYPE_CHROMAKEY >0 then vid_type_str+=', Chromakey';
  365. if i and VID_TYPE_CLIPPING >0 then vid_type_str+=', Clipping';
  366. if i and VID_TYPE_FRAMERAM >0 then vid_type_str+=', FrameRAM';
  367. if i and VID_TYPE_SCALES >0 then vid_type_str+=', Scales';
  368. if i and VID_TYPE_MONOCHROME >0 then vid_type_str+=', Monochrome';
  369. if i and VID_TYPE_SUBCAPTURE >0 then vid_type_str+=', Subcapture';
  370. if length(vid_type_str)>1 then delete(vid_type_str,1,2)
  371.     else vid_type_str:='Unknown';
  372. end;
  373.  
  374. { ******* video_channel ********************************************** }
  375. procedure get_video_channel(fd,c:longint;var vc:video_channel);
  376. begin
  377. if fd<0 then videodev_error('get_video_channel: invalid handle');
  378. vc.channel:=c;
  379. if not ioctl(fd,VIDIOCGCHAN,@vc) then videodev_error('get_video_channel: ioctl error');
  380. end;
  381. procedure set_video_channel(fd:longint;var vc:video_channel);
  382. begin
  383. if fd<0 then videodev_error('set_video_channel: invalid handle');
  384. if not ioctl(fd,VIDIOCSCHAN,@vc) then videodev_warning('set_video_channel: ioctl error');
  385. end;
  386.  
  387. function video_vc_str(i:longint):string;
  388. begin
  389. video_vc_str:='';
  390. if i and VIDEO_VC_TUNER>0 then video_vc_str+=', Tuner';
  391. if i and VIDEO_VC_AUDIO>0 then video_vc_str+=', Audio';
  392. if length(video_vc_str)>1 then delete(video_vc_str,1,2)
  393.     else video_vc_str:='Unknown';
  394. end;
  395.  
  396. function video_type_str(i:longint):string;
  397. begin
  398. video_type_str:='';
  399. if i and VIDEO_TYPE_TV>0 then video_type_str+=', TV';
  400. if i and VIDEO_TYPE_CAMERA>0 then video_type_str+=', Camera';
  401. if length(video_type_str)>1 then delete(video_type_str,1,2)
  402.     else video_type_str:='Unknown';
  403. end;
  404.  
  405. function video_mode_str(i:longint):string[15];
  406. begin
  407. video_mode_str:='Unknown';
  408. case i of
  409.  VIDEO_MODE_PAL   : video_mode_str:='PAL';
  410.  VIDEO_MODE_NTSC  : video_mode_str:='NTSC';
  411.  VIDEO_MODE_SECAM : video_mode_str:='SECAM';
  412.  VIDEO_MODE_AUTO  : video_mode_str:='AUTO';
  413.  end;
  414. end;
  415.  
  416. { ******* video_tuner ********************************************** }
  417. procedure get_video_tuner(fd,c:longint;var t:video_tuner);
  418. begin
  419. if fd<0 then videodev_error('get_video_tuner: invalid handle');
  420. t.tuner:=c;
  421. if not ioctl(fd,VIDIOCGTUNER,@t) then videodev_error('get_video_tuner: ioctl error');
  422. end;
  423. procedure set_video_tuner(fd:longint;var t:video_tuner);
  424. begin
  425. if fd<0 then videodev_error('set_video_tuner: invalid handle');
  426. if not ioctl(fd,VIDIOCSTUNER,@t) then videodev_warning('set_video_tuner: ioctl error');
  427. end;
  428.  
  429. function video_tuner_str(i:longint):string;
  430. begin
  431. video_tuner_str:='';
  432. if i and VIDEO_TUNER_PAL >0 then video_tuner_str:=', PAL';
  433. if i and VIDEO_TUNER_NTSC >0 then video_tuner_str:=', NTSC';
  434. if i and VIDEO_TUNER_SECAM >0 then video_tuner_str:=', SECAM';
  435. if i and VIDEO_TUNER_LOW >0 then video_tuner_str:=', Low';
  436. if i and VIDEO_TUNER_NORM >0 then video_tuner_str:=', Norm';
  437. if i and VIDEO_TUNER_STEREO_ON >0 then video_tuner_str:=', Stereo';
  438. if i and VIDEO_TUNER_RDS_ON >0 then video_tuner_str:=', RDS';
  439. if i and VIDEO_TUNER_MBS_ON >0 then video_tuner_str:=', MBS';
  440. if length(video_tuner_str)>1 then delete(video_tuner_str,1,2)
  441.     else video_tuner_str:='Unknown';
  442. end;
  443.  
  444. procedure setfreq(fd:longint; f:dword);
  445. begin
  446. if fd<0 then videodev_error('setfreq: invalid handle');
  447. if not ioctl(fd,VIDIOCSFREQ,@f) then videodev_warning('setfreq: ioctl error');
  448. end;
  449. function getfreq(fd:longint):dword;
  450. var f : dword;
  451. begin
  452. if fd<0 then videodev_error('getfreq: invalid handle');
  453. if not ioctl(fd,VIDIOCGFREQ,@f) then videodev_warning('getfreq: ioctl error');
  454. getfreq:=f;
  455. end;
  456.  
  457. { ******* video_picture ********************************************** }
  458. procedure get_video_picture(fd:longint; var vp:video_picture);
  459. begin
  460. if fd<0 then videodev_error('get_video_picture: invalid handle');
  461. if not ioctl(fd,VIDIOCGPICT,@vp) then videodev_error('get_video_picture: ioctl error');
  462. end;
  463. procedure set_video_picture(fd:longint; var vp:video_picture);
  464. begin
  465. if fd<0 then videodev_error('set_video_picture: invalid handle');
  466. if not ioctl(fd,VIDIOCSPICT,@vp) then videodev_warning('set_video_picture: ioctl error');
  467. end;
  468.  
  469. function video_palette_str(i:longint):string[15];
  470. begin
  471. video_palette_str:='Unknown';
  472. case i of
  473.   VIDEO_PALETTE_GREY    : video_palette_str:='GREY';
  474.   VIDEO_PALETTE_HI240   : video_palette_str:='HI240';
  475.   VIDEO_PALETTE_RGB565  : video_palette_str:='RGB565';
  476.   VIDEO_PALETTE_RGB24   : video_palette_str:='RGB24';
  477.   VIDEO_PALETTE_RGB32   : video_palette_str:='RGB32';
  478.   VIDEO_PALETTE_RGB555  : video_palette_str:='RGB555';
  479.   VIDEO_PALETTE_YUV422  : video_palette_str:='YUV422';
  480.   VIDEO_PALETTE_YUYV    : video_palette_str:='YUYV';
  481.   VIDEO_PALETTE_UYVY    : video_palette_str:='UYVY';
  482.   VIDEO_PALETTE_YUV420  : video_palette_str:='YUV420';
  483.   VIDEO_PALETTE_YUV411  : video_palette_str:='YUV411';
  484.   VIDEO_PALETTE_RAW     : video_palette_str:='RAW';
  485.   VIDEO_PALETTE_YUV422P : video_palette_str:='YUV422P';
  486.   VIDEO_PALETTE_YUV411P : video_palette_str:='YUV411P';
  487.   VIDEO_PALETTE_YUV420P : video_palette_str:='YUV420P';
  488.   VIDEO_PALETTE_YUV410P : video_palette_str:='YUV410P';
  489.   end;
  490. end;
  491.  
  492. { ******* video_audio ************************************************ }
  493. procedure get_video_audio(fd:longint; var va:video_audio);
  494. begin
  495. if fd<0 then videodev_error('get_video_audio: invalid handle');
  496. if not ioctl(fd,VIDIOCGAUDIO,@va) then videodev_error('get_video_audio: ioctl error');
  497. end;
  498. procedure set_video_audio(fd:longint; var va:video_audio);
  499. begin
  500. if fd<0 then videodev_error('set_video_audio: invalid handle');
  501. if not ioctl(fd,VIDIOCSAUDIO,@va) then videodev_warning('set_video_audio: ioctl error');
  502. end;
  503.  
  504. function video_audio_str(i:longint):string[15];
  505. begin
  506. video_audio_str:='';
  507. if i and VIDEO_AUDIO_MUTE>0 then video_audio_str+=', MUTE';
  508. if i and VIDEO_AUDIO_MUTABLE>0 then video_audio_str+=', MUTABLE';
  509. if i and VIDEO_AUDIO_VOLUME>0 then video_audio_str+=', VOLUME';
  510. if i and VIDEO_AUDIO_BASS>0 then video_audio_str+=', BASS';
  511. if i and VIDEO_AUDIO_TREBLE>0 then video_audio_str+=', TREBLE';
  512. if length(video_audio_str)>1 then delete(video_audio_str,1,2);
  513. end;
  514.  
  515. function video_sound_str(i:longint):string[15];
  516. begin
  517. video_sound_str:='';
  518. if i and VIDEO_SOUND_MONO>0 then video_SOUND_str+=', Mono';
  519. if i and VIDEO_SOUND_STEREO>0 then video_SOUND_str+=', Stereo';
  520. if i and VIDEO_SOUND_LANG1>0 then video_SOUND_str+=', Lang1';
  521. if i and VIDEO_SOUND_LANG2>0 then video_SOUND_str+=', Lang2';
  522. if length(video_SOUND_str)>1 then delete(video_SOUND_str,1,2);
  523. end;
  524.  
  525. { ******* video_window ********************************************** }
  526. procedure get_video_window(fd:longint; var w:video_window);
  527. begin
  528. if fd<0 then videodev_error('get_video_window: invalid handle');
  529. if not ioctl(fd,VIDIOCGWIN,@w) then videodev_error('get_video_window: ioctl error');
  530. end;
  531. procedure set_video_window(fd:longint; var w:video_window);
  532. begin
  533. if fd<0 then videodev_error('set_video_window: invalid handle');
  534. if not ioctl(fd,VIDIOCSWIN,@w) then videodev_warning('set_video_window: ioctl error');
  535. end;
  536.  
  537. { ******* video_capture ********************************************** }
  538. procedure get_video_capture(fd:longint; var c:video_capture);
  539. begin
  540. if fd<0 then videodev_error('get_video_capture: invalid handle');
  541. if not ioctl(fd,VIDIOCGCAPTURE,@c) then videodev_error('get_video_capture: ioctl error');
  542. end;
  543. procedure set_video_capture(fd:longint; var c:video_capture);
  544. begin
  545. if fd<0 then videodev_error('set_video_capture: invalid handle');
  546. if not ioctl(fd,VIDIOCSCAPTURE,@c) then videodev_warning('set_video_capture: ioctl error');
  547. end;
  548.  
  549. { ******* video_buffer *********************************************** }
  550. procedure get_video_buffer(fd:longint;var vb:video_buffer);
  551. begin
  552. if fd<0 then videodev_error('get_video_buffer: invalid handle');
  553. if not ioctl(fd,VIDIOCGFBUF,@vb) then videodev_error('get_video_buffer: ioctl error');
  554. end;
  555. procedure set_video_buffer(fd:longint;var vb:video_buffer);
  556. begin
  557. if fd<0 then videodev_error('set_video_buffer: invalid handle');
  558. if not ioctl(fd,VIDIOCSFBUF,@vb) then videodev_warning('set_video_buffer: ioctl error');
  559. end;
  560.  
  561. { ******* video_mmap ************************************************* }
  562. procedure grab_video_mmap(fd:longint; mmap:video_mmap);
  563. begin
  564. if fd<0 then videodev_error('grab_video_mmap: invalid handle');
  565. if not ioctl(fd,VIDIOCMCAPTURE,@mmap) then videodev_warning('grab_video_mmap: ioctl error');
  566. end;
  567.  
  568. { ******* video_key ************************************************** }
  569. procedure get_video_key(fd:longint; key:video_key);
  570. begin
  571. if fd<0 then videodev_error('get_video_key: invalid handle');
  572. if not ioctl(fd,VIDIOCKEY,@key) then videodev_warning('get_video_key: ioctl error');
  573. end;
  574.  
  575. { ******* video_mbuf ************************************************* }
  576. procedure get_video_mbuf(fd:longint; var mb:video_mbuf);
  577. begin
  578. if fd<0 then videodev_error('get_video_mbuf: invalid handle');
  579. if not ioctl(fd,VIDIOCGMBUF,@mb) then videodev_error('get_video_mbuf: ioctl error');
  580. end;
  581.  
  582. { ******* video_sync ************************************************* }
  583. procedure video_sync(fd:longint;frame:longint);
  584. begin
  585. if fd<0 then videodev_error('video_sync: invalid handle');
  586. if not ioctl(fd,VIDIOCSYNC,@frame) then videodev_warning('video_sync: ioctl error');
  587. end;
  588.  
  589. { ******* video_overlay ********************************************** }
  590. procedure video_startoverlay(fd:longint);
  591. var i : longint;
  592. begin
  593. i:=1;
  594. if fd<0 then videodev_error('video_startoverlay: invalid handle');
  595. if not ioctl(fd,VIDIOCCAPTURE,@i) then videodev_warning('video_startoverlay: ioctl error');
  596. end;
  597. procedure video_stopoverlay(fd:longint);
  598. var i : longint;
  599. begin
  600. i:=0;
  601. if fd<0 then videodev_error('video_stopoverlay: invalid handle');
  602. if not ioctl(fd,VIDIOCCAPTURE,@i) then videodev_warning('video_stopoverlay: ioctl error');
  603. end;
  604.  
  605. { ******* get_video_unit ********************************************* }
  606. procedure get_video_unit(fd:longint; var vu:video_unit);
  607. begin
  608. if fd<0 then videodev_error('get_video_unit: invalid handle');
  609. if not ioctl(fd,VIDIOCGUNIT,@vu) then videodev_error('get_video_unit: ioctl error');
  610. end;
  611.  
  612. { ******* video_mmbuf ************************************************ }
  613. procedure get_video_mmbuf(fd:longint;var mmb:video_mmbuf);
  614. var ma  : tmmapargs;
  615. begin
  616. if fd<0 then videodev_error('get_video_mmbuf: invalid handle');
  617. if not ioctl(fd,VIDIOCGMBUF,@mmb.size) then videodev_error('get_video_mmbuf: ioctl error');
  618. if mmb.frames<1 then videodev_warning('get_video_mmbuf: no frames to grab');
  619. if mmb.size<1 then videodev_warning('get_video_mmbuf: no memory to map');
  620. if (mmb.frames>0) and (mmb.size>0)
  621.   then begin
  622.        ma.address:=0;
  623.        ma.size:=mmb.size;
  624.        ma.prot:=prot_read or prot_write;
  625.        ma.flags:=map_shared;
  626.        ma.fd:=fd;
  627.        ma.offset:=0;
  628.        mmb.map:=pointer(mmap(ma));
  629.        end
  630.   else mmb.map:=nil;
  631. if linuxerror<>0 then videodev_error('get_video_mmbuf: mmap failed');
  632. end;
  633.  
  634. procedure free_video_mmbuf(var mmb:video_mmbuf);
  635. begin
  636. if (mmb.size<=0) or (mmb.map=nil) or (not munmap(mmb.map,mmb.size)) then
  637.    videodev_error('free_video_mmbuf: munmap fails');
  638. end;
  639.  
  640.  
  641. begin
  642. videodev_error:=@stderror;
  643. videodev_warning:=@stdwarning;
  644. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement