Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 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> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame^] | 15 | |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 16 | #include <map> |
Ivo Creusen | 4384f53 | 2018-09-07 17:19:56 +0200 | [diff] [blame] | 17 | #include <vector> |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 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 { |
Ivo Creusen | 4384f53 | 2018-09-07 17:19:56 +0200 | [diff] [blame] | 44 | NetEqState(); |
| 45 | NetEqState(const NetEqState& other); |
Ivo Creusen | 4384f53 | 2018-09-07 17:19:56 +0200 | [diff] [blame] | 46 | ~NetEqState(); |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 47 | // The sum of the packet buffer and sync buffer delay. |
| 48 | int current_delay_ms = 0; |
Ivo Creusen | 4384f53 | 2018-09-07 17:19:56 +0200 | [diff] [blame] | 49 | // An indicator that packet loss occurred since the last GetAudio event. |
| 50 | bool packet_loss_occurred = false; |
Ivo Creusen | dc6d553 | 2018-09-27 11:43:42 +0200 | [diff] [blame] | 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; |
Ivo Creusen | 4384f53 | 2018-09-07 17:19:56 +0200 | [diff] [blame] | 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; |
Ivo Creusen | dc6d553 | 2018-09-27 11:43:42 +0200 | [diff] [blame] | 59 | // The current packet size in ms. |
| 60 | int packet_size_ms = 0; |
Ivo Creusen | 55de08e | 2018-09-03 11:49:27 +0200 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | // Runs the simulation until we hit the next GetAudio event. If the simulation |
| 64 | // is finished, is_simulation_finished will be set to true in the returned |
| 65 | // SimulationStepResult. |
| 66 | virtual SimulationStepResult RunToNextGetAudio() = 0; |
| 67 | |
| 68 | // Set the next action to be taken by NetEq. This will override any action |
| 69 | // that NetEq would normally decide to take. |
| 70 | virtual void SetNextAction(Action next_operation) = 0; |
| 71 | |
| 72 | // Get the current state of NetEq. |
| 73 | virtual NetEqState GetNetEqState() = 0; |
| 74 | }; |
| 75 | |
| 76 | } // namespace test |
| 77 | } // namespace webrtc |
| 78 | |
| 79 | #endif // API_TEST_NETEQ_SIMULATOR_H_ |