add configure without-thirdparty, without-libzmpeg, without-commercial
[goodguy/history.git] / cinelerra-5.1 / cinelerra / file.C
index 0fb926b26d6601fd4e99018bf4f2f08bf1f19664..03348e0a6422f3316a26dc008757157f8ba546f8 100644 (file)
@@ -54,6 +54,7 @@
 #undef HAVE_STDLIB_H // automake conflict
 #include "fileogg.h"
 #include "filepng.h"
+#include "fileppm.h"
 #include "filescene.h"
 #include "filesndfile.h"
 #include "filetga.h"
@@ -75,6 +76,7 @@
 #include "samples.h"
 #include "vframe.h"
 
+//static int temp_debug = 0;
 //suppress noref warning
 void *vorbis0_ov_callbacks[] = {
  &OV_CALLBACKS_DEFAULT, &OV_CALLBACKS_NOCLOSE,
@@ -99,8 +101,10 @@ File::~File()
                format_completion->unlock();
        }
 
-       if( temp_frame ) delete temp_frame;
-
+       if( temp_frame ) {
+//printf("File::~File %d temp_debug=%d\n", __LINE__, --temp_debug);
+               delete temp_frame;
+       }
 
        close_file(0);
 
@@ -161,23 +165,21 @@ int File::get_options(FormatTools *format,
        int audio_options, int video_options)
 {
        BC_WindowBase *parent_window = format->window;
-       //ArrayList<PluginServer*> *plugindb = format->plugindb;
        Asset *asset = format->asset;
-
+       EDL *edl = format->mwindow ? format->mwindow->edl : 0;
+       format_window = 0;
        getting_options = 1;
        format_completion->lock("File::get_options");
        switch( asset->format ) {
-       case FILE_AC3:
-               FileAC3::get_parameters(parent_window,
-                       asset,
-                       format_window,
-                       audio_options,
-                       video_options);
+#ifdef HAVE_CIN_3RDPARTY
+       case FILE_AC3: FileAC3::get_parameters(parent_window, asset, format_window,
+                       audio_options, video_options, edl);
                break;
+#endif
 #ifdef HAVE_DV
        case FILE_RAWDV:
                FileDV::get_parameters(parent_window, asset, format_window,
-                       audio_options, video_options);
+                       audio_options, video_options, edl);
                break;
 #endif
        case FILE_PCM:
@@ -186,51 +188,58 @@ int File::get_options(FormatTools *format,
        case FILE_AIFF:
        case FILE_SND:
                FileSndFile::get_parameters(parent_window, asset, format_window,
-                       audio_options, video_options);
+                       audio_options, video_options, edl);
                break;
        case FILE_FFMPEG:
                FileFFMPEG::get_parameters(parent_window, asset, format_window,
-                       audio_options, video_options);
+                       audio_options, video_options, edl);
                break;
+#ifdef HAVE_LIBZMPEG
        case FILE_AMPEG:
        case FILE_VMPEG:
                FileMPEG::get_parameters(parent_window, asset, format_window,
-                       audio_options, video_options);
+                       audio_options, video_options, edl);
                break;
+#endif
        case FILE_JPEG:
        case FILE_JPEG_LIST:
                FileJPEG::get_parameters(parent_window, asset, format_window,
-                       audio_options, video_options);
+                       audio_options, video_options, edl);
                break;
 #ifdef HAVE_OPENEXR
        case FILE_EXR:
        case FILE_EXR_LIST:
                FileEXR::get_parameters(parent_window, asset, format_window,
-                       audio_options, video_options);
+                       audio_options, video_options, edl);
                break;
 #endif
        case FILE_FLAC:
                FileFLAC::get_parameters(parent_window, asset, format_window,
-                       audio_options, video_options);
+                       audio_options, video_options, edl);
                break;
        case FILE_PNG:
        case FILE_PNG_LIST:
                FilePNG::get_parameters(parent_window, asset, format_window,
-                       audio_options, video_options);
+                       audio_options, video_options, edl);
+               break;
+       case FILE_PPM:
+       case FILE_PPM_LIST:
+               FilePPM::get_parameters(parent_window, asset, format_window,
+                       audio_options, video_options, edl);
                break;
        case FILE_TGA:
        case FILE_TGA_LIST:
                FileTGA::get_parameters(parent_window, asset, format_window,
-                       audio_options, video_options);
+                       audio_options, video_options, edl);
                break;
        case FILE_TIFF:
        case FILE_TIFF_LIST:
                FileTIFF::get_parameters(parent_window, asset, format_window,
-                       audio_options, video_options);
+                       audio_options, video_options, edl);
                break;
        case FILE_OGG:
                FileOGG::get_parameters(parent_window, asset, format_window,
-                       audio_options, video_options);
+                       audio_options, video_options, edl);
                break;
        default:
                break;
@@ -298,7 +307,6 @@ void File::set_white_balance_raw(int value)
        this->white_balance_raw = value;
 }
 
-
 void File::set_cache_frames(int value)
 {
 // caching only done locally
@@ -319,7 +327,7 @@ int File::purge_cache()
 
 int File::delete_oldest()
 {
-// caching only done locally
+// return the number of bytes freed
        return frame_cache->delete_oldest();
 }
 
@@ -334,6 +342,7 @@ const char *File::default_probes[] = {
 #endif 
        "SndFile",
        "PNG",
+       "PPM",
        "JPEG",
        "GIF",
 #ifdef HAVE_OPENEXR
@@ -371,11 +380,13 @@ int File::probe()
                        file = new FileFFMPEG(this->asset, this);
                        return FILE_OK;
                }
+#ifdef HAVE_COMMERCIAL
                if( !strcmp(pref->name,"DB") ) { // MediaDB
                        if( !FileDB::check_sig(this->asset) ) continue;
                        file = new FileDB(this->asset, this);
                        return FILE_OK;
                }
+#endif
                if( !strcmp(pref->name,"Scene") ) { // scene file
                        if( !FileScene::check_sig(this->asset, data)) continue;
                        file = new FileScene(this->asset, this);
@@ -398,6 +409,11 @@ int File::probe()
                        file = new FilePNG(this->asset, this);
                        return FILE_OK;
                }
+               if( !strcmp(pref->name,"PPM") ) { // PPM file
+                       if( !FilePPM::check_sig(this->asset) ) continue;
+                       file = new FilePPM(this->asset, this);
+                       return FILE_OK;
+               }
                if( !strcmp(pref->name,"JPEG") ) { // JPEG file
                        if( !FileJPEG::check_sig(this->asset) ) continue;
                        file = new FileJPEG(this->asset, this);
@@ -445,11 +461,13 @@ int File::probe()
                        file = new FileVorbis(this->asset, this);
                        return FILE_OK;
                }
+#ifdef HAVE_LIBZMPEG
                if( !strcmp(pref->name,"MPEG") ) { // MPEG file
                        if( !FileMPEG::check_sig(this->asset) ) continue;
                        file = new FileMPEG(this->asset, this);
                        return FILE_OK;
                }
+#endif
                if( !strcmp(pref->name,"EDL") ) { // XML file
                        if( data[0] != '<' ) continue;
                        if( !strncmp(&data[1],"EDL>",4) ||
@@ -474,8 +492,6 @@ int File::open_file(Preferences *preferences,
        this->wr = wr;
        file = 0;
 
-       if( debug ) printf("File::open_file %d\n", __LINE__);
-
        if( debug ) printf("File::open_file %p %d\n", this, __LINE__);
 
        switch( this->asset->format ) {
@@ -487,10 +503,11 @@ int File::open_file(Preferences *preferences,
                if( ret != FILE_OK ) return ret;
                break; }
 // format already determined
+#ifdef HAVE_CIN_3RDPARTY
        case FILE_AC3:
                file = new FileAC3(this->asset, this);
                break;
-
+#endif
        case FILE_SCENE:
                file = new FileScene(this->asset, this);
                break;
@@ -513,6 +530,11 @@ int File::open_file(Preferences *preferences,
                file = new FilePNG(this->asset, this);
                break;
 
+       case FILE_PPM:
+       case FILE_PPM_LIST:
+               file = new FilePPM(this->asset, this);
+               break;
+
        case FILE_JPEG:
        case FILE_JPEG_LIST:
                file = new FileJPEG(this->asset, this);
@@ -546,17 +568,19 @@ int File::open_file(Preferences *preferences,
        case FILE_TIFF_LIST:
                file = new FileTIFF(this->asset, this);
                break;
-
+#ifdef HAVE_COMMERCIAL
        case FILE_DB:
                file = new FileDB(this->asset, this);
                break;
+#endif
 
+#ifdef HAVE_LIBZMPEG
        case FILE_MPEG:
        case FILE_AMPEG:
        case FILE_VMPEG:
                file = new FileMPEG(this->asset, this);
                break;
-
+#endif
        case FILE_OGG:
                file = new FileOGG(this->asset, this);
                break;
@@ -1113,14 +1137,7 @@ int File::read_frame(VFrame *frame, int is_thread)
        const int debug = 0;
 //printf("File::read_frame pos=%jd cache=%d 1frame=%d\n",
 // current_frame, use_cache, asset->single_frame);
-       if( debug ) PRINT_TRACE
-
-//printf("File::read_frame %d\n", __LINE__);
-
        if( video_thread && !is_thread ) return video_thread->read_frame(frame);
-
-//printf("File::read_frame %d\n", __LINE__);
-       if( debug ) PRINT_TRACE
        if( !file ) return 1;
        if( debug ) PRINT_TRACE
        int result = 0;
@@ -1128,6 +1145,7 @@ int File::read_frame(VFrame *frame, int is_thread)
        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( cache_active && frame_cache->get_frame(frame, cache_position,
                        current_layer, asset->frame_rate) ) {
@@ -1138,8 +1156,9 @@ int File::read_frame(VFrame *frame, int is_thread)
 // Need temp
        else if( frame->get_color_model() != BC_COMPRESSED &&
                (supported_colormodel != frame->get_color_model() ||
-               frame->get_w() != asset->width ||
-               frame->get_h() != asset->height) ) {
+               (!file->can_scale_input() &&
+                       (frame->get_w() != asset->width ||
+                        frame->get_h() != asset->height))) ) {
 
 //                     printf("File::read_frame %d\n", __LINE__);
 // Can't advance position here because it needs to be added to cache
@@ -1150,14 +1169,8 @@ int File::read_frame(VFrame *frame, int is_thread)
                        }
                }
 
-//                     printf("File::read_frame %d\n", __LINE__);
                if( !temp_frame ) {
-                       temp_frame = new VFrame(0,
-                               -1,
-                               asset->width,
-                               asset->height,
-                               supported_colormodel,
-                               -1);
+                       temp_frame = new VFrame(asset->width, asset->height, supported_colormodel, 0);
                }
 
 //                     printf("File::read_frame %d\n", __LINE__);
@@ -1191,10 +1204,7 @@ int File::read_frame(VFrame *frame, int is_thread)
        return 0;
 }
 
-int File::can_copy_from(Asset *asset,
-       int64_t position,
-       int output_w,
-       int output_h)
+int File::can_copy_from(Asset *asset, int64_t position, int output_w, int output_h)
 {
        if( asset && file ) {
                return asset->width == output_w &&
@@ -1218,6 +1228,8 @@ int File::strtoformat(const char *format)
        if( !strcasecmp(format, _(SND_NAME)) ) return FILE_SND;
        if( !strcasecmp(format, _(PNG_NAME)) ) return FILE_PNG;
        if( !strcasecmp(format, _(PNG_LIST_NAME)) ) return FILE_PNG_LIST;
+       if( !strcasecmp(format, _(PPM_NAME)) ) return FILE_PPM;
+       if( !strcasecmp(format, _(PPM_LIST_NAME)) ) return FILE_PPM_LIST;
        if( !strcasecmp(format, _(TIFF_NAME)) ) return FILE_TIFF;
        if( !strcasecmp(format, _(TIFF_LIST_NAME)) ) return FILE_TIFF_LIST;
        if( !strcasecmp(format, _(JPEG_NAME)) ) return FILE_JPEG;
@@ -1254,6 +1266,8 @@ const char* File::formattostr(int format)
        case FILE_SND:          return _(SND_NAME);
        case FILE_PNG:          return _(PNG_NAME);
        case FILE_PNG_LIST:     return _(PNG_LIST_NAME);
+       case FILE_PPM:          return _(PPM_NAME);
+       case FILE_PPM_LIST:     return _(PPM_LIST_NAME);
        case FILE_JPEG:         return _(JPEG_NAME);
        case FILE_JPEG_LIST:    return _(JPEG_LIST_NAME);
        case FILE_CR2:          return _(CR2_NAME);
@@ -1261,7 +1275,9 @@ const char* File::formattostr(int format)
        case FILE_FLAC:         return _(FLAC_NAME);
        case FILE_EXR:          return _(EXR_NAME);
        case FILE_EXR_LIST:     return _(EXR_LIST_NAME);
+#ifdef HAVE_LIBZMPEG
        case FILE_MPEG:         return _(MPEG_NAME);
+#endif
        case FILE_AMPEG:        return _(AMPEG_NAME);
        case FILE_VMPEG:        return _(VMPEG_NAME);
        case FILE_TGA:          return _(TGA_NAME);
@@ -1331,12 +1347,10 @@ int File::bytes_per_sample(int bits)
 }
 
 
-
-
-
-int File::get_best_colormodel(int driver)
+int File::get_best_colormodel(int driver, int vstream)
 {
-       return get_best_colormodel(asset, driver);
+       return file ? file->get_best_colormodel(driver, vstream) :
+               get_best_colormodel(asset, driver);
 }
 
 int File::get_best_colormodel(Asset *asset, int driver)
@@ -1345,7 +1359,9 @@ int File::get_best_colormodel(Asset *asset, int driver)
 #ifdef HAVE_DV
        case FILE_RAWDV:        return FileDV::get_best_colormodel(asset, driver);
 #endif
+#ifdef HAVE_LIBZMPEG
        case FILE_MPEG:         return FileMPEG::get_best_colormodel(asset, driver);
+#endif
        case FILE_JPEG:
        case FILE_JPEG_LIST:    return FileJPEG::get_best_colormodel(asset, driver);
 #ifdef HAVE_OPENEXR
@@ -1354,11 +1370,15 @@ int File::get_best_colormodel(Asset *asset, int driver)
 #endif
        case FILE_PNG:
        case FILE_PNG_LIST:     return FilePNG::get_best_colormodel(asset, driver);
+       case FILE_PPM:
+       case FILE_PPM_LIST:     return FilePPM::get_best_colormodel(asset, driver);
        case FILE_TGA:
        case FILE_TGA_LIST:     return FileTGA::get_best_colormodel(asset, driver);
        case FILE_CR2:
        case FILE_CR2_LIST:     return FileCR2::get_best_colormodel(asset, driver);
+#ifdef HAVE_COMMERCIAL
        case FILE_DB:           return FileDB::get_best_colormodel(asset, driver);
+#endif
        case FILE_FFMPEG:       return FileFFMPEG::get_best_colormodel(asset, driver);
        }
 
@@ -1406,6 +1426,8 @@ int File::renders_video(int format)
        case FILE_EXR_LIST:
        case FILE_PNG:
        case FILE_PNG_LIST:
+       case FILE_PPM:
+       case FILE_PPM_LIST:
        case FILE_TGA:
        case FILE_TGA_LIST:
        case FILE_TIFF:
@@ -1420,7 +1442,7 @@ int File::renders_video(int format)
 int File::renders_video(Asset *asset)
 {
        return asset->format == FILE_FFMPEG ?
-               FileFFMPEG::renders_video(asset->fformat) :
+               FFMPEG::renders_video(asset->fformat) :
                renders_video(asset->format);
 }
 
@@ -1446,7 +1468,7 @@ int File::renders_audio(int format)
 int File::renders_audio(Asset *asset)
 {
        return asset->format == FILE_FFMPEG ?
-               FileFFMPEG::renders_audio(asset->fformat) :
+               FFMPEG::renders_audio(asset->fformat) :
                renders_audio(asset->format);
 }
 
@@ -1456,6 +1478,7 @@ int File::is_image_render(int format)
        case FILE_EXR:
        case FILE_JPEG:
        case FILE_PNG:
+       case FILE_PPM:
        case FILE_TGA:
        case FILE_TIFF:
                return 1;
@@ -1482,6 +1505,8 @@ const char* File::get_tag(int format)
        case FILE_PCM:          return "pcm";
        case FILE_PNG:          return "png";
        case FILE_PNG_LIST:     return "png";
+       case FILE_PPM:          return "ppm";
+       case FILE_PPM_LIST:     return "ppm";
        case FILE_TGA:          return "tga";
        case FILE_TGA_LIST:     return "tga";
        case FILE_TIFF:         return "tif";
@@ -1500,6 +1525,7 @@ const char* File::get_prefix(int format)
        case FILE_PCM:          return "PCM";
        case FILE_WAV:          return "WAV";
        case FILE_PNG:          return "PNG";
+       case FILE_PPM:          return "PPM";
        case FILE_JPEG:         return "JPEG";
        case FILE_TIFF:         return "TIFF";
        case FILE_GIF:          return "GIF";
@@ -1515,6 +1541,7 @@ const char* File::get_prefix(int format)
        case FILE_RAWDV:        return "RAWDV";
        case FILE_TIFF_LIST:    return "TIFF_LIST";
        case FILE_PNG_LIST:     return "PNG_LIST";
+       case FILE_PPM_LIST:     return "PPM_LIST";
        case FILE_AC3:          return "AC3";
        case FILE_EXR:          return "EXR";
        case FILE_EXR_LIST:     return "EXR_LIST";
@@ -1594,42 +1621,26 @@ void File::getenv_path(char *result, const char *path)
        *rp = 0;
 }
 
-void File::setenv_path(char *result, const char *var, const char *path)
+void File::setenv_path(const char *var, const char *path, int overwrite)
 {
-       char *env = getenv(var);
-       if( env ) return;
        char env_path[BCTEXTLEN];
        getenv_path(env_path, path);
-       sprintf(result, "%s=%s", var, env_path);
-       putenv(result);
+       setenv(var, env_path, overwrite);
 }
 
-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];
-char File::cinbwr_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);
-
-       setenv_path(cindat_path, "CIN_DAT", CINDAT_DIR);
-       setenv_path(cinlib_path, "CIN_LIB", CINLIB_DIR);
-       setenv_path(cincfg_path, "CIN_CONFIG", CONFIG_DIR);
-       setenv_path(cinplg_path, "CIN_PLUGIN", PLUGIN_DIR);
-       setenv_path(cinlad_path, "CIN_LADSPA", LADSPA_DIR);
-       setenv_path(cinlcl_path, "CIN_LOCALE", LOCALE_DIR);
-       setenv_path(cinbwr_path, "CIN_BROWSER", CIN_BROWSER);
+       setenv_path("CIN_PATH", env_path, 1);
+       setenv_path("CIN_PKG", env_pkg, 1);
+       setenv_path("CIN_DAT", CINDAT_DIR, 0);
+       setenv_path("CIN_LIB", CINLIB_DIR, 0);
+       setenv_path("CIN_CONFIG", CONFIG_DIR, 0);
+       setenv_path("CIN_PLUGIN", PLUGIN_DIR, 0);
+       setenv_path("CIN_LADSPA", LADSPA_DIR, 0);
+       setenv_path("CIN_LOCALE", LOCALE_DIR, 0);
+       setenv_path("CIN_BROWSER", CIN_BROWSER, 0);
 }