1
// Compress/BZip2Decoder.h
3
#ifndef __COMPRESS_BZIP2_DECODER_H
4
#define __COMPRESS_BZIP2_DECODER_H
6
#include "../../Common/MyCom.h"
8
#ifdef COMPRESS_BZIP2_MT
9
#include "../../Windows/Synchronization.h"
10
#include "../../Windows/Thread.h"
13
#include "../ICoder.h"
15
#include "../Common/InBuffer.h"
16
#include "../Common/OutBuffer.h"
18
#include "BitmDecoder.h"
19
#include "BZip2Const.h"
21
#include "HuffmanDecoder.h"
26
typedef NCompress::NHuffman::CDecoder<kMaxHuffmanLen, kMaxAlphaSize> CHuffmanDecoder;
34
#ifdef COMPRESS_BZIP2_MT
37
NWindows::CThread Thread;
38
bool m_OptimizeNumTables;
40
NWindows::NSynchronization::CAutoResetEvent StreamWasFinishedEvent;
41
NWindows::NSynchronization::CAutoResetEvent WaitingWasStartedEvent;
43
// it's not member of this thread. We just need one event per thread
44
NWindows::NSynchronization::CAutoResetEvent CanWriteEvent;
46
Byte MtPad[1 << 8]; // It's pad for Multi-Threading. Must be >= Cache_Line_Size.
54
CState(): Counters(0) {}
61
public ICompressCoder,
62
#ifdef COMPRESS_BZIP2_MT
63
public ICompressSetCoderMt,
65
public ICompressGetInStreamProcessedSize,
69
COutBuffer m_OutStream;
70
Byte MtPad[1 << 8]; // It's pad for Multi-Threading. Must be >= Cache_Line_Size.
71
NBitm::CDecoder<CInBuffer> m_InStream;
72
Byte m_Selectors[kNumSelectorsMax];
73
CHuffmanDecoder m_HuffmanDecoders[kNumTablesMax];
76
UInt32 m_NumThreadsPrev;
78
UInt32 ReadBits(int numBits);
82
HRESULT PrepareBlock(CState &state);
83
HRESULT DecodeFile(bool &isBZ, ICompressProgressInfo *progress);
84
HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
85
const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
91
CDecoderFlusher(CDecoder *decoder): _decoder(decoder), NeedFlush(true) {}
96
_decoder->ReleaseStreams();
101
CBZip2CombinedCrc CombinedCrc;
103
#ifdef COMPRESS_BZIP2_MT
104
ICompressProgressInfo *Progress;
107
NWindows::NSynchronization::CManualResetEvent CanProcessEvent;
108
NWindows::NSynchronization::CCriticalSection CS;
111
UInt32 NextBlockIndex;
113
bool StreamWasFinished1;
114
bool StreamWasFinished2;
115
NWindows::NSynchronization::CManualResetEvent CanStartWaitingEvent;
130
HRESULT ReadSignatures(bool &wasFinished, UInt32 &crc);
133
HRESULT Flush() { return m_OutStream.Flush(); }
134
void ReleaseStreams()
136
m_InStream.ReleaseStream();
137
m_OutStream.ReleaseStream();
140
#ifdef COMPRESS_BZIP2_MT
141
MY_UNKNOWN_IMP2(ICompressSetCoderMt, ICompressGetInStreamProcessedSize)
143
MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize)
147
STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
148
const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
150
STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);
152
#ifdef COMPRESS_BZIP2_MT
153
STDMETHOD(SetNumberOfThreads)(UInt32 numThreads);