add haupauge-1657 dual usb capture support, add deinterlace to recordmonitor, asset...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / playbackengine.C
index 364b8c9ed243d25427caca1e3f0710773eb992b1..f95f57581b0dcf7f3ee025d5620912069624d8ca 100644 (file)
@@ -22,6 +22,7 @@
 #include "bchash.h"
 #include "bcsignals.h"
 #include "cache.h"
+#include "canvas.h"
 #include "condition.h"
 #include "edl.h"
 #include "edlsession.h"
@@ -32,6 +33,7 @@
 #include "mwindowgui.h"
 #include "patchbay.h"
 #include "tracking.h"
+#include "tracks.h"
 #include "playbackengine.h"
 #include "playtransport.h"
 #include "preferences.h"
@@ -39,6 +41,8 @@
 #include "mainsession.h"
 #include "trackcanvas.h"
 #include "transportque.h"
+#include "videodevice.h"
+#include "vdevicex11.h"
 #include "vrender.h"
 
 
@@ -129,7 +133,11 @@ int PlaybackEngine::create_render_engine()
 void PlaybackEngine::delete_render_engine()
 {
        renderengine_lock->lock("PlaybackEngine::delete_render_engine");
-       delete render_engine;  render_engine = 0;
+       if( render_engine ) {
+               render_engine->interrupt_playback();
+               render_engine->wait_done();
+               delete render_engine;  render_engine = 0;
+       }
        renderengine_lock->unlock();
 }
 
@@ -406,7 +414,7 @@ void PlaybackEngine::run()
 // Start tracking after arming so the tracking position doesn't change.
 // The tracking for a single frame command occurs during PAUSE
                        init_tracking();
-
+                       clear_borders();
 // Dispatch the command
                        start_render_engine();
                        break;
@@ -415,6 +423,23 @@ void PlaybackEngine::run()
        }
 }
 
+void PlaybackEngine::clear_borders()
+{
+       EDL *edl = command->get_edl();
+       PlaybackConfig *config = edl->session->playback_config;
+       if( config->vconfig->driver == PLAYBACK_X11_GL ) {
+               if( render_engine && render_engine->video ) {
+                       VDeviceBase *vdriver = render_engine->video->get_output_base();
+                       ((VDeviceX11*)vdriver)->clear_output();
+                       return;
+               }
+       }
+       BC_WindowBase *window = output->get_canvas();
+       if( !window ) return;
+       window->lock_window("PlaybackEngine::clear_output");
+       output->clear_borders(edl);
+       window->unlock_window();
+}
 
 void PlaybackEngine::stop_playback(int wait_tracking)
 {
@@ -427,13 +452,18 @@ void PlaybackEngine::stop_playback(int wait_tracking)
        renderengine_lock->unlock();
 }
 
+int PlaybackEngine::get_direction()
+{
+       int curr_command = is_playing_back ? this->command->command : STOP;
+       return TransportCommand::get_direction(curr_command);
+}
 
 void PlaybackEngine::send_command(int command, EDL *edl, int wait_tracking, int use_inout)
 {
 //printf("PlaybackEngine::send_command 1 %d\n", command);
 // Stop requires transferring the output buffer to a refresh buffer.
        int do_stop = 0;
-       int curr_command = this->command->command;
+       int curr_command = is_playing_back ? this->command->command : STOP;
        int curr_single_frame = TransportCommand::single_frame(curr_command);
        int curr_audio = this->command->toggle_audio ?
                !curr_single_frame : curr_single_frame;
@@ -525,15 +555,10 @@ int PlaybackEngine::transport_command(int command, int change_type, EDL *new_edl
 // Just change the EDL if the change requires it because renderengine
 // structures won't point to the new EDL otherwise and because copying the
 // EDL for every cursor movement is slow.
-               switch( change_type ) {
-               case CHANGE_EDL:
-               case CHANGE_ALL:
+               if( change_type == CHANGE_EDL || change_type == CHANGE_ALL )
                        next_command->get_edl()->copy_all(new_edl);
-                       break;
-               case CHANGE_PARAMS:
+               else if( change_type == CHANGE_PARAMS )
                        next_command->get_edl()->synchronize_params(new_edl);
-                       break;
-               }
                next_command->set_playback_range(new_edl, use_inout,
                                preferences->forward_render_displacement);
        }