henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_coding/neteq/tools/neteq_test.h" |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 12 | |
Ivo Creusen | 2db46b0 | 2018-12-14 16:49:12 +0100 | [diff] [blame] | 13 | #include <iomanip> |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 14 | #include <iostream> |
| 15 | |
Ivo Creusen | 39cf3c7 | 2019-11-28 14:07:14 +0100 | [diff] [blame] | 16 | #include "modules/audio_coding/neteq/default_neteq_factory.h" |
Ivo Creusen | 2db46b0 | 2018-12-14 16:49:12 +0100 | [diff] [blame] | 17 | #include "modules/rtp_rtcp/source/byte_io.h" |
Alessio Bazzica | 8f319a3 | 2019-07-24 16:47:02 +0000 | [diff] [blame] | 18 | #include "system_wrappers/include/clock.h" |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | namespace test { |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 22 | namespace { |
| 23 | |
Ivo Creusen | 3ce44a3 | 2019-10-31 14:38:11 +0100 | [diff] [blame] | 24 | absl::optional<NetEq::Operation> ActionToOperations( |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 25 | absl::optional<NetEqSimulator::Action> a) { |
| 26 | if (!a) { |
| 27 | return absl::nullopt; |
| 28 | } |
| 29 | switch (*a) { |
| 30 | case NetEqSimulator::Action::kAccelerate: |
Ivo Creusen | 3ce44a3 | 2019-10-31 14:38:11 +0100 | [diff] [blame] | 31 | return absl::make_optional(NetEq::Operation::kAccelerate); |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 32 | case NetEqSimulator::Action::kExpand: |
Ivo Creusen | 3ce44a3 | 2019-10-31 14:38:11 +0100 | [diff] [blame] | 33 | return absl::make_optional(NetEq::Operation::kExpand); |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 34 | case NetEqSimulator::Action::kNormal: |
Ivo Creusen | 3ce44a3 | 2019-10-31 14:38:11 +0100 | [diff] [blame] | 35 | return absl::make_optional(NetEq::Operation::kNormal); |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 36 | case NetEqSimulator::Action::kPreemptiveExpand: |
Ivo Creusen | 3ce44a3 | 2019-10-31 14:38:11 +0100 | [diff] [blame] | 37 | return absl::make_optional(NetEq::Operation::kPreemptiveExpand); |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | |
Ivo Creusen | 3ce44a3 | 2019-10-31 14:38:11 +0100 | [diff] [blame] | 41 | std::unique_ptr<NetEq> CreateNetEq( |
| 42 | const NetEq::Config& config, |
| 43 | Clock* clock, |
| 44 | const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) { |
Ivo Creusen | 39cf3c7 | 2019-11-28 14:07:14 +0100 | [diff] [blame] | 45 | return DefaultNetEqFactory().CreateNetEq(config, decoder_factory, clock); |
Ivo Creusen | 3ce44a3 | 2019-10-31 14:38:11 +0100 | [diff] [blame] | 46 | } |
| 47 | |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 48 | } // namespace |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 49 | |
| 50 | void DefaultNetEqTestErrorCallback::OnInsertPacketError( |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 51 | const NetEqInput::PacketData& packet) { |
Henrik Lundin | c417d9e | 2017-06-14 12:29:03 +0200 | [diff] [blame] | 52 | std::cerr << "InsertPacket returned an error." << std::endl; |
henrik.lundin | 7a38fd2 | 2017-04-28 01:35:53 -0700 | [diff] [blame] | 53 | std::cerr << "Packet data: " << packet.ToString() << std::endl; |
Mirko Bonadei | 01719fb | 2020-11-17 14:50:54 +0100 | [diff] [blame] | 54 | RTC_FATAL(); |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Henrik Lundin | c417d9e | 2017-06-14 12:29:03 +0200 | [diff] [blame] | 57 | void DefaultNetEqTestErrorCallback::OnGetAudioError() { |
| 58 | std::cerr << "GetAudio returned an error." << std::endl; |
Mirko Bonadei | 01719fb | 2020-11-17 14:50:54 +0100 | [diff] [blame] | 59 | RTC_FATAL(); |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | NetEqTest::NetEqTest(const NetEq::Config& config, |
Niels Möller | 3f651d8 | 2018-12-19 15:06:17 +0100 | [diff] [blame] | 63 | rtc::scoped_refptr<AudioDecoderFactory> decoder_factory, |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 64 | const DecoderMap& codecs, |
Ivo Creusen | 2db46b0 | 2018-12-14 16:49:12 +0100 | [diff] [blame] | 65 | std::unique_ptr<std::ofstream> text_log, |
Ivo Creusen | cee751a | 2020-01-16 17:17:09 +0100 | [diff] [blame] | 66 | NetEqFactory* neteq_factory, |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 67 | std::unique_ptr<NetEqInput> input, |
| 68 | std::unique_ptr<AudioSink> output, |
henrik.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 69 | Callbacks callbacks) |
Alessio Bazzica | 8f319a3 | 2019-07-24 16:47:02 +0000 | [diff] [blame] | 70 | : clock_(0), |
Ivo Creusen | cee751a | 2020-01-16 17:17:09 +0100 | [diff] [blame] | 71 | neteq_(neteq_factory |
| 72 | ? neteq_factory->CreateNetEq(config, decoder_factory, &clock_) |
| 73 | : CreateNetEq(config, &clock_, decoder_factory)), |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 74 | input_(std::move(input)), |
| 75 | output_(std::move(output)), |
henrik.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 76 | callbacks_(callbacks), |
Ivo Creusen | 2db46b0 | 2018-12-14 16:49:12 +0100 | [diff] [blame] | 77 | sample_rate_hz_(config.sample_rate_hz), |
| 78 | text_log_(std::move(text_log)) { |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 79 | RTC_CHECK(!config.enable_muted_state) |
| 80 | << "The code does not handle enable_muted_state"; |
| 81 | RegisterDecoders(codecs); |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Mirko Bonadei | 682aac5 | 2018-07-20 13:59:20 +0200 | [diff] [blame] | 84 | NetEqTest::~NetEqTest() = default; |
| 85 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 86 | int64_t NetEqTest::Run() { |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 87 | int64_t simulation_time = 0; |
| 88 | SimulationStepResult step_result; |
| 89 | do { |
| 90 | step_result = RunToNextGetAudio(); |
| 91 | simulation_time += step_result.simulation_step_ms; |
| 92 | } while (!step_result.is_simulation_finished); |
| 93 | if (callbacks_.simulation_ended_callback) { |
Henrik Lundin | c49e9c2 | 2020-05-25 11:26:15 +0200 | [diff] [blame] | 94 | callbacks_.simulation_ended_callback->SimulationEnded(simulation_time, |
| 95 | neteq_.get()); |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 96 | } |
| 97 | return simulation_time; |
| 98 | } |
| 99 | |
| 100 | NetEqTest::SimulationStepResult NetEqTest::RunToNextGetAudio() { |
| 101 | SimulationStepResult result; |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 102 | const int64_t start_time_ms = *input_->NextEventTime(); |
| 103 | int64_t time_now_ms = start_time_ms; |
Ivo Creusen | 4384f53 | 2018-09-07 17:19:56 +0200 | [diff] [blame] | 104 | current_state_.packet_iat_ms.clear(); |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 105 | |
| 106 | while (!input_->ended()) { |
| 107 | // Advance time to next event. |
| 108 | RTC_DCHECK(input_->NextEventTime()); |
Alessio Bazzica | 8f319a3 | 2019-07-24 16:47:02 +0000 | [diff] [blame] | 109 | clock_.AdvanceTimeMilliseconds(*input_->NextEventTime() - time_now_ms); |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 110 | time_now_ms = *input_->NextEventTime(); |
| 111 | // Check if it is time to insert packet. |
| 112 | if (input_->NextPacketTime() && time_now_ms >= *input_->NextPacketTime()) { |
| 113 | std::unique_ptr<NetEqInput::PacketData> packet_data = input_->PopPacket(); |
| 114 | RTC_CHECK(packet_data); |
Minyue Li | 1a80018 | 2018-09-12 12:52:48 +0200 | [diff] [blame] | 115 | const size_t payload_data_length = |
| 116 | packet_data->payload.size() - packet_data->header.paddingLength; |
| 117 | if (payload_data_length != 0) { |
| 118 | int error = neteq_->InsertPacket( |
| 119 | packet_data->header, |
Karl Wiberg | 45eb135 | 2019-10-10 14:23:00 +0200 | [diff] [blame] | 120 | rtc::ArrayView<const uint8_t>(packet_data->payload)); |
Minyue Li | 1a80018 | 2018-09-12 12:52:48 +0200 | [diff] [blame] | 121 | if (error != NetEq::kOK && callbacks_.error_callback) { |
| 122 | callbacks_.error_callback->OnInsertPacketError(*packet_data); |
| 123 | } |
| 124 | if (callbacks_.post_insert_packet) { |
| 125 | callbacks_.post_insert_packet->AfterInsertPacket(*packet_data, |
| 126 | neteq_.get()); |
| 127 | } |
| 128 | } else { |
| 129 | neteq_->InsertEmptyPacket(packet_data->header); |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 130 | } |
Ivo Creusen | 4384f53 | 2018-09-07 17:19:56 +0200 | [diff] [blame] | 131 | if (last_packet_time_ms_) { |
| 132 | current_state_.packet_iat_ms.push_back(time_now_ms - |
| 133 | *last_packet_time_ms_); |
| 134 | } |
Ivo Creusen | 2db46b0 | 2018-12-14 16:49:12 +0100 | [diff] [blame] | 135 | if (text_log_) { |
| 136 | const auto ops_state = neteq_->GetOperationsAndState(); |
| 137 | const auto delta_wallclock = |
| 138 | last_packet_time_ms_ ? (time_now_ms - *last_packet_time_ms_) : -1; |
| 139 | const auto delta_timestamp = |
| 140 | last_packet_timestamp_ |
| 141 | ? (static_cast<int64_t>(packet_data->header.timestamp) - |
| 142 | *last_packet_timestamp_) * |
| 143 | 1000 / sample_rate_hz_ |
| 144 | : -1; |
| 145 | const auto packet_size_bytes = |
| 146 | packet_data->payload.size() == 12 |
| 147 | ? ByteReader<uint32_t>::ReadLittleEndian( |
| 148 | &packet_data->payload[8]) |
| 149 | : -1; |
| 150 | *text_log_ << "Packet - wallclock: " << std::setw(5) << time_now_ms |
| 151 | << ", delta wc: " << std::setw(4) << delta_wallclock |
Jakob Ivarsson | e98954c | 2019-02-06 15:37:50 +0100 | [diff] [blame] | 152 | << ", seq_no: " << packet_data->header.sequenceNumber |
Ivo Creusen | 2db46b0 | 2018-12-14 16:49:12 +0100 | [diff] [blame] | 153 | << ", timestamp: " << std::setw(10) |
| 154 | << packet_data->header.timestamp |
| 155 | << ", delta ts: " << std::setw(4) << delta_timestamp |
| 156 | << ", size: " << std::setw(5) << packet_size_bytes |
| 157 | << ", frame size: " << std::setw(3) |
| 158 | << ops_state.current_frame_size_ms |
| 159 | << ", buffer size: " << std::setw(4) |
| 160 | << ops_state.current_buffer_size_ms << std::endl; |
| 161 | } |
Ivo Creusen | 4384f53 | 2018-09-07 17:19:56 +0200 | [diff] [blame] | 162 | last_packet_time_ms_ = absl::make_optional<int>(time_now_ms); |
Ivo Creusen | 2db46b0 | 2018-12-14 16:49:12 +0100 | [diff] [blame] | 163 | last_packet_timestamp_ = |
| 164 | absl::make_optional<uint32_t>(packet_data->header.timestamp); |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | // Check if it is time to get output audio. |
| 168 | if (input_->NextOutputEventTime() && |
| 169 | time_now_ms >= *input_->NextOutputEventTime()) { |
henrik.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 170 | if (callbacks_.get_audio_callback) { |
| 171 | callbacks_.get_audio_callback->BeforeGetAudio(neteq_.get()); |
| 172 | } |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 173 | AudioFrame out_frame; |
| 174 | bool muted; |
Tommi | 3cc68ec | 2021-06-09 19:30:41 +0200 | [diff] [blame] | 175 | int error = neteq_->GetAudio(&out_frame, &muted, nullptr, |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 176 | ActionToOperations(next_action_)); |
| 177 | next_action_ = absl::nullopt; |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 178 | RTC_CHECK(!muted) << "The code does not handle enable_muted_state"; |
| 179 | if (error != NetEq::kOK) { |
henrik.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 180 | if (callbacks_.error_callback) { |
Henrik Lundin | c417d9e | 2017-06-14 12:29:03 +0200 | [diff] [blame] | 181 | callbacks_.error_callback->OnGetAudioError(); |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 182 | } |
| 183 | } else { |
| 184 | sample_rate_hz_ = out_frame.sample_rate_hz_; |
| 185 | } |
henrik.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 186 | if (callbacks_.get_audio_callback) { |
| 187 | callbacks_.get_audio_callback->AfterGetAudio(time_now_ms, out_frame, |
| 188 | muted, neteq_.get()); |
| 189 | } |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 190 | |
| 191 | if (output_) { |
| 192 | RTC_CHECK(output_->WriteArray( |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 193 | out_frame.data(), |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 194 | out_frame.samples_per_channel_ * out_frame.num_channels_)); |
| 195 | } |
| 196 | |
| 197 | input_->AdvanceOutputEvent(); |
Henrik Lundin | 9be7745 | 2018-09-10 12:53:27 +0200 | [diff] [blame] | 198 | result.simulation_step_ms = |
| 199 | input_->NextEventTime().value_or(time_now_ms) - start_time_ms; |
Ivo Creusen | d1c2f78 | 2018-09-13 14:39:55 +0200 | [diff] [blame] | 200 | const auto operations_state = neteq_->GetOperationsAndState(); |
| 201 | current_state_.current_delay_ms = operations_state.current_buffer_size_ms; |
Ivo Creusen | dc6d553 | 2018-09-27 11:43:42 +0200 | [diff] [blame] | 202 | current_state_.packet_size_ms = operations_state.current_frame_size_ms; |
| 203 | current_state_.next_packet_available = |
| 204 | operations_state.next_packet_available; |
| 205 | current_state_.packet_buffer_flushed = |
| 206 | operations_state.packet_buffer_flushes > |
| 207 | prev_ops_state_.packet_buffer_flushes; |
Ivo Creusen | d1c2f78 | 2018-09-13 14:39:55 +0200 | [diff] [blame] | 208 | // TODO(ivoc): Add more accurate reporting by tracking the origin of |
| 209 | // samples in the sync buffer. |
| 210 | result.action_times_ms[Action::kExpand] = 0; |
| 211 | result.action_times_ms[Action::kAccelerate] = 0; |
| 212 | result.action_times_ms[Action::kPreemptiveExpand] = 0; |
| 213 | result.action_times_ms[Action::kNormal] = 0; |
| 214 | |
| 215 | if (out_frame.speech_type_ == AudioFrame::SpeechType::kPLC || |
| 216 | out_frame.speech_type_ == AudioFrame::SpeechType::kPLCCNG) { |
| 217 | // Consider the whole frame to be the result of expansion. |
| 218 | result.action_times_ms[Action::kExpand] = 10; |
| 219 | } else if (operations_state.accelerate_samples - |
| 220 | prev_ops_state_.accelerate_samples > |
| 221 | 0) { |
| 222 | // Consider the whole frame to be the result of acceleration. |
| 223 | result.action_times_ms[Action::kAccelerate] = 10; |
| 224 | } else if (operations_state.preemptive_samples - |
| 225 | prev_ops_state_.preemptive_samples > |
| 226 | 0) { |
| 227 | // Consider the whole frame to be the result of preemptive expansion. |
| 228 | result.action_times_ms[Action::kPreemptiveExpand] = 10; |
| 229 | } else { |
| 230 | // Consider the whole frame to be the result of normal playout. |
| 231 | result.action_times_ms[Action::kNormal] = 10; |
| 232 | } |
Ivo Creusen | 2db46b0 | 2018-12-14 16:49:12 +0100 | [diff] [blame] | 233 | auto lifetime_stats = LifetimeStats(); |
| 234 | if (text_log_) { |
| 235 | const bool plc = |
| 236 | (out_frame.speech_type_ == AudioFrame::SpeechType::kPLC) || |
| 237 | (out_frame.speech_type_ == AudioFrame::SpeechType::kPLCCNG); |
| 238 | const bool cng = out_frame.speech_type_ == AudioFrame::SpeechType::kCNG; |
| 239 | const bool voice_concealed = |
Ivo Creusen | bf4a221 | 2019-04-24 14:06:24 +0200 | [diff] [blame] | 240 | (lifetime_stats.concealed_samples - |
| 241 | lifetime_stats.silent_concealed_samples) > |
| 242 | (prev_lifetime_stats_.concealed_samples - |
| 243 | prev_lifetime_stats_.silent_concealed_samples); |
Ivo Creusen | 2db46b0 | 2018-12-14 16:49:12 +0100 | [diff] [blame] | 244 | *text_log_ << "GetAudio - wallclock: " << std::setw(5) << time_now_ms |
| 245 | << ", delta wc: " << std::setw(4) |
| 246 | << (input_->NextEventTime().value_or(time_now_ms) - |
| 247 | start_time_ms) |
| 248 | << ", CNG: " << cng << ", PLC: " << plc |
| 249 | << ", voice concealed: " << voice_concealed |
| 250 | << ", buffer size: " << std::setw(4) |
| 251 | << current_state_.current_delay_ms << std::endl; |
| 252 | if (operations_state.discarded_primary_packets > |
| 253 | prev_ops_state_.discarded_primary_packets) { |
| 254 | *text_log_ << "Discarded " |
| 255 | << (operations_state.discarded_primary_packets - |
| 256 | prev_ops_state_.discarded_primary_packets) |
| 257 | << " primary packets." << std::endl; |
| 258 | } |
| 259 | if (operations_state.packet_buffer_flushes > |
| 260 | prev_ops_state_.packet_buffer_flushes) { |
| 261 | *text_log_ << "Flushed packet buffer " |
| 262 | << (operations_state.packet_buffer_flushes - |
| 263 | prev_ops_state_.packet_buffer_flushes) |
| 264 | << " times." << std::endl; |
| 265 | } |
| 266 | } |
| 267 | prev_lifetime_stats_ = lifetime_stats; |
Jakob Ivarsson | 9ce451a | 2019-05-22 16:41:22 +0200 | [diff] [blame] | 268 | const bool no_more_packets_to_decode = |
| 269 | !input_->NextPacketTime() && !operations_state.next_packet_available; |
Ivo Creusen | 876a3dc | 2020-08-18 17:08:18 +0200 | [diff] [blame] | 270 | // End the simulation if the gap is too large. This indicates an issue |
| 271 | // with the event log file. |
| 272 | const bool simulation_step_too_large = result.simulation_step_ms > 1000; |
Ivo Creusen | b9b7456 | 2020-10-26 17:49:25 +0100 | [diff] [blame] | 273 | if (simulation_step_too_large) { |
| 274 | // If we don't reset the step time, the large gap will be included in |
| 275 | // the simulation time, which can be a large distortion. |
| 276 | result.simulation_step_ms = 10; |
| 277 | } |
Ivo Creusen | 876a3dc | 2020-08-18 17:08:18 +0200 | [diff] [blame] | 278 | result.is_simulation_finished = simulation_step_too_large || |
| 279 | no_more_packets_to_decode || |
| 280 | input_->ended(); |
Ivo Creusen | d1c2f78 | 2018-09-13 14:39:55 +0200 | [diff] [blame] | 281 | prev_ops_state_ = operations_state; |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 282 | return result; |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 283 | } |
| 284 | } |
Henrik Lundin | 9be7745 | 2018-09-10 12:53:27 +0200 | [diff] [blame] | 285 | result.simulation_step_ms = |
| 286 | input_->NextEventTime().value_or(time_now_ms) - start_time_ms; |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 287 | result.is_simulation_finished = true; |
| 288 | return result; |
| 289 | } |
| 290 | |
| 291 | void NetEqTest::SetNextAction(NetEqTest::Action next_operation) { |
| 292 | next_action_ = absl::optional<Action>(next_operation); |
| 293 | } |
| 294 | |
| 295 | NetEqTest::NetEqState NetEqTest::GetNetEqState() { |
Ivo Creusen | 4384f53 | 2018-09-07 17:19:56 +0200 | [diff] [blame] | 296 | return current_state_; |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | NetEqNetworkStatistics NetEqTest::SimulationStats() { |
| 300 | NetEqNetworkStatistics stats; |
| 301 | RTC_CHECK_EQ(neteq_->NetworkStatistics(&stats), 0); |
| 302 | return stats; |
| 303 | } |
| 304 | |
Alex Narest | 7ff6ca5 | 2018-02-07 18:46:33 +0100 | [diff] [blame] | 305 | NetEqLifetimeStatistics NetEqTest::LifetimeStats() const { |
| 306 | return neteq_->GetLifetimeStatistics(); |
| 307 | } |
| 308 | |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 309 | NetEqTest::DecoderMap NetEqTest::StandardDecoderMap() { |
| 310 | DecoderMap codecs = { |
Niels Möller | 0554368 | 2019-01-10 16:55:06 +0100 | [diff] [blame] | 311 | {0, SdpAudioFormat("pcmu", 8000, 1)}, |
| 312 | {8, SdpAudioFormat("pcma", 8000, 1)}, |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 313 | #ifdef WEBRTC_CODEC_ILBC |
Niels Möller | 0554368 | 2019-01-10 16:55:06 +0100 | [diff] [blame] | 314 | {102, SdpAudioFormat("ilbc", 8000, 1)}, |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 315 | #endif |
Niels Möller | 0554368 | 2019-01-10 16:55:06 +0100 | [diff] [blame] | 316 | {103, SdpAudioFormat("isac", 16000, 1)}, |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 317 | #if !defined(WEBRTC_ANDROID) |
Niels Möller | 0554368 | 2019-01-10 16:55:06 +0100 | [diff] [blame] | 318 | {104, SdpAudioFormat("isac", 32000, 1)}, |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 319 | #endif |
| 320 | #ifdef WEBRTC_CODEC_OPUS |
Niels Möller | 0554368 | 2019-01-10 16:55:06 +0100 | [diff] [blame] | 321 | {111, SdpAudioFormat("opus", 48000, 2)}, |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 322 | #endif |
Niels Möller | 0554368 | 2019-01-10 16:55:06 +0100 | [diff] [blame] | 323 | {93, SdpAudioFormat("l16", 8000, 1)}, |
| 324 | {94, SdpAudioFormat("l16", 16000, 1)}, |
| 325 | {95, SdpAudioFormat("l16", 32000, 1)}, |
| 326 | {96, SdpAudioFormat("l16", 48000, 1)}, |
| 327 | {9, SdpAudioFormat("g722", 8000, 1)}, |
| 328 | {106, SdpAudioFormat("telephone-event", 8000, 1)}, |
| 329 | {114, SdpAudioFormat("telephone-event", 16000, 1)}, |
| 330 | {115, SdpAudioFormat("telephone-event", 32000, 1)}, |
| 331 | {116, SdpAudioFormat("telephone-event", 48000, 1)}, |
| 332 | {117, SdpAudioFormat("red", 8000, 1)}, |
| 333 | {13, SdpAudioFormat("cn", 8000, 1)}, |
| 334 | {98, SdpAudioFormat("cn", 16000, 1)}, |
| 335 | {99, SdpAudioFormat("cn", 32000, 1)}, |
| 336 | {100, SdpAudioFormat("cn", 48000, 1)} |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 337 | }; |
| 338 | return codecs; |
| 339 | } |
| 340 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 341 | void NetEqTest::RegisterDecoders(const DecoderMap& codecs) { |
| 342 | for (const auto& c : codecs) { |
Niels Möller | 0554368 | 2019-01-10 16:55:06 +0100 | [diff] [blame] | 343 | RTC_CHECK(neteq_->RegisterPayloadType(c.first, c.second)) |
| 344 | << "Cannot register " << c.second.name << " to payload type " |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 345 | << c.first; |
| 346 | } |
| 347 | } |
| 348 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 349 | } // namespace test |
| 350 | } // namespace webrtc |