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

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

Issue 2735303004: Add video codec setting to AppRTCMobile on iOS. (Closed)
Patch Set: Fix AppRTCMobile on Mac. 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
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 "ARDSettingsViewController.h" 11 #import "ARDSettingsViewController.h"
12 #import "ARDSettingsModel.h" 12 #import "ARDSettingsModel.h"
13 13
14 NS_ASSUME_NONNULL_BEGIN 14 NS_ASSUME_NONNULL_BEGIN
15 15
16 typedef NS_ENUM(int, ARDSettingsSections) { 16 typedef NS_ENUM(int, ARDSettingsSections) {
17 ARDSettingsSectionMediaConstraints = 0, 17 ARDSettingsSectionMediaConstraints = 0,
18 ARDSettingsSectionBitRate 18 ARDSettingsSectionVideoCodec,
19 ARDSettingsSectionBitRate,
19 }; 20 };
20 21
21 @interface ARDSettingsViewController () <UITextFieldDelegate> { 22 @interface ARDSettingsViewController () <UITextFieldDelegate> {
22 ARDSettingsModel *_settingsModel; 23 ARDSettingsModel *_settingsModel;
23 } 24 }
24 25
25 @end 26 @end
26 27
27 @implementation ARDSettingsViewController 28 @implementation ARDSettingsViewController
28 29
29 - (instancetype)initWithStyle:(UITableViewStyle)style 30 - (instancetype)initWithStyle:(UITableViewStyle)style
30 settingsModel:(ARDSettingsModel *)settingsModel { 31 settingsModel:(ARDSettingsModel *)settingsModel {
31 self = [super initWithStyle:style]; 32 self = [super initWithStyle:style];
32 if (self) { 33 if (self) {
33 _settingsModel = settingsModel; 34 _settingsModel = settingsModel;
34 } 35 }
35 return self; 36 return self;
36 } 37 }
37 38
38 #pragma mark - View lifecycle 39 #pragma mark - View lifecycle
39 40
40 - (void)viewDidLoad { 41 - (void)viewDidLoad {
41 [super viewDidLoad]; 42 [super viewDidLoad];
42 self.title = @"Settings"; 43 self.title = @"Settings";
43 [self addDoneBarButton]; 44 [self addDoneBarButton];
44 } 45 }
45 46
47 - (void)viewWillAppear:(BOOL)animated {
48 [super viewWillAppear:animated];
49 [self addCheckmarkInSection:ARDSettingsSectionMediaConstraints
50 withArray:[self mediaConstraintsArray]
51 selecting:[_settingsModel currentVideoResoultionConstraintFr omStore]];
52 [self addCheckmarkInSection:ARDSettingsSectionVideoCodec
53 withArray:[self videoCodecArray]
54 selecting:[_settingsModel currentVideoCodecSettingFromStore] ];
55 }
56
46 - (void)viewDidAppear:(BOOL)animated { 57 - (void)viewDidAppear:(BOOL)animated {
daniela-webrtc 2017/03/20 13:10:07 This can be removed
47 [super viewDidAppear:animated]; 58 [super viewDidAppear:animated];
48 [self selectCurrentlyStoredOrDefaultMediaConstraints];
49 } 59 }
50 60
51 #pragma mark - Data source 61 #pragma mark - Data source
52 62
53 - (NSArray<NSString *> *)mediaConstraintsArray { 63 - (NSArray<NSString *> *)mediaConstraintsArray {
54 return _settingsModel.availableVideoResoultionsMediaConstraints; 64 return _settingsModel.availableVideoResoultionsMediaConstraints;
55 } 65 }
56 66
67 - (NSArray<NSString *> *)videoCodecArray {
68 return _settingsModel.availableVideoCodecs;
69 }
70
57 #pragma mark - 71 #pragma mark -
58 72
59 - (void)addDoneBarButton { 73 - (void)addDoneBarButton {
60 UIBarButtonItem *barItem = 74 UIBarButtonItem *barItem =
61 [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItem Done 75 [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItem Done
62 target:self 76 target:self
63 action:@selector(dismissModa lly:)]; 77 action:@selector(dismissModa lly:)];
64 self.navigationItem.leftBarButtonItem = barItem; 78 self.navigationItem.leftBarButtonItem = barItem;
65 } 79 }
66 80
67 - (void)selectCurrentlyStoredOrDefaultMediaConstraints { 81 - (void)addCheckmarkInSection:(int)section
68 NSString *currentSelection = [_settingsModel currentVideoResoultionConstraintF romStore]; 82 withArray:(NSArray<NSString*>*) array
69 83 selecting:(NSString*)selection {
70 NSUInteger indexOfSelection = [[self mediaConstraintsArray] indexOfObject:curr entSelection]; 84 NSUInteger indexOfSelection = [array indexOfObject:selection];
71 NSIndexPath *pathToBeSelected = [NSIndexPath indexPathForRow:indexOfSelection inSection:0]; 85 NSIndexPath *pathToBeDecorated = [NSIndexPath indexPathForRow:indexOfSelection
72 [self.tableView selectRowAtIndexPath:pathToBeSelected 86 inSection:section];
73 animated:NO 87 UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:pathToBeDecorate d];
74 scrollPosition:UITableViewScrollPositionNone]; 88 cell.accessoryType = UITableViewCellAccessoryCheckmark;
75 // Manully invoke the delegate method because the previous invocation will not .
76 [self tableView:self.tableView didSelectRowAtIndexPath:pathToBeSelected];
77 } 89 }
78 90
79 #pragma mark - Dismissal of view controller 91 #pragma mark - Dismissal of view controller
80 92
81 - (void)dismissModally:(id)sender { 93 - (void)dismissModally:(id)sender {
82 [self dismissViewControllerAnimated:YES completion:nil]; 94 [self dismissViewControllerAnimated:YES completion:nil];
83 } 95 }
84 96
85 #pragma mark - Table view data source 97 #pragma mark - Table view data source
86 98
87 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 99 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
88 return 2; 100 return 3;
89 } 101 }
90 102
91 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger )section { 103 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger )section {
92 if ([self sectionIsMediaConstraints:section]) { 104 switch (section) {
93 return self.mediaConstraintsArray.count; 105 case ARDSettingsSectionMediaConstraints:
106 return self.mediaConstraintsArray.count;
107 case ARDSettingsSectionVideoCodec:
108 return self.videoCodecArray.count;
109 default:
110 return 1;
94 } 111 }
95
96 return 1;
97 } 112 }
98 113
99 #pragma mark - Index path helpers 114 #pragma mark - Table view delegate helpers
100 115
101 - (BOOL)sectionIsMediaConstraints:(int)section { 116 - (void)removeAllAccessories:(UITableView *)tableView
102 return section == ARDSettingsSectionMediaConstraints; 117 inSection:(int)section
118 {
119 for (int i = 0; i < [tableView numberOfRowsInSection:section]; i++) {
120 NSIndexPath *rowPath = [NSIndexPath indexPathForRow:i inSection:section];
121 UITableViewCell *cell = [tableView cellForRowAtIndexPath:rowPath];
122 cell.accessoryType = UITableViewCellAccessoryNone;
123 }
103 } 124 }
104 125
105 - (BOOL)sectionIsBitrate:(int)section { 126 - (void)tableView:(UITableView *)tableView
106 return section == ARDSettingsSectionBitRate; 127 updateListSelectionAtIndexPath:(NSIndexPath *)indexPath
107 } 128 inSection:(int)section {
108 129 [self removeAllAccessories:tableView inSection:section];
109 - (BOOL)indexPathIsMediaConstraints:(NSIndexPath *)indexPath { 130 UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
110 return [self sectionIsMediaConstraints:indexPath.section]; 131 cell.accessoryType = UITableViewCellAccessoryCheckmark;
111 } 132 [tableView deselectRowAtIndexPath:indexPath animated:YES];
112
113 - (BOOL)indexPathIsBitrate:(NSIndexPath *)indexPath {
114 return [self sectionIsBitrate:indexPath.section];
115 } 133 }
116 134
117 #pragma mark - Table view delegate 135 #pragma mark - Table view delegate
118 136
119 - (nullable NSString *)tableView:(UITableView *)tableView 137 - (nullable NSString *)tableView:(UITableView *)tableView
120 titleForHeaderInSection:(NSInteger)section { 138 titleForHeaderInSection:(NSInteger)section {
121 if ([self sectionIsMediaConstraints:section]) { 139 switch (section) {
122 return @"Media constraints"; 140 case ARDSettingsSectionMediaConstraints:
141 return @"Media constraints";
142 case ARDSettingsSectionVideoCodec:
143 return @"Video codec";
144 case ARDSettingsSectionBitRate:
145 return @"Maximum bitrate";
146 default:
147 return @"";
123 } 148 }
124
125 if ([self sectionIsBitrate:section]) {
126 return @"Maximum bitrate";
127 }
128
129 return @"";
130 } 149 }
131 150
132 - (UITableViewCell *)tableView:(UITableView *)tableView 151 - (UITableViewCell *)tableView:(UITableView *)tableView
133 cellForRowAtIndexPath:(NSIndexPath *)indexPath { 152 cellForRowAtIndexPath:(NSIndexPath *)indexPath {
134 if ([self indexPathIsMediaConstraints:indexPath]) { 153 switch (indexPath.section) {
135 return [self mediaConstraintsTableViewCellForTableView:tableView atIndexPath :indexPath]; 154 case ARDSettingsSectionMediaConstraints:
155 return [self mediaConstraintsTableViewCellForTableView:tableView atIndexPa th:indexPath];
156
157 case ARDSettingsSectionVideoCodec:
158 return [self videoCodecTableViewCellForTableView:tableView atIndexPath:ind exPath];
159
160 case ARDSettingsSectionBitRate:
161 return [self bitrateTableViewCellForTableView:tableView atIndexPath:indexP ath];
162
163 default:
164 return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
165 reuseIdentifier:@"identifier"];
136 } 166 }
137
138 if ([self indexPathIsBitrate:indexPath]) {
139 return [self bitrateTableViewCellForTableView:tableView atIndexPath:indexPat h];
140 }
141
142 return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
143 reuseIdentifier:@"identifier"];
144 }
145
146 - (nullable NSIndexPath *)tableView:(UITableView *)tableView
147 willSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
148 if ([self indexPathIsMediaConstraints:indexPath]) {
149 return [self tableView:tableView willDeselectMediaConstraintsRowAtIndexPath: indexPath];
150 }
151 return indexPath;
152 } 167 }
153 168
154 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 169 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
155 if ([self indexPathIsMediaConstraints:indexPath]) { 170 switch (indexPath.section) {
156 [self tableView:tableView didSelectMediaConstraintsCellAtIndexPath:indexPath ]; 171 case ARDSettingsSectionMediaConstraints:
172 [self tableView:tableView didSelectMediaConstraintsCellAtIndexPath:indexPa th];
173 break;
174
175 case ARDSettingsSectionVideoCodec:
176 [self tableView:tableView didSelectVideoCodecCellAtIndexPath:indexPath];
177 break;
157 } 178 }
158 } 179 }
159 180
160 #pragma mark - Table view delegate(Media Constraints) 181 #pragma mark - Table view delegate(Media Constraints)
161 182
162 - (UITableViewCell *)mediaConstraintsTableViewCellForTableView:(UITableView *)ta bleView 183 - (UITableViewCell *)mediaConstraintsTableViewCellForTableView:(UITableView *)ta bleView
163 atIndexPath:(NSIndexPath *)in dexPath { 184 atIndexPath:(NSIndexPath *)in dexPath {
164 NSString *dequeueIdentifier = @"ARDSettingsMediaConstraintsViewCellIdentifier" ; 185 NSString *dequeueIdentifier = @"ARDSettingsMediaConstraintsViewCellIdentifier" ;
165 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dequeueId entifier]; 186 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dequeueId entifier];
166 if (!cell) { 187 if (!cell) {
167 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 188 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
168 reuseIdentifier:dequeueIdentifier]; 189 reuseIdentifier:dequeueIdentifier];
169 } 190 }
170 cell.textLabel.text = self.mediaConstraintsArray[indexPath.row]; 191 cell.textLabel.text = self.mediaConstraintsArray[indexPath.row];
171 return cell; 192 return cell;
172 } 193 }
173 194
174 - (void)tableView:(UITableView *)tableView 195 - (void)tableView:(UITableView *)tableView
175 didSelectMediaConstraintsCellAtIndexPath:(NSIndexPath *)indexPath { 196 didSelectMediaConstraintsCellAtIndexPath:(NSIndexPath *)indexPath {
176 UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 197 [self tableView:tableView
177 cell.accessoryType = UITableViewCellAccessoryCheckmark; 198 updateListSelectionAtIndexPath:indexPath
199 inSection:ARDSettingsSectionMediaConstraints];
178 200
179 NSString *mediaConstraintsString = self.mediaConstraintsArray[indexPath.row]; 201 NSString *mediaConstraintsString = self.mediaConstraintsArray[indexPath.row];
180 [_settingsModel storeVideoResoultionConstraint:mediaConstraintsString]; 202 [_settingsModel storeVideoResoultionConstraint:mediaConstraintsString];
181 } 203 }
182 204
183 - (NSIndexPath *)tableView:(UITableView *)tableView 205 #pragma mark - Table view delegate(Video Codec)
184 willDeselectMediaConstraintsRowAtIndexPath:(NSIndexPath *)indexPath { 206
185 NSIndexPath *oldSelection = [tableView indexPathForSelectedRow]; 207 - (UITableViewCell *)videoCodecTableViewCellForTableView:(UITableView *)tableVie w
186 UITableViewCell *cell = [tableView cellForRowAtIndexPath:oldSelection]; 208 atIndexPath:(NSIndexPath *)indexPat h {
187 cell.accessoryType = UITableViewCellAccessoryNone; 209 NSString *dequeueIdentifier = @"ARDSettingsVideoCodecCellIdentifier";
188 return indexPath; 210 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dequeueId entifier];
211 if (!cell) {
212 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
213 reuseIdentifier:dequeueIdentifier];
214 }
215 cell.textLabel.text = self.videoCodecArray[indexPath.row];
216
217 return cell;
218 }
219
220 - (void)tableView:(UITableView *)tableView
221 didSelectVideoCodecCellAtIndexPath:(NSIndexPath *)indexPath {
222 [self tableView:tableView
223 updateListSelectionAtIndexPath:indexPath
224 inSection:ARDSettingsSectionVideoCodec];
225
226 NSString *videoCodec = self.videoCodecArray[indexPath.row];
227 [_settingsModel storeVideoCodecSetting:videoCodec];
189 } 228 }
190 229
191 #pragma mark - Table view delegate(Bitrate) 230 #pragma mark - Table view delegate(Bitrate)
192 231
193 - (UITableViewCell *)bitrateTableViewCellForTableView:(UITableView *)tableView 232 - (UITableViewCell *)bitrateTableViewCellForTableView:(UITableView *)tableView
194 atIndexPath:(NSIndexPath *)indexPath { 233 atIndexPath:(NSIndexPath *)indexPath {
195 NSString *dequeueIdentifier = @"ARDSettingsBitrateCellIdentifier"; 234 NSString *dequeueIdentifier = @"ARDSettingsBitrateCellIdentifier";
196 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dequeueId entifier]; 235 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dequeueId entifier];
197 if (!cell) { 236 if (!cell) {
198 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 237 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 274
236 if (textField.text.length != 0) { 275 if (textField.text.length != 0) {
237 bitrateNumber = [NSNumber numberWithInteger:textField.text.intValue]; 276 bitrateNumber = [NSNumber numberWithInteger:textField.text.intValue];
238 } 277 }
239 278
240 [_settingsModel storeMaxBitrateSetting:bitrateNumber]; 279 [_settingsModel storeMaxBitrateSetting:bitrateNumber];
241 } 280 }
242 281
243 @end 282 @end
244 NS_ASSUME_NONNULL_END 283 NS_ASSUME_NONNULL_END
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698