Replace inconsistent log_segments() function in RTC event log parser

Bug: webrtc:11566
Change-Id: I739bbc29ae5423f3fedcc08e991e27fa0af840c5
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176081
Commit-Queue: Björn Terelius <terelius@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31371}
This commit is contained in:
Björn Terelius
2020-05-27 20:25:06 +02:00
committed by Commit Bot
parent 0ee4ee85dd
commit 0d1b28cf09
6 changed files with 59 additions and 59 deletions

View File

@ -1076,6 +1076,7 @@ void ParsedRtcEventLog::Clear() {
first_timestamp_ = std::numeric_limits<int64_t>::max();
last_timestamp_ = std::numeric_limits<int64_t>::min();
first_log_segment_ = LogSegment(0, std::numeric_limits<int64_t>::max());
incoming_rtp_extensions_maps_.clear();
outgoing_rtp_extensions_maps_.clear();
@ -1214,31 +1215,37 @@ ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::ParseStream(
StoreFirstAndLastTimestamp(generic_packets_sent_);
StoreFirstAndLastTimestamp(generic_packets_received_);
StoreFirstAndLastTimestamp(generic_acks_received_);
StoreFirstAndLastTimestamp(remote_estimate_events_);
// TODO(terelius): This should be cleaned up. We could also handle
// a "missing" end event, by inserting the last previous regular
// event rather than the next start event.
// Stop events could be missing due to file size limits. If so, use the
// last event, or the next start timestamp if available.
// TODO(terelius): This could be improved. Instead of using the next start
// event, we could use the timestamp of the the last previous regular event.
auto start_iter = start_log_events().begin();
auto stop_iter = stop_log_events().begin();
while (start_iter != start_log_events().end()) {
int64_t start_us = start_iter->log_time_us();
int64_t start_us = first_timestamp();
int64_t next_start_us = std::numeric_limits<int64_t>::max();
int64_t stop_us = std::numeric_limits<int64_t>::max();
if (start_iter != start_log_events().end()) {
start_us = std::min(start_us, start_iter->log_time_us());
++start_iter;
absl::optional<int64_t> next_start_us;
if (start_iter != start_log_events().end())
next_start_us.emplace(start_iter->log_time_us());
if (stop_iter != stop_log_events().end() &&
stop_iter->log_time_us() <=
next_start_us.value_or(std::numeric_limits<int64_t>::max())) {
int64_t stop_us = stop_iter->log_time_us();
RTC_PARSE_CHECK_OR_RETURN_LE(start_us, stop_us);
log_segments_.emplace_back(start_us, stop_us);
++stop_iter;
} else {
// We're missing an end event. Assume that it occurred just before the
// next start.
log_segments_.emplace_back(start_us,
next_start_us.value_or(last_timestamp()));
}
next_start_us = start_iter->log_time_us();
}
if (stop_iter != stop_log_events().end()) {
stop_us = stop_iter->log_time_us();
}
stop_us = std::min(stop_us, next_start_us);
if (stop_us == std::numeric_limits<int64_t>::max() &&
last_timestamp() != std::numeric_limits<int64_t>::min()) {
stop_us = last_timestamp();
}
RTC_PARSE_CHECK_OR_RETURN_LE(start_us, stop_us);
first_log_segment_ = LogSegment(start_us, stop_us);
if (first_timestamp_ == std::numeric_limits<int64_t>::max() &&
last_timestamp_ == std::numeric_limits<int64_t>::min()) {
first_timestamp_ = last_timestamp_ = 0;
}
return status;