示例#1
0
BRCMIMAGE_STATUS_T brcmimage_create(BRCMIMAGE_TYPE_T type, unsigned int encoding, BRCMIMAGE_T **ctx)
{
   BRCMIMAGE_STATUS_T status = BRCMIMAGE_SUCCESS;
   BRCMIMAGE_T **comp;

   if (type == BRCMIMAGE_TYPE_ENCODER)
      comp = &brcmimage_encoder[getEncoderIndexFromType(encoding)];
   else
      comp = &brcmimage_decoder[getEncoderIndexFromType(encoding)];

   vcos_once(&once, brcmimage_init_once);
   LOCK();
   if (!*comp)
   {
      int init1, init2, init3;
      *comp = (BRCMIMAGE_T*)calloc(sizeof(BRCMIMAGE_T), 1);
      if (!*comp)
      {
         UNLOCK();
         return BRCMIMAGE_ERROR_NOMEM;
      }
      (*comp)->type = type;
      (*comp)->encoding = encoding;
      init1 = vcos_mutex_create(&(*comp)->lock, "brcmimage lock") != VCOS_SUCCESS;
      init2 = vcos_mutex_create(&(*comp)->process_lock, "brcmimage process lock") != VCOS_SUCCESS;
      init3 = vcos_semaphore_create(&(*comp)->sema, "brcmimage sema", 0) != VCOS_SUCCESS;
      if (init1 | init2 | init3)
      {
         if (init1) vcos_mutex_delete(&(*comp)->lock);
         if (init2) vcos_mutex_delete(&(*comp)->process_lock);
         if (init3) vcos_semaphore_delete(&(*comp)->sema);
         free(comp);
         UNLOCK();
         return BRCMIMAGE_ERROR_NOMEM;
      }
   }
   (*comp)->ref_count++;
   UNLOCK();

   LOCK_COMP(*comp);
   if (!(*comp)->init)
   {
      if (type == BRCMIMAGE_TYPE_ENCODER)
         status = brcmimage_init_encoder(*comp);
      else
         status = brcmimage_init_decoder(*comp);

      (*comp)->init = status == BRCMIMAGE_SUCCESS;
   }
   UNLOCK_COMP(*comp);

   if (status != BRCMIMAGE_SUCCESS)
      brcmimage_release(*comp);

   *ctx = *comp;
   return status;
}
示例#2
0
BRCMJPEG_STATUS_T brcmjpeg_create(BRCMJPEG_TYPE_T type, BRCMJPEG_T **ctx)
{
   BRCMJPEG_STATUS_T status = BRCMJPEG_SUCCESS;
   BRCMJPEG_T **comp;

   if (type == BRCMJPEG_TYPE_ENCODER)
      comp = &brcmjpeg_encoder;
   else
      comp = &brcmjpeg_decoder;

   vcos_once(&once, brcmjpeg_init_once);
   LOCK();
   if (!*comp)
   {
      int init1, init2, init3;
      *comp = (BRCMJPEG_T*)calloc(sizeof(BRCMJPEG_T), 1);
      if (!*comp)
      {
         UNLOCK();
         return BRCMJPEG_ERROR_NOMEM;
      }
      (*comp)->type = type;
      init1 = vcos_mutex_create(&(*comp)->lock, "brcmjpeg lock") != VCOS_SUCCESS;
      init2 = vcos_mutex_create(&(*comp)->process_lock, "brcmjpeg process lock") != VCOS_SUCCESS;
      init3 = vcos_semaphore_create(&(*comp)->sema, "brcmjpeg sema", 0) != VCOS_SUCCESS;
      if (init1 | init2 | init3)
      {
         if (init1) vcos_mutex_delete(&(*comp)->lock);
         if (init2) vcos_mutex_delete(&(*comp)->process_lock);
         if (init3) vcos_semaphore_delete(&(*comp)->sema);
         free(comp);
         UNLOCK();
         return BRCMJPEG_ERROR_NOMEM;
      }
   }
   (*comp)->ref_count++;
   UNLOCK();

   LOCK_COMP(*comp);
   if (!(*comp)->init)
   {
      if (type == BRCMJPEG_TYPE_ENCODER)
         status = brcmjpeg_init_encoder(*comp);
      else
         status = brcmjpeg_init_decoder(*comp);

      (*comp)->init = status == BRCMJPEG_SUCCESS;
   }
   UNLOCK_COMP(*comp);

   if (status != BRCMJPEG_SUCCESS)
      brcmjpeg_release(*comp);

   *ctx = *comp;
   return status;
}
示例#3
0
void brcmimage_release(BRCMIMAGE_T *ctx)
{
   LOCK_COMP(ctx);
   if (--ctx->ref_count)
   {
      UNLOCK_COMP(ctx);
      return;
   }

   LOCK();
   if (ctx->type == BRCMIMAGE_TYPE_ENCODER)
      brcmimage_encoder[ctx->encoding] = NULL;
   else
      brcmimage_decoder[ctx->encoding] = NULL;
   UNLOCK();
   UNLOCK_COMP(ctx);

   brcmimage_destroy(ctx);
   return;
}
示例#4
0
void brcmjpeg_release(BRCMJPEG_T *ctx)
{
   LOCK_COMP(ctx);
   if (--ctx->ref_count)
   {
      UNLOCK_COMP(ctx);
      return;
   }

   LOCK();
   if (ctx->type == BRCMJPEG_TYPE_ENCODER)
      brcmjpeg_encoder = NULL;
   else
      brcmjpeg_decoder = NULL;
   UNLOCK();
   UNLOCK_COMP(ctx);

   brcmjpeg_destroy(ctx);
   return;
}
示例#5
0
void brcmimage_acquire(BRCMIMAGE_T *ctx)
{
   LOCK_COMP(ctx);
   ctx->ref_count++;
   UNLOCK_COMP(ctx);
}
示例#6
0
void brcmjpeg_acquire(BRCMJPEG_T *ctx)
{
   LOCK_COMP(ctx);
   ctx->ref_count++;
   UNLOCK_COMP(ctx);
}