Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 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 | |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 13 | #include <memory> |
Alessio Bazzica | 5ad789c | 2019-03-13 11:51:44 +0100 | [diff] [blame] | 14 | #include <string> |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 15 | #include <vector> |
Alessio Bazzica | 5ad789c | 2019-03-13 11:51:44 +0100 | [diff] [blame] | 16 | |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 17 | #include "absl/flags/flag.h" |
| 18 | #include "absl/flags/parse.h" |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 19 | #include "modules/audio_coding/neteq/tools/neteq_test_factory.h" |
Ivo Creusen | f81b0f1 | 2018-09-11 10:30:58 +0200 | [diff] [blame] | 20 | #include "rtc_base/checks.h" |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | namespace test { |
Ivo Creusen | 47156e2 | 2020-10-13 15:17:32 +0200 | [diff] [blame] | 24 | namespace { |
| 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 |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 42 | |
| 43 | NetEqSimulatorFactory::NetEqSimulatorFactory() |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 44 | : factory_(std::make_unique<NetEqTestFactory>()) {} |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 45 | |
| 46 | NetEqSimulatorFactory::~NetEqSimulatorFactory() = default; |
| 47 | |
Ivo Creusen | 5ec6156 | 2019-03-20 10:52:18 +0100 | [diff] [blame] | 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) { |
Ivo Creusen | 47156e2 | 2020-10-13 15:17:32 +0200 | [diff] [blame] | 52 | NetEqTestFactory::Config config = |
| 53 | convertConfig(simulation_config, replacement_audio_filename); |
Ivo Creusen | cee751a | 2020-01-16 17:17:09 +0100 | [diff] [blame] | 54 | return factory_->InitializeTestFromFile( |
| 55 | std::string(event_log_filename), simulation_config.neteq_factory, config); |
Ivo Creusen | 5ec6156 | 2019-03-20 10:52:18 +0100 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | std::unique_ptr<NetEqSimulator> |
| 59 | NetEqSimulatorFactory::CreateSimulatorFromString( |
| 60 | absl::string_view event_log_file_contents, |
| 61 | absl::string_view replacement_audio_filename, |
| 62 | Config simulation_config) { |
Ivo Creusen | 47156e2 | 2020-10-13 15:17:32 +0200 | [diff] [blame] | 63 | NetEqTestFactory::Config config = |
| 64 | convertConfig(simulation_config, replacement_audio_filename); |
Ivo Creusen | 5ec6156 | 2019-03-20 10:52:18 +0100 | [diff] [blame] | 65 | return factory_->InitializeTestFromString( |
Ivo Creusen | cee751a | 2020-01-16 17:17:09 +0100 | [diff] [blame] | 66 | std::string(event_log_file_contents), simulation_config.neteq_factory, |
| 67 | config); |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | } // namespace test |
| 71 | } // namespace webrtc |