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

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

Issue 1693443002: VideoCaptureInput enforce VideoFrame::render_time to be generated by webrtc clock. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 months 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/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" 20 #include "webrtc/system_wrappers/include/tick_util.h"
22 #include "webrtc/video/overuse_frame_detector.h" 21 #include "webrtc/video/overuse_frame_detector.h"
23 #include "webrtc/video/send_statistics_proxy.h" 22 #include "webrtc/video/send_statistics_proxy.h"
24 #include "webrtc/video/vie_encoder.h" 23 #include "webrtc/video/vie_encoder.h"
25 24
26 namespace webrtc { 25 namespace webrtc {
27 26
28 namespace internal { 27 namespace internal {
29 VideoCaptureInput::VideoCaptureInput(VideoCaptureCallback* frame_callback, 28 VideoCaptureInput::VideoCaptureInput(VideoCaptureCallback* frame_callback,
30 VideoRenderer* local_renderer, 29 VideoRenderer* local_renderer,
31 SendStatisticsProxy* stats_proxy, 30 SendStatisticsProxy* stats_proxy,
32 OveruseFrameDetector* overuse_detector) 31 OveruseFrameDetector* overuse_detector)
33 : frame_callback_(frame_callback), 32 : frame_callback_(frame_callback),
34 local_renderer_(local_renderer), 33 local_renderer_(local_renderer),
35 stats_proxy_(stats_proxy), 34 stats_proxy_(stats_proxy),
36 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"), 35 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"),
37 capture_event_(false, false), 36 capture_event_(false, false),
38 stop_(0), 37 stop_(0),
38 // TODO(danilchap): pass clock from outside to ensure it is same clock
39 // used for audio frame timestamping.
stefan-webrtc 2016/02/11 16:08:47 Audio frames aren't timestamped using the clock, b
danilchap 2016/02/11 17:18:54 I skipped several steps in reasoning why this cloc
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 TickTime::MillisecondTimestamp()),
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.
stefan-webrtc 2016/02/11 16:08:46 It's not clear to me if anything below actually ha
danilchap 2016/02/11 17:18:54 render_time is always taken from clock_ instead of
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);
stefan-webrtc 2016/02/11 16:08:46 Have you figured out what the render time is used
danilchap 2016/02/11 17:18:54 render_time (later named capture_time) is used by
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);
stefan-webrtc 2016/02/11 16:08:46 We should probably comment here that the ntp time
danilchap 2016/02/11 17:18:54 there is such comment 2 lines below.
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
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
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