📄 spcaview.c
字号:
0x100; setVideoPict (&videopict, fd); break; case SDLK_c: videopict.colour -= 0x200; // = saturation ? setVideoPict (&videopict, fd); break; case SDLK_s: /* should get the next frame available */ pictFlag = 1; printf ("\nPicture asked\n"); break; case SDLK_v: videopict.colour += 0x200; // = saturation ? setVideoPict (&videopict, fd); break; case SDLK_w: videopict. contrast -= 0x200; // -contrast setVideoPict (&videopict, fd); break; case SDLK_x: videopict. contrast += 0x200; // +contrast setVideoPict (&videopict, fd); break; case SDLK_g: timeDown(fd, &videoparam); //up the frame rate by 10ms break; case SDLK_h: timeUp(fd, &videoparam); //slow the frame rate break; case SDLK_j: spcaSetAutoExpo(fd, &videoparam); //toggle autoexpo break; case SDLK_d: qualityUp(fd, &videoparam); // increase quality break; case SDLK_f: qualityDown(fd, &videoparam); //decrease quality break; case SDLK_l: spcaSwitchLightFrequency(fd, &videoparam); //switch light frequency filter break; case SDLK_q: printf ("\nStop asked\n"); run = 0; break; default: break; } break; case SDL_QUIT: run = 0; break; } } } if (audioout) { SDL_CloseAudioIn(); //stop record printf ("free sound buffer\n"); } if (interval && decodeOn && videoOn){ // set_timer(interval); SDL_SetTimer((Uint32) 0, NULL); } time = SDL_GetTicks () - time; printf ("\nUsed %dms for %d images => %dms/image %dfps.\n", time, framecount, time / framecount, framecount * 1000 / time); printf ("Quiting SDL.\n"); printf ("Decoded frames:%d Average decode time: %f\n", framecount, average_decode_time); if (grabMethod) { printf ("unmapping\n"); munmap (pFramebuffer, mmapsize); } printf ("closing\n"); close (fd); printf ("closed\n"); if (outputfile) { if (!interval) out_fd->fps = (double) framecount *1000 / time; AVI_close (out_fd); printf ("close avi\n"); if (audioout) { SDL_QuitAudioIn(); printf ("free sound buffer\n"); } free (jpegData); free(dpshDest); } pthread_cancel(waitandshoot_id); pthread_join (waitandshoot_id,NULL); pthread_cond_destroy(&mypict.cond); pthread_mutex_destroy(&mypict.mutex); if (mypict.data) free(mypict.data); printf ("Destroy Picture thread ...\n"); /* Shutdown all subsystems */ free (tmp); //close_libjpeg_decoder (); printf ("Quiting....\n"); SDL_Quit ();return 0; }Uint32 GetVideoBpp (void){ const SDL_VideoInfo *info; info = SDL_GetVideoInfo(); printf( "Current display: %d bits-per-pixel\n",info->vfmt->BitsPerPixel);return info->vfmt->BitsPerPixel;}static int setVideoPict (struct video_picture *videopict, int fd){ if (ioctl (fd, VIDIOCSPICT, videopict) < 0) { perror ("Couldnt get videopict params with VIDIOCSPICT\n"); return -1; } printf ("VIDIOCSPICT\n"); printf ("brightness=%d hue=%d color=%d contrast=%d whiteness=%d \n", videopict->brightness, videopict->hue, videopict->colour, videopict->contrast, videopict->whiteness); printf("depth=%d palette=%d \n",videopict->depth, videopict->palette); return 0;}static int readFrame (avi_t *out_fd, long i,unsigned char **jpegData, int *jpegSize, struct Rbuffer *RingBuffer, int maxsound, int *audiolen, int *soundbytes, int isaudio, int updown, int compress ){ static int avipos = 0; unsigned char *dpshDest = NULL; int ptwrite; int ptread; int audiosize=0; int delta =0 ; /* got frame i and read the data */ if (AVI_set_video_position (out_fd, i) < 0) printf ("error get video position\n"); *jpegSize = (int) AVI_frame_size (out_fd, i); //audiosize = (int)AVI_chunk_size (out_fd, i); audiosize = *soundbytes; avipos += audiosize; delta = ((i+1) * (*soundbytes))-avipos; //printf("audiosize delta %d \n",delta); *jpegData = (unsigned char *) realloc (*jpegData, (size_t) *jpegSize); if (AVI_read_frame (out_fd, *jpegData) < 0) printf ("error read frame\n"); if (compress){ /* decompress the video stream */ dpshDest = malloc(640*480*3); dpsh_yuv_decode(*jpegData , dpshDest, jpegSize); /* restore jpegData size to the uncompressed mode */ *jpegData = (unsigned char *) realloc (*jpegData, (size_t) *jpegSize); memcpy(*jpegData, dpshDest, *jpegSize); free(dpshDest); } if (isaudio && (*audiolen > 0)) { SDL_LockAudio(); ptread = RingBuffer->ptread; ptwrite = RingBuffer->ptwrite; SDL_UnlockAudio(); if (updown) { /* upstream */ /* read the audio Byte until no Byte */ if (ptwrite + audiosize < MAXBUFFERSIZE) { if (AVI_read_audio (out_fd, (char *) RingBuffer->buffer+ptwrite, audiosize) < 0) printf (" Read AVIchunck error \n"); } else { //printf ("part1 %d, part2 %d \n",MAXBUFFERSIZE-ptwrite,audiosize -( MAXBUFFERSIZE-ptwrite)); if (AVI_read_audio (out_fd, (char *) RingBuffer->buffer+ptwrite, MAXBUFFERSIZE-ptwrite) < 0) printf (" Read AVIpart1 error \n"); if (AVI_read_audio (out_fd, (char *) RingBuffer->buffer, audiosize -( MAXBUFFERSIZE-ptwrite)) < 0) printf (" Read AVIpart2 error \n"); } SDL_LockAudio(); RingBuffer->ptwrite = (RingBuffer->ptwrite + audiosize)%MAXBUFFERSIZE; SDL_UnlockAudio(); *audiolen -= audiosize; } else { /* down stream */ /* rewind one sound fragment */ *audiolen += *soundbytes ; avipos = (maxsound - *audiolen); if (avipos >= 0) if (AVI_set_audio_position (out_fd, (long)avipos) < 0) printf ("error read soundframe down \n"); //printf("audiolenth : %d soundbytes %d aviposition %d\n",*audiolen,audiosize,avipos); } }return delta;}#define ADDRESSE(x,y,w) (((y)*(w))+(x))void resize16 (unsigned char *dst,unsigned char *src, int Wd,int Hd,int Ws,int Hs) { int rx,ry; int xscale,yscale; int x,y; Myrgb24 pixel; Myrgb16 *output =(Myrgb16*) dst ; Myrgb24 *input = (Myrgb24*) src ; xscale = (Ws << 16)/Wd; yscale = (Hs << 16)/ Hd; for (y = 0; y < Hd; y++){ for (x = 0; x < Wd; x++){ rx = x*xscale >> 16; ry = y*yscale >> 16; output->blue = input[ADDRESSE((int)rx,(int)ry,Ws)].blue >> 3; output->green = input[ADDRESSE((int)rx,(int)ry,Ws)].green >> 2; output->red = input[ADDRESSE((int)rx,(int)ry,Ws)].red >> 3; output++ ; } } }void resize (unsigned char *dst,unsigned char *src, int Wd,int Hd,int Ws,int Hs) { int rx,ry; int xscale,yscale; int x,y; Myrgb24 pixel; Myrgb24 *output =(Myrgb24*) dst ; Myrgb24 *input = (Myrgb24*) src ; xscale = (Ws << 16)/Wd; yscale = (Hs << 16)/ Hd; for (y = 0; y < Hd; y++){ for (x = 0; x < Wd; x++){ rx = x*xscale >> 16; ry = y*yscale >> 16; memcpy(output++,&input[ADDRESSE((int)rx,(int)ry,Ws)],sizeof(Myrgb24)); } } }/* refresh_screen input all palette to RGB24 -> RGB565 */static voidrefresh_screen (unsigned char *src, unsigned char *pict, int format, int width, int height,int owidth ,int oheight, int size, int autobright){ unsigned int *lpix; unsigned short *pix; int i; int intwidth = width; int intheight = height;unsigned char *dst = NULL;/* in case VIDEO_PALETTE_RAW_JPEG nothing todo */ if( format == VIDEO_PALETTE_RAW_JPEG) return ; /* for some strange reason tiny_jpegdecode need 1 macroblok line more ?? */ dst = malloc (width*(height+8)*3); switch (format) { case VIDEO_PALETTE_JPEG:{ //libjpeg_decode (dst, src, size, width, height); jpeg_decode (&dst, src, &intwidth, &intheight); } break; case VIDEO_PALETTE_YUV420P:{ // uncompressed data yuv420P decoder in module // equalize (src, width, height, 0); YUV420toRGB ((unsigned char *) src, (unsigned char *) dst, width, height, 0, 0); } break; case VIDEO_PALETTE_RGB565: pix = (unsigned short *) src; for (i = 0; i < ((width*height*3) - 3); i += 3) { dst[i] = (*pix & 0x001F) << 3; dst[i + 1] = (*pix & 0x07E0) >> 3; dst[i + 2] = (*pix & 0xF800) >> 8; pix++; } break; case VIDEO_PALETTE_RGB32: lpix = (unsigned int *) src; for (i = 0; i < ((width*height*3) - 3); i += 3) { dst[i] = (*lpix & 0x000000FF); dst[i + 1] = (*lpix & 0x0000FF00) >> 8; dst[i + 2] = (*lpix & 0x00FF0000) >> 16; lpix++; } break; case VIDEO_PALETTE_RGB24:{ // uncompressed data. rgb decoder in module simple copy for display. memcpy (dst, src, size); } break; default: break; }if (autobright) totmean = get_pic_mean( width, height, dst, 0, 0, 0, width, height );/* rezize16 input rgb24 output rgb565 */resize16 (pict,dst,owidth,oheight,width,height) ; free(dst);}static int isSpcaChip (const char *BridgeName){ int i = -1; int size =0; //size = strlen(BridgeName)-1; /* Spca506 return more with channel video, cut it */ //if (size > 10) size = 8; /* return Bridge otherwhise -1 */ for (i=0; i < MAX_BRIDGE ;i++){ size=strlen(Blist[i].name); if(strncmp(BridgeName,Blist[i].name,size) == 0) { printf("Bridge find %s number %d\n",Blist[i].name,i); break; } } return i;}static int getStreamId (const char * BridgeName){ int i = -1; int match = -1;/* return Stream_id otherwhise -1 */ if((match=isSpcaChip(BridgeName)) < 0){ printf("Not an Spca5xx Camera !!\n"); return match; } switch (match) { case BRIDGE_SPCA505: case BRIDGE_SPCA506: i= YYUV; break; case BRIDGE_SPCA501: i = YUYV; break; case BRIDGE_SPCA508: i = YUVY; break; case BRIDGE_SPCA504: case BRIDGE_SPCA500: case BRIDGE_SPCA504B: case BRIDGE_SPCA533: case BRIDGE_SPCA504C: case BRIDGE_SPCA536: case BRIDGE_ZR364XX: case BRIDGE_ZC3XX: case BRIDGE_CX11646: case BRIDGE_SN9CXXX: case BRIDGE_MR97311: i = JPEG; break; case BRIDGE_ETOMS: case BRIDGE_SONIX: case BRIDGE_SPCA561: case BRIDGE_TV8532: i = GBRG; break; default: i = -1; printf("Unable to find a StreamId !!\n"); break; }return i; } static int probeSize (const char *BridgeName, int *width, int *height){ int bridge = -1; int i; unsigned int intwidth; unsigned int intheight; unsigned int intformat; int match =0;/* return 1->ok otherwhise -1 */ if ((bridge= isSpcaChip(BridgeName)) < 0) { printf ("Cannot Probe Size !! maybe not an Spca5xx Camera\n"); return -1; } for (i=0; (unsigned int)(GET_EXT_MODES(bridge)[i][0]);i++){ intwidth = GET_EXT_MODES(bridge)[i][0]; intheight = GET_EXT_MODES(bridge)[i][1]; intformat = (GET_EXT_MODES(bridge)[i][2] & 0xF0) >> 4; if ((intwidth== *width) && (intheight == *height)){ match = 1; } else { match = 0; } printf("Available Resolutions width %d heigth %d %s %c\n", intwidth,intheight,(intformat)?"decoded":"native", (match)?'*':' '); }}/* * get_pic_mean: Calculate the mean value of the pixels in an image. * This routine is used for adjusting the values of * the pixels to reasonable brightness. * * Arguments: width, height = Dimensions of the picture * buffer = Buffer to picture. * is_rgb = 1 if the picture is rgb, else 0 * start{x,y}, end{x,y} = Region to calculate the * mean of. This MUST be valid before * being passed in! * * Return values: Returns the average of all the components if rgb, else * the average whiteness of each pixel if B&W */static int g
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -