hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 11 | #import "RTCMediaConstraints+Private.h" |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 12 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 13 | #import "NSString+StdString.h" |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 14 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 15 | #include <memory> |
| 16 | |
magjed | 78810b6 | 2016-08-17 11:07:37 -0700 | [diff] [blame] | 17 | NSString * const kRTCMediaConstraintsMinAspectRatio = |
| 18 | @(webrtc::MediaConstraintsInterface::kMinAspectRatio); |
| 19 | NSString * const kRTCMediaConstraintsMaxAspectRatio = |
| 20 | @(webrtc::MediaConstraintsInterface::kMaxAspectRatio); |
| 21 | NSString * const kRTCMediaConstraintsMinWidth = |
| 22 | @(webrtc::MediaConstraintsInterface::kMinWidth); |
| 23 | NSString * const kRTCMediaConstraintsMaxWidth = |
| 24 | @(webrtc::MediaConstraintsInterface::kMaxWidth); |
| 25 | NSString * const kRTCMediaConstraintsMinHeight = |
| 26 | @(webrtc::MediaConstraintsInterface::kMinHeight); |
| 27 | NSString * const kRTCMediaConstraintsMaxHeight = |
| 28 | @(webrtc::MediaConstraintsInterface::kMaxHeight); |
| 29 | NSString * const kRTCMediaConstraintsMinFrameRate = |
| 30 | @(webrtc::MediaConstraintsInterface::kMinFrameRate); |
| 31 | NSString * const kRTCMediaConstraintsMaxFrameRate = |
| 32 | @(webrtc::MediaConstraintsInterface::kMaxFrameRate); |
tkchin | ab1293a | 2016-08-30 12:35:05 -0700 | [diff] [blame^] | 33 | NSString * const kRTCMediaConstraintsLevelControl = |
| 34 | @(webrtc::MediaConstraintsInterface::kLevelControl); |
| 35 | |
| 36 | NSString * const kRTCMediaConstraintsValueTrue = |
| 37 | @(webrtc::MediaConstraintsInterface::kValueTrue); |
| 38 | NSString * const kRTCMediaConstraintsValueFalse = |
| 39 | @(webrtc::MediaConstraintsInterface::kValueFalse); |
magjed | 78810b6 | 2016-08-17 11:07:37 -0700 | [diff] [blame] | 40 | |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 41 | namespace webrtc { |
| 42 | |
| 43 | MediaConstraints::~MediaConstraints() {} |
| 44 | |
| 45 | MediaConstraints::MediaConstraints() {} |
| 46 | |
| 47 | MediaConstraints::MediaConstraints( |
| 48 | const MediaConstraintsInterface::Constraints& mandatory, |
| 49 | const MediaConstraintsInterface::Constraints& optional) |
| 50 | : mandatory_(mandatory), optional_(optional) {} |
| 51 | |
| 52 | const MediaConstraintsInterface::Constraints& |
| 53 | MediaConstraints::GetMandatory() const { |
| 54 | return mandatory_; |
| 55 | } |
| 56 | |
| 57 | const MediaConstraintsInterface::Constraints& |
| 58 | MediaConstraints::GetOptional() const { |
| 59 | return optional_; |
| 60 | } |
| 61 | |
| 62 | } // namespace webrtc |
| 63 | |
| 64 | |
| 65 | @implementation RTCMediaConstraints { |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 66 | NSDictionary<NSString *, NSString *> *_mandatory; |
| 67 | NSDictionary<NSString *, NSString *> *_optional; |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | - (instancetype)initWithMandatoryConstraints: |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 71 | (NSDictionary<NSString *, NSString *> *)mandatory |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 72 | optionalConstraints: |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 73 | (NSDictionary<NSString *, NSString *> *)optional { |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 74 | if (self = [super init]) { |
| 75 | _mandatory = [[NSDictionary alloc] initWithDictionary:mandatory |
| 76 | copyItems:YES]; |
| 77 | _optional = [[NSDictionary alloc] initWithDictionary:optional |
| 78 | copyItems:YES]; |
| 79 | } |
| 80 | return self; |
| 81 | } |
| 82 | |
| 83 | - (NSString *)description { |
| 84 | return [NSString stringWithFormat:@"RTCMediaConstraints:\n%@\n%@", |
| 85 | _mandatory, |
| 86 | _optional]; |
| 87 | } |
| 88 | |
| 89 | #pragma mark - Private |
| 90 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 91 | - (std::unique_ptr<webrtc::MediaConstraints>)nativeConstraints { |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 92 | webrtc::MediaConstraintsInterface::Constraints mandatory = |
| 93 | [[self class] nativeConstraintsForConstraints:_mandatory]; |
| 94 | webrtc::MediaConstraintsInterface::Constraints optional = |
| 95 | [[self class] nativeConstraintsForConstraints:_optional]; |
| 96 | |
| 97 | webrtc::MediaConstraints *nativeConstraints = |
| 98 | new webrtc::MediaConstraints(mandatory, optional); |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 99 | return std::unique_ptr<webrtc::MediaConstraints>(nativeConstraints); |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | + (webrtc::MediaConstraintsInterface::Constraints) |
| 103 | nativeConstraintsForConstraints: |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 104 | (NSDictionary<NSString *, NSString *> *)constraints { |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 105 | webrtc::MediaConstraintsInterface::Constraints nativeConstraints; |
| 106 | for (NSString *key in constraints) { |
| 107 | NSAssert([key isKindOfClass:[NSString class]], |
| 108 | @"%@ is not an NSString.", key); |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 109 | NSString *value = [constraints objectForKey:key]; |
| 110 | NSAssert([value isKindOfClass:[NSString class]], |
| 111 | @"%@ is not an NSString.", value); |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 112 | nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint( |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 113 | key.stdString, value.stdString)); |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 114 | } |
| 115 | return nativeConstraints; |
| 116 | } |
| 117 | |
| 118 | @end |