X-Git-Url: http://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Ffile.C;h=f19ce0184137e6eb0aaf01f0a97a59f4c17d8435;hb=7be8c7f90868895abddcbafda66ede5632752a70;hp=103c9a4d3b5e1810021604ab2803719d3a677343;hpb=30bdb85eb33a8ee7ba675038a86c6be59c43d7bd;p=goodguy%2Fhistory.git diff --git a/cinelerra-5.1/cinelerra/file.C b/cinelerra-5.1/cinelerra/file.C index 103c9a4d..f19ce018 100644 --- a/cinelerra-5.1/cinelerra/file.C +++ b/cinelerra-5.1/cinelerra/file.C @@ -65,6 +65,7 @@ #include "formattools.h" #include "framecache.h" #include "language.h" +#include "mainprogress.inc" #include "mutex.h" #include "mwindow.h" #include "packagingengine.h" @@ -176,6 +177,7 @@ int File::get_options(FormatTools *format, audio_options, video_options); break; +#ifdef HAVE_DV case FILE_RAWDV: FileDV::get_parameters(parent_window, asset, @@ -183,6 +185,7 @@ int File::get_options(FormatTools *format, audio_options, video_options); break; +#endif case FILE_PCM: case FILE_WAV: case FILE_AU: @@ -416,12 +419,14 @@ int File::open_file(Preferences *preferences, file = new FileScene(this->asset, this); break; } +#ifdef HAVE_DV if(FileDV::check_sig(this->asset)) { // libdv fclose(stream); file = new FileDV(this->asset, this); break; } +#endif if(FileSndFile::check_sig(this->asset)) { // libsndfile fclose(stream); @@ -591,11 +596,11 @@ int File::open_file(Preferences *preferences, case FILE_VORBIS: file = new FileVorbis(this->asset, this); break; - +#ifdef HAVE_DV case FILE_RAWDV: file = new FileDV(this->asset, this); break; - +#endif // try plugins default: return 1; @@ -618,9 +623,12 @@ int File::open_file(Preferences *preferences, if( rd ) { // one frame image file, no specific length - if( !this->asset->audio_data && this->asset->video_data && - this->asset->video_length <= 1 ) + if( !this->asset->audio_data && + this->asset->video_data && !this->asset->single_frame && + this->asset->video_length >= 0 && this->asset->video_length <= 1 ) { + this->asset->single_frame = 1; this->asset->video_length = -1; + } } // Synchronize header parameters @@ -710,12 +718,9 @@ int File::close_file(int ignore_thread) -int File::get_index(char *index_path) +int File::get_index(IndexFile *index_file, MainProgressBar *progress_bar) { - if(file) { - return file->get_index(index_path); - } - return 1; + return !file ? -1 : file->get_index(index_file, progress_bar); } @@ -1122,7 +1127,7 @@ VFrame*** File::get_video_buffer() int File::read_samples(Samples *samples, int64_t len) { // Never try to read more samples than exist in the file - if (current_sample + len > asset->audio_length) { + if (asset->audio_length >= 0 && current_sample + len > asset->audio_length) { len = asset->audio_length - current_sample; } if(len <= 0) return 0; @@ -1171,13 +1176,11 @@ int File::read_frame(VFrame *frame, int is_thread) if(debug) PRINT_TRACE int supported_colormodel = colormodel_supported(frame->get_color_model()); int advance_position = 1; - + int cache_active = use_cache || asset->single_frame ? 1 : 0; + int64_t cache_position = !asset->single_frame ? current_frame : -1; // Test cache - if(use_cache && - frame_cache->get_frame(frame, - current_frame, - current_layer, - asset->frame_rate)) + if( cache_active && frame_cache->get_frame(frame, cache_position, + current_layer, asset->frame_rate) ) { // Can't advance position if cache used. //printf("File::read_frame %d\n", __LINE__); @@ -1245,11 +1248,9 @@ int File::read_frame(VFrame *frame, int is_thread) //for(int i = 0; i < 100 * 1000; i++) ((float*)frame->get_rows()[0])[i] = 1.0; } -//printf("File::read_frame %d use_cache=%d\n", __LINE__, use_cache); - if(use_cache) - frame_cache->put_frame(frame, - current_frame, current_layer, - asset->frame_rate, 1, 0); + if( cache_active && advance_position && frame->get_status() > 0 ) + frame_cache->put_frame(frame, cache_position, + current_layer, asset->frame_rate, 1, 0); //printf("File::read_frame %d\n", __LINE__); if(advance_position) current_frame++; @@ -1426,7 +1427,9 @@ int File::get_best_colormodel(Asset *asset, int driver) { switch(asset->format) { +#ifdef HAVE_FIREWIRE case FILE_RAWDV: return FileDV::get_best_colormodel(asset, driver); +#endif case FILE_MPEG: return FileMPEG::get_best_colormodel(asset, driver); case FILE_JPEG: case FILE_JPEG_LIST: return FileJPEG::get_best_colormodel(asset, driver); @@ -1439,6 +1442,7 @@ int File::get_best_colormodel(Asset *asset, int driver) case FILE_CR2: case FILE_CR2_LIST: return FileCR2::get_best_colormodel(asset, driver); case FILE_DB: return FileDB::get_best_colormodel(asset, driver); + case FILE_FFMPEG: return FileFFMPEG::get_best_colormodel(asset, driver); } return BC_RGB888; @@ -1628,16 +1632,88 @@ int File::record_fd() } -void get_exe_path(char *result) +void File::get_exe_path(char *result, char *bnp) { -// Get executable path +// Get executable path, basename int len = readlink("/proc/self/exe", result, BCTEXTLEN-1); if( len >= 0 ) { result[len] = 0; char *ptr = strrchr(result, '/'); - if( ptr ) *ptr = 0; + if( ptr ) *ptr++ = 0; else ptr = result; + if( bnp ) strncpy(bnp, ptr, BCTEXTLEN); } - else - result[0] = 0; + else { + *result = 0; + if( bnp ) *bnp = 0; + } +} + +void File::getenv_path(char *result, const char *path) +{ + char *rp = result, *ep = rp + BCTEXTLEN-1; + const char *cp = path; +// any env var can be used here to expand a path as: +// "path...$id...": and id is a word as alpha,alnum... +// expands as "path...getenv(id)..." +// CIN_PATH, CIN_LIB are set in main.C, + for( int ch=*cp++; ch && rp < ep; ch=*cp++ ) { + if( ch == '$' && isalpha(*cp) ) { // scan alpha,alnum... + const char *bp = cp; char *p = rp; + while( p < ep && *bp && (isalnum(*bp) || *bp == '_') ) *p++ = *bp++; + *p = 0; + const char *envp = getenv(rp); // read env value + if( !envp ) continue; + while( *envp && rp < ep ) *rp++ = *envp++; + cp = bp; // subst id=value + continue; + } + *rp++ = ch; + } + *rp = 0; +} + +char File::cinexe_path[BCTEXTLEN]; +char File::cinpkg_path[BCTEXTLEN]; +char File::cindat_path[BCTEXTLEN]; +char File::cinlib_path[BCTEXTLEN]; +char File::cincfg_path[BCTEXTLEN]; +char File::cinplg_path[BCTEXTLEN]; +char File::cinlad_path[BCTEXTLEN]; +char File::cinlcl_path[BCTEXTLEN]; + +void File::init_cin_path() +{ + char env_path[BCTEXTLEN], env_pkg[BCTEXTLEN]; +// these values are advertised for forks/shell scripts + get_exe_path(env_path, env_pkg); + snprintf(cinexe_path, sizeof(cinexe_path), "CIN_PATH=%s", env_path); + putenv(cinexe_path); + snprintf(cinpkg_path, sizeof(cinpkg_path), "CIN_PKG=%s", env_pkg); + putenv(cinpkg_path); + + getenv_path(env_path, CINDAT_DIR); + snprintf(cindat_path, sizeof(cindat_path), "CIN_DAT=%s", env_path); + putenv(cindat_path); + + getenv_path(env_path, CINLIB_DIR); + snprintf(cinlib_path, sizeof(cinlib_path), "CIN_LIB=%s", env_path); + putenv(cinlib_path); + + getenv_path(env_path, CONFIG_DIR); + snprintf(cincfg_path, sizeof(cincfg_path), "CIN_CONFIG=%s", env_path); + putenv(cincfg_path); + + getenv_path(env_path, PLUGIN_DIR); + snprintf(cinplg_path, sizeof(cinplg_path), "CIN_PLUGIN=%s", env_path); + putenv(cinplg_path); + + getenv_path(env_path, LADSPA_DIR); + snprintf(cinlad_path, sizeof(cinlad_path), "CIN_LADSPA=%s", env_path); + putenv(cinlad_path); + + getenv_path(env_path, LOCALE_DIR); + snprintf(cinlcl_path, sizeof(cinlcl_path), "CIN_LOCALE=%s", env_path); + putenv(cinlcl_path); } +