mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-06 09:36:49 +08:00
[linux]: fix mpp_buffer_test error on linux
git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@970 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
*/
|
||||
typedef struct {
|
||||
size_t alignment;
|
||||
RK_S32 fd_count;
|
||||
} allocator_ctx;
|
||||
|
||||
MPP_RET os_allocator_normal_open(void **ctx, size_t alignment)
|
||||
@@ -49,6 +50,8 @@ MPP_RET os_allocator_normal_open(void **ctx, size_t alignment)
|
||||
} else
|
||||
p->alignment = alignment;
|
||||
|
||||
p->fd_count = 0;
|
||||
|
||||
*ctx = p;
|
||||
return ret;
|
||||
}
|
||||
@@ -63,6 +66,7 @@ MPP_RET os_allocator_normal_alloc(void *ctx, MppBufferInfo *info)
|
||||
}
|
||||
|
||||
p = (allocator_ctx *)ctx;
|
||||
info->fd = p->fd_count++;
|
||||
return os_malloc(&info->ptr, p->alignment, info->size);
|
||||
}
|
||||
|
||||
@@ -76,11 +80,12 @@ MPP_RET os_allocator_normal_free(void *ctx, MppBufferInfo *info)
|
||||
|
||||
MPP_RET os_allocator_normal_import(void *ctx, MppBufferInfo *info)
|
||||
{
|
||||
(void) ctx;
|
||||
allocator_ctx *p = (allocator_ctx *)ctx;
|
||||
mpp_assert(ctx);
|
||||
mpp_assert(info->ptr);
|
||||
mpp_assert(info->size);
|
||||
info->hnd = NULL;
|
||||
info->fd = -1;
|
||||
info->fd = p->fd_count++;
|
||||
return MPP_OK;
|
||||
}
|
||||
|
||||
@@ -119,8 +124,8 @@ static os_allocator allocator_v4l2 = {
|
||||
os_allocator_normal_open,
|
||||
os_allocator_normal_alloc,
|
||||
os_allocator_normal_free,
|
||||
NULL,
|
||||
NULL,
|
||||
os_allocator_normal_import,
|
||||
os_allocator_normal_release,
|
||||
os_allocator_normal_close,
|
||||
};
|
||||
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#include "mpp_log.h"
|
||||
#include "mpp_env.h"
|
||||
#include "mpp_buffer.h"
|
||||
#include "mpp_allocator.h"
|
||||
|
||||
#define MPP_BUFFER_TEST_DEBUG_FLAG (0xf)
|
||||
#define MPP_BUFFER_TEST_SIZE (SZ_1K*4)
|
||||
@@ -33,6 +34,8 @@
|
||||
int main()
|
||||
{
|
||||
MPP_RET ret = MPP_OK;
|
||||
MppAllocator allocator = NULL;
|
||||
MppAllocatorApi *api = NULL;
|
||||
MppBufferInfo commit;
|
||||
MppBufferGroup group = NULL;
|
||||
MppBuffer commit_buffer[MPP_BUFFER_TEST_COMMIT_COUNT];
|
||||
@@ -113,18 +116,22 @@ int main()
|
||||
|
||||
mpp_log("mpp_buffer_test commit mode with used status start\n");
|
||||
|
||||
ret = mpp_allocator_get(&allocator, &api, MPP_BUFFER_TYPE_ION);
|
||||
if (MPP_OK != ret) {
|
||||
mpp_err("mpp_buffer_test mpp_allocator_get ion failed\n");
|
||||
goto MPP_BUFFER_failed;
|
||||
}
|
||||
|
||||
commit.type = MPP_BUFFER_TYPE_ION;
|
||||
commit.size = size;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
commit_ptr[i] = malloc(size);
|
||||
if (NULL == commit_ptr[i]) {
|
||||
mpp_err("mpp_buffer_test malloc failed\n");
|
||||
ret = api->alloc(allocator, &commit);
|
||||
if (ret) {
|
||||
mpp_err("mpp_buffer_test mpp_allocator_alloc failed\n");
|
||||
goto MPP_BUFFER_failed;
|
||||
}
|
||||
|
||||
commit.ptr = commit_ptr[i];
|
||||
|
||||
/*
|
||||
* NOTE: commit buffer info will be directly return within new MppBuffer
|
||||
* This mode allow input group is NULL
|
||||
@@ -138,20 +145,33 @@ int main()
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
if (commit_buffer[i]) {
|
||||
ret = mpp_buffer_info_get(commit_buffer[i], &commit);
|
||||
if (MPP_OK != ret) {
|
||||
mpp_err("mpp_buffer_test mpp_buffer_info_get failed\n");
|
||||
goto MPP_BUFFER_failed;
|
||||
}
|
||||
|
||||
ret = mpp_buffer_put(commit_buffer[i]);
|
||||
if (MPP_OK != ret) {
|
||||
mpp_err("mpp_buffer_test mpp_buffer_put commit mode failed\n");
|
||||
goto MPP_BUFFER_failed;
|
||||
}
|
||||
|
||||
commit_buffer[i] = NULL;
|
||||
|
||||
/* NOTE: buffer info from allocator need to be free directly */
|
||||
ret = api->free(allocator, &commit);
|
||||
if (MPP_OK != ret) {
|
||||
mpp_err("mpp_buffer_test api->free failed\n");
|
||||
goto MPP_BUFFER_failed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
if (commit_ptr[i]) {
|
||||
free(commit_ptr[i]);
|
||||
commit_ptr[i] = NULL;
|
||||
}
|
||||
ret = mpp_allocator_put(&allocator);
|
||||
if (MPP_OK != ret) {
|
||||
mpp_err("mpp_buffer_test mpp_allocator_put failed\n");
|
||||
goto MPP_BUFFER_failed;
|
||||
}
|
||||
|
||||
mpp_log("mpp_buffer_test commit mode with used status success\n");
|
||||
@@ -238,6 +258,11 @@ MPP_BUFFER_failed:
|
||||
legacy_buffer = NULL;
|
||||
}
|
||||
|
||||
if (allocator) {
|
||||
mpp_allocator_put(&allocator);
|
||||
}
|
||||
mpp_assert(NULL == allocator);
|
||||
|
||||
mpp_log("mpp_buffer_test failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user