This commit is contained in:
bnnm 2021-09-05 17:53:47 +02:00
parent be24c70e01
commit bee90fd0ad
6 changed files with 532 additions and 528 deletions

View File

@ -257,16 +257,18 @@ sourceball:
# git archive --format zip --output bin/vgmstream-$(VGMSTREAM_VERSION)-src.zip master # git archive --format zip --output bin/vgmstream-$(VGMSTREAM_VERSION)-src.zip master
rm -rf vgmstream-$(VGMSTREAM_VERSION) rm -rf vgmstream-$(VGMSTREAM_VERSION)
bin: vgmstream_cli winamp xmplay bin: vgmstream-cli winamp xmplay
mkdir -p bin mkdir -p bin
zip -FS -j "bin/$(BIN_FILE).zip" $(ZIP_FILES) zip -FS -j "bin/$(BIN_FILE).zip" $(ZIP_FILES)
#separate since vgmstream123 is kinda untested #separate since vgmstream123 is kinda untested
bin-ex: vgmstream_cli winamp xmplay vgmstream123 bin-ex: vgmstream-cli winamp xmplay vgmstream123
mkdir -p bin mkdir -p bin
zip -FS -j "bin/$(BIN_FILE).zip" $(ZIP_FILES) $(ZIP_FILES_AO) zip -FS -j "bin/$(BIN_FILE).zip" $(ZIP_FILES) $(ZIP_FILES_AO)
vgmstream_cli: version vgmstream_cli: vgmstream-cli
vgmstream-cli: version
$(MAKE) -C cli vgmstream_cli $(MAKE) -C cli vgmstream_cli
vgmstream123: version vgmstream123: version
@ -289,4 +291,4 @@ clean:
$(MAKE) -C xmplay clean $(MAKE) -C xmplay clean
$(MAKE) -C ext_libs clean $(MAKE) -C ext_libs clean
.PHONY: clean buildfullrelease buildrelease sourceball bin vgmstream_cli winamp .PHONY: clean buildfullrelease buildrelease sourceball bin vgmstream-cli vgmstream_cli vgmstream123 winamp xmplay version

View File

@ -285,7 +285,7 @@ sudo apt-get install gcc g++ make git
sudo apt-get install autoconf automake libtool sudo apt-get install autoconf automake libtool
# vgmstream dependencies # vgmstream dependencies
sudo apt-get install libmpg123-dev libvorbis-dev libspeex-dev sudo apt-get install libmpg123-dev libvorbis-dev libspeex-dev
#sudo apt-get install libavformat-dev libavcodec-dev libavutil-dev libswresample-dev sudo apt-get install libavformat-dev libavcodec-dev libavutil-dev libswresample-dev
# Audacious player and dependencies # Audacious player and dependencies
sudo apt-get install audacious sudo apt-get install audacious
sudo apt-get install audacious-dev libglib2.0-dev libgtk2.0-dev libpango1.0-dev sudo apt-get install audacious-dev libglib2.0-dev libgtk2.0-dev libpango1.0-dev

View File

@ -10,7 +10,8 @@
#include <shared.h> #include <shared.h>
extern "C" { extern "C" {
#include "../src/vgmstream.h" #include "../src/streamfile.h"
//#include "../src/vgmstream.h"
#include "../src/util.h" #include "../src/util.h"
} }
#include "foo_vgmstream.h" #include "foo_vgmstream.h"
@ -18,184 +19,183 @@ extern "C" {
/* a STREAMFILE that operates via foobar's file service using a buffer */ /* a STREAMFILE that operates via foobar's file service using a buffer */
typedef struct { typedef struct {
STREAMFILE sf; /* callbacks */ STREAMFILE vt; /* callbacks */
bool m_file_opened; /* if foobar IO service opened the file */ bool m_file_opened; /* if foobar IO service opened the file */
service_ptr_t<file> m_file; /* foobar IO service */ service_ptr_t<file> m_file; /* foobar IO service */
abort_callback * p_abort; /* foobar error stuff */ abort_callback * p_abort; /* foobar error stuff */
char * name; /* IO filename */ char* name; /* IO filename */
offv_t offset; /* last read offset (info) */ offv_t offset; /* last read offset (info) */
offv_t buffer_offset; /* current buffer data start */ offv_t buf_offset; /* current buffer data start */
uint8_t * buffer; /* data buffer */ uint8_t* buf; /* data buffer */
size_t buffersize; /* max buffer size */ size_t buf_size; /* max buffer size */
size_t validsize; /* current buffer size */ size_t valid_size; /* current buffer size */
size_t filesize; /* buffered file size */ size_t file_size; /* buffered file size */
} FOO_STREAMFILE; } FOO_STREAMFILE;
static STREAMFILE * open_foo_streamfile_buffer(const char * const filename, size_t buffersize, abort_callback * p_abort, t_filestats * stats); static STREAMFILE* open_foo_streamfile_buffer(const char* const filename, size_t buf_size, abort_callback* p_abort, t_filestats* stats);
static STREAMFILE * open_foo_streamfile_buffer_by_file(service_ptr_t<file> m_file, bool m_file_opened, const char * const filename, size_t buffersize, abort_callback * p_abort); static STREAMFILE* open_foo_streamfile_buffer_by_file(service_ptr_t<file> m_file, bool m_file_opened, const char* const filename, size_t buf_size, abort_callback* p_abort);
static size_t read_foo(FOO_STREAMFILE *streamfile, uint8_t * dest, offv_t offset, size_t length) { static size_t foo_read(FOO_STREAMFILE* sf, uint8_t* dst, offv_t offset, size_t length) {
size_t length_read_total = 0; size_t read_total = 0;
if (!streamfile || !streamfile->m_file_opened || !dest || length <= 0 || offset < 0) if (!sf || !sf->m_file_opened || !dst || length <= 0 || offset < 0)
return 0; return 0;
/* is the part of the requested length in the buffer? */ /* is the part of the requested length in the buffer? */
if (offset >= streamfile->buffer_offset && offset < streamfile->buffer_offset + streamfile->validsize) { if (offset >= sf->buf_offset && offset < sf->buf_offset + sf->valid_size) {
size_t length_to_read; size_t buf_limit;
int offset_into_buffer = (offset - streamfile->buffer_offset); int buf_into = (int)(offset - sf->buf_offset);
length_to_read = streamfile->validsize - offset_into_buffer; buf_limit = sf->valid_size - buf_into;
if (length_to_read > length) if (buf_limit > length)
length_to_read = length; buf_limit = length;
memcpy(dest, streamfile->buffer + offset_into_buffer, length_to_read); memcpy(dst, sf->buf + buf_into, buf_limit);
length_read_total += length_to_read; read_total += buf_limit;
length -= length_to_read; length -= buf_limit;
offset += length_to_read; offset += buf_limit;
dest += length_to_read; dst += buf_limit;
} }
/* read the rest of the requested length */ /* read the rest of the requested length */
while (length > 0) { while (length > 0) {
size_t length_to_read; size_t buf_limit;
/* ignore requests at EOF */ /* ignore requests at EOF */
if (offset >= streamfile->filesize) { if (offset >= sf->file_size) {
//offset = streamfile->filesize; /* seems fseek doesn't clamp offset */ //offset = sf->file_size; /* seems fseek doesn't clamp offset */
//VGM_ASSERT_ONCE(offset > streamfile->filesize, "STDIO: reading over filesize 0x%x @ 0x%lx + 0x%x\n", streamfile->filesize, offset, length); //VGM_ASSERT_ONCE(offset > sf->file_size, "STDIO: reading over file_size 0x%x @ 0x%lx + 0x%x\n", sf->file_size, offset, length);
break; break;
} }
/* position to new offset */ /* position to new offset */
try { try {
streamfile->m_file->seek(offset,*streamfile->p_abort); sf->m_file->seek(offset, *sf->p_abort);
} catch (...) { } catch (...) {
break; /* this shouldn't happen in our code */ break; /* this shouldn't happen in our code */
} }
/* fill the buffer (offset now is beyond buffer_offset) */ /* fill the buffer (offset now is beyond buf_offset) */
try { try {
streamfile->buffer_offset = offset; sf->buf_offset = offset;
streamfile->validsize = streamfile->m_file->read(streamfile->buffer,streamfile->buffersize,*streamfile->p_abort); sf->valid_size = sf->m_file->read(sf->buf, sf->buf_size, *sf->p_abort);
} catch(...) { } catch(...) {
break; /* improbable? */ break; /* improbable? */
} }
/* decide how much must be read this time */ /* decide how much must be read this time */
if (length > streamfile->buffersize) if (length > sf->buf_size)
length_to_read = streamfile->buffersize; buf_limit = sf->buf_size;
else else
length_to_read = length; buf_limit = length;
/* give up on partial reads (EOF) */ /* give up on partial reads (EOF) */
if (streamfile->validsize < length_to_read) { if (sf->valid_size < buf_limit) {
memcpy(dest,streamfile->buffer,streamfile->validsize); memcpy(dst, sf->buf, sf->valid_size);
offset += streamfile->validsize; offset += sf->valid_size;
length_read_total += streamfile->validsize; read_total += sf->valid_size;
break; break;
} }
/* use the new buffer */ /* use the new buffer */
memcpy(dest,streamfile->buffer,length_to_read); memcpy(dst, sf->buf, buf_limit);
offset += length_to_read; offset += buf_limit;
length_read_total += length_to_read; read_total += buf_limit;
length -= length_to_read; length -= buf_limit;
dest += length_to_read; dst += buf_limit;
} }
streamfile->offset = offset; /* last fread offset */ sf->offset = offset; /* last fread offset */
return length_read_total; return read_total;
} }
static size_t get_size_foo(FOO_STREAMFILE * streamfile) { static size_t foo_get_size(FOO_STREAMFILE* sf) {
return streamfile->filesize; return sf->file_size;
} }
static offv_t get_offset_foo(FOO_STREAMFILE *streamfile) { static offv_t foo_get_offset(FOO_STREAMFILE* sf) {
return streamfile->offset; return sf->offset;
} }
static void get_name_foo(FOO_STREAMFILE *streamfile,char *buffer,size_t length) { static void foo_get_name(FOO_STREAMFILE* sf, char* name, size_t name_size) {
/* Most crap only cares about the filename itself */ /* Most crap only cares about the filename itself */
size_t ourlen = strlen(streamfile->name); size_t ourlen = strlen(sf->name);
if (ourlen > length) { if (ourlen > name_size) {
if (length) strcpy(buffer, streamfile->name + ourlen - length + 1); if (name_size) strcpy(name, sf->name + ourlen - name_size + 1);
} else { }
strcpy(buffer, streamfile->name); else {
} strcpy(name, sf->name);
}
} }
static void close_foo(FOO_STREAMFILE * streamfile) { static void foo_close(FOO_STREAMFILE* sf) {
streamfile->m_file.release(); //release alloc'ed ptr sf->m_file.release(); //release alloc'ed ptr
free(streamfile->name); free(sf->name);
free(streamfile->buffer); free(sf->buf);
free(streamfile); free(sf);
} }
static STREAMFILE *open_foo(FOO_STREAMFILE *streamFile,const char * const filename,size_t buffersize) { static STREAMFILE* foo_open(FOO_STREAMFILE* sf, const char* const filename,size_t buf_size) {
service_ptr_t<file> m_file; service_ptr_t<file> m_file;
STREAMFILE *newstreamFile;
if (!filename) if (!filename)
return NULL; return NULL;
// if same name, duplicate the file pointer we already have open // if same name, duplicate the file pointer we already have open
if (streamFile->m_file_opened && !strcmp(streamFile->name,filename)) { if (sf->m_file_opened && !strcmp(sf->name,filename)) {
m_file = streamFile->m_file; //copy? m_file = sf->m_file; //copy?
{ {
newstreamFile = open_foo_streamfile_buffer_by_file(m_file, streamFile->m_file_opened, filename, buffersize, streamFile->p_abort); STREAMFILE* new_sf = open_foo_streamfile_buffer_by_file(m_file, sf->m_file_opened, filename, buf_size, sf->p_abort);
if (newstreamFile) { if (new_sf) {
return newstreamFile; return new_sf;
} }
// failure, close it and try the default path (which will probably fail a second time) // failure, close it and try the default path (which will probably fail a second time)
} }
} }
// a normal open, open a new file // a normal open, open a new file
return open_foo_streamfile_buffer(filename,buffersize,streamFile->p_abort,NULL); return open_foo_streamfile_buffer(filename,buf_size,sf->p_abort,NULL);
} }
static STREAMFILE * open_foo_streamfile_buffer_by_file(service_ptr_t<file> m_file, bool m_file_opened, const char * const filename, size_t buffersize, abort_callback * p_abort) { static STREAMFILE* open_foo_streamfile_buffer_by_file(service_ptr_t<file> m_file, bool m_file_opened, const char* const filename, size_t buf_size, abort_callback* p_abort) {
uint8_t * buffer; uint8_t* buf;
FOO_STREAMFILE * streamfile; FOO_STREAMFILE* this_sf;
buffer = (uint8_t *) calloc(buffersize,1); buf = (uint8_t*) calloc(buf_size, sizeof(uint8_t));
if (!buffer) goto fail; if (!buf) goto fail;
streamfile = (FOO_STREAMFILE *) calloc(1,sizeof(FOO_STREAMFILE)); this_sf = (FOO_STREAMFILE*) calloc(1, sizeof(FOO_STREAMFILE));
if (!streamfile) goto fail; if (!this_sf) goto fail;
streamfile->sf.read = (size_t (__cdecl *)(_STREAMFILE *,uint8_t *,offv_t,size_t)) read_foo; this_sf->vt.read = (size_t (__cdecl *)(_STREAMFILE*, uint8_t*, offv_t, size_t)) foo_read;
streamfile->sf.get_size = (size_t (__cdecl *)(_STREAMFILE *)) get_size_foo; this_sf->vt.get_size = (size_t (__cdecl *)(_STREAMFILE*)) foo_get_size;
streamfile->sf.get_offset = (offv_t (__cdecl *)(_STREAMFILE *)) get_offset_foo; this_sf->vt.get_offset = (offv_t (__cdecl *)(_STREAMFILE*)) foo_get_offset;
streamfile->sf.get_name = (void (__cdecl *)(_STREAMFILE *,char *,size_t)) get_name_foo; this_sf->vt.get_name = (void (__cdecl *)(_STREAMFILE*, char*, size_t)) foo_get_name;
streamfile->sf.open = (_STREAMFILE *(__cdecl *)(_STREAMFILE *,const char *const ,size_t)) open_foo; this_sf->vt.open = (_STREAMFILE* (__cdecl *)(_STREAMFILE* ,const char* const, size_t)) foo_open;
streamfile->sf.close = (void (__cdecl *)(_STREAMFILE *)) close_foo; this_sf->vt.close = (void (__cdecl *)(_STREAMFILE* )) foo_close;
streamfile->m_file_opened = m_file_opened; this_sf->m_file_opened = m_file_opened;
streamfile->m_file = m_file; this_sf->m_file = m_file;
streamfile->p_abort = p_abort; this_sf->p_abort = p_abort;
streamfile->buffersize = buffersize; this_sf->buf_size = buf_size;
streamfile->buffer = buffer; this_sf->buf = buf;
streamfile->name = strdup(filename); this_sf->name = strdup(filename);
if (!streamfile->name) goto fail; if (!this_sf->name) goto fail;
/* cache filesize */ /* cache file_size */
if (streamfile->m_file_opened) if (this_sf->m_file_opened)
streamfile->filesize = streamfile->m_file->get_size(*streamfile->p_abort); this_sf->file_size = this_sf->m_file->get_size(*this_sf->p_abort);
else else
streamfile->filesize = 0; this_sf->file_size = 0;
return &streamfile->sf; return &this_sf->vt;
fail: fail:
free(buffer); free(buf);
free(streamfile); free(this_sf);
return NULL; return NULL;
} }
static STREAMFILE* open_foo_streamfile_buffer(const char* const filename, size_t buffersize, abort_callback* p_abort, t_filestats* stats) { static STREAMFILE* open_foo_streamfile_buffer(const char* const filename, size_t buf_size, abort_callback* p_abort, t_filestats* stats) {
STREAMFILE* sf = NULL; STREAMFILE* sf = NULL;
service_ptr_t<file> infile; service_ptr_t<file> infile;
bool infile_exists; bool infile_exists;
@ -213,7 +213,7 @@ static STREAMFILE* open_foo_streamfile_buffer(const char* const filename, size_t
if(stats) *stats = infile->get_stats(*p_abort); if(stats) *stats = infile->get_stats(*p_abort);
} }
sf = open_foo_streamfile_buffer_by_file(infile, infile_exists, filename, buffersize, p_abort); sf = open_foo_streamfile_buffer_by_file(infile, infile_exists, filename, buf_size, p_abort);
if (!sf) { if (!sf) {
//m_file.release(); //refcounted and cleaned after it goes out of scope //m_file.release(); //refcounted and cleaned after it goes out of scope
} }

View File

@ -3,6 +3,10 @@
#define SAMPLE_BUFFER_SIZE 1024 #define SAMPLE_BUFFER_SIZE 1024
extern "C" {
#include "../src/vgmstream.h"
}
class input_vgmstream : public input_stubs { class input_vgmstream : public input_stubs {
public: public:
@ -69,18 +73,18 @@ class input_vgmstream : public input_stubs {
//bool exts_unknown_on; //bool exts_unknown_on;
/* helpers */ /* helpers */
VGMSTREAM * init_vgmstream_foo(t_uint32 p_subsong, const char * const filename, abort_callback & p_abort); VGMSTREAM* init_vgmstream_foo(t_uint32 p_subsong, const char* const filename, abort_callback& p_abort);
void setup_vgmstream(abort_callback & p_abort); void setup_vgmstream(abort_callback& p_abort);
void load_settings(); void load_settings();
void get_subsong_info(t_uint32 p_subsong, pfc::string_base & title, int *length_in_ms, int *total_samples, int *loop_flag, int *loop_start, int *loop_end, int *sample_rate, int *channels, int *bitrate, pfc::string_base & description, abort_callback & p_abort); void get_subsong_info(t_uint32 p_subsong, pfc::string_base& title, int* length_in_ms, int* total_samples, int* loop_flag, int *loop_start, int* loop_end, int* sample_rate, int* channels, int* bitrate, pfc::string_base& description, abort_callback& p_abort);
bool get_description_tag(pfc::string_base & temp, pfc::string_base const& description, const char *tag, char delimiter = '\n'); bool get_description_tag(pfc::string_base& temp, pfc::string_base const& description, const char* tag, char delimiter = '\n');
void apply_config(VGMSTREAM * vgmstream); void apply_config(VGMSTREAM* vgmstream);
static void g_load_cfg(int *accept_unknown, int *accept_common); static void g_load_cfg(int* accept_unknown, int* accept_common);
}; };
/* foo_streamfile.cpp */ /* foo_streamfile.cpp */
STREAMFILE * open_foo_streamfile(const char * const filename, abort_callback * p_abort, t_filestats * stats); STREAMFILE* open_foo_streamfile(const char* const filename, abort_callback* p_abort, t_filestats* stats);
#endif /*_FOO_VGMSTREAM_*/ #endif /*_FOO_VGMSTREAM_*/

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,7 @@
/* ************************************* */ /* ************************************* */
/* opens a utf16 (unicode) path */ /* opens a utf16 (unicode) path */
static FILE* wa_fopen(const in_char *wpath) { static FILE* wa_fopen(const in_char* wpath) {
#ifdef UNICODE_INPUT_PLUGIN #ifdef UNICODE_INPUT_PLUGIN
return _wfopen(wpath,L"rb"); return _wfopen(wpath,L"rb");
#else #else
@ -34,16 +34,16 @@ static FILE* wa_fdopen(int fd) {
/* a STREAMFILE that operates via STDIOSTREAMFILE but handles Winamp's unicode (in_char) paths */ /* a STREAMFILE that operates via STDIOSTREAMFILE but handles Winamp's unicode (in_char) paths */
typedef struct { typedef struct {
STREAMFILE sf; STREAMFILE vt;
STREAMFILE *stdiosf; STREAMFILE* stdiosf;
FILE *infile_ref; /* pointer to the infile in stdiosf (partially handled by stdiosf) */ FILE* infile_ref; /* pointer to the infile in stdiosf (partially handled by stdiosf) */
} WINAMP_STREAMFILE; } WINAMP_STREAMFILE;
static STREAMFILE *open_winamp_streamfile_by_file(FILE *infile, const char * path); static STREAMFILE* open_winamp_streamfile_by_file(FILE* infile, const char* path);
//static STREAMFILE *open_winamp_streamfile_by_ipath(const in_char *wpath); //static STREAMFILE* open_winamp_streamfile_by_ipath(const in_char* wpath);
static size_t wasf_read(WINAMP_STREAMFILE* sf, uint8_t* dest, offv_t offset, size_t length) { static size_t wasf_read(WINAMP_STREAMFILE* sf, uint8_t* dst, offv_t offset, size_t length) {
return sf->stdiosf->read(sf->stdiosf, dest, offset, length); return sf->stdiosf->read(sf->stdiosf, dst, offset, length);
} }
static size_t wasf_get_size(WINAMP_STREAMFILE* sf) { static size_t wasf_get_size(WINAMP_STREAMFILE* sf) {
@ -58,7 +58,7 @@ static void wasf_get_name(WINAMP_STREAMFILE* sf, char* buffer, size_t length) {
sf->stdiosf->get_name(sf->stdiosf, buffer, length); sf->stdiosf->get_name(sf->stdiosf, buffer, length);
} }
static STREAMFILE *wasf_open(WINAMP_STREAMFILE* sf, const char* const filename, size_t buffersize) { static STREAMFILE* wasf_open(WINAMP_STREAMFILE* sf, const char* const filename, size_t buffersize) {
in_char wpath[PATH_LIMIT]; in_char wpath[PATH_LIMIT];
if (!filename) if (!filename)
@ -77,7 +77,7 @@ static STREAMFILE *wasf_open(WINAMP_STREAMFILE* sf, const char* const filename,
FILE *new_file; FILE *new_file;
if (((new_fd = dup(fileno(sf->infile_ref))) >= 0) && (new_file = wa_fdopen(new_fd))) { if (((new_fd = dup(fileno(sf->infile_ref))) >= 0) && (new_file = wa_fdopen(new_fd))) {
STREAMFILE *new_sf = open_winamp_streamfile_by_file(new_file, filename); STREAMFILE* new_sf = open_winamp_streamfile_by_file(new_file, filename);
if (new_sf) if (new_sf)
return new_sf; return new_sf;
fclose(new_file); fclose(new_file);
@ -101,7 +101,7 @@ static void wasf_close(WINAMP_STREAMFILE* sf) {
free(sf); /* and the current struct */ free(sf); /* and the current struct */
} }
static STREAMFILE *open_winamp_streamfile_by_file(FILE* file, const char* path) { static STREAMFILE* open_winamp_streamfile_by_file(FILE* file, const char* path) {
WINAMP_STREAMFILE* this_sf = NULL; WINAMP_STREAMFILE* this_sf = NULL;
STREAMFILE* stdiosf = NULL; STREAMFILE* stdiosf = NULL;
@ -111,17 +111,17 @@ static STREAMFILE *open_winamp_streamfile_by_file(FILE* file, const char* path)
stdiosf = open_stdio_streamfile_by_file(file, path); stdiosf = open_stdio_streamfile_by_file(file, path);
if (!stdiosf) goto fail; if (!stdiosf) goto fail;
this_sf->sf.read = (void*)wasf_read; this_sf->vt.read = (void*)wasf_read;
this_sf->sf.get_size = (void*)wasf_get_size; this_sf->vt.get_size = (void*)wasf_get_size;
this_sf->sf.get_offset = (void*)wasf_get_offset; this_sf->vt.get_offset = (void*)wasf_get_offset;
this_sf->sf.get_name = (void*)wasf_get_name; this_sf->vt.get_name = (void*)wasf_get_name;
this_sf->sf.open = (void*)wasf_open; this_sf->vt.open = (void*)wasf_open;
this_sf->sf.close = (void*)wasf_close; this_sf->vt.close = (void*)wasf_close;
this_sf->stdiosf = stdiosf; this_sf->stdiosf = stdiosf;
this_sf->infile_ref = file; this_sf->infile_ref = file;
return &this_sf->sf; /* pointer to STREAMFILE start = rest of the custom data follows */ return &this_sf->vt;
fail: fail:
close_streamfile(stdiosf); close_streamfile(stdiosf);