[Okvm-cvs] okvm/tools README.vidSource,NONE,1.1 vidSource.c,NONE,1.1 vidSource.h,NONE,1.1 Makefile,1
Status: Pre-Alpha
Brought to you by:
david-m
|
From: David M. <da...@us...> - 2006-05-24 07:05:09
|
Update of /cvsroot/okvm/okvm/tools In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv7894/tools Modified Files: Makefile Added Files: README.vidSource vidSource.c vidSource.h Log Message: vidSource adds a tool which uses the vloopback kernel module to provide a V4L device which cycles through solid red, green and blue. It can change resolution and color depth on command. It still needs work, but it works and it helped me. Scott Burns <sb...@ii...> Index: Makefile =================================================================== RCS file: /cvsroot/okvm/okvm/tools/Makefile,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Makefile 4 Nov 2005 12:18:04 -0000 1.1.1.1 --- Makefile 24 May 2006 07:05:04 -0000 1.2 *************** *** 14,18 **** LIBS += $(CXXLIBS) ! PROGRAMS = scan kbtest vidreg okvm-vidmode all: $(PROGRAMS) --- 14,18 ---- LIBS += $(CXXLIBS) ! PROGRAMS = scan kbtest vidreg okvm-vidmode vidSource all: $(PROGRAMS) *************** *** 38,41 **** --- 38,44 ---- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ vidreg.c $(LDLIBS) + vidSource: vidSource.c vidSource.h + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ vidSource.c $(LDLIBS) -lm + $(REALVNC_LIBS): $(MAKE) -C $(VNCDIR) --- NEW FILE: README.vidSource --- This program is designed to be used with the vloopback kernel driver. It can be used to testing the graphics section of OKVM. Initially, a fake graphics device is set up with 32bpp at 1120x840 pixels. Each second the color of the pixels with cycle through the three basic colors of red, blue and green. 32bpp, 24bpp and 16bpp have been tested. 15bpp has not. Neither 8, nor any of the more exotic depths are supported at all at this time. A shared memory section is also set up. This contains two integers representing depth and resolution. Both are enumerated types, although resolution is set to (n+1)*112 pixels wide. Resolutions are currently always 4:3 aspect ratio. The four depths are 15, 16, 24 and 32bpp, represented with zero through three respectively. Future versions should support command line options for initial depth and resolution, custom resolutions, different aspect ratios, runtime adjustments via stdin, variable update times (currently one frame per second), insertion of text into the picture, and different image adjustments in addition to R->G->B->R. --- NEW FILE: vidSource.c --- /* vidSource.c: * * Modified from resize.c distributed in cloopback package: * Example program for videoloopback device. * Copyright 2000 by Jeroen Vreeken (pe...@am...) * Copyright 2005 by Angel Carpintero (ac...@te...) * This software is distributed under the GNU public license version 2 * See also the file 'COPYING'. * * Simple program to open a loopback source, and every second * to change the picture to diferent color. Also supports * resizing and changing color depth on request depth via a * shared memory segment. * */ #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <string.h> #include <errno.h> #include <sys/ioctl.h> #include <sys/mman.h> #include <sys/shm.h> #include <signal.h> #include <sys/wait.h> #include <linux/videodev.h> #include <math.h> #include "vidSource.h" static int bpps[] = { 15, 16, 24, 32, 0 }; SHMSTRUCT * request; int curBpp = 3; int curRes = 9; static int formats[] = { VIDEO_PALETTE_RGB555, VIDEO_PALETTE_RGB565, VIDEO_PALETTE_RGB24, VIDEO_PALETTE_RGB32, 0 }; static int resolutions[] = { 112, 224, 336, 448, 560, 672, 784, 896, 1008, 1120, 0 }; unsigned char * framebuffer = NULL; int fbsize; // attach to shared memory int init_mem() { int shmid; // SBSBSB error checks shmid = shmget( SHMKEY, sizeof( SHMSTRUCT ), 0666 | IPC_CREAT ); if( shmid == -1 ) { fprintf( stderr, "Unable to find shared memory segment\n" ); exit( errno ); } request = (SHMSTRUCT *)shmat( shmid, 0, 0 ); // Seriously - why does a memory allocator return -1 on error // and not NULL? if( (int)request == -1 ) { fprintf( stderr, "Unable to attach to shared memory segment\n" ); exit( errno ); } request->depth = curBpp; request->res = curRes; return 0; } int check_mem(int dev) { int i; if( request->depth != curBpp || request->res != curRes ) { for( i = 0;i < request->depth;i++ ) { if( bpps[i] == 0 ) { fprintf( stderr, "Invalid depth requested - %d\n", request->depth ); request->depth = curBpp; } } for( i = 0;i < request->res;i++ ) { if( resolutions[i] == 0 ) { fprintf( stderr, "Invalid depth requested - %d\n", request->depth ); request->depth = curRes; } } if( request->depth != curBpp || request->res != curRes ) { start_pipe( dev ); } } return 0; } int start_pipe (int dev) { struct video_capability vid_caps; struct video_window vid_win; struct video_picture vid_pic; int pixSize; int i; int resx; int resy; int bpp; unsigned char * cp; curBpp = request->depth; curRes = request->res; printf( "Starting pipe %d %d\n", curBpp, curRes ); pixSize = (int)ceil( bpps[curBpp] / 8.0 ); bpp = formats[curBpp]; resx = resolutions[curRes]; resy = (resx * 3 ) / 4; if (ioctl (dev, VIDIOCGCAP, &vid_caps) == -1) { printf ("ioctl (VIDIOCGCAP)\nError[%s]\n",strerror(errno)); return (1); } if (ioctl (dev, VIDIOCGPICT, &vid_pic)== -1) { printf ("ioctl VIDIOCGPICT\nError[%s]\n",strerror(errno)); return (1); } vid_pic.palette = bpp; if (ioctl (dev, VIDIOCSPICT, &vid_pic)== -1) { printf ("ioctl VIDIOCSPICT\nError[%s]\n",strerror(errno)); return (1); } if (ioctl (dev, VIDIOCGWIN, &vid_win)== -1) { printf ("ioctl VIDIOCGWIN"); return (1); } vid_win.width = resx; vid_win.height = resy; // this always errors but still works ioctl (dev, VIDIOCSWIN, &vid_win); if( framebuffer ) { free( framebuffer ); } printf( "Mallocing %d\n", pixSize * resx * resy ); framebuffer = malloc( pixSize * resx * resy ); if( framebuffer == NULL ) { fprintf( stderr, "Unable to allocate memory\n" ); exit( errno ); } cp = framebuffer; printf( "Running through %d at %d bpp\n", resx * resy, curBpp ); for( i = 0; i < resx * resy;i++ ) { switch( curBpp ) { case 3: *cp++ = 0x00; case 2: *cp++ = 0x00; *cp++ = 0xff; *cp++ = 0x00; break; case 1: case 0: *cp++ = 0xf8; *cp++ = 0x00; break; default: break; } } printf( "Ran through %d\n", (int)cp - (int)framebuffer ); return 0; } int put_image(int dev ) { int pixSize = ceil( bpps[curBpp] / 8.0 ); int resx = resolutions[curRes]; int resy = ( resx * 3 ) / 4; int i; unsigned char temp; unsigned char * cp = framebuffer; for( i = 0; i < resx * resy;i++ ) { switch( curBpp ) { case 3: case 2: temp = *cp; *cp = *(cp + 1 ); *(cp+1) = *(cp + 2 ); *(cp+2) = temp; cp+=pixSize; break; case 1: // RGB565 temp = *cp >> 3; // R *cp = *cp << 5; *cp |= (*(cp+1) & 0xc0 ) >> 3; // G *cp |= (*(cp+1) & 0x1c ) >> 2; cp++; *cp = (*cp & 0x03) << 6; // Copy the last bit from the second last *cp |= *cp & 0x01 << 5; // B *cp |= temp; cp++; break; case 0: // RGB555 temp = *cp >> 2; // R *cp = *cp << 5; *cp |= (*(cp+1) & 0xc0 ) >> 3; // G *cp |= (*(cp+1) & 0x1c ) >> 2; cp++; *cp = *cp & 0x03 << 6; // B *cp |= temp; break; default: // SBSBSB break; } } printf( "Writing %d\n", pixSize * resx * resy ); write( dev, framebuffer, pixSize * resx * resy ); return 1; } int main (int argc, char **argv) { int devout; if (argc != 2) { printf("Usage:\n\n"); printf("vidSource <device>\n\n"); printf("example: vidSource /dev/video0\n\n"); exit(1); } devout=open (argv[1], O_RDWR); if (devout < 0) { printf ("Failed to open video device%s \nError[%s]\n",argv[1],strerror(errno)); exit(1); } init_mem(); if( start_pipe(devout) ) exit(0); while ( 1 ) { put_image( devout ); printf( "%d %d\n", curBpp, curRes ); sleep( 1 ); check_mem(devout); } close (devout); exit(0); } --- NEW FILE: vidSource.h --- /* vidSource.h: * * Copyright 2006 by Scott Burns (sb...@ii...) * This software is distributed under the GNU public license version 2 * See also the file 'COPYING'. * * Simple program to open a loopback source, and every second * to change the picture to diferent color. Also supports * resizing and changing color depth on request depth via a * shared memory segment. * */ #ifndef __H_VID_SOURCE_H__ #define __H_VID_SOURCE_H__ typedef struct shmstruct { int depth; int res; } SHMSTRUCT; #define SHMKEY 0x1234 int init_mem( void ); int check_mem( int ); int start_pipe( int ); int put_image( int ); #endif |