Added TI patches, generated from commit 04f9d72 of the following tree:
[ubuntu-omap:gst-plugins-bad1-0.git] / debian / patches / 0004-04-30-dri2videosink-refcount-dri2window.patch
1 From 8613b4a49c74f2f57f97df9d0f60ee60d947f9b5 Mon Sep 17 00:00:00 2001
2 From: Vincent Penquerc'h <vincent.penquerch@collabora.co.uk>
3 Date: Sun, 24 Jun 2012 13:58:38 +0000
4 Subject: [PATCH 004/100] [04/30] dri2videosink: refcount dri2window
5
6 I'm not convinced this was wrong in the first place, since the dri2window
7 was destroying the pool on destruction, and I'm told buffers cannot outlive
8 the pool, but refcounting makes this certain, though care has to be taken
9 to avoid ref cycles between dri2window and buffer pool.
10 ---
11  sys/dri2/gstdri2bufferpool.c |   17 +++++++++++++++
12  sys/dri2/gstdri2util.c       |   49 ++++++++++++++++++++++++++++++++++++++++--
13  sys/dri2/gstdri2util.h       |   10 +++++++++
14  3 files changed, 74 insertions(+), 2 deletions(-)
15
16 diff --git a/sys/dri2/gstdri2bufferpool.c b/sys/dri2/gstdri2bufferpool.c
17 index 76faad7..1953e0c 100644
18 --- a/sys/dri2/gstdri2bufferpool.c
19 +++ b/sys/dri2/gstdri2bufferpool.c
20 @@ -33,6 +33,8 @@
21   * GstDRI2BufferPool:
22   */
23  
24 +static GstMiniObjectClass * gst_dri2bufferpool_parent_class = NULL;
25 +
26  G_DEFINE_TYPE (GstDRI2BufferPool, gst_dri2_buffer_pool,
27      GST_TYPE_DRM_BUFFER_POOL);
28  
29 @@ -46,6 +48,7 @@ gst_dri2_buffer_pool_new (GstDRI2Window * xwindow,
30    gst_drm_buffer_pool_initialize (GST_DRM_BUFFER_POOL (self),
31        xwindow->dcontext->elem, fd, caps, size);
32  
33 +  gst_mini_object_ref (GST_MINI_OBJECT (xwindow));
34    self->xwindow = xwindow;
35  
36    return self;
37 @@ -59,6 +62,8 @@ gst_dri2_buffer_alloc (GstDRMBufferPool * pool)
38        gst_mini_object_new (GST_TYPE_DRI2_BUFFER);
39    struct omap_bo *bo;
40  
41 +  gst_mini_object_ref (GST_MINI_OBJECT (pool));
42 +
43    self->dri2buf = gst_dri2window_get_dri2buffer (dri2pool->xwindow,
44        pool->width, pool->height, pool->fourcc);
45  
46 @@ -79,6 +84,15 @@ gst_dri2_buffer_cleanup (GstDRMBufferPool * pool, GstDRMBuffer * buf)
47    gst_dri2window_free_dri2buffer (
48        GST_DRI2_BUFFER_POOL (pool)->xwindow,
49        GST_DRI2_BUFFER (buf)->dri2buf);
50 +  gst_mini_object_unref (GST_MINI_OBJECT (pool));
51 +}
52 +
53 +static void
54 +gst_dri2_buffer_pool_finalize (GstDRMBufferPool * pool)
55 +{
56 +  gst_mini_object_unref (GST_MINI_OBJECT (GST_DRI2_BUFFER_POOL(pool)->xwindow));
57 +  GST_MINI_OBJECT_CLASS (gst_dri2bufferpool_parent_class)->finalize (GST_MINI_OBJECT
58 +      (pool));
59  }
60  
61  static void
62 @@ -88,6 +102,9 @@ gst_dri2_buffer_pool_class_init (GstDRI2BufferPoolClass * klass)
63        GST_DEBUG_FUNCPTR (gst_dri2_buffer_alloc);
64    GST_DRM_BUFFER_POOL_CLASS (klass)->buffer_cleanup =
65        GST_DEBUG_FUNCPTR (gst_dri2_buffer_cleanup);
66 +  GST_MINI_OBJECT_CLASS (klass)->finalize =
67 +      (GstMiniObjectFinalizeFunction) GST_DEBUG_FUNCPTR (gst_dri2_buffer_pool_finalize);
68 +  gst_dri2bufferpool_parent_class = g_type_class_peek_parent (klass);
69  }
70  
71  static void
72 diff --git a/sys/dri2/gstdri2util.c b/sys/dri2/gstdri2util.c
73 index f117d6f..59e59bf 100644
74 --- a/sys/dri2/gstdri2util.c
75 +++ b/sys/dri2/gstdri2util.c
76 @@ -32,6 +32,8 @@
77  #include "gstdri2util.h"
78  #include "gstdri2bufferpool.h"
79  
80 +static GstMiniObjectClass *dri2window_parent_class = NULL;
81 +
82  static Bool WireToEvent (Display * dpy, XExtDisplayInfo * info,
83      XEvent * event, xEvent * wire)
84  {
85 @@ -301,7 +303,7 @@ gst_dri2window_new_from_handle (GstDRI2Context *dcontext, XID xwindow_id)
86    GstDRI2Window *xwindow;
87    XWindowAttributes attr;
88  
89 -  xwindow = g_new0 (GstDRI2Window, 1);
90 +  xwindow = (GstDRI2Window *)gst_mini_object_new (GST_TYPE_DRI2WINDOW);
91    xwindow->dcontext = dcontext;
92    xwindow->window = xwindow_id;
93    xwindow->pool_lock = g_mutex_new ();
94 @@ -376,6 +378,20 @@ gst_dri2window_new (GstDRI2Context * dcontext, gint width, gint height)
95  void
96  gst_dri2window_delete (GstDRI2Window * xwindow)
97  {
98 +  g_mutex_lock (xwindow->pool_lock);
99 +  xwindow->pool_valid = FALSE;
100 +  if (xwindow->buffer_pool) {
101 +    gst_drm_buffer_pool_destroy (xwindow->buffer_pool);
102 +    xwindow->buffer_pool = NULL;
103 +  }
104 +  g_mutex_unlock (xwindow->pool_lock);
105 +
106 +  gst_mini_object_unref (GST_MINI_OBJECT (xwindow));
107 +}
108 +
109 +static void
110 +gst_dri2window_finalize (GstDRI2Window * xwindow)
111 +{
112    GstDRI2Context *dcontext = xwindow->dcontext;
113  
114    g_mutex_lock (xwindow->pool_lock);
115 @@ -408,7 +424,8 @@ gst_dri2window_delete (GstDRI2Window * xwindow)
116  
117    g_mutex_unlock (dcontext->x_lock);
118  
119 -  g_free (xwindow);
120 +  GST_MINI_OBJECT_CLASS (dri2window_parent_class)->finalize (GST_MINI_OBJECT
121 +      (xwindow));
122  }
123  
124  /* call with x_lock held */
125 @@ -640,3 +657,31 @@ gst_dri2window_free_dri2buffer (GstDRI2Window * xwindow, DRI2Buffer * dri2buf)
126    free (xwindow->dri2bufs[idx]);
127    xwindow->dri2bufs[idx] = NULL;
128  }
129 +
130 +static void
131 +gst_dri2window_class_init (gpointer g_class, gpointer class_data)
132 +{
133 +  GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (g_class);
134 +
135 +  dri2window_parent_class = g_type_class_peek_parent (g_class);
136 +
137 +  mini_object_class->finalize = (GstMiniObjectFinalizeFunction)
138 +      GST_DEBUG_FUNCPTR (gst_dri2window_finalize);
139 +}
140 +
141 +GType
142 +gst_dri2window_get_type (void)
143 +{
144 +  static GType type;
145 +
146 +  if (G_UNLIKELY (type == 0)) {
147 +    static const GTypeInfo info = {
148 +      .class_size = sizeof (GstMiniObjectClass),
149 +      .class_init = gst_dri2window_class_init,
150 +      .instance_size = sizeof (GstDRI2Window),
151 +    };
152 +    type = g_type_register_static (GST_TYPE_MINI_OBJECT,
153 +        "GstDRI2Window", &info, 0);
154 +  }
155 +  return type;
156 +}
157 diff --git a/sys/dri2/gstdri2util.h b/sys/dri2/gstdri2util.h
158 index bfc4390..751aa87 100644
159 --- a/sys/dri2/gstdri2util.h
160 +++ b/sys/dri2/gstdri2util.h
161 @@ -84,8 +84,18 @@ void gst_dri2context_delete (GstDRI2Context *dcontext);
162   * GstDRI2Window
163   */
164  
165 +GType gst_dri2window_get_type (void);
166 +#define GST_TYPE_DRI2WINDOW (gst_dri2window_get_type())
167 +#define GST_IS_DRI2WINDOW(obj) \
168 +  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_DRI2WINDOW))
169 +#define GST_DRI2WINDOW(obj) \
170 +  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_DRI2WINDOW, \
171 +                               GstDRI2Window))
172 +
173  struct _GstDRI2Window
174  {
175 +  GstMiniObject parent;
176 +
177    GstDRI2Context *dcontext;
178  
179    Window window;
180 -- 
181 1.7.9.5
182