OpenShot Library | libopenshot-audio
0.2.0
|
27 : blockToUse (&internalBlock)
29 internalBlock.
setSize (initialSize,
false);
33 const bool appendToExistingBlockContent)
34 : blockToUse (&memoryBlockToWriteTo)
36 if (appendToExistingBlockContent)
37 position = size = memoryBlockToWriteTo.
getSize();
41 : externalData (destBuffer), availableSize (destBufferSize)
43 jassert (externalData !=
nullptr);
48 trimExternalBlockSize();
53 trimExternalBlockSize();
56 void MemoryOutputStream::trimExternalBlockSize()
58 if (blockToUse != &internalBlock && blockToUse !=
nullptr)
59 blockToUse->
setSize (size,
false);
64 if (blockToUse !=
nullptr)
65 blockToUse->
ensureSize (bytesToPreallocate + 1);
74 char* MemoryOutputStream::prepareToWrite (
size_t numBytes)
76 jassert ((ssize_t) numBytes >= 0);
77 auto storageNeeded = position + numBytes;
81 if (blockToUse !=
nullptr)
83 if (storageNeeded >= blockToUse->
getSize())
84 blockToUse->
ensureSize ((storageNeeded + jmin (storageNeeded / 2, (
size_t) (1024 * 1024)) + 32) & ~31u);
86 data =
static_cast<char*
> (blockToUse->
getData());
90 if (storageNeeded > availableSize)
93 data =
static_cast<char*
> (externalData);
96 auto* writePointer = data + position;
98 size = jmax (size, position);
107 jassert (buffer !=
nullptr);
109 if (
auto* dest = prepareToWrite (howMany))
111 memcpy (dest, buffer, howMany);
123 if (
auto* dest = prepareToWrite (howMany))
125 memset (dest,
byte, howMany);
150 if (blockToUse ==
nullptr)
153 if (blockToUse->
getSize() > size)
154 static_cast<char*
> (blockToUse->
getData()) [size] = 0;
161 if (newPosition <= (int64) size)
164 position = jlimit ((
size_t) 0, size, (
size_t) newPosition);
177 if (availableData > 0)
179 if (maxNumBytesToWrite > availableData || maxNumBytesToWrite < 0)
180 maxNumBytesToWrite = availableData;
182 if (blockToUse !=
nullptr)
191 auto* d =
static_cast<const char*
> (
getData());
bool write(const void *, size_t) override
Writes a block of data to the stream.
static String createStringFromData(const void *data, int size)
Creates a string from data in an unknown format.
virtual int64 writeFromInputStream(InputStream &source, int64 maxNumBytesToWrite)
Reads data from an input stream and writes it to this stream.
void * getData() const noexcept
Returns a void pointer to the data.
void reset() noexcept
Resets the stream, clearing any data that has been written to it so far.
MemoryBlock getMemoryBlock() const
Returns a copy of the stream's data as a memory block.
Writes data to an internal memory buffer, which grows as required.
bool setPosition(int64) override
Tries to move the stream's output position.
const void * getData() const noexcept
Returns a pointer to the data that has been written to the stream.
bool writeRepeatedByte(uint8 byte, size_t numTimesToRepeat) override
Writes a byte to the output stream a given number of times.
virtual bool write(const void *dataToWrite, size_t numberOfBytes)=0
Writes a block of data to the stream.
The base class for streams that write data to some kind of destination.
size_t getSize() const noexcept
Returns the block's current allocated size, in bytes.
String toUTF8() const
Returns a String created from the (UTF8) data that has been written to the stream.
void ensureSize(const size_t minimumSize, bool initialiseNewSpaceToZero=false)
Increases the block's size only if it's smaller than a given size.
void flush() override
If the stream is writing to a user-supplied MemoryBlock, this will trim any excess capacity off the b...
~MemoryOutputStream() override
Destructor.
int64 writeFromInputStream(InputStream &, int64 maxNumBytesToWrite) override
Reads data from an input stream and writes it to this stream.
void preallocate(size_t bytesToPreallocate)
Increases the internal storage capacity to be able to contain at least the specified amount of data w...
String toString() const
Attempts to detect the encoding of the data and convert it to a string.
Wraps a pointer to a null-terminated UTF-8 character string, and provides various methods to operate ...
MemoryOutputStream(size_t initialSize=256)
Creates an empty memory stream, ready to be written into.
void write(const juce_wchar charToWrite) noexcept
Writes a unicode character to this string, and advances this pointer to point to the next position.
static size_t getBytesRequiredFor(const juce_wchar charToWrite) noexcept
Returns the number of bytes that would be needed to represent the given unicode character in this enc...
size_t getDataSize() const noexcept
Returns the number of bytes of data that have been written to the stream.
bool appendUTF8Char(juce_wchar character)
Appends the utf-8 bytes for a unicode character.
A class to hold a resizable block of raw data.
void setSize(const size_t newSize, bool initialiseNewSpaceToZero=false)
Resizes the memory block.