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 | |
| 11 | #import "RTCMediaConstraints.h" |
| 12 | |
| 13 | #import "webrtc/api/objc/RTCMediaConstraints+Private.h" |
| 14 | #import "webrtc/base/objc/NSString+StdString.h" |
| 15 | |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 16 | // TODO(hjon): Update nullability types. See http://crbug/webrtc/5592 |
| 17 | |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 18 | namespace webrtc { |
| 19 | |
| 20 | MediaConstraints::~MediaConstraints() {} |
| 21 | |
| 22 | MediaConstraints::MediaConstraints() {} |
| 23 | |
| 24 | MediaConstraints::MediaConstraints( |
| 25 | const MediaConstraintsInterface::Constraints& mandatory, |
| 26 | const MediaConstraintsInterface::Constraints& optional) |
| 27 | : mandatory_(mandatory), optional_(optional) {} |
| 28 | |
| 29 | const MediaConstraintsInterface::Constraints& |
| 30 | MediaConstraints::GetMandatory() const { |
| 31 | return mandatory_; |
| 32 | } |
| 33 | |
| 34 | const MediaConstraintsInterface::Constraints& |
| 35 | MediaConstraints::GetOptional() const { |
| 36 | return optional_; |
| 37 | } |
| 38 | |
| 39 | } // namespace webrtc |
| 40 | |
| 41 | |
| 42 | @implementation RTCMediaConstraints { |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 43 | NSDictionary *_mandatory; |
| 44 | // NSDictionary<NSString *, NSString *> *_mandatory; |
| 45 | NSDictionary *_optional; |
| 46 | // NSDictionary<NSString *, NSString *> *_optional; |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | - (instancetype)initWithMandatoryConstraints: |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 50 | (NSDictionary *)mandatory |
| 51 | // (NSDictionary<NSString *, NSString *> *)mandatory |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 52 | optionalConstraints: |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 53 | (NSDictionary *)optional { |
| 54 | // (NSDictionary<NSString *, NSString *> *)optional { |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 55 | if (self = [super init]) { |
| 56 | _mandatory = [[NSDictionary alloc] initWithDictionary:mandatory |
| 57 | copyItems:YES]; |
| 58 | _optional = [[NSDictionary alloc] initWithDictionary:optional |
| 59 | copyItems:YES]; |
| 60 | } |
| 61 | return self; |
| 62 | } |
| 63 | |
| 64 | - (NSString *)description { |
| 65 | return [NSString stringWithFormat:@"RTCMediaConstraints:\n%@\n%@", |
| 66 | _mandatory, |
| 67 | _optional]; |
| 68 | } |
| 69 | |
| 70 | #pragma mark - Private |
| 71 | |
| 72 | - (rtc::scoped_ptr<webrtc::MediaConstraints>)nativeConstraints { |
| 73 | webrtc::MediaConstraintsInterface::Constraints mandatory = |
| 74 | [[self class] nativeConstraintsForConstraints:_mandatory]; |
| 75 | webrtc::MediaConstraintsInterface::Constraints optional = |
| 76 | [[self class] nativeConstraintsForConstraints:_optional]; |
| 77 | |
| 78 | webrtc::MediaConstraints *nativeConstraints = |
| 79 | new webrtc::MediaConstraints(mandatory, optional); |
| 80 | return rtc::scoped_ptr<webrtc::MediaConstraints>(nativeConstraints); |
| 81 | } |
| 82 | |
| 83 | + (webrtc::MediaConstraintsInterface::Constraints) |
| 84 | nativeConstraintsForConstraints: |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 85 | (NSDictionary *)constraints { |
| 86 | // (NSDictionary<NSString *, NSString *> *)constraints { |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 87 | webrtc::MediaConstraintsInterface::Constraints nativeConstraints; |
| 88 | for (NSString *key in constraints) { |
| 89 | NSAssert([key isKindOfClass:[NSString class]], |
| 90 | @"%@ is not an NSString.", key); |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 91 | NSString *value = [constraints objectForKey:key]; |
| 92 | NSAssert([value isKindOfClass:[NSString class]], |
| 93 | @"%@ is not an NSString.", value); |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 94 | nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint( |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 95 | key.stdString, value.stdString)); |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 96 | } |
| 97 | return nativeConstraints; |
| 98 | } |
| 99 | |
| 100 | @end |