Rename --codec to --video-codec WIP

This commit is contained in:
Romain Vimont 2023-02-20 21:19:36 +01:00
parent 3610c240d2
commit a437a4e4b8
9 changed files with 29 additions and 27 deletions

View file

@ -57,7 +57,7 @@
#define OPT_NO_CLEANUP 1037
#define OPT_PRINT_FPS 1038
#define OPT_NO_POWER_ON 1039
#define OPT_CODEC 1040
#define OPT_VIDEO_CODEC 1040
#define OPT_NO_AUDIO 1041
struct sc_option {
@ -107,9 +107,10 @@ static const struct sc_option options[] = {
"Unit suffixes are supported: 'K' (x1000) and 'M' (x1000000).\n"
"Default is 8M (8000000).",
},
// TODO keep OPT_CODEC to avoid partial matching with codec_options
{
.longopt_id = OPT_CODEC,
.longopt = "codec",
.longopt_id = OPT_VIDEO_CODEC,
.longopt = "video-codec",
.argdesc = "name",
.text = "Select a video codec (h264, h265 or av1).\n"
"Default is h264.",
@ -1393,7 +1394,7 @@ guess_record_format(const char *filename) {
}
static bool
parse_codec(const char *optarg, enum sc_codec *codec) {
parse_video_codec(const char *optarg, enum sc_codec *codec) {
if (!strcmp(optarg, "h264")) {
*codec = SC_CODEC_H264;
return true;
@ -1406,7 +1407,7 @@ parse_codec(const char *optarg, enum sc_codec *codec) {
*codec = SC_CODEC_AV1;
return true;
}
LOGE("Unsupported codec: %s (expected h264, h265 or av1)", optarg);
LOGE("Unsupported video codec: %s (expected h264, h265 or av1)", optarg);
return false;
}
@ -1646,8 +1647,8 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
case OPT_PRINT_FPS:
opts->start_fps_counter = true;
break;
case OPT_CODEC:
if (!parse_codec(optarg, &opts->codec)) {
case OPT_VIDEO_CODEC:
if (!parse_video_codec(optarg, &opts->video_codec)) {
return false;
}
break;

View file

@ -13,7 +13,7 @@ const struct scrcpy_options scrcpy_options_default = {
.v4l2_device = NULL,
#endif
.log_level = SC_LOG_LEVEL_INFO,
.codec = SC_CODEC_H264,
.video_codec = SC_CODEC_H264,
.record_format = SC_RECORD_FORMAT_AUTO,
.keyboard_input_mode = SC_KEYBOARD_INPUT_MODE_INJECT,
.port_range = {

View file

@ -99,7 +99,7 @@ struct scrcpy_options {
const char *v4l2_device;
#endif
enum sc_log_level log_level;
enum sc_codec codec;
enum sc_codec video_codec;
enum sc_record_format record_format;
enum sc_keyboard_input_mode keyboard_input_mode;
enum sc_mouse_input_mode mouse_input_mode;

View file

@ -350,7 +350,7 @@ scrcpy(struct scrcpy_options *options) {
.select_usb = options->select_usb,
.select_tcpip = options->select_tcpip,
.log_level = options->log_level,
.codec = options->codec,
.video_codec = options->video_codec,
.crop = options->crop,
.port_range = options->port_range,
.tunnel_host = options->tunnel_host,

View file

@ -222,8 +222,9 @@ execute_server(struct sc_server *server,
if (!params->audio) {
ADD_PARAM("audio=false");
}
if (params->codec != SC_CODEC_H264) {
ADD_PARAM("codec=%s", sc_server_get_codec_name(params->codec));
if (params->video_codec != SC_CODEC_H264) {
ADD_PARAM("video_codec=%s",
sc_server_get_codec_name(params->video_codec));
}
if (params->max_size) {
ADD_PARAM("max_size=%" PRIu16, params->max_size);

View file

@ -25,7 +25,7 @@ struct sc_server_params {
uint32_t scid;
const char *req_serial;
enum sc_log_level log_level;
enum sc_codec codec;
enum sc_codec video_codec;
const char *crop;
const char *codec_options;
const char *encoder_name;

View file

@ -10,7 +10,7 @@ public class Options {
private int scid = -1; // 31-bit non-negative value, or -1
private boolean audio = true;
private int maxSize;
private VideoCodec codec = VideoCodec.H264;
private VideoCodec videoCodec = VideoCodec.H264;
private int bitRate = 8000000;
private int maxFps;
private int lockVideoOrientation = -1;
@ -66,12 +66,12 @@ public class Options {
this.maxSize = maxSize;
}
public VideoCodec getCodec() {
return codec;
public VideoCodec getVideoCodec() {
return videoCodec;
}
public void setCodec(VideoCodec codec) {
this.codec = codec;
public void setVideoCodec(VideoCodec videoCodec) {
this.videoCodec = videoCodec;
}
public int getBitRate() {

View file

@ -231,7 +231,7 @@ public class ScreenEncoder implements Device.RotationListener {
if (encoders != null && encoders.length > 0) {
msg.append("\nTry to use one of the available encoders:");
for (MediaCodecInfo encoder : encoders) {
msg.append("\n scrcpy --codec=").append(codec.getName()).append(" --encoder='").append(encoder.getName()).append("'");
msg.append("\n scrcpy --video-codec=").append(codec.getName()).append(" --encoder='").append(encoder.getName()).append("'");
}
}
return msg.toString();

View file

@ -96,7 +96,6 @@ public final class Server {
AudioEncoder audioEncoder = null;
try (DesktopConnection connection = DesktopConnection.open(scid, tunnelForward, audio, control, sendDummyByte)) {
VideoCodec codec = options.getCodec();
if (options.getSendDeviceMeta()) {
Size videoSize = device.getScreenInfo().getVideoSize();
connection.sendDeviceMeta(Device.getDeviceName(), videoSize.getWidth(), videoSize.getHeight());
@ -116,9 +115,10 @@ public final class Server {
audioEncoder.start();
}
Streamer videoStreamer = new Streamer(connection.getVideoFd(), codec, options.getSendCodecId(), options.getSendFrameMeta());
ScreenEncoder screenEncoder = new ScreenEncoder(device, videoStreamer, options.getBitRate(), options.getMaxFps(),
codecOptions, options.getEncoderName(), options.getDownsizeOnError());
Streamer videoStreamer = new Streamer(connection.getVideoFd(), options.getVideoCodec(), options.getSendCodecId(),
options.getSendFrameMeta());
ScreenEncoder screenEncoder = new ScreenEncoder(device, videoStreamer, options.getBitRate(), options.getMaxFps(), codecOptions,
options.getEncoderName(), options.getDownsizeOnError());
try {
// synchronous
screenEncoder.streamScreen();
@ -195,12 +195,12 @@ public final class Server {
boolean audio = Boolean.parseBoolean(value);
options.setAudio(audio);
break;
case "codec":
VideoCodec codec = VideoCodec.findByName(value);
if (codec == null) {
case "video_codec":
VideoCodec videoCodec = VideoCodec.findByName(value);
if (videoCodec == null) {
throw new IllegalArgumentException("Video codec " + value + " not supported");
}
options.setCodec(codec);
options.setVideoCodec(videoCodec);
break;
case "max_size":
int maxSize = Integer.parseInt(value) & ~7; // multiple of 8