aboutsummaryrefslogtreecommitdiff
path: root/webrtc/modules/remote_bitrate_estimator/transport_feedback_adapter.h
blob: 58829b072b103f8b44a34fee692031e1a57f9c33 (plain)
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
/*
 *  Copyright (c) 2015 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_REMOTE_BITRATE_ESTIMATOR_TRANSPORT_FEEDBACK_ADAPTER_H_
#define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TRANSPORT_FEEDBACK_ADAPTER_H_

#include <vector>

#include "webrtc/base/criticalsection.h"
#include "webrtc/base/thread_annotations.h"
#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
#include "webrtc/modules/interface/module_common_types.h"
#include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
#include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h"

namespace webrtc {

class ProcessThread;

class TransportFeedbackAdapter : public TransportFeedbackObserver,
                                 public CallStatsObserver,
                                 public RemoteBitrateObserver {
 public:
  TransportFeedbackAdapter(RtcpBandwidthObserver* bandwidth_observer,
                           Clock* clock,
                           ProcessThread* process_thread);
  virtual ~TransportFeedbackAdapter();

  void AddPacket(uint16_t sequence_number,
                 size_t length,
                 bool was_paced) override;

  void OnSentPacket(uint16_t sequence_number, int64_t send_time_ms);

  void OnTransportFeedback(const rtcp::TransportFeedback& feedback) override;

  void SetBitrateEstimator(RemoteBitrateEstimator* rbe);

  RemoteBitrateEstimator* GetBitrateEstimator() const {
    return bitrate_estimator_.get();
  }

 private:
  void OnReceiveBitrateChanged(const std::vector<unsigned int>& ssrcs,
                               unsigned int bitrate) override;
  void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override;

  rtc::CriticalSection lock_;
  SendTimeHistory send_time_history_ GUARDED_BY(&lock_);
  rtc::scoped_ptr<RtcpBandwidthObserver> rtcp_bandwidth_observer_;
  rtc::scoped_ptr<RemoteBitrateEstimator> bitrate_estimator_;
  ProcessThread* const process_thread_;
  Clock* const clock_;
  int64_t current_offset_ms_;
  int64_t last_timestamp_us_;
};

}  // namespace webrtc

#endif  // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TRANSPORT_FEEDBACK_ADAPTER_H_