BugFix Stream Source reload

Change stream reopen() to StreamSource reload()
This commit is contained in:
Bruno Herbelin
2023-11-13 23:03:31 +01:00
parent 378257b7bf
commit a57419150e
6 changed files with 22 additions and 18 deletions

View File

@@ -1878,7 +1878,7 @@ void ImGuiVisitor::visit(TextSource &s)
ImGui::SetCursorPos( ImGui::SetCursorPos(
ImVec2(top.x + 0.95 * ImGui::GetFrameHeight(), botom.y - ImGui::GetFrameHeight())); ImVec2(top.x + 0.95 * ImGui::GetFrameHeight(), botom.y - ImGui::GetFrameHeight()));
if (ImGuiToolkit::IconButton(ICON_FA_REDO_ALT, "Reload")) if (ImGuiToolkit::IconButton(ICON_FA_REDO_ALT, "Reload"))
tc->reopen(); s.reload();
} }
// general case of free text : text editor // general case of free text : text editor
else { else {

View File

@@ -1453,14 +1453,12 @@ void SourceControlWindow::RenderSingleSource(Source *s)
if (ImGui::BeginPopup( "MenuStreamOptions" )) 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 // 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(); 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); ss->stream()->setRewindOnDisabled(option);
}
if (ImGui::IsWindowHovered()) if (ImGui::IsWindowHovered())
counter_menu_timeout=0; counter_menu_timeout=0;
@@ -1856,7 +1854,6 @@ void SourceControlWindow::RenderMediaPlayer(MediaSource *ms)
ImGui::EndPopup(); ImGui::EndPopup();
} }
/// ///
/// Dialog to edit timeline fade in and out /// Dialog to edit timeline fade in and out
/// ///

View File

@@ -216,16 +216,6 @@ void Stream::open(const std::string &gstreamer_description, guint w, guint h)
discoverer_ = std::async(StreamDiscoverer, description_, w, 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 std::string Stream::description() const
{ {
return description_; return description_;

View File

@@ -40,6 +40,8 @@ struct StreamInfo {
class Stream { class Stream {
friend class StreamSource;
public: public:
/** /**
* Constructor of a GStreamer Stream * Constructor of a GStreamer Stream
@@ -57,7 +59,6 @@ public:
* Open a media using gstreamer pipeline keyword * Open a media using gstreamer pipeline keyword
* */ * */
void open(const std::string &gstreamer_description, guint w = 0, guint h = 0); void open(const std::string &gstreamer_description, guint w = 0, guint h = 0);
void reopen ();
/** /**
* Get description string * Get description string
* */ * */

View File

@@ -103,6 +103,7 @@ Source::Failure StreamSource::failed() const
return (stream_ != nullptr && stream_->failed()) ? FAIL_CRITICAL : FAIL_NONE; return (stream_ != nullptr && stream_->failed()) ? FAIL_CRITICAL : FAIL_NONE;
} }
uint StreamSource::texture() const uint StreamSource::texture() const
{ {
if (stream_ == nullptr) if (stream_ == nullptr)
@@ -187,6 +188,20 @@ void StreamSource::replay ()
stream_->rewind(); stream_->rewind();
} }
void StreamSource::reload()
{
if (stream_) {
stream_->close();
// reset renderbuffer_
if (renderbuffer_)
delete renderbuffer_;
renderbuffer_ = nullptr;
stream_->execute_open();
}
}
guint64 StreamSource::playtime () const guint64 StreamSource::playtime () const
{ {
if ( stream_ ) if ( stream_ )

View File

@@ -40,6 +40,7 @@ public:
// pure virtual interface // pure virtual interface
virtual Stream *stream() const = 0; virtual Stream *stream() const = 0;
void reload ();
// Source interface // Source interface
virtual void accept (Visitor& v) override; virtual void accept (Visitor& v) override;