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_channel.h" | 11 #include "webrtc/video/vie_channel.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <map> | 14 #include <map> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
19 #include "webrtc/base/platform_thread.h" | 19 #include "webrtc/base/platform_thread.h" |
20 #include "webrtc/common_video/include/frame_callback.h" | 20 #include "webrtc/common_video/include/frame_callback.h" |
21 #include "webrtc/common_video/include/incoming_video_stream.h" | 21 #include "webrtc/common_video/include/incoming_video_stream.h" |
22 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 22 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
23 #include "webrtc/modules/pacing/paced_sender.h" | |
24 #include "webrtc/modules/pacing/packet_router.h" | |
25 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" | 23 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" |
26 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
27 #include "webrtc/modules/utility/include/process_thread.h" | 25 #include "webrtc/modules/utility/include/process_thread.h" |
28 #include "webrtc/modules/video_coding/video_coding_impl.h" | 26 #include "webrtc/modules/video_coding/video_coding_impl.h" |
29 #include "webrtc/modules/video_processing/include/video_processing.h" | 27 #include "webrtc/modules/video_processing/include/video_processing.h" |
30 #include "webrtc/modules/video_render/video_render_defines.h" | 28 #include "webrtc/modules/video_render/video_render_defines.h" |
31 #include "webrtc/system_wrappers/include/metrics.h" | 29 #include "webrtc/system_wrappers/include/metrics.h" |
32 #include "webrtc/video/call_stats.h" | 30 #include "webrtc/video/call_stats.h" |
33 #include "webrtc/video/payload_router.h" | 31 #include "webrtc/video/payload_router.h" |
34 #include "webrtc/video/receive_statistics_proxy.h" | 32 #include "webrtc/video/receive_statistics_proxy.h" |
35 | 33 |
36 namespace webrtc { | 34 namespace webrtc { |
37 | 35 |
38 static const int kMaxPacketAgeToNack = 450; | 36 static const int kMaxPacketAgeToNack = 450; |
39 static const int kMaxNackListSize = 250; | 37 static const int kMaxNackListSize = 250; |
40 | 38 |
41 namespace { | |
42 | |
43 std::unique_ptr<RtpRtcp> CreateRtpRtcpModule( | |
44 ReceiveStatistics* receive_statistics, | |
45 Transport* outgoing_transport, | |
46 RtcpRttStats* rtt_stats, | |
47 RtcpPacketTypeCounterObserver* rtcp_packet_type_counter_observer, | |
48 RemoteBitrateEstimator* remote_bitrate_estimator, | |
49 RtpPacketSender* paced_sender, | |
50 TransportSequenceNumberAllocator* transport_sequence_number_allocator) { | |
51 RtpRtcp::Configuration configuration; | |
52 configuration.audio = false; | |
53 configuration.receiver_only = true; | |
54 configuration.receive_statistics = receive_statistics; | |
55 configuration.outgoing_transport = outgoing_transport; | |
56 configuration.intra_frame_callback = nullptr; | |
57 configuration.rtt_stats = rtt_stats; | |
58 configuration.rtcp_packet_type_counter_observer = | |
59 rtcp_packet_type_counter_observer; | |
60 configuration.paced_sender = paced_sender; | |
61 configuration.transport_sequence_number_allocator = | |
62 transport_sequence_number_allocator; | |
63 configuration.send_bitrate_observer = nullptr; | |
64 configuration.send_frame_count_observer = nullptr; | |
65 configuration.send_side_delay_observer = nullptr; | |
66 configuration.bandwidth_callback = nullptr; | |
67 configuration.transport_feedback_callback = nullptr; | |
68 | |
69 std::unique_ptr<RtpRtcp> rtp_rtcp(RtpRtcp::CreateRtpRtcp(configuration)); | |
70 rtp_rtcp->SetSendingStatus(false); | |
71 rtp_rtcp->SetSendingMediaStatus(false); | |
72 rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound); | |
73 | |
74 return rtp_rtcp; | |
75 } | |
76 | |
77 } // namespace | |
78 | |
79 // Helper class receiving statistics callbacks. | 39 // Helper class receiving statistics callbacks. |
80 class ChannelStatsObserver : public CallStatsObserver { | 40 class ChannelStatsObserver : public CallStatsObserver { |
81 public: | 41 public: |
82 explicit ChannelStatsObserver(ViEChannel* owner) : owner_(owner) {} | 42 explicit ChannelStatsObserver(ViEChannel* owner) : owner_(owner) {} |
83 virtual ~ChannelStatsObserver() {} | 43 virtual ~ChannelStatsObserver() {} |
84 | 44 |
85 // Implements StatsObserver. | 45 // Implements StatsObserver. |
86 virtual void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 46 virtual void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
87 owner_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); | 47 owner_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); |
88 } | 48 } |
89 | 49 |
90 private: | 50 private: |
91 ViEChannel* const owner_; | 51 ViEChannel* const owner_; |
92 }; | 52 }; |
93 | 53 |
94 ViEChannel::ViEChannel(Transport* transport, | 54 ViEChannel::ViEChannel(Transport* transport, |
95 ProcessThread* module_process_thread, | 55 ProcessThread* module_process_thread, |
96 vcm::VideoReceiver* video_receiver, | 56 vcm::VideoReceiver* video_receiver, |
97 RemoteBitrateEstimator* remote_bitrate_estimator, | 57 RemoteBitrateEstimator* remote_bitrate_estimator, |
98 RtcpRttStats* rtt_stats, | 58 RtcpRttStats* rtt_stats, |
99 PacedSender* paced_sender, | 59 PacedSender* paced_sender, |
100 PacketRouter* packet_router) | 60 PacketRouter* packet_router) |
101 : module_process_thread_(module_process_thread), | 61 : module_process_thread_(module_process_thread), |
102 video_receiver_(video_receiver), | 62 video_receiver_(video_receiver), |
103 vie_receiver_(video_receiver_, remote_bitrate_estimator, this), | 63 vie_receiver_(video_receiver, remote_bitrate_estimator, this, transport, |
| 64 rtt_stats, paced_sender, packet_router), |
| 65 rtp_rtcp_(vie_receiver_.rtp_rtcp()), |
104 stats_observer_(new ChannelStatsObserver(this)), | 66 stats_observer_(new ChannelStatsObserver(this)), |
105 receive_stats_callback_(nullptr), | 67 receive_stats_callback_(nullptr), |
106 incoming_video_stream_(nullptr), | 68 incoming_video_stream_(nullptr), |
107 rtt_stats_(rtt_stats), | |
108 paced_sender_(paced_sender), | |
109 packet_router_(packet_router), | |
110 max_nack_reordering_threshold_(kMaxPacketAgeToNack), | 69 max_nack_reordering_threshold_(kMaxPacketAgeToNack), |
111 pre_render_callback_(nullptr), | 70 pre_render_callback_(nullptr), |
112 last_rtt_ms_(0), | 71 last_rtt_ms_(0) { |
113 rtp_rtcp_(CreateRtpRtcpModule(vie_receiver_.GetReceiveStatistics(), | |
114 transport, | |
115 rtt_stats_, | |
116 &rtcp_packet_type_counter_observer_, | |
117 remote_bitrate_estimator, | |
118 paced_sender_, | |
119 packet_router_)) { | |
120 vie_receiver_.Init(rtp_rtcp_.get()); | |
121 RTC_DCHECK(video_receiver_); | 72 RTC_DCHECK(video_receiver_); |
122 video_receiver_->SetNackSettings(kMaxNackListSize, | 73 video_receiver_->SetNackSettings(kMaxNackListSize, |
123 max_nack_reordering_threshold_, 0); | 74 max_nack_reordering_threshold_, 0); |
124 } | 75 } |
125 | 76 |
126 int32_t ViEChannel::Init() { | 77 int32_t ViEChannel::Init() { |
127 static const int kDefaultRenderDelayMs = 10; | 78 static const int kDefaultRenderDelayMs = 10; |
128 module_process_thread_->RegisterModule(vie_receiver_.GetReceiveStatistics()); | 79 module_process_thread_->RegisterModule(vie_receiver_.GetReceiveStatistics()); |
| 80 module_process_thread_->RegisterModule(rtp_rtcp_); |
129 | 81 |
130 // RTP/RTCP initialization. | |
131 module_process_thread_->RegisterModule(rtp_rtcp_.get()); | |
132 packet_router_->AddRtpModule(rtp_rtcp_.get()); | |
133 | |
134 rtp_rtcp_->SetKeyFrameRequestMethod(kKeyFrameReqPliRtcp); | |
135 if (video_receiver_->RegisterReceiveCallback(this) != 0) { | 82 if (video_receiver_->RegisterReceiveCallback(this) != 0) { |
136 return -1; | 83 return -1; |
137 } | 84 } |
138 video_receiver_->RegisterFrameTypeCallback(this); | 85 video_receiver_->RegisterFrameTypeCallback(this); |
139 video_receiver_->RegisterReceiveStatisticsCallback(this); | 86 video_receiver_->RegisterReceiveStatisticsCallback(this); |
140 video_receiver_->RegisterDecoderTimingCallback(this); | 87 video_receiver_->RegisterDecoderTimingCallback(this); |
141 video_receiver_->SetRenderDelay(kDefaultRenderDelayMs); | 88 video_receiver_->SetRenderDelay(kDefaultRenderDelayMs); |
142 | 89 |
143 return 0; | 90 return 0; |
144 } | 91 } |
145 | 92 |
146 ViEChannel::~ViEChannel() { | 93 ViEChannel::~ViEChannel() { |
147 // Make sure we don't get more callbacks from the RTP module. | 94 // Make sure we don't get more callbacks from the RTP module. |
148 module_process_thread_->DeRegisterModule( | 95 module_process_thread_->DeRegisterModule( |
149 vie_receiver_.GetReceiveStatistics()); | 96 vie_receiver_.GetReceiveStatistics()); |
150 | 97 |
151 packet_router_->RemoveRtpModule(rtp_rtcp_.get()); | 98 module_process_thread_->DeRegisterModule(rtp_rtcp_); |
152 module_process_thread_->DeRegisterModule(rtp_rtcp_.get()); | |
153 } | 99 } |
154 | 100 |
155 void ViEChannel::SetProtectionMode(bool enable_nack, | 101 void ViEChannel::SetProtectionMode(bool enable_nack, |
156 bool enable_fec, | 102 bool enable_fec, |
157 int payload_type_red, | 103 int payload_type_red, |
158 int payload_type_fec) { | 104 int payload_type_fec) { |
159 // Validate payload types. If either RED or FEC payload types are set then | 105 // Validate payload types. If either RED or FEC payload types are set then |
160 // both should be. If FEC is enabled then they both have to be set. | 106 // both should be. If FEC is enabled then they both have to be set. |
161 if (enable_fec || payload_type_red != -1 || payload_type_fec != -1) { | 107 if (enable_fec || payload_type_red != -1 || payload_type_fec != -1) { |
162 RTC_DCHECK_GE(payload_type_red, 0); | 108 RTC_DCHECK_GE(payload_type_red, 0); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 163 } |
218 | 164 |
219 RtpState ViEChannel::GetRtpStateForSsrc(uint32_t ssrc) const { | 165 RtpState ViEChannel::GetRtpStateForSsrc(uint32_t ssrc) const { |
220 RTC_DCHECK(!rtp_rtcp_->Sending()); | 166 RTC_DCHECK(!rtp_rtcp_->Sending()); |
221 RTC_DCHECK_EQ(ssrc, rtp_rtcp_->SSRC()); | 167 RTC_DCHECK_EQ(ssrc, rtp_rtcp_->SSRC()); |
222 return rtp_rtcp_->GetRtpState(); | 168 return rtp_rtcp_->GetRtpState(); |
223 } | 169 } |
224 | 170 |
225 void ViEChannel::RegisterRtcpPacketTypeCounterObserver( | 171 void ViEChannel::RegisterRtcpPacketTypeCounterObserver( |
226 RtcpPacketTypeCounterObserver* observer) { | 172 RtcpPacketTypeCounterObserver* observer) { |
227 rtcp_packet_type_counter_observer_.Set(observer); | 173 vie_receiver_.RegisterRtcpPacketTypeCounterObserver(observer); |
228 } | |
229 | |
230 RtpRtcp* ViEChannel::rtp_rtcp() const { | |
231 return rtp_rtcp_.get(); | |
232 } | 174 } |
233 | 175 |
234 ViEReceiver* ViEChannel::vie_receiver() { | 176 ViEReceiver* ViEChannel::vie_receiver() { |
235 return &vie_receiver_; | 177 return &vie_receiver_; |
236 } | 178 } |
237 | 179 |
238 CallStatsObserver* ViEChannel::GetStatsObserver() { | 180 CallStatsObserver* ViEChannel::GetStatsObserver() { |
239 return stats_observer_.get(); | 181 return stats_observer_.get(); |
240 } | 182 } |
241 | 183 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 rtc::CritScope lock(&crit_); | 298 rtc::CritScope lock(&crit_); |
357 receive_stats_callback_ = receive_statistics_proxy; | 299 receive_stats_callback_ = receive_statistics_proxy; |
358 } | 300 } |
359 | 301 |
360 void ViEChannel::SetIncomingVideoStream( | 302 void ViEChannel::SetIncomingVideoStream( |
361 IncomingVideoStream* incoming_video_stream) { | 303 IncomingVideoStream* incoming_video_stream) { |
362 rtc::CritScope lock(&crit_); | 304 rtc::CritScope lock(&crit_); |
363 incoming_video_stream_ = incoming_video_stream; | 305 incoming_video_stream_ = incoming_video_stream; |
364 } | 306 } |
365 } // namespace webrtc | 307 } // namespace webrtc |
OLD | NEW |