[banshee/gst#] [gst#] Fix subtitle
- From: Olivier Dufour <dufoli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee/gst#] [gst#] Fix subtitle
- Date: Fri, 17 Jun 2011 10:35:54 +0000 (UTC)
commit 34e764ee91f0a260cc084e6fce350c40bef96eec
Author: Olivier Dufour <olivier duff gmail com>
Date: Thu Jun 2 00:17:28 2011 +0200
[gst#] Fix subtitle
.../Banshee.GStreamerSharp/PlayerEngine.cs | 79 +++++++++++++++++++-
.../Banshee.GStreamerSharp/VideoManager.cs | 30 ++++----
2 files changed, 91 insertions(+), 18 deletions(-)
---
diff --git a/src/Backends/Banshee.GStreamerSharp/Banshee.GStreamerSharp/PlayerEngine.cs b/src/Backends/Banshee.GStreamerSharp/Banshee.GStreamerSharp/PlayerEngine.cs
index 598e8b4..565493e 100644
--- a/src/Backends/Banshee.GStreamerSharp/Banshee.GStreamerSharp/PlayerEngine.cs
+++ b/src/Backends/Banshee.GStreamerSharp/Banshee.GStreamerSharp/PlayerEngine.cs
@@ -395,6 +395,9 @@ namespace Banshee.GStreamerSharp
return;
}
playbin.Uri = uri.AbsoluteUri;
+ if (maybeVideo)
+ LookupForSubtitle (uri);
+
next_track_set.Set ();
}
@@ -626,8 +629,45 @@ namespace Banshee.GStreamerSharp
}
playbin.Uri = uri.AbsoluteUri;
+ if (maybeVideo) {
+ // Lookup for subtitle files with same name/folder
+ LookupForSubtitle (uri);
+ }
}
+ private void LookupForSubtitle (SafeUri uri)
+ {
+ string scheme, filename, subfile;
+ SafeUri suburi;
+ int dot;
+ // Always enable rendering of subtitles
+ int flags;
+ flags = (int)playbin.Flags;
+ flags |= (1 << 2);//GST_PLAY_FLAG_TEXT
+ playbin.Flags = (ObjectFlags)flags;
+
+ Log.Debug ("[subtitle]: lookup for subtitle for video file.");
+ scheme = uri.Scheme;
+ string[] subtitle_extensions = { ".srt", ".sub", ".smi", ".txt", ".mpl", ".dks", ".qtx" };
+ if (scheme == null || scheme == "file") {
+ return;
+ }
+
+ dot = uri.AbsoluteUri.LastIndexOf ('.');
+ if (dot == -1)
+ return;
+ filename = uri.AbsoluteUri.Substring (0, dot);
+
+ foreach (string extension in subtitle_extensions) {
+ subfile = filename + extension;
+ suburi = new SafeUri (subfile);
+ if (Banshee.IO.File.Exists (suburi)) {
+ Log.DebugFormat ("[subtitle]: Found srt file: {0}", subfile);
+ playbin.Suburi = subfile;
+ return;
+ }
+ }
+ }
public override void Play ()
{
playbin.SetState (Gst.State.Playing);
@@ -761,14 +801,49 @@ namespace Banshee.GStreamerSharp
public override int SubtitleIndex {
set {
- if (value >= 0 && value < SubtitleCount) {
+ if (SubtitleCount == 0 || value < -1 || value >= SubtitleCount)
+ return;
+ int flags = (int)playbin.Flags;
+
+ if (value == -1) {
+ flags &= ~(1 << 2);//GST_PLAY_FLAG_TEXT
+ playbin.Flags = (ObjectFlags)flags;
+ } else {
+ flags |= (1 << 2);//GST_PLAY_FLAG_TEXT
+ playbin.Flags = (ObjectFlags)flags;
playbin.CurrentText = value;
}
}
}
public override SafeUri SubtitleUri {
- set { playbin.Suburi = value.AbsoluteUri; }
+ set {
+ long pos = -1;
+ State state;
+ Format format = Format.Bytes;
+ bool paused = false;
+
+ // Gstreamer playbin do not support to set suburi during playback
+ // so have to stop/play and seek
+ playbin.GetState (out state, 0);
+ paused = (state == State.Paused);
+ if (state >= State.Paused) {
+ playbin.QueryPosition (ref format, out pos);
+ playbin.SetState (State.Ready);
+ // Force to wait asynch operation
+ playbin.GetState (out state, 0);
+ }
+
+ playbin.Suburi = value.AbsoluteUri;
+ playbin.SetState (paused ? State.Paused : State.Playing);
+
+ // Force to wait asynch operation
+ playbin.GetState (out state, 0);
+
+ if (pos != -1) {
+ playbin.Seek (format, SeekFlags.Flush | SeekFlags.KeyUnit, pos);
+ }
+ }
get { return new SafeUri (playbin.Suburi); }
}
diff --git a/src/Backends/Banshee.GStreamerSharp/Banshee.GStreamerSharp/VideoManager.cs b/src/Backends/Banshee.GStreamerSharp/Banshee.GStreamerSharp/VideoManager.cs
index 3f6106d..c0f649b 100644
--- a/src/Backends/Banshee.GStreamerSharp/Banshee.GStreamerSharp/VideoManager.cs
+++ b/src/Backends/Banshee.GStreamerSharp/Banshee.GStreamerSharp/VideoManager.cs
@@ -71,7 +71,8 @@ namespace Banshee.GStreamerSharp
return;
}
}
- #if GDK_WINDOWING_X11 || GDK_WINDOWING_WIN32
+
+#if GDK_WINDOWING_X11 || GDK_WINDOWING_WIN32
video_display_context_type = VideoDisplayContextType.GdkWindow;
@@ -96,22 +97,19 @@ namespace Banshee.GStreamerSharp
((Bin)videosink).ElementAdded += OnVideoSinkElementAdded;
}
- #else
+#else
video_display_context_type = VideoDisplayContextType.Unsupported;
- #if WIN32
-
- videosink = ElementFactory.Make ("fakesink", "videosink");
- if (videosink != NULL) {
- videosink ["sync"] = true;
+ if (PlatformDetection.IsWindows) {
+ videosink = ElementFactory.Make ("fakesink", "videosink");
+ if (videosink != null) {
+ videosink ["sync"] = true;
+ }
+ playbin ["video-sink"] = videosink;
}
- playbin ["video-sink"] = videosink;
-
- #endif
-
- #endif
+#endif
if (PrepareWindow != null) {
PrepareWindow ();
@@ -133,7 +131,7 @@ namespace Banshee.GStreamerSharp
if (message.Type != MessageType.Element)
return;
- #if GDK_WINDOWING_X11 || GDK_WINDOWING_WIN32
+#if GDK_WINDOWING_X11 || GDK_WINDOWING_WIN32
if (message.Structure == null || !message.Structure.HasName ("prepare-xwindow-id")) {
return;
@@ -145,14 +143,14 @@ namespace Banshee.GStreamerSharp
xoverlay.XwindowId = video_window_xid;
}
- #endif
+#endif
}
private void OnVideoSinkElementAdded (object o, ElementAddedArgs args)
{
- #if GDK_WINDOWING_X11 || GDK_WINDOWING_WIN32
+#if GDK_WINDOWING_X11 || GDK_WINDOWING_WIN32
FindXOverlay ();
- #endif
+#endif
}
private bool FindXOverlay ()
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]