mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-06 01:26:49 +08:00
[misc]: use static api structure rather than malloc on
git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@141 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
45
mpp/mpi.cpp
45
mpp/mpi.cpp
@@ -116,10 +116,24 @@ static MPP_RET mpi_control(MppCtx ctx, MPI_CMD cmd, MppParam param)
|
|||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static MppApi mpp_api = {
|
||||||
|
sizeof(mpp_api),
|
||||||
|
1,
|
||||||
|
mpi_init,
|
||||||
|
mpi_decode,
|
||||||
|
mpi_encode,
|
||||||
|
mpi_decode_put_packet,
|
||||||
|
mpi_decode_get_frame,
|
||||||
|
mpi_encode_put_frame,
|
||||||
|
mpi_encode_get_packet,
|
||||||
|
mpi_flush,
|
||||||
|
mpi_control,
|
||||||
|
{0},
|
||||||
|
};
|
||||||
|
|
||||||
MPP_RET mpp_init(MppCtx *ctx, MppApi **mpi)
|
MPP_RET mpp_init(MppCtx *ctx, MppApi **mpi)
|
||||||
{
|
{
|
||||||
MpiImpl *p;
|
MpiImpl *p;
|
||||||
MppApi *api;
|
|
||||||
MPI_FUNCTION_ENTER();
|
MPI_FUNCTION_ENTER();
|
||||||
|
|
||||||
if (NULL == ctx || NULL == mpi) {
|
if (NULL == ctx || NULL == mpi) {
|
||||||
@@ -134,30 +148,11 @@ MPP_RET mpp_init(MppCtx *ctx, MppApi **mpi)
|
|||||||
return MPP_ERR_MALLOC;
|
return MPP_ERR_MALLOC;
|
||||||
}
|
}
|
||||||
|
|
||||||
api = mpp_malloc(MppApi, 1);
|
memset(p, 0, sizeof(*p));
|
||||||
if (NULL == api) {
|
p->api = &mpp_api;
|
||||||
mpp_err("mpp_init failed to allocate mpi\n");
|
p->check = p;
|
||||||
mpp_free(p);
|
|
||||||
return MPP_ERR_MALLOC;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(p, 0, sizeof(*p));
|
|
||||||
memset(api, 0, sizeof(*api));
|
|
||||||
api->size = sizeof(*api);
|
|
||||||
api->version = 1;
|
|
||||||
api->init = mpi_init;
|
|
||||||
api->decode = mpi_decode;
|
|
||||||
api->encode = mpi_encode;
|
|
||||||
api->decode_put_packet = mpi_decode_put_packet;
|
|
||||||
api->decode_get_frame = mpi_decode_get_frame;
|
|
||||||
api->encode_put_frame = mpi_encode_put_frame;
|
|
||||||
api->encode_get_packet = mpi_encode_get_packet;
|
|
||||||
api->flush = mpi_flush;
|
|
||||||
api->control = mpi_control;
|
|
||||||
p->api = api;
|
|
||||||
p->check = p;
|
|
||||||
*ctx = p;
|
*ctx = p;
|
||||||
*mpi = api;
|
*mpi = p->api;
|
||||||
|
|
||||||
get_mpi_debug();
|
get_mpi_debug();
|
||||||
|
|
||||||
@@ -182,8 +177,6 @@ MPP_RET mpp_deinit(MppCtx* ctx)
|
|||||||
return MPP_ERR_UNKNOW;
|
return MPP_ERR_UNKNOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p->api)
|
|
||||||
mpp_free(p->api);
|
|
||||||
if (p)
|
if (p)
|
||||||
mpp_free(p);
|
mpp_free(p);
|
||||||
*ctx = NULL;
|
*ctx = NULL;
|
||||||
|
@@ -58,6 +58,13 @@ MPP_RET mpp_allocator_free(MppAllocator allocator, MppBufferData *data)
|
|||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static MppAllocatorApi mpp_allocator_api = {
|
||||||
|
sizeof(mpp_allocator_api),
|
||||||
|
1,
|
||||||
|
mpp_allocator_alloc,
|
||||||
|
mpp_allocator_free,
|
||||||
|
};
|
||||||
|
|
||||||
MPP_RET mpp_alloctor_get(MppAllocator *allocator, MppAllocatorApi **api, MppBufferType type)
|
MPP_RET mpp_alloctor_get(MppAllocator *allocator, MppAllocatorApi **api, MppBufferType type)
|
||||||
{
|
{
|
||||||
if (NULL == allocator || NULL == api || type >= MPP_BUFFER_TYPE_BUTT) {
|
if (NULL == allocator || NULL == api || type >= MPP_BUFFER_TYPE_BUTT) {
|
||||||
@@ -72,21 +79,9 @@ MPP_RET mpp_alloctor_get(MppAllocator *allocator, MppAllocatorApi **api, MppBuff
|
|||||||
return MPP_ERR_NULL_PTR;
|
return MPP_ERR_NULL_PTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
MppAllocatorApi *papi = mpp_malloc(MppAllocatorApi, 1);
|
|
||||||
if (NULL == papi) {
|
|
||||||
mpp_err("mpp_alloctor_get failed to malloc api context\n");
|
|
||||||
mpp_free(palloc);
|
|
||||||
return MPP_ERR_NULL_PTR;
|
|
||||||
}
|
|
||||||
|
|
||||||
palloc->alignment = SZ_4K;
|
palloc->alignment = SZ_4K;
|
||||||
os_allocator_open(&palloc->allocator, palloc->alignment, type);
|
os_allocator_open(&palloc->allocator, palloc->alignment, type);
|
||||||
|
palloc->api = &mpp_allocator_api;
|
||||||
papi->size = sizeof(papi->size);
|
|
||||||
papi->version = 1;
|
|
||||||
papi->alloc = mpp_allocator_alloc;
|
|
||||||
papi->free = mpp_allocator_free;
|
|
||||||
palloc->api = papi;
|
|
||||||
|
|
||||||
pthread_mutexattr_t attr;
|
pthread_mutexattr_t attr;
|
||||||
pthread_mutexattr_init(&attr);
|
pthread_mutexattr_init(&attr);
|
||||||
@@ -95,7 +90,7 @@ MPP_RET mpp_alloctor_get(MppAllocator *allocator, MppAllocatorApi **api, MppBuff
|
|||||||
pthread_mutexattr_destroy(&attr);
|
pthread_mutexattr_destroy(&attr);
|
||||||
|
|
||||||
*allocator = palloc;
|
*allocator = palloc;
|
||||||
*api = papi;
|
*api = &mpp_allocator_api;
|
||||||
|
|
||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
}
|
}
|
||||||
@@ -111,8 +106,6 @@ MPP_RET mpp_alloctor_put(MppAllocator *allocator)
|
|||||||
*allocator = NULL;
|
*allocator = NULL;
|
||||||
os_allocator_close(p->allocator);
|
os_allocator_close(p->allocator);
|
||||||
|
|
||||||
mpp_assert(p->api);
|
|
||||||
mpp_free(p->api);
|
|
||||||
if (p)
|
if (p)
|
||||||
mpp_free(p);
|
mpp_free(p);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user