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