| 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 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 VideoCaptureCallback* frame_callback, | 33 VideoCaptureCallback* frame_callback, |
| 34 VideoRenderer* local_renderer, | 34 VideoRenderer* local_renderer, |
| 35 SendStatisticsProxy* stats_proxy, | 35 SendStatisticsProxy* stats_proxy, |
| 36 CpuOveruseObserver* overuse_observer) | 36 CpuOveruseObserver* overuse_observer) |
| 37 : capture_cs_(CriticalSectionWrapper::CreateCriticalSection()), | 37 : capture_cs_(CriticalSectionWrapper::CreateCriticalSection()), |
| 38 module_process_thread_(module_process_thread), | 38 module_process_thread_(module_process_thread), |
| 39 frame_callback_(frame_callback), | 39 frame_callback_(frame_callback), |
| 40 local_renderer_(local_renderer), | 40 local_renderer_(local_renderer), |
| 41 stats_proxy_(stats_proxy), | 41 stats_proxy_(stats_proxy), |
| 42 incoming_frame_cs_(CriticalSectionWrapper::CreateCriticalSection()), | 42 incoming_frame_cs_(CriticalSectionWrapper::CreateCriticalSection()), |
| 43 capture_thread_(ThreadWrapper::CreateThread(CaptureThreadFunction, | 43 encoder_thread_(ThreadWrapper::CreateThread(EncoderThreadFunction, |
| 44 this, | 44 this, |
| 45 "CaptureThread")), | 45 "EncoderThread")), |
| 46 capture_event_(*EventWrapper::Create()), | 46 capture_event_(EventWrapper::Create()), |
| 47 stop_(0), | 47 stop_(0), |
| 48 last_captured_timestamp_(0), | 48 last_captured_timestamp_(0), |
| 49 delta_ntp_internal_ms_( | 49 delta_ntp_internal_ms_( |
| 50 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds() - | 50 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds() - |
| 51 TickTime::MillisecondTimestamp()), | 51 TickTime::MillisecondTimestamp()), |
| 52 overuse_detector_(new OveruseFrameDetector(Clock::GetRealTimeClock(), | 52 overuse_detector_(new OveruseFrameDetector(Clock::GetRealTimeClock(), |
| 53 CpuOveruseOptions(), | 53 CpuOveruseOptions(), |
| 54 overuse_observer, | 54 overuse_observer, |
| 55 stats_proxy)) { | 55 stats_proxy)) { |
| 56 capture_thread_->Start(); | 56 encoder_thread_->Start(); |
| 57 capture_thread_->SetPriority(kHighPriority); | 57 encoder_thread_->SetPriority(kHighPriority); |
| 58 module_process_thread_->RegisterModule(overuse_detector_.get()); | 58 module_process_thread_->RegisterModule(overuse_detector_.get()); |
| 59 } | 59 } |
| 60 | 60 |
| 61 VideoCaptureInput::~VideoCaptureInput() { | 61 VideoCaptureInput::~VideoCaptureInput() { |
| 62 module_process_thread_->DeRegisterModule(overuse_detector_.get()); | 62 module_process_thread_->DeRegisterModule(overuse_detector_.get()); |
| 63 | 63 |
| 64 // Stop the thread. | 64 // Stop the thread. |
| 65 rtc::AtomicOps::ReleaseStore(&stop_, 1); | 65 rtc::AtomicOps::ReleaseStore(&stop_, 1); |
| 66 capture_event_.Set(); | 66 capture_event_->Set(); |
| 67 | 67 encoder_thread_->Stop(); |
| 68 // Stop the camera input. | |
| 69 capture_thread_->Stop(); | |
| 70 delete &capture_event_; | |
| 71 } | 68 } |
| 72 | 69 |
| 73 void VideoCaptureInput::IncomingCapturedFrame(const VideoFrame& video_frame) { | 70 void VideoCaptureInput::IncomingCapturedFrame(const VideoFrame& video_frame) { |
| 74 // 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 |
| 75 // if required. | 72 // if required. |
| 76 if (local_renderer_) | 73 if (local_renderer_) |
| 77 local_renderer_->RenderFrame(video_frame, 0); | 74 local_renderer_->RenderFrame(video_frame, 0); |
| 78 | 75 |
| 79 stats_proxy_->OnIncomingFrame(video_frame.width(), video_frame.height()); | 76 stats_proxy_->OnIncomingFrame(video_frame.width(), video_frame.height()); |
| 80 | 77 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 111 captured_frame_.ShallowCopy(incoming_frame); | 108 captured_frame_.ShallowCopy(incoming_frame); |
| 112 last_captured_timestamp_ = incoming_frame.ntp_time_ms(); | 109 last_captured_timestamp_ = incoming_frame.ntp_time_ms(); |
| 113 | 110 |
| 114 overuse_detector_->FrameCaptured(captured_frame_.width(), | 111 overuse_detector_->FrameCaptured(captured_frame_.width(), |
| 115 captured_frame_.height(), | 112 captured_frame_.height(), |
| 116 captured_frame_.render_time_ms()); | 113 captured_frame_.render_time_ms()); |
| 117 | 114 |
| 118 TRACE_EVENT_ASYNC_BEGIN1("webrtc", "Video", video_frame.render_time_ms(), | 115 TRACE_EVENT_ASYNC_BEGIN1("webrtc", "Video", video_frame.render_time_ms(), |
| 119 "render_time", video_frame.render_time_ms()); | 116 "render_time", video_frame.render_time_ms()); |
| 120 | 117 |
| 121 capture_event_.Set(); | 118 capture_event_->Set(); |
| 122 } | 119 } |
| 123 | 120 |
| 124 bool VideoCaptureInput::CaptureThreadFunction(void* obj) { | 121 bool VideoCaptureInput::EncoderThreadFunction(void* obj) { |
| 125 return static_cast<VideoCaptureInput*>(obj)->CaptureProcess(); | 122 return static_cast<VideoCaptureInput*>(obj)->EncoderProcess(); |
| 126 } | 123 } |
| 127 | 124 |
| 128 bool VideoCaptureInput::CaptureProcess() { | 125 bool VideoCaptureInput::EncoderProcess() { |
| 129 static const int kThreadWaitTimeMs = 100; | 126 static const int kThreadWaitTimeMs = 100; |
| 130 int64_t capture_time = -1; | 127 int64_t capture_time = -1; |
| 131 if (capture_event_.Wait(kThreadWaitTimeMs) == kEventSignaled) { | 128 if (capture_event_->Wait(kThreadWaitTimeMs) == kEventSignaled) { |
| 132 if (rtc::AtomicOps::AcquireLoad(&stop_)) | 129 if (rtc::AtomicOps::AcquireLoad(&stop_)) |
| 133 return false; | 130 return false; |
| 134 | 131 |
| 135 int64_t encode_start_time = -1; | 132 int64_t encode_start_time = -1; |
| 136 VideoFrame deliver_frame; | 133 VideoFrame deliver_frame; |
| 137 { | 134 { |
| 138 CriticalSectionScoped cs(capture_cs_.get()); | 135 CriticalSectionScoped cs(capture_cs_.get()); |
| 139 if (!captured_frame_.IsZeroSize()) { | 136 if (!captured_frame_.IsZeroSize()) { |
| 140 deliver_frame = captured_frame_; | 137 deliver_frame = captured_frame_; |
| 141 captured_frame_.Reset(); | 138 captured_frame_.Reset(); |
| (...skipping 14 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 |