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); |
| 33 | |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 34 | namespace webrtc { |
| 35 | |
| 36 | MediaConstraints::~MediaConstraints() {} |
| 37 | |
| 38 | MediaConstraints::MediaConstraints() {} |
| 39 | |
| 40 | MediaConstraints::MediaConstraints( |
| 41 | const MediaConstraintsInterface::Constraints& mandatory, |
| 42 | const MediaConstraintsInterface::Constraints& optional) |
| 43 | : mandatory_(mandatory), optional_(optional) {} |
| 44 | |
| 45 | const MediaConstraintsInterface::Constraints& |
| 46 | MediaConstraints::GetMandatory() const { |
| 47 | return mandatory_; |
| 48 | } |
| 49 | |
| 50 | const MediaConstraintsInterface::Constraints& |
| 51 | MediaConstraints::GetOptional() const { |
| 52 | return optional_; |
| 53 | } |
| 54 | |
| 55 | } // namespace webrtc |
| 56 | |
| 57 | |
| 58 | @implementation RTCMediaConstraints { |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 59 | NSDictionary<NSString *, NSString *> *_mandatory; |
| 60 | NSDictionary<NSString *, NSString *> *_optional; |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | - (instancetype)initWithMandatoryConstraints: |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 64 | (NSDictionary<NSString *, NSString *> *)mandatory |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 65 | optionalConstraints: |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 66 | (NSDictionary<NSString *, NSString *> *)optional { |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 67 | if (self = [super init]) { |
| 68 | _mandatory = [[NSDictionary alloc] initWithDictionary:mandatory |
| 69 | copyItems:YES]; |
| 70 | _optional = [[NSDictionary alloc] initWithDictionary:optional |
| 71 | copyItems:YES]; |
| 72 | } |
| 73 | return self; |
| 74 | } |
| 75 | |
| 76 | - (NSString *)description { |
| 77 | return [NSString stringWithFormat:@"RTCMediaConstraints:\n%@\n%@", |
| 78 | _mandatory, |
| 79 | _optional]; |
| 80 | } |
| 81 | |
| 82 | #pragma mark - Private |
| 83 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 84 | - (std::unique_ptr<webrtc::MediaConstraints>)nativeConstraints { |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 85 | webrtc::MediaConstraintsInterface::Constraints mandatory = |
| 86 | [[self class] nativeConstraintsForConstraints:_mandatory]; |
| 87 | webrtc::MediaConstraintsInterface::Constraints optional = |
| 88 | [[self class] nativeConstraintsForConstraints:_optional]; |
| 89 | |
| 90 | webrtc::MediaConstraints *nativeConstraints = |
| 91 | new webrtc::MediaConstraints(mandatory, optional); |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 92 | return std::unique_ptr<webrtc::MediaConstraints>(nativeConstraints); |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | + (webrtc::MediaConstraintsInterface::Constraints) |
| 96 | nativeConstraintsForConstraints: |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 97 | (NSDictionary<NSString *, NSString *> *)constraints { |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 98 | webrtc::MediaConstraintsInterface::Constraints nativeConstraints; |
| 99 | for (NSString *key in constraints) { |
| 100 | NSAssert([key isKindOfClass:[NSString class]], |
| 101 | @"%@ is not an NSString.", key); |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 102 | NSString *value = [constraints objectForKey:key]; |
| 103 | NSAssert([value isKindOfClass:[NSString class]], |
| 104 | @"%@ is not an NSString.", value); |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 105 | nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint( |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 106 | key.stdString, value.stdString)); |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 107 | } |
| 108 | return nativeConstraints; |
| 109 | } |
| 110 | |
| 111 | @end |