From d19774f0e7a6e95ac499c99d36fca5dba0c2914a Mon Sep 17 00:00:00 2001 From: c0ntrol Date: Tue, 24 May 2016 20:49:24 +0200 Subject: [PATCH] issue #116, #115 --- .../veejay-server/libstream/v4l2utils.c | 46 +++++++++++++++---- .../veejay-server/veejay/vj-perform.c | 35 +++++++------- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/veejay-current/veejay-server/libstream/v4l2utils.c b/veejay-current/veejay-server/libstream/v4l2utils.c index c3aafd06..3cd5104d 100644 --- a/veejay-current/veejay-server/libstream/v4l2utils.c +++ b/veejay-current/veejay-server/libstream/v4l2utils.c @@ -277,7 +277,8 @@ static int v4l2_vidioc_qbuf( v4l2info *v ) v->buffer.index = i; if( -1 == vioctl( v->fd, VIDIOC_QBUF, &(v->buffer)) ) { - veejay_msg(0, "v4l2: first VIDIOC_QBUF failed with %s", strerror(errno)); + if( errno != ENODEV ) + veejay_msg(0, "v4l2: first VIDIOC_QBUF failed with %s", strerror(errno)); return -1; } } @@ -288,7 +289,8 @@ static int v4l2_stop_video_capture( v4l2info *v ) { if(v->is_streaming) { if( -1 == vioctl( v->fd, VIDIOC_STREAMOFF, &(v->buftype)) ) { - veejay_msg(0,"v4l2: unable to stop streaming:%d, %s",errno,strerror(errno)); + if( errno != ENODEV ) + veejay_msg(0,"v4l2: unable to stop streaming:%d, %s",errno,strerror(errno)); return 0; } v->is_streaming = 0; @@ -801,14 +803,22 @@ static void v4l2_set_output_pointers( v4l2info *v, void *src ) VJFrame *v4l2_get_dst( void *vv, uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *A ) { v4l2info *v = (v4l2info*) vv; + v4l2_thread_info *i = (v4l2_thread_info *) v->video_info; + + if(i->stop) + return NULL; + if(v->threaded) - lock_(v->video_info); + lock_(i); + v->host_frame->data[0] = Y; v->host_frame->data[1] = U; v->host_frame->data[2] = V; v->host_frame->data[3] = A; + if(v->threaded) - unlock_(v->video_info); + unlock_(i); + return v->host_frame; } @@ -1209,8 +1219,9 @@ static int v4l2_pull_frame_intern( v4l2info *v ) if( v->rw == 0 ) { if( -1 == vioctl( v->fd, VIDIOC_DQBUF, &(v->buffer))) { - veejay_msg(0, "v4l2: VIDIOC_DQBUF: %s", strerror(errno)); - if( errno != EIO ) { + if( errno == ENODEV ) { + veejay_msg(0, "v4l2: %s (anymore)", strerror(errno)); + } else if( errno != EIO ) { veejay_msg(0,"v4l2: unable to grab a frame: %d, %s",errno,strerror(errno)); } v4l2_stop_video_capture(v); @@ -1302,7 +1313,7 @@ int v4l2_pull_frame(void *vv,VJFrame *dst) v4l2info *v = (v4l2info*) vv; - if( (v->rw == 1 && v->pause_read ) || (v->rw == 0 && !v->is_streaming) ) + if( (dst == NULL || v->rw == 1 && v->pause_read ) || (v->rw == 0 && !v->is_streaming) ) return 0; if( v->scaler == NULL ) { @@ -1447,7 +1458,7 @@ void v4l2_close( void *d ) if( v->buffers ) { free(v->buffers); - v->host_frame = NULL; + v->buffers = NULL; } free(v); @@ -2058,7 +2069,8 @@ static void *v4l2_grabber_thread( void *v ) while( 1 ) { int err = (v4l2->rw); - + int ret = 0; + if( i->stop ) { veejay_msg(VEEJAY_MSG_DEBUG, "v4l2: Closing video capture device"); goto v4l2_grabber_exit; @@ -2086,6 +2098,18 @@ static void *v4l2_grabber_thread( void *v ) continue; } + ret = v4l2_poll( v4l2, 1, 200 ); + if( ret > 0 ) { + if(!v4l2_pull_frame_intern( v4l2 ) ) + err = -1; + else + i->retries = max_retries; + } + else if ( ret == -1 ) { + err = -1; + } + + /* while( ( err = v4l2_poll( v4l2, 1, 200 ) ) < 0 ) { if( !(err == -1) ) { break; @@ -2093,6 +2117,7 @@ static void *v4l2_grabber_thread( void *v ) } if( err > 0 && !v4l2_pull_frame_intern( v4l2 ) ) err = -1; + */ if( err == -1 ) { if( i->retries < 0 ) { @@ -2101,6 +2126,7 @@ static void *v4l2_grabber_thread( void *v ) } else { i->retries --; + nanosleep(&req, NULL); } } @@ -2163,7 +2189,7 @@ int v4l2_thread_pull( v4l2_thread_info *i , VJFrame *dst ) int status = 0; lock_(i); - if(i->stop) { + if(i->stop || dst == NULL) { unlock_(i); return status; } diff --git a/veejay-current/veejay-server/veejay/vj-perform.c b/veejay-current/veejay-server/veejay/vj-perform.c index 7353fddd..ea20e3f9 100644 --- a/veejay-current/veejay-server/veejay/vj-perform.c +++ b/veejay-current/veejay-server/veejay/vj-perform.c @@ -167,7 +167,7 @@ static int vj_perform_post_chain_tag(veejay_t *info, VJFrame *frame); static void seq_play_sample( veejay_t *info, int n, int t); static int vj_perform_valid_sequence( veejay_t *info, int *type ); static void vj_perform_plain_fill_buffer(veejay_t * info, int *result); -static int vj_perform_tag_fill_buffer(veejay_t * info); +static void vj_perform_tag_fill_buffer(veejay_t * info); static void vj_perform_clear_cache(void); static int vj_perform_increase_tag_frame(veejay_t * info, long num); static int vj_perform_increase_plain_frame(veejay_t * info, long num); @@ -2944,7 +2944,6 @@ void vj_perform_record_offline_tag_frame(veejay_t *info) } void vj_perform_record_tag_frame(veejay_t *info) { - video_playback_setup *settings = info->settings; uint8_t *frame[4]; int res = 1; int stream_id = info->uc->sample_id; @@ -3004,7 +3003,7 @@ void vj_perform_record_tag_frame(veejay_t *info) { } -static int vj_perform_tag_fill_buffer(veejay_t * info) +static void vj_perform_tag_fill_buffer(veejay_t * info) { int error = 1; uint8_t *frame[4]; @@ -3028,7 +3027,7 @@ static int vj_perform_tag_fill_buffer(veejay_t * info) 0, }; vj_frame_copy(feedback_buffer,frame,strides); - return 1; + return; } if(!active) @@ -3061,8 +3060,6 @@ static int vj_perform_tag_fill_buffer(veejay_t * info) { info->uc->take_bg = vj_perform_take_bg(info,info->effect_frame1); } - - return 1; } static void vj_perform_pre_chain(veejay_t *info, VJFrame *frame) @@ -3321,14 +3318,16 @@ int vj_perform_queue_audio_frame(veejay_t *info) if(el->has_audio) { num_samples = vj_tag_get_audio_frame(info->uc->sample_id, a_buf); - if(num_samples <= 0 ) - { - num_samples = pred_len; - veejay_memset(a_buf, 0, num_samples * bps ); - } + } + + if(num_samples <= 0 ) + { + num_samples = pred_len; + veejay_memset(a_buf, 0, num_samples * bps ); } break; } + vj_jack_continue( settings->current_playback_speed ); vj_perform_play_audio( settings, a_buf, (num_samples * bps )); @@ -3852,16 +3851,14 @@ int vj_perform_queue_video_frame(veejay_t *info, const int skip_incr) if( (info->seq->active && info->seq->rec_id) || info->settings->offline_record ) pvar_.enc_active = 1; + vj_perform_tag_fill_buffer(info); - if (vj_perform_tag_fill_buffer(info)) - { - if(vj_perform_verify_rows(info)) - vj_perform_tag_complete_buffers(info, &is444); + if(vj_perform_verify_rows(info)) + vj_perform_tag_complete_buffers(info, &is444); - cur_out = vj_perform_render_magic( info, info->settings, is444 ); - } - res = 1; - break; + cur_out = vj_perform_render_magic( info, info->settings, is444 ); + res = 1; + break; default: return 0; }