static void *v4l_thread(void *ptr){ V4lState *s=(V4lState*)ptr; int err=-1; ms_message("v4l_thread starting"); if (s->v4lv2){ #ifdef HAVE_LINUX_VIDEODEV2_H err=v4lv2_do_mmap(s); #endif }else{ err=v4l_do_mmap(s); } if (err<0){ ms_thread_exit(NULL); } while(s->run){ mblk_t *m; #ifdef HAVE_LINUX_VIDEODEV2_H if (s->v4lv2) m=v4lv2_grab_image(s); else #endif m=v4l_grab_image_mmap(s); if (m) { ms_mutex_lock(&s->mutex); putq(&s->rq,dupmsg(m)); ms_mutex_unlock(&s->mutex); } } v4l_do_munmap(s); ms_message("v4l_thread exited."); ms_thread_exit(NULL); }
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; }
static void msv4l2_process(MSFilter *f){ V4l2State *s=(V4l2State*)f->data; #ifdef V4L2_THREADED uint32_t timestamp; int cur_frame; if (s->frame_count==-1){ s->start_time=f->ticker->time; s->frame_count=0; } cur_frame=((f->ticker->time-s->start_time)*s->fps/1000.0); if (cur_frame>=s->frame_count){ mblk_t *om=NULL; ms_mutex_lock(&s->mutex); /*keep the most recent frame if several frames have been captured */ if (s->fd!=-1){ om=getq(&s->rq); } ms_mutex_unlock(&s->mutex); if (om!=NULL){ timestamp=f->ticker->time*90;/* rtp uses a 90000 Hz clockrate for video*/ mblk_set_timestamp_info(om,timestamp); mblk_set_marker_info(om,TRUE); ms_queue_put(f->outputs[0],om); /*ms_message("picture sent");*/ s->frame_count++; } }else{ flushq(&s->rq,0); } #else uint32_t elapsed; if (s->fd!=-1){ /*see it is necessary to output a frame:*/ elapsed=f->ticker->time-s->start_time; if (((float)elapsed*s->fps/1000.0)>s->frame_count){ 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_queue_put(f->outputs[0],om); s->frame_count++; } } } #endif }
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); }
static void *v4l_thread(void *ptr){ V4lState *s=(V4lState*)ptr; int err=-1; ms_message("v4l_thread starting"); if (s->v4lv2){ #ifdef HAVE_LINUX_VIDEODEV2_H err=v4lv2_do_mmap(s); #endif }else{ err=v4l_do_mmap(s); } if (err<0){ ms_thread_exit(NULL); } while(s->run){ mblk_t *m; #ifdef HAVE_LINUX_VIDEODEV2_H if (s->v4lv2) m=v4lv2_grab_image(s); else #endif m=v4l_grab_image_mmap(s); if (s->vsize.width!=s->got_vsize.width){ if (m){ /* mblock was allocated by crop or pad! */ ms_mutex_lock(&s->mutex); putq(&s->rq,m); ms_mutex_unlock(&s->mutex); }else{ ms_error("grabbing failed !"); } } else if (m!=NULL) { mblk_t *dm=dupmsg(m); ms_mutex_lock(&s->mutex); putq(&s->rq,dm); ms_mutex_unlock(&s->mutex); } } v4l_do_munmap(s); ms_message("v4l_thread exited."); ms_thread_exit(NULL); return NULL; }
static void v4l2_process(MSFilter *f){ V4l2State *s=(V4l2State*)f->data; uint32_t elapsed; if (s->fd!=-1){ /*see it is necessary to output a frame:*/ elapsed=f->ticker->time-s->start_time; if (((float)elapsed*s->fps/1000.0)>s->frame_count){ 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_queue_put(f->outputs[0],om); s->frame_count++; } } } }