From e8acfc1c26c02e7f10b93c81eec189a85792440b Mon Sep 17 00:00:00 2001 From: Bruno Date: Sun, 1 Aug 2021 19:10:46 +0200 Subject: [PATCH] New Media Player option to Rewind on Disabled --- MediaPlayer.cpp | 17 ++++++++++++++++- MediaPlayer.h | 9 ++++++++- SessionCreator.cpp | 4 ++++ SessionVisitor.cpp | 1 + UserInterfaceManager.cpp | 8 ++++++-- 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/MediaPlayer.cpp b/MediaPlayer.cpp index cc7c1e1..ee08bfe 100644 --- a/MediaPlayer.cpp +++ b/MediaPlayer.cpp @@ -37,6 +37,7 @@ MediaPlayer::MediaPlayer() failed_ = false; seeking_ = false; + rewind_on_disable_ = false; force_software_decoding_ = false; decoder_name_ = ""; rate_ = 1.0; @@ -517,6 +518,11 @@ void MediaPlayer::enable(bool on) if ( enabled_ != on ) { + // option to automatically rewind each time the player is disabled + if (!on && rewind_on_disable_ ) + rewind(true); + + // apply change enabled_ = on; // default to pause @@ -648,7 +654,7 @@ void MediaPlayer::setLoop(MediaPlayer::LoopMode mode) loop_ = mode; } -void MediaPlayer::rewind() +void MediaPlayer::rewind(bool force) { if (!enabled_ || !media_.seekable) return; @@ -665,6 +671,12 @@ void MediaPlayer::rewind() // normal case, end is last frame execute_seek_command( timeline_.previous(timeline_.last()) ); } + + if (force) { + GstState state; + gst_element_get_state (pipeline_, &state, NULL, GST_CLOCK_TIME_NONE); + update(); + } } @@ -1111,7 +1123,9 @@ bool MediaPlayer::fill_frame(GstBuffer *buf, FrameStatus status) // get the frame from buffer if ( !gst_video_frame_map (&frame_[write_index_].vframe, &v_frame_video_info_, buf, GST_MAP_READ ) ) { +#ifdef MEDIA_PLAYER_DEBUG Log::Info("MediaPlayer %s Failed to map the video buffer", std::to_string(id_).c_str()); +#endif // free access to frame & exit frame_[write_index_].status = INVALID; frame_[write_index_].access.unlock(); @@ -1138,6 +1152,7 @@ bool MediaPlayer::fill_frame(GstBuffer *buf, FrameStatus status) #ifdef MEDIA_PLAYER_DEBUG Log::Info("MediaPlayer %s Received an Invalid frame", std::to_string(id_).c_str()); #endif + // free access to frame & exit frame_[write_index_].status = INVALID; frame_[write_index_].access.unlock(); return false; diff --git a/MediaPlayer.h b/MediaPlayer.h index 52497b9..fe0bba8 100644 --- a/MediaPlayer.h +++ b/MediaPlayer.h @@ -187,7 +187,7 @@ public: /** * Seek to zero * */ - void rewind(); + void rewind(bool force = false); /** * Get position time * */ @@ -254,6 +254,12 @@ public: * */ void setSoftwareDecodingForced(bool on); bool softwareDecodingForced(); + /** + * Option to automatically rewind each time the player is disabled + * (i.e. when enable(false) is called ) + * */ + inline void setRewindOnDisabled(bool on) { rewind_on_disable_ = on; } + inline bool rewindOnDisabled() const { return rewind_on_disable_; } /** * Accept visitors * */ @@ -292,6 +298,7 @@ private: std::atomic failed_; bool seeking_; bool enabled_; + bool rewind_on_disable_; bool force_software_decoding_; std::string decoder_name_; diff --git a/SessionCreator.cpp b/SessionCreator.cpp index ae1d433..f162d46 100644 --- a/SessionCreator.cpp +++ b/SessionCreator.cpp @@ -701,6 +701,10 @@ void SessionLoader::visit(MediaPlayer &n) mediaplayerNode->QueryBoolAttribute("software_decoding", &gpudisable); n.setSoftwareDecodingForced(gpudisable); + bool rewind_on_disabled = false; + mediaplayerNode->QueryBoolAttribute("rewind_on_disabled", &rewind_on_disabled); + n.setRewindOnDisabled(rewind_on_disabled); + bool play = true; mediaplayerNode->QueryBoolAttribute("play", &play); n.play(play); diff --git a/SessionVisitor.cpp b/SessionVisitor.cpp index e9b7a65..87ed16d 100644 --- a/SessionVisitor.cpp +++ b/SessionVisitor.cpp @@ -334,6 +334,7 @@ void SessionVisitor::visit(MediaPlayer &n) newelement->SetAttribute("loop", (int) n.loop()); newelement->SetAttribute("speed", n.playSpeed()); newelement->SetAttribute("software_decoding", n.softwareDecodingForced()); + newelement->SetAttribute("rewind_on_disabled", n.rewindOnDisabled()); // timeline XMLElement *timelineelement = xmlDoc_->NewElement("Timeline"); diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index f15d2c3..c4b800d 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -72,7 +72,7 @@ TextEditor editor; #define PLOT_ARRAY_SIZE 180 #define LABEL_AUTO_MEDIA_PLAYER ICON_FA_CARET_SQUARE_RIGHT " Dynamic selection" #define LABEL_STORE_SELECTION " Store selection" -#define LABEL_EDIT_FADING ICON_FA_RANDOM " Fading" +#define LABEL_EDIT_FADING ICON_FA_RANDOM " Edit Fading" // utility functions void ShowAboutGStreamer(bool* p_open); @@ -2159,9 +2159,13 @@ void SourceController::Render() Action::manager().store(oss.str()); } - if ( ImGui::MenuItem(LABEL_EDIT_FADING) ) + if (ImGui::MenuItem(LABEL_EDIT_FADING)) mediaplayer_edit_fading_ = true; + bool option = mediaplayer_active_->rewindOnDisabled(); + if (ImGui::MenuItem(ICON_FA_FAST_BACKWARD " " ICON_FA_SNOWFLAKE " Rewind when Inactive" , NULL, &option)) + mediaplayer_active_->setRewindOnDisabled(option); + // if (ImGui::BeginMenu(ICON_FA_CUT " Auto cut" )) // { // if (ImGuiToolkit::MenuItemIcon(14, 12, "Cut faded areas" ))