From ced318637fdddf9514ecaa76ad5dd887914165ad Mon Sep 17 00:00:00 2001 From: Bruno Herbelin Date: Wed, 31 May 2023 19:27:08 +0200 Subject: [PATCH] Source replacement and create source with software decoder --- src/ImGuiVisitor.cpp | 16 +++++++++++++++- src/Mixer.cpp | 22 ++++++++++++++-------- src/Mixer.h | 6 ++++-- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/ImGuiVisitor.cpp b/src/ImGuiVisitor.cpp index 807a939..cc0c666 100644 --- a/src/ImGuiVisitor.cpp +++ b/src/ImGuiVisitor.cpp @@ -694,15 +694,29 @@ void ImGuiVisitor::visit (MediaSource& s) if (ImGuiToolkit::IconButton(ICON_FA_FOLDER_OPEN, "Show in finder")) SystemToolkit::open(SystemToolkit::path_filename(s.path())); + ImGui::SetCursorPos(botom); } else { + // failed ImGui::SetCursorPos(top); if (ImGuiToolkit::IconButton(ICON_FA_COPY, "Copy message")) ImGui::SetClipboardText(info.str().c_str()); info.reset(); + + ImGui::SetCursorPos(botom); + + // because sometimes the error comes from gpu decoding + if ( Settings::application.render.gpu_decoding ) + { + // offer to reload the source without hardware decoding + if ( ImGui::Button( ICON_FA_REDO_ALT " Try again without\nhardware decoding", ImVec2(IMGUI_RIGHT_ALIGN, 0)) ) { + // replace current source with one created with a flag forcing software decoding + Mixer::manager().replaceSource(Mixer::manager().currentSource(), + Mixer::manager().createSourceFile(s.path(), true)); + } + } } - ImGui::SetCursorPos(botom); } void ImGuiVisitor::visit (SessionFileSource& s) diff --git a/src/Mixer.cpp b/src/Mixer.cpp index 463a33a..ba6beab 100644 --- a/src/Mixer.cpp +++ b/src/Mixer.cpp @@ -31,6 +31,7 @@ #include +#include "ImageShader.h" #include "defines.h" #include "Settings.h" #include "Log.h" @@ -42,6 +43,7 @@ #include "SessionSource.h" #include "CloneSource.h" #include "RenderSource.h" +#include "MediaPlayer.h" #include "MediaSource.h" #include "PatternSource.h" #include "DeviceSource.h" @@ -186,8 +188,14 @@ void Mixer::update() // if there is a source candidate for this session if (candidate_sources_.size() > 0) { + // the first element of the pair is the source to insert // NB: only make the last candidate the current source in Mixing view - insertSource(candidate_sources_.front(), candidate_sources_.size() > 1 ? View::INVALID : View::MIXING); + insertSource(candidate_sources_.front().first, candidate_sources_.size() > 1 ? View::INVALID : View::MIXING); + + // the second element of the pair is the source to be replaced, i.e. deleted if provided + if (candidate_sources_.front().second != nullptr) + deleteSource(candidate_sources_.front().second); + candidate_sources_.pop_front(); } @@ -264,7 +272,7 @@ void Mixer::draw() } // manangement of sources -Source * Mixer::createSourceFile(const std::string &path) +Source * Mixer::createSourceFile(const std::string &path, bool disable_hw_decoding) { // ready to create a source Source *s = nullptr; @@ -283,6 +291,7 @@ Source * Mixer::createSourceFile(const std::string &path) else { // (try to) create media source by default MediaSource *ms = new MediaSource; + ms->mediaplayer()->setSoftwareDecodingForced(disable_hw_decoding); ms->setPath(path); s = ms; } @@ -451,7 +460,7 @@ Source * Mixer::createSourceClone(const std::string &namesource, bool copy_attri void Mixer::addSource(Source *s) { if (s != nullptr) - candidate_sources_.push_back(s); + candidate_sources_.push_back( std::make_pair(s, nullptr) ); } void delayed_notification( Source *source ) @@ -546,14 +555,11 @@ void Mixer::replaceSource(Source *previous, Source *s) s->setImageProcessingEnabled( previous->imageProcessingEnabled() ); s->blendingShader()->blending = previous->blendingShader()->blending; - // delete previous source - session_->deleteSource(previous); - // rename s renameSource(s, previous_name); - // add source s - candidate_sources_.push_back(s); + // add source 's' and remove source 'previous' + candidate_sources_.push_back( std::make_pair(s, previous) ); } diff --git a/src/Mixer.h b/src/Mixer.h index 3945be7..854e909 100644 --- a/src/Mixer.h +++ b/src/Mixer.h @@ -48,7 +48,7 @@ public: void draw (); // creation of sources - Source * createSourceFile (const std::string &path); + Source * createSourceFile (const std::string &path, bool disable_hw_decoding = false); Source * createSourceMultifile(const std::list &list_files, uint fps); Source * createSourceClone (const std::string &namesource = "", bool copy_attributes = true); Source * createSourceRender (); @@ -137,7 +137,9 @@ protected: bool sessionSwapRequested_; void swap(); - SourceList candidate_sources_; + // temporary buffer of sources to be inserted at next iteration, + // stored in pair with the source to replace, if provided + std::list< std::pair > candidate_sources_; SourceList stash_; void insertSource (Source *s, View::Mode m = View::INVALID); bool recreateSource(Source *s);