[longomatch] Call multimedia callbacks from the main thread
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Call multimedia callbacks from the main thread
- Date: Mon, 28 Jul 2014 13:38:34 +0000 (UTC)
commit f890cfd8213dde3349fddcb5568cfbf1415cc687
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Mon Jul 28 13:58:11 2014 +0200
Call multimedia callbacks from the main thread
LongoMatch.GUI.Helpers/Makefile.am | 2 +-
LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs | 47 ++++++++------
LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs | 71 ++++++++++++--------
.../Gui/Utils/FramesCapturer.cs | 5 +-
LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic | 3 +-
LongoMatch.GUI/gtk-gui/gui.stetic | 1 -
LongoMatch.Multimedia/LongoMatch.Multimedia.mdp | 7 +-
LongoMatch.Multimedia/Makefile.am | 4 +-
LongoMatch.Multimedia/Remuxer/MpegRemuxer.cs | 7 +--
.../Utils/{GtkHelpers.cs => WindowHandle.cs} | 7 +--
10 files changed, 83 insertions(+), 71 deletions(-)
---
diff --git a/LongoMatch.GUI.Helpers/Makefile.am b/LongoMatch.GUI.Helpers/Makefile.am
index b2cb6d7..a846581 100644
--- a/LongoMatch.GUI.Helpers/Makefile.am
+++ b/LongoMatch.GUI.Helpers/Makefile.am
@@ -8,6 +8,6 @@ SOURCES = FileChooserHelper.cs \
MessagesHelpers.cs \
Misc.cs
-RESOURCES =
+RESOURCES =
include $(top_srcdir)/build/build.mk
diff --git a/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs b/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs
index 81686b9..9474881 100644
--- a/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs
+++ b/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs
@@ -281,12 +281,32 @@ namespace LongoMatch.Gui
}
if (type == CapturerType.Live) {
- windowHandle = GtkHelpers.GetWindowHandle (videodrawingarea.GdkWindow);
+ windowHandle = WindowHandle.GetWindowHandle (videodrawingarea.GdkWindow);
}
capturer.Configure (settings, windowHandle);
delayStart = false;
}
+ void DeviceChanged (int deviceID)
+ {
+ string msg;
+ /* device disconnected, pause capture */
+ if (deviceID == -1) {
+ if (Capturing)
+ capturer.TogglePause ();
+ recbutton.Sensitive = false;
+ msg = Catalog.GetString ("Device disconnected. " + "The capture will be
paused");
+ MessagesHelpers.WarningMessage (this, msg);
+ }
+ else {
+ recbutton.Sensitive = true;
+ msg = Catalog.GetString ("Device reconnected." + "Do you want to restart the
capture?");
+ if (MessagesHelpers.QuestionMessage (this, msg, null)) {
+ capturer.TogglePause ();
+ }
+ }
+ }
+
void OnTick(Time ellapsedTime) {
string text = "";
Time duration = new Time (0);
@@ -307,29 +327,16 @@ namespace LongoMatch.Gui
}
void OnError (string message) {
- Config.EventsBroker.EmitCaptureError (message);
+ Application.Invoke (delegate {
+ Config.EventsBroker.EmitCaptureError (message);
+ });
}
void OnDeviceChange(int deviceID)
{
- string msg;
- /* device disconnected, pause capture */
- if(deviceID == -1) {
- if(Capturing)
- capturer.TogglePause();
-
- recbutton.Sensitive = false;
- msg = Catalog.GetString("Device disconnected. " +
- "The capture will be paused");
- MessagesHelpers.WarningMessage (this, msg);
- } else {
- recbutton.Sensitive = true;
- msg = Catalog.GetString("Device reconnected." +
- "Do you want to restart the capture?");
- if (MessagesHelpers.QuestionMessage (this, msg, null)) {
- capturer.TogglePause();
- }
- }
+ Application.Invoke (delegate {
+ DeviceChanged (deviceID);
+ });
}
}
}
diff --git a/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs b/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs
index c2b5870..b627b18 100644
--- a/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs
+++ b/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs
@@ -432,11 +432,10 @@ namespace LongoMatch.Gui
videodrawingarea.DoubleBuffered = false;
player = Config.MultimediaToolkit.GetPlayer ();
- player.Error += Config.EventsBroker.EmitMultimediaError;
+ player.Error += OnError;
player.StateChange += OnStateChanged;
player.Eos += OnEndOfStream;
player.ReadyToSeek += OnReadyToSeek;
-
videoeventbox.ButtonPressEvent += OnVideoboxButtonPressEvent;
videoeventbox.ScrollEvent += OnVideoboxScrollEvent;
videodrawingarea.Realized += HandleRealized;
@@ -454,43 +453,55 @@ namespace LongoMatch.Gui
}
}
- #endregion
-
- #region Callbacks
- void HandleExposeEvent (object sender, ExposeEventArgs args)
+ void StateChanged (bool playing)
{
- player.Expose();
- }
-
- void OnStateChanged(bool playing) {
- if(playing) {
+ if (playing) {
ReconfigureTimeout (20);
- playbutton.Hide();
- pausebutton.Show();
+ playbutton.Hide ();
+ pausebutton.Show ();
}
else {
ReconfigureTimeout (0);
- playbutton.Show();
- pausebutton.Hide();
+ playbutton.Show ();
+ pausebutton.Hide ();
}
- if(PlayStateChanged != null)
- PlayStateChanged(playing);
+ if (PlayStateChanged != null)
+ PlayStateChanged (playing);
}
- void OnReadyToSeek() {
+ void ReadyToSeek ()
+ {
readyToSeek = true;
length = player.StreamLength;
- if(pendingSeek != null) {
- player.Rate = (float) pendingSeek [1];
- player.Seek ((Time)pendingSeek[0], true);
- if ((bool)pendingSeek[2]) {
- Play();
+ if (pendingSeek != null) {
+ player.Rate = (float)pendingSeek [1];
+ player.Seek ((Time)pendingSeek [0], true);
+ if ((bool)pendingSeek [2]) {
+ Play ();
}
pendingSeek = null;
}
OnTick ();
}
+ #endregion
+
+ #region Callbacks
+ void HandleExposeEvent (object sender, ExposeEventArgs args)
+ {
+ player.Expose();
+ }
+
+ void OnStateChanged(bool playing) {
+ Application.Invoke (delegate {
+ StateChanged (playing);});
+ }
+
+ void OnReadyToSeek() {
+ Application.Invoke (delegate {
+ ReadyToSeek ();});
+ }
+
bool OnTick () {
string slength;
Time currentTime;
@@ -593,13 +604,17 @@ namespace LongoMatch.Gui
Pause ();
}
- void OnEndOfStream(object o, EventArgs args) {
- player.Seek (new Time (0), true);
- Pause ();
+ void OnEndOfStream (object o, EventArgs args) {
+ Application.Invoke (delegate {
+ player.Seek (new Time (0), true);
+ Pause ();
+ });
}
void OnError(string message) {
- Config.EventsBroker.EmitMultimediaError (message);
+ Application.Invoke (delegate {
+ Config.EventsBroker.EmitMultimediaError (message);
+ });
}
void OnClosebuttonClicked(object sender, System.EventArgs e)
@@ -690,7 +705,7 @@ namespace LongoMatch.Gui
void HandleRealized (object sender, EventArgs e)
{
- player.WindowHandle = GtkHelpers.GetWindowHandle (videodrawingarea.GdkWindow);
+ player.WindowHandle = WindowHandle.GetWindowHandle (videodrawingarea.GdkWindow);
}
void HandleSeekEvent (SeekType type, Time start, float rate)
diff --git a/LongoMatch.GUI.Multimedia/Gui/Utils/FramesCapturer.cs
b/LongoMatch.GUI.Multimedia/Gui/Utils/FramesCapturer.cs
index 5628e69..5e3b0df 100644
--- a/LongoMatch.GUI.Multimedia/Gui/Utils/FramesCapturer.cs
+++ b/LongoMatch.GUI.Multimedia/Gui/Utils/FramesCapturer.cs
@@ -27,6 +27,7 @@ using LongoMatch.Video;
using LongoMatch.Video.Common;
using LongoMatch.Store;
using LongoMatch.Multimedia.Utils;
+using Gtk;
namespace LongoMatch.Video.Utils
{
@@ -78,7 +79,7 @@ namespace LongoMatch.Video.Utils
pos = start;
if(Progress != null) {
- GtkHelpers.CallFromAppThread (delegate {
+ Application.Invoke (delegate {
Progress(0,totalFrames,null);
});
}
@@ -93,7 +94,7 @@ namespace LongoMatch.Video.Utils
}
if(Progress != null) {
- GtkHelpers.CallFromAppThread (delegate {
+ Application.Invoke (delegate {
Progress(i+1, totalFrames, frame);
});
}
diff --git a/LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic b/LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic
index 2a4f243..fe3495b 100644
--- a/LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic
+++ b/LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic
@@ -5,10 +5,9 @@
<target-gtk-version>2.12</target-gtk-version>
</configuration>
<import>
- <widget-library name="../../bin/LongoMatch.Multimedia.dll" />
<widget-library name="../../bin/LongoMatch.GUI.Helpers.dll" />
- <widget-library name="../../bin/LongoMatch.GUI.Multimedia.dll" internal="true" />
<widget-library name="../../LongoMatch.Drawing.Cairo/bin/Debug/LongoMatch.Drawing.Cairo.dll" />
+ <widget-library name="../../bin/LongoMatch.GUI.Multimedia.dll" internal="true" />
</import>
<widget class="Gtk.Window" id="LongoMatch.Gui.VolumeWindow" design-size="31 204">
<property name="MemberName" />
diff --git a/LongoMatch.GUI/gtk-gui/gui.stetic b/LongoMatch.GUI/gtk-gui/gui.stetic
index 007c139..065015b 100644
--- a/LongoMatch.GUI/gtk-gui/gui.stetic
+++ b/LongoMatch.GUI/gtk-gui/gui.stetic
@@ -6,7 +6,6 @@
</configuration>
<import>
<widget-library name="../../bin/LongoMatch.GUI.Multimedia.dll" />
- <widget-library name="../../bin/LongoMatch.Multimedia.dll" />
<widget-library name="../../bin/LongoMatch.GUI.Helpers.dll" />
<widget-library name="../../LongoMatch.Drawing.Cairo/bin/Debug/LongoMatch.Drawing.Cairo.dll" />
<widget-library name="../../bin/LongoMatch.GUI.dll" internal="true" />
diff --git a/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp b/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp
index edf8883..4e9da09 100644
--- a/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp
+++ b/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp
@@ -51,10 +51,10 @@
<File subtype="Code" buildaction="Compile" name="Utils/Seeker.cs" />
<File subtype="Code" buildaction="Compile" name="Remuxer/MpegRemuxer.cs" />
<File subtype="Code" buildaction="Compile" name="Utils/MultimediaFactory.cs" />
- <File subtype="Code" buildaction="Compile" name="Utils/GtkHelpers.cs" />
<File subtype="Directory" buildaction="Compile" name="Player" />
<File subtype="Code" buildaction="Compile" name="Player/GstPlayer.cs" />
<File subtype="Code" buildaction="Compile" name="Player/ObjectManager.cs" />
+ <File subtype="Code" buildaction="Compile" name="Utils/WindowHandle.cs" />
</Contents>
<References>
<ProjectReference type="Project" localcopy="True" refto="libcesarplayer" />
@@ -62,8 +62,7 @@
<ProjectReference type="Project" localcopy="True" refto="LongoMatch.Core" />
<ProjectReference type="Package" localcopy="True" refto="Mono.Posix, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=0738eb9f132ed756" />
<ProjectReference type="Package" localcopy="True" refto="System, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />
- <ProjectReference type="Package" localcopy="False" refto="gdk-sharp, Version=2.12.0.0, Culture=neutral,
PublicKeyToken=35e10195dab3c99f" />
- <ProjectReference type="Package" localcopy="True" refto="gtk-sharp, Version=2.12.0.0, Culture=neutral,
PublicKeyToken=35e10195dab3c99f" />
<ProjectReference type="Package" specificVersion="False" localcopy="False" refto="System.Core,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ <ProjectReference type="Package" localcopy="False" refto="gdk-sharp, Version=2.12.0.0, Culture=neutral,
PublicKeyToken=35e10195dab3c99f" />
</References>
-</Project>
+</Project>
\ No newline at end of file
diff --git a/LongoMatch.Multimedia/Makefile.am b/LongoMatch.Multimedia/Makefile.am
index fc766e1..229452f 100644
--- a/LongoMatch.Multimedia/Makefile.am
+++ b/LongoMatch.Multimedia/Makefile.am
@@ -20,12 +20,12 @@ SOURCES = Capturer/FakeCapturer.cs \
Remuxer/MpegRemuxer.cs \
Remuxer/ObjectManager.cs \
Utils/GStreamer.cs \
- Utils/GtkHelpers.cs \
Utils/GstDiscoverer.cs \
Utils/MultimediaFactory.cs \
Utils/Seeker.cs \
Utils/TimeString.cs \
- Utils/VideoDevice.cs
+ Utils/VideoDevice.cs \
+ Utils/WindowHandle.cs
DLLCONFIG = LongoMatch.Multimedia.dll.config
diff --git a/LongoMatch.Multimedia/Remuxer/MpegRemuxer.cs b/LongoMatch.Multimedia/Remuxer/MpegRemuxer.cs
index 7555ca9..2cca807 100644
--- a/LongoMatch.Multimedia/Remuxer/MpegRemuxer.cs
+++ b/LongoMatch.Multimedia/Remuxer/MpegRemuxer.cs
@@ -90,16 +90,13 @@ namespace LongoMatch.Video.Remuxer
ret = LaunchRemuxer ();
}
- /* FIXME: not called from main thread */
if (ret != 0) {
if (Error != null) {
- GtkHelpers.CallFromAppThread (delegate {
- Error ("Unkown error");});
+ Error ("Unkown error");
}
} else {
if (Progress != null) {
- GtkHelpers.CallFromAppThread (delegate {
- Progress (1);});
+ Progress (1);
}
}
}
diff --git a/LongoMatch.Multimedia/Utils/GtkHelpers.cs b/LongoMatch.Multimedia/Utils/WindowHandle.cs
similarity index 89%
rename from LongoMatch.Multimedia/Utils/GtkHelpers.cs
rename to LongoMatch.Multimedia/Utils/WindowHandle.cs
index d05738c..755242f 100644
--- a/LongoMatch.Multimedia/Utils/GtkHelpers.cs
+++ b/LongoMatch.Multimedia/Utils/WindowHandle.cs
@@ -17,19 +17,14 @@
//
using System;
using System.Runtime.InteropServices;
-using Gtk;
namespace LongoMatch.Multimedia.Utils
{
- public class GtkHelpers
+ public class WindowHandle
{
[DllImport("libcesarplayer.dll")]
static extern IntPtr lgm_get_window_handle (IntPtr window);
- public static void CallFromAppThread (EventHandler del) {
- Application.Invoke (del);
- }
-
public static IntPtr GetWindowHandle (Gdk.Window window) {
return lgm_get_window_handle (window.Handle);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]