add transition caching with pref, rev read frame caching, cache lock tweaks, fix...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / playbackengine.C
index 8ce98234c3ffc7ed2b0ed6e4c00b4f6e3fa749ee..571afe2a83a174a3eaeeab536182258131839d2b 100644 (file)
@@ -71,6 +71,7 @@ PlaybackEngine::PlaybackEngine(MWindow *mwindow, Canvas *output)
        tracking_done = new Condition(1, "PlaybackEngine::tracking_done");
        pause_lock = new Condition(0, "PlaybackEngine::pause_lock");
        start_lock = new Condition(0, "PlaybackEngine::start_lock");
+       cache_lock = new Mutex("PlaybackEngine::cache_lock");
        input_lock = new Condition(1, "PlaybackEngine::input_lock");
        output_lock = new Condition(0, "PlaybackEngine::output_lock", 1);
 
@@ -85,12 +86,15 @@ PlaybackEngine::~PlaybackEngine()
        Thread::join();
        delete preferences;
        delete_render_engine();
-       delete audio_cache;
-       delete video_cache;
+       if( audio_cache )
+               audio_cache->remove_user();
+       if( video_cache )
+               video_cache->remove_user();
        delete tracking_lock;
        delete tracking_done;
        delete pause_lock;
        delete start_lock;
+       delete cache_lock;
        delete renderengine_lock;
        delete command;
        delete next_command;
@@ -162,10 +166,14 @@ void PlaybackEngine::wait_render_engine()
 
 void PlaybackEngine::create_cache()
 {
-       if(audio_cache) { delete audio_cache;  audio_cache = 0; }
-       if(video_cache) { delete video_cache;  video_cache = 0; }
-       if(!audio_cache) audio_cache = new CICache(preferences);
-       if(!video_cache) video_cache = new CICache(preferences);
+       cache_lock->lock("PlaybackEngine::create_cache");
+       if( audio_cache )
+               audio_cache->remove_user();
+       if( video_cache )
+               video_cache->remove_user();
+       audio_cache = new CICache(preferences);
+       video_cache = new CICache(preferences);
+       cache_lock->unlock();
 }
 
 
@@ -458,6 +466,12 @@ int PlaybackEngine::get_direction()
        return TransportCommand::get_direction(curr_command);
 }
 
+void PlaybackEngine::update_preferences(Preferences *prefs)
+{
+       preferences->copy_from(prefs);
+       create_render_engine();
+}
+
 void PlaybackEngine::send_command(int command, EDL *edl, int wait_tracking, int use_inout)
 {
 //printf("PlaybackEngine::send_command 1 %d\n", command);