blob: 34e5899ad433e7f173c8d7798e198ec9fb234e32 [file] [log] [blame]
hjon6f5ca082016-01-07 09:29:29 -08001/*
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
tkchin9eeb6242016-04-27 01:54:20 -070011#import "RTCMediaConstraints+Private.h"
hjon6f5ca082016-01-07 09:29:29 -080012
tkchin9eeb6242016-04-27 01:54:20 -070013#import "NSString+StdString.h"
hjon6f5ca082016-01-07 09:29:29 -080014
kwibergbfefb032016-05-01 14:53:46 -070015#include <memory>
16
magjed78810b62016-08-17 11:07:37 -070017NSString * const kRTCMediaConstraintsMinAspectRatio =
18 @(webrtc::MediaConstraintsInterface::kMinAspectRatio);
19NSString * const kRTCMediaConstraintsMaxAspectRatio =
20 @(webrtc::MediaConstraintsInterface::kMaxAspectRatio);
21NSString * const kRTCMediaConstraintsMinWidth =
22 @(webrtc::MediaConstraintsInterface::kMinWidth);
23NSString * const kRTCMediaConstraintsMaxWidth =
24 @(webrtc::MediaConstraintsInterface::kMaxWidth);
25NSString * const kRTCMediaConstraintsMinHeight =
26 @(webrtc::MediaConstraintsInterface::kMinHeight);
27NSString * const kRTCMediaConstraintsMaxHeight =
28 @(webrtc::MediaConstraintsInterface::kMaxHeight);
29NSString * const kRTCMediaConstraintsMinFrameRate =
30 @(webrtc::MediaConstraintsInterface::kMinFrameRate);
31NSString * const kRTCMediaConstraintsMaxFrameRate =
32 @(webrtc::MediaConstraintsInterface::kMaxFrameRate);
haysc98c43742017-02-03 13:03:39 -080033NSString * const kRTCMediaConstraintsAudioNetworkAdaptorConfig =
34 @(webrtc::MediaConstraintsInterface::kAudioNetworkAdaptorConfig);
tkchinab1293a2016-08-30 12:35:05 -070035
VladimirTechMan7b3eca92017-05-31 18:25:48 -070036NSString * const kRTCMediaConstraintsIceRestart =
37 @(webrtc::MediaConstraintsInterface::kIceRestart);
38NSString * const kRTCMediaConstraintsOfferToReceiveAudio =
39 @(webrtc::MediaConstraintsInterface::kOfferToReceiveAudio);
40NSString * const kRTCMediaConstraintsOfferToReceiveVideo =
41 @(webrtc::MediaConstraintsInterface::kOfferToReceiveVideo);
42NSString * const kRTCMediaConstraintsVoiceActivityDetection =
43 @(webrtc::MediaConstraintsInterface::kVoiceActivityDetection);
44
tkchinab1293a2016-08-30 12:35:05 -070045NSString * const kRTCMediaConstraintsValueTrue =
46 @(webrtc::MediaConstraintsInterface::kValueTrue);
47NSString * const kRTCMediaConstraintsValueFalse =
48 @(webrtc::MediaConstraintsInterface::kValueFalse);
magjed78810b62016-08-17 11:07:37 -070049
hjon6f5ca082016-01-07 09:29:29 -080050namespace webrtc {
51
52MediaConstraints::~MediaConstraints() {}
53
54MediaConstraints::MediaConstraints() {}
55
56MediaConstraints::MediaConstraints(
57 const MediaConstraintsInterface::Constraints& mandatory,
58 const MediaConstraintsInterface::Constraints& optional)
59 : mandatory_(mandatory), optional_(optional) {}
60
61const MediaConstraintsInterface::Constraints&
62MediaConstraints::GetMandatory() const {
63 return mandatory_;
64}
65
66const MediaConstraintsInterface::Constraints&
67MediaConstraints::GetOptional() const {
68 return optional_;
69}
70
71} // namespace webrtc
72
73
74@implementation RTCMediaConstraints {
Jon Hjelle32e0c012016-03-08 16:04:46 -080075 NSDictionary<NSString *, NSString *> *_mandatory;
76 NSDictionary<NSString *, NSString *> *_optional;
hjon6f5ca082016-01-07 09:29:29 -080077}
78
79- (instancetype)initWithMandatoryConstraints:
Jon Hjelle32e0c012016-03-08 16:04:46 -080080 (NSDictionary<NSString *, NSString *> *)mandatory
hjon6f5ca082016-01-07 09:29:29 -080081 optionalConstraints:
Jon Hjelle32e0c012016-03-08 16:04:46 -080082 (NSDictionary<NSString *, NSString *> *)optional {
hjon6f5ca082016-01-07 09:29:29 -080083 if (self = [super init]) {
84 _mandatory = [[NSDictionary alloc] initWithDictionary:mandatory
85 copyItems:YES];
86 _optional = [[NSDictionary alloc] initWithDictionary:optional
87 copyItems:YES];
88 }
89 return self;
90}
91
92- (NSString *)description {
93 return [NSString stringWithFormat:@"RTCMediaConstraints:\n%@\n%@",
94 _mandatory,
95 _optional];
96}
97
98#pragma mark - Private
99
kwibergbfefb032016-05-01 14:53:46 -0700100- (std::unique_ptr<webrtc::MediaConstraints>)nativeConstraints {
hjon6f5ca082016-01-07 09:29:29 -0800101 webrtc::MediaConstraintsInterface::Constraints mandatory =
102 [[self class] nativeConstraintsForConstraints:_mandatory];
103 webrtc::MediaConstraintsInterface::Constraints optional =
104 [[self class] nativeConstraintsForConstraints:_optional];
105
106 webrtc::MediaConstraints *nativeConstraints =
107 new webrtc::MediaConstraints(mandatory, optional);
kwibergbfefb032016-05-01 14:53:46 -0700108 return std::unique_ptr<webrtc::MediaConstraints>(nativeConstraints);
hjon6f5ca082016-01-07 09:29:29 -0800109}
110
111+ (webrtc::MediaConstraintsInterface::Constraints)
112 nativeConstraintsForConstraints:
Jon Hjelle32e0c012016-03-08 16:04:46 -0800113 (NSDictionary<NSString *, NSString *> *)constraints {
hjon6f5ca082016-01-07 09:29:29 -0800114 webrtc::MediaConstraintsInterface::Constraints nativeConstraints;
115 for (NSString *key in constraints) {
116 NSAssert([key isKindOfClass:[NSString class]],
117 @"%@ is not an NSString.", key);
hjon6b039952016-02-25 12:32:58 -0800118 NSString *value = [constraints objectForKey:key];
119 NSAssert([value isKindOfClass:[NSString class]],
120 @"%@ is not an NSString.", value);
haysc98c43742017-02-03 13:03:39 -0800121 if ([kRTCMediaConstraintsAudioNetworkAdaptorConfig isEqualToString:key]) {
122 // This value is base64 encoded.
123 NSData *charData = [[NSData alloc] initWithBase64EncodedString:value options:0];
124 std::string configValue =
125 std::string(reinterpret_cast<const char *>(charData.bytes), charData.length);
126 nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint(
127 key.stdString, configValue));
128 } else {
129 nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint(
130 key.stdString, value.stdString));
131 }
hjon6f5ca082016-01-07 09:29:29 -0800132 }
133 return nativeConstraints;
134}
135
136@end