mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
libfreerdp-codec: cleanup and fix XCrush context flush synchronization
This commit is contained in:
@@ -48,7 +48,9 @@ FREERDP_API int mppc_compress(MPPC_CONTEXT* mppc, BYTE* pSrcData, UINT32 SrcSize
|
||||
FREERDP_API int mppc_decompress(MPPC_CONTEXT* mppc, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize, UINT32 flags);
|
||||
|
||||
FREERDP_API void mppc_set_compression_level(MPPC_CONTEXT* mppc, DWORD CompressionLevel);
|
||||
|
||||
FREERDP_API void mppc_context_reset(MPPC_CONTEXT* mppc);
|
||||
FREERDP_API void mppc_context_flush(MPPC_CONTEXT* mppc);
|
||||
|
||||
FREERDP_API MPPC_CONTEXT* mppc_context_new(DWORD CompressionLevel, BOOL Compressor);
|
||||
FREERDP_API void mppc_context_free(MPPC_CONTEXT* mppc);
|
||||
|
||||
@@ -100,6 +100,7 @@ FREERDP_API int xcrush_compress(XCRUSH_CONTEXT* xcrush, BYTE* pSrcData, UINT32 S
|
||||
FREERDP_API int xcrush_decompress(XCRUSH_CONTEXT* xcrush, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize, UINT32 flags);
|
||||
|
||||
FREERDP_API void xcrush_context_reset(XCRUSH_CONTEXT* xcrush);
|
||||
FREERDP_API void xcrush_context_flush(XCRUSH_CONTEXT* xcrush);
|
||||
|
||||
FREERDP_API XCRUSH_CONTEXT* xcrush_context_new(BOOL Compressor);
|
||||
FREERDP_API void xcrush_context_free(XCRUSH_CONTEXT* xcrush);
|
||||
|
||||
@@ -510,7 +510,10 @@ int mppc_compress(MPPC_CONTEXT* mppc, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppD
|
||||
if (!pDstData)
|
||||
return -1;
|
||||
|
||||
DstSize = SrcSize;
|
||||
if (*pDstSize > SrcSize)
|
||||
DstSize = SrcSize;
|
||||
else
|
||||
DstSize = *pDstSize;
|
||||
|
||||
BitStream_Attach(bs, pDstData, DstSize);
|
||||
|
||||
@@ -541,9 +544,7 @@ int mppc_compress(MPPC_CONTEXT* mppc, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppD
|
||||
{
|
||||
if (((bs->position / 8) + 2) > (DstSize - 1))
|
||||
{
|
||||
ZeroMemory(HistoryBuffer, HistoryBufferSize);
|
||||
ZeroMemory(mppc->MatchBuffer, sizeof(mppc->MatchBuffer));
|
||||
mppc->HistoryOffset = HistoryBufferSize + 1;
|
||||
mppc_context_flush(mppc);
|
||||
*pFlags |= PACKET_FLUSHED;
|
||||
*pFlags |= CompressionLevel;
|
||||
*ppDstData = pSrcData;
|
||||
@@ -595,9 +596,7 @@ int mppc_compress(MPPC_CONTEXT* mppc, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppD
|
||||
|
||||
if (((bs->position / 8) + 7) > (DstSize - 1))
|
||||
{
|
||||
ZeroMemory(HistoryBuffer, HistoryBufferSize);
|
||||
ZeroMemory(mppc->MatchBuffer, sizeof(mppc->MatchBuffer));
|
||||
mppc->HistoryOffset = HistoryBufferSize + 1;
|
||||
mppc_context_flush(mppc);
|
||||
*pFlags |= PACKET_FLUSHED;
|
||||
*pFlags |= CompressionLevel;
|
||||
*ppDstData = pSrcData;
|
||||
@@ -754,9 +753,7 @@ int mppc_compress(MPPC_CONTEXT* mppc, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppD
|
||||
{
|
||||
if (((bs->position / 8) + 2) > (DstSize - 1))
|
||||
{
|
||||
ZeroMemory(HistoryBuffer, HistoryBufferSize);
|
||||
ZeroMemory(mppc->MatchBuffer, sizeof(mppc->MatchBuffer));
|
||||
mppc->HistoryOffset = HistoryBufferSize + 1;
|
||||
mppc_context_flush(mppc);
|
||||
*pFlags |= PACKET_FLUSHED;
|
||||
*pFlags |= CompressionLevel;
|
||||
*ppDstData = pSrcData;
|
||||
@@ -831,6 +828,12 @@ void mppc_context_reset(MPPC_CONTEXT* mppc)
|
||||
mppc->HistoryPtr = &(mppc->HistoryBuffer[mppc->HistoryOffset]);
|
||||
}
|
||||
|
||||
void mppc_context_flush(MPPC_CONTEXT* mppc)
|
||||
{
|
||||
mppc_context_reset(mppc);
|
||||
mppc->HistoryOffset = mppc->HistoryBufferSize + 1;
|
||||
}
|
||||
|
||||
MPPC_CONTEXT* mppc_context_new(DWORD CompressionLevel, BOOL Compressor)
|
||||
{
|
||||
MPPC_CONTEXT* mppc;
|
||||
|
||||
@@ -647,7 +647,7 @@ int xcrush_generate_output(XCRUSH_CONTEXT* xcrush, BYTE* OutputBuffer, UINT32 Ou
|
||||
if (Literals + MatchOffset - CurrentOffset >= OutputEnd)
|
||||
return -6004; /* error */
|
||||
|
||||
MoveMemory(Literals, &xcrush->HistoryBuffer[CurrentOffset], MatchOffsetDiff);
|
||||
CopyMemory(Literals, &xcrush->HistoryBuffer[CurrentOffset], MatchOffsetDiff);
|
||||
|
||||
if (Literals >= OutputEnd)
|
||||
return -6005; /* error */
|
||||
@@ -662,7 +662,7 @@ int xcrush_generate_output(XCRUSH_CONTEXT* xcrush, BYTE* OutputBuffer, UINT32 Ou
|
||||
if (Literals + HistoryOffsetDiff >= OutputEnd)
|
||||
return -6006; /* error */
|
||||
|
||||
MoveMemory(Literals, &xcrush->HistoryBuffer[CurrentOffset], HistoryOffsetDiff);
|
||||
CopyMemory(Literals, &xcrush->HistoryBuffer[CurrentOffset], HistoryOffsetDiff);
|
||||
*pDstSize = Literals + HistoryOffsetDiff - OutputBuffer;
|
||||
|
||||
return 1;
|
||||
@@ -963,8 +963,7 @@ int xcrush_compress(XCRUSH_CONTEXT* xcrush, BYTE* pSrcData, UINT32 SrcSize, BYTE
|
||||
{
|
||||
if (CompressedDataSize > DstSize)
|
||||
{
|
||||
xcrush_context_reset(xcrush);
|
||||
xcrush->HistoryOffset = xcrush->HistoryBufferSize + 1;
|
||||
xcrush_context_flush(xcrush);
|
||||
*ppDstData = pSrcData;
|
||||
*pDstSize = SrcSize;
|
||||
*pFlags = 0;
|
||||
@@ -972,7 +971,7 @@ int xcrush_compress(XCRUSH_CONTEXT* xcrush, BYTE* pSrcData, UINT32 SrcSize, BYTE
|
||||
}
|
||||
|
||||
DstSize = CompressedDataSize;
|
||||
MoveMemory(&OriginalData[2], CompressedData, CompressedDataSize);
|
||||
CopyMemory(&OriginalData[2], CompressedData, CompressedDataSize);
|
||||
}
|
||||
|
||||
if (Level2ComprFlags & PACKET_COMPRESSED)
|
||||
@@ -990,6 +989,12 @@ int xcrush_compress(XCRUSH_CONTEXT* xcrush, BYTE* pSrcData, UINT32 SrcSize, BYTE
|
||||
OriginalData[0] = (BYTE) Level1ComprFlags;
|
||||
OriginalData[1] = (BYTE) Level2ComprFlags;
|
||||
|
||||
#if 0
|
||||
printf("XCrushCompress: Level1ComprFlags: %s Level2ComprFlags: %s\n",
|
||||
xcrush_get_level_1_compression_flags_string(Level1ComprFlags),
|
||||
xcrush_get_level_2_compression_flags_string(Level2ComprFlags));
|
||||
#endif
|
||||
|
||||
if (*pDstSize < (DstSize + 2))
|
||||
return -1006;
|
||||
|
||||
@@ -1017,6 +1022,14 @@ void xcrush_context_reset(XCRUSH_CONTEXT* xcrush)
|
||||
mppc_context_reset(xcrush->mppc);
|
||||
}
|
||||
|
||||
void xcrush_context_flush(XCRUSH_CONTEXT* xcrush)
|
||||
{
|
||||
xcrush_context_reset(xcrush);
|
||||
xcrush->HistoryOffset = xcrush->HistoryBufferSize + 1;
|
||||
|
||||
mppc_context_flush(xcrush->mppc);
|
||||
}
|
||||
|
||||
XCRUSH_CONTEXT* xcrush_context_new(BOOL Compressor)
|
||||
{
|
||||
XCRUSH_CONTEXT* xcrush;
|
||||
|
||||
Reference in New Issue
Block a user