Exemple #1
0
/** Allocate a payload buffer */
uint8_t *mmal_port_payload_alloc(MMAL_PORT_T *port, uint32_t payload_size)
{
   uint8_t *mem;

   if (!port || !port->priv)
      return NULL;

   LOG_TRACE("%s(%i:%i) port %p, size %i", port->component->name,
             (int)port->type, (int)port->index, port, (int)payload_size);

   if (!payload_size)
      return NULL;

   /* TODO: keep track of the allocs so we can free them when the component is destroyed */

   if (!port->priv->pf_payload_alloc)
   {
      /* Revert to using the heap */
      mem = vcos_malloc(payload_size, "mmal payload");
      goto end;
   }

   LOCK_PORT(port);
   mem = port->priv->pf_payload_alloc(port, payload_size);
   UNLOCK_PORT(port);

 end:
   /* Acquire the port if the allocation was successful.
    * This will ensure that the component is not destroyed until the payload has been freed. */
   if (mem)
      mmal_port_acquire(port);
   return mem;
}
Exemple #2
0
VCOS_THREAD_T *vcos_dummy_thread_create(void)
{

   VCOS_STATUS_T st;
   VCOS_THREAD_T *thread_hndl = NULL;
   int rc;

   thread_hndl = (VCOS_THREAD_T *)vcos_malloc(sizeof(VCOS_THREAD_T), NULL);
   vcos_assert(thread_hndl != NULL);

   memset(thread_hndl, 0, sizeof(VCOS_THREAD_T));

   thread_hndl->dummy = 1;
   thread_hndl->thread = vcos_llthread_current();

   st = vcos_semaphore_create(&thread_hndl->suspend, NULL, 0);
   if (st != VCOS_SUCCESS)
   {
      vcos_free(thread_hndl);
      return( thread_hndl );
   }

   vcos_once(&current_thread_key_once, current_thread_key_init);

#ifdef WIN32_KERN 
   // TODO : Implement kenel mode implementation
#else
   TlsSetValue(_vcos_thread_current_key, thread_hndl);
#endif
   (void)rc;

   return(thread_hndl);
}
Exemple #3
0
VCOS_STATUS_T gx_priv_font_init(const unsigned char *font, int fontsize)
{
   VCOS_STATUS_T ret;

   if (vgft_init())
   {
      ret = VCOS_ENOMEM;
      goto fail_init;
   }

   default_font.mem = vcos_malloc(fontsize, "font");
   if (!default_font.mem)
   {
       GX_ERROR("No memory for font");
      ret = VCOS_ENOMEM;
      goto fail_mem;
   }

   memcpy(default_font.mem,font,fontsize);
   default_font.len = fontsize;

   inited = 1;
   return VCOS_SUCCESS;

fail_mem:
   vgft_term();
fail_init:
   return ret;
}
VCOS_THREAD_T *vcos_dummy_thread_create(void)
{
   VCOS_STATUS_T st;
   VCOS_THREAD_T *thread_hndl = NULL;
   int rc;

   thread_hndl = (VCOS_THREAD_T *)vcos_malloc(sizeof(VCOS_THREAD_T), NULL);
   vcos_assert(thread_hndl != NULL);

   memset(thread_hndl, 0, sizeof(VCOS_THREAD_T));

   thread_hndl->dummy = 1;
   thread_hndl->thread = pthread_self();

   st = vcos_semaphore_create(&thread_hndl->suspend, NULL, 0);
   if (st != VCOS_SUCCESS)
   {
      vcos_free(thread_hndl);
      return( thread_hndl );
   }

   vcos_once(&current_thread_key_once, current_thread_key_init);

   rc = pthread_setspecific(_vcos_thread_current_key,
                            thread_hndl);
   (void)rc;

   return( thread_hndl );
}
Exemple #5
0
/** Create a QUEUE of MMAL_BUFFER_HEADER_T */
MMAL_QUEUE_T *mmal_queue_create(void)
{
   MMAL_QUEUE_T *queue;

   queue = vcos_malloc(sizeof(*queue), "MMAL queue");
   if(!queue) return 0;

   if(vcos_mutex_create(&queue->lock, "MMAL queue lock") != VCOS_SUCCESS )
   {
      vcos_free(queue);
      return 0;
   }

   if(vcos_semaphore_create(&queue->semaphore, "MMAL queue sema", 0) != VCOS_SUCCESS )
   {
      vcos_mutex_delete(&queue->lock);
      vcos_free(queue);
      return 0;
   }

   /* gratuitous lock for coverity */ vcos_mutex_lock(&queue->lock);
   queue->length = 0;
   queue->first = 0;
   queue->last = &queue->first;
   mmal_queue_sanity_check(queue, NULL);
   /* gratuitous unlock for coverity */ vcos_mutex_unlock(&queue->lock);

   return queue;
}
int vchiq_wrapper_add_service(VCHIQ_STATE_T *state, void **vconnection, int fourcc, VCHIQ_CALLBACK_T callback, void *userdata)
{
   VCHI_CONNECTION_T **connection = (VCHI_CONNECTION_T **) vconnection;
   VCHI_INSTANCE_T *instance_handle = (VCHI_INSTANCE_T *) state;
   SERVICE_CREATION_T parameters = { fourcc,                  // 4cc service code
                                     0,                       // passed in fn ptrs
                                     0,                       // tx fifo size (unused)
                                     0,                       // tx fifo size (unused)
                                     vchiq_wrapper_callback,  // service callback
                                     0 };                     // callback parameter
   VCHIQ_WRAPPER_T *st = vcos_malloc(sizeof(VCHIQ_WRAPPER_T), "vchiq wrapper");

   if(st == NULL)
      return 0;

   parameters.connection = connection[0];
   parameters.callback_param = st;
   st->state = state;
   st->fourcc = fourcc;
   st->callback = callback;
   st->userdata = userdata;
   st->slot_free = ((1<<SLOT_NUM)-1);

   if(vchi_service_create(*instance_handle, &parameters, &st->vchi_handle) != 0)
   {
      vcos_free(st);
      return 0;
   }

   // add to the global list of wrappers   
   st->next = wrapper_list;
   wrapper_list = st;
   
   return 1;
}
VCOS_STATUS_T vcos_generic_blockpool_create_on_heap(VCOS_BLOCKPOOL_T *pool,
      VCOS_UNSIGNED num_blocks, VCOS_UNSIGNED block_size, VCOS_UNSIGNED align,
      VCOS_UNSIGNED flags, const char *name)
{
   VCOS_STATUS_T status = VCOS_SUCCESS;
   size_t size = VCOS_BLOCKPOOL_SIZE(num_blocks, block_size, align);
   void* mem = vcos_malloc(size, name);

   vcos_log_trace("%s: num_blocks %d block_size %d name %s",
         VCOS_FUNCTION, num_blocks, block_size, name);

   if (! mem)
      return VCOS_ENOMEM;

   status = vcos_generic_blockpool_init(pool, num_blocks,
         block_size, mem, size, align, flags, name);

   if (status != VCOS_SUCCESS)
      goto fail;

   pool->subpools[0].flags |= VCOS_BLOCKPOOL_SUBPOOL_FLAG_OWNS_MEM;
   return status;

fail:
   vcos_free(mem);
   return status;
}
Exemple #8
0
/** Create an instance of a component  */
static MMAL_STATUS_T mmal_component_create_splitter(const char *name, MMAL_COMPONENT_T *component)
{
   MMAL_COMPONENT_MODULE_T *module;
   MMAL_STATUS_T status = MMAL_ENOMEM;
   unsigned int i;
   MMAL_PARAM_UNUSED(name);

   /* Allocate the context for our module */
   component->priv->module = module = vcos_malloc(sizeof(*module), "mmal module");
   if (!module)
      return MMAL_ENOMEM;
   memset(module, 0, sizeof(*module));

   component->priv->pf_destroy = splitter_component_destroy;

   /* Allocate and initialise all the ports for this component */
   component->input = mmal_ports_alloc(component, 1, MMAL_PORT_TYPE_INPUT, sizeof(MMAL_PORT_MODULE_T));
   if(!component->input)
      goto error;
   component->input_num = 1;
   component->input[0]->priv->pf_enable = splitter_port_enable;
   component->input[0]->priv->pf_disable = splitter_port_disable;
   component->input[0]->priv->pf_flush = splitter_port_flush;
   component->input[0]->priv->pf_send = splitter_port_send;
   component->input[0]->priv->pf_set_format = splitter_port_format_commit;
   component->input[0]->priv->pf_parameter_set = splitter_port_parameter_set;
   component->input[0]->buffer_num_min = 1;
   component->input[0]->buffer_num_recommended = 0;
   component->input[0]->priv->module->queue = mmal_queue_create();
   if(!component->input[0]->priv->module->queue)
      goto error;

   component->output = mmal_ports_alloc(component, SPLITTER_OUTPUT_PORTS_NUM,
                                        MMAL_PORT_TYPE_OUTPUT, sizeof(MMAL_PORT_MODULE_T));
   if(!component->output)
      goto error;
   component->output_num = SPLITTER_OUTPUT_PORTS_NUM;
   for(i = 0; i < component->output_num; i++)
   {
      component->output[i]->priv->pf_enable = splitter_port_enable;
      component->output[i]->priv->pf_disable = splitter_port_disable;
      component->output[i]->priv->pf_flush = splitter_port_flush;
      component->output[i]->priv->pf_send = splitter_port_send;
      component->output[i]->priv->pf_set_format = splitter_port_format_commit;
      component->output[i]->priv->pf_parameter_set = splitter_port_parameter_set;
      component->output[i]->buffer_num_min = 1;
      component->output[i]->buffer_num_recommended = 0;
      component->output[i]->capabilities = MMAL_PORT_CAPABILITY_PASSTHROUGH;
      component->output[i]->priv->module->queue = mmal_queue_create();
      if(!component->output[i]->priv->module->queue)
         goto error;
   }

   return MMAL_SUCCESS;

 error:
   splitter_component_destroy(component);
   return status;
}
Exemple #9
0
/** Find a font in our cache, or create a new entry in the cache.
  *
  * Very primitive at present.
  */
static VGFT_FONT_T *find_font(const char *text, uint32_t text_size)
{
   int ptsize, dpi_x = 0, dpi_y = 0;
   VCOS_STATUS_T status;
   gx_font_cache_entry_t *font;

   ptsize = text_size << 6; // freetype takes size in points, in 26.6 format.

   for (font = fonts; font; font = font->next)
   {
      if (font->ptsize == ptsize)
         return &font->font;
   }

   font = vcos_malloc(sizeof(*font), "font");
   if (!font)
      return NULL;

   font->ptsize = ptsize;

   status = vgft_font_init(&font->font);
   if (status != VCOS_SUCCESS)
   {
      vcos_free(font);
      return NULL;
   }

   // load the font
   status = vgft_font_load_mem(&font->font, default_font.mem, default_font.len);
   if (status != VCOS_SUCCESS)
   {
      GX_LOG("Could not load font from memory: %d", status);
      vgft_font_term(&font->font);
      vcos_free(font);
      return NULL;
   }

   status = vgft_font_convert_glyphs(&font->font, ptsize, dpi_x, dpi_y);
   if (status != VCOS_SUCCESS)
   {
      GX_LOG("Could not convert font '%s' at size %d", fname, ptsize);
      vgft_font_term(&font->font);
      vcos_free(font);
      return NULL;
   }

   font->next = fonts;
   fonts = font;

   return &font->font;
}
static int malloc_test()
{
   int passed = 1;
   int size;

   for(size = 1; size < 4096; size = (size*3)+7)
   {
      uint8_t *mem = vcos_malloc(size, "test");

      if(!mem)
         passed = 0;
      else
      {
         int i;
         for(i=0; i<size; i++)
            mem[i] = i&0xff;
         vcos_free(mem);
      }
   }

   if(passed)
   {
      uint8_t *mem1, *mem2, *mem3;
      mem1 = vcos_malloc(1<<10, "test1");
      mem2 = vcos_malloc(1<<11, "test2");
      mem3 = vcos_malloc(1<<16, "test3");

      if(!mem1 || !mem2 || !mem3 || mem1==mem2 || mem1==mem3 || mem2==mem3)
         passed = 0;

      if(mem1) vcos_free(mem1);
      if(mem2) vcos_free(mem2);
      if(mem3) vcos_free(mem3);
   }

   return passed;
}
Exemple #11
0
int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size)
{
   vcos_assert(is_pow2(size));

   queue->size = size;
   queue->read = 0;
   queue->write = 0;

   vcos_event_create(&queue->pop, "vchiu");
   vcos_event_create(&queue->push, "vchiu");

   queue->storage = vcos_malloc(size * sizeof(VCHIQ_HEADER_T *), VCOS_FUNCTION);
   if (queue->storage == NULL)
   {
      vchiu_queue_delete(queue);
      return 0;
   }
   return 1;
}
Exemple #12
0
// Called on the host side to create an OMX component.
OMX_ERRORTYPE vcil_out_create_component(ILCS_COMMON_T *st, OMX_HANDLETYPE hComponent, OMX_STRING component_name)
{
   OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *) hComponent;
   IL_CREATE_COMPONENT_EXECUTE_T exe;
   IL_CREATE_COMPONENT_RESPONSE_T resp;
   VC_PRIVATE_COMPONENT_T *comp;
   OMX_U32 i;
   int rlen = sizeof(resp);

   if (strlen(component_name) >= sizeof(exe.name))
      return OMX_ErrorInvalidComponent;

   strcpy(exe.name, component_name);
   exe.mark = pComp;

   if(ilcs_execute_function(st->ilcs, IL_CREATE_COMPONENT, &exe, sizeof(exe), &resp, &rlen) < 0 || rlen != sizeof(resp))
      return OMX_ErrorHardware;

   if (resp.err != OMX_ErrorNone)
      return resp.err;

   comp = vcos_malloc(sizeof(VC_PRIVATE_COMPONENT_T) + (sizeof(VC_PRIVATE_PORT_T) * resp.numPorts), "ILCS Host Comp");
   if (!comp)
   {
      IL_EXECUTE_HEADER_T dexe;
      IL_RESPONSE_HEADER_T dresp;
      int dlen = sizeof(dresp);

      dexe.reference = resp.reference;

      ilcs_execute_function(st->ilcs, IL_COMPONENT_DEINIT, &dexe, sizeof(dexe), &dresp, &dlen);
      return OMX_ErrorInsufficientResources;
   }

   memset(comp, 0, sizeof(VC_PRIVATE_COMPONENT_T) + (sizeof(VC_PRIVATE_PORT_T) * resp.numPorts));

   comp->reference = resp.reference;
   comp->comp = pComp;
   comp->numPorts = resp.numPorts;
   comp->port = (VC_PRIVATE_PORT_T *) ((unsigned char *) comp + sizeof(VC_PRIVATE_COMPONENT_T));

   for (i=0; i<comp->numPorts; i++)
   {
      if (i && !(i&0x1f))
      {
         IL_GET_EXECUTE_T gexe;
         IL_GET_RESPONSE_T gresp;
         OMX_PARAM_PORTSUMMARYTYPE *summary;
         int glen = sizeof(gresp);

         gexe.reference = comp->reference;
         gexe.index = OMX_IndexParamPortSummary;

         summary = (OMX_PARAM_PORTSUMMARYTYPE *) &gexe.param;
         summary->nSize = sizeof(OMX_PARAM_PORTSUMMARYTYPE);
         summary->nVersion.nVersion = OMX_VERSION;
         summary->reqSet = i>>5;

         ilcs_execute_function(st->ilcs, IL_GET_PARAMETER, &gexe,
                               sizeof(OMX_PARAM_PORTSUMMARYTYPE)+IL_GET_EXECUTE_HEADER_SIZE,
                               &gresp, &glen);

         summary = (OMX_PARAM_PORTSUMMARYTYPE *) &gresp.param;
         resp.portDir = summary->portDir;
         memcpy(resp.portIndex, summary->portIndex, sizeof(OMX_U32) * 32);
      }

      comp->port[i].port = resp.portIndex[i&0x1f];
      comp->port[i].dir = ((resp.portDir >> (i&0x1f)) & 1) ? OMX_DirOutput : OMX_DirInput;
   }
Exemple #13
0
static OMX_ERRORTYPE vcil_out_addBuffer(OMX_IN OMX_HANDLETYPE hComponent,
                                        OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
                                        OMX_IN OMX_U32 nPortIndex,
                                        OMX_IN OMX_PTR pAppPrivate,
                                        OMX_IN OMX_U32 nSizeBytes,
                                        OMX_IN OMX_U8* pBuffer,
                                        OMX_IN void *eglImage,
                                        IL_FUNCTION_T func)
{
   OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *) hComponent;
   VC_PRIVATE_COMPONENT_T *comp;
   IL_ADD_BUFFER_EXECUTE_T exe;
   IL_ADD_BUFFER_RESPONSE_T resp;
   OMX_BUFFERHEADERTYPE *pHeader;
   VC_PRIVATE_PORT_T *port;
   ILCS_COMMON_T *st;
   int rlen = sizeof(resp);

   if (!(pComp && ppBufferHdr))
      return OMX_ErrorBadParameter;

   st = pComp->pApplicationPrivate;
   comp = (VC_PRIVATE_COMPONENT_T *) pComp->pComponentPrivate;

   port = find_port(comp, nPortIndex);
   if (!port) // bad port index
      return OMX_ErrorBadPortIndex;

   if (port->numBuffers > 0 && port->func != func)
   {
      // inconsistent use of usebuffer/allocatebuffer/eglimage
      // all ports must receive all buffers by exactly one of these methods
      vc_assert(port->func != func);
      return OMX_ErrorInsufficientResources;
   }
   port->func = func;

   if (!VCHI_BULK_ALIGNED(pBuffer))
   {
      // cannot transfer this buffer across the host interface
      return OMX_ErrorBadParameter;
   }

   pHeader = vcos_malloc(sizeof(*pHeader), "vcout buffer header");

   if (!pHeader)
      return OMX_ErrorInsufficientResources;

   if (func == IL_ALLOCATE_BUFFER)
   {
      pBuffer = vcos_malloc_aligned(nSizeBytes, ILCS_ALIGN, "vcout mapping buffer");
      if (!pBuffer)
      {
         vcos_free(pHeader);
         return OMX_ErrorInsufficientResources;
      }
   }

   exe.reference = comp->reference;
   exe.bufferReference = pHeader;
   exe.port = nPortIndex;
   exe.size = nSizeBytes;
   exe.eglImage = eglImage;

   if(ilcs_execute_function(st->ilcs, func, &exe, sizeof(exe), &resp, &rlen) < 0 || rlen != sizeof(resp))
      resp.err = OMX_ErrorHardware;

   if (resp.err == OMX_ErrorNone)
   {
      memcpy(pHeader, &resp.bufferHeader, sizeof(OMX_BUFFERHEADERTYPE));
      if (port->dir == OMX_DirOutput)
         pHeader->pOutputPortPrivate = resp.reference;
      else
         pHeader->pInputPortPrivate = resp.reference;

      if (func == IL_USE_EGL_IMAGE)
      {
         pHeader->pBuffer = (OMX_U8*)eglImage;
         port->bEGL = OMX_TRUE;
      }         
      else
      {
         pHeader->pBuffer = pBuffer;
         port->bEGL = OMX_FALSE;
      }

      pHeader->pAppPrivate = pAppPrivate;
      *ppBufferHdr = pHeader;
      port->numBuffers++;
   }
   else
   {
      if (func == IL_ALLOCATE_BUFFER)
         vcos_free(pBuffer);
      vcos_free(pHeader);
   }

   return resp.err;
}
static uint32_t do_allocate(uint32_t szBuffer){
	uint32_t retVal = (uint32_t)vcos_malloc(szBuffer, "GRALLOC -> vc_handle");
	return retVal; 
}
/**
   Allocate memory

   @param size Size in bytes of memory block to allocate
   @return pointer to memory block
**/
void *khrn_platform_malloc(size_t size, const char * name)
{
   return vcos_malloc(size, name);
}
void *vcos_generic_blockpool_alloc(VCOS_BLOCKPOOL_T *pool)
{
   VCOS_UNSIGNED i;
   void* ret = NULL;
   VCOS_BLOCKPOOL_SUBPOOL_T *subpool = NULL;

   ASSERT_POOL(pool);
   vcos_mutex_lock(&pool->mutex);

   /* Starting with the main pool try and find a free block */
   for (i = 0; i < pool->num_subpools; ++i)
   {
      if (pool->subpools[i].start && pool->subpools[i].available_blocks > 0)
      {
         subpool = &pool->subpools[i];
         break; /* Found a subpool with free blocks */
      }
   }

   if (! subpool)
   {
      /* All current subpools are full, try to allocate a new one */
      for (i = 1; i < pool->num_subpools; ++i)
      {
         if (! pool->subpools[i].start)
         {
            VCOS_BLOCKPOOL_SUBPOOL_T *s = &pool->subpools[i];
            size_t size = VCOS_BLOCKPOOL_SIZE(pool->num_extension_blocks,
                  pool->block_data_size, pool->align);
            void *mem = vcos_malloc(size, pool->name);
            if (mem)
            {
               vcos_log_trace("%s: Allocated subpool %d", VCOS_FUNCTION, i);
               vcos_generic_blockpool_subpool_init(pool, s, mem, size,
                     pool->num_extension_blocks,
                     pool->align,
                     VCOS_BLOCKPOOL_SUBPOOL_FLAG_OWNS_MEM |
                     VCOS_BLOCKPOOL_SUBPOOL_FLAG_EXTENSION);
               subpool = s;
               break; /* Created a subpool */
            }
            else
            {
               vcos_log_warn("%s: Failed to allocate subpool", VCOS_FUNCTION);
            }
         }
      }
   }

   if (subpool)
   {
      /* Remove from free list */
      VCOS_BLOCKPOOL_HEADER_T* nb = subpool->free_list;

      vcos_assert(subpool->free_list);
      subpool->free_list = nb->owner.next;

      /* Owner is pool so free can be called without passing pool
       * as a parameter */
      nb->owner.subpool = subpool;

      ret = nb + 1; /* Return pointer to block data */
      --(subpool->available_blocks);
   }
   vcos_mutex_unlock(&pool->mutex);
   VCOS_BLOCKPOOL_DEBUG_LOG("pool %p subpool %p ret %p", pool, subpool, ret);

   if (ret)
   {
      vcos_assert(ret > subpool->start);
      vcos_assert(ret < subpool->end);
   }
   return ret;
}
VCOS_STATUS_T vcos_thread_create(VCOS_THREAD_T *thread,
                                 const char *name,
                                 VCOS_THREAD_ATTR_T *attrs,
                                 void *(*entry)(void *arg),
                                 void *arg)
{
   VCOS_STATUS_T status;

   void *stack, *allocstack = 0;

   /* If no attributes, use the defaults */
   if (!attrs)
      attrs = &default_attrs;

   status = create_base(thread, name);
   if (status != VCOS_SUCCESS)
      goto fail_base;

   /* Do we need to create a stack? */
   stack = attrs->ta_stackaddr;

   if (stack && !VCOS_CAN_SET_STACK_ADDR)
   {
      status = VCOS_EINVAL;
      goto fail_stack;
   }

   if (!stack && VCOS_CAN_SET_STACK_ADDR)
   {
      allocstack = vcos_malloc(attrs->ta_stacksz,thread->name);
      if (!allocstack)
      {
         status = VCOS_ENOMEM;
         goto fail_stack;
      }
      stack = allocstack;
      thread->stack = stack;
   }

   thread->legacy = attrs->legacy;

   thread->entry = entry;
   thread->arg = arg;

   status = vcos_llthread_create(&thread->thread, thread->name, vcos_thread_wrapper, thread,
                                 stack, attrs->ta_stacksz,
                                 attrs->ta_priority, attrs->ta_affinity,
                                 attrs->ta_timeslice, attrs->ta_autostart);
   if (status != VCOS_SUCCESS)
      goto fail_thread;

   return VCOS_SUCCESS;

fail_thread:
   if (allocstack)
      vcos_free(allocstack);
fail_stack:
   delete_base(thread);
fail_base:
   return status;
}
Exemple #18
0
static void *mmal_pool_allocator_default_alloc(void *context, uint32_t size)
{
    MMAL_PARAM_UNUSED(context);
    return vcos_malloc(size, "mmal_pool payload");
}