blob: f0f3c860b20d7206a19042ade5a304d9290ec998 [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);
33
hjon6f5ca082016-01-07 09:29:29 -080034namespace webrtc {
35
36MediaConstraints::~MediaConstraints() {}
37
38MediaConstraints::MediaConstraints() {}
39
40MediaConstraints::MediaConstraints(
41 const MediaConstraintsInterface::Constraints& mandatory,
42 const MediaConstraintsInterface::Constraints& optional)
43 : mandatory_(mandatory), optional_(optional) {}
44
45const MediaConstraintsInterface::Constraints&
46MediaConstraints::GetMandatory() const {
47 return mandatory_;
48}
49
50const MediaConstraintsInterface::Constraints&
51MediaConstraints::GetOptional() const {
52 return optional_;
53}
54
55} // namespace webrtc
56
57
58@implementation RTCMediaConstraints {
Jon Hjelle32e0c012016-03-08 16:04:46 -080059 NSDictionary<NSString *, NSString *> *_mandatory;
60 NSDictionary<NSString *, NSString *> *_optional;
hjon6f5ca082016-01-07 09:29:29 -080061}
62
63- (instancetype)initWithMandatoryConstraints:
Jon Hjelle32e0c012016-03-08 16:04:46 -080064 (NSDictionary<NSString *, NSString *> *)mandatory
hjon6f5ca082016-01-07 09:29:29 -080065 optionalConstraints:
Jon Hjelle32e0c012016-03-08 16:04:46 -080066 (NSDictionary<NSString *, NSString *> *)optional {
hjon6f5ca082016-01-07 09:29:29 -080067 if (self = [super init]) {
68 _mandatory = [[NSDictionary alloc] initWithDictionary:mandatory
69 copyItems:YES];
70 _optional = [[NSDictionary alloc] initWithDictionary:optional
71 copyItems:YES];
72 }
73 return self;
74}
75
76- (NSString *)description {
77 return [NSString stringWithFormat:@"RTCMediaConstraints:\n%@\n%@",
78 _mandatory,
79 _optional];
80}
81
82#pragma mark - Private
83
kwibergbfefb032016-05-01 14:53:46 -070084- (std::unique_ptr<webrtc::MediaConstraints>)nativeConstraints {
hjon6f5ca082016-01-07 09:29:29 -080085 webrtc::MediaConstraintsInterface::Constraints mandatory =
86 [[self class] nativeConstraintsForConstraints:_mandatory];
87 webrtc::MediaConstraintsInterface::Constraints optional =
88 [[self class] nativeConstraintsForConstraints:_optional];
89
90 webrtc::MediaConstraints *nativeConstraints =
91 new webrtc::MediaConstraints(mandatory, optional);
kwibergbfefb032016-05-01 14:53:46 -070092 return std::unique_ptr<webrtc::MediaConstraints>(nativeConstraints);
hjon6f5ca082016-01-07 09:29:29 -080093}
94
95+ (webrtc::MediaConstraintsInterface::Constraints)
96 nativeConstraintsForConstraints:
Jon Hjelle32e0c012016-03-08 16:04:46 -080097 (NSDictionary<NSString *, NSString *> *)constraints {
hjon6f5ca082016-01-07 09:29:29 -080098 webrtc::MediaConstraintsInterface::Constraints nativeConstraints;
99 for (NSString *key in constraints) {
100 NSAssert([key isKindOfClass:[NSString class]],
101 @"%@ is not an NSString.", key);
hjon6b039952016-02-25 12:32:58 -0800102 NSString *value = [constraints objectForKey:key];
103 NSAssert([value isKindOfClass:[NSString class]],
104 @"%@ is not an NSString.", value);
hjon6f5ca082016-01-07 09:29:29 -0800105 nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint(
hjon6b039952016-02-25 12:32:58 -0800106 key.stdString, value.stdString));
hjon6f5ca082016-01-07 09:29:29 -0800107 }
108 return nativeConstraints;
109}
110
111@end