-
Notifications
You must be signed in to change notification settings - Fork 0
/
autocomplete.c
408 lines (389 loc) · 10.4 KB
/
autocomplete.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
/*****************************************************************************
* autocomplete: x264cli shell autocomplete
*****************************************************************************
* Copyright (C) 2018-2023 x264 project
*
* Authors: Henrik Gramner <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*
* This program is also available under a commercial proprietary license.
* For more information, contact us at [email protected].
*****************************************************************************/
#include "x264cli.h"
#include "input/input.h"
#if HAVE_LAVF
#undef DECLARE_ALIGNED
#include <libavformat/avformat.h>
#include <libavutil/pixdesc.h>
#endif
static const char * const level_names[] =
{
"1", "1.1", "1.2", "1.3", "1b",
"2", "2.1", "2.2",
"3", "3.1", "3.2",
"4", "4.1", "4.2",
"5", "5.1", "5.2",
"6", "6.1", "6.2",
NULL
};
/* Options requiring a value for which we provide suggestions. */
static const char * const opts_suggest[] =
{
"--alternative-transfer",
"--aq-mode",
"--asm",
"--avcintra-class",
"--avcintra-flavor",
"--b-adapt",
"--b-pyramid",
"--colormatrix",
"--colorprim",
"--cqm",
"--demuxer",
"--direct",
"--frame-packing",
"--input-csp",
"--input-fmt",
"--input-range",
"--level",
"--log-level",
"--me",
"--muxer",
"--nal-hrd",
"--output-csp",
"--overscan",
"--pass", "-p",
"--preset",
"--profile",
"--pulldown",
"--range",
"--subme", "-m",
"--transfer",
"--trellis", "-t",
"--tune",
"--videoformat",
"--weightp",
NULL
};
/* Options requiring a value for which we don't provide suggestions. */
static const char * const opts_nosuggest[] =
{
"--b-bias",
"--bframes", "-b",
"--deblock", "-f",
"--bitrate", "-B",
"--chroma-qp-offset",
"--chromaloc",
"--cplxblur",
"--cqm4",
"--cqm4i",
"--cqm4ic",
"--cqm4iy",
"--cqm4p",
"--cqm4pc",
"--cqm4py",
"--cqm8",
"--cqm8i",
"--cqm8p",
"--crf",
"--crf-max",
"--crop-rect",
"--deadzone-inter",
"--deadzone-intra",
"--fps",
"--frames",
"--input-depth",
"--input-res",
"--ipratio",
"--keyint", "-I",
"--lookahead-threads",
"--mastering-display",
"--cll",
"--merange",
"--min-keyint", "-i",
"--mvrange",
"--mvrange-thread",
"--nr",
"--opencl-device",
"--output-depth",
"--partitions", "-A",
"--pbratio",
"--psy-rd",
"--qblur",
"--qcomp",
"--qp", "-q",
"--qpmax",
"--qpmin",
"--qpstep",
"--ratetol",
"--ref", "-r",
"--rc-lookahead",
"--sar",
"--scenecut",
"--seek",
"--slices",
"--slices-max",
"--slice-max-size",
"--slice-max-mbs",
"--slice-min-mbs",
"--sps-id",
"--sync-lookahead",
"--threads",
"--timebase",
"--vbv-bufsize",
"--vbv-init",
"--vbv-maxrate",
"--video-filter", "--vf",
"--zones",
NULL
};
/* Options requiring a filename. */
static const char * const opts_filename[] =
{
"--cqmfile",
"--dump-yuv",
"--index",
"--opencl-clbin",
"--output", "-o",
"--qpfile",
"--stats",
"--tcfile-in",
"--tcfile-out",
NULL
};
/* Options without an associated value. */
static const char * const opts_standalone[] =
{
"--8x8dct",
"--aud",
"--bff",
"--bluray-compat",
"--cabac",
"--constrained-intra",
"--cpu-independent",
"--dts-compress",
"--fake-interlaced",
"--fast-pskip",
"--filler",
"--force-cfr",
"--mbtree",
"--mixed-refs",
"--no-8x8dct",
"--no-asm",
"--no-cabac",
"--no-chroma-me",
"--no-dct-decimate",
"--no-deblock",
"--no-fast-pskip",
"--no-mbtree",
"--no-mixed-refs",
"--no-progress",
"--no-psy",
"--no-scenecut",
"--no-weightb",
"--non-deterministic",
"--open-gop",
"--opencl",
"--pic-struct",
"--psnr",
"--quiet",
"--sliced-threads",
"--slow-firstpass",
"--ssim",
"--stitchable",
"--tff",
"--thread-input",
"--verbose", "-v",
"--weightb",
NULL
};
/* Options which shouldn't be suggested in combination with other options. */
static const char * const opts_special[] =
{
"--fullhelp",
"--help", "-h",
"--longhelp",
"--version",
NULL
};
static int list_contains( const char * const *list, const char *s )
{
if( *s )
for( ; *list; list++ )
if( !strcmp( *list, s ) )
return 1;
return 0;
}
static void suggest( const char *s, const char *cur, int cur_len )
{
if( s && *s && !strncmp( s, cur, cur_len ) )
printf( "%s ", s );
}
static void suggest_lower( const char *s, const char *cur, int cur_len )
{
if( s && *s && !strncasecmp( s, cur, cur_len ) )
{
for( ; *s; s++ )
putchar( *s < 'A' || *s > 'Z' ? *s : *s | 0x20 );
putchar( ' ' );
}
}
static void suggest_num_range( int start, int end, const char *cur, int cur_len )
{
char buf[16];
for( int i = start; i <= end; i++ )
{
snprintf( buf, sizeof( buf ), "%d", i );
suggest( buf, cur, cur_len );
}
}
#if HAVE_LAVF
/* Suggest each token in a string separated by delimiters. */
static void suggest_token( const char *s, int delim, const char *cur, int cur_len )
{
if( s && *s )
{
for( const char *tok_end; (tok_end = strchr( s, delim )); s = tok_end + 1 )
{
int tok_len = tok_end - s;
if( tok_len && tok_len >= cur_len && !strncmp( s, cur, cur_len ) )
printf( "%.*s ", tok_len, s );
}
suggest( s, cur, cur_len );
}
}
#endif
#define OPT( opt ) else if( !strcmp( prev, opt ) )
#define OPT2( opt1, opt2 ) else if( !strcmp( prev, opt1 ) || !strcmp( prev, opt2 ) )
#define OPT_TYPE( type ) list_contains( opts_##type, prev )
#define suggest( s ) suggest( s, cur, cur_len )
#define suggest_lower( s ) suggest_lower( s, cur, cur_len )
#define suggest_list( list ) for( const char * const *s = list; *s; s++ ) suggest( *s )
#define suggest_num_range( start, end ) suggest_num_range( start, end, cur, cur_len )
#define suggest_token( s, delim ) suggest_token( s, delim, cur, cur_len )
int x264_cli_autocomplete( const char *prev, const char *cur )
{
int cur_len = strlen( cur );
if( 0 );
OPT( "--alternative-transfer" )
suggest_list( x264_transfer_names );
OPT( "--aq-mode" )
suggest_num_range( 0, 3 );
OPT( "--asm" )
for( const x264_cpu_name_t *cpu = x264_cpu_names; cpu->flags; cpu++ )
suggest_lower( cpu->name );
OPT( "--avcintra-class" )
suggest_list( x264_avcintra_class_names );
OPT( "--avcintra-flavor" )
suggest_list( x264_avcintra_flavor_names );
OPT( "--b-adapt" )
suggest_num_range( 0, 2 );
OPT( "--b-pyramid" )
suggest_list( x264_b_pyramid_names );
OPT( "--colormatrix" )
suggest_list( x264_colmatrix_names );
OPT( "--colorprim" )
suggest_list( x264_colorprim_names );
OPT( "--cqm" )
suggest_list( x264_cqm_names );
OPT( "--demuxer" )
suggest_list( x264_demuxer_names );
OPT( "--direct" )
suggest_list( x264_direct_pred_names );
OPT( "--frame-packing" )
suggest_num_range( 0, 7 );
OPT( "--input-csp" )
{
for( int i = X264_CSP_NONE+1; i < X264_CSP_CLI_MAX; i++ )
suggest( x264_cli_csps[i].name );
#if HAVE_LAVF
for( const AVPixFmtDescriptor *d = NULL; (d = av_pix_fmt_desc_next( d )); )
suggest( d->name );
#endif
}
OPT( "--input-fmt" )
{
#if HAVE_LAVF
void *i = NULL;
for( const AVInputFormat *f; (f = av_demuxer_iterate( &i )); )
suggest_token( f->name, ',' );
#endif
}
OPT( "--input-range" )
suggest_list( x264_range_names );
OPT( "--level" )
suggest_list( level_names );
OPT( "--log-level" )
suggest_list( x264_log_level_names );
OPT( "--me" )
suggest_list( x264_motion_est_names );
OPT( "--muxer" )
suggest_list( x264_muxer_names );
OPT( "--nal-hrd" )
suggest_list( x264_nal_hrd_names );
OPT( "--output-csp" )
suggest_list( x264_output_csp_names );
OPT( "--output-depth" )
{
#if HAVE_BITDEPTH8
suggest( "8" );
#endif
#if HAVE_BITDEPTH10
suggest( "10" );
#endif
}
OPT( "--overscan" )
suggest_list( x264_overscan_names );
OPT2( "--partitions", "-A" )
suggest_list( x264_partition_names );
OPT2( "--pass", "-p" )
suggest_num_range( 1, 3 );
OPT( "--preset" )
suggest_list( x264_preset_names );
OPT( "--profile" )
suggest_list( x264_valid_profile_names );
OPT( "--pulldown" )
suggest_list( x264_pulldown_names );
OPT( "--range" )
suggest_list( x264_range_names );
OPT2( "--subme", "-m" )
suggest_num_range( 0, 11 );
OPT( "--transfer" )
suggest_list( x264_transfer_names );
OPT2( "--trellis", "-t" )
suggest_num_range( 0, 2 );
OPT( "--tune" )
suggest_list( x264_tune_names );
OPT( "--videoformat" )
suggest_list( x264_vidformat_names );
OPT( "--weightp" )
suggest_num_range( 0, 2 );
else if( !OPT_TYPE( nosuggest ) && !OPT_TYPE( special ) )
{
if( OPT_TYPE( filename ) || strncmp( cur, "--", 2 ) )
return 1; /* Fall back to default shell filename autocomplete. */
/* Suggest options. */
suggest_list( opts_suggest );
suggest_list( opts_nosuggest );
suggest_list( opts_filename );
suggest_list( opts_standalone );
/* Only suggest special options if no other options have been specified. */
if( !*prev )
suggest_list( opts_special );
}
putchar( '\n' );
return 0;
}