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 #include "webrtc/video/vie_receiver.h" | 11 #include "webrtc/video/vie_receiver.h" |
12 | 12 |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "webrtc/base/logging.h" | 15 #include "webrtc/base/logging.h" |
16 #include "webrtc/config.h" | 16 #include "webrtc/config.h" |
| 17 #include "webrtc/modules/pacing/packet_router.h" |
17 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" | 18 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" |
18 #include "webrtc/modules/rtp_rtcp/include/fec_receiver.h" | 19 #include "webrtc/modules/rtp_rtcp/include/fec_receiver.h" |
19 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" | 20 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" |
20 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" | 21 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" |
21 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" | 22 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
22 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" | 23 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" |
23 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
24 #include "webrtc/modules/video_coding/video_coding_impl.h" | 25 #include "webrtc/modules/video_coding/video_coding_impl.h" |
25 #include "webrtc/system_wrappers/include/metrics.h" | 26 #include "webrtc/system_wrappers/include/metrics.h" |
26 #include "webrtc/system_wrappers/include/tick_util.h" | 27 #include "webrtc/system_wrappers/include/tick_util.h" |
27 #include "webrtc/system_wrappers/include/timestamp_extrapolator.h" | 28 #include "webrtc/system_wrappers/include/timestamp_extrapolator.h" |
28 #include "webrtc/system_wrappers/include/trace.h" | 29 #include "webrtc/system_wrappers/include/trace.h" |
29 | 30 |
30 namespace webrtc { | 31 namespace webrtc { |
31 | 32 |
| 33 std::unique_ptr<RtpRtcp> CreateRtpRtcpModule( |
| 34 ReceiveStatistics* receive_statistics, |
| 35 Transport* outgoing_transport, |
| 36 RtcpRttStats* rtt_stats, |
| 37 RtcpPacketTypeCounterObserver* rtcp_packet_type_counter_observer, |
| 38 RemoteBitrateEstimator* remote_bitrate_estimator, |
| 39 RtpPacketSender* paced_sender, |
| 40 TransportSequenceNumberAllocator* transport_sequence_number_allocator) { |
| 41 RtpRtcp::Configuration configuration; |
| 42 configuration.audio = false; |
| 43 configuration.receiver_only = true; |
| 44 configuration.receive_statistics = receive_statistics; |
| 45 configuration.outgoing_transport = outgoing_transport; |
| 46 configuration.intra_frame_callback = nullptr; |
| 47 configuration.rtt_stats = rtt_stats; |
| 48 configuration.rtcp_packet_type_counter_observer = |
| 49 rtcp_packet_type_counter_observer; |
| 50 configuration.paced_sender = paced_sender; |
| 51 configuration.transport_sequence_number_allocator = |
| 52 transport_sequence_number_allocator; |
| 53 configuration.send_bitrate_observer = nullptr; |
| 54 configuration.send_frame_count_observer = nullptr; |
| 55 configuration.send_side_delay_observer = nullptr; |
| 56 configuration.bandwidth_callback = nullptr; |
| 57 configuration.transport_feedback_callback = nullptr; |
| 58 |
| 59 std::unique_ptr<RtpRtcp> rtp_rtcp(RtpRtcp::CreateRtpRtcp(configuration)); |
| 60 rtp_rtcp->SetSendingStatus(false); |
| 61 rtp_rtcp->SetSendingMediaStatus(false); |
| 62 rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound); |
| 63 |
| 64 return rtp_rtcp; |
| 65 } |
| 66 |
| 67 |
32 static const int kPacketLogIntervalMs = 10000; | 68 static const int kPacketLogIntervalMs = 10000; |
33 | 69 |
34 ViEReceiver::ViEReceiver(vcm::VideoReceiver* video_receiver, | 70 ViEReceiver::ViEReceiver(vcm::VideoReceiver* video_receiver, |
35 RemoteBitrateEstimator* remote_bitrate_estimator, | 71 RemoteBitrateEstimator* remote_bitrate_estimator, |
36 RtpFeedback* rtp_feedback) | 72 RtpFeedback* rtp_feedback, |
| 73 Transport* transport, |
| 74 RtcpRttStats* rtt_stats, |
| 75 PacedSender* paced_sender, |
| 76 PacketRouter* packet_router) |
37 : clock_(Clock::GetRealTimeClock()), | 77 : clock_(Clock::GetRealTimeClock()), |
38 video_receiver_(video_receiver), | 78 video_receiver_(video_receiver), |
39 remote_bitrate_estimator_(remote_bitrate_estimator), | 79 remote_bitrate_estimator_(remote_bitrate_estimator), |
| 80 packet_router_(packet_router), |
40 ntp_estimator_(clock_), | 81 ntp_estimator_(clock_), |
41 rtp_payload_registry_(RTPPayloadStrategy::CreateStrategy(false)), | 82 rtp_payload_registry_(RTPPayloadStrategy::CreateStrategy(false)), |
42 rtp_header_parser_(RtpHeaderParser::Create()), | 83 rtp_header_parser_(RtpHeaderParser::Create()), |
43 rtp_receiver_(RtpReceiver::CreateVideoReceiver(clock_, | 84 rtp_receiver_(RtpReceiver::CreateVideoReceiver(clock_, |
44 this, | 85 this, |
45 rtp_feedback, | 86 rtp_feedback, |
46 &rtp_payload_registry_)), | 87 &rtp_payload_registry_)), |
47 rtp_receive_statistics_(ReceiveStatistics::Create(clock_)), | 88 rtp_receive_statistics_(ReceiveStatistics::Create(clock_)), |
48 fec_receiver_(FecReceiver::Create(this)), | 89 fec_receiver_(FecReceiver::Create(this)), |
49 receiving_(false), | 90 receiving_(false), |
50 restored_packet_in_use_(false), | 91 restored_packet_in_use_(false), |
51 last_packet_log_ms_(-1) {} | 92 last_packet_log_ms_(-1), |
| 93 rtp_rtcp_(CreateRtpRtcpModule(rtp_receive_statistics_.get(), |
| 94 transport, |
| 95 rtt_stats, |
| 96 &rtcp_packet_type_counter_observer_, |
| 97 remote_bitrate_estimator_, |
| 98 paced_sender, |
| 99 packet_router)) { |
| 100 packet_router_->AddRtpModule(rtp_rtcp_.get()); |
| 101 rtp_rtcp_->SetKeyFrameRequestMethod(kKeyFrameReqPliRtcp); |
| 102 } |
52 | 103 |
53 ViEReceiver::~ViEReceiver() { | 104 ViEReceiver::~ViEReceiver() { |
| 105 packet_router_->RemoveRtpModule(rtp_rtcp_.get()); |
54 UpdateHistograms(); | 106 UpdateHistograms(); |
55 } | 107 } |
56 | 108 |
57 void ViEReceiver::UpdateHistograms() { | 109 void ViEReceiver::UpdateHistograms() { |
58 FecPacketCounter counter = fec_receiver_->GetPacketCounter(); | 110 FecPacketCounter counter = fec_receiver_->GetPacketCounter(); |
59 if (counter.num_packets > 0) { | 111 if (counter.num_packets > 0) { |
60 RTC_LOGGED_HISTOGRAM_PERCENTAGE( | 112 RTC_LOGGED_HISTOGRAM_PERCENTAGE( |
61 "WebRTC.Video.ReceivedFecPacketsInPercent", | 113 "WebRTC.Video.ReceivedFecPacketsInPercent", |
62 static_cast<int>(counter.num_fec_packets * 100 / counter.num_packets)); | 114 static_cast<int>(counter.num_fec_packets * 100 / counter.num_packets)); |
63 } | 115 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } | 169 } |
118 | 170 |
119 uint32_t ViEReceiver::GetRemoteSsrc() const { | 171 uint32_t ViEReceiver::GetRemoteSsrc() const { |
120 return rtp_receiver_->SSRC(); | 172 return rtp_receiver_->SSRC(); |
121 } | 173 } |
122 | 174 |
123 int ViEReceiver::GetCsrcs(uint32_t* csrcs) const { | 175 int ViEReceiver::GetCsrcs(uint32_t* csrcs) const { |
124 return rtp_receiver_->CSRCs(csrcs); | 176 return rtp_receiver_->CSRCs(csrcs); |
125 } | 177 } |
126 | 178 |
127 void ViEReceiver::Init(RtpRtcp* rtp_rtcp) { | |
128 rtp_rtcp_ = rtp_rtcp; | |
129 } | |
130 | |
131 RtpReceiver* ViEReceiver::GetRtpReceiver() const { | 179 RtpReceiver* ViEReceiver::GetRtpReceiver() const { |
132 return rtp_receiver_.get(); | 180 return rtp_receiver_.get(); |
133 } | 181 } |
134 | 182 |
135 void ViEReceiver::EnableReceiveRtpHeaderExtension(const std::string& extension, | 183 void ViEReceiver::EnableReceiveRtpHeaderExtension(const std::string& extension, |
136 int id) { | 184 int id) { |
137 RTC_DCHECK(RtpExtension::IsSupportedForVideo(extension)); | 185 RTC_DCHECK(RtpExtension::IsSupportedForVideo(extension)); |
138 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( | 186 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( |
139 StringToRtpExtensionType(extension), id)); | 187 StringToRtpExtensionType(extension), id)); |
140 } | 188 } |
141 | 189 |
| 190 void ViEReceiver::RegisterRtcpPacketTypeCounterObserver( |
| 191 RtcpPacketTypeCounterObserver* observer) { |
| 192 rtcp_packet_type_counter_observer_.Set(observer); |
| 193 } |
| 194 |
| 195 |
142 int32_t ViEReceiver::OnReceivedPayloadData(const uint8_t* payload_data, | 196 int32_t ViEReceiver::OnReceivedPayloadData(const uint8_t* payload_data, |
143 const size_t payload_size, | 197 const size_t payload_size, |
144 const WebRtcRTPHeader* rtp_header) { | 198 const WebRtcRTPHeader* rtp_header) { |
145 RTC_DCHECK(video_receiver_); | 199 RTC_DCHECK(video_receiver_); |
146 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header; | 200 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header; |
147 rtp_header_with_ntp.ntp_time_ms = | 201 rtp_header_with_ntp.ntp_time_ms = |
148 ntp_estimator_.Estimate(rtp_header->header.timestamp); | 202 ntp_estimator_.Estimate(rtp_header->header.timestamp); |
149 if (video_receiver_->IncomingPacket(payload_data, payload_size, | 203 if (video_receiver_->IncomingPacket(payload_data, payload_size, |
150 rtp_header_with_ntp) != 0) { | 204 rtp_header_with_ntp) != 0) { |
151 // Check this... | 205 // Check this... |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 rtp_receive_statistics_->GetStatistician(header.ssrc); | 431 rtp_receive_statistics_->GetStatistician(header.ssrc); |
378 if (!statistician) | 432 if (!statistician) |
379 return false; | 433 return false; |
380 // Check if this is a retransmission. | 434 // Check if this is a retransmission. |
381 int64_t min_rtt = 0; | 435 int64_t min_rtt = 0; |
382 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), nullptr, nullptr, &min_rtt, nullptr); | 436 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), nullptr, nullptr, &min_rtt, nullptr); |
383 return !in_order && | 437 return !in_order && |
384 statistician->IsRetransmitOfOldPacket(header, min_rtt); | 438 statistician->IsRetransmitOfOldPacket(header, min_rtt); |
385 } | 439 } |
386 } // namespace webrtc | 440 } // namespace webrtc |
OLD | NEW |