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/logging.h" | |
24 | 23 |
25 namespace webrtc { | 24 namespace webrtc { |
26 namespace videocapturemodule { | 25 namespace videocapturemodule { |
27 rtc::scoped_refptr<VideoCaptureModule> VideoCaptureImpl::Create( | 26 rtc::scoped_refptr<VideoCaptureModule> VideoCaptureImpl::Create( |
28 VideoCaptureExternal*& externalCapture) { | 27 VideoCaptureExternal*& externalCapture) { |
29 rtc::scoped_refptr<VideoCaptureImpl> implementation( | 28 rtc::scoped_refptr<VideoCaptureImpl> implementation( |
30 new rtc::RefCountedObject<VideoCaptureImpl>()); | 29 new rtc::RefCountedObject<VideoCaptureImpl>()); |
31 externalCapture = implementation.get(); | 30 externalCapture = implementation.get(); |
32 return implementation; | 31 return implementation; |
33 } | 32 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 TRACE_EVENT1("webrtc", "VC::IncomingFrame", "capture_time", captureTime); | 134 TRACE_EVENT1("webrtc", "VC::IncomingFrame", "capture_time", captureTime); |
136 | 135 |
137 // Not encoded, convert to I420. | 136 // Not encoded, convert to I420. |
138 const VideoType commonVideoType = | 137 const VideoType commonVideoType = |
139 RawVideoTypeToCommonVideoVideoType(frameInfo.rawType); | 138 RawVideoTypeToCommonVideoVideoType(frameInfo.rawType); |
140 | 139 |
141 if (frameInfo.rawType != kVideoMJPEG && | 140 if (frameInfo.rawType != kVideoMJPEG && |
142 CalcBufferSize(commonVideoType, width, | 141 CalcBufferSize(commonVideoType, width, |
143 abs(height)) != videoFrameLength) | 142 abs(height)) != videoFrameLength) |
144 { | 143 { |
145 LOG(LS_ERROR) << "Wrong incoming frame length."; | |
146 return -1; | 144 return -1; |
147 } | 145 } |
148 | 146 |
149 int stride_y = width; | 147 int stride_y = width; |
150 int stride_uv = (width + 1) / 2; | 148 int stride_uv = (width + 1) / 2; |
151 int target_width = width; | 149 int target_width = width; |
152 int target_height = height; | 150 int target_height = height; |
153 | 151 |
154 // SetApplyRotation doesn't take any lock. Make a local copy here. | 152 // SetApplyRotation doesn't take any lock. Make a local copy here. |
155 bool apply_rotation = apply_rotation_; | 153 bool apply_rotation = apply_rotation_; |
(...skipping 13 matching lines...) Expand all Loading... |
169 | 167 |
170 // TODO(nisse): Use a pool? | 168 // TODO(nisse): Use a pool? |
171 rtc::scoped_refptr<I420Buffer> buffer = I420Buffer::Create( | 169 rtc::scoped_refptr<I420Buffer> buffer = I420Buffer::Create( |
172 target_width, abs(target_height), stride_y, stride_uv, stride_uv); | 170 target_width, abs(target_height), stride_y, stride_uv, stride_uv); |
173 const int conversionResult = ConvertToI420( | 171 const int conversionResult = ConvertToI420( |
174 commonVideoType, videoFrame, 0, 0, // No cropping | 172 commonVideoType, videoFrame, 0, 0, // No cropping |
175 width, height, videoFrameLength, | 173 width, height, videoFrameLength, |
176 apply_rotation ? _rotateFrame : kVideoRotation_0, buffer.get()); | 174 apply_rotation ? _rotateFrame : kVideoRotation_0, buffer.get()); |
177 if (conversionResult < 0) | 175 if (conversionResult < 0) |
178 { | 176 { |
179 LOG(LS_ERROR) << "Failed to convert capture frame from type " | |
180 << frameInfo.rawType << "to I420."; | |
181 return -1; | 177 return -1; |
182 } | 178 } |
183 | 179 |
184 VideoFrame captureFrame( | 180 VideoFrame captureFrame( |
185 buffer, 0, rtc::TimeMillis(), | 181 buffer, 0, rtc::TimeMillis(), |
186 !apply_rotation ? _rotateFrame : kVideoRotation_0); | 182 !apply_rotation ? _rotateFrame : kVideoRotation_0); |
187 captureFrame.set_ntp_time_ms(captureTime); | 183 captureFrame.set_ntp_time_ms(captureTime); |
188 | 184 |
189 DeliverCapturedFrame(captureFrame); | 185 DeliverCapturedFrame(captureFrame); |
190 | 186 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 if (diff > 0) | 243 if (diff > 0) |
248 { | 244 { |
249 return uint32_t((nrOfFrames * 1000.0f / diff) + 0.5f); | 245 return uint32_t((nrOfFrames * 1000.0f / diff) + 0.5f); |
250 } | 246 } |
251 } | 247 } |
252 | 248 |
253 return nrOfFrames; | 249 return nrOfFrames; |
254 } | 250 } |
255 } // namespace videocapturemodule | 251 } // namespace videocapturemodule |
256 } // namespace webrtc | 252 } // namespace webrtc |
OLD | NEW |