CoderMixer2.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // CoderMixer2.h
  2. #ifndef __CODER_MIXER2_H
  3. #define __CODER_MIXER2_H
  4. #include "../../../Common/MyVector.h"
  5. #include "../../../Common/Types.h"
  6. #include "../../../Common/MyCom.h"
  7. #include "../../ICoder.h"
  8. namespace NCoderMixer {
  9. struct CBindPair
  10. {
  11. UInt32 InIndex;
  12. UInt32 OutIndex;
  13. };
  14. struct CCoderStreamsInfo
  15. {
  16. UInt32 NumInStreams;
  17. UInt32 NumOutStreams;
  18. };
  19. struct CBindInfo
  20. {
  21. CRecordVector<CCoderStreamsInfo> Coders;
  22. CRecordVector<CBindPair> BindPairs;
  23. CRecordVector<UInt32> InStreams;
  24. CRecordVector<UInt32> OutStreams;
  25. void Clear()
  26. {
  27. Coders.Clear();
  28. BindPairs.Clear();
  29. InStreams.Clear();
  30. OutStreams.Clear();
  31. }
  32. /*
  33. UInt32 GetCoderStartOutStream(UInt32 coderIndex) const
  34. {
  35. UInt32 numOutStreams = 0;
  36. for (UInt32 i = 0; i < coderIndex; i++)
  37. numOutStreams += Coders[i].NumOutStreams;
  38. return numOutStreams;
  39. }
  40. */
  41. void GetNumStreams(UInt32 &numInStreams, UInt32 &numOutStreams) const
  42. {
  43. numInStreams = 0;
  44. numOutStreams = 0;
  45. for (int i = 0; i < Coders.Size(); i++)
  46. {
  47. const CCoderStreamsInfo &coderStreamsInfo = Coders[i];
  48. numInStreams += coderStreamsInfo.NumInStreams;
  49. numOutStreams += coderStreamsInfo.NumOutStreams;
  50. }
  51. }
  52. int FindBinderForInStream(UInt32 inStream) const
  53. {
  54. for (int i = 0; i < BindPairs.Size(); i++)
  55. if (BindPairs[i].InIndex == inStream)
  56. return i;
  57. return -1;
  58. }
  59. int FindBinderForOutStream(UInt32 outStream) const
  60. {
  61. for (int i = 0; i < BindPairs.Size(); i++)
  62. if (BindPairs[i].OutIndex == outStream)
  63. return i;
  64. return -1;
  65. }
  66. UInt32 GetCoderInStreamIndex(UInt32 coderIndex) const
  67. {
  68. UInt32 streamIndex = 0;
  69. for (UInt32 i = 0; i < coderIndex; i++)
  70. streamIndex += Coders[i].NumInStreams;
  71. return streamIndex;
  72. }
  73. UInt32 GetCoderOutStreamIndex(UInt32 coderIndex) const
  74. {
  75. UInt32 streamIndex = 0;
  76. for (UInt32 i = 0; i < coderIndex; i++)
  77. streamIndex += Coders[i].NumOutStreams;
  78. return streamIndex;
  79. }
  80. void FindInStream(UInt32 streamIndex, UInt32 &coderIndex,
  81. UInt32 &coderStreamIndex) const
  82. {
  83. for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)
  84. {
  85. UInt32 curSize = Coders[coderIndex].NumInStreams;
  86. if (streamIndex < curSize)
  87. {
  88. coderStreamIndex = streamIndex;
  89. return;
  90. }
  91. streamIndex -= curSize;
  92. }
  93. throw 1;
  94. }
  95. void FindOutStream(UInt32 streamIndex, UInt32 &coderIndex,
  96. UInt32 &coderStreamIndex) const
  97. {
  98. for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)
  99. {
  100. UInt32 curSize = Coders[coderIndex].NumOutStreams;
  101. if (streamIndex < curSize)
  102. {
  103. coderStreamIndex = streamIndex;
  104. return;
  105. }
  106. streamIndex -= curSize;
  107. }
  108. throw 1;
  109. }
  110. };
  111. class CBindReverseConverter
  112. {
  113. UInt32 _numSrcOutStreams;
  114. NCoderMixer::CBindInfo _srcBindInfo;
  115. CRecordVector<UInt32> _srcInToDestOutMap;
  116. CRecordVector<UInt32> _srcOutToDestInMap;
  117. CRecordVector<UInt32> _destInToSrcOutMap;
  118. public:
  119. UInt32 NumSrcInStreams;
  120. CRecordVector<UInt32> DestOutToSrcInMap;
  121. CBindReverseConverter(const NCoderMixer::CBindInfo &srcBindInfo);
  122. void CreateReverseBindInfo(NCoderMixer::CBindInfo &destBindInfo);
  123. };
  124. struct CCoderInfo2
  125. {
  126. CMyComPtr<ICompressCoder> Coder;
  127. CMyComPtr<ICompressCoder2> Coder2;
  128. UInt32 NumInStreams;
  129. UInt32 NumOutStreams;
  130. CRecordVector<UInt64> InSizes;
  131. CRecordVector<UInt64> OutSizes;
  132. CRecordVector<const UInt64 *> InSizePointers;
  133. CRecordVector<const UInt64 *> OutSizePointers;
  134. CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams);
  135. void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);
  136. HRESULT QueryInterface(REFGUID iid, void** pp) const
  137. {
  138. IUnknown *p = Coder ? (IUnknown *)Coder : (IUnknown *)Coder2;
  139. return p->QueryInterface(iid, pp);
  140. }
  141. };
  142. class CCoderMixer2
  143. {
  144. public:
  145. virtual HRESULT SetBindInfo(const CBindInfo &bindInfo) = 0;
  146. virtual void ReInit() = 0;
  147. virtual void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes) = 0;
  148. };
  149. }
  150. #endif