mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-07 18:11:02 +08:00
[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:
@@ -87,11 +87,11 @@ typedef struct {
|
||||
|
||||
#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_put(...) _mpp_buffer_put(MODULE_TAG, ## __VA_ARGS__)
|
||||
#define mpp_buffer_inc_ref(...) _mpp_buffer_inc_ref(MODULE_TAG, ## __VA_ARGS__)
|
||||
#define mpp_buffer_put(...) _mpp_buffer_put(## __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_put(...) _mpp_buffer_group_put(MODULE_TAG, ## __VA_ARGS__)
|
||||
#define mpp_buffer_group_put(...) _mpp_buffer_group_put(## __VA_ARGS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -104,11 +104,11 @@ extern "C" {
|
||||
*/
|
||||
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_put(const char *tag, MppBuffer *buffer);
|
||||
MPP_RET _mpp_buffer_inc_ref(const char *tag, MppBuffer buffer);
|
||||
MPP_RET _mpp_buffer_put(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_put(const char *tag, MppBufferGroup *group);
|
||||
MPP_RET _mpp_buffer_group_put(MppBufferGroup *group);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@@ -21,10 +21,11 @@ add_subdirectory(hal)
|
||||
# ----------------------------------------------------------------------------
|
||||
add_library(mpp STATIC
|
||||
mpp_info.cpp
|
||||
mpp_buffer.cpp
|
||||
mpp_packet.cpp
|
||||
mpi_impl.cpp
|
||||
mpi.cpp
|
||||
mpp_buffer_impl.cpp
|
||||
mpp_buffer.cpp
|
||||
mpp_packet.cpp
|
||||
mpi_impl.cpp
|
||||
mpi.cpp
|
||||
)
|
||||
|
||||
add_subdirectory(legacy)
|
||||
|
@@ -20,8 +20,7 @@
|
||||
|
||||
#include "mpp_log.h"
|
||||
#include "mpp_mem.h"
|
||||
#include "mpp_list.h"
|
||||
#include "mpp_buffer.h"
|
||||
#include "mpp_buffer_impl.h"
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
MPP_RET _mpp_buffer_put(const char *tag, MppBuffer *buffer)
|
||||
MPP_RET _mpp_buffer_put(MppBuffer *buffer)
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
MppBufferGroupImpl *p;
|
||||
return mpp_buffer_group_create(&p, tag, type);
|
||||
}
|
||||
|
||||
MPP_RET _mpp_buffer_group_put(const char *tag, MppBufferGroup *group)
|
||||
MPP_RET _mpp_buffer_group_put(MppBufferGroup *group)
|
||||
{
|
||||
return MPP_OK;
|
||||
}
|
||||
|
130
mpp/mpp_buffer_impl.cpp
Normal file
130
mpp/mpp_buffer_impl.cpp
Normal 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
82
mpp/mpp_buffer_impl.h
Normal 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__*/
|
@@ -12,8 +12,8 @@ endif()
|
||||
include_directories(.)
|
||||
|
||||
add_library(osal STATIC
|
||||
mpp_common.cpp
|
||||
mpp_time.cpp
|
||||
mpp_common.cpp
|
||||
mpp_time.cpp
|
||||
mpp_list.cpp
|
||||
mpp_mem.cpp
|
||||
mpp_env.cpp
|
||||
|
@@ -19,6 +19,8 @@
|
||||
|
||||
#include "rk_type.h"
|
||||
|
||||
#define MPP_TAG_SIZE 32
|
||||
|
||||
#define MPP_MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#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)))
|
||||
@@ -34,12 +36,13 @@
|
||||
|
||||
|
||||
#if defined(_WIN32) && !defined(__MINGW32CE__)
|
||||
#define fseeko _fseeki64
|
||||
#include <stdio.h>
|
||||
#define snprintf _snprintf
|
||||
#define fseeko _fseeki64
|
||||
#elif defined(__MINGW32CE__)
|
||||
#define fseeko fseeko64
|
||||
#define fseeko fseeko64
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@@ -49,10 +49,5 @@ void mpp_osal_free(void *ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
// buffer manipulation function
|
||||
#if defined(_WIN32)
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#endif /*__MPP_MEM_H__*/
|
||||
|
||||
|
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "mpp_log.h"
|
||||
#include "mpp_mem.h"
|
||||
#include "mpp_common.h"
|
||||
|
||||
#include "os_log.h"
|
||||
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#include "mpp_env.h"
|
||||
#include "mpp_mem.h"
|
||||
#include "mpp_list.h"
|
||||
#include "mpp_common.h"
|
||||
|
||||
#include "os_mem.h"
|
||||
|
||||
@@ -49,7 +50,7 @@ struct mem_node {
|
||||
size_t size;
|
||||
|
||||
/* memory node extra information */
|
||||
char tag[32];
|
||||
char tag[MPP_TAG_SIZE];
|
||||
};
|
||||
|
||||
static void get_osal_mem_flag()
|
||||
|
Reference in New Issue
Block a user