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

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

Issue 1917363005: Rename ViEReceiver and move ownership to VideoReceiveStream. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Changed comment. Created 4 years, 7 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
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"
20 #include "webrtc/common_video/include/frame_callback.h" 19 #include "webrtc/common_video/include/frame_callback.h"
21 #include "webrtc/common_video/include/incoming_video_stream.h" 20 #include "webrtc/common_video/include/incoming_video_stream.h"
22 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" 21 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
23 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" 22 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h"
24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 23 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
25 #include "webrtc/modules/utility/include/process_thread.h"
26 #include "webrtc/modules/video_coding/video_coding_impl.h" 24 #include "webrtc/modules/video_coding/video_coding_impl.h"
27 #include "webrtc/modules/video_processing/include/video_processing.h" 25 #include "webrtc/modules/video_processing/include/video_processing.h"
28 #include "webrtc/system_wrappers/include/metrics.h" 26 #include "webrtc/system_wrappers/include/metrics.h"
29 #include "webrtc/video/call_stats.h" 27 #include "webrtc/video/call_stats.h"
30 #include "webrtc/video/payload_router.h" 28 #include "webrtc/video/payload_router.h"
31 #include "webrtc/video/receive_statistics_proxy.h" 29 #include "webrtc/video/receive_statistics_proxy.h"
32 30
33 namespace webrtc { 31 namespace webrtc {
34 32
35 static const int kMaxPacketAgeToNack = 450; 33 static const int kMaxPacketAgeToNack = 450;
36 static const int kMaxNackListSize = 250; 34 static const int kMaxNackListSize = 250;
37 35
38 // Helper class receiving statistics callbacks. 36 // Helper class receiving statistics callbacks.
39 class ChannelStatsObserver : public CallStatsObserver { 37 class ChannelStatsObserver : public CallStatsObserver {
40 public: 38 public:
41 explicit ChannelStatsObserver(ViEChannel* owner) : owner_(owner) {} 39 explicit ChannelStatsObserver(ViEChannel* owner) : owner_(owner) {}
42 virtual ~ChannelStatsObserver() {} 40 virtual ~ChannelStatsObserver() {}
43 41
44 // Implements StatsObserver. 42 // Implements StatsObserver.
45 virtual void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { 43 virtual void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) {
46 owner_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); 44 owner_->OnRttUpdate(avg_rtt_ms, max_rtt_ms);
47 } 45 }
48 46
49 private: 47 private:
50 ViEChannel* const owner_; 48 ViEChannel* const owner_;
51 }; 49 };
52 50
53 ViEChannel::ViEChannel(Transport* transport, 51 ViEChannel::ViEChannel(vcm::VideoReceiver* video_receiver,
54 ProcessThread* module_process_thread, 52 RtpStreamReceiver* rtp_stream_receiver)
55 vcm::VideoReceiver* video_receiver, 53 : video_receiver_(video_receiver),
56 RemoteBitrateEstimator* remote_bitrate_estimator, 54 rtp_stream_receiver_(rtp_stream_receiver),
57 RtcpRttStats* rtt_stats, 55 rtp_rtcp_(rtp_stream_receiver_->rtp_rtcp()),
58 PacedSender* paced_sender,
59 PacketRouter* packet_router)
60 : module_process_thread_(module_process_thread),
61 video_receiver_(video_receiver),
62 vie_receiver_(video_receiver, remote_bitrate_estimator, this, transport,
63 rtt_stats, paced_sender, packet_router),
64 rtp_rtcp_(vie_receiver_.rtp_rtcp()),
65 stats_observer_(new ChannelStatsObserver(this)), 56 stats_observer_(new ChannelStatsObserver(this)),
66 receive_stats_callback_(nullptr), 57 receive_stats_callback_(nullptr),
67 incoming_video_stream_(nullptr), 58 incoming_video_stream_(nullptr),
68 max_nack_reordering_threshold_(kMaxPacketAgeToNack), 59 max_nack_reordering_threshold_(kMaxPacketAgeToNack),
69 pre_render_callback_(nullptr), 60 pre_render_callback_(nullptr),
70 last_rtt_ms_(0) { 61 last_rtt_ms_(0) {
71 RTC_DCHECK(video_receiver_); 62 RTC_DCHECK(video_receiver_);
72 video_receiver_->SetNackSettings(kMaxNackListSize, 63 video_receiver_->SetNackSettings(kMaxNackListSize,
73 max_nack_reordering_threshold_, 0); 64 max_nack_reordering_threshold_, 0);
74 } 65 }
75 66
76 int32_t ViEChannel::Init() { 67 int32_t ViEChannel::Init() {
77 static const int kDefaultRenderDelayMs = 10; 68 static const int kDefaultRenderDelayMs = 10;
78 module_process_thread_->RegisterModule(vie_receiver_.GetReceiveStatistics());
79 module_process_thread_->RegisterModule(rtp_rtcp_);
80 69
81 if (video_receiver_->RegisterReceiveCallback(this) != 0) { 70 if (video_receiver_->RegisterReceiveCallback(this) != 0) {
82 return -1; 71 return -1;
83 } 72 }
84 video_receiver_->RegisterFrameTypeCallback(this); 73 video_receiver_->RegisterFrameTypeCallback(this);
85 video_receiver_->RegisterReceiveStatisticsCallback(this); 74 video_receiver_->RegisterReceiveStatisticsCallback(this);
86 video_receiver_->RegisterDecoderTimingCallback(this); 75 video_receiver_->RegisterDecoderTimingCallback(this);
87 video_receiver_->SetRenderDelay(kDefaultRenderDelayMs); 76 video_receiver_->SetRenderDelay(kDefaultRenderDelayMs);
88 77
89 return 0; 78 return 0;
90 } 79 }
91 80
92 ViEChannel::~ViEChannel() { 81 ViEChannel::~ViEChannel() {}
pbos-webrtc 2016/04/28 14:26:49 Remove dtor
mflodman 2016/04/29 04:50:15 Done.
93 // Make sure we don't get more callbacks from the RTP module.
94 module_process_thread_->DeRegisterModule(
95 vie_receiver_.GetReceiveStatistics());
96
97 module_process_thread_->DeRegisterModule(rtp_rtcp_);
98 }
99 82
100 void ViEChannel::SetProtectionMode(bool enable_nack, 83 void ViEChannel::SetProtectionMode(bool enable_nack,
101 bool enable_fec, 84 bool enable_fec,
102 int payload_type_red, 85 int payload_type_red,
103 int payload_type_fec) { 86 int payload_type_fec) {
104 // Validate payload types. If either RED or FEC payload types are set then 87 // Validate payload types. If either RED or FEC payload types are set then
105 // both should be. If FEC is enabled then they both have to be set. 88 // both should be. If FEC is enabled then they both have to be set.
106 if (enable_fec || payload_type_red != -1 || payload_type_fec != -1) { 89 if (enable_fec || payload_type_red != -1 || payload_type_fec != -1) {
107 RTC_DCHECK_GE(payload_type_red, 0); 90 RTC_DCHECK_GE(payload_type_red, 0);
108 RTC_DCHECK_GE(payload_type_fec, 0); 91 RTC_DCHECK_GE(payload_type_fec, 0);
(...skipping 24 matching lines...) Expand all
133 rtp_rtcp_->SetGenericFECStatus(enable_fec, 116 rtp_rtcp_->SetGenericFECStatus(enable_fec,
134 static_cast<uint8_t>(payload_type_red), 117 static_cast<uint8_t>(payload_type_red),
135 static_cast<uint8_t>(payload_type_fec)); 118 static_cast<uint8_t>(payload_type_fec));
136 } 119 }
137 120
138 void ViEChannel::ProcessNACKRequest(const bool enable) { 121 void ViEChannel::ProcessNACKRequest(const bool enable) {
139 if (enable) { 122 if (enable) {
140 // Turn on NACK. 123 // Turn on NACK.
141 if (rtp_rtcp_->RTCP() == RtcpMode::kOff) 124 if (rtp_rtcp_->RTCP() == RtcpMode::kOff)
142 return; 125 return;
143 vie_receiver_.SetNackStatus(true, max_nack_reordering_threshold_); 126 rtp_stream_receiver_->SetNackStatus(true, max_nack_reordering_threshold_);
144 video_receiver_->RegisterPacketRequestCallback(this); 127 video_receiver_->RegisterPacketRequestCallback(this);
145 // Don't introduce errors when NACK is enabled. 128 // Don't introduce errors when NACK is enabled.
146 video_receiver_->SetDecodeErrorMode(kNoErrors); 129 video_receiver_->SetDecodeErrorMode(kNoErrors);
147 130
148 } else { 131 } else {
149 video_receiver_->RegisterPacketRequestCallback(nullptr); 132 video_receiver_->RegisterPacketRequestCallback(nullptr);
150 // When NACK is off, allow decoding with errors. Otherwise, the video 133 // When NACK is off, allow decoding with errors. Otherwise, the video
151 // will freeze, and will only recover with a complete key frame. 134 // will freeze, and will only recover with a complete key frame.
152 video_receiver_->SetDecodeErrorMode(kWithErrors); 135 video_receiver_->SetDecodeErrorMode(kWithErrors);
153 vie_receiver_.SetNackStatus(false, max_nack_reordering_threshold_); 136 rtp_stream_receiver_->SetNackStatus(false, max_nack_reordering_threshold_);
154 } 137 }
155 } 138 }
156 139
157 int ViEChannel::GetRequiredNackListSize(int target_delay_ms) { 140 int ViEChannel::GetRequiredNackListSize(int target_delay_ms) {
158 // The max size of the nack list should be large enough to accommodate the 141 // The max size of the nack list should be large enough to accommodate the
159 // the number of packets (frames) resulting from the increased delay. 142 // the number of packets (frames) resulting from the increased delay.
160 // Roughly estimating for ~40 packets per frame @ 30fps. 143 // Roughly estimating for ~40 packets per frame @ 30fps.
161 return target_delay_ms * 40 * 30 / 1000; 144 return target_delay_ms * 40 * 30 / 1000;
162 } 145 }
163 146
164 RtpState ViEChannel::GetRtpStateForSsrc(uint32_t ssrc) const { 147 RtpState ViEChannel::GetRtpStateForSsrc(uint32_t ssrc) const {
165 RTC_DCHECK(!rtp_rtcp_->Sending()); 148 RTC_DCHECK(!rtp_rtcp_->Sending());
166 RTC_DCHECK_EQ(ssrc, rtp_rtcp_->SSRC()); 149 RTC_DCHECK_EQ(ssrc, rtp_rtcp_->SSRC());
167 return rtp_rtcp_->GetRtpState(); 150 return rtp_rtcp_->GetRtpState();
168 } 151 }
169 152
170 void ViEChannel::RegisterRtcpPacketTypeCounterObserver( 153 void ViEChannel::RegisterRtcpPacketTypeCounterObserver(
171 RtcpPacketTypeCounterObserver* observer) { 154 RtcpPacketTypeCounterObserver* observer) {
172 vie_receiver_.RegisterRtcpPacketTypeCounterObserver(observer); 155 rtp_stream_receiver_->RegisterRtcpPacketTypeCounterObserver(observer);
pbos-webrtc 2016/04/28 14:26:49 Can you move this to VideoReceiveStream since it's
mflodman 2016/04/29 04:50:15 I have a CL almost reay to upload as soon as this
173 }
174
175 ViEReceiver* ViEChannel::vie_receiver() {
176 return &vie_receiver_;
177 } 156 }
178 157
179 CallStatsObserver* ViEChannel::GetStatsObserver() { 158 CallStatsObserver* ViEChannel::GetStatsObserver() {
180 return stats_observer_.get(); 159 return stats_observer_.get();
181 } 160 }
182 161
183 // Do not acquire the lock of |video_receiver_| in this function. Decode 162 // Do not acquire the lock of |video_receiver_| in this function. Decode
184 // callback won't necessarily be called from the decoding thread. The decoding 163 // callback won't necessarily be called from the decoding thread. The decoding
185 // thread may have held the lock when calling VideoDecoder::Decode, Reset, or 164 // thread may have held the lock when calling VideoDecoder::Decode, Reset, or
186 // Release. Acquiring the same lock in the path of decode callback can deadlock. 165 // Release. Acquiring the same lock in the path of decode callback can deadlock.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 rtc::CritScope lock(&crit_); 246 rtc::CritScope lock(&crit_);
268 last_rtt_ms_ = avg_rtt_ms; 247 last_rtt_ms_ = avg_rtt_ms;
269 } 248 }
270 249
271 void ViEChannel::RegisterPreRenderCallback( 250 void ViEChannel::RegisterPreRenderCallback(
272 I420FrameCallback* pre_render_callback) { 251 I420FrameCallback* pre_render_callback) {
273 rtc::CritScope lock(&crit_); 252 rtc::CritScope lock(&crit_);
274 pre_render_callback_ = pre_render_callback; 253 pre_render_callback_ = pre_render_callback;
275 } 254 }
276 255
277 // TODO(pbos): Remove as soon as audio can handle a changing payload type
278 // without this callback.
279 int32_t ViEChannel::OnInitializeDecoder(
280 const int8_t payload_type,
281 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
282 const int frequency,
283 const size_t channels,
284 const uint32_t rate) {
285 RTC_NOTREACHED();
286 return 0;
287 }
288
289 void ViEChannel::OnIncomingSSRCChanged(const uint32_t ssrc) {
290 rtp_rtcp_->SetRemoteSSRC(ssrc);
291 }
292
293 void ViEChannel::OnIncomingCSRCChanged(const uint32_t CSRC, const bool added) {}
294
295 void ViEChannel::RegisterReceiveStatisticsProxy( 256 void ViEChannel::RegisterReceiveStatisticsProxy(
296 ReceiveStatisticsProxy* receive_statistics_proxy) { 257 ReceiveStatisticsProxy* receive_statistics_proxy) {
297 rtc::CritScope lock(&crit_); 258 rtc::CritScope lock(&crit_);
298 receive_stats_callback_ = receive_statistics_proxy; 259 receive_stats_callback_ = receive_statistics_proxy;
299 } 260 }
300 261
301 void ViEChannel::SetIncomingVideoStream( 262 void ViEChannel::SetIncomingVideoStream(
302 IncomingVideoStream* incoming_video_stream) { 263 IncomingVideoStream* incoming_video_stream) {
303 rtc::CritScope lock(&crit_); 264 rtc::CritScope lock(&crit_);
304 incoming_video_stream_ = incoming_video_stream; 265 incoming_video_stream_ = incoming_video_stream;
305 } 266 }
306 } // namespace webrtc 267 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698