Skip to content

Commit

Permalink
Add --audio-codec=raw option
Browse files Browse the repository at this point in the history
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 <#3757>
  • Loading branch information
rom1v committed Mar 3, 2023
1 parent 73cd59a commit 29e47bd
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/data/bash-completion/scrcpy
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ _scrcpy() {
return
;;
--audio-codec)
COMPREPLY=($(compgen -W 'opus aac' -- "$cur"))
COMPREPLY=($(compgen -W 'raw opus aac' -- "$cur"))
return
;;
--lock-video-orientation)
Expand Down
2 changes: 1 addition & 1 deletion app/data/zsh-completion/_scrcpy
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local arguments
arguments=(
'--always-on-top[Make scrcpy window always on top \(above other windows\)]'
'--audio-bit-rate=[Encode the audio at the given bit-rate]'
'--audio-codec=[Select the audio codec]:codec:(opus aac)'
'--audio-codec=[Select the audio codec]:codec:(raw opus aac)'
'--audio-codec-options=[Set a list of comma-separated key\:type=value options for the device audio encoder]'
'--audio-encoder=[Use a specific MediaCodec audio encoder]'
{-b,--video-bit-rate=}'[Encode the video at the given bit-rate]'
Expand Down
2 changes: 1 addition & 1 deletion app/scrcpy.1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Default is 0 (no buffering).

.TP
.BI "\-\-audio\-codec " name
Select an audio codec (opus or aac).
Select an audio codec (raw, opus or aac).

Default is opus.

Expand Down
14 changes: 12 additions & 2 deletions app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
},
{
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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");
Expand Down
3 changes: 3 additions & 0 deletions app/src/demuxer.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ sc_demuxer_to_avcodec_id(uint32_t codec_id) {
#define SC_CODEC_ID_H264 UINT32_C(0x68323634) // "h264" in ASCII
#define SC_CODEC_ID_H265 UINT32_C(0x68323635) // "h265" in ASCII
#define SC_CODEC_ID_AV1 UINT32_C(0x00617631) // "av1" in ASCII
#define SC_CODEC_ID_RAW UINT32_C(0x00726177) // "raw" in ASCII
#define SC_CODEC_ID_OPUS UINT32_C(0x6f707573) // "opus" in ASCII
#define SC_CODEC_ID_AAC UINT32_C(0x00616163) // "aac in ASCII"
switch (codec_id) {
Expand All @@ -32,6 +33,8 @@ sc_demuxer_to_avcodec_id(uint32_t codec_id) {
return AV_CODEC_ID_HEVC;
case SC_CODEC_ID_AV1:
return AV_CODEC_ID_AV1;
case SC_CODEC_ID_RAW:
return AV_CODEC_ID_PCM_S16LE;
case SC_CODEC_ID_OPUS:
return AV_CODEC_ID_OPUS;
case SC_CODEC_ID_AAC:
Expand Down
1 change: 1 addition & 0 deletions app/src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ enum sc_codec {
SC_CODEC_H264,
SC_CODEC_H265,
SC_CODEC_AV1,
SC_CODEC_RAW,
SC_CODEC_OPUS,
SC_CODEC_AAC,
};
Expand Down
2 changes: 2 additions & 0 deletions app/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ sc_server_get_codec_name(enum sc_codec codec) {
return "h265";
case SC_CODEC_AV1:
return "av1";
case SC_CODEC_RAW:
return "raw";
case SC_CODEC_OPUS:
return "opus";
case SC_CODEC_AAC:
Expand Down

0 comments on commit 29e47bd

Please sign in to comment.