Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(770)

Side by Side Diff: webrtc/video/vie_channel.cc

Issue 1905983002: Use vcm::VideoReceiver on the receive side. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/vie_channel.h ('k') | webrtc/video/vie_encoder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 23 #include "webrtc/modules/pacing/paced_sender.h"
24 #include "webrtc/modules/pacing/packet_router.h" 24 #include "webrtc/modules/pacing/packet_router.h"
25 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" 25 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h"
26 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 26 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
27 #include "webrtc/modules/utility/include/process_thread.h" 27 #include "webrtc/modules/utility/include/process_thread.h"
28 #include "webrtc/modules/video_coding/include/video_coding.h" 28 #include "webrtc/modules/video_coding/video_coding_impl.h"
29 #include "webrtc/modules/video_processing/include/video_processing.h" 29 #include "webrtc/modules/video_processing/include/video_processing.h"
30 #include "webrtc/modules/video_render/video_render_defines.h" 30 #include "webrtc/modules/video_render/video_render_defines.h"
31 #include "webrtc/system_wrappers/include/metrics.h" 31 #include "webrtc/system_wrappers/include/metrics.h"
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 kMaxPacketAgeToNack = 450; 38 static const int kMaxPacketAgeToNack = 450;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 virtual void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { 86 virtual void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) {
87 owner_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); 87 owner_->OnRttUpdate(avg_rtt_ms, max_rtt_ms);
88 } 88 }
89 89
90 private: 90 private:
91 ViEChannel* const owner_; 91 ViEChannel* const owner_;
92 }; 92 };
93 93
94 ViEChannel::ViEChannel(Transport* transport, 94 ViEChannel::ViEChannel(Transport* transport,
95 ProcessThread* module_process_thread, 95 ProcessThread* module_process_thread,
96 VideoCodingModule* vcm, 96 vcm::VideoReceiver* video_receiver,
97 RemoteBitrateEstimator* remote_bitrate_estimator, 97 RemoteBitrateEstimator* remote_bitrate_estimator,
98 RtcpRttStats* rtt_stats, 98 RtcpRttStats* rtt_stats,
99 PacedSender* paced_sender, 99 PacedSender* paced_sender,
100 PacketRouter* packet_router) 100 PacketRouter* packet_router)
101 : module_process_thread_(module_process_thread), 101 : module_process_thread_(module_process_thread),
102 vcm_(vcm), 102 video_receiver_(video_receiver),
103 vie_receiver_(vcm_, remote_bitrate_estimator, this), 103 vie_receiver_(video_receiver_, remote_bitrate_estimator, this),
104 stats_observer_(new ChannelStatsObserver(this)), 104 stats_observer_(new ChannelStatsObserver(this)),
105 receive_stats_callback_(nullptr), 105 receive_stats_callback_(nullptr),
106 incoming_video_stream_(nullptr), 106 incoming_video_stream_(nullptr),
107 rtt_stats_(rtt_stats), 107 rtt_stats_(rtt_stats),
108 paced_sender_(paced_sender), 108 paced_sender_(paced_sender),
109 packet_router_(packet_router), 109 packet_router_(packet_router),
110 max_nack_reordering_threshold_(kMaxPacketAgeToNack), 110 max_nack_reordering_threshold_(kMaxPacketAgeToNack),
111 pre_render_callback_(nullptr), 111 pre_render_callback_(nullptr),
112 last_rtt_ms_(0), 112 last_rtt_ms_(0),
113 rtp_rtcp_(CreateRtpRtcpModule(vie_receiver_.GetReceiveStatistics(), 113 rtp_rtcp_(CreateRtpRtcpModule(vie_receiver_.GetReceiveStatistics(),
114 transport, 114 transport,
115 rtt_stats_, 115 rtt_stats_,
116 &rtcp_packet_type_counter_observer_, 116 &rtcp_packet_type_counter_observer_,
117 remote_bitrate_estimator, 117 remote_bitrate_estimator,
118 paced_sender_, 118 paced_sender_,
119 packet_router_)) { 119 packet_router_)) {
120 vie_receiver_.Init(rtp_rtcp_.get()); 120 vie_receiver_.Init(rtp_rtcp_.get());
121 RTC_DCHECK(vcm_); 121 RTC_DCHECK(video_receiver_);
122 vcm_->SetNackSettings(kMaxNackListSize, max_nack_reordering_threshold_, 0); 122 video_receiver_->SetNackSettings(kMaxNackListSize,
123 max_nack_reordering_threshold_, 0);
123 } 124 }
124 125
125 int32_t ViEChannel::Init() { 126 int32_t ViEChannel::Init() {
126 static const int kDefaultRenderDelayMs = 10; 127 static const int kDefaultRenderDelayMs = 10;
127 module_process_thread_->RegisterModule(vie_receiver_.GetReceiveStatistics()); 128 module_process_thread_->RegisterModule(vie_receiver_.GetReceiveStatistics());
128 129
129 // RTP/RTCP initialization. 130 // RTP/RTCP initialization.
130 module_process_thread_->RegisterModule(rtp_rtcp_.get()); 131 module_process_thread_->RegisterModule(rtp_rtcp_.get());
131 packet_router_->AddRtpModule(rtp_rtcp_.get()); 132 packet_router_->AddRtpModule(rtp_rtcp_.get());
132 133
133 rtp_rtcp_->SetKeyFrameRequestMethod(kKeyFrameReqPliRtcp); 134 rtp_rtcp_->SetKeyFrameRequestMethod(kKeyFrameReqPliRtcp);
134 if (vcm_->RegisterReceiveCallback(this) != 0) { 135 if (video_receiver_->RegisterReceiveCallback(this) != 0) {
135 return -1; 136 return -1;
136 } 137 }
137 vcm_->RegisterFrameTypeCallback(this); 138 video_receiver_->RegisterFrameTypeCallback(this);
138 vcm_->RegisterReceiveStatisticsCallback(this); 139 video_receiver_->RegisterReceiveStatisticsCallback(this);
139 vcm_->RegisterDecoderTimingCallback(this); 140 video_receiver_->RegisterDecoderTimingCallback(this);
140 vcm_->SetRenderDelay(kDefaultRenderDelayMs); 141 video_receiver_->SetRenderDelay(kDefaultRenderDelayMs);
141 142
142 return 0; 143 return 0;
143 } 144 }
144 145
145 ViEChannel::~ViEChannel() { 146 ViEChannel::~ViEChannel() {
146 // Make sure we don't get more callbacks from the RTP module. 147 // Make sure we don't get more callbacks from the RTP module.
147 module_process_thread_->DeRegisterModule( 148 module_process_thread_->DeRegisterModule(
148 vie_receiver_.GetReceiveStatistics()); 149 vie_receiver_.GetReceiveStatistics());
149 150
150 packet_router_->RemoveRtpModule(rtp_rtcp_.get()); 151 packet_router_->RemoveRtpModule(rtp_rtcp_.get());
(...skipping 20 matching lines...) Expand all
171 payload_type_fec = 0; 172 payload_type_fec = 0;
172 } 173 }
173 174
174 VCMVideoProtection protection_method; 175 VCMVideoProtection protection_method;
175 if (enable_nack) { 176 if (enable_nack) {
176 protection_method = enable_fec ? kProtectionNackFEC : kProtectionNack; 177 protection_method = enable_fec ? kProtectionNackFEC : kProtectionNack;
177 } else { 178 } else {
178 protection_method = kProtectionNone; 179 protection_method = kProtectionNone;
179 } 180 }
180 181
181 vcm_->SetVideoProtection(protection_method, true); 182 video_receiver_->SetVideoProtection(protection_method, true);
182 183
183 // Set NACK. 184 // Set NACK.
184 ProcessNACKRequest(enable_nack); 185 ProcessNACKRequest(enable_nack);
185 186
186 // Set FEC. 187 // Set FEC.
187 rtp_rtcp_->SetGenericFECStatus(enable_fec, 188 rtp_rtcp_->SetGenericFECStatus(enable_fec,
188 static_cast<uint8_t>(payload_type_red), 189 static_cast<uint8_t>(payload_type_red),
189 static_cast<uint8_t>(payload_type_fec)); 190 static_cast<uint8_t>(payload_type_fec));
190 } 191 }
191 192
192 void ViEChannel::ProcessNACKRequest(const bool enable) { 193 void ViEChannel::ProcessNACKRequest(const bool enable) {
193 if (enable) { 194 if (enable) {
194 // Turn on NACK. 195 // Turn on NACK.
195 if (rtp_rtcp_->RTCP() == RtcpMode::kOff) 196 if (rtp_rtcp_->RTCP() == RtcpMode::kOff)
196 return; 197 return;
197 vie_receiver_.SetNackStatus(true, max_nack_reordering_threshold_); 198 vie_receiver_.SetNackStatus(true, max_nack_reordering_threshold_);
198 vcm_->RegisterPacketRequestCallback(this); 199 video_receiver_->RegisterPacketRequestCallback(this);
199 // Don't introduce errors when NACK is enabled. 200 // Don't introduce errors when NACK is enabled.
200 vcm_->SetDecodeErrorMode(kNoErrors); 201 video_receiver_->SetDecodeErrorMode(kNoErrors);
201 202
202 } else { 203 } else {
203 vcm_->RegisterPacketRequestCallback(nullptr); 204 video_receiver_->RegisterPacketRequestCallback(nullptr);
204 // When NACK is off, allow decoding with errors. Otherwise, the video 205 // When NACK is off, allow decoding with errors. Otherwise, the video
205 // will freeze, and will only recover with a complete key frame. 206 // will freeze, and will only recover with a complete key frame.
206 vcm_->SetDecodeErrorMode(kWithErrors); 207 video_receiver_->SetDecodeErrorMode(kWithErrors);
207 vie_receiver_.SetNackStatus(false, max_nack_reordering_threshold_); 208 vie_receiver_.SetNackStatus(false, max_nack_reordering_threshold_);
208 } 209 }
209 } 210 }
210 211
211 int ViEChannel::GetRequiredNackListSize(int target_delay_ms) { 212 int ViEChannel::GetRequiredNackListSize(int target_delay_ms) {
212 // The max size of the nack list should be large enough to accommodate the 213 // The max size of the nack list should be large enough to accommodate the
213 // the number of packets (frames) resulting from the increased delay. 214 // the number of packets (frames) resulting from the increased delay.
214 // Roughly estimating for ~40 packets per frame @ 30fps. 215 // Roughly estimating for ~40 packets per frame @ 30fps.
215 return target_delay_ms * 40 * 30 / 1000; 216 return target_delay_ms * 40 * 30 / 1000;
216 } 217 }
(...skipping 14 matching lines...) Expand all
231 } 232 }
232 233
233 ViEReceiver* ViEChannel::vie_receiver() { 234 ViEReceiver* ViEChannel::vie_receiver() {
234 return &vie_receiver_; 235 return &vie_receiver_;
235 } 236 }
236 237
237 CallStatsObserver* ViEChannel::GetStatsObserver() { 238 CallStatsObserver* ViEChannel::GetStatsObserver() {
238 return stats_observer_.get(); 239 return stats_observer_.get();
239 } 240 }
240 241
241 // Do not acquire the lock of |vcm_| in this function. Decode callback won't 242 // Do not acquire the lock of |video_receiver_| in this function. Decode
242 // necessarily be called from the decoding thread. The decoding thread may have 243 // callback won't necessarily be called from the decoding thread. The decoding
243 // held the lock when calling VideoDecoder::Decode, Reset, or Release. Acquiring 244 // thread may have held the lock when calling VideoDecoder::Decode, Reset, or
244 // the same lock in the path of decode callback can deadlock. 245 // Release. Acquiring the same lock in the path of decode callback can deadlock.
245 int32_t ViEChannel::FrameToRender(VideoFrame& video_frame) { // NOLINT 246 int32_t ViEChannel::FrameToRender(VideoFrame& video_frame) { // NOLINT
246 rtc::CritScope lock(&crit_); 247 rtc::CritScope lock(&crit_);
247 248
248 if (pre_render_callback_) 249 if (pre_render_callback_)
249 pre_render_callback_->FrameCallback(&video_frame); 250 pre_render_callback_->FrameCallback(&video_frame);
250 251
251 // TODO(pbos): Remove stream id argument. 252 // TODO(pbos): Remove stream id argument.
252 incoming_video_stream_->RenderFrame(0xFFFFFFFF, video_frame); 253 incoming_video_stream_->RenderFrame(0xFFFFFFFF, video_frame);
253 return 0; 254 return 0;
254 } 255 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 return rtp_rtcp_->SendRTCPSliceLossIndication( 314 return rtp_rtcp_->SendRTCPSliceLossIndication(
314 static_cast<uint8_t>(picture_id)); 315 static_cast<uint8_t>(picture_id));
315 } 316 }
316 317
317 int32_t ViEChannel::ResendPackets(const uint16_t* sequence_numbers, 318 int32_t ViEChannel::ResendPackets(const uint16_t* sequence_numbers,
318 uint16_t length) { 319 uint16_t length) {
319 return rtp_rtcp_->SendNACK(sequence_numbers, length); 320 return rtp_rtcp_->SendNACK(sequence_numbers, length);
320 } 321 }
321 322
322 void ViEChannel::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { 323 void ViEChannel::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) {
323 vcm_->SetReceiveChannelParameters(max_rtt_ms); 324 video_receiver_->SetReceiveChannelParameters(max_rtt_ms);
324 325
325 rtc::CritScope lock(&crit_); 326 rtc::CritScope lock(&crit_);
326 last_rtt_ms_ = avg_rtt_ms; 327 last_rtt_ms_ = avg_rtt_ms;
327 } 328 }
328 329
329 void ViEChannel::RegisterPreRenderCallback( 330 void ViEChannel::RegisterPreRenderCallback(
330 I420FrameCallback* pre_render_callback) { 331 I420FrameCallback* pre_render_callback) {
331 rtc::CritScope lock(&crit_); 332 rtc::CritScope lock(&crit_);
332 pre_render_callback_ = pre_render_callback; 333 pre_render_callback_ = pre_render_callback;
333 } 334 }
(...skipping 21 matching lines...) Expand all
355 rtc::CritScope lock(&crit_); 356 rtc::CritScope lock(&crit_);
356 receive_stats_callback_ = receive_statistics_proxy; 357 receive_stats_callback_ = receive_statistics_proxy;
357 } 358 }
358 359
359 void ViEChannel::SetIncomingVideoStream( 360 void ViEChannel::SetIncomingVideoStream(
360 IncomingVideoStream* incoming_video_stream) { 361 IncomingVideoStream* incoming_video_stream) {
361 rtc::CritScope lock(&crit_); 362 rtc::CritScope lock(&crit_);
362 incoming_video_stream_ = incoming_video_stream; 363 incoming_video_stream_ = incoming_video_stream;
363 } 364 }
364 } // namespace webrtc 365 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/vie_channel.h ('k') | webrtc/video/vie_encoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698