mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-05 17:16:50 +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 {
|
typedef struct {
|
||||||
size_t alignment;
|
size_t alignment;
|
||||||
|
RK_S32 fd_count;
|
||||||
} allocator_ctx;
|
} allocator_ctx;
|
||||||
|
|
||||||
MPP_RET os_allocator_normal_open(void **ctx, size_t alignment)
|
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
|
} else
|
||||||
p->alignment = alignment;
|
p->alignment = alignment;
|
||||||
|
|
||||||
|
p->fd_count = 0;
|
||||||
|
|
||||||
*ctx = p;
|
*ctx = p;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -63,6 +66,7 @@ MPP_RET os_allocator_normal_alloc(void *ctx, MppBufferInfo *info)
|
|||||||
}
|
}
|
||||||
|
|
||||||
p = (allocator_ctx *)ctx;
|
p = (allocator_ctx *)ctx;
|
||||||
|
info->fd = p->fd_count++;
|
||||||
return os_malloc(&info->ptr, p->alignment, info->size);
|
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)
|
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->ptr);
|
||||||
mpp_assert(info->size);
|
mpp_assert(info->size);
|
||||||
info->hnd = NULL;
|
info->hnd = NULL;
|
||||||
info->fd = -1;
|
info->fd = p->fd_count++;
|
||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,8 +124,8 @@ static os_allocator allocator_v4l2 = {
|
|||||||
os_allocator_normal_open,
|
os_allocator_normal_open,
|
||||||
os_allocator_normal_alloc,
|
os_allocator_normal_alloc,
|
||||||
os_allocator_normal_free,
|
os_allocator_normal_free,
|
||||||
NULL,
|
os_allocator_normal_import,
|
||||||
NULL,
|
os_allocator_normal_release,
|
||||||
os_allocator_normal_close,
|
os_allocator_normal_close,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
#include "mpp_log.h"
|
#include "mpp_log.h"
|
||||||
#include "mpp_env.h"
|
#include "mpp_env.h"
|
||||||
#include "mpp_buffer.h"
|
#include "mpp_buffer.h"
|
||||||
|
#include "mpp_allocator.h"
|
||||||
|
|
||||||
#define MPP_BUFFER_TEST_DEBUG_FLAG (0xf)
|
#define MPP_BUFFER_TEST_DEBUG_FLAG (0xf)
|
||||||
#define MPP_BUFFER_TEST_SIZE (SZ_1K*4)
|
#define MPP_BUFFER_TEST_SIZE (SZ_1K*4)
|
||||||
@@ -33,6 +34,8 @@
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
MPP_RET ret = MPP_OK;
|
MPP_RET ret = MPP_OK;
|
||||||
|
MppAllocator allocator = NULL;
|
||||||
|
MppAllocatorApi *api = NULL;
|
||||||
MppBufferInfo commit;
|
MppBufferInfo commit;
|
||||||
MppBufferGroup group = NULL;
|
MppBufferGroup group = NULL;
|
||||||
MppBuffer commit_buffer[MPP_BUFFER_TEST_COMMIT_COUNT];
|
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");
|
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.type = MPP_BUFFER_TYPE_ION;
|
||||||
commit.size = size;
|
commit.size = size;
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
commit_ptr[i] = malloc(size);
|
ret = api->alloc(allocator, &commit);
|
||||||
if (NULL == commit_ptr[i]) {
|
if (ret) {
|
||||||
mpp_err("mpp_buffer_test malloc failed\n");
|
mpp_err("mpp_buffer_test mpp_allocator_alloc failed\n");
|
||||||
goto MPP_BUFFER_failed;
|
goto MPP_BUFFER_failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
commit.ptr = commit_ptr[i];
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NOTE: commit buffer info will be directly return within new MppBuffer
|
* NOTE: commit buffer info will be directly return within new MppBuffer
|
||||||
* This mode allow input group is NULL
|
* This mode allow input group is NULL
|
||||||
@@ -138,20 +145,33 @@ int main()
|
|||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
if (commit_buffer[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]);
|
ret = mpp_buffer_put(commit_buffer[i]);
|
||||||
if (MPP_OK != ret) {
|
if (MPP_OK != ret) {
|
||||||
mpp_err("mpp_buffer_test mpp_buffer_put commit mode failed\n");
|
mpp_err("mpp_buffer_test mpp_buffer_put commit mode failed\n");
|
||||||
goto MPP_BUFFER_failed;
|
goto MPP_BUFFER_failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
commit_buffer[i] = NULL;
|
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++) {
|
ret = mpp_allocator_put(&allocator);
|
||||||
if (commit_ptr[i]) {
|
if (MPP_OK != ret) {
|
||||||
free(commit_ptr[i]);
|
mpp_err("mpp_buffer_test mpp_allocator_put failed\n");
|
||||||
commit_ptr[i] = NULL;
|
goto MPP_BUFFER_failed;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mpp_log("mpp_buffer_test commit mode with used status success\n");
|
mpp_log("mpp_buffer_test commit mode with used status success\n");
|
||||||
@@ -238,6 +258,11 @@ MPP_BUFFER_failed:
|
|||||||
legacy_buffer = NULL;
|
legacy_buffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (allocator) {
|
||||||
|
mpp_allocator_put(&allocator);
|
||||||
|
}
|
||||||
|
mpp_assert(NULL == allocator);
|
||||||
|
|
||||||
mpp_log("mpp_buffer_test failed\n");
|
mpp_log("mpp_buffer_test failed\n");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user