[+] LZ4 required some more work
This commit is contained in:
parent
dd06417d04
commit
955578cf8e
@ -300,8 +300,10 @@ namespace Aurora::Compression
|
||||
|
||||
std::pair<AuUInt32, AuUInt32> Ingest(AuUInt32 input) override
|
||||
{
|
||||
AuUInt32 done {}, read {};
|
||||
std::shared_ptr<char> pinShared;
|
||||
AuUInt32 done {}, read {}, lastFrameSize {};
|
||||
std::shared_ptr<char> inFrame;
|
||||
std::shared_ptr<char> outFrames[2];
|
||||
bool outFrame {};
|
||||
|
||||
while (read != input)
|
||||
{
|
||||
@ -314,26 +316,36 @@ namespace Aurora::Compression
|
||||
}
|
||||
read += request;
|
||||
|
||||
std::shared_ptr<char> inFrame(new char[frameSize], std::default_delete<char[]>());
|
||||
std::shared_ptr<char> outFrame(new char[frameSize], std::default_delete<char[]>());
|
||||
if ((lastFrameSize < frameSize) || (!outFrames[outFrame]))
|
||||
{
|
||||
inFrame = std::shared_ptr<char>(new char[frameSize], std::default_delete<char[]>());
|
||||
outFrames[outFrame] = std::shared_ptr<char>(new char[frameSize], std::default_delete<char[]>());
|
||||
lastFrameSize = frameSize;
|
||||
}
|
||||
|
||||
request = frameSize;
|
||||
if (this->_reader->Read(inFrame.get(), request) != IO::EStreamError::eErrorNone)
|
||||
{
|
||||
return std::make_pair(read, done);
|
||||
}
|
||||
read += request;
|
||||
|
||||
auto bytes = LZ4_decompress_safe_continue(_lz4Stream, inFrame.get(), outFrame.get(), frameSize, frameSize);
|
||||
auto outPtr = outFrames[outFrame].get();
|
||||
|
||||
auto bytes = LZ4_decompress_safe_continue(_lz4Stream, inFrame.get(), outPtr, frameSize, frameSize);
|
||||
if (bytes <= 0)
|
||||
{
|
||||
return std::make_pair(read, 0);
|
||||
}
|
||||
|
||||
done += bytes;
|
||||
pinShared = std::move(inFrame);
|
||||
|
||||
this->_outbuffer.insert(this->_outbuffer.end(),
|
||||
reinterpret_cast<const AuUInt8 *>(outFrame.get()),
|
||||
reinterpret_cast<const AuUInt8 *>(outFrame.get()) + bytes);
|
||||
reinterpret_cast<const AuUInt8 *>(outPtr),
|
||||
reinterpret_cast<const AuUInt8 *>(outPtr) + bytes);
|
||||
|
||||
outFrames[!outFrame] = std::move(outFrames[outFrame]);
|
||||
outFrame = !outFrame;
|
||||
}
|
||||
|
||||
return std::make_pair(read, done);
|
||||
|
@ -470,57 +470,62 @@ namespace Aurora::Compression
|
||||
{
|
||||
bool ret = true;
|
||||
LZ4_streamDecode_t* lz4Stream = LZ4_createStreamDecode();
|
||||
char inBuf[kChunkSize];
|
||||
char outBuf[kChunkSize];
|
||||
AuUInt32 inputStat = 0, outputStat = 0;
|
||||
|
||||
AuUInt32 inputStat {}, outputStat {}, lastFrameSize {};
|
||||
std::shared_ptr<char> inFrame;
|
||||
std::shared_ptr<char> outFrames[2];
|
||||
bool outFrame {};
|
||||
|
||||
while (true)
|
||||
{
|
||||
AuUInt16 bufferedBytes;
|
||||
auto read = pipe.inPipe(&bufferedBytes, sizeof(bufferedBytes));
|
||||
if (read == 0)
|
||||
AuUInt16 frameSize;
|
||||
AuUInt32 request = sizeof(frameSize);
|
||||
auto read = pipe.inPipe(&frameSize, sizeof(frameSize));
|
||||
if (read != request)
|
||||
{
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
inputStat += request;
|
||||
|
||||
if ((lastFrameSize < frameSize) || (!outFrames[outFrame]))
|
||||
{
|
||||
inFrame = std::shared_ptr<char>(new char[frameSize], std::default_delete<char[]>());
|
||||
outFrames[outFrame] = std::shared_ptr<char>(new char[frameSize], std::default_delete<char[]>());
|
||||
lastFrameSize = frameSize;
|
||||
}
|
||||
|
||||
request = frameSize;
|
||||
read = pipe.inPipe(inFrame.get(), request);
|
||||
if (read != request)
|
||||
{
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
inputStat += request;
|
||||
|
||||
auto outPtr = outFrames[outFrame].get();
|
||||
|
||||
auto bytes = LZ4_decompress_safe_continue(lz4Stream, inFrame.get(), outPtr, frameSize, frameSize);
|
||||
if (bytes <= 0)
|
||||
{
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (read != 2)
|
||||
pipe.writePipe(outPtr, bytes);
|
||||
inputStat += bytes;
|
||||
|
||||
outFrames[!outFrame] = std::move(outFrames[outFrame]);
|
||||
outFrame = !outFrame;
|
||||
|
||||
if (!pipe.reportProgress(inputStat, outputStat))
|
||||
{
|
||||
ret = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
//while (bufferedBytes) TODO:
|
||||
{
|
||||
auto toRead = std::min(AuUInt16(ArraySize(inBuf)), bufferedBytes);
|
||||
|
||||
read = pipe.inPipe(inBuf, toRead);
|
||||
if (read != toRead)
|
||||
{
|
||||
ret = false;
|
||||
goto out;
|
||||
}
|
||||
bufferedBytes -= toRead;
|
||||
|
||||
auto err = LZ4_decompress_safe_continue(lz4Stream, inBuf, outBuf, read, ArraySize(outBuf));
|
||||
if (err < 0)
|
||||
{
|
||||
ret = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
pipe.writePipe(outBuf, err);
|
||||
|
||||
inputStat += bufferedBytes;
|
||||
outputStat += read;
|
||||
|
||||
if (!pipe.reportProgress(inputStat, outputStat))
|
||||
{
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
out:
|
||||
LZ4_freeStreamDecode(lz4Stream);
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user