Code: Select all
#ifndef __VIDEODEV_BI
#define __VIDEODEV_BI
'#if defined (CONFIG_VIDEO_V4L1_COMPAT)
enum VIDEO_CAPS
CAN_CAPTURE = 1 /' Can capture '/
CAN_TUNER = 2 /' Can tune '/
CAN_TELETEXT = 4 /' Does teletext '/
CAN_OVERLAY = 8 /' Overlay onto frame buffer '/
CAN_CHROMAKEY = 16 /' Overlay by chromakey '/
CAN_CLIPPING = 32 /' Can clip '/
CAN_FRAMERAM = 64 /' Uses the frame buffer memory '/
CAN_SCALES = 128 /' Scalable '/
CAN_MONOCHROME = 256 /' Monochrome only '/
CAN_SUBCAPTURE = 512 /' Can capture subareas of the image '/
CAN_MPEG_DECODER = 1024 /' Can decode MPEG streams '/
CAN_MPEG_ENCODER = 2048 /' Can encode MPEG streams '/
CAN_MJPEG_DECODER = 4096 /' Can decode MJPEG streams '/
CAN_MJPEG_ENCODER = 8192 /' Can encode MJPEG streams '/
end enum
type video_capability
as ubyte name(0 to 31)
as VIDEO_CAPS type
as integer channels /' Num channels '/
as integer audios /' Num audio devices '/
as integer maxwidth
as integer maxheight
as integer minwidth
as integer minheight
end type
#define VIDEO_VC_TUNER 1 /' Channel has a tuner '/
#define VIDEO_VC_AUDIO 2 /' Channel has audio '/
#define VIDEO_TYPE_TV 1
#define VIDEO_TYPE_CAMERA 2
type video_channel
as integer channel
as string * 31 name
as integer tuners
as uinteger flags
as ushort type
as ushort norm /' Norm set by channel '/
end type
#define VIDEO_TUNER_PAL 1
#define VIDEO_TUNER_NTSC 2
#define VIDEO_TUNER_SECAM 4
#define VIDEO_TUNER_LOW 8 /' Uses KHz not MHz '/
#define VIDEO_TUNER_NORM 16 /' Tuner can set norm '/
#define VIDEO_TUNER_STEREO_ON 128 /' Tuner is seeing stereo '/
#define VIDEO_TUNER_RDS_ON 256 /' Tuner is seeing an RDS datastream '/
#define VIDEO_TUNER_MBS_ON 512 /' Tuner is seeing an MBS datastream '/
#define VIDEO_MODE_PAL 0
#define VIDEO_MODE_NTSC 1
#define VIDEO_MODE_SECAM 2
#define VIDEO_MODE_AUTO 3
type video_tuner
as integer tuner
as string * 31 name
as ulong rangelow /' Tuner range '/
as ulong rangehigh
as uinteger flags
as ushort mode /' PAL/NTSC/SECAM/OTHER '/
as ushort signal /' Signal strength 16bit scale '/
end type
#define VIDEO_PALETTE_GREY 1 /' Linear greyscale '/
#define VIDEO_PALETTE_HI240 2 /' High 240 cube (BT848) '/
#define VIDEO_PALETTE_RGB565 3 /' 565 16 bit RGB '/
#define VIDEO_PALETTE_RGB24 4 /' 24bit RGB '/
#define VIDEO_PALETTE_RGB32 5 /' 32bit RGB '/
#define VIDEO_PALETTE_RGB555 6 /' 555 15bit RGB '/
#define VIDEO_PALETTE_YUV422 7 /' YUV422 capture '/
#define VIDEO_PALETTE_YUYV 8
#define VIDEO_PALETTE_UYVY 9 /' The great thing about standards is ... '/
#define VIDEO_PALETTE_YUV420 10
#define VIDEO_PALETTE_YUV411 11 /' YUV411 capture '/
#define VIDEO_PALETTE_RAW 12 /' RAW capture (BT848) '/
#define VIDEO_PALETTE_YUV422P 13 /' YUV 4:2:2 Planar '/
#define VIDEO_PALETTE_YUV411P 14 /' YUV 4:1:1 Planar '/
#define VIDEO_PALETTE_YUV420P 15 /' YUV 4:2:0 Planar '/
#define VIDEO_PALETTE_YUV410P 16 /' YUV 4:1:0 Planar '/
#define VIDEO_PALETTE_PLANAR 13 /' start of planar entries '/
#define VIDEO_PALETTE_COMPONENT 7 /' start of component entries '/
type video_picture
as ushort brightness
as ushort hue
as ushort colour
as ushort contrast
as ushort whiteness /' Black and white only '/
as ushort depth /' Capture depth '/
as ushort palette /' Palette in use '/
end type
#define VIDEO_AUDIO_MUTE 1
#define VIDEO_AUDIO_MUTABLE 2
#define VIDEO_AUDIO_VOLUME 4
#define VIDEO_AUDIO_BASS 8
#define VIDEO_AUDIO_TREBLE 16
#define VIDEO_AUDIO_BALANCE 32
#define VIDEO_SOUND_MONO 1
#define VIDEO_SOUND_STEREO 2
#define VIDEO_SOUND_LANG1 4
#define VIDEO_SOUND_LANG2 8
type video_audio
as integer audio /' Audio channel '/
as ushort volume /' If settable '/
as ushort bass
as ushort treble
as uinteger flags
as string * 15 name
as ushort mode
as ushort balance /' Stereo balance '/
as ushort step /' Step actual volume uses '/
end type
type video_clip
as integer x
as integer y
as integer width
as integer height
as video_clip ptr next /' For user use/driver use only '/
end type
#define VIDEO_WINDOW_INTERLACE 1
#define VIDEO_WINDOW_CHROMAKEY 16 /' Overlay by chromakey '/
#define VIDEO_CLIP_BITMAP -1
/' bitmap is 1024x625, a '1' bit represents a clipped pixel '/
#define VIDEO_CLIPMAP_SIZE (128 * 625)
type video_window
as uinteger x,y /' Position of window '/
as uinteger width,height /' Its size '/
as uinteger chromakey
as uinteger flags
as video_clip ptr clips /' Set only '/
as integer clipcount
end type
#define VIDEO_CAPTURE_ODD 0 /' Temporal '/
#define VIDEO_CAPTURE_EVEN 1
type video_capture
as uinteger x /' Offsets into image '/
as uinteger y' sub macro
as uinteger width /' Area to capture '/
as uinteger height
as ushort decimation /' Decimation divider '/
as ushort flags /' Flags for capture '/
end type
type video_buffer
as any ptr base
as integer height
as integer width
as integer depth
as integer bytesperline
end type
type video_mmap
as uinteger frame /' Frame (0 - n) for double buffer '/
as integer height,width
as uinteger format /' should be VIDEO_PALETTE_* '/
end type
type video_key
as ubyte key(8-1)
as uinteger flags
end type
type video_mbuf
as integer size /' Total memory to map '/
as integer frames /' Frames '/
as integer offsets(0 to 31)
end type
#define VIDEO_NO_UNIT (-1)
type video_unit
as integer video /' Video minor '/
as integer vbi /' VBI minor '/
as integer radio /' Radio minor '/
as integer audio /' Audio minor '/
as integer teletext /' Teletext minor '/
end type
#define VBI_UNSYNC 1 /' can distingues between top/bottom field '/
#define VBI_INTERLACED 2 /' lines are interlaced '/
type vbi_format
as uinteger sampling_rate /' in Hz '/
as uinteger samples_per_line
as uinteger sample_format /' VIDEO_PALETTE_RAW only (1 byte) '/
as integer start(2-1) /' starting line for each frame '/
as uinteger count(2-1) /' count of lines for each frame '/
as uinteger flags
end type
/' video_info is biased towards hardware mpeg encode/decode '/
/' but it could apply generically to any hardware compressor/decompressor '/
type video_info
as uinteger frame_count /' frames output since decode/encode began '/
as uinteger h_size /' current unscaled horizontal size '/
as uinteger v_size /' current unscaled veritcal size '/
as uinteger smpte_timecode /' current SMPTE timecode (for current GOP) '/
as uinteger picture_type /' current picture type '/
as uinteger temporal_reference /' current temporal reference '/
as ubyte user_data(256-1) /' user data last found in compressed stream '/
/' user_data[0-1) contains user data flags, user_data[1-1) has count '/
end type
/' generic structure for setting playback modes '/
type video_play_mode
as integer mode
as integer p1
as integer p2
end type
/' for loading microcode / fpga programming '/
type video_code
as string * 15 loadwhat /' name or tag of file being passed '/
as integer datasize
as ubyte ptr data
end type
const VIDIOCGCAP = &H803C7601
const VIDIOCGCHAN = &HC0307602
const VIDIOCSCHAN = &H40307603
const VIDIOCGTUNER = &HC0347604
const VIDIOCSTUNER = &H40347605
const VIDIOCGPICT = &H800E7606
const VIDIOCSPICT = &H400E7607
const VIDIOCCAPTURE = &H40047608
const VIDIOCGWIN = &H80207609
const VIDIOCSWIN = &H4020760A
const VIDIOCGFBUF = &H8014760B
const VIDIOCSFBUF = &H4014760C
const VIDIOCKEY = &H800C760D
const VIDIOCGFREQ = &H8004760E
const VIDIOCSFREQ = &H4004760F
const VIDIOCGAUDIO = &H80287610
const VIDIOCSAUDIO = &H40287611
const VIDIOCSYNC = &H40047612
const VIDIOCMCAPTURE = &H40107613
const VIDIOCGMBUF = &H80887614
const VIDIOCGUNIT = &H80147615
const VIDIOCGCAPTURE = &H80147616
const VIDIOCSCAPTURE = &H40147617
const VIDIOCSPLAYMODE = &H400C7618
const VIDIOCSWRITEMODE = &H40047619
const VIDIOCGPLAYINFO = &H8118761A
const VIDIOCSMICROCODE = &H4018761B
const VIDIOCGVBIFMT = &H8020761C
const VIDIOCSVBIFMT = &H4020761D
#define BASE_VIDIOCPRIVATE 192 /' 192-255 are private '/
/' VIDIOCSWRITEMODE '/
#define VID_WRITE_MPEG_AUD 0
#define VID_WRITE_MPEG_VID 1
#define VID_WRITE_OSD 2
#define VID_WRITE_TTX 3
#define VID_WRITE_CC 4
#define VID_WRITE_MJPEG 5
/' VIDIOCSPLAYMODE '/
#define VID_PLAY_VID_OUT_MODE 0
/' p1: = VIDEO_MODE_PAL, VIDEO_MODE_NTSC, etc ... '/
#define VID_PLAY_GENLOCK 1
/' p1: 0 = OFF, 1 = ON '/
/' p2: GENLOCK FINE DELAY value '/
#define VID_PLAY_NORMAL 2
#define VID_PLAY_PAUSE 3
#define VID_PLAY_SINGLE_FRAME 4
#define VID_PLAY_FAST_FORWARD 5
#define VID_PLAY_SLOW_MOTION 6
#define VID_PLAY_IMMEDIATE_NORMAL 7
#define VID_PLAY_SWITCH_CHANNELS 8
#define VID_PLAY_FREEZE_FRAME 9
#define VID_PLAY_STILL_MODE 10
#define VID_PLAY_MASTER_MODE 11
#define VID_PLAY_ACTIVE_SCANLINES 12
/' p1: see below '/
#define VID_PLAY_MASTER_NONE 1
#define VID_PLAY_MASTER_VIDEO 2
#define VID_PLAY_MASTER_AUDIO 3
/' p1 = first active p2 = last active '/
#define VID_PLAY_RESET 13
#define VID_PLAY_END_MARK 14
#define VID_HARDWARE_BT848 1
#define VID_HARDWARE_QCAM_BW 2
#define VID_HARDWARE_PMS 3
#define VID_HARDWARE_QCAM_C 4
#define VID_HARDWARE_PSEUDO 5
#define VID_HARDWARE_SAA5249 6
#define VID_HARDWARE_AZTECH 7
#define VID_HARDWARE_SF16MI 8
#define VID_HARDWARE_RTRACK 9
#define VID_HARDWARE_ZOLTRIX 10
#define VID_HARDWARE_SAA7146 11
#define VID_HARDWARE_VIDEUM 12 /' Reserved for Winnov videum '/
#define VID_HARDWARE_RTRACK2 13
#define VID_HARDWARE_PERMEDIA2 14 /' Reserved for Permedia2 '/
#define VID_HARDWARE_RIVA128 15 /' Reserved for RIVA 128 '/
#define VID_HARDWARE_PLANB 16 /' PowerMac motherboard video-in '/
#define VID_HARDWARE_BROADWAY 17 /' Broadway project '/
#define VID_HARDWARE_GEMTEK 18
#define VID_HARDWARE_TYPHOON 19
#define VID_HARDWARE_VINO 20 /' SGI Indy Vino '/
#define VID_HARDWARE_CADET 21 /' Cadet radio '/
#define VID_HARDWARE_TRUST 22 /' Trust FM Radio '/
#define VID_HARDWARE_TERRATEC 23 /' TerraTec ActiveRadio '/
#define VID_HARDWARE_CPIA 24
#define VID_HARDWARE_ZR36120 25 /' Zoran ZR36120/ZR36125 '/
#define VID_HARDWARE_ZR36067 26 /' Zoran ZR36067/36060 '/
#define VID_HARDWARE_OV511 27
#define VID_HARDWARE_ZR356700 28 /' Zoran 36700 series '/
#define VID_HARDWARE_W9966 29
#define VID_HARDWARE_SE401 30 /' SE401 USB webcams '/
#define VID_HARDWARE_PWC 31 /' Philips webcams '/
#define VID_HARDWARE_MEYE 32 /' Sony Vaio MotionEye cameras '/
#define VID_HARDWARE_CPIA2 33
#define VID_HARDWARE_VICAM 34
#define VID_HARDWARE_SF16FMR2 35
#define VID_HARDWARE_W9968CF 36
#define VID_HARDWARE_SAA7114H 37
#define VID_HARDWARE_SN9C102 38
#define VID_HARDWARE_ARV 39
'#endif /' CONFIG_VIDEO_V4L1_COMPAT '/
#endif /' __VIDEODEV_BI '/
Code: Select all
'' v4l1device.bi
'
#include "fbgfx.bi"
#include "videodev.bi"
#macro ESI_888_2_EDI_555(o1,o2,o3)
xor ah,ah
mov bh,ah
mov al,[esi+o1]
shr al,3
mov bl,[esi+o2]
and bl,&H1F
shl bx,3
mov ah,[esi+o3]
and ah,&HF1
or ax,bx
mov [edi],ax
#endmacro
#macro ESI_565_2_EDI_555()
mov ax,[esi]
mov bx,ax
and ax,&h001F
and bx,&HFFE0
shr bx,1
or ax,bx
mov [edi],ax
#endmacro
#macro ESI_555_2_EDI_888(o1,o2,o3)
mov dx,[esi]
mov al,dl
shl al,3
mov [edi+o1],al
shr dx,2
and dl,&F8
mov [edi+o2],dl
shl dh,3
mov [edi+o3],dh
#endmacro
#macro ESI_565_2_EDI_888(o1,o2,o3)
mov dx,[esi]
mov al,dl
shl al,3
shr dx,3
mov [edi+o1],al
and dl,&FE
shl dh,3
mov [edi+o2],dl
mov [edi+o3],dh
#endmacro
#macro ESI_888_2_565(o1,o2,o3)
mov ax,[esi+o1]
mov dl,[esi+o3]
shr ah,2
and dl,&HF1
shr ax,3
or ah,dl
mov [edi],ax
#endmacro
type V4L1DEVICE
declare constructor
declare constructor(byval strDevice as string)
declare destructor
declare function Name as string
declare function hDevice as integer
declare function IsError as integer
declare function LastError as string
' get sets device string delaut="/dev/video0"
declare property Device (v as string)
declare property Device as string
' get / set curent mode
declare property Mode as integer
declare property Mode (v as integer)
' get number of enumerated modes
declare function Modes as integer
' get size of Mode(n) for i=0 to .Modes-1
declare function ModeWidth (FromMode as Integer) as integer
declare function ModeHeight(FromMode as Integer) as integer
' get curent size
declare function CurentWidth as integer
declare function CurentHeight as integer
' get min and max supported size
declare function MinWidth as integer
declare function MinHeight as integer
declare function MaxWidth as integer
declare function MaxHeight as integer
' must be in range of ushort 0-65535
declare property brightness (v as integer)
declare property brightness as integer
declare property hue (v as integer)
declare property hue as integer
declare property colour (v as integer)
declare property colour as integer
declare property contrast (v as integer)
declare property contrast as integer
' only for older b/w devices
declare property whiteness (v as integer)
declare property whiteness as integer
' must be conected before capture
declare sub Connect
declare sub Disconnect
' capture in fbgfx Image
declare sub FillImage(UserImage as FB.Image ptr)
' screenres w,h,32 ' or 15,16,24
' create Image with the right size
' dim as any ptr Image1=CreateImage(MyDev.CurentWidth,MyDev.CurentWidth)
' .FillImage Image1
' put (x,y),Image1, pset (or or xor trans,alpha, alpha value ...)
'#############################
' internal private interface
'#############################
private:
const _READ as integer = 3
const _OPEN as integer = 5
const _CLOSE as integer = 6
const _IOCTL as integer = 54
const O_RDONLY as integer = 0
const EAGAIN as integer =-11
const EBUSY as integer =-16
const ENDEV as integer =-19
declare function DeviceOpen(DevName as string) as integer
declare function IOCTL(io_cmd as integer, _
lpArg as any ptr) as integer
declare function DeviceRead(lpBuffer as any ptr, _
Buffersize as integer) as integer
declare function DeviceClose as integer
declare function Palette_2_BPP(v as integer) as integer
declare sub Rangei(byref v as integer,lo as integer,hi as integer)
declare sub Colorspace(depth as integer,palette as integer)
declare sub Enumerate
declare sub GetChnParams
declare sub SetChnParams
declare sub GetPicParams
declare sub SetPicParams
declare sub GetWinParams
declare sub SetWinParams
declare sub AllocBuffer
as integer m_hDevice
as string m_Device
as string m_Name
as integer m_IsOpen
as integer m_IsError
as string m_LastError
as any ptr m_lpBuffer
as integer m_BufferSize
as video_capability m_Cap
as video_picture m_Pic
as video_channel m_Chn
as video_window m_Win
as video_window ptr ptr m_lpModes
as integer m_Modes
as integer m_CurMode
end type
' close the V4L1 device
destructor V4L1DEVICE
Disconnect
if m_Modes>0 then
if m_lpModes<>0 then
for i as integer =0 to m_Modes-1
if m_lpModes[i]<>0 then deallocate m_lpModes[i]
next
deallocate m_lpModes
m_lpModes=0
end if
end if
if m_lpBuffer<>0 then
deallocate m_lpBuffer
m_lpBuffer=0
end if
end destructor
constructor V4L1DEVICE(byval strDevice as string="/dev/video0")
m_Device=strDevice
enumerate ' getparams
end constructor
constructor V4L1DEVICE
'm_Device="/dev/bttv" ' my tv card
m_Device="/dev/video0" ' my webcam
enumerate ' getparams
end constructor
function V4L1DEVICE.DeviceOpen(Dev as string) as integer
dim as integer retCode
if m_IsOpen then return m_hDevice ' !!!
asm
mov eax, _OPEN
mov ebx, [Dev]
xor ecx,ecx ' [flag]
xor edx,edx ' [Mode]
int &H80
mov [retCode],eax
end asm
if retCode<0 then
m_IsOpen=0
else
m_IsOpen=1
end if
return retCode
end function
function V4L1DEVICE.IOCTL (io_cmd as integer, _
lpArg as any ptr) as integer
if m_IsOpen=0 then return -1
dim as integer hDev=m_hDevice
asm
mov eax, _IOCTL
mov ebx, [hDev]
mov ecx, [io_cmd]
mov edx, [lpArg]
int &H80
mov [function],eax
end asm
end function
function V4L1DEVICE.DeviceRead(lpBuffer as any ptr, _
Buffersize as integer) as integer
if m_IsOpen=0 then return -1
dim as integer hDev=m_hDevice
asm
mov eax, _READ
mov ebx, [hDev]
mov ecx, [lpBuffer]
mov edx, [Buffersize]
int &H80
mov [function],eax
end asm
end function
function V4L1DEVICE.DeviceClose as integer
if m_IsOpen=0 then return 0
dim as integer hDev=m_hDevice
asm
mov eax, _CLOSE
mov ebx, [hDev]
int &H80
mov [function],eax
end asm
m_IsOpen=0
end function
sub V4L1DEVICE.AllocBuffer
if m_IsOpen=0 then
m_IsError=1
m_LastError="V4L1 error: alloc without connected device !"
if (m_lpBuffer<>0) then
deallocate m_lpBuffer
m_lpBuffer=0
end if
return
end if
dim as integer Bits=palette_2_bpp(m_Pic.Palette)
if (bits<8) then
m_IsError=1:m_LastError="V4L1 error: wrong bpp !"
if (m_lpBuffer<>0) then
deallocate m_lpBuffer
m_lpBuffer=0
end if
return
end if
Bits shr=3
m_BufferSize=m_Win.Width*m_Win.Height*Bits
m_lpBuffer=reallocate(m_lpBuffer,m_BufferSize)
end sub
sub V4L1DEVICE.Enumerate
dim as integer i
if m_IsOpen then beep:exit sub
m_Name=""
m_hDevice=DeviceOpen(m_Device)
if m_hDevice<0 then
m_IsError=1:m_LastError="V4L1 can't open [" & m_Device &"] !"
beep:exit sub
end if
if (ioctl(VIDIOCGCAP,@m_Cap)<0) then
DeviceClose:m_IsError=1
m_LastError="V4L1 can't get 'capture' capabilities!"
beep:exit sub
end if
while m_Cap.name(i)
m_Name=m_Name & chr(m_Cap.name(i)):i+=1
wend
if (m_Cap.type and CAN_CAPTURE)=0 then
DeviceClose:m_IsError=1
m_LastError="V4L1 device [" & m_Name & "] can't capture!"
beep:exit sub
end if
if m_Cap.channels>0 then ioctl(VIDIOCGCHAN ,@m_CHN)
ioctl(VIDIOCGPICT ,@m_PIC)
ioctl(VIDIOCGWIN ,@m_WIN)
dim as video_window tmpwin,list()
i=0
for w as integer=m_Cap.MinWidth to m_Cap.MaxWidth 'step 8
for h as integer=m_Cap.MinHeight to m_Cap.MaxHeight 'step 8
tmpwin.x=0:tmpwin.y=0:tmpwin.width =w:tmpwin.height=h
if ioctl(VIDIOCSWIN ,@tmpwin)=0 then
redim preserve list(i)
list(i)=tmpwin
i+=1
end if
next ' height
next ' width
m_Modes=i
if m_Modes>0 then
m_lpModes=reallocate(m_lpModes,m_Modes*sizeof(video_window ptr))
for i=0 to m_Modes-1
m_lpModes[i]=reallocate(m_lpModes[i],m_Modes*sizeof(video_window))
m_lpModes[i]->x=list(i).x
m_lpModes[i]->y=list(i).y
m_lpModes[i]->width=list(i).width
m_lpModes[i]->height=list(i).height
if (m_Win.x =list(i).x) and _
(m_Win.y =list(i).y) and _
(m_Win.width =list(i).width) and _
(m_Win.height=list(i).height) then m_CurMode=i
next
end if
' restore init mode = curent mode
SetWinParams
DeviceClose
m_IsError=0:m_LastError="V4L1 device [" & m_Name & "] enumerated."
end sub
sub V4L1DEVICE.RangeI(byref v as integer,lo as integer,hi as integer)
if v<lo then
v=lo
elseif v>hi then
v=hi
end if
end sub
function V4L1DEVICE.Palette_2_BPP(v as integer) as integer
select case as const v
case VIDEO_PALETTE_RGB555 : return 15 ' 555 15bit RGB
case VIDEO_PALETTE_RGB565 : return 16 ' 565 16 bit RGB
case VIDEO_PALETTE_RGB24 : return 24 ' 24bit RGB
case VIDEO_PALETTE_RGB32 : return 32 ' 32bit RGB
#if 0
case VIDEO_PALETTE_GREY : return 8 ' Linear greyscale
case VIDEO_PALETTE_HI240 : return 8 ' High 240 cube (BT848)
case VIDEO_PALETTE_YUV422 : return ?? ' YUV422 capture
case VIDEO_PALETTE_YUYV : return 8
case VIDEO_PALETTE_UYVY : return 8
case VIDEO_PALETTE_YUV420 : return 24
case VIDEO_PALETTE_YUV422P : return 24 ' YUV 4:2:2 Planar
case VIDEO_PALETTE_YUV411 : return ?? ' YUV411 capture
case VIDEO_PALETTE_RAW : return ?? ' RAW capture (BT848)
case VIDEO_PALETTE_YUV411P : return ?? ' YUV 4:1:1 Planar
case VIDEO_PALETTE_YUV420P : return ?? ' YUV 4:2:0 Planar
case VIDEO_PALETTE_YUV410P : return ?? ' YUV 4:1:0 Planar
case VIDEO_PALETTE_PLANAR : return ?? ' start of planar entries
#endif
case else
return m_PIC.depth
end select
end function
sub V4L1DEVICE.GetChnParams
if m_IsOpen=0 then
m_IsError=1:m_LastError="V4L1 warning: not connected!"
exit sub
end if
if (ioctl(VIDIOCGCHAN ,@m_CHN)<0) then
m_IsError=1:m_LastError="V4L1 warning: can't get curent channel params!"
else
m_IsError=0:m_LastError="V4L1 got channel params ok"
end if
end sub
sub V4L1DEVICE.SetChnParams
if m_IsOpen=0 then
m_IsError=1:m_LastError="V4L1 warning: not connected!"
exit sub
end if
if (ioctl(VIDIOCSCHAN,@m_CHN)<0) then
m_IsError=1:m_LastError="V4L1 warning: can't set curtent channel params!"
ioctl(VIDIOCGCHAN,@m_PIC)
else
m_IsError=0:m_LastError="V4L1 set channel params ok"
end if
end sub
sub V4L1DEVICE.GetPicParams
if m_IsOpen=0 then
m_IsError=1:m_LastError="V4L1 warning: not connected!"
exit sub
end if
if (ioctl(VIDIOCGPICT,@m_PIC)<0) then
m_IsError=1:m_LastError="V4L1 warning: can't get curent picture params!"
else
m_IsError=0:m_LastError="V4L1 got picture params ok"
end if
end sub
sub V4L1DEVICE.SetPicParams
if m_IsOpen=0 then
m_IsError=1:m_LastError="V4L1 warning: not connected!"
exit sub
end if
if (ioctl(VIDIOCSPICT,@m_PIC)<0) then
m_IsError=1:m_LastError="V4L1 warning: can't set curtent picture params!"
ioctl(VIDIOCGPICT,@m_PIC)
else
m_IsError=0:m_LastError="V4L1 set picture params ok"
end if
end sub
sub V4L1DEVICE.GetWinParams
if m_IsOpen=0 then
m_IsError=1:m_LastError="V4L1 warning: not connected!"
exit sub
end if
if (ioctl(VIDIOCGWIN ,@m_WIN)<0) then
m_IsError=1:m_LastError="V4L1 warning: can't get curent capture window params!"
else
m_IsError=0:m_LastError="V4L1 get capture window params ok"
end if
end sub
sub V4L1DEVICE.SetWinParams
if m_IsOpen=0 then
m_IsError=1:m_LastError="V4L1 warning: not connected!"
exit sub
end if
if (ioctl(VIDIOCSWIN ,@m_WIN)<0) then
m_IsError=1:m_LastError="V4L1 warning: can't set curent capture window params!"
ioctl(VIDIOCGWIN,@m_WIN)
else
m_IsError=0:m_LastError="V4L1 set capture window params ok"
end if
AllocBuffer
end sub
sub V4L1DEVICE.Colorspace(bpp as integer,pal as integer)
m_Pic.Depth=bpp:m_Pic.Palette=pal
SetPicParams
'if m_IsError then sys_ioctl(hDevice,VIDIOCGPICT,@m_PIC)
end sub
'----------------------------
' public interface read only
'----------------------------
function V4L1DEVICE.IsError as integer
function=m_IsError
end function
function V4L1DEVICE.LastError as string
function=m_LastError
end function
function V4L1DEVICE.Name as string
function=m_Name
end function
function V4L1DEVICE.hDevice as integer
function=m_hDevice
end function
function V4L1DEVICE.Modes as integer
function=m_Modes
end function
function V4L1DEVICE.ModeWidth(FromMode as Integer) as integer
if (FromMode<0) or (FromMode>=m_Modes) then
m_IsError=1:m_LastError="V4L1 warning: mode out of range!"
return m_Win.Width
end if
return m_lpModes[FromMode]->Width
end function
function V4L1DEVICE.ModeHeight(FromMode as Integer) as integer
if (FromMode<0) or (FromMode>=m_Modes) then
m_IsError=1:m_LastError="V4L1 warning: mode out of range!"
return m_Win.Height
end if
return m_lpModes[FromMode]->Height
end function
function V4L1DEVICE.CurentWidth as integer
function=m_Win.Width
end function
function V4L1DEVICE.CurentHeight as integer
function=m_Win.Height
end function
function V4L1DEVICE.MinWidth as integer
function=m_Cap.MinWidth
end function
function V4L1DEVICE.MinHeight as integer
function=m_Cap.MinHeight
end function
function V4L1DEVICE.MaxWidth as integer
function=m_Cap.MaxWidth
end function
function V4L1DEVICE.MaxHeight as integer
function=m_Cap.MaxHeight
end function
'---------------------------------
' public interface read and write
'---------------------------------
property V4L1DEVICE.Device as string
property=m_Device
end property
' if your video device are not on /dev/video0 or
' you switch to an other device you can change it
' with dev.Device "/dev/the_other_name"
' NOTE: any open device will be disconnect and closed
' any fbgfx Image as capture target must be recreated
' ImageDestroy Image
' dev.Device="/dev/video1"
' if dev.IsError then print dev.LastError
' Image=ImageCreate(dev.CurentWidth,dev.CurentHeight)
' dev.FillImage Image
property V4L1DEVICE.Device (v as string)
m_Device=v
DeviceClose
Enumerate
end property
sub V4L1DEVICE.Disconnect
if m_IsOpen=0 then return
DeviceClose
end sub
sub V4L1DEVICE.Connect
dim as integer i
if m_IsOpen then
m_IsError=1
m_LastError="V4L1 warning device [" & m_Device &"] allready connected!"
exit sub
end if
m_hDevice=DeviceOpen(m_Device)
if m_IsOpen=0 then
m_IsError=1
m_LastError="V4L1 can't open [" & m_Device &"] !"
else
m_LastError="V4L1 connected to [" & m_Device &"] ok."
m_IsError=0
end if
end sub
property V4L1DEVICE.brightness (v as integer)
rangei(v,0,65355):m_Pic.brightness=v:SetPicParams
end property
property V4L1DEVICE.brightness as integer
GetPicParams:property=m_Pic.brightness
end property
property V4L1DEVICE.hue (v as integer)
rangei(v,0,65355):m_Pic.hue=v:SetPicParams
end property
property V4L1DEVICE.hue as integer
GetPicParams:Property=m_Pic.hue
end property
property V4L1DEVICE.colour (v as integer)
rangei(v,0,65355):m_Pic.colour=v:SetPicParams
end property
property V4L1DEVICE.colour as integer
GetPicParams:Property=m_Pic.colour
end property
property V4L1DEVICE.contrast (v as integer)
rangei(v,0,65355):m_Pic.contrast=v:SetPicParams
end property
property V4L1DEVICE.contrast as integer
GetPicParams:property=m_Pic.contrast
end property
property V4L1DEVICE.whiteness (v as integer)
rangei(v,0,65355):m_Pic.whiteness=v:SetPicParams
end property
property V4L1DEVICE.whiteness as integer
GetPicParams:property=m_Pic.whiteness
end property
property V4L1DEVICE.Mode(NewMode as integer)
if NewMode=m_CurMode then return
if (NewMode < 0) or (NewMode>=m_Modes) then
m_IsError=1
m_LastError="V4L1 warning: mode are out of range!"
return
end if
if m_Isopen=0 then
m_IsError=1
m_LastError="V4L1 warning: must be connected for mode change !"
end if
m_CurMode=NewMode
m_Win.x =m_lpModes[m_CurMode]->x
m_Win.x =m_lpModes[m_CurMode]->y
m_Win.width =m_lpModes[m_CurMode]->width
m_Win.height=m_lpModes[m_CurMode]->height
SetWinParams
end property
property V4L1DEVICE.Mode as integer
property = m_CurMode
end property
sub V4L1DEVICE.FillImage(UserImage as FB.Image ptr)
if m_IsOpen=0 then
m_IsError=1:m_LastError="V4L1 error: must be connected first!"
return
end if
if (m_lpBuffer=0) then
m_IsError=1:m_LastError="V4L1 error: capture buffer not allocated !"
return
end if
if (m_BufferSize=0) then
m_IsError=1:m_LastError="V4L1 error: wrong buffer size=0 !"
return
end if
if UserImage=0 then
m_IsError=1:m_LastError="V4L1 error: image not allocated !"
return
end if
if (UserImage->bpp<2) then
m_IsError=1:m_LastError="V4L1 error: image should be in 15,16,24 or 32 bits !"
return
end if
if UserImage->Width <>m_Win.Width or _
UserImage->Height<>m_Win.Height then
m_IsError=1:m_LastError="V4L1 error: wrong size!"
return
end if
dim bits as integer=Palette_2_BPP(m_pic.palette)
if bits=0 then
m_IsError=1:m_LastError="V4L1 error: wrong bpp!"
return
end if
dim as integer pixels=m_BufferSize\(bits\8)
dim as any ptr des=UserImage
dim as any ptr src=m_lpBuffer
des+=sizeof(FB.Image)
dim as integer readed=DeviceRead(src,m_BufferSize)
if readed<0 then
m_IsError=1:m_LastError="V4L1 error: can't read from device !"
return
end if
if readed<>m_BufferSize then
m_IsError=1:m_LastError="V4L1 warning: should be get =" & m_BufferSize & " bytes but got =" & readed & "!"
return
end if
m_IsError=0
select case bits
case 24
select case UserImage->bpp
case 2
asm
mov ecx,[pixels]
mov esi,[src]
mov edi,[des]
loop24_16:
mov ax,[esi]
shr ah,2
shr ax,3
mov dl,[esi+2]
and dl,&Hf8
or ah,dl
mov [edi],ax
add esi,3
add edi,2
loop loop24_16
end asm
case 4
asm
mov ecx,[pixels]
mov esi,[src]
mov edi,[des]
loop24_32:
mov ax,[esi]
mov [edi],ax
mov al,[esi+2]
mov [edi+2],al
add esi,3
add edi,4
loop loop24_32
end asm
end select
case 32
select case UserImage->bpp
case 2
asm
mov ecx,[pixels]
mov esi,[src]
mov edi,[des]
loop32_16:
mov ax,[esi]
shr ah,2
shr ax,3
mov dl,[esi+2]
and dl,&Hf8
or ah,dl
mov [edi],ax
add esi,4
add edi,2
loop loop32_16
end asm
case 4
asm
mov ecx,[pixels]
mov esi,[src]
mov edi,[des]
loop32_32:
mov eax,[esi]
mov [edi],eax
add esi,4
add edi,4
loop loop32_32
end asm
end select
case else
m_IsError=1
m_LastError= "bits=" & bits & "V4L1 error: not supported in this version!"
end select
end sub
Code: Select all
'#######################
' V4L1DEVICE test01.bas
'#######################
#include "v4l1device.bi"
'
' main
'
dim as V4L1DEVICE MyDevice
with MyDevice
if .IsError then
print .LastError
beep:sleep:end 1
end if
? "name :" & .Name
? "dev :" & .Device
? "min :" & .MinWidth & " x " & .MinHeight
? "max :" & .MaxWidth & " x " & .MaxHeight
? "cur :" & .CurentWidth & " x " & .CurentHeight
? "modes:" & .Modes
for i as integer = 0 to .Modes-1
? "mode[" & i & "]=" & .ModeWidth(i) & " x " & .ModeHeight(i)
next
end With
sleep
' next are 'test02.bas'
Code: Select all
'#######################
' V4L1DEVICE test02.bas
'#######################
#include "v4l1device.bi"
'
' main
'
dim as V4L1DEVICE Dev
dim as any ptr Img
if Dev.IsError then
print Dev.LastError
beep:sleep:end 1
end if
ScreenRes Dev.CurentWidth,Dev.CurentHeight,24
Img=ImageCreate(Dev.CurentWidth,Dev.CurentHeight)
dev.Connect
dev.FillImage Img
put (0,0),Img
sleep
' bsave "test02.bmp"
' next are 'test03.bas'
Code: Select all
'#######################
' V4L1DEVICE test03.bas
'#######################
#include "v4l1device.bi"
'
' main
'
dim as V4L1DEVICE Dev
dim as any ptr Img
dim as integer BigMode
if Dev.IsError then
print Dev.LastError
beep:sleep:end 1
end if
' the device must not be connected to
' get enumerated settings
For m as integer=0 to dev.Modes-1
if dev.ModeWidth(m) =dev.MaxWidth and _
dev.ModeHeight(m)=dev.MaxHeight then
BigMode=m:exit for
end if
next
' NOTE:
' to change any setting the video device
' must be connected first!
dev.Connect
' now we can change any setting
dev.Mode=BigMode
ScreenRes Dev.CurentWidth,Dev.CurentHeight,24
Img=ImageCreate(Dev.CurentWidth,Dev.CurentHeight)
while inkey=""
dev.FillImage Img
put (0,0),Img,PSET
sleep 20
wend
' bsave "test03.bmp"
' next are 'test04.bas'
Code: Select all
'#######################
' V4L1DEVICE test04.bas
'#######################
#include "v4l1device.bi"
'
' main
'
dim as V4L1DEVICE Dev
dim as any ptr Img
dim as integer Frames
dim as integer CurentMode
if Dev.IsError then
print Dev.LastError
beep:sleep:end 1
end if
CurentMode=dev.Mode
ScreenRes Dev.MaxWidth,Dev.MaxHeight,24
Img=ImageCreate(Dev.CurentWidth,Dev.CurentHeight)
dim as integer colour=dev.colour
dev.Connect
while inkey=""
dev.FillImage Img
seenlock:put (0,0),Img,PSET:screenunlock
Frames+=1
if Frames mod 50=0 then
ImageDestroy Img
CurentMode+=1
if CurentMode>=dev.Modes then CurentMode=0
dev.Mode=CurentMode
Img=ImageCreate(Dev.CurentWidth,Dev.CurentHeight)
end if
sleep 20
wend
' bsave "test04.bmp"
' next are 'test05.bas'
Code: Select all
'#######################
' V4L1DEVICE test04.bas
'#######################
#include "v4l1device.bi"
const MAX_IMAGES=100
'
' main
'
dim as V4L1DEVICE Dev
dim as any ptr Images(MAX_IMAGES-1)
dim as integer IRec,IPlay,PlayStep=4
if Dev.IsError then
print Dev.LastError
beep:sleep:end 1
end if
dev.Connect
dev.Mode=dev.Modes\2
ScreenRes Dev.CurentWidth,Dev.CurentHeight,32
Windowtitle ":-)"
for IRec=0 to MAX_IMAGES-1
Images(IRec)=ImageCreate(Dev.CurentWidth,Dev.CurentHeight)
next
IRec=0:IPlay=0
while inkey=""
dev.FillImage Images(IRec mod MAX_IMAGES)
put (0,0),Images(IPlay),pset
put Images(IRec mod MAX_IMAGES),(0,0),Images(IPlay),Alpha,128
IRec +=1
IPlay-=2:if IPlay<0 then IPlay=(MAX_IMAGES-1)+IPlay
sleep 20
wend
' bsave "test05.bmp"