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 #include "api/test/neteq_simulator_factory.h"
12
13 #include <memory>
14 #include <string>
15 #include <vector>
16
17 #include "absl/flags/flag.h"
18 #include "absl/flags/parse.h"
19 #include "modules/audio_coding/neteq/tools/neteq_test_factory.h"
20 #include "rtc_base/checks.h"
21
22 namespace webrtc {
23 namespace test {
24 namespace {
convertConfig(const NetEqSimulatorFactory::Config & simulation_config,absl::string_view replacement_audio_filename)25 NetEqTestFactory::Config convertConfig(
26 const NetEqSimulatorFactory::Config& simulation_config,
27 absl::string_view replacement_audio_filename) {
28 NetEqTestFactory::Config config;
29 config.replacement_audio_file = std::string(replacement_audio_filename);
30 config.max_nr_packets_in_buffer = simulation_config.max_nr_packets_in_buffer;
31 config.initial_dummy_packets = simulation_config.initial_dummy_packets;
32 config.skip_get_audio_events = simulation_config.skip_get_audio_events;
33 config.field_trial_string = simulation_config.field_trial_string;
34 config.output_audio_filename = simulation_config.output_audio_filename;
35 config.pythonplot = simulation_config.python_plot_filename.has_value();
36 config.plot_scripts_basename = simulation_config.python_plot_filename;
37 config.textlog = simulation_config.text_log_filename.has_value();
38 config.textlog_filename = simulation_config.text_log_filename;
39 return config;
40 }
41 } // namespace
42
NetEqSimulatorFactory()43 NetEqSimulatorFactory::NetEqSimulatorFactory()
44 : factory_(std::make_unique<NetEqTestFactory>()) {}
45
46 NetEqSimulatorFactory::~NetEqSimulatorFactory() = default;
47
CreateSimulatorFromFile(absl::string_view event_log_filename,absl::string_view replacement_audio_filename,Config simulation_config)48 std::unique_ptr<NetEqSimulator> NetEqSimulatorFactory::CreateSimulatorFromFile(
49 absl::string_view event_log_filename,
50 absl::string_view replacement_audio_filename,
51 Config simulation_config) {
52 NetEqTestFactory::Config config =
53 convertConfig(simulation_config, replacement_audio_filename);
54 return factory_->InitializeTestFromFile(
55 std::string(event_log_filename), simulation_config.neteq_factory, config);
56 }
57
58 std::unique_ptr<NetEqSimulator>
CreateSimulatorFromString(absl::string_view event_log_file_contents,absl::string_view replacement_audio_filename,Config simulation_config)59 NetEqSimulatorFactory::CreateSimulatorFromString(
60 absl::string_view event_log_file_contents,
61 absl::string_view replacement_audio_filename,
62 Config simulation_config) {
63 NetEqTestFactory::Config config =
64 convertConfig(simulation_config, replacement_audio_filename);
65 return factory_->InitializeTestFromString(
66 std::string(event_log_file_contents), simulation_config.neteq_factory,
67 config);
68 }
69
70 } // namespace test
71 } // namespace webrtc
72