@@ -160,67 +160,93 @@ private static Options createOptions(String... args) {
160
160
"The server version (" + BuildConfig .VERSION_NAME + ") does not match the client " + "(" + clientVersion + ")" );
161
161
}
162
162
163
- final int expectedParameters = 17 ;
164
- if (args .length != expectedParameters ) {
165
- throw new IllegalArgumentException ("Expecting " + expectedParameters + " parameters" );
166
- }
167
-
168
163
Options options = new Options ();
169
164
170
- Ln .Level level = Ln .Level .valueOf (args [1 ].toUpperCase (Locale .ENGLISH ));
171
- options .setLogLevel (level );
172
-
173
- int maxSize = Integer .parseInt (args [2 ]) & ~7 ; // multiple of 8
174
- options .setMaxSize (maxSize );
175
-
176
- int bitRate = Integer .parseInt (args [3 ]);
177
- options .setBitRate (bitRate );
178
-
179
- int maxFps = Integer .parseInt (args [4 ]);
180
- options .setMaxFps (maxFps );
181
-
182
- int lockedVideoOrientation = Integer .parseInt (args [5 ]);
183
- options .setLockedVideoOrientation (lockedVideoOrientation );
184
-
185
- // use "adb forward" instead of "adb tunnel"? (so the server must listen)
186
- boolean tunnelForward = Boolean .parseBoolean (args [6 ]);
187
- options .setTunnelForward (tunnelForward );
188
-
189
- Rect crop = parseCrop (args [7 ]);
190
- options .setCrop (crop );
191
-
192
- boolean sendFrameMeta = Boolean .parseBoolean (args [8 ]);
193
- options .setSendFrameMeta (sendFrameMeta );
194
-
195
- boolean control = Boolean .parseBoolean (args [9 ]);
196
- options .setControl (control );
197
-
198
- int displayId = Integer .parseInt (args [10 ]);
199
- options .setDisplayId (displayId );
200
-
201
- boolean showTouches = Boolean .parseBoolean (args [11 ]);
202
- options .setShowTouches (showTouches );
203
-
204
- boolean stayAwake = Boolean .parseBoolean (args [12 ]);
205
- options .setStayAwake (stayAwake );
206
-
207
- List <CodecOption > codecOptions = CodecOption .parse (args [13 ]);
208
- options .setCodecOptions (codecOptions );
209
-
210
- String encoderName = "-" .equals (args [14 ]) ? null : args [14 ];
211
- options .setEncoderName (encoderName );
212
-
213
- boolean powerOffScreenOnClose = Boolean .parseBoolean (args [15 ]);
214
- options .setPowerOffScreenOnClose (powerOffScreenOnClose );
215
-
216
- boolean clipboardAutosync = Boolean .parseBoolean (args [16 ]);
217
- options .setClipboardAutosync (clipboardAutosync );
165
+ for (int i = 1 ; i < args .length ; ++i ) {
166
+ String arg = args [i ];
167
+ int equalIndex = arg .indexOf ('=' );
168
+ if (equalIndex == -1 ) {
169
+ throw new IllegalArgumentException ("Invalid key=value pair: \" " + arg + "\" " );
170
+ }
171
+ String key = arg .substring (0 , equalIndex );
172
+ String value = arg .substring (equalIndex + 1 );
173
+ switch (key ) {
174
+ case "log_level" :
175
+ Ln .Level level = Ln .Level .valueOf (value .toUpperCase (Locale .ENGLISH ));
176
+ options .setLogLevel (level );
177
+ break ;
178
+ case "max_size" :
179
+ int maxSize = Integer .parseInt (value ) & ~7 ; // multiple of 8
180
+ options .setMaxSize (maxSize );
181
+ break ;
182
+ case "bit_rate" :
183
+ int bitRate = Integer .parseInt (value );
184
+ options .setBitRate (bitRate );
185
+ break ;
186
+ case "max_fps" :
187
+ int maxFps = Integer .parseInt (value );
188
+ options .setMaxFps (maxFps );
189
+ break ;
190
+ case "lock_video_orientation" :
191
+ int lockedVideoOrientation = Integer .parseInt (value );
192
+ options .setLockedVideoOrientation (lockedVideoOrientation );
193
+ break ;
194
+ case "tunnel_forward" :
195
+ boolean tunnelForward = Boolean .parseBoolean (value );
196
+ options .setTunnelForward (tunnelForward );
197
+ break ;
198
+ case "crop" :
199
+ Rect crop = parseCrop (value );
200
+ options .setCrop (crop );
201
+ break ;
202
+ case "send_frame_meta" :
203
+ boolean sendFrameMeta = Boolean .parseBoolean (value );
204
+ options .setSendFrameMeta (sendFrameMeta );
205
+ break ;
206
+ case "control" :
207
+ boolean control = Boolean .parseBoolean (value );
208
+ options .setControl (control );
209
+ break ;
210
+ case "display_id" :
211
+ int displayId = Integer .parseInt (value );
212
+ options .setDisplayId (displayId );
213
+ break ;
214
+ case "show_touches" :
215
+ boolean showTouches = Boolean .parseBoolean (value );
216
+ options .setShowTouches (showTouches );
217
+ break ;
218
+ case "stay_awake" :
219
+ boolean stayAwake = Boolean .parseBoolean (value );
220
+ options .setStayAwake (stayAwake );
221
+ break ;
222
+ case "codec_options" :
223
+ List <CodecOption > codecOptions = CodecOption .parse (value );
224
+ options .setCodecOptions (codecOptions );
225
+ break ;
226
+ case "encoder_name" :
227
+ if (!value .isEmpty ()) {
228
+ options .setEncoderName (value );
229
+ }
230
+ break ;
231
+ case "power_off_on_close" :
232
+ boolean powerOffScreenOnClose = Boolean .parseBoolean (value );
233
+ options .setPowerOffScreenOnClose (powerOffScreenOnClose );
234
+ break ;
235
+ case "clipboard_autosync" :
236
+ boolean clipboardAutosync = Boolean .parseBoolean (value );
237
+ options .setClipboardAutosync (clipboardAutosync );
238
+ break ;
239
+ default :
240
+ Ln .w ("Unknown server option: " + key );
241
+ break ;
242
+ }
243
+ }
218
244
219
245
return options ;
220
246
}
221
247
222
248
private static Rect parseCrop (String crop ) {
223
- if ("-" . equals ( crop )) {
249
+ if (crop . isEmpty ( )) {
224
250
return null ;
225
251
}
226
252
// input format: "width:height:x:y"
0 commit comments