Skip to content

Commit

Permalink
[Chromecast] Lower output buffer size for cast audio managed streams.
Browse files Browse the repository at this point in the history
The default audio buffer sizes for a device are not currently chosen
with real-time communication in mind, and are also set independently of
the sample rate of the audio used. We want minimal latency, so we set
the buffer size to always be 10ms of audio regardless of the sample
rate.

Bug: internal 170432827
Test: On device. Ensured correct size is set.
Change-Id: Ifb7e37ef1c033e6efbabd07eb01b6c58476addc0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2481287
Reviewed-by: Kenneth MacKay <kmackay@chromium.org>
Commit-Queue: Adam Whiteside <awhiteside@google.com>
Cr-Commit-Position: refs/heads/master@{#818062}
  • Loading branch information
Adam Whiteside authored and Commit Bot committed Oct 16, 2020
1 parent 35d0dcc commit 51567de
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions chromecast/media/audio/cast_audio_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,8 @@ namespace {
// TODO(alokp): Query the preferred value from media backend.
const int kDefaultSampleRate = 48000;

// Define bounds for the output buffer size (in frames).
// TODO(alokp): Query the preferred value from media backend.
static const int kMinimumOutputBufferSize =
BUILDFLAG(MINIMUM_OUTPUT_BUFFER_SIZE_IN_FRAMES);
static const int kMaximumOutputBufferSize =
BUILDFLAG(MAXIMUM_OUTPUT_BUFFER_SIZE_IN_FRAMES);
static const int kDefaultOutputBufferSize =
BUILDFLAG(DEFAULT_OUTPUT_BUFFER_SIZE_IN_FRAMES);

// TODO(jyw): Query the preferred value from media backend.
static const int kDefaultInputBufferSize = 1024;

} // namespace

namespace chromecast {
Expand Down Expand Up @@ -201,18 +191,8 @@ ::media::AudioParameters CastAudioManager::GetPreferredOutputStreamParameters(
const ::media::AudioParameters& input_params) {
::media::ChannelLayout channel_layout = ::media::CHANNEL_LAYOUT_STEREO;
int sample_rate = kDefaultSampleRate;
int buffer_size = kDefaultOutputBufferSize;
if (input_params.IsValid()) {
// Do not change:
// - the channel layout
// - the number of bits per sample
// We support stereo only with 16 bits per sample.
sample_rate = input_params.sample_rate();
buffer_size = std::min(
kMaximumOutputBufferSize,
std::max(kMinimumOutputBufferSize, input_params.frames_per_buffer()));
}

// Set buffer size to 10ms of the sample rate.
int buffer_size = sample_rate / 100;
::media::AudioParameters output_params(
::media::AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
sample_rate, buffer_size);
Expand Down

0 comments on commit 51567de

Please sign in to comment.