mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-06 17:46:50 +08:00
[h265d]: dpb size change to MAX_DPB_SIZE
[vpu_legacy]: add vpu_mem alloc and rk_list.cpp to compatibility old version vpu [vpu_legacy]: used dlopen to compatibility using old librk_vpuapi git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@419 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
@@ -19,20 +19,13 @@
|
||||
#include <string.h>
|
||||
#include "mpp_log.h"
|
||||
#include "mpp_mem.h"
|
||||
#include "mpp_buffer.h"
|
||||
#include "vpu_api_legacy.h"
|
||||
#include "vpu_mem_legacy.h"
|
||||
#include "vpu_api.h"
|
||||
#include "vpu.h"
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <linux/ion.h>
|
||||
#endif
|
||||
|
||||
typedef struct vpu_display_mem_pool_impl {
|
||||
vpu_display_mem_pool_FIELDS
|
||||
MppBufferGroup group;
|
||||
RK_S32 size;
|
||||
} vpu_display_mem_pool_impl;
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
#include "mpp_env.h"
|
||||
|
||||
static RK_S32 vpu_api_init(VpuCodecContext *ctx, RK_U8 *extraData, RK_U32 extra_size)
|
||||
{
|
||||
@@ -196,40 +189,107 @@ static RK_S32 vpu_api_control(VpuCodecContext *ctx, VPU_API_CMD cmdType, void *p
|
||||
return api->control(ctx, cmdType, param);
|
||||
}
|
||||
|
||||
#ifdef ANDROID
|
||||
RK_S32 open_orign_vpu(VpuCodecContext **ctx)
|
||||
{
|
||||
void *rkapi_hdl = NULL;
|
||||
RK_S32 (*rkvpu_open_cxt)(VpuCodecContext **ctx);
|
||||
rkapi_hdl = dlopen("/system/lib/librk_vpuapi.so", RTLD_LAZY);
|
||||
if (rkapi_hdl == NULL) {
|
||||
mpp_err_f("dlopen librk_vpuapi library fail\n");
|
||||
return -1;
|
||||
}
|
||||
rkvpu_open_cxt = (RK_S32 (*)(VpuCodecContext **ctx))dlsym(rkapi_hdl, "vpu_open_context");
|
||||
dlclose(rkapi_hdl);
|
||||
if (rkvpu_open_cxt == NULL) {
|
||||
mpp_err("dlsym rkvpu_open_cxt fail ");
|
||||
return -1;
|
||||
} else {
|
||||
(*rkvpu_open_cxt)(ctx);
|
||||
return MPP_OK;
|
||||
}
|
||||
}
|
||||
|
||||
RK_S32 close_orign_vpu(VpuCodecContext **ctx)
|
||||
{
|
||||
void *rkapi_hdl = NULL;
|
||||
RK_S32 (*rkvpu_close_cxt)(VpuCodecContext **ctx);
|
||||
rkapi_hdl = dlopen("/system/lib/librk_vpuapi.so", RTLD_LAZY);
|
||||
if (rkapi_hdl == NULL) {
|
||||
mpp_err_f("dlopen librk_vpuapi library fail\n");
|
||||
return -1;
|
||||
}
|
||||
rkvpu_close_cxt = (RK_S32 (*)(VpuCodecContext **ctx))dlsym(rkapi_hdl, "vpu_close_context");
|
||||
if (rkvpu_close_cxt == NULL) {
|
||||
mpp_err_f("dlsym rkvpu_close_cxt fail");
|
||||
return -1;
|
||||
} else {
|
||||
(*rkvpu_close_cxt)(ctx);
|
||||
return MPP_OK;
|
||||
}
|
||||
dlclose(rkapi_hdl);
|
||||
}
|
||||
#endif
|
||||
RK_S32 vpu_open_context(VpuCodecContext **ctx)
|
||||
{
|
||||
mpp_log("vpu_open_context in");
|
||||
VpuCodecContext *s = *ctx;
|
||||
|
||||
if (!s) {
|
||||
s = mpp_malloc(VpuCodecContext, 1);
|
||||
if (!s) {
|
||||
mpp_err("Input context has not been properly allocated");
|
||||
return -1;
|
||||
RK_U32 value;
|
||||
mpp_env_get_u32("chg_org", &value, 0);
|
||||
#ifdef ANDROID
|
||||
if (value || !s) {
|
||||
if (s) {
|
||||
free(s);
|
||||
s = NULL;
|
||||
}
|
||||
memset(s, 0, sizeof(VpuCodecContext));
|
||||
s->enableparsing = 1;
|
||||
|
||||
VpuApi* api = new VpuApi();
|
||||
|
||||
if (api == NULL) {
|
||||
mpp_err("Vpu api object has not been properly allocated");
|
||||
return -1;
|
||||
}
|
||||
|
||||
s->vpuApiObj = (void*)api;
|
||||
s->init = vpu_api_init;
|
||||
s->decode = vpu_api_decode;
|
||||
s->encode = vpu_api_encode;
|
||||
s->flush = vpu_api_flush;
|
||||
s->control = vpu_api_control;
|
||||
s->decode_sendstream = vpu_api_sendstream;
|
||||
s->decode_getframe = vpu_api_getframe;
|
||||
s->encoder_sendframe = vpu_api_sendframe;
|
||||
s->encoder_getstream = vpu_api_getstream;
|
||||
|
||||
open_orign_vpu(&s);
|
||||
s->extra_cfg.reserved[0] = 1;
|
||||
*ctx = s;
|
||||
return 0;
|
||||
return MPP_OK;
|
||||
}
|
||||
#endif
|
||||
if (s != NULL) {
|
||||
mpp_log("s->videoCoding = %d", s->videoCoding);
|
||||
if (s->videoCoding == OMX_RK_VIDEO_CodingHEVC) {
|
||||
free(s);
|
||||
s = NULL;
|
||||
s = mpp_malloc(VpuCodecContext, 1);
|
||||
if (!s) {
|
||||
mpp_err("Input context has not been properly allocated");
|
||||
return -1;
|
||||
}
|
||||
memset(s, 0, sizeof(VpuCodecContext));
|
||||
s->enableparsing = 1;
|
||||
|
||||
VpuApi* api = new VpuApi();
|
||||
|
||||
if (api == NULL) {
|
||||
mpp_err("Vpu api object has not been properly allocated");
|
||||
return -1;
|
||||
}
|
||||
|
||||
s->vpuApiObj = (void*)api;
|
||||
s->init = vpu_api_init;
|
||||
s->decode = vpu_api_decode;
|
||||
s->encode = vpu_api_encode;
|
||||
s->flush = vpu_api_flush;
|
||||
s->control = vpu_api_control;
|
||||
s->decode_sendstream = vpu_api_sendstream;
|
||||
s->decode_getframe = vpu_api_getframe;
|
||||
s->encoder_sendframe = vpu_api_sendframe;
|
||||
s->encoder_getstream = vpu_api_getstream;
|
||||
|
||||
*ctx = s;
|
||||
return 0;
|
||||
} else {
|
||||
#ifdef ANDROID
|
||||
free(s);
|
||||
s = NULL;
|
||||
open_orign_vpu(&s);
|
||||
s->extra_cfg.reserved[0] = 1;
|
||||
*ctx = s;
|
||||
return MPP_OK;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (!s->vpuApiObj) {
|
||||
@@ -243,7 +303,15 @@ RK_S32 vpu_close_context(VpuCodecContext **ctx)
|
||||
{
|
||||
mpp_log("vpu_close_context in");
|
||||
VpuCodecContext *s = *ctx;
|
||||
|
||||
RK_U32 value;
|
||||
mpp_env_get_u32("chg_org", &value, 0);
|
||||
#ifdef ANDROID
|
||||
if (value || s->extra_cfg.reserved[0]) {
|
||||
close_orign_vpu(ctx);
|
||||
mpp_log("org vpu_close_context ok");
|
||||
return MPP_OK;
|
||||
}
|
||||
#endif
|
||||
if (s) {
|
||||
VpuApi* api = (VpuApi*)(s->vpuApiObj);
|
||||
if (s->vpuApiObj) {
|
||||
@@ -254,216 +322,7 @@ RK_S32 vpu_close_context(VpuCodecContext **ctx)
|
||||
mpp_free(s->private_data);
|
||||
mpp_free(s);
|
||||
*ctx = s = NULL;
|
||||
|
||||
mpp_log("vpu_close_context ok");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static RK_S32 commit_memory_handle(vpu_display_mem_pool *p, RK_S32 mem_hdl, RK_S32 size)
|
||||
{
|
||||
MppBufferInfo info;
|
||||
|
||||
vpu_display_mem_pool_impl *p_mempool = (vpu_display_mem_pool_impl *)p;
|
||||
memset(&info, 0, sizeof(MppBufferInfo));
|
||||
info.type = MPP_BUFFER_TYPE_ION;
|
||||
info.fd = mem_hdl;
|
||||
info.size = size;
|
||||
p_mempool->size = size;
|
||||
mpp_buffer_commit(p_mempool->group, &info);
|
||||
return info.fd;
|
||||
}
|
||||
|
||||
static void* get_free_memory_vpumem(vpu_display_mem_pool *p)
|
||||
{
|
||||
MPP_RET ret = MPP_OK;
|
||||
MppBuffer buffer = NULL;
|
||||
VPUMemLinear_t *dmabuf = mpp_calloc(VPUMemLinear_t, 1);
|
||||
vpu_display_mem_pool_impl *p_mempool = (vpu_display_mem_pool_impl *)p;
|
||||
if (dmabuf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ret = mpp_buffer_get(p_mempool->group, &buffer, p_mempool->size);
|
||||
if (MPP_OK != ret) {
|
||||
mpp_free(dmabuf);
|
||||
return NULL;
|
||||
}
|
||||
dmabuf->phy_addr = (RK_U32)mpp_buffer_get_fd(buffer);
|
||||
dmabuf->vir_addr = (RK_U32*)mpp_buffer_get_ptr(buffer);
|
||||
dmabuf->size = p_mempool->size;
|
||||
dmabuf->offset = (RK_U32*)buffer;
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
static RK_S32 inc_used_memory_handle_ref(vpu_display_mem_pool *p, void * hdl)
|
||||
{
|
||||
(void)p;
|
||||
VPUMemLinear_t *dmabuf = (VPUMemLinear_t *)hdl;
|
||||
MppBuffer buffer = (MppBuffer)dmabuf->offset;
|
||||
if (buffer != NULL) {
|
||||
mpp_buffer_inc_ref(buffer);
|
||||
}
|
||||
return MPP_OK;
|
||||
|
||||
}
|
||||
|
||||
static RK_S32 put_used_memory_handle(vpu_display_mem_pool *p, void *hdl)
|
||||
{
|
||||
(void)p;
|
||||
VPUMemLinear_t *dmabuf = (VPUMemLinear_t *)hdl;
|
||||
MppBuffer buf = (MppBuffer)dmabuf->offset;
|
||||
if (buf != NULL) {
|
||||
mpp_buffer_put(buf);
|
||||
}
|
||||
return MPP_OK;
|
||||
}
|
||||
|
||||
static RK_S32 get_free_memory_num(vpu_display_mem_pool *p)
|
||||
{
|
||||
vpu_display_mem_pool_impl *p_mempool = (vpu_display_mem_pool_impl *)p;
|
||||
if (p_mempool->group != NULL) {
|
||||
return mpp_buffer_group_unused(p_mempool->group);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static RK_S32 reset_vpu_mem_pool(vpu_display_mem_pool *p)
|
||||
{
|
||||
vpu_display_mem_pool_impl *p_mempool = (vpu_display_mem_pool_impl *)p;
|
||||
mpp_buffer_group_clear(p_mempool->group);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
vpu_display_mem_pool* open_vpu_memory_pool()
|
||||
{
|
||||
mpp_err("open_vpu_memory_pool in\n");
|
||||
vpu_display_mem_pool_impl *p_mempool = mpp_calloc(vpu_display_mem_pool_impl, 1);
|
||||
|
||||
if (NULL == p_mempool) {
|
||||
return NULL;
|
||||
}
|
||||
mpp_buffer_group_get_external(&p_mempool->group, MPP_BUFFER_TYPE_ION);
|
||||
if (NULL == p_mempool->group) {
|
||||
return NULL;
|
||||
}
|
||||
p_mempool->commit_hdl = commit_memory_handle;
|
||||
p_mempool->get_free = get_free_memory_vpumem;
|
||||
p_mempool->put_used = put_used_memory_handle;
|
||||
p_mempool->inc_used = inc_used_memory_handle_ref;
|
||||
p_mempool->reset = reset_vpu_mem_pool;
|
||||
p_mempool->get_unused_num = get_free_memory_num;
|
||||
p_mempool->version = 1;
|
||||
p_mempool->buff_size = -1;
|
||||
return (vpu_display_mem_pool*)p_mempool;
|
||||
}
|
||||
|
||||
void close_vpu_memory_pool(vpu_display_mem_pool *p)
|
||||
{
|
||||
|
||||
vpu_display_mem_pool_impl *p_mempool = (vpu_display_mem_pool_impl *)p;
|
||||
mpp_buffer_group_put(p_mempool->group);
|
||||
return;
|
||||
}
|
||||
|
||||
int create_vpu_memory_pool_allocator(vpu_display_mem_pool **ipool, int num, int size)
|
||||
{
|
||||
(void)ipool;
|
||||
(void)num;
|
||||
(void)size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void release_vpu_memory_pool_allocator(vpu_display_mem_pool *ipool)
|
||||
{
|
||||
(void)ipool;
|
||||
}
|
||||
|
||||
RK_S32 VPUMemJudgeIommu()
|
||||
{
|
||||
int ret = 0;
|
||||
#ifdef ANDROID
|
||||
if (VPUClientGetIOMMUStatus() > 0) {
|
||||
//mpp_err("media.used.iommu");
|
||||
ret = 1;
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
RK_S32 VPUMallocLinear(VPUMemLinear_t *p, RK_U32 size)
|
||||
{
|
||||
(void)p;
|
||||
(void)size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
RK_S32 VPUFreeLinear(VPUMemLinear_t *p)
|
||||
{
|
||||
put_used_memory_handle(NULL, p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
RK_S32 VPUMemDuplicate(VPUMemLinear_t *dst, VPUMemLinear_t *src)
|
||||
{
|
||||
(void)dst;
|
||||
(void)src;
|
||||
return 0;
|
||||
}
|
||||
|
||||
RK_S32 VPUMemLink(VPUMemLinear_t *p)
|
||||
{
|
||||
(void)p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
RK_S32 VPUMemFlush(VPUMemLinear_t *p)
|
||||
{
|
||||
(void)p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
RK_S32 VPUMemClean(VPUMemLinear_t *p)
|
||||
{
|
||||
(void)p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
RK_S32 VPUMemInvalidate(VPUMemLinear_t *p)
|
||||
{
|
||||
(void)p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
RK_S32 VPUMemGetFD(VPUMemLinear_t *p)
|
||||
{
|
||||
RK_S32 fd = 0;
|
||||
MppBuffer buffer = (MppBuffer)p->offset;
|
||||
fd = mpp_buffer_get_fd(buffer);
|
||||
//mpp_err("fd = 0x%x",fd);
|
||||
return fd;
|
||||
|
||||
}
|
||||
|
||||
RK_S32 vpu_mem_judge_used_heaps_type()
|
||||
{
|
||||
// TODO, use property_get
|
||||
#if 0 //def ANDROID
|
||||
if (!VPUClientGetIOMMUStatus() > 0) {
|
||||
return ION_HEAP(ION_CMA_HEAP_ID);
|
||||
} else {
|
||||
ALOGV("USE ION_SYSTEM_HEAP");
|
||||
return ION_HEAP(ION_VMALLOC_HEAP_ID);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user