blob: 0a61f99e9efd43444a672f0e4857befbf14436b6 [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
magjed78810b62016-08-17 11:07:37 -070017NSString * const kRTCMediaConstraintsMinAspectRatio =
18 @(webrtc::MediaConstraintsInterface::kMinAspectRatio);
19NSString * const kRTCMediaConstraintsMaxAspectRatio =
20 @(webrtc::MediaConstraintsInterface::kMaxAspectRatio);
21NSString * const kRTCMediaConstraintsMinWidth =
22 @(webrtc::MediaConstraintsInterface::kMinWidth);
23NSString * const kRTCMediaConstraintsMaxWidth =
24 @(webrtc::MediaConstraintsInterface::kMaxWidth);
25NSString * const kRTCMediaConstraintsMinHeight =
26 @(webrtc::MediaConstraintsInterface::kMinHeight);
27NSString * const kRTCMediaConstraintsMaxHeight =
28 @(webrtc::MediaConstraintsInterface::kMaxHeight);
29NSString * const kRTCMediaConstraintsMinFrameRate =
30 @(webrtc::MediaConstraintsInterface::kMinFrameRate);
31NSString * const kRTCMediaConstraintsMaxFrameRate =
32 @(webrtc::MediaConstraintsInterface::kMaxFrameRate);
tkchinab1293a2016-08-30 12:35:05 -070033NSString * const kRTCMediaConstraintsLevelControl =
34 @(webrtc::MediaConstraintsInterface::kLevelControl);
35
36NSString * const kRTCMediaConstraintsValueTrue =
37 @(webrtc::MediaConstraintsInterface::kValueTrue);
38NSString * const kRTCMediaConstraintsValueFalse =
39 @(webrtc::MediaConstraintsInterface::kValueFalse);
magjed78810b62016-08-17 11:07:37 -070040
hjon6f5ca082016-01-07 09:29:29 -080041namespace webrtc {
42
43MediaConstraints::~MediaConstraints() {}
44
45MediaConstraints::MediaConstraints() {}
46
47MediaConstraints::MediaConstraints(
48 const MediaConstraintsInterface::Constraints& mandatory,
49 const MediaConstraintsInterface::Constraints& optional)
50 : mandatory_(mandatory), optional_(optional) {}
51
52const MediaConstraintsInterface::Constraints&
53MediaConstraints::GetMandatory() const {
54 return mandatory_;
55}
56
57const MediaConstraintsInterface::Constraints&
58MediaConstraints::GetOptional() const {
59 return optional_;
60}
61
62} // namespace webrtc
63
64
65@implementation RTCMediaConstraints {
Jon Hjelle32e0c012016-03-08 16:04:46 -080066 NSDictionary<NSString *, NSString *> *_mandatory;
67 NSDictionary<NSString *, NSString *> *_optional;
hjon6f5ca082016-01-07 09:29:29 -080068}
69
70- (instancetype)initWithMandatoryConstraints:
Jon Hjelle32e0c012016-03-08 16:04:46 -080071 (NSDictionary<NSString *, NSString *> *)mandatory
hjon6f5ca082016-01-07 09:29:29 -080072 optionalConstraints:
Jon Hjelle32e0c012016-03-08 16:04:46 -080073 (NSDictionary<NSString *, NSString *> *)optional {
hjon6f5ca082016-01-07 09:29:29 -080074 if (self = [super init]) {
75 _mandatory = [[NSDictionary alloc] initWithDictionary:mandatory
76 copyItems:YES];
77 _optional = [[NSDictionary alloc] initWithDictionary:optional
78 copyItems:YES];
79 }
80 return self;
81}
82
83- (NSString *)description {
84 return [NSString stringWithFormat:@"RTCMediaConstraints:\n%@\n%@",
85 _mandatory,
86 _optional];
87}
88
89#pragma mark - Private
90
kwibergbfefb032016-05-01 14:53:46 -070091- (std::unique_ptr<webrtc::MediaConstraints>)nativeConstraints {
hjon6f5ca082016-01-07 09:29:29 -080092 webrtc::MediaConstraintsInterface::Constraints mandatory =
93 [[self class] nativeConstraintsForConstraints:_mandatory];
94 webrtc::MediaConstraintsInterface::Constraints optional =
95 [[self class] nativeConstraintsForConstraints:_optional];
96
97 webrtc::MediaConstraints *nativeConstraints =
98 new webrtc::MediaConstraints(mandatory, optional);
kwibergbfefb032016-05-01 14:53:46 -070099 return std::unique_ptr<webrtc::MediaConstraints>(nativeConstraints);
hjon6f5ca082016-01-07 09:29:29 -0800100}
101
102+ (webrtc::MediaConstraintsInterface::Constraints)
103 nativeConstraintsForConstraints:
Jon Hjelle32e0c012016-03-08 16:04:46 -0800104 (NSDictionary<NSString *, NSString *> *)constraints {
hjon6f5ca082016-01-07 09:29:29 -0800105 webrtc::MediaConstraintsInterface::Constraints nativeConstraints;
106 for (NSString *key in constraints) {
107 NSAssert([key isKindOfClass:[NSString class]],
108 @"%@ is not an NSString.", key);
hjon6b039952016-02-25 12:32:58 -0800109 NSString *value = [constraints objectForKey:key];
110 NSAssert([value isKindOfClass:[NSString class]],
111 @"%@ is not an NSString.", value);
hjon6f5ca082016-01-07 09:29:29 -0800112 nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint(
hjon6b039952016-02-25 12:32:58 -0800113 key.stdString, value.stdString));
hjon6f5ca082016-01-07 09:29:29 -0800114 }
115 return nativeConstraints;
116}
117
118@end