+/* takes ownership of the pool, allocator and query */
+static gboolean
+gst_deinterlace_set_allocation (GstDeinterlace * self,
+ GstBufferPool * pool, GstAllocator * allocator,
+ GstAllocationParams * params)
+{
+ GstAllocator *oldalloc;
+ GstBufferPool *oldpool;
+
+ GST_OBJECT_LOCK (self);
+ oldpool = self->pool;
+ self->pool = pool;
+
+ oldalloc = self->allocator;
+ self->allocator = allocator;
+
+ if (params)
+ self->params = *params;
+ else
+ gst_allocation_params_init (&self->params);
+ GST_OBJECT_UNLOCK (self);
+
+ if (oldpool) {
+ GST_DEBUG_OBJECT (self, "deactivating old pool %p", oldpool);
+ gst_buffer_pool_set_active (oldpool, FALSE);
+ gst_object_unref (oldpool);
+ }
+ if (oldalloc) {
+ gst_object_unref (oldalloc);
+ }
+ if (pool) {
+ GST_DEBUG_OBJECT (self, "activating new pool %p", pool);
+ gst_buffer_pool_set_active (pool, TRUE);
+ }
+ return TRUE;
+}
+
+static gboolean
+gst_deinterlace_do_bufferpool (GstDeinterlace * self, GstCaps * outcaps)
+{
+ GstQuery *query;
+ gboolean result = TRUE;
+ GstBufferPool *pool;
+ GstAllocator *allocator;
+ GstAllocationParams params;
+ GstStructure *config;
+ guint size, min, max;
+
+ if (self->passthrough) {
+ /* we are in passthrough, the input buffer is never copied and always passed
+ * along. We never allocate an output buffer on the srcpad. What we do is
+ * let the upstream element decide if it wants to use a bufferpool and
+ * then we will proxy the downstream pool */
+ GST_DEBUG_OBJECT (self, "we're passthough, delay bufferpool");
+ gst_deinterlace_set_allocation (self, NULL, NULL, NULL);
+ return TRUE;
+ }
+
+ /* not passthrough, we need to allocate */
+ /* find a pool for the negotiated caps now */
+ GST_DEBUG_OBJECT (self, "doing allocation query");
+ query = gst_query_new_allocation (outcaps, TRUE);
+ if (!gst_pad_peer_query (self->srcpad, query)) {
+ /* not a problem, just debug a little */
+ GST_DEBUG_OBJECT (self, "peer ALLOCATION query failed");
+ }
+
+ GST_DEBUG_OBJECT (self, "ALLOCATION (%d) params: %" GST_PTR_FORMAT, result,
+ query);
+
+ /* we got configuration from our peer or the decide_allocation method,
+ * parse them */
+ if (gst_query_get_n_allocation_params (query) > 0) {
+ gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
+ } else {
+ allocator = NULL;
+ gst_allocation_params_init (¶ms);
+ }
+
+ if (gst_query_get_n_allocation_pools (query) > 0)
+ gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
+ else {
+ pool = NULL;
+ size = GST_VIDEO_INFO_SIZE (&self->vinfo), min = max = 0;
+ }
+
+ if (pool == NULL) {
+ /* no pool, we can make our own */
+ GST_DEBUG_OBJECT (self, "no pool, making new pool");
+ pool = gst_video_buffer_pool_new ();
+ }
+
+ /* now configure */
+ config = gst_buffer_pool_get_config (pool);
+ gst_buffer_pool_config_set_params (config, outcaps, size, min, max);
+ gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
+ gst_buffer_pool_set_config (pool, config);
+
+ /* now store */
+ result = gst_deinterlace_set_allocation (self, pool, allocator, ¶ms);
+
+ return result;
+}
+
+