mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-06 01:26:49 +08:00
[mpp_buffer]: add empty flow test for mpp_buffer
git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@120 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
@@ -31,10 +31,12 @@ typedef void* MppBufferGroup;
|
|||||||
*
|
*
|
||||||
* typical call flow:
|
* typical call flow:
|
||||||
*
|
*
|
||||||
* mpp_buffer_get() return a
|
* mpp_buffer_group_get() return A
|
||||||
* mpp_buffer_inc_ref(a)
|
* mpp_buffer_get(A) return a ref +1 -> used
|
||||||
* mpp_buffer_put(a)
|
* mpp_buffer_inc_ref(a) ref +1
|
||||||
* mpp_buffer_put(a)
|
* mpp_buffer_put(a) ref -1
|
||||||
|
* mpp_buffer_put(a) ref -1 -> unused
|
||||||
|
* mpp_buffer_group_put(A)
|
||||||
*
|
*
|
||||||
* commit mode: all buffer are commited out of mpp
|
* commit mode: all buffer are commited out of mpp
|
||||||
* under this mode, buffer pool is controlled by external api
|
* under this mode, buffer pool is controlled by external api
|
||||||
@@ -42,21 +44,20 @@ typedef void* MppBufferGroup;
|
|||||||
* typical call flow:
|
* typical call flow:
|
||||||
*
|
*
|
||||||
* ==== external allocator ====
|
* ==== external allocator ====
|
||||||
* mpp_buffer_commit(a)
|
* mpp_buffer_group_get() return A
|
||||||
* mpp_buffer_commit(b)
|
* mpp_buffer_commit(A, x)
|
||||||
|
* mpp_buffer_commit(A, y)
|
||||||
*
|
*
|
||||||
* ======= internal user ======
|
* ======= internal user ======
|
||||||
* mpp_buffer_get() return a
|
* mpp_buffer_get(A) return a
|
||||||
* mpp_buffer_get() return b
|
* mpp_buffer_get(A) return b
|
||||||
* mpp_buffer_put(a)
|
* mpp_buffer_put(a)
|
||||||
* mpp_buffer_put(b)
|
* mpp_buffer_put(b)
|
||||||
*
|
*
|
||||||
* ==== external allocator ====
|
* ==== external allocator ====
|
||||||
* mpp_buffer_commit(a)
|
* mpp_buffer_group_put(A)
|
||||||
* mpp_buffer_commit(b)
|
|
||||||
*
|
*
|
||||||
* NOTE: commit/remove interface required group handle to record
|
* NOTE: commit interface required group handle to record group information
|
||||||
* buffer group information
|
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MPP_BUFFER_MODE_NATIVE,
|
MPP_BUFFER_MODE_NATIVE,
|
||||||
@@ -75,12 +76,22 @@ typedef enum {
|
|||||||
MPP_BUFFER_TYPE_BUTT,
|
MPP_BUFFER_TYPE_BUTT,
|
||||||
} MppBufferType;
|
} MppBufferType;
|
||||||
|
|
||||||
#define mpp_buffer_commit(...) _mpp_buffer_commit(MODULE_TAG, ## __VA_ARGS__)
|
typedef struct {
|
||||||
#define mpp_buffer_remove(...) _mpp_buffer_remove(MODULE_TAG, ## __VA_ARGS__)
|
MppBufferType type;
|
||||||
|
size_t size;
|
||||||
|
union {
|
||||||
|
void *ptr;
|
||||||
|
RK_S32 fd;
|
||||||
|
} data;
|
||||||
|
} MppBufferCommit;
|
||||||
|
|
||||||
#define mpp_buffer_get(...) _mpp_buffer_get(MODULE_TAG, ## __VA_ARGS__)
|
#define mpp_buffer_commit(...) _mpp_buffer_commit(MODULE_TAG, ## __VA_ARGS__)
|
||||||
#define mpp_buffer_put(...) _mpp_buffer_put(MODULE_TAG, ## __VA_ARGS__)
|
#define mpp_buffer_get(...) _mpp_buffer_get(MODULE_TAG, ## __VA_ARGS__)
|
||||||
#define mpp_buffer_inc_ref(...) _mpp_buffer_inc_ref(MODULE_TAG, ## __VA_ARGS__)
|
#define mpp_buffer_put(...) _mpp_buffer_put(MODULE_TAG, ## __VA_ARGS__)
|
||||||
|
#define mpp_buffer_inc_ref(...) _mpp_buffer_inc_ref(MODULE_TAG, ## __VA_ARGS__)
|
||||||
|
|
||||||
|
#define mpp_buffer_group_get(...) _mpp_buffer_group_get(MODULE_TAG, ## __VA_ARGS__)
|
||||||
|
#define mpp_buffer_group_put(...) _mpp_buffer_group_put(MODULE_TAG, ## __VA_ARGS__)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -88,14 +99,17 @@ extern "C" {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* MppBuffer interface
|
* MppBuffer interface
|
||||||
|
* these interface will change value of group and buffer so before calling functions
|
||||||
|
* parameter need to be checked.
|
||||||
*/
|
*/
|
||||||
MPP_RET _mpp_buffer_commit(const char *tag, MppBufferGroup *group, MppBuffer *buffer, MppBufferType type, size_t size);
|
MPP_RET _mpp_buffer_commit(const char *tag, MppBufferGroup group, MppBufferCommit *buffer);
|
||||||
MPP_RET _mpp_buffer_remove(const char *tag, MppBufferGroup *group, MppBuffer *buffer);
|
MPP_RET _mpp_buffer_get(const char *tag, MppBufferGroup group, MppBuffer *buffer, size_t size);
|
||||||
|
|
||||||
MPP_RET _mpp_buffer_get(const char *tag, MppBuffer *buffer, size_t size);
|
|
||||||
MPP_RET _mpp_buffer_put(const char *tag, MppBuffer *buffer);
|
MPP_RET _mpp_buffer_put(const char *tag, MppBuffer *buffer);
|
||||||
MPP_RET _mpp_buffer_inc_ref(const char *tag, MppBuffer buffer);
|
MPP_RET _mpp_buffer_inc_ref(const char *tag, MppBuffer buffer);
|
||||||
|
|
||||||
|
MPP_RET _mpp_buffer_group_get(const char *tag, MppBufferGroup *group, MppBufferType type);
|
||||||
|
MPP_RET _mpp_buffer_group_put(const char *tag, MppBufferGroup *group);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -21,6 +21,7 @@ add_subdirectory(hal)
|
|||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
add_library(mpp STATIC
|
add_library(mpp STATIC
|
||||||
mpp_info.cpp
|
mpp_info.cpp
|
||||||
|
mpp_buffer.cpp
|
||||||
mpp_packet.cpp
|
mpp_packet.cpp
|
||||||
mpi_impl.cpp
|
mpi_impl.cpp
|
||||||
mpi.cpp
|
mpi.cpp
|
||||||
|
56
mpp/mpp_buffer.cpp
Normal file
56
mpp/mpp_buffer.cpp
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010 Rockchip Electronics S.LSI Co. LTD
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define MODULE_TAG "mpp_buffer"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "mpp_log.h"
|
||||||
|
#include "mpp_mem.h"
|
||||||
|
#include "mpp_list.h"
|
||||||
|
#include "mpp_buffer.h"
|
||||||
|
|
||||||
|
MPP_RET _mpp_buffer_commit(const char *tag, MppBufferGroup group, MppBufferCommit *buffer)
|
||||||
|
{
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET _mpp_buffer_get(const char *tag, MppBufferGroup group, MppBuffer *buffer, size_t size)
|
||||||
|
{
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET _mpp_buffer_put(const char *tag, MppBuffer *buffer)
|
||||||
|
{
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET _mpp_buffer_inc_ref(const char *tag, MppBuffer buffer)
|
||||||
|
{
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MPP_RET _mpp_buffer_group_get(const char *tag, MppBufferGroup *group, MppBufferType type)
|
||||||
|
{
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET _mpp_buffer_group_put(const char *tag, MppBufferGroup *group)
|
||||||
|
{
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
@@ -21,6 +21,9 @@ endmacro()
|
|||||||
# legacy vpu_api unit test
|
# legacy vpu_api unit test
|
||||||
add_mpp_test(vpu_api)
|
add_mpp_test(vpu_api)
|
||||||
|
|
||||||
|
# mpp_buffer unit test
|
||||||
|
add_mpp_test(mpp_buffer)
|
||||||
|
|
||||||
# mpp_packet unit test
|
# mpp_packet unit test
|
||||||
add_mpp_test(mpp_packet)
|
add_mpp_test(mpp_packet)
|
||||||
|
|
||||||
|
114
test/mpp_buffer_test.c
Normal file
114
test/mpp_buffer_test.c
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010 Rockchip Electronics S.LSI Co. LTD
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define MODULE_TAG "mpp_buffer_test"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "mpp_log.h"
|
||||||
|
#include "mpp_buffer.h"
|
||||||
|
|
||||||
|
#define MPP_BUFFER_TEST_SIZE 1024
|
||||||
|
#define MPP_BUFFER_TEST_COUNT 10
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
MPP_RET ret = MPP_OK;
|
||||||
|
MppBufferCommit commit;
|
||||||
|
MppBufferGroup group = NULL;
|
||||||
|
MppBuffer buffer[MPP_BUFFER_TEST_COUNT];
|
||||||
|
void *ptr[MPP_BUFFER_TEST_COUNT];
|
||||||
|
size_t size = MPP_BUFFER_TEST_SIZE;
|
||||||
|
RK_S32 i;
|
||||||
|
|
||||||
|
mpp_log("mpp_buffer_test start\n");
|
||||||
|
|
||||||
|
memset(ptr, 0, sizeof(ptr));
|
||||||
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
|
||||||
|
ret = mpp_buffer_group_get(&group, MPP_BUFFER_TYPE_NORMAL);
|
||||||
|
if (MPP_OK != ret) {
|
||||||
|
mpp_err("mpp_buffer_test mpp_buffer_group_get failed\n");
|
||||||
|
goto MPP_BUFFER_failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
commit.type = MPP_BUFFER_TYPE_NORMAL;
|
||||||
|
commit.size = size;
|
||||||
|
|
||||||
|
for (i = 0; i < MPP_BUFFER_TEST_COUNT; i++) {
|
||||||
|
ptr[i] = malloc(size);
|
||||||
|
if (NULL == ptr[i]) {
|
||||||
|
mpp_err("mpp_buffer_test malloc failed\n");
|
||||||
|
goto MPP_BUFFER_failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
commit.data.ptr = ptr[i];
|
||||||
|
|
||||||
|
ret = mpp_buffer_commit(group, &commit);
|
||||||
|
if (MPP_OK != ret) {
|
||||||
|
mpp_err("mpp_buffer_test mpp_buffer_commit failed\n");
|
||||||
|
goto MPP_BUFFER_failed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < MPP_BUFFER_TEST_COUNT; i++) {
|
||||||
|
ret = mpp_buffer_get(group, &buffer[i], size);
|
||||||
|
if (MPP_OK != ret) {
|
||||||
|
mpp_err("mpp_buffer_test mpp_buffer_get failed\n");
|
||||||
|
goto MPP_BUFFER_failed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < MPP_BUFFER_TEST_COUNT; i++) {
|
||||||
|
ret = mpp_buffer_put(&buffer[i]);
|
||||||
|
if (MPP_OK != ret) {
|
||||||
|
mpp_err("mpp_buffer_test mpp_buffer_put failed\n");
|
||||||
|
goto MPP_BUFFER_failed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < MPP_BUFFER_TEST_COUNT; i++) {
|
||||||
|
if (ptr[i]) {
|
||||||
|
free(ptr[i]);
|
||||||
|
ptr[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (group)
|
||||||
|
mpp_buffer_group_put(group);
|
||||||
|
|
||||||
|
mpp_log("mpp_buffer_test success\n");
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
MPP_BUFFER_failed:
|
||||||
|
for (i = 0; i < MPP_BUFFER_TEST_COUNT; i++) {
|
||||||
|
mpp_buffer_put(&buffer[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < MPP_BUFFER_TEST_COUNT; i++) {
|
||||||
|
if (ptr[i]) {
|
||||||
|
free(ptr[i]);
|
||||||
|
ptr[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (group)
|
||||||
|
mpp_buffer_group_put(group);
|
||||||
|
|
||||||
|
mpp_log("mpp_buffer_test failed\n");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user