Files
WizzardSK 79e83492e5 libretro: read media through the frontend's VFS (#58)
Requested in #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.
2026-08-12 19:42:56 -05:00

47 lines
1.0 KiB
C

/*
Copyright 2013 Michael Pavone
This file is part of BlastEm.
BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
*/
#ifndef WAVE_H_
#define WAVE_H_
#include <stdint.h>
#include <stdio.h>
#include "media_file.h"
#pragma pack(push, 1)
typedef struct {
char id[4];
uint32_t size;
char format[4];
} riff_chunk;
typedef struct {
char id[4];
uint32_t size;
} riff_sub_chunk;
typedef struct {
riff_chunk chunk;
riff_sub_chunk format_header;
uint16_t audio_format;
uint16_t num_channels;
uint32_t sample_rate;
uint32_t byte_rate;
uint16_t block_align;
uint16_t bits_per_sample;
riff_sub_chunk data_header;
long data_offset;
} wave_header;
#pragma pack(pop)
int wave_init(FILE * f, uint32_t sample_rate, uint16_t bits_per_sample, uint16_t num_channels);
uint8_t wave_read_header(media_file *f, wave_header *header);
int wave_finalize(FILE * f);
#endif //WAVE_H_