From 70074679333c236bca857a0242ae34442a4874f6 Mon Sep 17 00:00:00 2001 From: Austin Yuan Date: Sat, 8 May 2010 02:03:56 +0800 Subject: Seperate 3rd party API (e.g. vaCreateSurfaceFromXXX) into a libva-tpi.so and driver table memory is allocated by driver if driver wants to support it. Signed-off-by: Austin Yuan --- va/Makefile.am | 8 +- va/android/va_android.c | 319 +--------------------------------------------- va/android/va_android.cpp | 2 +- va/va.c | 85 +++--------- va/va.h | 14 -- va/va_backend.h | 34 +++-- va/va_backend_tpi.h | 56 ++++++++ va/va_tpi.c | 99 ++++++++++++++ va/va_tpi.h | 49 +++++++ va/va_trace.c | 6 +- 10 files changed, 247 insertions(+), 425 deletions(-) mode change 100644 => 120000 va/android/va_android.c create mode 100644 va/va_backend_tpi.h create mode 100644 va/va_tpi.c create mode 100644 va/va_tpi.h (limited to 'va') diff --git a/va/Makefile.am b/va/Makefile.am index f57ac42..5241b6a 100644 --- a/va/Makefile.am +++ b/va/Makefile.am @@ -29,12 +29,17 @@ LDADD = \ lib_LTLIBRARIES = \ libva.la \ + libva-tpi.la \ libva-x11.la libva_ladir = $(libdir) libva_la_LDFLAGS = $(LDADD) -no-undefined libva_la_LIBADD = $(LIBVA_LIBS) -ldl +libva_tpi_ladir = $(libdir) +libva_tpi_la_LDFLAGS = $(LDADD) -no-undefined +libva_tpi_la_LIBADD = $(libvacorelib) -ldl + libva_x11_la_SOURCES = libva_x11_la_LIBADD = $(libvacorelib) x11/libva_x11.la $(LIBVA_LIBS) $(X11_LIBS) $(XEXT_LIBS) $(DRM_LIBS) $(XFIXES_LIBS) libva_x11_la_LDFLAGS = $(LDADD) @@ -55,9 +60,10 @@ SUBDIRS += dummy endif libva_la_SOURCES = va.c va_trace.c +libva_tpi_la_SOURCES = va_tpi.c libvaincludedir = ${includedir}/va -libvainclude_HEADERS = va.h va_x11.h va_backend.h va_dummy.h va_version.h +libvainclude_HEADERS = va.h va_tpi.h va_x11.h va_backend.h va_backend_tpi.h va_dummy.h va_version.h DISTCLEANFILES = \ va_version.h diff --git a/va/android/va_android.c b/va/android/va_android.c deleted file mode 100644 index 31f8581..0000000 --- a/va/android/va_android.c +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Copyright (c) 2007 Intel Corporation. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#define _GNU_SOURCE 1 -#include "va.h" -#include "va_backend.h" -#include "va_android.h" -#include "va_dricommon.h" /* needs some helper functions from this file */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifndef ANDROID -#include -#include "drm_test.h" -#endif - -#define CHECK_SYMBOL(func) { if (!func) printf("func %s not found\n", #func); return VA_STATUS_ERROR_UNKNOWN; } -#define DEVICE_NAME "/dev/card0" - -static VADisplayContextP pDisplayContexts = NULL; - -static int open_device (char *dev_name) -{ - struct stat st; - int fd; - - if (-1 == stat (dev_name, &st)) - { - printf ("Cannot identify '%s': %d, %s\n", - dev_name, errno, strerror (errno)); - return -1; - } - - if (!S_ISCHR (st.st_mode)) - { - printf ("%s is no device\n", dev_name); - return -1; - } - - fd = open (dev_name, O_RDWR); - - if (-1 == fd) - { - fprintf (stderr, "Cannot open '%s': %d, %s\n", - dev_name, errno, strerror (errno)); - return -1; - } - - return fd; -} - -static int va_DisplayContextIsValid ( - VADisplayContextP pDisplayContext -) -{ - VADisplayContextP ctx = pDisplayContexts; - - while (ctx) - { - if (ctx == pDisplayContext && pDisplayContext->pDriverContext) - return 1; - ctx = ctx->pNext; - } - return 0; -} - -static void va_DisplayContextDestroy ( - VADisplayContextP pDisplayContext -) -{ - VADisplayContextP *ctx = &pDisplayContexts; - - /* Throw away pDisplayContext */ - while (*ctx) - { - if (*ctx == pDisplayContext) - { - *ctx = pDisplayContext->pNext; - pDisplayContext->pNext = NULL; - break; - } - ctx = &((*ctx)->pNext); - } - free(pDisplayContext->pDriverContext->dri_state); - free(pDisplayContext->pDriverContext); - free(pDisplayContext); -} - -#ifdef ANDROID -static VAStatus va_DisplayContextGetDriverName ( - VADisplayContextP pDisplayContext, - char **driver_name -) -{ - VADriverContextP ctx = pDisplayContext->pDriverContext; - struct dri_state *dri_state = (struct dri_state *)ctx->dri_state; - char *driver_name_env; - int vendor_id, device_id; - - struct { - int vendor_id; - int device_id; - char driver_name[64]; - } devices[] = { - { 0x8086, 0x4100, "pvr" }, - { 0x8086, 0x0130, "pvr" }, - { 0x0, 0x0, "\0" }, - }; - - memset(dri_state, 0, sizeof(*dri_state)); - dri_state->fd = open_device(DEVICE_NAME); - - if (dri_state->fd < 0) { - fprintf(stderr,"can't open DRM devices\n"); - return VA_STATUS_ERROR_UNKNOWN; - } - - if ((driver_name_env = getenv("LIBVA_DRIVER_NAME")) != NULL - && geteuid() == getuid()) { - /* don't allow setuid apps to use LIBVA_DRIVER_NAME */ - *driver_name = strdup(driver_name_env); - return VA_STATUS_SUCCESS; - } else { /* TBD: other vendor driver names */ - vendor_id = devices[0].vendor_id; - device_id = devices[0].device_id; - *driver_name = strdup(devices[0].driver_name); - } - - dri_state->driConnectedFlag = VA_DUMMY; - - return VA_STATUS_SUCCESS; -} -#else -static VAStatus va_DisplayContextGetDriverName ( - VADisplayContextP pDisplayContext, - char **driver_name -) -{ - VADriverContextP ctx = pDisplayContext->pDriverContext; - struct dri_state *dri_state = (struct dri_state *)ctx->dri_state; - char *driver_name_env; - int vendor_id, device_id; - - struct { - int vendor_id; - int device_id; - char driver_name[64]; - } devices[] = { - { 0x8086, 0x4100, "pvr" }, - { 0x8086, 0x0130, "pvr" }, - { 0x0, 0x0, "\0" }, - }; - - memset(dri_state, 0, sizeof(*dri_state)); - dri_state->fd = drm_open_any(&vendor_id, &device_id); - - if (dri_state->fd < 0) { - fprintf(stderr,"can't open DRM devices\n"); - return VA_STATUS_ERROR_UNKNOWN; - } - - if ((driver_name_env = getenv("LIBVA_DRIVER_NAME")) != NULL - && geteuid() == getuid()) { - /* don't allow setuid apps to use LIBVA_DRIVER_NAME */ - *driver_name = strdup(driver_name_env); - return VA_STATUS_SUCCESS; - } else { /* TBD: other vendor driver names */ - int i = 0; - - while (devices[i].device_id != 0) { - if ((devices[i].vendor_id == vendor_id) && - (devices[i].device_id == device_id)) - break; - i++; - } - - if (devices[i].device_id != 0) - *driver_name = strdup(devices[i].driver_name); - else { - fprintf(stderr,"device (0x%04x:0x%04x) is not supported\n", - vendor_id, device_id); - - return VA_STATUS_ERROR_UNKNOWN; - } - } - - printf("DRM device is opened, loading driver %s for device 0x%04x:0x%04x\n", - driver_name, vendor_id, device_id); - - dri_state->driConnectedFlag = VA_DUMMY; - - return VA_STATUS_SUCCESS; -} -#endif - -VADisplay vaGetDisplay ( - void *native_dpy /* implementation specific */ -) -{ - VADisplay dpy = NULL; - VADisplayContextP pDisplayContext = pDisplayContexts; - - if (!native_dpy) - return NULL; - - while (pDisplayContext) - { - if (pDisplayContext->pDriverContext && - pDisplayContext->pDriverContext->native_dpy == (void *)native_dpy) - { - dpy = (VADisplay)pDisplayContext; - break; - } - pDisplayContext = pDisplayContext->pNext; - } - - - if (!dpy) - { - /* create new entry */ - VADriverContextP pDriverContext; - struct dri_state *dri_state; - pDisplayContext = (VADisplayContextP)calloc(1, sizeof(*pDisplayContext)); - pDriverContext = (VADriverContextP)calloc(1, sizeof(*pDriverContext)); - dri_state = calloc(1, sizeof(*dri_state)); - if (pDisplayContext && pDriverContext && dri_state) - { - pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC; - - pDriverContext->native_dpy = (void *)native_dpy; - pDisplayContext->pNext = pDisplayContexts; - pDisplayContext->pDriverContext = pDriverContext; - pDisplayContext->vaIsValid = va_DisplayContextIsValid; - pDisplayContext->vaDestroy = va_DisplayContextDestroy; - pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName; - pDisplayContexts = pDisplayContext; - pDriverContext->dri_state = dri_state; - dpy = (VADisplay)pDisplayContext; - } - else - { - if (pDisplayContext) - free(pDisplayContext); - if (pDriverContext) - free(pDriverContext); - if (dri_state) - free(dri_state); - } - } - - return dpy; -} - -#define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext) -#define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; } - -static int vaDisplayIsValid(VADisplay dpy) -{ - VADisplayContextP pDisplayContext = (VADisplayContextP)dpy; - return pDisplayContext && (pDisplayContext->vadpy_magic == VA_DISPLAY_MAGIC) && pDisplayContext->vaIsValid(pDisplayContext); -} - -#ifdef ANDROID -VAStatus vaPutSurface ( - VADisplay dpy, - VASurfaceID surface, - Surface *draw, /* Android Surface/Window */ - short srcx, - short srcy, - unsigned short srcw, - unsigned short srch, - short destx, - short desty, - unsigned short destw, - unsigned short desth, - VARectangle *cliprects, /* client supplied clip list */ - unsigned int number_cliprects, /* number of clip rects in the clip list */ - unsigned int flags /* de-interlacing flags */ -) -{ - VADriverContextP ctx; - - CHECK_DISPLAY(dpy); - ctx = CTX(dpy); - return ctx->vtable.vaPutSurface( ctx, surface, (void *)draw, srcx, srcy, srcw, srch, - destx, desty, destw, desth, - cliprects, number_cliprects, flags ); -} - -#endif diff --git a/va/android/va_android.c b/va/android/va_android.c new file mode 120000 index 0000000..b47bd16 --- /dev/null +++ b/va/android/va_android.c @@ -0,0 +1 @@ +va_android.cpp \ No newline at end of file diff --git a/va/android/va_android.cpp b/va/android/va_android.cpp index caa6fcb..c9c017d 100644 --- a/va/android/va_android.cpp +++ b/va/android/va_android.cpp @@ -39,7 +39,7 @@ #include #ifndef ANDROID #include -#include "drm_test.h" +#include "drmtest.h" #endif #define CHECK_SYMBOL(func) { if (!func) printf("func %s not found\n", #func); return VA_STATUS_ERROR_UNKNOWN; } diff --git a/va/va.c b/va/va.c index 1917716..def7200 100644 --- a/va/va.c +++ b/va/va.c @@ -679,10 +679,7 @@ VAStatus vaBufferInfo ( CHECK_DISPLAY(dpy); ctx = CTX(dpy); - if (ctx->vtable.vaBufferInfo) - return ctx->vtable.vaBufferInfo( ctx, context, buf_id, type, size, num_elements ); - else - return VA_STATUS_ERROR_UNIMPLEMENTED; + return ctx->vtable.vaBufferInfo( ctx, context, buf_id, type, size, num_elements ); } VAStatus vaBeginPicture ( @@ -1153,67 +1150,7 @@ VAStatus vaSetDisplayAttributes ( return ctx->vtable.vaSetDisplayAttributes ( ctx, attr_list, num_attributes ); } -/* Wrap a CI (camera imaging) frame as a VA surface to share captured video between camear - * and VA encode. With frame_id, VA driver need to call CI interfaces to get the information - * of the frame, and to determine if the frame can be wrapped as a VA surface - * - * Application should make sure the frame is idle before the frame is passed into VA stack - * and also a vaSyncSurface should be called before application tries to access the frame - * from CI stack - */ -VAStatus vaCreateSurfaceFromCIFrame ( - VADisplay dpy, - unsigned long frame_id, - VASurfaceID *surface /* out */ -) -{ - VADriverContextP ctx; - CHECK_DISPLAY(dpy); - ctx = CTX(dpy); - - if (ctx->vtable.vaCreateSurfaceFromCIFrame) - return ctx->vtable.vaCreateSurfaceFromCIFrame( ctx, frame_id, surface ); - else - return VA_STATUS_ERROR_UNIMPLEMENTED; -} - - -/* Wrap a V4L2 buffer as a VA surface, so that V4L2 camera, VA encode - * can share the data without copy - * The VA driver should query the camera device from v4l2_fd to see - * if camera device memory/buffer can be wrapped into a VA surface - * Buffer information is passed in by v4l2_fmt and v4l2_buf structure, - * VA driver also needs do further check if the buffer can meet encode - * hardware requirement, such as dimension, fourcc, stride, etc - * - * Application should make sure the buffer is idle before the frame into VA stack - * and also a vaSyncSurface should be called before application tries to access the frame - * from V4L2 stack - */ -VAStatus vaCreateSurfaceFromV4L2Buf( - VADisplay dpy, - int v4l2_fd, /* file descriptor of V4L2 device */ - struct v4l2_format *v4l2_fmt, /* format of V4L2 */ - struct v4l2_buffer *v4l2_buf, /* V4L2 buffer */ - VASurfaceID *surface /* out */ -) -{ - VADriverContextP ctx; - CHECK_DISPLAY(dpy); - ctx = CTX(dpy); - - if (ctx->vtable.vaCreateSurfaceFromV4L2Buf) - return ctx->vtable.vaCreateSurfaceFromV4L2Buf( ctx, v4l2_fd, v4l2_fmt, v4l2_buf, surface ); - else - return VA_STATUS_ERROR_UNKNOWN; -} - -/* It is a debug interface, and isn't exported in core VAAPI - * It is used to dump surface data into system memory - * Application should explicitly call free to release the buffer memory - */ - -VAStatus vaCopySurfaceToBuffer(VADisplay dpy, +VAStatus vaLockSurface(VADisplay dpy, VASurfaceID surface, unsigned int *fourcc, /* following are output argument */ unsigned int *luma_stride, @@ -1222,6 +1159,7 @@ VAStatus vaCopySurfaceToBuffer(VADisplay dpy, unsigned int *luma_offset, unsigned int *chroma_u_offset, unsigned int *chroma_v_offset, + unsigned int *buffer_name, void **buffer ) { @@ -1229,8 +1167,17 @@ VAStatus vaCopySurfaceToBuffer(VADisplay dpy, CHECK_DISPLAY(dpy); ctx = CTX(dpy); - if (ctx->vtable.vaCopySurfaceToBuffer) - return ctx->vtable.vaCopySurfaceToBuffer( ctx, surface, fourcc, luma_stride, chroma_u_stride, chroma_v_stride, luma_offset, chroma_u_offset, chroma_v_offset, buffer); - else - return VA_STATUS_ERROR_UNIMPLEMENTED; + return ctx->vtable.vaLockSurface( ctx, surface, fourcc, luma_stride, chroma_u_stride, chroma_v_stride, luma_offset, chroma_u_offset, chroma_v_offset, buffer_name, buffer); +} + + +VAStatus vaUnlockSurface(VADisplay dpy, + VASurfaceID surface +) +{ + VADriverContextP ctx; + CHECK_DISPLAY(dpy); + ctx = CTX(dpy); + + return ctx->vtable.vaUnlockSurface( ctx, surface ); } diff --git a/va/va.h b/va/va.h index de962df..bb11048 100644 --- a/va/va.h +++ b/va/va.h @@ -411,20 +411,6 @@ VAStatus vaCreateSurfaces ( VASurfaceID *surfaces /* out */ ); -/* Wrap a CI (camera imaging) frame as a VA surface to share captured video between camear - * and VA encode. With frame_id, VA driver need to call CI interfaces to get the information - * of the frame, and to determine if the frame can be wrapped as a VA surface - * - * Application should make sure the frame is idle before the frame is passed into VA stack - * and also a vaSyncSurface should be called before application tries to access the frame - * from CI stack - */ -VAStatus vaCreateSurfaceFromCIFrame ( - VADisplay dpy, - unsigned long frame_id, - VASurfaceID *surface /* out */ -); - /* * vaDestroySurfaces - Destroy resources associated with surfaces. diff --git a/va/va_backend.h b/va/va_backend.h index 423de2d..9ba9000 100644 --- a/va/va_backend.h +++ b/va/va_backend.h @@ -338,22 +338,7 @@ struct VADriverVTable int num_attributes ); - /* device specific */ - VAStatus (*vaCreateSurfaceFromCIFrame) ( - VADriverContextP ctx, - unsigned long frame_id, - VASurfaceID *surface /* out */ - ); - - - VAStatus (*vaCreateSurfaceFromV4L2Buf) ( - VADriverContextP ctx, - int v4l2_fd, /* file descriptor of V4L2 device */ - struct v4l2_format *v4l2_fmt, /* format of V4L2 */ - struct v4l2_buffer *v4l2_buf, /* V4L2 buffer */ - VASurfaceID *surface /* out */ - ); - + /* used by va trace */ VAStatus (*vaBufferInfo) ( VADriverContextP ctx, VAContextID context, /* in */ @@ -363,8 +348,8 @@ struct VADriverVTable unsigned int *num_elements /* out */ ); - - VAStatus (*vaCopySurfaceToBuffer) ( + /* lock/unlock surface for external access */ + VAStatus (*vaLockSurface) ( VADriverContextP ctx, VASurfaceID surface, unsigned int *fourcc, /* out for follow argument */ @@ -374,7 +359,17 @@ struct VADriverVTable unsigned int *luma_offset, unsigned int *chroma_u_offset, unsigned int *chroma_v_offset, - void **buffer + unsigned int *buffer_name, /* if it is not NULL, assign the low lever + * surface buffer name + */ + void **buffer /* if it is not NULL, map the surface buffer for + * CPU access + */ + ); + + VAStatus (*vaUnlockSurface) ( + VADriverContextP ctx, + VASurfaceID surface ); }; @@ -382,6 +377,7 @@ struct VADriverContext { void *pDriverData; struct VADriverVTable vtable; + void *vtable_tpi; /* the structure is malloc-ed */ void *native_dpy; int x11_screen; diff --git a/va/va_backend_tpi.h b/va/va_backend_tpi.h new file mode 100644 index 0000000..898a467 --- /dev/null +++ b/va/va_backend_tpi.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2007 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * Video Decode Acceleration -Backend API + */ + +#ifndef _VA_BACKEND_TPI_H_ +#define _VA_BACKEND_TPI_H_ + +#include +#include + +#include + +struct VADriverVTableTPI +{ + /* device specific */ + VAStatus (*vaCreateSurfaceFromCIFrame) ( + VADriverContextP ctx, + unsigned long frame_id, + VASurfaceID *surface /* out */ + ); + + VAStatus (*vaCreateSurfaceFromV4L2Buf) ( + VADriverContextP ctx, + int v4l2_fd, /* file descriptor of V4L2 device */ + struct v4l2_format *v4l2_fmt, /* format of V4L2 */ + struct v4l2_buffer *v4l2_buf, /* V4L2 buffer */ + VASurfaceID *surface /* out */ + ); +}; + + +#endif /* _VA_BACKEND_TPI_H_ */ diff --git a/va/va_tpi.c b/va/va_tpi.c new file mode 100644 index 0000000..fccd089 --- /dev/null +++ b/va/va_tpi.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2007 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#define _GNU_SOURCE 1 +#include "va.h" +#include "va_backend.h" +#include "va_backend_tpi.h" +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include + +#define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext) +#define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; } + +/* Wrap a CI (camera imaging) frame as a VA surface to share captured video between camear + * and VA encode. With frame_id, VA driver need to call CI interfaces to get the information + * of the frame, and to determine if the frame can be wrapped as a VA surface + * + * Application should make sure the frame is idle before the frame is passed into VA stack + * and also a vaSyncSurface should be called before application tries to access the frame + * from CI stack + */ +VAStatus vaCreateSurfaceFromCIFrame ( + VADisplay dpy, + unsigned long frame_id, + VASurfaceID *surface /* out */ +) +{ + VADriverContextP ctx; + struct VADriverVTableTPI *tpi; + CHECK_DISPLAY(dpy); + ctx = CTX(dpy); + + tpi = ( struct VADriverVTableTPI *)ctx->vtable_tpi; + if (tpi && tpi->vaCreateSurfaceFromCIFrame) { + return tpi->vaCreateSurfaceFromCIFrame( ctx, frame_id, surface ); + } else + return VA_STATUS_ERROR_UNIMPLEMENTED; + +} + +/* Wrap a V4L2 buffer as a VA surface, so that V4L2 camera, VA encode + * can share the data without copy + * The VA driver should query the camera device from v4l2_fd to see + * if camera device memory/buffer can be wrapped into a VA surface + * Buffer information is passed in by v4l2_fmt and v4l2_buf structure, + * VA driver also needs do further check if the buffer can meet encode + * hardware requirement, such as dimension, fourcc, stride, etc + * + * Application should make sure the buffer is idle before the frame into VA stack + * and also a vaSyncSurface should be called before application tries to access the frame + * from V4L2 stack + */ +VAStatus vaCreateSurfaceFromV4L2Buf( + VADisplay dpy, + int v4l2_fd, /* file descriptor of V4L2 device */ + struct v4l2_format *v4l2_fmt, /* format of V4L2 */ + struct v4l2_buffer *v4l2_buf, /* V4L2 buffer */ + VASurfaceID *surface /* out */ +) +{ + VADriverContextP ctx; + struct VADriverVTableTPI *tpi; + CHECK_DISPLAY(dpy); + ctx = CTX(dpy); + + tpi = ( struct VADriverVTableTPI *)ctx->vtable_tpi; + if (tpi && tpi->vaCreateSurfaceFromV4L2Buf) { + return tpi->vaCreateSurfaceFromV4L2Buf( ctx, v4l2_fd, v4l2_fmt, v4l2_buf, surface ); + } else + return VA_STATUS_ERROR_UNIMPLEMENTED; +} diff --git a/va/va_tpi.h b/va/va_tpi.h new file mode 100644 index 0000000..559fdfc --- /dev/null +++ b/va/va_tpi.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2007-2009 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* Wrap a CI (camera imaging) frame as a VA surface to share captured video between camear + * and VA encode. With frame_id, VA driver need to call CI interfaces to get the information + * of the frame, and to determine if the frame can be wrapped as a VA surface + * + * Application should make sure the frame is idle before the frame is passed into VA stack + * and also a vaSyncSurface should be called before application tries to access the frame + * from CI stack + */ + +#include +VAStatus vaCreateSurfaceFromCIFrame ( + VADisplay dpy, + unsigned long frame_id, + VASurfaceID *surface /* out */ +); + +VAStatus vaCreateSurfaceFromV4L2Buf( + VADisplay dpy, + int v4l2_fd, /* file descriptor of V4L2 device */ + struct v4l2_format *v4l2_fmt, /* format of V4L2 */ + struct v4l2_buffer *v4l2_buf, /* V4L2 buffer */ + VASurfaceID *surface /* out */ +); + + diff --git a/va/va_trace.c b/va/va_trace.c index e0e335f..dbd0749 100644 --- a/va/va_trace.c +++ b/va/va_trace.c @@ -1048,6 +1048,7 @@ int va_TraceEndPicture( unsigned int luma_offset; unsigned int chroma_u_offset; unsigned int chroma_v_offset; + unsigned int buffer_name; void *buffer; char *Y_data, *UV_data, *tmp; @@ -1061,8 +1062,8 @@ int va_TraceEndPicture( va_TraceMsg("***dump surface data***\n", trace_rendertarget); - va_status = vaCopySurfaceToBuffer(dpy, trace_rendertarget, &fourcc, &luma_stride, &chroma_u_stride, &chroma_v_stride, - &luma_offset, &chroma_u_offset, &chroma_v_offset, &buffer); + va_status = vaLockSurface(dpy, trace_rendertarget, &fourcc, &luma_stride, &chroma_u_stride, &chroma_v_stride, + &luma_offset, &chroma_u_offset, &chroma_v_offset, &buffer_name, &buffer); if (va_status != VA_STATUS_SUCCESS) return va_status; @@ -1110,5 +1111,4 @@ int va_TraceEndPicture( tmp = UV_data + i * chroma_u_stride; } } - free((void *)buffer); } -- cgit v1.2.1