Open 3D Engine AzCore API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::IO::CompressorZLib Class Reference

#include <CompressorZLib.h>

Inherits AZ::IO::Compressor.

Public Member Functions

 AZ_CLASS_ALLOCATOR (CompressorZLib, AZ::SystemAllocator)
 
 CompressorZLib (unsigned int decompressionCachePerStream=64 *1024, unsigned int dataBufferSize=128 *1024)
 
AZ::u32 GetTypeId () const override
 Return compressor type id.
 
bool ReadHeaderAndData (CompressorStream *stream, AZ::u8 *data, unsigned int dataSize) override
 Called when we open a stream to Read for the first time. Data contains the first. dataSize <= m_maxHeaderSize.
 
bool WriteHeaderAndData (CompressorStream *stream) override
 Called when we are about to start writing to a compressed stream.
 
SizeType Read (CompressorStream *stream, SizeType byteSize, SizeType offset, void *buffer) override
 Forwarded function from the Device when we from a compressed stream.
 
SizeType Write (CompressorStream *stream, SizeType byteSize, const void *data, SizeType offset=SizeType(-1)) override
 Forwarded function from the Device when we write to a compressed stream.
 
bool WriteSeekPoint (CompressorStream *stream) override
 Write a seek point.
 
bool StartCompressor (CompressorStream *stream, int compressionLevel, SizeType autoSeekDataSize) override
 Set auto seek point even dataSize bytes.
 
bool Close (CompressorStream *stream) override
 Called just before we close the stream. All compression data will be flushed and finalized. (You can't add data afterwards).
 
- Public Member Functions inherited from AZ::IO::Compressor
virtual ~Compressor ()
 When we open a stream to check if it's compressed we read the first m_maxHeaderSize bytes.
 
virtual AZ::u32 GetTypeId () const =0
 Return compressor type id.
 
virtual bool ReadHeaderAndData (CompressorStream *stream, AZ::u8 *data, unsigned int dataSize)=0
 Called when we open a stream to Read for the first time. Data contains the first. dataSize <= m_maxHeaderSize.
 
virtual bool WriteHeaderAndData (CompressorStream *stream)
 Called when we are about to start writing to a compressed stream. (Must be called first to write compressor header)
 
virtual SizeType Read (CompressorStream *stream, SizeType byteSize, SizeType offset, void *buffer)=0
 Forwarded function from the Device when we from a compressed stream.
 
virtual SizeType Write (CompressorStream *stream, SizeType byteSize, const void *data, SizeType offset=SizeType(-1))=0
 Forwarded function from the Device when we write to a compressed stream.
 
virtual bool WriteSeekPoint (CompressorStream *stream)
 Write a seek point.
 
virtual bool StartCompressor (CompressorStream *stream, int compressionLevel, SizeType autoSeekDataSize)
 Initializes Compressor for writing data.
 
virtual bool Close (CompressorStream *stream)=0
 Called just before we close the stream. All compression data will be flushed and finalized. (You can't add data afterwards).
 

Static Public Member Functions

static AZ::u32 TypeId ()
 Return compressor type id.
 

Protected Member Functions

SizeType FillFromDecompressCache (CompressorZLibData *zlibData, void *&buffer, SizeType &byteSize, SizeType &offset)
 Read as much data as possible and adjust the parameters.
 
SizeType FillCompressedBuffer (CompressorStream *stream)
 Read data from stream into the compression buffer.
 
void AcquireDataBuffer ()
 Acquire data buffer resource (if not created it will be allocated) and increment m_dataBufferUseCount.
 
void ReleaseDataBuffer ()
 Release data buffer resource, if m_dataBufferUseCount == 0 all memory will be freed.
 

Protected Attributes

CompressorStreamm_lastReadStream
 Cached last stream we read data into the m_dataBuffer.
 
SizeType m_lastReadStreamOffset
 Offset of the last read (in the m_dataBuffer) in the compressed stream.
 
SizeType m_lastReadStreamSize
 Size of the data in m_dataBuffer of the last read.
 
unsigned char * m_compressedDataBuffer
 Data buffer used to read/write compressed data.
 
unsigned int m_compressedDataBufferSize
 Data buffer size (stored so we can lazy allocate m_dataBuffer as we need).
 
unsigned int m_compressedDataBufferUseCount
 Data buffer use count.
 
unsigned int m_decompressionCachePerStream
 Cache per stream for each compressed stream stream in bytes.
 

Static Protected Attributes

static const int m_CompressedDataBufferAlignment = 16
 

Additional Inherited Members

- Public Types inherited from AZ::IO::Compressor
typedef AZ::u64 SizeType
 
- Static Public Attributes inherited from AZ::IO::Compressor
static const int m_maxHeaderSize = 4096
 

Detailed Description

ZLib compressor implementation. Note: As of now the CompressorZLib is the only supported compressor. We can move much of the caching functionality into the base Compressor class to be shared. Please do so when you have an actual need to implement another compressor, don't just copy and paste.

Constructor & Destructor Documentation

◆ CompressorZLib()

AZ::IO::CompressorZLib::CompressorZLib ( unsigned int  decompressionCachePerStream = 64 *1024,
unsigned int  dataBufferSize = 128 *1024 
)
Parameters
decompressionCachePerStreamcache of decompressed data stored per stream, the more streams you have open the more memory it will use, You can use 0 size too to save memory, but every read will happen with decompression from the closest seek point. That might be fine if we use stream read cache and it matches the size of the seek points (you will need to make sure of that), otherwise the extra cache can be useful. We can convert this system to use pools of caches, but as of now this should be fine.
dataBufferSizewe have one compressor per device, only one stream can read/write at a time and the data buffer is shared for IO operations, the buffer is refCounted and existing only when we read/write compressed streams.

Member Function Documentation

◆ Close()

bool AZ::IO::CompressorZLib::Close ( CompressorStream stream)
overridevirtual

Called just before we close the stream. All compression data will be flushed and finalized. (You can't add data afterwards).

Implements AZ::IO::Compressor.

◆ GetTypeId()

AZ::u32 AZ::IO::CompressorZLib::GetTypeId ( ) const
inlineoverridevirtual

Return compressor type id.

Implements AZ::IO::Compressor.

◆ Read()

SizeType AZ::IO::CompressorZLib::Read ( CompressorStream stream,
SizeType  byteSize,
SizeType  offset,
void *  buffer 
)
overridevirtual

Forwarded function from the Device when we from a compressed stream.

Implements AZ::IO::Compressor.

◆ ReadHeaderAndData()

bool AZ::IO::CompressorZLib::ReadHeaderAndData ( CompressorStream stream,
AZ::u8 *  data,
unsigned int  dataSize 
)
overridevirtual

Called when we open a stream to Read for the first time. Data contains the first. dataSize <= m_maxHeaderSize.

Implements AZ::IO::Compressor.

◆ StartCompressor()

bool AZ::IO::CompressorZLib::StartCompressor ( CompressorStream stream,
int  compressionLevel,
SizeType  autoSeekDataSize 
)
overridevirtual

Set auto seek point even dataSize bytes.

Reimplemented from AZ::IO::Compressor.

◆ Write()

SizeType AZ::IO::CompressorZLib::Write ( CompressorStream stream,
SizeType  byteSize,
const void *  data,
SizeType  offset = SizeType(-1) 
)
overridevirtual

Forwarded function from the Device when we write to a compressed stream.

Implements AZ::IO::Compressor.

◆ WriteHeaderAndData()

bool AZ::IO::CompressorZLib::WriteHeaderAndData ( CompressorStream stream)
overridevirtual

Called when we are about to start writing to a compressed stream.

Reimplemented from AZ::IO::Compressor.

◆ WriteSeekPoint()

bool AZ::IO::CompressorZLib::WriteSeekPoint ( CompressorStream stream)
overridevirtual

Write a seek point.

Reimplemented from AZ::IO::Compressor.


The documentation for this class was generated from the following file: