2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #if !defined(__has_feature) || !__has_feature(objc_arc)
12 #error "This file requires ARC support."
15 #include "webrtc/modules/video_capture/ios/device_info_ios_objc.h"
16 #include "webrtc/modules/video_capture/ios/rtc_video_capture_ios_objc.h"
17 #include "webrtc/system_wrappers/interface/ref_count.h"
18 #include "webrtc/system_wrappers/interface/scoped_refptr.h"
19 #include "webrtc/system_wrappers/interface/trace.h"
21 using namespace webrtc;
22 using namespace videocapturemodule;
24 VideoCaptureModule* VideoCaptureImpl::Create(const int32_t capture_id,
25 const char* deviceUniqueIdUTF8) {
26 return VideoCaptureIos::Create(capture_id, deviceUniqueIdUTF8);
29 VideoCaptureIos::VideoCaptureIos(const int32_t capture_id)
30 : VideoCaptureImpl(capture_id), is_capturing_(false), id_(capture_id) {
31 capability_.width = kDefaultWidth;
32 capability_.height = kDefaultHeight;
33 capability_.maxFPS = kDefaultFrameRate;
36 VideoCaptureIos::~VideoCaptureIos() {
38 [capture_device_ stopCapture];
42 VideoCaptureModule* VideoCaptureIos::Create(const int32_t capture_id,
43 const char* deviceUniqueIdUTF8) {
44 if (!deviceUniqueIdUTF8[0]) {
48 RefCountImpl<VideoCaptureIos>* capture_module =
49 new RefCountImpl<VideoCaptureIos>(capture_id);
51 const int32_t name_length = strlen(deviceUniqueIdUTF8);
52 if (name_length > kVideoCaptureUniqueNameLength)
55 capture_module->_deviceUniqueId = new char[name_length + 1];
56 strncpy(capture_module->_deviceUniqueId, deviceUniqueIdUTF8, name_length + 1);
57 capture_module->_deviceUniqueId[name_length] = '\0';
59 capture_module->capture_device_ =
60 [[RTCVideoCaptureIosObjC alloc] initWithOwner:capture_module
61 captureId:capture_module->id_];
62 if (!capture_module->capture_device_) {
66 if (![capture_module->capture_device_ setCaptureDeviceByUniqueId:[
67 [NSString alloc] initWithCString:deviceUniqueIdUTF8
68 encoding:NSUTF8StringEncoding]]) {
71 return capture_module;
74 int32_t VideoCaptureIos::StartCapture(
75 const VideoCaptureCapability& capability) {
76 capability_ = capability;
78 if (![capture_device_ startCaptureWithCapability:capability]) {
87 int32_t VideoCaptureIos::StopCapture() {
88 if (![capture_device_ stopCapture]) {
92 is_capturing_ = false;
96 bool VideoCaptureIos::CaptureStarted() { return is_capturing_; }
98 int32_t VideoCaptureIos::CaptureSettings(VideoCaptureCapability& settings) {
99 settings = capability_;
100 settings.rawType = kVideoNV12;