OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2016 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 "ARDMediaConstraintsModel+Private.h" | |
12 #import "ARDMediaConstraintsSettingsStore.h" | |
13 #import "WebRTC/RTCMediaConstraints.h" | |
14 | |
15 NS_ASSUME_NONNULL_BEGIN | |
16 static NSArray<NSString *> *videoResolutionsStaticValues() { | |
17 return @[ @"640x480", @"960x540", @"1280x720" ]; | |
18 } | |
19 | |
20 @interface ARDMediaConstraintsModel () { | |
21 ARDMediaConstraintsSettingsStore *_settingsStore; | |
22 } | |
23 @end | |
24 | |
25 @implementation ARDMediaConstraintsModel | |
26 | |
27 - (NSArray<NSString *> *)availableVideoResoultionsMediaConstraints { | |
28 return videoResolutionsStaticValues(); | |
29 } | |
30 | |
31 - (NSString *)currentVideoResoultionConstraintFromStore { | |
32 NSString *constraint = [[self settingsStore] videoResolutionConstraintsSetting ]; | |
33 if (!constraint) { | |
34 constraint = [self defaultVideoResolutionMediaConstraint]; | |
35 // To ensure consistency add the default to the store. | |
36 [[self settingsStore] setVideoResolutionConstraintsSetting:constraint]; | |
37 } | |
38 return constraint; | |
39 } | |
40 | |
41 - (void)storeVideoResoultionConstraint:(NSString *)constraint { | |
42 [[self settingsStore] setVideoResolutionConstraintsSetting:constraint]; | |
magjed_webrtc
2016/10/31 19:26:39
Should we verify that |constraint| is one of the a
daniela-webrtc
2016/11/01 09:51:12
Yes! I missed that. Thanks
| |
43 } | |
44 | |
45 #pragma mark - Testable | |
46 | |
47 - (ARDMediaConstraintsSettingsStore *)settingsStore { | |
48 if (!_settingsStore) { | |
49 _settingsStore = [[ARDMediaConstraintsSettingsStore alloc] init]; | |
50 } | |
51 return _settingsStore; | |
52 } | |
53 | |
54 - (nullable NSString *)currentVideoResolutionWidthFromStore { | |
55 NSString *mediaConstraintFromStore = [self currentVideoResoultionConstraintFro mStore]; | |
56 | |
57 return [self videoResolutionComponentAtIndex:0 inConstraintsString:mediaConstr aintFromStore]; | |
58 } | |
59 | |
60 - (nullable NSString *)currentVideoResolutionHeightFromStore { | |
61 NSString *mediaConstraintFromStore = [self currentVideoResoultionConstraintFro mStore]; | |
62 return [self videoResolutionComponentAtIndex:1 inConstraintsString:mediaConstr aintFromStore]; | |
63 } | |
64 | |
65 #pragma mark - | |
66 | |
67 - (NSString *)defaultVideoResolutionMediaConstraint { | |
68 return videoResolutionsStaticValues()[0]; | |
69 } | |
70 | |
71 - (nullable NSString *)videoResolutionComponentAtIndex:(int)index | |
72 inConstraintsString:(NSString *)constraint { | |
73 if (index != 0 && index != 1) { | |
74 return nil; | |
75 } | |
76 NSArray *components = [constraint componentsSeparatedByString:@"x"]; | |
77 if (components.count != 2) { | |
78 return nil; | |
79 } | |
80 return components[index]; | |
81 } | |
82 | |
83 #pragma mark - Conversion to RTCMediaConstraints | |
84 | |
85 - (nullable NSDictionary *)currentMediaConstraintFromStoreAsRTCDictionary { | |
86 NSDictionary *mediaConstraintsDictionary = nil; | |
87 | |
88 NSString *widthConstraint = [self currentVideoResolutionWidthFromStore]; | |
89 NSString *heightConstraint = [self currentVideoResolutionHeightFromStore]; | |
90 if (widthConstraint && heightConstraint) { | |
91 mediaConstraintsDictionary = @{ | |
92 kRTCMediaConstraintsMinWidth : widthConstraint, | |
93 kRTCMediaConstraintsMinHeight : heightConstraint | |
94 }; | |
95 } | |
96 return mediaConstraintsDictionary; | |
97 } | |
98 | |
99 @end | |
100 NS_ASSUME_NONNULL_END | |
OLD | NEW |