?? spcav4l.c
字號:
if (vd->formatIn != vd->videopict.palette || vd->bppIn != vd->videopict.depth) exit_fatal ("could't set video palette Abort !"); if (erreur < 0) exit_fatal ("could't set video palette Abort !"); if (vd->grabMethod) { if(debug) printf (" grabbing method default MMAP asked \n"); // MMAP VIDEO acquisition memset (&(vd->videombuf), 0, sizeof (vd->videombuf)); if (ioctl (vd->fd, VIDIOCGMBUF, &(vd->videombuf)) < 0) { perror (" init VIDIOCGMBUF FAILED\n"); } if(debug) printf ("VIDIOCGMBUF size %d frames %d offets[0]=%d offsets[1]=%d\n", vd->videombuf.size, vd->videombuf.frames, vd->videombuf.offsets[0], vd->videombuf.offsets[1]); vd->pFramebuffer = (unsigned char *) mmap (0, vd->videombuf.size, PROT_READ | PROT_WRITE, MAP_SHARED, vd->fd, 0); vd->mmapsize = vd->videombuf.size; vd->vmmap.height = vd->hdrheight; vd->vmmap.width = vd->hdrwidth; vd->vmmap.format = vd->formatIn; for (f = 0; f < vd->videombuf.frames; f++) { vd->vmmap.frame = f; if (ioctl (vd->fd, VIDIOCMCAPTURE, &(vd->vmmap))) { perror ("cmcapture"); } } vd->vmmap.frame = 0; } else { /* read method */ /* allocate the read buffer */ vd->pFramebuffer = (unsigned char *) realloc (vd->pFramebuffer, (size_t) vd->framesizeIn); if(debug) printf (" grabbing method READ asked \n"); if (ioctl (vd->fd, VIDIOCGWIN, &(vd->videowin)) < 0) perror ("VIDIOCGWIN failed \n"); vd->videowin.height = vd->hdrheight; vd->videowin.width = vd->hdrwidth; if (ioctl (vd->fd, VIDIOCSWIN, &(vd->videowin)) < 0) perror ("VIDIOCSWIN failed \n"); if(debug) printf ("VIDIOCSWIN height %d width %d \n", vd->videowin.height, vd->videowin.width); } vd->frame_cour = 0; return erreur;}#if 0staticint probePalette ( struct vdIn *vd ){ /* probe palette and set a default one for unknow cams*/ int pal[] ={VIDEO_PALETTE_JPEG,VIDEO_PALETTE_YUV420P,VIDEO_PALETTE_RGB24,VIDEO_PALETTE_RGB565,VIDEO_PALETTE_RGB32}; struct video_picture pict; int masq = 0x1; int i; int availpal = 0; int defaut = 1; /* initialize the internal struct */ if (ioctl (vd->fd, VIDIOCGPICT, &pict) < 0) { perror ("Couldnt get videopict params with VIDIOCGPICT\n"); return -1; } /* try each palette we have we skip raw_jpeg */ for(i = 0; i < 5 ; i++){ pict.palette = pal[i]; /* maybe correct the bug on qca driver depth always 24 ? */ pict.depth = GetDepth (pal[i]); if(debug) printf("try palette %d depth %d\n",pict.palette,pict.depth); if (ioctl (vd->fd, VIDIOCSPICT, &pict) < 0) { if(debug) printf("Couldnt set palette first try %d \n", pal[i]); } if (ioctl (vd->fd, VIDIOCGPICT, &pict) < 0) { if(debug) printf("Couldnt get palette %d \n", pal[i]); } if (pict.palette != pal[i]){ if(debug) printf("Damned second try fail \n"); } else { availpal = availpal | masq ; if(debug) printf("Available palette %d \n", pal[i]); if (defaut){ defaut = 0; //vd->formatIn = pal[i]; // vd->bppIn = GetDepth (pal[i]); } } masq = masq << 1; } vd->palette = availpal; //should set default palette here ? return 1; }staticint probeSize ( struct vdIn *vd ){ /* probe size and set a default one for unknow cams */ int size[] = { 640,480,384,288,352,288,320,240,192,144,176,144,160,120 }; struct video_window win; int maxw,minw,maxh,minh; int masq = 0x1; int i = 0; int defaut = 1 ; /* initialize de parameters */ maxw = vd->videocap.maxwidth; minw = vd->videocap.minwidth; maxh = vd->videocap.maxheight; minh = vd->videocap.minheight; if(debug) printf("probe size in \n"); while (size[i] > maxw){ if(debug) printf("skip size %d x %d\n",size[i],size[i+1]); i += 2; masq = masq << 1; if (i > 13) break; } /* initialize the internal struct */ if (ioctl (vd->fd, VIDIOCGWIN, &win) < 0) { perror ("VIDIOCGWIN failed \n"); return -1; } /* now i is on the first possible width */ while ((size[i] >= minw) && i < 13) { win.width = size[i]; win.height = size[i+1]; if (ioctl (vd->fd, VIDIOCSWIN, &win) < 0) { if(debug) printf ("VIDIOCSWIN reject width %d height %d \n", win.width, win.height); } else { vd->sizeothers = vd->sizeothers | masq; if(debug) printf ("Available Resolutions width %d heigth %d \n", win.width, win.height); if (defaut) { // vd->hdrwidth = win.width; // vd->hdrheight = win.height; defaut = 0; } } masq = masq << 1 ; i += 2; } return 1; }#endifintchangeSize (struct vdIn *vd){ int erreur; erreur = GetVideoPict (vd); vd->formatIn = vd->videopict.palette; vd->bppIn = vd->videopict.depth; /* To Compute the estimate frame size perhaps not need !!! */ if ((vd->bppIn = GetDepth (vd->formatIn)) < 0) { perror ("getdepth failed \n"); exit (1); } if (vd->grabMethod) { vd->vmmap.height = vd->hdrheight; vd->vmmap.width = vd->hdrwidth; vd->vmmap.format = vd->formatIn; } else { if (ioctl (vd->fd, VIDIOCGWIN, &vd->videowin) < 0) perror ("VIDIOCGWIN failed \n"); vd->videowin.height = vd->hdrheight; vd->videowin.width = vd->hdrwidth; if (ioctl (vd->fd, VIDIOCSWIN, &vd->videowin) < 0) perror ("VIDIOCSWIN failed \n"); if(debug) printf ("VIDIOCGWIN height %d width %d \n", vd->videowin.height, vd->videowin.width); } vd->framesizeIn = ((vd->hdrwidth * vd->hdrheight * vd->bppIn) >> 3);return 0;}#if 0/* return masq byte for the needed size */static int convertsize( int width, int height){ switch (width){ case 640: if(height == 480) return VGA; break; case 384: if(height == 288) return PAL; break; case 352: if(height == 288) return SIF; break; case 320: if(height == 240) return CIF; break; case 192: if(height == 144) return QPAL; break; case 176: if(height == 144) return QSIF; break; case 160: if(height == 120) return QCIF; break; default: break; } return -1;}static int sizeconvert( int *width, int *height, int size){ switch (size){ case VGA: *height = 480; *width = 640; break; case PAL: *height = 288; *width = 384; break; case SIF: *height = 288; *width = 352; break; case CIF: *height = 240; *width = 320; break; case QPAL: *height = 144; *width = 192; break; case QSIF: *height = 144; *width = 176; break; case QCIF: *height = 120; *width = 160; break; default: return -1; break; } return 0;}static int convertpalette( int palette){ switch (palette){ case VIDEO_PALETTE_JPEG: return JPG; break; case VIDEO_PALETTE_YUV420P: return YUV420P; break; case VIDEO_PALETTE_RGB24: return RGB24; break; case VIDEO_PALETTE_RGB565: return RGB565; break; case VIDEO_PALETTE_RGB32: return RGB32; break; default: break; } return -1;}static int paletteconvert( int code){ switch (code){ case JPG: return VIDEO_PALETTE_JPEG; break; case YUV420P: return VIDEO_PALETTE_YUV420P; break; case RGB24: return VIDEO_PALETTE_RGB24; break; case RGB565: return VIDEO_PALETTE_RGB565; break; case RGB32: return VIDEO_PALETTE_RGB32; break; default: return -1; break; } return 0;}/*check palette not so easy try VIDIOCMCAPTURE IOCTL the only one with palette and size *//* some drivers may fail here */static int checkpalette (struct vdIn *vd){ unsigned char masq = 0x00; int needpalette = 0; int palette =0; needpalette = convertpalette(vd->formatIn); /* is the palette available */ if (!(vd->palette & needpalette)){ /* find an other one */ if(needpalette >1){ masq = needpalette -1; } if (( masq & vd->palette) > 1){ /* check lower masq upper size */ while (!((needpalette = needpalette >> 1) & vd->palette) && needpalette); } else if ((masq & vd->palette) == 0){ masq = 0xff -(needpalette << 1) +1; if ((masq & vd->palette) == 0){ /* no more size available */ needpalette = 0; } else { /* check upper masq */ while (!((needpalette = needpalette << 1) & vd->palette) && needpalette); } } // maybe == 1 } if ((palette = paletteconvert( needpalette)) < 0){ if(debug) printf("Invalid palette in check palette fatal !! \n"); return -1; } if (palette){ vd->vmmap.height = vd->hdrheight; vd->vmmap.width = vd->hdrwidth; vd->vmmap.format = palette; vd->vmmap.frame = 0; if (ioctl (vd->fd, VIDIOCMCAPTURE, &(vd->vmmap))) { perror ("cmcapture"); return -1; } } else { if(debug) printf("palette not find check palette fatal !! \n"); return -1; } /*populate the change */ vd->formatIn = palette;return palette; }/* test is palette and size are available otherwhise return the next available palette and size palette is set by preference order jpeg yuv420p rbg24 rgb565 and rgb32 */static int check_palettesize(struct vdIn *vd ){ int needsize = 0; int needpalette = 0; unsigned char masq = 0x00; /* initialize needed size */ if ((needsize = convertsize(vd->hdrwidth,vd->hdrheight)) < 0){ if(debug) printf( "size seem unavailable fatal errors !!\n"); return -1; } /* is there a match with available palette */ /* check */ if (!(vd->sizeothers & needsize)){ if (needsize > 1){ masq = needsize -1; } if (( masq & vd->sizeothers) > 1){ /* check lower masq upper size */ while (!((needsize = needsize >> 1) & vd->sizeothers) && needsize); } else if ((masq & vd->sizeothers) == 0){ masq = 0xff -(needsize << 1) +1; if ((masq & vd->sizeothers) == 0){
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -