RDK Documentation (Open Sourced RDK Components)
AampMemoryUtils.h
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's license file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2020 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 /**
21  * @file AampMemoryUtils.h
22  * @brief Header file of helper functions for memory management
23  */
24 
25 
26 #ifndef __AAMP_MEMORY_UTILS_H__
27 #define __AAMP_MEMORY_UTILS_H__
28 
29 #include <stddef.h>
30 #ifdef USE_SECMANAGER
31 #include <sys/shm.h>
32 #define SHM_ACCESS_PERMISSION 0666
33 #define SHMGET_RETRY_MAX 10
34 #endif
35 /**
36  * @struct GrowableBuffer
37  * @brief Structure of GrowableBuffer
38  */
40 {
41  char *ptr; /**< Pointer to buffer's memory location */
42  size_t len; /**< Buffer size */
43  size_t avail; /**< Available buffer size */
44 };
45 
46 /**
47  * @fn aamp_Free
48  * @param ptr memory allocated with aamp_Malloc
49  */
50 void aamp_Free(void *ptr);
51 /**
52  * @fn aamp_Free
53  * @param[in] buffer struct GrowableBuffer
54  */
55 void aamp_Free(struct GrowableBuffer *buffer);
56 void *aamp_Realloc( void *ptr, size_t numBytes );
57 void *aamp_Malloc( size_t numBytes );
58 void aamp_TransferMemory( void *ptr );
59 
60 /**
61  * @brief Allocate memory to growable buffer
62  * @param buffer growable buffer
63  * @param len size of memory to be allocated
64  */
65 void aamp_Malloc(struct GrowableBuffer *buffer, size_t len);
66 
67 /**
68  * @fn aamp_AppendBytes
69  * @param buffer Growable buffer object pointer
70  * @param ptr Buffer to append
71  * @param len Buffer size
72  */
73 void aamp_AppendBytes(struct GrowableBuffer *buffer, const void *ptr, size_t len);
74 
75 /**
76  * @fn aamp_MoveBytes
77  * @param buffer Growable buffer object pointer
78  * @param ptr Buffer to Move
79  * @param len Buffer size
80  */
81 void aamp_MoveBytes(struct GrowableBuffer *buffer, const void *ptr, size_t len);
82 
83 /**
84  * @fn aamp_AppendNulTerminator
85  * @param buffer buffer in which nul to be append
86  */
87 void aamp_AppendNulTerminator(struct GrowableBuffer *buffer);
88 
89 #ifdef USE_SECMANAGER
90 /**
91  * @fn aamp_CreateSharedMem
92  * @param shmLen Length of the buffer to be created
93  * @param shmKey shared memory key
94  */
95 void * aamp_CreateSharedMem( size_t shmLen, key_t & shmKey);
96 /**
97  * @fn aamp_CleanUpSharedMem
98  * @param shmPointer Pointer to the created memory
99  * @param shmKey shared memory key
100  * @param shmLen Length of the buffer
101  */
102 void aamp_CleanUpSharedMem(void* shmPointer, key_t shmKey, size_t shmLen);
103 #endif
104 #endif /* __AAMP_MEMORY_UTILS_H__ */
GrowableBuffer::avail
size_t avail
Definition: AampMemoryUtils.h:43
aamp_AppendBytes
void aamp_AppendBytes(struct GrowableBuffer *buffer, const void *ptr, size_t len)
append data to GrowableBuffer ADT
Definition: AampMemoryUtils.cpp:108
GrowableBuffer::len
size_t len
Definition: AampMemoryUtils.h:42
aamp_Malloc
void * aamp_Malloc(size_t numBytes)
wrapper for g_malloc, used for segment allocation
Definition: AampMemoryUtils.cpp:68
GrowableBuffer::ptr
char * ptr
Definition: AampMemoryUtils.h:41
aamp_MoveBytes
void aamp_MoveBytes(struct GrowableBuffer *buffer, const void *ptr, size_t len)
Move data to buffer.
Definition: AampMemoryUtils.cpp:132
aamp_Free
void aamp_Free(void *ptr)
wrapper for g_free, used for segment allocation
Definition: AampMemoryUtils.cpp:56
GrowableBuffer
Structure of GrowableBuffer.
Definition: AampMemoryUtils.h:39
aamp_AppendNulTerminator
void aamp_AppendNulTerminator(struct GrowableBuffer *buffer)
Append nul character to buffer.
Definition: AampMemoryUtils.cpp:156
aamp_TransferMemory
void aamp_TransferMemory(void *ptr)
called when ownership of memory of injected fragments passed to gstreamer
Definition: AampMemoryUtils.cpp:81