Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(624)

Side by Side Diff: webrtc/tools/event_log_visualizer/analyzer.cc

Issue 2876423002: Add NetEq delay plotting to event_log_visualizer (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/tools/event_log_visualizer/analyzer.h" 11 #include "webrtc/tools/event_log_visualizer/analyzer.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <limits> 14 #include <limits>
15 #include <map> 15 #include <map>
16 #include <sstream> 16 #include <sstream>
17 #include <string> 17 #include <string>
18 #include <utility> 18 #include <utility>
19 19
20 #include "webrtc/base/checks.h" 20 #include "webrtc/base/checks.h"
21 #include "webrtc/base/format_macros.h"
21 #include "webrtc/base/logging.h" 22 #include "webrtc/base/logging.h"
22 #include "webrtc/base/rate_statistics.h" 23 #include "webrtc/base/rate_statistics.h"
23 #include "webrtc/call/audio_receive_stream.h" 24 #include "webrtc/call/audio_receive_stream.h"
24 #include "webrtc/call/audio_send_stream.h" 25 #include "webrtc/call/audio_send_stream.h"
25 #include "webrtc/call/call.h" 26 #include "webrtc/call/call.h"
26 #include "webrtc/common_types.h" 27 #include "webrtc/common_types.h"
28 #include "webrtc/modules/audio_coding/neteq/tools/audio_sink.h"
29 #include "webrtc/modules/audio_coding/neteq/tools/fake_decode_from_file.h"
30 #include "webrtc/modules/audio_coding/neteq/tools/neteq_delay_analyzer.h"
31 #include "webrtc/modules/audio_coding/neteq/tools/neteq_replacement_input.h"
32 #include "webrtc/modules/audio_coding/neteq/tools/neteq_test.h"
33 #include "webrtc/modules/audio_coding/neteq/tools/resample_input_audio_file.h"
27 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" 34 #include "webrtc/modules/congestion_controller/include/congestion_controller.h"
28 #include "webrtc/modules/include/module_common_types.h" 35 #include "webrtc/modules/include/module_common_types.h"
29 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 36 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
30 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 37 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
31 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h" 38 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
32 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" 39 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
33 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h" 40 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
34 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" 41 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
35 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" 42 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h"
36 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" 43 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
(...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 static_cast<float>(*ana_event.config.num_channels)); 1393 static_cast<float>(*ana_event.config.num_channels));
1387 return rtc::Optional<float>(); 1394 return rtc::Optional<float>();
1388 }, 1395 },
1389 audio_network_adaptation_events_, begin_time_, &time_series); 1396 audio_network_adaptation_events_, begin_time_, &time_series);
1390 plot->AppendTimeSeries(std::move(time_series)); 1397 plot->AppendTimeSeries(std::move(time_series));
1391 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); 1398 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1392 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))", 1399 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1393 kBottomMargin, kTopMargin); 1400 kBottomMargin, kTopMargin);
1394 plot->SetTitle("Reported audio encoder number of channels"); 1401 plot->SetTitle("Reported audio encoder number of channels");
1395 } 1402 }
1403
1404 class NetEqStreamInput : public test::NetEqInput {
1405 public:
1406 // Does not take any ownership, and all pointers must refer to valid objects
1407 // that outlive the one constructed.
1408 NetEqStreamInput(const std::vector<LoggedRtpPacket>* packet_stream,
ivoc 2017/05/16 13:25:50 It looks like this class is not actually modifying
hlundin-webrtc 2017/05/30 14:56:07 This is a recommended pattern. It avoids the poten
ivoc 2017/05/30 16:29:45 Acknowledged.
1409 const std::vector<uint64_t>* output_events_us)
1410 : packet_stream_(*packet_stream),
1411 output_events_us_(*output_events_us),
1412 packet_stream_it_(packet_stream_.begin()),
1413 output_events_us_it_(output_events_us_.begin()) {
1414 RTC_DCHECK(packet_stream);
1415 RTC_DCHECK(output_events_us);
1416 }
1417
1418 rtc::Optional<int64_t> NextPacketTime() const override {
1419 if (packet_stream_it_ == packet_stream_.end()) {
1420 return rtc::Optional<int64_t>();
1421 }
1422 // Convert from us to ms.
1423 return rtc::Optional<int64_t>(packet_stream_it_->timestamp / 1000);
1424 }
1425
1426 rtc::Optional<int64_t> NextOutputEventTime() const override {
1427 if (output_events_us_it_ == output_events_us_.end()) {
1428 return rtc::Optional<int64_t>();
1429 }
1430 // Convert from us to ms.
1431 return rtc::Optional<int64_t>(
1432 rtc::checked_cast<int64_t>(*output_events_us_it_ / 1000));
1433 }
1434
1435 std::unique_ptr<PacketData> PopPacket() override {
1436 if (packet_stream_it_ == packet_stream_.end()) {
1437 return std::unique_ptr<PacketData>();
1438 }
1439 std::unique_ptr<PacketData> packet_data(new PacketData());
1440 packet_data->header = packet_stream_it_->header;
1441 // Convert from us to ms.
1442 packet_data->time_ms = packet_stream_it_->timestamp / 1000.0;
1443
1444 // This is a header-only "dummy" packet. Set the payload to all zeros, with
1445 // length according to the virtual length.
1446 packet_data->payload.SetSize(packet_stream_it_->total_length);
1447 std::fill_n(packet_data->payload.data(), packet_data->payload.size(), 0);
1448
1449 ++packet_stream_it_;
1450 return packet_data;
1451 }
1452
1453 void AdvanceOutputEvent() override {
1454 if (output_events_us_it_ != output_events_us_.end()) {
1455 ++output_events_us_it_;
1456 }
1457 }
1458
1459 bool ended() const override {
1460 return packet_stream_it_ == packet_stream_.end() ||
1461 output_events_us_it_ == output_events_us_.end();
1462 }
1463
1464 rtc::Optional<RTPHeader> NextHeader() const override {
1465 if (packet_stream_it_ == packet_stream_.end()) {
1466 return rtc::Optional<RTPHeader>();
1467 }
1468 return rtc::Optional<RTPHeader>(packet_stream_it_->header);
1469 }
1470
1471 private:
1472 const std::vector<LoggedRtpPacket>& packet_stream_;
1473 const std::vector<uint64_t>& output_events_us_;
ivoc 2017/05/16 13:25:50 Since all that is used is the end iterator (for bo
hlundin-webrtc 2017/05/30 14:56:07 Done.
1474 std::vector<LoggedRtpPacket>::const_iterator packet_stream_it_;
1475 std::vector<uint64_t>::const_iterator output_events_us_it_;
1476 };
1477
1478 // Plots the jitter buffer delay profile. This will plot only for the first
1479 // incoming audio SSRC. If the stream contains more than one incoming audio
1480 // SSRC, all but the first will be ignored.
1481 void EventLogAnalyzer::CreateAudioJitterBufferGraph(
ivoc 2017/05/16 13:25:50 This function is a bit long, so I think it would b
hlundin-webrtc 2017/05/30 14:56:07 I broke out two parts but left the actual graph po
ivoc 2017/05/30 16:29:45 Looks good! Nice work.
1482 const std::string& replacement_file_name,
1483 int file_sample_rate_hz,
1484 Plot* plot) {
1485 const auto& incoming_audio_kv = std::find_if(
1486 rtp_packets_.begin(), rtp_packets_.end(),
1487 [this](std::pair<StreamId, std::vector<LoggedRtpPacket>> kv) {
1488 return kv.first.GetDirection() == kIncomingPacket &&
1489 this->IsAudioSsrc(kv.first);
1490 });
1491 if (incoming_audio_kv == rtp_packets_.end()) {
1492 // No incoming audio stream found.
1493 return;
1494 }
1495 const StreamId stream_id = incoming_audio_kv->first;
1496 const std::vector<LoggedRtpPacket>& packet_stream = incoming_audio_kv->second;
1497
1498 // Create a vector of all audio output events.
1499 std::vector<uint64_t> output_events_us;
1500 rtc::Optional<uint32_t> ssrc;
1501 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); ++i) {
1502 if (parsed_log_.GetEventType(i) == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) {
1503 uint32_t this_ssrc;
1504 parsed_log_.GetAudioPlayout(i, &this_ssrc);
1505 if (!ssrc || *ssrc == 0) {
ivoc 2017/05/16 13:25:50 Isn't it better to check that this_ssrc == stream_
hlundin-webrtc 2017/05/30 14:56:07 Won't we miss out on the events with SSRC == 0 the
ivoc 2017/05/30 16:29:45 Good point.
1506 ssrc = rtc::Optional<uint32_t>(this_ssrc);
1507 } else {
1508 RTC_DCHECK_EQ(this_ssrc, *ssrc)
1509 << "Audio output events from multiple SSRCs";
1510 }
1511 output_events_us.push_back(parsed_log_.GetTimestamp(i));
1512 } else if (parsed_log_.GetEventType(i) == ParsedRtcEventLog::LOG_END) {
1513 // End of first part of the log. The logging might restart after this, but
1514 // it makes the plot hard to interpret if we include subsequent parts.
1515 break;
1516 }
1517 }
1518
1519 // Create the NetEqInput object based on the packet and audio output events.
1520 std::unique_ptr<test::NetEqInput> input(
1521 new NetEqStreamInput(&packet_stream, &output_events_us));
1522
1523 constexpr int kReplacementPt = 127;
1524 std::set<uint8_t> cn_types;
1525 std::set<uint8_t> forbidden_types;
1526 input.reset(new test::NetEqReplacementInput(std::move(input), kReplacementPt,
1527 cn_types, forbidden_types));
1528
1529 NetEq::Config config;
1530 config.max_packets_in_buffer = 200;
1531 config.enable_fast_accelerate = true;
1532
1533 std::unique_ptr<test::VoidAudioSink> output(new test::VoidAudioSink());
1534
1535 test::NetEqTest::DecoderMap codecs;
1536
1537 // Create a "replacement decoder" that produces the decoded audio by reading
1538 // from a file rather than from the encoded payloads.
1539 std::unique_ptr<test::ResampleInputAudioFile> replacement_file(
1540 new test::ResampleInputAudioFile(replacement_file_name,
1541 file_sample_rate_hz));
1542 replacement_file->set_output_rate_hz(48000);
1543 std::unique_ptr<AudioDecoder> replacement_decoder(
1544 new test::FakeDecodeFromFile(std::move(replacement_file), 48000, false));
1545 test::NetEqTest::ExtDecoderMap ext_codecs;
1546 ext_codecs[kReplacementPt] = {replacement_decoder.get(),
1547 NetEqDecoder::kDecoderArbitrary,
1548 "replacement codec"};
1549
1550 test::DefaultNetEqTestErrorCallback error_cb;
1551 test::NetEqDelayAnalyzer delay_cb;
1552 test::NetEqTest::Callbacks callbacks;
1553 callbacks.error_callback = &error_cb;
1554 callbacks.post_insert_packet = &delay_cb;
1555 callbacks.get_audio_callback = &delay_cb;
1556
1557 test::NetEqTest test(config, codecs, ext_codecs, std::move(input),
1558 std::move(output), callbacks);
1559 test.Run();
1560
1561 std::vector<float> send_times_s;
1562 std::vector<float> arrival_delay_ms;
1563 std::vector<float> corrected_arrival_delay_ms;
1564 std::vector<rtc::Optional<float>> playout_delay_ms;
1565 std::vector<rtc::Optional<float>> target_delay_ms;
1566 delay_cb.CreateGraphs(&send_times_s, &arrival_delay_ms,
1567 &corrected_arrival_delay_ms, &playout_delay_ms,
1568 &target_delay_ms);
1569 RTC_DCHECK_EQ(send_times_s.size(), arrival_delay_ms.size());
1570 RTC_DCHECK_EQ(send_times_s.size(), corrected_arrival_delay_ms.size());
1571 RTC_DCHECK_EQ(send_times_s.size(), playout_delay_ms.size());
1572 RTC_DCHECK_EQ(send_times_s.size(), target_delay_ms.size());
1573
1574 std::map<StreamId, TimeSeries> time_series_packet_arrival;
1575 std::map<StreamId, TimeSeries> time_series_relative_packet_arrival;
1576 std::map<StreamId, TimeSeries> time_series_play_time;
1577 std::map<StreamId, TimeSeries> time_series_target_time;
1578 float min_y_axis = 0.f;
1579 float max_y_axis = 0.f;
1580 for (size_t i = 0; i < send_times_s.size(); ++i) {
1581 time_series_packet_arrival[stream_id].points.emplace_back(
1582 TimeSeriesPoint(send_times_s[i], arrival_delay_ms[i]));
1583 time_series_relative_packet_arrival[stream_id].points.emplace_back(
1584 TimeSeriesPoint(send_times_s[i], corrected_arrival_delay_ms[i]));
1585 min_y_axis = std::min(min_y_axis, corrected_arrival_delay_ms[i]);
1586 max_y_axis = std::max(max_y_axis, corrected_arrival_delay_ms[i]);
1587 if (playout_delay_ms[i]) {
1588 time_series_play_time[stream_id].points.emplace_back(
1589 TimeSeriesPoint(send_times_s[i], *playout_delay_ms[i]));
1590 min_y_axis = std::min(min_y_axis, *playout_delay_ms[i]);
1591 max_y_axis = std::max(max_y_axis, *playout_delay_ms[i]);
1592 }
1593 if (target_delay_ms[i]) {
1594 time_series_target_time[stream_id].points.emplace_back(
1595 TimeSeriesPoint(send_times_s[i], *target_delay_ms[i]));
1596 min_y_axis = std::min(min_y_axis, *target_delay_ms[i]);
1597 max_y_axis = std::max(max_y_axis, *target_delay_ms[i]);
1598 }
1599 }
1600
1601 for (auto& series : time_series_relative_packet_arrival) {
1602 series.second.label = "Relative packet arrival delay";
1603 series.second.style = LINE_GRAPH;
1604 plot->AppendTimeSeries(std::move(series.second));
1605 }
1606 for (auto& series : time_series_play_time) {
1607 series.second.label = "Playout delay";
1608 series.second.style = LINE_GRAPH;
1609 plot->AppendTimeSeries(std::move(series.second));
1610 }
1611 for (auto& series : time_series_target_time) {
1612 series.second.label = "Target delay";
1613 series.second.style = LINE_DOT_GRAPH;
1614 plot->AppendTimeSeries(std::move(series.second));
1615 }
1616
1617 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1618 plot->SetYAxis(min_y_axis, max_y_axis, "Relative delay (ms)", kBottomMargin,
1619 kTopMargin);
1620 plot->SetTitle("NetEq timing");
1621 }
1396 } // namespace plotting 1622 } // namespace plotting
1397 } // namespace webrtc 1623 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698