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 |
(...skipping 21 matching lines...) Expand all Loading... | |
32 #include "webrtc/video/call_stats.h" | 32 #include "webrtc/video/call_stats.h" |
33 #include "webrtc/video/payload_router.h" | 33 #include "webrtc/video/payload_router.h" |
34 #include "webrtc/video/receive_statistics_proxy.h" | 34 #include "webrtc/video/receive_statistics_proxy.h" |
35 | 35 |
36 namespace webrtc { | 36 namespace webrtc { |
37 | 37 |
38 static const int kMinSendSidePacketHistorySize = 600; | 38 static const int kMinSendSidePacketHistorySize = 600; |
39 static const int kMaxPacketAgeToNack = 450; | 39 static const int kMaxPacketAgeToNack = 450; |
40 static const int kMaxNackListSize = 250; | 40 static const int kMaxNackListSize = 250; |
41 | 41 |
42 namespace { | |
43 | |
44 std::unique_ptr<RtpRtcp> CreateRtpRtcpModule( | |
45 ReceiveStatistics* receive_statistics, | |
46 Transport* outgoing_transport, | |
47 RtcpBandwidthObserver* bandwidth_callback, | |
48 RtcpRttStats* rtt_stats, | |
49 RtcpPacketTypeCounterObserver* rtcp_packet_type_counter_observer, | |
50 RemoteBitrateEstimator* remote_bitrate_estimator, | |
51 RtpPacketSender* paced_sender, | |
52 TransportSequenceNumberAllocator* transport_sequence_number_allocator) { | |
53 RtpRtcp::Configuration configuration; | |
54 configuration.audio = false; | |
55 configuration.receiver_only = true; | |
56 configuration.receive_statistics = receive_statistics; | |
57 configuration.outgoing_transport = outgoing_transport; | |
58 configuration.intra_frame_callback = nullptr; | |
59 configuration.rtt_stats = rtt_stats; | |
60 configuration.rtcp_packet_type_counter_observer = | |
61 rtcp_packet_type_counter_observer; | |
62 configuration.paced_sender = paced_sender; | |
63 configuration.transport_sequence_number_allocator = | |
64 transport_sequence_number_allocator; | |
65 configuration.send_bitrate_observer = nullptr; | |
66 configuration.send_frame_count_observer = nullptr; | |
67 configuration.send_side_delay_observer = nullptr; | |
68 configuration.bandwidth_callback = bandwidth_callback; | |
69 configuration.transport_feedback_callback = nullptr; | |
70 | |
71 std::unique_ptr<RtpRtcp> rtp_rtcp(RtpRtcp::CreateRtpRtcp(configuration)); | |
72 rtp_rtcp->SetSendingStatus(false); | |
73 rtp_rtcp->SetSendingMediaStatus(false); | |
74 rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound); | |
75 | |
76 return rtp_rtcp; | |
77 } | |
78 | |
79 } // namespace | |
80 | |
42 // Helper class receiving statistics callbacks. | 81 // Helper class receiving statistics callbacks. |
43 class ChannelStatsObserver : public CallStatsObserver { | 82 class ChannelStatsObserver : public CallStatsObserver { |
44 public: | 83 public: |
45 explicit ChannelStatsObserver(ViEChannel* owner) : owner_(owner) {} | 84 explicit ChannelStatsObserver(ViEChannel* owner) : owner_(owner) {} |
46 virtual ~ChannelStatsObserver() {} | 85 virtual ~ChannelStatsObserver() {} |
47 | 86 |
48 // Implements StatsObserver. | 87 // Implements StatsObserver. |
49 virtual void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 88 virtual void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
50 owner_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); | 89 owner_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); |
51 } | 90 } |
52 | 91 |
53 private: | 92 private: |
54 ViEChannel* const owner_; | 93 ViEChannel* const owner_; |
55 }; | 94 }; |
56 | 95 |
57 class ViEChannelProtectionCallback : public VCMProtectionCallback { | |
58 public: | |
59 explicit ViEChannelProtectionCallback(ViEChannel* owner) : owner_(owner) {} | |
60 ~ViEChannelProtectionCallback() {} | |
61 | |
62 | |
63 int ProtectionRequest( | |
64 const FecProtectionParams* delta_fec_params, | |
65 const FecProtectionParams* key_fec_params, | |
66 uint32_t* sent_video_rate_bps, | |
67 uint32_t* sent_nack_rate_bps, | |
68 uint32_t* sent_fec_rate_bps) override { | |
69 return owner_->ProtectionRequest(delta_fec_params, key_fec_params, | |
70 sent_video_rate_bps, sent_nack_rate_bps, | |
71 sent_fec_rate_bps); | |
72 } | |
73 private: | |
74 ViEChannel* owner_; | |
75 }; | |
76 | |
77 ViEChannel::ViEChannel(Transport* transport, | 96 ViEChannel::ViEChannel(Transport* transport, |
78 ProcessThread* module_process_thread, | 97 ProcessThread* module_process_thread, |
79 PayloadRouter* send_payload_router, | |
80 VideoCodingModule* vcm, | 98 VideoCodingModule* vcm, |
81 RtcpIntraFrameObserver* intra_frame_observer, | |
82 RtcpBandwidthObserver* bandwidth_observer, | |
83 TransportFeedbackObserver* transport_feedback_observer, | |
84 RemoteBitrateEstimator* remote_bitrate_estimator, | 99 RemoteBitrateEstimator* remote_bitrate_estimator, |
85 RtcpRttStats* rtt_stats, | 100 RtcpRttStats* rtt_stats, |
86 PacedSender* paced_sender, | 101 PacedSender* paced_sender, |
87 PacketRouter* packet_router, | 102 PacketRouter* packet_router) |
88 size_t max_rtp_streams, | 103 : module_process_thread_(module_process_thread), |
89 bool sender) | |
90 : sender_(sender), | |
91 module_process_thread_(module_process_thread), | |
92 send_payload_router_(send_payload_router), | |
93 vcm_protection_callback_(new ViEChannelProtectionCallback(this)), | |
94 vcm_(vcm), | 104 vcm_(vcm), |
95 vie_receiver_(vcm_, remote_bitrate_estimator, this), | 105 vie_receiver_(vcm_, remote_bitrate_estimator, this), |
96 stats_observer_(new ChannelStatsObserver(this)), | 106 stats_observer_(new ChannelStatsObserver(this)), |
97 receive_stats_callback_(nullptr), | 107 receive_stats_callback_(nullptr), |
98 incoming_video_stream_(nullptr), | 108 incoming_video_stream_(nullptr), |
99 intra_frame_observer_(intra_frame_observer), | |
100 rtt_stats_(rtt_stats), | 109 rtt_stats_(rtt_stats), |
101 paced_sender_(paced_sender), | 110 paced_sender_(paced_sender), |
102 packet_router_(packet_router), | 111 packet_router_(packet_router), |
103 bandwidth_observer_(bandwidth_observer), | |
104 transport_feedback_observer_(transport_feedback_observer), | |
105 max_nack_reordering_threshold_(kMaxPacketAgeToNack), | 112 max_nack_reordering_threshold_(kMaxPacketAgeToNack), |
106 pre_render_callback_(nullptr), | 113 pre_render_callback_(nullptr), |
107 last_rtt_ms_(0), | 114 last_rtt_ms_(0), |
108 rtp_rtcp_modules_( | 115 rtp_rtcp_modules_( |
109 CreateRtpRtcpModules(!sender, | 116 CreateRtpRtcpModule(vie_receiver_.GetReceiveStatistics(), |
110 vie_receiver_.GetReceiveStatistics(), | 117 transport, |
111 transport, | 118 bandwidth_observer_.get(), |
112 intra_frame_observer_, | 119 rtt_stats_, |
113 bandwidth_observer_.get(), | 120 &rtcp_packet_type_counter_observer_, |
114 transport_feedback_observer_, | 121 remote_bitrate_estimator, |
115 rtt_stats_, | 122 paced_sender_, |
116 &rtcp_packet_type_counter_observer_, | 123 packet_router_)) { |
117 remote_bitrate_estimator, | 124 vie_receiver_.Init(rtp_rtcp_modules_.get()); |
118 paced_sender_, | 125 RTC_DCHECK(vcm_); |
119 packet_router_, | 126 vcm_->SetNackSettings(kMaxNackListSize, max_nack_reordering_threshold_, 0); |
120 &send_bitrate_observer_, | |
121 &send_frame_count_observer_, | |
122 &send_side_delay_observer_, | |
123 max_rtp_streams)) { | |
124 vie_receiver_.Init(rtp_rtcp_modules_); | |
125 if (sender_) { | |
126 RTC_DCHECK(send_payload_router_); | |
127 RTC_DCHECK(!vcm_); | |
128 } else { | |
129 RTC_DCHECK(!send_payload_router_); | |
130 RTC_DCHECK(vcm_); | |
131 vcm_->SetNackSettings(kMaxNackListSize, max_nack_reordering_threshold_, 0); | |
132 } | |
133 } | 127 } |
134 | 128 |
135 int32_t ViEChannel::Init() { | 129 int32_t ViEChannel::Init() { |
136 static const int kDefaultRenderDelayMs = 10; | 130 static const int kDefaultRenderDelayMs = 10; |
137 module_process_thread_->RegisterModule(vie_receiver_.GetReceiveStatistics()); | 131 module_process_thread_->RegisterModule(vie_receiver_.GetReceiveStatistics()); |
138 | 132 |
139 // RTP/RTCP initialization. | 133 // RTP/RTCP initialization. |
140 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 134 module_process_thread_->RegisterModule(rtp_rtcp_modules_.get()); |
141 module_process_thread_->RegisterModule(rtp_rtcp); | 135 packet_router_->AddRtpModule(rtp_rtcp_modules_.get()); |
142 packet_router_->AddRtpModule(rtp_rtcp); | 136 |
137 rtp_rtcp_modules_->SetKeyFrameRequestMethod(kKeyFrameReqPliRtcp); | |
138 if (paced_sender_) { | |
pbos-webrtc
2016/04/07 16:02:08
I'd expect that paced_sender_ is either always tru
perkj_webrtc
2016/04/08 10:59:04
Looks like this is only nack - send side.
Removing
| |
139 rtp_rtcp_modules_->SetStorePacketsStatus(true, | |
140 kMinSendSidePacketHistorySize); | |
143 } | 141 } |
144 | 142 |
145 rtp_rtcp_modules_[0]->SetKeyFrameRequestMethod(kKeyFrameReqPliRtcp); | 143 if (vcm_->RegisterReceiveCallback(this) != 0) { |
pbos-webrtc
2016/04/07 16:02:08
I think we could RTC_CHECK_EQ this and make it voi
perkj_webrtc
2016/04/08 10:59:04
not part of this cl.
| |
146 if (paced_sender_) { | 144 return -1; |
147 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) | |
148 rtp_rtcp->SetStorePacketsStatus(true, kMinSendSidePacketHistorySize); | |
149 } | 145 } |
150 if (sender_) { | 146 vcm_->RegisterFrameTypeCallback(this); |
151 send_payload_router_->SetSendingRtpModules(1); | 147 vcm_->RegisterReceiveStatisticsCallback(this); |
152 RTC_DCHECK(!send_payload_router_->active()); | 148 vcm_->RegisterDecoderTimingCallback(this); |
153 } else { | 149 vcm_->SetRenderDelay(kDefaultRenderDelayMs); |
154 if (vcm_->RegisterReceiveCallback(this) != 0) { | 150 |
155 return -1; | |
156 } | |
157 vcm_->RegisterFrameTypeCallback(this); | |
158 vcm_->RegisterReceiveStatisticsCallback(this); | |
159 vcm_->RegisterDecoderTimingCallback(this); | |
160 vcm_->SetRenderDelay(kDefaultRenderDelayMs); | |
161 } | |
162 return 0; | 151 return 0; |
163 } | 152 } |
164 | 153 |
165 ViEChannel::~ViEChannel() { | 154 ViEChannel::~ViEChannel() { |
166 // Make sure we don't get more callbacks from the RTP module. | 155 // Make sure we don't get more callbacks from the RTP module. |
167 module_process_thread_->DeRegisterModule( | 156 module_process_thread_->DeRegisterModule( |
168 vie_receiver_.GetReceiveStatistics()); | 157 vie_receiver_.GetReceiveStatistics()); |
169 if (sender_) { | 158 |
170 send_payload_router_->SetSendingRtpModules(0); | 159 packet_router_->RemoveRtpModule(rtp_rtcp_modules_.get()); |
171 } | 160 module_process_thread_->DeRegisterModule(rtp_rtcp_modules_.get()); |
172 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | |
173 packet_router_->RemoveRtpModule(rtp_rtcp); | |
174 module_process_thread_->DeRegisterModule(rtp_rtcp); | |
175 delete rtp_rtcp; | |
176 } | |
177 } | 161 } |
178 | 162 |
179 void ViEChannel::SetProtectionMode(bool enable_nack, | 163 void ViEChannel::SetProtectionMode(bool enable_nack, |
180 bool enable_fec, | 164 bool enable_fec, |
181 int payload_type_red, | 165 int payload_type_red, |
182 int payload_type_fec) { | 166 int payload_type_fec) { |
183 // Validate payload types. If either RED or FEC payload types are set then | 167 // Validate payload types. If either RED or FEC payload types are set then |
184 // both should be. If FEC is enabled then they both have to be set. | 168 // both should be. If FEC is enabled then they both have to be set. |
185 if (enable_fec || payload_type_red != -1 || payload_type_fec != -1) { | 169 if (enable_fec || payload_type_red != -1 || payload_type_fec != -1) { |
186 RTC_DCHECK_GE(payload_type_red, 0); | 170 RTC_DCHECK_GE(payload_type_red, 0); |
187 RTC_DCHECK_GE(payload_type_fec, 0); | 171 RTC_DCHECK_GE(payload_type_fec, 0); |
188 RTC_DCHECK_LE(payload_type_red, 127); | 172 RTC_DCHECK_LE(payload_type_red, 127); |
189 RTC_DCHECK_LE(payload_type_fec, 127); | 173 RTC_DCHECK_LE(payload_type_fec, 127); |
190 } else { | 174 } else { |
191 // Payload types unset. | 175 // Payload types unset. |
192 RTC_DCHECK_EQ(payload_type_red, -1); | 176 RTC_DCHECK_EQ(payload_type_red, -1); |
193 RTC_DCHECK_EQ(payload_type_fec, -1); | 177 RTC_DCHECK_EQ(payload_type_fec, -1); |
194 // Set to valid uint8_ts to be castable later without signed overflows. | 178 // Set to valid uint8_ts to be castable later without signed overflows. |
195 payload_type_red = 0; | 179 payload_type_red = 0; |
196 payload_type_fec = 0; | 180 payload_type_fec = 0; |
197 } | 181 } |
198 | 182 |
199 VCMVideoProtection protection_method; | 183 VCMVideoProtection protection_method; |
200 if (enable_nack) { | 184 if (enable_nack) { |
201 protection_method = enable_fec ? kProtectionNackFEC : kProtectionNack; | 185 protection_method = enable_fec ? kProtectionNackFEC : kProtectionNack; |
202 } else { | 186 } else { |
203 protection_method = kProtectionNone; | 187 protection_method = kProtectionNone; |
204 } | 188 } |
205 | 189 |
206 if (!sender_) | 190 vcm_->SetVideoProtection(protection_method, true); |
207 vcm_->SetVideoProtection(protection_method, true); | |
208 | 191 |
209 // Set NACK. | 192 // Set NACK. |
210 ProcessNACKRequest(enable_nack); | 193 ProcessNACKRequest(enable_nack); |
211 | 194 |
212 // Set FEC. | 195 // Set FEC. |
213 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 196 rtp_rtcp_modules_->SetGenericFECStatus( |
214 rtp_rtcp->SetGenericFECStatus(enable_fec, | 197 enable_fec, static_cast<uint8_t>(payload_type_red), |
215 static_cast<uint8_t>(payload_type_red), | 198 static_cast<uint8_t>(payload_type_fec)); |
216 static_cast<uint8_t>(payload_type_fec)); | |
217 } | |
218 } | 199 } |
219 | 200 |
220 void ViEChannel::ProcessNACKRequest(const bool enable) { | 201 void ViEChannel::ProcessNACKRequest(const bool enable) { |
221 if (enable) { | 202 if (enable) { |
222 // Turn on NACK. | 203 // Turn on NACK. |
223 if (rtp_rtcp_modules_[0]->RTCP() == RtcpMode::kOff) | 204 if (rtp_rtcp_modules_->RTCP() == RtcpMode::kOff) |
224 return; | 205 return; |
225 vie_receiver_.SetNackStatus(true, max_nack_reordering_threshold_); | 206 vie_receiver_.SetNackStatus(true, max_nack_reordering_threshold_); |
226 | 207 |
227 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) | 208 rtp_rtcp_modules_->SetStorePacketsStatus(true, |
228 rtp_rtcp->SetStorePacketsStatus(true, kMinSendSidePacketHistorySize); | 209 kMinSendSidePacketHistorySize); |
229 | 210 |
230 if (!sender_) { | 211 vcm_->RegisterPacketRequestCallback(this); |
231 vcm_->RegisterPacketRequestCallback(this); | 212 // Don't introduce errors when NACK is enabled. |
232 // Don't introduce errors when NACK is enabled. | 213 vcm_->SetDecodeErrorMode(kNoErrors); |
233 vcm_->SetDecodeErrorMode(kNoErrors); | 214 |
234 } | |
235 } else { | 215 } else { |
236 if (!sender_) { | 216 vcm_->RegisterPacketRequestCallback(nullptr); |
237 vcm_->RegisterPacketRequestCallback(nullptr); | 217 rtp_rtcp_modules_->SetStorePacketsStatus(false, 0); |
238 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) | 218 // When NACK is off, allow decoding with errors. Otherwise, the video |
239 rtp_rtcp->SetStorePacketsStatus(false, 0); | 219 // will freeze, and will only recover with a complete key frame. |
240 // When NACK is off, allow decoding with errors. Otherwise, the video | 220 vcm_->SetDecodeErrorMode(kWithErrors); |
241 // will freeze, and will only recover with a complete key frame. | |
242 vcm_->SetDecodeErrorMode(kWithErrors); | |
243 } | |
244 vie_receiver_.SetNackStatus(false, max_nack_reordering_threshold_); | 221 vie_receiver_.SetNackStatus(false, max_nack_reordering_threshold_); |
245 } | 222 } |
246 } | 223 } |
247 | 224 |
248 int ViEChannel::GetRequiredNackListSize(int target_delay_ms) { | 225 int ViEChannel::GetRequiredNackListSize(int target_delay_ms) { |
249 // The max size of the nack list should be large enough to accommodate the | 226 // The max size of the nack list should be large enough to accommodate the |
250 // the number of packets (frames) resulting from the increased delay. | 227 // the number of packets (frames) resulting from the increased delay. |
251 // Roughly estimating for ~40 packets per frame @ 30fps. | 228 // Roughly estimating for ~40 packets per frame @ 30fps. |
252 return target_delay_ms * 40 * 30 / 1000; | 229 return target_delay_ms * 40 * 30 / 1000; |
253 } | 230 } |
254 | 231 |
255 RtpState ViEChannel::GetRtpStateForSsrc(uint32_t ssrc) const { | 232 RtpState ViEChannel::GetRtpStateForSsrc(uint32_t ssrc) const { |
256 RTC_DCHECK(!rtp_rtcp_modules_[0]->Sending()); | 233 RTC_DCHECK(!rtp_rtcp_modules_->Sending()); |
257 RtpState rtp_state; | 234 RtpState rtp_state; |
258 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 235 |
259 if (rtp_rtcp->GetRtpStateForSsrc(ssrc, &rtp_state)) | 236 if (rtp_rtcp_modules_->GetRtpStateForSsrc(ssrc, &rtp_state)) |
260 return rtp_state; | 237 return rtp_state; |
261 } | 238 |
262 LOG(LS_ERROR) << "Couldn't get RTP state for ssrc: " << ssrc; | 239 LOG(LS_ERROR) << "Couldn't get RTP state for ssrc: " << ssrc; |
263 return rtp_state; | 240 return rtp_state; |
264 } | 241 } |
265 | 242 |
266 void ViEChannel::RegisterRtcpPacketTypeCounterObserver( | 243 void ViEChannel::RegisterRtcpPacketTypeCounterObserver( |
267 RtcpPacketTypeCounterObserver* observer) { | 244 RtcpPacketTypeCounterObserver* observer) { |
268 rtcp_packet_type_counter_observer_.Set(observer); | 245 rtcp_packet_type_counter_observer_.Set(observer); |
269 } | 246 } |
270 | 247 |
271 void ViEChannel::GetSendStreamDataCounters( | 248 RtpRtcp* ViEChannel::rtp_rtcp() const { |
272 StreamDataCounters* rtp_counters, | 249 return rtp_rtcp_modules_.get(); |
273 StreamDataCounters* rtx_counters) const { | |
274 *rtp_counters = StreamDataCounters(); | |
275 *rtx_counters = StreamDataCounters(); | |
276 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | |
277 StreamDataCounters rtp_data; | |
278 StreamDataCounters rtx_data; | |
279 rtp_rtcp->GetSendStreamDataCounters(&rtp_data, &rtx_data); | |
280 rtp_counters->Add(rtp_data); | |
281 rtx_counters->Add(rtx_data); | |
282 } | |
283 } | |
284 | |
285 void ViEChannel::RegisterSendSideDelayObserver( | |
286 SendSideDelayObserver* observer) { | |
287 send_side_delay_observer_.Set(observer); | |
288 } | |
289 | |
290 void ViEChannel::RegisterSendBitrateObserver( | |
291 BitrateStatisticsObserver* observer) { | |
292 send_bitrate_observer_.Set(observer); | |
293 } | |
294 | |
295 const std::vector<RtpRtcp*>& ViEChannel::rtp_rtcp() const { | |
296 return rtp_rtcp_modules_; | |
297 } | 250 } |
298 | 251 |
299 ViEReceiver* ViEChannel::vie_receiver() { | 252 ViEReceiver* ViEChannel::vie_receiver() { |
300 return &vie_receiver_; | 253 return &vie_receiver_; |
301 } | 254 } |
302 | 255 |
303 VCMProtectionCallback* ViEChannel::vcm_protection_callback() { | |
304 return vcm_protection_callback_.get(); | |
305 } | |
306 | |
307 CallStatsObserver* ViEChannel::GetStatsObserver() { | 256 CallStatsObserver* ViEChannel::GetStatsObserver() { |
308 return stats_observer_.get(); | 257 return stats_observer_.get(); |
309 } | 258 } |
310 | 259 |
311 // Do not acquire the lock of |vcm_| in this function. Decode callback won't | 260 // Do not acquire the lock of |vcm_| in this function. Decode callback won't |
312 // necessarily be called from the decoding thread. The decoding thread may have | 261 // necessarily be called from the decoding thread. The decoding thread may have |
313 // held the lock when calling VideoDecoder::Decode, Reset, or Release. Acquiring | 262 // held the lock when calling VideoDecoder::Decode, Reset, or Release. Acquiring |
314 // the same lock in the path of decode callback can deadlock. | 263 // the same lock in the path of decode callback can deadlock. |
315 int32_t ViEChannel::FrameToRender(VideoFrame& video_frame) { // NOLINT | 264 int32_t ViEChannel::FrameToRender(VideoFrame& video_frame) { // NOLINT |
316 rtc::CritScope lock(&crit_); | 265 rtc::CritScope lock(&crit_); |
317 | 266 |
318 if (pre_render_callback_) | 267 if (pre_render_callback_) |
319 pre_render_callback_->FrameCallback(&video_frame); | 268 pre_render_callback_->FrameCallback(&video_frame); |
320 | 269 |
321 // TODO(pbos): Remove stream id argument. | 270 // TODO(pbos): Remove stream id argument. |
322 incoming_video_stream_->RenderFrame(0xFFFFFFFF, video_frame); | 271 incoming_video_stream_->RenderFrame(0xFFFFFFFF, video_frame); |
323 return 0; | 272 return 0; |
324 } | 273 } |
325 | 274 |
326 int32_t ViEChannel::ReceivedDecodedReferenceFrame( | 275 int32_t ViEChannel::ReceivedDecodedReferenceFrame( |
327 const uint64_t picture_id) { | 276 const uint64_t picture_id) { |
328 return rtp_rtcp_modules_[0]->SendRTCPReferencePictureSelection(picture_id); | 277 return rtp_rtcp_modules_->SendRTCPReferencePictureSelection(picture_id); |
329 } | 278 } |
330 | 279 |
331 void ViEChannel::OnIncomingPayloadType(int payload_type) { | 280 void ViEChannel::OnIncomingPayloadType(int payload_type) { |
332 rtc::CritScope lock(&crit_); | 281 rtc::CritScope lock(&crit_); |
333 if (receive_stats_callback_) | 282 if (receive_stats_callback_) |
334 receive_stats_callback_->OnIncomingPayloadType(payload_type); | 283 receive_stats_callback_->OnIncomingPayloadType(payload_type); |
335 } | 284 } |
336 | 285 |
337 void ViEChannel::OnDecoderImplementationName(const char* implementation_name) { | 286 void ViEChannel::OnDecoderImplementationName(const char* implementation_name) { |
338 rtc::CritScope lock(&crit_); | 287 rtc::CritScope lock(&crit_); |
(...skipping 29 matching lines...) Expand all Loading... | |
368 int render_delay_ms) { | 317 int render_delay_ms) { |
369 rtc::CritScope lock(&crit_); | 318 rtc::CritScope lock(&crit_); |
370 if (!receive_stats_callback_) | 319 if (!receive_stats_callback_) |
371 return; | 320 return; |
372 receive_stats_callback_->OnDecoderTiming( | 321 receive_stats_callback_->OnDecoderTiming( |
373 decode_ms, max_decode_ms, current_delay_ms, target_delay_ms, | 322 decode_ms, max_decode_ms, current_delay_ms, target_delay_ms, |
374 jitter_buffer_ms, min_playout_delay_ms, render_delay_ms, last_rtt_ms_); | 323 jitter_buffer_ms, min_playout_delay_ms, render_delay_ms, last_rtt_ms_); |
375 } | 324 } |
376 | 325 |
377 int32_t ViEChannel::RequestKeyFrame() { | 326 int32_t ViEChannel::RequestKeyFrame() { |
378 return rtp_rtcp_modules_[0]->RequestKeyFrame(); | 327 return rtp_rtcp_modules_->RequestKeyFrame(); |
379 } | 328 } |
380 | 329 |
381 int32_t ViEChannel::SliceLossIndicationRequest( | 330 int32_t ViEChannel::SliceLossIndicationRequest( |
382 const uint64_t picture_id) { | 331 const uint64_t picture_id) { |
383 return rtp_rtcp_modules_[0]->SendRTCPSliceLossIndication( | 332 return rtp_rtcp_modules_->SendRTCPSliceLossIndication( |
384 static_cast<uint8_t>(picture_id)); | 333 static_cast<uint8_t>(picture_id)); |
385 } | 334 } |
386 | 335 |
387 int32_t ViEChannel::ResendPackets(const uint16_t* sequence_numbers, | 336 int32_t ViEChannel::ResendPackets(const uint16_t* sequence_numbers, |
388 uint16_t length) { | 337 uint16_t length) { |
389 return rtp_rtcp_modules_[0]->SendNACK(sequence_numbers, length); | 338 return rtp_rtcp_modules_->SendNACK(sequence_numbers, length); |
390 } | 339 } |
391 | 340 |
392 void ViEChannel::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 341 void ViEChannel::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
393 if (!sender_) | 342 vcm_->SetReceiveChannelParameters(max_rtt_ms); |
394 vcm_->SetReceiveChannelParameters(max_rtt_ms); | |
395 | 343 |
396 rtc::CritScope lock(&crit_); | 344 rtc::CritScope lock(&crit_); |
397 last_rtt_ms_ = avg_rtt_ms; | 345 last_rtt_ms_ = avg_rtt_ms; |
398 } | 346 } |
399 | 347 |
400 int ViEChannel::ProtectionRequest(const FecProtectionParams* delta_fec_params, | |
401 const FecProtectionParams* key_fec_params, | |
402 uint32_t* video_rate_bps, | |
403 uint32_t* nack_rate_bps, | |
404 uint32_t* fec_rate_bps) { | |
405 *video_rate_bps = 0; | |
406 *nack_rate_bps = 0; | |
407 *fec_rate_bps = 0; | |
408 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | |
409 uint32_t not_used = 0; | |
410 uint32_t module_video_rate = 0; | |
411 uint32_t module_fec_rate = 0; | |
412 uint32_t module_nack_rate = 0; | |
413 rtp_rtcp->SetFecParameters(delta_fec_params, key_fec_params); | |
414 rtp_rtcp->BitrateSent(¬_used, &module_video_rate, &module_fec_rate, | |
415 &module_nack_rate); | |
416 *video_rate_bps += module_video_rate; | |
417 *nack_rate_bps += module_nack_rate; | |
418 *fec_rate_bps += module_fec_rate; | |
419 } | |
420 return 0; | |
421 } | |
422 | |
423 std::vector<RtpRtcp*> ViEChannel::CreateRtpRtcpModules( | |
424 bool receiver_only, | |
425 ReceiveStatistics* receive_statistics, | |
426 Transport* outgoing_transport, | |
427 RtcpIntraFrameObserver* intra_frame_callback, | |
428 RtcpBandwidthObserver* bandwidth_callback, | |
429 TransportFeedbackObserver* transport_feedback_callback, | |
430 RtcpRttStats* rtt_stats, | |
431 RtcpPacketTypeCounterObserver* rtcp_packet_type_counter_observer, | |
432 RemoteBitrateEstimator* remote_bitrate_estimator, | |
433 RtpPacketSender* paced_sender, | |
434 TransportSequenceNumberAllocator* transport_sequence_number_allocator, | |
435 BitrateStatisticsObserver* send_bitrate_observer, | |
436 FrameCountObserver* send_frame_count_observer, | |
437 SendSideDelayObserver* send_side_delay_observer, | |
438 size_t num_modules) { | |
439 RTC_DCHECK_GT(num_modules, 0u); | |
440 RtpRtcp::Configuration configuration; | |
441 ReceiveStatistics* null_receive_statistics = configuration.receive_statistics; | |
442 configuration.audio = false; | |
443 configuration.receiver_only = receiver_only; | |
444 configuration.receive_statistics = receive_statistics; | |
445 configuration.outgoing_transport = outgoing_transport; | |
446 configuration.intra_frame_callback = intra_frame_callback; | |
447 configuration.rtt_stats = rtt_stats; | |
448 configuration.rtcp_packet_type_counter_observer = | |
449 rtcp_packet_type_counter_observer; | |
450 configuration.paced_sender = paced_sender; | |
451 configuration.transport_sequence_number_allocator = | |
452 transport_sequence_number_allocator; | |
453 configuration.send_bitrate_observer = send_bitrate_observer; | |
454 configuration.send_frame_count_observer = send_frame_count_observer; | |
455 configuration.send_side_delay_observer = send_side_delay_observer; | |
456 configuration.bandwidth_callback = bandwidth_callback; | |
457 configuration.transport_feedback_callback = transport_feedback_callback; | |
458 | |
459 std::vector<RtpRtcp*> modules; | |
460 for (size_t i = 0; i < num_modules; ++i) { | |
461 RtpRtcp* rtp_rtcp = RtpRtcp::CreateRtpRtcp(configuration); | |
462 rtp_rtcp->SetSendingStatus(false); | |
463 rtp_rtcp->SetSendingMediaStatus(false); | |
464 rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound); | |
465 modules.push_back(rtp_rtcp); | |
466 // Receive statistics and remote bitrate estimator should only be set for | |
467 // the primary (first) module. | |
468 configuration.receive_statistics = null_receive_statistics; | |
469 configuration.remote_bitrate_estimator = nullptr; | |
470 } | |
471 return modules; | |
472 } | |
473 | |
474 void ViEChannel::RegisterPreRenderCallback( | 348 void ViEChannel::RegisterPreRenderCallback( |
475 I420FrameCallback* pre_render_callback) { | 349 I420FrameCallback* pre_render_callback) { |
476 RTC_DCHECK(!sender_); | |
477 rtc::CritScope lock(&crit_); | 350 rtc::CritScope lock(&crit_); |
478 pre_render_callback_ = pre_render_callback; | 351 pre_render_callback_ = pre_render_callback; |
479 } | 352 } |
480 | 353 |
481 // TODO(pbos): Remove as soon as audio can handle a changing payload type | 354 // TODO(pbos): Remove as soon as audio can handle a changing payload type |
482 // without this callback. | 355 // without this callback. |
483 int32_t ViEChannel::OnInitializeDecoder( | 356 int32_t ViEChannel::OnInitializeDecoder( |
484 const int8_t payload_type, | 357 const int8_t payload_type, |
485 const char payload_name[RTP_PAYLOAD_NAME_SIZE], | 358 const char payload_name[RTP_PAYLOAD_NAME_SIZE], |
486 const int frequency, | 359 const int frequency, |
487 const size_t channels, | 360 const size_t channels, |
488 const uint32_t rate) { | 361 const uint32_t rate) { |
489 RTC_NOTREACHED(); | 362 RTC_NOTREACHED(); |
490 return 0; | 363 return 0; |
491 } | 364 } |
492 | 365 |
493 void ViEChannel::OnIncomingSSRCChanged(const uint32_t ssrc) { | 366 void ViEChannel::OnIncomingSSRCChanged(const uint32_t ssrc) { |
494 rtp_rtcp_modules_[0]->SetRemoteSSRC(ssrc); | 367 rtp_rtcp_modules_->SetRemoteSSRC(ssrc); |
495 } | 368 } |
496 | 369 |
497 void ViEChannel::OnIncomingCSRCChanged(const uint32_t CSRC, const bool added) {} | 370 void ViEChannel::OnIncomingCSRCChanged(const uint32_t CSRC, const bool added) {} |
498 | 371 |
499 void ViEChannel::RegisterSendFrameCountObserver( | |
500 FrameCountObserver* observer) { | |
501 send_frame_count_observer_.Set(observer); | |
502 } | |
503 | |
504 void ViEChannel::RegisterReceiveStatisticsProxy( | 372 void ViEChannel::RegisterReceiveStatisticsProxy( |
505 ReceiveStatisticsProxy* receive_statistics_proxy) { | 373 ReceiveStatisticsProxy* receive_statistics_proxy) { |
506 rtc::CritScope lock(&crit_); | 374 rtc::CritScope lock(&crit_); |
507 receive_stats_callback_ = receive_statistics_proxy; | 375 receive_stats_callback_ = receive_statistics_proxy; |
508 } | 376 } |
509 | 377 |
510 void ViEChannel::SetIncomingVideoStream( | 378 void ViEChannel::SetIncomingVideoStream( |
511 IncomingVideoStream* incoming_video_stream) { | 379 IncomingVideoStream* incoming_video_stream) { |
512 rtc::CritScope lock(&crit_); | 380 rtc::CritScope lock(&crit_); |
513 incoming_video_stream_ = incoming_video_stream; | 381 incoming_video_stream_ = incoming_video_stream; |
514 } | 382 } |
515 } // namespace webrtc | 383 } // namespace webrtc |
OLD | NEW |