[longomatch] Simplify the IFramesCapturer interface



commit 0650ad551e2f871a03c3a7c15fc8b784651837c9
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sun Sep 7 13:24:23 2014 +0200

    Simplify the IFramesCapturer interface

 .../Interfaces/Multimedia/IFramesCapturer.cs       |    4 +---
 .../Gui/Utils/FramesCapturer.cs                    |    8 ++++----
 LongoMatch.Multimedia/Player/GstPlayer.cs          |   11 +++++++++--
 LongoMatch.Multimedia/Utils/GstDiscoverer.cs       |    4 ++--
 LongoMatch.Services/Services/EventsManager.cs      |   16 ++++++++++++----
 .../Services/RenderingJobsManager.cs               |    6 +++---
 LongoMatch.Services/Services/ToolsManager.cs       |    8 +++-----
 7 files changed, 34 insertions(+), 23 deletions(-)
---
diff --git a/LongoMatch.Core/Interfaces/Multimedia/IFramesCapturer.cs 
b/LongoMatch.Core/Interfaces/Multimedia/IFramesCapturer.cs
index 0515d4f..75cc7bb 100644
--- a/LongoMatch.Core/Interfaces/Multimedia/IFramesCapturer.cs
+++ b/LongoMatch.Core/Interfaces/Multimedia/IFramesCapturer.cs
@@ -30,9 +30,7 @@ namespace LongoMatch.Core.Interfaces.Multimedia
        public interface IFramesCapturer
        {
                bool Open (string uri);
-               bool Seek (Time time, bool accurate);
-               void Pause ();
                void Dispose();
-               Image GetCurrentFrame (int outwidth=-1, int outheight=-1);
+               Image GetFrame (Time pos, bool accurate, int outwidth=-1, int outheight=-1);
        }
 }
diff --git a/LongoMatch.GUI.Multimedia/Gui/Utils/FramesCapturer.cs 
b/LongoMatch.GUI.Multimedia/Gui/Utils/FramesCapturer.cs
index d858939..e7f1d7e 100644
--- a/LongoMatch.GUI.Multimedia/Gui/Utils/FramesCapturer.cs
+++ b/LongoMatch.GUI.Multimedia/Gui/Utils/FramesCapturer.cs
@@ -77,17 +77,16 @@ namespace LongoMatch.Video.Utils
 
                        System.IO.Directory.CreateDirectory(outputDir);
 
-                       pos = start;
+                       pos = new Time {MSeconds = start.MSeconds};
                        if(Progress != null) {
                                Application.Invoke (delegate {
                                        Progress(0,totalFrames,null);
                                });
                        }
+
                        while(pos <= stop) {
                                if(!cancel) {
-                                       capturer.Seek (pos, true);
-                                       capturer.Pause();
-                                       frame = capturer.GetCurrentFrame();
+                                       frame = capturer.GetFrame(pos, true);
                                        if(frame != null) {
                                                frame.Save(System.IO.Path.Combine(outputDir,seriesName+"_" + 
i +".png"));
                                                frame.ScaleInplace(THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT);
@@ -107,6 +106,7 @@ namespace LongoMatch.Video.Utils
                                        break;
                                }
                        }
+                       capturer.Dispose ();
                }
        }
 }
\ No newline at end of file
diff --git a/LongoMatch.Multimedia/Player/GstPlayer.cs b/LongoMatch.Multimedia/Player/GstPlayer.cs
index fc9a4ea..ef55626 100644
--- a/LongoMatch.Multimedia/Player/GstPlayer.cs
+++ b/LongoMatch.Multimedia/Player/GstPlayer.cs
@@ -27,7 +27,7 @@ using LongoMatch.Core.Handlers;
 
 namespace LongoMatch.Video.Player
 {
-       public class GstPlayer : GLib.Object, IPlayer, IFramesCapturer
+       public class GstPlayer : GLib.Object, IPlayer
        {
 
                public event ErrorHandler Error;
@@ -520,11 +520,18 @@ namespace LongoMatch.Video.Player
                }
        }
 
-       public class GstFramesCapturer: GstPlayer
+       public class GstFramesCapturer: GstPlayer , IFramesCapturer
        {
        
                public unsafe GstFramesCapturer () : base (PlayerUseType.Capture)
                {
                }
+               
+               public Image GetFrame (Time pos, bool accurate, int outwidth=-1, int outheight=-1)
+               {
+                       Seek (pos, accurate);
+                       Pause ();
+                       return GetCurrentFrame (outwidth, outheight);
+               }
        }
 }
diff --git a/LongoMatch.Multimedia/Utils/GstDiscoverer.cs b/LongoMatch.Multimedia/Utils/GstDiscoverer.cs
index c03797f..de20db2 100644
--- a/LongoMatch.Multimedia/Utils/GstDiscoverer.cs
+++ b/LongoMatch.Multimedia/Utils/GstDiscoverer.cs
@@ -76,8 +76,8 @@ namespace LongoMatch.Video.Utils
                                        factory = new MultimediaFactory ();
                                        thumbnailer = factory.GetFramesCapturer ();
                                        thumbnailer.Open (filePath);
-                                       thumbnailer.Seek (new Time { Seconds = 2 }, false);
-                                       preview = thumbnailer.GetCurrentFrame (THUMBNAIL_MAX_WIDTH, 
THUMBNAIL_MAX_HEIGHT);
+                                       preview = thumbnailer.GetFrame (new Time { Seconds = 2 }, false,
+                                       THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT);
                                        thumbnailer.Dispose ();
                                }
                        }
diff --git a/LongoMatch.Services/Services/EventsManager.cs b/LongoMatch.Services/Services/EventsManager.cs
index bb4ad8c..197a465 100644
--- a/LongoMatch.Services/Services/EventsManager.cs
+++ b/LongoMatch.Services/Services/EventsManager.cs
@@ -133,6 +133,7 @@ namespace LongoMatch.Services
                {
                        Image pixbuf;
                        FrameDrawing drawing = null;
+                       Time pos;
 
                        player.Pause ();
                        if (play == null) {
@@ -145,9 +146,16 @@ namespace LongoMatch.Services
                                } else {
                                        drawing = play.Drawings [drawingIndex];
                                }
-                               player.Seek (drawing.Render, true);
+                               pos = drawing.Render;
+                       } else {
+                               pos = player.CurrentTime;
+                       }
+
+                       if (framesCapturer != null) {
+                               pixbuf = framesCapturer.GetFrame (pos, true, -1, -1);
+                       } else {
+                               pixbuf = player.CurrentFrame;
                        }
-                       pixbuf = player.CurrentFrame;
                        guiToolkit.DrawingTool (pixbuf, play, drawing);
                }
 
@@ -193,8 +201,8 @@ namespace LongoMatch.Services
                                projectType == ProjectType.URICaptureProject) {
                                frame = capturer.CurrentMiniatureFrame;
                        } else if (projectType == ProjectType.FileProject) {
-                               framesCapturer.Seek (tagtime, true);
-                               frame = player.CurrentMiniatureFrame;
+                               frame = framesCapturer.GetFrame (tagtime, true, Constants.MAX_THUMBNAIL_SIZE,
+                                                                Constants.MAX_THUMBNAIL_SIZE);
                        }
                        return frame;
                }
diff --git a/LongoMatch.Services/Services/RenderingJobsManager.cs 
b/LongoMatch.Services/Services/RenderingJobsManager.cs
index 187883c..24a139d 100644
--- a/LongoMatch.Services/Services/RenderingJobsManager.cs
+++ b/LongoMatch.Services/Services/RenderingJobsManager.cs
@@ -44,7 +44,6 @@ namespace LongoMatch.Services
                        this.guiToolkit = guiToolkit;
                        this.multimediaToolkit = multimediaToolkit; 
                        this.stateBar = guiToolkit.RenderingStateBar;
-                       capturer = multimediaToolkit.GetFramesCapturer ();
                        jobs = new List<Job> ();
                        pendingJobs = new List<Job> ();
                        stateBar.Cancel += (sender, e) => CancelCurrentJob ();
@@ -251,9 +250,10 @@ namespace LongoMatch.Services
                        Image frame, final_image;
                        string path = System.IO.Path.GetTempFileName ().Replace (@"\", @"\\");
                        
+                       capturer = multimediaToolkit.GetFramesCapturer ();
                        capturer.Open (filename);
-                       capturer.Seek (drawing.Render, true);
-                       frame = capturer.GetCurrentFrame ();
+                       frame = capturer.GetFrame (drawing.Render, true);
+                       capturer.Dispose ();
                        final_image = Drawing.Utils.RenderFrameDrawingToImage (Config.DrawingToolkit, frame, 
drawing);
                        final_image.Save (path);
                        return path;
diff --git a/LongoMatch.Services/Services/ToolsManager.cs b/LongoMatch.Services/Services/ToolsManager.cs
index 85260f5..f980bd2 100644
--- a/LongoMatch.Services/Services/ToolsManager.cs
+++ b/LongoMatch.Services/Services/ToolsManager.cs
@@ -125,11 +125,9 @@ namespace LongoMatch.Services
                        capturer.Open (project.Description.File.FilePath);
                        foreach (TimelineEvent play in project.Timeline) {
                                try {
-                                       capturer.Seek (play.Start + ((play.Stop - play.Start) / 2),
-                                                      true);
-                                       play.Miniature = capturer.GetCurrentFrame (
-                                               Constants.MAX_THUMBNAIL_SIZE,
-                                               Constants.MAX_THUMBNAIL_SIZE);
+                                       play.Miniature = capturer.GetFrame (play.Start + ((play.Stop - 
play.Start) / 2),
+                                                                           true, 
Constants.MAX_THUMBNAIL_SIZE,
+                                                                           Constants.MAX_THUMBNAIL_SIZE);
                                        dialog.Pulse ();
 
                                } catch (Exception ex) {


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