Return status instead of CHECKing in event log parser.

This CL adds ParseStatus/ParseStatusOr classes and returns those instead
of CHECKing that the log is well formed. Some refactoring was required.

We also add a allow_incomplete_logs parameter to the parser which by
default is false. Setting it to true will make the parser log a warning
but return success for errors that typically indicate that the log has
been truncated. "Deeper" errors indicating log corruption still return
an error.

Bug: webrtc:11064
Change-Id: Id5bd6e321de07e250662ae3aaa5ef15f48db6d55
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/158746
Reviewed-by: Ivo Creusen <ivoc@webrtc.org>
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Commit-Queue: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29679}
This commit is contained in:
Björn Terelius
2019-11-01 14:31:46 +01:00
committed by Commit Bot
parent cc9bf6398c
commit a06048a41e
10 changed files with 1006 additions and 709 deletions

View File

@ -259,6 +259,48 @@ class ParsedRtcEventLog {
kDontParse,
kAttemptWebrtcDefaultConfig
};
class ParseStatus {
public:
static ParseStatus Success() { return ParseStatus(); }
static ParseStatus Error(std::string error, std::string file, int line) {
return ParseStatus(error, file, line);
}
bool ok() const { return error_.empty() && file_.empty() && line_ == 0; }
std::string message() const {
return error_ + " failed at " + file_ + " line " + std::to_string(line_);
}
RTC_DEPRECATED operator bool() const { return ok(); }
private:
ParseStatus() : error_(), file_(), line_(0) {}
ParseStatus(std::string error, std::string file, int line)
: error_(error), file_(file), line_(line) {}
std::string error_;
std::string file_;
int line_;
};
template <typename T>
class ParseStatusOr {
public:
ParseStatusOr(const ParseStatus& error) // NOLINT
: status_(error), value_() {}
ParseStatusOr(const T& value) // NOLINT
: status_(ParseStatus::Success()), value_(value) {}
bool ok() const { return status_.ok(); }
const T& value() const& {
RTC_DCHECK(status_.ok());
return value_;
}
std::string message() const { return status_.message(); }
const ParseStatus& status() const { return status_; }
private:
ParseStatus status_;
T value_;
};
struct LoggedRtpStreamIncoming {
LoggedRtpStreamIncoming();
@ -292,7 +334,8 @@ class ParsedRtcEventLog {
explicit ParsedRtcEventLog(
UnconfiguredHeaderExtensions parse_unconfigured_header_extensions =
UnconfiguredHeaderExtensions::kDontParse);
UnconfiguredHeaderExtensions::kDontParse,
bool allow_incomplete_log = false);
~ParsedRtcEventLog();
@ -300,14 +343,14 @@ class ParsedRtcEventLog {
// empty state.
void Clear();
// Reads an RtcEventLog file and returns true if parsing was successful.
bool ParseFile(const std::string& file_name);
// Reads an RtcEventLog file and returns success if parsing was successful.
ParseStatus ParseFile(const std::string& file_name);
// Reads an RtcEventLog from a string and returns true if successful.
bool ParseString(const std::string& s);
// Reads an RtcEventLog from a string and returns success if successful.
ParseStatus ParseString(const std::string& s);
// Reads an RtcEventLog from an istream and returns true if successful.
bool ParseStream(
// Reads an RtcEventLog from an istream and returns success if successful.
ParseStatus ParseStream(
std::istream& stream); // no-presubmit-check TODO(webrtc:8982)
MediaType GetMediaType(uint32_t ssrc, PacketDirection direction) const;
@ -567,104 +610,126 @@ class ParsedRtcEventLog {
std::vector<InferredRouteChangeEvent> GetRouteChanges() const;
private:
bool ParseStreamInternal(
ABSL_MUST_USE_RESULT ParseStatus ParseStreamInternal(
std::istream& stream); // no-presubmit-check TODO(webrtc:8982)
void StoreParsedLegacyEvent(const rtclog::Event& event);
ABSL_MUST_USE_RESULT ParseStatus
StoreParsedLegacyEvent(const rtclog::Event& event);
template <typename T>
void StoreFirstAndLastTimestamp(const std::vector<T>& v);
// Reads the arrival timestamp (in microseconds) from a rtclog::Event.
int64_t GetTimestamp(const rtclog::Event& event) const;
// Reads the header, direction, header length and packet length from the RTP
// event at |index|, and stores the values in the corresponding output
// parameters. Each output parameter can be set to nullptr if that value
// isn't needed.
// NB: The header must have space for at least IP_PACKET_SIZE bytes.
ParseStatus GetRtpHeader(const rtclog::Event& event,
PacketDirection* incoming,
uint8_t* header,
size_t* header_length,
size_t* total_length,
int* probe_cluster_id) const;
// Returns: a pointer to a header extensions map acquired from parsing
// corresponding Audio/Video Sender/Receiver config events.
// Warning: if the same SSRC is reused by both video and audio streams during
// call, extensions maps may be incorrect (the last one would be returned).
const webrtc::RtpHeaderExtensionMap* GetRtpHeader(
const rtclog::Event& event,
PacketDirection* incoming,
uint8_t* header,
size_t* header_length,
size_t* total_length,
int* probe_cluster_id) const;
const RtpHeaderExtensionMap* GetRtpHeaderExtensionMap(
PacketDirection direction,
uint32_t ssrc);
// Reads packet, direction and packet length from the RTCP event at |index|,
// and stores the values in the corresponding output parameters.
// Each output parameter can be set to nullptr if that value isn't needed.
// NB: The packet must have space for at least IP_PACKET_SIZE bytes.
void GetRtcpPacket(const rtclog::Event& event,
PacketDirection* incoming,
uint8_t* packet,
size_t* length) const;
ParseStatus GetRtcpPacket(const rtclog::Event& event,
PacketDirection* incoming,
uint8_t* packet,
size_t* length) const;
rtclog::StreamConfig GetVideoReceiveConfig(const rtclog::Event& event) const;
rtclog::StreamConfig GetVideoSendConfig(const rtclog::Event& event) const;
rtclog::StreamConfig GetAudioReceiveConfig(const rtclog::Event& event) const;
rtclog::StreamConfig GetAudioSendConfig(const rtclog::Event& event) const;
LoggedAudioPlayoutEvent GetAudioPlayout(const rtclog::Event& event) const;
LoggedBweLossBasedUpdate GetLossBasedBweUpdate(
ParseStatusOr<rtclog::StreamConfig> GetVideoReceiveConfig(
const rtclog::Event& event) const;
LoggedBweDelayBasedUpdate GetDelayBasedBweUpdate(
ParseStatusOr<rtclog::StreamConfig> GetVideoSendConfig(
const rtclog::Event& event) const;
ParseStatusOr<rtclog::StreamConfig> GetAudioReceiveConfig(
const rtclog::Event& event) const;
ParseStatusOr<rtclog::StreamConfig> GetAudioSendConfig(
const rtclog::Event& event) const;
LoggedAudioNetworkAdaptationEvent GetAudioNetworkAdaptation(
ParsedRtcEventLog::ParseStatusOr<LoggedAudioPlayoutEvent> GetAudioPlayout(
const rtclog::Event& event) const;
LoggedBweProbeClusterCreatedEvent GetBweProbeClusterCreated(
const rtclog::Event& event) const;
LoggedBweProbeFailureEvent GetBweProbeFailure(
const rtclog::Event& event) const;
LoggedBweProbeSuccessEvent GetBweProbeSuccess(
ParsedRtcEventLog::ParseStatusOr<LoggedBweLossBasedUpdate>
GetLossBasedBweUpdate(const rtclog::Event& event) const;
ParsedRtcEventLog::ParseStatusOr<LoggedBweDelayBasedUpdate>
GetDelayBasedBweUpdate(const rtclog::Event& event) const;
ParsedRtcEventLog::ParseStatusOr<LoggedAudioNetworkAdaptationEvent>
GetAudioNetworkAdaptation(const rtclog::Event& event) const;
ParsedRtcEventLog::ParseStatusOr<LoggedBweProbeClusterCreatedEvent>
GetBweProbeClusterCreated(const rtclog::Event& event) const;
ParsedRtcEventLog::ParseStatusOr<LoggedBweProbeFailureEvent>
GetBweProbeFailure(const rtclog::Event& event) const;
ParsedRtcEventLog::ParseStatusOr<LoggedBweProbeSuccessEvent>
GetBweProbeSuccess(const rtclog::Event& event) const;
ParsedRtcEventLog::ParseStatusOr<LoggedAlrStateEvent> GetAlrState(
const rtclog::Event& event) const;
LoggedAlrStateEvent GetAlrState(const rtclog::Event& event) const;
ParsedRtcEventLog::ParseStatusOr<LoggedIceCandidatePairConfig>
GetIceCandidatePairConfig(const rtclog::Event& event) const;
LoggedIceCandidatePairConfig GetIceCandidatePairConfig(
const rtclog::Event& event) const;
LoggedIceCandidatePairEvent GetIceCandidatePairEvent(
const rtclog::Event& event) const;
ParsedRtcEventLog::ParseStatusOr<LoggedIceCandidatePairEvent>
GetIceCandidatePairEvent(const rtclog::Event& event) const;
// Parsing functions for new format.
void StoreAlrStateEvent(const rtclog2::AlrState& proto);
void StoreAudioNetworkAdaptationEvent(
ParseStatus StoreAlrStateEvent(const rtclog2::AlrState& proto);
ParseStatus StoreAudioNetworkAdaptationEvent(
const rtclog2::AudioNetworkAdaptations& proto);
void StoreAudioPlayoutEvent(const rtclog2::AudioPlayoutEvents& proto);
void StoreAudioRecvConfig(const rtclog2::AudioRecvStreamConfig& proto);
void StoreAudioSendConfig(const rtclog2::AudioSendStreamConfig& proto);
void StoreBweDelayBasedUpdate(const rtclog2::DelayBasedBweUpdates& proto);
void StoreBweLossBasedUpdate(const rtclog2::LossBasedBweUpdates& proto);
void StoreBweProbeClusterCreated(const rtclog2::BweProbeCluster& proto);
void StoreBweProbeFailureEvent(const rtclog2::BweProbeResultFailure& proto);
void StoreBweProbeSuccessEvent(const rtclog2::BweProbeResultSuccess& proto);
void StoreDtlsTransportState(const rtclog2::DtlsTransportStateEvent& proto);
void StoreDtlsWritableState(const rtclog2::DtlsWritableState& proto);
void StoreGenericAckReceivedEvent(const rtclog2::GenericAckReceived& proto);
void StoreGenericPacketReceivedEvent(
ParseStatus StoreAudioPlayoutEvent(const rtclog2::AudioPlayoutEvents& proto);
ParseStatus StoreAudioRecvConfig(const rtclog2::AudioRecvStreamConfig& proto);
ParseStatus StoreAudioSendConfig(const rtclog2::AudioSendStreamConfig& proto);
ParseStatus StoreBweDelayBasedUpdate(
const rtclog2::DelayBasedBweUpdates& proto);
ParseStatus StoreBweLossBasedUpdate(
const rtclog2::LossBasedBweUpdates& proto);
ParseStatus StoreBweProbeClusterCreated(
const rtclog2::BweProbeCluster& proto);
ParseStatus StoreBweProbeFailureEvent(
const rtclog2::BweProbeResultFailure& proto);
ParseStatus StoreBweProbeSuccessEvent(
const rtclog2::BweProbeResultSuccess& proto);
ParseStatus StoreDtlsTransportState(
const rtclog2::DtlsTransportStateEvent& proto);
ParseStatus StoreDtlsWritableState(const rtclog2::DtlsWritableState& proto);
ParseStatus StoreGenericAckReceivedEvent(
const rtclog2::GenericAckReceived& proto);
ParseStatus StoreGenericPacketReceivedEvent(
const rtclog2::GenericPacketReceived& proto);
void StoreGenericPacketSentEvent(const rtclog2::GenericPacketSent& proto);
void StoreIceCandidateEvent(const rtclog2::IceCandidatePairEvent& proto);
void StoreIceCandidatePairConfig(
ParseStatus StoreGenericPacketSentEvent(
const rtclog2::GenericPacketSent& proto);
ParseStatus StoreIceCandidateEvent(
const rtclog2::IceCandidatePairEvent& proto);
ParseStatus StoreIceCandidatePairConfig(
const rtclog2::IceCandidatePairConfig& proto);
void StoreIncomingRtcpPackets(const rtclog2::IncomingRtcpPackets& proto);
void StoreIncomingRtpPackets(const rtclog2::IncomingRtpPackets& proto);
void StoreOutgoingRtcpPackets(const rtclog2::OutgoingRtcpPackets& proto);
void StoreOutgoingRtpPackets(const rtclog2::OutgoingRtpPackets& proto);
void StoreParsedNewFormatEvent(const rtclog2::EventStream& event);
void StoreRouteChangeEvent(const rtclog2::RouteChange& proto);
void StoreRemoteEstimateEvent(const rtclog2::RemoteEstimates& proto);
void StoreStartEvent(const rtclog2::BeginLogEvent& proto);
void StoreStopEvent(const rtclog2::EndLogEvent& proto);
void StoreVideoRecvConfig(const rtclog2::VideoRecvStreamConfig& proto);
void StoreVideoSendConfig(const rtclog2::VideoSendStreamConfig& proto);
ParseStatus StoreIncomingRtcpPackets(
const rtclog2::IncomingRtcpPackets& proto);
ParseStatus StoreIncomingRtpPackets(const rtclog2::IncomingRtpPackets& proto);
ParseStatus StoreOutgoingRtcpPackets(
const rtclog2::OutgoingRtcpPackets& proto);
ParseStatus StoreOutgoingRtpPackets(const rtclog2::OutgoingRtpPackets& proto);
ParseStatus StoreParsedNewFormatEvent(const rtclog2::EventStream& event);
ParseStatus StoreRouteChangeEvent(const rtclog2::RouteChange& proto);
ParseStatus StoreRemoteEstimateEvent(const rtclog2::RemoteEstimates& proto);
ParseStatus StoreStartEvent(const rtclog2::BeginLogEvent& proto);
ParseStatus StoreStopEvent(const rtclog2::EndLogEvent& proto);
ParseStatus StoreVideoRecvConfig(const rtclog2::VideoRecvStreamConfig& proto);
ParseStatus StoreVideoSendConfig(const rtclog2::VideoSendStreamConfig& proto);
// End of new parsing functions.
struct Stream {
@ -683,6 +748,7 @@ class ParsedRtcEventLog {
};
const UnconfiguredHeaderExtensions parse_unconfigured_header_extensions_;
const bool allow_incomplete_logs_;
// Make a default extension map for streams without configuration information.
// TODO(ivoc): Once configuration of audio streams is stored in the event log,