|
|
|
@@ -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); |
|
|
|
|
|
|
|
in->setPosition (pos); |
|
|
|
MemoryBlock headerData; |
|
|
|
|
|
|
|
for (int i = 0; i < numEntries; ++i) |
|
|
|
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; |
|
|
|
|
|
|
|
ZipEntryInfo* const zei = new ZipEntryInfo(); |
|
|
|
zei->entry.filename = String (buffer + 46, fileNameLen); |
|
|
|
|
|
|
|
const int time = littleEndianShort (buffer + 12); |
|
|
|
const int date = littleEndianShort (buffer + 14); |
|
|
|
const int time = littleEndianShort (buffer + 12); |
|
|
|
const int date = littleEndianShort (buffer + 14); |
|
|
|
|
|
|
|
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 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->entry.fileTime = Time (year, month, day, hours, minutes, seconds); |
|
|
|
zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds); |
|
|
|
|
|
|
|
zei->compressed = littleEndianShort (buffer + 10) != 0; |
|
|
|
zei->compressedSize = littleEndianInt (buffer + 20); |
|
|
|
zei->entry.uncompressedSize = littleEndianInt (buffer + 24); |
|
|
|
zei->compressed = littleEndianShort (buffer + 10) != 0; |
|
|
|
zei->compressedSize = littleEndianInt (buffer + 20); |
|
|
|
zei->entry.uncompressedSize = littleEndianInt (buffer + 24); |
|
|
|
|
|
|
|
zei->streamOffset = littleEndianInt (buffer + 42); |
|
|
|
entries.add (zei); |
|
|
|
zei->streamOffset = littleEndianInt (buffer + 42); |
|
|
|
entries.add (zei); |
|
|
|
|
|
|
|
pos += 46 + fileNameLen |
|
|
|
+ littleEndianShort (buffer + 30) |
|
|
|
+ littleEndianShort (buffer + 32); |
|
|
|
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 (startSampleInFile >= reservoirStart && numAvailable > 0) |
|
|
|
{ |
|
|
|
// got a few samples overlapping, so use them before seeking.. |
|
|
|
|
|
|
|
if (reservoirStart != (int) ov_pcm_tell (&ovFile)) |
|
|
|
ov_pcm_seek (&ovFile, reservoirStart); |
|
|
|
for (unsigned int i = 0; i < numChannels; ++i) |
|
|
|
{ |
|
|
|
if (destSamples[i] == 0) |
|
|
|
break; |
|
|
|
|
|
|
|
int offset = 0; |
|
|
|
int numToRead = samplesInReservoir; |
|
|
|
memcpy (destSamples[i] + writeOffset, |
|
|
|
reservoir.getSampleData (jmin (i, reservoir.getNumChannels()), |
|
|
|
(int) (startSampleInFile - reservoirStart)), |
|
|
|
sizeof (float) * numSamples); |
|
|
|
} |
|
|
|
|
|
|
|
while (numToRead > 0) |
|
|
|
{ |
|
|
|
float** dataIn = 0; |
|
|
|
startSampleInFile += numAvailable; |
|
|
|
numSamples -= numAvailable; |
|
|
|
writeOffset += numAvailable; |
|
|
|
|
|
|
|
const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream); |
|
|
|
if (samps == 0) |
|
|
|
if (numSamples == 0) |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
jassert (samps <= numToRead); |
|
|
|
if (startSampleInFile < reservoirStart |
|
|
|
|| startSampleInFile + numSamples > reservoirStart + samplesInReservoir) |
|
|
|
{ |
|
|
|
// buffer miss, so refill the reservoir |
|
|
|
int bitStream = 0; |
|
|
|
|
|
|
|
reservoirStart = jmax (0, (int) startSampleInFile); |
|
|
|
samplesInReservoir = reservoir.getNumSamples(); |
|
|
|
|
|
|
|
if (reservoirStart != (int) ov_pcm_tell (&ovFile)) |
|
|
|
ov_pcm_seek (&ovFile, reservoirStart); |
|
|
|
|
|
|
|
for (int i = jmin (numChannels, reservoir.getNumChannels()); --i >= 0;) |
|
|
|
int offset = 0; |
|
|
|
int numToRead = samplesInReservoir; |
|
|
|
|
|
|
|
while (numToRead > 0) |
|
|
|
{ |
|
|
|
memcpy (reservoir.getSampleData (i, offset), |
|
|
|
dataIn[i], |
|
|
|
sizeof (float) * samps); |
|
|
|
} |
|
|
|
float** dataIn = 0; |
|
|
|
|
|
|
|
numToRead -= samps; |
|
|
|
offset += samps; |
|
|
|
} |
|
|
|
const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream); |
|
|
|
if (samps == 0) |
|
|
|
break; |
|
|
|
|
|
|
|
if (numToRead > 0) |
|
|
|
reservoir.clear (offset, numToRead); |
|
|
|
} |
|
|
|
jassert (samps <= numToRead); |
|
|
|
|
|
|
|
if (numSamples > 0) |
|
|
|
{ |
|
|
|
for (unsigned int i = 0; i < numChannels; ++i) |
|
|
|
{ |
|
|
|
if (destSamples[i] == 0) |
|
|
|
break; |
|
|
|
for (int i = jmin (numChannels, reservoir.getNumChannels()); --i >= 0;) |
|
|
|
{ |
|
|
|
memcpy (reservoir.getSampleData (i, offset), |
|
|
|
dataIn[i], |
|
|
|
sizeof (float) * samps); |
|
|
|
} |
|
|
|
|
|
|
|
numToRead -= samps; |
|
|
|
offset += samps; |
|
|
|
} |
|
|
|
|
|
|
|
memcpy (destSamples[i], |
|
|
|
reservoir.getSampleData (jmin (i, reservoir.getNumChannels()), |
|
|
|
(int) (startSampleInFile - reservoirStart)), |
|
|
|
sizeof (float) * numSamples); |
|
|
|
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 |
|
|
|
{ |
|
|
|
|