blob: a826ca5c644f87645971db46a69b63620eea341e [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>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
Ivo Creusen55de08e2018-09-03 11:49:27 +020016#include <map>
Ivo Creusen4384f532018-09-07 17:19:56 +020017#include <vector>
Ivo Creusen55de08e2018-09-03 11:49:27 +020018
19namespace webrtc {
20namespace test {
21
22class 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 Creusen4384f532018-09-07 17:19:56 +020044 NetEqState();
45 NetEqState(const NetEqState& other);
Ivo Creusen4384f532018-09-07 17:19:56 +020046 ~NetEqState();
Ivo Creusen55de08e2018-09-03 11:49:27 +020047 // The sum of the packet buffer and sync buffer delay.
48 int current_delay_ms = 0;
Ivo Creusen4384f532018-09-07 17:19:56 +020049 // An indicator that packet loss occurred since the last GetAudio event.
50 bool packet_loss_occurred = false;
Ivo Creusendc6d5532018-09-27 11:43:42 +020051 // 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 Creusen4384f532018-09-07 17:19:56 +020056 // 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 Creusendc6d5532018-09-27 11:43:42 +020059 // The current packet size in ms.
60 int packet_size_ms = 0;
Ivo Creusen55de08e2018-09-03 11:49:27 +020061 };
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_