neteq_simulator.h 2.7 KB

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