From 8bc69ba0a4396228ff998ff487703057887d90b5 Mon Sep 17 00:00:00 2001 From: Bruno Herbelin Date: Tue, 30 May 2023 15:03:32 +0200 Subject: [PATCH] Delay user notification for when source is ready --- src/Mixer.cpp | 36 ++++++++++++++++++++++++++++++------ src/MixingView.cpp | 3 +-- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/Mixer.cpp b/src/Mixer.cpp index 88a4821..2a129e8 100644 --- a/src/Mixer.cpp +++ b/src/Mixer.cpp @@ -51,7 +51,6 @@ #include "SrtReceiverSource.h" #include "SourceCallback.h" -#include "InfoVisitor.h" #include "ActionManager.h" #include "MixingGroup.h" #include "FrameGrabber.h" @@ -455,6 +454,33 @@ void Mixer::addSource(Source *s) candidate_sources_.push_back(s); } +void delayed_notification( Source *source ) +{ + bool done = false; + + while (!done) { + // give it a bit of time and avoid CPU overload + std::this_thread::sleep_for(std::chrono::milliseconds(30)); + + // to be safe, make sure we have a valid source + Session *session = Mixer::manager().session(); + SourceList::iterator sit = session->find(source); + if ( sit != session->end() ) { + // voila! the source is valid : notify user if it's ready + if ( (*sit)->ready() ) { + Log::Notify("%s source %s is ready.", (*sit)->info().c_str(), (*sit)->name().c_str()); + done = true; + } + // do not notify if failed + else if ( (*sit)->failed() ) + done = true; + } + // end loop if invalid source + else + done = true; + } +} + void Mixer::insertSource(Source *s, View::Mode m) { if ( s != nullptr ) @@ -477,11 +503,9 @@ void Mixer::insertSource(Source *s, View::Mode m) // new state in history manager Action::manager().store(s->name() + std::string(": source inserted")); - // notify creation of source - static InfoVisitor _more_info; - s->accept(_more_info); - std::string moreinfo = BaseToolkit::unspace(_more_info.str(), ' '); - Log::Notify("Added %s source '%s' (%s)", s->info().c_str(), s->name().c_str(), moreinfo.c_str()); + // Log & notification + Log::Info("Adding source '%s'...", s->name().c_str()); + std::thread(delayed_notification, s).detach(); // if requested to show the source in a given view // (known to work for View::MIXING et TRANSITION: other views untested) diff --git a/src/MixingView.cpp b/src/MixingView.cpp index 41374a1..b5f95fc 100644 --- a/src/MixingView.cpp +++ b/src/MixingView.cpp @@ -656,13 +656,12 @@ View::Cursor MixingView::over (glm::vec2 pos) if (s != nullptr && s->ready()) { s->symbol_->color = glm::vec4( COLOR_HIGHLIGHT_SOURCE, 1.f ); - s->initial_0_->color = glm::vec4( COLOR_HIGHLIGHT_SOURCE, 1.f ); - s->initial_1_->color = glm::vec4( COLOR_HIGHLIGHT_SOURCE, 1.f ); const ImVec4 h = ImGuiToolkit::HighlightColor(); // overlay symbol if ( pick.first == s->symbol_ ) s->symbol_->color = glm::vec4( h.x, h.y, h.z, 1.f ); + } return ret;