| 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 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 _lastProcessTimeNanos(rtc::TimeNanos()), | 86 _lastProcessTimeNanos(rtc::TimeNanos()), |
| 87 _lastFrameRateCallbackTimeNanos(rtc::TimeNanos()), | 87 _lastFrameRateCallbackTimeNanos(rtc::TimeNanos()), |
| 88 _dataCallBack(NULL), | 88 _dataCallBack(NULL), |
| 89 _lastProcessFrameTimeNanos(rtc::TimeNanos()), | 89 _lastProcessFrameTimeNanos(rtc::TimeNanos()), |
| 90 _rotateFrame(kVideoRotation_0), | 90 _rotateFrame(kVideoRotation_0), |
| 91 apply_rotation_(false) { | 91 apply_rotation_(false) { |
| 92 _requestedCapability.width = kDefaultWidth; | 92 _requestedCapability.width = kDefaultWidth; |
| 93 _requestedCapability.height = kDefaultHeight; | 93 _requestedCapability.height = kDefaultHeight; |
| 94 _requestedCapability.maxFPS = 30; | 94 _requestedCapability.maxFPS = 30; |
| 95 _requestedCapability.rawType = kVideoI420; | 95 _requestedCapability.rawType = kVideoI420; |
| 96 _requestedCapability.codecType = kVideoCodecUnknown; | |
| 97 memset(_incomingFrameTimesNanos, 0, sizeof(_incomingFrameTimesNanos)); | 96 memset(_incomingFrameTimesNanos, 0, sizeof(_incomingFrameTimesNanos)); |
| 98 } | 97 } |
| 99 | 98 |
| 100 VideoCaptureImpl::~VideoCaptureImpl() | 99 VideoCaptureImpl::~VideoCaptureImpl() |
| 101 { | 100 { |
| 102 DeRegisterCaptureDataCallback(); | 101 DeRegisterCaptureDataCallback(); |
| 103 delete &_apiCs; | 102 delete &_apiCs; |
| 104 | 103 |
| 105 if (_deviceUniqueId) | 104 if (_deviceUniqueId) |
| 106 delete[] _deviceUniqueId; | 105 delete[] _deviceUniqueId; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 132 const VideoCaptureCapability& frameInfo, | 131 const VideoCaptureCapability& frameInfo, |
| 133 int64_t captureTime/*=0*/) | 132 int64_t captureTime/*=0*/) |
| 134 { | 133 { |
| 135 CriticalSectionScoped cs(&_apiCs); | 134 CriticalSectionScoped cs(&_apiCs); |
| 136 | 135 |
| 137 const int32_t width = frameInfo.width; | 136 const int32_t width = frameInfo.width; |
| 138 const int32_t height = frameInfo.height; | 137 const int32_t height = frameInfo.height; |
| 139 | 138 |
| 140 TRACE_EVENT1("webrtc", "VC::IncomingFrame", "capture_time", captureTime); | 139 TRACE_EVENT1("webrtc", "VC::IncomingFrame", "capture_time", captureTime); |
| 141 | 140 |
| 142 if (frameInfo.codecType == kVideoCodecUnknown) | 141 // Not encoded, convert to I420. |
| 142 const VideoType commonVideoType = |
| 143 RawVideoTypeToCommonVideoVideoType(frameInfo.rawType); |
| 144 |
| 145 if (frameInfo.rawType != kVideoMJPEG && |
| 146 CalcBufferSize(commonVideoType, width, |
| 147 abs(height)) != videoFrameLength) |
| 143 { | 148 { |
| 144 // Not encoded, convert to I420. | 149 LOG(LS_ERROR) << "Wrong incoming frame length."; |
| 145 const VideoType commonVideoType = | |
| 146 RawVideoTypeToCommonVideoVideoType(frameInfo.rawType); | |
| 147 | |
| 148 if (frameInfo.rawType != kVideoMJPEG && | |
| 149 CalcBufferSize(commonVideoType, width, | |
| 150 abs(height)) != videoFrameLength) | |
| 151 { | |
| 152 LOG(LS_ERROR) << "Wrong incoming frame length."; | |
| 153 return -1; | |
| 154 } | |
| 155 | |
| 156 int stride_y = width; | |
| 157 int stride_uv = (width + 1) / 2; | |
| 158 int target_width = width; | |
| 159 int target_height = height; | |
| 160 | |
| 161 // SetApplyRotation doesn't take any lock. Make a local copy here. | |
| 162 bool apply_rotation = apply_rotation_; | |
| 163 | |
| 164 if (apply_rotation) { | |
| 165 // Rotating resolution when for 90/270 degree rotations. | |
| 166 if (_rotateFrame == kVideoRotation_90 || | |
| 167 _rotateFrame == kVideoRotation_270) { | |
| 168 target_width = abs(height); | |
| 169 target_height = width; | |
| 170 } | |
| 171 } | |
| 172 | |
| 173 // Setting absolute height (in case it was negative). | |
| 174 // In Windows, the image starts bottom left, instead of top left. | |
| 175 // Setting a negative source height, inverts the image (within LibYuv). | |
| 176 | |
| 177 // TODO(nisse): Use a pool? | |
| 178 rtc::scoped_refptr<I420Buffer> buffer = I420Buffer::Create( | |
| 179 target_width, abs(target_height), stride_y, stride_uv, stride_uv); | |
| 180 const int conversionResult = ConvertToI420( | |
| 181 commonVideoType, videoFrame, 0, 0, // No cropping | |
| 182 width, height, videoFrameLength, | |
| 183 apply_rotation ? _rotateFrame : kVideoRotation_0, buffer.get()); | |
| 184 if (conversionResult < 0) | |
| 185 { | |
| 186 LOG(LS_ERROR) << "Failed to convert capture frame from type " | |
| 187 << frameInfo.rawType << "to I420."; | |
| 188 return -1; | |
| 189 } | |
| 190 | |
| 191 VideoFrame captureFrame( | |
| 192 buffer, 0, rtc::TimeMillis(), | |
| 193 !apply_rotation ? _rotateFrame : kVideoRotation_0); | |
| 194 captureFrame.set_ntp_time_ms(captureTime); | |
| 195 | |
| 196 DeliverCapturedFrame(captureFrame); | |
| 197 } | |
| 198 else // Encoded format | |
| 199 { | |
| 200 assert(false); | |
| 201 return -1; | 150 return -1; |
| 202 } | 151 } |
| 203 | 152 |
| 153 int stride_y = width; |
| 154 int stride_uv = (width + 1) / 2; |
| 155 int target_width = width; |
| 156 int target_height = height; |
| 157 |
| 158 // SetApplyRotation doesn't take any lock. Make a local copy here. |
| 159 bool apply_rotation = apply_rotation_; |
| 160 |
| 161 if (apply_rotation) { |
| 162 // Rotating resolution when for 90/270 degree rotations. |
| 163 if (_rotateFrame == kVideoRotation_90 || |
| 164 _rotateFrame == kVideoRotation_270) { |
| 165 target_width = abs(height); |
| 166 target_height = width; |
| 167 } |
| 168 } |
| 169 |
| 170 // Setting absolute height (in case it was negative). |
| 171 // In Windows, the image starts bottom left, instead of top left. |
| 172 // Setting a negative source height, inverts the image (within LibYuv). |
| 173 |
| 174 // TODO(nisse): Use a pool? |
| 175 rtc::scoped_refptr<I420Buffer> buffer = I420Buffer::Create( |
| 176 target_width, abs(target_height), stride_y, stride_uv, stride_uv); |
| 177 const int conversionResult = ConvertToI420( |
| 178 commonVideoType, videoFrame, 0, 0, // No cropping |
| 179 width, height, videoFrameLength, |
| 180 apply_rotation ? _rotateFrame : kVideoRotation_0, buffer.get()); |
| 181 if (conversionResult < 0) |
| 182 { |
| 183 LOG(LS_ERROR) << "Failed to convert capture frame from type " |
| 184 << frameInfo.rawType << "to I420."; |
| 185 return -1; |
| 186 } |
| 187 |
| 188 VideoFrame captureFrame( |
| 189 buffer, 0, rtc::TimeMillis(), |
| 190 !apply_rotation ? _rotateFrame : kVideoRotation_0); |
| 191 captureFrame.set_ntp_time_ms(captureTime); |
| 192 |
| 193 DeliverCapturedFrame(captureFrame); |
| 194 |
| 204 return 0; | 195 return 0; |
| 205 } | 196 } |
| 206 | 197 |
| 207 int32_t VideoCaptureImpl::SetCaptureRotation(VideoRotation rotation) { | 198 int32_t VideoCaptureImpl::SetCaptureRotation(VideoRotation rotation) { |
| 208 CriticalSectionScoped cs(&_apiCs); | 199 CriticalSectionScoped cs(&_apiCs); |
| 209 _rotateFrame = rotation; | 200 _rotateFrame = rotation; |
| 210 return 0; | 201 return 0; |
| 211 } | 202 } |
| 212 | 203 |
| 213 bool VideoCaptureImpl::SetApplyRotation(bool enable) { | 204 bool VideoCaptureImpl::SetApplyRotation(bool enable) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 if (diff > 0) | 251 if (diff > 0) |
| 261 { | 252 { |
| 262 return uint32_t((nrOfFrames * 1000.0f / diff) + 0.5f); | 253 return uint32_t((nrOfFrames * 1000.0f / diff) + 0.5f); |
| 263 } | 254 } |
| 264 } | 255 } |
| 265 | 256 |
| 266 return nrOfFrames; | 257 return nrOfFrames; |
| 267 } | 258 } |
| 268 } // namespace videocapturemodule | 259 } // namespace videocapturemodule |
| 269 } // namespace webrtc | 260 } // namespace webrtc |
| OLD | NEW |