Skip to content

Commit

Permalink
Changing codec-profile -> codec-options
Browse files Browse the repository at this point in the history
  • Loading branch information
Tzah Mazuz committed Apr 17, 2020
1 parent c265d63 commit aa42833
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 61 deletions.
2 changes: 1 addition & 1 deletion app/scrcpy.1
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Default is 0 (automatic).\n

.TP
.BI "\-\-\codec\-options " 'options'
'options' is a list of key=value pairs seperated by comma\n
options is a list of key=value pairs seperated by comma\n
for the device encoder.\n
For a list of possible codec options:\n
https://developer.android.com/reference/android/media/MediaCodecInfo\n
Expand Down
64 changes: 14 additions & 50 deletions app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,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"
" --codec-options 'options'\n"
" 'options' is a list of key=value pairs seperated by comma\n"
" for the device encoder.\n"
" For a list of possible codec options:\n"
" https://developer.android.com/reference/android/media/MediaCodecInfo\n"
" Currently supported keys: [profile, level].\n"
"\n"
"Shortcuts:\n"
"\n"
Expand Down Expand Up @@ -374,35 +375,6 @@ 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 @@ -433,6 +405,7 @@ guess_record_format(const char *filename) {
#define OPT_WINDOW_BORDERLESS 1011
#define OPT_MAX_FPS 1012
#define OPT_LOCK_VIDEO_ORIENTATION 1013
#define OPT_CODEC_OPTIONS 1014

bool
scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
Expand All @@ -442,8 +415,7 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
{"crop", required_argument, NULL, OPT_CROP},
{"fullscreen", no_argument, NULL, 'f'},
{"help", no_argument, NULL, 'h'},
{"lock-video-orientation", required_argument, NULL,
OPT_LOCK_VIDEO_ORIENTATION},
{"lock-video-orientation", required_argument, NULL, OPT_LOCK_VIDEO_ORIENTATION},
{"max-fps", required_argument, NULL, OPT_MAX_FPS},
{"max-size", required_argument, NULL, 'm'},
{"no-control", no_argument, NULL, 'n'},
Expand All @@ -452,8 +424,7 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
{"push-target", required_argument, NULL, OPT_PUSH_TARGET},
{"record", required_argument, NULL, 'r'},
{"record-format", required_argument, NULL, OPT_RECORD_FORMAT},
{"render-expired-frames", no_argument, NULL,
OPT_RENDER_EXPIRED_FRAMES},
{"render-expired-frames", no_argument, NULL, OPT_RENDER_EXPIRED_FRAMES},
{"serial", required_argument, NULL, 's'},
{"show-touches", no_argument, NULL, 't'},
{"turn-screen-off", no_argument, NULL, 'S'},
Expand All @@ -464,9 +435,8 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
{"window-y", required_argument, NULL, OPT_WINDOW_Y},
{"window-width", required_argument, NULL, OPT_WINDOW_WIDTH},
{"window-height", required_argument, NULL, OPT_WINDOW_HEIGHT},
{"window-borderless", no_argument, NULL,
OPT_WINDOW_BORDERLESS},
{"codec-profile", required_argument, NULL, 'P'},
{"window-borderless", no_argument, NULL, OPT_WINDOW_BORDERLESS},
{"codec-options", required_argument, NULL, OPT_CODEC_OPTIONS},
{NULL, 0, NULL, 0 },
};

Expand All @@ -475,11 +445,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;
<<<<<<< HEAD
while ((c = getopt_long(argc, argv, "b:c:fF:hm:nNp:r:s:StTv:P:", long_options,
=======
while ((c = getopt_long(argc, argv, "b:c:fF:hm:nNp:r:s:StTv", long_options,
>>>>>>> 1b12204... fixup! Added help and parsing of the codec-profile option
while ((c = getopt_long(argc, argv, "b:c:fF:hm:nNp:r:s:StTv:", long_options,
NULL)) != -1) {
switch (c) {
case 'b':
Expand Down Expand Up @@ -589,10 +555,8 @@ 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;
}
case OPT_CODEC_OPTIONS:
opts->codec_options = optarg;
break;
default:
// getopt prints the error message on stderr
Expand Down
2 changes: 1 addition & 1 deletion app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ scrcpy(const struct scrcpy_options *options) {
.max_fps = options->max_fps,
.lock_video_orientation = options->lock_video_orientation,
.control = options->control,
.codec_profile = options->codec_profile,
.codec_options = options->codec_options,
};
if (!server_start(&server, options->serial, &params)) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions app/src/scrcpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct scrcpy_options {
const char *record_filename;
const char *window_title;
const char *push_target;
const char *codec_options;
enum recorder_format record_format;
struct port_range port_range;
uint16_t max_size;
Expand All @@ -34,7 +35,6 @@ struct scrcpy_options {
bool render_expired_frames;
bool prefer_text;
bool window_borderless;
uint32_t codec_profile;
};

#define SCRCPY_OPTIONS_DEFAULT { \
Expand All @@ -43,6 +43,7 @@ struct scrcpy_options {
.record_filename = NULL, \
.window_title = NULL, \
.push_target = NULL, \
.codec_options = NULL, \
.record_format = RECORDER_FORMAT_AUTO, \
.port_range = { \
.first = DEFAULT_LOCAL_PORT_RANGE_FIRST, \
Expand All @@ -65,7 +66,6 @@ struct scrcpy_options {
.render_expired_frames = false, \
.prefer_text = false, \
.window_borderless = false, \
.codec_profile = 0, \
}

bool
Expand Down
5 changes: 1 addition & 4 deletions app/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,10 @@ execute_server(struct server *server, const struct server_params *params) {
char bit_rate_string[11];
char max_fps_string[6];
char lock_video_orientation_string[3];
char codec_profile_string[11];
sprintf(max_size_string, "%"PRIu16, params->max_size);
sprintf(bit_rate_string, "%"PRIu32, params->bit_rate);
sprintf(max_fps_string, "%"PRIu16, params->max_fps);
sprintf(lock_video_orientation_string, "%"PRIi8, params->lock_video_orientation);
sprintf(codec_profile_string, "%"PRIu32, params->codec_profile);
const char *const cmd[] = {
"shell",
"CLASSPATH=" DEVICE_SERVER_PATH,
Expand All @@ -256,7 +254,7 @@ execute_server(struct server *server, const struct server_params *params) {
bit_rate_string,
max_fps_string,
lock_video_orientation_string,
codec_profile_string,
params->codec_options ? params->codec_options : "-",
server->tunnel_forward ? "true" : "false",
params->crop ? params->crop : "-",
"true", // always send frame meta (packet boundaries + timestamp)
Expand Down Expand Up @@ -330,7 +328,6 @@ bool
server_start(struct server *server, const char *serial,
const struct server_params *params) {
server->port_range = params->port_range;
server->codec_profile = params->codec_profile;

if (serial) {
server->serial = SDL_strdup(serial);
Expand Down
4 changes: 1 addition & 3 deletions app/src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct server {
uint16_t local_port; // selected from port_range
bool tunnel_enabled;
bool tunnel_forward; // use "adb forward" instead of "adb reverse"
uint32_t codec_profile;
};

#define SERVER_INITIALIZER { \
Expand All @@ -35,7 +34,6 @@ struct server {
.local_port = 0, \
.tunnel_enabled = false, \
.tunnel_forward = false, \
.codec_profile = 0, \
}

struct server_params {
Expand All @@ -46,7 +44,7 @@ struct server_params {
uint16_t max_fps;
int8_t lock_video_orientation;
bool control;
uint32_t codec_profile;
char *codec_options;
};

// init default values
Expand Down

0 comments on commit aa42833

Please sign in to comment.