MHEG  17.9.0
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Pages
glue_memory.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  * Copyright © 2011 Ocean Blue Software Ltd
4  *
5  * This file is part of a DTVKit Software Component
6  * You are permitted to copy, modify or distribute this file subject to the terms
7  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
8  *
9  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
10  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
11  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * If you or your organisation is not a member of DTVKit then you have access
14  * to this source code outside of the terms of the licence agreement
15  * and you are expected to delete this and any associated files immediately.
16  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
17  *******************************************************************************/
25 #ifndef _GLUE_MEMORY_H
26 #define _GLUE_MEMORY_H
27 
28 /*---includes for this file--------------------------------------------------*/
29 
30 #include "stb_memory.h"
31 #include "dtvstring.h"
32 
33 #include <string.h> /* for memcpy() */
34 
35 /*---Constant and macro definitions for public use---------------------------*/
36 
37 /* Strip the callingFunction function pointer in retail builds */
38 #ifdef MHG_TRACK_MEM
39 
40  #define SRCMEM_SYSTEM 1
41  #define SRCMEM_DSMCC 2
42  #define SRCMEM_SIQURY 3
43  #define SRCMEM_SSF 4
44  #define SRCMEM_FT2 5
45  #define SRCMEM_APP 6
46  #define SRCMEM_OSD 7
47  #define SRCMEM_SURF 8
48  #define SRCMEM_HBB 9
49  #define MAX_MEM_SRCS 10
50 
51  #ifndef F_IDENT
52  #define F_IDENT __FUNCTION__
53  #endif
54 
55 /* MHEG engine initial overhead */
56  #define SYS_Alloc(sz) MHEG5getMemFunc((void *)F_IDENT, sz, __LINE__, SRCMEM_SYSTEM )
57  #define SYS_Free MHEG5freeMemFunc
58 
59 /* DSM-CC */
60  #define DSMAlloc(sz) MHEG5getMemFunc((void *)F_IDENT, sz, __LINE__, SRCMEM_DSMCC )
61  #define DSMFree MHEG5freeMemFunc
62 
63 /* Freetype */
64  #define FT2_MemAlloc(sz) MHEG5getMemFunc((void *)F_IDENT, sz, __LINE__, SRCMEM_FT2 )
65  #define FT2_MemFree MHEG5freeMemFunc
66 
67 /* Mheg application */
68  #define MHEG5getMem(size) MHEG5getMemFunc((void *)F_IDENT, size, __LINE__, SRCMEM_APP )
69  #define MHEG5freeMem MHEG5freeMemFunc
70 
71 /* Mheg Graphics */
72  #define OSD_MemAlloc(sz) MHEG5getMemFunc((void *)F_IDENT, sz, __LINE__, SRCMEM_OSD )
73  #define OSD_MemFree MHEG5freeMemFunc
74 
75  #define STR_DataAlloc(l) STR_DataAllocFunc(l, __LINE__)
76 
77  #define MH5GlueStringAlloc(l) MH5GlueStringAllocFunc(l, __LINE__)
78  #define MH5GlueStringCreate(l,d) MH5GlueStringCreateFunc(l, d, __LINE__)
79  #define MH5GlueStringCopy(s) MH5GlueStringCopyFunc(s, __LINE__)
80  #define MH5GlueStringConcat(s1, s2) MH5GlueStringConcatFunc(s1, s2, __LINE__)
81 
82 #else
83 
84  #define SYS_Alloc STB_MemAlloc
85  #define SYS_Free STB_MemFree
86 
87  #define DSMAlloc STB_MemAlloc
88  #define DSMFree STB_MemFree
89 
90  #define FT2_MemAlloc STB_MemAlloc
91  #define FT2_MemFree STB_MemFree
92 
93  #define MHEG5getMem STB_MemAlloc
94  #define MHEG5freeMem STB_MemFree
95 
96  #define OSD_MemAlloc STB_MemAlloc
97  #define OSD_MemFree STB_MemFree
98 
99 #endif /* MHG_TRACK_MEM */
100 
101 /*---Enumerations for public use---------------------------------------------*/
102 
103 /*---Global type defs for public use-----------------------------------------*/
104 
105 /*---Global variable declarations for public use-----------------------------*/
106 
107 /*---Global Function prototypes for public use-------------------------------*/
108 
109 BOOLEAN MH5GlueMemoryInitialise(void);
110 void MH5GlueMemoryTerminate(void);
111 
112 /*
113  system dependend memory handling
114  */
115 
121 void MHEG5freeMemFunc(void *what);
122 
123 
124 #ifdef MHG_TRACK_MEM
125 
126 /*******************************************************************************
127  *@begin
128  * NAME: MHEG5getMemFunc
129  * Allocate a block of memory from the free pool.
130  *
131  * Returns : Pointer to allocated memory, or NULL if allocation fails.
132  *
133  * Parameter Flow Description
134  * ------------------------------------------------------------------------------
135  * callingFunction IN Pointer to the calling function (only when MHEG5LOG
136  * is defined.
137  * size IN Size in bytes of the memory region to allocate.
138  *
139  * Additional information:
140  *
141  * This function should be called using the macro MHEG5getMem. This ensures
142  * that the callingFunction parameter is only passed in when MHEG5LOG is
143  * defined.
144  *
145  *@end
146  *******************************************************************************/
147 void* MHEG5getMemFunc(void *callingFunction, int size, int line, int src);
148 
149 void mh5emt_print(unsigned int which);
150 
151 /*******************************************************************************
152  *@begin
153  * NAME: STR_DataAlloc(Func)
154  * Allocate a block of memory from the free pool for strings
155  *
156  * Returns : Pointer to allocated memory, or NULL if allocation fails.
157  *
158  * Parameter Flow Description
159  * --------------------------------------------------------------------------
160  * size IN Size in bytes of the memory region to allocate.
161  * line IN Line number in source (with 'Func')
162  *
163  * Additional information:
164  *
165  * This function should be called using the macro MHEG5getMem. This ensures
166  * that the callingFunction parameter is only passed in when MHEG5LOG is
167  * defined.
168  *
169  *@end
170  *******************************************************************************/
171 unsigned char* STR_DataAllocFunc( unsigned int size, int line );
172 
173 S_STRING MH5GlueStringAllocFunc( U32BIT size, int line );
174 S_STRING MH5GlueStringCreateFunc( U32BIT size, U8BIT *data, int line );
175 S_STRING MH5GlueStringCopyFunc( S_STRING source, int line );
176 S_STRING MH5GlueStringConcatFunc(S_STRING src1, S_STRING src2, int line);
177 
178 #else /* MHG_TRACK_MEM */
179 
180 unsigned char* STR_DataAlloc( unsigned int size );
181 
182 S_STRING MH5GlueStringAlloc( U32BIT size );
183 S_STRING MH5GlueStringCreate( U32BIT size, U8BIT *data );
184 S_STRING MH5GlueStringCopy( S_STRING source );
185 S_STRING MH5GlueStringConcat(S_STRING src1, S_STRING src2);
186 
187 
188 #endif /* MHG_TRACK_MEM */
189 
190 void STR_Shutdown(void);
191 void STR_TidyUp(void);
192 void STR_DataFree( unsigned char *data, unsigned int size );
193 void MH5GlueStringFree( S_STRING *pStr );
194 
195 #endif /*_GLUE_MEMORY_H*/
void MHEG5freeMemFunc(void *what)
Free some memory allocated by a call to MHEG5getMemFunc.
Definition: glue_memory.c:190
Define MHEG5 String type.
System Memory allocation interface.
Definition: dtvstring.h:28
void * MHEG5getMemFunc(int size)
Allocate a block of memory from the free pool. This function should be called using the macro MHEG5ge...
Definition: glue_memory.c:291