Add --audio-buffer
Expose an option to add a buffering delay (in milliseconds) before playing audio. This is similar to the options --display-buffer and --v4l2-buffer for video frames. PR #3757 <https://github.com/Genymobile/scrcpy/pull/3757>
This commit is contained in:
parent
d66b0b3dcc
commit
df55bc2683
5 changed files with 26 additions and 1 deletions
|
@ -25,6 +25,14 @@ Encode the audio at the given bit\-rate, expressed in bits/s. Unit suffixes are
|
|||
|
||||
Default is 128K (128000).
|
||||
|
||||
.TP
|
||||
.BI "\-\-audio\-buffer ms
|
||||
Configure the audio buffering delay (in milliseconds).
|
||||
|
||||
Lower values decrease the latency, but increase the likelyhood of buffer underrun (causing audio glitches).
|
||||
|
||||
Default is 50.
|
||||
|
||||
.TP
|
||||
.BI "\-\-audio\-codec " name
|
||||
Select an audio codec (opus or aac).
|
||||
|
|
|
@ -71,6 +71,7 @@ enum {
|
|||
OPT_LIST_ENCODERS,
|
||||
OPT_LIST_DISPLAYS,
|
||||
OPT_REQUIRE_AUDIO,
|
||||
OPT_AUDIO_BUFFER,
|
||||
};
|
||||
|
||||
struct sc_option {
|
||||
|
@ -120,6 +121,15 @@ static const struct sc_option options[] = {
|
|||
"Unit suffixes are supported: 'K' (x1000) and 'M' (x1000000).\n"
|
||||
"Default is 128K (128000).",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_AUDIO_BUFFER,
|
||||
.longopt = "audio-buffer",
|
||||
.argdesc = "ms",
|
||||
.text = "Configure the audio buffering delay (in milliseconds).\n"
|
||||
"Lower values decrease the latency, but increase the "
|
||||
"likelyhood of buffer underrun (causing audio glitches).\n"
|
||||
"Default is 50.",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_AUDIO_CODEC,
|
||||
.longopt = "audio-codec",
|
||||
|
@ -1822,6 +1832,11 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||
case OPT_REQUIRE_AUDIO:
|
||||
opts->require_audio = true;
|
||||
break;
|
||||
case OPT_AUDIO_BUFFER:
|
||||
if (!parse_buffering_time(optarg, &opts->audio_buffer)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// getopt prints the error message on stderr
|
||||
return false;
|
||||
|
|
|
@ -43,6 +43,7 @@ const struct scrcpy_options scrcpy_options_default = {
|
|||
.display_id = 0,
|
||||
.display_buffer = 0,
|
||||
.v4l2_buffer = 0,
|
||||
.audio_buffer = SC_TICK_FROM_MS(50),
|
||||
#ifdef HAVE_USB
|
||||
.otg = false,
|
||||
#endif
|
||||
|
|
|
@ -125,6 +125,7 @@ struct scrcpy_options {
|
|||
uint32_t display_id;
|
||||
sc_tick display_buffer;
|
||||
sc_tick v4l2_buffer;
|
||||
sc_tick audio_buffer;
|
||||
#ifdef HAVE_USB
|
||||
bool otg;
|
||||
#endif
|
||||
|
|
|
@ -687,7 +687,7 @@ aoa_hid_end:
|
|||
sc_frame_source_add_sink(src, &s->screen.frame_sink);
|
||||
|
||||
if (options->audio) {
|
||||
sc_audio_player_init(&s->audio_player, SC_TICK_FROM_MS(50));
|
||||
sc_audio_player_init(&s->audio_player, options->audio_buffer);
|
||||
sc_frame_source_add_sink(&s->audio_decoder.frame_source,
|
||||
&s->audio_player.frame_sink);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue