From aa42833cbbde15f5c1e64ab70a9c6714562a612c Mon Sep 17 00:00:00 2001 From: Tzah Mazuz Date: Tue, 14 Apr 2020 18:32:26 +0300 Subject: [PATCH] Changing codec-profile -> codec-options --- app/scrcpy.1 | 2 +- app/src/cli.c | 64 +++++++++++------------------------------------- app/src/scrcpy.c | 2 +- app/src/scrcpy.h | 4 +-- app/src/server.c | 5 +--- app/src/server.h | 4 +-- 6 files changed, 20 insertions(+), 61 deletions(-) diff --git a/app/scrcpy.1 b/app/scrcpy.1 index 443bb19d57..755bd981c0 100644 --- a/app/scrcpy.1 +++ b/app/scrcpy.1 @@ -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 diff --git a/app/src/cli.c b/app/src/cli.c index 44fee83899..f62b7f9fe6 100644 --- a/app/src/cli.c +++ b/app/src/cli.c @@ -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" @@ -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); @@ -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[]) { @@ -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'}, @@ -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'}, @@ -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 }, }; @@ -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': @@ -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 diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 0057c75b83..5cc0f616dc 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -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, ¶ms)) { return false; diff --git a/app/src/scrcpy.h b/app/src/scrcpy.h index 4d5ad9fc34..17f2a4795d 100644 --- a/app/src/scrcpy.h +++ b/app/src/scrcpy.h @@ -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; @@ -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 { \ @@ -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, \ @@ -65,7 +66,6 @@ struct scrcpy_options { .render_expired_frames = false, \ .prefer_text = false, \ .window_borderless = false, \ - .codec_profile = 0, \ } bool diff --git a/app/src/server.c b/app/src/server.c index d4b36887f9..55a8151b16 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -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, @@ -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) @@ -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); diff --git a/app/src/server.h b/app/src/server.h index 5d940f203a..9bc25671df 100644 --- a/app/src/server.h +++ b/app/src/server.h @@ -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 { \ @@ -35,7 +34,6 @@ struct server { .local_port = 0, \ .tunnel_enabled = false, \ .tunnel_forward = false, \ - .codec_profile = 0, \ } struct server_params { @@ -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