Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to keep audio playing on device while mirroring #5102

Merged
merged 13 commits into from
Jul 19, 2024
Merged

Conversation

rom1v
Copy link
Collaborator

@rom1v rom1v commented Jul 16, 2024

Add a new method to capture audio on the device, provided by @yume-chan in #4380. It is exposed as a separate audio source (in addition to output and mic):

scrcpy --audio-source=playback

There are pros and cons, as noted by @yume-chan:

Pros:

  • Can choose to continue playing audio on device
  • Not affected by connected headsets
  • Not affected by system volume
  • […]

Cons:

  • Requires Android 13, in which the Shell app has MODIFY_AUDIO_ROUTING permission added
  • Apps can opt out from being captured. […]

With this audio source, it is possible to request to keep playing on the device while mirroring:

scrcpy --audio-source=playback --audio-dup

If the audio source is not specified and --audio-dup is set, then it is implicitly set to --audio-source=playback:

scrcpy --audio-dup   # equivalent

Fixes #3875

rom1v and others added 13 commits July 19, 2024 17:48
It is only used from AudioEncoder.

PR #5102 <#5102>
The AudioCaptureForegroundException was very specific. Rename it to
AudioCaptureException to support other capture failures.

PR #5102 <#5102>
Replace a RuntimeException by a specific AudioCaptureException.

PR #5102 <#5102>
The compatibility depends on the capture constraints, not the encoding.

This will allow to add a new capture implementation with different
constraints.

PR #5102 <#5102>
This will allow to use these constants from different classes not
directly related to AudioCapture.

PR #5102 <#5102>
This will allow to reuse this method.

PR #5102 <#5102>
Move the logic to read from an AudioRecord and handle all corner cases
for PTS. This simplifies AudioCapture.

PR #5102 <#5102>
Move the implementation to AudioDirectCapture and extract an
AudioCapture interface.

This will allow to provide another AudioCapture implementation.

PR #5102 <#5102>
The MediaRecorder constant should not belong to the AudioSource enum.

This will allow to add a new AudioSource which has no meaningful
MediaRecorder audio source value.

PR #5102 <#5102>
Add a new method to capture audio playback.

It requires Android 13 (where the Shell app has MODIFY_AUDIO_ROUTING
permission).

The main benefit is that it supports keeping audio playing on the device
(implemented in a further commit).

Fixes #4380 <#4380>
PR #5102 <#5102>

Co-authored-by: Simon Chan <1330321+yume-chan@users.noreply.github.com>
Add an option to duplicate audio on the device, compatible with the new
audio playback capture (--audio-source=playback).

Fixes #3875 <#3875>
Fixes #4380 <#4380>
PR #5102 <#5102>

Co-authored-by: Simon Chan <1330321+yume-chan@users.noreply.github.com>
Automatically switch implicit audio source to "playback" if --audio-dup
is passed.

This allows to run:

    scrcpy --audio-dup

without specifying explicitly:

    scrcpy --audio-source=playback --audio-dup

PR #5102 <#5102>
@rom1v
Copy link
Collaborator Author

rom1v commented Jul 19, 2024

🚀

Here is a binary for the current dev version:

I will probably publish a new version v2.6 in 10~15 days. Consider this as a release candidate.

@rom1v rom1v added this to the v2.6 milestone Jul 28, 2024
FreedomBen pushed a commit to FreedomBen/scrcpy that referenced this pull request Aug 2, 2024
It is only used from AudioEncoder.

PR Genymobile#5102 <Genymobile#5102>
FreedomBen pushed a commit to FreedomBen/scrcpy that referenced this pull request Aug 2, 2024
The AudioCaptureForegroundException was very specific. Rename it to
AudioCaptureException to support other capture failures.

PR Genymobile#5102 <Genymobile#5102>
FreedomBen pushed a commit to FreedomBen/scrcpy that referenced this pull request Aug 2, 2024
Replace a RuntimeException by a specific AudioCaptureException.

PR Genymobile#5102 <Genymobile#5102>
FreedomBen pushed a commit to FreedomBen/scrcpy that referenced this pull request Aug 2, 2024
The compatibility depends on the capture constraints, not the encoding.

This will allow to add a new capture implementation with different
constraints.

PR Genymobile#5102 <Genymobile#5102>
FreedomBen pushed a commit to FreedomBen/scrcpy that referenced this pull request Aug 2, 2024
This will allow to use these constants from different classes not
directly related to AudioCapture.

PR Genymobile#5102 <Genymobile#5102>
FreedomBen pushed a commit to FreedomBen/scrcpy that referenced this pull request Aug 2, 2024
FreedomBen pushed a commit to FreedomBen/scrcpy that referenced this pull request Aug 2, 2024
Move the logic to read from an AudioRecord and handle all corner cases
for PTS. This simplifies AudioCapture.

PR Genymobile#5102 <Genymobile#5102>
FreedomBen pushed a commit to FreedomBen/scrcpy that referenced this pull request Aug 2, 2024
Move the implementation to AudioDirectCapture and extract an
AudioCapture interface.

This will allow to provide another AudioCapture implementation.

PR Genymobile#5102 <Genymobile#5102>
FreedomBen pushed a commit to FreedomBen/scrcpy that referenced this pull request Aug 2, 2024
The MediaRecorder constant should not belong to the AudioSource enum.

This will allow to add a new AudioSource which has no meaningful
MediaRecorder audio source value.

PR Genymobile#5102 <Genymobile#5102>
FreedomBen pushed a commit to FreedomBen/scrcpy that referenced this pull request Aug 2, 2024
Add a new method to capture audio playback.

It requires Android 13 (where the Shell app has MODIFY_AUDIO_ROUTING
permission).

The main benefit is that it supports keeping audio playing on the device
(implemented in a further commit).

Fixes Genymobile#4380 <Genymobile#4380>
PR Genymobile#5102 <Genymobile#5102>

Co-authored-by: Simon Chan <1330321+yume-chan@users.noreply.github.com>
FreedomBen pushed a commit to FreedomBen/scrcpy that referenced this pull request Aug 2, 2024
Add an option to duplicate audio on the device, compatible with the new
audio playback capture (--audio-source=playback).

Fixes Genymobile#3875 <Genymobile#3875>
Fixes Genymobile#4380 <Genymobile#4380>
PR Genymobile#5102 <Genymobile#5102>

Co-authored-by: Simon Chan <1330321+yume-chan@users.noreply.github.com>
FreedomBen pushed a commit to FreedomBen/scrcpy that referenced this pull request Aug 2, 2024
Automatically switch implicit audio source to "playback" if --audio-dup
is passed.

This allows to run:

    scrcpy --audio-dup

without specifying explicitly:

    scrcpy --audio-source=playback --audio-dup

PR Genymobile#5102 <Genymobile#5102>
FreedomBen pushed a commit to FreedomBen/scrcpy that referenced this pull request Aug 2, 2024
Gottox pushed a commit to Gottox/scrcpy that referenced this pull request Sep 29, 2024
It is only used from AudioEncoder.

PR Genymobile#5102 <Genymobile#5102>
Gottox pushed a commit to Gottox/scrcpy that referenced this pull request Sep 29, 2024
The AudioCaptureForegroundException was very specific. Rename it to
AudioCaptureException to support other capture failures.

PR Genymobile#5102 <Genymobile#5102>
Gottox pushed a commit to Gottox/scrcpy that referenced this pull request Sep 29, 2024
Replace a RuntimeException by a specific AudioCaptureException.

PR Genymobile#5102 <Genymobile#5102>
Gottox pushed a commit to Gottox/scrcpy that referenced this pull request Sep 29, 2024
The compatibility depends on the capture constraints, not the encoding.

This will allow to add a new capture implementation with different
constraints.

PR Genymobile#5102 <Genymobile#5102>
Gottox pushed a commit to Gottox/scrcpy that referenced this pull request Sep 29, 2024
This will allow to use these constants from different classes not
directly related to AudioCapture.

PR Genymobile#5102 <Genymobile#5102>
Gottox pushed a commit to Gottox/scrcpy that referenced this pull request Sep 29, 2024
Gottox pushed a commit to Gottox/scrcpy that referenced this pull request Sep 29, 2024
Move the logic to read from an AudioRecord and handle all corner cases
for PTS. This simplifies AudioCapture.

PR Genymobile#5102 <Genymobile#5102>
Gottox pushed a commit to Gottox/scrcpy that referenced this pull request Sep 29, 2024
Move the implementation to AudioDirectCapture and extract an
AudioCapture interface.

This will allow to provide another AudioCapture implementation.

PR Genymobile#5102 <Genymobile#5102>
Gottox pushed a commit to Gottox/scrcpy that referenced this pull request Sep 29, 2024
The MediaRecorder constant should not belong to the AudioSource enum.

This will allow to add a new AudioSource which has no meaningful
MediaRecorder audio source value.

PR Genymobile#5102 <Genymobile#5102>
Gottox pushed a commit to Gottox/scrcpy that referenced this pull request Sep 29, 2024
Add a new method to capture audio playback.

It requires Android 13 (where the Shell app has MODIFY_AUDIO_ROUTING
permission).

The main benefit is that it supports keeping audio playing on the device
(implemented in a further commit).

Fixes Genymobile#4380 <Genymobile#4380>
PR Genymobile#5102 <Genymobile#5102>

Co-authored-by: Simon Chan <1330321+yume-chan@users.noreply.github.com>
Gottox pushed a commit to Gottox/scrcpy that referenced this pull request Sep 29, 2024
Add an option to duplicate audio on the device, compatible with the new
audio playback capture (--audio-source=playback).

Fixes Genymobile#3875 <Genymobile#3875>
Fixes Genymobile#4380 <Genymobile#4380>
PR Genymobile#5102 <Genymobile#5102>

Co-authored-by: Simon Chan <1330321+yume-chan@users.noreply.github.com>
Gottox pushed a commit to Gottox/scrcpy that referenced this pull request Sep 29, 2024
Automatically switch implicit audio source to "playback" if --audio-dup
is passed.

This allows to run:

    scrcpy --audio-dup

without specifying explicitly:

    scrcpy --audio-source=playback --audio-dup

PR Genymobile#5102 <Genymobile#5102>
Gottox pushed a commit to Gottox/scrcpy that referenced this pull request Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant