123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- /*
- * Copyright 2016 The WebRTC Project Authors. All rights reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
- #import "ARDSettingsModel+Private.h"
- #import "ARDSettingsStore.h"
- #import "WebRTC/RTCMediaConstraints.h"
- NS_ASSUME_NONNULL_BEGIN
- static NSArray<NSString *> *videoResolutionsStaticValues() {
- return @[ @"480x360", @"640x480", @"960x540", @"1280x720" ];
- }
- static NSArray<NSString *> *videoCodecsStaticValues() {
- return @[ @"H264", @"VP8", @"VP9" ];
- }
- @interface ARDSettingsModel () {
- ARDSettingsStore *_settingsStore;
- }
- @end
- @implementation ARDSettingsModel
- - (NSArray<NSString *> *)availableVideoResolutions {
- return videoResolutionsStaticValues();
- }
- - (NSString *)currentVideoResolutionSettingFromStore {
- NSString *resolution = [[self settingsStore] videoResolution];
- if (!resolution) {
- resolution = [self defaultVideoResolutionSetting];
- // To ensure consistency add the default to the store.
- [[self settingsStore] setVideoResolution:resolution];
- }
- return resolution;
- }
- - (NSString *)readableResolution:(NSString *)resolution {
- NSString *readableResolution = NSLocalizedString(@"Unknown", nil);
- if ([resolution isEqualToString:videoResolutionsStaticValues()[0]]) {
- readableResolution = NSLocalizedString(@"Low", @"TRANSLATORS this is a video quality option (Video quality : Low)");
- } else if ([resolution isEqualToString:videoResolutionsStaticValues()[1]]) {
- readableResolution = NSLocalizedString(@"Normal", @"TRANSLATORS this is a video quality option (Video quality : Normal)");
- } else if ([resolution isEqualToString:videoResolutionsStaticValues()[2]]) {
- readableResolution = NSLocalizedString(@"High", @"TRANSLATORS this is a video quality option (Video quality : High)");
- } else if ([resolution isEqualToString:videoResolutionsStaticValues()[3]]) {
- readableResolution = NSLocalizedString(@"HD", @"TRANSLATORS this is a video quality option (Video quality : HD)");
- }
- return readableResolution;
- }
- - (BOOL)storeVideoResolutionSetting:(NSString *)resolution {
- if (![[self availableVideoResolutions] containsObject:resolution]) {
- return NO;
- }
- [[self settingsStore] setVideoResolution:resolution];
- return YES;
- }
- - (BOOL)videoDisabledSettingFromStore {
- BOOL videoDisabled = [[self settingsStore] videoDisabledDefault];
- if (!videoDisabled) {
- [[self settingsStore] setVideoDisabledDefault:NO];
- }
- return videoDisabled;
- }
- - (void)storeVideoDisabledDefault:(BOOL)disabled {
- [[self settingsStore] setVideoDisabledDefault:disabled];
- }
- - (NSArray<NSString *> *)availableVideoCodecs {
- return videoCodecsStaticValues();
- }
- - (NSString *)currentVideoCodecSettingFromStore {
- NSString *videoCodec = [[self settingsStore] videoCodec];
- if (!videoCodec) {
- videoCodec = [self defaultVideoCodecSetting];
- [[self settingsStore] setVideoCodec:videoCodec];
- }
- return videoCodec;
- }
- - (BOOL)storeVideoCodecSetting:(NSString *)videoCodec {
- if (![[self availableVideoCodecs] containsObject:videoCodec]) {
- return NO;
- }
- [[self settingsStore] setVideoCodec:videoCodec];
- return YES;
- }
- - (nullable NSNumber *)currentMaxBitrateSettingFromStore {
- return [[self settingsStore] maxBitrate];
- }
- - (void)storeMaxBitrateSetting:(nullable NSNumber *)bitrate {
- [[self settingsStore] setMaxBitrate:bitrate];
- }
- #pragma mark - Testable
- - (ARDSettingsStore *)settingsStore {
- if (!_settingsStore) {
- _settingsStore = [[ARDSettingsStore alloc] init];
- }
- return _settingsStore;
- }
- - (int)currentVideoResolutionWidthFromStore {
- NSString *resolution = [self currentVideoResolutionSettingFromStore];
- return [self videoResolutionComponentAtIndex:0 inString:resolution];
- }
- - (int)currentVideoResolutionHeightFromStore {
- NSString *resolution = [self currentVideoResolutionSettingFromStore];
- return [self videoResolutionComponentAtIndex:1 inString:resolution];
- }
- #pragma mark -
- - (NSString *)defaultVideoResolutionSetting {
- return videoResolutionsStaticValues()[1];
- }
- - (int)videoResolutionComponentAtIndex:(int)index inString:(NSString *)resolution {
- if (index != 0 && index != 1) {
- return 0;
- }
- NSArray<NSString *> *components = [resolution componentsSeparatedByString:@"x"];
- if (components.count != 2) {
- return 0;
- }
- return components[index].intValue;
- }
- - (NSString *)defaultVideoCodecSetting {
- return videoCodecsStaticValues()[0];
- }
- @end
- NS_ASSUME_NONNULL_END
|