New Media Player option to Rewind on Disabled

This commit is contained in:
Bruno
2021-08-01 19:10:46 +02:00
parent eaadc210ae
commit e8acfc1c26
5 changed files with 35 additions and 4 deletions

View File

@@ -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;

View File

@@ -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<bool> failed_;
bool seeking_;
bool enabled_;
bool rewind_on_disable_;
bool force_software_decoding_;
std::string decoder_name_;

View File

@@ -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);

View File

@@ -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");

View File

@@ -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);
@@ -2162,6 +2162,10 @@ void SourceController::Render()
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" ))