Chromium Code Reviews| 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/video/overuse_frame_detector.h" | 19 #include "webrtc/video/overuse_frame_detector.h" |
| 20 #include "webrtc/video/send_statistics_proxy.h" | 20 #include "webrtc/video/send_statistics_proxy.h" |
| 21 #include "webrtc/video/vie_encoder.h" | 21 #include "webrtc/video/vie_encoder.h" |
| 22 | 22 |
| 23 namespace webrtc { | 23 namespace webrtc { |
| 24 namespace { | |
| 25 const int64_t kFrameLogIntervalMs = 60000; | |
| 26 } // namespace | |
| 24 | 27 |
| 25 namespace internal { | 28 namespace internal { |
| 26 VideoCaptureInput::VideoCaptureInput( | 29 VideoCaptureInput::VideoCaptureInput( |
| 27 rtc::Event* capture_event, | 30 rtc::Event* capture_event, |
| 28 rtc::VideoSinkInterface<VideoFrame>* local_renderer, | 31 rtc::VideoSinkInterface<VideoFrame>* local_renderer, |
| 29 SendStatisticsProxy* stats_proxy, | 32 SendStatisticsProxy* stats_proxy, |
| 30 OveruseFrameDetector* overuse_detector) | 33 OveruseFrameDetector* overuse_detector) |
| 31 : local_renderer_(local_renderer), | 34 : local_renderer_(local_renderer), |
| 32 stats_proxy_(stats_proxy), | 35 stats_proxy_(stats_proxy), |
| 33 capture_event_(capture_event), | 36 capture_event_(capture_event), |
| 34 // TODO(danilchap): Pass clock from outside to ensure it is same clock | 37 // TODO(danilchap): Pass clock from outside to ensure it is same clock |
| 35 // rtcp module use to calculate offset since last frame captured | 38 // rtcp module use to calculate offset since last frame captured |
| 36 // to estimate rtp timestamp for SenderReport. | 39 // to estimate rtp timestamp for SenderReport. |
| 37 clock_(Clock::GetRealTimeClock()), | 40 clock_(Clock::GetRealTimeClock()), |
| 38 last_captured_timestamp_(0), | 41 last_captured_timestamp_(0), |
| 39 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - | 42 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - |
| 40 clock_->TimeInMilliseconds()), | 43 clock_->TimeInMilliseconds()), |
| 41 overuse_detector_(overuse_detector) {} | 44 overuse_detector_(overuse_detector), |
| 45 last_frame_log_ms_(clock_->TimeInMilliseconds()), | |
| 46 captured_frame_count_(0), | |
| 47 dropped_frame_count_(0) {} | |
| 42 | 48 |
| 43 VideoCaptureInput::~VideoCaptureInput() { | 49 VideoCaptureInput::~VideoCaptureInput() { |
| 44 } | 50 } |
| 45 | 51 |
| 46 void VideoCaptureInput::IncomingCapturedFrame(const VideoFrame& video_frame) { | 52 void VideoCaptureInput::IncomingCapturedFrame(const VideoFrame& video_frame) { |
| 47 // TODO(pbos): Remove local rendering, it should be handled by the client code | 53 // TODO(pbos): Remove local rendering, it should be handled by the client code |
| 48 // if required. | 54 // if required. |
| 49 if (local_renderer_) | 55 if (local_renderer_) |
| 50 local_renderer_->OnFrame(video_frame); | 56 local_renderer_->OnFrame(video_frame); |
| 51 | 57 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 76 rtc::CritScope lock(&crit_); | 82 rtc::CritScope lock(&crit_); |
| 77 if (incoming_frame.ntp_time_ms() <= last_captured_timestamp_) { | 83 if (incoming_frame.ntp_time_ms() <= last_captured_timestamp_) { |
| 78 // We don't allow the same capture time for two frames, drop this one. | 84 // We don't allow the same capture time for two frames, drop this one. |
| 79 LOG(LS_WARNING) << "Same/old NTP timestamp (" | 85 LOG(LS_WARNING) << "Same/old NTP timestamp (" |
| 80 << incoming_frame.ntp_time_ms() | 86 << incoming_frame.ntp_time_ms() |
| 81 << " <= " << last_captured_timestamp_ | 87 << " <= " << last_captured_timestamp_ |
| 82 << ") for incoming frame. Dropping."; | 88 << ") for incoming frame. Dropping."; |
| 83 return; | 89 return; |
| 84 } | 90 } |
| 85 | 91 |
| 92 ++captured_frame_count_; | |
| 93 if (captured_frame_.get()) | |
| 94 ++dropped_frame_count_; | |
| 95 | |
| 86 captured_frame_.reset(new VideoFrame); | 96 captured_frame_.reset(new VideoFrame); |
| 87 captured_frame_->ShallowCopy(incoming_frame); | 97 captured_frame_->ShallowCopy(incoming_frame); |
| 88 last_captured_timestamp_ = incoming_frame.ntp_time_ms(); | 98 last_captured_timestamp_ = incoming_frame.ntp_time_ms(); |
| 89 | 99 |
| 90 overuse_detector_->FrameCaptured(*captured_frame_); | 100 overuse_detector_->FrameCaptured(*captured_frame_); |
| 91 | 101 |
| 92 TRACE_EVENT_ASYNC_BEGIN1("webrtc", "Video", video_frame.render_time_ms(), | 102 TRACE_EVENT_ASYNC_BEGIN1("webrtc", "Video", video_frame.render_time_ms(), |
| 93 "render_time", video_frame.render_time_ms()); | 103 "render_time", video_frame.render_time_ms()); |
| 94 | 104 |
| 105 if (current_time - last_frame_log_ms_ > kFrameLogIntervalMs) { | |
| 106 last_frame_log_ms_ = current_time; | |
| 107 LOG(LS_INFO) << "Number of frames: captured " << captured_frame_count_ | |
|
mflodman
2016/09/02 08:46:02
I'd prefer to log the number of frames for the las
mnilsson
2016/09/02 09:21:10
Yes, resetting the count will make it easier to se
åsapersson
2016/09/02 10:19:43
Done.
åsapersson
2016/09/02 10:19:43
Done.
| |
| 108 << ", dropped " << dropped_frame_count_; | |
| 109 } | |
| 110 | |
| 95 capture_event_->Set(); | 111 capture_event_->Set(); |
| 96 } | 112 } |
| 97 | 113 |
| 98 bool VideoCaptureInput::GetVideoFrame(VideoFrame* video_frame) { | 114 bool VideoCaptureInput::GetVideoFrame(VideoFrame* video_frame) { |
| 99 rtc::CritScope lock(&crit_); | 115 rtc::CritScope lock(&crit_); |
| 100 if (!captured_frame_) | 116 if (!captured_frame_) |
| 101 return false; | 117 return false; |
| 102 | 118 |
| 103 *video_frame = *captured_frame_; | 119 *video_frame = *captured_frame_; |
| 104 captured_frame_.reset(); | 120 captured_frame_.reset(); |
| 105 return true; | 121 return true; |
| 106 } | 122 } |
| 107 | 123 |
| 108 } // namespace internal | 124 } // namespace internal |
| 109 } // namespace webrtc | 125 } // namespace webrtc |
| OLD | NEW |