예제 #1
0
static int detect_standard(struct capture_device *c, int fd){
	int found=0, i=0;

	dprint(LIBVIDEO_SOURCE_CAP, LIBVIDEO_LOG_DEBUG,
			"Trying to autodetect standard\n");

	while(found==0 && i<4) {
		if (try_std(fd, i)==0){
			found=1;
			if(i==WEBCAM) {
				info("Adjusted standard to WEBCAM\n");
				c->std = WEBCAM;
			} else if (i==PAL) {
				info("Adjusted standard to PAL\n");
				c->std = PAL;
			} else if (i==NTSC) {
				info("Adjusted standard to NTSC\n");
				c->std = NTSC;
			} else  {
				info("Adjusted standard to SECAM\n");
				c->std = SECAM;
			}
		}
		i++;
	}
	return found==0 ? -1 : 0;
}
예제 #2
0
static int detect_standard(struct capture_device *c, int fd){
	int found=0, i=0;

	dprint(LIBV4L_LOG_SOURCE_CAPTURE, LIBV4L_LOG_LEVEL_DEBUG, "Trying to autodetect standard\n");

	while(found==0 && i<4) {
		if (try_std(fd, i)==0){
			found=1;
			if(i==WEBCAM) {
				dprint(LIBV4L_LOG_SOURCE_CAPTURE, LIBV4L_LOG_LEVEL_DEBUG, "WEBCAM standard autodetected\n");
				c->std = WEBCAM;
			} else if (i==PAL) {
				dprint(LIBV4L_LOG_SOURCE_CAPTURE, LIBV4L_LOG_LEVEL_DEBUG, "PAL standard autodetected\n");
				c->std = PAL;
			} else if (i==NTSC) {
				dprint(LIBV4L_LOG_SOURCE_CAPTURE, LIBV4L_LOG_LEVEL_DEBUG, "NTSC standard autodetected\n");
				c->std = NTSC;
			} else  {
				dprint(LIBV4L_LOG_SOURCE_CAPTURE, LIBV4L_LOG_LEVEL_DEBUG, "SECAM standard autodetected\n");
				c->std = SECAM;
			}
		}
		i++;
	}
	return found==0 ? -1 : 0;
}
예제 #3
0
static int set_std(struct capture_device *c, int fd){
	struct v4l2_standard s;
	CLEAR(s);


	//Linux UVC doesnt like to be ioctl'ed(VIDIOC_S_STD)
	//even though v4l2 specs say nothing
	//about usb cam drivers returning EINVAL...
	//so we first try VIDIOC_ENUMSTD. if it returns EINVAL, then we
	//assume it is a webcam
	//otherwise, we need to set a standard
	if(-1 != ioctl(fd, VIDIOC_ENUMSTD, &s)){
		//driver says "I use standards" -
		//check if it is the UNKNOWN one, only used by webcams
		if(s.id != V4L2_STD_UNKNOWN) {
			//driver says "not webcam", check what we want...
			if(c->std == WEBCAM){
				//we want webcam... try to autodetect
				info("The specified standard (%d) is invalid.\n", c->std);
				if(detect_standard(c, fd)!=0) {
					//autodetect failed, so do we
					info("libvideo could not autodetect a standard for this "
							"input.\n");
					return -1;
				}
				//autodetect suceeded keep going
			} else {
				//we want !WEBCAM, so try that standard
				dprint(LIBVIDEO_SOURCE_CAP, LIBVIDEO_LOG_DEBUG,
						"Trying standard (%d).\n", c->std);
				if (-1 == try_std(fd, c->std)) {
					//failed, try autodetect
					info("The specified standard (%d) cannot be selected\n",
							c->std);
					if(detect_standard(c, fd)!=0) {
						//failed, exit
						info("libvideo could not autodetect a standard for this"
								" input.\n");
						return -1;
					}
					//autodetect succeeded, keep going
				}
				//given standard succeeded, keep going
			}
		} else {
			//driver says webcam, check what we want
			if(c->std != WEBCAM){
				//we want !WEBCAM, so try that standard
				if (-1 == try_std(fd, c->std)) {
					//failed, try autodetect
					info("The specified standard (%d) cannot be selected\n",
							c->std);
					if(detect_standard(c, fd)!=0) {
						//failed, exit
						dprint(LIBVIDEO_SOURCE_CAP, LIBVIDEO_LOG_ERR,
								"CAP: Couldnt autodetect a standard for this "
							"input.\n");
						return -1;
					}
					//autodetect succeeded, keep going
				}
			} else {
				//driver sais WEBCAM, so did we, keep going
			}
		}
	} else {
		//driver doesnt use standards - most likely a webcam
		if(c->std!=WEBCAM){
			info("The standard has been autodetected and set to WEBCAM \n");
			c->std = WEBCAM;
		}
	}

	return 0;
}