Add some more assertions to debug a crash.

This commit is contained in:
John Preston 2021-08-21 09:33:20 +03:00
parent fb0fcbca7f
commit 3136c0586e

View file

@ -140,6 +140,8 @@ private:
[[nodiscard]] TimePoint trackTime() const; [[nodiscard]] TimePoint trackTime() const;
void debugAssertKnownTime(int step, crl::time time) const;
const crl::weak_on_queue<VideoTrackObject> _weak; const crl::weak_on_queue<VideoTrackObject> _weak;
PlaybackOptions _options; PlaybackOptions _options;
@ -270,12 +272,40 @@ void VideoTrackObject::queueReadFrames(crl::time delay) {
} }
} }
void VideoTrackObject::debugAssertKnownTime(int step, crl::time time) const {
if (time < kTimeUnknown / 2) {
CrashReports::SetAnnotation("DebugStep", QString::number(step));
CrashReports::SetAnnotation("CheckedValue", QString::number(time));
CrashReports::SetAnnotation(
"_syncTimePoint.trackTime",
QString::number(_syncTimePoint.trackTime));
CrashReports::SetAnnotation(
"_syncTimePoint.worldTime",
QString::number(_syncTimePoint.worldTime));
CrashReports::SetAnnotation(
"_pausedTime",
QString::number(_pausedTime));
CrashReports::SetAnnotation(
"_resumedTime",
QString::number(_resumedTime));
if (!_shared) {
CrashReports::SetAnnotation("_shared", "NULL");
} else {
CrashReports::SetAnnotation(
"_shared->initialized",
_shared->initialized() ? "true" : "false");
}
CrashReports::SetAnnotation("Now", QString::number(crl::now()));
Unexpected("Bad time value.");
}
}
void VideoTrackObject::readFrames() { void VideoTrackObject::readFrames() {
if (interrupted()) { if (interrupted()) {
return; return;
} }
auto time = trackTime().trackTime; auto time = trackTime().trackTime;
Assert(1 && time >= kTimeUnknown / 2); // Debugging a crash. debugAssertKnownTime(1, time);
while (true) { while (true) {
const auto result = readEnoughFrames(time); const auto result = readEnoughFrames(time);
v::match(result, [&](FrameResult result) { v::match(result, [&](FrameResult result) {
@ -286,7 +316,7 @@ void VideoTrackObject::readFrames() {
const auto duration = computeDuration(); const auto duration = computeDuration();
Assert(duration != kDurationUnavailable); Assert(duration != kDurationUnavailable);
time -= duration; time -= duration;
Assert(2 && time >= kTimeUnknown / 2); // Debugging a crash. debugAssertKnownTime(2, time);
} }
}, [&](Shared::PrepareNextCheck delay) { }, [&](Shared::PrepareNextCheck delay) {
Expects(delay == kTimeUnknown || delay > 0); Expects(delay == kTimeUnknown || delay > 0);
@ -533,8 +563,7 @@ void VideoTrackObject::setSpeed(float64 speed) {
} }
if (_syncTimePoint.valid()) { if (_syncTimePoint.valid()) {
_syncTimePoint = trackTime(); _syncTimePoint = trackTime();
// Debugging a crash. debugAssertKnownTime(3, _syncTimePoint.trackTime);
Assert(3 && _syncTimePoint.trackTime >= kTimeUnknown / 2);
} }
_options.speed = speed; _options.speed = speed;
} }
@ -622,8 +651,7 @@ bool VideoTrackObject::processFirstFrame() {
if (frame.isNull()) { if (frame.isNull()) {
return false; return false;
} }
// Debugging a crash. debugAssertKnownTime(4, _syncTimePoint.trackTime);
Assert(4 && _syncTimePoint.trackTime >= kTimeUnknown / 2);
_shared->init(std::move(frame), _syncTimePoint.trackTime); _shared->init(std::move(frame), _syncTimePoint.trackTime);
callReady(); callReady();
queueReadFrames(); queueReadFrames();
@ -647,8 +675,7 @@ bool VideoTrackObject::fillStateFromFrame() {
return false; return false;
} }
_syncTimePoint.trackTime = position; _syncTimePoint.trackTime = position;
// Debugging a crash. debugAssertKnownTime(5, _syncTimePoint.trackTime);
Assert(5 && _syncTimePoint.trackTime >= kTimeUnknown / 2);
return true; return true;
} }
@ -675,8 +702,7 @@ void VideoTrackObject::callReady() {
} }
TimePoint VideoTrackObject::trackTime() const { TimePoint VideoTrackObject::trackTime() const {
// Debugging a crash. debugAssertKnownTime(7, _syncTimePoint.trackTime);
Assert(7 && _syncTimePoint.trackTime >= kTimeUnknown / 2);
auto result = TimePoint(); auto result = TimePoint();
result.worldTime = (_pausedTime != kTimeUnknown) result.worldTime = (_pausedTime != kTimeUnknown)
@ -686,6 +712,8 @@ TimePoint VideoTrackObject::trackTime() const {
result.trackTime = _syncTimePoint.trackTime; result.trackTime = _syncTimePoint.trackTime;
return result; return result;
} }
debugAssertKnownTime(8, _syncTimePoint.worldTime);
debugAssertKnownTime(9, result.worldTime);
Assert(_resumedTime != kTimeUnknown); Assert(_resumedTime != kTimeUnknown);
if (_options.syncVideoByAudio && _audioId.externalPlayId()) { if (_options.syncVideoByAudio && _audioId.externalPlayId()) {
@ -693,13 +721,14 @@ TimePoint VideoTrackObject::trackTime() const {
const auto point = mixer->getExternalSyncTimePoint(_audioId); const auto point = mixer->getExternalSyncTimePoint(_audioId);
if (point && point.worldTime > _resumedTime) { if (point && point.worldTime > _resumedTime) {
_syncTimePoint = point; _syncTimePoint = point;
// Debugging a crash. debugAssertKnownTime(6, _syncTimePoint.trackTime);
Assert(6 && _syncTimePoint.trackTime >= kTimeUnknown / 2); debugAssertKnownTime(10, _syncTimePoint.worldTime);
} }
} }
const auto adjust = (result.worldTime - _syncTimePoint.worldTime); const auto adjust = (result.worldTime - _syncTimePoint.worldTime);
result.trackTime = _syncTimePoint.trackTime result.trackTime = _syncTimePoint.trackTime
+ crl::time(std::round(adjust * _options.speed)); + crl::time(std::round(adjust * _options.speed));
debugAssertKnownTime(11, result.trackTime);
return result; return result;
} }