blob: ab6db9c84c7b8b7cbd58bbb4788b025ad26ae5b7 [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;
50 // The inter-arrival times in ms of the packets that have arrived since the
51 // last GetAudio event.
52 std::vector<int> packet_iat_ms;
Ivo Creusen55de08e2018-09-03 11:49:27 +020053 };
54
55 // Runs the simulation until we hit the next GetAudio event. If the simulation
56 // is finished, is_simulation_finished will be set to true in the returned
57 // SimulationStepResult.
58 virtual SimulationStepResult RunToNextGetAudio() = 0;
59
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
64 // Get the current state of NetEq.
65 virtual NetEqState GetNetEqState() = 0;
66};
67
68} // namespace test
69} // namespace webrtc
70
71#endif // API_TEST_NETEQ_SIMULATOR_H_