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