libretro: read media through the frontend's VFS - #58
Open
WizzardSK wants to merge 1 commit into
Open
Conversation
Requested in libretro#56: on Android the frontend hands out Storage Access Framework content:// URIs, and an SMB share is smb://, neither of which fopen() can do anything with. Plain ROMs already arrive in memory through the content info override, so what was left unreachable is everything the core opens by name itself: CD images (cue/toc/iso/chd) and every track file a cue sheet points at, compressed ROMs, and the Sega CD, 32X, Colecovision and LaserActive BIOS. vfs_file.c is that layer, and media_file.h picks it over stdio for the libretro build alone - with no VFS interface on offer, or in the standalone emulator, it is the same stdio calls as before. gzip needed handling of its own: it used to come from gzopen(), which takes a filename and so cannot be pointed at a VFS handle, so a gzipped file is now read through the VFS and inflated in memory, falling back to reading the file as-is unless a complete stream comes out. CHDs go through chd_open_core_file() with a bridge to the same layer rather than chd_open(), which would open the path itself. is_absolute_path() had to be relaxed for the BIOS lookups: a URI does not look absolute to it, so the BIOS path was falling through to read_bundled_file(), which in a libretro build never finds anything. Tested with a harness that offers the core a VFS whose paths carry a scheme nothing else can resolve, so a successful load proves the callbacks were used: ROM, gzipped ROM, cue plus its track file, iso, and the BIOS all load through it, an invalid CHD fails cleanly with the right message, and with the interface withheld everything still loads over stdio. The gzipped and uncompressed ROM produce identical framebuffers after 30 frames.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #56.
On Android the frontend hands out Storage Access Framework
content://URIs, and an SMB share issmb://;fopen()can do nothing with either. Plain ROMs already arrive in memory through the content info override, so what was unreachable is everything the core opens by name itself: CD images (cue/toc/iso/chd) and every track file a cue sheet points at, compressed ROMs, and the Sega CD, 32X, Colecovision and LaserActive BIOS.vfs_file.ctalks toRETRO_ENVIRONMENT_GET_VFS_INTERFACEandmedia_file.hselects it for the libretro build alone; with no interface on offer, or in the standalone emulator, it compiles down to the same stdio calls as before. Two things needed more than a rename: gzip used to come fromgzopen(), which takes a filename and cannot be pointed at a VFS handle, so a gzipped file is read through the VFS and inflated in memory (falling back to reading it as-is unless a complete stream comes out); and CHDs go throughchd_open_core_file()with a bridge to the same layer instead ofchd_open(), which opens the path itself.is_absolute_path()also had to be relaxed for the BIOS lookups — a URI does not look absolute to it, so the path fell through toread_bundled_file(), which in a libretro build never finds anything.Tested with a harness that offers the core a VFS whose paths carry a scheme nothing else can resolve, so a successful load proves the callbacks were used: ROM, gzipped ROM, cue plus its track file, iso and the BIOS all load through it, an invalid CHD fails cleanly with the existing message, and with the interface withheld everything still loads over stdio. The gzipped and uncompressed ROM produce identical framebuffers after 30 frames. Standalone was checked by type-checking the shared translation units without
IS_LIB;system.c,coleco.candlaseractive.cneed SDL/GLES headers I don't have here, and their changes are either inside#ifdef IS_LIBor macros expanding to the exact stdio calls that were there before.