Replace tracks with successfully processed mOutputTracks copies. Else clear and delete mOutputTracks copies.
| 101 | // Replace tracks with successfully processed mOutputTracks copies. |
| 102 | // Else clear and delete mOutputTracks copies. |
| 103 | void EffectOutputTracks::Commit() |
| 104 | { |
| 105 | if (!mOutputTracks) { |
| 106 | // Already committed, violating precondition. Maybe wrong intent... |
| 107 | assert(false); |
| 108 | // ... but harmless |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | size_t cnt = mOMap.size(); |
| 113 | size_t i = 0; |
| 114 | |
| 115 | while (!mOutputTracks->empty()) { |
| 116 | const auto pOutputTrack = *mOutputTracks->begin(); |
| 117 | |
| 118 | // If tracks were removed from mOutputTracks, then there will be |
| 119 | // tracks in the map that must be removed from mTracks. |
| 120 | while (i < cnt && mOMap[i] != pOutputTrack) { |
| 121 | const auto t = mIMap[i]; |
| 122 | // Class invariant justifies the assertion |
| 123 | assert(t); |
| 124 | ++i; |
| 125 | mTracks.Remove(*t); |
| 126 | } |
| 127 | |
| 128 | // The output track, still in the list, must also have been placed in |
| 129 | // the map |
| 130 | assert(i < cnt); |
| 131 | |
| 132 | // Find the input track it corresponds to |
| 133 | if (!mIMap[i]) |
| 134 | // This track was an addition to output tracks; add it to mTracks |
| 135 | mTracks.AppendOne(std::move(*mOutputTracks)); |
| 136 | else if ( |
| 137 | mEffectType != EffectTypeNone && mEffectType != EffectTypeAnalyze) |
| 138 | // Replace mTracks entry with the new track |
| 139 | mTracks.ReplaceOne(*mIMap[i], std::move(*mOutputTracks)); |
| 140 | else |
| 141 | // This output track was just a placeholder for pre-processing. Discard |
| 142 | // it. |
| 143 | mOutputTracks->Remove(*pOutputTrack); |
| 144 | ++i; |
| 145 | } |
| 146 | |
| 147 | // If tracks were removed from mOutputTracks, then there may be tracks |
| 148 | // left at the end of the map that must be removed from mTracks. |
| 149 | while (i < cnt) { |
| 150 | const auto t = mIMap[i]; |
| 151 | // Class invariant justifies the assertion |
| 152 | assert(t); |
| 153 | ++i; |
| 154 | mTracks.Remove(*t); |
| 155 | } |
| 156 | |
| 157 | // Reset map |
| 158 | mIMap.clear(); |
| 159 | mOMap.clear(); |
| 160 |