Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 #if !defined(__has_feature) || !__has_feature(objc_arc) | 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 12 #error "This file requires ARC support." | 12 #error "This file requires ARC support." |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 #include "webrtc/base/refcount.h" | |
| 16 #include "webrtc/base/scoped_ref_ptr.h" | |
| 15 #include "webrtc/modules/video_capture/ios/device_info_ios_objc.h" | 17 #include "webrtc/modules/video_capture/ios/device_info_ios_objc.h" |
| 16 #include "webrtc/modules/video_capture/ios/rtc_video_capture_ios_objc.h" | 18 #include "webrtc/modules/video_capture/ios/rtc_video_capture_ios_objc.h" |
| 17 #include "webrtc/system_wrappers/include/ref_count.h" | |
| 18 #include "webrtc/system_wrappers/include/trace.h" | 19 #include "webrtc/system_wrappers/include/trace.h" |
| 19 | 20 |
| 20 using namespace webrtc; | 21 using namespace webrtc; |
| 21 using namespace videocapturemodule; | 22 using namespace videocapturemodule; |
| 22 | 23 |
| 23 VideoCaptureModule* VideoCaptureImpl::Create(const int32_t capture_id, | 24 rtc::scoped_refptr<VideoCaptureModule> VideoCaptureImpl::Create( |
| 24 const char* deviceUniqueIdUTF8) { | 25 const int32_t capture_id, |
| 26 const char* deviceUniqueIdUTF8) { | |
| 25 return VideoCaptureIos::Create(capture_id, deviceUniqueIdUTF8); | 27 return VideoCaptureIos::Create(capture_id, deviceUniqueIdUTF8); |
| 26 } | 28 } |
| 27 | 29 |
| 28 VideoCaptureIos::VideoCaptureIos(const int32_t capture_id) | 30 VideoCaptureIos::VideoCaptureIos(const int32_t capture_id) |
| 29 : VideoCaptureImpl(capture_id), is_capturing_(false), id_(capture_id) { | 31 : VideoCaptureImpl(capture_id), is_capturing_(false), id_(capture_id) { |
| 30 capability_.width = kDefaultWidth; | 32 capability_.width = kDefaultWidth; |
| 31 capability_.height = kDefaultHeight; | 33 capability_.height = kDefaultHeight; |
| 32 capability_.maxFPS = kDefaultFrameRate; | 34 capability_.maxFPS = kDefaultFrameRate; |
| 33 capture_device_ = nil; | 35 capture_device_ = nil; |
| 34 } | 36 } |
| 35 | 37 |
| 36 VideoCaptureIos::~VideoCaptureIos() { | 38 VideoCaptureIos::~VideoCaptureIos() { |
| 37 if (is_capturing_) { | 39 if (is_capturing_) { |
| 38 [capture_device_ stopCapture]; | 40 [capture_device_ stopCapture]; |
| 39 capture_device_ = nil; | 41 capture_device_ = nil; |
| 40 } | 42 } |
| 41 } | 43 } |
| 42 | 44 |
| 43 VideoCaptureModule* VideoCaptureIos::Create(const int32_t capture_id, | 45 rtc::scoped_refptr<VideoCaptureModule> VideoCaptureIos::Create( |
| 44 const char* deviceUniqueIdUTF8) { | 46 const int32_t capture_id, |
| 47 const char* deviceUniqueIdUTF8) { | |
| 45 if (!deviceUniqueIdUTF8[0]) { | 48 if (!deviceUniqueIdUTF8[0]) { |
| 46 return NULL; | 49 return NULL; |
| 47 } | 50 } |
| 48 | 51 |
| 49 RefCountImpl<VideoCaptureIos>* capture_module = | 52 rtc::scoped_refptr<VideoCaptureIos> capture_module( |
| 50 new RefCountImpl<VideoCaptureIos>(capture_id); | 53 new rtc::RefCountedObject<VideoCaptureIos>(capture_id)); |
| 51 | 54 |
| 52 const int32_t name_length = strlen(deviceUniqueIdUTF8); | 55 const int32_t name_length = strlen(deviceUniqueIdUTF8); |
| 53 if (name_length > kVideoCaptureUniqueNameLength) | 56 if (name_length > kVideoCaptureUniqueNameLength) |
| 54 return NULL; | 57 return nullptr; |
|
tommi
2016/01/07 16:41:40
uhm... I guess we've just been leaking then :-/
pbos-webrtc
2016/01/07 17:23:16
Acknowledged.
| |
| 55 | 58 |
| 56 capture_module->_deviceUniqueId = new char[name_length + 1]; | 59 capture_module->_deviceUniqueId = new char[name_length + 1]; |
| 57 strncpy(capture_module->_deviceUniqueId, deviceUniqueIdUTF8, name_length + 1); | 60 strncpy(capture_module->_deviceUniqueId, deviceUniqueIdUTF8, name_length + 1); |
| 58 capture_module->_deviceUniqueId[name_length] = '\0'; | 61 capture_module->_deviceUniqueId[name_length] = '\0'; |
| 59 | 62 |
| 60 capture_module->capture_device_ = | 63 capture_module->capture_device_ = |
| 61 [[RTCVideoCaptureIosObjC alloc] initWithOwner:capture_module | 64 [[RTCVideoCaptureIosObjC alloc] initWithOwner:capture_module |
| 62 captureId:capture_module->id_]; | 65 captureId:capture_module->id_]; |
| 63 if (!capture_module->capture_device_) { | 66 if (!capture_module->capture_device_) { |
| 64 return NULL; | 67 return nullptr; |
| 65 } | 68 } |
| 66 | 69 |
| 67 if (![capture_module->capture_device_ setCaptureDeviceByUniqueId:[ | 70 if (![capture_module->capture_device_ setCaptureDeviceByUniqueId:[ |
| 68 [NSString alloc] initWithCString:deviceUniqueIdUTF8 | 71 [NSString alloc] initWithCString:deviceUniqueIdUTF8 |
| 69 encoding:NSUTF8StringEncoding]]) { | 72 encoding:NSUTF8StringEncoding]]) { |
| 70 return NULL; | 73 return nullptr; |
| 71 } | 74 } |
| 72 return capture_module; | 75 return capture_module; |
| 73 } | 76 } |
| 74 | 77 |
| 75 int32_t VideoCaptureIos::StartCapture( | 78 int32_t VideoCaptureIos::StartCapture( |
| 76 const VideoCaptureCapability& capability) { | 79 const VideoCaptureCapability& capability) { |
| 77 capability_ = capability; | 80 capability_ = capability; |
| 78 | 81 |
| 79 if (![capture_device_ startCaptureWithCapability:capability]) { | 82 if (![capture_device_ startCaptureWithCapability:capability]) { |
| 80 return -1; | 83 return -1; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 94 return 0; | 97 return 0; |
| 95 } | 98 } |
| 96 | 99 |
| 97 bool VideoCaptureIos::CaptureStarted() { return is_capturing_; } | 100 bool VideoCaptureIos::CaptureStarted() { return is_capturing_; } |
| 98 | 101 |
| 99 int32_t VideoCaptureIos::CaptureSettings(VideoCaptureCapability& settings) { | 102 int32_t VideoCaptureIos::CaptureSettings(VideoCaptureCapability& settings) { |
| 100 settings = capability_; | 103 settings = capability_; |
| 101 settings.rawType = kVideoNV12; | 104 settings.rawType = kVideoNV12; |
| 102 return 0; | 105 return 0; |
| 103 } | 106 } |
| OLD | NEW |