Browse Source

tags/2021-05-28
jules 17 years ago
parent
commit
6b6bcdb2a0
6 changed files with 191 additions and 146 deletions
  1. +114
    -89
      juce_amalgamated.cpp
  2. +3
    -3
      juce_amalgamated.h
  3. +54
    -39
      src/juce_appframework/audio/audio_file_formats/juce_OggVorbisAudioFormat.cpp
  4. +14
    -7
      src/juce_core/io/streams/juce_BufferedInputStream.cpp
  5. +5
    -7
      src/juce_core/io/streams/juce_GZIPDecompressorInputStream.cpp
  6. +1
    -1
      src/juce_core/io/streams/juce_GZIPDecompressorInputStream.h

+ 114
- 89
juce_amalgamated.cpp View File

@@ -7151,7 +7151,7 @@ void BufferedInputStream::ensureBuffered()
int BufferedInputStream::read (void* destBuffer, int maxBytesToRead) int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
{ {
if (position >= bufferStart if (position >= bufferStart
&& position + maxBytesToRead < lastReadPos)
&& position + maxBytesToRead <= lastReadPos)
{ {
memcpy (destBuffer, buffer + (position - bufferStart), maxBytesToRead); memcpy (destBuffer, buffer + (position - bufferStart), maxBytesToRead);
position += maxBytesToRead; position += maxBytesToRead;
@@ -7160,21 +7160,28 @@ int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
} }
else else
{ {
if (position < bufferStart || position >= lastReadPos)
ensureBuffered();

int bytesRead = 0; int bytesRead = 0;


while (maxBytesToRead > 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(); ensureBuffered();


if (isExhausted()) if (isExhausted())
break; 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; return bytesRead;
@@ -7919,52 +7926,56 @@ void ZipFile::init()
{ {
numEntries = 0; numEntries = 0;
int pos = findEndOfZipEntryTable (in); 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()); in.setPosition (in.getTotalLength());
int64 pos = in.getPosition(); int64 pos = in.getPosition();
const int64 lowestPos = jmax ((int64) 0, pos - 1024);


char buffer [32]; char buffer [32];
zeromem (buffer, sizeof (buffer)); zeromem (buffer, sizeof (buffer));


while (pos > 0)
while (pos > lowestPos)
{ {
in.setPosition (pos - 22); in.setPosition (pos - 22);
pos = in.getPosition(); pos = in.getPosition();
@@ -97991,7 +98003,6 @@ public:
} }


bool needsInput() const throw() { return dataSize <= 0; } 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() void setInput (uint8* const data_, const int size) throw()
{ {
@@ -98050,7 +98061,8 @@ GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sou
noWrap (noWrap_), noWrap (noWrap_),
isEof (false), isEof (false),
activeBufferSize (0), activeBufferSize (0),
originalSourcePos (sourceStream_->getPosition())
originalSourcePos (sourceStream_->getPosition()),
currentPos (0)
{ {
buffer = (uint8*) juce_malloc (gzipDecompBufferSize); buffer = (uint8*) juce_malloc (gzipDecompBufferSize);
helper = new GZIPDecompressHelper (noWrap_); helper = new GZIPDecompressHelper (noWrap_);
@@ -98088,6 +98100,7 @@ int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
while (! h->error) while (! h->error)
{ {
const int n = h->doNextBlock (d, howMany); const int n = h->doNextBlock (d, howMany);
currentPos += n;


if (n == 0) if (n == 0)
{ {
@@ -98137,15 +98150,11 @@ bool GZIPDecompressorInputStream::isExhausted()


int64 GZIPDecompressorInputStream::getPosition() int64 GZIPDecompressorInputStream::getPosition()
{ {
const GZIPDecompressHelper* const h = (GZIPDecompressHelper*) helper;

return h->getTotalOut() + activeBufferSize;
return currentPos;
} }


bool GZIPDecompressorInputStream::setPosition (int64 newPos) bool GZIPDecompressorInputStream::setPosition (int64 newPos)
{ {
const int64 currentPos = getPosition();

if (newPos != currentPos) if (newPos != currentPos)
{ {
// reset the stream and start again.. // reset the stream and start again..
@@ -98154,6 +98163,7 @@ bool GZIPDecompressorInputStream::setPosition (int64 newPos)


isEof = false; isEof = false;
activeBufferSize = 0; activeBufferSize = 0;
currentPos = 0;
helper = new GZIPDecompressHelper (noWrap); helper = new GZIPDecompressHelper (noWrap);


sourceStream->setPosition (originalSourcePos); sourceStream->setPosition (originalSourcePos);
@@ -179949,7 +179959,7 @@ public:


OggReader (InputStream* const inp) OggReader (InputStream* const inp)
: AudioFormatReader (inp, oggFormatName), : AudioFormatReader (inp, oggFormatName),
reservoir (2, 2048),
reservoir (2, 4096),
reservoirStart (0), reservoirStart (0),
samplesInReservoir (0) samplesInReservoir (0)
{ {
@@ -179985,58 +179995,73 @@ public:
int64 startSampleInFile, int64 startSampleInFile,
int numSamples) 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; 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; location = T("http://") + location;


if (levelsOfRedirection++ < 3) if (levelsOfRedirection++ < 3)
return open (location, headers, postData, isPost, callback, callbackContext);
return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
} }
else else
{ {
@@ -253426,7 +253451,7 @@ public:
location = T("http://") + location; location = T("http://") + location;


if (levelsOfRedirection++ < 3) if (levelsOfRedirection++ < 3)
return open (location, headers, postData, isPost, callback, callbackContext);
return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
} }
else else
{ {


+ 3
- 3
juce_amalgamated.h View File

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


@@ -19548,7 +19548,7 @@ public:
int sourceClipWidth, int sourceClipWidth,
int sourceClipHeight, int sourceClipHeight,
const AffineTransform& transform, const AffineTransform& transform,
const bool fillAlphaChannelWithCurrentBrush) const throw();
const bool fillAlphaChannelWithCurrentBrush = false) const throw();


/** Draws an image to fit within a designated rectangle. /** Draws an image to fit within a designated rectangle.


@@ -19577,7 +19577,7 @@ public:
const int destWidth, const int destWidth,
const int destHeight, const int destHeight,
const RectanglePlacement& placementWithinTarget, 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. /** Returns the position of the bounding box for the current clipping region.




+ 54
- 39
src/juce_appframework/audio/audio_file_formats/juce_OggVorbisAudioFormat.cpp View File

@@ -98,7 +98,7 @@ public:
//============================================================================== //==============================================================================
OggReader (InputStream* const inp) OggReader (InputStream* const inp)
: AudioFormatReader (inp, oggFormatName), : AudioFormatReader (inp, oggFormatName),
reservoir (2, 2048),
reservoir (2, 4096),
reservoirStart (0), reservoirStart (0),
samplesInReservoir (0) samplesInReservoir (0)
{ {
@@ -135,58 +135,73 @@ public:
int64 startSampleInFile, int64 startSampleInFile,
int numSamples) 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; break;
}
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);
jassert (samps <= numToRead);
int offset = 0;
int numToRead = samplesInReservoir;
for (int i = jmin (numChannels, reservoir.getNumChannels()); --i >= 0;)
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);
} }
} }


+ 14
- 7
src/juce_core/io/streams/juce_BufferedInputStream.cpp View File

@@ -135,21 +135,28 @@ int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
} }
else else
{ {
if (position < bufferStart || position >= lastReadPos)
ensureBuffered();
int bytesRead = 0; int bytesRead = 0;
while (maxBytesToRead > 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(); ensureBuffered();
if (isExhausted()) if (isExhausted())
break; 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; return bytesRead;


+ 5
- 7
src/juce_core/io/streams/juce_GZIPDecompressorInputStream.cpp View File

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


+ 1
- 1
src/juce_core/io/streams/juce_GZIPDecompressorInputStream.h View File

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


Loading…
Cancel
Save