[longomatch] Fix a race in the video window X Bad Window



commit 1e3f4283b7af4bf11df0ab5173aaa7e4f5fc53b5
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sun Sep 7 13:37:11 2014 +0200

    Fix a race in the video window X Bad Window
    
    When listenning to the realized event, the first usage
    of the GdkWindow in the sink happens before the window
    is registered in the X server, resulting in a Bad Window segfault.

 LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs         |   25 ++++++++++++++-----
 LongoMatch.GUI.Multimedia/Gui/VideoWindow.cs       |   17 +++++++++----
 .../gtk-gui/LongoMatch.Gui.PlayerBin.cs            |    1 +
 LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic       |    1 +
 LongoMatch.GUI.Multimedia/gtk-gui/objects.xml      |    8 ++++-
 5 files changed, 38 insertions(+), 14 deletions(-)
---
diff --git a/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs b/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs
index ba6ffa3..ee56787 100644
--- a/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs
+++ b/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs
@@ -59,7 +59,7 @@ namespace LongoMatch.Gui
                Playlist loadedPlaylist;
                Time length, lastTime;
                bool seeking, IsPlayingPrevState, muted, emitRateScale, readyToSeek;
-               bool ignoreTick, stillimageLoaded;
+               bool ignoreTick, stillimageLoaded, delayedOpen;
                MediaFile file;
                double previousVLevel = 1;
                double[] seeksQueue;
@@ -165,7 +165,12 @@ namespace LongoMatch.Gui
                #region Public methods
                public void Open (MediaFile file)
                {
-                       Open (file, true);
+                       if (videowindow.Ready) {
+                               Open (file, true);
+                       } else {
+                               this.file = file;
+                               delayedOpen = true;
+                       }
                }
 
                public void Play ()
@@ -324,12 +329,12 @@ namespace LongoMatch.Gui
                        }
                }
 
-               void Open (MediaFile file, bool seek)
+               void Open (MediaFile file, bool seek, bool force=false)
                {
                        ResetGui ();
                        CloseSegment ();
                        videowindow.Ratio = (float) (file.VideoWidth * file.Par / file.VideoHeight);
-                       if (file != this.file) {
+                       if (file != this.file || force) {
                                readyToSeek = false;
                                this.file = file;
                                try {
@@ -501,7 +506,7 @@ namespace LongoMatch.Gui
                        player.ReadyToSeek += OnReadyToSeek;
                        videowindow.ButtonPressEvent += OnVideoboxButtonPressEvent;
                        videowindow.ScrollEvent += OnVideoboxScrollEvent;
-                       videowindow.Realized += HandleRealized;
+                       videowindow.ReadyEvent += HandleReady;
                        videowindow.ExposeEvent += HandleExposeEvent;
                        videowindow.CanFocus = true;
                }
@@ -793,9 +798,15 @@ namespace LongoMatch.Gui
                        Config.EventsBroker.EmitDrawFrame (null, -1);
                }
 
-               void HandleRealized (object sender, EventArgs e)
+               void HandleReady (object sender, EventArgs e)
                {
-                       player.WindowHandle = WindowHandle.GetWindowHandle (videowindow.Window.GdkWindow);
+                       IntPtr handle = WindowHandle.GetWindowHandle (videowindow.Window.GdkWindow);
+                       player.WindowHandle = handle;
+                       if (delayedOpen) {
+                               Open (file, true, true);
+                               delayedOpen = false;
+                               player.Expose ();
+                       }
                }
 
                void HandleSeekEvent (SeekType type, Time start, float rate)
diff --git a/LongoMatch.GUI.Multimedia/Gui/VideoWindow.cs b/LongoMatch.GUI.Multimedia/Gui/VideoWindow.cs
index 1edb135..936b185 100644
--- a/LongoMatch.GUI.Multimedia/Gui/VideoWindow.cs
+++ b/LongoMatch.GUI.Multimedia/Gui/VideoWindow.cs
@@ -24,7 +24,7 @@ namespace LongoMatch.Gui
        public partial class VideoWindow : Gtk.Bin
        {
                AspectFrame frame;
-               public new event EventHandler Realized;
+               public new event EventHandler ReadyEvent;
                public new event ExposeEventHandler ExposeEvent;
                public new event ButtonPressEventHandler ButtonPressEvent;
                public new event ScrollEventHandler ScrollEvent;
@@ -37,7 +37,6 @@ namespace LongoMatch.Gui
 
                        Window = new DrawingArea ();
                        Window.DoubleBuffered = false;
-                       Window.Realized += HandleRealized;
                        Window.ExposeEvent += HandleExposeEvent;
                        videoeventbox.ButtonPressEvent += HandleButtonPressEvent;
                        videoeventbox.ScrollEvent += HandleScrollEvent;
@@ -48,6 +47,11 @@ namespace LongoMatch.Gui
                        ShowAll ();
                }
 
+               public bool Ready {
+                       get;
+                       set;
+               }
+
                void HandleScrollEvent (object o, ScrollEventArgs args)
                {
                        if (ScrollEvent != null) {
@@ -58,6 +62,12 @@ namespace LongoMatch.Gui
 
                void HandleExposeEvent (object o, ExposeEventArgs args)
                {
+                       if (!Ready) {
+                               if (ReadyEvent != null) {
+                                       ReadyEvent (o, null);
+                               }
+                               Ready = true;
+                       }
                        if (ExposeEvent != null) {
                                ExposeEvent (o, args);
                        }
@@ -72,9 +82,6 @@ namespace LongoMatch.Gui
 
                void HandleRealized (object sender, EventArgs e)
                {
-                       if (Realized != null) {
-                               Realized (sender, e);
-                       }
                        
                }
                
diff --git a/LongoMatch.GUI.Multimedia/gtk-gui/LongoMatch.Gui.PlayerBin.cs 
b/LongoMatch.GUI.Multimedia/gtk-gui/LongoMatch.Gui.PlayerBin.cs
index 405c498..093d418 100644
--- a/LongoMatch.GUI.Multimedia/gtk-gui/LongoMatch.Gui.PlayerBin.cs
+++ b/LongoMatch.GUI.Multimedia/gtk-gui/LongoMatch.Gui.PlayerBin.cs
@@ -60,6 +60,7 @@ namespace LongoMatch.Gui
                        this.videowindow = new global::LongoMatch.Gui.VideoWindow ();
                        this.videowindow.Events = ((global::Gdk.EventMask)(256));
                        this.videowindow.Name = "videowindow";
+                       this.videowindow.Ready = false;
                        this.hbox2.Add (this.videowindow);
                        global::Gtk.Box.BoxChild w1 = ((global::Gtk.Box.BoxChild)(this.hbox2 
[this.videowindow]));
                        w1.Position = 0;
diff --git a/LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic b/LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic
index 2283d20..a1b28c6 100644
--- a/LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic
+++ b/LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic
@@ -99,6 +99,7 @@
                           <widget class="LongoMatch.Gui.VideoWindow" id="videowindow">
                             <property name="MemberName" />
                             <property name="Events">ButtonPressMask</property>
+                            <property name="Ready">False</property>
                           </widget>
                           <packing>
                             <property name="Position">0</property>
diff --git a/LongoMatch.GUI.Multimedia/gtk-gui/objects.xml b/LongoMatch.GUI.Multimedia/gtk-gui/objects.xml
index 8d87d61..b8d3ed6 100644
--- a/LongoMatch.GUI.Multimedia/gtk-gui/objects.xml
+++ b/LongoMatch.GUI.Multimedia/gtk-gui/objects.xml
@@ -33,13 +33,17 @@
     </signals>
   </object>
   <object type="LongoMatch.Gui.VideoWindow" palette-category="General" allow-children="false" 
base-type="Gtk.Bin">
-    <itemgroups />
+    <itemgroups>
+      <itemgroup label="VideoWindow Properties">
+        <property name="Ready" />
+      </itemgroup>
+    </itemgroups>
     <signals>
       <itemgroup label="VideoWindow Signals">
-        <signal name="Realized" />
         <signal name="ExposeEvent" />
         <signal name="ButtonPressEvent" />
         <signal name="ScrollEvent" />
+        <signal name="ReadyEvent" />
       </itemgroup>
     </signals>
   </object>


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