Improve UI Play Direction and speed

Play speed slider changes the speed without changing direction (not working well). Change play direction is now in a play sub-menu (mouse over) in play bar. Video menu changed, with Timeline section
This commit is contained in:
Bruno Herbelin
2023-08-08 23:02:34 +02:00
parent f75b384c17
commit ebd59e38ce
4 changed files with 82 additions and 43 deletions

Binary file not shown.

View File

@@ -319,6 +319,7 @@ typedef enum {
GST_PLAY_FLAG_SW_DECODER = 0x00001000
} GstPlayFlags;
//
// Setup a media player using gstreamer playbin
//
@@ -368,7 +369,7 @@ void MediaPlayer::execute_open()
}
// setup appsink
GstElement *sink = gst_element_factory_make ("appsink", NULL);
GstElement *sink = gst_element_factory_make ("appsink", "appsink");
if (!sink) {
Log::Warning("MediaPlayer %s Could not configure sink", std::to_string(id_).c_str());
failed_ = true;
@@ -1358,10 +1359,8 @@ void MediaPlayer::setPlaySpeed(double s)
GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE,
GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
if (seek_event && gst_element_send_event(pipeline_, seek_event) ) {
if (seek_event && gst_element_send_event(pipeline_, seek_event) )
seeking_ = true;
Log::Info("MediaPlayer %s; instant rate to %f", std::to_string(id_).c_str(), rate_);
}
else {
Log::Info("MediaPlayer %s; cannot perform instantaneous speed change. Change of play speed will not be smooth.", std::to_string(id_).c_str());
rate_change_ = RATE_CHANGE_FLUSH;
@@ -1370,10 +1369,8 @@ void MediaPlayer::setPlaySpeed(double s)
// Generic way is a flush seek
// following the example from
// https://gstreamer.freedesktop.org/documentation/tutorials/basic/playback-speed.html
else {
Log::Info("MediaPlayer %s; flush rate to %f", std::to_string(id_).c_str(), rate_);
else
execute_seek_command();
}
// Set after initialization (will be used next time)
if (rate_change_ == RATE_CHANGE_NONE)
@@ -1616,3 +1613,16 @@ void MediaPlayer::TimeCounter::tic ()
}
}
//static void audio_changed_callback (GstElement *pipeline, MediaPlayer *mp)
//{
// gint n_audio;
// g_object_get (G_OBJECT (pipeline), "n-audio", &n_audio, NULL);
// if ( n_audio > 0 ) {
// Log::Info("MediaPlayer %d Audio stream muted", std::to_string( mp->id() ).c_str() );
// gst_stream_volume_set_volume (GST_STREAM_VOLUME (pipeline), GST_STREAM_VOLUME_FORMAT_LINEAR, 0.);
// gst_stream_volume_set_mute (GST_STREAM_VOLUME (pipeline), true);
// }
//}
// flags |= GST_PLAY_FLAG_AUDIO;
// g_signal_connect ( G_OBJECT (pipeline_), "audio-changed", G_CALLBACK (audio_changed_callback), this);

View File

@@ -140,7 +140,7 @@ void ShaderEditWindow::Render()
if (ImGui::BeginMenu(IMGUI_TITLE_SHADEREDITOR))
{
// reload code from GPU
if (ImGui::MenuItem( ICON_FA_SYNC " Reload", nullptr, nullptr, current_ != nullptr)) {
if (ImGui::MenuItem( ICON_FA_REDO_ALT " Reload", nullptr, nullptr, current_ != nullptr)) {
// force reload
if ( current_ != nullptr )
filters_.erase(current_);

View File

@@ -374,7 +374,33 @@ void SourceControlWindow::Render()
//
if (ImGui::BeginMenu(ICON_FA_FILM " Video", mediaplayer_active_) )
{
if (ImGui::MenuItem(ICON_FA_WINDOW_CLOSE " Reset timeline")){
if (ImGui::MenuItem( ICON_FA_REDO_ALT " Reload" ))
mediaplayer_active_->reopen();
if (ImGuiToolkit::MenuItemIcon(16, 16, "Gstreamer effect") )
mediaplayer_edit_pipeline_ = true;
if (ImGui::BeginMenu(ICON_FA_SNOWFLAKE " On deactivation"))
{
bool option = !mediaplayer_active_->rewindOnDisabled();
if (ImGui::MenuItem(ICON_FA_STOP " Stop", NULL, &option ))
mediaplayer_active_->setRewindOnDisabled(false);
option = mediaplayer_active_->rewindOnDisabled();
if (ImGui::MenuItem(ICON_FA_FAST_BACKWARD " Rewind & Stop", NULL, &option ))
mediaplayer_active_->setRewindOnDisabled(true);
ImGui::EndMenu();
}
if (ImGui::BeginMenu(ICON_FA_MICROCHIP " Hardware decoding"))
{
bool hwdec = !mediaplayer_active_->softwareDecodingForced();
if (ImGui::MenuItem("Auto", "", &hwdec ))
mediaplayer_active_->setSoftwareDecodingForced(false);
hwdec = mediaplayer_active_->softwareDecodingForced();
if (ImGui::MenuItem("Disabled", "", &hwdec ))
mediaplayer_active_->setSoftwareDecodingForced(true);
ImGui::EndMenu();
}
ImGui::Separator();
ImGui::TextDisabled("Timeline");
if (ImGui::MenuItem(ICON_FA_WINDOW_CLOSE " Reset")){
mediaplayer_timeline_zoom_ = 1.f;
mediaplayer_active_->timeline()->clearFading();
mediaplayer_active_->timeline()->clearGaps();
@@ -402,32 +428,6 @@ void SourceControlWindow::Render()
ImGui::EndMenu();
}
ImGui::Separator();
if (ImGui::BeginMenu(ICON_FA_SNOWFLAKE " Deactivation"))
{
bool option = !mediaplayer_active_->rewindOnDisabled();
if (ImGui::MenuItem(ICON_FA_STOP " Stop", NULL, &option ))
mediaplayer_active_->setRewindOnDisabled(false);
option = mediaplayer_active_->rewindOnDisabled();
if (ImGui::MenuItem(ICON_FA_FAST_BACKWARD " Rewind & Stop", NULL, &option ))
mediaplayer_active_->setRewindOnDisabled(true);
ImGui::EndMenu();
}
// always allow for hardware decoding to be disabled
if (ImGui::BeginMenu(ICON_FA_MICROCHIP " Hardware decoding"))
{
bool hwdec = !mediaplayer_active_->softwareDecodingForced();
if (ImGui::MenuItem("Auto", "", &hwdec ))
mediaplayer_active_->setSoftwareDecodingForced(false);
hwdec = mediaplayer_active_->softwareDecodingForced();
if (ImGui::MenuItem("Disabled", "", &hwdec ))
mediaplayer_active_->setSoftwareDecodingForced(true);
ImGui::EndMenu();
}
// TODO finalize pipeline editor
if (ImGui::MenuItem(ICON_FA_MAGIC " Video effect"))
mediaplayer_edit_pipeline_ = true;
ImGui::EndMenu();
}
@@ -1491,6 +1491,8 @@ void SourceControlWindow::RenderMediaPlayer(MediaSource *ms)
///
/// media player timelines
///
double current_play_speed = mediaplayer_active_->playSpeed();
static uint counter_menu_timeout = 0;
const ImVec2 scrollwindow = ImVec2(ImGui::GetContentRegionAvail().x - slider_zoom_width - 3.0,
2.f * timeline_height_ + scrollbar_ );
@@ -1656,12 +1658,12 @@ void SourceControlWindow::RenderMediaPlayer(MediaSource *ms)
ImGui::SameLine(0, MAX(h_space_ * 2.f, rendersize.x - min_width_ * 1.4f) );
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - buttons_height_ );
// speed slider
float speed = static_cast<float>(mediaplayer_active_->playSpeed());
if (ImGui::DragFloat( "##Speed", &speed, 0.01f, -10.f, 10.f, UNICODE_MULTIPLY " %.2f"))
mediaplayer_active_->setPlaySpeed( static_cast<double>(speed) );
float s = fabs(static_cast<float>(current_play_speed));
if (ImGui::DragFloat( "##Speed", &s, 0.01f, 0.1f, 10.f, UNICODE_MULTIPLY " %.2f"))
mediaplayer_active_->setPlaySpeed( SIGN(current_play_speed) * static_cast<double>(s) );
// store action on mouse release
if (ImGui::IsItemDeactivatedAfterEdit()){
oss << ": Speed x" << std::setprecision(3) << speed;
oss << ": Speed x" << std::setprecision(3) << s;
Action::manager().store(oss.str());
}
if (ImGui::IsItemHovered())
@@ -1670,8 +1672,9 @@ void SourceControlWindow::RenderMediaPlayer(MediaSource *ms)
ImGui::SameLine();
ImGui::SetCursorPosX(rendersize.x - buttons_height_ / 1.4f);
if (ImGuiToolkit::IconButton(12,14,"Reset" )) {
mediaplayer_active_->reopen();
if (ImGuiToolkit::IconButton(5, 8) || ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup)) {
counter_menu_timeout=0;
ImGui::OpenPopup( "MenuPlaySpeed" );
}
// restore buttons style
@@ -1715,6 +1718,32 @@ void SourceControlWindow::RenderMediaPlayer(MediaSource *ms)
DrawButtonBar(bottom, rendersize.x);
}
if (ImGui::BeginPopup( "MenuPlaySpeed" ))
{
if (ImGuiToolkit::MenuItemIcon(8,0, "Play forward", nullptr, current_play_speed>0)) {
mediaplayer_active_->setPlaySpeed( ABS(mediaplayer_active_->playSpeed()) );
oss << ": Play forward";
Action::manager().store(oss.str());
}
if (ImGuiToolkit::MenuItemIcon(9,0, "Play backward", nullptr, current_play_speed<0)) {
mediaplayer_active_->setPlaySpeed( - ABS(mediaplayer_active_->playSpeed()) );
oss << ": Play backward";
Action::manager().store(oss.str());
}
if (ImGuiToolkit::MenuItemIcon(19,15, "Reset speed")) {
mediaplayer_active_->setPlaySpeed(1.0);
oss << ": Speed x 1.0";
Action::manager().store(oss.str());
}
if (ImGui::IsWindowHovered())
counter_menu_timeout=0;
else if (++counter_menu_timeout > 10)
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
if (mediaplayer_edit_fading_) {
ImGui::OpenPopup(LABEL_EDIT_FADING);
@@ -1798,7 +1827,7 @@ void SourceControlWindow::RenderMediaPlayer(MediaSource *ms)
static bool _effect_description_changed = false;
if (mediaplayer_edit_pipeline_) {
// open dialog
ImGui::OpenPopup(ICON_FA_MAGIC " Video effect");
ImGui::OpenPopup("Gstreamer Video effect");
mediaplayer_edit_pipeline_ = false;
// initialize dialog
_effect_description = mediaplayer_active_->videoEffect();
@@ -1808,7 +1837,7 @@ void SourceControlWindow::RenderMediaPlayer(MediaSource *ms)
ImGui::SetNextWindowSize(mpp_dialog_size, ImGuiCond_Always);
const ImVec2 mpp_dialog_pos = top + rendersize * 0.5f - mpp_dialog_size * 0.5f;
ImGui::SetNextWindowPos(mpp_dialog_pos, ImGuiCond_Always);
if (ImGui::BeginPopupModal(ICON_FA_MAGIC " Video effect", NULL, ImGuiWindowFlags_NoResize))
if (ImGui::BeginPopupModal("Gstreamer Video effect", NULL, ImGuiWindowFlags_NoResize))
{
const ImVec2 pos = ImGui::GetCursorPos();
const ImVec2 area = ImGui::GetContentRegionAvail();