diff options
-rw-r--r-- | api/test/neteq_simulator.cc | 5 | ||||
-rw-r--r-- | api/test/neteq_simulator.h | 11 | ||||
-rw-r--r-- | modules/audio_coding/neteq/tools/neteq_test.cc | 30 | ||||
-rw-r--r-- | modules/audio_coding/neteq/tools/neteq_test.h | 2 |
4 files changed, 42 insertions, 6 deletions
diff --git a/api/test/neteq_simulator.cc b/api/test/neteq_simulator.cc index 061570167b..2933d10628 100644 --- a/api/test/neteq_simulator.cc +++ b/api/test/neteq_simulator.cc @@ -18,5 +18,10 @@ NetEqSimulator::SimulationStepResult::SimulationStepResult( const NetEqSimulator::SimulationStepResult& other) = default; NetEqSimulator::SimulationStepResult::~SimulationStepResult() = default; +NetEqSimulator::NetEqState::NetEqState() = default; +NetEqSimulator::NetEqState::NetEqState(const NetEqState& other) = default; +NetEqSimulator::NetEqState::NetEqState(NetEqState&& other) = default; +NetEqSimulator::NetEqState::~NetEqState() = default; + } // namespace test } // namespace webrtc diff --git a/api/test/neteq_simulator.h b/api/test/neteq_simulator.h index 8f1cd81425..d7dbb1ec20 100644 --- a/api/test/neteq_simulator.h +++ b/api/test/neteq_simulator.h @@ -13,6 +13,7 @@ #include <stdint.h> #include <map> +#include <vector> namespace webrtc { namespace test { @@ -39,9 +40,17 @@ class NetEqSimulator { }; struct NetEqState { + NetEqState(); + NetEqState(const NetEqState& other); + NetEqState(NetEqState&& other); + ~NetEqState(); // The sum of the packet buffer and sync buffer delay. int current_delay_ms = 0; - // TODO(ivoc): Expand this struct with more useful metrics. + // An indicator that packet loss occurred since the last GetAudio event. + bool packet_loss_occurred = false; + // The inter-arrival times in ms of the packets that have arrived since the + // last GetAudio event. + std::vector<int> packet_iat_ms; }; // Runs the simulation until we hit the next GetAudio event. If the simulation diff --git a/modules/audio_coding/neteq/tools/neteq_test.cc b/modules/audio_coding/neteq/tools/neteq_test.cc index 110819c85b..08e17dc023 100644 --- a/modules/audio_coding/neteq/tools/neteq_test.cc +++ b/modules/audio_coding/neteq/tools/neteq_test.cc @@ -85,6 +85,7 @@ NetEqTest::SimulationStepResult NetEqTest::RunToNextGetAudio() { SimulationStepResult result; const int64_t start_time_ms = *input_->NextEventTime(); int64_t time_now_ms = start_time_ms; + current_state_.packet_iat_ms.clear(); while (!input_->ended()) { // Advance time to next event. @@ -105,6 +106,11 @@ NetEqTest::SimulationStepResult NetEqTest::RunToNextGetAudio() { callbacks_.post_insert_packet->AfterInsertPacket(*packet_data, neteq_.get()); } + if (last_packet_time_ms_) { + current_state_.packet_iat_ms.push_back(time_now_ms - + *last_packet_time_ms_); + } + last_packet_time_ms_ = absl::make_optional<int>(time_now_ms); } // Check if it is time to get output audio. @@ -139,7 +145,24 @@ NetEqTest::SimulationStepResult NetEqTest::RunToNextGetAudio() { input_->AdvanceOutputEvent(); result.simulation_step_ms = time_now_ms - start_time_ms; - // TODO(ivoc): Set the result.<action>_ms values correctly. + const auto network_stats = SimulationStats(); + current_state_.current_delay_ms = network_stats.current_buffer_size_ms; + current_state_.packet_loss_occurred = network_stats.packet_loss_rate > 0; + int scaling_factor = std::max(1 << 14, network_stats.accelerate_rate + + network_stats.expand_rate + + network_stats.preemptive_rate); + // TODO(ivoc): Improve the accuracy of these numbers by adding a new API + // to NetEq. + result.action_times_ms[Action::kAccelerate] = + (10 * network_stats.accelerate_rate) / scaling_factor; + result.action_times_ms[Action::kExpand] = + (10 * network_stats.expand_rate) / scaling_factor; + result.action_times_ms[Action::kPreemptiveExpand] = + (10 * network_stats.preemptive_rate) / scaling_factor; + result.action_times_ms[Action::kNormal] = + 10 - result.action_times_ms[Action::kAccelerate] - + result.action_times_ms[Action::kExpand] - + result.action_times_ms[Action::kPreemptiveExpand]; result.is_simulation_finished = input_->ended(); return result; } @@ -154,10 +177,7 @@ void NetEqTest::SetNextAction(NetEqTest::Action next_operation) { } NetEqTest::NetEqState NetEqTest::GetNetEqState() { - NetEqState state; - const auto network_stats = SimulationStats(); - state.current_delay_ms = network_stats.current_buffer_size_ms; - return state; + return current_state_; } NetEqNetworkStatistics NetEqTest::SimulationStats() { diff --git a/modules/audio_coding/neteq/tools/neteq_test.h b/modules/audio_coding/neteq/tools/neteq_test.h index c5580456ad..787d507504 100644 --- a/modules/audio_coding/neteq/tools/neteq_test.h +++ b/modules/audio_coding/neteq/tools/neteq_test.h @@ -113,11 +113,13 @@ class NetEqTest : public NetEqSimulator { void RegisterDecoders(const DecoderMap& codecs); void RegisterExternalDecoders(const ExtDecoderMap& codecs); absl::optional<Action> next_action_; + absl::optional<int> last_packet_time_ms_; std::unique_ptr<NetEq> neteq_; std::unique_ptr<NetEqInput> input_; std::unique_ptr<AudioSink> output_; Callbacks callbacks_; int sample_rate_hz_; + NetEqState current_state_; }; } // namespace test |