Understanding how SDL_RWops work on SDL1.3 in Android

Hi,

For my app I’m trying to implement file system calls through SDL1.3’s SDL_RWops to support reading assets from APKs in Android. As I’m having some problems, I’m trying to understand how they work and have run into something I’m not sure about (I’ve never coded in java).

Reading from src/core/android/SDL_android.cpp I understand that the code is using the first version of InputStream (method?) as defined in the android docs at:
http://developer.android.com/reference/android/content/res/AssetManager.html#pubmethods

And later on SDL_android.cpp in the Android_JNI_FileSeek function, comments and the code suggest that SDL cannot seek backwards.

Isn’t it possible to make SDL_RWops implement the second call to InputStream, which allows specifying accesMode as ACCESS_RANDOM and which claims to be able to seek forward and backwards?. That way the seeking could be done just like with stdio.

As I said, it’s only a doubt. I might just not be getting how this part of the code works…
Thanks for your time :slight_smile:

A SDL_RWops is just an abstract stream interface.? You can wrap it around anything that implements basic stream functionality and it will work the way the underlying stream works.________________________________
From: joseba.gar@gmail.com (josebagar)
Subject: [SDL] Understanding how SDL_RWops work on SDL1.3 in Android

Hi,

For my app I’m trying to implement file system calls through SDL1.3’s SDL_RWops to support reading assets from APKs in Android. As I’m having some problems, I’m trying to understand how they work and have run into something I’m not sure about (I’ve never coded in java).

Reading from src/core/android/SDL_android.cpp I understand that the code is using the first version of InputStream (method?) as defined in the android docs at:
http://developer.android.com/reference/android/content/res/AssetManager.html#pubmethods

And later on SDL_android.cpp in the Android_JNI_FileSeek function, comments and the code suggest that SDL cannot seek backwards.

Isn’t it possible to make SDL_RWops implement the second call to InputStream, which allows specifying accesMode as ACCESS_RANDOM and which claims to be able to seek forward and backwards?. That way the seeking could be done just like with stdio.

As I said, it’s only a doubt. I might just not be getting how this part of the code works…
Thanks for your time


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

A SDL_RWops is just an abstract stream interface. You can wrap it around
anything that implements basic stream functionality and it will work the
way the underlying stream works.

That’s not what he was asking.

Tim Angus: is there any reason we can’t just switch the Android RWOPS to
random-access mode? I don’t know if there’s any limitation to prevent that.

–ryan.

On Dom 18 Sep 2011 11:51:20 josebagar escribi?:

And later on SDL_android.cpp in the Android_JNI_FileSeek function, comments
and the code suggest that SDL cannot seek backwards.

The code does seek forward and backwards at least in principle (I’ve worked
with SDL in Android but I’m using the RWOPS via SDL_image so I’m not sure what
goes on behind the curtains). What the comments in the code explain is that
for seeking backwards, what it does is reopen the file and seek forward to the
beginning, which, as you mentioned, could be avoided if the file is opened in
ACCESS_RANDOM mode.
Also, make sure that you are working with an updated hg copy of SDL as there’s
been some fixes introduced to that code to fix some resource handling issues
which you may run into if you open a few files from native code.

Gabriel.

I don’t believe that would help anything. Depsite the documentation
claiming “ACCESS_RANDOM Mode for open(String, int): Read
chunks, and seek forward and backward.”, said method returns an
InputStream [1]. The problem with this is that an InputStream provides
no interface to seek randomly, only to skip forward.

Unless we are expected to upcast the InputStream to something else that
does provide a seeking interface, I can’t see how random seeking is
possible. That would of course be a spectaculary poor API design, so I
don’t think this is the case. Most likely the ACCESS_ constants simply
aren’t hooked up to anything or are intended as a hinting mechanism to
choose an appropriate internal read method. FWIW a lot of the Android
API seems a bit rough and hastily put together. The documentation
should be viewed with suspicion too. For example, the
AssetInputStream::available documentation is flat out wrong compared to
how it behaves and how Android example code uses and comments it.

Anyway, I am of course open to suggestions if there is a way to seek
properly, but a quick google indicates there isn’t. This is all rather
academic anyway, as seeking via the SDL interface is of course possible,
it’s just that I’ve implmented seeking backwards as reopening the file
and seeking forwards. Obviously this is going to be dog slow, but as
far as I can tell it’s the only option available under the
circumstances.

HTH.

[1]
http://developer.android.com/reference/android/content/res/AssetManager.html#open(java.lang.String,%20int)
[2]
http://developer.android.com/reference/java/io/InputStream.html#skip(long)On Mon, 19 Sep 2011 16:22:31 -0400 Ryan wrote:

Tim Angus: is there any reason we can’t just switch the Android RWOPS
to random-access mode? I don’t know if there’s any limitation to
prevent that.

iThank you all for your input. I think I now understand better how SDL_RWops work and I got a few ideas about what might be failing.
Again, thanks for your time and thanks for your work in SDL.