Ejemplo n.º 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;
}
Ejemplo n.º 2
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);
}
Ejemplo n.º 3
0
static void msv4l2_postprocess(MSFilter *f){
	V4l2State *s=(V4l2State*)f->data;
#ifdef V4L2_THREADED
	s->thread_run = FALSE;
	if(ms_thread_join(s->thread,NULL))
		ms_warning("msv4l2 thread was already stopped");
	else
		ms_message("msv4l2 thread has joined.");
	flushq(&s->rq,0);
#else
	if (s->fd!=-1){
		msv4l2_do_munmap(s);
		msv4l2_close(s);
	}
#endif
}