Home | History | Annotate | Download | only in ios
      1 /*
      2  *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
      3  *
      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.
      9  */
     10 
     11 #if !defined(__has_feature) || !__has_feature(objc_arc)
     12 #error "This file requires ARC support."
     13 #endif
     14 
     15 #include "webrtc/modules/video_capture/ios/device_info_ios.h"
     16 #include "webrtc/modules/video_capture/ios/device_info_ios_objc.h"
     17 #include "webrtc/modules/video_capture/video_capture_impl.h"
     18 #include "webrtc/system_wrappers/interface/trace.h"
     19 
     20 using namespace webrtc;
     21 using namespace videocapturemodule;
     22 
     23 #define IOS_UNSUPPORTED()                                  \
     24   WEBRTC_TRACE(kTraceError,                                \
     25                kTraceVideoCapture,                         \
     26                _id,                                        \
     27                "%s is not supported on the iOS platform.", \
     28                __FUNCTION__);                              \
     29   return -1;
     30 
     31 VideoCaptureModule::DeviceInfo* VideoCaptureImpl::CreateDeviceInfo(
     32     const int32_t device_id) {
     33   return new DeviceInfoIos(device_id);
     34 }
     35 
     36 DeviceInfoIos::DeviceInfoIos(const int32_t device_id)
     37     : DeviceInfoImpl(device_id) {}
     38 
     39 DeviceInfoIos::~DeviceInfoIos() {}
     40 
     41 int32_t DeviceInfoIos::Init() { return 0; }
     42 
     43 uint32_t DeviceInfoIos::NumberOfDevices() {
     44   return [DeviceInfoIosObjC captureDeviceCount];
     45 }
     46 
     47 int32_t DeviceInfoIos::GetDeviceName(uint32_t deviceNumber,
     48                                      char* deviceNameUTF8,
     49                                      uint32_t deviceNameUTF8Length,
     50                                      char* deviceUniqueIdUTF8,
     51                                      uint32_t deviceUniqueIdUTF8Length,
     52                                      char* productUniqueIdUTF8,
     53                                      uint32_t productUniqueIdUTF8Length) {
     54   NSString* deviceName = [DeviceInfoIosObjC deviceNameForIndex:deviceNumber];
     55 
     56   NSString* deviceUniqueId =
     57       [DeviceInfoIosObjC deviceUniqueIdForIndex:deviceNumber];
     58 
     59   strncpy(deviceNameUTF8, [deviceName UTF8String], deviceNameUTF8Length);
     60   deviceNameUTF8[deviceNameUTF8Length - 1] = '\0';
     61 
     62   strncpy(deviceUniqueIdUTF8,
     63           [deviceUniqueId UTF8String],
     64           deviceUniqueIdUTF8Length);
     65   deviceUniqueIdUTF8[deviceUniqueIdUTF8Length - 1] = '\0';
     66 
     67   if (productUniqueIdUTF8) {
     68     productUniqueIdUTF8[0] = '\0';
     69   }
     70 
     71   return 0;
     72 }
     73 
     74 int32_t DeviceInfoIos::NumberOfCapabilities(const char* deviceUniqueIdUTF8) {
     75   IOS_UNSUPPORTED();
     76 }
     77 
     78 int32_t DeviceInfoIos::GetCapability(const char* deviceUniqueIdUTF8,
     79                                      const uint32_t deviceCapabilityNumber,
     80                                      VideoCaptureCapability& capability) {
     81   IOS_UNSUPPORTED();
     82 }
     83 
     84 int32_t DeviceInfoIos::GetBestMatchedCapability(
     85     const char* deviceUniqueIdUTF8,
     86     const VideoCaptureCapability& requested,
     87     VideoCaptureCapability& resulting) {
     88   IOS_UNSUPPORTED();
     89 }
     90 
     91 int32_t DeviceInfoIos::DisplayCaptureSettingsDialogBox(
     92     const char* deviceUniqueIdUTF8,
     93     const char* dialogTitleUTF8,
     94     void* parentWindow,
     95     uint32_t positionX,
     96     uint32_t positionY) {
     97   IOS_UNSUPPORTED();
     98 }
     99 
    100 int32_t DeviceInfoIos::GetOrientation(const char* deviceUniqueIdUTF8,
    101                                       VideoCaptureRotation& orientation) {
    102   if (strcmp(deviceUniqueIdUTF8, "Front Camera") == 0) {
    103     orientation = kCameraRotate0;
    104   } else {
    105     orientation = kCameraRotate90;
    106   }
    107   return orientation;
    108 }
    109 
    110 int32_t DeviceInfoIos::CreateCapabilityMap(const char* deviceUniqueIdUTF8) {
    111   IOS_UNSUPPORTED();
    112 }
    113