⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 spec5xx for xp in terminal 在xp下编译过的摄像头驱动源码
💻 CPP
字号:
#include <stdio.h>
#include <stdlib.h>

#include <sys/types.h>
#include <sys/stat.h>

#include <string.h>

#include "videodev.h"
#include "jconfig.h"
#include "utils.h"
#include "version.h"
#include "tcputils.h"

extern "C"
{
int spcaClient (char *Ip, short port,int owidth, int oheight ,int statOn);

}

int main (int argc, char *argv[])
{
	/* Timing value used for statistic */

	
	const char *videodevice = NULL;
	/* default mmap */
	int grabMethod = 1;
	
	int format = VIDEO_PALETTE_YUV420P;
	/******** output screen pointer ***/
	
	int image_width = IMAGE_WIDTH;
	int image_height = IMAGE_HEIGHT;
	int owidth = 0;
	int oheight = 0;
	/**********************************/
	/*        avi parametres          */
	char *inputfile = NULL;
	char *outputfile = NULL;
	char fourcc[5] = "MJPG";
	
	char *sizestring = NULL;
	int use_libjpeg = 1;
	char *separateur;
	char *mode = NULL;
	/*********************************/
	/*          Starting Flags       */
	int i;
	int videoOn = 1;
	int decodeOn =1 ;
	int statOn = 0;
	int audioout = 0;
	int videocomp = 0;
	int channel = 0;
	int norme = 0;
	int autobright = 0;
	/*********************************/
	char *AdIpPort;
	char AdIp[]= "000.000.000.000";
	unsigned short ports = 0;
	
	/*********************************/
	SPCASTATE funct;
	
 
	/* init default bytes per pixels for VIDEO_PALETTE_RAW_JPEG 	*/
	/* FIXME bpp is used as byte per pixel for the ouput screen	*/
	/* we need also a bpp_in for the input stream as spcaview   	*/
	/* can convert stream That will be a good idea to have 2 struct */
	/* with all global data one for input the other for output      */ 
	bpp = 3;
	funct = GRABBER;
	printf(" %s \n",version);
	/* check arguments */
	for (i = 1; i < argc; i++) {
		/* skip bad arguments */
		if (argv[i] == NULL || *argv[i] == 0 || *argv[i] != '-') {
			continue;
		}
		if (strcmp (argv[i], "-d") == 0) {
			if (i + 1 >= argc) {
				printf ("No parameter specified with -d, aborting.\n");
				exit (1);
			}
			videodevice = strdup (argv[i + 1]);
		}
		if (strcmp (argv[i], "-n") == 0) {
			if (i + 1 >= argc) {
				printf ("No parameter specified with -n, aborting.\n");
				exit (1);
			}
			norme = atoi (argv[i + 1]);
			if (norme < 0 || norme > 4)
			printf ("Norme should be between 0..4 Read the readme !.\n");
		}
		if (strcmp (argv[i], "-c") == 0) {
			if (i + 1 >= argc) {
				printf ("No parameter specified with -c, aborting.\n");
				exit (1);
			}
			channel = atoi (argv[i + 1]);
			if (channel < 0 || channel > 9)
			printf ("Channel should be between [0..3] || [6..9] Read the readme !.\n");
		}
		if (strcmp (argv[i], "-v") == 0) {
			videoOn = 0;

		}
		if (strcmp (argv[i], "-j") == 0) {
			decodeOn = 0;

		}
		if (strcmp (argv[i], "-t") == 0) {
			statOn = 1;

		}
		if (strcmp (argv[i], "-z") == 0) {
			videocomp = 1;

		}
		if (strcmp (argv[i], "-b") == 0) {
		  autobright = 1;
		}
		if (strcmp (argv[i], "-f") == 0) {
			if (i + 1 >= argc) {
				printf ("No parameter specified with -f, aborting.\n");
				exit (1);
			}
			mode = strdup (argv[i + 1]);

			if (strncmp (mode, "r32", 3) == 0) {
				format = VIDEO_PALETTE_RGB32;
				bpp = 4;
				_snprintf (fourcc, 5, "RGB4");

			} else if (strncmp (mode, "r24", 3) == 0) {
				format = VIDEO_PALETTE_RGB24;
				bpp = 3;
				_snprintf (fourcc, 5, "RGB3");
			} else if (strncmp (mode, "r16", 3) == 0) {
				format = VIDEO_PALETTE_RGB565;
				bpp = 2;
				_snprintf (fourcc, 5, "RGB2");
			} else if (strncmp (mode, "yuv", 3) == 0) {
				format = VIDEO_PALETTE_YUV420P;
				bpp = 3;
				_snprintf (fourcc, 5, "I420");
			} else if (strncmp (mode, "jpg", 3) == 0) {
				format = VIDEO_PALETTE_JPEG;
				bpp = 3;
				_snprintf (fourcc, 5, "MJPG");
			}else {
				format = VIDEO_PALETTE_YUV420P;
				bpp = 3;
				_snprintf (fourcc, 5, "I420");
			}

		}

		if (strcmp (argv[i], "-i") == 0) {
			if (i + 1 >= argc) {
				printf ("No parameter specified with -i, aborting.\n");
				exit (1);
			}
			inputfile = strdup (argv[i + 1]);
			funct = PLAYER ;
		}

		if (strcmp (argv[i], "-g") == 0) {
			/* Ask for read instead default  mmap */
			grabMethod = 0;
		}

		if (strcmp (argv[i], "-a") == 0) {
			if (i + 1 >= argc) {
				printf ("No parameter specified with -a, aborting.\n");
				exit (1);
			}
			audioout = atoi (argv[i + 1]);
			if ((audioout < 0) || (audioout > 2)) {
				audioout = 0;
			}
			printf ("audio channel %d\n", audioout);
		}

		if (strcmp (argv[i], "-o") == 0) {
			if (i + 1 >= argc) {
				printf ("No parameter specified with -o, aborting.\n");
				exit (1);
			}
			outputfile = strdup (argv[i + 1]);
		}
		/* custom ? */
		if (strcmp (argv[i], "-s") == 0) {
			if (i + 1 >= argc) {
				printf ("No parameter specified with -s, aborting.\n");
				exit (1);
			}

			sizestring = strdup (argv[i + 1]);

			image_width = strtoul (sizestring, &separateur, 10);
			if (*separateur != 'x') {
				printf ("Error in size use -s widthxheight \n");
				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], "-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);
		}
	}

	// 仅作为客户端
	spcaClient(AdIp,ports,owidth,oheight, statOn);
	
	printf("程序正常结束!\n");

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -