From: Good Guy Date: Sat, 16 Feb 2019 01:44:27 +0000 (-0700) Subject: usb_direct fix for rev2 shuttle, playbackengine locks again, viewer cursor fix X-Git-Tag: 2019-08~102 X-Git-Url: https://git.cinelerra-gg.org/git/?a=commitdiff_plain;h=45dd712aa4b2894f6b2390b4797262831dcdb47a;p=goodguy%2Fcinelerra.git usb_direct fix for rev2 shuttle, playbackengine locks again, viewer cursor fix --- diff --git a/cinelerra-5.1/cinelerra/awindowgui.C b/cinelerra-5.1/cinelerra/awindowgui.C index 65e5ba25..8b53f7ad 100644 --- a/cinelerra-5.1/cinelerra/awindowgui.C +++ b/cinelerra-5.1/cinelerra/awindowgui.C @@ -398,7 +398,7 @@ int AssetViewPopup::button_press_event() vedl->set_inpoint(start); vedl->set_outpoint(end); vedl->local_session->set_selectionstart(start); - vedl->local_session->set_selectionend(end); + vedl->local_session->set_selectionend(start); vwindow->gui->lock_window("AssetViewPopup::button_press_event"); vwindow->update_position(); vwindow->gui->unlock_window(); diff --git a/cinelerra-5.1/cinelerra/playbackengine.C b/cinelerra-5.1/cinelerra/playbackengine.C index 0dd9b37f..16f6bd7a 100644 --- a/cinelerra-5.1/cinelerra/playbackengine.C +++ b/cinelerra-5.1/cinelerra/playbackengine.C @@ -128,26 +128,25 @@ int PlaybackEngine::create_render_engine() void PlaybackEngine::delete_render_engine() { renderengine_lock->lock("PlaybackEngine::delete_render_engine"); - delete render_engine; - render_engine = 0; + delete render_engine; render_engine = 0; renderengine_lock->unlock(); } void PlaybackEngine::arm_render_engine() { - if(render_engine) + if( render_engine ) render_engine->arm_command(command); } void PlaybackEngine::start_render_engine() { - if(render_engine) render_engine->start_command(); + if( render_engine ) + render_engine->start_command(); } void PlaybackEngine::wait_render_engine() { - if(command->realtime && render_engine) - { + if( command->realtime && render_engine ) { render_engine->join(); } } @@ -180,14 +179,14 @@ void PlaybackEngine::sync_parameters(EDL *edl) { // TODO: lock out render engine from keyframe deletions command->get_edl()->synchronize_params(edl); - if(render_engine) render_engine->get_edl()->synchronize_params(edl); + if( render_engine ) + render_engine->get_edl()->synchronize_params(edl); } - void PlaybackEngine::interrupt_playback(int wait_tracking) { renderengine_lock->lock("PlaybackEngine::interrupt_playback"); - if(render_engine) + if( render_engine ) render_engine->interrupt_playback(); renderengine_lock->unlock(); @@ -195,22 +194,19 @@ void PlaybackEngine::interrupt_playback(int wait_tracking) pause_lock->unlock(); // Wait for tracking to finish if it is running - if(wait_tracking) - { + if( wait_tracking ) { tracking_done->lock("PlaybackEngine::interrupt_playback"); tracking_done->unlock(); } } - // Return 1 if levels exist int PlaybackEngine::get_output_levels(double *levels, long position) { int result = 0; - if(render_engine && render_engine->do_audio) - { - result = 1; + if( render_engine && render_engine->do_audio ) { render_engine->get_output_levels(levels, position); + result = 1; } return result; } @@ -219,10 +215,9 @@ int PlaybackEngine::get_output_levels(double *levels, long position) int PlaybackEngine::get_module_levels(ArrayList *module_levels, long position) { int result = 0; - if(render_engine && render_engine->do_audio) - { - result = 1; + if( render_engine && render_engine->do_audio ) { render_engine->get_module_levels(module_levels, position); + result = 1; } return result; } @@ -287,10 +282,8 @@ double PlaybackEngine::get_tracking_position() // Don't interpolate when every frame is played. - if(command->get_edl()->session->video_every_frame && - render_engine && - render_engine->do_video) - { + if( command->get_edl()->session->video_every_frame && + render_engine && render_engine->do_video ) { result = tracking_position; } else @@ -422,7 +415,7 @@ void PlaybackEngine::stop_playback(int wait_tracking) { transport_stop(wait_tracking); renderengine_lock->lock("PlaybackEngine::stop_playback"); - if(render_engine) + if( render_engine ) render_engine->wait_done(); renderengine_lock->unlock(); } @@ -491,12 +484,23 @@ void PlaybackEngine::send_command(int command, EDL *edl, int wait_tracking, int } } -int PlaybackEngine::transport_stop(int wait_tracking) +int PlaybackEngine::put_command(TransportCommand *command, int reset) { - interrupt_playback(0); - input_lock->lock("PlaybackEngine::transport_stop"); - sent_command->copy_from(stop_command); +// commands can deadlock updating tracking,meters,clock... + int mlocked = mwindow->gui->break_lock(); + input_lock->lock("PlaybackEngine::put_command"); + sent_command->copy_from(command); + if( reset ) + command->reset(); output_lock->unlock(); + if( mlocked ) + mwindow->gui->lock_window("PlaybackEngine::put_command"); + return 0; +} + +int PlaybackEngine::transport_stop(int wait_tracking) +{ + put_command(stop_command, 0); if( wait_tracking ) { tracking_done->lock("PlaybackEngine::transport_stop"); tracking_done->unlock(); @@ -525,13 +529,7 @@ int PlaybackEngine::transport_command(int command, int change_type, EDL *new_edl next_command->set_playback_range(new_edl, use_inout, preferences->forward_render_displacement); } - - interrupt_playback(0); - input_lock->lock("PlaybackEngine::transport_command"); - sent_command->copy_from(next_command); - next_command->reset(); - output_lock->unlock(); - + put_command(next_command, 1); //static const char *types[] = { "NONE", // "FRAME_FWD", "NORMAL_FWD", "FAST_FWD", "FRAME_REV", "NORMAL_REV", "FAST_REV", // "STOP", "PAUSE", "SLOW_FWD", "SLOW_REV", "REWIND", "GOTO_END", "CURRENT_FRAME", diff --git a/cinelerra-5.1/cinelerra/playbackengine.h b/cinelerra-5.1/cinelerra/playbackengine.h index 29632529..62616822 100644 --- a/cinelerra-5.1/cinelerra/playbackengine.h +++ b/cinelerra-5.1/cinelerra/playbackengine.h @@ -110,6 +110,7 @@ public: // Copy of main preferences Preferences *preferences; + int put_command(TransportCommand *command, int reset); int transport_stop(int wait_tracking); int transport_command(int command, int change_type=CHANGE_NONE, EDL *new_edl=0, int use_inout=0); diff --git a/cinelerra-5.1/cinelerra/renderengine.C b/cinelerra-5.1/cinelerra/renderengine.C index 3c178bb0..9b640d20 100644 --- a/cinelerra-5.1/cinelerra/renderengine.C +++ b/cinelerra-5.1/cinelerra/renderengine.C @@ -349,13 +349,9 @@ int64_t RenderEngine::sync_position() // Use audio device // No danger of race conditions because the output devices are closed after all // threads join. - if(do_audio) - { + if( do_audio ) return audio->current_position(); - } - - if(do_video) - { + if( do_video ) { int64_t result = timer.get_scaled_difference( get_edl()->session->sample_rate); return result; @@ -366,8 +362,7 @@ int64_t RenderEngine::sync_position() int RenderEngine::start_command() { - if(command->realtime && !is_nested) - { + if( command->realtime && !is_nested ) { interrupt_lock->lock("RenderEngine::start_command"); start_lock->lock("RenderEngine::start_command 1"); Thread::start(); @@ -379,15 +374,8 @@ int RenderEngine::start_command() void RenderEngine::arm_render_threads() { - if(do_audio) - { - arender->arm_command(); - } - - if(do_video) - { - vrender->arm_command(); - } + if( do_audio ) arender->arm_command(); + if( do_video ) vrender->arm_command(); } @@ -396,15 +384,10 @@ void RenderEngine::start_render_threads() // Synchronization timer. Gets reset once again after the first video frame. timer.update(); - if(do_audio) - { - arender->start_command(); - } + if( do_audio ) arender->start_command(); + if( do_video ) vrender->start_command(); - if(do_video) - { - vrender->start_command(); - } + start_lock->unlock(); } void RenderEngine::update_framerate(float framerate) @@ -415,29 +398,18 @@ void RenderEngine::update_framerate(float framerate) void RenderEngine::wait_render_threads() { - if(do_audio) - { - arender->Thread::join(); - } - - if(do_video) - { - vrender->Thread::join(); - } + if( do_audio ) arender->Thread::join(); + if( do_video ) vrender->Thread::join(); } void RenderEngine::interrupt_playback() { + if( interrupted ) return; interrupt_lock->lock("RenderEngine::interrupt_playback"); - interrupted = 1; - if(do_audio && arender) - { - arender->interrupt_playback(); - } - - if(do_video && vrender) - { - vrender->interrupt_playback(); + if( !interrupted ) { + interrupted = 1; + if( do_audio && arender ) arender->interrupt_playback(); + if( do_video && vrender ) vrender->interrupt_playback(); } interrupt_lock->unlock(); } @@ -445,25 +417,15 @@ void RenderEngine::interrupt_playback() int RenderEngine::close_output() { // Nested engines share devices - if(!is_nested) - { - if(audio) - { - audio->close_all(); - delete audio; - audio = 0; - } - - - - if(video) - { - video->close_all(); - delete video; - video = 0; - } + if( is_nested ) return 0; + if( audio ) { + audio->close_all(); + delete audio; audio = 0; + } + if( video ) { + video->close_all(); + delete video; video = 0; } - return 0; } @@ -497,58 +459,33 @@ void RenderEngine::get_module_levels(ArrayList *module_levels, int64_t p void RenderEngine::run() { render_active->lock("RenderEngine::run"); - start_render_threads(); - start_lock->unlock(); - interrupt_lock->unlock(); + interrupt_lock->unlock(); + start_render_threads(); wait_render_threads(); - - interrupt_lock->lock("RenderEngine::run"); - - - if(interrupted) - { - playback_engine->tracking_position = playback_engine->get_tracking_position(); - } + interrupt_lock->lock("RenderEngine::wait_render_threads"); close_output(); -// Fix the tracking position - if(playback_engine) - { - if(command->command == CURRENT_FRAME || command->command == LAST_FRAME) - { -//printf("RenderEngine::run 4.1 %d\n", playback_engine->tracking_position); - playback_engine->tracking_position = command->playbackstart; - } - else - { -// Make sure transport doesn't issue a pause command next -//printf("RenderEngine::run 4.1 %d\n", playback_engine->tracking_position); - if(!interrupted) - { - playback_engine->tracking_position = - command->get_direction() == PLAY_FORWARD ? - command->end_position : command->start_position; - } - - if( playback_engine->is_playing_back && command->displacement ) { - double position = playback_engine->tracking_position - - 1./command->get_edl()->session->frame_rate; - playback_engine->tracking_position = position >= 0 ? position : 0; - } - - if( !interrupted ) - playback_engine->command->command = STOP; - playback_engine->stop_tracking(); - + if( playback_engine && playback_engine->is_playing_back ) { + double position = interrupted ? + playback_engine->get_tracking_position() : + command->get_direction() == PLAY_FORWARD ? + command->end_position : + command->start_position; + playback_engine->command->command = STOP; + if( playback_engine->is_playing_back && command->displacement ) { + position -= 1./command->get_edl()->session->frame_rate; + if( position < 0 ) position = 0; } playback_engine->is_playing_back = 0; + playback_engine->tracking_position = position; + playback_engine->stop_tracking(); } - input_lock->unlock(); - interrupt_lock->unlock(); render_active->unlock(); + interrupt_lock->unlock(); + input_lock->unlock(); } void RenderEngine::wait_done() diff --git a/cinelerra-5.1/cinelerra/shudmp.C b/cinelerra-5.1/cinelerra/shudmp.C index fbb85cf6..ae31aceb 100644 --- a/cinelerra-5.1/cinelerra/shudmp.C +++ b/cinelerra-5.1/cinelerra/shudmp.C @@ -58,7 +58,7 @@ int main(int ac, char **av) while( !done ) { int len = 0; static const int IN_ENDPOINT = 0x81; - unsigned char dat[64]; + unsigned char dat[5]; int ret = libusb_interrupt_transfer(devsh, IN_ENDPOINT, dat, sizeof(dat), &len, 100); if( ret != 0 ) { diff --git a/cinelerra-5.1/cinelerra/shuttle.C b/cinelerra-5.1/cinelerra/shuttle.C index 22adeaf0..7bf3c5e4 100644 --- a/cinelerra-5.1/cinelerra/shuttle.C +++ b/cinelerra-5.1/cinelerra/shuttle.C @@ -847,7 +847,7 @@ void Shuttle::run() while( devsh && !done ) { int len = 0; static const int IN_ENDPOINT = 0x81; - unsigned char dat[BCSTRLEN]; + unsigned char dat[5]; int ret = libusb_interrupt_transfer(devsh, IN_ENDPOINT, dat, sizeof(dat), &len, 100); if( ret != 0 ) { diff --git a/cinelerra-5.1/cinelerra/trackcanvas.C b/cinelerra-5.1/cinelerra/trackcanvas.C index ab93d623..4b1c2364 100644 --- a/cinelerra-5.1/cinelerra/trackcanvas.C +++ b/cinelerra-5.1/cinelerra/trackcanvas.C @@ -3993,7 +3993,7 @@ int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y) // Snap to nearby values old_value = current->get_value(); if(shift_down()) { - double value1, value2, distance1, distance2; + double value1, value2, distance1=-1, distance2=-1; if(current->previous) { int autogrouptype = current->previous->autos->autogrouptype; diff --git a/cinelerra-5.1/guicast/bcscrollbar.C b/cinelerra-5.1/guicast/bcscrollbar.C index 680341d0..a148bc30 100644 --- a/cinelerra-5.1/guicast/bcscrollbar.C +++ b/cinelerra-5.1/guicast/bcscrollbar.C @@ -86,16 +86,14 @@ void BC_ScrollBar::set_images(VFrame **data) void BC_ScrollBar::calculate_dimensions(int &w, int &h) { - switch(orientation) - { + w = h = pixels; + switch( orientation ) { case SCROLL_HORIZ: - w = pixels; h = data[SCROLL_HANDLE_UP]->get_h(); break; case SCROLL_VERT: w = data[SCROLL_HANDLE_UP]->get_w(); - h = pixels; break; } } diff --git a/cinelerra-5.1/guicast/bcwindowbase.C b/cinelerra-5.1/guicast/bcwindowbase.C index f9e49e22..099f8249 100644 --- a/cinelerra-5.1/guicast/bcwindowbase.C +++ b/cinelerra-5.1/guicast/bcwindowbase.C @@ -3334,6 +3334,23 @@ int BC_WindowBase::unlock_window() return 0; } +int BC_WindowBase::break_lock() +{ + if( !top_level ) return 0; + if( top_level != this ) return top_level->break_lock(); + if( top_level->display_lock_owner != pthread_self() ) return 0; + if( top_level->window_lock != 1 ) return 0; + UNSET_LOCK(this); + window_lock = 0; + display_lock_owner = 0; +#ifdef SINGLE_THREAD + BC_Display::unlock_display(); +#else + XUnlockDisplay(display); +#endif + return 1; +} + void BC_WindowBase::set_done(int return_value) { if(done_set) return; diff --git a/cinelerra-5.1/guicast/bcwindowbase.h b/cinelerra-5.1/guicast/bcwindowbase.h index b512820d..7dfc26fd 100644 --- a/cinelerra-5.1/guicast/bcwindowbase.h +++ b/cinelerra-5.1/guicast/bcwindowbase.h @@ -251,6 +251,7 @@ public: int lock_window(const char *location = 0); int unlock_window(); int get_window_lock(); + int break_lock(); BC_MenuBar* add_menubar(BC_MenuBar *menu_bar); BC_WindowBase* add_subwindow(BC_WindowBase *subwindow); diff --git a/cinelerra-5.1/libzmpeg3/audio/layer3.C b/cinelerra-5.1/libzmpeg3/audio/layer3.C index b0eb2909..d8f18970 100644 --- a/cinelerra-5.1/libzmpeg3/audio/layer3.C +++ b/cinelerra-5.1/libzmpeg3/audio/layer3.C @@ -742,7 +742,7 @@ do_layer3(uint8_t *zframe, int zframe_size, float **zoutput, int render) /* max 39 for short[13][3] mode, mixed: 38, long: 22 */ int scalefacs[2][39]; l3_sideinfo_t sideinfo; - int ms_stereo, i_stereo; + int ms_stereo=0, i_stereo=0; int sfreq = sampling_frequency_code; int stereo1, granules; int output_offset = 0; @@ -798,8 +798,8 @@ do_layer3(uint8_t *zframe, int zframe_size, float **zoutput, int render) ptr = bsbuf + ssize - prev_len; memcpy(ptr, prev, prev_len); past_framesize += prev_framesize; - } -//} +// } + } if( ptr && past_framesize >= prev_len ) { stream->use_ptr(ptr); for( gr=0; gr