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