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_RTP_STREAM_RECEIVER_H_ | 11 #ifndef WEBRTC_VIDEO_RTP_STREAM_RECEIVER_H_ |
12 #define WEBRTC_VIDEO_RTP_STREAM_RECEIVER_H_ | 12 #define WEBRTC_VIDEO_RTP_STREAM_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/constructormagic.h" | 19 #include "webrtc/base/constructormagic.h" |
20 #include "webrtc/base/criticalsection.h" | 20 #include "webrtc/base/criticalsection.h" |
21 #include "webrtc/engine_configurations.h" | 21 #include "webrtc/engine_configurations.h" |
22 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" | 22 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" |
23 #include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h" | 23 #include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h" |
24 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" | 24 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" |
25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
26 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 26 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 27 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
27 #include "webrtc/typedefs.h" | 28 #include "webrtc/typedefs.h" |
| 29 #include "webrtc/video_receive_stream.h" |
28 | 30 |
29 namespace webrtc { | 31 namespace webrtc { |
30 | 32 |
31 class FecReceiver; | 33 class FecReceiver; |
32 class PacedSender; | 34 class PacedSender; |
33 class PacketRouter; | 35 class PacketRouter; |
34 class RemoteNtpTimeEstimator; | 36 class RemoteNtpTimeEstimator; |
35 class ReceiveStatistics; | 37 class ReceiveStatistics; |
| 38 class ReceiveStatisticsProxy; |
36 class RemoteBitrateEstimator; | 39 class RemoteBitrateEstimator; |
37 class RtcpRttStats; | 40 class RtcpRttStats; |
38 class RtpHeaderParser; | 41 class RtpHeaderParser; |
39 class RTPPayloadRegistry; | 42 class RTPPayloadRegistry; |
40 class RtpReceiver; | 43 class RtpReceiver; |
41 class Transport; | 44 class Transport; |
42 | 45 |
43 namespace vcm { | 46 namespace vcm { |
44 class VideoReceiver; | 47 class VideoReceiver; |
45 } // namespace vcm | 48 } // namespace vcm |
46 | 49 |
47 class RtpStreamReceiver : public RtpData, public RtpFeedback { | 50 class RtpStreamReceiver : public RtpData, public RtpFeedback, |
| 51 public VCMFrameTypeCallback, |
| 52 public VCMPacketRequestCallback { |
48 public: | 53 public: |
49 RtpStreamReceiver(vcm::VideoReceiver* video_receiver, | 54 RtpStreamReceiver(vcm::VideoReceiver* video_receiver, |
50 RemoteBitrateEstimator* remote_bitrate_estimator, | 55 RemoteBitrateEstimator* remote_bitrate_estimator, |
51 Transport* transport, | 56 Transport* transport, |
52 RtcpRttStats* rtt_stats, | 57 RtcpRttStats* rtt_stats, |
53 PacedSender* paced_sender, | 58 PacedSender* paced_sender, |
54 PacketRouter* packet_router); | 59 PacketRouter* packet_router, |
| 60 const VideoReceiveStream::Config& config, |
| 61 ReceiveStatisticsProxy* receive_stats_proxy); |
55 ~RtpStreamReceiver(); | 62 ~RtpStreamReceiver(); |
56 | 63 |
57 bool SetReceiveCodec(const VideoCodec& video_codec); | 64 bool SetReceiveCodec(const VideoCodec& video_codec); |
58 | 65 |
59 void SetNackStatus(bool enable, int max_nack_reordering_threshold); | |
60 void SetRtxPayloadType(int payload_type, int associated_payload_type); | 66 void SetRtxPayloadType(int payload_type, int associated_payload_type); |
61 // If set to true, the RTX payload type mapping supplied in | 67 // If set to true, the RTX payload type mapping supplied in |
62 // |SetRtxPayloadType| will be used when restoring RTX packets. Without it, | 68 // |SetRtxPayloadType| will be used when restoring RTX packets. Without it, |
63 // RTX packets will always be restored to the last non-RTX packet payload type | 69 // RTX packets will always be restored to the last non-RTX packet payload type |
64 // received. | 70 // received. |
65 void SetUseRtxPayloadMappingOnRestore(bool val); | 71 void SetUseRtxPayloadMappingOnRestore(bool val); |
66 void SetRtxSsrc(uint32_t ssrc); | 72 void SetRtxSsrc(uint32_t ssrc); |
67 bool GetRtxSsrc(uint32_t* ssrc) const; | 73 bool GetRtxSsrc(uint32_t* ssrc) const; |
68 | 74 |
69 bool IsFecEnabled() const; | 75 bool IsFecEnabled() const; |
70 | 76 |
71 uint32_t GetRemoteSsrc() const; | 77 uint32_t GetRemoteSsrc() const; |
72 int GetCsrcs(uint32_t* csrcs) const; | 78 int GetCsrcs(uint32_t* csrcs) const; |
73 | 79 |
74 RtpReceiver* GetRtpReceiver() const; | 80 RtpReceiver* GetRtpReceiver() const; |
75 RtpRtcp* rtp_rtcp() const { return rtp_rtcp_.get(); } | 81 RtpRtcp* rtp_rtcp() const { return rtp_rtcp_.get(); } |
76 | 82 |
77 void EnableReceiveRtpHeaderExtension(const std::string& extension, int id); | 83 void EnableReceiveRtpHeaderExtension(const std::string& extension, int id); |
78 void RegisterRtcpPacketTypeCounterObserver( | |
79 RtcpPacketTypeCounterObserver* observer); | |
80 | 84 |
81 void StartReceive(); | 85 void StartReceive(); |
82 void StopReceive(); | 86 void StopReceive(); |
83 | 87 |
84 bool DeliverRtp(const uint8_t* rtp_packet, | 88 bool DeliverRtp(const uint8_t* rtp_packet, |
85 size_t rtp_packet_length, | 89 size_t rtp_packet_length, |
86 const PacketTime& packet_time); | 90 const PacketTime& packet_time); |
87 bool DeliverRtcp(const uint8_t* rtcp_packet, size_t rtcp_packet_length); | 91 bool DeliverRtcp(const uint8_t* rtcp_packet, size_t rtcp_packet_length); |
88 | 92 |
89 // Implements RtpData. | 93 // Implements RtpData. |
90 int32_t OnReceivedPayloadData(const uint8_t* payload_data, | 94 int32_t OnReceivedPayloadData(const uint8_t* payload_data, |
91 const size_t payload_size, | 95 const size_t payload_size, |
92 const WebRtcRTPHeader* rtp_header) override; | 96 const WebRtcRTPHeader* rtp_header) override; |
93 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override; | 97 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override; |
94 | 98 |
95 // Implements RtpFeedback. | 99 // Implements RtpFeedback. |
96 int32_t OnInitializeDecoder(const int8_t payload_type, | 100 int32_t OnInitializeDecoder(const int8_t payload_type, |
97 const char payload_name[RTP_PAYLOAD_NAME_SIZE], | 101 const char payload_name[RTP_PAYLOAD_NAME_SIZE], |
98 const int frequency, | 102 const int frequency, |
99 const size_t channels, | 103 const size_t channels, |
100 const uint32_t rate) override; | 104 const uint32_t rate) override; |
101 void OnIncomingSSRCChanged(const uint32_t ssrc) override; | 105 void OnIncomingSSRCChanged(const uint32_t ssrc) override; |
102 void OnIncomingCSRCChanged(const uint32_t CSRC, const bool added) override {} | 106 void OnIncomingCSRCChanged(const uint32_t CSRC, const bool added) override {} |
103 | 107 |
| 108 // Implements VCMFrameTypeCallback. |
| 109 int32_t RequestKeyFrame() override; |
| 110 int32_t SliceLossIndicationRequest(const uint64_t picture_id) override; |
| 111 |
| 112 // Implements VCMPacketRequestCallback. |
| 113 int32_t ResendPackets(const uint16_t* sequenceNumbers, |
| 114 uint16_t length) override; |
| 115 |
104 ReceiveStatistics* GetReceiveStatistics() const; | 116 ReceiveStatistics* GetReceiveStatistics() const; |
105 | 117 |
106 template <class T> | |
107 class RegisterableCallback : public T { | |
108 public: | |
109 RegisterableCallback() : callback_(nullptr) {} | |
110 | |
111 void Set(T* callback) { | |
112 rtc::CritScope lock(&critsect_); | |
113 callback_ = callback; | |
114 } | |
115 | |
116 protected: | |
117 // Note: this should be implemented with a RW-lock to allow simultaneous | |
118 // calls into the callback. However that doesn't seem to be needed for the | |
119 // current type of callbacks covered by this class. | |
120 rtc::CriticalSection critsect_; | |
121 T* callback_ GUARDED_BY(critsect_); | |
122 | |
123 private: | |
124 RTC_DISALLOW_COPY_AND_ASSIGN(RegisterableCallback); | |
125 }; | |
126 | |
127 class RegisterableRtcpPacketTypeCounterObserver | |
128 : public RegisterableCallback<RtcpPacketTypeCounterObserver> { | |
129 public: | |
130 void RtcpPacketTypesCounterUpdated( | |
131 uint32_t ssrc, | |
132 const RtcpPacketTypeCounter& packet_counter) override { | |
133 rtc::CritScope lock(&critsect_); | |
134 if (callback_) | |
135 callback_->RtcpPacketTypesCounterUpdated(ssrc, packet_counter); | |
136 } | |
137 | |
138 private: | |
139 } rtcp_packet_type_counter_observer_; | |
140 | |
141 private: | 118 private: |
142 bool ReceivePacket(const uint8_t* packet, | 119 bool ReceivePacket(const uint8_t* packet, |
143 size_t packet_length, | 120 size_t packet_length, |
144 const RTPHeader& header, | 121 const RTPHeader& header, |
145 bool in_order); | 122 bool in_order); |
146 // Parses and handles for instance RTX and RED headers. | 123 // Parses and handles for instance RTX and RED headers. |
147 // This function assumes that it's being called from only one thread. | 124 // This function assumes that it's being called from only one thread. |
148 bool ParseAndHandleEncapsulatingHeader(const uint8_t* packet, | 125 bool ParseAndHandleEncapsulatingHeader(const uint8_t* packet, |
149 size_t packet_length, | 126 size_t packet_length, |
150 const RTPHeader& header); | 127 const RTPHeader& header); |
(...skipping 20 matching lines...) Expand all Loading... |
171 uint8_t restored_packet_[IP_PACKET_SIZE] GUARDED_BY(receive_cs_); | 148 uint8_t restored_packet_[IP_PACKET_SIZE] GUARDED_BY(receive_cs_); |
172 bool restored_packet_in_use_ GUARDED_BY(receive_cs_); | 149 bool restored_packet_in_use_ GUARDED_BY(receive_cs_); |
173 int64_t last_packet_log_ms_ GUARDED_BY(receive_cs_); | 150 int64_t last_packet_log_ms_ GUARDED_BY(receive_cs_); |
174 | 151 |
175 const std::unique_ptr<RtpRtcp> rtp_rtcp_; | 152 const std::unique_ptr<RtpRtcp> rtp_rtcp_; |
176 }; | 153 }; |
177 | 154 |
178 } // namespace webrtc | 155 } // namespace webrtc |
179 | 156 |
180 #endif // WEBRTC_VIDEO_RTP_STREAM_RECEIVER_H_ | 157 #endif // WEBRTC_VIDEO_RTP_STREAM_RECEIVER_H_ |
OLD | NEW |