OLD | NEW |
| (Empty) |
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+Private.h" | |
12 | |
13 #import "NSString+StdString.h" | |
14 | |
15 #include <memory> | |
16 | |
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 NSString * const kRTCMediaConstraintsLevelControl = | |
34 @(webrtc::MediaConstraintsInterface::kLevelControl); | |
35 NSString * const kRTCMediaConstraintsAudioNetworkAdaptorConfig = | |
36 @(webrtc::MediaConstraintsInterface::kAudioNetworkAdaptorConfig); | |
37 | |
38 NSString * const kRTCMediaConstraintsValueTrue = | |
39 @(webrtc::MediaConstraintsInterface::kValueTrue); | |
40 NSString * const kRTCMediaConstraintsValueFalse = | |
41 @(webrtc::MediaConstraintsInterface::kValueFalse); | |
42 | |
43 namespace webrtc { | |
44 | |
45 MediaConstraints::~MediaConstraints() {} | |
46 | |
47 MediaConstraints::MediaConstraints() {} | |
48 | |
49 MediaConstraints::MediaConstraints( | |
50 const MediaConstraintsInterface::Constraints& mandatory, | |
51 const MediaConstraintsInterface::Constraints& optional) | |
52 : mandatory_(mandatory), optional_(optional) {} | |
53 | |
54 const MediaConstraintsInterface::Constraints& | |
55 MediaConstraints::GetMandatory() const { | |
56 return mandatory_; | |
57 } | |
58 | |
59 const MediaConstraintsInterface::Constraints& | |
60 MediaConstraints::GetOptional() const { | |
61 return optional_; | |
62 } | |
63 | |
64 } // namespace webrtc | |
65 | |
66 | |
67 @implementation RTCMediaConstraints { | |
68 NSDictionary<NSString *, NSString *> *_mandatory; | |
69 NSDictionary<NSString *, NSString *> *_optional; | |
70 } | |
71 | |
72 - (instancetype)initWithMandatoryConstraints: | |
73 (NSDictionary<NSString *, NSString *> *)mandatory | |
74 optionalConstraints: | |
75 (NSDictionary<NSString *, NSString *> *)optional { | |
76 if (self = [super init]) { | |
77 _mandatory = [[NSDictionary alloc] initWithDictionary:mandatory | |
78 copyItems:YES]; | |
79 _optional = [[NSDictionary alloc] initWithDictionary:optional | |
80 copyItems:YES]; | |
81 } | |
82 return self; | |
83 } | |
84 | |
85 - (NSString *)description { | |
86 return [NSString stringWithFormat:@"RTCMediaConstraints:\n%@\n%@", | |
87 _mandatory, | |
88 _optional]; | |
89 } | |
90 | |
91 #pragma mark - Private | |
92 | |
93 - (std::unique_ptr<webrtc::MediaConstraints>)nativeConstraints { | |
94 webrtc::MediaConstraintsInterface::Constraints mandatory = | |
95 [[self class] nativeConstraintsForConstraints:_mandatory]; | |
96 webrtc::MediaConstraintsInterface::Constraints optional = | |
97 [[self class] nativeConstraintsForConstraints:_optional]; | |
98 | |
99 webrtc::MediaConstraints *nativeConstraints = | |
100 new webrtc::MediaConstraints(mandatory, optional); | |
101 return std::unique_ptr<webrtc::MediaConstraints>(nativeConstraints); | |
102 } | |
103 | |
104 + (webrtc::MediaConstraintsInterface::Constraints) | |
105 nativeConstraintsForConstraints: | |
106 (NSDictionary<NSString *, NSString *> *)constraints { | |
107 webrtc::MediaConstraintsInterface::Constraints nativeConstraints; | |
108 for (NSString *key in constraints) { | |
109 NSAssert([key isKindOfClass:[NSString class]], | |
110 @"%@ is not an NSString.", key); | |
111 NSString *value = [constraints objectForKey:key]; | |
112 NSAssert([value isKindOfClass:[NSString class]], | |
113 @"%@ is not an NSString.", value); | |
114 if ([kRTCMediaConstraintsAudioNetworkAdaptorConfig isEqualToString:key]) { | |
115 // This value is base64 encoded. | |
116 NSData *charData = [[NSData alloc] initWithBase64EncodedString:value optio
ns:0]; | |
117 std::string configValue = | |
118 std::string(reinterpret_cast<const char *>(charData.bytes), charData.l
ength); | |
119 nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint( | |
120 key.stdString, configValue)); | |
121 } else { | |
122 nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint( | |
123 key.stdString, value.stdString)); | |
124 } | |
125 } | |
126 return nativeConstraints; | |
127 } | |
128 | |
129 @end | |
OLD | NEW |