mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-05 17:16:50 +08:00
[hal_jpege]: Add dma heap options for JPEG encode.
use cachable dma buffer to reduce copy time. Signed-off-by: xueman.ruan <xueman.ruan@rock-chips.com> Change-Id: I7fcc0fa5942ea5aa4e247b5f10677843d006ff28
This commit is contained in:
@@ -142,9 +142,14 @@ typedef enum {
|
|||||||
* DRM SECURE buffer: MPP_BUFFER_TYPE_DRM | MPP_BUFFER_FLAGS_SECURE
|
* DRM SECURE buffer: MPP_BUFFER_TYPE_DRM | MPP_BUFFER_FLAGS_SECURE
|
||||||
* = 0x00080003
|
* = 0x00080003
|
||||||
*
|
*
|
||||||
|
* The dma buffer source can also be set by format: flags | type.
|
||||||
|
* dma buffer source flags:
|
||||||
|
* MPP_BUFFER_FLAGS_CONTIG means cma
|
||||||
|
* MPP_BUFFER_FLAGS_CACHABLE means cachable
|
||||||
|
* MPP_BUFFER_FLAGS_DMA32 means dma32
|
||||||
|
*
|
||||||
* flags originate from drm_rockchip_gem_mem_type
|
* flags originate from drm_rockchip_gem_mem_type
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define MPP_BUFFER_FLAGS_MASK 0x003f0000 //ROCKCHIP_BO_MASK << 16
|
#define MPP_BUFFER_FLAGS_MASK 0x003f0000 //ROCKCHIP_BO_MASK << 16
|
||||||
#define MPP_BUFFER_FLAGS_CONTIG 0x00010000 //ROCKCHIP_BO_CONTIG << 16
|
#define MPP_BUFFER_FLAGS_CONTIG 0x00010000 //ROCKCHIP_BO_CONTIG << 16
|
||||||
#define MPP_BUFFER_FLAGS_CACHABLE 0x00020000 //ROCKCHIP_BO_CACHABLE << 16
|
#define MPP_BUFFER_FLAGS_CACHABLE 0x00020000 //ROCKCHIP_BO_CACHABLE << 16
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
#define MAX_GROUP_BIT 8
|
#define MAX_GROUP_BIT 8
|
||||||
#define MAX_MISC_GROUP_BIT 3
|
#define MAX_MISC_GROUP_BIT 3
|
||||||
#define BUFFER_OPS_MAX_COUNT 1024
|
#define BUFFER_OPS_MAX_COUNT 1024
|
||||||
|
#define MPP_BUFFER_SPECIAL_DMA_HEAP_NUM 8
|
||||||
|
|
||||||
#define SEARCH_GROUP_BY_ID(id) ((MppBufferService::get_instance())->get_group_by_id(id))
|
#define SEARCH_GROUP_BY_ID(id) ((MppBufferService::get_instance())->get_group_by_id(id))
|
||||||
|
|
||||||
@@ -63,6 +64,8 @@ private:
|
|||||||
/* preset allocator apis */
|
/* preset allocator apis */
|
||||||
MppAllocator mAllocator[MPP_BUFFER_TYPE_BUTT];
|
MppAllocator mAllocator[MPP_BUFFER_TYPE_BUTT];
|
||||||
MppAllocatorApi *mAllocatorApi[MPP_BUFFER_TYPE_BUTT];
|
MppAllocatorApi *mAllocatorApi[MPP_BUFFER_TYPE_BUTT];
|
||||||
|
/* special dma heap allocator apis */
|
||||||
|
MppAllocator mAllocatorDmaHeapWithFlag[MPP_BUFFER_SPECIAL_DMA_HEAP_NUM];
|
||||||
|
|
||||||
struct list_head mListGroup;
|
struct list_head mListGroup;
|
||||||
DECLARE_HASHTABLE(mHashGroup, MAX_GROUP_BIT);
|
DECLARE_HASHTABLE(mHashGroup, MAX_GROUP_BIT);
|
||||||
@@ -777,9 +780,6 @@ MppBufferService::MppBufferService()
|
|||||||
|
|
||||||
for (i = 0; i < (RK_S32)HASH_SIZE(mHashGroup); i++)
|
for (i = 0; i < (RK_S32)HASH_SIZE(mHashGroup); i++)
|
||||||
INIT_HLIST_HEAD(&mHashGroup[i]);
|
INIT_HLIST_HEAD(&mHashGroup[i]);
|
||||||
|
|
||||||
for (i = 0; i < MPP_BUFFER_TYPE_BUTT; i++)
|
|
||||||
mpp_allocator_get(&mAllocator[i], &mAllocatorApi[i], (MppBufferType)i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "mpp_time.h"
|
#include "mpp_time.h"
|
||||||
@@ -833,6 +833,9 @@ MppBufferService::~MppBufferService()
|
|||||||
|
|
||||||
for (i = 0; i < MPP_BUFFER_TYPE_BUTT; i++)
|
for (i = 0; i < MPP_BUFFER_TYPE_BUTT; i++)
|
||||||
mpp_allocator_put(&mAllocator[i]);
|
mpp_allocator_put(&mAllocator[i]);
|
||||||
|
|
||||||
|
for (i = 1; i < MPP_BUFFER_SPECIAL_DMA_HEAP_NUM; i++)
|
||||||
|
mpp_allocator_put(&mAllocatorDmaHeapWithFlag[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
RK_U32 MppBufferService::get_group_id()
|
RK_U32 MppBufferService::get_group_id()
|
||||||
@@ -868,6 +871,7 @@ MppBufferGroupImpl *MppBufferService::get_group(const char *tag, const char *cal
|
|||||||
RK_U32 is_misc)
|
RK_U32 is_misc)
|
||||||
{
|
{
|
||||||
MppBufferType buffer_type = (MppBufferType)(type & MPP_BUFFER_TYPE_MASK);
|
MppBufferType buffer_type = (MppBufferType)(type & MPP_BUFFER_TYPE_MASK);
|
||||||
|
RK_U32 flags = (type & MPP_BUFFER_FLAGS_MASK);
|
||||||
MppBufferGroupImpl *p = (MppBufferGroupImpl *)mpp_mem_pool_get_f(caller, mpp_buf_grp_pool);
|
MppBufferGroupImpl *p = (MppBufferGroupImpl *)mpp_mem_pool_get_f(caller, mpp_buf_grp_pool);
|
||||||
if (NULL == p) {
|
if (NULL == p) {
|
||||||
mpp_err("MppBufferService failed to allocate group context\n");
|
mpp_err("MppBufferService failed to allocate group context\n");
|
||||||
@@ -896,8 +900,38 @@ MppBufferGroupImpl *MppBufferService::get_group(const char *tag, const char *cal
|
|||||||
pthread_mutex_init(&p->buf_lock, &attr);
|
pthread_mutex_init(&p->buf_lock, &attr);
|
||||||
pthread_mutexattr_destroy(&attr);
|
pthread_mutexattr_destroy(&attr);
|
||||||
|
|
||||||
p->allocator = mAllocator[type];
|
{
|
||||||
p->alloc_api = mAllocatorApi[type];
|
AutoMutex auto_lock(get_lock());
|
||||||
|
|
||||||
|
// allocate general buffer first
|
||||||
|
if (!mAllocator[buffer_type])
|
||||||
|
mpp_allocator_get(&mAllocator[buffer_type], &mAllocatorApi[buffer_type], buffer_type);
|
||||||
|
|
||||||
|
p->allocator = mAllocator[buffer_type];
|
||||||
|
p->alloc_api = mAllocatorApi[buffer_type];
|
||||||
|
|
||||||
|
// allocate extra dma heap buffer if necessary
|
||||||
|
if (flags && MPP_BUFFER_TYPE_DMA_HEAP == get_real_allocator_type(p->allocator)) {
|
||||||
|
RK_U32 extra_allocator_idx = 0;
|
||||||
|
|
||||||
|
// calculate index of extra allocator
|
||||||
|
if (flags & MPP_BUFFER_FLAGS_CONTIG)
|
||||||
|
extra_allocator_idx |= 1 << 0;
|
||||||
|
|
||||||
|
if (flags & MPP_BUFFER_FLAGS_CACHABLE)
|
||||||
|
extra_allocator_idx |= 1 << 1;
|
||||||
|
|
||||||
|
if (flags & MPP_BUFFER_FLAGS_DMA32)
|
||||||
|
extra_allocator_idx |= 1 << 2;
|
||||||
|
|
||||||
|
if (!mAllocatorDmaHeapWithFlag[extra_allocator_idx])
|
||||||
|
mpp_allocator_get(&mAllocatorDmaHeapWithFlag[extra_allocator_idx],
|
||||||
|
&p->alloc_api, type);
|
||||||
|
|
||||||
|
if (mAllocatorDmaHeapWithFlag[extra_allocator_idx])
|
||||||
|
p->allocator = mAllocatorDmaHeapWithFlag[extra_allocator_idx];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mpp_assert(p->allocator);
|
mpp_assert(p->allocator);
|
||||||
mpp_assert(p->alloc_api);
|
mpp_assert(p->alloc_api);
|
||||||
|
@@ -208,8 +208,11 @@ MPP_RET hal_jpege_vepu2_get_task(void *hal, HalEncTask *task)
|
|||||||
|
|
||||||
mpp_assert(ctx_ext);
|
mpp_assert(ctx_ext);
|
||||||
|
|
||||||
|
if (!ctx_ext->partions_group) {
|
||||||
|
mpp_buffer_group_get_internal(&ctx_ext->partions_group, MPP_BUFFER_TYPE_DMA_HEAP | MPP_BUFFER_FLAGS_CACHABLE);
|
||||||
if (!ctx_ext->partions_group)
|
if (!ctx_ext->partions_group)
|
||||||
mpp_buffer_group_get_internal(&ctx_ext->partions_group, MPP_BUFFER_TYPE_ION);
|
mpp_buffer_group_get_internal(&ctx_ext->partions_group, MPP_BUFFER_TYPE_ION);
|
||||||
|
}
|
||||||
|
|
||||||
mpp_assert(ctx_ext->partions_group);
|
mpp_assert(ctx_ext->partions_group);
|
||||||
|
|
||||||
|
@@ -100,7 +100,7 @@ static int dma_heap_alloc(int fd, size_t len, RK_S32 *dmabuf_fd, RK_U32 flags)
|
|||||||
memset(&data, 0, sizeof(data));
|
memset(&data, 0, sizeof(data));
|
||||||
data.len = len;
|
data.len = len;
|
||||||
data.fd_flags = O_RDWR | O_CLOEXEC;
|
data.fd_flags = O_RDWR | O_CLOEXEC;
|
||||||
data.heap_flags = flags;
|
data.heap_flags = 0; // heap_flags should be set to 0
|
||||||
|
|
||||||
ret = ioctl(fd, DMA_HEAP_IOCTL_ALLOC, &data);
|
ret = ioctl(fd, DMA_HEAP_IOCTL_ALLOC, &data);
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ static int heap_fd_open(DmaHeapType type)
|
|||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
snprintf(name, sizeof(name) - 1, "%s%s", heap_path, heap_names[type]);
|
snprintf(name, sizeof(name) - 1, "%s%s", heap_path, heap_names[type]);
|
||||||
fd = open(name, O_RDWR | O_CLOEXEC);
|
fd = open(name, O_RDONLY | O_CLOEXEC); // read authority is enough
|
||||||
mpp_assert(fd > 0);
|
mpp_assert(fd > 0);
|
||||||
|
|
||||||
dma_heap_dbg(DMA_HEAP_DEVICE, "open dma heap dev %s fd %d\n", name, fd);
|
dma_heap_dbg(DMA_HEAP_DEVICE, "open dma heap dev %s fd %d\n", name, fd);
|
||||||
@@ -320,6 +320,7 @@ static MPP_RET os_allocator_dma_heap_mmap(void *ctx, MppBufferInfo *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
os_allocator allocator_dma_heap = {
|
os_allocator allocator_dma_heap = {
|
||||||
|
.type = MPP_BUFFER_TYPE_DMA_HEAP,
|
||||||
.open = os_allocator_dma_heap_open,
|
.open = os_allocator_dma_heap_open,
|
||||||
.close = os_allocator_dma_heap_close,
|
.close = os_allocator_dma_heap_close,
|
||||||
.alloc = os_allocator_dma_heap_alloc,
|
.alloc = os_allocator_dma_heap_alloc,
|
||||||
|
@@ -322,6 +322,7 @@ static MPP_RET os_allocator_drm_mmap(void *ctx, MppBufferInfo *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
os_allocator allocator_drm = {
|
os_allocator allocator_drm = {
|
||||||
|
.type = MPP_BUFFER_TYPE_DRM,
|
||||||
.open = os_allocator_drm_open,
|
.open = os_allocator_drm_open,
|
||||||
.close = os_allocator_drm_close,
|
.close = os_allocator_drm_close,
|
||||||
.alloc = os_allocator_drm_alloc,
|
.alloc = os_allocator_drm_alloc,
|
||||||
|
@@ -135,6 +135,7 @@ static MPP_RET allocator_ext_dma_close(void *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
os_allocator allocator_ext_dma = {
|
os_allocator allocator_ext_dma = {
|
||||||
|
.type = MPP_BUFFER_TYPE_EXT_DMA,
|
||||||
.open = allocator_ext_dma_open,
|
.open = allocator_ext_dma_open,
|
||||||
.close = allocator_ext_dma_close,
|
.close = allocator_ext_dma_close,
|
||||||
.alloc = allocator_ext_dma_alloc,
|
.alloc = allocator_ext_dma_alloc,
|
||||||
|
@@ -482,6 +482,7 @@ static MPP_RET allocator_ion_close(void *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
os_allocator allocator_ion = {
|
os_allocator allocator_ion = {
|
||||||
|
.type = MPP_BUFFER_TYPE_ION,
|
||||||
.open = allocator_ion_open,
|
.open = allocator_ion_open,
|
||||||
.close = allocator_ion_close,
|
.close = allocator_ion_close,
|
||||||
.alloc = allocator_ion_alloc,
|
.alloc = allocator_ion_alloc,
|
||||||
|
@@ -114,6 +114,7 @@ static MPP_RET allocator_std_close(void *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
os_allocator allocator_std = {
|
os_allocator allocator_std = {
|
||||||
|
.type = MPP_BUFFER_TYPE_NORMAL,
|
||||||
.open = allocator_std_open,
|
.open = allocator_std_open,
|
||||||
.close = allocator_std_close,
|
.close = allocator_std_close,
|
||||||
.alloc = allocator_std_alloc,
|
.alloc = allocator_std_alloc,
|
||||||
|
@@ -46,6 +46,7 @@ extern "C" {
|
|||||||
MPP_RET mpp_allocator_get(MppAllocator *allocator,
|
MPP_RET mpp_allocator_get(MppAllocator *allocator,
|
||||||
MppAllocatorApi **api, MppBufferType type);
|
MppAllocatorApi **api, MppBufferType type);
|
||||||
MPP_RET mpp_allocator_put(MppAllocator *allocator);
|
MPP_RET mpp_allocator_put(MppAllocator *allocator);
|
||||||
|
MppBufferType get_real_allocator_type(const MppAllocator allocator);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@@ -189,3 +189,10 @@ MPP_RET mpp_allocator_put(MppAllocator *allocator)
|
|||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MppBufferType get_real_allocator_type(const MppAllocator allocator)
|
||||||
|
{
|
||||||
|
MppAllocatorImpl *p = (MppAllocatorImpl *)allocator;
|
||||||
|
MppBufferType type = allocator ? p->os_api.type : MPP_BUFFER_TYPE_BUTT;
|
||||||
|
|
||||||
|
return type;
|
||||||
|
}
|
@@ -86,7 +86,7 @@ MppRuntimeService::MppRuntimeService()
|
|||||||
allocator_valid[MPP_BUFFER_TYPE_NORMAL] = 1;
|
allocator_valid[MPP_BUFFER_TYPE_NORMAL] = 1;
|
||||||
allocator_valid[MPP_BUFFER_TYPE_ION] = !access("/dev/ion", F_OK | R_OK | W_OK);
|
allocator_valid[MPP_BUFFER_TYPE_ION] = !access("/dev/ion", F_OK | R_OK | W_OK);
|
||||||
allocator_valid[MPP_BUFFER_TYPE_DRM] = !access("/dev/dri/card0", F_OK | R_OK | W_OK);
|
allocator_valid[MPP_BUFFER_TYPE_DRM] = !access("/dev/dri/card0", F_OK | R_OK | W_OK);
|
||||||
allocator_valid[MPP_BUFFER_TYPE_DMA_HEAP] = !access("/dev/dma_heap", F_OK | R_OK | W_OK);
|
allocator_valid[MPP_BUFFER_TYPE_DMA_HEAP] = !access("/dev/dma_heap", F_OK | R_OK);
|
||||||
|
|
||||||
if (!allocator_valid[MPP_BUFFER_TYPE_ION] &&
|
if (!allocator_valid[MPP_BUFFER_TYPE_ION] &&
|
||||||
!allocator_valid[MPP_BUFFER_TYPE_DRM] &&
|
!allocator_valid[MPP_BUFFER_TYPE_DRM] &&
|
||||||
|
@@ -22,6 +22,8 @@
|
|||||||
typedef MPP_RET (*OsAllocatorFunc)(void *ctx, MppBufferInfo *info);
|
typedef MPP_RET (*OsAllocatorFunc)(void *ctx, MppBufferInfo *info);
|
||||||
|
|
||||||
typedef struct os_allocator_t {
|
typedef struct os_allocator_t {
|
||||||
|
MppBufferType type;
|
||||||
|
|
||||||
MPP_RET (*open)(void **ctx, MppAllocatorCfg *cfg);
|
MPP_RET (*open)(void **ctx, MppAllocatorCfg *cfg);
|
||||||
MPP_RET (*close)(void *ctx);
|
MPP_RET (*close)(void *ctx);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user