OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_VIDEO_VIE_RECEIVER_H_ | 11 #ifndef WEBRTC_VIDEO_VIE_RECEIVER_H_ |
12 #define WEBRTC_VIDEO_VIE_RECEIVER_H_ | 12 #define WEBRTC_VIDEO_VIE_RECEIVER_H_ |
13 | 13 |
14 #include <list> | 14 #include <list> |
15 #include <memory> | 15 #include <memory> |
16 #include <string> | 16 #include <string> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "webrtc/base/criticalsection.h" | 19 #include "webrtc/base/criticalsection.h" |
20 #include "webrtc/engine_configurations.h" | 20 #include "webrtc/engine_configurations.h" |
21 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" | 21 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" |
22 #include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h" | 22 #include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h" |
23 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" | 23 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" |
| 24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
25 #include "webrtc/typedefs.h" | 26 #include "webrtc/typedefs.h" |
26 | 27 |
27 namespace webrtc { | 28 namespace webrtc { |
28 | 29 |
29 class FecReceiver; | 30 class FecReceiver; |
| 31 class PacedSender; |
| 32 class PacketRouter; |
30 class RemoteNtpTimeEstimator; | 33 class RemoteNtpTimeEstimator; |
31 class ReceiveStatistics; | 34 class ReceiveStatistics; |
32 class RemoteBitrateEstimator; | 35 class RemoteBitrateEstimator; |
| 36 class RtcpRttStats; |
33 class RtpHeaderParser; | 37 class RtpHeaderParser; |
34 class RTPPayloadRegistry; | 38 class RTPPayloadRegistry; |
35 class RtpReceiver; | 39 class RtpReceiver; |
36 class RtpRtcp; | 40 class Transport; |
37 class VideoCodingModule; | 41 class VideoCodingModule; |
38 | 42 |
39 class ViEReceiver : public RtpData { | 43 class ViEReceiver : public RtpData { |
40 public: | 44 public: |
41 ViEReceiver(VideoCodingModule* module_vcm, | 45 ViEReceiver(VideoCodingModule* module_vcm, |
42 RemoteBitrateEstimator* remote_bitrate_estimator, | 46 RemoteBitrateEstimator* remote_bitrate_estimator, |
43 RtpFeedback* rtp_feedback); | 47 RtpFeedback* rtp_feedback, |
| 48 Transport* transport, |
| 49 RtcpRttStats* rtt_stats, |
| 50 PacedSender* paced_sender, |
| 51 PacketRouter* packet_router); |
44 ~ViEReceiver(); | 52 ~ViEReceiver(); |
45 | 53 |
46 bool SetReceiveCodec(const VideoCodec& video_codec); | 54 bool SetReceiveCodec(const VideoCodec& video_codec); |
47 | 55 |
48 void SetNackStatus(bool enable, int max_nack_reordering_threshold); | 56 void SetNackStatus(bool enable, int max_nack_reordering_threshold); |
49 void SetRtxPayloadType(int payload_type, int associated_payload_type); | 57 void SetRtxPayloadType(int payload_type, int associated_payload_type); |
50 // If set to true, the RTX payload type mapping supplied in | 58 // If set to true, the RTX payload type mapping supplied in |
51 // |SetRtxPayloadType| will be used when restoring RTX packets. Without it, | 59 // |SetRtxPayloadType| will be used when restoring RTX packets. Without it, |
52 // RTX packets will always be restored to the last non-RTX packet payload type | 60 // RTX packets will always be restored to the last non-RTX packet payload type |
53 // received. | 61 // received. |
54 void SetUseRtxPayloadMappingOnRestore(bool val); | 62 void SetUseRtxPayloadMappingOnRestore(bool val); |
55 void SetRtxSsrc(uint32_t ssrc); | 63 void SetRtxSsrc(uint32_t ssrc); |
56 bool GetRtxSsrc(uint32_t* ssrc) const; | 64 bool GetRtxSsrc(uint32_t* ssrc) const; |
57 | 65 |
58 bool IsFecEnabled() const; | 66 bool IsFecEnabled() const; |
59 | 67 |
60 uint32_t GetRemoteSsrc() const; | 68 uint32_t GetRemoteSsrc() const; |
61 int GetCsrcs(uint32_t* csrcs) const; | 69 int GetCsrcs(uint32_t* csrcs) const; |
62 | 70 |
63 void Init(RtpRtcp* rtp_rtcp); | |
64 | |
65 RtpReceiver* GetRtpReceiver() const; | 71 RtpReceiver* GetRtpReceiver() const; |
| 72 RtpRtcp* rtp_rtcp() const { return rtp_rtcp_.get(); } |
66 | 73 |
67 void EnableReceiveRtpHeaderExtension(const std::string& extension, int id); | 74 void EnableReceiveRtpHeaderExtension(const std::string& extension, int id); |
| 75 void RegisterRtcpPacketTypeCounterObserver( |
| 76 RtcpPacketTypeCounterObserver* observer); |
68 | 77 |
69 void StartReceive(); | 78 void StartReceive(); |
70 void StopReceive(); | 79 void StopReceive(); |
71 | 80 |
72 bool DeliverRtp(const uint8_t* rtp_packet, | 81 bool DeliverRtp(const uint8_t* rtp_packet, |
73 size_t rtp_packet_length, | 82 size_t rtp_packet_length, |
74 const PacketTime& packet_time); | 83 const PacketTime& packet_time); |
75 bool DeliverRtcp(const uint8_t* rtcp_packet, size_t rtcp_packet_length); | 84 bool DeliverRtcp(const uint8_t* rtcp_packet, size_t rtcp_packet_length); |
76 | 85 |
77 // Implements RtpData. | 86 // Implements RtpData. |
78 int32_t OnReceivedPayloadData(const uint8_t* payload_data, | 87 int32_t OnReceivedPayloadData(const uint8_t* payload_data, |
79 const size_t payload_size, | 88 const size_t payload_size, |
80 const WebRtcRTPHeader* rtp_header) override; | 89 const WebRtcRTPHeader* rtp_header) override; |
81 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override; | 90 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override; |
82 | 91 |
83 ReceiveStatistics* GetReceiveStatistics() const; | 92 ReceiveStatistics* GetReceiveStatistics() const; |
84 | 93 |
| 94 template <class T> |
| 95 class RegisterableCallback : public T { |
| 96 public: |
| 97 RegisterableCallback() : callback_(nullptr) {} |
| 98 |
| 99 void Set(T* callback) { |
| 100 rtc::CritScope lock(&critsect_); |
| 101 callback_ = callback; |
| 102 } |
| 103 |
| 104 protected: |
| 105 // Note: this should be implemented with a RW-lock to allow simultaneous |
| 106 // calls into the callback. However that doesn't seem to be needed for the |
| 107 // current type of callbacks covered by this class. |
| 108 rtc::CriticalSection critsect_; |
| 109 T* callback_ GUARDED_BY(critsect_); |
| 110 |
| 111 private: |
| 112 RTC_DISALLOW_COPY_AND_ASSIGN(RegisterableCallback); |
| 113 }; |
| 114 |
| 115 class RegisterableRtcpPacketTypeCounterObserver |
| 116 : public RegisterableCallback<RtcpPacketTypeCounterObserver> { |
| 117 public: |
| 118 void RtcpPacketTypesCounterUpdated( |
| 119 uint32_t ssrc, |
| 120 const RtcpPacketTypeCounter& packet_counter) override { |
| 121 rtc::CritScope lock(&critsect_); |
| 122 if (callback_) |
| 123 callback_->RtcpPacketTypesCounterUpdated(ssrc, packet_counter); |
| 124 } |
| 125 |
| 126 private: |
| 127 } rtcp_packet_type_counter_observer_; |
| 128 |
85 private: | 129 private: |
86 bool ReceivePacket(const uint8_t* packet, | 130 bool ReceivePacket(const uint8_t* packet, |
87 size_t packet_length, | 131 size_t packet_length, |
88 const RTPHeader& header, | 132 const RTPHeader& header, |
89 bool in_order); | 133 bool in_order); |
90 // Parses and handles for instance RTX and RED headers. | 134 // Parses and handles for instance RTX and RED headers. |
91 // This function assumes that it's being called from only one thread. | 135 // This function assumes that it's being called from only one thread. |
92 bool ParseAndHandleEncapsulatingHeader(const uint8_t* packet, | 136 bool ParseAndHandleEncapsulatingHeader(const uint8_t* packet, |
93 size_t packet_length, | 137 size_t packet_length, |
94 const RTPHeader& header); | 138 const RTPHeader& header); |
95 void NotifyReceiverOfFecPacket(const RTPHeader& header); | 139 void NotifyReceiverOfFecPacket(const RTPHeader& header); |
96 bool IsPacketInOrder(const RTPHeader& header) const; | 140 bool IsPacketInOrder(const RTPHeader& header) const; |
97 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const; | 141 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const; |
98 void UpdateHistograms(); | 142 void UpdateHistograms(); |
99 | 143 |
100 Clock* const clock_; | 144 Clock* const clock_; |
101 VideoCodingModule* const vcm_; | 145 VideoCodingModule* const vcm_; |
102 RemoteBitrateEstimator* const remote_bitrate_estimator_; | 146 RemoteBitrateEstimator* const remote_bitrate_estimator_; |
103 | 147 PacketRouter* const packet_router_; |
104 // TODO(pbos): Make const and set on construction. | |
105 RtpRtcp* rtp_rtcp_; // Owned by ViEChannel | |
106 | 148 |
107 RemoteNtpTimeEstimator ntp_estimator_; | 149 RemoteNtpTimeEstimator ntp_estimator_; |
108 RTPPayloadRegistry rtp_payload_registry_; | 150 RTPPayloadRegistry rtp_payload_registry_; |
109 | 151 |
110 const std::unique_ptr<RtpHeaderParser> rtp_header_parser_; | 152 const std::unique_ptr<RtpHeaderParser> rtp_header_parser_; |
111 const std::unique_ptr<RtpReceiver> rtp_receiver_; | 153 const std::unique_ptr<RtpReceiver> rtp_receiver_; |
112 const std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_; | 154 const std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_; |
113 std::unique_ptr<FecReceiver> fec_receiver_; | 155 std::unique_ptr<FecReceiver> fec_receiver_; |
114 | 156 |
115 rtc::CriticalSection receive_cs_; | 157 rtc::CriticalSection receive_cs_; |
116 bool receiving_ GUARDED_BY(receive_cs_); | 158 bool receiving_ GUARDED_BY(receive_cs_); |
117 uint8_t restored_packet_[IP_PACKET_SIZE] GUARDED_BY(receive_cs_); | 159 uint8_t restored_packet_[IP_PACKET_SIZE] GUARDED_BY(receive_cs_); |
118 bool restored_packet_in_use_ GUARDED_BY(receive_cs_); | 160 bool restored_packet_in_use_ GUARDED_BY(receive_cs_); |
119 int64_t last_packet_log_ms_ GUARDED_BY(receive_cs_); | 161 int64_t last_packet_log_ms_ GUARDED_BY(receive_cs_); |
| 162 |
| 163 const std::unique_ptr<RtpRtcp> rtp_rtcp_; |
120 }; | 164 }; |
121 | 165 |
122 } // namespace webrtc | 166 } // namespace webrtc |
123 | 167 |
124 #endif // WEBRTC_VIDEO_VIE_RECEIVER_H_ | 168 #endif // WEBRTC_VIDEO_VIE_RECEIVER_H_ |
OLD | NEW |