Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Side by Side Diff: webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsModel.m

Issue 2770113004: Pass settings model to ARDAppClient instead of individual settings. (Closed)
Patch Set: Fix test. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "ARDSettingsModel+Private.h"
12 #import "ARDSettingsStore.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 static NSArray<NSString *> *videoCodecsStaticValues() {
21 return @[ @"H264", @"VP8", @"VP9" ];
22 }
23
24 @interface ARDSettingsModel () {
25 ARDSettingsStore *_settingsStore;
26 }
27 @end
28
29 @implementation ARDSettingsModel
30
31 - (NSArray<NSString *> *)availableVideoResoultionsMediaConstraints {
32 return videoResolutionsStaticValues();
33 }
34
35 - (NSString *)currentVideoResoultionConstraintFromStore {
36 NSString *constraint = [[self settingsStore] videoResolutionConstraints];
37 if (!constraint) {
38 constraint = [self defaultVideoResolutionMediaConstraint];
39 // To ensure consistency add the default to the store.
40 [[self settingsStore] setVideoResolutionConstraints:constraint];
41 }
42 return constraint;
43 }
44
45 - (BOOL)storeVideoResoultionConstraint:(NSString *)constraint {
46 if (![[self availableVideoResoultionsMediaConstraints] containsObject:constrai nt]) {
47 return NO;
48 }
49 [[self settingsStore] setVideoResolutionConstraints:constraint];
50 return YES;
51 }
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
74 - (nullable NSNumber *)currentMaxBitrateSettingFromStore {
75 return [[self settingsStore] maxBitrate];
76 }
77
78 - (void)storeMaxBitrateSetting:(nullable NSNumber *)bitrate {
79 [[self settingsStore] setMaxBitrate:bitrate];
80 }
81
82 #pragma mark - Testable
83
84 - (ARDSettingsStore *)settingsStore {
85 if (!_settingsStore) {
86 _settingsStore = [[ARDSettingsStore alloc] init];
87 }
88 return _settingsStore;
89 }
90
91 - (nullable NSString *)currentVideoResolutionWidthFromStore {
92 NSString *mediaConstraintFromStore = [self currentVideoResoultionConstraintFro mStore];
93
94 return [self videoResolutionComponentAtIndex:0 inConstraintsString:mediaConstr aintFromStore];
95 }
96
97 - (nullable NSString *)currentVideoResolutionHeightFromStore {
98 NSString *mediaConstraintFromStore = [self currentVideoResoultionConstraintFro mStore];
99 return [self videoResolutionComponentAtIndex:1 inConstraintsString:mediaConstr aintFromStore];
100 }
101
102 #pragma mark -
103
104 - (NSString *)defaultVideoResolutionMediaConstraint {
105 return videoResolutionsStaticValues()[0];
106 }
107
108 - (nullable NSString *)videoResolutionComponentAtIndex:(int)index
109 inConstraintsString:(NSString *)constraint {
110 if (index != 0 && index != 1) {
111 return nil;
112 }
113 NSArray *components = [constraint componentsSeparatedByString:@"x"];
114 if (components.count != 2) {
115 return nil;
116 }
117 return components[index];
118 }
119
120 - (NSString *)defaultVideoCodecSetting {
121 return videoCodecsStaticValues()[0];
122 }
123
124 #pragma mark - Conversion to RTCMediaConstraints
125
126 - (nullable NSDictionary *)currentMediaConstraintFromStoreAsRTCDictionary {
127 NSDictionary *mediaConstraintsDictionary = nil;
128
129 NSString *widthConstraint = [self currentVideoResolutionWidthFromStore];
130 NSString *heightConstraint = [self currentVideoResolutionHeightFromStore];
131 if (widthConstraint && heightConstraint) {
132 mediaConstraintsDictionary = @{
133 kRTCMediaConstraintsMinWidth : widthConstraint,
134 kRTCMediaConstraintsMinHeight : heightConstraint
135 };
136 }
137 return mediaConstraintsDictionary;
138 }
139
140 @end
141 NS_ASSUME_NONNULL_END
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698