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 ERROR code only if there is progress or stream error. 42 Decode() returns S_OK in case of xz decoding error, but DecodeRes and CStatInfo contain error information */ 43 HRESULT Decode(ISequentialInStream *seqInStream, ISequentialOutStream *outStream, 44 const UInt64 *outSizeLimit, bool finishStream, ICompressProgressInfo *compressProgress); 45 }; 46 47 48 class CComDecoder: 49 public ICompressCoder, 50 public ICompressSetFinishMode, 51 public ICompressGetInStreamProcessedSize, 52 53 #ifndef _7ZIP_ST 54 public ICompressSetCoderMt, 55 public ICompressSetMemLimit, 56 #endif 57 58 public CMyUnknownImp, 59 public CDecoder 60 { 61 bool _finishStream; 62 63 public: 64 MY_QUERYINTERFACE_BEGIN2(ICompressCoder) 65 66 MY_QUERYINTERFACE_ENTRY(ICompressSetFinishMode) 67 MY_QUERYINTERFACE_ENTRY(ICompressGetInStreamProcessedSize) 68 69 #ifndef _7ZIP_ST 70 MY_QUERYINTERFACE_ENTRY(ICompressSetCoderMt) 71 MY_QUERYINTERFACE_ENTRY(ICompressSetMemLimit) 72 #endif 73 74 MY_QUERYINTERFACE_END 75 MY_ADDREF_RELEASE 76 77 STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, 78 const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 79 STDMETHOD(SetFinishMode)(UInt32 finishMode); 80 STDMETHOD(GetInStreamProcessedSize)(UInt64 *value); 81 82 #ifndef _7ZIP_ST 83 STDMETHOD(SetNumberOfThreads)(UInt32 numThreads); 84 STDMETHOD(SetMemLimit)(UInt64 memUsage); 85 #endif 86 CComDecoder()87 CComDecoder(): _finishStream(false) {} 88 }; 89 90 }} 91 92 #endif 93