Factor out direct-rendering infrastructure.

This commit is contained in:
gb 2010-03-19 08:42:51 +00:00
parent 6b27844b5b
commit bb66a7ea4a
3 changed files with 51 additions and 75 deletions

5
NEWS
View file

@ -1,5 +1,8 @@
gst-vaapi NEWS -- summary of changes. 2010-03-16 gst-vaapi NEWS -- summary of changes. 2010-03-DD
Copyright (C) 2010 Splitted-Desktop Systems Copyright (C) 2010 Splitted-Desktop Systems
Version 0.1.1 - DD.Mar.2010
* Optimize `vaapiconvert' pipeline (direct-rendering)
Version 0.1.0 - 16.Mar.2010 Version 0.1.0 - 16.Mar.2010
* Initial release * Initial release

View file

@ -69,11 +69,12 @@ GST_BOILERPLATE(
GstBaseTransform, GstBaseTransform,
GST_TYPE_BASE_TRANSFORM); GST_TYPE_BASE_TRANSFORM);
#define DIRECT_RENDERING_DEFAULT 2
enum { enum {
PROP_0, PROP_0,
PROP_USE_INOUT_BUFFERS, PROP_DIRECT_RENDERING,
PROP_USE_DERIVE_IMAGE
}; };
static gboolean gst_vaapiconvert_start(GstBaseTransform *trans); static gboolean gst_vaapiconvert_start(GstBaseTransform *trans);
@ -183,11 +184,8 @@ gst_vaapiconvert_set_property(
GstVaapiConvert * const convert = GST_VAAPICONVERT(object); GstVaapiConvert * const convert = GST_VAAPICONVERT(object);
switch (prop_id) { switch (prop_id) {
case PROP_USE_INOUT_BUFFERS: case PROP_DIRECT_RENDERING:
convert->allow_use_inout_buffers = g_value_get_boolean(value); convert->direct_rendering = g_value_get_uint(value);
break;
case PROP_USE_DERIVE_IMAGE:
convert->allow_use_derive_image = g_value_get_boolean(value);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
@ -206,11 +204,8 @@ gst_vaapiconvert_get_property(
GstVaapiConvert * const convert = GST_VAAPICONVERT(object); GstVaapiConvert * const convert = GST_VAAPICONVERT(object);
switch (prop_id) { switch (prop_id) {
case PROP_USE_INOUT_BUFFERS: case PROP_DIRECT_RENDERING:
g_value_set_boolean(value, convert->allow_use_inout_buffers); g_value_set_uint(value, convert->direct_rendering);
break;
case PROP_USE_DERIVE_IMAGE:
g_value_set_boolean(value, convert->allow_use_derive_image);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
@ -238,21 +233,13 @@ gst_vaapiconvert_class_init(GstVaapiConvertClass *klass)
g_object_class_install_property g_object_class_install_property
(object_class, (object_class,
PROP_USE_INOUT_BUFFERS, PROP_DIRECT_RENDERING,
g_param_spec_boolean("use-inout-buffers", g_param_spec_uint("direct-rendering",
"Use in/out buffers", "Direct rendering",
"Allow use of in/out buffers whenever possible", "Direct rendering level",
TRUE, 0, 2,
G_PARAM_READWRITE)); DIRECT_RENDERING_DEFAULT,
G_PARAM_READWRITE));
g_object_class_install_property
(object_class,
PROP_USE_DERIVE_IMAGE,
g_param_spec_boolean("use-derive-image",
"Use vaDeriveImage()",
"Allow use of vaDeriveImage() whenever possible",
TRUE,
G_PARAM_READWRITE));
} }
static void static void
@ -267,12 +254,8 @@ gst_vaapiconvert_init(GstVaapiConvert *convert, GstVaapiConvertClass *klass)
convert->surfaces = NULL; convert->surfaces = NULL;
convert->surface_width = 0; convert->surface_width = 0;
convert->surface_height = 0; convert->surface_height = 0;
convert->allow_use_inout_buffers = TRUE; convert->direct_rendering_caps = 0;
convert->can_use_inout_buffers = FALSE; convert->direct_rendering = G_MAXUINT32;
convert->use_inout_buffers = FALSE;
convert->allow_use_derive_image = TRUE;
convert->can_use_derive_image = FALSE;
convert->use_derive_image = FALSE;
/* Override buffer allocator on sink pad */ /* Override buffer allocator on sink pad */
sinkpad = gst_element_get_static_pad(GST_ELEMENT(convert), "sink"); sinkpad = gst_element_get_static_pad(GST_ELEMENT(convert), "sink");
@ -329,7 +312,7 @@ gst_vaapiconvert_transform(
if (!surface) if (!surface)
return GST_FLOW_UNEXPECTED; return GST_FLOW_UNEXPECTED;
if (convert->use_inout_buffers) { if (convert->direct_rendering) {
if (!GST_VAAPI_IS_VIDEO_BUFFER(inbuf)) { if (!GST_VAAPI_IS_VIDEO_BUFFER(inbuf)) {
GST_DEBUG("GstVaapiVideoBuffer was expected"); GST_DEBUG("GstVaapiVideoBuffer was expected");
return GST_FLOW_UNEXPECTED; return GST_FLOW_UNEXPECTED;
@ -345,7 +328,7 @@ gst_vaapiconvert_transform(
if (!gst_vaapi_image_unmap(image)) if (!gst_vaapi_image_unmap(image))
return GST_FLOW_UNEXPECTED; return GST_FLOW_UNEXPECTED;
if (!convert->use_derive_image) if (convert->direct_rendering < 2)
gst_vaapi_surface_put_image(surface, image); gst_vaapi_surface_put_image(surface, image);
return GST_FLOW_OK; return GST_FLOW_OK;
} }
@ -438,10 +421,11 @@ gst_vaapiconvert_ensure_image_pool(GstVaapiConvert *convert, GstCaps *caps)
if (gst_video_format_parse_caps(caps, &vformat, NULL, NULL)) { if (gst_video_format_parse_caps(caps, &vformat, NULL, NULL)) {
image = gst_vaapi_video_pool_get_object(convert->images); image = gst_vaapi_video_pool_get_object(convert->images);
if (image) { if (image) {
convert->can_use_inout_buffers = if (convert->direct_rendering_caps == 0 &&
(gst_vaapi_image_is_linear(image) && (gst_vaapi_image_is_linear(image) &&
(gst_vaapi_image_get_data_size(image) == (gst_vaapi_image_get_data_size(image) ==
gst_video_format_get_size(vformat, width, height))); gst_video_format_get_size(vformat, width, height))))
convert->direct_rendering_caps = 1;
gst_vaapi_video_pool_put_object(convert->images, image); gst_vaapi_video_pool_put_object(convert->images, image);
} }
} }
@ -475,7 +459,8 @@ gst_vaapiconvert_ensure_surface_pool(GstVaapiConvert *convert, GstCaps *caps)
image = gst_vaapi_surface_derive_image(surface); image = gst_vaapi_surface_derive_image(surface);
if (image) { if (image) {
if (gst_vaapi_image_map(image)) { if (gst_vaapi_image_map(image)) {
convert->can_use_derive_image = TRUE; if (convert->direct_rendering_caps == 1)
convert->direct_rendering_caps = 2;
gst_vaapi_image_unmap(image); gst_vaapi_image_unmap(image);
} }
g_object_unref(image); g_object_unref(image);
@ -493,7 +478,7 @@ gst_vaapiconvert_negotiate_buffers(
GstCaps *outcaps GstCaps *outcaps
) )
{ {
gboolean enable; guint dr;
if (!gst_vaapiconvert_ensure_image_pool(convert, incaps)) if (!gst_vaapiconvert_ensure_image_pool(convert, incaps))
return FALSE; return FALSE;
@ -501,22 +486,10 @@ gst_vaapiconvert_negotiate_buffers(
if (!gst_vaapiconvert_ensure_surface_pool(convert, outcaps)) if (!gst_vaapiconvert_ensure_surface_pool(convert, outcaps))
return FALSE; return FALSE;
if (convert->allow_use_inout_buffers) { dr = MIN(convert->direct_rendering, convert->direct_rendering_caps);
enable = convert->can_use_inout_buffers; if (convert->direct_rendering != dr) {
if (convert->use_inout_buffers != enable) { convert->direct_rendering = dr;
convert->use_inout_buffers = enable; GST_DEBUG("direct-rendering level: %d", dr);
GST_DEBUG("use-inout-buffers: %s",
convert->use_inout_buffers ? "enabled" : "disabled");
}
}
if (convert->allow_use_derive_image) {
enable = convert->use_inout_buffers && convert->can_use_derive_image;
if (convert->use_derive_image != enable) {
convert->use_derive_image = enable;
GST_DEBUG("use-derive-image: %s",
convert->use_derive_image ? "enabled" : "disabled");
}
} }
return TRUE; return TRUE;
} }
@ -569,10 +542,10 @@ gst_vaapiconvert_buffer_alloc(
GstBuffer *buffer = NULL; GstBuffer *buffer = NULL;
GstVaapiImage *image = NULL; GstVaapiImage *image = NULL;
/* Check if we can use the inout-buffers optimization */ /* Check if we can use direct-rendering */
if (!gst_vaapiconvert_negotiate_buffers(convert, caps, caps)) if (!gst_vaapiconvert_negotiate_buffers(convert, caps, caps))
goto error; goto error;
if (!convert->use_inout_buffers) if (!convert->direct_rendering)
return GST_FLOW_OK; return GST_FLOW_OK;
buffer = gst_vaapi_video_buffer_new_from_pool(convert->surfaces); buffer = gst_vaapi_video_buffer_new_from_pool(convert->surfaces);
@ -580,18 +553,22 @@ gst_vaapiconvert_buffer_alloc(
goto error; goto error;
GstVaapiVideoBuffer * const vbuffer = GST_VAAPI_VIDEO_BUFFER(buffer); GstVaapiVideoBuffer * const vbuffer = GST_VAAPI_VIDEO_BUFFER(buffer);
if (convert->use_derive_image) { GstVaapiSurface *surface;
GstVaapiSurface *surface = gst_vaapi_video_buffer_get_surface(vbuffer); switch (convert->direct_rendering) {
image = gst_vaapi_surface_derive_image(surface); case 2:
if (image) surface = gst_vaapi_video_buffer_get_surface(vbuffer);
image = gst_vaapi_surface_derive_image(surface);
if (image) {
gst_vaapi_video_buffer_set_image(vbuffer, image); gst_vaapi_video_buffer_set_image(vbuffer, image);
else /* We can't use the derive-image optimization. Disable it. */ break;
convert->use_derive_image = FALSE; }
} /* We can't use the derive-image optimization. Disable it. */
if (!image) { convert->direct_rendering = 1;
case 1:
if (!gst_vaapi_video_buffer_set_image_from_pool(vbuffer, convert->images)) if (!gst_vaapi_video_buffer_set_image_from_pool(vbuffer, convert->images))
goto error; goto error;
image = gst_vaapi_video_buffer_get_image(vbuffer); image = gst_vaapi_video_buffer_get_image(vbuffer);
break;
} }
g_assert(image); g_assert(image);
@ -609,7 +586,7 @@ error:
/* We can't use the inout-buffers optimization. Disable it. */ /* We can't use the inout-buffers optimization. Disable it. */
if (buffer) if (buffer)
gst_buffer_unref(buffer); gst_buffer_unref(buffer);
convert->use_inout_buffers = FALSE; convert->direct_rendering = 0;
return GST_FLOW_OK; return GST_FLOW_OK;
} }
@ -649,9 +626,9 @@ gst_vaapiconvert_prepare_output_buffer(
if (GST_VAAPI_IS_VIDEO_BUFFER(inbuf)) if (GST_VAAPI_IS_VIDEO_BUFFER(inbuf))
buffer = gst_buffer_ref(inbuf); buffer = gst_buffer_ref(inbuf);
else { else {
if (convert->use_inout_buffers) { if (convert->direct_rendering) {
GST_DEBUG("upstream element destroyed our inout buffer"); GST_DEBUG("upstream element destroyed our inout buffer");
convert->use_inout_buffers = FALSE; convert->direct_rendering = 0;
} }
buffer = gst_vaapi_video_buffer_new_from_pool(convert->surfaces); buffer = gst_vaapi_video_buffer_new_from_pool(convert->surfaces);
if (!buffer) if (!buffer)

View file

@ -71,12 +71,8 @@ struct _GstVaapiConvert {
GstVaapiVideoPool *surfaces; GstVaapiVideoPool *surfaces;
guint surface_width; guint surface_width;
guint surface_height; guint surface_height;
guint allow_use_inout_buffers : 1; guint direct_rendering_caps;
guint can_use_inout_buffers : 1; guint direct_rendering;
guint use_inout_buffers : 1;
guint allow_use_derive_image : 1;
guint can_use_derive_image : 1;
guint use_derive_image : 1;
}; };
struct _GstVaapiConvertClass { struct _GstVaapiConvertClass {