Timecodes and keyframes are always sorted, so fix some code that assumed they could be unsorted

Originally committed to SVN as r5083.
This commit is contained in:
Thomas Goyne 2010-12-31 23:53:23 +00:00
parent 17c07cc131
commit 4fdad923ad
3 changed files with 16 additions and 55 deletions

View File

@ -92,7 +92,6 @@ class AudioMarkerProviderKeyframes : public AudioMarkerProvider {
keyframe_samples.push_back(AudioMarkerKeyframe( keyframe_samples.push_back(AudioMarkerKeyframe(
controller->SamplesFromMilliseconds(vc->TimeAtFrame(raw_keyframes[i])))); controller->SamplesFromMilliseconds(vc->TimeAtFrame(raw_keyframes[i]))));
} }
std::sort(keyframe_samples.begin(), keyframe_samples.end());
AnnounceMarkerMoved(); AnnounceMarkerMoved();
} }

View File

@ -199,43 +199,17 @@ void MatroskaWrapper::Parse() {
} }
} }
// Copy raw rawFrames.reserve(frames.size());
std::copy(frames.begin(), frames.end(), std::back_inserter(rawFrames));
// Process timecodes and keyframes
frames.sort();
int i = 0;
for (std::list<MkvFrame>::iterator cur=frames.begin();cur!=frames.end();cur++) { for (std::list<MkvFrame>::iterator cur=frames.begin();cur!=frames.end();cur++) {
rawFrames.push_back(*cur); if (cur->isKey) keyFrames.push_back(i);
} bytePos.Add(cur->filePos);
timecodes.push_back(cur->time);
bool sortFirst = true; i++;
if (sortFirst) {
// Process timecodes and keyframes
frames.sort();
MkvFrame curFrame(false,0,0);
int i = 0;
for (std::list<MkvFrame>::iterator cur=frames.begin();cur!=frames.end();cur++) {
curFrame = *cur;
if (curFrame.isKey) keyFrames.push_back(i);
bytePos.Add(curFrame.filePos);
timecodes.push_back(curFrame.time);
i++;
}
}
else {
// Process keyframes
MkvFrame curFrame(false,0,0);
int i = 0;
for (std::list<MkvFrame>::iterator cur=frames.begin();cur!=frames.end();cur++) {
curFrame = *cur;
if (curFrame.isKey) keyFrames.push_back(i);
bytePos.Add(curFrame.filePos);
i++;
}
// Process timecodes
frames.sort();
for (std::list<MkvFrame>::iterator cur=frames.begin();cur!=frames.end();cur++) {
curFrame = *cur;
timecodes.push_back(curFrame.time);
}
} }
} }

View File

@ -346,26 +346,14 @@ void VideoSlider::OnKeyDown(wxKeyEvent &event) {
// Snap to keyframe // Snap to keyframe
if (shift && !ctrl && !alt) { if (shift && !ctrl && !alt) {
if (direction != 0) { if (direction != 0) {
// Prepare std::vector<int>::iterator pos = std::lower_bound(keyframes.begin(), keyframes.end(), val);
int prevKey = 0;
int nextKey = max;
int keys = keyframes.size();
// Find previous keyframe if (direction < 0 && val != 0 && (pos == keyframes.end() || *pos == val))
// This algorithm does unnecessary loops, but it ensures it works even if keyframes are out of order. --pos;
for (int i=0;i<keys;i++) { if (direction > 0 && pos != keyframes.end())
int temp = keyframes[i]; ++pos;
if (temp < val && temp > prevKey) prevKey = temp;
}
// Find next keyframe VideoContext::Get()->JumpToFrame(pos == keyframes.end() ? max : *pos);
for (int i=0;i<keys;i++) {
int temp = keyframes[i];
if (temp > val && temp < nextKey) nextKey = temp;
}
if (direction == -1) VideoContext::Get()->JumpToFrame(prevKey);
if (direction == 1) VideoContext::Get()->JumpToFrame(nextKey);
return; return;
} }
} }