blob: 11be2ec026c61c8a1e0016c90820b3738fc9a6c7 [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
hjon6f5ca082016-01-07 09:29:29 -080017namespace webrtc {
18
19MediaConstraints::~MediaConstraints() {}
20
21MediaConstraints::MediaConstraints() {}
22
23MediaConstraints::MediaConstraints(
24 const MediaConstraintsInterface::Constraints& mandatory,
25 const MediaConstraintsInterface::Constraints& optional)
26 : mandatory_(mandatory), optional_(optional) {}
27
28const MediaConstraintsInterface::Constraints&
29MediaConstraints::GetMandatory() const {
30 return mandatory_;
31}
32
33const MediaConstraintsInterface::Constraints&
34MediaConstraints::GetOptional() const {
35 return optional_;
36}
37
38} // namespace webrtc
39
40
41@implementation RTCMediaConstraints {
Jon Hjelle32e0c012016-03-08 16:04:46 -080042 NSDictionary<NSString *, NSString *> *_mandatory;
43 NSDictionary<NSString *, NSString *> *_optional;
hjon6f5ca082016-01-07 09:29:29 -080044}
45
46- (instancetype)initWithMandatoryConstraints:
Jon Hjelle32e0c012016-03-08 16:04:46 -080047 (NSDictionary<NSString *, NSString *> *)mandatory
hjon6f5ca082016-01-07 09:29:29 -080048 optionalConstraints:
Jon Hjelle32e0c012016-03-08 16:04:46 -080049 (NSDictionary<NSString *, NSString *> *)optional {
hjon6f5ca082016-01-07 09:29:29 -080050 if (self = [super init]) {
51 _mandatory = [[NSDictionary alloc] initWithDictionary:mandatory
52 copyItems:YES];
53 _optional = [[NSDictionary alloc] initWithDictionary:optional
54 copyItems:YES];
55 }
56 return self;
57}
58
59- (NSString *)description {
60 return [NSString stringWithFormat:@"RTCMediaConstraints:\n%@\n%@",
61 _mandatory,
62 _optional];
63}
64
65#pragma mark - Private
66
kwibergbfefb032016-05-01 14:53:46 -070067- (std::unique_ptr<webrtc::MediaConstraints>)nativeConstraints {
hjon6f5ca082016-01-07 09:29:29 -080068 webrtc::MediaConstraintsInterface::Constraints mandatory =
69 [[self class] nativeConstraintsForConstraints:_mandatory];
70 webrtc::MediaConstraintsInterface::Constraints optional =
71 [[self class] nativeConstraintsForConstraints:_optional];
72
73 webrtc::MediaConstraints *nativeConstraints =
74 new webrtc::MediaConstraints(mandatory, optional);
kwibergbfefb032016-05-01 14:53:46 -070075 return std::unique_ptr<webrtc::MediaConstraints>(nativeConstraints);
hjon6f5ca082016-01-07 09:29:29 -080076}
77
78+ (webrtc::MediaConstraintsInterface::Constraints)
79 nativeConstraintsForConstraints:
Jon Hjelle32e0c012016-03-08 16:04:46 -080080 (NSDictionary<NSString *, NSString *> *)constraints {
hjon6f5ca082016-01-07 09:29:29 -080081 webrtc::MediaConstraintsInterface::Constraints nativeConstraints;
82 for (NSString *key in constraints) {
83 NSAssert([key isKindOfClass:[NSString class]],
84 @"%@ is not an NSString.", key);
hjon6b039952016-02-25 12:32:58 -080085 NSString *value = [constraints objectForKey:key];
86 NSAssert([value isKindOfClass:[NSString class]],
87 @"%@ is not an NSString.", value);
hjon6f5ca082016-01-07 09:29:29 -080088 nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint(
hjon6b039952016-02-25 12:32:58 -080089 key.stdString, value.stdString));
hjon6f5ca082016-01-07 09:29:29 -080090 }
91 return nativeConstraints;
92}
93
94@end