[SDL] SMPEG: playing back MPG in pak-like container

Ryan C. Gordon icculus at clutteredmind.org
Mon Jun 27 10:23:29 PDT 2005


> sounds good. are there any tutorials on coding with SDLRWOPs?

With rwops, you basically fill in four functions: seek, close, read, and
write for your archive type (and write can just fail if this is
read-only...seek may not be used by smpeg, either), and then smpeg will
do all its i/o through those functions, which means you can make a
single file in an archive visible to the library.


Here's how PhysicsFS (a generic archive processing library) does it:
  http://svn.icculus.org/physfs/trunk/extras/physfsrwops.c?view=auto

create_rwops() sets up the structure with the function pointers; the
return value from that would be what you give to SMPEG_new_rwops(). The
other functions (physfsrwops_close(), physfsrwops_read(), etc) are the
functions that make up the rwops structure. Obviously, "PHYSFS_File"
would be a pointer to whatever data your specific archive code needs.


zziplib (another library like PhysicsFS) did something almost identical:
   http://zziplib.sourceforge.net/SDL_rwops_zzip.c

Overall, it's really just a little bit of glue code. Internally, SMPEG
uses rwops for all cases...if you give it a filename, it'll create a
rwops that uses fread(), fclose(), etc, so you're not really even
looking at a wildly different codepath through the library when you're done.

Good luck,
--ryan.





More information about the SDL mailing list