mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-07 10:00:55 +08:00
[osal]: add new buffer type for DMA import buffer
This buffer type is used for the buffer coming from the application, the application should make sure those buffers are the dma buffer. Change-Id: I2c8491f4dea77e5d7ae8d9157b0a1eda204f4bd6 Signed-off-by: Randy Li <randy.li@rock-chips.com>
This commit is contained in:
@@ -144,13 +144,13 @@ typedef enum {
|
|||||||
*
|
*
|
||||||
* normal : normal malloc buffer for unit test or hardware simulation
|
* normal : normal malloc buffer for unit test or hardware simulation
|
||||||
* ion : use ion device under Android/Linux, MppBuffer will encapsulte ion file handle
|
* ion : use ion device under Android/Linux, MppBuffer will encapsulte ion file handle
|
||||||
* v4l2 : not used now
|
* ext_dma : the DMABUF(DMA buffers) come from the application
|
||||||
* drm : use the drm device interface for memory management
|
* drm : use the drm device interface for memory management
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MPP_BUFFER_TYPE_NORMAL,
|
MPP_BUFFER_TYPE_NORMAL,
|
||||||
MPP_BUFFER_TYPE_ION,
|
MPP_BUFFER_TYPE_ION,
|
||||||
MPP_BUFFER_TYPE_V4L2,
|
MPP_BUFFER_TYPE_EXT_DMA,
|
||||||
MPP_BUFFER_TYPE_DRM,
|
MPP_BUFFER_TYPE_DRM,
|
||||||
MPP_BUFFER_TYPE_BUTT,
|
MPP_BUFFER_TYPE_BUTT,
|
||||||
} MppBufferType;
|
} MppBufferType;
|
||||||
@@ -158,10 +158,15 @@ typedef enum {
|
|||||||
/*
|
/*
|
||||||
* MppBufferInfo variable's meaning is different in different MppBufferType
|
* MppBufferInfo variable's meaning is different in different MppBufferType
|
||||||
*
|
*
|
||||||
|
* Common
|
||||||
|
* index - the buffer index used to track buffer in buffer pool
|
||||||
|
* size - the buffer size
|
||||||
|
*
|
||||||
* MPP_BUFFER_TYPE_NORMAL
|
* MPP_BUFFER_TYPE_NORMAL
|
||||||
*
|
*
|
||||||
* ptr - virtual address of normal malloced buffer
|
* ptr - virtual address of normal malloced buffer
|
||||||
* fd - unused and set to -1
|
* fd - unused and set to -1, the allocator would return its
|
||||||
|
* internal buffer counter number
|
||||||
*
|
*
|
||||||
* MPP_BUFFER_TYPE_ION
|
* MPP_BUFFER_TYPE_ION
|
||||||
*
|
*
|
||||||
@@ -169,9 +174,6 @@ typedef enum {
|
|||||||
* hnd - ion handle in user space
|
* hnd - ion handle in user space
|
||||||
* fd - ion buffer file handle for map / unmap
|
* fd - ion buffer file handle for map / unmap
|
||||||
*
|
*
|
||||||
* MPP_BUFFER_TYPE_V4L2
|
|
||||||
*
|
|
||||||
* TODO: to be implemented.
|
|
||||||
*/
|
*/
|
||||||
typedef struct MppBufferInfo_t {
|
typedef struct MppBufferInfo_t {
|
||||||
MppBufferType type;
|
MppBufferType type;
|
||||||
|
@@ -19,6 +19,7 @@ endif()
|
|||||||
set(MPP_ALLOCATOR
|
set(MPP_ALLOCATOR
|
||||||
allocator/allocator_std.c
|
allocator/allocator_std.c
|
||||||
allocator/allocator_ion.c
|
allocator/allocator_ion.c
|
||||||
|
allocator/allocator_ext_dma.c
|
||||||
${DRM_FILES}
|
${DRM_FILES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
146
osal/allocator/allocator_ext_dma.c
Normal file
146
osal/allocator/allocator_ext_dma.c
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 Rockchip Electronics Co. LTD
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
|
||||||
|
#include "mpp_mem.h"
|
||||||
|
#include "mpp_log.h"
|
||||||
|
#include "os_mem.h"
|
||||||
|
|
||||||
|
#include "allocator_ext_dma.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
size_t alignment;
|
||||||
|
} allocator_ctx;
|
||||||
|
|
||||||
|
static MPP_RET allocator_ext_dma_open(void **ctx, size_t alignment)
|
||||||
|
{
|
||||||
|
MPP_RET ret = MPP_OK;
|
||||||
|
allocator_ctx *p = NULL;
|
||||||
|
|
||||||
|
if (NULL == ctx) {
|
||||||
|
mpp_err_f("do not accept NULL input\n");
|
||||||
|
return MPP_ERR_NULL_PTR;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = mpp_malloc(allocator_ctx, 1);
|
||||||
|
if (NULL == p) {
|
||||||
|
mpp_err_f("failed to allocate context\n");
|
||||||
|
ret = MPP_ERR_MALLOC;
|
||||||
|
} else {
|
||||||
|
p->alignment = alignment;
|
||||||
|
}
|
||||||
|
|
||||||
|
*ctx = p;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static MPP_RET allocator_ext_dma_alloc(void *ctx, MppBufferInfo *info)
|
||||||
|
{
|
||||||
|
if (!ctx || !info) {
|
||||||
|
mpp_err_f("found NULL context input\n");
|
||||||
|
return MPP_ERR_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MPP_ERR_PERM;
|
||||||
|
}
|
||||||
|
|
||||||
|
static MPP_RET allocator_ext_dma_free(void *ctx, MppBufferInfo *info)
|
||||||
|
{
|
||||||
|
if (!ctx || !info) {
|
||||||
|
mpp_err_f("found NULL context input\n");
|
||||||
|
return MPP_ERR_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MPP_ERR_PERM;
|
||||||
|
}
|
||||||
|
|
||||||
|
static MPP_RET allocator_ext_dma_import(void *ctx, MppBufferInfo *info)
|
||||||
|
{
|
||||||
|
allocator_ctx *p = (allocator_ctx *)ctx;
|
||||||
|
mpp_assert(p);
|
||||||
|
mpp_assert(info->size);
|
||||||
|
|
||||||
|
if (info->ptr) {
|
||||||
|
mpp_err_f("The ext_dma is not used for userptr\n");
|
||||||
|
return MPP_ERR_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ((info->fd < 0) ? MPP_ERR_VALUE : MPP_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
static MPP_RET allocator_ext_dma_mmap(void *ctx, MppBufferInfo *info)
|
||||||
|
{
|
||||||
|
void *ptr = NULL;
|
||||||
|
unsigned long offset = 0L;
|
||||||
|
mpp_assert(ctx);
|
||||||
|
mpp_assert(info->size);
|
||||||
|
mpp_assert(info->fd >= 0);
|
||||||
|
|
||||||
|
if (info->ptr)
|
||||||
|
return MPP_OK;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* It is insecure to access the first memory page,
|
||||||
|
* usually system doesn't allow this behavior.
|
||||||
|
*/
|
||||||
|
ptr = mmap(NULL, info->size, PROT_READ | PROT_WRITE,
|
||||||
|
MAP_SHARED, info->fd, offset);
|
||||||
|
if (ptr == MAP_FAILED)
|
||||||
|
return MPP_ERR_NULL_PTR;
|
||||||
|
|
||||||
|
info->ptr = ptr;
|
||||||
|
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static MPP_RET allocator_ext_dma_release(void *ctx, MppBufferInfo *info)
|
||||||
|
{
|
||||||
|
mpp_assert(ctx);
|
||||||
|
mpp_assert(info->size);
|
||||||
|
|
||||||
|
if (info->ptr)
|
||||||
|
munmap(info->ptr, info->size);
|
||||||
|
|
||||||
|
info->ptr = NULL;
|
||||||
|
info->hnd = NULL;
|
||||||
|
info->fd = -1;
|
||||||
|
info->size = 0;
|
||||||
|
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static MPP_RET allocator_ext_dma_close(void *ctx)
|
||||||
|
{
|
||||||
|
if (ctx) {
|
||||||
|
mpp_free(ctx);
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
mpp_err_f("found NULL context input\n");
|
||||||
|
return MPP_ERR_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
os_allocator allocator_ext_dma = {
|
||||||
|
.open = allocator_ext_dma_open,
|
||||||
|
.close = allocator_ext_dma_close,
|
||||||
|
.alloc = allocator_ext_dma_alloc,
|
||||||
|
.free = allocator_ext_dma_free,
|
||||||
|
.import = allocator_ext_dma_import,
|
||||||
|
.release = allocator_ext_dma_release,
|
||||||
|
.mmap = allocator_ext_dma_mmap,
|
||||||
|
};
|
24
osal/allocator/allocator_ext_dma.h
Normal file
24
osal/allocator/allocator_ext_dma.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 Rockchip Electronics Co. LTD
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ALLOCATOR_EXT_DMA_H__
|
||||||
|
#define __ALLOCATOR_EXT_DMA_H__
|
||||||
|
|
||||||
|
#include "os_allocator.h"
|
||||||
|
|
||||||
|
extern os_allocator allocator_ext_dma;
|
||||||
|
|
||||||
|
#endif
|
@@ -15,9 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
#include "allocator_std.h"
|
|
||||||
#include "allocator_ion.h"
|
|
||||||
#include "allocator_drm.h"
|
#include "allocator_drm.h"
|
||||||
|
#include "allocator_ext_dma.h"
|
||||||
|
#include "allocator_ion.h"
|
||||||
|
#include "allocator_std.h"
|
||||||
#include "mpp_runtime.h"
|
#include "mpp_runtime.h"
|
||||||
|
|
||||||
MPP_RET os_allocator_get(os_allocator *api, MppBufferType type)
|
MPP_RET os_allocator_get(os_allocator *api, MppBufferType type)
|
||||||
@@ -26,9 +27,7 @@ MPP_RET os_allocator_get(os_allocator *api, MppBufferType type)
|
|||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MPP_BUFFER_TYPE_NORMAL :
|
case MPP_BUFFER_TYPE_NORMAL :
|
||||||
case MPP_BUFFER_TYPE_V4L2 : {
|
|
||||||
*api = allocator_std;
|
*api = allocator_std;
|
||||||
} break;
|
|
||||||
case MPP_BUFFER_TYPE_ION : {
|
case MPP_BUFFER_TYPE_ION : {
|
||||||
*api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_ION)) ? allocator_ion :
|
*api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_ION)) ? allocator_ion :
|
||||||
#if HAVE_DRM
|
#if HAVE_DRM
|
||||||
@@ -36,6 +35,9 @@ MPP_RET os_allocator_get(os_allocator *api, MppBufferType type)
|
|||||||
#endif
|
#endif
|
||||||
allocator_std;
|
allocator_std;
|
||||||
} break;
|
} break;
|
||||||
|
case MPP_BUFFER_TYPE_EXT_DMA: {
|
||||||
|
*api = allocator_ext_dma;
|
||||||
|
} break;
|
||||||
case MPP_BUFFER_TYPE_DRM : {
|
case MPP_BUFFER_TYPE_DRM : {
|
||||||
#if HAVE_DRM
|
#if HAVE_DRM
|
||||||
*api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DRM)) ? allocator_drm :
|
*api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DRM)) ? allocator_drm :
|
||||||
|
@@ -18,9 +18,10 @@
|
|||||||
#include "mpp_log.h"
|
#include "mpp_log.h"
|
||||||
#include "mpp_runtime.h"
|
#include "mpp_runtime.h"
|
||||||
|
|
||||||
#include "allocator_std.h"
|
|
||||||
#include "allocator_ion.h"
|
|
||||||
#include "allocator_drm.h"
|
#include "allocator_drm.h"
|
||||||
|
#include "allocator_ext_dma.h"
|
||||||
|
#include "allocator_ion.h"
|
||||||
|
#include "allocator_std.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Linux only support MPP_BUFFER_TYPE_NORMAL so far
|
* Linux only support MPP_BUFFER_TYPE_NORMAL so far
|
||||||
@@ -41,9 +42,8 @@ MPP_RET os_allocator_get(os_allocator *api, MppBufferType type)
|
|||||||
#endif
|
#endif
|
||||||
allocator_std;
|
allocator_std;
|
||||||
} break;
|
} break;
|
||||||
case MPP_BUFFER_TYPE_V4L2 : {
|
case MPP_BUFFER_TYPE_EXT_DMA: {
|
||||||
mpp_err("os_allocator_get Linux MPP_BUFFER_TYPE_V4L2 do not implement yet\n");
|
*api = allocator_ext_dma;
|
||||||
*api = allocator_std;
|
|
||||||
} break;
|
} break;
|
||||||
case MPP_BUFFER_TYPE_DRM : {
|
case MPP_BUFFER_TYPE_DRM : {
|
||||||
#if HAVE_DRM
|
#if HAVE_DRM
|
||||||
|
@@ -77,7 +77,6 @@ MppRuntimeService::MppRuntimeService()
|
|||||||
{
|
{
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
allocator_valid[MPP_BUFFER_TYPE_NORMAL] = 1;
|
allocator_valid[MPP_BUFFER_TYPE_NORMAL] = 1;
|
||||||
allocator_valid[MPP_BUFFER_TYPE_V4L2] = 0;
|
|
||||||
|
|
||||||
fd = open("/dev/ion", O_RDWR);
|
fd = open("/dev/ion", O_RDWR);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
@@ -6,7 +6,7 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
|
|||||||
Name: rockchip_mpp
|
Name: rockchip_mpp
|
||||||
Description: Rockchip Media Process Platform
|
Description: Rockchip Media Process Platform
|
||||||
Requires.private:
|
Requires.private:
|
||||||
Version: 1.3.7
|
Version: 1.3.8
|
||||||
Libs: -L${libdir} -lrockchip_mpp
|
Libs: -L${libdir} -lrockchip_mpp
|
||||||
Libs.private:
|
Libs.private:
|
||||||
Cflags: -I${includedir}
|
Cflags: -I${includedir}
|
||||||
|
Reference in New Issue
Block a user