[gnome-subtitles] Only emit Video Loaded when all video info is available (Fixes #587097). Check for audio-only stream



commit 5ae93b7943b002827afc402f5b4da86e59707ba3
Author: Pedro Castro <mail pedrocastro org>
Date:   Sun Jul 12 20:42:12 2009 +0100

    Only emit Video Loaded when all video info is available (Fixes #587097). Check for audio-only streams.
    
    Video loading takes 3 steps: playbin loaded state, duration tag found and video information found. Previously, different parts of the UI were updated according to each of the video information part found. Now, the UI only updates when all info is available,

 src/External/GStreamerPlaybin/Engine.cs            |    6 +++-
 src/External/GStreamerPlaybin/main.c               |   31 ++++++++++++++--
 src/GnomeSubtitles/Ui/Menus.cs                     |    4 ++
 src/GnomeSubtitles/Ui/VideoPreview/Player.cs       |   24 +++++++++++--
 src/GnomeSubtitles/Ui/VideoPreview/Video.cs        |   37 +++++++++++++++++---
 .../Ui/VideoPreview/VideoPosition.cs               |   12 +++---
 src/SubLib/IO/Output/VerboseConsole.cs             |    6 ++--
 7 files changed, 98 insertions(+), 22 deletions(-)
---
diff --git a/src/External/GStreamerPlaybin/Engine.cs b/src/External/GStreamerPlaybin/Engine.cs
index 873d009..296ed03 100644
--- a/src/External/GStreamerPlaybin/Engine.cs
+++ b/src/External/GStreamerPlaybin/Engine.cs
@@ -533,6 +533,8 @@ namespace GStreamer
     	int width;
 		int height;
     	float frame_rate;
+		bool has_audio;
+		bool has_video;
 		
 		public VideoInfo (IntPtr ptr)
 		{
@@ -544,10 +546,12 @@ namespace GStreamer
        	public int Height { get{ return height; } }
        	public float AspectRatio { get { return (float)width/height; } }
     	public float FrameRate { get{ return frame_rate; } }
+		public bool HasAudio { get{ return has_audio; } }
+		public bool HasVideo { get{ return has_video; } }
     	
     	public override string ToString ()
     	{
-    		return "width=" + width + ", height=" + height + ", frame_rate=" + frame_rate;
+    		return "width=" + width + ", height=" + height + ", frame_rate=" + frame_rate + ", has_audio=" + has_audio + ", has_video=" + has_video;
     	}
 
     }
diff --git a/src/External/GStreamerPlaybin/main.c b/src/External/GStreamerPlaybin/main.c
index 6b27680..d598eac 100644
--- a/src/External/GStreamerPlaybin/main.c
+++ b/src/External/GStreamerPlaybin/main.c
@@ -46,6 +46,8 @@ struct gstVideoInfo {
 	gint width;
 	gint height;
 	gfloat frame_rate;
+	gboolean has_audio;
+	gboolean has_video;
 };
 
 
@@ -83,6 +85,8 @@ struct gstPlay {
 //Declarations
 static void setup_vis (gstPlay *play);
 gboolean gst_binding_load_video_info (gstPlay *play);
+gboolean gst_binding_has_video (gstPlay *play);
+gboolean gst_binding_has_audio (gstPlay *play);
 
 
 static GstBusSyncReply
@@ -382,7 +386,14 @@ gboolean gst_binding_has_video (gstPlay *play) {
 	else return TRUE;
 }
 
-
+gboolean gst_binding_has_audio (gstPlay *play) {
+	if (!isValid (play)) return FALSE;
+	
+	gint cur_audio;
+	g_object_get (play->element, "current-audio", &cur_audio, NULL);
+	if (cur_audio == -1) return FALSE;
+	else return TRUE;
+}
 
 //returns the tag information
 gstTag *gst_binding_get_tag (gstPlay *play) {
@@ -404,11 +415,24 @@ gstVideoInfo *gst_binding_get_video_info (gstPlay *play) {
 //retrieves video information, or NULL if it's not available
 gboolean gst_binding_load_video_info (gstPlay *play) {
 	if (!isValid (play)) return FALSE;
-
+	
 	GList *stream_info = NULL, *stream;
 	g_object_get (G_OBJECT (play->element), "stream-info", &stream_info, NULL);
 	if (!stream_info) return FALSE;
-
+	
+	/* Initialize video info structure */
+	if (play->video_info == NULL) {
+		play->video_info = g_new0 (gstVideoInfo, 1);
+	}
+	
+	/* Check if audio or video is available */
+	play->video_info->has_video = gst_binding_has_video(play);
+	play->video_info->has_audio = gst_binding_has_audio(play);
+	
+	/* Only check for video details if a video stream is present */
+	if (!play->video_info->has_video)
+		return play->video_info->has_audio;
+	
 	/* Iterate through the streams */
   	for (stream = stream_info; stream; stream = g_list_next (stream)) {
   		GObject *stream_data = G_OBJECT (stream->data);
@@ -457,7 +481,6 @@ gboolean gst_binding_load_video_info (gstPlay *play) {
 			}
 			
 			if ((caps_width != -1) && (caps_height != -1) && (caps_frame_rate != -1)) {
-				play->video_info = g_new0 (gstVideoInfo, 1);
 				play->video_info->width = caps_width;
 				play->video_info->height = caps_height;
 				play->video_info->frame_rate = caps_frame_rate;
diff --git a/src/GnomeSubtitles/Ui/Menus.cs b/src/GnomeSubtitles/Ui/Menus.cs
index 144f4f2..4d2f608 100644
--- a/src/GnomeSubtitles/Ui/Menus.cs
+++ b/src/GnomeSubtitles/Ui/Menus.cs
@@ -474,6 +474,10 @@ public class Menus {
 		SetVideoSensitivity(true);
     	SetViewVideoSubtitlesSensitivity();
     	SetViewVideoActivity(true);
+
+		if (Base.Ui.Video.HasVideo) {
+			AddFrameRateVideoTag(Base.Ui.Video.FrameRate);
+		}
 	}
 
 	private void OnBaseVideoUnloaded () {
diff --git a/src/GnomeSubtitles/Ui/VideoPreview/Player.cs b/src/GnomeSubtitles/Ui/VideoPreview/Player.cs
index ef584ab..fb2116c 100644
--- a/src/GnomeSubtitles/Ui/VideoPreview/Player.cs
+++ b/src/GnomeSubtitles/Ui/VideoPreview/Player.cs
@@ -69,13 +69,24 @@ public class Player {
 	public event PositionChangedEventHandler PositionChanged;
 	public event VideoInfoEventHandler FoundVideoInfo;
 	public event VideoDurationEventHandler FoundDuration;
-	
 
 	/* Properties */
 
+	public MediaStatus State {
+		get { return playbin.CurrentStatus; }
+	}
+
+	public bool HasDuration {
+		get { return playbin.Duration != TimeSpan.Zero; }
+	}
+
 	public TimeSpan Duration {
 		get { return playbin.Duration; }
 	}
+
+	public bool HasVideoInfo {
+		get { return playbin.VideoInfo != null; }
+	}
 	
 	public float AspectRatio {
 		get { return playbin.VideoInfo.AspectRatio; }
@@ -84,6 +95,14 @@ public class Player {
 	public float FrameRate {
 		get { return playbin.VideoInfo.FrameRate; }
 	}
+
+	public bool HasAudio {
+		get { return playbin.VideoInfo.HasAudio; }
+	}
+
+	public bool HasVideo {
+		get { return playbin.VideoInfo.HasVideo; }
+	}
 	
 	public Uri VideoUri {
 		get { return videoUri; }
@@ -94,7 +113,7 @@ public class Player {
 	
 	public void Open (Uri videoUri) {
 		this.videoUri = videoUri;
-	
+
 		/* Load the playbin */
 		playbin.Load(videoUri.AbsoluteUri);
 	}
@@ -174,7 +193,6 @@ public class Player {
 		else
 			position.Start();
 
-
 		if (StateChanged != null)
 			StateChanged(args);
 	}
diff --git a/src/GnomeSubtitles/Ui/VideoPreview/Video.cs b/src/GnomeSubtitles/Ui/VideoPreview/Video.cs
index 47d8baa..4b63c21 100644
--- a/src/GnomeSubtitles/Ui/VideoPreview/Video.cs
+++ b/src/GnomeSubtitles/Ui/VideoPreview/Video.cs
@@ -74,6 +74,18 @@ public class Video {
 	public float FrameRate {
 		get { return player.FrameRate; }
 	}
+
+	public TimeSpan Duration {
+		get { return player.Duration; }
+	}
+
+	public bool HasAudio {
+		get { return (player != null) && (player.HasAudio); }
+	}
+
+	public bool HasVideo {
+		get { return (player != null) && (player.HasVideo); }
+	}
 	
 	/* Public methods */
 	
@@ -192,6 +204,7 @@ public class Video {
 		
 		player.FoundVideoInfo += OnPlayerFoundVideoInfo;
 		player.StateChanged += OnPlayerStateChanged;
+		player.FoundDuration += OnPlayerFoundDuration;
 		player.EndOfStream += OnPlayerEndOfStream;
 		player.Error += OnPlayerError;
 	}
@@ -218,6 +231,19 @@ public class Video {
 			button.Active = false;
 		}		
 	}
+
+	private void handlePlayerLoading () {
+		if (isLoaded || (!isPlayerLoadComplete()))
+			return;
+
+		isLoaded = true;
+		SetControlsSensitivity(true);
+		Base.UpdateFromVideoLoaded(player.VideoUri);
+	}
+
+	private bool isPlayerLoadComplete () {
+		return (player != null) && (player.State != MediaStatus.Unloaded) && (player.HasVideoInfo) && (player.HasDuration);
+	}
 	
 	/* Event members */
 	
@@ -241,17 +267,18 @@ public class Video {
 	}
 	
 	private void OnPlayerFoundVideoInfo (VideoInfoEventArgs args) {
-		Core.Base.Ui.Menus.AddFrameRateVideoTag(player.FrameRate);
+		handlePlayerLoading();
 	}
 	
 	private void OnPlayerStateChanged (StateEventArgs args) {
 		if (args.State == MediaStatus.Loaded) {
-			SetControlsSensitivity(true);
-			isLoaded = true;
-			
-			Base.UpdateFromVideoLoaded(player.VideoUri);
+			handlePlayerLoading();
 		}
 	}
+
+	private void OnPlayerFoundDuration (TimeSpan duration) {
+		handlePlayerLoading();
+	}
 	
 	private void OnPlayerEndOfStream () {
 		ToggleButton playPauseButton = Base.GetWidget(WidgetNames.VideoPlayPauseButton) as ToggleButton;
diff --git a/src/GnomeSubtitles/Ui/VideoPreview/VideoPosition.cs b/src/GnomeSubtitles/Ui/VideoPreview/VideoPosition.cs
index 1ee4eaa..b2d80c8 100644
--- a/src/GnomeSubtitles/Ui/VideoPreview/VideoPosition.cs
+++ b/src/GnomeSubtitles/Ui/VideoPreview/VideoPosition.cs
@@ -119,9 +119,9 @@ public class VideoPosition {
 		UpdatePositionValueLabel(newPosition);
 		EmitVideoPositionChanged(newPosition);
 	}
-	
-	private void OnPlayerFoundDuration (TimeSpan duration) {
-		SetLength(duration);
+
+	private void OnBaseVideoLoaded (Uri videoUri) {
+		SetLength(Base.Ui.Video.Duration);
 		slider.Sensitive = true;
 		ConnectSliderSignals();
 	}
@@ -157,10 +157,10 @@ public class VideoPosition {
 	}
 	
 	private void OnBaseInitFinished () {
-		player.PositionChanged += OnPlayerPositionChanged;
-		player.FoundDuration += OnPlayerFoundDuration;
+		Base.TimingModeChanged += OnBaseTimingModeChanged;		
+		Base.VideoLoaded += OnBaseVideoLoaded;
 
-		Base.TimingModeChanged += OnBaseTimingModeChanged;
+		player.PositionChanged += OnPlayerPositionChanged;
 	}
 	
 	private void OnBaseTimingModeChanged (TimingMode timingMode) {
diff --git a/src/SubLib/IO/Output/VerboseConsole.cs b/src/SubLib/IO/Output/VerboseConsole.cs
index 64b9615..e54914a 100644
--- a/src/SubLib/IO/Output/VerboseConsole.cs
+++ b/src/SubLib/IO/Output/VerboseConsole.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of SubLib.
- * Copyright (C) 2006-2008 Pedro Castro
+ * Copyright (C) 2006-2009 Pedro Castro
  *
  * SubLib is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -31,12 +31,12 @@ internal class VerboseConsole {
 	
 	internal static void Write (string text) {
 		if (verbose)
-			Console.Write(text);
+			Console.Error.Write(text);
 	}
 	
 	internal static void WriteLine (string text) {
 		if (verbose)
-			Console.WriteLine(text);
+			Console.Error.WriteLine(text);
 	}
 
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]