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

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

Issue 1569853002: Measure encoding time on encode callbacks. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: add extended overuse time Created 4 years, 11 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) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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/video_send_stream.h" 11 #include "webrtc/video/video_send_stream.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <sstream> 14 #include <sstream>
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "webrtc/base/checks.h" 18 #include "webrtc/base/checks.h"
19 #include "webrtc/base/logging.h" 19 #include "webrtc/base/logging.h"
20 #include "webrtc/base/trace_event.h" 20 #include "webrtc/base/trace_event.h"
21 #include "webrtc/call/congestion_controller.h" 21 #include "webrtc/call/congestion_controller.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/bitrate_controller/include/bitrate_controller.h" 23 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
24 #include "webrtc/modules/pacing/packet_router.h" 24 #include "webrtc/modules/pacing/packet_router.h"
25 #include "webrtc/modules/utility/include/process_thread.h"
25 #include "webrtc/video/call_stats.h" 26 #include "webrtc/video/call_stats.h"
26 #include "webrtc/video/encoder_state_feedback.h" 27 #include "webrtc/video/encoder_state_feedback.h"
27 #include "webrtc/video/payload_router.h" 28 #include "webrtc/video/payload_router.h"
28 #include "webrtc/video/video_capture_input.h" 29 #include "webrtc/video/video_capture_input.h"
29 #include "webrtc/video/vie_channel.h" 30 #include "webrtc/video/vie_channel.h"
30 #include "webrtc/video/vie_encoder.h" 31 #include "webrtc/video/vie_encoder.h"
31 #include "webrtc/video_send_stream.h" 32 #include "webrtc/video_send_stream.h"
32 33
33 namespace webrtc { 34 namespace webrtc {
34 35
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 ss << ", local_renderer: " << (local_renderer != nullptr ? "(VideoRenderer)" 101 ss << ", local_renderer: " << (local_renderer != nullptr ? "(VideoRenderer)"
101 : "nullptr"); 102 : "nullptr");
102 ss << ", render_delay_ms: " << render_delay_ms; 103 ss << ", render_delay_ms: " << render_delay_ms;
103 ss << ", target_delay_ms: " << target_delay_ms; 104 ss << ", target_delay_ms: " << target_delay_ms;
104 ss << ", suspend_below_min_bitrate: " << (suspend_below_min_bitrate ? "on" 105 ss << ", suspend_below_min_bitrate: " << (suspend_below_min_bitrate ? "on"
105 : "off"); 106 : "off");
106 ss << '}'; 107 ss << '}';
107 return ss.str(); 108 return ss.str();
108 } 109 }
109 110
111 namespace {
112
113 CpuOveruseOptions GetCpuOveruseOptions(bool full_overuse_time) {
114 CpuOveruseOptions options;
115 if (full_overuse_time) {
116 options.low_encode_usage_threshold_percent = 100;
117 options.high_encode_usage_threshold_percent = 120;
118 }
119 return options;
120 }
121 } // namespace
122
110 namespace internal { 123 namespace internal {
111 VideoSendStream::VideoSendStream( 124 VideoSendStream::VideoSendStream(
112 int num_cpu_cores, 125 int num_cpu_cores,
113 ProcessThread* module_process_thread, 126 ProcessThread* module_process_thread,
114 CallStats* call_stats, 127 CallStats* call_stats,
115 CongestionController* congestion_controller, 128 CongestionController* congestion_controller,
116 BitrateAllocator* bitrate_allocator, 129 BitrateAllocator* bitrate_allocator,
117 const VideoSendStream::Config& config, 130 const VideoSendStream::Config& config,
118 const VideoEncoderConfig& encoder_config, 131 const VideoEncoderConfig& encoder_config,
119 const std::map<uint32_t, RtpState>& suspended_ssrcs) 132 const std::map<uint32_t, RtpState>& suspended_ssrcs)
120 : stats_proxy_(Clock::GetRealTimeClock(), 133 : stats_proxy_(Clock::GetRealTimeClock(),
121 config, 134 config,
122 encoder_config.content_type), 135 encoder_config.content_type),
123 transport_adapter_(config.send_transport), 136 transport_adapter_(config.send_transport),
124 encoded_frame_proxy_(config.post_encode_callback), 137 encoded_frame_proxy_(config.post_encode_callback),
125 config_(config), 138 config_(config),
126 suspended_ssrcs_(suspended_ssrcs), 139 suspended_ssrcs_(suspended_ssrcs),
127 module_process_thread_(module_process_thread), 140 module_process_thread_(module_process_thread),
128 call_stats_(call_stats), 141 call_stats_(call_stats),
129 congestion_controller_(congestion_controller), 142 congestion_controller_(congestion_controller),
143 overuse_detector_(
144 Clock::GetRealTimeClock(),
145 GetCpuOveruseOptions(config.encoder_settings.full_overuse_time),
146 this,
147 &stats_proxy_),
130 encoder_feedback_(new EncoderStateFeedback()), 148 encoder_feedback_(new EncoderStateFeedback()),
131 use_config_bitrate_(true) { 149 use_config_bitrate_(true) {
132 LOG(LS_INFO) << "VideoSendStream: " << config_.ToString(); 150 LOG(LS_INFO) << "VideoSendStream: " << config_.ToString();
133 RTC_DCHECK(!config_.rtp.ssrcs.empty()); 151 RTC_DCHECK(!config_.rtp.ssrcs.empty());
134 152
135 // Set up Call-wide sequence numbers, if configured for this send stream. 153 // Set up Call-wide sequence numbers, if configured for this send stream.
136 TransportFeedbackObserver* transport_feedback_observer = nullptr; 154 TransportFeedbackObserver* transport_feedback_observer = nullptr;
137 for (const RtpExtension& extension : config.rtp.extensions) { 155 for (const RtpExtension& extension : config.rtp.extensions) {
138 if (extension.name == RtpExtension::kTransportSequenceNumber) { 156 if (extension.name == RtpExtension::kTransportSequenceNumber) {
139 transport_feedback_observer = 157 transport_feedback_observer =
140 congestion_controller_->GetTransportFeedbackObserver(); 158 congestion_controller_->GetTransportFeedbackObserver();
141 break; 159 break;
142 } 160 }
143 } 161 }
144 162
145 const std::vector<uint32_t>& ssrcs = config.rtp.ssrcs; 163 const std::vector<uint32_t>& ssrcs = config.rtp.ssrcs;
146 164
147 vie_encoder_.reset(new ViEEncoder( 165 vie_encoder_.reset(new ViEEncoder(num_cpu_cores,
148 num_cpu_cores, module_process_thread_, &stats_proxy_, 166 module_process_thread_,
149 config.pre_encode_callback, congestion_controller_->pacer(), 167 &stats_proxy_,
150 bitrate_allocator)); 168 config.pre_encode_callback,
169 &overuse_detector_,
170 congestion_controller_->pacer(),
171 bitrate_allocator));
151 RTC_CHECK(vie_encoder_->Init()); 172 RTC_CHECK(vie_encoder_->Init());
152 173
153 vie_channel_.reset(new ViEChannel( 174 vie_channel_.reset(new ViEChannel(
154 num_cpu_cores, config.send_transport, module_process_thread_, 175 num_cpu_cores, config.send_transport, module_process_thread_,
155 encoder_feedback_->GetRtcpIntraFrameObserver(), 176 encoder_feedback_->GetRtcpIntraFrameObserver(),
156 congestion_controller_->GetBitrateController()-> 177 congestion_controller_->GetBitrateController()->
157 CreateRtcpBandwidthObserver(), 178 CreateRtcpBandwidthObserver(),
158 transport_feedback_observer, 179 transport_feedback_observer,
159 congestion_controller_->GetRemoteBitrateEstimator(false), 180 congestion_controller_->GetRemoteBitrateEstimator(false),
160 call_stats_->rtcp_rtt_stats(), congestion_controller_->pacer(), 181 call_stats_->rtcp_rtt_stats(), congestion_controller_->pacer(),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 config_.rtp.fec.red_payload_type, 221 config_.rtp.fec.red_payload_type,
201 config_.rtp.fec.ulpfec_payload_type); 222 config_.rtp.fec.ulpfec_payload_type);
202 vie_encoder_->SetProtectionMethod(enable_protection_nack, 223 vie_encoder_->SetProtectionMethod(enable_protection_nack,
203 enable_protection_fec); 224 enable_protection_fec);
204 225
205 ConfigureSsrcs(); 226 ConfigureSsrcs();
206 227
207 vie_channel_->SetRTCPCName(config_.rtp.c_name.c_str()); 228 vie_channel_->SetRTCPCName(config_.rtp.c_name.c_str());
208 229
209 input_.reset(new internal::VideoCaptureInput( 230 input_.reset(new internal::VideoCaptureInput(
210 module_process_thread_, vie_encoder_.get(), config_.local_renderer, 231 vie_encoder_.get(), config_.local_renderer, &stats_proxy_,
211 &stats_proxy_, this, config_.encoding_time_observer)); 232 &overuse_detector_, config_.encoding_time_observer));
212 233
213 // 28 to match packet overhead in ModuleRtpRtcpImpl. 234 // 28 to match packet overhead in ModuleRtpRtcpImpl.
214 RTC_DCHECK_LE(config_.rtp.max_packet_size, static_cast<size_t>(0xFFFF - 28)); 235 RTC_DCHECK_LE(config_.rtp.max_packet_size, static_cast<size_t>(0xFFFF - 28));
215 vie_channel_->SetMTU(static_cast<uint16_t>(config_.rtp.max_packet_size + 28)); 236 vie_channel_->SetMTU(static_cast<uint16_t>(config_.rtp.max_packet_size + 28));
216 237
217 RTC_DCHECK(config.encoder_settings.encoder != nullptr); 238 RTC_DCHECK(config.encoder_settings.encoder != nullptr);
218 RTC_DCHECK_GE(config.encoder_settings.payload_type, 0); 239 RTC_DCHECK_GE(config.encoder_settings.payload_type, 0);
219 RTC_DCHECK_LE(config.encoder_settings.payload_type, 127); 240 RTC_DCHECK_LE(config.encoder_settings.payload_type, 127);
220 RTC_CHECK_EQ(0, vie_encoder_->RegisterExternalEncoder( 241 RTC_CHECK_EQ(0, vie_encoder_->RegisterExternalEncoder(
221 config.encoder_settings.encoder, 242 config.encoder_settings.encoder,
(...skipping 11 matching lines...) Expand all
233 vie_encoder_->SuspendBelowMinBitrate(); 254 vie_encoder_->SuspendBelowMinBitrate();
234 255
235 congestion_controller_->AddEncoder(vie_encoder_.get()); 256 congestion_controller_->AddEncoder(vie_encoder_.get());
236 encoder_feedback_->AddEncoder(ssrcs, vie_encoder_.get()); 257 encoder_feedback_->AddEncoder(ssrcs, vie_encoder_.get());
237 258
238 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(&stats_proxy_); 259 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(&stats_proxy_);
239 vie_channel_->RegisterSendChannelRtpStatisticsCallback(&stats_proxy_); 260 vie_channel_->RegisterSendChannelRtpStatisticsCallback(&stats_proxy_);
240 vie_channel_->RegisterRtcpPacketTypeCounterObserver(&stats_proxy_); 261 vie_channel_->RegisterRtcpPacketTypeCounterObserver(&stats_proxy_);
241 vie_channel_->RegisterSendBitrateObserver(&stats_proxy_); 262 vie_channel_->RegisterSendBitrateObserver(&stats_proxy_);
242 vie_channel_->RegisterSendFrameCountObserver(&stats_proxy_); 263 vie_channel_->RegisterSendFrameCountObserver(&stats_proxy_);
264
265 module_process_thread_->RegisterModule(&overuse_detector_);
243 } 266 }
244 267
245 VideoSendStream::~VideoSendStream() { 268 VideoSendStream::~VideoSendStream() {
246 LOG(LS_INFO) << "~VideoSendStream: " << config_.ToString(); 269 LOG(LS_INFO) << "~VideoSendStream: " << config_.ToString();
270 module_process_thread_->DeRegisterModule(&overuse_detector_);
247 vie_channel_->RegisterSendFrameCountObserver(nullptr); 271 vie_channel_->RegisterSendFrameCountObserver(nullptr);
248 vie_channel_->RegisterSendBitrateObserver(nullptr); 272 vie_channel_->RegisterSendBitrateObserver(nullptr);
249 vie_channel_->RegisterRtcpPacketTypeCounterObserver(nullptr); 273 vie_channel_->RegisterRtcpPacketTypeCounterObserver(nullptr);
250 vie_channel_->RegisterSendChannelRtpStatisticsCallback(nullptr); 274 vie_channel_->RegisterSendChannelRtpStatisticsCallback(nullptr);
251 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(nullptr); 275 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(nullptr);
252 276
253 // Remove capture input (thread) so that it's not running after the current 277 // Remove capture input (thread) so that it's not running after the current
254 // channel is deleted. 278 // channel is deleted.
255 input_.reset(); 279 input_.reset();
256 280
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 vie_encoder_->SetSsrcs(used_ssrcs); 599 vie_encoder_->SetSsrcs(used_ssrcs);
576 600
577 // Restart the media flow 601 // Restart the media flow
578 vie_encoder_->Restart(); 602 vie_encoder_->Restart();
579 603
580 return true; 604 return true;
581 } 605 }
582 606
583 } // namespace internal 607 } // namespace internal
584 } // namespace webrtc 608 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698