blob: a53a517747f7a2ebcf9fb8f71b36a7ae8f3379bd [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 {
41 NSDictionary<NSString *, NSString *> *_mandatory;
42 NSDictionary<NSString *, NSString *> *_optional;
43}
44
45- (instancetype)initWithMandatoryConstraints:
46 (NSDictionary<NSString *, NSString *> *)mandatory
47 optionalConstraints:
48 (NSDictionary<NSString *, NSString *> *)optional {
49 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:
79 (NSDictionary<NSString *, NSString *> *)constraints {
80 webrtc::MediaConstraintsInterface::Constraints nativeConstraints;
81 for (NSString *key in constraints) {
82 NSAssert([key isKindOfClass:[NSString class]],
83 @"%@ is not an NSString.", key);
84 NSAssert([constraints[key] isKindOfClass:[NSString class]],
85 @"%@ is not an NSString.", constraints[key]);
86 nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint(
87 key.stdString, constraints[key].stdString));
88 }
89 return nativeConstraints;
90}
91
92@end