Skip to content

Commit

Permalink
Use VFSFile member functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlindgren90 committed Sep 17, 2014
1 parent f91f908 commit ae0cdf6
Show file tree
Hide file tree
Showing 140 changed files with 576 additions and 690 deletions.
59 changes: 28 additions & 31 deletions src/aac-raw/aac.cc
Expand Up @@ -78,14 +78,14 @@ static int find_aac_header (unsigned char * data, int length, int * size)
return -1;
}

static bool parse_aac_stream (const char * filename, VFSFile * stream)
static bool parse_aac_stream (const char * filename, VFSFile & stream)
{
unsigned char data[8192];
int offset, found, inner, size;

size = 0; /* avoid bogus uninitialized variable warning */

if (vfs_fread (data, 1, sizeof data, stream) != sizeof data)
if (stream.fread (data, 1, sizeof data) != sizeof data)
{
PROBE_DEBUG ("Read failed.\n");
return false;
Expand Down Expand Up @@ -128,13 +128,13 @@ static int aac_probe (unsigned char * buf, int len)
/* Gets info (some approximated) from an AAC/ADTS file. <length> is
* milliseconds, <bitrate> is kilobits per second. Any parameters that cannot
* be read are set to -1. */
static void calc_aac_info (VFSFile * handle, int * length, int * bitrate,
static void calc_aac_info (VFSFile & handle, int * length, int * bitrate,
int * samplerate, int * channels)
{
NeAACDecHandle decoder;
NeAACDecFrameInfo frame;
bool initted = false;
int size = vfs_fsize (handle);
int size = handle.fsize ();
unsigned char buffer[BUFFER_SIZE];
int offset = 0, filled = 0;
int found, bytes_used = 0, time_used = 0;
Expand All @@ -147,7 +147,7 @@ static void calc_aac_info (VFSFile * handle, int * length, int * bitrate,
*channels = -1;

/* look for a representative bitrate in the middle of the file */
if (size > 0 && vfs_fseek (handle, size / 2, VFS_SEEK_SET))
if (size < 0 || handle.fseek (size / 2, VFS_SEEK_SET) < 0)
goto DONE;

for (found = 0; found < 32; found++)
Expand All @@ -157,7 +157,7 @@ static void calc_aac_info (VFSFile * handle, int * length, int * bitrate,
memmove (buffer, buffer + offset, filled);
offset = 0;

if (vfs_fread (buffer + filled, 1, BUFFER_SIZE - filled, handle)
if (handle.fread (buffer + filled, 1, BUFFER_SIZE - filled)
!= BUFFER_SIZE - filled)
{
PROBE_DEBUG ("Read failed.\n");
Expand Down Expand Up @@ -233,36 +233,32 @@ static void calc_aac_info (VFSFile * handle, int * length, int * bitrate,
NeAACDecClose (decoder);
}

static Tuple aac_get_tuple (const char * filename, VFSFile * handle)
static Tuple aac_get_tuple (const char * filename, VFSFile & handle)
{
Tuple tuple;
int length, bitrate, samplerate, channels;

tuple.set_filename (filename);
tuple.set_str (FIELD_CODEC, "MPEG-2/4 AAC");

if (!vfs_is_remote (filename))
{
calc_aac_info (handle, &length, &bitrate, &samplerate, &channels);

if (length > 0)
tuple.set_int (FIELD_LENGTH, length);
calc_aac_info (handle, &length, &bitrate, &samplerate, &channels);

if (bitrate > 0)
tuple.set_int (FIELD_BITRATE, bitrate);
}
if (length > 0)
tuple.set_int (FIELD_LENGTH, length);
if (bitrate > 0)
tuple.set_int (FIELD_BITRATE, bitrate);

tuple.fetch_stream_info (handle);

return tuple;
}

static void aac_seek (VFSFile * file, NeAACDecHandle dec, int time, int len,
static void aac_seek (VFSFile & file, NeAACDecHandle dec, int time, int len,
void * buf, int size, int * buflen)
{
/* == ESTIMATE BYTE OFFSET == */

int64_t total = vfs_fsize (file);
int64_t total = file.fsize ();
if (total < 0)
{
AUDERR ("File is not seekable.\n");
Expand All @@ -271,10 +267,10 @@ static void aac_seek (VFSFile * file, NeAACDecHandle dec, int time, int len,

/* == SEEK == */

if (vfs_fseek (file, total * time / len, VFS_SEEK_SET))
if (file.fseek (total * time / len, VFS_SEEK_SET))
return;

* buflen = vfs_fread (buf, 1, size, file);
* buflen = file.fread (buf, 1, size);

/* == FIND FRAME HEADER == */

Expand All @@ -291,7 +287,7 @@ static void aac_seek (VFSFile * file, NeAACDecHandle dec, int time, int len,
{
* buflen -= used;
memmove (buf, (char *) buf + used, * buflen);
* buflen += vfs_fread ((char *) buf + * buflen, 1, size - * buflen, file);
* buflen += file.fread ((char *) buf + * buflen, 1, size - * buflen);
}

/* == START DECODING == */
Expand All @@ -303,11 +299,11 @@ static void aac_seek (VFSFile * file, NeAACDecHandle dec, int time, int len,
{
* buflen -= used;
memmove (buf, (char *) buf + used, * buflen);
* buflen += vfs_fread ((char *) buf + * buflen, 1, size - * buflen, file);
* buflen += file.fread ((char *) buf + * buflen, 1, size - * buflen);
}
}

static bool my_decode_aac (const char * filename, VFSFile * file)
static bool my_decode_aac (const char * filename, VFSFile & file)
{
NeAACDecHandle decoder = 0;
NeAACDecConfigurationPtr decoder_config;
Expand Down Expand Up @@ -337,20 +333,21 @@ static bool my_decode_aac (const char * filename, VFSFile * file)

unsigned char buf[BUFFER_SIZE];
int buflen;
buflen = vfs_fread (buf, 1, sizeof buf, file);
buflen = file.fread (buf, 1, sizeof buf);

/* == SKIP ID3 TAG == */

if (buflen >= 10 && ! strncmp ((char *) buf, "ID3", 3))
{
if (vfs_fseek (file, 10 + (buf[6] << 21) + (buf[7] << 14) + (buf[8] <<
7) + buf[9], VFS_SEEK_SET))
int tagsize = 10 + (buf[6] << 21) + (buf[7] << 14) + (buf[8] << 7) + buf[9];

if (file.fseek (tagsize, VFS_SEEK_SET))
{
AUDERR ("Failed to seek past ID3v2 tag.\n");
goto ERR_CLOSE_DECODER;
}

buflen = vfs_fread (buf, 1, sizeof buf, file);
buflen = file.fread (buf, 1, sizeof buf);
}

/* == FIND FRAME HEADER == */
Expand All @@ -368,7 +365,7 @@ static bool my_decode_aac (const char * filename, VFSFile * file)
{
buflen -= used;
memmove (buf, buf + used, buflen);
buflen += vfs_fread (buf + buflen, 1, sizeof buf - buflen, file);
buflen += file.fread (buf + buflen, 1, sizeof buf - buflen);
}

/* == START DECODING == */
Expand All @@ -377,7 +374,7 @@ static bool my_decode_aac (const char * filename, VFSFile * file)
{
buflen -= used;
memmove (buf, buf + used, buflen);
buflen += vfs_fread (buf + buflen, 1, sizeof buf - buflen, file);
buflen += file.fread (buf + buflen, 1, sizeof buf - buflen);
}

/* == CHECK FOR METADATA == */
Expand Down Expand Up @@ -432,7 +429,7 @@ static bool my_decode_aac (const char * filename, VFSFile * file)
used = 1 + aac_probe (buf + 1, buflen - 1);
buflen -= used;
memmove (buf, buf + used, buflen);
buflen += vfs_fread (buf + buflen, 1, sizeof buf - buflen, file);
buflen += file.fread (buf + buflen, 1, sizeof buf - buflen);
}

continue;
Expand All @@ -442,7 +439,7 @@ static bool my_decode_aac (const char * filename, VFSFile * file)
{
buflen -= used;
memmove (buf, buf + used, buflen);
buflen += vfs_fread (buf + buflen, 1, sizeof buf - buflen, file);
buflen += file.fread (buf + buflen, 1, sizeof buf - buflen);
}

/* == PLAY THE SOUND == */
Expand Down
12 changes: 6 additions & 6 deletions src/adplug/adplug-xmms.cc
Expand Up @@ -102,14 +102,14 @@ dbg_printf (const char *fmt, ...)
#endif

static CPlayer *
factory (VFSFile * fd, Copl * newopl)
factory (VFSFile & fd, Copl * newopl)
{
return CAdPlug::factory (fd, newopl, conf.players);
}

/***** Main player (!! threaded !!) *****/

Tuple adplug_get_tuple (const char * filename, VFSFile * fd)
Tuple adplug_get_tuple (const char * filename, VFSFile & fd)
{
Tuple tuple;
CSilentopl tmpopl;
Expand Down Expand Up @@ -143,7 +143,7 @@ Tuple adplug_get_tuple (const char * filename, VFSFile * fd)
// Define sampsize macro (only usable inside play_loop()!)
#define sampsize ((bit16 ? 2 : 1) * (stereo ? 2 : 1))

static bool play_loop (const char * filename, VFSFile * fd)
static bool play_loop (const char * filename, VFSFile & fd)
/* Main playback thread. Takes the filename to play as argument. */
{
dbg_printf ("play_loop(\"%s\"): ", filename);
Expand Down Expand Up @@ -249,7 +249,7 @@ static bool play_loop (const char * filename, VFSFile * fd)
/***** Informational *****/

bool
adplug_is_our_fd (const char * filename, VFSFile * fd)
adplug_is_our_fd (const char * filename, VFSFile & fd)
{
CSilentopl tmpopl;

Expand All @@ -271,7 +271,7 @@ adplug_is_our_fd (const char * filename, VFSFile * fd)
/***** Player control *****/

bool
adplug_play (const char * filename, VFSFile * file)
adplug_play (const char * filename, VFSFile & file)
{
dbg_printf ("adplug_play(\"%s\"): ", filename);
audio_error = false;
Expand Down Expand Up @@ -335,7 +335,7 @@ bool adplug_init (void)
std::string userdb;
userdb = std::string ("file://") + homedir + "/" ADPLUG_CONFDIR "/" + ADPLUGDB_FILE;

if (vfs_file_test (userdb.c_str (), VFS_EXISTS))
if (VFSFile::test_file (userdb.c_str (), VFS_EXISTS))
{
plr.db->load (userdb); // load user's database
dbg_printf (" (userdb=\"%s\")", userdb.c_str());
Expand Down
6 changes: 3 additions & 3 deletions src/adplug/adplug-xmms.h
Expand Up @@ -26,9 +26,9 @@ bool adplug_init (void);
void adplug_quit (void);
void adplug_about (void);
void adplug_config (void);
bool adplug_play (const char * filename, VFSFile * file);
bool adplug_play (const char * filename, VFSFile & file);
void adplug_info_box (const char * filename);
Tuple adplug_get_tuple (const char * filename, VFSFile * file);
bool adplug_is_our_fd (const char * filename, VFSFile * file);
Tuple adplug_get_tuple (const char * filename, VFSFile & file);
bool adplug_is_our_fd (const char * filename, VFSFile & file);

#endif
2 changes: 1 addition & 1 deletion src/adplug/core/a2m.cc
Expand Up @@ -64,7 +64,7 @@ Ca2mLoader::factory (Copl * newopl)
}

bool
Ca2mLoader::load (VFSFile * fd, const CFileProvider & fp)
Ca2mLoader::load (VFSFile & fd, const CFileProvider & fp)
{
binistream *f = fp.open (fd);
if (!f)
Expand Down
3 changes: 1 addition & 2 deletions src/adplug/core/a2m.h
Expand Up @@ -33,7 +33,7 @@ class Ca2mLoader: public CmodPlayer
: CmodPlayer(newopl)
{ };

bool load(VFSFile *fd, const CFileProvider &fp);
bool load(VFSFile &fd, const CFileProvider &fp);
float getrefresh();

std::string gettype()
Expand Down Expand Up @@ -82,4 +82,3 @@ class Ca2mLoader: public CmodPlayer
unsigned char *obuf, *buf;
};
#endif

4 changes: 2 additions & 2 deletions src/adplug/core/adl.cc
Expand Up @@ -2748,10 +2748,10 @@ CadlPlayer::play (uint8_t track)
// }

bool
CadlPlayer::load (VFSFile * fd, const CFileProvider & fp)
CadlPlayer::load (VFSFile & fd, const CFileProvider & fp)
{
binistream *f = fp.open (fd);
std::string filename (vfs_get_filename (fd));
std::string filename (fd.filename ());

// file validation section
if (!f || !fp.extension (filename, ".adl"))
Expand Down
2 changes: 1 addition & 1 deletion src/adplug/core/adl.h
Expand Up @@ -36,7 +36,7 @@ class CadlPlayer: public CPlayer
CadlPlayer(Copl *newopl);
~CadlPlayer();

bool load(VFSFile *fd, const CFileProvider &fp);
bool load(VFSFile &fd, const CFileProvider &fp);
bool update();
void rewind(int subsong = -1);

Expand Down
6 changes: 3 additions & 3 deletions src/adplug/core/adplug.cc
Expand Up @@ -189,7 +189,7 @@ CAdPlugDatabase *
CAdPlug::database = 0;

CPlayer *
CAdPlug::factory (VFSFile * fd, Copl * opl, const CPlayers & pl,
CAdPlug::factory (VFSFile & fd, Copl * opl, const CPlayers & pl,
const CFileProvider & fp)
{
CPlayer *p;
Expand All @@ -201,7 +201,7 @@ CAdPlug::factory (VFSFile * fd, Copl * opl, const CPlayers & pl,
{
for (j = 0; (*i)->get_extension (j); j++)
{
if (fp.extension (vfs_get_filename (fd), (*i)->get_extension (j)))
if (fp.extension (fd.filename (), (*i)->get_extension (j)))
{
AdPlug_LogWrite ("Trying direct hit: %s\n", (*i)->filetype.c_str ());

Expand All @@ -216,7 +216,7 @@ CAdPlug::factory (VFSFile * fd, Copl * opl, const CPlayers & pl,

delete p;

if (vfs_fseek (fd, 0, VFS_SEEK_SET) < 0)
if (fd.fseek (0, VFS_SEEK_SET) < 0)
return 0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/adplug/core/adplug.h
Expand Up @@ -37,7 +37,7 @@ class CAdPlug
public:
static const CPlayers& getPlayers();

static CPlayer *factory(VFSFile *fd, Copl *opl,
static CPlayer *factory(VFSFile &fd, Copl *opl,
const CPlayers &pl = getPlayers(),
const CFileProvider &fp = CProvider_Filesystem());

Expand Down
7 changes: 3 additions & 4 deletions src/adplug/core/adtrack.cc
Expand Up @@ -44,7 +44,7 @@ CadtrackLoader::factory (Copl * newopl)
}

bool
CadtrackLoader::load (VFSFile * fd, const CFileProvider & fp)
CadtrackLoader::load (VFSFile & fd, const CFileProvider & fp)
{
binistream *f = fp.open (fd);
if (!f)
Expand All @@ -55,7 +55,7 @@ CadtrackLoader::load (VFSFile * fd, const CFileProvider & fp)
unsigned char chp, octave, pnote = 0;
int i, j;
AdTrackInst myinst;
std::string filename (vfs_get_filename (fd));
std::string filename (fd.filename ());

// file validation
if (!fp.extension (filename, ".sng") || fp.filesize (f) != 36000)
Expand All @@ -70,12 +70,11 @@ CadtrackLoader::load (VFSFile * fd, const CFileProvider & fp)
AdPlug_LogWrite ("CadtrackLoader::load(,\"%s\"): Checking for \"%s\"...\n",
filename.c_str (), instfilename.c_str ());

VFSFile *instfd = vfs_fopen (instfilename.c_str (), "rb");
VFSFile instfd (instfilename.c_str (), "rb");
instf = fp.open (instfd);
if (!instf || fp.filesize (instf) != 468)
{
fp.close (f);
vfs_fclose (instfd);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/adplug/core/adtrack.h
Expand Up @@ -30,7 +30,7 @@ class CadtrackLoader: public CmodPlayer
: CmodPlayer(newopl)
{ };

bool load(VFSFile *fd, const CFileProvider &fp);
bool load(VFSFile &fd, const CFileProvider &fp);
float getrefresh();

std::string gettype()
Expand Down
2 changes: 1 addition & 1 deletion src/adplug/core/amd.cc
Expand Up @@ -31,7 +31,7 @@ CamdLoader::factory (Copl * newopl)
}

bool
CamdLoader::load (VFSFile * fd, const CFileProvider & fp)
CamdLoader::load (VFSFile & fd, const CFileProvider & fp)
{
binistream *f = fp.open (fd);
if (!f)
Expand Down
2 changes: 1 addition & 1 deletion src/adplug/core/amd.h
Expand Up @@ -30,7 +30,7 @@ class CamdLoader: public CmodPlayer
: CmodPlayer(newopl)
{ };

bool load(VFSFile *fd, const CFileProvider &fp);
bool load(VFSFile &fd, const CFileProvider &fp);
float getrefresh();

std::string gettype()
Expand Down

0 comments on commit ae0cdf6

Please sign in to comment.