📄 block_mem.c
字号:
/******************************************************************************
** File Name: block_mem.c *
** Author: Richard Yang *
** DATE: 05/09/2005 *
** Copyright: 2005 Spreatrum, Incoporated. All Rights Reserved. *
** Description: This file defines the basic operation interfaces of *
** large block memory including malloc and free *
******************************************************************************
******************************************************************************
** Edit History *
** ------------------------------------------------------------------------- *
** DATE NAME DESCRIPTION *
** 05/09/2005 Richard.Yang Create. *
******************************************************************************/
/**---------------------------------------------------------------------------*
** Dependencies *
**---------------------------------------------------------------------------*/
#include "os_api.h"
#include "block_mem.h"
#include "mmivc.h"
#include "mmiwap.h"
#include "mmidisplay_data.h"
//#include "mmimpeg4.h"
#include "Decode.h"
#include "mmimultim.h"
/**---------------------------------------------------------------------------*
** Compiler Flag *
**---------------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C"
{
#endif
#undef APP_JPG_DECODE_USED_MEMORY
#define APP_JPG_DECODE_USED_MEMORY 1024
/**---------------------------------------------------------------------------*
** Function Propertype *
**---------------------------------------------------------------------------*/
#define MMI_MPEG4_OSD_BUFFER_SIZE 1024
#define BLOCK_POOL_SIZE 1024
#define TOTAL_BLOCK_POOL_SIZE (MMIVC_SHOOT_BUFFER_SIZE + MMIWAP_WAP_MEMORY_SIZE + MMI_MPEG4_OSD_BUFFER_SIZE + APP_JPG_DECODE_USED_MEMORY)
//大内存分配表
//LOCAL BLOCK_MEM_T mem_table[] =
//{
// {0, MMIVC_SHOOT_BUFFER_SIZE, NOT_USE},
// {MMIVC_SHOOT_BUFFER_SIZE, MMIWAP_WAP_MEMORY_SIZE, NOT_USE},
// {MMIVC_SHOOT_BUFFER_SIZE + MMIWAP_WAP_MEMORY_SIZE, MMI_MPEG4_OSD_BUFFER_SIZE, NOT_USE},
// {MMIVC_SHOOT_BUFFER_SIZE + MMIWAP_WAP_MEMORY_SIZE + MMI_MPEG4_OSD_BUFFER_SIZE, APP_JPG_DECODE_USED_MEMORY, NOT_USE},
//};
//大内存分配表(对比以上旧的有如下改动:将 JPG 和 WAP 项调换位置,使 VC 和 JPG 相临 GJM )
LOCAL BLOCK_MEM_T mem_table[] =
{
{0, MMIVC_SHOOT_BUFFER_SIZE, NOT_USE},
{MMIVC_SHOOT_BUFFER_SIZE, APP_JPG_DECODE_USED_MEMORY, NOT_USE},
{MMIVC_SHOOT_BUFFER_SIZE + APP_JPG_DECODE_USED_MEMORY, MMI_MPEG4_OSD_BUFFER_SIZE, NOT_USE},
{MMIVC_SHOOT_BUFFER_SIZE + APP_JPG_DECODE_USED_MEMORY + MMI_MPEG4_OSD_BUFFER_SIZE, MMIWAP_WAP_MEMORY_SIZE, NOT_USE},
};
//可用大内存池
LOCAL uint32 BLOCK_POOL[TOTAL_BLOCK_POOL_SIZE/4];
/**---------------------------------------------------------------------------*
** FUNCTION *
** void BL_Malloc() *
** *
** DESCRIPTION *
** Malloc a block mem from memory pool . *
** *
** INPUT *
** BLOCK_MEM_ID_E id *
** *
** OUTPUT *
** Return the allocated memory pointer *
** *
** RETURN VALUE *
** None *
** *
** DEPENDENCIES *
** *
** *
**---------------------------------------------------------------------------*/
void * BL_Malloc(BLOCK_MEM_ID_E id)
{
//暂时先不做状态控制
// int j = 0;
//
// if(id >= ARR_SIZE(mem_table))
// {
// SCI_TRACE_LOW("BL_Malloc:invalid id = %d",id);
// return NULL;
// }
//
// if(mem_table[id].block_mem_flag == ALLOC_BY_OTHERS)
// {
// SCI_TRACE_LOW("BL_Malloc:in used id = %d",id);
// return NULL;
// }
//
// mem_table[id].block_mem_flag = ALLOC_BY_SELF;
// for(j = 0 ; j < ARR_SIZE(mem_table); j++)
// {
// if((mem_table[id].block_offset < mem_table[j].block_offset + mem_table[j].block_num * BLOCK_POOL_SIZE )
// && (mem_table[j].block_offset < mem_table[id].block_offset + mem_table[id].block_num * BLOCK_POOL_SIZE) )
// {
// //两个block有重合部分
// mem_table[j].block_mem_flag = ALLOC_BY_OTHERS;
// }
// }
// Add by GJM 06-07-21
id = ( BLOCK_MEM_POOL_1 == id || BLOCK_MEM_POOL_3 == id ) ? ( ( BLOCK_MEM_POOL_1 == id ) ? BLOCK_MEM_POOL_3 : BLOCK_MEM_POOL_1 ) : id;
// Add end
return ((unsigned char *)BLOCK_POOL + mem_table[id].block_offset);
}
/**---------------------------------------------------------------------------*
** FUNCTION *
** void BL_Free() *
** *
** DESCRIPTION *
** Free a block mem from memory pool *
** *
** INPUT *
** BLOCK_MEM_ID_E id *
** *
** OUTPUT *
** None *
** *
** RETURN VALUE *
** None *
** *
** DEPENDENCIES *
** *
** *
**---------------------------------------------------------------------------*/
void BL_Free(BLOCK_MEM_ID_E id)
{
//暂时先不做状态控制
// int j = 0;
//
// if(id >= ARR_SIZE(mem_table))
// {
// SCI_TRACE_LOW("BL_Free:invalid id = %d",id);
// return;
// }
//
// if(NOT_USE == mem_table[id].block_mem_flag )
// {
// SCI_TRACE_LOW("BL_Free:unused id = %d",id);
// return;
// }
//
// mem_table[id].block_mem_flag = NOT_USE;
//
// for(j = 0 ; j < ARR_SIZE(mem_table); j++)
// {
// if((mem_table[id].block_offset < mem_table[j].block_offset + mem_table[j].block_num * BLOCK_POOL_SIZE )
// && (mem_table[j].block_offset < mem_table[id].block_offset + mem_table[id].block_num * BLOCK_POOL_SIZE) )
// {
// //两个block有重合部分
// mem_table[j].block_mem_flag = NOT_USE;
// }
// }
}
/**---------------------------------------------------------------------------*
** FUNCTION *
** void BL_GetStatus() *
** *
** DESCRIPTION *
** Return whether the block is used or not *
** *
** INPUT *
** BLOCK_MEM_ID_E id *
** *
** OUTPUT *
** None *
** *
** RETURN VALUE *
** None *
** *
** DEPENDENCIES *
** *
** *
**---------------------------------------------------------------------------*/
BLOCK_MEM_STATUS_E BL_GetStatus(BLOCK_MEM_ID_E id)
{
//暂时先不做状态控制
// if(id >= ARR_SIZE(mem_table))
// {
// SCI_TRACE_LOW("BL_GetStatus:invalid id = %d",id);
// return ERROR_STATUS;
// }
// Add by GJM 06-07-21
id = ( BLOCK_MEM_POOL_1 == id || BLOCK_MEM_POOL_3 == id ) ? ( ( BLOCK_MEM_POOL_1 == id ) ? BLOCK_MEM_POOL_3 : BLOCK_MEM_POOL_1 ) : id;
// Add end
return mem_table[id].block_mem_flag;
}
//add for bug #192 by yinchao 2006.7.20
/**---------------------------------------------------------------------------*
** FUNCTION *
** BOOLEAN GetFixMemPoolAddr() *
** *
** DESCRIPTION *
** 获得固定内存的开始和结束的地址 *
** *
** INPUT *
** void **ppStartAddr, void **ppEndAddr *
** *
** OUTPUT *
** TURE OR FALSE *
** *
** RETURN VALUE *
** TURE OR FALSE *
** *
** DEPENDENCIES *
** *
** *
**---------------------------------------------------------------------------*/
BOOLEAN GetFixMemPoolAddr(void **ppStartAddr, void **ppEndAddr)
{
if (ppStartAddr == NULL || ppEndAddr == NULL)
return FALSE;
*ppStartAddr = BLOCK_POOL;
*ppEndAddr = &BLOCK_POOL[TOTAL_BLOCK_POOL_SIZE/4];
return TRUE;
}//end bug #192 by yinchao 2006.7.20
//GTS公司游戏加入分配内存
void *GameMemMalloc(uint32 *size)
{
*size = MMIWAP_WAP_MEMORY_SIZE;
return BL_Malloc(BLOCK_MEM_POOL_3);
}
void GameMemFree(void *ptr)
{
BL_Free(BLOCK_MEM_POOL_3);
}
/**---------------------------------------------------------------------------*
** Compiler Flag *
**---------------------------------------------------------------------------*/
#ifdef __cplusplus
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -