diff src/win32/7zip/7z/CPP/7zip/Compress/BZip2Decoder.h @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/7zip/7z/CPP/7zip/Compress/BZip2Decoder.h	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,159 @@
     1.4 +// Compress/BZip2Decoder.h
     1.5 +
     1.6 +#ifndef __COMPRESS_BZIP2_DECODER_H
     1.7 +#define __COMPRESS_BZIP2_DECODER_H
     1.8 +
     1.9 +#include "../../Common/MyCom.h"
    1.10 +
    1.11 +#ifdef COMPRESS_BZIP2_MT
    1.12 +#include "../../Windows/Synchronization.h"
    1.13 +#include "../../Windows/Thread.h"
    1.14 +#endif
    1.15 +
    1.16 +#include "../ICoder.h"
    1.17 +
    1.18 +#include "../Common/InBuffer.h"
    1.19 +#include "../Common/OutBuffer.h"
    1.20 +
    1.21 +#include "BitmDecoder.h"
    1.22 +#include "BZip2Const.h"
    1.23 +#include "BZip2Crc.h"
    1.24 +#include "HuffmanDecoder.h"
    1.25 +
    1.26 +namespace NCompress {
    1.27 +namespace NBZip2 {
    1.28 +
    1.29 +typedef NCompress::NHuffman::CDecoder<kMaxHuffmanLen, kMaxAlphaSize> CHuffmanDecoder;
    1.30 +
    1.31 +class CDecoder;
    1.32 +
    1.33 +struct CState
    1.34 +{
    1.35 +  UInt32 *Counters;
    1.36 +
    1.37 +  #ifdef COMPRESS_BZIP2_MT
    1.38 +
    1.39 +  CDecoder *Decoder;
    1.40 +  NWindows::CThread Thread;
    1.41 +  bool m_OptimizeNumTables;
    1.42 +
    1.43 +  NWindows::NSynchronization::CAutoResetEvent StreamWasFinishedEvent;
    1.44 +  NWindows::NSynchronization::CAutoResetEvent WaitingWasStartedEvent;
    1.45 +
    1.46 +  // it's not member of this thread. We just need one event per thread
    1.47 +  NWindows::NSynchronization::CAutoResetEvent CanWriteEvent;
    1.48 +
    1.49 +  Byte MtPad[1 << 8]; // It's pad for Multi-Threading. Must be >= Cache_Line_Size.
    1.50 +
    1.51 +  HRESULT Create();
    1.52 +  void FinishStream();
    1.53 +  void ThreadFunc();
    1.54 +
    1.55 +  #endif
    1.56 +
    1.57 +  CState(): Counters(0) {}
    1.58 +  ~CState() { Free(); }
    1.59 +  bool Alloc();
    1.60 +  void Free();
    1.61 +};
    1.62 +
    1.63 +class CDecoder :
    1.64 +  public ICompressCoder,
    1.65 +  #ifdef COMPRESS_BZIP2_MT
    1.66 +  public ICompressSetCoderMt,
    1.67 +  #endif
    1.68 +  public ICompressGetInStreamProcessedSize,
    1.69 +  public CMyUnknownImp
    1.70 +{
    1.71 +public:
    1.72 +  COutBuffer m_OutStream;
    1.73 +  Byte MtPad[1 << 8]; // It's pad for Multi-Threading. Must be >= Cache_Line_Size.
    1.74 +  NBitm::CDecoder<CInBuffer> m_InStream;
    1.75 +  Byte m_Selectors[kNumSelectorsMax];
    1.76 +  CHuffmanDecoder m_HuffmanDecoders[kNumTablesMax];
    1.77 +private:
    1.78 +
    1.79 +  UInt32 m_NumThreadsPrev;
    1.80 +
    1.81 +  UInt32 ReadBits(int numBits);
    1.82 +  Byte ReadByte();
    1.83 +  bool ReadBit();
    1.84 +  UInt32 ReadCrc();
    1.85 +  HRESULT PrepareBlock(CState &state);
    1.86 +  HRESULT DecodeFile(bool &isBZ, ICompressProgressInfo *progress);
    1.87 +  HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
    1.88 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
    1.89 +  class CDecoderFlusher
    1.90 +  {
    1.91 +    CDecoder *_decoder;
    1.92 +  public:
    1.93 +    bool NeedFlush;
    1.94 +    CDecoderFlusher(CDecoder *decoder): _decoder(decoder), NeedFlush(true) {}
    1.95 +    ~CDecoderFlusher()
    1.96 +    {
    1.97 +      if (NeedFlush)
    1.98 +        _decoder->Flush();
    1.99 +      _decoder->ReleaseStreams();
   1.100 +    }
   1.101 +  };
   1.102 +
   1.103 +public:
   1.104 +  CBZip2CombinedCrc CombinedCrc;
   1.105 +
   1.106 +  #ifdef COMPRESS_BZIP2_MT
   1.107 +  ICompressProgressInfo *Progress;
   1.108 +  CState *m_States;
   1.109 +
   1.110 +  NWindows::NSynchronization::CManualResetEvent CanProcessEvent;
   1.111 +  NWindows::NSynchronization::CCriticalSection CS;
   1.112 +  UInt32 NumThreads;
   1.113 +  bool MtMode;
   1.114 +  UInt32 NextBlockIndex;
   1.115 +  bool CloseThreads;
   1.116 +  bool StreamWasFinished1;
   1.117 +  bool StreamWasFinished2;
   1.118 +  NWindows::NSynchronization::CManualResetEvent CanStartWaitingEvent;
   1.119 +
   1.120 +  HRESULT Result1;
   1.121 +  HRESULT Result2;
   1.122 +
   1.123 +  UInt32 BlockSizeMax;
   1.124 +  CDecoder();
   1.125 +  ~CDecoder();
   1.126 +  HRESULT Create();
   1.127 +  void Free();
   1.128 +
   1.129 +  #else
   1.130 +  CState m_States[1];
   1.131 +  #endif
   1.132 +
   1.133 +  HRESULT ReadSignatures(bool &wasFinished, UInt32 &crc);
   1.134 +
   1.135 +
   1.136 +  HRESULT Flush() { return m_OutStream.Flush(); }
   1.137 +  void ReleaseStreams()
   1.138 +  {
   1.139 +    m_InStream.ReleaseStream();
   1.140 +    m_OutStream.ReleaseStream();
   1.141 +  }
   1.142 +
   1.143 +  #ifdef COMPRESS_BZIP2_MT
   1.144 +  MY_UNKNOWN_IMP2(ICompressSetCoderMt, ICompressGetInStreamProcessedSize)
   1.145 +  #else
   1.146 +  MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize)
   1.147 +  #endif
   1.148 +
   1.149 +  
   1.150 +  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
   1.151 +      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
   1.152 +
   1.153 +  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);
   1.154 +
   1.155 +  #ifdef COMPRESS_BZIP2_MT
   1.156 +  STDMETHOD(SetNumberOfThreads)(UInt32 numThreads);
   1.157 +  #endif
   1.158 +};
   1.159 +
   1.160 +}}
   1.161 +
   1.162 +#endif