From 5eb3bb05f7219f4b3a875df6840d8307b8ac2943 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 6 Apr 2016 21:58:23 +0200 Subject: [PATCH] Start adding streams/interface_stream.c --- Makefile.common | 2 + griffin/griffin.c | 2 + .../include/streams/interface_stream.h | 56 +++++++++++++++ libretro-common/streams/interface_stream.c | 72 +++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 libretro-common/include/streams/interface_stream.h create mode 100644 libretro-common/streams/interface_stream.c diff --git a/Makefile.common b/Makefile.common index f1afbd1f8f..ea1bcf7452 100644 --- a/Makefile.common +++ b/Makefile.common @@ -133,6 +133,8 @@ OBJ += frontend/frontend.o \ libretro-common/lists/dir_list.o \ libretro-common/file/retro_dirent.o \ libretro-common/streams/file_stream.o \ + libretro-common/streams/interface_stream.o \ + libretro-common/streams/memory_stream.o \ libretro-common/file/retro_stat.o \ libretro-common/lists/string_list.o \ libretro-common/string/stdstring.o \ diff --git a/griffin/griffin.c b/griffin/griffin.c index 85ff5f5176..e6615ffef4 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -643,6 +643,8 @@ FILE #include "../libretro-common/lists/file_list.c" #include "../libretro-common/file/retro_dirent.c" #include "../libretro-common/streams/file_stream.c" +#include "../libretro-common/streams/interface_stream.c" +#include "../libretro-common/streams/memory_stream.c" #include "../libretro-common/file/retro_stat.c" #include "../list_special.c" #include "../libretro-common/string/stdstring.c" diff --git a/libretro-common/include/streams/interface_stream.h b/libretro-common/include/streams/interface_stream.h new file mode 100644 index 0000000000..3c106df27e --- /dev/null +++ b/libretro-common/include/streams/interface_stream.h @@ -0,0 +1,56 @@ +/* Copyright (C) 2010-2015 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (memory_stream.h). + * --------------------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, + * to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef _LIBRETRO_SDK_INTERFACE_STREAM_H +#define _LIBRETRO_SDK_INTERFACE_STREAM_H + +#include +#include + +#include + +enum intfstream_type +{ + INTFSTREAM_FILE = 0, + INTFSTREAM_MEMORY +}; + +typedef struct intfstream_internal intfstream_internal_t; + +typedef struct intfstream intfstream_t; + +typedef struct intfstream_info +{ + struct + { + uint8_t *data; + unsigned size; + } buf; + enum intfstream_type type; +} intfstream_info_t; + +void *intfstream_init(intfstream_info_t *info); + +bool intfstream_resize(intfstream_internal_t *intf, + intfstream_info_t *info); + +#endif diff --git a/libretro-common/streams/interface_stream.c b/libretro-common/streams/interface_stream.c new file mode 100644 index 0000000000..b183e2cc58 --- /dev/null +++ b/libretro-common/streams/interface_stream.c @@ -0,0 +1,72 @@ +#include + +#include +#include +#include + +struct intfstream_internal +{ + enum intfstream_type type; + + struct + { + struct + { + uint8_t *data; + unsigned size; + } buf; + } memory; +}; + +bool intfstream_resize(intfstream_internal_t *intf, intfstream_info_t *info) +{ + if (!intf || !info) + return false; + + switch (intf->type) + { + case INTFSTREAM_FILE: + break; + case INTFSTREAM_MEMORY: + intf->memory.buf.data = info->buf.data; + intf->memory.buf.size = info->buf.size; + + memstream_set_buffer(intf->memory.buf.data, + intf->memory.buf.size); + break; + } + + return true; +} + +void *intfstream_init(intfstream_info_t *info) +{ + intfstream_internal_t *intf = NULL; + if (!info) + goto error; + + intf = (intfstream_internal_t*)calloc(1, sizeof(*intf)); + + if (!intf) + goto error; + + intf->type = info->type; + + switch (intf->type) + { + case INTFSTREAM_FILE: + break; + case INTFSTREAM_MEMORY: + if (!intfstream_resize(intf, info)) + goto error; + break; + } + + return intf; + +error: + if (intf) + free(intf); + return NULL; +} +