[osal]: add NORMAL path on android

git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@140 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
ChenHengming
2015-08-20 10:31:45 +00:00
parent 505e4dd8ae
commit 805db6b02d
3 changed files with 85 additions and 23 deletions

View File

@@ -143,7 +143,7 @@ typedef enum {
typedef union MppBufferData_t MppBufferData; typedef union MppBufferData_t MppBufferData;
union MppBufferData_t { union MppBufferData_t {
void *ptr; void *ptr;
RK_S32 fd; int fd;
}; };
typedef struct { typedef struct {

View File

@@ -25,9 +25,10 @@
#include "mpp_log.h" #include "mpp_log.h"
typedef struct { typedef struct {
RK_S32 ion_device; MppBufferType type;
RK_U32 alignment; RK_S32 ion_device;
} allocator_ion; RK_U32 alignment;
} allocator_impl;
static int ion_open() static int ion_open()
{ {
@@ -87,7 +88,6 @@ static int ion_free(int fd, ion_user_handle_t handle)
static int ion_share(int fd, ion_user_handle_t handle, int *share_fd) static int ion_share(int fd, ion_user_handle_t handle, int *share_fd)
{ {
int map_fd;
int ret; int ret;
struct ion_fd_data data = { struct ion_fd_data data = {
.handle = handle, .handle = handle,
@@ -121,64 +121,125 @@ static int ion_alloc_fd(int fd, size_t len, size_t align, unsigned int heap_mask
return ret; return ret;
} }
int os_allocator_open(void **ctx, size_t alignment) MPP_RET os_allocator_open(void **ctx, size_t alignment, MppBufferType type)
{ {
allocator_ion *p = NULL; allocator_impl *p = NULL;
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;
} }
p = mpp_malloc(allocator_ion, 1); p = mpp_malloc(allocator_impl, 1);
if (NULL == p) { if (NULL == p) {
*ctx = NULL; *ctx = NULL;
mpp_err("os_allocator_open Android failed to allocate context\n"); mpp_err("os_allocator_open Android failed to allocate context\n");
return MPP_ERR_MALLOC; return MPP_ERR_MALLOC;
} }
p->ion_device = ion_open(); switch (type) {
p->alignment = alignment; case MPP_BUFFER_TYPE_NORMAL :
case MPP_BUFFER_TYPE_ION : {
p = mpp_malloc(allocator_impl, 1);
if (NULL == p) {
*ctx = NULL;
mpp_err("os_allocator_open Android failed to allocate context\n");
return MPP_ERR_MALLOC;
}
p->alignment = alignment;
p->type = type;
if (MPP_BUFFER_TYPE_ION == type)
p->ion_device = ion_open();
} break;
default : {
mpp_err("os_allocator_open Window do not accept type %d\n");
} break;
}
*ctx = p; *ctx = p;
return 0; return 0;
} }
int os_allocator_alloc(void *ctx, MppBufferData *data, size_t size) MPP_RET os_allocator_alloc(void *ctx, MppBufferData *data, size_t size)
{ {
allocator_ion *p = NULL; MPP_RET ret = MPP_OK;
allocator_impl *p = NULL;
if (NULL == ctx) { if (NULL == ctx) {
mpp_err("os_allocator_close Android do not accept NULL input\n"); mpp_err("os_allocator_close Android do not accept NULL input\n");
return MPP_ERR_NULL_PTR; return MPP_ERR_NULL_PTR;
} }
p = (allocator_ion *)ctx; p = (allocator_impl *)ctx;
return (MPP_RET)os_malloc(&data->ptr, p->alignment, size); switch (p->type) {
case MPP_BUFFER_TYPE_NORMAL : {
ret = os_malloc(&data->ptr, p->alignment, size);
} break;
case MPP_BUFFER_TYPE_ION : {
ret = ion_alloc_fd(p->ion_device, size, p->alignment, ION_HEAP_TYPE_CARVEOUT, 0, &data->fd);
} break;
default : {
mpp_err("os_allocator_alloc Linux do not accept type %d\n", p->type);
ret = MPP_ERR_UNKNOW;
} break;
}
return ret;
} }
void os_allocator_free(void *ctx, MppBufferData *data) MPP_RET os_allocator_free(void *ctx, MppBufferData *data)
{ {
allocator_ion *p = NULL; MPP_RET ret = MPP_OK;
allocator_impl *p = NULL;
if (NULL == ctx) { if (NULL == ctx) {
mpp_err("os_allocator_close Android do not accept NULL input\n"); mpp_err("os_allocator_close Android do not accept NULL input\n");
return ; return MPP_ERR_NULL_PTR;
} }
os_free(data->ptr); p = (allocator_impl *)ctx;
switch (p->type) {
case MPP_BUFFER_TYPE_NORMAL : {
os_free(data->ptr);
} break;
case MPP_BUFFER_TYPE_ION : {
close(data->fd);
} break;
default : {
mpp_err("os_allocator_alloc Linux do not accept type %d\n", p->type);
ret = MPP_ERR_UNKNOW;
} break;
}
return ret;
} }
void os_allocator_close(void *ctx) MPP_RET os_allocator_close(void *ctx)
{ {
allocator_ion *p = NULL; MPP_RET ret = MPP_OK;
allocator_impl *p = NULL;
if (NULL == ctx) { if (NULL == ctx) {
mpp_err("os_allocator_close Android do not accept NULL input\n"); mpp_err("os_allocator_close Android do not accept NULL input\n");
return ; return MPP_ERR_NULL_PTR;
} }
p = (allocator_ion *)ctx; p = (allocator_impl *)ctx;
ion_close(p->ion_device);
switch (p->type) {
case MPP_BUFFER_TYPE_NORMAL : {
} break;
case MPP_BUFFER_TYPE_ION : {
ion_close(p->ion_device);
} break;
default : {
mpp_err("os_allocator_alloc Linux do not accept type %d\n", p->type);
ret = MPP_ERR_UNKNOW;
} break;
}
return ret;
} }

View File

@@ -50,6 +50,7 @@ MPP_RET os_allocator_open(void **ctx, size_t alignment, MppBufferType type)
} }
p->alignment = alignment; p->alignment = alignment;
p->type = type;
} break; } break;
default : { default : {
mpp_err("os_allocator_open Window do not accept type %d\n"); mpp_err("os_allocator_open Window do not accept type %d\n");