tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

neteq_simulator.h (2886B)


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