implemented set_active, enable and disable routines for v4l2 capture

implemented pause v4l2 capture
This commit is contained in:
niels
2011-04-11 00:19:36 +02:00
parent 817373cc57
commit fa73aa5d67
2 changed files with 51 additions and 4 deletions

View File

@@ -43,7 +43,6 @@
*/ */
//@ FIXME: fix greyscale
//@ FIXME: not all drivers implement TRY_FMT //@ FIXME: not all drivers implement TRY_FMT
//@ FIXME: find maximum width/height: start with large and TRY_FMT //@ FIXME: find maximum width/height: start with large and TRY_FMT
//@ TODO: add support for tuner (set frequency) //@ TODO: add support for tuner (set frequency)
@@ -114,6 +113,7 @@ typedef struct
VJFrame *buffer_filled; VJFrame *buffer_filled;
uint8_t *tmpbuf; uint8_t *tmpbuf;
int is_streaming; int is_streaming;
int pause_read;
AVCodec *codec; AVCodec *codec;
AVCodecContext *c; AVCodecContext *c;
@@ -413,7 +413,7 @@ static int v4l2_try_pix_format( v4l2info *v, int pixelformat, int wid, int hei,
if( greycap ) { if( greycap ) {
int gc = atoi(greycap); int gc = atoi(greycap);
if( gc == 1 ) { if( gc == 1 ) {
v4l2_pixel_format = V4L2_PIX_FMT_GREY; //@ FIXME v4l2_pixel_format = V4L2_PIX_FMT_GREY;
veejay_msg(VEEJAY_MSG_DEBUG, "v4l2: setting grey scale (env)"); veejay_msg(VEEJAY_MSG_DEBUG, "v4l2: setting grey scale (env)");
v->grey=1; v->grey=1;
} }
@@ -913,6 +913,7 @@ v4l2_rw_fallback:
v->buffers[0].length = v->sizeimage; v->buffers[0].length = v->sizeimage;
v->buffers[0].start = malloc( v->sizeimage * 2 ); v->buffers[0].start = malloc( v->sizeimage * 2 );
} }
@@ -1022,6 +1023,10 @@ int v4l2_pull_frame(void *vv,VJFrame *dst)
int n = 0; int n = 0;
v4l2info *v = (v4l2info*) vv; v4l2info *v = (v4l2info*) vv;
if( (v->rw == 1 && v->pause_read ) || (v->rw == 0 && !v->is_streaming) )
return 0;
if( v->scaler == NULL ) { if( v->scaler == NULL ) {
int tmp = dst->format; int tmp = dst->format;
sws_template templ; sws_template templ;
@@ -1703,6 +1708,11 @@ static void *v4l2_grabber_thread( void *v )
while( 1 ) { while( 1 ) {
int err = (v4l2->rw); int err = (v4l2->rw);
if( ( !v4l2->is_streaming && v4l2->rw == 0 ) || ( v4l2->rw == 1 && v4l2->pause_read ) ) {
usleep(1000);
continue;
}
while( ( err = v4l2_poll( v4l2, 1, 200 ) ) < 0 ) { while( ( err = v4l2_poll( v4l2, 1, 200 ) ) < 0 ) {
if( !(err == -1) ) { if( !(err == -1) ) {
break; break;
@@ -1750,6 +1760,27 @@ int v4l2_thread_start( v4l2_thread_info *i )
return 0; return 0;
} }
void v4l2_thread_set_status( v4l2_thread_info *i, int status )
{
v4l2info *v = (v4l2info* )i->v4l2;
lock_(i);
if( v->rw == 0 ) {
if( status == 0 ) {
v4l2_stop_video_capture(i->v4l2);
v4l2_vidioc_qbuf( i->v4l2 );
} else {
v4l2_start_video_capture(i->v4l2);
}
} else {
if( status == 0 ) {
v->pause_read = 1;
} else {
v->pause_read = 0;
}
}
unlock_(i);
}
void v4l2_thread_stop( v4l2_thread_info *i ) void v4l2_thread_stop( v4l2_thread_info *i )
{ {
lock_(i); lock_(i);

View File

@@ -1171,8 +1171,13 @@ int vj_tag_del(int id)
if(tag->capture_type==1) if(tag->capture_type==1)
#ifdef HAVE_V4L2 #ifdef HAVE_V4L2
v4l2_close( vj_tag_input->unicap[tag->index]); if( no_v4l2_threads_ ) {
#else v4l2_close( vj_tag_input->unicap[tag->index]);
} else {
v4l2_thread_stop( v4l2_thread_info_get(vj_tag_input->unicap[tag->index]));
}
#endif
#ifdef HAVE_V4L1
v4lvideo_destroy( vj_tag_input->unicap[tag->index] ); v4lvideo_destroy( vj_tag_input->unicap[tag->index] );
#endif #endif
if(tag->blackframe) if(tag->blackframe)
@@ -2350,6 +2355,11 @@ int vj_tag_disable(int t1) {
// v4lvideo_grabstop(vj_tag_input->unicap[tag->index]); // v4lvideo_grabstop(vj_tag_input->unicap[tag->index]);
} }
#endif #endif
#ifdef HAVE_V4L2
if(tag->capture_type==1) {
v4l2_thread_set_status( v4l2_thread_info_get(vj_tag_input->unicap[tag->index]),0 );
}
#endif
#ifdef HAVE_UNICAP #ifdef HAVE_UNICAP
if( tag->capture_type == 0 ) if( tag->capture_type == 0 )
vj_unicap_set_pause( vj_tag_input->unicap[tag->index], 1 ); vj_unicap_set_pause( vj_tag_input->unicap[tag->index], 1 );
@@ -2394,6 +2404,9 @@ int vj_tag_enable(int t1) {
v4lvideo_set_paused( vj_tag_input->unicap[tag->index],0); v4lvideo_set_paused( vj_tag_input->unicap[tag->index],0);
tag->active = 1; tag->active = 1;
} }
#endif
#ifdef HAVE_V4L2
v4l2_thread_set_status( v4l2_thread_info_get( vj_tag_input->unicap[tag->index] ), 1 );
#endif #endif
} }
#ifdef HAVE_UNICAP #ifdef HAVE_UNICAP
@@ -2482,6 +2495,9 @@ int vj_tag_set_active(int t1, int active)
if( !v4lvideo_is_paused( vj_tag_input->unicap[tag->index] ) ) if( !v4lvideo_is_paused( vj_tag_input->unicap[tag->index] ) )
v4lvideo_set_paused( vj_tag_input->unicap[tag->index], 1 ); v4lvideo_set_paused( vj_tag_input->unicap[tag->index], 1 );
} }
#endif
#ifdef HAVE_V4L2
v4l2_thread_set_status( v4l2_thread_info_get( vj_tag_input->unicap[tag->index]), active );
#endif #endif
} }
#ifdef HAVE_UNICAP #ifdef HAVE_UNICAP