MHEG5  15.3.0
source/glue/inc/glue_memory.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
00003  * Copyright © 2011 Ocean Blue Software Ltd
00004  *
00005  * This file is part of a DTVKit Software Component
00006  * You are permitted to copy, modify or distribute this file subject to the terms
00007  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
00008  * 
00009  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
00010  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
00011  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
00012  * 
00013  * If you or your organisation is not a member of DTVKit then you have access
00014  * to this source code outside of the terms of the licence agreement
00015  * and you are expected to delete this and any associated files immediately.
00016  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
00017  *******************************************************************************/
00025 #ifndef _GLUE_MEMORY_H
00026 #define _GLUE_MEMORY_H
00027 
00028 /*---includes for this file--------------------------------------------------*/
00029 
00030 #include "stb_memory.h"
00031 #include "dtvstring.h"
00032 
00033 #include <string.h>     /* for memcpy() */
00034 
00035 /*---Constant and macro definitions for public use---------------------------*/
00036 
00037 /* Strip the callingFunction function pointer in retail builds */
00038 #ifdef MHG_TRACK_MEM
00039 
00040    #define SRCMEM_SYSTEM     1
00041    #define SRCMEM_DSMCC      2
00042    #define SRCMEM_SIQURY     3
00043    #define SRCMEM_SSF        4
00044    #define SRCMEM_FT2        5
00045    #define SRCMEM_APP        6
00046    #define SRCMEM_OSD        7
00047    #define SRCMEM_SURF       8
00048    #define SRCMEM_HBB        9
00049    #define MAX_MEM_SRCS      10
00050 
00051    #ifndef F_IDENT
00052    #define F_IDENT __FUNCTION__
00053    #endif
00054 
00055 /* MHEG engine initial overhead */
00056    #define SYS_Alloc(sz)      MHEG5getMemFunc((void *)F_IDENT, sz, __LINE__, SRCMEM_SYSTEM )
00057    #define SYS_Free           MHEG5freeMemFunc
00058 
00059 /* DSM-CC */
00060    #define DSMAlloc(sz)       MHEG5getMemFunc((void *)F_IDENT, sz, __LINE__, SRCMEM_DSMCC )
00061    #define DSMFree            MHEG5freeMemFunc
00062 
00063 /* Freetype */
00064    #define FT2_MemAlloc(sz)   MHEG5getMemFunc((void *)F_IDENT, sz, __LINE__, SRCMEM_FT2 )
00065    #define FT2_MemFree        MHEG5freeMemFunc
00066 
00067 /* Mheg application */
00068    #define MHEG5getMem(size)  MHEG5getMemFunc((void *)F_IDENT, size, __LINE__, SRCMEM_APP )
00069    #define MHEG5freeMem       MHEG5freeMemFunc
00070 
00071 /* Mheg Graphics */
00072    #define OSD_MemAlloc(sz)   MHEG5getMemFunc((void *)F_IDENT, sz, __LINE__, SRCMEM_OSD )
00073    #define OSD_MemFree        MHEG5freeMemFunc
00074 
00075    #define STR_DataAlloc(l)   STR_DataAllocFunc(l, __LINE__)
00076 
00077    #define MH5GlueStringAlloc(l)    MH5GlueStringAllocFunc(l, __LINE__)
00078    #define MH5GlueStringCreate(l)   MH5GlueStringCreateFunc(l, d, __LINE__)
00079    #define MH5GlueStringCopy(s)     MH5GlueStringCopyFunc(s, __LINE__)
00080    #define MH5GlueStringConcat(s1, s2) MH5GlueStringConcatFunc(s1, s2, __LINE__)
00081 
00082 #else
00083 
00084    #define SYS_Alloc           STB_MemAlloc
00085    #define SYS_Free            STB_MemFree
00086 
00087    #define DSMAlloc           STB_MemAlloc
00088    #define DSMFree            STB_MemFree
00089 
00090    #define FT2_MemAlloc       STB_MemAlloc
00091    #define FT2_MemFree        STB_MemFree
00092 
00093    #define MHEG5getMem        STB_MemAlloc
00094    #define MHEG5freeMem       STB_MemFree
00095 
00096    #define OSD_MemAlloc       STB_MemAlloc
00097    #define OSD_MemFree        STB_MemFree
00098 
00099 #endif /* MHG_TRACK_MEM */
00100 
00101 /*---Enumerations for public use---------------------------------------------*/
00102 
00103 /*---Global type defs for public use-----------------------------------------*/
00104 
00105 /*---Global variable declarations for public use-----------------------------*/
00106 
00107 /*---Global Function prototypes for public use-------------------------------*/
00108 
00109 BOOLEAN MH5GlueMemoryInitialise(void);
00110 void MH5GlueMemoryTerminate(void);
00111 
00112 /*
00113    system dependend memory handling
00114  */
00115 
00121 void MHEG5freeMemFunc(void *what);
00122 
00123 
00124 #ifdef MHG_TRACK_MEM
00125 
00126 /*******************************************************************************
00127  *@begin
00128  * NAME: MHEG5getMemFunc
00129  *       Allocate a block of memory from the free pool.
00130  *
00131  * Returns : Pointer to allocated memory, or NULL if allocation fails.
00132  *
00133  * Parameter         Flow    Description
00134  * ------------------------------------------------------------------------------
00135  * callingFunction   IN      Pointer to the calling function (only when MHEG5LOG
00136  *                           is defined.
00137  * size              IN      Size in bytes of the memory region to allocate.
00138  *
00139  * Additional information:
00140  *
00141  *   This function should be called using the macro MHEG5getMem. This ensures
00142  *   that the callingFunction parameter is only passed in when MHEG5LOG is
00143  *   defined.
00144  *
00145  *@end
00146  *******************************************************************************/
00147 void* MHEG5getMemFunc(void *callingFunction, int size, int line, int src);
00148 
00149 void mh5emt_print(unsigned int which);
00150 
00151 /*******************************************************************************
00152  *@begin
00153  * NAME: STR_DataAlloc(Func)
00154  *       Allocate a block of memory from the free pool for strings
00155  *
00156  * Returns : Pointer to allocated memory, or NULL if allocation fails.
00157  *
00158  * Parameter    Flow    Description
00159  * --------------------------------------------------------------------------
00160  * size          IN     Size in bytes of the memory region to allocate.
00161  * line          IN     Line number in source (with 'Func')
00162  *
00163  * Additional information:
00164  *
00165  *   This function should be called using the macro MHEG5getMem. This ensures
00166  *   that the callingFunction parameter is only passed in when MHEG5LOG is
00167  *   defined.
00168  *
00169  *@end
00170  *******************************************************************************/
00171 unsigned char* STR_DataAllocFunc( unsigned int size, int line );
00172 
00173 S_STRING MH5GlueStringAllocFunc( U32BIT size, int line );
00174 S_STRING MH5GlueStringCreateFunc( U32BIT size, U8BIT *data, int line );
00175 S_STRING MH5GlueStringCopyFunc( S_STRING source, int line );
00176 S_STRING MH5GlueStringConcatFunc(S_STRING src1, S_STRING src2);
00177 
00178 #else   /* MHG_TRACK_MEM */
00179 
00180 unsigned char* STR_DataAlloc( unsigned int size );
00181 
00182 S_STRING MH5GlueStringAlloc( U32BIT size );
00183 S_STRING MH5GlueStringCreate( U32BIT size, U8BIT *data );
00184 S_STRING MH5GlueStringCopy( S_STRING source );
00185 S_STRING MH5GlueStringConcat(S_STRING src1, S_STRING src2);
00186 
00187 
00188 #endif  /* MHG_TRACK_MEM */
00189 
00190 void STR_Shutdown(void);
00191 void STR_TidyUp(void);
00192 void STR_DataFree( unsigned char *data, unsigned int size );
00193 void MH5GlueStringFree( S_STRING *pStr );
00194 
00195 #endif /*_GLUE_MEMORY_H*/
 All Data Structures Files Functions Variables Typedefs Defines