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

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

Issue 2876423002: Add NetEq delay plotting to event_log_visualizer (Closed)
Patch Set: Updated after first review Created 3 years, 6 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,
1409 const std::vector<uint64_t>* output_events_us)
1410 : packet_stream_(*packet_stream),
1411 packet_stream_it_(packet_stream_.begin()),
1412 output_events_us_it_(output_events_us->begin()),
1413 output_events_us_end_(output_events_us->end()) {
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 std::vector<LoggedRtpPacket>::const_iterator packet_stream_it_;
1474 std::vector<uint64_t>::const_iterator output_events_us_it_;
1475 const std::vector<uint64_t>::const_iterator output_events_us_end_;
1476 };
1477
1478 namespace {
1479 // Creates a vector of all audio output events.
1480 void CreateOutputEventVector(const ParsedRtcEventLog& parsed_log,
1481 std::vector<uint64_t>* output_events_us) {
1482 rtc::Optional<uint32_t> ssrc;
1483 for (size_t i = 0; i < parsed_log.GetNumberOfEvents(); ++i) {
1484 if (parsed_log.GetEventType(i) == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) {
1485 uint32_t this_ssrc;
1486 parsed_log.GetAudioPlayout(i, &this_ssrc);
1487 if (!ssrc || *ssrc == 0) {
1488 ssrc = rtc::Optional<uint32_t>(this_ssrc);
1489 } else {
1490 RTC_DCHECK_EQ(this_ssrc, *ssrc)
1491 << "Audio output events from multiple SSRCs";
1492 }
1493 output_events_us->push_back(parsed_log.GetTimestamp(i));
1494 } else if (parsed_log.GetEventType(i) == ParsedRtcEventLog::LOG_END) {
1495 // End of first part of the log. The logging might restart after this, but
1496 // it makes the plot hard to interpret if we include subsequent parts.
1497 break;
1498 }
1499 }
1500 }
1501
1502 // Creates a NetEq test object and all necessary input and output helpers. Runs
1503 // the test and returns the NetEqDelayAnalyzer object that was used to
1504 // instrument the test.
1505 std::unique_ptr<test::NetEqDelayAnalyzer> CreateNetEqTestAndRun(
1506 const std::vector<LoggedRtpPacket>* packet_stream,
1507 const std::vector<uint64_t>* output_events_us,
1508 const std::string& replacement_file_name,
1509 int file_sample_rate_hz) {
1510 std::unique_ptr<test::NetEqInput> input(
1511 new NetEqStreamInput(packet_stream, output_events_us));
1512
1513 constexpr int kReplacementPt = 127;
1514 std::set<uint8_t> cn_types;
1515 std::set<uint8_t> forbidden_types;
1516 input.reset(new test::NetEqReplacementInput(std::move(input), kReplacementPt,
1517 cn_types, forbidden_types));
1518
1519 NetEq::Config config;
1520 config.max_packets_in_buffer = 200;
1521 config.enable_fast_accelerate = true;
1522
1523 std::unique_ptr<test::VoidAudioSink> output(new test::VoidAudioSink());
1524
1525 test::NetEqTest::DecoderMap codecs;
1526
1527 // Create a "replacement decoder" that produces the decoded audio by reading
1528 // from a file rather than from the encoded payloads.
1529 std::unique_ptr<test::ResampleInputAudioFile> replacement_file(
1530 new test::ResampleInputAudioFile(replacement_file_name,
1531 file_sample_rate_hz));
1532 replacement_file->set_output_rate_hz(48000);
1533 std::unique_ptr<AudioDecoder> replacement_decoder(
1534 new test::FakeDecodeFromFile(std::move(replacement_file), 48000, false));
1535 test::NetEqTest::ExtDecoderMap ext_codecs;
1536 ext_codecs[kReplacementPt] = {replacement_decoder.get(),
1537 NetEqDecoder::kDecoderArbitrary,
1538 "replacement codec"};
1539
1540 std::unique_ptr<test::NetEqDelayAnalyzer> delay_cb(
1541 new test::NetEqDelayAnalyzer);
1542 test::DefaultNetEqTestErrorCallback error_cb;
1543 test::NetEqTest::Callbacks callbacks;
1544 callbacks.error_callback = &error_cb;
1545 callbacks.post_insert_packet = delay_cb.get();
1546 callbacks.get_audio_callback = delay_cb.get();
1547
1548 test::NetEqTest test(config, codecs, ext_codecs, std::move(input),
1549 std::move(output), callbacks);
1550 test.Run();
1551 return delay_cb;
1552 }
1553 } // namespace
1554
1555 // Plots the jitter buffer delay profile. This will plot only for the first
1556 // incoming audio SSRC. If the stream contains more than one incoming audio
1557 // SSRC, all but the first will be ignored.
1558 void EventLogAnalyzer::CreateAudioJitterBufferGraph(
1559 const std::string& replacement_file_name,
1560 int file_sample_rate_hz,
1561 Plot* plot) {
1562 const auto& incoming_audio_kv = std::find_if(
1563 rtp_packets_.begin(), rtp_packets_.end(),
1564 [this](std::pair<StreamId, std::vector<LoggedRtpPacket>> kv) {
1565 return kv.first.GetDirection() == kIncomingPacket &&
1566 this->IsAudioSsrc(kv.first);
1567 });
1568 if (incoming_audio_kv == rtp_packets_.end()) {
1569 // No incoming audio stream found.
1570 return;
1571 }
1572
1573 std::vector<uint64_t> output_events_us;
1574 CreateOutputEventVector(parsed_log_, &output_events_us);
1575
1576 auto delay_cb =
1577 CreateNetEqTestAndRun(&incoming_audio_kv->second, &output_events_us,
1578 replacement_file_name, file_sample_rate_hz);
1579
1580 std::vector<float> send_times_s;
1581 std::vector<float> arrival_delay_ms;
1582 std::vector<float> corrected_arrival_delay_ms;
1583 std::vector<rtc::Optional<float>> playout_delay_ms;
1584 std::vector<rtc::Optional<float>> target_delay_ms;
1585 delay_cb->CreateGraphs(&send_times_s, &arrival_delay_ms,
1586 &corrected_arrival_delay_ms, &playout_delay_ms,
1587 &target_delay_ms);
1588 RTC_DCHECK_EQ(send_times_s.size(), arrival_delay_ms.size());
1589 RTC_DCHECK_EQ(send_times_s.size(), corrected_arrival_delay_ms.size());
1590 RTC_DCHECK_EQ(send_times_s.size(), playout_delay_ms.size());
1591 RTC_DCHECK_EQ(send_times_s.size(), target_delay_ms.size());
1592
1593 std::map<StreamId, TimeSeries> time_series_packet_arrival;
1594 std::map<StreamId, TimeSeries> time_series_relative_packet_arrival;
1595 std::map<StreamId, TimeSeries> time_series_play_time;
1596 std::map<StreamId, TimeSeries> time_series_target_time;
1597 float min_y_axis = 0.f;
1598 float max_y_axis = 0.f;
1599 const StreamId stream_id = incoming_audio_kv->first;
1600 for (size_t i = 0; i < send_times_s.size(); ++i) {
1601 time_series_packet_arrival[stream_id].points.emplace_back(
1602 TimeSeriesPoint(send_times_s[i], arrival_delay_ms[i]));
1603 time_series_relative_packet_arrival[stream_id].points.emplace_back(
1604 TimeSeriesPoint(send_times_s[i], corrected_arrival_delay_ms[i]));
1605 min_y_axis = std::min(min_y_axis, corrected_arrival_delay_ms[i]);
1606 max_y_axis = std::max(max_y_axis, corrected_arrival_delay_ms[i]);
1607 if (playout_delay_ms[i]) {
1608 time_series_play_time[stream_id].points.emplace_back(
1609 TimeSeriesPoint(send_times_s[i], *playout_delay_ms[i]));
1610 min_y_axis = std::min(min_y_axis, *playout_delay_ms[i]);
1611 max_y_axis = std::max(max_y_axis, *playout_delay_ms[i]);
1612 }
1613 if (target_delay_ms[i]) {
1614 time_series_target_time[stream_id].points.emplace_back(
1615 TimeSeriesPoint(send_times_s[i], *target_delay_ms[i]));
1616 min_y_axis = std::min(min_y_axis, *target_delay_ms[i]);
1617 max_y_axis = std::max(max_y_axis, *target_delay_ms[i]);
1618 }
1619 }
1620
1621 for (auto& series : time_series_relative_packet_arrival) {
1622 series.second.label = "Relative packet arrival delay";
1623 series.second.style = LINE_GRAPH;
1624 plot->AppendTimeSeries(std::move(series.second));
1625 }
1626 for (auto& series : time_series_play_time) {
1627 series.second.label = "Playout delay";
1628 series.second.style = LINE_GRAPH;
1629 plot->AppendTimeSeries(std::move(series.second));
1630 }
1631 for (auto& series : time_series_target_time) {
1632 series.second.label = "Target delay";
1633 series.second.style = LINE_DOT_GRAPH;
1634 plot->AppendTimeSeries(std::move(series.second));
1635 }
1636
1637 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1638 plot->SetYAxis(min_y_axis, max_y_axis, "Relative delay (ms)", kBottomMargin,
1639 kTopMargin);
1640 plot->SetTitle("NetEq timing");
1641 }
1396 } // namespace plotting 1642 } // namespace plotting
1397 } // namespace webrtc 1643 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698