Skip to content

starboard: Add setting to skip audio resampling on unchanged sample rate - #13467

Merged
xiaomings merged 1 commit into
youtube:mainfrom
xiaomings:audio_renderer
Oct 20, 2026
Merged

xiaomings merged 1 commit into
youtube:mainfrom
xiaomings:audio_renderer

Conversation

@xiaomings

Copy link
Copy Markdown
Member

AudioRendererPcm feeds its AudioTimeStretcher float32 samples. When the decoder produces another sample type, e.g. the int16 output of the Android MediaCodec audio decoder, OnFirstOutput() creates a full AudioResamplerImpl even if the sample rate doesn't change, so every buffer goes through a 32-tap sinc convolution at a ratio of 1.0 just to be converted to float32.

Add the H5vcc setting Media.SkipAudioResamplingOnUnchangedSampleRate. When it is set, IdentityAudioResampler is used whenever the sample rate is unchanged and the samples are converted by the existing code in ProcessAudioData() before they are enqueued to the time stretcher, as is already the case for float32 decoders. The setting is off by default so the change can be experimented with in production.

Measured on a local Android TV device (Android 10, 4x Cortex-A53) playing a 1080p24 VP9 + AAC 44.1 kHz stereo YouTube video through the MediaCodec audio decoder (int16 output), averaged over two 95 s windows:

player_worker thread: 6.9% -> 2.9% of one core
Cobalt process total: 65.8% -> 62.0% of one core

Bug: 511356295

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor
Context State Description
CI / All Pass ✅ PASS All checks passed
CI / android ✅ PASS Passed
CI / evergreen ✅ PASS Passed
CI / linux ✅ PASS Passed
CI / tvos ✅ PASS Passed
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Gemini Suggested Commit Message


starboard: Skip redundant audio resampling

Introduce the Media.SkipAudioResamplingOnUnchangedSampleRate feature to
avoid creating a full AudioResamplerImpl when the sample rate is
unchanged. Currently, non-float32 samples (like int16 from Android
MediaCodec) trigger a 32-tap sinc convolution at a 1.0 ratio just for
format conversion.

When enabled, redundant resampling is bypassed and samples are instead
converted to float32 by existing logic in ProcessAudioData() before
being enqueued. This reduces CPU overhead on low-power devices.

Bug: 511356295

💡 Pro Tips for a Better Commit Message:

  1. Influence the Result: Want to change the output? You can write custom prompts or instructions directly in the Pull Request description. The model uses that text to generate the message.
  2. Re-run the Generator: Post a comment with: /generate-commit-message

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an experimental feature flag, kMediaSkipAudioResamplingOnUnchangedSampleRate, which allows AudioRendererPcm to skip routing decoded audio through the resampler when the sample rate remains unchanged, even if the audio sample type is not float32. This avoids unnecessary resampling overhead. The changes include reading the new experimental flag, updating the resampling logic in AudioRendererPcm::OnFirstOutput, and adding a new unit test SunnyDayWithInt16SamplesWithoutResampling to verify the behavior. There are no review comments to address, and I have no additional feedback to provide.

@xiaomings
xiaomings force-pushed the audio_renderer branch 2 times, most recently from dd1f0ab to 0a79949 Compare October 19, 2026 22:21
AudioRendererPcm feeds its AudioTimeStretcher float32 samples. When the
decoder produces another sample type, e.g. the int16 output of the
Android MediaCodec audio decoder, OnFirstOutput() creates a full
AudioResamplerImpl even if the sample rate doesn't change, so every
buffer goes through a 32-tap sinc convolution at a ratio of 1.0 just to
be converted to float32.

Add the H5vcc setting Media.SkipAudioResamplingOnUnchangedSampleRate.
When it is set, IdentityAudioResampler is used whenever the sample rate
is unchanged and the samples are converted by the existing code in
ProcessAudioData() before they are enqueued to the time stretcher, as is
already the case for float32 decoders. The setting is off by default so
the change can be experimented with in production.

Measured on a local Android TV device (Android 10, 4x Cortex-A53)
playing a 1080p24 VP9 + AAC 44.1 kHz stereo YouTube video through the
MediaCodec audio decoder (int16 output), averaged over two 95 s windows:

  player_worker thread: 6.9% -> 2.9% of one core
  Cobalt process total: 65.8% -> 62.0% of one core

Bug: 511356295
TAG=agy
CONV=75cbba55-91ae-4914-a546-0ce1106643ed
@xiaomings

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an experimental feature, kMediaSkipAudioResamplingOnUnchangedSampleRate, which allows AudioRendererPcm to skip routing decoded audio through the resampler when the sample rate is unchanged, even if a sample type conversion to float32 is needed. The changes implement this optimization in AudioRendererPcm and add a new unit test, SunnyDayWithInt16SamplesWithoutResampling, to verify the behavior. I have no feedback to provide as there are no review comments and the implementation is clean.

@xiaomings
xiaomings requested review from a team, jasonzhangxx and kjyoun October 19, 2026 23:03
@xiaomings
xiaomings enabled auto-merge (squash) October 19, 2026 23:34
@xiaomings
xiaomings merged commit 0183d36 into youtube:main Oct 20, 2026
546 of 548 checks passed
cobalt-github-releaser-bot pushed a commit that referenced this pull request Oct 20, 2026
…g on unchanged sample rate

Refer to original PR: #13467

AudioRendererPcm feeds its AudioTimeStretcher float32 samples. When the
decoder produces another sample type, e.g. the int16 output of the
Android MediaCodec audio decoder, OnFirstOutput() creates a full
AudioResamplerImpl even if the sample rate doesn't change, so every
buffer goes through a 32-tap sinc convolution at a ratio of 1.0 just to
be converted to float32.

Add the H5vcc setting Media.SkipAudioResamplingOnUnchangedSampleRate.
When it is set, IdentityAudioResampler is used whenever the sample rate
is unchanged and the samples are converted by the existing code in
ProcessAudioData() before they are enqueued to the time stretcher, as is
already the case for float32 decoders. The setting is off by default so
the change can be experimented with in production.

Measured on a local Android TV device (Android 10, 4x Cortex-A53)
playing a 1080p24 VP9 + AAC 44.1 kHz stereo YouTube video through the
MediaCodec audio decoder (int16 output), averaged over two 95 s windows:

  player_worker thread: 6.9% -> 2.9% of one core
  Cobalt process total: 65.8% -> 62.0% of one core

Bug: 511356295

(cherry picked from commit 0183d36)
cobalt-github-releaser-bot pushed a commit that referenced this pull request Oct 20, 2026
…g on unchanged sample rate

Refer to original PR: #13467

AudioRendererPcm feeds its AudioTimeStretcher float32 samples. When the
decoder produces another sample type, e.g. the int16 output of the
Android MediaCodec audio decoder, OnFirstOutput() creates a full
AudioResamplerImpl even if the sample rate doesn't change, so every
buffer goes through a 32-tap sinc convolution at a ratio of 1.0 just to
be converted to float32.

Add the H5vcc setting Media.SkipAudioResamplingOnUnchangedSampleRate.
When it is set, IdentityAudioResampler is used whenever the sample rate
is unchanged and the samples are converted by the existing code in
ProcessAudioData() before they are enqueued to the time stretcher, as is
already the case for float32 decoders. The setting is off by default so
the change can be experimented with in production.

Measured on a local Android TV device (Android 10, 4x Cortex-A53)
playing a 1080p24 VP9 + AAC 44.1 kHz stereo YouTube video through the
MediaCodec audio decoder (int16 output), averaged over two 95 s windows:

  player_worker thread: 6.9% -> 2.9% of one core
  Cobalt process total: 65.8% -> 62.0% of one core

Bug: 511356295

(cherry picked from commit 0183d36)
briantting pushed a commit that referenced this pull request Oct 20, 2026
…g on unchanged sample rate

Refer to original PR: #13467

AudioRendererPcm feeds its AudioTimeStretcher float32 samples. When the
decoder produces another sample type, e.g. the int16 output of the
Android MediaCodec audio decoder, OnFirstOutput() creates a full
AudioResamplerImpl even if the sample rate doesn't change, so every
buffer goes through a 32-tap sinc convolution at a ratio of 1.0 just to
be converted to float32.

Add the H5vcc setting Media.SkipAudioResamplingOnUnchangedSampleRate.
When it is set, IdentityAudioResampler is used whenever the sample rate
is unchanged and the samples are converted by the existing code in
ProcessAudioData() before they are enqueued to the time stretcher, as is
already the case for float32 decoders. The setting is off by default so
the change can be experimented with in production.

Measured on a local Android TV device (Android 10, 4x Cortex-A53)
playing a 1080p24 VP9 + AAC 44.1 kHz stereo YouTube video through the
MediaCodec audio decoder (int16 output), averaged over two 95 s windows:

  player_worker thread: 6.9% -> 2.9% of one core
  Cobalt process total: 65.8% -> 62.0% of one core

Bug: 511356295

(cherry picked from commit 0183d36)
@xiaomings
xiaomings deleted the audio_renderer branch October 21, 2026 02:36
briantting pushed a commit that referenced this pull request Oct 26, 2026
…g on unchanged sample rate

Refer to original PR: #13467

AudioRendererPcm feeds its AudioTimeStretcher float32 samples. When the
decoder produces another sample type, e.g. the int16 output of the
Android MediaCodec audio decoder, OnFirstOutput() creates a full
AudioResamplerImpl even if the sample rate doesn't change, so every
buffer goes through a 32-tap sinc convolution at a ratio of 1.0 just to
be converted to float32.

Add the H5vcc setting Media.SkipAudioResamplingOnUnchangedSampleRate.
When it is set, IdentityAudioResampler is used whenever the sample rate
is unchanged and the samples are converted by the existing code in
ProcessAudioData() before they are enqueued to the time stretcher, as is
already the case for float32 decoders. The setting is off by default so
the change can be experimented with in production.

Measured on a local Android TV device (Android 10, 4x Cortex-A53)
playing a 1080p24 VP9 + AAC 44.1 kHz stereo YouTube video through the
MediaCodec audio decoder (int16 output), averaged over two 95 s windows:

  player_worker thread: 6.9% -> 2.9% of one core
  Cobalt process total: 65.8% -> 62.0% of one core

Bug: 511356295

(cherry picked from commit 0183d36)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants