diff --git a/src/ImGuiVisitor.cpp b/src/ImGuiVisitor.cpp index feffc08..fd352c3 100644 --- a/src/ImGuiVisitor.cpp +++ b/src/ImGuiVisitor.cpp @@ -1878,7 +1878,7 @@ void ImGuiVisitor::visit(TextSource &s) ImGui::SetCursorPos( ImVec2(top.x + 0.95 * ImGui::GetFrameHeight(), botom.y - ImGui::GetFrameHeight())); if (ImGuiToolkit::IconButton(ICON_FA_REDO_ALT, "Reload")) - tc->reopen(); + s.reload(); } // general case of free text : text editor else { diff --git a/src/SourceControlWindow.cpp b/src/SourceControlWindow.cpp index 744376b..4c5c38c 100644 --- a/src/SourceControlWindow.cpp +++ b/src/SourceControlWindow.cpp @@ -1453,14 +1453,12 @@ void SourceControlWindow::RenderSingleSource(Source *s) if (ImGui::BeginPopup( "MenuStreamOptions" )) { + if (ImGui::MenuItem(ICON_FA_REDO_ALT " Reload")) + ss->reload(); // NB: ss is playable (tested above), and thus ss->stream() is not null - if (ImGui::MenuItem( ICON_FA_REDO_ALT " Reload" )) { - ss->stream()->reopen(); - } bool option = ss->stream()->rewindOnDisabled(); - if (ImGui::MenuItem(ICON_FA_SNOWFLAKE " Restart on deactivation", NULL, &option )) { + if (ImGui::MenuItem(ICON_FA_SNOWFLAKE " Restart on deactivation", NULL, &option )) ss->stream()->setRewindOnDisabled(option); - } if (ImGui::IsWindowHovered()) counter_menu_timeout=0; @@ -1856,7 +1854,6 @@ void SourceControlWindow::RenderMediaPlayer(MediaSource *ms) ImGui::EndPopup(); } - /// /// Dialog to edit timeline fade in and out /// diff --git a/src/Stream.cpp b/src/Stream.cpp index f988ab4..fc1be26 100644 --- a/src/Stream.cpp +++ b/src/Stream.cpp @@ -216,16 +216,6 @@ void Stream::open(const std::string &gstreamer_description, guint w, guint h) discoverer_ = std::async(StreamDiscoverer, description_, w, h); } -void Stream::reopen() -{ - // re-openning is meaningfull only if it was already open - if (pipeline_ != nullptr) { - // reload : terminate pipeline and re-create it - close(); - execute_open(); - } -} - std::string Stream::description() const { return description_; diff --git a/src/Stream.h b/src/Stream.h index b0b95cc..48d2432 100644 --- a/src/Stream.h +++ b/src/Stream.h @@ -40,6 +40,8 @@ struct StreamInfo { class Stream { + friend class StreamSource; + public: /** * Constructor of a GStreamer Stream @@ -57,7 +59,6 @@ public: * Open a media using gstreamer pipeline keyword * */ void open(const std::string &gstreamer_description, guint w = 0, guint h = 0); - void reopen (); /** * Get description string * */ diff --git a/src/StreamSource.cpp b/src/StreamSource.cpp index e745372..d880e23 100644 --- a/src/StreamSource.cpp +++ b/src/StreamSource.cpp @@ -103,6 +103,7 @@ Source::Failure StreamSource::failed() const return (stream_ != nullptr && stream_->failed()) ? FAIL_CRITICAL : FAIL_NONE; } + uint StreamSource::texture() const { if (stream_ == nullptr) @@ -187,6 +188,20 @@ void StreamSource::replay () stream_->rewind(); } +void StreamSource::reload() +{ + if (stream_) { + stream_->close(); + + // reset renderbuffer_ + if (renderbuffer_) + delete renderbuffer_; + renderbuffer_ = nullptr; + + stream_->execute_open(); + } +} + guint64 StreamSource::playtime () const { if ( stream_ ) diff --git a/src/StreamSource.h b/src/StreamSource.h index 1601888..5def20f 100644 --- a/src/StreamSource.h +++ b/src/StreamSource.h @@ -40,6 +40,7 @@ public: // pure virtual interface virtual Stream *stream() const = 0; + void reload (); // Source interface virtual void accept (Visitor& v) override;