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

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

Issue 1763693002: Move encoder thread to VideoSendStream. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: feedback Created 4 years, 9 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/video_send_stream.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) 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
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 : stats_proxy_(Clock::GetRealTimeClock(), 164 : stats_proxy_(Clock::GetRealTimeClock(),
165 config, 165 config,
166 encoder_config.content_type), 166 encoder_config.content_type),
167 encoded_frame_proxy_(config.post_encode_callback), 167 encoded_frame_proxy_(config.post_encode_callback),
168 config_(config), 168 config_(config),
169 suspended_ssrcs_(suspended_ssrcs), 169 suspended_ssrcs_(suspended_ssrcs),
170 module_process_thread_(module_process_thread), 170 module_process_thread_(module_process_thread),
171 call_stats_(call_stats), 171 call_stats_(call_stats),
172 congestion_controller_(congestion_controller), 172 congestion_controller_(congestion_controller),
173 remb_(remb), 173 remb_(remb),
174 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"),
175 encoder_wakeup_event_(false, false),
176 stop_encoder_thread_(0),
174 overuse_detector_( 177 overuse_detector_(
175 Clock::GetRealTimeClock(), 178 Clock::GetRealTimeClock(),
176 GetCpuOveruseOptions(config.encoder_settings.full_overuse_time), 179 GetCpuOveruseOptions(config.encoder_settings.full_overuse_time),
177 this, 180 this,
178 config.post_encode_callback, 181 config.post_encode_callback,
179 &stats_proxy_), 182 &stats_proxy_),
180 vie_channel_(config.send_transport, 183 vie_channel_(config.send_transport,
181 module_process_thread_, 184 module_process_thread_,
182 &payload_router_, 185 &payload_router_,
183 nullptr, 186 nullptr,
(...skipping 12 matching lines...) Expand all
196 config_.rtp.ssrcs, 199 config_.rtp.ssrcs,
197 module_process_thread_, 200 module_process_thread_,
198 &stats_proxy_, 201 &stats_proxy_,
199 config.pre_encode_callback, 202 config.pre_encode_callback,
200 &overuse_detector_, 203 &overuse_detector_,
201 congestion_controller_->pacer(), 204 congestion_controller_->pacer(),
202 &payload_router_, 205 &payload_router_,
203 bitrate_allocator), 206 bitrate_allocator),
204 vcm_(vie_encoder_.vcm()), 207 vcm_(vie_encoder_.vcm()),
205 rtp_rtcp_modules_(vie_channel_.rtp_rtcp()), 208 rtp_rtcp_modules_(vie_channel_.rtp_rtcp()),
206 input_(&vie_encoder_, 209 input_(&encoder_wakeup_event_,
207 config_.local_renderer, 210 config_.local_renderer,
208 &stats_proxy_, 211 &stats_proxy_,
209 &overuse_detector_) { 212 &overuse_detector_) {
210 LOG(LS_INFO) << "VideoSendStream: " << config_.ToString(); 213 LOG(LS_INFO) << "VideoSendStream: " << config_.ToString();
211 214
212 RTC_DCHECK(!config_.rtp.ssrcs.empty()); 215 RTC_DCHECK(!config_.rtp.ssrcs.empty());
213 RTC_DCHECK(module_process_thread_); 216 RTC_DCHECK(module_process_thread_);
214 RTC_DCHECK(call_stats_); 217 RTC_DCHECK(call_stats_);
215 RTC_DCHECK(congestion_controller_); 218 RTC_DCHECK(congestion_controller_);
216 RTC_DCHECK(remb_); 219 RTC_DCHECK(remb_);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 vie_encoder_.RegisterPostEncodeImageCallback(&encoded_frame_proxy_); 299 vie_encoder_.RegisterPostEncodeImageCallback(&encoded_frame_proxy_);
297 300
298 if (config_.suspend_below_min_bitrate) 301 if (config_.suspend_below_min_bitrate)
299 vie_encoder_.SuspendBelowMinBitrate(); 302 vie_encoder_.SuspendBelowMinBitrate();
300 303
301 vie_channel_.RegisterRtcpPacketTypeCounterObserver(&stats_proxy_); 304 vie_channel_.RegisterRtcpPacketTypeCounterObserver(&stats_proxy_);
302 vie_channel_.RegisterSendBitrateObserver(&stats_proxy_); 305 vie_channel_.RegisterSendBitrateObserver(&stats_proxy_);
303 vie_channel_.RegisterSendFrameCountObserver(&stats_proxy_); 306 vie_channel_.RegisterSendFrameCountObserver(&stats_proxy_);
304 307
305 module_process_thread_->RegisterModule(&overuse_detector_); 308 module_process_thread_->RegisterModule(&overuse_detector_);
309
310 encoder_thread_.Start();
311 encoder_thread_.SetPriority(rtc::kHighPriority);
306 } 312 }
307 313
308 VideoSendStream::~VideoSendStream() { 314 VideoSendStream::~VideoSendStream() {
309 LOG(LS_INFO) << "~VideoSendStream: " << config_.ToString(); 315 LOG(LS_INFO) << "~VideoSendStream: " << config_.ToString();
310 Stop(); 316 Stop();
311 317
318 // Stop the encoder thread permanently.
319 rtc::AtomicOps::ReleaseStore(&stop_encoder_thread_, 1);
320 encoder_wakeup_event_.Set();
321 encoder_thread_.Stop();
322
312 module_process_thread_->DeRegisterModule(&overuse_detector_); 323 module_process_thread_->DeRegisterModule(&overuse_detector_);
313 vie_channel_.RegisterSendFrameCountObserver(nullptr); 324 vie_channel_.RegisterSendFrameCountObserver(nullptr);
314 vie_channel_.RegisterSendBitrateObserver(nullptr); 325 vie_channel_.RegisterSendBitrateObserver(nullptr);
315 vie_channel_.RegisterRtcpPacketTypeCounterObserver(nullptr); 326 vie_channel_.RegisterRtcpPacketTypeCounterObserver(nullptr);
316 327
317 vie_encoder_.DeRegisterExternalEncoder(config_.encoder_settings.payload_type); 328 vie_encoder_.DeRegisterExternalEncoder(config_.encoder_settings.payload_type);
318 329
319 call_stats_->DeregisterStatsObserver(vie_channel_.GetStatsObserver()); 330 call_stats_->DeregisterStatsObserver(vie_channel_.GetStatsObserver());
320 rtp_rtcp_modules_[0]->SetREMBStatus(false); 331 rtp_rtcp_modules_[0]->SetREMBStatus(false);
321 remb_->RemoveRembSender(rtp_rtcp_modules_[0]); 332 remb_->RemoveRembSender(rtp_rtcp_modules_[0]);
(...skipping 22 matching lines...) Expand all
344 } 355 }
345 356
346 void VideoSendStream::Stop() { 357 void VideoSendStream::Stop() {
347 if (!payload_router_.active()) 358 if (!payload_router_.active())
348 return; 359 return;
349 // TODO(pbos): Make sure the encoder stops here. 360 // TODO(pbos): Make sure the encoder stops here.
350 payload_router_.set_active(false); 361 payload_router_.set_active(false);
351 vie_receiver_->StopReceive(); 362 vie_receiver_->StopReceive();
352 } 363 }
353 364
365 bool VideoSendStream::EncoderThreadFunction(void* obj) {
366 static_cast<VideoSendStream*>(obj)->EncoderProcess();
367 // We're done, return false to abort.
368 return false;
369 }
370
371 void VideoSendStream::EncoderProcess() {
372 while (true) {
373 encoder_wakeup_event_.Wait(rtc::Event::kForever);
374 if (rtc::AtomicOps::AcquireLoad(&stop_encoder_thread_))
375 return;
376
377 VideoFrame frame;
378 if (input_.GetVideoFrame(&frame))
379 vie_encoder_.EncodeVideoFrame(frame);
380 }
381 }
382
354 void VideoSendStream::ReconfigureVideoEncoder( 383 void VideoSendStream::ReconfigureVideoEncoder(
355 const VideoEncoderConfig& config) { 384 const VideoEncoderConfig& config) {
356 TRACE_EVENT0("webrtc", "VideoSendStream::(Re)configureVideoEncoder"); 385 TRACE_EVENT0("webrtc", "VideoSendStream::(Re)configureVideoEncoder");
357 LOG(LS_INFO) << "(Re)configureVideoEncoder: " << config.ToString(); 386 LOG(LS_INFO) << "(Re)configureVideoEncoder: " << config.ToString();
358 const std::vector<VideoStream>& streams = config.streams; 387 const std::vector<VideoStream>& streams = config.streams;
359 static const int kEncoderMinBitrateKbps = 30; 388 static const int kEncoderMinBitrateKbps = 30;
360 RTC_DCHECK(!streams.empty()); 389 RTC_DCHECK(!streams.empty());
361 RTC_DCHECK_GE(config_.rtp.ssrcs.size(), streams.size()); 390 RTC_DCHECK_GE(config_.rtp.ssrcs.size(), streams.size());
362 RTC_DCHECK_GE(config.min_transmit_bitrate_bps, 0); 391 RTC_DCHECK_GE(config.min_transmit_bitrate_bps, 0);
363 392
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) 609 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_)
581 rtp_rtcp->SetRTCPStatus(RtcpMode::kOff); 610 rtp_rtcp->SetRTCPStatus(RtcpMode::kOff);
582 } 611 }
583 } 612 }
584 613
585 int VideoSendStream::GetPaddingNeededBps() const { 614 int VideoSendStream::GetPaddingNeededBps() const {
586 return vie_encoder_.GetPaddingNeededBps(); 615 return vie_encoder_.GetPaddingNeededBps();
587 } 616 }
588 } // namespace internal 617 } // namespace internal
589 } // namespace webrtc 618 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/video_send_stream.h ('k') | webrtc/video/vie_encoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698