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