summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorJulien Moutte <julien@moutte.net>2005-11-27 18:12:23 +0000
committerJulien Moutte <julien@moutte.net>2005-11-27 18:12:23 +0000
commit532bb2e6056d039b4b1f29ab02038d9f217e12c6 (patch)
tree2b75801e3ff39a1aef0f1c7608e55c16a39d5592 /sys
parent56c6518c556717bd0c3d54ffbb0fe67ecba6cf2f (diff)
sys/ximage/ximagesink.c: Fixed a tricky race.
Original commit message from CVS: 2005-11-27 Julien MOUTTE <julien@moutte.net> * sys/ximage/ximagesink.c: (gst_ximage_buffer_free), (gst_ximagesink_ximage_new), (gst_ximagesink_ximage_put), (gst_ximagesink_bufferpool_clear), (gst_ximagesink_buffer_alloc), (gst_ximagesink_expose): Fixed a tricky race. * sys/ximage/ximagesink.h: * sys/xvimage/xvimagesink.c: (gst_xvimagesink_xvimage_put), (gst_xvimagesink_expose): Fixed a tricky race. * sys/xvimage/xvimagesink.h:
Diffstat (limited to 'sys')
-rw-r--r--sys/ximage/ximagesink.c35
-rw-r--r--sys/ximage/ximagesink.h2
-rw-r--r--sys/xvimage/xvimagesink.c20
-rw-r--r--sys/xvimage/xvimagesink.h2
4 files changed, 40 insertions, 19 deletions
diff --git a/sys/ximage/ximagesink.c b/sys/ximage/ximagesink.c
index e867f772..91a7200b 100644
--- a/sys/ximage/ximagesink.c
+++ b/sys/ximage/ximagesink.c
@@ -1,5 +1,5 @@
/* GStreamer
- * Copyright (C) <2003> Julien Moutte <julien@moutte.net>
+ * Copyright (C) <2005> Julien Moutte <julien@moutte.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -229,6 +229,15 @@ beach:
}
static void
+gst_ximage_buffer_free (GstXImageBuffer * ximage)
+{
+ /* make sure it is not recycled */
+ ximage->width = -1;
+ ximage->height = -1;
+ gst_buffer_unref (GST_BUFFER (ximage));
+}
+
+static void
gst_ximage_buffer_init (GstXImageBuffer * ximage_buffer, gpointer g_class)
{
#ifdef HAVE_XSHM
@@ -456,7 +465,7 @@ beach:
g_mutex_unlock (ximagesink->x_lock);
if (!succeeded) {
- gst_buffer_unref (GST_BUFFER (ximage));
+ gst_ximage_buffer_free (ximage);
ximage = NULL;
}
@@ -555,16 +564,12 @@ gst_ximagesink_ximage_put (GstXImageSink * ximagesink, GstXImageBuffer * ximage)
g_return_if_fail (GST_IS_XIMAGESINK (ximagesink));
- if (!ximage) {
- return;
- }
-
/* We take the flow_lock. If expose is in there we don't want to run
concurrently from the data flow thread */
g_mutex_lock (ximagesink->flow_lock);
/* Store a reference to the last image we put, loose the previous one */
- if (ximagesink->cur_image != ximage) {
+ if (ximage && ximagesink->cur_image != ximage) {
if (ximagesink->cur_image) {
GST_DEBUG_OBJECT (ximagesink, "unreffing %p", ximagesink->cur_image);
gst_buffer_unref (ximagesink->cur_image);
@@ -572,6 +577,16 @@ gst_ximagesink_ximage_put (GstXImageSink * ximagesink, GstXImageBuffer * ximage)
ximagesink->cur_image = GST_XIMAGE_BUFFER (gst_buffer_ref (ximage));
}
+ /* Expose sends a NULL image, we take the latest frame */
+ if (!ximage) {
+ if (ximagesink->cur_image) {
+ ximage = ximagesink->cur_image;
+ } else {
+ g_mutex_unlock (ximagesink->flow_lock);
+ return;
+ }
+ }
+
gst_ximagesink_xwindow_update_geometry (ximagesink, ximagesink->xwindow);
src.w = ximage->width;
@@ -1117,7 +1132,7 @@ gst_ximagesink_bufferpool_clear (GstXImageSink * ximagesink)
ximagesink->buffer_pool = g_slist_delete_link (ximagesink->buffer_pool,
ximagesink->buffer_pool);
- gst_ximagesink_ximage_destroy (ximagesink, ximage);
+ gst_ximage_buffer_free (ximage);
}
g_mutex_unlock (ximagesink->pool_lock);
@@ -1508,7 +1523,7 @@ alloc:
/* If the ximage is invalid for our need, destroy */
if ((ximage->width != width) || (ximage->height != height)) {
- gst_ximagesink_ximage_destroy (ximagesink, ximage);
+ gst_ximage_buffer_free (ximage);
ximage = NULL;
} else {
/* We found a suitable ximage */
@@ -1687,7 +1702,7 @@ gst_ximagesink_expose (GstXOverlay * overlay)
if (!ximagesink->xwindow)
return;
- gst_ximagesink_ximage_put (ximagesink, ximagesink->cur_image);
+ gst_ximagesink_ximage_put (ximagesink, NULL);
}
static void
diff --git a/sys/ximage/ximagesink.h b/sys/ximage/ximagesink.h
index d9401941..1383f773 100644
--- a/sys/ximage/ximagesink.h
+++ b/sys/ximage/ximagesink.h
@@ -1,5 +1,5 @@
/* GStreamer
- * Copyright (C) <2003> Julien Moutte <julien@moutte.net>
+ * Copyright (C) <2005> Julien Moutte <julien@moutte.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
diff --git a/sys/xvimage/xvimagesink.c b/sys/xvimage/xvimagesink.c
index 987ddb26..ebda4511 100644
--- a/sys/xvimage/xvimagesink.c
+++ b/sys/xvimage/xvimagesink.c
@@ -1,5 +1,5 @@
/* GStreamer
- * Copyright (C) <2003> Julien Moutte <julien@moutte.net>
+ * Copyright (C) <2005> Julien Moutte <julien@moutte.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -587,16 +587,12 @@ gst_xvimagesink_xvimage_put (GstXvImageSink * xvimagesink,
g_return_if_fail (GST_IS_XVIMAGESINK (xvimagesink));
g_return_if_fail (xvimagesink->xwindow != NULL);
- if (!xvimage) {
- return;
- }
-
/* We take the flow_lock. If expose is in there we don't want to run
concurrently from the data flow thread */
g_mutex_lock (xvimagesink->flow_lock);
/* Store a reference to the last image we put, loose the previous one */
- if (xvimagesink->cur_image != xvimage) {
+ if (xvimage && xvimagesink->cur_image != xvimage) {
if (xvimagesink->cur_image) {
GST_DEBUG_OBJECT (xvimagesink, "unreffing %p", xvimagesink->cur_image);
gst_buffer_unref (xvimagesink->cur_image);
@@ -604,6 +600,16 @@ gst_xvimagesink_xvimage_put (GstXvImageSink * xvimagesink,
xvimagesink->cur_image = GST_XVIMAGE_BUFFER (gst_buffer_ref (xvimage));
}
+ /* Expose sends a NULL image, we take the latest frame */
+ if (!xvimage) {
+ if (xvimagesink->cur_image) {
+ xvimage = xvimagesink->cur_image;
+ } else {
+ g_mutex_unlock (xvimagesink->flow_lock);
+ return;
+ }
+ }
+
gst_xvimagesink_xwindow_update_geometry (xvimagesink, xvimagesink->xwindow);
src.w = xvimage->width;
@@ -2002,7 +2008,7 @@ gst_xvimagesink_expose (GstXOverlay * overlay)
if (!xvimagesink->xwindow)
return;
- gst_xvimagesink_xvimage_put (xvimagesink, xvimagesink->cur_image);
+ gst_xvimagesink_xvimage_put (xvimagesink, NULL);
}
static void
diff --git a/sys/xvimage/xvimagesink.h b/sys/xvimage/xvimagesink.h
index fa88aa8c..80bb1f5f 100644
--- a/sys/xvimage/xvimagesink.h
+++ b/sys/xvimage/xvimagesink.h
@@ -1,5 +1,5 @@
/* GStreamer
- * Copyright (C) <2003> Julien Moutte <julien@moutte.net>
+ * Copyright (C) <2005> Julien Moutte <julien@moutte.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public