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

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

Issue 1487893004: Replace EventWrapper in video/, test/ and call/. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: add some back, EventTimerWrapper is in use Created 5 years 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_capture_input.h ('k') | webrtc/video/video_capture_input_unittest.cc » ('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/video_capture_input.h" 11 #include "webrtc/video/video_capture_input.h"
12 12
13 #include "webrtc/base/checks.h" 13 #include "webrtc/base/checks.h"
14 #include "webrtc/base/logging.h" 14 #include "webrtc/base/logging.h"
15 #include "webrtc/base/trace_event.h" 15 #include "webrtc/base/trace_event.h"
16 #include "webrtc/modules/include/module_common_types.h" 16 #include "webrtc/modules/include/module_common_types.h"
17 #include "webrtc/modules/utility/include/process_thread.h" 17 #include "webrtc/modules/utility/include/process_thread.h"
18 #include "webrtc/modules/video_capture/video_capture_factory.h" 18 #include "webrtc/modules/video_capture/video_capture_factory.h"
19 #include "webrtc/modules/video_processing/include/video_processing.h" 19 #include "webrtc/modules/video_processing/include/video_processing.h"
20 #include "webrtc/modules/video_render/video_render_defines.h" 20 #include "webrtc/modules/video_render/video_render_defines.h"
21 #include "webrtc/system_wrappers/include/clock.h" 21 #include "webrtc/system_wrappers/include/clock.h"
22 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 22 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
23 #include "webrtc/system_wrappers/include/event_wrapper.h"
24 #include "webrtc/system_wrappers/include/tick_util.h" 23 #include "webrtc/system_wrappers/include/tick_util.h"
25 #include "webrtc/video/overuse_frame_detector.h" 24 #include "webrtc/video/overuse_frame_detector.h"
26 #include "webrtc/video/send_statistics_proxy.h" 25 #include "webrtc/video/send_statistics_proxy.h"
27 #include "webrtc/video/vie_encoder.h" 26 #include "webrtc/video/vie_encoder.h"
28 27
29 namespace webrtc { 28 namespace webrtc {
30 29
31 namespace internal { 30 namespace internal {
32 VideoCaptureInput::VideoCaptureInput( 31 VideoCaptureInput::VideoCaptureInput(
33 ProcessThread* module_process_thread, 32 ProcessThread* module_process_thread,
34 VideoCaptureCallback* frame_callback, 33 VideoCaptureCallback* frame_callback,
35 VideoRenderer* local_renderer, 34 VideoRenderer* local_renderer,
36 SendStatisticsProxy* stats_proxy, 35 SendStatisticsProxy* stats_proxy,
37 CpuOveruseObserver* overuse_observer, 36 CpuOveruseObserver* overuse_observer,
38 EncodingTimeObserver* encoding_time_observer) 37 EncodingTimeObserver* encoding_time_observer)
39 : capture_cs_(CriticalSectionWrapper::CreateCriticalSection()), 38 : capture_cs_(CriticalSectionWrapper::CreateCriticalSection()),
40 module_process_thread_(module_process_thread), 39 module_process_thread_(module_process_thread),
41 frame_callback_(frame_callback), 40 frame_callback_(frame_callback),
42 local_renderer_(local_renderer), 41 local_renderer_(local_renderer),
43 stats_proxy_(stats_proxy), 42 stats_proxy_(stats_proxy),
44 incoming_frame_cs_(CriticalSectionWrapper::CreateCriticalSection()), 43 incoming_frame_cs_(CriticalSectionWrapper::CreateCriticalSection()),
45 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"), 44 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"),
46 capture_event_(EventWrapper::Create()), 45 capture_event_(false, false),
47 stop_(0), 46 stop_(0),
48 last_captured_timestamp_(0), 47 last_captured_timestamp_(0),
49 delta_ntp_internal_ms_( 48 delta_ntp_internal_ms_(
50 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds() - 49 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds() -
51 TickTime::MillisecondTimestamp()), 50 TickTime::MillisecondTimestamp()),
52 overuse_detector_(new OveruseFrameDetector(Clock::GetRealTimeClock(), 51 overuse_detector_(new OveruseFrameDetector(Clock::GetRealTimeClock(),
53 CpuOveruseOptions(), 52 CpuOveruseOptions(),
54 overuse_observer, 53 overuse_observer,
55 stats_proxy)), 54 stats_proxy)),
56 encoding_time_observer_(encoding_time_observer) { 55 encoding_time_observer_(encoding_time_observer) {
57 encoder_thread_.Start(); 56 encoder_thread_.Start();
58 encoder_thread_.SetPriority(rtc::kHighPriority); 57 encoder_thread_.SetPriority(rtc::kHighPriority);
59 module_process_thread_->RegisterModule(overuse_detector_.get()); 58 module_process_thread_->RegisterModule(overuse_detector_.get());
60 } 59 }
61 60
62 VideoCaptureInput::~VideoCaptureInput() { 61 VideoCaptureInput::~VideoCaptureInput() {
63 module_process_thread_->DeRegisterModule(overuse_detector_.get()); 62 module_process_thread_->DeRegisterModule(overuse_detector_.get());
64 63
65 // Stop the thread. 64 // Stop the thread.
66 rtc::AtomicOps::ReleaseStore(&stop_, 1); 65 rtc::AtomicOps::ReleaseStore(&stop_, 1);
67 capture_event_->Set(); 66 capture_event_.Set();
68 encoder_thread_.Stop(); 67 encoder_thread_.Stop();
69 } 68 }
70 69
71 void VideoCaptureInput::IncomingCapturedFrame(const VideoFrame& video_frame) { 70 void VideoCaptureInput::IncomingCapturedFrame(const VideoFrame& video_frame) {
72 // TODO(pbos): Remove local rendering, it should be handled by the client code 71 // TODO(pbos): Remove local rendering, it should be handled by the client code
73 // if required. 72 // if required.
74 if (local_renderer_) 73 if (local_renderer_)
75 local_renderer_->RenderFrame(video_frame, 0); 74 local_renderer_->RenderFrame(video_frame, 0);
76 75
77 stats_proxy_->OnIncomingFrame(video_frame.width(), video_frame.height()); 76 stats_proxy_->OnIncomingFrame(video_frame.width(), video_frame.height());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 captured_frame_.ShallowCopy(incoming_frame); 108 captured_frame_.ShallowCopy(incoming_frame);
110 last_captured_timestamp_ = incoming_frame.ntp_time_ms(); 109 last_captured_timestamp_ = incoming_frame.ntp_time_ms();
111 110
112 overuse_detector_->FrameCaptured(captured_frame_.width(), 111 overuse_detector_->FrameCaptured(captured_frame_.width(),
113 captured_frame_.height(), 112 captured_frame_.height(),
114 captured_frame_.render_time_ms()); 113 captured_frame_.render_time_ms());
115 114
116 TRACE_EVENT_ASYNC_BEGIN1("webrtc", "Video", video_frame.render_time_ms(), 115 TRACE_EVENT_ASYNC_BEGIN1("webrtc", "Video", video_frame.render_time_ms(),
117 "render_time", video_frame.render_time_ms()); 116 "render_time", video_frame.render_time_ms());
118 117
119 capture_event_->Set(); 118 capture_event_.Set();
120 } 119 }
121 120
122 bool VideoCaptureInput::EncoderThreadFunction(void* obj) { 121 bool VideoCaptureInput::EncoderThreadFunction(void* obj) {
123 return static_cast<VideoCaptureInput*>(obj)->EncoderProcess(); 122 return static_cast<VideoCaptureInput*>(obj)->EncoderProcess();
124 } 123 }
125 124
126 bool VideoCaptureInput::EncoderProcess() { 125 bool VideoCaptureInput::EncoderProcess() {
127 static const int kThreadWaitTimeMs = 100; 126 static const int kThreadWaitTimeMs = 100;
128 int64_t capture_time = -1; 127 int64_t capture_time = -1;
129 if (capture_event_->Wait(kThreadWaitTimeMs) == kEventSignaled) { 128 if (capture_event_.Wait(kThreadWaitTimeMs)) {
130 if (rtc::AtomicOps::AcquireLoad(&stop_)) 129 if (rtc::AtomicOps::AcquireLoad(&stop_))
131 return false; 130 return false;
132 131
133 int64_t encode_start_time = -1; 132 int64_t encode_start_time = -1;
134 VideoFrame deliver_frame; 133 VideoFrame deliver_frame;
135 { 134 {
136 CriticalSectionScoped cs(capture_cs_.get()); 135 CriticalSectionScoped cs(capture_cs_.get());
137 if (!captured_frame_.IsZeroSize()) { 136 if (!captured_frame_.IsZeroSize()) {
138 deliver_frame = captured_frame_; 137 deliver_frame = captured_frame_;
139 captured_frame_.Reset(); 138 captured_frame_.Reset();
(...skipping 18 matching lines...) Expand all
158 } 157 }
159 // We're done! 158 // We're done!
160 if (capture_time != -1) { 159 if (capture_time != -1) {
161 overuse_detector_->FrameSent(capture_time); 160 overuse_detector_->FrameSent(capture_time);
162 } 161 }
163 return true; 162 return true;
164 } 163 }
165 164
166 } // namespace internal 165 } // namespace internal
167 } // namespace webrtc 166 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/video_capture_input.h ('k') | webrtc/video/video_capture_input_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698