1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-14 00:14:18 +00:00
This commit is contained in:
jules 2008-07-28 14:46:09 +00:00
parent e0588e14b2
commit 6b6bcdb2a0
6 changed files with 197 additions and 152 deletions

View file

@ -7151,7 +7151,7 @@ void BufferedInputStream::ensureBuffered()
int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
{
if (position >= bufferStart
&& position + maxBytesToRead < lastReadPos)
&& position + maxBytesToRead <= lastReadPos)
{
memcpy (destBuffer, buffer + (position - bufferStart), maxBytesToRead);
position += maxBytesToRead;
@ -7160,21 +7160,28 @@ int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
}
else
{
if (position < bufferStart || position >= lastReadPos)
ensureBuffered();
int bytesRead = 0;
while (maxBytesToRead > 0)
{
const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
if (bytesAvailable > 0)
{
memcpy (destBuffer, buffer + (position - bufferStart), bytesAvailable);
maxBytesToRead -= bytesAvailable;
bytesRead += bytesAvailable;
position += bytesAvailable;
destBuffer = (void*) (((char*) destBuffer) + bytesAvailable);
}
ensureBuffered();
if (isExhausted())
break;
const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
memcpy (destBuffer, buffer + (position - bufferStart), bytesAvailable);
maxBytesToRead -= bytesAvailable;
bytesRead += bytesAvailable;
position += bytesAvailable;
destBuffer = (void*) (((char*) destBuffer) + bytesAvailable);
}
return bytesRead;
@ -7919,52 +7926,56 @@ void ZipFile::init()
{
numEntries = 0;
int pos = findEndOfZipEntryTable (in);
const int size = (int) (in->getTotalLength() - pos);
in->setPosition (pos);
MemoryBlock headerData;
if (in->readIntoMemoryBlock (headerData, size) == size)
if (pos >= 0 && pos < in->getTotalLength())
{
pos = 0;
const int size = (int) (in->getTotalLength() - pos);
for (int i = 0; i < numEntries; ++i)
in->setPosition (pos);
MemoryBlock headerData;
if (in->readIntoMemoryBlock (headerData, size) == size)
{
if (pos + 46 > size)
break;
pos = 0;
const char* const buffer = ((const char*) headerData.getData()) + pos;
for (int i = 0; i < numEntries; ++i)
{
if (pos + 46 > size)
break;
const int fileNameLen = littleEndianShort (buffer + 28);
const char* const buffer = ((const char*) headerData.getData()) + pos;
if (pos + 46 + fileNameLen > size)
break;
const int fileNameLen = littleEndianShort (buffer + 28);
ZipEntryInfo* const zei = new ZipEntryInfo();
zei->entry.filename = String (buffer + 46, fileNameLen);
if (pos + 46 + fileNameLen > size)
break;
const int time = littleEndianShort (buffer + 12);
const int date = littleEndianShort (buffer + 14);
ZipEntryInfo* const zei = new ZipEntryInfo();
zei->entry.filename = String (buffer + 46, fileNameLen);
const int year = 1980 + (date >> 9);
const int month = ((date >> 5) & 15) - 1;
const int day = date & 31;
const int hours = time >> 11;
const int minutes = (time >> 5) & 63;
const int seconds = (time & 31) << 1;
const int time = littleEndianShort (buffer + 12);
const int date = littleEndianShort (buffer + 14);
zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
const int year = 1980 + (date >> 9);
const int month = ((date >> 5) & 15) - 1;
const int day = date & 31;
const int hours = time >> 11;
const int minutes = (time >> 5) & 63;
const int seconds = (time & 31) << 1;
zei->compressed = littleEndianShort (buffer + 10) != 0;
zei->compressedSize = littleEndianInt (buffer + 20);
zei->entry.uncompressedSize = littleEndianInt (buffer + 24);
zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
zei->streamOffset = littleEndianInt (buffer + 42);
entries.add (zei);
zei->compressed = littleEndianShort (buffer + 10) != 0;
zei->compressedSize = littleEndianInt (buffer + 20);
zei->entry.uncompressedSize = littleEndianInt (buffer + 24);
pos += 46 + fileNameLen
+ littleEndianShort (buffer + 30)
+ littleEndianShort (buffer + 32);
zei->streamOffset = littleEndianInt (buffer + 42);
entries.add (zei);
pos += 46 + fileNameLen
+ littleEndianShort (buffer + 30)
+ littleEndianShort (buffer + 32);
}
}
}
@ -7979,11 +7990,12 @@ int ZipFile::findEndOfZipEntryTable (InputStream* input)
in.setPosition (in.getTotalLength());
int64 pos = in.getPosition();
const int64 lowestPos = jmax ((int64) 0, pos - 1024);
char buffer [32];
zeromem (buffer, sizeof (buffer));
while (pos > 0)
while (pos > lowestPos)
{
in.setPosition (pos - 22);
pos = in.getPosition();
@ -97991,7 +98003,6 @@ public:
}
bool needsInput() const throw() { return dataSize <= 0; }
int getTotalOut() const throw() { return (stream != 0) ? stream->total_out : 0; }
void setInput (uint8* const data_, const int size) throw()
{
@ -98050,7 +98061,8 @@ GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sou
noWrap (noWrap_),
isEof (false),
activeBufferSize (0),
originalSourcePos (sourceStream_->getPosition())
originalSourcePos (sourceStream_->getPosition()),
currentPos (0)
{
buffer = (uint8*) juce_malloc (gzipDecompBufferSize);
helper = new GZIPDecompressHelper (noWrap_);
@ -98088,6 +98100,7 @@ int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
while (! h->error)
{
const int n = h->doNextBlock (d, howMany);
currentPos += n;
if (n == 0)
{
@ -98137,15 +98150,11 @@ bool GZIPDecompressorInputStream::isExhausted()
int64 GZIPDecompressorInputStream::getPosition()
{
const GZIPDecompressHelper* const h = (GZIPDecompressHelper*) helper;
return h->getTotalOut() + activeBufferSize;
return currentPos;
}
bool GZIPDecompressorInputStream::setPosition (int64 newPos)
{
const int64 currentPos = getPosition();
if (newPos != currentPos)
{
// reset the stream and start again..
@ -98154,6 +98163,7 @@ bool GZIPDecompressorInputStream::setPosition (int64 newPos)
isEof = false;
activeBufferSize = 0;
currentPos = 0;
helper = new GZIPDecompressHelper (noWrap);
sourceStream->setPosition (originalSourcePos);
@ -179949,7 +179959,7 @@ public:
OggReader (InputStream* const inp)
: AudioFormatReader (inp, oggFormatName),
reservoir (2, 2048),
reservoir (2, 4096),
reservoirStart (0),
samplesInReservoir (0)
{
@ -179985,58 +179995,73 @@ public:
int64 startSampleInFile,
int numSamples)
{
if (startSampleInFile < reservoirStart
|| startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
int writeOffset = 0;
while (numSamples > 0)
{
// buffer miss, so refill the reservoir
int bitStream = 0;
const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
reservoirStart = (int) jmax ((int64) 0, startSampleInFile - 32);
samplesInReservoir = jmax (numSamples + 32, reservoir.getNumSamples());
reservoir.setSize (numChannels, samplesInReservoir, false, false, true);
if (reservoirStart != (int) ov_pcm_tell (&ovFile))
ov_pcm_seek (&ovFile, reservoirStart);
int offset = 0;
int numToRead = samplesInReservoir;
while (numToRead > 0)
if (startSampleInFile >= reservoirStart && numAvailable > 0)
{
float** dataIn = 0;
// got a few samples overlapping, so use them before seeking..
const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
if (samps == 0)
break;
jassert (samps <= numToRead);
for (int i = jmin (numChannels, reservoir.getNumChannels()); --i >= 0;)
for (unsigned int i = 0; i < numChannels; ++i)
{
memcpy (reservoir.getSampleData (i, offset),
dataIn[i],
sizeof (float) * samps);
if (destSamples[i] == 0)
break;
memcpy (destSamples[i] + writeOffset,
reservoir.getSampleData (jmin (i, reservoir.getNumChannels()),
(int) (startSampleInFile - reservoirStart)),
sizeof (float) * numSamples);
}
numToRead -= samps;
offset += samps;
startSampleInFile += numAvailable;
numSamples -= numAvailable;
writeOffset += numAvailable;
if (numSamples == 0)
break;
}
if (numToRead > 0)
reservoir.clear (offset, numToRead);
}
if (numSamples > 0)
{
for (unsigned int i = 0; i < numChannels; ++i)
if (startSampleInFile < reservoirStart
|| startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
{
if (destSamples[i] == 0)
break;
// buffer miss, so refill the reservoir
int bitStream = 0;
memcpy (destSamples[i],
reservoir.getSampleData (jmin (i, reservoir.getNumChannels()),
(int) (startSampleInFile - reservoirStart)),
sizeof (float) * numSamples);
reservoirStart = jmax (0, (int) startSampleInFile);
samplesInReservoir = reservoir.getNumSamples();
if (reservoirStart != (int) ov_pcm_tell (&ovFile))
ov_pcm_seek (&ovFile, reservoirStart);
int offset = 0;
int numToRead = samplesInReservoir;
while (numToRead > 0)
{
float** dataIn = 0;
const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
if (samps == 0)
break;
jassert (samps <= numToRead);
for (int i = jmin (numChannels, reservoir.getNumChannels()); --i >= 0;)
{
memcpy (reservoir.getSampleData (i, offset),
dataIn[i],
sizeof (float) * samps);
}
numToRead -= samps;
offset += samps;
}
if (numToRead > 0)
reservoir.clear (offset, numToRead);
}
}
@ -244888,7 +244913,7 @@ public:
location = T("http://") + location;
if (levelsOfRedirection++ < 3)
return open (location, headers, postData, isPost, callback, callbackContext);
return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
}
else
{
@ -253426,7 +253451,7 @@ public:
location = T("http://") + location;
if (levelsOfRedirection++ < 3)
return open (location, headers, postData, isPost, callback, callbackContext);
return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
}
else
{

View file

@ -12614,7 +12614,7 @@ private:
const bool deleteSourceWhenDestroyed, noWrap;
bool isEof;
int activeBufferSize;
int64 originalSourcePos;
int64 originalSourcePos, currentPos;
uint8* buffer;
void* helper;
@ -19548,7 +19548,7 @@ public:
int sourceClipWidth,
int sourceClipHeight,
const AffineTransform& transform,
const bool fillAlphaChannelWithCurrentBrush) const throw();
const bool fillAlphaChannelWithCurrentBrush = false) const throw();
/** Draws an image to fit within a designated rectangle.
@ -19577,7 +19577,7 @@ public:
const int destWidth,
const int destHeight,
const RectanglePlacement& placementWithinTarget,
const bool fillAlphaChannelWithCurrentBrush) const throw();
const bool fillAlphaChannelWithCurrentBrush = false) const throw();
/** Returns the position of the bounding box for the current clipping region.

View file

@ -98,7 +98,7 @@ public:
//==============================================================================
OggReader (InputStream* const inp)
: AudioFormatReader (inp, oggFormatName),
reservoir (2, 2048),
reservoir (2, 4096),
reservoirStart (0),
samplesInReservoir (0)
{
@ -135,58 +135,73 @@ public:
int64 startSampleInFile,
int numSamples)
{
if (startSampleInFile < reservoirStart
|| startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
int writeOffset = 0;
while (numSamples > 0)
{
// buffer miss, so refill the reservoir
int bitStream = 0;
const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
reservoirStart = (int) jmax ((int64) 0, startSampleInFile - 32);
samplesInReservoir = jmax (numSamples + 32, reservoir.getNumSamples());
reservoir.setSize (numChannels, samplesInReservoir, false, false, true);
if (reservoirStart != (int) ov_pcm_tell (&ovFile))
ov_pcm_seek (&ovFile, reservoirStart);
int offset = 0;
int numToRead = samplesInReservoir;
while (numToRead > 0)
if (startSampleInFile >= reservoirStart && numAvailable > 0)
{
float** dataIn = 0;
// got a few samples overlapping, so use them before seeking..
const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
if (samps == 0)
break;
jassert (samps <= numToRead);
for (int i = jmin (numChannels, reservoir.getNumChannels()); --i >= 0;)
for (unsigned int i = 0; i < numChannels; ++i)
{
memcpy (reservoir.getSampleData (i, offset),
dataIn[i],
sizeof (float) * samps);
if (destSamples[i] == 0)
break;
memcpy (destSamples[i] + writeOffset,
reservoir.getSampleData (jmin (i, reservoir.getNumChannels()),
(int) (startSampleInFile - reservoirStart)),
sizeof (float) * numSamples);
}
numToRead -= samps;
offset += samps;
startSampleInFile += numAvailable;
numSamples -= numAvailable;
writeOffset += numAvailable;
if (numSamples == 0)
break;
}
if (numToRead > 0)
reservoir.clear (offset, numToRead);
}
if (numSamples > 0)
{
for (unsigned int i = 0; i < numChannels; ++i)
if (startSampleInFile < reservoirStart
|| startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
{
if (destSamples[i] == 0)
break;
// buffer miss, so refill the reservoir
int bitStream = 0;
memcpy (destSamples[i],
reservoir.getSampleData (jmin (i, reservoir.getNumChannels()),
(int) (startSampleInFile - reservoirStart)),
sizeof (float) * numSamples);
reservoirStart = jmax (0, (int) startSampleInFile);
samplesInReservoir = reservoir.getNumSamples();
if (reservoirStart != (int) ov_pcm_tell (&ovFile))
ov_pcm_seek (&ovFile, reservoirStart);
int offset = 0;
int numToRead = samplesInReservoir;
while (numToRead > 0)
{
float** dataIn = 0;
const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
if (samps == 0)
break;
jassert (samps <= numToRead);
for (int i = jmin (numChannels, reservoir.getNumChannels()); --i >= 0;)
{
memcpy (reservoir.getSampleData (i, offset),
dataIn[i],
sizeof (float) * samps);
}
numToRead -= samps;
offset += samps;
}
if (numToRead > 0)
reservoir.clear (offset, numToRead);
}
}

View file

@ -135,21 +135,28 @@ int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
}
else
{
if (position < bufferStart || position >= lastReadPos)
ensureBuffered();
int bytesRead = 0;
while (maxBytesToRead > 0)
{
const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
if (bytesAvailable > 0)
{
memcpy (destBuffer, buffer + (position - bufferStart), bytesAvailable);
maxBytesToRead -= bytesAvailable;
bytesRead += bytesAvailable;
position += bytesAvailable;
destBuffer = (void*) (((char*) destBuffer) + bytesAvailable);
}
ensureBuffered();
if (isExhausted())
break;
const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
memcpy (destBuffer, buffer + (position - bufferStart), bytesAvailable);
maxBytesToRead -= bytesAvailable;
bytesRead += bytesAvailable;
position += bytesAvailable;
destBuffer = (void*) (((char*) destBuffer) + bytesAvailable);
}
return bytesRead;

View file

@ -122,7 +122,6 @@ public:
}
bool needsInput() const throw() { return dataSize <= 0; }
int getTotalOut() const throw() { return (stream != 0) ? stream->total_out : 0; }
void setInput (uint8* const data_, const int size) throw()
{
@ -182,7 +181,8 @@ GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sou
noWrap (noWrap_),
isEof (false),
activeBufferSize (0),
originalSourcePos (sourceStream_->getPosition())
originalSourcePos (sourceStream_->getPosition()),
currentPos (0)
{
buffer = (uint8*) juce_malloc (gzipDecompBufferSize);
helper = new GZIPDecompressHelper (noWrap_);
@ -220,6 +220,7 @@ int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
while (! h->error)
{
const int n = h->doNextBlock (d, howMany);
currentPos += n;
if (n == 0)
{
@ -269,15 +270,11 @@ bool GZIPDecompressorInputStream::isExhausted()
int64 GZIPDecompressorInputStream::getPosition()
{
const GZIPDecompressHelper* const h = (GZIPDecompressHelper*) helper;
return h->getTotalOut() + activeBufferSize;
return currentPos;
}
bool GZIPDecompressorInputStream::setPosition (int64 newPos)
{
const int64 currentPos = getPosition();
if (newPos != currentPos)
{
// reset the stream and start again..
@ -286,6 +283,7 @@ bool GZIPDecompressorInputStream::setPosition (int64 newPos)
isEof = false;
activeBufferSize = 0;
currentPos = 0;
helper = new GZIPDecompressHelper (noWrap);
sourceStream->setPosition (originalSourcePos);

View file

@ -85,7 +85,7 @@ private:
const bool deleteSourceWhenDestroyed, noWrap;
bool isEof;
int activeBufferSize;
int64 originalSourcePos;
int64 originalSourcePos, currentPos;
uint8* buffer;
void* helper;