|
1 // CoderMixer2.cpp |
|
2 |
|
3 #include "StdAfx.h" |
|
4 |
|
5 #include "CoderMixer2.h" |
|
6 |
|
7 namespace NCoderMixer { |
|
8 |
|
9 CBindReverseConverter::CBindReverseConverter(const CBindInfo &srcBindInfo): |
|
10 _srcBindInfo(srcBindInfo) |
|
11 { |
|
12 srcBindInfo.GetNumStreams(NumSrcInStreams, _numSrcOutStreams); |
|
13 |
|
14 UInt32 j; |
|
15 for (j = 0; j < NumSrcInStreams; j++) |
|
16 { |
|
17 _srcInToDestOutMap.Add(0); |
|
18 DestOutToSrcInMap.Add(0); |
|
19 } |
|
20 for (j = 0; j < _numSrcOutStreams; j++) |
|
21 { |
|
22 _srcOutToDestInMap.Add(0); |
|
23 _destInToSrcOutMap.Add(0); |
|
24 } |
|
25 |
|
26 UInt32 destInOffset = 0; |
|
27 UInt32 destOutOffset = 0; |
|
28 UInt32 srcInOffset = NumSrcInStreams; |
|
29 UInt32 srcOutOffset = _numSrcOutStreams; |
|
30 |
|
31 for (int i = srcBindInfo.Coders.Size() - 1; i >= 0; i--) |
|
32 { |
|
33 const CCoderStreamsInfo &srcCoderInfo = srcBindInfo.Coders[i]; |
|
34 |
|
35 srcInOffset -= srcCoderInfo.NumInStreams; |
|
36 srcOutOffset -= srcCoderInfo.NumOutStreams; |
|
37 |
|
38 UInt32 j; |
|
39 for (j = 0; j < srcCoderInfo.NumInStreams; j++, destOutOffset++) |
|
40 { |
|
41 UInt32 index = srcInOffset + j; |
|
42 _srcInToDestOutMap[index] = destOutOffset; |
|
43 DestOutToSrcInMap[destOutOffset] = index; |
|
44 } |
|
45 for (j = 0; j < srcCoderInfo.NumOutStreams; j++, destInOffset++) |
|
46 { |
|
47 UInt32 index = srcOutOffset + j; |
|
48 _srcOutToDestInMap[index] = destInOffset; |
|
49 _destInToSrcOutMap[destInOffset] = index; |
|
50 } |
|
51 } |
|
52 } |
|
53 |
|
54 void CBindReverseConverter::CreateReverseBindInfo(CBindInfo &destBindInfo) |
|
55 { |
|
56 destBindInfo.Coders.Clear(); |
|
57 destBindInfo.BindPairs.Clear(); |
|
58 destBindInfo.InStreams.Clear(); |
|
59 destBindInfo.OutStreams.Clear(); |
|
60 |
|
61 int i; |
|
62 for (i = _srcBindInfo.Coders.Size() - 1; i >= 0; i--) |
|
63 { |
|
64 const CCoderStreamsInfo &srcCoderInfo = _srcBindInfo.Coders[i]; |
|
65 CCoderStreamsInfo destCoderInfo; |
|
66 destCoderInfo.NumInStreams = srcCoderInfo.NumOutStreams; |
|
67 destCoderInfo.NumOutStreams = srcCoderInfo.NumInStreams; |
|
68 destBindInfo.Coders.Add(destCoderInfo); |
|
69 } |
|
70 for (i = _srcBindInfo.BindPairs.Size() - 1; i >= 0; i--) |
|
71 { |
|
72 const CBindPair &srcBindPair = _srcBindInfo.BindPairs[i]; |
|
73 CBindPair destBindPair; |
|
74 destBindPair.InIndex = _srcOutToDestInMap[srcBindPair.OutIndex]; |
|
75 destBindPair.OutIndex = _srcInToDestOutMap[srcBindPair.InIndex]; |
|
76 destBindInfo.BindPairs.Add(destBindPair); |
|
77 } |
|
78 for (i = 0; i < _srcBindInfo.InStreams.Size(); i++) |
|
79 destBindInfo.OutStreams.Add(_srcInToDestOutMap[_srcBindInfo.InStreams[i]]); |
|
80 for (i = 0; i < _srcBindInfo.OutStreams.Size(); i++) |
|
81 destBindInfo.InStreams.Add(_srcOutToDestInMap[_srcBindInfo.OutStreams[i]]); |
|
82 } |
|
83 |
|
84 CCoderInfo2::CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams): |
|
85 NumInStreams(numInStreams), |
|
86 NumOutStreams(numOutStreams) |
|
87 { |
|
88 InSizes.Reserve(NumInStreams); |
|
89 InSizePointers.Reserve(NumInStreams); |
|
90 OutSizePointers.Reserve(NumOutStreams); |
|
91 OutSizePointers.Reserve(NumOutStreams); |
|
92 } |
|
93 |
|
94 static void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes, |
|
95 CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems) |
|
96 { |
|
97 sizes.Clear(); |
|
98 sizePointers.Clear(); |
|
99 for(UInt32 i = 0; i < numItems; i++) |
|
100 { |
|
101 if (srcSizes == 0 || srcSizes[i] == NULL) |
|
102 { |
|
103 sizes.Add(0); |
|
104 sizePointers.Add(NULL); |
|
105 } |
|
106 else |
|
107 { |
|
108 sizes.Add(*srcSizes[i]); |
|
109 sizePointers.Add(&sizes.Back()); |
|
110 } |
|
111 } |
|
112 } |
|
113 |
|
114 void CCoderInfo2::SetCoderInfo(const UInt64 **inSizes, |
|
115 const UInt64 **outSizes) |
|
116 { |
|
117 SetSizes(inSizes, InSizes, InSizePointers, NumInStreams); |
|
118 SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams); |
|
119 } |
|
120 |
|
121 } |