Skip to content

Commit

Permalink
Added help and parsing of the codec-profile option
Browse files Browse the repository at this point in the history
(cherry picked from commit e158243)
  • Loading branch information
Tzah Mazuz committed Mar 18, 2020
1 parent ef95046 commit a4ef318
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/scrcpy.1
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ Set the initial window height.

Default is 0 (automatic).\n

.TP
.BI "\-P, \-\-\codec\-profile " value
Request specific encoding codec profile, see AVC profiles at: https://developer.android.com/reference/android/media/MediaCodecInfo.CodecProfileLevel for valid codec profile values. Default is 0 (automatic).

.SH SHORTCUTS

.TP
Expand Down
42 changes: 41 additions & 1 deletion app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ scrcpy_print_usage(const char *arg0) {
" Set the initial window width.\n"
" Default is 0 (automatic).\n"
"\n"
" -P, --codec-profile value\n"
" Request specific encoding codec profile, see AVC profiles at:\n"
" https://developer.android.com/reference/android/media/MediaCodecInfo.CodecProfileLevel\n"
" for valid codec profile values.\n"
" Default is 0 (automatic).\n"
"\n"
"Shortcuts:\n"
"\n"
" " CTRL_OR_CMD "+f\n"
Expand Down Expand Up @@ -311,6 +317,35 @@ parse_record_format(const char *optarg, enum recorder_format *format) {
return false;
}

static bool
parse_codec_profile(const char *optarg, uint32_t *codec_profile) {
long value;
// long may be 32 bits (it is the case on mingw), so do not use more than
// 31 bits (long is signed)
bool ok = parse_integer_arg(optarg, &value, true, 0, 0x7FFFFFFF, "codec-profile");
if (!ok) {
return false;
}

switch (value) {
case 0: // Automatic
case 0x01: // AVCProfileBaseline
case 0x02: // AVCProfileMain
case 0x04: // AVCProfileExtended
case 0x08: // AVCProfileHigh
case 0x10: // AVCProfileHigh10
case 0x20: // AVCProfileHigh422
case 0x40: // AVCProfileHigh444
case 0x10000: // AVCProfileConstrainedBaseline
case 0x80000: // AVCProfileConstrainedHigh
*codec_profile = (uint32_t) value;
return true;
default:
LOGE("Invalid codec-profile, Use -h for help");
return false;
}
}

static enum recorder_format
guess_record_format(const char *filename) {
size_t len = strlen(filename);
Expand Down Expand Up @@ -380,7 +415,7 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
optind = 0; // reset to start from the first argument in tests

int c;
while ((c = getopt_long(argc, argv, "b:c:fF:hm:nNp:r:s:StTv", long_options,
while ((c = getopt_long(argc, argv, "b:c:fF:hm:nNp:r:s:StTv:P:", long_options,
NULL)) != -1) {
switch (c) {
case 'b':
Expand Down Expand Up @@ -485,6 +520,11 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
case OPT_PREFER_TEXT:
opts->prefer_text = true;
break;
case 'P':
if (!parse_codec_profile(optarg, &opts->codec_profile)) {
return false;
}
break;
default:
// getopt prints the error message on stderr
return false;
Expand Down

0 comments on commit a4ef318

Please sign in to comment.