1 /*
2  *  Copyright (c) 2018 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_TEST_FACTORY_H_
12 #define MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_TEST_FACTORY_H_
13 
14 #include <memory>
15 #include <string>
16 
17 #include "absl/types/optional.h"
18 #include "modules/audio_coding/neteq/tools/neteq_test.h"
19 #include "test/field_trial.h"
20 
21 namespace webrtc {
22 namespace test {
23 
24 class SsrcSwitchDetector;
25 class NetEqStatsGetter;
26 class NetEqStatsPlotter;
27 
28 // Note that the NetEqTestFactory needs to be alive when the NetEqTest object is
29 // used for a simulation.
30 class NetEqTestFactory {
31  public:
32   NetEqTestFactory();
33   ~NetEqTestFactory();
34   struct Config {
35     Config();
36     Config(const Config& other);
37     ~Config();
38     // RTP payload type for PCM-u.
default_pcmuConfig39     static constexpr int default_pcmu() { return 0; }
40     int pcmu = default_pcmu();
41     // RTP payload type for PCM-a.
default_pcmaConfig42     static constexpr int default_pcma() { return 8; }
43     int pcma = default_pcma();
44     // RTP payload type for iLBC.
default_ilbcConfig45     static constexpr int default_ilbc() { return 102; }
46     int ilbc = default_ilbc();
47     // RTP payload type for iSAC.
default_isacConfig48     static constexpr int default_isac() { return 103; }
49     int isac = default_isac();
50     // RTP payload type for iSAC-swb (32 kHz).
default_isac_swbConfig51     static constexpr int default_isac_swb() { return 104; }
52     int isac_swb = default_isac_swb();
53     // RTP payload type for Opus.
default_opusConfig54     static constexpr int default_opus() { return 111; }
55     int opus = default_opus();
56     // RTP payload type for PCM16b-nb (8 kHz).
default_pcm16bConfig57     static constexpr int default_pcm16b() { return 93; }
58     int pcm16b = default_pcm16b();
59     // RTP payload type for PCM16b-wb (16 kHz).
default_pcm16b_wbConfig60     static constexpr int default_pcm16b_wb() { return 94; }
61     int pcm16b_wb = default_pcm16b_wb();
62     // RTP payload type for PCM16b-swb32 (32 kHz).
default_pcm16b_swb32Config63     static constexpr int default_pcm16b_swb32() { return 95; }
64     int pcm16b_swb32 = default_pcm16b_swb32();
65     // RTP payload type for PCM16b-swb48 (48 kHz).
default_pcm16b_swb48Config66     static constexpr int default_pcm16b_swb48() { return 96; }
67     int pcm16b_swb48 = default_pcm16b_swb48();
68     // RTP payload type for G.722.
default_g722Config69     static constexpr int default_g722() { return 9; }
70     int g722 = default_g722();
71     // RTP payload type for AVT/DTMF (8 kHz).
default_avtConfig72     static constexpr int default_avt() { return 106; }
73     int avt = default_avt();
74     // RTP payload type for AVT/DTMF (16 kHz).
default_avt_16Config75     static constexpr int default_avt_16() { return 114; }
76     int avt_16 = default_avt_16();
77     // RTP payload type for AVT/DTMF (32 kHz).
default_avt_32Config78     static constexpr int default_avt_32() { return 115; }
79     int avt_32 = default_avt_32();
80     // RTP payload type for AVT/DTMF (48 kHz).
default_avt_48Config81     static constexpr int default_avt_48() { return 116; }
82     int avt_48 = default_avt_48();
83     // RTP payload type for redundant audio (RED).
default_redConfig84     static constexpr int default_red() { return 117; }
85     int red = default_red();
86     // RTP payload type for comfort noise (8 kHz).
default_cn_nbConfig87     static constexpr int default_cn_nb() { return 13; }
88     int cn_nb = default_cn_nb();
89     // RTP payload type for comfort noise (16 kHz).
default_cn_wbConfig90     static constexpr int default_cn_wb() { return 98; }
91     int cn_wb = default_cn_wb();
92     // RTP payload type for comfort noise (32 kHz).
default_cn_swb32Config93     static constexpr int default_cn_swb32() { return 99; }
94     int cn_swb32 = default_cn_swb32();
95     // RTP payload type for comfort noise (48 kHz).
default_cn_swb48Config96     static constexpr int default_cn_swb48() { return 100; }
97     int cn_swb48 = default_cn_swb48();
98     // A PCM file that will be used to populate dummy RTP packets.
99     std::string replacement_audio_file;
100     // Only use packets with this SSRC.
101     absl::optional<uint32_t> ssrc_filter;
102     // Extension ID for audio level (RFC 6464).
default_audio_levelConfig103     static constexpr int default_audio_level() { return 1; }
104     int audio_level = default_audio_level();
105     // Extension ID for absolute sender time.
default_abs_send_timeConfig106     static constexpr int default_abs_send_time() { return 3; }
107     int abs_send_time = default_abs_send_time();
108     // Extension ID for transport sequence number.
default_transport_seq_noConfig109     static constexpr int default_transport_seq_no() { return 5; }
110     int transport_seq_no = default_transport_seq_no();
111     // Extension ID for video content type.
default_video_content_typeConfig112     static constexpr int default_video_content_type() { return 7; }
113     int video_content_type = default_video_content_type();
114     // Extension ID for video timing.
default_video_timingConfig115     static constexpr int default_video_timing() { return 8; }
116     int video_timing = default_video_timing();
117     // Generate a matlab script for plotting the delay profile.
118     bool matlabplot = false;
119     // Generates a python script for plotting the delay profile.
120     bool pythonplot = false;
121     // Prints concealment events.
122     bool concealment_events = false;
123     // Maximum allowed number of packets in the buffer.
default_max_nr_packets_in_bufferConfig124     static constexpr int default_max_nr_packets_in_buffer() { return 200; }
125     int max_nr_packets_in_buffer = default_max_nr_packets_in_buffer();
126     // Number of dummy packets to put in the packet buffer at the start of the
127     // simulation.
default_initial_dummy_packetsConfig128     static constexpr int default_initial_dummy_packets() { return 0; }
129     int initial_dummy_packets = default_initial_dummy_packets();
130     // Number of getAudio events to skip at the start of the simulation.
default_skip_get_audio_eventsConfig131     static constexpr int default_skip_get_audio_events() { return 0; }
132     int skip_get_audio_events = default_skip_get_audio_events();
133     // Enables jitter buffer fast accelerate.
134     bool enable_fast_accelerate = false;
135     // Dumps events that describes the simulation on a step-by-step basis.
136     bool textlog = false;
137     // If specified and |textlog| is true, the output of |textlog| is written to
138     // the specified file name.
139     absl::optional<std::string> textlog_filename;
140     // Base name for the output script files for plotting the delay profile.
141     absl::optional<std::string> plot_scripts_basename;
142     // Path to the output audio file.
143     absl::optional<std::string> output_audio_filename;
144     // Field trials to use during the simulation.
145     std::string field_trial_string;
146   };
147 
148   std::unique_ptr<NetEqTest> InitializeTestFromFile(
149       const std::string& input_filename,
150       NetEqFactory* neteq_factory,
151       const Config& config);
152   std::unique_ptr<NetEqTest> InitializeTestFromString(
153       const std::string& input_string,
154       NetEqFactory* neteq_factory,
155       const Config& config);
156 
157  private:
158   std::unique_ptr<NetEqTest> InitializeTest(std::unique_ptr<NetEqInput> input,
159                                             NetEqFactory* neteq_factory,
160                                             const Config& config);
161   std::unique_ptr<SsrcSwitchDetector> ssrc_switch_detector_;
162   std::unique_ptr<NetEqStatsPlotter> stats_plotter_;
163   // The field trials are stored in the test factory, because neteq_test is not
164   // in a testonly target, and therefore cannot use ScopedFieldTrials.
165   std::unique_ptr<ScopedFieldTrials> field_trials_;
166 };
167 
168 }  // namespace test
169 }  // namespace webrtc
170 
171 #endif  // MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_TEST_FACTORY_H_
172