xref: /aosp_15_r20/external/webrtc/modules/audio_coding/neteq/tools/neteq_delay_analyzer.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 <map>
15 #include <set>
16 #include <string>
17 #include <vector>
18 
19 #include "absl/strings/string_view.h"
20 #include "absl/types/optional.h"
21 #include "modules/audio_coding/neteq/tools/neteq_input.h"
22 #include "modules/audio_coding/neteq/tools/neteq_test.h"
23 
24 namespace webrtc {
25 namespace test {
26 
27 class NetEqDelayAnalyzer : public test::NetEqPostInsertPacket,
28                            public test::NetEqGetAudioCallback {
29  public:
30   void AfterInsertPacket(const test::NetEqInput::PacketData& packet,
31                          NetEq* neteq) override;
32 
33   void BeforeGetAudio(NetEq* neteq) override;
34 
35   void AfterGetAudio(int64_t time_now_ms,
36                      const AudioFrame& audio_frame,
37                      bool muted,
38                      NetEq* neteq) override;
39 
40   using Delays = std::vector<std::pair<int64_t, float>>;
41   void CreateGraphs(Delays* arrival_delay_ms,
42                     Delays* corrected_arrival_delay_ms,
43                     Delays* playout_delay_ms,
44                     Delays* target_delay_ms) const;
45 
46   // Creates a matlab script with file name script_name. When executed in
47   // Matlab, the script will generate graphs with the same timing information
48   // as provided by CreateGraphs.
49   void CreateMatlabScript(absl::string_view script_name) const;
50 
51   // Creates a python script with file name `script_name`. When executed in
52   // Python, the script will generate graphs with the same timing information
53   // as provided by CreateGraphs.
54   void CreatePythonScript(absl::string_view script_name) const;
55 
56  private:
57   struct TimingData {
TimingDataTimingData58     explicit TimingData(int64_t at) : arrival_time_ms(at) {}
59     int64_t arrival_time_ms;
60     absl::optional<int64_t> decode_get_audio_count;
61     absl::optional<int64_t> sync_delay_ms;
62     absl::optional<int> target_delay_ms;
63     absl::optional<int> current_delay_ms;
64   };
65   std::map<uint32_t, TimingData> data_;
66   std::vector<int64_t> get_audio_time_ms_;
67   size_t get_audio_count_ = 0;
68   size_t last_sync_buffer_ms_ = 0;
69   int last_sample_rate_hz_ = 0;
70   std::set<uint32_t> ssrcs_;
71   std::set<int> payload_types_;
72 };
73 
74 }  // namespace test
75 }  // namespace webrtc
76 #endif  // MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_DELAY_ANALYZER_H_
77