surface: re-indent all GstVaapiSurface related source code.

This commit is contained in:
Gwenole Beauchesne 2014-09-15 14:57:57 +02:00
parent 568a62ae1e
commit 334dd704b6
3 changed files with 479 additions and 561 deletions

View file

@ -41,85 +41,74 @@
#include "gstvaapidebug.h"
static gboolean
_gst_vaapi_surface_associate_subpicture(
GstVaapiSurface *surface,
GstVaapiSubpicture *subpicture,
const GstVaapiRectangle *src_rect,
const GstVaapiRectangle *dst_rect
);
_gst_vaapi_surface_associate_subpicture (GstVaapiSurface * surface,
GstVaapiSubpicture * subpicture, const GstVaapiRectangle * src_rect,
const GstVaapiRectangle * dst_rect);
static gboolean
_gst_vaapi_surface_deassociate_subpicture(
GstVaapiSurface *surface,
GstVaapiSubpicture *subpicture
);
_gst_vaapi_surface_deassociate_subpicture (GstVaapiSurface * surface,
GstVaapiSubpicture * subpicture);
static void
destroy_subpicture_cb(gpointer subpicture, gpointer surface)
destroy_subpicture_cb (gpointer subpicture, gpointer surface)
{
_gst_vaapi_surface_deassociate_subpicture(surface, subpicture);
gst_vaapi_object_unref(subpicture);
_gst_vaapi_surface_deassociate_subpicture (surface, subpicture);
gst_vaapi_object_unref (subpicture);
}
static void
gst_vaapi_surface_destroy_subpictures(GstVaapiSurface *surface)
gst_vaapi_surface_destroy_subpictures (GstVaapiSurface * surface)
{
if (surface->subpictures) {
g_ptr_array_foreach(surface->subpictures, destroy_subpicture_cb,
surface);
g_ptr_array_free(surface->subpictures, TRUE);
g_ptr_array_foreach (surface->subpictures, destroy_subpicture_cb, surface);
g_ptr_array_free (surface->subpictures, TRUE);
surface->subpictures = NULL;
}
}
static void
gst_vaapi_surface_destroy(GstVaapiSurface *surface)
gst_vaapi_surface_destroy (GstVaapiSurface * surface)
{
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_DISPLAY(surface);
GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (surface);
VASurfaceID surface_id;
VAStatus status;
surface_id = GST_VAAPI_OBJECT_ID(surface);
GST_DEBUG("surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS(surface_id));
surface_id = GST_VAAPI_OBJECT_ID (surface);
GST_DEBUG ("surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS (surface_id));
gst_vaapi_surface_destroy_subpictures(surface);
gst_vaapi_surface_set_parent_context(surface, NULL);
gst_vaapi_surface_destroy_subpictures (surface);
gst_vaapi_surface_set_parent_context (surface, NULL);
if (surface_id != VA_INVALID_SURFACE) {
GST_VAAPI_DISPLAY_LOCK(display);
status = vaDestroySurfaces(
GST_VAAPI_DISPLAY_VADISPLAY(display),
&surface_id, 1
);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaDestroySurfaces()"))
g_warning("failed to destroy surface %" GST_VAAPI_ID_FORMAT,
GST_VAAPI_ID_ARGS(surface_id));
GST_VAAPI_OBJECT_ID(surface) = VA_INVALID_SURFACE;
GST_VAAPI_DISPLAY_LOCK (display);
status = vaDestroySurfaces (GST_VAAPI_DISPLAY_VADISPLAY (display),
&surface_id, 1);
GST_VAAPI_DISPLAY_UNLOCK (display);
if (!vaapi_check_status (status, "vaDestroySurfaces()"))
g_warning ("failed to destroy surface %" GST_VAAPI_ID_FORMAT,
GST_VAAPI_ID_ARGS (surface_id));
GST_VAAPI_OBJECT_ID (surface) = VA_INVALID_SURFACE;
}
}
static gboolean
gst_vaapi_surface_create(GstVaapiSurface *surface,
gst_vaapi_surface_create (GstVaapiSurface * surface,
GstVaapiChromaType chroma_type, guint width, guint height)
{
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_DISPLAY(surface);
GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (surface);
VASurfaceID surface_id;
VAStatus status;
guint va_chroma_format;
va_chroma_format = from_GstVaapiChromaType(chroma_type);
va_chroma_format = from_GstVaapiChromaType (chroma_type);
if (!va_chroma_format)
goto error_unsupported_chroma_type;
GST_VAAPI_DISPLAY_LOCK(display);
status = vaCreateSurfaces(
GST_VAAPI_DISPLAY_VADISPLAY(display),
width, height, va_chroma_format,
1, &surface_id
);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaCreateSurfaces()"))
GST_VAAPI_DISPLAY_LOCK (display);
status = vaCreateSurfaces (GST_VAAPI_DISPLAY_VADISPLAY (display),
width, height, va_chroma_format, 1, &surface_id);
GST_VAAPI_DISPLAY_UNLOCK (display);
if (!vaapi_check_status (status, "vaCreateSurfaces()"))
return FALSE;
surface->format = GST_VIDEO_FORMAT_UNKNOWN;
@ -127,37 +116,37 @@ gst_vaapi_surface_create(GstVaapiSurface *surface,
surface->width = width;
surface->height = height;
GST_DEBUG("surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS(surface_id));
GST_VAAPI_OBJECT_ID(surface) = surface_id;
GST_DEBUG ("surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS (surface_id));
GST_VAAPI_OBJECT_ID (surface) = surface_id;
return TRUE;
/* ERRORS */
error_unsupported_chroma_type:
GST_ERROR("unsupported chroma-type %u", chroma_type);
GST_ERROR ("unsupported chroma-type %u", chroma_type);
return FALSE;
}
static gboolean
gst_vaapi_surface_create_with_format(GstVaapiSurface *surface,
gst_vaapi_surface_create_with_format (GstVaapiSurface * surface,
GstVideoFormat format, guint width, guint height)
{
#if VA_CHECK_VERSION(0,34,0)
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_DISPLAY(surface);
GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (surface);
VASurfaceID surface_id;
VAStatus status;
guint chroma_type, va_chroma_format;
const VAImageFormat *va_format;
VASurfaceAttrib attrib;
va_format = gst_vaapi_video_format_to_va_format(format);
va_format = gst_vaapi_video_format_to_va_format (format);
if (!va_format)
goto error_unsupported_format;
chroma_type = gst_vaapi_video_format_get_chroma_type(format);
chroma_type = gst_vaapi_video_format_get_chroma_type (format);
if (!chroma_type)
goto error_unsupported_format;
va_chroma_format = from_GstVaapiChromaType(chroma_type);
va_chroma_format = from_GstVaapiChromaType (chroma_type);
if (!va_chroma_format)
goto error_unsupported_format;
@ -166,15 +155,11 @@ gst_vaapi_surface_create_with_format(GstVaapiSurface *surface,
attrib.value.type = VAGenericValueTypeInteger;
attrib.value.value.i = va_format->fourcc;
GST_VAAPI_DISPLAY_LOCK(display);
status = vaCreateSurfaces(
GST_VAAPI_DISPLAY_VADISPLAY(display),
va_chroma_format, width, height,
&surface_id, 1,
&attrib, 1
);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaCreateSurfaces()"))
GST_VAAPI_DISPLAY_LOCK (display);
status = vaCreateSurfaces (GST_VAAPI_DISPLAY_VADISPLAY (display),
va_chroma_format, width, height, &surface_id, 1, &attrib, 1);
GST_VAAPI_DISPLAY_UNLOCK (display);
if (!vaapi_check_status (status, "vaCreateSurfaces()"))
return FALSE;
surface->format = format;
@ -182,13 +167,14 @@ gst_vaapi_surface_create_with_format(GstVaapiSurface *surface,
surface->width = width;
surface->height = height;
GST_DEBUG("surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS(surface_id));
GST_VAAPI_OBJECT_ID(surface) = surface_id;
GST_DEBUG ("surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS (surface_id));
GST_VAAPI_OBJECT_ID (surface) = surface_id;
return TRUE;
/* ERRORS */
error_unsupported_format:
GST_ERROR("unsupported format %s", gst_vaapi_video_format_to_string(format));
GST_ERROR ("unsupported format %s",
gst_vaapi_video_format_to_string (format));
return FALSE;
#else
return FALSE;
@ -196,7 +182,7 @@ error_unsupported_format:
}
#define gst_vaapi_surface_finalize gst_vaapi_surface_destroy
GST_VAAPI_OBJECT_DEFINE_CLASS(GstVaapiSurface, gst_vaapi_surface)
GST_VAAPI_OBJECT_DEFINE_CLASS (GstVaapiSurface, gst_vaapi_surface);
/**
* gst_vaapi_surface_new:
@ -211,27 +197,23 @@ GST_VAAPI_OBJECT_DEFINE_CLASS(GstVaapiSurface, gst_vaapi_surface)
* Return value: the newly allocated #GstVaapiSurface object
*/
GstVaapiSurface *
gst_vaapi_surface_new(
GstVaapiDisplay *display,
GstVaapiChromaType chroma_type,
guint width,
guint height
)
gst_vaapi_surface_new (GstVaapiDisplay * display,
GstVaapiChromaType chroma_type, guint width, guint height)
{
GstVaapiSurface *surface;
GST_DEBUG("size %ux%u, chroma type 0x%x", width, height, chroma_type);
GST_DEBUG ("size %ux%u, chroma type 0x%x", width, height, chroma_type);
surface = gst_vaapi_object_new(gst_vaapi_surface_class(), display);
surface = gst_vaapi_object_new (gst_vaapi_surface_class (), display);
if (!surface)
return NULL;
if (!gst_vaapi_surface_create(surface, chroma_type, width, height))
if (!gst_vaapi_surface_create (surface, chroma_type, width, height))
goto error;
return surface;
error:
gst_vaapi_object_unref(surface);
gst_vaapi_object_unref (surface);
return NULL;
}
@ -250,28 +232,24 @@ error:
* supported or failed.
*/
GstVaapiSurface *
gst_vaapi_surface_new_with_format(
GstVaapiDisplay *display,
GstVideoFormat format,
guint width,
guint height
)
gst_vaapi_surface_new_with_format (GstVaapiDisplay * display,
GstVideoFormat format, guint width, guint height)
{
GstVaapiSurface *surface;
GST_DEBUG("size %ux%u, format %s", width, height,
gst_vaapi_video_format_to_string(format));
GST_DEBUG ("size %ux%u, format %s", width, height,
gst_vaapi_video_format_to_string (format));
surface = gst_vaapi_object_new(gst_vaapi_surface_class(), display);
surface = gst_vaapi_object_new (gst_vaapi_surface_class (), display);
if (!surface)
return NULL;
if (!gst_vaapi_surface_create_with_format(surface, format, width, height))
if (!gst_vaapi_surface_create_with_format (surface, format, width, height))
goto error;
return surface;
error:
gst_vaapi_object_unref(surface);
gst_vaapi_object_unref (surface);
return NULL;
}
@ -284,11 +262,11 @@ error:
* Return value: the underlying VA surface id
*/
GstVaapiID
gst_vaapi_surface_get_id(GstVaapiSurface *surface)
gst_vaapi_surface_get_id (GstVaapiSurface * surface)
{
g_return_val_if_fail(surface != NULL, VA_INVALID_SURFACE);
g_return_val_if_fail (surface != NULL, VA_INVALID_SURFACE);
return GST_VAAPI_OBJECT_ID(surface);
return GST_VAAPI_OBJECT_ID (surface);
}
/**
@ -300,11 +278,11 @@ gst_vaapi_surface_get_id(GstVaapiSurface *surface)
* Return value: the #GstVaapiChromaType
*/
GstVaapiChromaType
gst_vaapi_surface_get_chroma_type(GstVaapiSurface *surface)
gst_vaapi_surface_get_chroma_type (GstVaapiSurface * surface)
{
g_return_val_if_fail(surface != NULL, 0);
g_return_val_if_fail (surface != NULL, 0);
return GST_VAAPI_SURFACE_CHROMA_TYPE(surface);
return GST_VAAPI_SURFACE_CHROMA_TYPE (surface);
}
/**
@ -318,21 +296,21 @@ gst_vaapi_surface_get_chroma_type(GstVaapiSurface *surface)
* the underlying video format could not be determined
*/
GstVideoFormat
gst_vaapi_surface_get_format(GstVaapiSurface *surface)
gst_vaapi_surface_get_format (GstVaapiSurface * surface)
{
g_return_val_if_fail(surface != NULL, 0);
g_return_val_if_fail (surface != NULL, 0);
/* Try to determine the underlying VA surface format */
if (surface->format == GST_VIDEO_FORMAT_UNKNOWN) {
GstVaapiImage * const image = gst_vaapi_surface_derive_image(surface);
GstVaapiImage *const image = gst_vaapi_surface_derive_image (surface);
if (image) {
surface->format = GST_VAAPI_IMAGE_FORMAT(image);
gst_vaapi_object_unref(image);
surface->format = GST_VAAPI_IMAGE_FORMAT (image);
gst_vaapi_object_unref (image);
}
if (surface->format == GST_VIDEO_FORMAT_UNKNOWN)
surface->format = GST_VIDEO_FORMAT_ENCODED;
}
return GST_VAAPI_SURFACE_FORMAT(surface);
return GST_VAAPI_SURFACE_FORMAT (surface);
}
/**
@ -344,11 +322,11 @@ gst_vaapi_surface_get_format(GstVaapiSurface *surface)
* Return value: the surface width, in pixels
*/
guint
gst_vaapi_surface_get_width(GstVaapiSurface *surface)
gst_vaapi_surface_get_width (GstVaapiSurface * surface)
{
g_return_val_if_fail(surface != NULL, 0);
g_return_val_if_fail (surface != NULL, 0);
return GST_VAAPI_SURFACE_WIDTH(surface);
return GST_VAAPI_SURFACE_WIDTH (surface);
}
/**
@ -360,35 +338,32 @@ gst_vaapi_surface_get_width(GstVaapiSurface *surface)
* Return value: the surface height, in pixels.
*/
guint
gst_vaapi_surface_get_height(GstVaapiSurface *surface)
gst_vaapi_surface_get_height (GstVaapiSurface * surface)
{
g_return_val_if_fail(surface != NULL, 0);
g_return_val_if_fail (surface != NULL, 0);
return GST_VAAPI_SURFACE_HEIGHT(surface);
return GST_VAAPI_SURFACE_HEIGHT (surface);
}
/**
* gst_vaapi_surface_get_size:
* @surface: a #GstVaapiSurface
* @pwidth: return location for the width, or %NULL
* @pheight: return location for the height, or %NULL
* @width_ptr: return location for the width, or %NULL
* @height_ptr: return location for the height, or %NULL
*
* Retrieves the dimensions of a #GstVaapiSurface.
*/
void
gst_vaapi_surface_get_size(
GstVaapiSurface *surface,
guint *pwidth,
guint *pheight
)
gst_vaapi_surface_get_size (GstVaapiSurface * surface,
guint * width_ptr, guint * height_ptr)
{
g_return_if_fail(surface != NULL);
g_return_if_fail (surface != NULL);
if (pwidth)
*pwidth = GST_VAAPI_SURFACE_WIDTH(surface);
if (width_ptr)
*width_ptr = GST_VAAPI_SURFACE_WIDTH (surface);
if (pheight)
*pheight = GST_VAAPI_SURFACE_HEIGHT(surface);
if (height_ptr)
*height_ptr = GST_VAAPI_SURFACE_HEIGHT (surface);
}
/**
@ -401,12 +376,10 @@ gst_vaapi_surface_get_size(
* which will be released when the surface is destroyed.
*/
void
gst_vaapi_surface_set_parent_context(
GstVaapiSurface *surface,
GstVaapiContext *context
)
gst_vaapi_surface_set_parent_context (GstVaapiSurface * surface,
GstVaapiContext * context)
{
g_return_if_fail(surface != NULL);
g_return_if_fail (surface != NULL);
surface->parent_context = NULL;
}
@ -422,9 +395,9 @@ gst_vaapi_surface_set_parent_context(
* Return value: the parent context, if any.
*/
GstVaapiContext *
gst_vaapi_surface_get_parent_context(GstVaapiSurface *surface)
gst_vaapi_surface_get_parent_context (GstVaapiSurface * surface)
{
g_return_val_if_fail(surface != NULL, NULL);
g_return_val_if_fail (surface != NULL, NULL);
return surface->parent_context;
}
@ -454,31 +427,28 @@ gst_vaapi_surface_get_parent_context(GstVaapiSurface *surface)
* on failure
*/
GstVaapiImage *
gst_vaapi_surface_derive_image(GstVaapiSurface *surface)
gst_vaapi_surface_derive_image (GstVaapiSurface * surface)
{
GstVaapiDisplay *display;
VAImage va_image;
VAStatus status;
g_return_val_if_fail(surface != NULL, NULL);
g_return_val_if_fail (surface != NULL, NULL);
display = GST_VAAPI_OBJECT_DISPLAY(surface);
display = GST_VAAPI_OBJECT_DISPLAY (surface);
va_image.image_id = VA_INVALID_ID;
va_image.buf = VA_INVALID_ID;
GST_VAAPI_DISPLAY_LOCK(display);
status = vaDeriveImage(
GST_VAAPI_DISPLAY_VADISPLAY(display),
GST_VAAPI_OBJECT_ID(surface),
&va_image
);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaDeriveImage()"))
GST_VAAPI_DISPLAY_LOCK (display);
status = vaDeriveImage (GST_VAAPI_DISPLAY_VADISPLAY (display),
GST_VAAPI_OBJECT_ID (surface), &va_image);
GST_VAAPI_DISPLAY_UNLOCK (display);
if (!vaapi_check_status (status, "vaDeriveImage()"))
return NULL;
if (va_image.image_id == VA_INVALID_ID || va_image.buf == VA_INVALID_ID)
return NULL;
return gst_vaapi_image_new_with_image(display, &va_image);
return gst_vaapi_image_new_with_image (display, &va_image);
}
/**
@ -492,38 +462,34 @@ gst_vaapi_surface_derive_image(GstVaapiSurface *surface)
* Return value: %TRUE on success
*/
gboolean
gst_vaapi_surface_get_image(GstVaapiSurface *surface, GstVaapiImage *image)
gst_vaapi_surface_get_image (GstVaapiSurface * surface, GstVaapiImage * image)
{
GstVaapiDisplay *display;
VAImageID image_id;
VAStatus status;
guint width, height;
g_return_val_if_fail(surface != NULL, FALSE);
g_return_val_if_fail(image != NULL, FALSE);
g_return_val_if_fail (surface != NULL, FALSE);
g_return_val_if_fail (image != NULL, FALSE);
display = GST_VAAPI_OBJECT_DISPLAY(surface);
display = GST_VAAPI_OBJECT_DISPLAY (surface);
if (!display)
return FALSE;
width = GST_VAAPI_IMAGE_WIDTH(image);
height = GST_VAAPI_IMAGE_HEIGHT(image);
width = GST_VAAPI_IMAGE_WIDTH (image);
height = GST_VAAPI_IMAGE_HEIGHT (image);
if (width != surface->width || height != surface->height)
return FALSE;
image_id = GST_VAAPI_OBJECT_ID(image);
image_id = GST_VAAPI_OBJECT_ID (image);
if (image_id == VA_INVALID_ID)
return FALSE;
GST_VAAPI_DISPLAY_LOCK(display);
status = vaGetImage(
GST_VAAPI_DISPLAY_VADISPLAY(display),
GST_VAAPI_OBJECT_ID(surface),
0, 0, width, height,
image_id
);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaGetImage()"))
GST_VAAPI_DISPLAY_LOCK (display);
status = vaGetImage (GST_VAAPI_DISPLAY_VADISPLAY (display),
GST_VAAPI_OBJECT_ID (surface), 0, 0, width, height, image_id);
GST_VAAPI_DISPLAY_UNLOCK (display);
if (!vaapi_check_status (status, "vaGetImage()"))
return FALSE;
return TRUE;
@ -540,39 +506,35 @@ gst_vaapi_surface_get_image(GstVaapiSurface *surface, GstVaapiImage *image)
* Return value: %TRUE on success
*/
gboolean
gst_vaapi_surface_put_image(GstVaapiSurface *surface, GstVaapiImage *image)
gst_vaapi_surface_put_image (GstVaapiSurface * surface, GstVaapiImage * image)
{
GstVaapiDisplay *display;
VAImageID image_id;
VAStatus status;
guint width, height;
g_return_val_if_fail(surface != NULL, FALSE);
g_return_val_if_fail(image != NULL, FALSE);
g_return_val_if_fail (surface != NULL, FALSE);
g_return_val_if_fail (image != NULL, FALSE);
display = GST_VAAPI_OBJECT_DISPLAY(surface);
display = GST_VAAPI_OBJECT_DISPLAY (surface);
if (!display)
return FALSE;
width = GST_VAAPI_IMAGE_WIDTH(image);
height = GST_VAAPI_IMAGE_HEIGHT(image);
width = GST_VAAPI_IMAGE_WIDTH (image);
height = GST_VAAPI_IMAGE_HEIGHT (image);
if (width != surface->width || height != surface->height)
return FALSE;
image_id = GST_VAAPI_OBJECT_ID(image);
image_id = GST_VAAPI_OBJECT_ID (image);
if (image_id == VA_INVALID_ID)
return FALSE;
GST_VAAPI_DISPLAY_LOCK(display);
status = vaPutImage(
GST_VAAPI_DISPLAY_VADISPLAY(display),
GST_VAAPI_OBJECT_ID(surface),
image_id,
0, 0, width, height,
0, 0, width, height
);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaPutImage()"))
GST_VAAPI_DISPLAY_LOCK (display);
status = vaPutImage (GST_VAAPI_DISPLAY_VADISPLAY (display),
GST_VAAPI_OBJECT_ID (surface), image_id, 0, 0, width, height,
0, 0, width, height);
GST_VAAPI_DISPLAY_UNLOCK (display);
if (!vaapi_check_status (status, "vaPutImage()"))
return FALSE;
return TRUE;
@ -597,52 +559,41 @@ gst_vaapi_surface_put_image(GstVaapiSurface *surface, GstVaapiImage *image)
* Return value: %TRUE on success
*/
gboolean
gst_vaapi_surface_associate_subpicture(
GstVaapiSurface *surface,
GstVaapiSubpicture *subpicture,
const GstVaapiRectangle *src_rect,
const GstVaapiRectangle *dst_rect
)
gst_vaapi_surface_associate_subpicture (GstVaapiSurface * surface,
GstVaapiSubpicture * subpicture,
const GstVaapiRectangle * src_rect, const GstVaapiRectangle * dst_rect)
{
gboolean success;
g_return_val_if_fail(surface != NULL, FALSE);
g_return_val_if_fail(subpicture != NULL, FALSE);
g_return_val_if_fail (surface != NULL, FALSE);
g_return_val_if_fail (subpicture != NULL, FALSE);
if (!surface->subpictures) {
surface->subpictures = g_ptr_array_new();
surface->subpictures = g_ptr_array_new ();
if (!surface->subpictures)
return FALSE;
}
if (g_ptr_array_remove_fast(surface->subpictures, subpicture)) {
success = _gst_vaapi_surface_deassociate_subpicture(surface,
subpicture);
gst_vaapi_object_unref(subpicture);
if (g_ptr_array_remove_fast (surface->subpictures, subpicture)) {
success = _gst_vaapi_surface_deassociate_subpicture (surface, subpicture);
gst_vaapi_object_unref (subpicture);
if (!success)
return FALSE;
}
success = _gst_vaapi_surface_associate_subpicture(
surface,
subpicture,
src_rect,
dst_rect
);
success = _gst_vaapi_surface_associate_subpicture (surface,
subpicture, src_rect, dst_rect);
if (!success)
return FALSE;
g_ptr_array_add(surface->subpictures, gst_vaapi_object_ref(subpicture));
g_ptr_array_add (surface->subpictures, gst_vaapi_object_ref (subpicture));
return TRUE;
}
gboolean
_gst_vaapi_surface_associate_subpicture(
GstVaapiSurface *surface,
GstVaapiSubpicture *subpicture,
const GstVaapiRectangle *src_rect,
const GstVaapiRectangle *dst_rect
)
_gst_vaapi_surface_associate_subpicture (GstVaapiSurface * surface,
GstVaapiSubpicture * subpicture,
const GstVaapiRectangle * src_rect, const GstVaapiRectangle * dst_rect)
{
GstVaapiDisplay *display;
GstVaapiRectangle src_rect_default, dst_rect_default;
@ -650,23 +601,23 @@ _gst_vaapi_surface_associate_subpicture(
VASurfaceID surface_id;
VAStatus status;
display = GST_VAAPI_OBJECT_DISPLAY(surface);
display = GST_VAAPI_OBJECT_DISPLAY (surface);
if (!display)
return FALSE;
surface_id = GST_VAAPI_OBJECT_ID(surface);
surface_id = GST_VAAPI_OBJECT_ID (surface);
if (surface_id == VA_INVALID_SURFACE)
return FALSE;
if (!src_rect) {
image = gst_vaapi_subpicture_get_image(subpicture);
image = gst_vaapi_subpicture_get_image (subpicture);
if (!image)
return FALSE;
src_rect = &src_rect_default;
src_rect_default.x = 0;
src_rect_default.y = 0;
src_rect_default.width = GST_VAAPI_IMAGE_WIDTH(image);
src_rect_default.height = GST_VAAPI_IMAGE_HEIGHT(image);
src_rect_default.width = GST_VAAPI_IMAGE_WIDTH (image);
src_rect_default.height = GST_VAAPI_IMAGE_HEIGHT (image);
}
if (!dst_rect) {
@ -677,17 +628,15 @@ _gst_vaapi_surface_associate_subpicture(
dst_rect_default.height = surface->height;
}
GST_VAAPI_DISPLAY_LOCK(display);
status = vaAssociateSubpicture(
GST_VAAPI_DISPLAY_VADISPLAY(display),
GST_VAAPI_OBJECT_ID(subpicture),
&surface_id, 1,
GST_VAAPI_DISPLAY_LOCK (display);
status = vaAssociateSubpicture (GST_VAAPI_DISPLAY_VADISPLAY (display),
GST_VAAPI_OBJECT_ID (subpicture), &surface_id, 1,
src_rect->x, src_rect->y, src_rect->width, src_rect->height,
dst_rect->x, dst_rect->y, dst_rect->width, dst_rect->height,
from_GstVaapiSubpictureFlags(gst_vaapi_subpicture_get_flags(subpicture))
);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaAssociateSubpicture()"))
from_GstVaapiSubpictureFlags (gst_vaapi_subpicture_get_flags
(subpicture)));
GST_VAAPI_DISPLAY_UNLOCK (display);
if (!vaapi_check_status (status, "vaAssociateSubpicture()"))
return FALSE;
return TRUE;
@ -703,59 +652,52 @@ _gst_vaapi_surface_associate_subpicture(
* Return value: %TRUE on success
*/
gboolean
gst_vaapi_surface_deassociate_subpicture(
GstVaapiSurface *surface,
GstVaapiSubpicture *subpicture
)
gst_vaapi_surface_deassociate_subpicture (GstVaapiSurface * surface,
GstVaapiSubpicture * subpicture)
{
gboolean success;
g_return_val_if_fail(surface != NULL, FALSE);
g_return_val_if_fail(subpicture != NULL, FALSE);
g_return_val_if_fail (surface != NULL, FALSE);
g_return_val_if_fail (subpicture != NULL, FALSE);
if (!surface->subpictures)
return TRUE;
/* First, check subpicture was really associated with this surface */
if (!g_ptr_array_remove_fast(surface->subpictures, subpicture)) {
GST_DEBUG("subpicture %" GST_VAAPI_ID_FORMAT " was not bound to "
if (!g_ptr_array_remove_fast (surface->subpictures, subpicture)) {
GST_DEBUG ("subpicture %" GST_VAAPI_ID_FORMAT " was not bound to "
"surface %" GST_VAAPI_ID_FORMAT,
GST_VAAPI_ID_ARGS(GST_VAAPI_OBJECT_ID(subpicture)),
GST_VAAPI_ID_ARGS(GST_VAAPI_OBJECT_ID(surface)));
GST_VAAPI_ID_ARGS (GST_VAAPI_OBJECT_ID (subpicture)),
GST_VAAPI_ID_ARGS (GST_VAAPI_OBJECT_ID (surface)));
return TRUE;
}
success = _gst_vaapi_surface_deassociate_subpicture(surface, subpicture);
gst_vaapi_object_unref(subpicture);
success = _gst_vaapi_surface_deassociate_subpicture (surface, subpicture);
gst_vaapi_object_unref (subpicture);
return success;
}
gboolean
_gst_vaapi_surface_deassociate_subpicture(
GstVaapiSurface *surface,
GstVaapiSubpicture *subpicture
)
_gst_vaapi_surface_deassociate_subpicture (GstVaapiSurface * surface,
GstVaapiSubpicture * subpicture)
{
GstVaapiDisplay *display;
VASurfaceID surface_id;
VAStatus status;
display = GST_VAAPI_OBJECT_DISPLAY(surface);
display = GST_VAAPI_OBJECT_DISPLAY (surface);
if (!display)
return FALSE;
surface_id = GST_VAAPI_OBJECT_ID(surface);
surface_id = GST_VAAPI_OBJECT_ID (surface);
if (surface_id == VA_INVALID_SURFACE)
return FALSE;
GST_VAAPI_DISPLAY_LOCK(display);
status = vaDeassociateSubpicture(
GST_VAAPI_DISPLAY_VADISPLAY(display),
GST_VAAPI_OBJECT_ID(subpicture),
&surface_id, 1
);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaDeassociateSubpicture()"))
GST_VAAPI_DISPLAY_LOCK (display);
status = vaDeassociateSubpicture (GST_VAAPI_DISPLAY_VADISPLAY (display),
GST_VAAPI_OBJECT_ID (subpicture), &surface_id, 1);
GST_VAAPI_DISPLAY_UNLOCK (display);
if (!vaapi_check_status (status, "vaDeassociateSubpicture()"))
return FALSE;
return TRUE;
@ -771,24 +713,22 @@ _gst_vaapi_surface_deassociate_subpicture(
* Return value: %TRUE on success
*/
gboolean
gst_vaapi_surface_sync(GstVaapiSurface *surface)
gst_vaapi_surface_sync (GstVaapiSurface * surface)
{
GstVaapiDisplay *display;
VAStatus status;
g_return_val_if_fail(surface != NULL, FALSE);
g_return_val_if_fail (surface != NULL, FALSE);
display = GST_VAAPI_OBJECT_DISPLAY(surface);
display = GST_VAAPI_OBJECT_DISPLAY (surface);
if (!display)
return FALSE;
GST_VAAPI_DISPLAY_LOCK(display);
status = vaSyncSurface(
GST_VAAPI_DISPLAY_VADISPLAY(display),
GST_VAAPI_OBJECT_ID(surface)
);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaSyncSurface()"))
GST_VAAPI_DISPLAY_LOCK (display);
status = vaSyncSurface (GST_VAAPI_DISPLAY_VADISPLAY (display),
GST_VAAPI_OBJECT_ID (surface));
GST_VAAPI_DISPLAY_UNLOCK (display);
if (!vaapi_check_status (status, "vaSyncSurface()"))
return FALSE;
return TRUE;
@ -805,28 +745,23 @@ gst_vaapi_surface_sync(GstVaapiSurface *surface)
* Return value: %TRUE on success
*/
gboolean
gst_vaapi_surface_query_status(
GstVaapiSurface *surface,
GstVaapiSurfaceStatus *pstatus
)
gst_vaapi_surface_query_status (GstVaapiSurface * surface,
GstVaapiSurfaceStatus * pstatus)
{
VASurfaceStatus surface_status;
VAStatus status;
g_return_val_if_fail(surface != NULL, FALSE);
g_return_val_if_fail (surface != NULL, FALSE);
GST_VAAPI_OBJECT_LOCK_DISPLAY(surface);
status = vaQuerySurfaceStatus(
GST_VAAPI_OBJECT_VADISPLAY(surface),
GST_VAAPI_OBJECT_ID(surface),
&surface_status
);
GST_VAAPI_OBJECT_UNLOCK_DISPLAY(surface);
if (!vaapi_check_status(status, "vaQuerySurfaceStatus()"))
GST_VAAPI_OBJECT_LOCK_DISPLAY (surface);
status = vaQuerySurfaceStatus (GST_VAAPI_OBJECT_VADISPLAY (surface),
GST_VAAPI_OBJECT_ID (surface), &surface_status);
GST_VAAPI_OBJECT_UNLOCK_DISPLAY (surface);
if (!vaapi_check_status (status, "vaQuerySurfaceStatus()"))
return FALSE;
if (pstatus)
*pstatus = to_GstVaapiSurfaceStatus(surface_status);
*pstatus = to_GstVaapiSurfaceStatus (surface_status);
return TRUE;
}
@ -844,27 +779,24 @@ gst_vaapi_surface_query_status(
* Return value: %TRUE on success
*/
gboolean
gst_vaapi_surface_set_subpictures_from_composition(
GstVaapiSurface *surface,
GstVideoOverlayComposition *composition,
gboolean propagate_context
)
gst_vaapi_surface_set_subpictures_from_composition (GstVaapiSurface * surface,
GstVideoOverlayComposition * composition, gboolean propagate_context)
{
GstVaapiDisplay *display;
guint n, nb_rectangles;
g_return_val_if_fail(surface != NULL, FALSE);
g_return_val_if_fail (surface != NULL, FALSE);
if (propagate_context && surface->parent_context)
return gst_vaapi_context_apply_composition(surface->parent_context,
return gst_vaapi_context_apply_composition (surface->parent_context,
composition);
display = GST_VAAPI_OBJECT_DISPLAY(surface);
display = GST_VAAPI_OBJECT_DISPLAY (surface);
if (!display)
return FALSE;
/* Clear current subpictures */
gst_vaapi_surface_destroy_subpictures(surface);
gst_vaapi_surface_destroy_subpictures (surface);
if (!composition)
return TRUE;
@ -882,7 +814,7 @@ gst_vaapi_surface_set_subpictures_from_composition(
rect);
gst_video_overlay_rectangle_get_render_rectangle (rect,
(gint *)&sub_rect.x, (gint *)&sub_rect.y,
(gint *) & sub_rect.x, (gint *) & sub_rect.y,
&sub_rect.width, &sub_rect.height);
if (!gst_vaapi_surface_associate_subpicture (surface, subpicture,

View file

@ -67,7 +67,8 @@ G_BEGIN_DECLS
*
* The set of all chroma types for #GstVaapiSurface.
*/
typedef enum {
typedef enum
{
GST_VAAPI_CHROMA_TYPE_YUV420 = 1,
GST_VAAPI_CHROMA_TYPE_YUV422,
GST_VAAPI_CHROMA_TYPE_YUV444,
@ -91,7 +92,8 @@ typedef enum {
*
* The set of all surface status for #GstVaapiSurface.
*/
typedef enum {
typedef enum
{
GST_VAAPI_SURFACE_STATUS_IDLE = 1 << 0,
GST_VAAPI_SURFACE_STATUS_RENDERING = 1 << 1,
GST_VAAPI_SURFACE_STATUS_DISPLAYING = 1 << 2,
@ -121,7 +123,8 @@ typedef enum {
*
* The set of all render flags for gst_vaapi_window_put_surface().
*/
typedef enum {
typedef enum
{
/* Picture structure */
GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD = 0x01 << 0,
GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD = 0x02 << 0,
@ -145,81 +148,60 @@ typedef struct _GstVaapiSurface GstVaapiSurface;
typedef struct _GstVaapiSurfaceProxy GstVaapiSurfaceProxy;
GstVaapiSurface *
gst_vaapi_surface_new(
GstVaapiDisplay *display,
GstVaapiChromaType chroma_type,
guint width,
guint height
);
gst_vaapi_surface_new (GstVaapiDisplay * display,
GstVaapiChromaType chroma_type, guint width, guint height);
GstVaapiSurface *
gst_vaapi_surface_new_with_format(
GstVaapiDisplay *display,
GstVideoFormat format,
guint width,
guint height
);
gst_vaapi_surface_new_with_format (GstVaapiDisplay * display,
GstVideoFormat format, guint width, guint height);
GstVaapiID
gst_vaapi_surface_get_id(GstVaapiSurface *surface);
gst_vaapi_surface_get_id (GstVaapiSurface * surface);
GstVaapiChromaType
gst_vaapi_surface_get_chroma_type(GstVaapiSurface *surface);
gst_vaapi_surface_get_chroma_type (GstVaapiSurface * surface);
GstVideoFormat
gst_vaapi_surface_get_format(GstVaapiSurface *surface);
gst_vaapi_surface_get_format (GstVaapiSurface * surface);
guint
gst_vaapi_surface_get_width(GstVaapiSurface *surface);
gst_vaapi_surface_get_width (GstVaapiSurface * surface);
guint
gst_vaapi_surface_get_height(GstVaapiSurface *surface);
gst_vaapi_surface_get_height (GstVaapiSurface * surface);
void
gst_vaapi_surface_get_size(
GstVaapiSurface *surface,
guint *pwidth,
guint *pheight
);
gst_vaapi_surface_get_size (GstVaapiSurface * surface, guint * width_ptr,
guint * height_ptr);
GstVaapiImage *
gst_vaapi_surface_derive_image(GstVaapiSurface *surface);
gst_vaapi_surface_derive_image (GstVaapiSurface * surface);
gboolean
gst_vaapi_surface_get_image(GstVaapiSurface *surface, GstVaapiImage *image);
gst_vaapi_surface_get_image (GstVaapiSurface * surface, GstVaapiImage * image);
gboolean
gst_vaapi_surface_put_image(GstVaapiSurface *surface, GstVaapiImage *image);
gst_vaapi_surface_put_image (GstVaapiSurface * surface, GstVaapiImage * image);
gboolean
gst_vaapi_surface_associate_subpicture(
GstVaapiSurface *surface,
GstVaapiSubpicture *subpicture,
const GstVaapiRectangle *src_rect,
const GstVaapiRectangle *dst_rect
);
gst_vaapi_surface_associate_subpicture (GstVaapiSurface * surface,
GstVaapiSubpicture * subpicture, const GstVaapiRectangle * src_rect,
const GstVaapiRectangle * dst_rect);
gboolean
gst_vaapi_surface_deassociate_subpicture(
GstVaapiSurface *surface,
GstVaapiSubpicture *subpicture
);
gst_vaapi_surface_deassociate_subpicture (GstVaapiSurface * surface,
GstVaapiSubpicture * subpicture);
gboolean
gst_vaapi_surface_sync(GstVaapiSurface *surface);
gst_vaapi_surface_sync (GstVaapiSurface * surface);
gboolean
gst_vaapi_surface_query_status(
GstVaapiSurface *surface,
GstVaapiSurfaceStatus *pstatus
);
gst_vaapi_surface_query_status (GstVaapiSurface * surface,
GstVaapiSurfaceStatus * pstatus);
gboolean
gst_vaapi_surface_set_subpictures_from_composition(
GstVaapiSurface *surface,
GstVideoOverlayComposition *composition,
gboolean propagate_context
);
gst_vaapi_surface_set_subpictures_from_composition (GstVaapiSurface * surface,
GstVideoOverlayComposition * composition, gboolean propagate_context);
G_END_DECLS

View file

@ -27,6 +27,8 @@
#include <gst/vaapi/gstvaapisurface.h>
#include "gstvaapiobject_priv.h"
G_BEGIN_DECLS
typedef struct _GstVaapiSurfaceClass GstVaapiSurfaceClass;
/**
@ -34,7 +36,8 @@ typedef struct _GstVaapiSurfaceClass GstVaapiSurfaceClass;
*
* A VA surface wrapper.
*/
struct _GstVaapiSurface {
struct _GstVaapiSurface
{
/*< private >*/
GstVaapiObject parent_instance;
@ -51,7 +54,8 @@ struct _GstVaapiSurface {
*
* A VA surface wrapper class.
*/
struct _GstVaapiSurfaceClass {
struct _GstVaapiSurfaceClass
{
/*< private >*/
GstVaapiObjectClass parent_class;
};
@ -66,7 +70,7 @@ struct _GstVaapiSurfaceClass {
*/
#undef GST_VAAPI_SURFACE_CHROMA_TYPE
#define GST_VAAPI_SURFACE_CHROMA_TYPE(surface) \
GST_VAAPI_SURFACE(surface)->chroma_type
(GST_VAAPI_SURFACE (surface)->chroma_type)
/**
* GST_VAAPI_SURFACE_SURFACE_FORMAT:
@ -78,7 +82,7 @@ struct _GstVaapiSurfaceClass {
*/
#undef GST_VAAPI_SURFACE_FORMAT
#define GST_VAAPI_SURFACE_FORMAT(surface) \
GST_VAAPI_SURFACE(surface)->format
(GST_VAAPI_SURFACE (surface)->format)
/**
* GST_VAAPI_SURFACE_SURFACE_WIDTH:
@ -90,7 +94,7 @@ struct _GstVaapiSurfaceClass {
*/
#undef GST_VAAPI_SURFACE_WIDTH
#define GST_VAAPI_SURFACE_WIDTH(surface) \
GST_VAAPI_SURFACE(surface)->width
(GST_VAAPI_SURFACE (surface)->width)
/**
* GST_VAAPI_SURFACE_SURFACE_HEIGHT:
@ -102,17 +106,17 @@ struct _GstVaapiSurfaceClass {
*/
#undef GST_VAAPI_SURFACE_HEIGHT
#define GST_VAAPI_SURFACE_HEIGHT(surface) \
GST_VAAPI_SURFACE(surface)->height
(GST_VAAPI_SURFACE (surface)->height)
G_GNUC_INTERNAL
void
gst_vaapi_surface_set_parent_context(
GstVaapiSurface *surface,
GstVaapiContext *context
);
gst_vaapi_surface_set_parent_context (GstVaapiSurface * surface,
GstVaapiContext * context);
G_GNUC_INTERNAL
GstVaapiContext *
gst_vaapi_surface_get_parent_context(GstVaapiSurface *surface);
gst_vaapi_surface_get_parent_context (GstVaapiSurface * surface);
G_END_DECLS
#endif /* GST_VAAPI_SURFACE_PRIV_H */