Пример #1
0
static int rarch_main_data_nbio_iterate_parse_free(nbio_handle_t *nbio)
{
   if (!nbio || !nbio->is_finished)
      return -1;

   nbio_free(nbio->handle);
   nbio->handle      = NULL;
   nbio->is_finished = false;
   nbio->frame_count = 0;

   msg_queue_clear(nbio->msg_queue);

   return 0;
}
Пример #2
0
static void task_audio_mixer_load_free(retro_task_t *task)
{
   nbio_handle_t       *nbio        = (nbio_handle_t*)task->state;
   struct audio_mixer_handle *image = (struct audio_mixer_handle*)nbio->data;

   if (image)
   {
      if (image->buffer)
         free(image->buffer);
   }

   if (nbio->data)
      free(nbio->data);
   nbio_free(nbio->handle);
   free(nbio);
}
Пример #3
0
static bool rpng_nbio_load_image_argb(const char *path, uint32_t **data,
      unsigned *width, unsigned *height)
{
   int retval;
   size_t file_len;
   bool ret = true;
   struct rpng_t *rpng = NULL;
   void *ptr = NULL;
   unsigned val = 0;
   struct nbio_t* handle = (void*)nbio_open(path, NBIO_READ);

   if (!handle)
      goto end;

   ptr  = nbio_get_ptr(handle, &file_len);

   nbio_begin_read(handle);

   while (!nbio_iterate(handle));

   ptr = nbio_get_ptr(handle, &file_len);

   if (!ptr)
   {
      ret = false;
      goto end;
   }

   rpng = (struct rpng_t*)calloc(1, sizeof(struct rpng_t));

   if (!rpng)
   {
      ret = false;
      goto end;
   }

   rpng->buff_data = (uint8_t*)ptr;

   if (!rpng->buff_data)
   {
      ret = false;
      goto end;
   }

   if (!rpng_nbio_load_image_argb_start(rpng))
   {
      ret = false;
      goto end;
   }

   while (rpng_nbio_load_image_argb_iterate(
            rpng->buff_data, rpng, &val))
   {
      rpng->buff_data += val;
   }

#if 0
   fprintf(stderr, "has_ihdr: %d\n", rpng->has_ihdr);
   fprintf(stderr, "has_idat: %d\n", rpng->has_idat);
   fprintf(stderr, "has_iend: %d\n", rpng->has_iend);
#endif

   if (!rpng->has_ihdr || !rpng->has_idat || !rpng->has_iend)
   {
      ret = false;
      goto end;
   }
   
   do
   {
      retval = rpng_nbio_load_image_argb_process(rpng, data, width, height);
   }while(retval == IMAGE_PROCESS_NEXT);

   if (retval == IMAGE_PROCESS_ERROR || retval == IMAGE_PROCESS_ERROR_END)
      ret = false;

end:
   if (handle)
      nbio_free(handle);
   if (rpng)
      rpng_nbio_load_image_free(rpng);
   rpng = NULL;
   if (!ret)
      free(*data);
   return ret;
}
Пример #4
0
static bool rpng_load_image_argb(const char *path, uint32_t **data,
      unsigned *width, unsigned *height)
{
   int retval;
   size_t file_len;
   bool              ret = true;
   rpng_t          *rpng = NULL;
   void             *ptr = NULL;
   struct nbio_t* handle = (struct nbio_t*)nbio_open(path, NBIO_READ);

   if (!handle)
      goto end;

   nbio_begin_read(handle);

   while (!nbio_iterate(handle));

   ptr = nbio_get_ptr(handle, &file_len);

   if (!ptr)
   {
      ret = false;
      goto end;
   }

   rpng = rpng_alloc();

   if (!rpng)
   {
      ret = false;
      goto end;
   }

   if (!rpng_set_buf_ptr(rpng, (uint8_t*)ptr))
   {
      ret = false;
      goto end;
   }

   if (!rpng_start(rpng))
   {
      ret = false;
      goto end;
   }

   while (rpng_iterate_image(rpng));

   if (!rpng_is_valid(rpng))
   {
      ret = false;
      goto end;
   }

   do
   {
      retval = rpng_process_image(rpng,
            (void**)data, file_len, width, height);
   }while(retval == IMAGE_PROCESS_NEXT);

   if (retval == IMAGE_PROCESS_ERROR || retval == IMAGE_PROCESS_ERROR_END)
      ret = false;

end:
   if (handle)
      nbio_free(handle);
   if (rpng)
      rpng_free(rpng);
   rpng = NULL;
   if (!ret)
      free(*data);
   return ret;
}
Пример #5
0
bool task_push_audio_mixer_load(const char *fullpath, retro_task_callback_t cb, void *user_data)
{
   nbio_handle_t             *nbio    = NULL;
   struct audio_mixer_handle   *image = NULL;
   retro_task_t                   *t  = (retro_task_t*)calloc(1, sizeof(*t));

   if (!t)
      goto error;

   nbio               = (nbio_handle_t*)calloc(1, sizeof(*nbio));

   if (!nbio)
      goto error;

   strlcpy(nbio->path, fullpath, sizeof(nbio->path));

   image              = (struct audio_mixer_handle*)calloc(1, sizeof(*image));   
   if (!image)
      goto error;

   image->is_finished = false;

   strlcpy(image->path, fullpath, sizeof(image->path));

   nbio->type         = NBIO_TYPE_NONE;
   image->type        = AUDIO_MIXER_TYPE_NONE;

   if (strstr(fullpath, file_path_str(FILE_PATH_WAV_EXTENSION)))
   {
      image->type     = AUDIO_MIXER_TYPE_WAV;
      nbio->type      = NBIO_TYPE_WAV;
      t->callback     = task_audio_mixer_handle_upload_wav;
   }
   else if (strstr(fullpath, file_path_str(FILE_PATH_OGG_EXTENSION)))
   {
      image->type     = AUDIO_MIXER_TYPE_OGG;
      nbio->type      = NBIO_TYPE_OGG;
      t->callback     = task_audio_mixer_handle_upload_ogg;
   }
   else if (	strstr(fullpath, file_path_str(FILE_PATH_MOD_EXTENSION)) ||
		strstr(fullpath, file_path_str(FILE_PATH_S3M_EXTENSION)) ||
		strstr(fullpath, file_path_str(FILE_PATH_XM_EXTENSION)))
   {
      image->type     = AUDIO_MIXER_TYPE_MOD;
      nbio->type      = NBIO_TYPE_MOD;
      t->callback     = task_audio_mixer_handle_upload_mod;
   }

   nbio->data         = (struct audio_mixer_handle*)image;
   nbio->is_finished  = false;
   nbio->cb           = &cb_nbio_audio_mixer_load;
   nbio->status       = NBIO_STATUS_INIT;

   t->state           = nbio;
   t->handler         = task_file_load_handler;
   t->cleanup         = task_audio_mixer_load_free;
   t->user_data       = user_data;

   task_queue_push(t);

   return true;

error:
   if (nbio)
   {
      if (nbio->data)
         free(nbio->data);
      nbio_free(nbio->handle);
      free(nbio);
   }
   if (t)
      free(t);

   RARCH_ERR("[audio mixer load] Failed to open '%s': %s.\n",
         fullpath, strerror(errno));

   return false;
}
Пример #6
0
static void rarch_task_file_load_handler(rarch_task_t *task)
{
   nbio_handle_t         *nbio  = (nbio_handle_t*)task->state;
   nbio_image_handle_t   *image = nbio    ? &nbio->image   : NULL;

   switch (nbio->status)
   {
      case NBIO_STATUS_TRANSFER_PARSE:
         rarch_main_data_nbio_iterate_parse(nbio);
         nbio->status = NBIO_STATUS_TRANSFER_PARSE_FREE;
         break;
      case NBIO_STATUS_TRANSFER:
         if (rarch_main_data_nbio_iterate_transfer(nbio) == -1)
            nbio->status = NBIO_STATUS_TRANSFER_PARSE;
         break;
      case NBIO_STATUS_TRANSFER_PARSE_FREE:
      case NBIO_STATUS_POLL:
      default:
         break;
   }

   if (nbio->image.handle)
   {
      switch (image->status)
      {
         case NBIO_IMAGE_STATUS_PROCESS_TRANSFER:
            if (rarch_main_data_image_iterate_process_transfer(nbio) == -1)
               image->status = NBIO_IMAGE_STATUS_PROCESS_TRANSFER_PARSE;
            break;
         case NBIO_IMAGE_STATUS_TRANSFER_PARSE:
            rarch_main_data_image_iterate_transfer_parse(nbio);
            if (image->is_blocking_on_processing)
               image->status = NBIO_IMAGE_STATUS_PROCESS_TRANSFER;
            break;
         case NBIO_IMAGE_STATUS_TRANSFER:
            if (!image->is_blocking)
               if (rarch_main_data_image_iterate_transfer(nbio) == -1)
                  image->status = NBIO_IMAGE_STATUS_TRANSFER_PARSE;
            break;
         case NBIO_IMAGE_STATUS_PROCESS_TRANSFER_PARSE:
            rarch_main_data_image_iterate_process_transfer_parse(nbio);
            if (!image->is_finished)
               break;
         case NBIO_IMAGE_STATUS_TRANSFER_PARSE_FREE:
         case NBIO_IMAGE_STATUS_POLL:
         default:
            break;
      }

      if (nbio->is_finished && nbio->image.is_finished && !task->cancelled)
      {
         task->task_data = malloc(sizeof(nbio->image.ti));
         memcpy(task->task_data, &nbio->image.ti, sizeof(nbio->image.ti));
         goto task_finished;
      }

   } else
      if (nbio->is_finished)
         goto task_finished;


   if (task->cancelled)
   {
      task->error = strdup("Task canceled.");
      goto task_finished;
   }

   return;

task_finished:
   task->finished = true;

   if (image->handle)
   {
      rpng_nbio_load_image_free(image->handle);

      image->handle                 = NULL;
      image->frame_count            = 0;
   }

   nbio_free(nbio->handle);
   nbio->handle      = NULL;
   nbio->is_finished = false;
   nbio->frame_count = 0;
   free(nbio);
}