[longomatch] Add a new IViewPort interface



commit 337591b8baccc11d163de4e73f9a422a6a9ef4e3
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Mon Mar 30 14:22:44 2015 +0200

    Add a new IViewPort interface

 LongoMatch.Core/Handlers/Multimedia.cs             |    1 -
 .../Interfaces/GUI/IViewPort.cs                    |   23 +++---
 LongoMatch.Core/Interfaces/IPlayerController.cs    |   14 ++--
 LongoMatch.Core/Interfaces/Multimedia/IPlayer.cs   |   11 ++--
 LongoMatch.Core/LongoMatch.Core.csproj             |    1 +
 LongoMatch.Core/Makefile.am                        |    1 +
 LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs       |    2 +-
 LongoMatch.GUI.Multimedia/Gui/PlayerView.cs        |    9 +--
 LongoMatch.GUI.Multimedia/Gui/VideoWindow.cs       |   71 +++++++++++++-------
 .../gtk-gui/LongoMatch.Gui.VideoWindow.cs          |   12 ++--
 LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic       |    4 +-
 LongoMatch.GUI.Multimedia/gtk-gui/objects.xml      |    2 +
 LongoMatch.Multimedia/LongoMatch.Multimedia.csproj |    1 -
 LongoMatch.Multimedia/Makefile.am                  |    3 +-
 LongoMatch.Services/Services/PlayerController.cs   |   54 ++++-----------
 Tests/Services/TestPlayerController.cs             |   24 ++++---
 16 files changed, 114 insertions(+), 119 deletions(-)
---
diff --git a/LongoMatch.Core/Handlers/Multimedia.cs b/LongoMatch.Core/Handlers/Multimedia.cs
index 6cc0b38..1613ad1 100644
--- a/LongoMatch.Core/Handlers/Multimedia.cs
+++ b/LongoMatch.Core/Handlers/Multimedia.cs
@@ -46,7 +46,6 @@ namespace LongoMatch.Core.Handlers
        public delegate void MediaInfoHandler (int width,int height,int parN,int parD);
        public delegate void LoadDrawingsHandler (FrameDrawing frameDrawing);
        public delegate void ElementLoadedHandler (object element,bool hasNext);
-       public delegate void PARChangedHandler (IntPtr windowHandle,float par);
        public delegate void MediaFileSetLoadedHandler (MediaFileSet fileset,List<int> camerasVisible = null);
 
        public delegate void ErrorHandler (object sender,string message);
diff --git a/LongoMatch.Multimedia/Utils/WindowHandle.cs b/LongoMatch.Core/Interfaces/GUI/IViewPort.cs
similarity index 67%
rename from LongoMatch.Multimedia/Utils/WindowHandle.cs
rename to LongoMatch.Core/Interfaces/GUI/IViewPort.cs
index b51665f..d9f6f54 100644
--- a/LongoMatch.Multimedia/Utils/WindowHandle.cs
+++ b/LongoMatch.Core/Interfaces/GUI/IViewPort.cs
@@ -1,5 +1,5 @@
-//
-//  Copyright (C) 2014 Andoni Morales Alastruey
+//
+//  Copyright (C) 2015 Fluendo S.A.
 //
 //  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
@@ -16,19 +16,20 @@
 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 //
 using System;
-using System.Runtime.InteropServices;
 
-namespace LongoMatch.Multimedia.Utils
+namespace LongoMatch.Core.Interfaces.GUI
 {
-       public class WindowHandle
+       public interface IViewPort
        {
-               [DllImport ("libcesarplayer.dll")]
-               static extern IntPtr lgm_get_window_handle (IntPtr window);
+               float Ratio { set; get; }
+
+               IntPtr WindowHandle { get; }
+
+               string Message { set; }
+
+               bool MessageVisible { set; }
 
-               public static IntPtr GetWindowHandle (Gdk.Window window)
-               {
-                       return lgm_get_window_handle (window.Handle);
-               }
+               bool Visible { get; set; }
        }
 }
 
diff --git a/LongoMatch.Core/Interfaces/IPlayerController.cs b/LongoMatch.Core/Interfaces/IPlayerController.cs
index 8ddfb66..83ec057 100644
--- a/LongoMatch.Core/Interfaces/IPlayerController.cs
+++ b/LongoMatch.Core/Interfaces/IPlayerController.cs
@@ -16,12 +16,13 @@
 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 //
 using System;
-using LongoMatch.Core.Store;
-using LongoMatch.Core.Handlers;
-using LongoMatch.Core.Common;
 using System.Collections.Generic;
-using LongoMatch.Core.Store.Playlists;
+using LongoMatch.Core.Common;
+using LongoMatch.Core.Handlers;
+using LongoMatch.Core.Interfaces.GUI;
 using LongoMatch.Core.Interfaces.Multimedia;
+using LongoMatch.Core.Store;
+using LongoMatch.Core.Store.Playlists;
 
 
 namespace LongoMatch.Core.Interfaces
@@ -35,7 +36,6 @@ namespace LongoMatch.Core.Interfaces
                event PlaybackRateChangedHandler PlaybackRateChangedEvent;
                event VolumeChangedHandler VolumeChangedEvent;
                event ElementLoadedHandler ElementLoadedEvent;
-               event PARChangedHandler PARChangedEvent;
                event MediaFileSetLoadedHandler MediaFileSetLoadedEvent;
 
                /// <summary>
@@ -81,9 +81,9 @@ namespace LongoMatch.Core.Interfaces
                List<int> CamerasVisible { get; set; }
 
                /// <summary>
-               /// List of window handles set by the view as view ports.
+               /// List of view ports set by the view.
                /// </summary>
-               List<IntPtr> WindowHandles { set; }
+               List<IViewPort> ViewPorts { set; }
 
                /// <summary>
                /// Open the specified fileSet.
diff --git a/LongoMatch.Core/Interfaces/Multimedia/IPlayer.cs 
b/LongoMatch.Core/Interfaces/Multimedia/IPlayer.cs
index 27d8f36..5bbfefd 100644
--- a/LongoMatch.Core/Interfaces/Multimedia/IPlayer.cs
+++ b/LongoMatch.Core/Interfaces/Multimedia/IPlayer.cs
@@ -67,11 +67,6 @@ namespace LongoMatch.Core.Interfaces.Multimedia
                double Rate { get; set; }
 
                /// <summary>
-               /// Sets the window handle in when the video sink can draw.
-               /// </summary>
-               IntPtr WindowHandle { set; }
-
-               /// <summary>
                /// Starts playing.
                /// </summary>
                void Play ();
@@ -121,6 +116,11 @@ namespace LongoMatch.Core.Interfaces.Multimedia
                event ReadyToSeekHandler ReadyToSeek;
 
                /// <summary>
+               /// Sets the window handle in when the video sink can draw.
+               /// </summary>
+               IntPtr WindowHandle { set; }
+
+               /// <summary>
                /// Closes the opened media file.
                /// </summary>
                void Close ();
@@ -149,6 +149,7 @@ namespace LongoMatch.Core.Interfaces.Multimedia
 
        public interface IMultiPlayer: IPlayer
        {
+
                /// <summary>
                /// Open a set of media files.
                /// </summary>
diff --git a/LongoMatch.Core/LongoMatch.Core.csproj b/LongoMatch.Core/LongoMatch.Core.csproj
index d403266..df3479f 100644
--- a/LongoMatch.Core/LongoMatch.Core.csproj
+++ b/LongoMatch.Core/LongoMatch.Core.csproj
@@ -143,6 +143,7 @@
     <Compile Include="..\AssemblyInfo\AssemblyInfo.cs">
       <Link>AssemblyInfo.cs</Link>
     </Compile>
+    <Compile Include="Interfaces\GUI\IViewPort.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Common\" />
diff --git a/LongoMatch.Core/Makefile.am b/LongoMatch.Core/Makefile.am
index 0f05682..01dd3b5 100644
--- a/LongoMatch.Core/Makefile.am
+++ b/LongoMatch.Core/Makefile.am
@@ -47,6 +47,7 @@ SOURCES = ../AssemblyInfo/AssemblyInfo.cs \
        Interfaces/GUI/IPanel.cs \
        Interfaces/GUI/IPlayerView.cs \
        Interfaces/GUI/IRenderingStateBar.cs \
+       Interfaces/GUI/IViewPort.cs \
        Interfaces/IDataBaseManager.cs \
        Interfaces/IDatabase.cs \
        Interfaces/IIDObject.cs \
diff --git a/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs b/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs
index 5c393aa..abeb66a 100644
--- a/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs
+++ b/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs
@@ -410,7 +410,7 @@ namespace LongoMatch.Gui
                        if (muxer == VideoMuxerType.Avi || muxer == VideoMuxerType.Mp4) {
                                settings.EncodingSettings.EncodingProfile.Muxer = VideoMuxerType.Matroska;
                        }
-                       windowHandle = WindowHandle.GetWindowHandle (videowindow.Window.GdkWindow);
+                       windowHandle = videowindow.WindowHandle;
                        Capturer.Configure (settings, windowHandle); 
                        settings.EncodingSettings.EncodingProfile.Muxer = muxer;
                        delayStart = false;
diff --git a/LongoMatch.GUI.Multimedia/Gui/PlayerView.cs b/LongoMatch.GUI.Multimedia/Gui/PlayerView.cs
index 02e101f..e1ebf78 100644
--- a/LongoMatch.GUI.Multimedia/Gui/PlayerView.cs
+++ b/LongoMatch.GUI.Multimedia/Gui/PlayerView.cs
@@ -132,7 +132,6 @@ namespace LongoMatch.Gui
                                player = value;
                                player.ElementLoadedEvent += HandleElementLoadedEvent;
                                player.LoadDrawingsEvent += HandleLoadDrawingsEvent;
-                               player.PARChangedEvent += HandlePARChangedEvent;
                                player.PlaybackRateChangedEvent += HandlePlaybackRateChangedEvent;
                                player.PlaybackStateChangedEvent += HandlePlaybackStateChangedEvent;
                                player.TimeChangedEvent += HandleTimeChangedEvent;
@@ -328,11 +327,6 @@ namespace LongoMatch.Gui
                        ignoreRate = false;
                }
 
-               void HandlePARChangedEvent (IntPtr windowHandle, float par)
-               {
-                       videowindow.Ratio = par;
-               }
-
                void HandleLoadDrawingsEvent (FrameDrawing frameDrawing)
                {
                        if (frameDrawing != null) {
@@ -537,8 +531,7 @@ namespace LongoMatch.Gui
 
                void HandleReady (object sender, EventArgs e)
                {
-                       IntPtr handle = WindowHandle.GetWindowHandle (videowindow.Window.GdkWindow);
-                       Player.WindowHandle = handle;
+                       Player.ViewPorts = new List<IViewPort> { videowindow };
                        Player.Ready ();
                }
 
diff --git a/LongoMatch.GUI.Multimedia/Gui/VideoWindow.cs b/LongoMatch.GUI.Multimedia/Gui/VideoWindow.cs
index bbe481c..872d74c 100644
--- a/LongoMatch.GUI.Multimedia/Gui/VideoWindow.cs
+++ b/LongoMatch.GUI.Multimedia/Gui/VideoWindow.cs
@@ -16,14 +16,17 @@
 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 //
 using System;
+using System.Runtime.InteropServices;
 using Gtk;
+using LongoMatch.Core.Interfaces.GUI;
 
 namespace LongoMatch.Gui
 {
        [System.ComponentModel.ToolboxItem (true)]
-       public partial class VideoWindow : Gtk.Bin
+       public partial class VideoWindow : Gtk.Bin, IViewPort
        {
                AspectFrame frame;
+               DrawingArea drawingWindow;
 
                public event EventHandler ReadyEvent;
                public new event ExposeEventHandler ExposeEvent;
@@ -36,10 +39,10 @@ namespace LongoMatch.Gui
                        frame = new AspectFrame (null, 0.5f, 0.5f, 1f, false);
                        frame.Shadow = ShadowType.None;
 
-                       disabledtext.NoShowAll = true;
-                       Window = new DrawingArea ();
-                       Window.DoubleBuffered = false;
-                       Window.ExposeEvent += HandleExposeEvent;
+                       messageLabel.NoShowAll = true;
+                       drawingWindow = new DrawingArea ();
+                       drawingWindow.DoubleBuffered = false;
+                       drawingWindow.ExposeEvent += HandleExposeEvent;
                        videoeventbox.ButtonPressEvent += HandleButtonPressEvent;
                        videoeventbox.ScrollEvent += HandleScrollEvent;
                        videoeventbox.BorderWidth = 0;
@@ -47,18 +50,46 @@ namespace LongoMatch.Gui
                                // Workaround for GTK bugs on Windows not showing the video window
                                videoeventbox.VisibilityNotifyEvent += HandleVisibilityNotifyEvent;
                        }
-                       frame.Add (Window);
+                       frame.Add (drawingWindow);
                        videoeventbox.Add (frame);
                        videoeventbox.ShowAll ();
-                       Enabled = true;
+                       MessageVisible = false;
                }
 
                void HandleVisibilityNotifyEvent (object o, VisibilityNotifyEventArgs args)
                {
-                       if (videoeventbox.Visible && Window.GdkWindow != null) {
+                       if (videoeventbox.Visible && drawingWindow.GdkWindow != null) {
                                // Hack for Windows. Force video window visibility as
                                // EventBox window's might prevent it to be mapped again.
-                               Window.GdkWindow.Show ();
+                               drawingWindow.GdkWindow.Show ();
+                       }
+               }
+
+               public IntPtr WindowHandle {
+                       get {
+                               return GetWindowHandle (drawingWindow.GdkWindow);
+                       }
+               }
+
+               public string Message {
+                       set {
+                               messageLabel.Text = value;
+                       }
+               }
+
+               public bool MessageVisible {
+                       set {
+                               videoeventbox.Visible = !value;
+                               messageLabel.Visible = value;
+                       }
+               }
+
+               public float Ratio {
+                       set {
+                               frame.Ratio = value;
+                       }
+                       get {
+                               return frame.Ratio;
                        }
                }
 
@@ -78,10 +109,10 @@ namespace LongoMatch.Gui
                void HandleExposeEvent (object o, ExposeEventArgs args)
                {
                        if (!Ready) {
+                               Ready = true;
                                if (ReadyEvent != null) {
                                        ReadyEvent (this, null);
                                }
-                               Ready = true;
                        }
                        if (ExposeEvent != null) {
                                ExposeEvent (this, args);
@@ -100,22 +131,12 @@ namespace LongoMatch.Gui
                        
                }
 
-               public DrawingArea Window {
-                       get;
-                       protected set;
-               }
+               [DllImport ("libcesarplayer.dll")]
+               static extern IntPtr lgm_get_window_handle (IntPtr window);
 
-               public float Ratio {
-                       set {
-                               frame.Ratio = value;
-                       }
-               }
-
-               public bool Enabled {
-                       set {
-                               videoeventbox.Visible = value;
-                               disabledtext.Visible = !value;
-                       }
+               IntPtr GetWindowHandle (Gdk.Window window)
+               {
+                       return lgm_get_window_handle (window.Handle);
                }
        }
 }
diff --git a/LongoMatch.GUI.Multimedia/gtk-gui/LongoMatch.Gui.VideoWindow.cs 
b/LongoMatch.GUI.Multimedia/gtk-gui/LongoMatch.Gui.VideoWindow.cs
index 5b13d1f..44a72c0 100644
--- a/LongoMatch.GUI.Multimedia/gtk-gui/LongoMatch.Gui.VideoWindow.cs
+++ b/LongoMatch.GUI.Multimedia/gtk-gui/LongoMatch.Gui.VideoWindow.cs
@@ -8,7 +8,7 @@ namespace LongoMatch.Gui
                
                private global::Gtk.EventBox videoeventbox;
                
-               private global::Gtk.Label disabledtext;
+               private global::Gtk.Label messageLabel;
 
                protected virtual void Build ()
                {
@@ -26,11 +26,11 @@ namespace LongoMatch.Gui
                        global::Gtk.Box.BoxChild w1 = ((global::Gtk.Box.BoxChild)(this.totalbox 
[this.videoeventbox]));
                        w1.Position = 0;
                        // Container child totalbox.Gtk.Box+BoxChild
-                       this.disabledtext = new global::Gtk.Label ();
-                       this.disabledtext.Name = "disabledtext";
-                       this.disabledtext.LabelProp = global::Mono.Unix.Catalog.GetString ("Unavailable");
-                       this.totalbox.Add (this.disabledtext);
-                       global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(this.totalbox 
[this.disabledtext]));
+                       this.messageLabel = new global::Gtk.Label ();
+                       this.messageLabel.Name = "messageLabel";
+                       this.messageLabel.LabelProp = "Message label";
+                       this.totalbox.Add (this.messageLabel);
+                       global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(this.totalbox 
[this.messageLabel]));
                        w2.Position = 1;
                        this.Add (this.totalbox);
                        if ((this.Child != null)) {
diff --git a/LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic b/LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic
index 2fc8d1f..7a3b51b 100644
--- a/LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic
+++ b/LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic
@@ -913,9 +913,9 @@
           </packing>
         </child>
         <child>
-          <widget class="Gtk.Label" id="disabledtext">
+          <widget class="Gtk.Label" id="messageLabel">
             <property name="MemberName" />
-            <property name="LabelProp" translatable="yes">Unavailable</property>
+            <property name="LabelProp">Message label</property>
           </widget>
           <packing>
             <property name="Position">1</property>
diff --git a/LongoMatch.GUI.Multimedia/gtk-gui/objects.xml b/LongoMatch.GUI.Multimedia/gtk-gui/objects.xml
index 7441513..98ea6dc 100644
--- a/LongoMatch.GUI.Multimedia/gtk-gui/objects.xml
+++ b/LongoMatch.GUI.Multimedia/gtk-gui/objects.xml
@@ -17,6 +17,8 @@
     <itemgroups>
       <itemgroup label="VideoWindow Properties">
         <property name="Ready" />
+        <property name="Visible" />
+        <property name="Ratio" />
       </itemgroup>
     </itemgroups>
     <signals>
diff --git a/LongoMatch.Multimedia/LongoMatch.Multimedia.csproj 
b/LongoMatch.Multimedia/LongoMatch.Multimedia.csproj
index adc6564..bd087b5 100644
--- a/LongoMatch.Multimedia/LongoMatch.Multimedia.csproj
+++ b/LongoMatch.Multimedia/LongoMatch.Multimedia.csproj
@@ -47,7 +47,6 @@
     <Compile Include="Utils\MultimediaFactory.cs" />
     <Compile Include="Player\GstPlayer.cs" />
     <Compile Include="Player\ObjectManager.cs" />
-    <Compile Include="Utils\WindowHandle.cs" />
     <Compile Include="Utils\Devices.cs" />
     <Compile Include="..\AssemblyInfo\AssemblyInfo.cs">
       <Link>AssemblyInfo.cs</Link>
diff --git a/LongoMatch.Multimedia/Makefile.am b/LongoMatch.Multimedia/Makefile.am
index b37d293..554d5d2 100644
--- a/LongoMatch.Multimedia/Makefile.am
+++ b/LongoMatch.Multimedia/Makefile.am
@@ -23,8 +23,7 @@ SOURCES = ../AssemblyInfo/AssemblyInfo.cs \
        Utils/GStreamer.cs \
        Utils/GstDiscoverer.cs \
        Utils/MultimediaFactory.cs \
-       Utils/TimeString.cs \
-       Utils/WindowHandle.cs
+       Utils/TimeString.cs
 
 DLLCONFIG = LongoMatch.Multimedia.dll.config
 
diff --git a/LongoMatch.Services/Services/PlayerController.cs 
b/LongoMatch.Services/Services/PlayerController.cs
index c511432..8b35821 100644
--- a/LongoMatch.Services/Services/PlayerController.cs
+++ b/LongoMatch.Services/Services/PlayerController.cs
@@ -22,11 +22,12 @@ using System.Threading;
 using LongoMatch.Core.Common;
 using LongoMatch.Core.Handlers;
 using LongoMatch.Core.Interfaces;
+using LongoMatch.Core.Interfaces.GUI;
 using LongoMatch.Core.Interfaces.Multimedia;
 using LongoMatch.Core.Store;
 using LongoMatch.Core.Store.Playlists;
-using Timer = System.Threading.Timer;
 using Mono.Unix;
+using Timer = System.Threading.Timer;
 
 namespace LongoMatch.Services
 {
@@ -38,7 +39,6 @@ namespace LongoMatch.Services
                public event PlaybackRateChangedHandler PlaybackRateChangedEvent;
                public event VolumeChangedHandler VolumeChangedEvent;
                public event ElementLoadedHandler ElementLoadedEvent;
-               public event PARChangedHandler PARChangedEvent;
                public event MediaFileSetLoadedHandler MediaFileSetLoadedEvent;
 
                const int TIMEOUT_MS = 20;
@@ -49,7 +49,7 @@ namespace LongoMatch.Services
                TimelineEvent loadedEvent;
                IPlaylistElement loadedPlaylistElement;
                Playlist loadedPlaylist;
-               List<IntPtr> windowHandles;
+               List<IViewPort> viewPorts;
                List<int> camerasVisible;
 
                Time streamLength, videoTS, imageLoadedTS;
@@ -125,29 +125,19 @@ namespace LongoMatch.Services
                        set;
                }
 
-               public List<IntPtr> WindowHandles {
+               public List<IViewPort> ViewPorts {
                        set {
                                if (value != null) {
                                        if (multiPlayer == null) {
-                                               player.WindowHandle = value [0];
+                                               player.WindowHandle = value [0].WindowHandle;
                                        } else {
-                                               multiPlayer.WindowHandles = value;
+                                               multiPlayer.WindowHandles = value.Select (v => 
v.WindowHandle).ToList ();
                                        }
                                }
-                               windowHandles = value;
+                               viewPorts = value;
                        }
                        protected get {
-                               return windowHandles;
-                       }
-               }
-
-               public IntPtr WindowHandle {
-                       set {
-                               WindowHandles = new List<IntPtr> { value };
-                               player.WindowHandle = value;
-                       }
-                       get {
-                               return WindowHandles [0];
+                               return viewPorts;
                        }
                }
 
@@ -555,13 +545,6 @@ namespace LongoMatch.Services
                        }
                }
 
-               void EmitPARChanged (IntPtr windowHandle, float par)
-               {
-                       if (PARChangedEvent != null) {
-                               PARChangedEvent (windowHandle, par);
-                       }
-               }
-
                void EmitPlaybackStateChanged (object sender, bool playing)
                {
                        if (PlaybackStateChangedEvent != null) {
@@ -643,21 +626,14 @@ namespace LongoMatch.Services
 
                void UpdatePar ()
                {
-                       foreach (int index in CamerasVisible) {
-                               try {
-                                       MediaFile file = FileSet [index];
-                                       IntPtr windowHandle = WindowHandles [index];
-                                       if (file.VideoHeight != 0) {
-                                               EmitPARChanged (windowHandle, (float)(file.VideoWidth * 
file.Par / file.VideoHeight));
-                                       } else {
-                                               EmitPARChanged (windowHandle, 1);
-                                       }
-                               } catch (Exception ex) {
-                                       Config.EventsBroker.EmitMultimediaError (this, Catalog.GetString 
("Invalid camera configuration"));
-                                       FileSet = null;
-                                       Log.Exception (ex);
-                                       return;
+                       for (int i = 0; i < Math.Min (CamerasVisible.Count, ViewPorts.Count); i++) {
+                               int index = CamerasVisible [i];
+                               MediaFile file = FileSet [index];
+                               float par = 1;
+                               if (file.VideoHeight != 0) {
+                                       par = (float)(file.VideoWidth * file.Par / file.VideoHeight);
                                }
+                               ViewPorts [i].Ratio = par;
                        }
                }
 
diff --git a/Tests/Services/TestPlayerController.cs b/Tests/Services/TestPlayerController.cs
index 7a81e8d..6f674ed 100644
--- a/Tests/Services/TestPlayerController.cs
+++ b/Tests/Services/TestPlayerController.cs
@@ -33,6 +33,7 @@ namespace Tests.Services
        public class TestPlayerController
        {
                Mock<IPlayer> playerMock;
+               Mock<IViewPort> viewPortMock;
                MediaFileSet mfs;
                PlayerController player;
                Time currentTime, streamLength;
@@ -79,6 +80,7 @@ namespace Tests.Services
                [SetUp ()]
                public void Setup ()
                {
+                       currentTime = new Time (0);
                        playerMock.ResetCalls ();
                        player = new PlayerController ();
                        playlist.SetActive (playlist.Elements [0]);
@@ -94,7 +96,9 @@ namespace Tests.Services
                void PreparePlayer (bool readyToSeek = true)
                {
                        player.CamerasVisible = new List<int> { 0, 1 };
-                       player.WindowHandles = new List<IntPtr> { IntPtr.Zero, IntPtr.Zero };
+                       viewPortMock = new Mock <IViewPort> ();
+                       viewPortMock.SetupAllProperties ();
+                       player.ViewPorts = new List<IViewPort> { viewPortMock.Object, viewPortMock.Object };
                        player.Ready ();
                        player.Open (mfs);
                        if (readyToSeek) {
@@ -162,16 +166,11 @@ namespace Tests.Services
                [Test ()]
                public void Open ()
                {
-                       float par = 0;
-                       int parCount = 0, timeCount = 0;
+                       int timeCount = 0;
                        bool multimediaError = false;
                        Time curTime = null, duration = null;
                        MediaFileSet fileSet = null;
 
-                       player.PARChangedEvent += (w, p) => {
-                               par = p;
-                               parCount++;
-                       };
                        player.TimeChangedEvent += (c, d, seekable) => {
                                curTime = c;
                                duration = d;
@@ -205,9 +204,8 @@ namespace Tests.Services
                        playerMock.Verify (p => p.Open (mfs [0]), Times.Once ());
                        playerMock.Verify (p => p.Play (), Times.Never ());
                        playerMock.Verify (p => p.Seek (new Time (0), true, false), Times.Once ());
-                       Assert.AreEqual (2, parCount);
                        Assert.AreEqual (2, timeCount);
-                       Assert.AreEqual ((float)320 / 240, par);
+                       Assert.AreEqual ((float)320 / 240, viewPortMock.Object.Ratio);
                        Assert.AreEqual (streamLength, duration);
                        Assert.AreEqual (new Time (0), curTime);
                        Assert.AreEqual (fileSet, mfs);
@@ -581,7 +579,9 @@ namespace Tests.Services
                        };
 
                        player.CamerasVisible = new List<int> { 1, 0 };
-                       player.WindowHandles = new List<IntPtr> { IntPtr.Zero, IntPtr.Zero };
+                       viewPortMock = new Mock <IViewPort> ();
+                       viewPortMock.SetupAllProperties ();
+                       player.ViewPorts = new List<IViewPort> { viewPortMock.Object, viewPortMock.Object };
                        player.Ready ();
                        player.LoadEvent (mfs, evt2, evt2.Start, true);
                        // Only valid cameras should be visible although no fileset was opened.
@@ -609,7 +609,9 @@ namespace Tests.Services
 
                        /* Not ready to seek */
                        player.CamerasVisible = new List<int> { 0, 1 };
-                       player.WindowHandles = new List<IntPtr> { IntPtr.Zero, IntPtr.Zero };
+                       viewPortMock = new Mock <IViewPort> ();
+                       viewPortMock.SetupAllProperties ();
+                       player.ViewPorts = new List<IViewPort> { viewPortMock.Object, viewPortMock.Object };
                        player.Ready ();
                        Assert.IsNull (player.FileSet);
                        player.LoadEvent (mfs, evt, evt.Start, true);


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