mdf.c:
#define USE_DTCM_SPEEX_ALLOC
#ifdef USE_DTCM_SPEEX_ALLOC
// DTCM SPEEX ALLOCATE 80kb
#define SPEEX_DTCM_POOL_SIZE (80 * 1024)
__attribute__((section(".dtcm_bss"))) static uint8_t speex_dtcm_pool[SPEEX_DTCM_POOL_SIZE];
static size_t dtcm_ptr = 0;
static void *custom_speex_alloc_smart(size_t size)
{
// Align 4 byte's (Cortex-M7)
size = (size + 3) & ~3;
if (dtcm_ptr + size <= SPEEX_DTCM_POOL_SIZE) {
void *ptr = &speex_dtcm_pool[dtcm_ptr];
dtcm_ptr += size;
printf("\n================== SPEEX AEC MEMORY REPORT ==================\n");
printf("DTCM Pool allocated: %5d / %5d bytes (%d%% used)\n", dtcm_ptr, SPEEX_DTCM_POOL_SIZE, (dtcm_ptr * 100) / SPEEX_DTCM_POOL_SIZE);
return ptr;
}
printf("AEC Warning: DTCM ! Falling back to system heap for %d bytes\n", size);
extern void *k_malloc(size_t size);
return malloc(size);
}
#undef speex_alloc
#define speex_alloc(size) custom_speex_alloc_smart(size)
static void custom_speex_free_smart(void *ptr)
{
if (ptr == NULL) {
return;
}
if ((uint8_t *)ptr >= speex_dtcm_pool && (uint8_t *)ptr < (speex_dtcm_pool + SPEEX_DTCM_POOL_SIZE))
{
return;
}
free(ptr);
}
#undef speex_free
#define speex_free(ptr) custom_speex_free_smart(ptr)
#endif
По примеру speex надо всё алоцирование памяти для webrtc перенести в DTCM