mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-05 17:16:50 +08:00
[drm]: add android drm allocator support
1. enable drm allocator in android 2. modify size calculating when alloc Todo: wait for new interface of kernel to decide use whether drm or ion as allocator Change-Id: Ia6791d91d113b238be77088ae747012fb786d683 Signed-off-by: Jung Zhao <jung.zhao@rock-chips.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# vim: syntax=cmake
|
# vim: syntax=cmake
|
||||||
if(${ANDROID})
|
if(${ANDROID})
|
||||||
set(OS_DIR android)
|
set(OS_DIR android)
|
||||||
set(MPP_ALLOCATOR allocator/allocator_ion.c)
|
set(MPP_ALLOCATOR allocator/allocator_ion.c allocator/allocator_drm.c)
|
||||||
elseif(${UNIX})
|
elseif(${UNIX})
|
||||||
set(OS_DIR linux)
|
set(OS_DIR linux)
|
||||||
set(MPP_ALLOCATOR allocator/allocator_ion.c allocator/allocator_drm.c)
|
set(MPP_ALLOCATOR allocator/allocator_ion.c allocator/allocator_drm.c)
|
||||||
|
@@ -35,59 +35,58 @@
|
|||||||
|
|
||||||
static RK_U32 drm_debug = 0;
|
static RK_U32 drm_debug = 0;
|
||||||
|
|
||||||
#define DRM_FUNCTDRM (0x00000001)
|
#define DRM_FUNCTION (0x00000001)
|
||||||
#define DRM_DEVICE (0x00000002)
|
#define DRM_DEVICE (0x00000002)
|
||||||
#define DRM_CLINET (0x00000004)
|
#define DRM_CLIENT (0x00000004)
|
||||||
#define DRM_IOCTL (0x00000008)
|
#define DRM_IOCTL (0x00000008)
|
||||||
|
|
||||||
#define DRM_DETECT_IOMMU_DISABLE (0x0) /* use DRM_HEAP_TYPE_DMA */
|
#define DRM_DETECT_IOMMU_DISABLE (0x0) /* use DRM_HEAP_TYPE_DMA */
|
||||||
#define DRM_DETECT_IOMMU_ENABLE (0x1) /* use DRM_HEAP_TYPE_SYSTEM */
|
#define DRM_DETECT_IOMMU_ENABLE (0x1) /* use DRM_HEAP_TYPE_SYSTEM */
|
||||||
#define DRM_DETECT_NO_DTS (0x2) /* use DRM_HEAP_TYPE_CARVEOUT */
|
#define DRM_DETECT_NO_DTS (0x2) /* use DRM_HEAP_TYPE_CARVEOUT */
|
||||||
|
|
||||||
#define drm_dbg(flag, fmt, ...) _mpp_dbg(drm_debug, flag, fmt, ## __VA_ARGS__)
|
#define drm_dbg(flag, fmt, ...) _mpp_dbg_f(drm_debug, flag, fmt, ## __VA_ARGS__)
|
||||||
|
|
||||||
static int drm_ioctl(int fd, int req, void *arg)
|
static int drm_ioctl(int fd, int req, void *arg)
|
||||||
{
|
|
||||||
int ret = ioctl(fd, req, arg);
|
|
||||||
if (ret < 0) {
|
|
||||||
mpp_err("drm_ioctl %x failed with code %d: %s\n", req,
|
|
||||||
ret, strerror(errno));
|
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int drm_alloc(int fd, size_t len, size_t align, unsigned int heap_mask,
|
|
||||||
unsigned int flags, RK_U32 *handle)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct drm_mode_create_dumb dmcb;
|
|
||||||
memset(&dmcb, 0, sizeof(struct drm_mode_create_dumb));
|
|
||||||
dmcb.bpp = align;
|
|
||||||
dmcb.width = ((len + align) & (~align)) / align;
|
|
||||||
dmcb.height = 8;
|
|
||||||
dmcb.size = (len + align) & (~align);
|
|
||||||
|
|
||||||
if (handle == NULL)
|
do {
|
||||||
return -EINVAL;
|
ret = ioctl(fd, req, arg);
|
||||||
|
} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
|
||||||
|
|
||||||
|
drm_dbg(DRM_FUNCTION, "drm_ioctl %x with code %d: %s", req,
|
||||||
|
ret, strerror(errno));
|
||||||
|
|
||||||
ret = drm_ioctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &dmcb);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
*handle = dmcb.handle;
|
|
||||||
(void)heap_mask;
|
|
||||||
(void)flags;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void* drm_mmap(int fd, size_t len, int prot, int flags, loff_t offset)
|
||||||
|
{
|
||||||
|
static unsigned long pagesize_mask = 0;
|
||||||
|
|
||||||
|
if (fd < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!pagesize_mask)
|
||||||
|
pagesize_mask = getpagesize() - 1;
|
||||||
|
|
||||||
|
len = (len + pagesize_mask) & ~pagesize_mask;
|
||||||
|
|
||||||
|
if (offset & 4095) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mmap64(NULL, len, prot, flags, fd, offset);
|
||||||
|
}
|
||||||
|
|
||||||
static int drm_handle_to_fd(int fd, RK_U32 handle, int *map_fd, RK_U32 flags)
|
static int drm_handle_to_fd(int fd, RK_U32 handle, int *map_fd, RK_U32 flags)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct drm_prime_handle dph;
|
struct drm_prime_handle dph;
|
||||||
memset(&dph, 0, sizeof(struct drm_prime_handle));
|
memset(&dph, 0, sizeof(struct drm_prime_handle));
|
||||||
dph.handle = handle;
|
dph.handle = handle;
|
||||||
dph.fd = 1;
|
dph.fd = -1;
|
||||||
dph.flags = 0;
|
dph.flags = flags;
|
||||||
|
|
||||||
if (map_fd == NULL)
|
if (map_fd == NULL)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@@ -99,24 +98,37 @@ static int drm_handle_to_fd(int fd, RK_U32 handle, int *map_fd, RK_U32 flags)
|
|||||||
|
|
||||||
*map_fd = dph.fd;
|
*map_fd = dph.fd;
|
||||||
|
|
||||||
|
drm_dbg(DRM_FUNCTION, "get fd %d", *map_fd);
|
||||||
|
|
||||||
if (*map_fd < 0) {
|
if (*map_fd < 0) {
|
||||||
mpp_err("map ioctl returned negative fd\n");
|
mpp_err("map ioctl returned negative fd\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
(void)flags;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int drm_free(int fd, RK_U32 handle)
|
static int drm_fd_to_handle(int fd, int map_fd, RK_U32 *handle, RK_U32 flags)
|
||||||
{
|
{
|
||||||
struct drm_mode_destroy_dumb data = {
|
int ret;
|
||||||
.handle = handle,
|
struct drm_prime_handle dph;
|
||||||
};
|
|
||||||
return drm_ioctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &data);
|
dph.fd = map_fd;
|
||||||
|
dph.flags = flags;
|
||||||
|
|
||||||
|
ret = drm_ioctl(fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &dph);
|
||||||
|
if (ret < 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
*handle = dph.handle;
|
||||||
|
drm_dbg(DRM_FUNCTION, "get handle %d", *handle);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int drm_map(int fd, RK_U32 handle, size_t length, int prot,
|
static int drm_map(int fd, RK_U32 handle, size_t length, int prot,
|
||||||
int flags, off_t offset, unsigned char **ptr, int *map_fd)
|
int flags, unsigned char **ptr, int *map_fd)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct drm_mode_map_dumb dmmd;
|
struct drm_mode_map_dumb dmmd;
|
||||||
@@ -129,22 +141,65 @@ static int drm_map(int fd, RK_U32 handle, size_t length, int prot,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
ret = drm_handle_to_fd(fd, handle, map_fd, 0);
|
ret = drm_handle_to_fd(fd, handle, map_fd, 0);
|
||||||
|
drm_dbg(DRM_FUNCTION, "drm_map fd %d", *map_fd);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ret = drm_ioctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &dmmd);
|
ret = drm_ioctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &dmmd);
|
||||||
if (ret < 0)
|
if (ret < 0) {
|
||||||
|
close(*map_fd);
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
*ptr = mmap(NULL, length, prot, flags, *map_fd, dmmd.offset);
|
drm_dbg(DRM_FUNCTION, "dev fd %d length %d", fd, length);
|
||||||
|
|
||||||
|
*ptr = drm_mmap(fd, length, prot, flags, dmmd.offset);
|
||||||
if (*ptr == MAP_FAILED) {
|
if (*ptr == MAP_FAILED) {
|
||||||
|
close(*map_fd);
|
||||||
|
*map_fd = -1;
|
||||||
mpp_err("mmap failed: %s\n", strerror(errno));
|
mpp_err("mmap failed: %s\n", strerror(errno));
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
(void)offset;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int drm_alloc(int fd, size_t len, size_t align, RK_U32 *handle)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
struct drm_mode_create_dumb dmcb;
|
||||||
|
|
||||||
|
drm_dbg(DRM_FUNCTION, "len %ld aligned %ld\n", len, align);
|
||||||
|
|
||||||
|
memset(&dmcb, 0, sizeof(struct drm_mode_create_dumb));
|
||||||
|
dmcb.bpp = 8;
|
||||||
|
dmcb.width = (len + align - 1) & (~(align - 1));
|
||||||
|
dmcb.height = 1;
|
||||||
|
dmcb.size = dmcb.width * dmcb.bpp;
|
||||||
|
|
||||||
|
drm_dbg(DRM_FUNCTION, "fd %d aligned %d size %lld\n", fd, align, dmcb.size);
|
||||||
|
|
||||||
|
if (handle == NULL)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
ret = drm_ioctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &dmcb);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
*handle = dmcb.handle;
|
||||||
|
|
||||||
|
drm_dbg(DRM_FUNCTION, "get handle %d size %d", *handle, dmcb.size);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int drm_free(int fd, RK_U32 handle)
|
||||||
|
{
|
||||||
|
struct drm_mode_destroy_dumb data = {
|
||||||
|
.handle = handle,
|
||||||
|
};
|
||||||
|
return drm_ioctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &data);
|
||||||
|
}
|
||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
static const char *search_name = NULL;
|
static const char *search_name = NULL;
|
||||||
@@ -189,18 +244,28 @@ static RK_S32 find_dir_in_path(char *path, const char *dir_name, size_t max_leng
|
|||||||
return new_path_len;
|
return new_path_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static RK_S32 check_sysfs_iommu()
|
||||||
|
{
|
||||||
|
RK_U32 i = 0;
|
||||||
|
RK_U32 dts_info_found = 0;
|
||||||
|
RK_U32 ion_info_found = 0;
|
||||||
|
RK_S32 ret = DRM_DETECT_IOMMU_DISABLE;
|
||||||
|
char path[256];
|
||||||
static char *dts_devices[] = {
|
static char *dts_devices[] = {
|
||||||
"vpu_service",
|
"vpu_service",
|
||||||
"hevc_service",
|
"hevc_service",
|
||||||
"rkvdec",
|
"rkvdec",
|
||||||
"rkvenc",
|
"rkvenc",
|
||||||
};
|
};
|
||||||
|
static char *system_heaps[] = {
|
||||||
|
"vmalloc",
|
||||||
|
"system-heap",
|
||||||
|
};
|
||||||
|
|
||||||
static RK_S32 check_sysfs_iommu()
|
mpp_env_get_u32("drm_debug", &drm_debug, 0);
|
||||||
{
|
#ifdef SOFIA_3GR_LINUX
|
||||||
RK_U32 i = 0, found = 0;
|
return ret;
|
||||||
RK_S32 ret = DRM_DETECT_IOMMU_DISABLE;
|
#endif
|
||||||
char path[256];
|
|
||||||
|
|
||||||
for (i = 0; i < MPP_ARRAY_ELEMS(dts_devices); i++) {
|
for (i = 0; i < MPP_ARRAY_ELEMS(dts_devices); i++) {
|
||||||
snprintf(path, sizeof(path), "/proc/device-tree");
|
snprintf(path, sizeof(path), "/proc/device-tree");
|
||||||
@@ -216,14 +281,26 @@ static RK_S32 check_sysfs_iommu()
|
|||||||
if (iommu_enabled)
|
if (iommu_enabled)
|
||||||
ret = DRM_DETECT_IOMMU_ENABLE;
|
ret = DRM_DETECT_IOMMU_ENABLE;
|
||||||
}
|
}
|
||||||
found = 1;
|
dts_info_found = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!dts_info_found) {
|
||||||
mpp_err("can not find dts for all possible devices\n");
|
for (i = 0; i < MPP_ARRAY_ELEMS(system_heaps); i++) {
|
||||||
|
snprintf(path, sizeof(path), "/sys/kernel/debug/ion/heaps");
|
||||||
|
if (find_dir_in_path(path, system_heaps[i], sizeof(path))) {
|
||||||
|
mpp_log("%s found\n", system_heaps[i]);
|
||||||
|
ret = DRM_DETECT_IOMMU_ENABLE;
|
||||||
|
ion_info_found = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dts_info_found && !ion_info_found) {
|
||||||
|
mpp_err("can not find any hint from all possible devices\n");
|
||||||
ret = DRM_DETECT_NO_DTS;
|
ret = DRM_DETECT_NO_DTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,14 +323,14 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const char *dev_drm = "/dev/dri/card0";
|
const char *dev_drm = "/dev/dri/card0";
|
||||||
static RK_S32 drm_heap_id = -1;
|
|
||||||
static RK_U32 drm_heap_mask = 1;
|
|
||||||
|
|
||||||
MPP_RET os_allocator_drm_open(void **ctx, size_t alignment)
|
MPP_RET os_allocator_drm_open(void **ctx, size_t alignment)
|
||||||
{
|
{
|
||||||
RK_S32 fd;
|
RK_S32 fd;
|
||||||
allocator_ctx_drm *p;
|
allocator_ctx_drm *p;
|
||||||
|
|
||||||
|
drm_dbg(DRM_FUNCTION, "enter");
|
||||||
|
|
||||||
if (NULL == ctx) {
|
if (NULL == ctx) {
|
||||||
mpp_err("os_allocator_open Android do not accept NULL input\n");
|
mpp_err("os_allocator_open Android do not accept NULL input\n");
|
||||||
return MPP_ERR_NULL_PTR;
|
return MPP_ERR_NULL_PTR;
|
||||||
@@ -278,13 +355,13 @@ MPP_RET os_allocator_drm_open(void **ctx, size_t alignment)
|
|||||||
/*
|
/*
|
||||||
* default drm use cma, do nothing here
|
* default drm use cma, do nothing here
|
||||||
*/
|
*/
|
||||||
drm_heap_mask = (1 << DRM_HEAP_TYPE_CMA);
|
|
||||||
drm_heap_id = DRM_HEAP_TYPE_CMA;
|
|
||||||
p->alignment = alignment;
|
p->alignment = alignment;
|
||||||
p->drm_device = fd;
|
p->drm_device = fd;
|
||||||
*ctx = p;
|
*ctx = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drm_dbg(DRM_FUNCTION, "leave");
|
||||||
|
|
||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,16 +376,16 @@ MPP_RET os_allocator_drm_alloc(void *ctx, MppBufferInfo *info)
|
|||||||
}
|
}
|
||||||
|
|
||||||
p = (allocator_ctx_drm *)ctx;
|
p = (allocator_ctx_drm *)ctx;
|
||||||
|
drm_dbg(DRM_FUNCTION, "alignment %d size %d", p->alignment, info->size);
|
||||||
ret = drm_alloc(p->drm_device, info->size, p->alignment,
|
ret = drm_alloc(p->drm_device, info->size, p->alignment,
|
||||||
drm_heap_mask, 0,
|
|
||||||
(RK_U32 *)&info->hnd);
|
(RK_U32 *)&info->hnd);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
mpp_err("os_allocator_drm_alloc drm_alloc failed ret %d\n", ret);
|
mpp_err("os_allocator_drm_alloc drm_alloc failed ret %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
drm_dbg(DRM_FUNCTION, "handle %d", (RK_U32)((intptr_t)info->hnd));
|
||||||
ret = drm_map(p->drm_device, (RK_U32)((intptr_t)info->hnd), info->size,
|
ret = drm_map(p->drm_device, (RK_U32)((intptr_t)info->hnd), info->size,
|
||||||
PROT_READ | PROT_WRITE, MAP_SHARED, (off_t)0,
|
PROT_READ | PROT_WRITE, MAP_SHARED, (unsigned char **)&info->ptr, &info->fd);
|
||||||
(unsigned char**)&info->ptr, &info->fd);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
mpp_err("os_allocator_drm_alloc drm_map failed ret %d\n", ret);
|
mpp_err("os_allocator_drm_alloc drm_map failed ret %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
@@ -319,19 +396,35 @@ MPP_RET os_allocator_drm_alloc(void *ctx, MppBufferInfo *info)
|
|||||||
MPP_RET os_allocator_drm_import(void *ctx, MppBufferInfo *data)
|
MPP_RET os_allocator_drm_import(void *ctx, MppBufferInfo *data)
|
||||||
{
|
{
|
||||||
MPP_RET ret = MPP_OK;
|
MPP_RET ret = MPP_OK;
|
||||||
(void)ctx;
|
allocator_ctx_drm *p = (allocator_ctx_drm *)ctx;
|
||||||
|
struct drm_mode_map_dumb dmmd;
|
||||||
|
memset(&dmmd, 0, sizeof(dmmd));
|
||||||
|
|
||||||
|
drm_dbg(DRM_FUNCTION, "enter");
|
||||||
// NOTE: do not use the original buffer fd,
|
// NOTE: do not use the original buffer fd,
|
||||||
// use dup fd to avoid unexpected external fd close
|
// use dup fd to avoid unexpected external fd close
|
||||||
data->fd = dup(data->fd);
|
data->fd = dup(data->fd);
|
||||||
/* I don't know whether it is correct for drm */
|
|
||||||
data->ptr = mmap(NULL, data->size, PROT_READ | PROT_WRITE, MAP_SHARED, data->fd, 0);
|
ret = drm_fd_to_handle(p->drm_device, data->fd, (RK_U32 *)&data->hnd, 0);
|
||||||
|
|
||||||
|
drm_dbg(DRM_FUNCTION, "get handle %d", (RK_U32)(data->hnd));
|
||||||
|
|
||||||
|
dmmd.handle = (RK_U32)(data->hnd);
|
||||||
|
|
||||||
|
ret = drm_ioctl(p->drm_device, DRM_IOCTL_MODE_MAP_DUMB, &dmmd);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
drm_dbg(DRM_FUNCTION, "dev fd %d length %d", p->drm_device, data->size);
|
||||||
|
|
||||||
|
data->ptr = drm_mmap(p->drm_device, data->size, PROT_READ | PROT_WRITE, MAP_SHARED, dmmd.offset);
|
||||||
if (data->ptr == MAP_FAILED) {
|
if (data->ptr == MAP_FAILED) {
|
||||||
mpp_err_f("map error %s\n", strerror(errno));
|
mpp_err("mmap failed: %s\n", strerror(errno));
|
||||||
ret = MPP_NOK;
|
return -errno;
|
||||||
close(data->fd);
|
|
||||||
data->fd = -1;
|
|
||||||
data->ptr = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drm_dbg(DRM_FUNCTION, "leave");
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,6 +463,7 @@ MPP_RET os_allocator_drm_close(void *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
p = (allocator_ctx_drm *)ctx;
|
p = (allocator_ctx_drm *)ctx;
|
||||||
|
drm_dbg(DRM_FUNCTION, "close fd %d", p->drm_device);
|
||||||
ret = close(p->drm_device);
|
ret = close(p->drm_device);
|
||||||
mpp_free(p);
|
mpp_free(p);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@@ -385,4 +479,3 @@ os_allocator allocator_drm = {
|
|||||||
os_allocator_drm_release,
|
os_allocator_drm_release,
|
||||||
os_allocator_drm_close,
|
os_allocator_drm_close,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -22,9 +22,11 @@
|
|||||||
#include "os_mem.h"
|
#include "os_mem.h"
|
||||||
#include "os_allocator.h"
|
#include "os_allocator.h"
|
||||||
#include "allocator_ion.h"
|
#include "allocator_ion.h"
|
||||||
|
#include "allocator_drm.h"
|
||||||
|
|
||||||
#include "mpp_mem.h"
|
#include "mpp_mem.h"
|
||||||
#include "mpp_log.h"
|
#include "mpp_log.h"
|
||||||
|
#include "mpp_common.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
RK_U32 alignment;
|
RK_U32 alignment;
|
||||||
@@ -121,17 +123,25 @@ static os_allocator allocator_normal = {
|
|||||||
MPP_RET os_allocator_get(os_allocator *api, MppBufferType type)
|
MPP_RET os_allocator_get(os_allocator *api, MppBufferType type)
|
||||||
{
|
{
|
||||||
MPP_RET ret = MPP_OK;
|
MPP_RET ret = MPP_OK;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MPP_BUFFER_TYPE_NORMAL :
|
case MPP_BUFFER_TYPE_NORMAL :
|
||||||
case MPP_BUFFER_TYPE_V4L2 : {
|
case MPP_BUFFER_TYPE_V4L2 : {
|
||||||
*api = allocator_normal;
|
*api = allocator_normal;
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
case MPP_BUFFER_TYPE_ION : {
|
case MPP_BUFFER_TYPE_ION : {
|
||||||
*api = allocator_ion;
|
*api = allocator_ion;
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
|
case MPP_BUFFER_TYPE_DRM : {
|
||||||
|
*api = allocator_drm;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default : {
|
default : {
|
||||||
ret = MPP_NOK;
|
ret = MPP_NOK;
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@@ -630,15 +630,15 @@ struct drm_get_cap {
|
|||||||
/**
|
/**
|
||||||
* DRM_CLIENT_CAP_UNIVERSAL_PLANES
|
* DRM_CLIENT_CAP_UNIVERSAL_PLANES
|
||||||
*
|
*
|
||||||
* if set to 1, the DRM core will expose the full universal plane list
|
* If set to 1, the DRM core will expose all planes (overlay, primary, and
|
||||||
* (including primary and cursor planes).
|
* cursor) to userspace.
|
||||||
*/
|
*/
|
||||||
#define DRM_CLIENT_CAP_UNIVERSAL_PLANES 2
|
#define DRM_CLIENT_CAP_UNIVERSAL_PLANES 2
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DRM_CLIENT_CAP_ATOMIC
|
* DRM_CLIENT_CAP_ATOMIC
|
||||||
*
|
*
|
||||||
* If set to 1, the DRM core will allow atomic modesetting requests.
|
* If set to 1, the DRM core will expose atomic properties to userspace
|
||||||
*/
|
*/
|
||||||
#define DRM_CLIENT_CAP_ATOMIC 3
|
#define DRM_CLIENT_CAP_ATOMIC 3
|
||||||
|
|
||||||
@@ -816,7 +816,6 @@ struct drm_event_vblank {
|
|||||||
#define DRM_CAP_PRIME 0x5
|
#define DRM_CAP_PRIME 0x5
|
||||||
#define DRM_CAP_TIMESTAMP_MONOTONIC 0x6
|
#define DRM_CAP_TIMESTAMP_MONOTONIC 0x6
|
||||||
#define DRM_CAP_ASYNC_PAGE_FLIP 0x7
|
#define DRM_CAP_ASYNC_PAGE_FLIP 0x7
|
||||||
#define DRM_CAP_ADDFB2_MODIFIERS 0x10
|
|
||||||
|
|
||||||
#define DRM_PRIME_CAP_IMPORT 0x1
|
#define DRM_PRIME_CAP_IMPORT 0x1
|
||||||
#define DRM_PRIME_CAP_EXPORT 0x2
|
#define DRM_PRIME_CAP_EXPORT 0x2
|
||||||
|
@@ -92,6 +92,14 @@
|
|||||||
#define DRM_MODE_DIRTY_ON 1
|
#define DRM_MODE_DIRTY_ON 1
|
||||||
#define DRM_MODE_DIRTY_ANNOTATE 2
|
#define DRM_MODE_DIRTY_ANNOTATE 2
|
||||||
|
|
||||||
|
/* rotation property bits */
|
||||||
|
#define DRM_ROTATE_0 0
|
||||||
|
#define DRM_ROTATE_90 1
|
||||||
|
#define DRM_ROTATE_180 2
|
||||||
|
#define DRM_ROTATE_270 3
|
||||||
|
#define DRM_REFLECT_X 4
|
||||||
|
#define DRM_REFLECT_Y 5
|
||||||
|
|
||||||
struct drm_mode_modeinfo {
|
struct drm_mode_modeinfo {
|
||||||
__u32 clock;
|
__u32 clock;
|
||||||
__u16 hdisplay, hsync_start, hsync_end, htotal, hskew;
|
__u16 hdisplay, hsync_start, hsync_end, htotal, hskew;
|
||||||
@@ -259,6 +267,13 @@ struct drm_mode_get_connector {
|
|||||||
#define DRM_MODE_PROP_OBJECT DRM_MODE_PROP_TYPE(1)
|
#define DRM_MODE_PROP_OBJECT DRM_MODE_PROP_TYPE(1)
|
||||||
#define DRM_MODE_PROP_SIGNED_RANGE DRM_MODE_PROP_TYPE(2)
|
#define DRM_MODE_PROP_SIGNED_RANGE DRM_MODE_PROP_TYPE(2)
|
||||||
|
|
||||||
|
/* the PROP_ATOMIC flag is used to hide properties from userspace that
|
||||||
|
* is not aware of atomic properties. This is mostly to work around
|
||||||
|
* older userspace (DDX drivers) that read/write each prop they find,
|
||||||
|
* witout being aware that this could be triggering a lengthy modeset.
|
||||||
|
*/
|
||||||
|
#define DRM_MODE_PROP_ATOMIC 0x80000000
|
||||||
|
|
||||||
struct drm_mode_property_enum {
|
struct drm_mode_property_enum {
|
||||||
__u64 value;
|
__u64 value;
|
||||||
char name[DRM_PROP_NAME_LEN];
|
char name[DRM_PROP_NAME_LEN];
|
||||||
@@ -323,7 +338,6 @@ struct drm_mode_fb_cmd {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define DRM_MODE_FB_INTERLACED (1<<0) /* for interlaced framebuffers */
|
#define DRM_MODE_FB_INTERLACED (1<<0) /* for interlaced framebuffers */
|
||||||
#define DRM_MODE_FB_MODIFIERS (1<<1) /* enables ->modifer[] */
|
|
||||||
|
|
||||||
struct drm_mode_fb_cmd2 {
|
struct drm_mode_fb_cmd2 {
|
||||||
__u32 fb_id;
|
__u32 fb_id;
|
||||||
@@ -344,18 +358,10 @@ struct drm_mode_fb_cmd2 {
|
|||||||
* So it would consist of Y as offset[0] and UV as
|
* So it would consist of Y as offset[0] and UV as
|
||||||
* offset[1]. Note that offset[0] will generally
|
* offset[1]. Note that offset[0] will generally
|
||||||
* be 0.
|
* be 0.
|
||||||
*
|
|
||||||
* To accommodate tiled, compressed, etc formats, a per-plane
|
|
||||||
* modifier can be specified. The default value of zero
|
|
||||||
* indicates "native" format as specified by the fourcc.
|
|
||||||
* Vendor specific modifier token. This allows, for example,
|
|
||||||
* different tiling/swizzling pattern on different planes.
|
|
||||||
* See discussion above of DRM_FORMAT_MOD_xxx.
|
|
||||||
*/
|
*/
|
||||||
__u32 handles[4];
|
__u32 handles[4];
|
||||||
__u32 pitches[4]; /* pitch for each plane */
|
__u32 pitches[4]; /* pitch for each plane */
|
||||||
__u32 offsets[4]; /* offset of each plane */
|
__u32 offsets[4]; /* offset of each plane */
|
||||||
__u64 modifier[4]; /* ie, tiling, compressed (per plane) */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DRM_MODE_FB_DIRTY_ANNOTATE_COPY 0x01
|
#define DRM_MODE_FB_DIRTY_ANNOTATE_COPY 0x01
|
||||||
@@ -521,6 +527,13 @@ struct drm_mode_destroy_dumb {
|
|||||||
#define DRM_MODE_ATOMIC_NONBLOCK 0x0200
|
#define DRM_MODE_ATOMIC_NONBLOCK 0x0200
|
||||||
#define DRM_MODE_ATOMIC_ALLOW_MODESET 0x0400
|
#define DRM_MODE_ATOMIC_ALLOW_MODESET 0x0400
|
||||||
|
|
||||||
|
#define DRM_MODE_ATOMIC_FLAGS (\
|
||||||
|
DRM_MODE_PAGE_FLIP_EVENT |\
|
||||||
|
DRM_MODE_PAGE_FLIP_ASYNC |\
|
||||||
|
DRM_MODE_ATOMIC_TEST_ONLY |\
|
||||||
|
DRM_MODE_ATOMIC_NONBLOCK |\
|
||||||
|
DRM_MODE_ATOMIC_ALLOW_MODESET)
|
||||||
|
|
||||||
struct drm_mode_atomic {
|
struct drm_mode_atomic {
|
||||||
__u32 flags;
|
__u32 flags;
|
||||||
__u32 count_objs;
|
__u32 count_objs;
|
||||||
@@ -552,5 +565,4 @@ struct drm_mode_destroy_blob {
|
|||||||
__u32 blob_id;
|
__u32 blob_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -655,7 +655,14 @@ static RK_S32 vpu_decode_demo(VpuApiDemoCmdContext_t *cmd)
|
|||||||
/* note: must set out put size to 0 before do decoder. */
|
/* note: must set out put size to 0 before do decoder. */
|
||||||
pOut->size = 0;
|
pOut->size = 0;
|
||||||
|
|
||||||
if ((ret = ctx->decode(ctx, pkt, pOut)) != 0) {
|
if (ctx->decode_sendstream(ctx, pkt) != 0) {
|
||||||
|
mpp_log("send packet failed");
|
||||||
|
DECODE_ERR_RET(ERROR_VPU_DECODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ((ret = ctx->decode_getframe(ctx, pOut)) != 0) {
|
||||||
|
mpp_log("get decoded data failed\n");
|
||||||
DECODE_ERR_RET(ERROR_VPU_DECODE);
|
DECODE_ERR_RET(ERROR_VPU_DECODE);
|
||||||
} else {
|
} else {
|
||||||
mpp_log("vpu decode one frame, out len: %d, left size: %d\n",
|
mpp_log("vpu decode one frame, out len: %d, left size: %d\n",
|
||||||
|
Reference in New Issue
Block a user