blob: 65dc3a8dc414386ab8c51dc573107bc383be64b5 [file] [log] [blame]
Ivo Creusen55de08e2018-09-03 11:49:27 +02001/*
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
Alessio Bazzica5ad789c2019-03-13 11:51:44 +010013#include <string>
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020014#include <vector>
Alessio Bazzica5ad789c2019-03-13 11:51:44 +010015
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020016#include "absl/flags/flag.h"
17#include "absl/flags/parse.h"
Ivo Creusen55de08e2018-09-03 11:49:27 +020018#include "absl/memory/memory.h"
19#include "modules/audio_coding/neteq/tools/neteq_test_factory.h"
Ivo Creusenf81b0f12018-09-11 10:30:58 +020020#include "rtc_base/checks.h"
Ivo Creusen55de08e2018-09-03 11:49:27 +020021
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020022ABSL_FLAG(std::string,
23 replacement_audio_file,
24 "",
25 "A PCM file that will be used to populate dummy"
26 " RTP packets");
27ABSL_FLAG(int,
28 max_nr_packets_in_buffer,
29 50,
30 "Maximum allowed number of packets in the buffer");
Ivo Creusenba7886b2019-02-26 13:03:21 +010031
Ivo Creusen55de08e2018-09-03 11:49:27 +020032namespace webrtc {
33namespace test {
34
35NetEqSimulatorFactory::NetEqSimulatorFactory()
36 : factory_(absl::make_unique<NetEqTestFactory>()) {}
37
38NetEqSimulatorFactory::~NetEqSimulatorFactory() = default;
39
40std::unique_ptr<NetEqSimulator> NetEqSimulatorFactory::CreateSimulator(
41 int argc,
42 char* argv[]) {
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020043 std::vector<char*> args = absl::ParseCommandLine(argc, argv);
44 RTC_CHECK_EQ(args.size(), 3)
45 << "Wrong number of input arguments. Expected 3, got " << args.size();
Ivo Creusenba7886b2019-02-26 13:03:21 +010046 // TODO(ivoc) Stop (ab)using command-line flags in this function.
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020047 const std::string output_audio_filename(args[2]);
Ivo Creusenba7886b2019-02-26 13:03:21 +010048 NetEqTestFactory::Config config;
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020049 config.replacement_audio_file = absl::GetFlag(FLAGS_replacement_audio_file);
50 config.max_nr_packets_in_buffer =
51 absl::GetFlag(FLAGS_max_nr_packets_in_buffer);
Alessio Bazzica5ad789c2019-03-13 11:51:44 +010052 config.output_audio_filename = output_audio_filename;
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020053 return factory_->InitializeTestFromFile(args[1], config);
Ivo Creusen5ec61562019-03-20 10:52:18 +010054}
55
56std::unique_ptr<NetEqSimulator> NetEqSimulatorFactory::CreateSimulatorFromFile(
57 absl::string_view event_log_filename,
58 absl::string_view replacement_audio_filename,
59 Config simulation_config) {
60 NetEqTestFactory::Config config;
61 config.replacement_audio_file = std::string(replacement_audio_filename);
62 config.max_nr_packets_in_buffer = simulation_config.max_nr_packets_in_buffer;
63 return factory_->InitializeTestFromFile(std::string(event_log_filename),
64 config);
65}
66
67std::unique_ptr<NetEqSimulator>
68NetEqSimulatorFactory::CreateSimulatorFromString(
69 absl::string_view event_log_file_contents,
70 absl::string_view replacement_audio_filename,
71 Config simulation_config) {
72 NetEqTestFactory::Config config;
73 config.replacement_audio_file = std::string(replacement_audio_filename);
74 config.max_nr_packets_in_buffer = simulation_config.max_nr_packets_in_buffer;
75 return factory_->InitializeTestFromString(
76 std::string(event_log_file_contents), config);
Ivo Creusen55de08e2018-09-03 11:49:27 +020077}
78
79} // namespace test
80} // namespace webrtc