1*d9f75844SAndroid Build Coastguard Worker /* 2*d9f75844SAndroid Build Coastguard Worker * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3*d9f75844SAndroid Build Coastguard Worker * 4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license 5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source 6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found 7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may 8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree. 9*d9f75844SAndroid Build Coastguard Worker */ 10*d9f75844SAndroid Build Coastguard Worker 11*d9f75844SAndroid Build Coastguard Worker #ifndef API_TEST_NETEQ_SIMULATOR_H_ 12*d9f75844SAndroid Build Coastguard Worker #define API_TEST_NETEQ_SIMULATOR_H_ 13*d9f75844SAndroid Build Coastguard Worker 14*d9f75844SAndroid Build Coastguard Worker #include <stdint.h> 15*d9f75844SAndroid Build Coastguard Worker 16*d9f75844SAndroid Build Coastguard Worker #include <map> 17*d9f75844SAndroid Build Coastguard Worker #include <vector> 18*d9f75844SAndroid Build Coastguard Worker 19*d9f75844SAndroid Build Coastguard Worker namespace webrtc { 20*d9f75844SAndroid Build Coastguard Worker namespace test { 21*d9f75844SAndroid Build Coastguard Worker 22*d9f75844SAndroid Build Coastguard Worker class NetEqSimulator { 23*d9f75844SAndroid Build Coastguard Worker public: 24*d9f75844SAndroid Build Coastguard Worker virtual ~NetEqSimulator() = default; 25*d9f75844SAndroid Build Coastguard Worker 26*d9f75844SAndroid Build Coastguard Worker enum class Action { kNormal, kExpand, kAccelerate, kPreemptiveExpand }; 27*d9f75844SAndroid Build Coastguard Worker 28*d9f75844SAndroid Build Coastguard Worker // The results of one simulation step. 29*d9f75844SAndroid Build Coastguard Worker struct SimulationStepResult { 30*d9f75844SAndroid Build Coastguard Worker SimulationStepResult(); 31*d9f75844SAndroid Build Coastguard Worker SimulationStepResult(const SimulationStepResult& other); 32*d9f75844SAndroid Build Coastguard Worker ~SimulationStepResult(); 33*d9f75844SAndroid Build Coastguard Worker 34*d9f75844SAndroid Build Coastguard Worker bool is_simulation_finished = false; 35*d9f75844SAndroid Build Coastguard Worker // The amount of audio produced (in ms) with the actions in this time step. 36*d9f75844SAndroid Build Coastguard Worker std::map<Action, int> action_times_ms; 37*d9f75844SAndroid Build Coastguard Worker // The amount of wall clock time (in ms) that elapsed since the previous 38*d9f75844SAndroid Build Coastguard Worker // event. This is not necessarily equal to the sum of the values in 39*d9f75844SAndroid Build Coastguard Worker // action_times_ms. 40*d9f75844SAndroid Build Coastguard Worker int64_t simulation_step_ms = 0; 41*d9f75844SAndroid Build Coastguard Worker }; 42*d9f75844SAndroid Build Coastguard Worker 43*d9f75844SAndroid Build Coastguard Worker struct NetEqState { 44*d9f75844SAndroid Build Coastguard Worker NetEqState(); 45*d9f75844SAndroid Build Coastguard Worker NetEqState(const NetEqState& other); 46*d9f75844SAndroid Build Coastguard Worker ~NetEqState(); 47*d9f75844SAndroid Build Coastguard Worker // The sum of the packet buffer and sync buffer delay. 48*d9f75844SAndroid Build Coastguard Worker int current_delay_ms = 0; 49*d9f75844SAndroid Build Coastguard Worker // An indicator that packet loss occurred since the last GetAudio event. 50*d9f75844SAndroid Build Coastguard Worker bool packet_loss_occurred = false; 51*d9f75844SAndroid Build Coastguard Worker // An indicator that the packet buffer has been flushed since the last 52*d9f75844SAndroid Build Coastguard Worker // GetAudio event. 53*d9f75844SAndroid Build Coastguard Worker bool packet_buffer_flushed = false; 54*d9f75844SAndroid Build Coastguard Worker // Indicates if the next needed packet is available in the buffer. 55*d9f75844SAndroid Build Coastguard Worker bool next_packet_available = false; 56*d9f75844SAndroid Build Coastguard Worker // The inter-arrival times in ms of the packets that have arrived since the 57*d9f75844SAndroid Build Coastguard Worker // last GetAudio event. 58*d9f75844SAndroid Build Coastguard Worker std::vector<int> packet_iat_ms; 59*d9f75844SAndroid Build Coastguard Worker // The current packet size in ms. 60*d9f75844SAndroid Build Coastguard Worker int packet_size_ms = 0; 61*d9f75844SAndroid Build Coastguard Worker }; 62*d9f75844SAndroid Build Coastguard Worker 63*d9f75844SAndroid Build Coastguard Worker // Runs the simulation until the end. Returns the duration of the produced 64*d9f75844SAndroid Build Coastguard Worker // audio in ms. 65*d9f75844SAndroid Build Coastguard Worker virtual int64_t Run() = 0; 66*d9f75844SAndroid Build Coastguard Worker // Runs the simulation until we hit the next GetAudio event. If the simulation 67*d9f75844SAndroid Build Coastguard Worker // is finished, is_simulation_finished will be set to true in the returned 68*d9f75844SAndroid Build Coastguard Worker // SimulationStepResult. 69*d9f75844SAndroid Build Coastguard Worker virtual SimulationStepResult RunToNextGetAudio() = 0; 70*d9f75844SAndroid Build Coastguard Worker 71*d9f75844SAndroid Build Coastguard Worker // Set the next action to be taken by NetEq. This will override any action 72*d9f75844SAndroid Build Coastguard Worker // that NetEq would normally decide to take. 73*d9f75844SAndroid Build Coastguard Worker virtual void SetNextAction(Action next_operation) = 0; 74*d9f75844SAndroid Build Coastguard Worker 75*d9f75844SAndroid Build Coastguard Worker // Get the current state of NetEq. 76*d9f75844SAndroid Build Coastguard Worker virtual NetEqState GetNetEqState() = 0; 77*d9f75844SAndroid Build Coastguard Worker }; 78*d9f75844SAndroid Build Coastguard Worker 79*d9f75844SAndroid Build Coastguard Worker } // namespace test 80*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc 81*d9f75844SAndroid Build Coastguard Worker 82*d9f75844SAndroid Build Coastguard Worker #endif // API_TEST_NETEQ_SIMULATOR_H_ 83