Display and control your Android device
Add --audio-buffer
Romain Vimontdf55bc2683e2
diff --git a/app/scrcpy.1 b/app/scrcpy.1index 91258414..120ea192 100644--- a/app/scrcpy.1+++ b/app/scrcpy.1@@ -25,6 +25,14 @@ Encode the audio at the given bit\-rate, expressed in bits/s. Unit suffixes areDefault 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 " nameSelect an audio codec (opus or aac).diff --git a/app/src/cli.c b/app/src/cli.cindex 18f3b83b..122a5891 100644--- a/app/src/cli.c+++ b/app/src/cli.c@@ -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 stderrreturn false;diff --git a/app/src/options.c b/app/src/options.cindex 5dd655ce..68c16d53 100644--- a/app/src/options.c+++ b/app/src/options.c@@ -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,#endifdiff --git a/app/src/options.h b/app/src/options.hindex 5fcaf016..d9c2d228 100644--- a/app/src/options.h+++ b/app/src/options.h@@ -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_USBbool otg;#endifdiff --git a/app/src/scrcpy.c b/app/src/scrcpy.cindex 3f3a34f0..ce045c97 100644--- a/app/src/scrcpy.c+++ b/app/src/scrcpy.c@@ -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);}