static int store_data (oggdmux_prc_t * ap_prc, const OMX_U32 a_pid, const OMX_U8 * ap_data, OMX_U32 a_nbytes) { OMX_U8 ** pp_store = NULL; OMX_U32 * p_offset = NULL; OMX_U32 * p_size = NULL; OMX_U32 nbytes_to_copy = 0; OMX_U32 nbytes_avail = 0; assert (ap_prc); assert (a_pid <= ARATELIA_OGG_DEMUXER_VIDEO_PORT_BASE_INDEX); assert (ap_data); pp_store = get_store_ptr (ap_prc, a_pid); p_size = get_store_size_ptr (ap_prc, a_pid); p_offset = get_store_offset_ptr (ap_prc, a_pid); assert (pp_store && *pp_store); assert (p_size); assert (p_offset); nbytes_avail = *p_size - *p_offset; if (a_nbytes > nbytes_avail) { /* need to re-alloc */ OMX_U8 * p_new_store = NULL; p_new_store = tiz_mem_realloc (*pp_store, *p_offset + a_nbytes); if (p_new_store) { *pp_store = p_new_store; *p_size = *p_offset + a_nbytes; nbytes_avail = *p_size - *p_offset; TIZ_TRACE (handleOf (ap_prc), "pid [%d] : Realloc'd data store " "to new size [%d]", a_pid, *p_size); } } nbytes_to_copy = MIN (nbytes_avail, a_nbytes); memcpy (*pp_store + *p_offset, ap_data, nbytes_to_copy); *p_offset += nbytes_to_copy; TIZ_TRACE (handleOf (ap_prc), "pid [%d]: bytes currently stored [%d]", a_pid, *p_offset); return a_nbytes - nbytes_to_copy; }
static int store_data (vorbisd_prc_t *ap_prc, const OMX_U8 *ap_data, OMX_U32 a_nbytes) { OMX_U8 **pp_store = NULL; OMX_U32 *p_offset = NULL; OMX_U32 *p_size = NULL; OMX_U32 nbytes_to_copy = 0; OMX_U32 nbytes_avail = 0; assert (NULL != ap_prc); assert (NULL != ap_data); pp_store = get_store_ptr (ap_prc); p_size = get_store_size_ptr (ap_prc); p_offset = get_store_offset_ptr (ap_prc); assert (NULL != pp_store && NULL != *pp_store); assert (NULL != p_size); assert (NULL != p_offset); nbytes_avail = *p_size - *p_offset; if (a_nbytes > nbytes_avail) { /* need to re-alloc */ OMX_U8 *p_new_store = NULL; p_new_store = tiz_mem_realloc (*pp_store, *p_offset + a_nbytes); if (NULL != p_new_store) { *pp_store = p_new_store; *p_size = *p_offset + a_nbytes; nbytes_avail = *p_size - *p_offset; TIZ_TRACE (handleOf (ap_prc), "Realloc'd data store " "to new size [%d]", *p_size); } } nbytes_to_copy = MIN (nbytes_avail, a_nbytes); memcpy (*pp_store + *p_offset, ap_data, nbytes_to_copy); *p_offset += nbytes_to_copy; TIZ_TRACE (handleOf (ap_prc), "bytes currently stored [%d]", *p_offset); return a_nbytes - nbytes_to_copy; }