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

Unified 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: Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/video/video_send_stream.cc
diff --git a/webrtc/video/video_send_stream.cc b/webrtc/video/video_send_stream.cc
index 7ae55dcf72af857985f368602967764f3735ae82..680c27aa744bd9763e7b1ceba7128e191dd3f9ef 100644
--- a/webrtc/video/video_send_stream.cc
+++ b/webrtc/video/video_send_stream.cc
@@ -171,6 +171,9 @@ VideoSendStream::VideoSendStream(
call_stats_(call_stats),
congestion_controller_(congestion_controller),
remb_(remb),
+ encoder_thread_(EncoderThreadFunction, this, "EncoderThread"),
+ encoder_wakeup_event_(false, false),
+ stop_encoder_thread_(0),
overuse_detector_(
Clock::GetRealTimeClock(),
GetCpuOveruseOptions(config.encoder_settings.full_overuse_time),
@@ -203,7 +206,7 @@ VideoSendStream::VideoSendStream(
bitrate_allocator),
vcm_(vie_encoder_.vcm()),
rtp_rtcp_modules_(vie_channel_.rtp_rtcp()),
- input_(&vie_encoder_,
+ input_(&encoder_wakeup_event_,
config_.local_renderer,
&stats_proxy_,
&overuse_detector_) {
@@ -303,12 +306,20 @@ VideoSendStream::VideoSendStream(
vie_channel_.RegisterSendFrameCountObserver(&stats_proxy_);
module_process_thread_->RegisterModule(&overuse_detector_);
+
+ encoder_thread_.Start();
+ encoder_thread_.SetPriority(rtc::kHighPriority);
}
VideoSendStream::~VideoSendStream() {
LOG(LS_INFO) << "~VideoSendStream: " << config_.ToString();
Stop();
+ // Stop the encoder thread permanently.
+ rtc::AtomicOps::ReleaseStore(&stop_encoder_thread_, 1);
+ encoder_wakeup_event_.Set();
+ encoder_thread_.Stop();
+
module_process_thread_->DeRegisterModule(&overuse_detector_);
vie_channel_.RegisterSendFrameCountObserver(nullptr);
vie_channel_.RegisterSendBitrateObserver(nullptr);
@@ -351,6 +362,23 @@ void VideoSendStream::Stop() {
vie_receiver_->StopReceive();
}
+bool VideoSendStream::EncoderThreadFunction(void* obj) {
+ return static_cast<VideoSendStream*>(obj)->EncoderProcess();
+}
+
+bool VideoSendStream::EncoderProcess() {
+ static const int kThreadWaitTimeMs = 100;
+ if (!encoder_wakeup_event_.Wait(kThreadWaitTimeMs))
stefan-webrtc 2016/03/03 14:19:35 kWaitForevah
pbos-webrtc 2016/03/03 14:25:32 Done.
+ return true;
+ if (rtc::AtomicOps::AcquireLoad(&stop_encoder_thread_))
+ return false;
+
+ VideoFrame frame;
+ if (input_.GetVideoFrame(&frame))
+ vie_encoder_.EncodeVideoFrame(frame);
+ return true;
+}
+
void VideoSendStream::ReconfigureVideoEncoder(
const VideoEncoderConfig& config) {
TRACE_EVENT0("webrtc", "VideoSendStream::(Re)configureVideoEncoder");

Powered by Google App Engine
This is Rietveld 408576698