Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CoderMixerMT.cpp « Common « Archive « 7zip « CPP - github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ad6e12d80c7d295c2f36a3dd5009a04b1e19b8b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// CoderMixerMT.cpp

#include "StdAfx.h"

#include "CoderMixerMT.h"

namespace NCoderMixer {

void CCoder::Execute() { Code(NULL); }

void CCoder::Code(ICompressProgressInfo *progress)
{
  Result = Coder->Code(InStream, OutStream, 
      InSizeAssigned ? &InSizeValue : NULL, 
      OutSizeAssigned ? &OutSizeValue : NULL, 
      progress);
  InStream.Release();
  OutStream.Release();
}

void CCoderMixerMT::AddCoder(ICompressCoder *coder)
{
  _coders.Add(CCoder());
  _coders.Back().Coder = coder;
}

void CCoderMixerMT::ReInit()
{
  for(int i = 0; i < _coders.Size(); i++)
    _coders[i].ReInit();
}

STDMETHODIMP CCoderMixerMT::Code(ISequentialInStream *inStream,
    ISequentialOutStream *outStream, 
    const UInt64 * /* inSize */, const UInt64 * /* outSize */,
    ICompressProgressInfo *progress)
{
  _coders.Front().InStream = inStream;
  int i;
  _coders.Back().OutStream = outStream;

  for (i = 0; i < _coders.Size(); i++)
    if (i != _progressCoderIndex)
    {
      RINOK(_coders[i].Create());
    }

  while (_streamBinders.Size() + 1 < _coders.Size())
  {
    _streamBinders.Add(CStreamBinder());
    int i = _streamBinders.Size() - 1;
    CStreamBinder &sb = _streamBinders.Back();
    RINOK(sb.CreateEvents());
    sb.CreateStreams(&_coders[i + 1].InStream, &_coders[i].OutStream);
  }

  for(i = 0; i < _streamBinders.Size(); i++)
    _streamBinders[i].ReInit();

  for (i = 0; i < _coders.Size(); i++)
    if (i != _progressCoderIndex)
      _coders[i].Start();

  _coders[_progressCoderIndex].Code(progress);

  for (i = 0; i < _coders.Size(); i++)
    if (i != _progressCoderIndex)
      _coders[i].WaitFinish();

  for (i = 0; i < _coders.Size(); i++)
  {
    HRESULT result = _coders[i].Result;
    if (result == E_ABORT)
      return result;
  }
  for (i = 0; i < _coders.Size(); i++)
  {
    HRESULT result = _coders[i].Result;
    if (result == S_FALSE)
      return result;
  }
  for (i = 0; i < _coders.Size(); i++)
  {
    HRESULT result = _coders[i].Result;
    if (result != S_OK && result != E_FAIL)
      return result;
  }
  for (i = 0; i < _coders.Size(); i++)
  {
    HRESULT result = _coders[i].Result;
    if (result != S_OK)
      return result;
  }
  return S_OK;
}

}