denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 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 | |
denicija | 2256e04 | 2016-11-09 06:26:18 -0800 | [diff] [blame] | 11 | #import "ARDSettingsModel+Private.h" |
| 12 | #import "ARDSettingsStore.h" |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 13 | #import "WebRTC/RTCMediaConstraints.h" |
| 14 | |
| 15 | NS_ASSUME_NONNULL_BEGIN |
| 16 | static NSArray<NSString *> *videoResolutionsStaticValues() { |
| 17 | return @[ @"640x480", @"960x540", @"1280x720" ]; |
| 18 | } |
| 19 | |
sakal | 68b5df9 | 2017-03-17 09:01:59 -0700 | [diff] [blame] | 20 | static NSArray<NSString *> *videoCodecsStaticValues() { |
| 21 | return @[ @"H264", @"VP8", @"VP9" ]; |
| 22 | } |
| 23 | |
denicija | 2256e04 | 2016-11-09 06:26:18 -0800 | [diff] [blame] | 24 | @interface ARDSettingsModel () { |
| 25 | ARDSettingsStore *_settingsStore; |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 26 | } |
| 27 | @end |
| 28 | |
denicija | 2256e04 | 2016-11-09 06:26:18 -0800 | [diff] [blame] | 29 | @implementation ARDSettingsModel |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 30 | |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 31 | - (NSArray<NSString *> *)availableVideoResolutions { |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 32 | return videoResolutionsStaticValues(); |
| 33 | } |
| 34 | |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 35 | - (NSString *)currentVideoResolutionSettingFromStore { |
| 36 | NSString *resolution = [[self settingsStore] videoResolution]; |
| 37 | if (!resolution) { |
| 38 | resolution = [self defaultVideoResolutionSetting]; |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 39 | // To ensure consistency add the default to the store. |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 40 | [[self settingsStore] setVideoResolution:resolution]; |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 41 | } |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 42 | return resolution; |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 43 | } |
| 44 | |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 45 | - (BOOL)storeVideoResolutionSetting:(NSString *)resolution { |
| 46 | if (![[self availableVideoResolutions] containsObject:resolution]) { |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 47 | return NO; |
| 48 | } |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 49 | [[self settingsStore] setVideoResolution:resolution]; |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 50 | return YES; |
| 51 | } |
| 52 | |
sakal | 68b5df9 | 2017-03-17 09:01:59 -0700 | [diff] [blame] | 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 | |
denicija | 9af2b60 | 2016-11-17 00:43:43 -0800 | [diff] [blame] | 74 | - (nullable NSNumber *)currentMaxBitrateSettingFromStore { |
| 75 | return [[self settingsStore] maxBitrate]; |
| 76 | } |
| 77 | |
| 78 | - (void)storeMaxBitrateSetting:(nullable NSNumber *)bitrate { |
| 79 | [[self settingsStore] setMaxBitrate:bitrate]; |
| 80 | } |
| 81 | |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 82 | #pragma mark - Testable |
| 83 | |
denicija | 2256e04 | 2016-11-09 06:26:18 -0800 | [diff] [blame] | 84 | - (ARDSettingsStore *)settingsStore { |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 85 | if (!_settingsStore) { |
denicija | 2256e04 | 2016-11-09 06:26:18 -0800 | [diff] [blame] | 86 | _settingsStore = [[ARDSettingsStore alloc] init]; |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 87 | } |
| 88 | return _settingsStore; |
| 89 | } |
| 90 | |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 91 | - (int)currentVideoResolutionWidthFromStore { |
| 92 | NSString *resolution = [self currentVideoResolutionSettingFromStore]; |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 93 | |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 94 | return [self videoResolutionComponentAtIndex:0 inString:resolution]; |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 95 | } |
| 96 | |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 97 | - (int)currentVideoResolutionHeightFromStore { |
| 98 | NSString *resolution = [self currentVideoResolutionSettingFromStore]; |
| 99 | return [self videoResolutionComponentAtIndex:1 inString:resolution]; |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | #pragma mark - |
| 103 | |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 104 | - (NSString *)defaultVideoResolutionSetting { |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 105 | return videoResolutionsStaticValues()[0]; |
| 106 | } |
| 107 | |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 108 | - (int)videoResolutionComponentAtIndex:(int)index inString:(NSString *)resolution { |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 109 | if (index != 0 && index != 1) { |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 110 | return 0; |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 111 | } |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 112 | NSArray<NSString *> *components = [resolution componentsSeparatedByString:@"x"]; |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 113 | if (components.count != 2) { |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 114 | return 0; |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 115 | } |
sakal | c522e75 | 2017-04-05 12:17:48 -0700 | [diff] [blame^] | 116 | return components[index].intValue; |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 117 | } |
| 118 | |
sakal | 68b5df9 | 2017-03-17 09:01:59 -0700 | [diff] [blame] | 119 | - (NSString *)defaultVideoCodecSetting { |
| 120 | return videoCodecsStaticValues()[0]; |
| 121 | } |
| 122 | |
denicija | d17d536 | 2016-11-02 02:56:09 -0700 | [diff] [blame] | 123 | @end |
| 124 | NS_ASSUME_NONNULL_END |