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/modules/video_capture/video_capture_impl.h" | 11 #include "webrtc/modules/video_capture/video_capture_impl.h" |
12 | 12 |
13 #include <stdlib.h> | 13 #include <stdlib.h> |
14 | 14 |
15 #include "webrtc/api/video/i420_buffer.h" | 15 #include "webrtc/api/video/i420_buffer.h" |
16 #include "webrtc/base/refcount.h" | 16 #include "webrtc/base/refcount.h" |
17 #include "webrtc/base/timeutils.h" | 17 #include "webrtc/base/timeutils.h" |
18 #include "webrtc/base/trace_event.h" | 18 #include "webrtc/base/trace_event.h" |
19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
20 #include "webrtc/modules/include/module_common_types.h" | 20 #include "webrtc/modules/include/module_common_types.h" |
21 #include "webrtc/modules/video_capture/video_capture_config.h" | 21 #include "webrtc/modules/video_capture/video_capture_config.h" |
22 #include "webrtc/system_wrappers/include/clock.h" | 22 #include "webrtc/system_wrappers/include/clock.h" |
23 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | |
24 #include "webrtc/system_wrappers/include/logging.h" | 23 #include "webrtc/system_wrappers/include/logging.h" |
25 | 24 |
26 namespace webrtc { | 25 namespace webrtc { |
27 namespace videocapturemodule { | 26 namespace videocapturemodule { |
28 rtc::scoped_refptr<VideoCaptureModule> VideoCaptureImpl::Create( | 27 rtc::scoped_refptr<VideoCaptureModule> VideoCaptureImpl::Create( |
29 VideoCaptureExternal*& externalCapture) { | 28 VideoCaptureExternal*& externalCapture) { |
30 rtc::scoped_refptr<VideoCaptureImpl> implementation( | 29 rtc::scoped_refptr<VideoCaptureImpl> implementation( |
31 new rtc::RefCountedObject<VideoCaptureImpl>()); | 30 new rtc::RefCountedObject<VideoCaptureImpl>()); |
32 externalCapture = implementation.get(); | 31 externalCapture = implementation.get(); |
33 return implementation; | 32 return implementation; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 return 0; | 73 return 0; |
75 case kVideoRotation_270: | 74 case kVideoRotation_270: |
76 *degrees = 270; | 75 *degrees = 270; |
77 return 0; | 76 return 0; |
78 } | 77 } |
79 return -1; | 78 return -1; |
80 } | 79 } |
81 | 80 |
82 VideoCaptureImpl::VideoCaptureImpl() | 81 VideoCaptureImpl::VideoCaptureImpl() |
83 : _deviceUniqueId(NULL), | 82 : _deviceUniqueId(NULL), |
84 _apiCs(*CriticalSectionWrapper::CreateCriticalSection()), | |
85 _requestedCapability(), | 83 _requestedCapability(), |
86 _lastProcessTimeNanos(rtc::TimeNanos()), | 84 _lastProcessTimeNanos(rtc::TimeNanos()), |
87 _lastFrameRateCallbackTimeNanos(rtc::TimeNanos()), | 85 _lastFrameRateCallbackTimeNanos(rtc::TimeNanos()), |
88 _dataCallBack(NULL), | 86 _dataCallBack(NULL), |
89 _lastProcessFrameTimeNanos(rtc::TimeNanos()), | 87 _lastProcessFrameTimeNanos(rtc::TimeNanos()), |
90 _rotateFrame(kVideoRotation_0), | 88 _rotateFrame(kVideoRotation_0), |
91 apply_rotation_(false) { | 89 apply_rotation_(false) { |
92 _requestedCapability.width = kDefaultWidth; | 90 _requestedCapability.width = kDefaultWidth; |
93 _requestedCapability.height = kDefaultHeight; | 91 _requestedCapability.height = kDefaultHeight; |
94 _requestedCapability.maxFPS = 30; | 92 _requestedCapability.maxFPS = 30; |
95 _requestedCapability.rawType = kVideoI420; | 93 _requestedCapability.rawType = kVideoI420; |
96 memset(_incomingFrameTimesNanos, 0, sizeof(_incomingFrameTimesNanos)); | 94 memset(_incomingFrameTimesNanos, 0, sizeof(_incomingFrameTimesNanos)); |
97 } | 95 } |
98 | 96 |
99 VideoCaptureImpl::~VideoCaptureImpl() | 97 VideoCaptureImpl::~VideoCaptureImpl() |
100 { | 98 { |
101 DeRegisterCaptureDataCallback(); | 99 DeRegisterCaptureDataCallback(); |
102 delete &_apiCs; | |
103 | |
104 if (_deviceUniqueId) | 100 if (_deviceUniqueId) |
105 delete[] _deviceUniqueId; | 101 delete[] _deviceUniqueId; |
106 } | 102 } |
107 | 103 |
108 void VideoCaptureImpl::RegisterCaptureDataCallback( | 104 void VideoCaptureImpl::RegisterCaptureDataCallback( |
109 rtc::VideoSinkInterface<VideoFrame>* dataCallBack) { | 105 rtc::VideoSinkInterface<VideoFrame>* dataCallBack) { |
110 CriticalSectionScoped cs(&_apiCs); | 106 rtc::CritScope cs(&_apiCs); |
111 _dataCallBack = dataCallBack; | 107 _dataCallBack = dataCallBack; |
112 } | 108 } |
113 | 109 |
114 void VideoCaptureImpl::DeRegisterCaptureDataCallback() { | 110 void VideoCaptureImpl::DeRegisterCaptureDataCallback() { |
115 CriticalSectionScoped cs(&_apiCs); | 111 rtc::CritScope cs(&_apiCs); |
116 _dataCallBack = NULL; | 112 _dataCallBack = NULL; |
117 } | 113 } |
118 int32_t VideoCaptureImpl::DeliverCapturedFrame(VideoFrame& captureFrame) { | 114 int32_t VideoCaptureImpl::DeliverCapturedFrame(VideoFrame& captureFrame) { |
119 UpdateFrameCount(); // frame count used for local frame rate callback. | 115 UpdateFrameCount(); // frame count used for local frame rate callback. |
120 | 116 |
121 if (_dataCallBack) { | 117 if (_dataCallBack) { |
122 _dataCallBack->OnFrame(captureFrame); | 118 _dataCallBack->OnFrame(captureFrame); |
123 } | 119 } |
124 | 120 |
125 return 0; | 121 return 0; |
126 } | 122 } |
127 | 123 |
128 int32_t VideoCaptureImpl::IncomingFrame( | 124 int32_t VideoCaptureImpl::IncomingFrame( |
129 uint8_t* videoFrame, | 125 uint8_t* videoFrame, |
130 size_t videoFrameLength, | 126 size_t videoFrameLength, |
131 const VideoCaptureCapability& frameInfo, | 127 const VideoCaptureCapability& frameInfo, |
132 int64_t captureTime/*=0*/) | 128 int64_t captureTime/*=0*/) |
133 { | 129 { |
134 CriticalSectionScoped cs(&_apiCs); | 130 rtc::CritScope cs(&_apiCs); |
135 | 131 |
136 const int32_t width = frameInfo.width; | 132 const int32_t width = frameInfo.width; |
137 const int32_t height = frameInfo.height; | 133 const int32_t height = frameInfo.height; |
138 | 134 |
139 TRACE_EVENT1("webrtc", "VC::IncomingFrame", "capture_time", captureTime); | 135 TRACE_EVENT1("webrtc", "VC::IncomingFrame", "capture_time", captureTime); |
140 | 136 |
141 // Not encoded, convert to I420. | 137 // Not encoded, convert to I420. |
142 const VideoType commonVideoType = | 138 const VideoType commonVideoType = |
143 RawVideoTypeToCommonVideoVideoType(frameInfo.rawType); | 139 RawVideoTypeToCommonVideoVideoType(frameInfo.rawType); |
144 | 140 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 buffer, 0, rtc::TimeMillis(), | 185 buffer, 0, rtc::TimeMillis(), |
190 !apply_rotation ? _rotateFrame : kVideoRotation_0); | 186 !apply_rotation ? _rotateFrame : kVideoRotation_0); |
191 captureFrame.set_ntp_time_ms(captureTime); | 187 captureFrame.set_ntp_time_ms(captureTime); |
192 | 188 |
193 DeliverCapturedFrame(captureFrame); | 189 DeliverCapturedFrame(captureFrame); |
194 | 190 |
195 return 0; | 191 return 0; |
196 } | 192 } |
197 | 193 |
198 int32_t VideoCaptureImpl::SetCaptureRotation(VideoRotation rotation) { | 194 int32_t VideoCaptureImpl::SetCaptureRotation(VideoRotation rotation) { |
199 CriticalSectionScoped cs(&_apiCs); | 195 rtc::CritScope cs(&_apiCs); |
200 _rotateFrame = rotation; | 196 _rotateFrame = rotation; |
201 return 0; | 197 return 0; |
202 } | 198 } |
203 | 199 |
204 bool VideoCaptureImpl::SetApplyRotation(bool enable) { | 200 bool VideoCaptureImpl::SetApplyRotation(bool enable) { |
205 // We can't take any lock here as it'll cause deadlock with IncomingFrame. | 201 // We can't take any lock here as it'll cause deadlock with IncomingFrame. |
206 | 202 |
207 // The effect of this is the last caller wins. | 203 // The effect of this is the last caller wins. |
208 apply_rotation_ = enable; | 204 apply_rotation_ = enable; |
209 return true; | 205 return true; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 if (diff > 0) | 247 if (diff > 0) |
252 { | 248 { |
253 return uint32_t((nrOfFrames * 1000.0f / diff) + 0.5f); | 249 return uint32_t((nrOfFrames * 1000.0f / diff) + 0.5f); |
254 } | 250 } |
255 } | 251 } |
256 | 252 |
257 return nrOfFrames; | 253 return nrOfFrames; |
258 } | 254 } |
259 } // namespace videocapturemodule | 255 } // namespace videocapturemodule |
260 } // namespace webrtc | 256 } // namespace webrtc |
OLD | NEW |