Add --audio-codec=raw option

Add support for raw (PCM S16 LE) audio codec (a decoder is included in
FFmpeg).

Even if it consumes more bandwidth, it provides a lower latency.

PR #3757 <https://github.com/Genymobile/scrcpy/pull/3757>
This commit is contained in:
Romain Vimont 2023-03-03 21:19:37 +01:00
parent 73cd59ab25
commit 29e47bdcdc
7 changed files with 21 additions and 5 deletions

View file

@ -132,7 +132,7 @@ static const struct sc_option options[] = {
.longopt_id = OPT_AUDIO_CODEC,
.longopt = "audio-codec",
.argdesc = "name",
.text = "Select an audio codec (opus or aac).\n"
.text = "Select an audio codec (raw, opus or aac).\n"
"Default is opus.",
},
{
@ -1506,6 +1506,10 @@ parse_video_codec(const char *optarg, enum sc_codec *codec) {
static bool
parse_audio_codec(const char *optarg, enum sc_codec *codec) {
if (!strcmp(optarg, "raw")) {
*codec = SC_CODEC_RAW;
return true;
}
if (!strcmp(optarg, "opus")) {
*codec = SC_CODEC_OPUS;
return true;
@ -1514,7 +1518,7 @@ parse_audio_codec(const char *optarg, enum sc_codec *codec) {
*codec = SC_CODEC_AAC;
return true;
}
LOGE("Unsupported audio codec: %s (expected opus or aac)", optarg);
LOGE("Unsupported audio codec: %s (expected raw, opus or aac)", optarg);
return false;
}
@ -1912,6 +1916,12 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
}
}
if (opts->record_filename && opts->audio_codec == SC_CODEC_RAW) {
LOGW("Recording does not support RAW audio codec, automatically "
"switching to --audio-codec=opus");
opts->audio_codec = SC_CODEC_OPUS;
}
if (!opts->control) {
if (opts->turn_screen_off) {
LOGE("Could not request to turn screen off if control is disabled");