neteq_delay_analyzer.h (2810B)
1 /* 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_DELAY_ANALYZER_H_ 12 #define MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_DELAY_ANALYZER_H_ 13 14 #include <cstddef> 15 #include <cstdint> 16 #include <map> 17 #include <optional> 18 #include <set> 19 #include <utility> 20 #include <vector> 21 22 #include "absl/strings/string_view.h" 23 #include "api/audio/audio_frame.h" 24 #include "api/neteq/neteq.h" 25 #include "modules/audio_coding/neteq/tools/neteq_test.h" 26 #include "modules/rtp_rtcp/source/rtp_packet_received.h" 27 28 namespace webrtc { 29 namespace test { 30 31 class NetEqDelayAnalyzer : public test::NetEqPostInsertPacket, 32 public test::NetEqGetAudioCallback { 33 public: 34 void AfterInsertPacket(const RtpPacketReceived& packet, 35 NetEq* neteq) override; 36 37 void BeforeGetAudio(NetEq* neteq) override; 38 39 void AfterGetAudio(int64_t time_now_ms, 40 const AudioFrame& audio_frame, 41 bool muted, 42 NetEq* neteq) override; 43 44 using Delays = std::vector<std::pair<int64_t, float>>; 45 void CreateGraphs(Delays* arrival_delay_ms, 46 Delays* corrected_arrival_delay_ms, 47 Delays* playout_delay_ms, 48 Delays* target_delay_ms) const; 49 50 // Creates a matlab script with file name script_name. When executed in 51 // Matlab, the script will generate graphs with the same timing information 52 // as provided by CreateGraphs. 53 void CreateMatlabScript(absl::string_view script_name) const; 54 55 // Creates a python script with file name `script_name`. When executed in 56 // Python, the script will generate graphs with the same timing information 57 // as provided by CreateGraphs. 58 void CreatePythonScript(absl::string_view script_name) const; 59 60 private: 61 struct TimingData { 62 explicit TimingData(int64_t at) : arrival_time_ms(at) {} 63 int64_t arrival_time_ms; 64 std::optional<int64_t> decode_get_audio_count; 65 std::optional<int64_t> sync_delay_ms; 66 std::optional<int> target_delay_ms; 67 std::optional<int> current_delay_ms; 68 }; 69 std::map<uint32_t, TimingData> data_; 70 std::vector<int64_t> get_audio_time_ms_; 71 size_t get_audio_count_ = 0; 72 size_t last_sync_buffer_ms_ = 0; 73 int last_sample_rate_hz_ = 0; 74 std::set<uint32_t> ssrcs_; 75 std::set<int> payload_types_; 76 }; 77 78 } // namespace test 79 } // namespace webrtc 80 #endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_DELAY_ANALYZER_H_