static GstMemory *
gst_dwl_allocator_alloc (GstAllocator * allocator, gsize size,
    GstAllocationParams * params)
{
  GstDwlAllocator *dwl;
  GstDwlMemory *dwlmem;
  GstG1Memory *g1mem;
  GstMemory *mem;
  gsize maxsize;
  gint ret;

  dwl = GST_DWL_ALLOCATOR (allocator);
  dwlmem = g_slice_new (GstDwlMemory);
  mem = GST_MEMORY_CAST (dwlmem);

  /* Take into account prefix and padding */
  maxsize = size + params->prefix + params->padding;

  GST_LOG ("Allocating new slice %p of %d", mem, maxsize);

  ret = DWLMallocLinear (dwl->dwl, maxsize, &dwlmem->linearmem);
  if (DWL_FAILED (ret)) {
    GST_ERROR_OBJECT (dwl, "Unable to allocate buffer of size %d, reason: %d",
        size, ret);
    g_free (dwlmem);
    dwlmem = NULL;
    mem = NULL;
    goto exit;
  }

  /* Initialize GstMemory */
  gst_memory_init (mem, GST_MEMORY_FLAG_PHYSICALLY_CONTIGUOUS, _dwl_allocator,
      NULL, maxsize, 0, params->prefix, size);

  g1mem = (GstG1Memory *) dwlmem;
  g1mem->virtaddress = dwlmem->linearmem.virtualAddress;
  g1mem->physaddress = dwlmem->linearmem.busAddress;

exit:
  {
    return mem;
  }
}
Beispiel #2
0
/*------------------------------------------------------------------------------
    OSAL_AllocatorAllocMem
------------------------------------------------------------------------------*/
OSAL_ERRORTYPE OSAL_AllocatorAllocMem(OSAL_ALLOCATOR* alloc, OSAL_U32* size,
        OSAL_U8** bus_data, OSAL_BUS_WIDTH* bus_address)
{
#ifdef OMX_MEM_TRC

    if(pf)
        fprintf(pf, "%d bytes; %d chunks;\n", *size, *size/4096);

#endif
#ifdef ANDROID

    DWLLinearMem_t info;
 //   memset(&info, 0, sizeof(DWLLinearMem_t));
    TRACE("OSAL_AllocatorAllocMem size=%d\n",*size);

    if(alloc->pdwl == 0)
    {
        OSAL_ALLOCATOR a;
        OSAL_AllocatorInit(&a);
    }

    int ret = DWLMallocLinear(alloc->pdwl, *size, &info);
    if (ret == 0)
    {
        *bus_data = (OSAL_U8*)info.virtualAddress;
        *bus_address = (OSAL_BUS_WIDTH)info.busAddress;
        TRACE("OSAL_AllocatorAllocMem OK\n    bus addr = 0x%08x\n    vir addr = 0x%08x\n",info.busAddress, info.virtualAddress);
        memset(info.virtualAddress, 0xab, *size);
        return OSAL_ERRORNONE;
    }
    else
    {
        LOGE("MallocLinear error %d\n",ret);
        return OSAL_ERROR_UNDEFINED;
    }
#endif
#ifdef MEMALLOCHW
    assert(alloc->fd_memalloc > 0);
    assert(alloc->fd_mem > 0);
    int pgsize = getpagesize();

    MemallocParams params;
    memset(&params, 0, sizeof(MemallocParams));

    *size = (*size + pgsize) & (~(pgsize - 1));
    params.size = *size;
    *bus_data   = MAP_FAILED;
    // get linear memory buffer
    ioctl(alloc->fd_memalloc, MEMALLOC_IOCXGETBUFFER, &params);
    if (params.busAddress == 0)
    {
        LOGE("OSAL_ERROR_INSUFFICIENT_RESOURCES\n");
        return OSAL_ERROR_INSUFFICIENT_RESOURCES;
    }
    // map the bus address to a virtual address

    TRACE_PRINT("alloc success. bus addr = 0x%x\n",params.busAddress);

    TRACE_PRINT("mmap(0, %d, %x, %x, %d, 0x%x);\n", *size, PROT_READ | PROT_WRITE, MAP_SHARED, alloc->fd_mem, params.busAddress);
    *bus_data = (OSAL_U8*)mmap(0, *size, PROT_READ | PROT_WRITE, MAP_SHARED, alloc->fd_mem, params.busAddress);
    if (*bus_data == MAP_FAILED)
    {
        TRACE_PRINT("mmap failed %s\n",strerror(errno));
        return OSAL_ERROR_UNDEFINED;
    }

    TRACE_PRINT("mmap success. vir addr = 0x%x\n",*bus_data);
    memset(*bus_data, 0, *size);

    TRACE_PRINT("memset OK\n");
    *bus_address = params.busAddress;
    return OSAL_ERRORNONE;
#else
    OSAL_U32 extra = sizeof(OSAL_U32);
    OSAL_U8* data  = (OSAL_U8*)malloc(*size + extra);
    if (data==NULL)
    {
        LOGE("OSAL_ERROR_INSUFFICIENT_RESOURCES\n");
        return OSAL_ERROR_INSUFFICIENT_RESOURCES;
    }

    OSAL_U32 sentinel = MEMORY_SENTINEL;
    // copy sentinel at the end of mem block
    memcpy(&data[*size], &sentinel, sizeof(OSAL_U32));

    *bus_data    = data;
    *bus_address = (OSAL_BUS_WIDTH)data;
    return OSAL_ERRORNONE;
#endif
}