Index: webrtc/tools/event_log_visualizer/analyzer.cc |
diff --git a/webrtc/tools/event_log_visualizer/analyzer.cc b/webrtc/tools/event_log_visualizer/analyzer.cc |
index 0125914e57a8f6963f72d666b1c21d02a9ae9e32..0c90896106821e760afdd797d0001df455a52e71 100644 |
--- a/webrtc/tools/event_log_visualizer/analyzer.cc |
+++ b/webrtc/tools/event_log_visualizer/analyzer.cc |
@@ -113,84 +113,44 @@ constexpr float kRightMargin = 0.02f; |
constexpr float kBottomMargin = 0.02f; |
constexpr float kTopMargin = 0.05f; |
-class PacketSizeBytes { |
+template <typename SampleDataType, typename ExtractedType> |
+class Pointwise { |
public: |
- using DataType = LoggedRtpPacket; |
- using ResultType = size_t; |
- size_t operator()(const LoggedRtpPacket& packet) { |
- return packet.total_length; |
- } |
-}; |
+ using DataType = SampleDataType; |
+ using ResultType = ExtractedType; |
+ using FunctionType = |
+ rtc::FunctionView<rtc::Optional<ResultType>(const DataType& data)>; |
-class SequenceNumberDiff { |
- public: |
- using DataType = LoggedRtpPacket; |
- using ResultType = int64_t; |
- int64_t operator()(const LoggedRtpPacket& old_packet, |
- const LoggedRtpPacket& new_packet) { |
- return WrappingDifference(new_packet.header.sequenceNumber, |
- old_packet.header.sequenceNumber, 1ul << 16); |
+ explicit Pointwise(FunctionType get_sample) : get_sample_(get_sample) {} |
+ |
+ rtc::Optional<ResultType> operator()(DataType data) { |
+ return get_sample_(data); |
} |
+ |
+ private: |
+ FunctionType get_sample_; |
}; |
-class NetworkDelayDiff { |
+template <typename SampleDataType, typename ExtractedType> |
+class Pairwise { |
public: |
- class AbsSendTime { |
- public: |
- using DataType = LoggedRtpPacket; |
- using ResultType = double; |
- double operator()(const LoggedRtpPacket& old_packet, |
- const LoggedRtpPacket& new_packet) { |
- if (old_packet.header.extension.hasAbsoluteSendTime && |
- new_packet.header.extension.hasAbsoluteSendTime) { |
- int64_t send_time_diff = WrappingDifference( |
- new_packet.header.extension.absoluteSendTime, |
- old_packet.header.extension.absoluteSendTime, 1ul << 24); |
- int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp; |
- return static_cast<double>(recv_time_diff - |
- AbsSendTimeToMicroseconds(send_time_diff)) / |
- 1000; |
- } else { |
- return 0; |
- } |
- } |
- }; |
+ using DataType = SampleDataType; |
+ using ResultType = ExtractedType; |
+ using FunctionType = |
+ rtc::FunctionView<rtc::Optional<ResultType>(const DataType& last_sample, |
+ const DataType& sample)>; |
+ explicit Pairwise(FunctionType get_samples) |
+ : get_samples_(get_samples) {} |
+ rtc::Optional<ResultType> operator()(DataType sample) { |
+ auto result = last_sample_ ? get_samples_(*last_sample_, sample) |
+ : rtc::Optional<ResultType>(); |
+ last_sample_ = rtc::Optional<DataType>(sample); |
+ return result; |
+ } |
- class CaptureTime { |
- public: |
- using DataType = LoggedRtpPacket; |
- using ResultType = double; |
- double operator()(const LoggedRtpPacket& old_packet, |
- const LoggedRtpPacket& new_packet) { |
- int64_t send_time_diff = WrappingDifference( |
- new_packet.header.timestamp, old_packet.header.timestamp, 1ull << 32); |
- int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp; |
- |
- const double kVideoSampleRate = 90000; |
- // TODO(terelius): We treat all streams as video for now, even though |
- // audio might be sampled at e.g. 16kHz, because it is really difficult to |
- // figure out the true sampling rate of a stream. The effect is that the |
- // delay will be scaled incorrectly for non-video streams. |
- |
- double delay_change = |
- static_cast<double>(recv_time_diff) / 1000 - |
- static_cast<double>(send_time_diff) / kVideoSampleRate * 1000; |
- if (delay_change < -10000 || 10000 < delay_change) { |
- LOG(LS_WARNING) << "Very large delay change. Timestamps correct?"; |
- LOG(LS_WARNING) << "Old capture time " << old_packet.header.timestamp |
- << ", received time " << old_packet.timestamp; |
- LOG(LS_WARNING) << "New capture time " << new_packet.header.timestamp |
- << ", received time " << new_packet.timestamp; |
- LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = " |
- << static_cast<double>(recv_time_diff) / 1000000 << "s"; |
- LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = " |
- << static_cast<double>(send_time_diff) / |
- kVideoSampleRate |
- << "s"; |
- } |
- return delay_change; |
- } |
- }; |
+ private: |
+ FunctionType get_samples_; |
+ rtc::Optional<DataType> last_sample_; |
}; |
template <typename Extractor> |
@@ -198,10 +158,13 @@ class Accumulated { |
public: |
using DataType = typename Extractor::DataType; |
using ResultType = typename Extractor::ResultType; |
- ResultType operator()(const DataType& old_packet, |
- const DataType& new_packet) { |
- sum += extract(old_packet, new_packet); |
- return sum; |
+ using FunctionType = typename Extractor::FunctionType; |
+ explicit Accumulated(FunctionType get_sample) : extract(get_sample) {} |
+ rtc::Optional<ResultType> operator()(const DataType& sample) { |
+ auto result = extract(sample); |
+ if (result) |
+ sum += *result; |
+ return rtc::Optional<ResultType>(sum); |
} |
private: |
@@ -209,32 +172,68 @@ class Accumulated { |
ResultType sum = 0; |
}; |
-// For each element in data, use |Extractor| to extract a y-coordinate and |
-// store the result in a TimeSeries. |
-template <typename Extractor> |
-void Pointwise(const std::vector<typename Extractor::DataType>& data, |
- uint64_t begin_time, |
- TimeSeries* result) { |
- Extractor extract; |
- for (size_t i = 0; i < data.size(); i++) { |
- float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000; |
- float y = extract(data[i]); |
- result->points.emplace_back(x, y); |
+rtc::Optional<double> NetworkDelayAbsSendTime( |
+ const LoggedRtpPacket& old_packet, |
+ const LoggedRtpPacket& new_packet) { |
+ if (old_packet.header.extension.hasAbsoluteSendTime && |
+ new_packet.header.extension.hasAbsoluteSendTime) { |
+ int64_t send_time_diff = WrappingDifference( |
+ new_packet.header.extension.absoluteSendTime, |
+ old_packet.header.extension.absoluteSendTime, 1ul << 24); |
+ int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp; |
+ return rtc::Optional<double>( |
+ static_cast<double>(recv_time_diff - |
+ AbsSendTimeToMicroseconds(send_time_diff)) / |
+ 1000); |
+ } else { |
+ return rtc::Optional<double>(0.0); |
+ } |
+} |
+ |
+rtc::Optional<double> NetworkDelayDiffCaptureTime( |
+ const LoggedRtpPacket& old_packet, |
+ const LoggedRtpPacket& new_packet) { |
+ int64_t send_time_diff = WrappingDifference( |
+ new_packet.header.timestamp, old_packet.header.timestamp, 1ull << 32); |
+ int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp; |
+ |
+ const double kVideoSampleRate = 90000; |
+ // TODO(terelius): We treat all streams as video for now, even though |
+ // audio might be sampled at e.g. 16kHz, because it is really difficult to |
+ // figure out the true sampling rate of a stream. The effect is that the |
+ // delay will be scaled incorrectly for non-video streams. |
+ |
+ double delay_change = |
+ static_cast<double>(recv_time_diff) / 1000 - |
+ static_cast<double>(send_time_diff) / kVideoSampleRate * 1000; |
+ if (delay_change < -10000 || 10000 < delay_change) { |
+ LOG(LS_WARNING) << "Very large delay change. Timestamps correct?"; |
+ LOG(LS_WARNING) << "Old capture time " << old_packet.header.timestamp |
+ << ", received time " << old_packet.timestamp; |
+ LOG(LS_WARNING) << "New capture time " << new_packet.header.timestamp |
+ << ", received time " << new_packet.timestamp; |
+ LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = " |
+ << static_cast<double>(recv_time_diff) / 1000000 << "s"; |
+ LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = " |
+ << static_cast<double>(send_time_diff) / kVideoSampleRate |
+ << "s"; |
} |
+ return rtc::Optional<double>(delay_change); |
} |
-// For each pair of adjacent elements in |data|, use |Extractor| to extract a |
-// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate |
-// will be the time of the second element in the pair. |
+// For each element in data, use |Extractor| to extract a y-coordinate and |
+// store the result in a TimeSeries. |
template <typename Extractor> |
-void Pairwise(const std::vector<typename Extractor::DataType>& data, |
- uint64_t begin_time, |
- TimeSeries* result) { |
- Extractor extract; |
- for (size_t i = 1; i < data.size(); i++) { |
- float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000; |
- float y = extract(data[i - 1], data[i]); |
- result->points.emplace_back(x, y); |
+void Process(const std::vector<typename Extractor::DataType>& data, |
+ uint64_t begin_time, |
+ TimeSeries* result, |
+ typename Extractor::FunctionType get_sample) { |
+ Extractor extract(get_sample); |
+ for (auto& sample : data) { |
+ float x = static_cast<float>(sample.timestamp - begin_time) / 1000000; |
+ auto y = extract(sample); |
+ if (y) |
+ result->points.emplace_back(x, *y); |
} |
} |
@@ -249,22 +248,27 @@ void MovingAverage(const std::vector<typename Extractor::DataType>& data, |
uint64_t window_duration_us, |
uint64_t step, |
float y_scaling, |
- webrtc::plotting::TimeSeries* result) { |
+ TimeSeries* result, |
+ typename Extractor::FunctionType get_sample) { |
size_t window_index_begin = 0; |
size_t window_index_end = 0; |
typename Extractor::ResultType sum_in_window = 0; |
- Extractor extract; |
+ Extractor extract(get_sample); |
for (uint64_t t = begin_time; t < end_time + step; t += step) { |
while (window_index_end < data.size() && |
data[window_index_end].timestamp < t) { |
- sum_in_window += extract(data[window_index_end]); |
+ auto sample = extract(data[window_index_end]); |
++window_index_end; |
+ if (sample) |
+ sum_in_window += *sample; |
} |
while (window_index_begin < data.size() && |
data[window_index_begin].timestamp < t - window_duration_us) { |
- sum_in_window -= extract(data[window_index_begin]); |
+ auto sample = extract(data[window_index_begin]); |
++window_index_begin; |
+ if (sample) |
+ sum_in_window -= *sample; |
} |
float window_duration_s = static_cast<float>(window_duration_us) / 1000000; |
float x = static_cast<float>(t - begin_time) / 1000000; |
@@ -536,21 +540,6 @@ std::string EventLogAnalyzer::GetStreamName(StreamId stream_id) const { |
return name.str(); |
} |
-void EventLogAnalyzer::FillAudioEncoderTimeSeries( |
- Plot* plot, |
- rtc::FunctionView<rtc::Optional<float>( |
- const AudioNetworkAdaptationEvent& ana_event)> get_y) const { |
- plot->series_list_.push_back(TimeSeries()); |
- plot->series_list_.back().style = LINE_DOT_GRAPH; |
- for (auto& ana_event : audio_network_adaptation_events_) { |
- rtc::Optional<float> y = get_y(ana_event); |
- if (y) { |
- float x = static_cast<float>(ana_event.timestamp - begin_time_) / 1000000; |
- plot->series_list_.back().points.emplace_back(x, *y); |
- } |
- } |
-} |
- |
void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction, |
Plot* plot) { |
for (auto& kv : rtp_packets_) { |
@@ -565,7 +554,12 @@ void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction, |
TimeSeries time_series; |
time_series.label = GetStreamName(stream_id); |
time_series.style = BAR_GRAPH; |
- Pointwise<PacketSizeBytes>(packet_stream, begin_time_, &time_series); |
+ |
+ Process<Pointwise<LoggedRtpPacket, float>>( |
+ packet_stream, begin_time_, &time_series, |
+ [](const LoggedRtpPacket& packet) { |
+ return rtc::Optional<float>(packet.total_length); |
+ }); |
plot->series_list_.push_back(std::move(time_series)); |
} |
@@ -711,7 +705,14 @@ void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) { |
TimeSeries time_series; |
time_series.label = GetStreamName(stream_id); |
time_series.style = BAR_GRAPH; |
- Pairwise<SequenceNumberDiff>(packet_stream, begin_time_, &time_series); |
+ |
+ Process<Pairwise<LoggedRtpPacket, float>>( |
+ packet_stream, begin_time_, &time_series, |
+ [](const LoggedRtpPacket& last_sample, const LoggedRtpPacket& sample) { |
+ return rtc::Optional<float>(static_cast<float>(WrappingDifference( |
+ sample.header.sequenceNumber, last_sample.header.sequenceNumber, |
+ 1ul << 16))); |
+ }); |
plot->series_list_.push_back(std::move(time_series)); |
} |
@@ -795,15 +796,19 @@ void EventLogAnalyzer::CreateDelayChangeGraph(Plot* plot) { |
TimeSeries capture_time_data; |
capture_time_data.label = GetStreamName(stream_id) + " capture-time"; |
capture_time_data.style = BAR_GRAPH; |
- Pairwise<NetworkDelayDiff::CaptureTime>(packet_stream, begin_time_, |
- &capture_time_data); |
+ |
+ Process<Pairwise<LoggedRtpPacket, double>>( |
+ packet_stream, begin_time_, &capture_time_data, |
+ NetworkDelayDiffCaptureTime); |
plot->series_list_.push_back(std::move(capture_time_data)); |
TimeSeries send_time_data; |
send_time_data.label = GetStreamName(stream_id) + " abs-send-time"; |
send_time_data.style = BAR_GRAPH; |
- Pairwise<NetworkDelayDiff::AbsSendTime>(packet_stream, begin_time_, |
- &send_time_data); |
+ |
+ Process<Pairwise<LoggedRtpPacket, double>>( |
+ packet_stream, begin_time_, &send_time_data, NetworkDelayAbsSendTime); |
+ |
plot->series_list_.push_back(std::move(send_time_data)); |
} |
@@ -828,15 +833,18 @@ void EventLogAnalyzer::CreateAccumulatedDelayChangeGraph(Plot* plot) { |
TimeSeries capture_time_data; |
capture_time_data.label = GetStreamName(stream_id) + " capture-time"; |
capture_time_data.style = LINE_GRAPH; |
- Pairwise<Accumulated<NetworkDelayDiff::CaptureTime>>( |
- packet_stream, begin_time_, &capture_time_data); |
+ |
+ Process<Accumulated<Pairwise<LoggedRtpPacket, double>>>( |
+ packet_stream, begin_time_, &capture_time_data, |
+ NetworkDelayDiffCaptureTime); |
+ |
plot->series_list_.push_back(std::move(capture_time_data)); |
TimeSeries send_time_data; |
send_time_data.label = GetStreamName(stream_id) + " abs-send-time"; |
send_time_data.style = LINE_GRAPH; |
- Pairwise<Accumulated<NetworkDelayDiff::AbsSendTime>>( |
- packet_stream, begin_time_, &send_time_data); |
+ Process<Accumulated<Pairwise<LoggedRtpPacket, double>>>( |
+ packet_stream, begin_time_, &send_time_data, NetworkDelayAbsSendTime); |
plot->series_list_.push_back(std::move(send_time_data)); |
} |
@@ -961,9 +969,12 @@ void EventLogAnalyzer::CreateStreamBitrateGraph( |
time_series.label = GetStreamName(stream_id); |
time_series.style = LINE_GRAPH; |
double bytes_to_kilobits = 8.0 / 1000; |
- MovingAverage<PacketSizeBytes>(packet_stream, begin_time_, end_time_, |
- window_duration_, step_, bytes_to_kilobits, |
- &time_series); |
+ |
+ MovingAverage<Pointwise<LoggedRtpPacket, float>>( |
+ packet_stream, begin_time_, end_time_, window_duration_, step_, |
+ bytes_to_kilobits, &time_series, [](const LoggedRtpPacket& packet) { |
+ return rtc::Optional<float>(packet.total_length); |
+ }); |
plot->series_list_.push_back(std::move(time_series)); |
} |
@@ -1296,8 +1307,11 @@ void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) { |
} |
void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) { |
- FillAudioEncoderTimeSeries( |
- plot, [](const AudioNetworkAdaptationEvent& ana_event) { |
+ plot->series_list_.push_back(TimeSeries()); |
+ plot->series_list_.back().style = LINE_DOT_GRAPH; |
+ Process<Pointwise<AudioNetworkAdaptationEvent, float>>( |
+ audio_network_adaptation_events_, begin_time_, &plot->series_list_.back(), |
+ [](const AudioNetworkAdaptationEvent& ana_event) { |
if (ana_event.config.bitrate_bps) |
return rtc::Optional<float>( |
static_cast<float>(*ana_event.config.bitrate_bps)); |
@@ -1310,8 +1324,11 @@ void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) { |
} |
void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) { |
- FillAudioEncoderTimeSeries( |
- plot, [](const AudioNetworkAdaptationEvent& ana_event) { |
+ plot->series_list_.push_back(TimeSeries()); |
+ plot->series_list_.back().style = LINE_DOT_GRAPH; |
+ Process<Pointwise<AudioNetworkAdaptationEvent, float>>( |
+ audio_network_adaptation_events_, begin_time_, &plot->series_list_.back(), |
+ [](const AudioNetworkAdaptationEvent& ana_event) { |
if (ana_event.config.frame_length_ms) |
return rtc::Optional<float>( |
static_cast<float>(*ana_event.config.frame_length_ms)); |
@@ -1325,8 +1342,11 @@ void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) { |
void EventLogAnalyzer::CreateAudioEncoderUplinkPacketLossFractionGraph( |
Plot* plot) { |
- FillAudioEncoderTimeSeries( |
- plot, [&](const AudioNetworkAdaptationEvent& ana_event) { |
+ plot->series_list_.push_back(TimeSeries()); |
+ plot->series_list_.back().style = LINE_DOT_GRAPH; |
+ Process<Pointwise<AudioNetworkAdaptationEvent, float>>( |
+ audio_network_adaptation_events_, begin_time_, &plot->series_list_.back(), |
+ [&](const AudioNetworkAdaptationEvent& ana_event) { |
if (ana_event.config.uplink_packet_loss_fraction) |
return rtc::Optional<float>(static_cast<float>( |
*ana_event.config.uplink_packet_loss_fraction)); |
@@ -1340,8 +1360,11 @@ void EventLogAnalyzer::CreateAudioEncoderUplinkPacketLossFractionGraph( |
} |
void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) { |
- FillAudioEncoderTimeSeries( |
- plot, [&](const AudioNetworkAdaptationEvent& ana_event) { |
+ plot->series_list_.push_back(TimeSeries()); |
+ plot->series_list_.back().style = LINE_DOT_GRAPH; |
+ Process<Pointwise<AudioNetworkAdaptationEvent, float>>( |
+ audio_network_adaptation_events_, begin_time_, &plot->series_list_.back(), |
+ [&](const AudioNetworkAdaptationEvent& ana_event) { |
if (ana_event.config.enable_fec) |
return rtc::Optional<float>( |
static_cast<float>(*ana_event.config.enable_fec)); |
@@ -1354,8 +1377,11 @@ void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) { |
} |
void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) { |
- FillAudioEncoderTimeSeries( |
- plot, [&](const AudioNetworkAdaptationEvent& ana_event) { |
+ plot->series_list_.push_back(TimeSeries()); |
+ plot->series_list_.back().style = LINE_DOT_GRAPH; |
+ Process<Pointwise<AudioNetworkAdaptationEvent, float>>( |
+ audio_network_adaptation_events_, begin_time_, &plot->series_list_.back(), |
+ [&](const AudioNetworkAdaptationEvent& ana_event) { |
if (ana_event.config.enable_dtx) |
return rtc::Optional<float>( |
static_cast<float>(*ana_event.config.enable_dtx)); |
@@ -1368,8 +1394,11 @@ void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) { |
} |
void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) { |
- FillAudioEncoderTimeSeries( |
- plot, [&](const AudioNetworkAdaptationEvent& ana_event) { |
+ plot->series_list_.push_back(TimeSeries()); |
+ plot->series_list_.back().style = LINE_DOT_GRAPH; |
+ Process<Pointwise<AudioNetworkAdaptationEvent, float>>( |
+ audio_network_adaptation_events_, begin_time_, &plot->series_list_.back(), |
+ [&](const AudioNetworkAdaptationEvent& ana_event) { |
if (ana_event.config.num_channels) |
return rtc::Optional<float>( |
static_cast<float>(*ana_event.config.num_channels)); |