[longomatch] Improve seeks a bit by limiting the rate at 80ms
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Improve seeks a bit by limiting the rate at 80ms
- Date: Fri, 14 Jun 2013 10:17:23 +0000 (UTC)
commit 22850d8ee7e95a863584186939d8f09c4ff11236
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Thu Jun 13 22:21:22 2013 +0200
Improve seeks a bit by limiting the rate at 80ms
LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs | 42 ++++++++++----
LongoMatch.Multimedia/Common/Enum.cs | 8 ++-
LongoMatch.Multimedia/Common/Handlers.cs | 1 +
LongoMatch.Multimedia/LongoMatch.Multimedia.mdp | 1 +
LongoMatch.Multimedia/Utils/Seeker.cs | 69 +++++++++++++++++++++++
5 files changed, 109 insertions(+), 12 deletions(-)
---
diff --git a/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs b/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs
index 7dedcca..a6cf747 100644
--- a/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs
+++ b/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs
@@ -68,6 +68,7 @@ namespace LongoMatch.Gui
private string filename = null;
protected VolumeWindow vwin;
bool readyToSeek = false;
+ Seeker seeker;
#region Constructors
@@ -94,6 +95,8 @@ namespace LongoMatch.Gui
seeksQueue [0] = -1;
seeksQueue [1] = -1;
detachbutton.Clicked += (sender, e) => EmitDetach();
+ seeker = new Seeker();
+ seeker.SeekEvent += HandleSeekEvent;
}
#endregion
@@ -310,12 +313,8 @@ namespace LongoMatch.Gui
public void SeekToPreviousFrame(bool in_segment) {
long currentTime = player.CurrentTime;
- if(currentTime> segmentStartTime) {
- if(player.Playing)
- player.Pause();
- player.SeekToPreviousFrame(GetRateFromScale(),in_segment);
- if(SeekEvent != null)
- SeekEvent(currentTime);
+ if (currentTime > segmentStartTime) {
+ seeker.Seek (SeekType.StepDown, GetRateFromScale(), in_segment);
}
}
@@ -438,13 +437,13 @@ namespace LongoMatch.Gui
private void SeekFromTimescale(double pos) {
if(InSegment()) {
long seekPos = segmentStartTime +
(long)(pos*(segmentStopTime-segmentStartTime));
- player.SeekInSegment(seekPos, GetRateFromScale());
- timelabel.Text= TimeString.MSecondsToSecondsString(seekPos) + "/" +
-
TimeString.MSecondsToSecondsString(segmentStopTime-segmentStartTime);
+ seeker.Seek (SeekType.Keyframe, GetRateFromScale(), true, seekPos);
+ timelabel.Text= TimeString.MSecondsToMSecondsString(seekPos) + "/" +
+
TimeString.MSecondsToMSecondsString(segmentStopTime-segmentStartTime);
}
else {
- player.Position = pos;
- timelabel.Text= TimeString.MSecondsToSecondsString(player.CurrentTime) + "/"
+ slength;
+ seeker.Seek (SeekType.Keyframe, GetRateFromScale(), true, (int) (pos *
length));
+ timelabel.Text= TimeString.MSecondsToMSecondsString(player.CurrentTime) + "/"
+ slength;
Rate = 1;
}
}
@@ -685,6 +684,27 @@ namespace LongoMatch.Gui
if(DrawFrame != null)
DrawFrame(currentTime);
}
+
+ void HandleSeekEvent (SeekType type, float rate, bool inSegment, long start, long stop)
+ {
+ /* We only use it for backwards framestepping for now */
+ if (type == SeekType.StepDown || type == SeekType.StepUp) {
+ if(player.Playing)
+ player.Pause ();
+ if (type == SeekType.StepDown)
+ player.SeekToPreviousFrame (rate, inSegment);
+ else
+ player.SeekToNextFrame (rate, inSegment);
+ if (SeekEvent != null)
+ SeekEvent ((int)AccurateCurrentTime);
+ }
+ if (type == SeekType.Accurate || type == SeekType.Keyframe) {
+ player.SeekTime (start, rate, type == SeekType.Accurate);
+ if (SeekEvent != null)
+ SeekEvent ((int)start);
+ }
+ }
+
#endregion
}
}
diff --git a/LongoMatch.Multimedia/Common/Enum.cs b/LongoMatch.Multimedia/Common/Enum.cs
index 38f1e66..006456b 100644
--- a/LongoMatch.Multimedia/Common/Enum.cs
+++ b/LongoMatch.Multimedia/Common/Enum.cs
@@ -118,5 +118,11 @@ namespace LongoMatch.Video.Common
Par,
}
-
+ public enum SeekType {
+ Keyframe,
+ Accurate,
+ StepUp,
+ StepDown,
+ None
+ }
}
diff --git a/LongoMatch.Multimedia/Common/Handlers.cs b/LongoMatch.Multimedia/Common/Handlers.cs
index 409a5a4..9f63c3d 100644
--- a/LongoMatch.Multimedia/Common/Handlers.cs
+++ b/LongoMatch.Multimedia/Common/Handlers.cs
@@ -31,6 +31,7 @@ namespace LongoMatch.Video.Common
public delegate void StateChangeHandler(object o, StateChangeArgs args);
public delegate void TickHandler(object o, TickArgs args);
public delegate void DeviceChangeHandler(object o, DeviceChangeArgs args);
+ public delegate void SeekHandler (SeekType type, float rate, bool inSegment, long start, long stop);
diff --git a/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp b/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp
index ec9f164..08ba8b1 100644
--- a/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp
+++ b/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp
@@ -62,6 +62,7 @@
<File subtype="Directory" buildaction="Compile" name="Converter" />
<File subtype="Code" buildaction="Compile" name="Converter/GstVideoConverter.cs" />
<File subtype="Code" buildaction="Compile" name="Converter/ObjectManager.cs" />
+ <File subtype="Code" buildaction="Compile" name="Utils/Seeker.cs" />
</Contents>
<References>
<ProjectReference type="Project" localcopy="True" refto="libcesarplayer" />
diff --git a/LongoMatch.Multimedia/Utils/Seeker.cs b/LongoMatch.Multimedia/Utils/Seeker.cs
new file mode 100644
index 0000000..8ef468b
--- /dev/null
+++ b/LongoMatch.Multimedia/Utils/Seeker.cs
@@ -0,0 +1,69 @@
+//
+// Copyright (C) 2013 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using LongoMatch.Video.Common;
+
+namespace LongoMatch.Video.Utils
+{
+ public class Seeker
+ {
+ public event SeekHandler SeekEvent;
+
+ uint timeout;
+ int pendingSeekId;
+ long start, stop;
+ float rate;
+ bool inSegment;
+ SeekType seekType;
+
+ public Seeker (uint timeoutMS=80)
+ {
+ timeout = timeoutMS;
+ pendingSeekId = -1;
+ seekType = SeekType.None;
+ }
+
+ public void Seek (SeekType seekType, float rate=1, bool inSegment=false, long start=0, long
stop=0)
+ {
+ this.seekType = seekType;
+ this.start = start;
+ this.stop = stop;
+ this.rate = rate;
+ this.inSegment = inSegment;
+
+ if (pendingSeekId != -1)
+ return;
+
+ HandleSeekTimeout ();
+ pendingSeekId = (int) GLib.Timeout.Add (timeout, HandleSeekTimeout);
+
+ }
+
+ public bool HandleSeekTimeout () {
+ pendingSeekId = -1;
+ if (seekType != SeekType.None) {
+ if (SeekEvent != null) {
+ SeekEvent (seekType, rate, inSegment, start, stop);
+ }
+ seekType = SeekType.None;
+ }
+ return false;
+ }
+ }
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]