DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (777e60ca8853)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
/*
 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */
#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_OVERUSE_DETECTOR_H_
#define WEBRTC_MODULES_RTP_RTCP_SOURCE_OVERUSE_DETECTOR_H_

#include <list>

#include "webrtc/modules/interface/module_common_types.h"
#include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
#include "webrtc/typedefs.h"

#ifdef WEBRTC_BWE_MATLAB
#include "webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.h"
#endif

namespace webrtc {
enum RateControlRegion;

// This class is assumed to be protected by the owner if used by multiple
// threads.
class OveruseDetector {
 public:
  explicit OveruseDetector(const OverUseDetectorOptions& options);
  ~OveruseDetector();
  void Update(uint16_t packet_size,
              int64_t timestamp_ms,
              uint32_t rtp_timestamp,
              int64_t now_ms);
  BandwidthUsage State() const;
  double NoiseVar() const;
  void SetRateControlRegion(RateControlRegion region);
  int64_t time_of_last_received_packet() const;

 private:
  struct FrameSample {
    FrameSample()
        : size(0),
          complete_time_ms(-1),
          timestamp(-1),
          timestamp_ms(-1) {}

    uint32_t size;
    int64_t complete_time_ms;
    int64_t timestamp;
    int64_t timestamp_ms;
  };

  struct DebugPlots {
#ifdef WEBRTC_BWE_MATLAB
    DebugPlots() : plot1(NULL), plot2(NULL), plot3(NULL), plot4(NULL) {}
    MatlabPlot* plot1;
    MatlabPlot* plot2;
    MatlabPlot* plot3;
    MatlabPlot* plot4;
#endif
  };

  // Returns true if |timestamp| represent a time which is later than
  // |prev_timestamp|.
  static bool InOrderTimestamp(uint32_t timestamp, uint32_t prev_timestamp);

  bool PacketInOrder(uint32_t timestamp, int64_t timestamp_ms);

  // Prepares the overuse detector to start using timestamps in milliseconds
  // instead of 90 kHz timestamps.
  void SwitchTimeBase();

  void TimeDeltas(const FrameSample& current_frame,
                  const FrameSample& prev_frame,
                  int64_t* t_delta,
                  double* ts_delta);
  void UpdateKalman(int64_t t_delta,
                    double ts_elta,
                    uint32_t frame_size,
                    uint32_t prev_frame_size);
  double UpdateMinFramePeriod(double ts_delta);
  void UpdateNoiseEstimate(double residual, double ts_delta, bool stable_state);
  BandwidthUsage Detect(double ts_delta);
  double CurrentDrift();

  OverUseDetectorOptions options_;  // Must be first member
                                    // variable. Cannot be const
                                    // because we need to be copyable.
  FrameSample current_frame_;
  FrameSample prev_frame_;
  uint16_t num_of_deltas_;
  double slope_;
  double offset_;
  double E_[2][2];
  double process_noise_[2];
  double avg_noise_;
  double var_noise_;
  double threshold_;
  std::list<double> ts_delta_hist_;
  double prev_offset_;
  double time_over_using_;
  uint16_t over_use_counter_;
  BandwidthUsage hypothesis_;
  int64_t time_of_last_received_packet_;
#ifdef WEBRTC_BWE_MATLAB
  DebugPlots plots_;
#endif
};
}  // namespace webrtc

#endif  // WEBRTC_MODULES_RTP_RTCP_SOURCE_OVERUSE_DETECTOR_H_