diff --git a/veejay-current/veejay-server/libel/avhelper.c b/veejay-current/veejay-server/libel/avhelper.c index a848a2bc..743ecdd2 100644 --- a/veejay-current/veejay-server/libel/avhelper.c +++ b/veejay-current/veejay-server/libel/avhelper.c @@ -155,7 +155,9 @@ static int avcodec_decode_video( AVCodecContext *avctx, AVFrame *picture, int *g veejay_memset( &pkt, 0, sizeof(AVPacket)); pkt.data = data; pkt.size = pktsize; - return avcodec_decode_video2( avctx, picture, got_picture, &pkt ); + int ret = avcodec_decode_video2( avctx, picture, got_picture, &pkt ); + free_av_packet(&pkt); + return ret; } #endif static void avhelper_close_input_file( AVFormatContext *s ) { @@ -267,6 +269,7 @@ further: if ( avcodec_open( x->codec_ctx, x->codec ) < 0 ) #endif { + avhelper_close_input_file( x->avformat_ctx ); free(x); return NULL; } @@ -304,9 +307,10 @@ further: x->input = yuv_yuv_template( NULL,NULL,NULL, x->codec_ctx->width,x->codec_ctx->height, x->pixfmt ); sws_template sws_tem; - veejay_memset(&sws_tem, 0,sizeof(sws_template)); - sws_tem.flags = yuv_which_scaler(); - x->scaler = yuv_init_swscaler( x->input,x->output, &sws_tem, yuv_sws_get_cpu_flags()); + veejay_memset(&sws_tem, 0,sizeof(sws_template)); + sws_tem.flags = yuv_which_scaler(); + x->scaler = yuv_init_swscaler( x->input,x->output, &sws_tem, yuv_sws_get_cpu_flags()); + if( x->scaler == NULL ) { veejay_msg(VEEJAY_MSG_ERROR,"FFmpeg: Failed to get scaler context for %dx%d in %d to %dx%d in %d", x->codec_ctx->width,x->codec_ctx->height, x->pixfmt, @@ -320,7 +324,7 @@ further: free(x); return NULL; } - + return (void*) x; } diff --git a/veejay-current/veejay-server/libel/avilib.c b/veejay-current/veejay-server/libel/avilib.c index 15e329f7..88601f19 100644 --- a/veejay-current/veejay-server/libel/avilib.c +++ b/veejay-current/veejay-server/libel/avilib.c @@ -2411,6 +2411,8 @@ int avi_parse_input_file(avi_t *AVI, int getIndex) if(AVI->anum > AVI_MAX_TRACKS) { fprintf(stderr, "error - only %d audio tracks supported\n", AVI_MAX_TRACKS); + if( AVI->idx ) + free(AVI->idx); return(-1); } @@ -2431,6 +2433,8 @@ int avi_parse_input_file(avi_t *AVI, int getIndex) } else if (strncasecmp (hdrl_data+i,"iavs",4) ==0 && ! auds_strh_seen) { fprintf(stderr, "AVILIB: error - DV AVI Type 1 no supported\n"); + if( AVI->idx ) + free(AVI->idx); return (-1); } else diff --git a/veejay-current/veejay-server/libel/vj-el.c b/veejay-current/veejay-server/libel/vj-el.c index 26cf37e1..ed0160df 100644 --- a/veejay-current/veejay-server/libel/vj-el.c +++ b/veejay-current/veejay-server/libel/vj-el.c @@ -577,12 +577,12 @@ int open_video_file(char *filename, editlist * el, int preserve_pathname, int de el->ctx[n] = avhelper_get_decoder( filename, out_format, width, height ); - - if( el->ctx[n] == NULL ) { pixfmt = test_video_frame( el, n, elfd, el_pixel_format_ ); if( pixfmt == -1 ) { veejay_msg(VEEJAY_MSG_ERROR, "Unable to determine video format" ); + lav_close(elfd); + if(realname) free(realname); return -1; } el->pixfmt[n] = pixfmt; @@ -607,7 +607,7 @@ int open_video_file(char *filename, editlist * el, int preserve_pathname, int de if( !(_fc == CHROMA422 || _fc == CHROMA420 || _fc == CHROMA444 || _fc == CHROMAUNKNOWN || _fc == CHROMA411 || _fc == CHROMA422F || _fc == CHROMA420F)) { veejay_msg(VEEJAY_MSG_ERROR,"Input file %s is not in a valid format (%d)",filename,_fc); - if(realname) free(realname); + if(realname) free(realname); lav_close( elfd ); return -1; diff --git a/veejay-current/veejay-server/libsample/sampleadm.c b/veejay-current/veejay-server/libsample/sampleadm.c index f87f0bce..b0b6944d 100644 --- a/veejay-current/veejay-server/libsample/sampleadm.c +++ b/veejay-current/veejay-server/libsample/sampleadm.c @@ -79,6 +79,8 @@ static int avail_num[SAMPLE_MAX_SAMPLES]; /* an array of freed sample id's */ static void *sample_font_ = NULL; static int sampleadm_state = SAMPLE_PEEK; /* default state */ static void *sample_cache[SAMPLE_MAX_SAMPLES]; +static editlist *plain_editlist=NULL; + extern void tagParseStreamFX(char *file, xmlDocPtr doc, xmlNodePtr cur, void *font, void *vp); extern void tag_writeStream( char *file, int n, xmlNodePtr node, void *font, void *vp ); extern int vj_tag_size(); @@ -143,6 +145,37 @@ static int int_compare(const void *key1, const void *key2) #endif } +static void sample_close_edl(int s1, editlist *el) +{ + /* check if another sample has same EDL */ + if( el != NULL ) { + int end = sample_size() + 1; + int same = 0; + int i; + + if( el == plain_editlist ) { + same = 1; + } + + if( same == 0 ) { + for (i = 1; i < end; i++) { + if (!sample_exists(i) || s1 == i) + continue; + + sample_info *b = sample_get(i); + if( b->edit_list == el ) { + same = 1; + break; + } + } + } + + if( same == 0 ) { + vj_el_free(el); + } + } +} + int sample_update(sample_info *sample, int s1) { /* if(s1 <= 0 || s1 >= SAMPLE_MAX_SAMPLES) return 0; if(sample) { @@ -196,7 +229,7 @@ void *sample_get_dict( int sample_id ) * call before using any other function as sample_skeleton_new * ****************************************************************************************************/ -void sample_init(int len, void *font) +void sample_init(int len, void *font, editlist *pedl) { if (!initialized) { int i; @@ -212,6 +245,7 @@ void sample_init(int len, void *font) } sample_font_ = font; + plain_editlist = pedl; } void sample_free(void *edl) @@ -220,17 +254,6 @@ void sample_free(void *edl) return; sample_del_all(edl); -/* - hscan_t scan; - hash_scan_begin( &scan, (hash_t*) SampleHash ); - hnode_t *node; - while( (node = hash_scan_next(&scan)) != NULL ) - { - sample_info *info = (sample_info*) node; - sample_del( info->sample_id); - } - hash_free_nodes( SampleHash ); - hash_destroy( SampleHash );*/ } int sample_set_state(int new_state) @@ -893,7 +916,7 @@ int sample_del(int sample_id) sample_info *si; si = sample_get(sample_id); if (!si) - return 0; + return 0; sample_node = hash_lookup(SampleHash, (void *) si->sample_id); if (sample_node) { @@ -925,15 +948,20 @@ int sample_del(int sample_id) viewport_destroy(si->viewport); si->viewport = NULL; } - - free(si); - /* store freed sample_id */ + if(si->edit_list) { + /* check if another sample has same EDL */ + sample_close_edl( sample_id, si->edit_list ); + } + + /* store freed sample_id */ avail_num[next_avail_num] = sample_id; next_avail_num++; hash_delete_free(SampleHash, sample_node); sample_cache[ sample_id ] = NULL; + + free(si); return 1; } @@ -941,55 +969,24 @@ int sample_del(int sample_id) return 0; } -static void sample_free_el(void *port) { - int i; - char **keys = vevo_list_properties(port); - if(keys) { - for( i = 0; keys[i] != NULL; i ++ ) { - void *el = NULL; - if(vevo_property_get(port, keys[i], 0, &el ) == VEVO_NO_ERROR ) { - vj_el_free( (editlist*) el ); - } - free(keys[i]); - } - free(keys); - } -} - void sample_del_all(void *edl) { - int end = sample_size(); + int end = sample_size() + 1; int i; - void *port = vpn(VEVO_ANONYMOUS_PORT); - for (i = 1; i < end; i++) { - if (sample_exists(i)) { - sample_chain_clear(i); - sample_info *si = sample_get(i); - if(si->edit_list && edl != si->edit_list) { - char key[32]; - snprintf(key,sizeof(key), "p%p", si->edit_list ); - if( vevo_property_get( port, key, 0, NULL ) == VEVO_ERROR_NOSUCH_PROPERTY ) { - vevo_property_set( port, key, VEVO_ATOM_TYPE_VOIDPTR,1,&(si->edit_list)); - } - } - - sample_del(i); - } - } - - sample_free_el( port ); - - vpf(port); - - - memset( avail_num, 0, sizeof(int) * SAMPLE_MAX_SAMPLES ); + if (!sample_exists(i)) + continue; + + sample_chain_clear(i); + sample_del(i); + } + + veejay_memset( avail_num, 0, sizeof(int) * SAMPLE_MAX_SAMPLES ); next_avail_num = 0; this_sample_id = 0; hash_free_nodes( SampleHash ); - } /**************************************************************************************************** @@ -3256,15 +3253,16 @@ xmlNodePtr ParseSample(xmlDocPtr doc, xmlNodePtr cur, sample_info * skel,void *e ****************************************************************************************************/ int sample_read_edl( sample_info *sample ) { - char *files[1]; + char *files[1] = {0}; int res = 0; + files[0] = sample->edit_list_file; void *old = sample->edit_list; //EDL is stored in CWD, samplelist file can be anywhere. Cannot always load samplelists due to // missing EDL files in CWD. - veejay_msg(VEEJAY_MSG_DEBUG, "Loading '%s' from current working directory" , files[0] ); + veejay_msg(VEEJAY_MSG_DEBUG, "Loading '%s' from video sample from current working directory" , files[0] ); sample->edit_list = vj_el_init_with_args( files,1, __sample_project_settings.flags, @@ -3279,7 +3277,10 @@ int sample_read_edl( sample_info *sample ) { res = 1; sample->soft_edl = 0; - if( old ) vj_el_free( old ); + + if( old ) { + sample_close_edl( sample->sample_id, old ); + } } else { diff --git a/veejay-current/veejay-server/libsample/sampleadm.h b/veejay-current/veejay-server/libsample/sampleadm.h index fd58cdb1..e846867d 100644 --- a/veejay-current/veejay-server/libsample/sampleadm.h +++ b/veejay-current/veejay-server/libsample/sampleadm.h @@ -181,7 +181,7 @@ extern int sample_chain_malloc(int sample_id); extern int sample_chain_free(int sample_id); extern int sample_size(); extern int sample_verify(); -extern void sample_init(int len, void *font); +extern void sample_init(int len, void *font, editlist *el); extern int sample_update(sample_info *sample, int s1); #ifdef HAVE_XML2 extern int sample_readFromFile(char *, void *vp, void *ptr, void *font, void *el, int *id, int *mode); diff --git a/veejay-current/veejay-server/veejay/liblavplayvj.c b/veejay-current/veejay-server/veejay/liblavplayvj.c index 600b10ec..e89873cc 100644 --- a/veejay-current/veejay-server/veejay/liblavplayvj.c +++ b/veejay-current/veejay-server/veejay/liblavplayvj.c @@ -1007,8 +1007,8 @@ static int veejay_screen_update(veejay_t * info ) #endif vj_perform_get_primary_frame_420p(info,c_frame); if (vj_dfb_update_yuv_overlay(info->dfb, c_frame) != 0) - { - return 0; + { + return 0; } #endif break; @@ -1018,7 +1018,6 @@ static int veejay_screen_update(veejay_t * info ) if( vj_yuv_put_frame( info->y4m, frame ) == -1 ) { veejay_msg(0, "Failed to write a frame!"); veejay_change_state(info,LAVPLAY_STATE_STOP); - return 0; } break; @@ -1772,7 +1771,7 @@ int veejay_init(veejay_t * info, int x, int y,char *arg, int def_tags, int gen_t } - sample_init( (info->video_output_width * info->video_output_height), info->font ); + sample_init( (info->video_output_width * info->video_output_height), info->font, el ); sample_set_project( info->pixel_format, info->auto_deinterlace,