OLD | NEW |
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" | |
23 #include "webrtc/system_wrappers/include/tick_util.h" | 22 #include "webrtc/system_wrappers/include/tick_util.h" |
24 #include "webrtc/video/overuse_frame_detector.h" | 23 #include "webrtc/video/overuse_frame_detector.h" |
25 #include "webrtc/video/send_statistics_proxy.h" | 24 #include "webrtc/video/send_statistics_proxy.h" |
26 #include "webrtc/video/vie_encoder.h" | 25 #include "webrtc/video/vie_encoder.h" |
27 | 26 |
28 namespace webrtc { | 27 namespace webrtc { |
29 | 28 |
30 namespace internal { | 29 namespace internal { |
31 VideoCaptureInput::VideoCaptureInput( | 30 VideoCaptureInput::VideoCaptureInput( |
32 ProcessThread* module_process_thread, | 31 ProcessThread* module_process_thread, |
33 VideoCaptureCallback* frame_callback, | 32 VideoCaptureCallback* frame_callback, |
34 VideoRenderer* local_renderer, | 33 VideoRenderer* local_renderer, |
35 SendStatisticsProxy* stats_proxy, | 34 SendStatisticsProxy* stats_proxy, |
36 CpuOveruseObserver* overuse_observer, | 35 CpuOveruseObserver* overuse_observer, |
37 EncodingTimeObserver* encoding_time_observer) | 36 EncodingTimeObserver* encoding_time_observer) |
38 : capture_cs_(CriticalSectionWrapper::CreateCriticalSection()), | 37 : module_process_thread_(module_process_thread), |
39 module_process_thread_(module_process_thread), | |
40 frame_callback_(frame_callback), | 38 frame_callback_(frame_callback), |
41 local_renderer_(local_renderer), | 39 local_renderer_(local_renderer), |
42 stats_proxy_(stats_proxy), | 40 stats_proxy_(stats_proxy), |
43 incoming_frame_cs_(CriticalSectionWrapper::CreateCriticalSection()), | |
44 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"), | 41 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"), |
45 capture_event_(false, false), | 42 capture_event_(false, false), |
46 stop_(0), | 43 stop_(0), |
47 last_captured_timestamp_(0), | 44 last_captured_timestamp_(0), |
48 delta_ntp_internal_ms_( | 45 delta_ntp_internal_ms_( |
49 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds() - | 46 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds() - |
50 TickTime::MillisecondTimestamp()), | 47 TickTime::MillisecondTimestamp()), |
51 overuse_detector_(new OveruseFrameDetector(Clock::GetRealTimeClock(), | 48 overuse_detector_(new OveruseFrameDetector(Clock::GetRealTimeClock(), |
52 CpuOveruseOptions(), | 49 CpuOveruseOptions(), |
53 overuse_observer, | 50 overuse_observer, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 85 |
89 incoming_frame.set_render_time_ms(render_time); | 86 incoming_frame.set_render_time_ms(render_time); |
90 incoming_frame.set_ntp_time_ms(render_time + delta_ntp_internal_ms_); | 87 incoming_frame.set_ntp_time_ms(render_time + delta_ntp_internal_ms_); |
91 } | 88 } |
92 | 89 |
93 // Convert NTP time, in ms, to RTP timestamp. | 90 // Convert NTP time, in ms, to RTP timestamp. |
94 const int kMsToRtpTimestamp = 90; | 91 const int kMsToRtpTimestamp = 90; |
95 incoming_frame.set_timestamp( | 92 incoming_frame.set_timestamp( |
96 kMsToRtpTimestamp * static_cast<uint32_t>(incoming_frame.ntp_time_ms())); | 93 kMsToRtpTimestamp * static_cast<uint32_t>(incoming_frame.ntp_time_ms())); |
97 | 94 |
98 CriticalSectionScoped cs(capture_cs_.get()); | 95 rtc::CritScope lock(&crit_); |
99 if (incoming_frame.ntp_time_ms() <= last_captured_timestamp_) { | 96 if (incoming_frame.ntp_time_ms() <= last_captured_timestamp_) { |
100 // We don't allow the same capture time for two frames, drop this one. | 97 // We don't allow the same capture time for two frames, drop this one. |
101 LOG(LS_WARNING) << "Same/old NTP timestamp (" | 98 LOG(LS_WARNING) << "Same/old NTP timestamp (" |
102 << incoming_frame.ntp_time_ms() | 99 << incoming_frame.ntp_time_ms() |
103 << " <= " << last_captured_timestamp_ | 100 << " <= " << last_captured_timestamp_ |
104 << ") for incoming frame. Dropping."; | 101 << ") for incoming frame. Dropping."; |
105 return; | 102 return; |
106 } | 103 } |
107 | 104 |
108 captured_frame_.ShallowCopy(incoming_frame); | 105 captured_frame_.ShallowCopy(incoming_frame); |
(...skipping 16 matching lines...) Expand all Loading... |
125 bool VideoCaptureInput::EncoderProcess() { | 122 bool VideoCaptureInput::EncoderProcess() { |
126 static const int kThreadWaitTimeMs = 100; | 123 static const int kThreadWaitTimeMs = 100; |
127 int64_t capture_time = -1; | 124 int64_t capture_time = -1; |
128 if (capture_event_.Wait(kThreadWaitTimeMs)) { | 125 if (capture_event_.Wait(kThreadWaitTimeMs)) { |
129 if (rtc::AtomicOps::AcquireLoad(&stop_)) | 126 if (rtc::AtomicOps::AcquireLoad(&stop_)) |
130 return false; | 127 return false; |
131 | 128 |
132 int64_t encode_start_time = -1; | 129 int64_t encode_start_time = -1; |
133 VideoFrame deliver_frame; | 130 VideoFrame deliver_frame; |
134 { | 131 { |
135 CriticalSectionScoped cs(capture_cs_.get()); | 132 rtc::CritScope lock(&crit_); |
136 if (!captured_frame_.IsZeroSize()) { | 133 if (!captured_frame_.IsZeroSize()) { |
137 deliver_frame = captured_frame_; | 134 deliver_frame = captured_frame_; |
138 captured_frame_.Reset(); | 135 captured_frame_.Reset(); |
139 } | 136 } |
140 } | 137 } |
141 if (!deliver_frame.IsZeroSize()) { | 138 if (!deliver_frame.IsZeroSize()) { |
142 capture_time = deliver_frame.render_time_ms(); | 139 capture_time = deliver_frame.render_time_ms(); |
143 encode_start_time = Clock::GetRealTimeClock()->TimeInMilliseconds(); | 140 encode_start_time = Clock::GetRealTimeClock()->TimeInMilliseconds(); |
144 frame_callback_->DeliverFrame(deliver_frame); | 141 frame_callback_->DeliverFrame(deliver_frame); |
145 } | 142 } |
(...skipping 10 matching lines...) Expand all Loading... |
156 } | 153 } |
157 // We're done! | 154 // We're done! |
158 if (capture_time != -1) { | 155 if (capture_time != -1) { |
159 overuse_detector_->FrameSent(capture_time); | 156 overuse_detector_->FrameSent(capture_time); |
160 } | 157 } |
161 return true; | 158 return true; |
162 } | 159 } |
163 | 160 |
164 } // namespace internal | 161 } // namespace internal |
165 } // namespace webrtc | 162 } // namespace webrtc |
OLD | NEW |