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 | 41 |
38 namespace vcm { | 42 namespace vcm { |
39 class VideoReceiver; | 43 class VideoReceiver; |
40 } // namespace vcm | 44 } // namespace vcm |
41 | 45 |
42 class ViEReceiver : public RtpData { | 46 class ViEReceiver : public RtpData { |
43 public: | 47 public: |
44 ViEReceiver(vcm::VideoReceiver* video_receiver, | 48 ViEReceiver(vcm::VideoReceiver* video_receiver, |
45 RemoteBitrateEstimator* remote_bitrate_estimator, | 49 RemoteBitrateEstimator* remote_bitrate_estimator, |
46 RtpFeedback* rtp_feedback); | 50 RtpFeedback* rtp_feedback, |
| 51 Transport* transport, |
| 52 RtcpRttStats* rtt_stats, |
| 53 PacedSender* paced_sender, |
| 54 PacketRouter* packet_router); |
47 ~ViEReceiver(); | 55 ~ViEReceiver(); |
48 | 56 |
49 bool SetReceiveCodec(const VideoCodec& video_codec); | 57 bool SetReceiveCodec(const VideoCodec& video_codec); |
50 | 58 |
51 void SetNackStatus(bool enable, int max_nack_reordering_threshold); | 59 void SetNackStatus(bool enable, int max_nack_reordering_threshold); |
52 void SetRtxPayloadType(int payload_type, int associated_payload_type); | 60 void SetRtxPayloadType(int payload_type, int associated_payload_type); |
53 // If set to true, the RTX payload type mapping supplied in | 61 // If set to true, the RTX payload type mapping supplied in |
54 // |SetRtxPayloadType| will be used when restoring RTX packets. Without it, | 62 // |SetRtxPayloadType| will be used when restoring RTX packets. Without it, |
55 // RTX packets will always be restored to the last non-RTX packet payload type | 63 // RTX packets will always be restored to the last non-RTX packet payload type |
56 // received. | 64 // received. |
57 void SetUseRtxPayloadMappingOnRestore(bool val); | 65 void SetUseRtxPayloadMappingOnRestore(bool val); |
58 void SetRtxSsrc(uint32_t ssrc); | 66 void SetRtxSsrc(uint32_t ssrc); |
59 bool GetRtxSsrc(uint32_t* ssrc) const; | 67 bool GetRtxSsrc(uint32_t* ssrc) const; |
60 | 68 |
61 bool IsFecEnabled() const; | 69 bool IsFecEnabled() const; |
62 | 70 |
63 uint32_t GetRemoteSsrc() const; | 71 uint32_t GetRemoteSsrc() const; |
64 int GetCsrcs(uint32_t* csrcs) const; | 72 int GetCsrcs(uint32_t* csrcs) const; |
65 | 73 |
66 void Init(RtpRtcp* rtp_rtcp); | |
67 | |
68 RtpReceiver* GetRtpReceiver() const; | 74 RtpReceiver* GetRtpReceiver() const; |
| 75 RtpRtcp* rtp_rtcp() const { return rtp_rtcp_.get(); } |
69 | 76 |
70 void EnableReceiveRtpHeaderExtension(const std::string& extension, int id); | 77 void EnableReceiveRtpHeaderExtension(const std::string& extension, int id); |
| 78 void RegisterRtcpPacketTypeCounterObserver( |
| 79 RtcpPacketTypeCounterObserver* observer); |
71 | 80 |
72 void StartReceive(); | 81 void StartReceive(); |
73 void StopReceive(); | 82 void StopReceive(); |
74 | 83 |
75 bool DeliverRtp(const uint8_t* rtp_packet, | 84 bool DeliverRtp(const uint8_t* rtp_packet, |
76 size_t rtp_packet_length, | 85 size_t rtp_packet_length, |
77 const PacketTime& packet_time); | 86 const PacketTime& packet_time); |
78 bool DeliverRtcp(const uint8_t* rtcp_packet, size_t rtcp_packet_length); | 87 bool DeliverRtcp(const uint8_t* rtcp_packet, size_t rtcp_packet_length); |
79 | 88 |
80 // Implements RtpData. | 89 // Implements RtpData. |
81 int32_t OnReceivedPayloadData(const uint8_t* payload_data, | 90 int32_t OnReceivedPayloadData(const uint8_t* payload_data, |
82 const size_t payload_size, | 91 const size_t payload_size, |
83 const WebRtcRTPHeader* rtp_header) override; | 92 const WebRtcRTPHeader* rtp_header) override; |
84 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override; | 93 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override; |
85 | 94 |
86 ReceiveStatistics* GetReceiveStatistics() const; | 95 ReceiveStatistics* GetReceiveStatistics() const; |
87 | 96 |
| 97 template <class T> |
| 98 class RegisterableCallback : public T { |
| 99 public: |
| 100 RegisterableCallback() : callback_(nullptr) {} |
| 101 |
| 102 void Set(T* callback) { |
| 103 rtc::CritScope lock(&critsect_); |
| 104 callback_ = callback; |
| 105 } |
| 106 |
| 107 protected: |
| 108 // Note: this should be implemented with a RW-lock to allow simultaneous |
| 109 // calls into the callback. However that doesn't seem to be needed for the |
| 110 // current type of callbacks covered by this class. |
| 111 rtc::CriticalSection critsect_; |
| 112 T* callback_ GUARDED_BY(critsect_); |
| 113 |
| 114 private: |
| 115 RTC_DISALLOW_COPY_AND_ASSIGN(RegisterableCallback); |
| 116 }; |
| 117 |
| 118 class RegisterableRtcpPacketTypeCounterObserver |
| 119 : public RegisterableCallback<RtcpPacketTypeCounterObserver> { |
| 120 public: |
| 121 void RtcpPacketTypesCounterUpdated( |
| 122 uint32_t ssrc, |
| 123 const RtcpPacketTypeCounter& packet_counter) override { |
| 124 rtc::CritScope lock(&critsect_); |
| 125 if (callback_) |
| 126 callback_->RtcpPacketTypesCounterUpdated(ssrc, packet_counter); |
| 127 } |
| 128 |
| 129 private: |
| 130 } rtcp_packet_type_counter_observer_; |
| 131 |
88 private: | 132 private: |
89 bool ReceivePacket(const uint8_t* packet, | 133 bool ReceivePacket(const uint8_t* packet, |
90 size_t packet_length, | 134 size_t packet_length, |
91 const RTPHeader& header, | 135 const RTPHeader& header, |
92 bool in_order); | 136 bool in_order); |
93 // Parses and handles for instance RTX and RED headers. | 137 // Parses and handles for instance RTX and RED headers. |
94 // This function assumes that it's being called from only one thread. | 138 // This function assumes that it's being called from only one thread. |
95 bool ParseAndHandleEncapsulatingHeader(const uint8_t* packet, | 139 bool ParseAndHandleEncapsulatingHeader(const uint8_t* packet, |
96 size_t packet_length, | 140 size_t packet_length, |
97 const RTPHeader& header); | 141 const RTPHeader& header); |
98 void NotifyReceiverOfFecPacket(const RTPHeader& header); | 142 void NotifyReceiverOfFecPacket(const RTPHeader& header); |
99 bool IsPacketInOrder(const RTPHeader& header) const; | 143 bool IsPacketInOrder(const RTPHeader& header) const; |
100 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const; | 144 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const; |
101 void UpdateHistograms(); | 145 void UpdateHistograms(); |
102 | 146 |
103 Clock* const clock_; | 147 Clock* const clock_; |
104 vcm::VideoReceiver* const video_receiver_; | 148 vcm::VideoReceiver* const video_receiver_; |
105 RemoteBitrateEstimator* const remote_bitrate_estimator_; | 149 RemoteBitrateEstimator* const remote_bitrate_estimator_; |
106 | 150 PacketRouter* const packet_router_; |
107 // TODO(pbos): Make const and set on construction. | |
108 RtpRtcp* rtp_rtcp_; // Owned by ViEChannel | |
109 | 151 |
110 RemoteNtpTimeEstimator ntp_estimator_; | 152 RemoteNtpTimeEstimator ntp_estimator_; |
111 RTPPayloadRegistry rtp_payload_registry_; | 153 RTPPayloadRegistry rtp_payload_registry_; |
112 | 154 |
113 const std::unique_ptr<RtpHeaderParser> rtp_header_parser_; | 155 const std::unique_ptr<RtpHeaderParser> rtp_header_parser_; |
114 const std::unique_ptr<RtpReceiver> rtp_receiver_; | 156 const std::unique_ptr<RtpReceiver> rtp_receiver_; |
115 const std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_; | 157 const std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_; |
116 std::unique_ptr<FecReceiver> fec_receiver_; | 158 std::unique_ptr<FecReceiver> fec_receiver_; |
117 | 159 |
118 rtc::CriticalSection receive_cs_; | 160 rtc::CriticalSection receive_cs_; |
119 bool receiving_ GUARDED_BY(receive_cs_); | 161 bool receiving_ GUARDED_BY(receive_cs_); |
120 uint8_t restored_packet_[IP_PACKET_SIZE] GUARDED_BY(receive_cs_); | 162 uint8_t restored_packet_[IP_PACKET_SIZE] GUARDED_BY(receive_cs_); |
121 bool restored_packet_in_use_ GUARDED_BY(receive_cs_); | 163 bool restored_packet_in_use_ GUARDED_BY(receive_cs_); |
122 int64_t last_packet_log_ms_ GUARDED_BY(receive_cs_); | 164 int64_t last_packet_log_ms_ GUARDED_BY(receive_cs_); |
| 165 |
| 166 const std::unique_ptr<RtpRtcp> rtp_rtcp_; |
123 }; | 167 }; |
124 | 168 |
125 } // namespace webrtc | 169 } // namespace webrtc |
126 | 170 |
127 #endif // WEBRTC_VIDEO_VIE_RECEIVER_H_ | 171 #endif // WEBRTC_VIDEO_VIE_RECEIVER_H_ |
OLD | NEW |