niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
mallinath@webrtc.org | 12984f0 | 2012-02-16 18:18:21 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
elham@webrtc.org | 5f49dba | 2012-04-23 21:24:02 +0000 | [diff] [blame] | 11 | #include <stdlib.h> |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 12 | #include <string.h> |
elham@webrtc.org | 5f49dba | 2012-04-23 21:24:02 +0000 | [diff] [blame] | 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "api/video/i420_buffer.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 15 | #include "api/video/video_frame_buffer.h" |
| 16 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "common_video/libyuv/include/webrtc_libyuv.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "modules/video_capture/video_capture_config.h" |
Mirko Bonadei | 6543206 | 2017-12-11 09:32:13 +0100 | [diff] [blame] | 19 | #include "modules/video_capture/video_capture_impl.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "rtc_base/logging.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame^] | 21 | #include "rtc_base/ref_counted_object.h" |
| 22 | #include "rtc_base/time_utils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "rtc_base/trace_event.h" |
Mirko Bonadei | 6543206 | 2017-12-11 09:32:13 +0100 | [diff] [blame] | 24 | #include "third_party/libyuv/include/libyuv.h" |
pbos@webrtc.org | a9b74ad | 2013-07-12 10:03:52 +0000 | [diff] [blame] | 25 | |
Peter Boström | 1d19441 | 2016-03-21 16:44:31 +0100 | [diff] [blame] | 26 | namespace webrtc { |
| 27 | namespace videocapturemodule { |
| 28 | rtc::scoped_refptr<VideoCaptureModule> VideoCaptureImpl::Create( |
Peter Boström | 1d19441 | 2016-03-21 16:44:31 +0100 | [diff] [blame] | 29 | VideoCaptureExternal*& externalCapture) { |
| 30 | rtc::scoped_refptr<VideoCaptureImpl> implementation( |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 31 | new rtc::RefCountedObject<VideoCaptureImpl>()); |
Peter Boström | 1d19441 | 2016-03-21 16:44:31 +0100 | [diff] [blame] | 32 | externalCapture = implementation.get(); |
| 33 | return implementation; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | } |
| 35 | |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 36 | const char* VideoCaptureImpl::CurrentDeviceName() const { |
| 37 | return _deviceUniqueId; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | } |
| 39 | |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 40 | // static |
| 41 | int32_t VideoCaptureImpl::RotationFromDegrees(int degrees, |
guoweis@webrtc.org | 5a7dc39 | 2015-02-13 14:31:26 +0000 | [diff] [blame] | 42 | VideoRotation* rotation) { |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 43 | switch (degrees) { |
| 44 | case 0: |
guoweis@webrtc.org | 5a7dc39 | 2015-02-13 14:31:26 +0000 | [diff] [blame] | 45 | *rotation = kVideoRotation_0; |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 46 | return 0; |
| 47 | case 90: |
guoweis@webrtc.org | 5a7dc39 | 2015-02-13 14:31:26 +0000 | [diff] [blame] | 48 | *rotation = kVideoRotation_90; |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 49 | return 0; |
| 50 | case 180: |
guoweis@webrtc.org | 5a7dc39 | 2015-02-13 14:31:26 +0000 | [diff] [blame] | 51 | *rotation = kVideoRotation_180; |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 52 | return 0; |
| 53 | case 270: |
guoweis@webrtc.org | 5a7dc39 | 2015-02-13 14:31:26 +0000 | [diff] [blame] | 54 | *rotation = kVideoRotation_270; |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 55 | return 0; |
| 56 | default: |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 57 | return -1; |
| 58 | ; |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
| 62 | // static |
guoweis@webrtc.org | 5a7dc39 | 2015-02-13 14:31:26 +0000 | [diff] [blame] | 63 | int32_t VideoCaptureImpl::RotationInDegrees(VideoRotation rotation, |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 64 | int* degrees) { |
| 65 | switch (rotation) { |
guoweis@webrtc.org | 5a7dc39 | 2015-02-13 14:31:26 +0000 | [diff] [blame] | 66 | case kVideoRotation_0: |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 67 | *degrees = 0; |
| 68 | return 0; |
guoweis@webrtc.org | 5a7dc39 | 2015-02-13 14:31:26 +0000 | [diff] [blame] | 69 | case kVideoRotation_90: |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 70 | *degrees = 90; |
| 71 | return 0; |
guoweis@webrtc.org | 5a7dc39 | 2015-02-13 14:31:26 +0000 | [diff] [blame] | 72 | case kVideoRotation_180: |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 73 | *degrees = 180; |
| 74 | return 0; |
guoweis@webrtc.org | 5a7dc39 | 2015-02-13 14:31:26 +0000 | [diff] [blame] | 75 | case kVideoRotation_270: |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 76 | *degrees = 270; |
| 77 | return 0; |
| 78 | } |
| 79 | return -1; |
| 80 | } |
| 81 | |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 82 | VideoCaptureImpl::VideoCaptureImpl() |
| 83 | : _deviceUniqueId(NULL), |
pbos@webrtc.org | 504af45 | 2013-07-02 10:15:43 +0000 | [diff] [blame] | 84 | _requestedCapability(), |
Niels Möller | d28db7f | 2016-05-10 16:31:47 +0200 | [diff] [blame] | 85 | _lastProcessTimeNanos(rtc::TimeNanos()), |
| 86 | _lastFrameRateCallbackTimeNanos(rtc::TimeNanos()), |
pbos@webrtc.org | 504af45 | 2013-07-02 10:15:43 +0000 | [diff] [blame] | 87 | _dataCallBack(NULL), |
Niels Möller | d28db7f | 2016-05-10 16:31:47 +0200 | [diff] [blame] | 88 | _lastProcessFrameTimeNanos(rtc::TimeNanos()), |
guoweis@webrtc.org | 59140d6 | 2015-03-09 17:07:31 +0000 | [diff] [blame] | 89 | _rotateFrame(kVideoRotation_0), |
deadbeef | f5629ad | 2016-03-18 11:38:26 -0700 | [diff] [blame] | 90 | apply_rotation_(false) { |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 91 | _requestedCapability.width = kDefaultWidth; |
| 92 | _requestedCapability.height = kDefaultHeight; |
| 93 | _requestedCapability.maxFPS = 30; |
| 94 | _requestedCapability.videoType = VideoType::kI420; |
| 95 | memset(_incomingFrameTimesNanos, 0, sizeof(_incomingFrameTimesNanos)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 98 | VideoCaptureImpl::~VideoCaptureImpl() { |
| 99 | DeRegisterCaptureDataCallback(); |
| 100 | if (_deviceUniqueId) |
| 101 | delete[] _deviceUniqueId; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | } |
| 103 | |
mallinath@webrtc.org | 7433a08 | 2014-01-29 00:56:02 +0000 | [diff] [blame] | 104 | void VideoCaptureImpl::RegisterCaptureDataCallback( |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 105 | rtc::VideoSinkInterface<VideoFrame>* dataCallBack) { |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 106 | rtc::CritScope cs(&_apiCs); |
| 107 | _dataCallBack = dataCallBack; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 108 | } |
| 109 | |
mallinath@webrtc.org | 7433a08 | 2014-01-29 00:56:02 +0000 | [diff] [blame] | 110 | void VideoCaptureImpl::DeRegisterCaptureDataCallback() { |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 111 | rtc::CritScope cs(&_apiCs); |
| 112 | _dataCallBack = NULL; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 113 | } |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 114 | int32_t VideoCaptureImpl::DeliverCapturedFrame(VideoFrame& captureFrame) { |
mikhal@webrtc.org | 80f14d2 | 2012-10-11 15:03:53 +0000 | [diff] [blame] | 115 | UpdateFrameCount(); // frame count used for local frame rate callback. |
mikhal@webrtc.org | 80f14d2 | 2012-10-11 15:03:53 +0000 | [diff] [blame] | 116 | |
mikhal@webrtc.org | 80f14d2 | 2012-10-11 15:03:53 +0000 | [diff] [blame] | 117 | if (_dataCallBack) { |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 118 | _dataCallBack->OnFrame(captureFrame); |
mikhal@webrtc.org | 80f14d2 | 2012-10-11 15:03:53 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 124 | int32_t VideoCaptureImpl::IncomingFrame(uint8_t* videoFrame, |
| 125 | size_t videoFrameLength, |
| 126 | const VideoCaptureCapability& frameInfo, |
| 127 | int64_t captureTime /*=0*/) { |
| 128 | rtc::CritScope cs(&_apiCs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 130 | const int32_t width = frameInfo.width; |
| 131 | const int32_t height = frameInfo.height; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 132 | |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 133 | TRACE_EVENT1("webrtc", "VC::IncomingFrame", "capture_time", captureTime); |
hclam@chromium.org | 806dc3b | 2013-04-09 19:54:10 +0000 | [diff] [blame] | 134 | |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 135 | // Not encoded, convert to I420. |
| 136 | if (frameInfo.videoType != VideoType::kMJPEG && |
| 137 | CalcBufferSize(frameInfo.videoType, width, abs(height)) != |
| 138 | videoFrameLength) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 139 | RTC_LOG(LS_ERROR) << "Wrong incoming frame length."; |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 140 | return -1; |
| 141 | } |
| 142 | |
| 143 | int stride_y = width; |
| 144 | int stride_uv = (width + 1) / 2; |
| 145 | int target_width = width; |
Robert Bares | 0eb7d3ff | 2018-10-28 00:16:33 +0000 | [diff] [blame] | 146 | int target_height = abs(height); |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 147 | |
| 148 | // SetApplyRotation doesn't take any lock. Make a local copy here. |
| 149 | bool apply_rotation = apply_rotation_; |
| 150 | |
| 151 | if (apply_rotation) { |
| 152 | // Rotating resolution when for 90/270 degree rotations. |
| 153 | if (_rotateFrame == kVideoRotation_90 || |
| 154 | _rotateFrame == kVideoRotation_270) { |
| 155 | target_width = abs(height); |
| 156 | target_height = width; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 157 | } |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 158 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 159 | |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 160 | // Setting absolute height (in case it was negative). |
| 161 | // In Windows, the image starts bottom left, instead of top left. |
| 162 | // Setting a negative source height, inverts the image (within LibYuv). |
nisse | 1e32122 | 2017-02-20 23:27:37 -0800 | [diff] [blame] | 163 | |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 164 | // TODO(nisse): Use a pool? |
| 165 | rtc::scoped_refptr<I420Buffer> buffer = I420Buffer::Create( |
Robert Bares | 0eb7d3ff | 2018-10-28 00:16:33 +0000 | [diff] [blame] | 166 | target_width, target_height, stride_y, stride_uv, stride_uv); |
mallikarjun82 | 12e555b | 2017-11-15 14:35:56 +0530 | [diff] [blame] | 167 | |
| 168 | libyuv::RotationMode rotation_mode = libyuv::kRotate0; |
| 169 | if (apply_rotation) { |
| 170 | switch (_rotateFrame) { |
| 171 | case kVideoRotation_0: |
| 172 | rotation_mode = libyuv::kRotate0; |
| 173 | break; |
| 174 | case kVideoRotation_90: |
| 175 | rotation_mode = libyuv::kRotate90; |
| 176 | break; |
| 177 | case kVideoRotation_180: |
| 178 | rotation_mode = libyuv::kRotate180; |
| 179 | break; |
| 180 | case kVideoRotation_270: |
| 181 | rotation_mode = libyuv::kRotate270; |
| 182 | break; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | const int conversionResult = libyuv::ConvertToI420( |
| 187 | videoFrame, videoFrameLength, buffer.get()->MutableDataY(), |
| 188 | buffer.get()->StrideY(), buffer.get()->MutableDataU(), |
| 189 | buffer.get()->StrideU(), buffer.get()->MutableDataV(), |
| 190 | buffer.get()->StrideV(), 0, 0, // No Cropping |
| 191 | width, height, target_width, target_height, rotation_mode, |
| 192 | ConvertVideoType(frameInfo.videoType)); |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 193 | if (conversionResult < 0) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 194 | RTC_LOG(LS_ERROR) << "Failed to convert capture frame from type " |
| 195 | << static_cast<int>(frameInfo.videoType) << "to I420."; |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 196 | return -1; |
| 197 | } |
nisse | 1e32122 | 2017-02-20 23:27:37 -0800 | [diff] [blame] | 198 | |
Artem Titov | 1ebfb6a | 2019-01-03 23:49:37 +0100 | [diff] [blame] | 199 | VideoFrame captureFrame = |
| 200 | VideoFrame::Builder() |
| 201 | .set_video_frame_buffer(buffer) |
| 202 | .set_timestamp_rtp(0) |
| 203 | .set_timestamp_ms(rtc::TimeMillis()) |
| 204 | .set_rotation(!apply_rotation ? _rotateFrame : kVideoRotation_0) |
| 205 | .build(); |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 206 | captureFrame.set_ntp_time_ms(captureTime); |
nisse | 1e32122 | 2017-02-20 23:27:37 -0800 | [diff] [blame] | 207 | |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 208 | DeliverCapturedFrame(captureFrame); |
nisse | 1e32122 | 2017-02-20 23:27:37 -0800 | [diff] [blame] | 209 | |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 210 | return 0; |
wu@webrtc.org | f10ea31 | 2011-10-14 17:16:04 +0000 | [diff] [blame] | 211 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 212 | |
Mirko Bonadei | 5aec1f6 | 2018-08-29 13:27:15 +0200 | [diff] [blame] | 213 | int32_t VideoCaptureImpl::StartCapture( |
| 214 | const VideoCaptureCapability& capability) { |
| 215 | _requestedCapability = capability; |
| 216 | return -1; |
| 217 | } |
| 218 | |
| 219 | int32_t VideoCaptureImpl::StopCapture() { |
| 220 | return -1; |
| 221 | } |
| 222 | |
| 223 | bool VideoCaptureImpl::CaptureStarted() { |
| 224 | return false; |
| 225 | } |
| 226 | |
| 227 | int32_t VideoCaptureImpl::CaptureSettings( |
| 228 | VideoCaptureCapability& /*settings*/) { |
| 229 | return -1; |
| 230 | } |
| 231 | |
guoweis@webrtc.org | 5a7dc39 | 2015-02-13 14:31:26 +0000 | [diff] [blame] | 232 | int32_t VideoCaptureImpl::SetCaptureRotation(VideoRotation rotation) { |
kthelgason | ff046c7 | 2017-03-31 02:03:55 -0700 | [diff] [blame] | 233 | rtc::CritScope cs(&_apiCs); |
guoweis@webrtc.org | 59140d6 | 2015-03-09 17:07:31 +0000 | [diff] [blame] | 234 | _rotateFrame = rotation; |
mikhal@webrtc.org | 0f34fd7 | 2012-11-19 21:15:35 +0000 | [diff] [blame] | 235 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 236 | } |
| 237 | |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 238 | bool VideoCaptureImpl::SetApplyRotation(bool enable) { |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 239 | // We can't take any lock here as it'll cause deadlock with IncomingFrame. |
| 240 | |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 241 | // The effect of this is the last caller wins. |
| 242 | apply_rotation_ = enable; |
| 243 | return true; |
| 244 | } |
| 245 | |
Mirko Bonadei | 5aec1f6 | 2018-08-29 13:27:15 +0200 | [diff] [blame] | 246 | bool VideoCaptureImpl::GetApplyRotation() { |
| 247 | return apply_rotation_; |
| 248 | } |
| 249 | |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 250 | void VideoCaptureImpl::UpdateFrameCount() { |
| 251 | if (_incomingFrameTimesNanos[0] / rtc::kNumNanosecsPerMicrosec == 0) { |
| 252 | // first no shift |
| 253 | } else { |
| 254 | // shift |
| 255 | for (int i = (kFrameRateCountHistorySize - 2); i >= 0; --i) { |
| 256 | _incomingFrameTimesNanos[i + 1] = _incomingFrameTimesNanos[i]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 257 | } |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 258 | } |
| 259 | _incomingFrameTimesNanos[0] = rtc::TimeNanos(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 260 | } |
| 261 | |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 262 | uint32_t VideoCaptureImpl::CalculateFrameRate(int64_t now_ns) { |
| 263 | int32_t num = 0; |
| 264 | int32_t nrOfFrames = 0; |
| 265 | for (num = 1; num < (kFrameRateCountHistorySize - 1); ++num) { |
| 266 | if (_incomingFrameTimesNanos[num] <= 0 || |
| 267 | (now_ns - _incomingFrameTimesNanos[num]) / |
| 268 | rtc::kNumNanosecsPerMillisec > |
| 269 | kFrameRateHistoryWindowMs) { // don't use data older than 2sec |
| 270 | break; |
| 271 | } else { |
| 272 | nrOfFrames++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 273 | } |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 274 | } |
| 275 | if (num > 1) { |
| 276 | int64_t diff = (now_ns - _incomingFrameTimesNanos[num - 1]) / |
| 277 | rtc::kNumNanosecsPerMillisec; |
| 278 | if (diff > 0) { |
| 279 | return uint32_t((nrOfFrames * 1000.0f / diff) + 0.5f); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 280 | } |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 281 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 282 | |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 283 | return nrOfFrames; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 284 | } |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 285 | } // namespace videocapturemodule |
| 286 | } // namespace webrtc |