1 // XzDecoder.h 2 3 #ifndef __XZ_DECODER_H 4 #define __XZ_DECODER_H 5 6 #include "../../../C/Xz.h" 7 8 #include "../../Common/MyCom.h" 9 10 #include "../ICoder.h" 11 12 namespace NCompress { 13 namespace NXz { 14 15 struct CDecoder 16 { 17 CXzDecMtHandle xz; 18 int _tryMt; 19 UInt32 _numThreads; 20 UInt64 _memUsage; 21 22 SRes MainDecodeSRes; // it's not HRESULT 23 bool MainDecodeSRes_wasUsed; 24 CXzStatInfo Stat; 25 CDecoderCDecoder26 CDecoder(): 27 xz(NULL), 28 _tryMt(True), 29 _numThreads(1), 30 _memUsage((UInt64)(sizeof(size_t)) << 28), 31 MainDecodeSRes(SZ_OK), 32 MainDecodeSRes_wasUsed(false) 33 {} 34 ~CDecoderCDecoder35 ~CDecoder() 36 { 37 if (xz) 38 XzDecMt_Destroy(xz); 39 } 40 41 /* Decode() can return S_OK, if there is data after good xz streams, and that data is not new xz stream. 42 check also (Stat.DataAfterEnd) flag */ 43 44 HRESULT Decode(ISequentialInStream *seqInStream, ISequentialOutStream *outStream, 45 const UInt64 *outSizeLimit, bool finishStream, ICompressProgressInfo *compressProgress); 46 }; 47 48 49 class CComDecoder: 50 public ICompressCoder, 51 public ICompressSetFinishMode, 52 public ICompressGetInStreamProcessedSize, 53 54 #ifndef _7ZIP_ST 55 public ICompressSetCoderMt, 56 public ICompressSetMemLimit, 57 #endif 58 59 public CMyUnknownImp, 60 public CDecoder 61 { 62 bool _finishStream; 63 64 public: 65 MY_QUERYINTERFACE_BEGIN2(ICompressCoder) 66 67 MY_QUERYINTERFACE_ENTRY(ICompressSetFinishMode) 68 MY_QUERYINTERFACE_ENTRY(ICompressGetInStreamProcessedSize) 69 70 #ifndef _7ZIP_ST 71 MY_QUERYINTERFACE_ENTRY(ICompressSetCoderMt) 72 MY_QUERYINTERFACE_ENTRY(ICompressSetMemLimit) 73 #endif 74 75 MY_QUERYINTERFACE_END 76 MY_ADDREF_RELEASE 77 78 STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, 79 const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 80 STDMETHOD(SetFinishMode)(UInt32 finishMode); 81 STDMETHOD(GetInStreamProcessedSize)(UInt64 *value); 82 83 #ifndef _7ZIP_ST 84 STDMETHOD(SetNumberOfThreads)(UInt32 numThreads); 85 STDMETHOD(SetMemLimit)(UInt64 memUsage); 86 #endif 87 CComDecoder()88 CComDecoder(): _finishStream(false) {} 89 }; 90 91 }} 92 93 #endif 94