OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #import "RTCMediaConstraints+Private.h" | 11 #import "RTCMediaConstraints+Private.h" |
12 | 12 |
13 #import "NSData+StdString.h" | |
13 #import "NSString+StdString.h" | 14 #import "NSString+StdString.h" |
14 | 15 |
15 #include <memory> | 16 #include <memory> |
16 | 17 |
17 NSString * const kRTCMediaConstraintsMinAspectRatio = | 18 NSString * const kRTCMediaConstraintsMinAspectRatio = |
18 @(webrtc::MediaConstraintsInterface::kMinAspectRatio); | 19 @(webrtc::MediaConstraintsInterface::kMinAspectRatio); |
19 NSString * const kRTCMediaConstraintsMaxAspectRatio = | 20 NSString * const kRTCMediaConstraintsMaxAspectRatio = |
20 @(webrtc::MediaConstraintsInterface::kMaxAspectRatio); | 21 @(webrtc::MediaConstraintsInterface::kMaxAspectRatio); |
21 NSString * const kRTCMediaConstraintsMinWidth = | 22 NSString * const kRTCMediaConstraintsMinWidth = |
22 @(webrtc::MediaConstraintsInterface::kMinWidth); | 23 @(webrtc::MediaConstraintsInterface::kMinWidth); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 | 57 |
57 const MediaConstraintsInterface::Constraints& | 58 const MediaConstraintsInterface::Constraints& |
58 MediaConstraints::GetOptional() const { | 59 MediaConstraints::GetOptional() const { |
59 return optional_; | 60 return optional_; |
60 } | 61 } |
61 | 62 |
62 } // namespace webrtc | 63 } // namespace webrtc |
63 | 64 |
64 | 65 |
65 @implementation RTCMediaConstraints { | 66 @implementation RTCMediaConstraints { |
66 NSDictionary<NSString *, NSString *> *_mandatory; | 67 NSMutableDictionary<NSString *, NSObject *> *_mandatory; |
67 NSDictionary<NSString *, NSString *> *_optional; | 68 NSMutableDictionary<NSString *, NSObject *> *_optional; |
68 } | 69 } |
69 | 70 |
70 - (instancetype)initWithMandatoryConstraints: | 71 - (instancetype)initWithMandatoryConstraints: |
71 (NSDictionary<NSString *, NSString *> *)mandatory | 72 (NSDictionary<NSString *, NSString *> *)mandatory |
72 optionalConstraints: | 73 optionalConstraints: |
73 (NSDictionary<NSString *, NSString *> *)optional { | 74 (NSDictionary<NSString *, NSString *> *)optional { |
74 if (self = [super init]) { | 75 if (self = [super init]) { |
75 _mandatory = [[NSDictionary alloc] initWithDictionary:mandatory | 76 _mandatory = [[NSMutableDictionary alloc] initWithDictionary:mandatory |
76 copyItems:YES]; | 77 copyItems:YES]; |
77 _optional = [[NSDictionary alloc] initWithDictionary:optional | 78 _optional = [[NSMutableDictionary alloc] initWithDictionary:optional |
78 copyItems:YES]; | 79 copyItems:YES]; |
79 } | 80 } |
80 return self; | 81 return self; |
81 } | 82 } |
82 | 83 |
83 - (NSString *)description { | 84 - (NSString *)description { |
84 return [NSString stringWithFormat:@"RTCMediaConstraints:\n%@\n%@", | 85 return [NSString stringWithFormat:@"RTCMediaConstraints:\n%@\n%@", |
85 _mandatory, | 86 _mandatory, |
86 _optional]; | 87 _optional]; |
87 } | 88 } |
88 | 89 |
90 - (void)addConstraintForKey:(NSString *)key | |
91 data:(NSData *)data | |
92 isMandatory:(BOOL)isMandatory { | |
93 NSAssert(data, @"Invalid data."); | |
94 NSAssert(key.length, @"Invalid key."); | |
95 if (!data || !key.length) { | |
96 return; | |
tkchin_webrtc
2017/02/02 19:04:53
nit: log error
Chuck
2017/02/03 15:55:50
Gone in latest iteration.
| |
97 } | |
98 if (isMandatory) { | |
99 _mandatory[key] = data; | |
tkchin_webrtc
2017/02/02 19:04:53
might break mac build - make sure to run bots ( do
Chuck
2017/02/03 15:55:50
Gone in latest iteration.
| |
100 } else { | |
101 _optional[key] = data; | |
102 } | |
103 } | |
104 | |
89 #pragma mark - Private | 105 #pragma mark - Private |
90 | 106 |
91 - (std::unique_ptr<webrtc::MediaConstraints>)nativeConstraints { | 107 - (std::unique_ptr<webrtc::MediaConstraints>)nativeConstraints { |
92 webrtc::MediaConstraintsInterface::Constraints mandatory = | 108 webrtc::MediaConstraintsInterface::Constraints mandatory = |
93 [[self class] nativeConstraintsForConstraints:_mandatory]; | 109 [[self class] nativeConstraintsForConstraints:_mandatory]; |
94 webrtc::MediaConstraintsInterface::Constraints optional = | 110 webrtc::MediaConstraintsInterface::Constraints optional = |
95 [[self class] nativeConstraintsForConstraints:_optional]; | 111 [[self class] nativeConstraintsForConstraints:_optional]; |
96 | 112 |
97 webrtc::MediaConstraints *nativeConstraints = | 113 webrtc::MediaConstraints *nativeConstraints = |
98 new webrtc::MediaConstraints(mandatory, optional); | 114 new webrtc::MediaConstraints(mandatory, optional); |
99 return std::unique_ptr<webrtc::MediaConstraints>(nativeConstraints); | 115 return std::unique_ptr<webrtc::MediaConstraints>(nativeConstraints); |
100 } | 116 } |
101 | 117 |
102 + (webrtc::MediaConstraintsInterface::Constraints) | 118 + (webrtc::MediaConstraintsInterface::Constraints) |
103 nativeConstraintsForConstraints: | 119 nativeConstraintsForConstraints: |
104 (NSDictionary<NSString *, NSString *> *)constraints { | 120 (NSDictionary<NSString *, NSObject *> *)constraints { |
105 webrtc::MediaConstraintsInterface::Constraints nativeConstraints; | 121 webrtc::MediaConstraintsInterface::Constraints nativeConstraints; |
106 for (NSString *key in constraints) { | 122 for (NSString *key in constraints) { |
107 NSAssert([key isKindOfClass:[NSString class]], | 123 NSAssert([key isKindOfClass:[NSString class]], |
108 @"%@ is not an NSString.", key); | 124 @"%@ is not an NSString.", key); |
109 NSString *value = [constraints objectForKey:key]; | 125 // value must be either NSString or NSData. |
110 NSAssert([value isKindOfClass:[NSString class]], | 126 NSObject *value = [constraints objectForKey:key]; |
111 @"%@ is not an NSString.", value); | 127 if ([value isKindOfClass:[NSData class]]) { |
112 nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint( | 128 NSData *data = (NSData *)value; |
113 key.stdString, value.stdString)); | 129 nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint( |
130 key.stdString, data.stdString)); | |
131 } else { | |
tkchin_webrtc
2017/02/02 19:04:53
nit: safer to do an else if NSString then finally
Chuck
2017/02/03 15:55:51
Gone in latest iteration.
| |
132 NSAssert([value isKindOfClass:[NSString class]], | |
133 @"%@ is not an NSString.", value); | |
134 NSString *string = (NSString *)value; | |
135 nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint( | |
136 key.stdString, string.stdString)); | |
137 } | |
114 } | 138 } |
115 return nativeConstraints; | 139 return nativeConstraints; |
116 } | 140 } |
117 | 141 |
118 @end | 142 @end |
OLD | NEW |