From f233ccb1418cc473d9fa95bc9064b8c824d2e4a5 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 22 Feb 2015 07:34:33 +0100 Subject: [PATCH] Start making rnbio_handle chain --- general.h | 3 + .../formats/png/rpng_decode_fnbio.c | 18 +-- retroarch.c | 2 + runloop.c | 113 +++++++++++++++++- 4 files changed, 125 insertions(+), 11 deletions(-) diff --git a/general.h b/general.h index 46de30967d..4a8c3ba8c1 100644 --- a/general.h +++ b/general.h @@ -33,6 +33,7 @@ #include #include "gfx/video_viewport.h" +#include #include #include "playlist.h" @@ -593,6 +594,8 @@ struct global struct { + transfer_cb_t cb; + struct nbio_t *handle; msg_queue_t *msg_queue; } nbio; diff --git a/libretro-common/formats/png/rpng_decode_fnbio.c b/libretro-common/formats/png/rpng_decode_fnbio.c index a9292f6ce5..36276bebd5 100644 --- a/libretro-common/formats/png/rpng_decode_fnbio.c +++ b/libretro-common/formats/png/rpng_decode_fnbio.c @@ -332,7 +332,7 @@ void rpng_nbio_load_image_free(struct rpng_t *rpng) struct rpng_t *rpng_nbio_load_image_argb_init(const char *path) { size_t file_len; - struct nbio_t* nbread = NULL; + struct nbio_t* handle = NULL; struct rpng_t *rpng = (struct rpng_t*)calloc(1, sizeof(struct rpng_t)); if (!rpng) @@ -340,14 +340,14 @@ struct rpng_t *rpng_nbio_load_image_argb_init(const char *path) rpng->userdata = (void*)nbio_open(path, NBIO_READ); - nbread = (struct nbio_t*)rpng->userdata; + handle = (struct nbio_t*)rpng->userdata; - if (!nbread) + if (!handle) goto error; - rpng->ptr = nbio_get_ptr(nbread, &file_len); + rpng->ptr = nbio_get_ptr(handle, &file_len); - nbio_begin_read(nbread); + nbio_begin_read(handle); return rpng; @@ -364,17 +364,17 @@ bool rpng_nbio_load_image_argb_start(struct rpng_t *rpng) unsigned i; size_t file_len; char header[8]; - struct nbio_t *nbread = NULL; + struct nbio_t *handle = NULL; if (!rpng) return false; - nbread = (struct nbio_t*)rpng->userdata; + handle = (struct nbio_t*)rpng->userdata; - if (!nbread) + if (!handle) return false; - rpng->ptr = nbio_get_ptr(nbread, &file_len); + rpng->ptr = nbio_get_ptr(handle, &file_len); if (!rpng->ptr) return false; diff --git a/retroarch.c b/retroarch.c index 4a582f0361..5697c6474f 100644 --- a/retroarch.c +++ b/retroarch.c @@ -2615,6 +2615,8 @@ bool rarch_main_command(unsigned cmd) #endif if (!g_extern.nbio.msg_queue) rarch_assert(g_extern.nbio.msg_queue = msg_queue_new(8)); + if (!g_extern.images.msg_queue) + rarch_assert(g_extern.images.msg_queue = msg_queue_new(8)); break; case RARCH_CMD_BSV_MOVIE_DEINIT: if (g_extern.bsv.movie) diff --git a/runloop.c b/runloop.c index 931d90590d..f2e25c6cc2 100644 --- a/runloop.c +++ b/runloop.c @@ -878,10 +878,37 @@ static int rarch_main_iterate_quit(void) return -1; } +static int rarch_main_iterate_nbio_transfer(void) +{ + size_t pos = 0, tot = 0; + + if (!nbio_iterate(g_extern.nbio.handle)) + return -1; + + return 0; +} + +static int rarch_main_iterate_nbio_parse(void) +{ + size_t len; + char *data = nbio_get_ptr(g_extern.nbio.handle, &len); + + if (data && g_extern.nbio.cb) + g_extern.nbio.cb(data, len); + + nbio_free(g_extern.nbio.handle); + g_extern.nbio.handle = NULL; + + msg_queue_clear(g_extern.nbio.msg_queue); + + return 0; +} + #ifdef HAVE_NETWORKING int cb_core_updater_download(void *data_, size_t len); int cb_core_updater_list(void *data_, size_t len); + /** * rarch_main_iterate_http_transfer: * @@ -919,8 +946,6 @@ static int rarch_main_iterate_http_parse(void) g_extern.http.handle = NULL; msg_queue_clear(g_extern.http.msg_queue); - msg_queue_clear(g_extern.nbio.msg_queue); - msg_queue_clear(g_extern.images.msg_queue); return 0; } @@ -986,6 +1011,82 @@ static int rarch_main_iterate_http_poll(void) } #endif +#ifdef HAVE_OVERLAY +static int cb_nbio_image_overlay_load(void *data, size_t len) +{ + (void)data; + (void)len; + + return 0; +} +#endif + +static int cb_nbio_default(void *data, size_t len) +{ + (void)data; + (void)len; + + return 0; +} + +static int rarch_main_iterate_nbio_poll(void) +{ + struct nbio_t* handle; + char elem0[PATH_MAX_LENGTH], elem1[PATH_MAX_LENGTH]; + struct string_list *str_list = NULL; + const char *path = msg_queue_pull(g_extern.nbio.msg_queue); + + if (!path) + return -1; + + /* Can only deal with one HTTP transfer at a time for now */ + if (g_extern.nbio.handle) + return -1; + + str_list = string_split(path, "|"); + + if (!str_list) + goto error; + + if (str_list->size > 0) + strlcpy(elem0, str_list->elems[0].data, sizeof(elem0)); + if (str_list->size > 1) + strlcpy(elem1, str_list->elems[1].data, sizeof(elem1)); + + handle = nbio_open(elem0, NBIO_READ); + + if (!handle) + { + RARCH_ERR("Could not create new file loading handle.\n"); + goto error; + } + + g_extern.nbio.handle = handle; + g_extern.nbio.cb = NULL; + + if (elem1[0] != '\0') + { +#ifdef HAVE_OVERLAY + if (!strcmp(elem1, "cb_image_overlay_load")) + g_extern.nbio.cb = &cb_nbio_image_overlay_load; + else +#endif + g_extern.nbio.cb = &cb_nbio_default; + } + + nbio_begin_read(handle); + + string_list_free(str_list); + + return 0; + +error: + if (str_list) + string_list_free(str_list); + + return -1; +} + #ifdef HAVE_MENU static void rarch_main_iterate_rdl(void) { @@ -1107,6 +1208,14 @@ int rarch_main_iterate(void) if (driver.overlay) rarch_main_iterate_overlay_state(); #endif + + if (g_extern.nbio.handle) + { + if (!rarch_main_iterate_nbio_transfer()) + rarch_main_iterate_nbio_parse(); + } + else + rarch_main_iterate_nbio_poll(); #ifdef HAVE_NETWORKING if (g_extern.http.handle)