blob: 7a7cdf15cf171430aff1edf0b2e09c48892bc3aa [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
15namespace webrtc {
16
17MediaConstraints::~MediaConstraints() {}
18
19MediaConstraints::MediaConstraints() {}
20
21MediaConstraints::MediaConstraints(
22 const MediaConstraintsInterface::Constraints& mandatory,
23 const MediaConstraintsInterface::Constraints& optional)
24 : mandatory_(mandatory), optional_(optional) {}
25
26const MediaConstraintsInterface::Constraints&
27MediaConstraints::GetMandatory() const {
28 return mandatory_;
29}
30
31const MediaConstraintsInterface::Constraints&
32MediaConstraints::GetOptional() const {
33 return optional_;
34}
35
36} // namespace webrtc
37
38
39@implementation RTCMediaConstraints {
Jon Hjelle32e0c012016-03-08 16:04:46 -080040 NSDictionary<NSString *, NSString *> *_mandatory;
41 NSDictionary<NSString *, NSString *> *_optional;
hjon6f5ca082016-01-07 09:29:29 -080042}
43
44- (instancetype)initWithMandatoryConstraints:
Jon Hjelle32e0c012016-03-08 16:04:46 -080045 (NSDictionary<NSString *, NSString *> *)mandatory
hjon6f5ca082016-01-07 09:29:29 -080046 optionalConstraints:
Jon Hjelle32e0c012016-03-08 16:04:46 -080047 (NSDictionary<NSString *, NSString *> *)optional {
hjon6f5ca082016-01-07 09:29:29 -080048 if (self = [super init]) {
49 _mandatory = [[NSDictionary alloc] initWithDictionary:mandatory
50 copyItems:YES];
51 _optional = [[NSDictionary alloc] initWithDictionary:optional
52 copyItems:YES];
53 }
54 return self;
55}
56
57- (NSString *)description {
58 return [NSString stringWithFormat:@"RTCMediaConstraints:\n%@\n%@",
59 _mandatory,
60 _optional];
61}
62
63#pragma mark - Private
64
65- (rtc::scoped_ptr<webrtc::MediaConstraints>)nativeConstraints {
66 webrtc::MediaConstraintsInterface::Constraints mandatory =
67 [[self class] nativeConstraintsForConstraints:_mandatory];
68 webrtc::MediaConstraintsInterface::Constraints optional =
69 [[self class] nativeConstraintsForConstraints:_optional];
70
71 webrtc::MediaConstraints *nativeConstraints =
72 new webrtc::MediaConstraints(mandatory, optional);
73 return rtc::scoped_ptr<webrtc::MediaConstraints>(nativeConstraints);
74}
75
76+ (webrtc::MediaConstraintsInterface::Constraints)
77 nativeConstraintsForConstraints:
Jon Hjelle32e0c012016-03-08 16:04:46 -080078 (NSDictionary<NSString *, NSString *> *)constraints {
hjon6f5ca082016-01-07 09:29:29 -080079 webrtc::MediaConstraintsInterface::Constraints nativeConstraints;
80 for (NSString *key in constraints) {
81 NSAssert([key isKindOfClass:[NSString class]],
82 @"%@ is not an NSString.", key);
hjon6b039952016-02-25 12:32:58 -080083 NSString *value = [constraints objectForKey:key];
84 NSAssert([value isKindOfClass:[NSString class]],
85 @"%@ is not an NSString.", value);
hjon6f5ca082016-01-07 09:29:29 -080086 nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint(
hjon6b039952016-02-25 12:32:58 -080087 key.stdString, value.stdString));
hjon6f5ca082016-01-07 09:29:29 -080088 }
89 return nativeConstraints;
90}
91
92@end