blob: 9d4e391d101b4af39c8edbd8a77df0d87c5e1005 [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
hjon6b039952016-02-25 12:32:58 -080016// TODO(hjon): Update nullability types. See http://crbug/webrtc/5592
17
hjon6f5ca082016-01-07 09:29:29 -080018namespace webrtc {
19
20MediaConstraints::~MediaConstraints() {}
21
22MediaConstraints::MediaConstraints() {}
23
24MediaConstraints::MediaConstraints(
25 const MediaConstraintsInterface::Constraints& mandatory,
26 const MediaConstraintsInterface::Constraints& optional)
27 : mandatory_(mandatory), optional_(optional) {}
28
29const MediaConstraintsInterface::Constraints&
30MediaConstraints::GetMandatory() const {
31 return mandatory_;
32}
33
34const MediaConstraintsInterface::Constraints&
35MediaConstraints::GetOptional() const {
36 return optional_;
37}
38
39} // namespace webrtc
40
41
42@implementation RTCMediaConstraints {
hjon6b039952016-02-25 12:32:58 -080043 NSDictionary *_mandatory;
44 // NSDictionary<NSString *, NSString *> *_mandatory;
45 NSDictionary *_optional;
46 // NSDictionary<NSString *, NSString *> *_optional;
hjon6f5ca082016-01-07 09:29:29 -080047}
48
49- (instancetype)initWithMandatoryConstraints:
hjon6b039952016-02-25 12:32:58 -080050 (NSDictionary *)mandatory
51 // (NSDictionary<NSString *, NSString *> *)mandatory
hjon6f5ca082016-01-07 09:29:29 -080052 optionalConstraints:
hjon6b039952016-02-25 12:32:58 -080053 (NSDictionary *)optional {
54 // (NSDictionary<NSString *, NSString *> *)optional {
hjon6f5ca082016-01-07 09:29:29 -080055 if (self = [super init]) {
56 _mandatory = [[NSDictionary alloc] initWithDictionary:mandatory
57 copyItems:YES];
58 _optional = [[NSDictionary alloc] initWithDictionary:optional
59 copyItems:YES];
60 }
61 return self;
62}
63
64- (NSString *)description {
65 return [NSString stringWithFormat:@"RTCMediaConstraints:\n%@\n%@",
66 _mandatory,
67 _optional];
68}
69
70#pragma mark - Private
71
72- (rtc::scoped_ptr<webrtc::MediaConstraints>)nativeConstraints {
73 webrtc::MediaConstraintsInterface::Constraints mandatory =
74 [[self class] nativeConstraintsForConstraints:_mandatory];
75 webrtc::MediaConstraintsInterface::Constraints optional =
76 [[self class] nativeConstraintsForConstraints:_optional];
77
78 webrtc::MediaConstraints *nativeConstraints =
79 new webrtc::MediaConstraints(mandatory, optional);
80 return rtc::scoped_ptr<webrtc::MediaConstraints>(nativeConstraints);
81}
82
83+ (webrtc::MediaConstraintsInterface::Constraints)
84 nativeConstraintsForConstraints:
hjon6b039952016-02-25 12:32:58 -080085 (NSDictionary *)constraints {
86 // (NSDictionary<NSString *, NSString *> *)constraints {
hjon6f5ca082016-01-07 09:29:29 -080087 webrtc::MediaConstraintsInterface::Constraints nativeConstraints;
88 for (NSString *key in constraints) {
89 NSAssert([key isKindOfClass:[NSString class]],
90 @"%@ is not an NSString.", key);
hjon6b039952016-02-25 12:32:58 -080091 NSString *value = [constraints objectForKey:key];
92 NSAssert([value isKindOfClass:[NSString class]],
93 @"%@ is not an NSString.", value);
hjon6f5ca082016-01-07 09:29:29 -080094 nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint(
hjon6b039952016-02-25 12:32:58 -080095 key.stdString, value.stdString));
hjon6f5ca082016-01-07 09:29:29 -080096 }
97 return nativeConstraints;
98}
99
100@end