Example #1
0
static int v4l_start(MSFilter *f, void *arg)
{
	V4lState *s=(V4lState*)f->data;
	int err=0;
	if (v4l_fd>=0 && reuse_fd){
		if (strcmp(v4l_devname,s->dev)==0 ){
			/*use this one!*/
			ms_message("v4l_start: reusing previous file descriptor.");
			s->fd=v4l_fd;
		}else{
			ms_message("closing cached fd");
			close(v4l_fd);
			v4l_fd=-1;
			ms_free(v4l_devname);
			v4l_devname=NULL;
		}
	}
	if (s->fd==-1){
		s->fd=open(s->dev,O_RDWR);
		ms_message("v4l_start: open, fd=%i",s->fd);
		if (s->fd>=0){
			v4l_fd=s->fd;
			v4l_devname=ms_strdup(s->dev);
		}
	}
	if (s->fd<0){
		ms_error("MSV4l: cannot open video device (%s): %s.",s->dev,strerror(errno));
		return -1;
	}else{
#ifdef HAVE_LINUX_VIDEODEV2_H
		if (v4lv2_configure(s)<0) {/*might not be V4LV2 */
#else
		{
#endif
			err=v4l_configure(s);
			if (err<0) 
			{
				ms_error("MSV4l: could not get configuration of video device");
				close(s->fd);
				s->fd=-1;
				return -1;
			}
			reuse_fd=TRUE;
		}else{
Example #2
0
static int v4l_start(MSFilter *f, void *arg)
{
	V4lState *s=(V4lState*)f->data;
	int err=0;
	if (v4l_fd>=0 && reuse_fd){
		if (strcmp(v4l_devname,s->dev)==0 ){
			/*use this one!*/
			ms_message("v4l_start: reusing previous file descriptor.");
			s->fd=v4l_fd;
		}else{
			ms_message("closing cached fd");
			close(v4l_fd);
			v4l_fd=-1;
			ms_free(v4l_devname);
			v4l_devname=NULL;
		}
	}
	if (s->fd==-1){
		s->fd=open(s->dev,O_RDWR);
		ms_message("v4l_start: open, fd=%i",s->fd);
		if (s->fd>=0){
			v4l_fd=s->fd;
			v4l_devname=ms_strdup(s->dev);
		}
	}
	if (s->fd<0){
		ms_error("MSV4l: cannot open video device (%s): %s.",s->dev,strerror(errno));
		if (!s->usemire){
			s->pix_fmt=MS_YUV420P;
			s->fps=1;
		}
		return -1;
	}else{
#ifdef HAVE_LINUX_VIDEODEV2_H
		if (s->force_v1 || v4lv2_configure(s)<0) {/*might not be V4LV2 */
#else
		if (1){
#endif
			struct video_capability vidcap;
			err=v4l_configure(s);
			if (err<0)
			{
				ms_error("MSV4l: could not get configuration of video device");
				close(s->fd);
				s->fd=-1;
				return -1;
			}
			if (!s->force_v1) reuse_fd=TRUE;

			err=ioctl(s->fd, VIDIOCGCAP, &vidcap);
			if (err==0)
			  {
			    ms_message("MSV4l: Webcam is %s.", vidcap.name);
			    if (strcasecmp(vidcap.name, "Logitech QuickCam USB")==0)
			      {
				int comp_arg=0;
				err=ioctl(s->fd, VIDIOCQCSCOMPATIBLE, &comp_arg);
				if (err==0)
				  {
				    ms_message("MSV4l: compatibility mode disabled for %s.", vidcap.name);
				  }
			      }
			}
		}else{
			ms_message("Device is a video4linux V2 one.");
			s->v4lv2=TRUE;
			reuse_fd=FALSE;
		}
	}
	return 0;
}

static void v4l_start_capture(V4lState *s){
	if (s->fd>=0){
		s->run=TRUE;
		ms_thread_create(&s->thread,NULL,v4l_thread,s);
	}
}

static int v4l_stop(MSFilter *f, void *arg){
	V4lState *s=(V4lState*)f->data;
	if (s->fd>=0){
		if (!reuse_fd){
			if (close(s->fd)<0){
				ms_warning("MSV4l: Could not close(): %s",strerror(errno));
			}
			ms_message("v4l fd %i closed",s->fd);
		}
		s->fd=-1;
		s->frame_count=-1;
	}
	return 0;
}