blob: ecb6ab344b9d5c2676a90b29ef546d9b8cdc1ace [file] [log] [blame]
denicijad17d5362016-11-02 02:56:09 -07001/*
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
denicija2256e042016-11-09 06:26:18 -080011#import "ARDSettingsModel+Private.h"
12#import "ARDSettingsStore.h"
denicijad17d5362016-11-02 02:56:09 -070013#import "WebRTC/RTCMediaConstraints.h"
14
15NS_ASSUME_NONNULL_BEGIN
16static NSArray<NSString *> *videoResolutionsStaticValues() {
17 return @[ @"640x480", @"960x540", @"1280x720" ];
18}
19
sakal68b5df92017-03-17 09:01:59 -070020static NSArray<NSString *> *videoCodecsStaticValues() {
21 return @[ @"H264", @"VP8", @"VP9" ];
22}
23
denicija2256e042016-11-09 06:26:18 -080024@interface ARDSettingsModel () {
25 ARDSettingsStore *_settingsStore;
denicijad17d5362016-11-02 02:56:09 -070026}
27@end
28
denicija2256e042016-11-09 06:26:18 -080029@implementation ARDSettingsModel
denicijad17d5362016-11-02 02:56:09 -070030
sakalc522e752017-04-05 12:17:48 -070031- (NSArray<NSString *> *)availableVideoResolutions {
denicijad17d5362016-11-02 02:56:09 -070032 return videoResolutionsStaticValues();
33}
34
sakalc522e752017-04-05 12:17:48 -070035- (NSString *)currentVideoResolutionSettingFromStore {
36 NSString *resolution = [[self settingsStore] videoResolution];
37 if (!resolution) {
38 resolution = [self defaultVideoResolutionSetting];
denicijad17d5362016-11-02 02:56:09 -070039 // To ensure consistency add the default to the store.
sakalc522e752017-04-05 12:17:48 -070040 [[self settingsStore] setVideoResolution:resolution];
denicijad17d5362016-11-02 02:56:09 -070041 }
sakalc522e752017-04-05 12:17:48 -070042 return resolution;
denicijad17d5362016-11-02 02:56:09 -070043}
44
sakalc522e752017-04-05 12:17:48 -070045- (BOOL)storeVideoResolutionSetting:(NSString *)resolution {
46 if (![[self availableVideoResolutions] containsObject:resolution]) {
denicijad17d5362016-11-02 02:56:09 -070047 return NO;
48 }
sakalc522e752017-04-05 12:17:48 -070049 [[self settingsStore] setVideoResolution:resolution];
denicijad17d5362016-11-02 02:56:09 -070050 return YES;
51}
52
sakal68b5df92017-03-17 09:01:59 -070053- (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
denicija9af2b602016-11-17 00:43:43 -080074- (nullable NSNumber *)currentMaxBitrateSettingFromStore {
75 return [[self settingsStore] maxBitrate];
76}
77
78- (void)storeMaxBitrateSetting:(nullable NSNumber *)bitrate {
79 [[self settingsStore] setMaxBitrate:bitrate];
80}
81
denicijad17d5362016-11-02 02:56:09 -070082#pragma mark - Testable
83
denicija2256e042016-11-09 06:26:18 -080084- (ARDSettingsStore *)settingsStore {
denicijad17d5362016-11-02 02:56:09 -070085 if (!_settingsStore) {
denicija2256e042016-11-09 06:26:18 -080086 _settingsStore = [[ARDSettingsStore alloc] init];
denicijad17d5362016-11-02 02:56:09 -070087 }
88 return _settingsStore;
89}
90
sakalc522e752017-04-05 12:17:48 -070091- (int)currentVideoResolutionWidthFromStore {
92 NSString *resolution = [self currentVideoResolutionSettingFromStore];
denicijad17d5362016-11-02 02:56:09 -070093
sakalc522e752017-04-05 12:17:48 -070094 return [self videoResolutionComponentAtIndex:0 inString:resolution];
denicijad17d5362016-11-02 02:56:09 -070095}
96
sakalc522e752017-04-05 12:17:48 -070097- (int)currentVideoResolutionHeightFromStore {
98 NSString *resolution = [self currentVideoResolutionSettingFromStore];
99 return [self videoResolutionComponentAtIndex:1 inString:resolution];
denicijad17d5362016-11-02 02:56:09 -0700100}
101
102#pragma mark -
103
sakalc522e752017-04-05 12:17:48 -0700104- (NSString *)defaultVideoResolutionSetting {
denicijad17d5362016-11-02 02:56:09 -0700105 return videoResolutionsStaticValues()[0];
106}
107
sakalc522e752017-04-05 12:17:48 -0700108- (int)videoResolutionComponentAtIndex:(int)index inString:(NSString *)resolution {
denicijad17d5362016-11-02 02:56:09 -0700109 if (index != 0 && index != 1) {
sakalc522e752017-04-05 12:17:48 -0700110 return 0;
denicijad17d5362016-11-02 02:56:09 -0700111 }
sakalc522e752017-04-05 12:17:48 -0700112 NSArray<NSString *> *components = [resolution componentsSeparatedByString:@"x"];
denicijad17d5362016-11-02 02:56:09 -0700113 if (components.count != 2) {
sakalc522e752017-04-05 12:17:48 -0700114 return 0;
denicijad17d5362016-11-02 02:56:09 -0700115 }
sakalc522e752017-04-05 12:17:48 -0700116 return components[index].intValue;
denicijad17d5362016-11-02 02:56:09 -0700117}
118
sakal68b5df92017-03-17 09:01:59 -0700119- (NSString *)defaultVideoCodecSetting {
120 return videoCodecsStaticValues()[0];
121}
122
denicijad17d5362016-11-02 02:56:09 -0700123@end
124NS_ASSUME_NONNULL_END