31 static int gNetMemoryCount;
32 static int gNetMemoryHighWatermark;
34 static void NETMEMORY_PLUS(
void )
37 if( gNetMemoryCount>gNetMemoryHighWatermark )
39 gNetMemoryHighWatermark = gNetMemoryCount;
40 AAMPLOG_WARN(
"***gNetMemoryHighWatermark=%d", gNetMemoryHighWatermark );
44 static void NETMEMORY_MINUS(
void )
47 if( gNetMemoryCount==0 )
49 AAMPLOG_WARN(
"***gNetMemoryCount=0" );
70 void *ptr = g_malloc(numBytes);
100 g_free( buffer->ptr );
110 size_t required = buffer->len + len;
111 if (required > buffer->avail)
115 buffer->avail = ((buffer->avail * 2) > required) ? (buffer->avail * 2) : (required * 2);
116 if( buffer->avail && !buffer->ptr )
120 buffer->ptr = (
char *)g_realloc(buffer->ptr, buffer->avail);
124 memcpy(&buffer->ptr[buffer->len], ptr, len);
125 buffer->len = required;
135 if (buffer->ptr && ptr)
137 if(buffer->avail >= len)
139 memmove(&buffer->ptr[0], ptr, len);
144 AAMPLOG_ERR(
"bad arg(len=%zu > available)", len );
149 AAMPLOG_ERR(
"bad arg(NULL)");
158 char zeros[2] = { 0, 0 };
162 #ifdef USE_SECMANAGER
167 void * aamp_CreateSharedMem(
size_t shmLen, key_t & shmKey)
169 void *shmPointer = NULL;
172 for(
int retryCount=0; retryCount<SHMGET_RETRY_MAX; retryCount++ )
178 int shmId = shmget(shmKey, shmLen,
181 SHM_ACCESS_PERMISSION);
184 shmPointer = shmat(shmId, NULL, 0 );
185 if( shmPointer != (
void *)-1 )
187 AAMPLOG_WARN(
"%s:%d Shared memory shmId=%d ptr=%p created for the key, %u\n",
188 __FUNCTION__, __LINE__, shmId, shmPointer, shmKey);
192 AAMPLOG_ERR(
"%s:%d shmat err=%d shmId=%d\n", __FUNCTION__, __LINE__, errno, shmId );
193 aamp_CleanUpSharedMem( shmPointer, shmKey, shmLen);
200 AAMPLOG_ERR(
"%s:%d shmget err=%d", __FUNCTION__, __LINE__, errno);
206 AAMPLOG_ERR(
"%s:%d invalid shmLen=%zu", __FUNCTION__, __LINE__, shmLen);
214 void aamp_CleanUpSharedMem(
void* shmPointer, key_t shmKey,
size_t shmLen)
216 if( NULL != shmPointer && (
void*)-1 != shmPointer)
218 if( -1 == shmdt(shmPointer) )
220 AAMPLOG_ERR(
"%s:%d shmdt failure %d for key %u \n", __FUNCTION__, __LINE__, errno, shmKey);
222 int shmId = shmget(shmKey, shmLen, SHM_ACCESS_PERMISSION);
225 if( -1 == shmctl(shmId, IPC_RMID, NULL) )
227 AAMPLOG_ERR(
"%s:%d shmctl err=%d shmId=%d\n", __FUNCTION__, __LINE__, errno, shmId );
232 AAMPLOG_ERR(
"%s:%d bad shmKey=%u\n", __FUNCTION__, __LINE__, shmKey);
237 AAMPLOG_ERR(
"%s:%d bad shmPointer=%p\n", __FUNCTION__, __LINE__, shmPointer );