From: Gwenole Beauchesne Date: Thu, 4 Aug 2011 15:29:41 +0000 (+0200) Subject: Add VA buffer helpers. X-Git-Tag: accepted/trunk/20120822.173359~232 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e0913aaf0e953bd2bbdabf03ebaee02e3bfb0651;p=profile%2Fivi%2Fgstreamer-vaapi.git Add VA buffer helpers. --- diff --git a/gst-libs/gst/vaapi/gstvaapiutils.c b/gst-libs/gst/vaapi/gstvaapiutils.c index bdc2b12..5e6eb6e 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils.c +++ b/gst-libs/gst/vaapi/gstvaapiutils.c @@ -47,6 +47,74 @@ vaapi_check_status(VAStatus status, const char *msg) return TRUE; } +/* Maps VA buffer */ +void * +vaapi_map_buffer(VADisplay dpy, VABufferID buf_id) +{ + VAStatus status; + void *data = NULL; + + status = vaMapBuffer(dpy, buf_id, &data); + if (!vaapi_check_status(status, "vaMapBuffer()")) + return NULL; + return data; +} + +/* Unmaps VA buffer */ +void +vaapi_unmap_buffer(VADisplay dpy, VABufferID buf_id, void **pbuf) +{ + VAStatus status; + + if (pbuf) + *pbuf = NULL; + + status = vaUnmapBuffer(dpy, buf_id); + if (!vaapi_check_status(status, "vaUnmapBuffer()")) + return; +} + +/* Creates and maps VA buffer */ +void * +vaapi_create_buffer( + VADisplay dpy, + VAContextID ctx, + int type, + unsigned int size, + VABufferID *buf_id_ptr +) +{ + VABufferID buf_id; + VAStatus status; + void *data; + + status = vaCreateBuffer(dpy, ctx, type, size, 1, NULL, &buf_id); + if (!vaapi_check_status(status, "vaCreateBuffer()")) + return NULL; + + data = vaapi_map_buffer(dpy, buf_id); + if (!data) + goto error; + + *buf_id_ptr = buf_id; + return data; + +error: + vaapi_destroy_buffer(dpy, &buf_id); + return NULL; +} + +/* Destroy VA buffer */ +void +vaapi_destroy_buffer(VADisplay dpy, VABufferID *buf_id_ptr) +{ + if (!buf_id_ptr || *buf_id_ptr == VA_INVALID_ID) + return; + + vaDestroyBuffer(dpy, *buf_id_ptr); + *buf_id_ptr = VA_INVALID_ID; +} + /* Return a string representation of a VAProfile */ const char *string_of_VAProfile(VAProfile profile) { diff --git a/gst-libs/gst/vaapi/gstvaapiutils.h b/gst-libs/gst/vaapi/gstvaapiutils.h index 7d45d3e..c626429 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils.h +++ b/gst-libs/gst/vaapi/gstvaapiutils.h @@ -36,6 +36,31 @@ gboolean vaapi_check_status(VAStatus status, const char *msg) attribute_hidden; +/** Maps VA buffer */ +void * +vaapi_map_buffer(VADisplay dpy, VABufferID buf_id) + attribute_hidden; + +/** Unmaps VA buffer */ +void +vaapi_unmap_buffer(VADisplay dpy, VABufferID buf_id, void **pbuf) + attribute_hidden; + +/** Creates and maps VA buffer */ +void * +vaapi_create_buffer( + VADisplay dpy, + VAContextID ctx, + int type, + unsigned int size, + VABufferID *buf_id +) attribute_hidden; + +/** Destroy VA buffer */ +void +vaapi_destroy_buffer(VADisplay dpy, VABufferID *buf_id) + attribute_hidden; + /** Return a string representation of a VAProfile */ const char *string_of_VAProfile(VAProfile profile) attribute_hidden;