[mpp_buffer_impl]: add MppBufferGroup module to mpp_buffer_impl

git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@122 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
ChenHengming
2015-08-18 12:57:16 +00:00
parent 4ccc9a2342
commit c0b913d3b9
10 changed files with 246 additions and 27 deletions

View File

@@ -87,11 +87,11 @@ typedef struct {
#define mpp_buffer_commit(...) _mpp_buffer_commit(MODULE_TAG, ## __VA_ARGS__) #define mpp_buffer_commit(...) _mpp_buffer_commit(MODULE_TAG, ## __VA_ARGS__)
#define mpp_buffer_get(...) _mpp_buffer_get(MODULE_TAG, ## __VA_ARGS__) #define mpp_buffer_get(...) _mpp_buffer_get(MODULE_TAG, ## __VA_ARGS__)
#define mpp_buffer_put(...) _mpp_buffer_put(MODULE_TAG, ## __VA_ARGS__) #define mpp_buffer_put(...) _mpp_buffer_put(## __VA_ARGS__)
#define mpp_buffer_inc_ref(...) _mpp_buffer_inc_ref(MODULE_TAG, ## __VA_ARGS__) #define mpp_buffer_inc_ref(...) _mpp_buffer_inc_ref(## __VA_ARGS__)
#define mpp_buffer_group_get(...) _mpp_buffer_group_get(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__) #define mpp_buffer_group_put(...) _mpp_buffer_group_put(## __VA_ARGS__)
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -104,11 +104,11 @@ extern "C" {
*/ */
MPP_RET _mpp_buffer_commit(const char *tag, MppBufferGroup group, MppBufferCommit *buffer); MPP_RET _mpp_buffer_commit(const char *tag, MppBufferGroup group, MppBufferCommit *buffer);
MPP_RET _mpp_buffer_get(const char *tag, MppBufferGroup group, MppBuffer *buffer, size_t size); MPP_RET _mpp_buffer_get(const char *tag, MppBufferGroup group, MppBuffer *buffer, size_t size);
MPP_RET _mpp_buffer_put(const char *tag, MppBuffer *buffer); MPP_RET _mpp_buffer_put(MppBuffer *buffer);
MPP_RET _mpp_buffer_inc_ref(const char *tag, MppBuffer buffer); MPP_RET _mpp_buffer_inc_ref(MppBuffer buffer);
MPP_RET _mpp_buffer_group_get(const char *tag, MppBufferGroup *group, MppBufferType type); MPP_RET _mpp_buffer_group_get(const char *tag, MppBufferGroup *group, MppBufferType type);
MPP_RET _mpp_buffer_group_put(const char *tag, MppBufferGroup *group); MPP_RET _mpp_buffer_group_put(MppBufferGroup *group);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -21,6 +21,7 @@ add_subdirectory(hal)
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
add_library(mpp STATIC add_library(mpp STATIC
mpp_info.cpp mpp_info.cpp
mpp_buffer_impl.cpp
mpp_buffer.cpp mpp_buffer.cpp
mpp_packet.cpp mpp_packet.cpp
mpi_impl.cpp mpi_impl.cpp

View File

@@ -20,8 +20,7 @@
#include "mpp_log.h" #include "mpp_log.h"
#include "mpp_mem.h" #include "mpp_mem.h"
#include "mpp_list.h" #include "mpp_buffer_impl.h"
#include "mpp_buffer.h"
MPP_RET _mpp_buffer_commit(const char *tag, MppBufferGroup group, MppBufferCommit *buffer) MPP_RET _mpp_buffer_commit(const char *tag, MppBufferGroup group, MppBufferCommit *buffer)
{ {
@@ -33,12 +32,12 @@ MPP_RET _mpp_buffer_get(const char *tag, MppBufferGroup group, MppBuffer *buffer
return MPP_OK; return MPP_OK;
} }
MPP_RET _mpp_buffer_put(const char *tag, MppBuffer *buffer) MPP_RET _mpp_buffer_put(MppBuffer *buffer)
{ {
return MPP_OK; return MPP_OK;
} }
MPP_RET _mpp_buffer_inc_ref(const char *tag, MppBuffer buffer) MPP_RET _mpp_buffer_inc_ref(MppBuffer buffer)
{ {
return MPP_OK; return MPP_OK;
} }
@@ -46,10 +45,17 @@ 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_get(const char *tag, MppBufferGroup *group, MppBufferType type)
{ {
return MPP_OK; if (NULL == group || type >= MPP_BUFFER_TYPE_BUTT) {
mpp_err("mpp_buffer_group_get input invalid group %p type %d\n",
group, type);
return MPP_ERR_UNKNOW;
} }
MPP_RET _mpp_buffer_group_put(const char *tag, MppBufferGroup *group) MppBufferGroupImpl *p;
return mpp_buffer_group_create(&p, tag, type);
}
MPP_RET _mpp_buffer_group_put(MppBufferGroup *group)
{ {
return MPP_OK; return MPP_OK;
} }

130
mpp/mpp_buffer_impl.cpp Normal file
View File

@@ -0,0 +1,130 @@
/*
* 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_common.h"
#include "mpp_buffer.h"
#include "mpp_buffer_impl.h"
#define MPP_BUFFER_SERVICE_LOCK() pthread_mutex_lock(&services.lock)
#define MPP_BUFFER_SERVICE_UNLOCK() pthread_mutex_unlock(&services.lock)
typedef struct {
pthread_mutex_t lock;
RK_U32 group_id;
RK_U32 group_count;
struct list_head list_group;
// list for used buffer which do not have group
struct list_head list_orphan;
} MppBufferService;
static MppBufferService services =
{
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP,
0,
0,
LIST_HEAD_INIT(services.list_group),
LIST_HEAD_INIT(services.list_orphan),
};
static RK_U32 add_group_to_service(MppBufferGroupImpl *p)
{
list_add_tail(&p->list_group, &services.list_group);
services.group_count++;
return services.group_id++;
}
static void del_group_from_service(MppBufferGroupImpl *p)
{
list_del_init(&p->list_group);
services.group_count--;
}
static void add_orphan_to_service(MppBufferImpl *p)
{
list_add_tail(&p->list_status, &services.list_orphan);
}
static void del_orphan_from_service(MppBufferImpl *p)
{
list_del_init(&p->list_status);
}
MPP_RET mpp_buffer_group_create(MppBufferGroupImpl **group, const char *tag, MppBufferType type)
{
MppBufferGroupImpl *p = mpp_malloc(MppBufferGroupImpl, 1);
if (NULL == p) {
mpp_err("mpp_buffer_group_get failed to allocate context\n");
*group = NULL;
return MPP_ERR_MALLOC;
}
MPP_BUFFER_SERVICE_LOCK();
INIT_LIST_HEAD(&p->list_group);
INIT_LIST_HEAD(&p->list_used);
INIT_LIST_HEAD(&p->list_unused);
RK_U32 group_id = add_group_to_service(p);
snprintf(p->tag, MPP_TAG_SIZE, "%s_%d", tag, group_id);
p->type = type;
p->group_id = group_id;
MPP_BUFFER_SERVICE_UNLOCK();
*group = p;
return MPP_OK;
}
MPP_RET mpp_buffer_group_destroy(MppBufferGroupImpl *p)
{
if (NULL == p) {
mpp_err("mpp_buffer_group_destroy found NULL pointer\n");
return MPP_ERR_NULL_PTR;
}
MPP_BUFFER_SERVICE_LOCK();
del_group_from_service(p);
// remove unused list
if (!list_empty(&p->list_unused)) {
MppBufferImpl *pos, *n;
list_for_each_entry_safe(pos, n, &p->list_unused, MppBufferImpl, list_status) {
mpp_free(pos);
}
}
if (!list_empty(&p->list_used)) {
MppBufferImpl *pos, *n;
list_for_each_entry_safe(pos, n, &p->list_used, MppBufferImpl, list_status) {
add_orphan_to_service(pos);
}
}
MPP_BUFFER_SERVICE_UNLOCK();
return MPP_OK;
}

82
mpp/mpp_buffer_impl.h Normal file
View File

@@ -0,0 +1,82 @@
/*
* 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.
*/
#ifndef __MPP_BUFFER_IMPL_H__
#define __MPP_BUFFER_IMPL_H__
#include "mpp_list.h"
#include "mpp_common.h"
#include "mpp_buffer.h"
#include "mpp_thread.h"
#define MPP_BUF_DBG_FUNCTION (0x00000001)
#define mpp_buf_dbg(flag, fmt, ...) mpp_dbg(mpp_buffer_debug, flag, fmt, ## __VA_ARGS__)
#define MPP_BUF_FUNCTION_ENTER() mpp_buf_dbg(MPP_BUF_DBG_FUNCTION, "%s enter\n", __FUNCTION__)
#define MPP_BUF_FUNCTION_LEAVE() mpp_buf_dbg(MPP_BUF_DBG_FUNCTION, "%s leave\n", __FUNCTION__)
#define MPP_BUF_FUNCTION_LEAVE_OK() mpp_buf_dbg(MPP_BUF_DBG_FUNCTION, "%s success\n", __FUNCTION__)
#define MPP_BUF_FUNCTION_LEAVE_FAIL() mpp_buf_dbg(MPP_BUF_DBG_FUNCTION, "%s failed\n", __FUNCTION__)
typedef union MppBufferData_t MppBufferData;
typedef struct MppBufferImpl_t MppBufferImpl;
typedef struct MppBufferGroupImpl_t MppBufferGroupImpl;
union MppBufferData_t {
void *ptr;
RK_S32 fd;
};
struct MppBufferImpl_t {
char tag[MPP_TAG_SIZE];
// use index instead of pointer to avoid invalid pointer
RK_U32 group_id;
MppBufferType type;
size_t size;
MppBufferData data;
RK_S32 ref_count;
struct list_head list_status;
};
struct MppBufferGroupImpl_t {
char tag[MPP_TAG_SIZE];
RK_U32 group_id;
MppBufferType type;
// link to the other MppBufferGroupImpl
struct list_head list_group;
// link to list_status in MppBufferImpl
struct list_head list_used;
struct list_head list_unused;
};
#ifdef __cplusplus
extern "C" {
#endif
extern RK_U32 mpp_buffer_debug;
MPP_RET mpp_buffer_group_create(MppBufferGroupImpl **group, const char *tag, MppBufferType type);
MPP_RET mpp_buffer_group_destroy(MppBufferGroupImpl *p);
#ifdef __cplusplus
}
#endif
#endif /*__MPP_BUFFER_IMPL_H__*/

View File

@@ -19,6 +19,8 @@
#include "rk_type.h" #include "rk_type.h"
#define MPP_TAG_SIZE 32
#define MPP_MAX(a, b) ((a) > (b) ? (a) : (b)) #define MPP_MAX(a, b) ((a) > (b) ? (a) : (b))
#define MPP_MAX3(a, b, c) MPP_MAX(MPP_MAX(a,b),c) #define MPP_MAX3(a, b, c) MPP_MAX(MPP_MAX(a,b),c)
#define MPP_MAX4(a, b, c, d) MPP_MAX((a), MPP_MAX3((b), (c), (d))) #define MPP_MAX4(a, b, c, d) MPP_MAX((a), MPP_MAX3((b), (c), (d)))
@@ -34,12 +36,13 @@
#if defined(_WIN32) && !defined(__MINGW32CE__) #if defined(_WIN32) && !defined(__MINGW32CE__)
#include <stdio.h>
#define snprintf _snprintf
#define fseeko _fseeki64 #define fseeko _fseeki64
#elif defined(__MINGW32CE__) #elif defined(__MINGW32CE__)
#define fseeko fseeko64 #define fseeko fseeko64
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View File

@@ -49,10 +49,5 @@ void mpp_osal_free(void *ptr);
} }
#endif #endif
// buffer manipulation function
#if defined(_WIN32)
#define snprintf _snprintf
#endif
#endif /*__MPP_MEM_H__*/ #endif /*__MPP_MEM_H__*/

View File

@@ -22,6 +22,7 @@
#include "mpp_log.h" #include "mpp_log.h"
#include "mpp_mem.h" #include "mpp_mem.h"
#include "mpp_common.h"
#include "os_log.h" #include "os_log.h"

View File

@@ -25,6 +25,7 @@
#include "mpp_env.h" #include "mpp_env.h"
#include "mpp_mem.h" #include "mpp_mem.h"
#include "mpp_list.h" #include "mpp_list.h"
#include "mpp_common.h"
#include "os_mem.h" #include "os_mem.h"
@@ -49,7 +50,7 @@ struct mem_node {
size_t size; size_t size;
/* memory node extra information */ /* memory node extra information */
char tag[32]; char tag[MPP_TAG_SIZE];
}; };
static void get_osal_mem_flag() static void get_osal_mem_flag()