• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/strings/string_view.h"
18 #include "absl/types/optional.h"
19 #include "modules/audio_coding/neteq/tools/neteq_test.h"
20 #include "test/field_trial.h"
21 
22 namespace webrtc {
23 namespace test {
24 
25 class SsrcSwitchDetector;
26 class NetEqStatsGetter;
27 class NetEqStatsPlotter;
28 
29 // Note that the NetEqTestFactory needs to be alive when the NetEqTest object is
30 // used for a simulation.
31 class NetEqTestFactory {
32  public:
33   NetEqTestFactory();
34   ~NetEqTestFactory();
35   struct Config {
36     Config();
37     Config(const Config& other);
38     ~Config();
39     // RTP payload type for PCM-u.
default_pcmuConfig40     static constexpr int default_pcmu() { return 0; }
41     int pcmu = default_pcmu();
42     // RTP payload type for PCM-a.
default_pcmaConfig43     static constexpr int default_pcma() { return 8; }
44     int pcma = default_pcma();
45     // RTP payload type for iLBC.
default_ilbcConfig46     static constexpr int default_ilbc() { return 102; }
47     int ilbc = default_ilbc();
48     // RTP payload type for iSAC.
default_isacConfig49     static constexpr int default_isac() { return 103; }
50     int isac = default_isac();
51     // RTP payload type for iSAC-swb (32 kHz).
default_isac_swbConfig52     static constexpr int default_isac_swb() { return 104; }
53     int isac_swb = default_isac_swb();
54     // RTP payload type for Opus.
default_opusConfig55     static constexpr int default_opus() { return 111; }
56     int opus = default_opus();
57     // RTP payload type for PCM16b-nb (8 kHz).
default_pcm16bConfig58     static constexpr int default_pcm16b() { return 93; }
59     int pcm16b = default_pcm16b();
60     // RTP payload type for PCM16b-wb (16 kHz).
default_pcm16b_wbConfig61     static constexpr int default_pcm16b_wb() { return 94; }
62     int pcm16b_wb = default_pcm16b_wb();
63     // RTP payload type for PCM16b-swb32 (32 kHz).
default_pcm16b_swb32Config64     static constexpr int default_pcm16b_swb32() { return 95; }
65     int pcm16b_swb32 = default_pcm16b_swb32();
66     // RTP payload type for PCM16b-swb48 (48 kHz).
default_pcm16b_swb48Config67     static constexpr int default_pcm16b_swb48() { return 96; }
68     int pcm16b_swb48 = default_pcm16b_swb48();
69     // RTP payload type for G.722.
default_g722Config70     static constexpr int default_g722() { return 9; }
71     int g722 = default_g722();
72     // RTP payload type for AVT/DTMF (8 kHz).
default_avtConfig73     static constexpr int default_avt() { return 106; }
74     int avt = default_avt();
75     // RTP payload type for AVT/DTMF (16 kHz).
default_avt_16Config76     static constexpr int default_avt_16() { return 114; }
77     int avt_16 = default_avt_16();
78     // RTP payload type for AVT/DTMF (32 kHz).
default_avt_32Config79     static constexpr int default_avt_32() { return 115; }
80     int avt_32 = default_avt_32();
81     // RTP payload type for AVT/DTMF (48 kHz).
default_avt_48Config82     static constexpr int default_avt_48() { return 116; }
83     int avt_48 = default_avt_48();
84     // RTP payload type for redundant audio (RED).
default_redConfig85     static constexpr int default_red() { return 117; }
86     int red = default_red();
87     // RTP payload type for comfort noise (8 kHz).
default_cn_nbConfig88     static constexpr int default_cn_nb() { return 13; }
89     int cn_nb = default_cn_nb();
90     // RTP payload type for comfort noise (16 kHz).
default_cn_wbConfig91     static constexpr int default_cn_wb() { return 98; }
92     int cn_wb = default_cn_wb();
93     // RTP payload type for comfort noise (32 kHz).
default_cn_swb32Config94     static constexpr int default_cn_swb32() { return 99; }
95     int cn_swb32 = default_cn_swb32();
96     // RTP payload type for comfort noise (48 kHz).
default_cn_swb48Config97     static constexpr int default_cn_swb48() { return 100; }
98     int cn_swb48 = default_cn_swb48();
99     // A PCM file that will be used to populate dummy RTP packets.
100     std::string replacement_audio_file;
101     // Only use packets with this SSRC.
102     absl::optional<uint32_t> ssrc_filter;
103     // Extension ID for audio level (RFC 6464).
default_audio_levelConfig104     static constexpr int default_audio_level() { return 1; }
105     int audio_level = default_audio_level();
106     // Extension ID for absolute sender time.
default_abs_send_timeConfig107     static constexpr int default_abs_send_time() { return 3; }
108     int abs_send_time = default_abs_send_time();
109     // Extension ID for transport sequence number.
default_transport_seq_noConfig110     static constexpr int default_transport_seq_no() { return 5; }
111     int transport_seq_no = default_transport_seq_no();
112     // Extension ID for video content type.
default_video_content_typeConfig113     static constexpr int default_video_content_type() { return 7; }
114     int video_content_type = default_video_content_type();
115     // Extension ID for video timing.
default_video_timingConfig116     static constexpr int default_video_timing() { return 8; }
117     int video_timing = default_video_timing();
118     // Generate a matlab script for plotting the delay profile.
119     bool matlabplot = false;
120     // Generates a python script for plotting the delay profile.
121     bool pythonplot = false;
122     // Prints concealment events.
123     bool concealment_events = false;
124     // Maximum allowed number of packets in the buffer.
default_max_nr_packets_in_bufferConfig125     static constexpr int default_max_nr_packets_in_buffer() { return 200; }
126     int max_nr_packets_in_buffer = default_max_nr_packets_in_buffer();
127     // Number of dummy packets to put in the packet buffer at the start of the
128     // simulation.
default_initial_dummy_packetsConfig129     static constexpr int default_initial_dummy_packets() { return 0; }
130     int initial_dummy_packets = default_initial_dummy_packets();
131     // Number of getAudio events to skip at the start of the simulation.
default_skip_get_audio_eventsConfig132     static constexpr int default_skip_get_audio_events() { return 0; }
133     int skip_get_audio_events = default_skip_get_audio_events();
134     // Enables jitter buffer fast accelerate.
135     bool enable_fast_accelerate = false;
136     // Dumps events that describes the simulation on a step-by-step basis.
137     bool textlog = false;
138     // If specified and `textlog` is true, the output of `textlog` is written to
139     // the specified file name.
140     absl::optional<std::string> textlog_filename;
141     // Base name for the output script files for plotting the delay profile.
142     absl::optional<std::string> plot_scripts_basename;
143     // Path to the output audio file.
144     absl::optional<std::string> output_audio_filename;
145     // Field trials to use during the simulation.
146     std::string field_trial_string;
147   };
148 
149   std::unique_ptr<NetEqTest> InitializeTestFromFile(
150       absl::string_view input_filename,
151       NetEqFactory* neteq_factory,
152       const Config& config);
153   std::unique_ptr<NetEqTest> InitializeTestFromString(
154       absl::string_view input_string,
155       NetEqFactory* neteq_factory,
156       const Config& config);
157 
158  private:
159   std::unique_ptr<NetEqTest> InitializeTest(std::unique_ptr<NetEqInput> input,
160                                             NetEqFactory* neteq_factory,
161                                             const Config& config);
162   std::unique_ptr<SsrcSwitchDetector> ssrc_switch_detector_;
163   std::unique_ptr<NetEqStatsPlotter> stats_plotter_;
164   // The field trials are stored in the test factory, because neteq_test is not
165   // in a testonly target, and therefore cannot use ScopedFieldTrials.
166   std::unique_ptr<ScopedFieldTrials> field_trials_;
167 };
168 
169 }  // namespace test
170 }  // namespace webrtc
171 
172 #endif  // MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_TEST_FACTORY_H_
173