From a16d153ad80459022e97f6de515bd801ecde3193 Mon Sep 17 00:00:00 2001 From: c0ntrol Date: Tue, 7 Jul 2020 21:38:45 +0200 Subject: [PATCH] use monotonic clock instead of system clock, allow calibration of any stream source and not just video4linux devices --- veejay-current/veejay-client/src/callback.c | 14 +- veejay-current/veejay-client/src/vj-api.c | 70 +++-- veejay-current/veejay-core/libvjmem/memcpy.c | 2 +- .../veejay-server/libsample/sampleadm.c | 17 +- .../veejay-server/libstream/vj-net.c | 2 +- .../veejay-server/libstream/vj-tag.c | 258 ++++++++---------- .../veejay-server/libstream/vj-tag.h | 5 +- .../thirdparty/bio2jack/bio2jack.c | 8 +- .../veejay-server/veejay/liblavplayvj.c | 10 +- veejay-current/veejay-server/veejay/veejay.c | 2 +- .../veejay-server/veejay/vj-event.c | 6 +- 11 files changed, 178 insertions(+), 216 deletions(-) diff --git a/veejay-current/veejay-client/src/callback.c b/veejay-current/veejay-client/src/callback.c index d69068d9..fef33d0e 100644 --- a/veejay-current/veejay-client/src/callback.c +++ b/veejay-current/veejay-client/src/callback.c @@ -2541,15 +2541,14 @@ void on_cali_take_button_clicked( GtkButton *button, gpointer data ) } gint duration=get_nums( "cali_duration_spin" ); - if( cali_stream_id <= 0 ) { - if(info->status_tokens[STREAM_TYPE] == STREAM_VIDEO4LINUX ) - cali_stream_id = - info->status_tokens[CURRENT_ID]; - } + if( info->status_tokens[STREAM_TYPE] != STREAM_VIDEO4LINUX ) { + vj_msg(VEEJAY_MSG_INFO,"Please use a camera source for light/dark frame calibration"); + } + + cali_stream_id = info->status_tokens[CURRENT_ID]; if( cali_stream_id <= 0 ) { error_dialog( "Error", "No source selected to calibrate. Play a Live stream or double click one in the List"); - return; } @@ -2560,9 +2559,6 @@ void on_cali_take_button_clicked( GtkButton *button, gpointer data ) method ); info->uc.cali_duration = duration; - - //@ substract duration in status pipe - } void on_cali_darkframe_clicked( GtkButton *button, gpointer data ) diff --git a/veejay-current/veejay-client/src/vj-api.c b/veejay-current/veejay-client/src/vj-api.c index 069f9efa..da6ca716 100644 --- a/veejay-current/veejay-client/src/vj-api.c +++ b/veejay-current/veejay-client/src/vj-api.c @@ -7722,47 +7722,39 @@ static void update_globalinfo(int *history, int pm, int last_pm) if( pm == MODE_STREAM ) { - if( info->status_tokens[STREAM_TYPE] == STREAM_VIDEO4LINUX ) + if(info->uc.cali_duration > 0 ) { - if(info->uc.cali_duration > 0 ) + GtkWidget *tb = widget_cache[WIDGET_CALI_TAKE_BUTTON]; + info->uc.cali_duration--; + vj_msg(VEEJAY_MSG_INFO, "Calibrate step %d of %d",info->uc.cali_duration,info->uc.cali_stage); + if(info->uc.cali_duration == 0) { - GtkWidget *tb = widget_cache[WIDGET_CALI_TAKE_BUTTON]; - info->uc.cali_duration--; - vj_msg(VEEJAY_MSG_INFO, - "Calibrate step %d of %d", - info->uc.cali_duration, - info->uc.cali_stage); - if(info->uc.cali_duration == 0) + info->uc.cali_stage ++; //@ cali_stage = 1, done capturing black frames + switch(info->uc.cali_stage) { - info->uc.cali_stage ++; //@ cali_stage = 1, done capturing black frames - - switch(info->uc.cali_stage) - { - case 1: //@ capturing black frames - gtk_label_set_text( GTK_LABEL( widget_cache[WIDGET_CURRENT_STEP_LABEL] ), - "Please take an image of a uniformly lit area in placed in front of your lens."); - gtk_button_set_label( GTK_BUTTON(tb), "Take White Frames"); - break; - case 2: - case 3: - gtk_label_set_text( GTK_LABEL( widget_cache[WIDGET_CURRENT_STEP_LABEL] ), - "Image calibrated. You may need to adjust brightness."); - if(!gtk_widget_is_sensitive(widget_cache[ WIDGET_CALI_SAVE_BUTTON ] )) - gtk_widget_set_sensitive(widget_cache[ WIDGET_CALI_SAVE_BUTTON ], TRUE); - break; - default: - gtk_label_set_text( GTK_LABEL( widget_cache[WIDGET_CURRENT_STEP_LABEL] ), - "Image calibrated. You may need to adjust brightness."); - gtk_button_set_label( GTK_BUTTON(tb), "Take Black Frames"); - veejay_msg(VEEJAY_MSG_ERROR, "Warning, mem leak if not reset first."); - break; - } - - if(info->uc.cali_stage >= 2 ) - { - info->uc.cali_stage = 0; - } - } + case 1: //@ capturing black frames + gtk_label_set_text( GTK_LABEL( widget_cache[WIDGET_CURRENT_STEP_LABEL] ), + "Please take an image of a uniformly lit area in placed in front of your lens."); + gtk_button_set_label( GTK_BUTTON(tb), "Take White Frames"); + break; + case 2: + case 3: + gtk_label_set_text( GTK_LABEL( widget_cache[WIDGET_CURRENT_STEP_LABEL] ), + "Image calibrated. You may need to adjust brightness."); + if(!gtk_widget_is_sensitive(widget_cache[ WIDGET_CALI_SAVE_BUTTON ] )) + gtk_widget_set_sensitive(widget_cache[ WIDGET_CALI_SAVE_BUTTON ], TRUE); + break; + default: + gtk_label_set_text( GTK_LABEL( widget_cache[WIDGET_CURRENT_STEP_LABEL] ), + "Image calibrated. You may need to adjust brightness."); + gtk_button_set_label( GTK_BUTTON(tb), "Take Black Frames"); + veejay_msg(VEEJAY_MSG_ERROR, "Warning, mem leak if not reset first."); + break; + } + if(info->uc.cali_stage >= 2 ) + { + info->uc.cali_stage = 0; + } } } } @@ -9985,7 +9977,7 @@ static void add_sample_to_effect_sources_list(gint id, -1 ); GtkTreeIter iter2; - if(type == STREAM_NO_STREAM) + if(type != STREAM_NO_STREAM) { gtk_list_store_append( cali_sourcestore,&iter2); gtk_list_store_set(cali_sourcestore,&iter2, diff --git a/veejay-current/veejay-core/libvjmem/memcpy.c b/veejay-current/veejay-core/libvjmem/memcpy.c index 7d3909d5..b18d773a 100644 --- a/veejay-current/veejay-core/libvjmem/memcpy.c +++ b/veejay-current/veejay-core/libvjmem/memcpy.c @@ -163,7 +163,7 @@ static int selected_best_memset = 1; static double get_time() { struct timespec ts; - clock_gettime( CLOCK_REALTIME, &ts ); + clock_gettime( CLOCK_MONOTONIC, &ts ); return (double) ts.tv_sec + (double) ts.tv_nsec / 1000000000.0; } diff --git a/veejay-current/veejay-server/libsample/sampleadm.c b/veejay-current/veejay-server/libsample/sampleadm.c index 9a24d48a..2764d72b 100644 --- a/veejay-current/veejay-server/libsample/sampleadm.c +++ b/veejay-current/veejay-server/libsample/sampleadm.c @@ -55,6 +55,7 @@ #include #include #include +#include //#define KAZLIB_OPAQUE_DEBUG 1 #ifdef HAVE_XML2 @@ -625,7 +626,7 @@ int sample_has_cali_fx(int sample_id) return -1; int i; for( i =0;i < SAMPLE_MAX_EFFECTS; i ++ ) { - if(si->effect_chain[i]->effect_id == 190) + if(si->effect_chain[i]->effect_id == VJ_IMAGE_EFFECT_CALI) return i; } return -1; @@ -633,25 +634,15 @@ int sample_has_cali_fx(int sample_id) void sample_cali_prepare( int sample_id, int slot, int chan ) { - sample_info *si = sample_get(sample_id); - if(si == NULL) - return; vj_tag *tag = vj_tag_get( chan ); if( tag == NULL || tag->source_type != VJ_TAG_TYPE_CALI ) return; - //FIXME: prepare cali - /* - int fx_id = nvj_effect_real_to_sequence( - si->effect_chain[slot]->effect_id ); - if( fx_id >= 0 ) { - vj_tag_cali_prepare_now( chan, fx_id ); - veejay_msg(VEEJAY_MSG_DEBUG, "Prepared calibration data"); - }*/ + vj_tag_cali_prepare_now( tag ); + veejay_msg(VEEJAY_MSG_DEBUG, "Prepared calibration data"); } - int sample_get_el_position( int sample_id, int *start, int *end ) { sample_info *si = sample_get(sample_id); diff --git a/veejay-current/veejay-server/libstream/vj-net.c b/veejay-current/veejay-server/libstream/vj-net.c index 7d177617..ec142311 100644 --- a/veejay-current/veejay-server/libstream/vj-net.c +++ b/veejay-current/veejay-server/libstream/vj-net.c @@ -58,7 +58,7 @@ static void net_delay(long ms, long sec ) struct timespec ts; ts.tv_sec = sec; ts.tv_nsec = MS_TO_NANO( ms ); - clock_nanosleep( CLOCK_REALTIME,0, &ts, NULL ); + clock_nanosleep( CLOCK_MONOTONIC,0, &ts, NULL ); } static int my_screen_id = -1; diff --git a/veejay-current/veejay-server/libstream/vj-tag.c b/veejay-current/veejay-server/libstream/vj-tag.c index 61092a2d..ed63711f 100644 --- a/veejay-current/veejay-server/libstream/vj-tag.c +++ b/veejay-current/veejay-server/libstream/vj-tag.c @@ -62,6 +62,7 @@ #include #include +#include static int recount_hash = 1; static unsigned int sample_count = 0; @@ -84,7 +85,7 @@ int _vj_tag_new_yuv4mpeg(vj_tag * tag, int stream_nr, int w, int h, float fps); extern int frei0r_get_param_count( void *port); extern void dummy_rgb_apply(VJFrame *frame, int r, int g, int b); -extern int cali_prepare( void *ed, double meanY, double meanU, double meanV, uint8_t *data, int len, int uv_len ); + #define RUP8(num)(((num)+8)&~8) @@ -97,6 +98,7 @@ typedef struct int uv_len; int len; double mean[3]; + void *ptr; } cali_tag_t; #define CALI_DARK 0 @@ -484,7 +486,7 @@ static int cali_write_file( char *file, vj_tag *tag , editlist *el) h, len, uv_len, - tag->mean[0], + tag->mean[0], tag->mean[1], tag->mean[2] ); @@ -592,7 +594,7 @@ static int cali_read_file( cali_tag_t *p, char *file,int w, int h ) p->data = (uint8_t*) vj_malloc(sizeof(uint8_t) * 3 * (len+uv_len+uv_len)); p->bf = p->data; - p->lf = p->data + (len + (2*uv_len)); + p->lf = p->data + (len + (2*uv_len)); p->mf = p->lf + (len + (2*uv_len)); p->uv_len = uv_len; @@ -632,17 +634,23 @@ static int _vj_tag_new_cali( vj_tag *tag, int stream_nr, int w, int h ) cali_tag_t *p = NULL; - p = (cali_tag_t*) vj_malloc(sizeof(cali_tag_t)); + p = (cali_tag_t*) vj_calloc(sizeof(cali_tag_t)); if(!p) return 0; - memset(p, 0, sizeof(cali_tag_t)); if(!cali_read_file( p, tag->source_name,w,h ) ) { veejay_msg(VEEJAY_MSG_ERROR, "Failed to find dark frame '%s'", tag->source_name ); free(p); return 0; } - + + p->ptr = cali_malloc(0,0); + if(!p->ptr) { + veejay_msg(VEEJAY_MSG_ERROR, "Failed to allocate"); + free(p); + return 0; + } + vj_tag_input->cali[stream_nr] = (void*)p; veejay_msg(VEEJAY_MSG_INFO, "Image Calibration files ready"); @@ -974,7 +982,7 @@ int vj_tag_new(int type, char *filename, int stream_nr, editlist * el, int pix_f tag->opacity = 0; tag->priv = NULL; tag->subrender = 1; - + if(type == VJ_TAG_TYPE_AVFORMAT ) tag->priv = avformat_thread_allocate(_tag_info->effect_frame1); @@ -1348,14 +1356,7 @@ int vj_tag_del(int id) v4l2_thread_stop( v4l2_thread_info_get(vj_tag_input->v4l2[tag->index])); } #endif - if(tag->blackframe)free(tag->blackframe); - if( tag->bf ) free(tag->bf); - if( tag->bfu ) free(tag->bfu); - if( tag->bfv ) free(tag->bfv); - if( tag->lf ) free(tag->lf); - if( tag->lfu ) free(tag->lfu); - if( tag->lfv ) free(tag->lfv); - + break; case VJ_TAG_TYPE_YUV4MPEG: veejay_msg(VEEJAY_MSG_INFO,"Closing yuv4mpeg file %s (Stream %d)", @@ -1387,7 +1388,8 @@ int vj_tag_del(int id) { cali_tag_t *calpic = (cali_tag_t*) vj_tag_input->cali[tag->index]; if(calpic) { - if(calpic->lf) free(calpic->data); + if(calpic->data) free(calpic->data); + if(calpic->ptr) cali_free(calpic->ptr); free(calpic); } vj_tag_input->cali[tag->index] = NULL; @@ -1409,6 +1411,14 @@ int vj_tag_del(int id) vj_tag_chain_free( tag->id,1 ); + if(tag->blackframe)free(tag->blackframe); + if( tag->bf ) free(tag->bf); + if( tag->bfu ) free(tag->bfu); + if( tag->bfv ) free(tag->bfv); + if( tag->lf ) free(tag->lf); + if( tag->lfu ) free(tag->lfu); + if( tag->lfv ) free(tag->lfv); + if(tag->encoder_active) vj_tag_stop_encoder( tag->id ); if(tag->source_name) @@ -2317,20 +2327,14 @@ int vj_tag_has_cali_fx( int t1 ) { return -1; } -void vj_tag_cali_prepare_now( int t1, int fx_id ) { - vj_tag *tag = vj_tag_get(t1); - if(tag==NULL) - return; +void vj_tag_cali_prepare_now( vj_tag *tag ) { if(tag->source_type != VJ_TAG_TYPE_CALI ) return; cali_tag_t *p = (cali_tag_t*) vj_tag_input->cali[tag->index]; if( p == NULL ) return; - if( fx_id <= 0) - return; - //FIXME - cali_prepare( NULL, //@ ptr to cali instance + cali_prepare( p->ptr, //@ ptr to cali instance p->mean[0], p->mean[1], p->mean[2], @@ -2341,20 +2345,12 @@ void vj_tag_cali_prepare_now( int t1, int fx_id ) { } void vj_tag_cali_prepare( int t1 , int pos, int cali_tag) { - vj_tag *tag = vj_tag_get(t1); - if (!tag) - return; vj_tag *tagc = vj_tag_get(cali_tag); if(!tagc) return; if(tagc->source_type != VJ_TAG_TYPE_CALI) return; - //FIXME - /* - int fx_id = vj_effect_real_to_sequence( tag->effect_chain[pos]->effect_id ); - if (fx_id >= 0 ) { - vj_tag_cali_prepare_now( cali_tag, fx_id ); - }*/ + vj_tag_cali_prepare_now( tagc ); } int vj_tag_get_chain_status(int t1, int position) @@ -3269,9 +3265,6 @@ static void whiteframe_new(uint8_t *buf, int w, int h, int uv_len, uint8_t * } mean_of_y = mean_of_y / (w*h); - - tag->tabmean[0][ tag->bf_count - 1 ] = mean_of_y; - mean_of_u = mean_of_u / uv_len; mean_of_v = mean_of_v / uv_len; @@ -3336,13 +3329,12 @@ static void whiteframe_process( uint8_t *Y, uint8_t *U, uint8_t *V, int w, int h mean_of_y = mean_of_y / (w*h); mean_of_u = mean_of_u / uv_len; mean_of_v = mean_of_v / uv_len; - tag->tabmean[0][ tag->bf_count - 1 ] = mean_of_y; } static void master_lightframe(int w,int h, int uv_len, vj_tag *tag) { int i; - int duration =tag->cali_duration -1; + int duration =tag->cali_duration; uint8_t *bf = cali_get(tag,CALI_LIGHT,w*h,uv_len); uint8_t *bu = bf + (w*h); uint8_t *bv = bu + uv_len; @@ -3389,7 +3381,7 @@ static void master_lightframe(int w,int h, int uv_len, vj_tag *tag) static void master_blackframe(int w, int h, int uv_len, vj_tag *tag ) { int i; - int duration =tag->cali_duration - 1; + int duration =tag->cali_duration; uint8_t *bf = cali_get(tag,CALI_DARK,w*h,uv_len); uint8_t *bu = bf + (w*h); uint8_t *bv = bu + uv_len; @@ -3566,37 +3558,47 @@ int vj_tag_grab_blackframe(int t1, int duration, int median_radius , int mode) if(!tag) return 0; if( tag->source_type != VJ_TAG_TYPE_V4L ) { - veejay_msg(VEEJAY_MSG_INFO, "Source is not a video device"); - return 0; + veejay_msg(VEEJAY_MSG_WARNING, "Calibration source is not a video device"); } - if( duration <= 0 ) + if( duration < 1 ) return 0; if( median_radius <= 0 ) { median_radius = 0; } - veejay_msg(VEEJAY_MSG_INFO, "Creating %s (%d frames) median=%d",(mode==0?"Blackframe":"Lightframe"),duration, median_radius ); + tag->cali_duration = duration; + + veejay_msg(VEEJAY_MSG_INFO,"Setup per-pixel camera calibration:"); + veejay_msg(VEEJAY_MSG_INFO," This method attempts to fix the inhomogenous brightness distribution. Each little pixel in your CCD camera is slightly different."); + veejay_msg(VEEJAY_MSG_INFO," This method may also help reduce the effect of dust collected on the lens."); + veejay_msg(VEEJAY_MSG_INFO," Processing starts immediately after taking the dark and light frames."); + veejay_msg(VEEJAY_MSG_INFO," Take the dark frame while having the cap on the lens."); + veejay_msg(VEEJAY_MSG_INFO," Take the light frame while illuminating the lens with a light source. The image should be white."); + veejay_msg(VEEJAY_MSG_INFO," You can save the dark,light and flattened image frame using reloaded."); + veejay_msg(VEEJAY_MSG_INFO,"\tMode: %s", (mode == 0 ? "Darkframe" : "Lightframe" ) ); + veejay_msg(VEEJAY_MSG_INFO,"\tMedian radius: %d", median_radius ); + veejay_msg(VEEJAY_MSG_INFO,"\tDuration: %d", duration ); tag->noise_suppression = (mode == 0 ? V4L_BLACKFRAME : V4L_WHITEFRAME ); tag->median_radius = median_radius; - tag->bf_count = duration; - tag->has_white = (mode == 1 ? 1 :0); + tag->bf_index = 0; + tag->has_white = (mode == 1 ? 1 :0); + return 1; } + int vj_tag_drop_blackframe(int t1) { vj_tag *tag = vj_tag_get(t1); if(!tag) - return 0; - if( tag->source_type != VJ_TAG_TYPE_V4L ) { - veejay_msg(VEEJAY_MSG_INFO, "Source is not a video device"); - return 0; - } + return 0; + if( tag->blackframe ) { - tag->noise_suppression = -1; - veejay_msg(VEEJAY_MSG_INFO, "Black Frame dropped"); + tag->noise_suppression = -1; + free(tag->blackframe); + tag->blackframe = NULL; } return 1; @@ -3627,94 +3629,11 @@ int vj_tag_get_frame(int t1, VJFrame *dst, uint8_t * abuffer) v4l2_get_dst( vj_tag_input->v4l2[tag->index], buffer[0],buffer[1],buffer[2],buffer[3])); } #endif - switch( tag->noise_suppression ) { - case V4L_BLACKFRAME: - tag->cali_duration = tag->bf_count; - blackframe_new(width,height,uv_len,buffer[0],buffer[1],buffer[2],tag->median_radius,tag); - tag->tabmean[0] = (double*) vj_malloc(sizeof(double)* tag->cali_duration); - if(tag->blackframe == NULL ) { - tag->noise_suppression = 0; - } else { - tag->bf_count --; - tag->noise_suppression = V4L_BLACKFRAME_NEXT; - if(tag->bf_count==0) { - master_blackframe(width,height,uv_len,tag); - tag->noise_suppression = V4L_BLACKFRAME_PROCESS; - veejay_msg(VEEJAY_MSG_INFO, "Please create a lightframe (white)"); - } - } - //@ grab black frame - break; - case V4L_WHITEFRAME: - tag->cali_duration = tag->bf_count; - if(!tag->blackframe) { - veejay_msg(0, "Please start with a black frame first (Put cap on lens)"); - tag->noise_suppression = 0; - break; - } - whiteframe_new( tag->blackframe,width,height,uv_len,buffer[0],buffer[1],buffer[2],tag->median_radius, tag); - tag->bf_count --; - tag->noise_suppression = V4L_WHITEFRAME_NEXT; - if(tag->bf_count <= 0 ) { - tag->noise_suppression = V4L_BLACKFRAME_PROCESS; - master_lightframe( width,height,uv_len,tag ); - master_flatframe( width,height,uv_len, tag ); - veejay_msg(VEEJAY_MSG_DEBUG, "Master flat frame"); - } - break; - case V4L_WHITEFRAME_NEXT: - whiteframe_process(buffer[0],buffer[1],buffer[2],width,height,uv_len,tag->median_radius,tag ); - tag->bf_count --; - if( tag->bf_count <= 0 ) { - tag->noise_suppression = V4L_BLACKFRAME_PROCESS; - master_lightframe( width,height,uv_len,tag); - master_flatframe( width,height,uv_len, tag ); - veejay_msg(VEEJAY_MSG_DEBUG, "Master flat frame"); - } else { - veejay_msg(VEEJAY_MSG_DEBUG, "Whiteframe %d",tag->bf_count ); - } - break; - case V4L_BLACKFRAME_NEXT: - blackframe_process( buffer[0],buffer[1],buffer[2],width,height,uv_len, tag->median_radius,tag ); - if( tag->bf_count <= 0 ) { - tag->noise_suppression = 0; - master_blackframe(width,height,uv_len,tag); - veejay_msg(VEEJAY_MSG_INFO, "Please create a lightframe"); - } else { - veejay_msg(VEEJAY_MSG_DEBUG, "Blackframe %d", tag->bf_count ); - tag->bf_count --; - } - break; - case V4L_BLACKFRAME_PROCESS: - blackframe_subtract( tag,buffer[0],buffer[1],buffer[2],width,height,uv_len, tag->has_white , tag->mean[0],tag->mean[1],tag->mean[2]); - break; - case -1: - if( tag->blackframe ) { - free(tag->blackframe); - tag->blackframe = NULL; - tag->noise_suppression = 0; - } - if( tag->bf ) free(tag->bf); - if( tag->bfu ) free(tag->bfu); - if( tag->bfv ) free(tag->bfv); - if( tag->lf ) free(tag->lf); - if( tag->lfu ) free(tag->lfu); - if( tag->lfv ) free(tag->lfv); - if( tag->tabmean[0]) free(tag->tabmean[0]); - break; - //@ process black frame - default: - break; - } - if( tag->noise_suppression != 0 && tag->noise_suppression != 6 && tag->noise_suppression != 3 ) - veejay_msg(VEEJAY_MSG_DEBUG, "Calibration step %d of %d", tag->bf_count, tag->cali_duration ); - - return 1; - break; + break; case VJ_TAG_TYPE_CALI: { cali_tag_t *p = (cali_tag_t*)vj_tag_input->cali[tag->index]; - if(p) { + if(p && p->mf) { veejay_memcpy(buffer[0], p->mf, len ); veejay_memcpy(buffer[1], p->mf + len, uv_len ); veejay_memcpy(buffer[2], p->mf + len + uv_len, uv_len); @@ -3794,6 +3713,71 @@ int vj_tag_get_frame(int t1, VJFrame *dst, uint8_t * abuffer) break; } + + switch( tag->noise_suppression ) { + + case V4L_BLACKFRAME_PROCESS: + blackframe_subtract( tag,buffer[0],buffer[1],buffer[2],width,height,uv_len, tag->has_white , tag->mean[0],tag->mean[1],tag->mean[2]); + break; + + case V4L_BLACKFRAME: + blackframe_new(width,height,uv_len,buffer[0],buffer[1],buffer[2],tag->median_radius,tag); + tag->noise_suppression = V4L_BLACKFRAME_NEXT; + tag->bf_index ++; + veejay_msg(VEEJAY_MSG_INFO,"Processed dark frame %d/%d", tag->bf_index, tag->cali_duration); + break; + + case V4L_BLACKFRAME_NEXT: + blackframe_process( buffer[0],buffer[1],buffer[2],width,height,uv_len, tag->median_radius,tag ); + tag->bf_index ++; + if(tag->bf_index == tag->cali_duration) { + tag->noise_suppression = 0; + master_blackframe(width,height,uv_len,tag); + veejay_msg(VEEJAY_MSG_INFO, "Please create a lightframe now"); + } + veejay_msg(VEEJAY_MSG_INFO, "Processed darkframe %d/%d", tag->bf_index, tag->cali_duration); + + break; + case V4L_WHITEFRAME: + if(!tag->blackframe) { + veejay_msg(0, "Please start with a dark frame first (Put cap on lens)"); + tag->noise_suppression = 0; + break; + } + + whiteframe_new( tag->blackframe,width,height,uv_len,buffer[0],buffer[1],buffer[2],tag->median_radius, tag); + tag->bf_index ++; + tag->noise_suppression = V4L_WHITEFRAME_NEXT; + veejay_msg(VEEJAY_MSG_INFO,"Processed light frame %d/%d", tag->bf_index, tag->cali_duration); + + break; + case V4L_WHITEFRAME_NEXT: + whiteframe_process(buffer[0],buffer[1],buffer[2],width,height,uv_len,tag->median_radius,tag ); + tag->bf_index ++; + if( tag->bf_index == tag->cali_duration ) { + tag->noise_suppression = V4L_BLACKFRAME_PROCESS; // actual processing + master_lightframe( width,height,uv_len,tag); + master_flatframe( width,height,uv_len, tag ); + veejay_msg(VEEJAY_MSG_DEBUG, "Mastered flat frame. Ready for processing. Mean is %g,%g,%g", tag->mean[0], tag->mean[1], tag->mean[2]); + } + veejay_msg(VEEJAY_MSG_INFO, "Processed light frame %d/%d", tag->bf_index, tag->cali_duration ); + + break; + case -1: + if( tag->blackframe ) { free(tag->blackframe); tag->blackframe = NULL; } + if( tag->bf ) { free(tag->bf); tag->bf = NULL; } + if( tag->bfu ) { free(tag->bfu); tag->bfu = NULL; } + if( tag->bfv ) { free(tag->bfv); tag->bfv = NULL; } + if( tag->lf ) { free(tag->lf); tag->lf = NULL; } + if( tag->lfu ) { free(tag->lfu); tag->lfu = NULL; } + if( tag->lfv ) { free(tag->lfv); tag->lfv = NULL; } + + veejay_msg(VEEJAY_MSG_INFO, "Calibration data cleaned up"); + break; + default: + break; + } + return 1; } diff --git a/veejay-current/veejay-server/libstream/vj-tag.h b/veejay-current/veejay-server/libstream/vj-tag.h index 3f8fbdde..2f761ee5 100644 --- a/veejay-current/veejay-server/libstream/vj-tag.h +++ b/veejay-current/veejay-server/libstream/vj-tag.h @@ -120,10 +120,9 @@ typedef struct { void *viewport; int noise_suppression; uint8_t *blackframe; - int bf_count; + int bf_index; int median_radius; int has_white; - double *tabmean[3]; double mean[3]; double *bf; double *bfu; @@ -351,7 +350,7 @@ int vj_tag_get_width(); int vj_tag_get_height(); int vj_tag_get_uvlen(); void vj_tag_cali_prepare( int t1 , int pos, int cali_tag); -void vj_tag_cali_prepare_now(int a, int b); +void vj_tag_cali_prepare_now(vj_tag *b); int vj_tag_chain_set_kfs( int s1, int len, unsigned char *data ); unsigned char * vj_tag_chain_get_kfs( int s1, int entry, int parameter_id, int *len ); int vj_tag_get_kf_status(int t1, int entry, int *type); diff --git a/veejay-current/veejay-server/thirdparty/bio2jack/bio2jack.c b/veejay-current/veejay-server/thirdparty/bio2jack/bio2jack.c index 31ff8bd7..bbd2eacd 100644 --- a/veejay-current/veejay-server/thirdparty/bio2jack/bio2jack.c +++ b/veejay-current/veejay-server/thirdparty/bio2jack/bio2jack.c @@ -227,7 +227,7 @@ getDriver(int deviceID) if(drv->jackd_died && drv->client == 0) { struct timespec now; - clock_gettime( CLOCK_REALTIME, &now); + clock_gettime( CLOCK_MONOTONIC, &now); /* wait 250ms before trying again */ if(TimeValDifference(&drv->last_reconnect_attempt, &now) >= 250) @@ -424,7 +424,7 @@ JACK_callback(nframes_t nframes, void *arg) struct timespec tmp_tp; unsigned int i; - clock_gettime(CLOCK_REALTIME, &tmp_tp ); + clock_gettime(CLOCK_MONOTONIC, &tmp_tp ); __sync_lock_test_and_set( &(drv->previousTime.tv_sec), tmp_tp.tv_sec ); __sync_lock_test_and_set( &(drv->previousTime.tv_nsec), tmp_tp.tv_nsec ); @@ -1876,7 +1876,7 @@ JACK_GetPositionFromDriver(jack_driver_t * drv, enum pos_enum position, // type_str = "PLAYED"; return_val = drv->played_client_bytes; // gettimeofday(&now, 0); - clock_gettime( CLOCK_REALTIME, &now ); + clock_gettime( CLOCK_MONOTONIC, &now ); elapsedMS = TimeValDifference(&drv->previousTime, &now); /* find the elapsed milliseconds since last JACK_Callback() */ @@ -2066,7 +2066,7 @@ JACK_CleanupDriver(jack_driver_t * drv) drv->output_sample_rate_ratio = 1.0; drv->input_sample_rate_ratio = 1.0; drv->jackd_died = FALSE; - clock_gettime(CLOCK_REALTIME, &drv->previousTime); /* record the current time */ + clock_gettime(CLOCK_MONOTONIC, &drv->previousTime); /* record the current time */ memcpy( &drv->last_reconnect_attempt, &drv->previousTime, sizeof(struct timespec)); } diff --git a/veejay-current/veejay-server/veejay/liblavplayvj.c b/veejay-current/veejay-server/veejay/liblavplayvj.c index a95a99e3..06922a5a 100644 --- a/veejay-current/veejay-server/veejay/liblavplayvj.c +++ b/veejay-current/veejay-server/veejay/liblavplayvj.c @@ -1112,7 +1112,7 @@ static void veejay_mjpeg_software_frame_sync(veejay_t * info, int usec_since_lastframe=0; for (;;) { - clock_gettime( CLOCK_REALTIME, &now ); + clock_gettime( CLOCK_MONOTONIC, &now ); usec_since_lastframe = (now.tv_nsec - settings->lastframe_completion.tv_nsec)/1000; @@ -1126,13 +1126,13 @@ static void veejay_mjpeg_software_frame_sync(veejay_t * info, } nsecsleep.tv_nsec = (settings->usec_per_frame - usec_since_lastframe - 1000000 / HZ) * 1000; - nsecsleep.tv_sec = 0; - clock_nanosleep(CLOCK_REALTIME,0, &nsecsleep, NULL); + nsecsleep.tv_sec = 0; + clock_nanosleep(CLOCK_MONOTONIC,0, &nsecsleep, NULL); } } settings->first_frame = 0; - clock_gettime( CLOCK_REALTIME, &(settings->lastframe_completion) ); + clock_gettime( CLOCK_MONOTONIC, &(settings->lastframe_completion) ); settings->syncinfo[settings->currently_processed_frame].timestamp = settings->lastframe_completion; } @@ -2383,7 +2383,7 @@ static void veejay_playback_cycle(veejay_t * info) frame = bs.frame; stats.nsync++; - clock_gettime( CLOCK_REALTIME, &time_now); + clock_gettime( CLOCK_MONOTONIC, &time_now); long d1 = (time_now.tv_sec * 1000000000) + time_now.tv_nsec; long n1 = (bs.timestamp.tv_sec * 1000000000) + bs.timestamp.tv_nsec; diff --git a/veejay-current/veejay-server/veejay/veejay.c b/veejay-current/veejay-server/veejay/veejay.c index a0d3dd73..c5b3f852 100644 --- a/veejay-current/veejay-server/veejay/veejay.c +++ b/veejay-current/veejay-server/veejay/veejay.c @@ -933,7 +933,7 @@ int main(int argc, char **argv) while( 1 ) { //@ until your PC stops working - clock_nanosleep( CLOCK_REALTIME, 0, &req, NULL ); + clock_nanosleep( CLOCK_MONOTONIC, 0, &req, NULL ); current_state = veejay_get_state(info); diff --git a/veejay-current/veejay-server/veejay/vj-event.c b/veejay-current/veejay-server/veejay/vj-event.c index f3e4ed3b..0e360e8b 100644 --- a/veejay-current/veejay-server/veejay/vj-event.c +++ b/veejay-current/veejay-server/veejay/vj-event.c @@ -5978,7 +5978,7 @@ void vj_event_chain_entry_srccha(void *ptr, const char format[], va_list ap) (source == VJ_TAG_TYPE_NONE ? "sample" : "stream") , channel_id); if( source != VJ_TAG_TYPE_NONE ) { int slot = sample_has_cali_fx( args[0]);//@sample - if( slot >= 0 ) { + if( slot >= 0 ) { sample_cali_prepare( args[0],slot,channel_id); veejay_msg(VEEJAY_MSG_DEBUG, "Using calibration data of stream %d",channel_id); } @@ -8395,7 +8395,7 @@ void vj_event_get_cali_image ( void *ptr, const char format[], va_l int id = args[0]; int type = args[1]; - if( !vj_tag_exists(id) || vj_tag_get_type(id) != VJ_TAG_TYPE_V4L || type < 0 || type > 2) + if( !vj_tag_exists(id) ) { SEND_MSG(v, "000000000" ); return; @@ -8416,7 +8416,7 @@ void vj_event_get_cali_image ( void *ptr, const char format[], va_l SEND_MSG( v, header ); int res = vj_server_send(v->vjs[VEEJAY_PORT_CMD], v->uc->current_link, buf,len); if(!res) { - veejay_msg(0,"Failed to get calibration image"); + veejay_msg(0,"Failed to send calibration image. Header: [%s]",header); } } }