From 7f1264ae27bb9fe75ee4d71d30520b21e8a52531 Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Fri, 16 Oct 2020 20:00:22 +0200 Subject: [PATCH] Add fast seeking (disabled by default) The fast seeking option. It seeks to the next keyframe which reduces seeking delay over 10 times, but makes the seeking very inaccurate as a side effect (usually up to few seconds from requested position). --- clapper_src/interface.js | 1 - clapper_src/player.js | 25 ++++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/clapper_src/interface.js b/clapper_src/interface.js index 3e14d3ef..72b35ee1 100644 --- a/clapper_src/interface.js +++ b/clapper_src/interface.js @@ -446,7 +446,6 @@ class ClapperInterface extends Gtk.Grid this.lastPositionValue = positionSeconds; this._player.seek_seconds(positionSeconds); - debug(`player is seeking to position: ${positionSeconds}`); /* Needed to enable preview after playback is stopped */ if(this._player.state === GstPlayer.PlayerState.STOPPED) diff --git a/clapper_src/player.js b/clapper_src/player.js index f7e50522..ca19d0ec 100644 --- a/clapper_src/player.js +++ b/clapper_src/player.js @@ -52,7 +52,7 @@ class ClapperPlayer extends GstPlayer.Player this.gstRegistry = Gst.Registry.get(); this.is_local_file = false; - this.seek_done = true; + this.seek_done = false; this._playerSignals = []; this._widgetSignals = []; @@ -77,6 +77,7 @@ class ClapperPlayer extends GstPlayer.Player this.widget = gtkglsink.widget; this.state = GstPlayer.PlayerState.STOPPED; this.visualization_enabled = false; + this.fast_seeking = opts.fast_seeking || false; this._playlist = []; this._trackId = 0; @@ -101,7 +102,6 @@ class ClapperPlayer extends GstPlayer.Player this.connect('state-changed', this._onStateChanged.bind(this)); this.connect('uri-loaded', this._onUriLoaded.bind(this)); - this.connect('seek-done', this._onSeekDone.bind(this)); this.connect('end-of-stream', this._onStreamEnded.bind(this)); this.connect('warning', this._onPlayerWarning.bind(this)); this.connect('error', this._onPlayerError.bind(this)); @@ -203,8 +203,17 @@ class ClapperPlayer extends GstPlayer.Player seek(position) { this.seek_done = false; + debug(`player is seeking to position: ${position}`); - super.seek(position); + if(!this.fast_seeking) + return super.seek(position); + + let pipeline = this.get_pipeline(); + let flags = Gst.SeekFlags.FLUSH + | Gst.SeekFlags.KEY_UNIT + | Gst.SeekFlags.SNAP_AFTER; + + pipeline.seek_simple(Gst.Format.TIME, flags, position); } seek_seconds(position) @@ -262,18 +271,16 @@ class ClapperPlayer extends GstPlayer.Player this.state = state; if(this.state === GstPlayer.PlayerState.STOPPED) { - this.seek_done = true; if( this.run_loop && this.loop.is_running() ) this.loop.quit(); } - } - - _onSeekDone() - { - this.seek_done = true; + if(!this.seek_done && this.state !== GstPlayer.PlayerState.BUFFERING) { + this.seek_done = true; + debug('seeking finished'); + } } _onStreamEnded(player)