apply sge motion plugin mods
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / proxy.C
index 522287bd420f3e2eee217e1feac6aebfbb258b56..fff64f37fb1eb850e8df5505f818f3abc4bcc871 100644 (file)
@@ -195,7 +195,16 @@ void ProxyRender::to_proxy_path(char *new_path, Indexable *indexable, int scale)
 {
 // path is already a proxy
        if( strstr(indexable->path, ".proxy") ) return;
-       strcpy(new_path, indexable->path);
+       if( !indexable->is_asset ) {
+               char *ifn = indexable->path, *cp = strrchr(ifn, '/');
+               if( cp ) ifn = cp+1;
+               char proxy_path[BCTEXTLEN];
+               File::getenv_path(proxy_path,
+                       mwindow->preferences->nested_proxy_path);
+               sprintf(new_path, "%s/%s", proxy_path, ifn);
+       }
+       else
+               strcpy(new_path, indexable->path);
        char prxy[BCSTRLEN];
        int n = sprintf(prxy, ".proxy%d", scale);
 // insert proxy, path.sfx => path.proxy#-sfx.ext
@@ -220,11 +229,11 @@ void ProxyRender::to_proxy_path(char *new_path, Indexable *indexable, int scale)
 //printf("ProxyRender::to_proxy_path %d %s %s\n", __LINE__, new_path), asset->path);
 }
 
-int ProxyRender::from_proxy_path(char *new_path, Indexable *indexable, int scale)
+int ProxyRender::from_proxy_path(char *new_path, Asset *asset, int scale)
 {
        char prxy[BCTEXTLEN];
        int n = sprintf(prxy, ".proxy%d", scale);
-       strcpy(new_path, indexable->path);
+       strcpy(new_path, asset->path);
        char *ptr = strstr(new_path, prxy);
        if( !ptr || (ptr[n] != '-' && ptr[n] != '.') ) return 1;
 // remove proxy, path.proxy#-sfx.ext => path.sfx
@@ -233,6 +242,12 @@ int ProxyRender::from_proxy_path(char *new_path, Indexable *indexable, int scale
        char *cp = ptr + n;
        for( *cp='.'; cp<ext; ++cp ) *ptr++ = *cp;
        *ptr = 0;
+       if( asset->proxy_edl ) {
+               if( (cp = strrchr(new_path, '/')) != 0 ) {
+                       for( ptr=new_path; *++cp; ) *ptr++ = *cp;
+                       *ptr = 0;
+               }
+       }
        return 0;
 }
 
@@ -265,8 +280,18 @@ Asset *ProxyRender::add_original(Indexable *idxbl, int new_scale)
        if( strstr(idxbl->path,".proxy") ) return 0;
        char new_path[BCTEXTLEN];
        to_proxy_path(new_path, idxbl, new_scale);
-// don't proxy if not readable
+// don't proxy if not readable, or proxy_path not writable
        if( idxbl->is_asset && access(idxbl->path, R_OK) ) return 0;
+       int ret = access(new_path, W_OK);
+       if( ret ) {
+               int fd = ::open(new_path,O_WRONLY);
+               if( fd < 0 ) fd = open(new_path,O_WRONLY+O_CREAT,0666);
+               if( fd >= 0 ) { close(fd);  ret = 0; }
+       }
+       if( ret ) {
+               eprintf(_("bad proxy path: %s\n"), new_path);
+               return 0;
+       }
 // add to orig_idxbls & orig_proxies if it isn't already there.
        int got_it = 0;
        for( int i = 0; !got_it && i<orig_proxies.size(); ++i )
@@ -288,6 +313,7 @@ Asset *ProxyRender::add_original(Indexable *idxbl, int new_scale)
                        proxy->video_length = video_frames;
                }
                proxy->folder_no = AW_PROXY_FOLDER;
+               proxy->proxy_edl = !idxbl->is_asset ? 1 : 0;
                proxy->audio_data = 0;
                proxy->video_data = 1;
                proxy->layers = 1;
@@ -339,8 +365,10 @@ int ProxyRender::create_needed_proxies(int new_scale)
        }
 
 // start progress bar.  MWindow is locked inside this
+       mwindow->gui->lock_window("ProxyRender::create_needed_proxies");
        progress = mwindow->mainprogress->
                start_progress(_("Creating proxy files..."), total_len);
+       mwindow->gui->unlock_window();
 
        ProxyFarm engine(mwindow, this, &needed_idxbls, &needed_proxies);
        engine.process_packages();
@@ -629,7 +657,8 @@ ProxyClient::ProxyClient(MWindow *mwindow,
 ProxyClient::~ProxyClient()
 {
        delete render_engine;
-       delete video_cache;
+       if( video_cache )
+               video_cache->remove_user();
        delete src_file;
 }
 
@@ -739,7 +768,7 @@ void ProxyClient::process_package(LoadPackage *ptr)
                if( !scale ) scale = 1;
                asset->width = asset->actual_width * scale;
                asset->height = asset->actual_height * scale;
-               mwindow->mainindexes->add_next_asset(0, asset);
+               mwindow->mainindexes->add_indexable(asset);
                mwindow->mainindexes->start_build();
        }
        else