Commit 1f4d9627 authored by Austin Yuan's avatar Austin Yuan

Merge branch 'va_backend' into PO

Conflicts:
	va/android/va_android.c
	va/va_android.h
	va/va_backend.h
Signed-off-by: default avatarAustin Yuan <shengquan.yuan@gmail.com>
parents be467652 c4a03c10
LOCAL_PATH:= $(call my-dir) LOCAL_PATH:= $(call my-dir)
LIBVA_MINOR_VERSION := 31
LIBVA_MAJOR_VERSION := 0
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_SRC_FILES := \ LOCAL_SRC_FILES := \
android/va_android.c va.c \
va_trace.c \
android/va_android.c \
android/drmtest.c \
LOCAL_CFLAGS += -DHAVE_CONFIG_H \ LOCAL_CFLAGS += -DHAVE_CONFIG_H \
-DIN_LIBVA \ -DANDROID \
LOCAL_C_INCLUDES += \ LOCAL_C_INCLUDES += \
$(TOPDIR)kernel/include \ $(TOPDIR)kernel/include \
$(TARGET_OUT_HEADERS)/libva \ $(TARGET_OUT_HEADERS)/libva \
$(TOPDIR)kernel/include/drm $(TOPDIR)kernel/include/drm
LOCAL_CC := g++
LOCAL_COPY_HEADERS_TO := libva/va LOCAL_COPY_HEADERS_TO := libva/va
LOCAL_COPY_HEADERS := \ LOCAL_COPY_HEADERS := \
va.h \ va.h \
va_backend.h \ va_backend.h \
va_version.h.in \ va_version.h.in \
x11/va_dricommon.h \
va_android.h va_android.h
LOCAL_MODULE := libva_android LOCAL_MODULE := libva_android
......
...@@ -55,7 +55,7 @@ static int is_master(int fd) ...@@ -55,7 +55,7 @@ static int is_master(int fd)
} }
/** Open the first DRM device matching the criteria */ /** Open the first DRM device matching the criteria */
int drm_open_matching(const char *pci_glob, int flags) int drm_open_matching(const char *pci_glob, int flags, int *device_id)
{ {
struct udev *udev; struct udev *udev;
struct udev_enumerate *e; struct udev_enumerate *e;
...@@ -64,10 +64,13 @@ int drm_open_matching(const char *pci_glob, int flags) ...@@ -64,10 +64,13 @@ int drm_open_matching(const char *pci_glob, int flags)
const char *pci_id, *path; const char *pci_id, *path;
int fd; int fd;
*device_id = ~0;
udev = udev_new(); udev = udev_new();
if (udev == NULL) { if (udev == NULL) {
fprintf(stderr, "failed to initialize udev context\n"); fprintf(stderr, "failed to initialize udev context\n");
abort(); //abort();
return -1;
} }
fd = -1; fd = -1;
...@@ -97,13 +100,16 @@ int drm_open_matching(const char *pci_glob, int flags) ...@@ -97,13 +100,16 @@ int drm_open_matching(const char *pci_glob, int flags)
} }
udev_enumerate_unref(e); udev_enumerate_unref(e);
udev_unref(udev); udev_unref(udev);
*device_id = pci_id;
return fd; return fd;
} }
int drm_open_any(void) int drm_open_any(void)
{ {
int fd = drm_open_matching("*:*", 0); int dev_id;
int fd = drm_open_matching("*:*", 0, &dev_id);
if (fd < 0) { if (fd < 0) {
fprintf(stderr, "failed to open any drm device\n"); fprintf(stderr, "failed to open any drm device\n");
...@@ -116,9 +122,9 @@ int drm_open_any(void) ...@@ -116,9 +122,9 @@ int drm_open_any(void)
/** /**
* Open the first DRM device we can find where we end up being the master. * Open the first DRM device we can find where we end up being the master.
*/ */
int drm_open_any_master(void) int drm_open_any_master(int *device_id)
{ {
int fd = drm_open_matching("*:*", DRM_TEST_MASTER); int fd = drm_open_matching("*:*", DRM_TEST_MASTER, device_id);
if (fd < 0) { if (fd < 0) {
fprintf(stderr, "failed to open any drm device\n"); fprintf(stderr, "failed to open any drm device\n");
......
...@@ -36,5 +36,5 @@ ...@@ -36,5 +36,5 @@
#define DRM_TEST_MASTER 0x01 #define DRM_TEST_MASTER 0x01
int drm_open_any(void); int drm_open_any(void);
int drm_open_any_master(void); int drm_open_any_master(int *device_id);
int drm_open_matching(const char *pci_glob, int flags); int drm_open_matching(const char *pci_glob, int flags, int *device_id);
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "va.h" #include "va.h"
#include "va_backend.h" #include "va_backend.h"
#include "va_android.h" #include "va_android.h"
#include "va_dricommon.h" #include "va_dricommon.h" /* needs some helper functions from this file */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
...@@ -35,11 +35,15 @@ ...@@ -35,11 +35,15 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <dlfcn.h>
#include <errno.h> #include <errno.h>
#define CHECK_SYMBOL(func) { if (!func) printf("func %s not found\n", #func); return VA_STATUS_ERROR_UNKNOWN; }
#define DEVICE_NAME "/dev/dri/card0"
static VADisplayContextP pDisplayContexts = NULL; static VADisplayContextP pDisplayContexts = NULL;
static int va_DisplayContextIsValid ( static int va_DisplayContextIsValid (
VADisplayContextP pDisplayContext VADisplayContextP pDisplayContext
) )
...@@ -86,21 +90,20 @@ static VAStatus va_DisplayContextGetDriverName ( ...@@ -86,21 +90,20 @@ static VAStatus va_DisplayContextGetDriverName (
VADriverContextP ctx = pDisplayContext->pDriverContext; VADriverContextP ctx = pDisplayContext->pDriverContext;
struct dri_state *dri_state = (struct dri_state *)ctx->dri_state; struct dri_state *dri_state = (struct dri_state *)ctx->dri_state;
char *driver_name_env; char *driver_name_env;
int dev_id;
struct { struct {
unsigned int verndor_id; int verndor_id;
unsigned int device_id; int device_id;
char driver_name[64]; char driver_name[64];
} devices[] = { } devices[] = {
{ 0x8086, 0x4100, "pvr" }, { 0x8086, 0x4100, "pvr" },
{ 0x8086, 0x0310, "pvr" },
{ 0x0, 0x0, "\0" },
}; };
memset(dri_state, 0, sizeof(*dri_state)); memset(dri_state, 0, sizeof(*dri_state));
dri_state->fd = drm_open_any_master(); dri_state->fd = drm_open_any_master(&dev_id);
if (dri_state->fd < 0) {
fprintf(stderr, "open DRM device by udev failed, try /dev/dri/card0\n");
dri_state->fd = open("/dev/dri/card0", O_RDWR);
}
if (dri_state->fd < 0) { if (dri_state->fd < 0) {
fprintf(stderr,"can't open DRM devices\n"); fprintf(stderr,"can't open DRM devices\n");
...@@ -108,14 +111,24 @@ static VAStatus va_DisplayContextGetDriverName ( ...@@ -108,14 +111,24 @@ static VAStatus va_DisplayContextGetDriverName (
} }
if ((driver_name_env = getenv("LIBVA_DRIVER_NAME")) != NULL if ((driver_name_env = getenv("LIBVA_DRIVER_NAME")) != NULL
&& geteuid() == getuid()) && geteuid() == getuid()) {
{
/* don't allow setuid apps to use LIBVA_DRIVER_NAME */ /* don't allow setuid apps to use LIBVA_DRIVER_NAME */
*driver_name = strdup(driver_name_env); *driver_name = strdup(driver_name_env);
return VA_STATUS_SUCCESS; return VA_STATUS_SUCCESS;
} else /* TBD: other vendor driver names */ } else { /* TBD: other vendor driver names */
*driver_name = strdup(devices[0].driver_name); int i=0;
while ((devices[i].device_id !=0) &&
(devices[i].device_id != dev_id))
i++;
if (devices[i].device_id != 0)
*driver_name = strdup(devices[0].driver_name);
else {
fprintf(stderr,"device (0x%04x) is not supported\n", dev_id);
return VA_STATUS_ERROR_UNKNOWN;
}
}
dri_state->driConnectedFlag = VA_DUMMY; dri_state->driConnectedFlag = VA_DUMMY;
...@@ -144,6 +157,7 @@ VADisplay vaGetDisplay ( ...@@ -144,6 +157,7 @@ VADisplay vaGetDisplay (
pDisplayContext = pDisplayContext->pNext; pDisplayContext = pDisplayContext->pNext;
} }
if (!dpy) if (!dpy)
{ {
/* create new entry */ /* create new entry */
...@@ -152,7 +166,6 @@ VADisplay vaGetDisplay ( ...@@ -152,7 +166,6 @@ VADisplay vaGetDisplay (
pDisplayContext = (VADisplayContextP)calloc(1, sizeof(*pDisplayContext)); pDisplayContext = (VADisplayContextP)calloc(1, sizeof(*pDisplayContext));
pDriverContext = (VADriverContextP)calloc(1, sizeof(*pDriverContext)); pDriverContext = (VADriverContextP)calloc(1, sizeof(*pDriverContext));
dri_state = calloc(1, sizeof(*dri_state)); dri_state = calloc(1, sizeof(*dri_state));
if (pDisplayContext && pDriverContext && dri_state) if (pDisplayContext && pDriverContext && dri_state)
{ {
pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC; pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;
...@@ -181,7 +194,6 @@ VADisplay vaGetDisplay ( ...@@ -181,7 +194,6 @@ VADisplay vaGetDisplay (
return dpy; return dpy;
} }
#define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext) #define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
#define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; } #define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
...@@ -214,36 +226,9 @@ VAStatus vaPutSurface ( ...@@ -214,36 +226,9 @@ VAStatus vaPutSurface (
CHECK_DISPLAY(dpy); CHECK_DISPLAY(dpy);
ctx = CTX(dpy); ctx = CTX(dpy);
return ctx->vtable.vaPutSurface( ctx, surface, draw, srcx, srcy, srcw, srch, return ctx->vtable.vaPutSurface( ctx, surface, (void *)draw, srcx, srcy, srcw, srch,
destx, desty, destw, desth, destx, desty, destw, desth,
cliprects, number_cliprects, flags ); cliprects, number_cliprects, flags );
} }
VAStatus vaPutSurfaceBuf (
VADisplay dpy,
VASurfaceID surface,
Drawable draw, /* Android Surface/Window */
unsigned char* data,
int* data_len,
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.vaPutSurfaceBuf( ctx, surface, draw, data, data_len, srcx, srcy, srcw, srch,
destx, desty, destw, desth, cliprects, number_cliprects, flags );
}
#endif #endif
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#define _GNU_SOURCE 1 #define _GNU_SOURCE 1
#include "va.h" #include "va.h"
#include "va_backend.h" #include "va_backend.h"
#include "config.h"
#include <assert.h> #include <assert.h>
#include <stdarg.h> #include <stdarg.h>
...@@ -54,6 +55,10 @@ extern int trace_flag; ...@@ -54,6 +55,10 @@ extern int trace_flag;
trace_func(__VA_ARGS__); \ trace_func(__VA_ARGS__); \
} }
#define VA_MAJOR_VERSION (0)
#define VA_MINOR_VERSION (31)
#define VA_VERSION_S "0.31.1"
static int vaDisplayIsValid(VADisplay dpy) static int vaDisplayIsValid(VADisplay dpy)
{ {
VADisplayContextP pDisplayContext = (VADisplayContextP)dpy; VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
...@@ -153,8 +158,11 @@ static VAStatus va_openDriver(VADisplay dpy, char *driver_name) ...@@ -153,8 +158,11 @@ static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
strncat( driver_path, DRIVER_EXTENSION, strlen(DRIVER_EXTENSION) ); strncat( driver_path, DRIVER_EXTENSION, strlen(DRIVER_EXTENSION) );
va_infoMessage("Trying to open %s\n", driver_path); va_infoMessage("Trying to open %s\n", driver_path);
#ifndef ANDROID
handle = dlopen( driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE ); handle = dlopen( driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE );
#else
handle = dlopen( driver_path, RTLD_NOW| RTLD_GLOBAL);
#endif
if (!handle) if (!handle)
{ {
/* Don't give errors for non-existing files */ /* Don't give errors for non-existing files */
......
...@@ -1804,6 +1804,17 @@ VAStatus vaSetDisplayAttributes ( ...@@ -1804,6 +1804,17 @@ VAStatus vaSetDisplayAttributes (
int num_attributes int num_attributes
); );
#ifdef ANDROID
#define Display unsigned int
#define Drawable unsigned int
#define XID unsigned int
#define Bool int
#define Status int
#define True 1
#define False 0
#define Xfree(ptr) free((ptr))
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -2,22 +2,18 @@ ...@@ -2,22 +2,18 @@
#define _VA_ANDROID_H_ #define _VA_ANDROID_H_
#include <va/va.h> #include <va/va.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* /*
* Returns a suitable VADisplay for VA API * Returns a suitable VADisplay for VA API
*/ */
VADisplay vaGetDisplay ( VADisplay vaGetDisplay (
void *dpy void *android_dpy
); );
#ifdef ANDROID #if ANDROID
#include <ui/Surface.h> #include <ui/Surface.h>
class Surface; class Surface;
...@@ -45,26 +41,6 @@ VAStatus vaPutSurface ( ...@@ -45,26 +41,6 @@ VAStatus vaPutSurface (
unsigned int number_cliprects, /* number of clip rects in the clip list */ unsigned int number_cliprects, /* number of clip rects in the clip list */
unsigned int flags /* PutSurface flags */ unsigned int flags /* PutSurface flags */
); );
VAStatus vaPutSurfaceBuf (
VADriverContextP ctx,
VASurfaceID surface,
Drawable draw, /* X Drawable */
unsigned char* data,
int* data_len,
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 */
);
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -30,12 +30,18 @@ ...@@ -30,12 +30,18 @@
#define _VA_BACKEND_H_ #define _VA_BACKEND_H_
#include <va/va.h> #include <va/va.h>
#ifndef ANDROID
#include <X11/Xlib.h> #include <X11/Xlib.h>
#endif
#include <linux/videodev2.h> #include <linux/videodev2.h>
typedef struct VADriverContext *VADriverContextP; typedef struct VADriverContext *VADriverContextP;
typedef struct VADisplayContext *VADisplayContextP; typedef struct VADisplayContext *VADisplayContextP;
#ifdef ANDROID
#define Surface void
#endif
struct VADriverVTable struct VADriverVTable
{ {
VAStatus (*vaTerminate) ( VADriverContextP ctx ); VAStatus (*vaTerminate) ( VADriverContextP ctx );
...@@ -179,7 +185,7 @@ struct VADriverVTable ...@@ -179,7 +185,7 @@ struct VADriverVTable
VAStatus (*vaPutSurface) ( VAStatus (*vaPutSurface) (
VADriverContextP ctx, VADriverContextP ctx,
VASurfaceID surface, VASurfaceID surface,
void* draw, /* X Drawable */ void * draw, /* Drawable of window system */
short srcx, short srcx,
short srcy, short srcy,
unsigned short srcw, unsigned short srcw,
......
#ifndef _VA_DRICOMMON_H_ #ifndef _VA_DRICOMMON_H_
#define _VA_DRICOMMON_H_ #define _VA_DRICOMMON_H_
#ifndef ANDROID
#include <X11/Xlib.h> #include <X11/Xlib.h>
#endif
#include <xf86drm.h> #include <xf86drm.h>
#include <drm.h> #include <drm.h>
#include <drm_sarea.h> #include <drm_sarea.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment