diff --git a/src/MediaPlayer.cpp b/src/MediaPlayer.cpp index c17f7ea..b361e62 100644 --- a/src/MediaPlayer.cpp +++ b/src/MediaPlayer.cpp @@ -1130,6 +1130,10 @@ void MediaPlayer::execute_seek_command(GstClockTime target, bool force) void MediaPlayer::setPlaySpeed(double s) { +#if GST_VERSION_MINOR > 17 && GST_VERSION_MAJOR > 0 + bool change_direction = s * rate_ < 0.0; +#endif + if (media_.isimage) return; @@ -1139,8 +1143,31 @@ void MediaPlayer::setPlaySpeed(double s) if (ABS(rate_) < MIN_PLAY_SPEED) rate_ = SIGN(rate_) * MIN_PLAY_SPEED; - // apply with seek + // Apply with gstreamer seek + // + // GST_SEEK_FLAG_INSTANT_RATE_CHANGE: Signals that a rate change should be + // applied immediately. Only valid if start/stop position + // are GST_CLOCK_TIME_NONE, the playback direction does not change + // and the seek is not flushing. (Since: 1.18) +#if GST_VERSION_MINOR > 17 && GST_VERSION_MAJOR > 0 + // if all conditions to use GST_SEEK_FLAG_INSTANT_RATE_CHANGE are met + if ( pipeline_ != nullptr && media_.seekable && !change_direction ) { + + GstEvent *seek_event = gst_event_new_seek (rate_, GST_FORMAT_TIME, GST_SEEK_FLAG_INSTANT_RATE_CHANGE, + GST_SEEK_TYPE_NONE, 0, GST_SEEK_TYPE_NONE, 0); + + if (seek_event && !gst_element_send_event(pipeline_, seek_event) ) + Log::Warning("MediaPlayer %s setPlaySpeed failed", std::to_string(id_).c_str()); + else + seeking_ = true; + } + // Generic way is following the example from + // https://gstreamer.freedesktop.org/documentation/tutorials/basic/playback-speed.html + else + execute_seek_command(); +#else execute_seek_command(); +#endif } double MediaPlayer::playSpeed() const diff --git a/src/UserInterfaceManager.cpp b/src/UserInterfaceManager.cpp index 2cef3d4..7456650 100644 --- a/src/UserInterfaceManager.cpp +++ b/src/UserInterfaceManager.cpp @@ -4401,7 +4401,7 @@ void SourceController::RenderMediaPlayer(MediaSource *ms) ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - buttons_height_ ); // speed slider float speed = static_cast(mediaplayer_active_->playSpeed()); - if (ImGui::DragFloat( "##Speed", &speed, 0.01f, -10.f, 10.f, UNICODE_MULTIPLY " %.2f", 2.f)) + if (ImGui::DragFloat( "##Speed", &speed, 0.01f, -10.f, 10.f, UNICODE_MULTIPLY " %.2f")) mediaplayer_active_->setPlaySpeed( static_cast(speed) ); // store action on mouse release if (ImGui::IsItemDeactivatedAfterEdit()){