blob: 8ef67313e8ee94a7f865aceccdc198ce7384e2d6 [file] [log] [blame]
Ivo Creusen55de08e2018-09-03 11:49:27 +02001/*
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#include <map>
Ivo Creusen4384f532018-09-07 17:19:56 +020016#include <vector>
Ivo Creusen55de08e2018-09-03 11:49:27 +020017
18namespace webrtc {
19namespace test {
20
21class NetEqSimulator {
22 public:
23 virtual ~NetEqSimulator() = default;
24
25 enum class Action { kNormal, kExpand, kAccelerate, kPreemptiveExpand };
26
27 // The results of one simulation step.
28 struct SimulationStepResult {
29 SimulationStepResult();
30 SimulationStepResult(const SimulationStepResult& other);
31 ~SimulationStepResult();
32
33 bool is_simulation_finished = false;
34 // The amount of audio produced (in ms) with the actions in this time step.
35 std::map<Action, int> action_times_ms;
36 // The amount of wall clock time (in ms) that elapsed since the previous
37 // event. This is not necessarily equal to the sum of the values in
38 // action_times_ms.
39 int64_t simulation_step_ms = 0;
40 };
41
42 struct NetEqState {
Ivo Creusen4384f532018-09-07 17:19:56 +020043 NetEqState();
44 NetEqState(const NetEqState& other);
Ivo Creusen4384f532018-09-07 17:19:56 +020045 ~NetEqState();
Ivo Creusen55de08e2018-09-03 11:49:27 +020046 // The sum of the packet buffer and sync buffer delay.
47 int current_delay_ms = 0;
Ivo Creusen4384f532018-09-07 17:19:56 +020048 // An indicator that packet loss occurred since the last GetAudio event.
49 bool packet_loss_occurred = false;
Ivo Creusendc6d5532018-09-27 11:43:42 +020050 // An indicator that the packet buffer has been flushed since the last
51 // GetAudio event.
52 bool packet_buffer_flushed = false;
53 // Indicates if the next needed packet is available in the buffer.
54 bool next_packet_available = false;
Ivo Creusen4384f532018-09-07 17:19:56 +020055 // The inter-arrival times in ms of the packets that have arrived since the
56 // last GetAudio event.
57 std::vector<int> packet_iat_ms;
Ivo Creusendc6d5532018-09-27 11:43:42 +020058 // The current packet size in ms.
59 int packet_size_ms = 0;
Ivo Creusen55de08e2018-09-03 11:49:27 +020060 };
61
62 // Runs the simulation until we hit the next GetAudio event. If the simulation
63 // is finished, is_simulation_finished will be set to true in the returned
64 // SimulationStepResult.
65 virtual SimulationStepResult RunToNextGetAudio() = 0;
66
67 // Set the next action to be taken by NetEq. This will override any action
68 // that NetEq would normally decide to take.
69 virtual void SetNextAction(Action next_operation) = 0;
70
71 // Get the current state of NetEq.
72 virtual NetEqState GetNetEqState() = 0;
73};
74
75} // namespace test
76} // namespace webrtc
77
78#endif // API_TEST_NETEQ_SIMULATOR_H_