[longomatch] Dipose properly the carpturer on error



commit 7892617c5d03545f568453c44af85d8716ae1b79
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sun Jun 6 21:15:23 2010 +0200

    Dipose properly the carpturer on error

 CesarPlayer/Capturer/GstCameraCapturer.cs |   10 ++++++++++
 CesarPlayer/Capturer/ICapturer.cs         |    2 ++
 CesarPlayer/Gui/CapturerBin.cs            |    7 +++++++
 libcesarplayer/src/gst-camera-capturer.c  |    9 ++++++---
 libcesarplayer/src/gst-camera-capturer.h  |    1 +
 5 files changed, 26 insertions(+), 3 deletions(-)
---
diff --git a/CesarPlayer/Capturer/GstCameraCapturer.cs b/CesarPlayer/Capturer/GstCameraCapturer.cs
index d494cec..6807c02 100644
--- a/CesarPlayer/Capturer/GstCameraCapturer.cs
+++ b/CesarPlayer/Capturer/GstCameraCapturer.cs
@@ -413,5 +413,15 @@ namespace LongoMatch.Video.Capturer {
 			LongoMatch.GtkSharp.Capturer.ObjectManager.Initialize ();
 		}
 #endregion
+		
+		[DllImport("libcesarplayer.dll")]
+		static extern IntPtr gst_camera_capturer_finalize(IntPtr raw);
+		
+		public override void Dispose ()
+		{
+			gst_camera_capturer_finalize (Handle);
+			base.Dispose ();
+		}
+
 	}
 }
diff --git a/CesarPlayer/Capturer/ICapturer.cs b/CesarPlayer/Capturer/ICapturer.cs
index 6591745..6eb8573 100644
--- a/CesarPlayer/Capturer/ICapturer.cs
+++ b/CesarPlayer/Capturer/ICapturer.cs
@@ -86,5 +86,7 @@ namespace LongoMatch.Video.Capturer
 		void Run();
 		
 		void Close();
+		
+		void Dispose();
 	}
 }
diff --git a/CesarPlayer/Gui/CapturerBin.cs b/CesarPlayer/Gui/CapturerBin.cs
index bd8489d..df8874c 100644
--- a/CesarPlayer/Gui/CapturerBin.cs
+++ b/CesarPlayer/Gui/CapturerBin.cs
@@ -305,6 +305,13 @@ namespace LongoMatch.Gui
 		{
 			if (Error != null)
 				Error (o, args);
+			/* On error, the capturer is not usable anymore. We reset everything
+			 * setting the fake capturer */
+			if (capturer != null){
+				capturer.Dispose();
+				capturer = null;
+			}
+			Type = CapturerType.FAKE;
 		}
 		
 		protected virtual void OnLogodrawingareaExposeEvent (object o, Gtk.ExposeEventArgs args)
diff --git a/libcesarplayer/src/gst-camera-capturer.c b/libcesarplayer/src/gst-camera-capturer.c
index df17736..37193ca 100644
--- a/libcesarplayer/src/gst-camera-capturer.c
+++ b/libcesarplayer/src/gst-camera-capturer.c
@@ -189,7 +189,7 @@ gst_camera_capturer_init (GstCameraCapturer * object)
   priv->lock = g_mutex_new ();
 }
 
-static void
+void
 gst_camera_capturer_finalize (GObject * object)
 {
   GstCameraCapturer *gcc = (GstCameraCapturer *) object;
@@ -1269,9 +1269,12 @@ gcc_bus_message_cb (GstBus * bus, GstMessage * message, gpointer data)
   switch (msg_type) {
     case GST_MESSAGE_ERROR:
     {
-      gcc_error_msg (gcc, message);
-      if (gcc->priv->main_pipeline)
+      if (gcc->priv->main_pipeline){
+        gst_camera_capturer_stop (gcc);
+        gst_camera_capturer_close(gcc);
         gst_element_set_state (gcc->priv->main_pipeline, GST_STATE_NULL);
+      }
+      gcc_error_msg (gcc, message);
       break;
     }
 
diff --git a/libcesarplayer/src/gst-camera-capturer.h b/libcesarplayer/src/gst-camera-capturer.h
index 3e17566..49412fd 100644
--- a/libcesarplayer/src/gst-camera-capturer.h
+++ b/libcesarplayer/src/gst-camera-capturer.h
@@ -96,6 +96,7 @@ EXPORT GList* gst_camera_capturer_enum_audio_devices (void);
 EXPORT GList* gst_camera_capturer_enum_video_devices (void);
 EXPORT GdkPixbuf* gst_camera_capturer_get_current_frame(GstCameraCapturer *gcc);
 EXPORT void gst_camera_capture_unref_pixbuf (GdkPixbuf * pixbuf);
+EXPORT void gst_camera_capturer_finalize (GObject * object);
 
 G_END_DECLS
 #endif /* _GST_CAMERA_CAPTURER_H_ */



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