Example #1
0
static void *msv4l2_thread(void *ptr){
	V4l2State *s=(V4l2State*)ptr;
	int try=0;
	
	ms_message("msv4l2_thread starting");
	if (s->fd==-1){
		if( msv4l2_open(s)!=0){
			ms_warning("msv4l2 could not be openned");
			goto close;
		}
	}
	
	if (!s->configured && msv4l2_configure(s)!=0){
		ms_warning("msv4l2 could not be configured");		
		goto close;
	}
	if (msv4l2_do_mmap(s)!=0)
	{
		ms_warning("msv4l2 do mmap");
		goto close;
	}
	ms_message("V4L2 video capture started.");
	while(s->thread_run)
	{
		if (s->fd!=-1){
			mblk_t *m;
			m=v4lv2_grab_image(s,50);
			if (m){
				mblk_t *om=dupmsg(m);
				mblk_set_marker_info(om,(s->pix_fmt==MS_MJPEG));
				ms_mutex_lock(&s->mutex);
				putq(&s->rq,om);
				ms_mutex_unlock(&s->mutex);
			}
		}
	}
	/*dequeue pending buffers so that we can properly unref them (avoids memleak )*/
	while(s->queued && try<10){
		v4l2_dequeue_ready_buffer(s,50);
		try++;
	}
	if (try==10) ms_warning("msv4l2: buffers not dequeued at exit !");
	msv4l2_do_munmap(s);
close:
	msv4l2_close(s);
	ms_message("msv4l2_thread exited.");
	ms_thread_exit(NULL);
	return NULL;
}

static void msv4l2_preprocess(MSFilter *f){
	V4l2State *s=(V4l2State*)f->data;
	s->thread_run=TRUE;
	ms_thread_create(&s->thread,NULL,msv4l2_thread,s);
	s->th_frame_count=-1;
	s->mean_inter_frame=0;
}
Example #2
0
static int msv4l2_check_configured(V4l2State *s){
	if (s->configured) return 0;
	if (s->fd!=-1){
		msv4l2_close(s);
	}
	if (msv4l2_open(s)==0){
		msv4l2_configure(s);
	}
	return 0;
}
Example #3
0
static int msv4l2_get_pixfmt(MSFilter *f, void *arg){
	V4l2State *s=(V4l2State*)f->data;
	if (s->fd==-1){
		if (msv4l2_open(s)==0){
			msv4l2_configure(s);
			*(MSPixFmt*)arg=s->pix_fmt;
#ifdef V4L2_THREADED
			msv4l2_close(s);
#endif
			return 0;
		}else return -1;
	}
	*(MSPixFmt*)arg=s->pix_fmt;
	return 0;
}
Example #4
0
static void *msv4l2_thread(void *ptr){
	V4l2State *s=(V4l2State*)ptr;
	int err=-1;
	ms_message("msv4l2_thread starting");
	if (s->fd!=-1)
	{
		ms_warning("msv4l2 file descriptor already openned fd:%d",s->fd);
		goto exit;
	}
	if( msv4l2_open(s)!=0){
		ms_warning("msv4l2 could not be openned");
		goto close;
	}
	if (!s->configured && msv4l2_configure(s)!=0){
		ms_warning("msv4l2 could not be configured");		
		goto close;
	}
	if (msv4l2_do_mmap(s)!=0)
	{
		ms_warning("msv4l2 do mmap");
		goto close;
	}
	ms_message("V4L2 video capture started.");
	while(s->thread_run)
	{
		mblk_t *m;
		if (s->fd!=-1){
			mblk_t *m;
			m=v4lv2_grab_image(s);
			if (m){
				mblk_t *om=dupb(m);
				mblk_set_marker_info(om,(s->pix_fmt==MS_MJPEG));
				ms_mutex_lock(&s->mutex);
				putq(&s->rq,om);
				ms_mutex_unlock(&s->mutex);
			}
		}
	}	
	ms_message("thread:%d",s->thread_run);
munmap:	
	msv4l2_do_munmap(s);
close:
	msv4l2_close(s);
exit:
	ms_message("msv4l2_thread exited.");
	s->fd = -1;
	ms_thread_exit(NULL);
}
Example #5
0
static void msv4l2_preprocess(MSFilter *f){
	V4l2State *s=(V4l2State*)f->data;
#ifdef V4L2_THREADED
	ms_thread_create(&s->thread,NULL,msv4l2_thread,s);
#else
	if (s->fd==-1 && msv4l2_open(s)!=0) {
		return;
	}
	if (!s->configured && msv4l2_configure(s)!=0){
		return;
	}
	if (msv4l2_do_mmap(s)==0){
		ms_message("V4L2 video capture started.");
	}else{
		msv4l2_close(s);
	}
	s->start_time=f->ticker->time;
#endif
}