| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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/media/engine/webrtcvideocapturer.h" | 11 #include "webrtc/media/engine/webrtcvideocapturer.h" |
| 12 | 12 |
| 13 #ifdef HAVE_CONFIG_H | 13 #ifdef HAVE_CONFIG_H |
| 14 #include <config.h> | 14 #include <config.h> |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 #ifdef HAVE_WEBRTC_VIDEO | |
| 18 #include "webrtc/base/arraysize.h" | 17 #include "webrtc/base/arraysize.h" |
| 19 #include "webrtc/base/bind.h" | 18 #include "webrtc/base/bind.h" |
| 20 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
| 21 #include "webrtc/base/criticalsection.h" | 20 #include "webrtc/base/criticalsection.h" |
| 22 #include "webrtc/base/logging.h" | 21 #include "webrtc/base/logging.h" |
| 23 #include "webrtc/base/safe_conversions.h" | 22 #include "webrtc/base/safe_conversions.h" |
| 24 #include "webrtc/base/thread.h" | 23 #include "webrtc/base/thread.h" |
| 25 #include "webrtc/base/timeutils.h" | 24 #include "webrtc/base/timeutils.h" |
| 26 #include "webrtc/media/engine/webrtcvideoframe.h" | 25 #include "webrtc/media/engine/webrtcvideoframe.h" |
| 27 #include "webrtc/media/engine/webrtcvideoframefactory.h" | 26 #include "webrtc/media/engine/webrtcvideoframefactory.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 if (!module_) { | 195 if (!module_) { |
| 197 LOG(LS_ERROR) << "Failed to create capturer for id: " << device.id; | 196 LOG(LS_ERROR) << "Failed to create capturer for id: " << device.id; |
| 198 return false; | 197 return false; |
| 199 } | 198 } |
| 200 | 199 |
| 201 // It is safe to change member attributes now. | 200 // It is safe to change member attributes now. |
| 202 module_->AddRef(); | 201 module_->AddRef(); |
| 203 SetId(device.id); | 202 SetId(device.id); |
| 204 SetSupportedFormats(supported); | 203 SetSupportedFormats(supported); |
| 205 | 204 |
| 206 // Ensure these 2 have the same value. | |
| 207 SetApplyRotation(module_->GetApplyRotation()); | |
| 208 | |
| 209 return true; | 205 return true; |
| 210 } | 206 } |
| 211 | 207 |
| 212 bool WebRtcVideoCapturer::Init(webrtc::VideoCaptureModule* module) { | 208 bool WebRtcVideoCapturer::Init(webrtc::VideoCaptureModule* module) { |
| 213 RTC_DCHECK(!start_thread_); | 209 RTC_DCHECK(!start_thread_); |
| 214 if (module_) { | 210 if (module_) { |
| 215 LOG(LS_ERROR) << "The capturer is already initialized"; | 211 LOG(LS_ERROR) << "The capturer is already initialized"; |
| 216 return false; | 212 return false; |
| 217 } | 213 } |
| 218 if (!module) { | 214 if (!module) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 236 best_format->width = desired.width; | 232 best_format->width = desired.width; |
| 237 best_format->height = desired.height; | 233 best_format->height = desired.height; |
| 238 best_format->fourcc = FOURCC_I420; | 234 best_format->fourcc = FOURCC_I420; |
| 239 best_format->interval = desired.interval; | 235 best_format->interval = desired.interval; |
| 240 LOG(LS_INFO) << "Failed to find best capture format," | 236 LOG(LS_INFO) << "Failed to find best capture format," |
| 241 << " fall back to the requested format " | 237 << " fall back to the requested format " |
| 242 << best_format->ToString(); | 238 << best_format->ToString(); |
| 243 } | 239 } |
| 244 return true; | 240 return true; |
| 245 } | 241 } |
| 246 bool WebRtcVideoCapturer::SetApplyRotation(bool enable) { | 242 void WebRtcVideoCapturer::OnSinkWantsChanged(const rtc::VideoSinkWants& wants) { |
| 247 // Can't take lock here as this will cause deadlock with | 243 // Can't take lock here as this will cause deadlock with |
| 248 // OnIncomingCapturedFrame. In fact, the whole method, including methods it | 244 // OnIncomingCapturedFrame. In fact, the whole method, including methods it |
| 249 // calls, can't take lock. | 245 // calls, can't take lock. |
| 250 RTC_DCHECK(module_); | 246 RTC_DCHECK(module_); |
| 251 | 247 |
| 252 const std::string group_name = | 248 const std::string group_name = |
| 253 webrtc::field_trial::FindFullName("WebRTC-CVO"); | 249 webrtc::field_trial::FindFullName("WebRTC-CVO"); |
| 254 | 250 |
| 255 if (group_name == "Disabled") { | 251 if (group_name == "Disabled") { |
| 256 return true; | 252 return; |
| 257 } | 253 } |
| 258 | 254 |
| 259 if (!VideoCapturer::SetApplyRotation(enable)) { | 255 VideoCapturer::OnSinkWantsChanged(wants); |
| 260 return false; | 256 bool result = module_->SetApplyRotation(wants.rotation_applied); |
| 261 } | 257 RTC_CHECK(result); |
| 262 return module_->SetApplyRotation(enable); | 258 |
| 259 return; |
| 263 } | 260 } |
| 264 | 261 |
| 265 CaptureState WebRtcVideoCapturer::Start(const VideoFormat& capture_format) { | 262 CaptureState WebRtcVideoCapturer::Start(const VideoFormat& capture_format) { |
| 266 if (!module_) { | 263 if (!module_) { |
| 267 LOG(LS_ERROR) << "The capturer has not been initialized"; | 264 LOG(LS_ERROR) << "The capturer has not been initialized"; |
| 268 return CS_NO_DEVICE; | 265 return CS_NO_DEVICE; |
| 269 } | 266 } |
| 270 if (start_thread_) { | 267 if (start_thread_) { |
| 271 LOG(LS_ERROR) << "The capturer is already running"; | 268 LOG(LS_ERROR) << "The capturer is already running"; |
| 272 RTC_DCHECK(start_thread_->IsCurrent()) | 269 RTC_DCHECK(start_thread_->IsCurrent()) |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 pixel_width = 1; | 417 pixel_width = 1; |
| 421 pixel_height = 1; | 418 pixel_height = 1; |
| 422 // Convert units from VideoFrame RenderTimeMs to CapturedFrame (nanoseconds). | 419 // Convert units from VideoFrame RenderTimeMs to CapturedFrame (nanoseconds). |
| 423 time_stamp = sample.render_time_ms() * rtc::kNumNanosecsPerMillisec; | 420 time_stamp = sample.render_time_ms() * rtc::kNumNanosecsPerMillisec; |
| 424 data_size = rtc::checked_cast<uint32_t>(length); | 421 data_size = rtc::checked_cast<uint32_t>(length); |
| 425 data = buffer; | 422 data = buffer; |
| 426 rotation = sample.rotation(); | 423 rotation = sample.rotation(); |
| 427 } | 424 } |
| 428 | 425 |
| 429 } // namespace cricket | 426 } // namespace cricket |
| 430 | |
| 431 #endif // HAVE_WEBRTC_VIDEO | |
| OLD | NEW |