eglglessink: Properly negotiate an allocator

This commit is contained in:
Sebastian Dröge 2013-02-25 13:43:28 +01:00
parent 5e948472ed
commit a2e89b0858

View File

@ -2477,10 +2477,13 @@ gst_eglglessink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
GstCaps *caps; GstCaps *caps;
gboolean need_pool; gboolean need_pool;
guint size; guint size;
GstAllocationParams params = { 0, }; GstAllocator *allocator;
GstAllocationParams params;
eglglessink = GST_EGLGLESSINK (bsink); eglglessink = GST_EGLGLESSINK (bsink);
gst_allocation_params_init (&params);
gst_query_parse_allocation (query, &caps, &need_pool); gst_query_parse_allocation (query, &caps, &need_pool);
if (!caps) { if (!caps) {
GST_ERROR_OBJECT (eglglessink, "allocation query without caps"); GST_ERROR_OBJECT (eglglessink, "allocation query without caps");
@ -2542,6 +2545,19 @@ gst_eglglessink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
gst_object_unref (pool); gst_object_unref (pool);
} }
/* First the default allocator */
if (!gst_egl_image_memory_is_mappable ()) {
allocator = gst_allocator_find (NULL);
gst_query_add_allocation_param (query, allocator, &params);
gst_object_unref (allocator);
}
allocator = gst_egl_image_allocator_obtain ();
if (!gst_egl_image_memory_is_mappable ())
params.flags |= GST_MEMORY_FLAG_NOT_MAPPABLE;
gst_query_add_allocation_param (query, allocator, &params);
gst_object_unref (allocator);
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL); gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
gst_query_add_allocation_meta (query, GST_VIDEO_CROP_META_API_TYPE, NULL); gst_query_add_allocation_meta (query, GST_VIDEO_CROP_META_API_TYPE, NULL);
@ -2949,6 +2965,7 @@ typedef struct
GstEglGlesSink *sink; GstEglGlesSink *sink;
GstAllocator *allocator; GstAllocator *allocator;
GstAllocationParams params;
GstVideoInfo info; GstVideoInfo info;
gboolean add_metavideo; gboolean add_metavideo;
gboolean want_eglimage; gboolean want_eglimage;
@ -3050,8 +3067,9 @@ gst_eglglessink_allocate_eglimage (GstEglGlesSink * eglglessink,
gst_egl_image_allocator_wrap (GST_EGL_IMAGE_BUFFER_POOL gst_egl_image_allocator_wrap (GST_EGL_IMAGE_BUFFER_POOL
(eglglessink->pool)->allocator, eglglessink->eglglesctx.display, (eglglessink->pool)->allocator, eglglessink->eglglesctx.display,
image, GST_EGL_IMAGE_MEMORY_TYPE_RGB, image, GST_EGL_IMAGE_MEMORY_TYPE_RGB,
(gst_egl_image_memory_can_map ()? 0 : GST_MEMORY_FLAG_NOT_MAPPABLE), (gst_egl_image_memory_is_mappable ()? 0 :
size, data, (GDestroyNotify) gst_egl_gles_image_data_free); GST_MEMORY_FLAG_NOT_MAPPABLE), size, data,
(GDestroyNotify) gst_egl_gles_image_data_free);
n_mem = 1; n_mem = 1;
} }
break; break;
@ -3114,8 +3132,9 @@ gst_eglglessink_allocate_eglimage (GstEglGlesSink * eglglessink,
gst_egl_image_allocator_wrap (GST_EGL_IMAGE_BUFFER_POOL gst_egl_image_allocator_wrap (GST_EGL_IMAGE_BUFFER_POOL
(eglglessink->pool)->allocator, eglglessink->eglglesctx.display, (eglglessink->pool)->allocator, eglglessink->eglglesctx.display,
image, GST_EGL_IMAGE_MEMORY_TYPE_RGB, image, GST_EGL_IMAGE_MEMORY_TYPE_RGB,
(gst_egl_image_memory_can_map ()? 0 : GST_MEMORY_FLAG_NOT_MAPPABLE), (gst_egl_image_memory_is_mappable ()? 0 :
size, data, (GDestroyNotify) gst_egl_gles_image_data_free); GST_MEMORY_FLAG_NOT_MAPPABLE), size, data,
(GDestroyNotify) gst_egl_gles_image_data_free);
n_mem = 1; n_mem = 1;
} }
break; break;
@ -3207,7 +3226,7 @@ gst_eglglessink_allocate_eglimage (GstEglGlesSink * eglglessink,
(i == (i ==
0 ? GST_EGL_IMAGE_MEMORY_TYPE_LUMINANCE : 0 ? GST_EGL_IMAGE_MEMORY_TYPE_LUMINANCE :
GST_EGL_IMAGE_MEMORY_TYPE_LUMINANCE_ALPHA), GST_EGL_IMAGE_MEMORY_TYPE_LUMINANCE_ALPHA),
(gst_egl_image_memory_can_map ()? 0 : (gst_egl_image_memory_is_mappable ()? 0 :
GST_MEMORY_FLAG_NOT_MAPPABLE), size[i], data, GST_MEMORY_FLAG_NOT_MAPPABLE), size[i], data,
(GDestroyNotify) gst_egl_gles_image_data_free); (GDestroyNotify) gst_egl_gles_image_data_free);
} }
@ -3309,7 +3328,7 @@ gst_eglglessink_allocate_eglimage (GstEglGlesSink * eglglessink,
gst_egl_image_allocator_wrap (GST_EGL_IMAGE_BUFFER_POOL gst_egl_image_allocator_wrap (GST_EGL_IMAGE_BUFFER_POOL
(eglglessink->pool)->allocator, eglglessink->eglglesctx.display, (eglglessink->pool)->allocator, eglglessink->eglglesctx.display,
image, GST_EGL_IMAGE_MEMORY_TYPE_LUMINANCE, image, GST_EGL_IMAGE_MEMORY_TYPE_LUMINANCE,
(gst_egl_image_memory_can_map ()? 0 : (gst_egl_image_memory_is_mappable ()? 0 :
GST_MEMORY_FLAG_NOT_MAPPABLE), size[i], data, GST_MEMORY_FLAG_NOT_MAPPABLE), size[i], data,
(GDestroyNotify) gst_egl_gles_image_data_free); (GDestroyNotify) gst_egl_gles_image_data_free);
} }
@ -3383,8 +3402,9 @@ gst_eglglessink_allocate_eglimage (GstEglGlesSink * eglglessink,
gst_egl_image_allocator_wrap (GST_EGL_IMAGE_BUFFER_POOL gst_egl_image_allocator_wrap (GST_EGL_IMAGE_BUFFER_POOL
(eglglessink->pool)->allocator, eglglessink->eglglesctx.display, (eglglessink->pool)->allocator, eglglessink->eglglesctx.display,
image, GST_EGL_IMAGE_MEMORY_TYPE_RGBA, image, GST_EGL_IMAGE_MEMORY_TYPE_RGBA,
(gst_egl_image_memory_can_map ()? 0 : GST_MEMORY_FLAG_NOT_MAPPABLE), (gst_egl_image_memory_is_mappable ()? 0 :
size, data, (GDestroyNotify) gst_egl_gles_image_data_free); GST_MEMORY_FLAG_NOT_MAPPABLE), size, data,
(GDestroyNotify) gst_egl_gles_image_data_free);
n_mem = 1; n_mem = 1;
} }
@ -3428,8 +3448,7 @@ G_DEFINE_TYPE (GstEGLImageBufferPool, gst_egl_image_buffer_pool,
static const gchar ** static const gchar **
gst_egl_image_buffer_pool_get_options (GstBufferPool * bpool) gst_egl_image_buffer_pool_get_options (GstBufferPool * bpool)
{ {
static const gchar *options[] = { GST_BUFFER_POOL_OPTION_VIDEO_META, static const gchar *options[] = { GST_BUFFER_POOL_OPTION_VIDEO_META, NULL
GST_BUFFER_POOL_OPTION_EGL_IMAGE, NULL
}; };
return options; return options;
@ -3458,15 +3477,16 @@ gst_egl_image_buffer_pool_set_config (GstBufferPool * bpool,
if (!gst_video_info_from_caps (&info, caps)) if (!gst_video_info_from_caps (&info, caps))
return FALSE; return FALSE;
if (!gst_buffer_pool_config_get_allocator (config, &pool->allocator,
&pool->params))
return FALSE;
pool->add_metavideo = pool->add_metavideo =
gst_buffer_pool_config_has_option (config, gst_buffer_pool_config_has_option (config,
GST_BUFFER_POOL_OPTION_VIDEO_META); GST_BUFFER_POOL_OPTION_VIDEO_META);
pool->want_eglimage = pool->want_eglimage = (pool->allocator
gst_buffer_pool_config_has_option (config, && g_strcmp0 (pool->allocator->mem_type, GST_EGL_IMAGE_MEMORY_TYPE) == 0);
GST_BUFFER_POOL_OPTION_EGL_IMAGE);
pool->allocator = gst_egl_image_allocator_obtain ();
pool->info = info; pool->info = info;
@ -3481,8 +3501,7 @@ gst_egl_image_buffer_pool_alloc_buffer (GstBufferPool * bpool,
*buffer = NULL; *buffer = NULL;
if (!pool->add_metavideo || (!gst_egl_image_memory_can_map () if (!pool->add_metavideo || !pool->want_eglimage)
&& !pool->want_eglimage))
return return
GST_BUFFER_POOL_CLASS GST_BUFFER_POOL_CLASS
(gst_egl_image_buffer_pool_parent_class)->alloc_buffer (bpool, (gst_egl_image_buffer_pool_parent_class)->alloc_buffer (bpool,