| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #import "ARDSettingsModel+Private.h" | 11 #import "ARDSettingsModel+Private.h" |
| 12 #import "ARDSettingsStore.h" | 12 #import "ARDSettingsStore.h" |
| 13 #import "WebRTC/RTCMediaConstraints.h" | 13 #import "WebRTC/RTCMediaConstraints.h" |
| 14 | 14 |
| 15 NS_ASSUME_NONNULL_BEGIN | 15 NS_ASSUME_NONNULL_BEGIN |
| 16 static NSArray<NSString *> *videoResolutionsStaticValues() { | 16 static NSArray<NSString *> *videoResolutionsStaticValues() { |
| 17 return @[ @"640x480", @"960x540", @"1280x720" ]; | 17 return @[ @"640x480", @"960x540", @"1280x720" ]; |
| 18 } | 18 } |
| 19 | 19 |
| 20 static NSArray<NSString *> *videoCodecsStaticValues() { |
| 21 return @[ @"H264", @"VP8", @"VP9" ]; |
| 22 } |
| 23 |
| 20 @interface ARDSettingsModel () { | 24 @interface ARDSettingsModel () { |
| 21 ARDSettingsStore *_settingsStore; | 25 ARDSettingsStore *_settingsStore; |
| 22 } | 26 } |
| 23 @end | 27 @end |
| 24 | 28 |
| 25 @implementation ARDSettingsModel | 29 @implementation ARDSettingsModel |
| 26 | 30 |
| 27 - (NSArray<NSString *> *)availableVideoResoultionsMediaConstraints { | 31 - (NSArray<NSString *> *)availableVideoResoultionsMediaConstraints { |
| 28 return videoResolutionsStaticValues(); | 32 return videoResolutionsStaticValues(); |
| 29 } | 33 } |
| 30 | 34 |
| 31 - (NSString *)currentVideoResoultionConstraintFromStore { | 35 - (NSString *)currentVideoResoultionConstraintFromStore { |
| 32 NSString *constraint = [[self settingsStore] videoResolutionConstraints]; | 36 NSString *constraint = [[self settingsStore] videoResolutionConstraints]; |
| 33 if (!constraint) { | 37 if (!constraint) { |
| 34 constraint = [self defaultVideoResolutionMediaConstraint]; | 38 constraint = [self defaultVideoResolutionMediaConstraint]; |
| 35 // To ensure consistency add the default to the store. | 39 // To ensure consistency add the default to the store. |
| 36 [[self settingsStore] setVideoResolutionConstraints:constraint]; | 40 [[self settingsStore] setVideoResolutionConstraints:constraint]; |
| 37 } | 41 } |
| 38 return constraint; | 42 return constraint; |
| 39 } | 43 } |
| 40 | 44 |
| 41 - (BOOL)storeVideoResoultionConstraint:(NSString *)constraint { | 45 - (BOOL)storeVideoResoultionConstraint:(NSString *)constraint { |
| 42 if (![[self availableVideoResoultionsMediaConstraints] containsObject:constrai
nt]) { | 46 if (![[self availableVideoResoultionsMediaConstraints] containsObject:constrai
nt]) { |
| 43 return NO; | 47 return NO; |
| 44 } | 48 } |
| 45 [[self settingsStore] setVideoResolutionConstraints:constraint]; | 49 [[self settingsStore] setVideoResolutionConstraints:constraint]; |
| 46 return YES; | 50 return YES; |
| 47 } | 51 } |
| 48 | 52 |
| 53 - (NSArray<NSString *> *)availableVideoCodecs { |
| 54 return videoCodecsStaticValues(); |
| 55 } |
| 56 |
| 57 - (NSString *)currentVideoCodecSettingFromStore { |
| 58 NSString *videoCodec = [[self settingsStore] videoCodec]; |
| 59 if (!videoCodec) { |
| 60 videoCodec = [self defaultVideoCodecSetting]; |
| 61 [[self settingsStore] setVideoCodec:videoCodec]; |
| 62 } |
| 63 return videoCodec; |
| 64 } |
| 65 |
| 66 - (BOOL)storeVideoCodecSetting:(NSString *)videoCodec { |
| 67 if (![[self availableVideoCodecs] containsObject:videoCodec]) { |
| 68 return NO; |
| 69 } |
| 70 [[self settingsStore] setVideoCodec:videoCodec]; |
| 71 return YES; |
| 72 } |
| 73 |
| 49 - (nullable NSNumber *)currentMaxBitrateSettingFromStore { | 74 - (nullable NSNumber *)currentMaxBitrateSettingFromStore { |
| 50 return [[self settingsStore] maxBitrate]; | 75 return [[self settingsStore] maxBitrate]; |
| 51 } | 76 } |
| 52 | 77 |
| 53 - (void)storeMaxBitrateSetting:(nullable NSNumber *)bitrate { | 78 - (void)storeMaxBitrateSetting:(nullable NSNumber *)bitrate { |
| 54 [[self settingsStore] setMaxBitrate:bitrate]; | 79 [[self settingsStore] setMaxBitrate:bitrate]; |
| 55 } | 80 } |
| 56 | 81 |
| 57 #pragma mark - Testable | 82 #pragma mark - Testable |
| 58 | 83 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 85 if (index != 0 && index != 1) { | 110 if (index != 0 && index != 1) { |
| 86 return nil; | 111 return nil; |
| 87 } | 112 } |
| 88 NSArray *components = [constraint componentsSeparatedByString:@"x"]; | 113 NSArray *components = [constraint componentsSeparatedByString:@"x"]; |
| 89 if (components.count != 2) { | 114 if (components.count != 2) { |
| 90 return nil; | 115 return nil; |
| 91 } | 116 } |
| 92 return components[index]; | 117 return components[index]; |
| 93 } | 118 } |
| 94 | 119 |
| 120 - (NSString *)defaultVideoCodecSetting { |
| 121 return videoCodecsStaticValues()[0]; |
| 122 } |
| 123 |
| 95 #pragma mark - Conversion to RTCMediaConstraints | 124 #pragma mark - Conversion to RTCMediaConstraints |
| 96 | 125 |
| 97 - (nullable NSDictionary *)currentMediaConstraintFromStoreAsRTCDictionary { | 126 - (nullable NSDictionary *)currentMediaConstraintFromStoreAsRTCDictionary { |
| 98 NSDictionary *mediaConstraintsDictionary = nil; | 127 NSDictionary *mediaConstraintsDictionary = nil; |
| 99 | 128 |
| 100 NSString *widthConstraint = [self currentVideoResolutionWidthFromStore]; | 129 NSString *widthConstraint = [self currentVideoResolutionWidthFromStore]; |
| 101 NSString *heightConstraint = [self currentVideoResolutionHeightFromStore]; | 130 NSString *heightConstraint = [self currentVideoResolutionHeightFromStore]; |
| 102 if (widthConstraint && heightConstraint) { | 131 if (widthConstraint && heightConstraint) { |
| 103 mediaConstraintsDictionary = @{ | 132 mediaConstraintsDictionary = @{ |
| 104 kRTCMediaConstraintsMinWidth : widthConstraint, | 133 kRTCMediaConstraintsMinWidth : widthConstraint, |
| 105 kRTCMediaConstraintsMinHeight : heightConstraint | 134 kRTCMediaConstraintsMinHeight : heightConstraint |
| 106 }; | 135 }; |
| 107 } | 136 } |
| 108 return mediaConstraintsDictionary; | 137 return mediaConstraintsDictionary; |
| 109 } | 138 } |
| 110 | 139 |
| 111 @end | 140 @end |
| 112 NS_ASSUME_NONNULL_END | 141 NS_ASSUME_NONNULL_END |
| OLD | NEW |