[Scummvm-cvs-logs] scummvm master -> 6fb232b9ff72cccf15df5faf5e1191b50957fec2
DrMcCoy
drmccoy at drmccoy.de
Fri May 6 16:51:04 CEST 2011
This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
88d562a361 COMMON: Add a class SafeSubReadStream
f0087e4608 SWORD2: Replace SafeSubReadStream with the same-name class in Common
6fb232b9ff GOB: Create a SafeSubReadStream for files in STKs
Commit: 88d562a3615ad93af8dc2b0f40e28dc239108968
https://github.com/scummvm/scummvm/commit/88d562a3615ad93af8dc2b0f40e28dc239108968
Author: Sven Hesse (drmccoy at users.sourceforge.net)
Date: 2011-05-06T07:47:48-07:00
Commit Message:
COMMON: Add a class SafeSubReadStream
SafeSubReadStream is basically a SeekableSubReadStream that
re-seek()s the parent stream before each read(). That way, more than
one SafeSubReadStream of the same parent stream can be used safely
at the same time, at the cost of increasing IO.
Changed paths:
common/stream.cpp
common/substream.h
diff --git a/common/stream.cpp b/common/stream.cpp
index e870e68..a785ac5 100644
--- a/common/stream.cpp
+++ b/common/stream.cpp
@@ -242,6 +242,13 @@ bool SeekableSubReadStream::seek(int32 offset, int whence) {
return ret;
}
+uint32 SafeSubReadStream::read(void *dataPtr, uint32 dataSize) {
+ // Make sure the parent stream is at the right position
+ seek(0, SEEK_CUR);
+
+ return SeekableSubReadStream::read(dataPtr, dataSize);
+}
+
#pragma mark -
diff --git a/common/substream.h b/common/substream.h
index ecf11c5..8b83dbd 100644
--- a/common/substream.h
+++ b/common/substream.h
@@ -102,6 +102,25 @@ public:
}
};
+/**
+ * A seekable substream that removes the exclusivity demand required by the
+ * normal SeekableSubReadStream, at the cost of seek()ing the parent stream
+ * before each read().
+ *
+ * More than one SafeSubReadStream to the same parent stream can be used
+ * at the same time; they won't mess up each other. They will, however,
+ * reposition the parent stream, so don't depend on its position to be
+ * the same after a read() or seek() on one of its SafeSubReadStream.
+ */
+class SafeSubReadStream : public SeekableSubReadStream {
+public:
+ SafeSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO) :
+ SeekableSubReadStream(parentStream, begin, end, disposeParentStream) {
+ }
+
+ virtual uint32 read(void *dataPtr, uint32 dataSize);
+};
+
} // End of namespace Common
Commit: f0087e46087f4a278f8dc2aae8b31800d439f9df
https://github.com/scummvm/scummvm/commit/f0087e46087f4a278f8dc2aae8b31800d439f9df
Author: Sven Hesse (drmccoy at users.sourceforge.net)
Date: 2011-05-06T07:47:48-07:00
Commit Message:
SWORD2: Replace SafeSubReadStream with the same-name class in Common
Changed paths:
engines/sword2/music.cpp
diff --git a/engines/sword2/music.cpp b/engines/sword2/music.cpp
index 233d936..ae6e2f1 100644
--- a/engines/sword2/music.cpp
+++ b/engines/sword2/music.cpp
@@ -53,40 +53,6 @@
namespace Sword2 {
-/**
- * This class behaves like SeekableSubReadStream, except it remembers where the
- * previous read() or seek() took it, so that it can continue from that point
- * the next time. This is because we're frequently streaming two pieces of
- * music from the same file.
- */
-class SafeSubReadStream : public Common::SeekableSubReadStream {
-protected:
- uint32 _previousPos;
-public:
- SafeSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end);
- virtual uint32 read(void *dataPtr, uint32 dataSize);
- virtual bool seek(int32 offset, int whence = SEEK_SET);
-};
-
-SafeSubReadStream::SafeSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end)
- : SeekableSubReadStream(parentStream, begin, end, DisposeAfterUse::NO) {
- _previousPos = 0;
-}
-
-uint32 SafeSubReadStream::read(void *dataPtr, uint32 dataSize) {
- uint32 result;
- SeekableSubReadStream::seek(_previousPos);
- result = SeekableSubReadStream::read(dataPtr, dataSize);
- _previousPos = pos();
- return result;
-}
-
-bool SafeSubReadStream::seek(int32 offset, int whence) {
- bool result = SeekableSubReadStream::seek(offset, whence);
- _previousPos = pos();
- return result;
-}
-
static Audio::AudioStream *makeCLUStream(Common::File *fp, int size);
static Audio::AudioStream *makePSXCLUStream(Common::File *fp, int size);
@@ -197,19 +163,19 @@ static Audio::AudioStream *getAudioStream(SoundFileHandle *fh, const char *base,
return makeCLUStream(&fh->file, enc_len);
#ifdef USE_MAD
case kMP3Mode: {
- SafeSubReadStream *tmp = new SafeSubReadStream(&fh->file, pos, pos + enc_len);
+ Common::SafeSubReadStream *tmp = new Common::SafeSubReadStream(&fh->file, pos, pos + enc_len);
return Audio::makeMP3Stream(tmp, DisposeAfterUse::YES);
}
#endif
#ifdef USE_VORBIS
case kVorbisMode: {
- SafeSubReadStream *tmp = new SafeSubReadStream(&fh->file, pos, pos + enc_len);
+ Common::SafeSubReadStream *tmp = new Common::SafeSubReadStream(&fh->file, pos, pos + enc_len);
return Audio::makeVorbisStream(tmp, DisposeAfterUse::YES);
}
#endif
#ifdef USE_FLAC
case kFLACMode: {
- SafeSubReadStream *tmp = new SafeSubReadStream(&fh->file, pos, pos + enc_len);
+ Common::SafeSubReadStream *tmp = new Common::SafeSubReadStream(&fh->file, pos, pos + enc_len);
return Audio::makeFLACStream(tmp, DisposeAfterUse::YES);
}
#endif
Commit: 6fb232b9ff72cccf15df5faf5e1191b50957fec2
https://github.com/scummvm/scummvm/commit/6fb232b9ff72cccf15df5faf5e1191b50957fec2
Author: Sven Hesse (drmccoy at users.sourceforge.net)
Date: 2011-05-06T07:47:49-07:00
Commit Message:
GOB: Create a SafeSubReadStream for files in STKs
Instead of memcpy'ing them into a MemoryReadStream.
This is necessary for the lower end PSPs to run Urban Runner with
its comparably big VMD videos.
Changed paths:
engines/gob/dataio.cpp
diff --git a/engines/gob/dataio.cpp b/engines/gob/dataio.cpp
index 78fc0ab..aa2743b 100644
--- a/engines/gob/dataio.cpp
+++ b/engines/gob/dataio.cpp
@@ -26,6 +26,7 @@
#include "common/endian.h"
#include "common/types.h"
#include "common/memstream.h"
+#include "common/substream.h"
#include "gob/gob.h"
#include "gob/dataio.h"
@@ -345,9 +346,8 @@ Common::SeekableReadStream *DataIO::getFile(File &file) {
if (!file.archive->file.seek(file.offset))
return 0;
- Common::SeekableReadStream *rawData = file.archive->file.readStream(file.size);
- if (!rawData)
- return 0;
+ Common::SeekableReadStream *rawData =
+ new Common::SafeSubReadStream(&file.archive->file, file.offset, file.offset + file.size);
if (!file.packed)
return rawData;
More information about the Scummvm-git-logs
mailing list