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