| 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/video_capture/video_capture_factory.h" | 17 #include "webrtc/modules/video_capture/video_capture_factory.h" |
| 18 #include "webrtc/modules/video_processing/include/video_processing.h" | 18 #include "webrtc/modules/video_processing/include/video_processing.h" |
| 19 #include "webrtc/modules/video_render/video_render_defines.h" | 19 #include "webrtc/modules/video_render/video_render_defines.h" |
| 20 #include "webrtc/system_wrappers/include/clock.h" | |
| 21 #include "webrtc/system_wrappers/include/tick_util.h" | |
| 22 #include "webrtc/video/overuse_frame_detector.h" | 20 #include "webrtc/video/overuse_frame_detector.h" |
| 23 #include "webrtc/video/send_statistics_proxy.h" | 21 #include "webrtc/video/send_statistics_proxy.h" |
| 24 #include "webrtc/video/vie_encoder.h" | 22 #include "webrtc/video/vie_encoder.h" |
| 25 | 23 |
| 26 namespace webrtc { | 24 namespace webrtc { |
| 27 | 25 |
| 28 namespace internal { | 26 namespace internal { |
| 29 VideoCaptureInput::VideoCaptureInput(VideoCaptureCallback* frame_callback, | 27 VideoCaptureInput::VideoCaptureInput(VideoCaptureCallback* frame_callback, |
| 30 VideoRenderer* local_renderer, | 28 VideoRenderer* local_renderer, |
| 31 SendStatisticsProxy* stats_proxy, | 29 SendStatisticsProxy* stats_proxy, |
| 32 OveruseFrameDetector* overuse_detector) | 30 OveruseFrameDetector* overuse_detector) |
| 33 : frame_callback_(frame_callback), | 31 : frame_callback_(frame_callback), |
| 34 local_renderer_(local_renderer), | 32 local_renderer_(local_renderer), |
| 35 stats_proxy_(stats_proxy), | 33 stats_proxy_(stats_proxy), |
| 36 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"), | 34 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"), |
| 37 capture_event_(false, false), | 35 capture_event_(false, false), |
| 38 stop_(0), | 36 stop_(0), |
| 37 // TODO(danilchap): Pass clock from outside to ensure it is same clock |
| 38 // rtcp module use to calculate offset since last frame captured |
| 39 // to estimate rtp timestamp for SenderReport. |
| 40 clock_(Clock::GetRealTimeClock()), |
| 39 last_captured_timestamp_(0), | 41 last_captured_timestamp_(0), |
| 40 delta_ntp_internal_ms_( | 42 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - |
| 41 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds() - | 43 clock_->TimeInMilliseconds()), |
| 42 TickTime::MillisecondTimestamp()), | |
| 43 overuse_detector_(overuse_detector) { | 44 overuse_detector_(overuse_detector) { |
| 44 encoder_thread_.Start(); | 45 encoder_thread_.Start(); |
| 45 encoder_thread_.SetPriority(rtc::kHighPriority); | 46 encoder_thread_.SetPriority(rtc::kHighPriority); |
| 46 } | 47 } |
| 47 | 48 |
| 48 VideoCaptureInput::~VideoCaptureInput() { | 49 VideoCaptureInput::~VideoCaptureInput() { |
| 49 // Stop the thread. | 50 // Stop the thread. |
| 50 rtc::AtomicOps::ReleaseStore(&stop_, 1); | 51 rtc::AtomicOps::ReleaseStore(&stop_, 1); |
| 51 capture_event_.Set(); | 52 capture_event_.Set(); |
| 52 encoder_thread_.Stop(); | 53 encoder_thread_.Stop(); |
| 53 } | 54 } |
| 54 | 55 |
| 55 void VideoCaptureInput::IncomingCapturedFrame(const VideoFrame& video_frame) { | 56 void VideoCaptureInput::IncomingCapturedFrame(const VideoFrame& video_frame) { |
| 56 // TODO(pbos): Remove local rendering, it should be handled by the client code | 57 // TODO(pbos): Remove local rendering, it should be handled by the client code |
| 57 // if required. | 58 // if required. |
| 58 if (local_renderer_) | 59 if (local_renderer_) |
| 59 local_renderer_->RenderFrame(video_frame, 0); | 60 local_renderer_->RenderFrame(video_frame, 0); |
| 60 | 61 |
| 61 stats_proxy_->OnIncomingFrame(video_frame.width(), video_frame.height()); | 62 stats_proxy_->OnIncomingFrame(video_frame.width(), video_frame.height()); |
| 62 | 63 |
| 63 VideoFrame incoming_frame = video_frame; | 64 VideoFrame incoming_frame = video_frame; |
| 64 | 65 |
| 65 if (incoming_frame.ntp_time_ms() != 0) { | 66 // Local time in webrtc time base. |
| 66 // If a NTP time stamp is set, this is the time stamp we will use. | 67 int64_t current_time = clock_->TimeInMilliseconds(); |
| 67 incoming_frame.set_render_time_ms(incoming_frame.ntp_time_ms() - | 68 incoming_frame.set_render_time_ms(current_time); |
| 68 delta_ntp_internal_ms_); | |
| 69 } else { // NTP time stamp not set. | |
| 70 int64_t render_time = incoming_frame.render_time_ms() != 0 | |
| 71 ? incoming_frame.render_time_ms() | |
| 72 : TickTime::MillisecondTimestamp(); | |
| 73 | 69 |
| 74 incoming_frame.set_render_time_ms(render_time); | 70 // Capture time may come from clock with an offset and drift from clock_. |
| 75 incoming_frame.set_ntp_time_ms(render_time + delta_ntp_internal_ms_); | 71 int64_t capture_ntp_time_ms; |
| 72 if (video_frame.ntp_time_ms() != 0) { |
| 73 capture_ntp_time_ms = video_frame.ntp_time_ms(); |
| 74 } else if (video_frame.render_time_ms() != 0) { |
| 75 capture_ntp_time_ms = video_frame.render_time_ms() + delta_ntp_internal_ms_; |
| 76 } else { |
| 77 capture_ntp_time_ms = current_time + delta_ntp_internal_ms_; |
| 76 } | 78 } |
| 79 incoming_frame.set_ntp_time_ms(capture_ntp_time_ms); |
| 77 | 80 |
| 78 // Convert NTP time, in ms, to RTP timestamp. | 81 // Convert NTP time, in ms, to RTP timestamp. |
| 79 const int kMsToRtpTimestamp = 90; | 82 const int kMsToRtpTimestamp = 90; |
| 80 incoming_frame.set_timestamp( | 83 incoming_frame.set_timestamp( |
| 81 kMsToRtpTimestamp * static_cast<uint32_t>(incoming_frame.ntp_time_ms())); | 84 kMsToRtpTimestamp * static_cast<uint32_t>(incoming_frame.ntp_time_ms())); |
| 82 | 85 |
| 83 rtc::CritScope lock(&crit_); | 86 rtc::CritScope lock(&crit_); |
| 84 if (incoming_frame.ntp_time_ms() <= last_captured_timestamp_) { | 87 if (incoming_frame.ntp_time_ms() <= last_captured_timestamp_) { |
| 85 // We don't allow the same capture time for two frames, drop this one. | 88 // We don't allow the same capture time for two frames, drop this one. |
| 86 LOG(LS_WARNING) << "Same/old NTP timestamp (" | 89 LOG(LS_WARNING) << "Same/old NTP timestamp (" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 124 } |
| 122 if (!deliver_frame.IsZeroSize()) { | 125 if (!deliver_frame.IsZeroSize()) { |
| 123 frame_callback_->DeliverFrame(deliver_frame); | 126 frame_callback_->DeliverFrame(deliver_frame); |
| 124 } | 127 } |
| 125 } | 128 } |
| 126 return true; | 129 return true; |
| 127 } | 130 } |
| 128 | 131 |
| 129 } // namespace internal | 132 } // namespace internal |
| 130 } // namespace webrtc | 133 } // namespace webrtc |
| OLD | NEW |