📄 spcaview.c
字号:
exit (1); } else { ++separateur; image_height = strtoul (separateur, &separateur, 10); if (*separateur != 0) printf ("hmm.. dont like that!! trying this height \n"); printf (" size width: %d height: %d \n", image_width, image_height); } } if (strcmp (argv[i], "-m") == 0) { if (i + 1 >= argc) { printf ("No parameter specified with -m, aborting.\n"); exit (1); } sizestring = strdup (argv[i + 1]); owidth = strtoul (sizestring, &separateur, 10); if (*separateur != 'x') { printf ("Error in size use -m widthxheight \n"); exit (1); } else { ++separateur; oheight = strtoul (separateur, &separateur, 10); if (*separateur != 0) printf ("hmm.. dont like that!! trying this height \n"); printf (" output size width: %d height: %d \n", owidth, oheight); } } if (strcmp (argv[i], "-p") == 0) { if (argv[i + 1]) interval = 1000* (atoi(argv[i + 1])); // timer works on ms else { printf ("No parameter specified with -p, aborting.\n"); exit (1); } } if (strcmp (argv[i], "-N") == 0) { if (argv[i + 1]){ numshoot = (atoi(argv[i + 1])); // timer works on ms if (numshoot <= 0) numshoot = 1; // in case :) if(!interval) interval = 1000; modshoot = 1; } else { printf ("No parameter specified with -p, aborting.\n"); exit (1); } } if (strcmp (argv[i], "-w") == 0) { if (i + 1 >= argc) { printf ("No parameter specified with -w, aborting.\n"); exit (1); } AdIpPort = strdup (argv[i + 1]); if(reportip(AdIpPort,AdIp,&ports) < 0) printf("error in port convertion \n"); printf ("using Server %s Port %d \n",AdIp,ports); funct = CLIENT ; } /* large ? */ if (strcmp (argv[i], "-l") == 0) { image_width = 640; image_height = 480; } if (strcmp (argv[i], "-h") == 0) { printf ("usage: spcaview [-h -d -n -c -v -j -z -g -l -s -m -a -f -b -t -p] [-i inputfile | -o outputfile]\n"); printf ("-h print this message \n"); printf ("-d /dev/videoX use videoX device\n"); printf ("-n norme 0->pal 2->secam 1->ntsc \n"); printf ("-c input channels 0..9 exclude 4 and 5 \n"); printf ("-v disable video output for raw recording \n"); printf ("-j disable video output and userspace decoding \n"); printf ("-z compress yuv420p video output with DPSH encoder\n"); printf ("-g use read method for grab instead mmap \n"); printf ("-l default 320x480 use input size 640x480 \n"); printf ("-s widthxheight use specified input size \n"); printf ("-m widthxheight use specified ouput size \n"); printf ("-a default 0 -> nosound 1-> microphone 2-> mixer output\n"); printf ("-f video format default yuv others options are r16 r24 r32 yuv jpg \n"); printf ("-b enable automatic brightness adjustment \n"); printf ("-t print statistics \n"); printf ("-p x getPicture every x seconds \n"); printf ("-p x && -o getPicture every x seconds and record in outfile\n"); printf ("-w Address:Port read from Address xxx.xxx.xxx.xxx:Port\n"); printf ("-N x take a x pictures and exit if p is not set p = 1 second \n"); exit (0); } } switch (funct) { case PLAYER: { /* that is spcaview player */ spcaPlay (inputfile, owidth, oheight); } break; case GRABBER: { /* spcaview grabber */ spcaGrab (outputfile,fourcc , videodevice, image_width,image_height, format, owidth, oheight, grabMethod, videoOn, audioout, videocomp, autobright, statOn, decodeOn); } break; case CLIENT: { spcaClient(AdIp,ports,owidth,oheight, statOn); } }exit (0);}int readjpeg(int sock, unsigned char **buf,struct frame_t *headerframe,struct client_t *message,int statOn){ int byteread,bytewrite; bytewrite = write_sock(sock,(unsigned char*)message,sizeof(struct client_t)); // is sleeping ? if ((byteread= read_sock(sock,(unsigned char*)headerframe,sizeof(struct frame_t))) < 0){ printf("Seem server is gone !! try later \n"); goto error; } if(statOn) printf (" key %s nb %d width %d height %d times %dms size %d \n",headerframe->header, headerframe->nbframe,headerframe->w,headerframe->h,headerframe->deltatimes,headerframe->size); if(headerframe->size && !headerframe->wakeup){ //if(headerframe->size){ *buf=(unsigned char*) realloc(*buf,headerframe->size); if((byteread = read_sock(sock,*buf,headerframe->size)) < 0){ printf("Seem server is gone !! try later \n"); goto error;} } //printf("buf read %d \n",byteread); if(headerframe->acknowledge) reset_callbackmessage(message); usleep(5000); return ((headerframe->wakeup)?0:(headerframe->size)); //return (headerframe->size);error:return -1;}void init_sdlall(void){ /* Initialize defaults, Video and Audio */ if ((SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_EVENTTHREAD) == -1)) { printf ("Could not initialize SDL: %s.\n", SDL_GetError ()); exit (-1); } videoOk =1; atexit (SDL_Quit); }void init_sdlvideo(void){ /* Initialize defaults, Video and Audio */ if ((SDL_InitSubSystem (SDL_INIT_VIDEO ) == -1)) { printf ("Could not initialize SDL: %s.\n", SDL_GetError ()); exit (-1); } videoOk = 1;}void close_sdlvideo(void){ SDL_QuitSubSystem (SDL_INIT_VIDEO ) ; videoOk = 0;}int spcaClient (char *Ip, short port,int owidth, int oheight, int statOn){ struct frame_t *headerframe; struct client_t *messcallback; unsigned char *buf = NULL; int width,height; int jpegsize; int sock_client; int run = 1; int quit =1; int keypressed =0; int bpp = 3; SDL_Surface *pscreen; SDL_Event sdlevent; unsigned char* p= NULL; unsigned char *picture = NULL; struct tm *tdate; time_t curdate; char titre[21]; init_sdlall(); sock_client = open_clientsock(Ip,port); headerframe=(struct frame_t*)malloc(sizeof(struct frame_t)); messcallback=(struct client_t*)malloc(sizeof(struct client_t)); init_callbackmessage(messcallback); if ((jpegsize = readjpeg(sock_client,&buf,headerframe,messcallback,statOn)) < 0){ printf("got size = 0 \n"); goto error; } width = headerframe->w; height = headerframe->h; if(!owidth || !oheight){ owidth = width; oheight = height; } if(videoOk) { pscreen = SDL_SetVideoMode (owidth, oheight, bpp * 8, SDL_DOUBLEBUF | SDL_SWSURFACE); p=pscreen->pixels; } do{ if((jpegsize = readjpeg(sock_client,&buf,headerframe,messcallback,statOn)) < 0){ // printf(" No size !!! exit fatal \n"); goto error; }/* mode sleep off */ if(!jpegsize && videoOk) close_sdlvideo(); if( !videoOk && jpegsize){ init_sdlvideo(); pscreen = SDL_SetVideoMode (owidth, oheight, bpp * 8, SDL_DOUBLEBUF | SDL_SWSURFACE); p=pscreen->pixels; } curdate = (time_t) (headerframe->seqtimes / 1000); tdate = localtime(&curdate); snprintf (titre,21,"%02d/%02d/%04d-%02d:%02d:%02d\0", tdate->tm_mday, tdate->tm_mon + 1, tdate->tm_year + 1900, tdate->tm_hour, tdate->tm_min, tdate->tm_sec); if(jpegsize && videoOk){ jpeg_decode(&picture,buf,&width,&height); resize (p,picture,owidth,oheight,width,height) ; SDL_WM_SetCaption (titre, NULL); SDL_Flip (pscreen); } printf("bright %05d contrast %05d \r",headerframe->bright,headerframe->contrast); fflush (stdout); switch (run){ case 1: if (SDL_PollEvent (&sdlevent) == 1) { switch (sdlevent.type) { case SDL_KEYDOWN: switch (sdlevent.key.keysym.sym) { case SDLK_s: //getPicture(buf,jpegsize); getJpegPicture(buf,width,height, VIDEO_PALETTE_JPEG,jpegsize,PICTURE,NULL); break; case SDLK_w: messcallback->updocontrast =2; break; case SDLK_x: messcallback->updocontrast =1; break; case SDLK_b: messcallback->updobright=1; break; case SDLK_n: messcallback->updobright=2; break; case SDLK_l: messcallback->sleepon=1; break; case SDLK_c: messcallback->sleepon=2; break; case SDLK_j: messcallback->updoexposure=1; break; case SDLK_d: messcallback->updosize=1; //workaround change quality index break; case SDLK_f: messcallback->updosize=2; //workaround change quality index break; case SDLK_g: messcallback->fps=1; // decrease time_interval break; case SDLK_h: messcallback->fps=2; // increase time interval break; case SDLK_UP: if(messcallback->y -1 > 0) messcallback->y--; keypressed = SDLK_UP ; run = 2; break; case SDLK_DOWN: if(messcallback->y +1 < 256) messcallback->y++; keypressed = SDLK_DOWN; run = 2; break; case SDLK_RIGHT: if(messcallback->x -1 > 0) messcallback->x--; keypressed = SDLK_RIGHT; run = 2; break; case SDLK_LEFT: if(messcallback->x +1 < 256) messcallback->x++; keypressed = SDLK_LEFT; run = 2; break; case SDLK_SPACE: run = 0; break; case SDLK_q: quit =0; break; } break; case SDL_QUIT: quit = 0; break; } } //end Poll event break; case 0: if (SDL_WaitEvent (&sdlevent) == 1) { switch (sdlevent.type) { case SDL_KEYDOWN: switch (sdlevent.key.keysym.sym) { case SDLK_s: //getPicture(buf,jpegsize); break; case SDLK_SPACE: run = 1; break; case SDLK_q: quit =0; break; } break; case SDL_QUIT: quit = 0; break; } } //end wait event break; case 2:{ if (SDL_PollEvent (&sdlevent) == 1) { switch (sdlevent.type) { case SDL_KEYDOWN: keypressed = 0; run = 1; break; } //end event type poll 2 } switch (keypressed){ case SDLK_UP: if(messcallback->y -1 > 0) messcallback->y--; break; case SDLK_DOWN: if(messcallback->y +1 < 256) messcallback->y++; break; case SDLK_RIGHT: if(messcallback->x -1 > 0) messcallback->x--; break; case SDLK_LEFT: if(messcallback->x +1 < 256) messcallback->x++; break; default: break; } } // end case 2 break; } }while(quit);error:if(picture){free(picture);picture = NULL;}close_sock(sock_client);free(buf);free(messcallback);free(headerframe);SDL_Quit ();return 0;}int spcaPlay (char* inputfile, int width, int height){ /* Timing value used for statistic */ Uint32 synctime = 0; Uint32 intime = 0; Uint32 pictime = 0; int format = VIDEO_PALETTE_YUV420P; /******** output screen pointer ***/ SDL_Surface *pscreen; SDL_Event sdlevent; unsigned char *p = NULL; unsigned char *pp = NULL; int image_width = IMAGE_WIDTH; int image_height = IMAGE_HEIGHT; int owidth = width; int oheight = height; /**********************************/ /* avi parametres */ avi_t *out_fd; char *compressor; double framerate; long audiorate; int audiobits; int audioformat; unsigned char *tmp = NULL; // don't forget the Till lesson unsigned char *dpshDest = NULL; u_int8_t *jpegData = NULL; // Till lesson a good pointer is a pointer NULL int jpegSize; int framecount = 0; /*********************************/ /* file input output */ char *outputfile = NULL; static char Picture[80]; char fourcc[4] = "MJPG"; FILE *foutpict; /*********************************/ /* Starting Flags */ int run = 1; int quit = 1; int initAudio = 0; //flag start audio int videocomp = 0; //is compression dsph int frame_size = 0; int len = 0; int fullsize = 0; /*********************************/ /* data for SDL_audioin && SDL_audio */ SDL_AudioSpec spec, result; SDL_AudioSpec expect; struct Rbuffer RingBuffer; int retry = 100; int err = 0; int bytes_per_read =0; int audioout = 0; int audiolength = 0; int maxsound = 0; /*********************************/ /* misc index */ int i,j,k; int testbpp = 16; RingBuffer.ptread =0; RingBuffer.ptwrite =0; /* that a is spcaview player */ printf ("Initializing SDL.\n"); /* Initialize defaults, Video and Audio */ if ((SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1)) { printf ("Could not initialize SDL: %s.\n", SDL_GetError ()); exit (-1); } //bitperpix = GetVideoBpp(); /* Clean up on exit */ atexit (SDL_Quit); printf ("SDL initialized.\n"); printf ("Using %s avifile \n", inputfile); if ((out_fd = AVI_open_input_file (inputfile, 1)) == NULL) { printf ("cannot open input file ? \n"); exit (1); } /* get the parameters from the file */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -