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