New method for accessing files on Android

Hey everyone, I implemented a new way to access APK files on Android, as
originally suggested by Andre Heider here:
http://forums.libsdl.org/viewtopic.php?p=33542#33542

You can look at the changeset here:

It’s not extensive, and “it works for me” using SDL_image, SDL_mixer and
SDL_ttf but if this makes someone else’s stuff explode, please let me know.

As a crude performance measurement (which is not the only concern involved
in implementing this solution), these are timings for image opening
using SDL_GetPerformanceCounter

“Legacy method”

?/IGNIFUGA( 910): FILE: images/dp/dp_idle.png TIME: 471226
?/IGNIFUGA( 910): FILE: images/menu/UI1_gradient.png TIME: 624761
?/IGNIFUGA( 910): FILE: images/menu/UI1_Sol.png TIME: 12279
?/IGNIFUGA( 910): FILE: images/menu/UI1_Title.png TIME: 19719
?/IGNIFUGA( 910): FILE: images/menu/UI1_SubTitle.png TIME: 8642
?/IGNIFUGA( 910): FILE: images/ignifuga/igni_idle.png TIME: 24221
?/IGNIFUGA( 910): FILE: images/menu/UI1_Piso.png TIME: 119672
?/IGNIFUGA( 910): FILE: images/ignifuga/igni_jump.png TIME: 87527
?/IGNIFUGA( 910): FILE: images/ignifuga/igni_walk.png TIME: 47062

?/IGNIFUGA( 1007): FILE: images/dp/dp_idle.png TIME: 474488
?/IGNIFUGA( 1007): FILE: images/menu/UI1_gradient.png TIME: 628639
?/IGNIFUGA( 1007): FILE: images/menu/UI1_Sol.png TIME: 12617
?/IGNIFUGA( 1007): FILE: images/menu/UI1_Title.png TIME: 19974
?/IGNIFUGA( 1007): FILE: images/menu/UI1_SubTitle.png TIME: 8678
?/IGNIFUGA( 1007): FILE: images/ignifuga/igni_idle.png TIME: 24551
?/IGNIFUGA( 1007): FILE: images/menu/UI1_Piso.png TIME: 130952
?/IGNIFUGA( 1007): FILE: images/ignifuga/igni_jump.png TIME: 85255
?/IGNIFUGA( 1007): FILE: images/ignifuga/igni_walk.png TIME: 46925

“New method”

?/IGNIFUGA( 398): FILE: images/dp/dp_idle.png TIME: 463721
?/IGNIFUGA( 398): FILE: images/menu/UI1_gradient.png TIME: 626492
?/IGNIFUGA( 398): FILE: images/menu/UI1_Sol.png TIME: 9909
?/IGNIFUGA( 398): FILE: images/menu/UI1_Title.png TIME: 17475
?/IGNIFUGA( 398): FILE: images/menu/UI1_SubTitle.png TIME: 6394
?/IGNIFUGA( 398): FILE: images/ignifuga/igni_idle.png TIME: 21714
?/IGNIFUGA( 398): FILE: images/menu/UI1_Piso.png TIME: 116490
?/IGNIFUGA( 398): FILE: images/ignifuga/igni_jump.png TIME: 76464
?/IGNIFUGA( 398): FILE: images/ignifuga/igni_walk.png TIME: 44350

?/IGNIFUGA( 473): FILE: images/dp/dp_idle.png TIME: 465144
?/IGNIFUGA( 473): FILE: images/menu/UI1_gradient.png TIME: 624390
?/IGNIFUGA( 473): FILE: images/menu/UI1_Sol.png TIME: 9346
?/IGNIFUGA( 473): FILE: images/menu/UI1_Title.png TIME: 17405
?/IGNIFUGA( 473): FILE: images/menu/UI1_SubTitle.png TIME: 6062
?/IGNIFUGA( 473): FILE: images/ignifuga/igni_idle.png TIME: 21918
?/IGNIFUGA( 473): FILE: images/menu/UI1_Piso.png TIME: 116628
?/IGNIFUGA( 473): FILE: images/ignifuga/igni_jump.png TIME: 76212
?/IGNIFUGA( 473): FILE: images/ignifuga/igni_walk.png TIME: 45154

There’s no definitive conclusion on speed improvements, except on the
smaller files. Probably measuring the performance on libraries that do more
extensive seeking on files would yield more clear results.–
Gabriel.

Gabriel,

This makes my stuff explode! :slight_smile:

Loading a wav file thus:

Code:

    if ((Sounds[i] = Mix_LoadWAV(name)) == NULL)
    {
        velcro_log(VL_ERROR, "Unable to load WAV file %s: %s\n",
                   name, Mix_GetError());
        return -1;
    }

give this error:

Code:
01-11 22:42:51.052 16067 16093 D SDL : Falling back to legacy InputStream method for opening file
01-11 22:42:51.052 16067 16093 D SDL : Falling back to legacy InputStream method for opening file
01-11 22:42:51.177 16067 16093 E Gravity : Unable to load WAV file data/sounds/thrust.wav: Unrecognized sound file type

If I revert to rev ef2ef554b662 (the one before your delta), things work as expected.

Let me know if there’s anything you need to know.

Thanks,
Philip.

2013/1/11 pmacfarlane

**
Gabriel,

This makes my stuff explode! [image: Smile]

Loading a wav file thus:

Code:

    if ((Sounds[i] = Mix_LoadWAV(name)) == NULL)
    {
        velcro_log(VL_ERROR, "Unable to load WAV file %s: %s\n",
                   name, Mix_GetError());
        return -1;
    }

give this error:

Code:

01-11 22:42:51.052 16067 16093 D SDL : Falling back to legacy
InputStream method for opening file
01-11 22:42:51.052 16067 16093 D SDL : Falling back to legacy
InputStream method for opening file
01-11 22:42:51.177 16067 16093 E Gravity : Unable to load WAV file
data/sounds/thrust.wav: Unrecognized sound file type

If I revert to rev ef2ef554b662 (the one before your delta), things work
as expected.

Let me know if there’s anything you need to know.

Thanks,
Philip.

There’s an additional bug fix here:
http://hg.libsdl.org/SDL/rev/b3d3ef1e15b5 Are you using this revision or an
earlier one?–
Gabriel.

Hi Gabriel,

I hadn’t tried the latest bugfix, as it didn’t exist when I posted.

But I just tried it, and it seems to work well. .wav files are being loaded correctly now.

Thanks!
Philip.