OLD | NEW |
---|---|
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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
449 LoggedRtcpPacket(timestamp, kRtcpRr, std::move(rtcp_packet))); | 456 LoggedRtcpPacket(timestamp, kRtcpRr, std::move(rtcp_packet))); |
450 } | 457 } |
451 } | 458 } |
452 } | 459 } |
453 break; | 460 break; |
454 } | 461 } |
455 case ParsedRtcEventLog::LOG_START: { | 462 case ParsedRtcEventLog::LOG_START: { |
456 break; | 463 break; |
457 } | 464 } |
458 case ParsedRtcEventLog::LOG_END: { | 465 case ParsedRtcEventLog::LOG_END: { |
466 log_end_events_.push_back(parsed_log_.GetTimestamp(i)); | |
459 break; | 467 break; |
460 } | 468 } |
461 case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: { | 469 case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: { |
470 uint32_t this_ssrc; | |
471 parsed_log_.GetAudioPlayout(i, &this_ssrc); | |
472 audio_playout_events_[this_ssrc].push_back(parsed_log_.GetTimestamp(i)); | |
462 break; | 473 break; |
463 } | 474 } |
464 case ParsedRtcEventLog::LOSS_BASED_BWE_UPDATE: { | 475 case ParsedRtcEventLog::LOSS_BASED_BWE_UPDATE: { |
465 LossBasedBweUpdate bwe_update; | 476 LossBasedBweUpdate bwe_update; |
466 bwe_update.timestamp = parsed_log_.GetTimestamp(i); | 477 bwe_update.timestamp = parsed_log_.GetTimestamp(i); |
467 parsed_log_.GetLossBasedBweUpdate(i, &bwe_update.new_bitrate, | 478 parsed_log_.GetLossBasedBweUpdate(i, &bwe_update.new_bitrate, |
468 &bwe_update.fraction_loss, | 479 &bwe_update.fraction_loss, |
469 &bwe_update.expected_packets); | 480 &bwe_update.expected_packets); |
470 bwe_loss_updates_.push_back(bwe_update); | 481 bwe_loss_updates_.push_back(bwe_update); |
471 break; | 482 break; |
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1389 static_cast<float>(*ana_event.config.num_channels)); | 1400 static_cast<float>(*ana_event.config.num_channels)); |
1390 return rtc::Optional<float>(); | 1401 return rtc::Optional<float>(); |
1391 }, | 1402 }, |
1392 audio_network_adaptation_events_, begin_time_, &time_series); | 1403 audio_network_adaptation_events_, begin_time_, &time_series); |
1393 plot->AppendTimeSeries(std::move(time_series)); | 1404 plot->AppendTimeSeries(std::move(time_series)); |
1394 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); | 1405 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); |
1395 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))", | 1406 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))", |
1396 kBottomMargin, kTopMargin); | 1407 kBottomMargin, kTopMargin); |
1397 plot->SetTitle("Reported audio encoder number of channels"); | 1408 plot->SetTitle("Reported audio encoder number of channels"); |
1398 } | 1409 } |
1410 | |
1411 class NetEqStreamInput : public test::NetEqInput { | |
1412 public: | |
1413 // Does not take any ownership, and all pointers must refer to valid objects | |
1414 // that outlive the one constructed. | |
1415 NetEqStreamInput(const std::vector<LoggedRtpPacket>* packet_stream, | |
1416 const std::vector<uint64_t>* output_events_us, | |
1417 rtc::Optional<uint64_t> end_time_us) | |
1418 : packet_stream_(*packet_stream), | |
1419 packet_stream_it_(packet_stream_.begin()), | |
1420 output_events_us_it_(output_events_us->begin()), | |
1421 output_events_us_end_(output_events_us->end()), | |
1422 end_time_us_(end_time_us) { | |
1423 RTC_DCHECK(packet_stream); | |
1424 RTC_DCHECK(output_events_us); | |
1425 } | |
1426 | |
1427 rtc::Optional<int64_t> NextPacketTime() const override { | |
1428 if (packet_stream_it_ == packet_stream_.end()) { | |
1429 return rtc::Optional<int64_t>(); | |
1430 } | |
1431 if (end_time_us_ && packet_stream_it_->timestamp > *end_time_us_) { | |
1432 return rtc::Optional<int64_t>(); | |
1433 } | |
1434 // Convert from us to ms. | |
1435 return rtc::Optional<int64_t>(packet_stream_it_->timestamp / 1000); | |
1436 } | |
1437 | |
1438 rtc::Optional<int64_t> NextOutputEventTime() const override { | |
1439 if (output_events_us_it_ == output_events_us_end_) { | |
1440 return rtc::Optional<int64_t>(); | |
1441 } | |
1442 if (end_time_us_ && *output_events_us_it_ > *end_time_us_) { | |
1443 return rtc::Optional<int64_t>(); | |
1444 } | |
1445 // Convert from us to ms. | |
1446 return rtc::Optional<int64_t>( | |
1447 rtc::checked_cast<int64_t>(*output_events_us_it_ / 1000)); | |
1448 } | |
1449 | |
1450 std::unique_ptr<PacketData> PopPacket() override { | |
1451 if (packet_stream_it_ == packet_stream_.end()) { | |
1452 return std::unique_ptr<PacketData>(); | |
1453 } | |
1454 std::unique_ptr<PacketData> packet_data(new PacketData()); | |
1455 packet_data->header = packet_stream_it_->header; | |
1456 // Convert from us to ms. | |
1457 packet_data->time_ms = packet_stream_it_->timestamp / 1000.0; | |
1458 | |
1459 // This is a header-only "dummy" packet. Set the payload to all zeros, with | |
1460 // length according to the virtual length. | |
1461 packet_data->payload.SetSize(packet_stream_it_->total_length); | |
1462 std::fill_n(packet_data->payload.data(), packet_data->payload.size(), 0); | |
1463 | |
1464 ++packet_stream_it_; | |
1465 return packet_data; | |
1466 } | |
1467 | |
1468 void AdvanceOutputEvent() override { | |
1469 if (output_events_us_it_ != output_events_us_end_) { | |
1470 ++output_events_us_it_; | |
1471 } | |
1472 } | |
1473 | |
1474 bool ended() const override { return !NextEventTime(); } | |
1475 | |
1476 rtc::Optional<RTPHeader> NextHeader() const override { | |
1477 if (packet_stream_it_ == packet_stream_.end()) { | |
1478 return rtc::Optional<RTPHeader>(); | |
1479 } | |
1480 return rtc::Optional<RTPHeader>(packet_stream_it_->header); | |
1481 } | |
1482 | |
1483 private: | |
1484 const std::vector<LoggedRtpPacket>& packet_stream_; | |
1485 std::vector<LoggedRtpPacket>::const_iterator packet_stream_it_; | |
1486 std::vector<uint64_t>::const_iterator output_events_us_it_; | |
1487 const std::vector<uint64_t>::const_iterator output_events_us_end_; | |
1488 const rtc::Optional<uint64_t> end_time_us_; | |
1489 }; | |
1490 | |
1491 namespace { | |
1492 // Creates a NetEq test object and all necessary input and output helpers. Runs | |
1493 // the test and returns the NetEqDelayAnalyzer object that was used to | |
1494 // instrument the test. | |
1495 std::unique_ptr<test::NetEqDelayAnalyzer> CreateNetEqTestAndRun( | |
1496 const std::vector<LoggedRtpPacket>* packet_stream, | |
1497 const std::vector<uint64_t>* output_events_us, | |
1498 rtc::Optional<uint64_t> end_time_us, | |
1499 const std::string& replacement_file_name, | |
1500 int file_sample_rate_hz) { | |
1501 std::unique_ptr<test::NetEqInput> input( | |
1502 new NetEqStreamInput(packet_stream, output_events_us, end_time_us)); | |
1503 | |
1504 constexpr int kReplacementPt = 127; | |
1505 std::set<uint8_t> cn_types; | |
1506 std::set<uint8_t> forbidden_types; | |
1507 input.reset(new test::NetEqReplacementInput(std::move(input), kReplacementPt, | |
1508 cn_types, forbidden_types)); | |
1509 | |
1510 NetEq::Config config; | |
1511 config.max_packets_in_buffer = 200; | |
1512 config.enable_fast_accelerate = true; | |
1513 | |
1514 std::unique_ptr<test::VoidAudioSink> output(new test::VoidAudioSink()); | |
1515 | |
1516 test::NetEqTest::DecoderMap codecs; | |
1517 | |
1518 // Create a "replacement decoder" that produces the decoded audio by reading | |
1519 // from a file rather than from the encoded payloads. | |
1520 std::unique_ptr<test::ResampleInputAudioFile> replacement_file( | |
1521 new test::ResampleInputAudioFile(replacement_file_name, | |
1522 file_sample_rate_hz)); | |
1523 replacement_file->set_output_rate_hz(48000); | |
1524 std::unique_ptr<AudioDecoder> replacement_decoder( | |
1525 new test::FakeDecodeFromFile(std::move(replacement_file), 48000, false)); | |
1526 test::NetEqTest::ExtDecoderMap ext_codecs; | |
1527 ext_codecs[kReplacementPt] = {replacement_decoder.get(), | |
1528 NetEqDecoder::kDecoderArbitrary, | |
1529 "replacement codec"}; | |
1530 | |
1531 std::unique_ptr<test::NetEqDelayAnalyzer> delay_cb( | |
1532 new test::NetEqDelayAnalyzer); | |
1533 test::DefaultNetEqTestErrorCallback error_cb; | |
1534 test::NetEqTest::Callbacks callbacks; | |
1535 callbacks.error_callback = &error_cb; | |
1536 callbacks.post_insert_packet = delay_cb.get(); | |
1537 callbacks.get_audio_callback = delay_cb.get(); | |
1538 | |
1539 test::NetEqTest test(config, codecs, ext_codecs, std::move(input), | |
1540 std::move(output), callbacks); | |
1541 test.Run(); | |
1542 return delay_cb; | |
1543 } | |
1544 } // namespace | |
1545 | |
1546 // Plots the jitter buffer delay profile. This will plot only for the first | |
1547 // incoming audio SSRC. If the stream contains more than one incoming audio | |
1548 // SSRC, all but the first will be ignored. | |
1549 void EventLogAnalyzer::CreateAudioJitterBufferGraph( | |
1550 const std::string& replacement_file_name, | |
1551 int file_sample_rate_hz, | |
1552 Plot* plot) { | |
1553 const auto& incoming_audio_kv = std::find_if( | |
1554 rtp_packets_.begin(), rtp_packets_.end(), | |
1555 [this](std::pair<StreamId, std::vector<LoggedRtpPacket>> kv) { | |
1556 return kv.first.GetDirection() == kIncomingPacket && | |
1557 this->IsAudioSsrc(kv.first); | |
1558 }); | |
1559 if (incoming_audio_kv == rtp_packets_.end()) { | |
1560 // No incoming audio stream found. | |
1561 return; | |
1562 } | |
1563 | |
1564 const uint32_t ssrc = incoming_audio_kv->first.GetSsrc(); | |
1565 | |
1566 std::map<uint32_t, std::vector<uint64_t>>::const_iterator output_events_it = | |
1567 audio_playout_events_.find(ssrc); | |
1568 if (output_events_it == audio_playout_events_.end()) { | |
1569 // Could not find output events with SSRC matching the input audio stream. | |
1570 // Using the first available stream of output events. | |
1571 output_events_it = audio_playout_events_.cbegin(); | |
1572 } | |
1573 | |
1574 rtc::Optional<uint64_t> end_time_us = | |
1575 log_end_events_.empty() | |
1576 ? rtc::Optional<uint64_t>() | |
1577 : rtc::Optional<uint64_t>(log_end_events_.front()); | |
1578 | |
1579 auto delay_cb = CreateNetEqTestAndRun( | |
1580 &incoming_audio_kv->second, &output_events_it->second, end_time_us, | |
1581 replacement_file_name, file_sample_rate_hz); | |
1582 | |
1583 std::vector<float> send_times_s; | |
1584 std::vector<float> arrival_delay_ms; | |
1585 std::vector<float> corrected_arrival_delay_ms; | |
1586 std::vector<rtc::Optional<float>> playout_delay_ms; | |
1587 std::vector<rtc::Optional<float>> target_delay_ms; | |
1588 delay_cb->CreateGraphs(&send_times_s, &arrival_delay_ms, | |
1589 &corrected_arrival_delay_ms, &playout_delay_ms, | |
1590 &target_delay_ms); | |
1591 RTC_DCHECK_EQ(send_times_s.size(), arrival_delay_ms.size()); | |
1592 RTC_DCHECK_EQ(send_times_s.size(), corrected_arrival_delay_ms.size()); | |
1593 RTC_DCHECK_EQ(send_times_s.size(), playout_delay_ms.size()); | |
1594 RTC_DCHECK_EQ(send_times_s.size(), target_delay_ms.size()); | |
1595 | |
1596 std::map<StreamId, TimeSeries> time_series_packet_arrival; | |
1597 std::map<StreamId, TimeSeries> time_series_relative_packet_arrival; | |
1598 std::map<StreamId, TimeSeries> time_series_play_time; | |
1599 std::map<StreamId, TimeSeries> time_series_target_time; | |
1600 float min_y_axis = 0.f; | |
1601 float max_y_axis = 0.f; | |
1602 const StreamId stream_id = incoming_audio_kv->first; | |
1603 for (size_t i = 0; i < send_times_s.size(); ++i) { | |
1604 time_series_packet_arrival[stream_id].points.emplace_back( | |
1605 TimeSeriesPoint(send_times_s[i], arrival_delay_ms[i])); | |
1606 time_series_relative_packet_arrival[stream_id].points.emplace_back( | |
1607 TimeSeriesPoint(send_times_s[i], corrected_arrival_delay_ms[i])); | |
1608 min_y_axis = std::min(min_y_axis, corrected_arrival_delay_ms[i]); | |
1609 max_y_axis = std::max(max_y_axis, corrected_arrival_delay_ms[i]); | |
1610 if (playout_delay_ms[i]) { | |
1611 time_series_play_time[stream_id].points.emplace_back( | |
1612 TimeSeriesPoint(send_times_s[i], *playout_delay_ms[i])); | |
1613 min_y_axis = std::min(min_y_axis, *playout_delay_ms[i]); | |
1614 max_y_axis = std::max(max_y_axis, *playout_delay_ms[i]); | |
1615 } | |
1616 if (target_delay_ms[i]) { | |
1617 time_series_target_time[stream_id].points.emplace_back( | |
1618 TimeSeriesPoint(send_times_s[i], *target_delay_ms[i])); | |
1619 min_y_axis = std::min(min_y_axis, *target_delay_ms[i]); | |
1620 max_y_axis = std::max(max_y_axis, *target_delay_ms[i]); | |
1621 } | |
1622 } | |
1623 | |
1624 // This code is adapted for a single stream. The creation of the streams above | |
1625 // guarantee that no more than one steam is included. If multiple streams are | |
1626 // to be plotted, they should likely be given distingt labels below. | |
terelius
2017/06/09 14:48:36
nit: "distinct"
hlundin-webrtc
2017/06/12 07:15:08
Done.
| |
1627 RTC_DCHECK_EQ(time_series_relative_packet_arrival.size(), 1); | |
1628 for (auto& series : time_series_relative_packet_arrival) { | |
1629 series.second.label = "Relative packet arrival delay"; | |
1630 series.second.style = LINE_GRAPH; | |
1631 plot->AppendTimeSeries(std::move(series.second)); | |
1632 } | |
1633 RTC_DCHECK_EQ(time_series_play_time.size(), 1); | |
1634 for (auto& series : time_series_play_time) { | |
1635 series.second.label = "Playout delay"; | |
1636 series.second.style = LINE_GRAPH; | |
1637 plot->AppendTimeSeries(std::move(series.second)); | |
1638 } | |
1639 RTC_DCHECK_EQ(time_series_target_time.size(), 1); | |
1640 for (auto& series : time_series_target_time) { | |
1641 series.second.label = "Target delay"; | |
1642 series.second.style = LINE_DOT_GRAPH; | |
1643 plot->AppendTimeSeries(std::move(series.second)); | |
1644 } | |
1645 | |
1646 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); | |
1647 plot->SetYAxis(min_y_axis, max_y_axis, "Relative delay (ms)", kBottomMargin, | |
1648 kTopMargin); | |
1649 plot->SetTitle("NetEq timing"); | |
1650 } | |
1399 } // namespace plotting | 1651 } // namespace plotting |
1400 } // namespace webrtc | 1652 } // namespace webrtc |
OLD | NEW |