From 6735e5eaaa9301641d64ec2488be3d9bf4c6ffb6 Mon Sep 17 00:00:00 2001 From: Bruno Herbelin Date: Tue, 14 Nov 2023 11:12:21 +0100 Subject: [PATCH] New Reload source function Generalize the reload of stream source to all types of sources. Enable OSC command to reload source. --- src/CloneSource.cpp | 5 +++++ src/CloneSource.h | 1 + src/ControlManager.cpp | 4 ++++ src/ControlManager.h | 1 + src/ImageFilter.cpp | 2 +- src/MediaSource.cpp | 5 +++++ src/MediaSource.h | 1 + src/RenderSource.cpp | 11 +++++++++++ src/RenderSource.h | 1 + src/SessionSource.cpp | 15 ++++++++++++--- src/SessionSource.h | 1 + src/Source.h | 1 + src/StreamSource.h | 2 +- 13 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/CloneSource.cpp b/src/CloneSource.cpp index 5b04821..99a409c 100644 --- a/src/CloneSource.cpp +++ b/src/CloneSource.cpp @@ -209,6 +209,11 @@ void CloneSource::replay() filter_->reset(); } +void CloneSource::reload() +{ + replay(); +} + guint64 CloneSource::playtime () const { if (filter_->type() != FrameBufferFilter::FILTER_PASSTHROUGH) diff --git a/src/CloneSource.h b/src/CloneSource.h index 5fab548..6c9431f 100644 --- a/src/CloneSource.h +++ b/src/CloneSource.h @@ -20,6 +20,7 @@ public: void play (bool on) override; bool playable () const override; void replay () override; + void reload() override; guint64 playtime () const override; uint texture() const override; Failure failed() const override; diff --git a/src/ControlManager.cpp b/src/ControlManager.cpp index d05ebfd..5982ccb 100644 --- a/src/ControlManager.cpp +++ b/src/ControlManager.cpp @@ -612,6 +612,10 @@ bool Control::receiveSourceAttribute(Source *target, const std::string &attribut else if ( attribute.compare(OSC_SOURCE_REPLAY) == 0) { target->call( new RePlay() ); } + /// e.g. '/vimix/current/reload' + else if ( attribute.compare(OSC_SOURCE_RELOAD) == 0) { + target->reload(); + } /// e.g. '/vimix/current/alpha f 0.3' else if ( attribute.compare(OSC_SOURCE_LOCK) == 0) { float x = 1.f; diff --git a/src/ControlManager.h b/src/ControlManager.h index a24de02..a30951f 100644 --- a/src/ControlManager.h +++ b/src/ControlManager.h @@ -38,6 +38,7 @@ #define OSC_SOURCE_PLAY "/play" #define OSC_SOURCE_PAUSE "/pause" #define OSC_SOURCE_REPLAY "/replay" +#define OSC_SOURCE_RELOAD "/reload" #define OSC_SOURCE_ALPHA "/alpha" #define OSC_SOURCE_LOOM "/loom" #define OSC_SOURCE_TRANSPARENCY "/transparency" diff --git a/src/ImageFilter.cpp b/src/ImageFilter.cpp index c8b2d81..d92ed17 100644 --- a/src/ImageFilter.cpp +++ b/src/ImageFilter.cpp @@ -112,7 +112,7 @@ FilteringProgram::FilteringProgram(const std::string &name, const std::string &f } FilteringProgram::FilteringProgram(const FilteringProgram &other) : - name_(other.name_), code_(other.code_), parameters_(other.parameters_), two_pass_filter_(other.two_pass_filter_) + name_(other.name_), code_(other.code_), two_pass_filter_(other.two_pass_filter_), parameters_(other.parameters_) { } diff --git a/src/MediaSource.cpp b/src/MediaSource.cpp index c50aab4..dfb512c 100644 --- a/src/MediaSource.cpp +++ b/src/MediaSource.cpp @@ -162,6 +162,11 @@ void MediaSource::replay () mediaplayer_->rewind(); } +void MediaSource::reload () +{ + mediaplayer_->reopen(); +} + guint64 MediaSource::playtime () const { return mediaplayer_->position(); diff --git a/src/MediaSource.h b/src/MediaSource.h index 40ad483..341472d 100644 --- a/src/MediaSource.h +++ b/src/MediaSource.h @@ -18,6 +18,7 @@ public: void play (bool) override; bool playable () const override; void replay () override; + void reload () override; guint64 playtime () const override; void render() override; Failure failed() const override; diff --git a/src/RenderSource.cpp b/src/RenderSource.cpp index 1885fd9..86eb1c0 100644 --- a/src/RenderSource.cpp +++ b/src/RenderSource.cpp @@ -162,6 +162,17 @@ void RenderSource::replay () reset_ = true; } +void RenderSource::reload () +{ + // reset renderbuffer_ + if (renderbuffer_) + delete renderbuffer_; + renderbuffer_ = nullptr; + + // request next frame to reset + reset_ = true; +} + glm::vec3 RenderSource::resolution() const { if (rendered_output_ != nullptr) diff --git a/src/RenderSource.h b/src/RenderSource.h index d5daa5c..5139e09 100644 --- a/src/RenderSource.h +++ b/src/RenderSource.h @@ -16,6 +16,7 @@ public: bool playing () const override { return !paused_; } void play (bool) override; void replay () override; + void reload () override; bool playable () const override { return true; } guint64 playtime () const override { return runtime_; } Failure failed () const override; diff --git a/src/SessionSource.cpp b/src/SessionSource.cpp index e57f886..a705fec 100644 --- a/src/SessionSource.cpp +++ b/src/SessionSource.cpp @@ -277,10 +277,14 @@ void SessionFileSource::load(const std::string &p, uint level) path_ = p; // delete session - if (session_) { + if (session_) delete session_; - session_ = nullptr; - } + session_ = nullptr; + + // reset renderbuffer_ + if (renderbuffer_) + delete renderbuffer_; + renderbuffer_ = nullptr; // init session if ( path_.empty() ) { @@ -299,6 +303,11 @@ void SessionFileSource::load(const std::string &p, uint level) ready_ = false; } +void SessionFileSource::reload() +{ + load(path_); +} + void SessionFileSource::init() { // init is first about getting the loaded session diff --git a/src/SessionSource.h b/src/SessionSource.h index 86eec92..2aa55cb 100644 --- a/src/SessionSource.h +++ b/src/SessionSource.h @@ -44,6 +44,7 @@ public: // SessionFile Source specific interface void load(const std::string &p = "", uint level = 0); + void reload () override; inline std::string path() const { return path_; } diff --git a/src/Source.h b/src/Source.h index 23d2033..f4cc059 100644 --- a/src/Source.h +++ b/src/Source.h @@ -184,6 +184,7 @@ public: virtual bool playing () const = 0; virtual void play (bool on) = 0; virtual void replay () {} + virtual void reload () {} virtual guint64 playtime () const { return 0; } // a Source shall informs if the source failed (i.e. shall be deleted) diff --git a/src/StreamSource.h b/src/StreamSource.h index 5def20f..8dfedef 100644 --- a/src/StreamSource.h +++ b/src/StreamSource.h @@ -34,13 +34,13 @@ public: void play (bool) override; bool playable () const override; void replay () override; + void reload () override; guint64 playtime () const override; Failure failed() const override; uint texture() const override; // pure virtual interface virtual Stream *stream() const = 0; - void reload (); // Source interface virtual void accept (Visitor& v) override;