/*resize buffers (blocking)*/ void gf_cm_resize(GF_CompositionMemory *cb, u32 newCapacity) { GF_CMUnit *cu; if (!newCapacity) return; /*lock buffer*/ gf_odm_lock(cb->odm, 1); cu = cb->input; cb->UnitSize = newCapacity; if (!cb->no_allocation) { my_large_gf_free(cu->data); cu->data = (char*) my_large_alloc(newCapacity); } else { cu->data = NULL; if (cu->dataLength && cb->odm->raw_frame_sema) { cu->dataLength = 0; gf_sema_notify(cb->odm->raw_frame_sema, 1); } } cu = cu->next; while (cu != cb->input) { if (!cb->no_allocation) { my_large_gf_free(cu->data); cu->data = (char*) my_large_alloc(newCapacity); } else { cu->data = NULL; } cu = cu->next; } gf_odm_lock(cb->odm, 0); }
GF_CompositionMemory *gf_cm_new(u32 UnitSize, u32 capacity, Bool no_allocation) { GF_CompositionMemory *tmp; GF_CMUnit *cu, *prev; u32 i; if (!capacity) return NULL; GF_SAFEALLOC(tmp, GF_CompositionMemory) if (!tmp) { GF_LOG(GF_LOG_ERROR, GF_LOG_MEDIA, ("[Terminal] Failed to allocate composition memory\n")); return NULL; } tmp->Capacity = capacity; tmp->UnitSize = UnitSize; tmp->no_allocation = no_allocation; prev = NULL; i = 1; while (capacity) { cu = gf_cm_unit_new(); if (!prev) { tmp->input = cu; } else { prev->next = cu; cu->prev = prev; } cu->dataLength = 0; if (no_allocation) { cu->data = NULL; } else { cu->data = UnitSize ? (char*)my_large_alloc(sizeof(char)*UnitSize) : NULL; if (cu->data) memset(cu->data, 0, sizeof(char)*UnitSize); } prev = cu; capacity --; i++; } cu->next = tmp->input; tmp->input->prev = cu; /*close the loop. The output is the input as the first item that will be ready for composition will be filled in the input*/ tmp->output = tmp->input; tmp->Status = CB_STOP; return tmp; }
/*resize buffers (blocking)*/ void gf_cm_reinit(GF_CompositionMemory *cb, u32 UnitSize, u32 Capacity) { GF_CMUnit *cu, *prev; u32 i; if (!Capacity || !UnitSize) return; gf_odm_lock(cb->odm, 1); if (cb->input){ /*break the loop and destroy*/ cb->input->prev->next = NULL; gf_cm_unit_del(cb->input, cb->no_allocation); cb->input = NULL; } cu = NULL; cb->Capacity = Capacity; cb->UnitSize = UnitSize; prev = NULL; i = 1; while (Capacity) { cu = gf_cm_unit_new(); if (!prev) { cb->input = cu; } else { prev->next = cu; cu->prev = prev; } cu->dataLength = 0; if (cb->no_allocation) { cu->data = NULL; } else { cu->data = (char*)my_large_alloc(UnitSize); } prev = cu; Capacity --; i++; } cu->next = cb->input; cb->input->prev = cu; cb->output = cb->input; gf_odm_lock(cb->odm, 0); }