-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[WIP] Add selectAudioOutput method. #1030
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
472eeaa
chore: Add selectAudioOutput method.
cloudwebrtc f67f401
cleanup.
cloudwebrtc e941e12
update.
cloudwebrtc c772588
bump version.
cloudwebrtc d584119
feat: selectAudioOutput support for macOS.
cloudwebrtc 538ca4e
Android audio outputs and audio selection
davidliu 0f411a8
chore: code format.
cloudwebrtc 21e1ab2
chore: update loopback sample.
cloudwebrtc 0a87072
update webrtc-interface.
cloudwebrtc e8ef0ec
Fix compilation errors for iOS.
cloudwebrtc c6ba324
Audio device enumeration for iOS.
cloudwebrtc 5b1f1a6
Merge branch 'main' into feat/select-audio-output
cloudwebrtc 0d45de2
Merge branch 'main' into feat/select-audio-output
cloudwebrtc 86dd6f7
Add mediaDeviceEvent for MediaDeviceNative.
cloudwebrtc 7a0d1f2
feat: Implemented ondevicechang events for windows.
cloudwebrtc 601e2da
chore: feat: Implemented ondevicechange events for Android.
cloudwebrtc 0cc6b4b
Tidy up the code.
cloudwebrtc 32fdb18
feat: Implemented ondevicechange events for macOS.
cloudwebrtc ccd8079
chore: Use the unified Events channel to transmit the ondevicechange …
cloudwebrtc 24e681b
chore: Use the unified Events channel to transmit the ondevicechange …
cloudwebrtc cb5561e
Remove unused import.
cloudwebrtc c7409da
feat: Implemented ondevicechange events for iOS.
cloudwebrtc 2a9dab2
Replace AVAudioSession with RTCAudioSession.
cloudwebrtc 1dac603
Add setPreferredInput/setPreferredOutput.
cloudwebrtc 4f55441
Implementation returns a list of audio sources,imp fun setPreferredIn…
zjzhang-cn a29d2ff
update.
cloudwebrtc 2f3eef0
Merge branch 'main' into feat/select-audio-output
cloudwebrtc b0cf535
Add SetPreferredInput for win.
cloudwebrtc ac9f0ab
update.
cloudwebrtc 264bf6d
update.
cloudwebrtc 9205ee4
fix compile error for mac.
cloudwebrtc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
import androidx.annotation.Nullable; | ||
import androidx.annotation.RequiresApi; | ||
|
||
import com.cloudwebrtc.webrtc.audio.AudioDeviceKind; | ||
import com.cloudwebrtc.webrtc.audio.AudioSwitchManager; | ||
import com.cloudwebrtc.webrtc.record.AudioChannel; | ||
import com.cloudwebrtc.webrtc.record.FrameCapturer; | ||
import com.cloudwebrtc.webrtc.utils.AnyThreadResult; | ||
|
@@ -28,6 +30,8 @@ | |
import com.cloudwebrtc.webrtc.utils.ObjectType; | ||
import com.cloudwebrtc.webrtc.utils.PermissionUtils; | ||
|
||
import com.twilio.audioswitch.AudioDevice; | ||
|
||
import org.webrtc.AudioTrack; | ||
import org.webrtc.CryptoOptions; | ||
import org.webrtc.DefaultVideoDecoderFactory; | ||
|
@@ -81,17 +85,6 @@ | |
import io.flutter.view.TextureRegistry.SurfaceTextureEntry; | ||
|
||
public class MethodCallHandlerImpl implements MethodCallHandler, StateProvider { | ||
interface AudioManager { | ||
|
||
void onAudioManagerRequested(boolean requested); | ||
|
||
void setMicrophoneMute(boolean mute); | ||
|
||
void setSpeakerphoneOn(boolean on); | ||
|
||
|
||
} | ||
|
||
static public final String TAG = "FlutterWebRTCPlugin"; | ||
|
||
private final Map<String, PeerConnectionObserver> mPeerConnectionObservers = new HashMap<>(); | ||
|
@@ -112,18 +105,18 @@ interface AudioManager { | |
*/ | ||
private GetUserMediaImpl getUserMediaImpl; | ||
|
||
private final AudioManager audioManager; | ||
private final AudioSwitchManager audioSwitchManager; | ||
|
||
private AudioDeviceModule audioDeviceModule; | ||
|
||
private Activity activity; | ||
|
||
MethodCallHandlerImpl(Context context, BinaryMessenger messenger, TextureRegistry textureRegistry, | ||
@NonNull AudioManager audioManager) { | ||
@NonNull AudioSwitchManager audioManager) { | ||
this.context = context; | ||
this.textures = textureRegistry; | ||
this.messenger = messenger; | ||
this.audioManager = audioManager; | ||
this.audioSwitchManager = audioManager; | ||
} | ||
|
||
static private void resultError(String method, String error, Result result) { | ||
|
@@ -472,14 +465,29 @@ public void onMethodCall(MethodCall call, @NonNull Result notSafeResult) { | |
result.success(null); | ||
break; | ||
} | ||
case "selectAudioOutput": { | ||
String deviceId = call.argument("deviceId"); | ||
audioSwitchManager.selectAudioOutput(AudioDeviceKind.fromTypeName(deviceId)); | ||
result.success(null); | ||
break; | ||
} | ||
case "setMicrophoneMute": | ||
boolean mute = call.argument("mute"); | ||
audioManager.setMicrophoneMute(mute); | ||
audioSwitchManager.setMicrophoneMute(mute); | ||
result.success(null); | ||
break; | ||
case "selectAudioInput": | ||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) { | ||
String deviceId = call.argument("deviceId"); | ||
getUserMediaImpl.setPreferredInputDevice(Integer.parseInt(deviceId)); | ||
result.success(null); | ||
} else { | ||
result.notImplemented(); | ||
} | ||
break; | ||
case "enableSpeakerphone": | ||
boolean enable = call.argument("enable"); | ||
audioManager.setSpeakerphoneOn(enable); | ||
audioSwitchManager.enableSpeakerphone(enable); | ||
result.success(null); | ||
break; | ||
case "getDisplayMedia": { | ||
|
@@ -980,14 +988,14 @@ public String peerConnectionInit(ConstraintsMap configuration, ConstraintsMap co | |
if (mPeerConnectionObservers.size() == 0) { | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S | ||
|| context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.S) { | ||
audioManager.onAudioManagerRequested(true); | ||
//audioSwitchManager.start(); | ||
} else { | ||
ArrayList<String> permissions = new ArrayList<>(); | ||
permissions.add(Manifest.permission.BLUETOOTH_CONNECT); | ||
requestPermissions( | ||
permissions, | ||
(args) -> { | ||
audioManager.onAudioManagerRequested(true); | ||
//audioSwitchManager.start(); | ||
}, | ||
(args) -> { | ||
}); | ||
|
@@ -1143,22 +1151,36 @@ public void getSources(Result result) { | |
audio.putString("kind", "audioinput"); | ||
array.pushMap(audio); | ||
} else { | ||
android.media.AudioManager audioManager = ((android.media.AudioManager) context.getSystemService(Context.AUDIO_SERVICE)); | ||
android.media.AudioManager audioManager = ((android.media.AudioManager) context | ||
.getSystemService(Context.AUDIO_SERVICE)); | ||
final AudioDeviceInfo[] devices = audioManager.getDevices(android.media.AudioManager.GET_DEVICES_INPUTS); | ||
for (int i=0;i<devices.length;i++) { | ||
AudioDeviceInfo device=devices[i]; | ||
int type = (device.getType() & 0xFF); | ||
String label=Build.VERSION.SDK_INT < Build.VERSION_CODES.P ? String.valueOf(i) : device.getAddress(); | ||
ConstraintsMap audio = new ConstraintsMap(); | ||
audio.putString("label", label); | ||
audio.putString("deviceId", String.valueOf(i)); | ||
audio.putString("groupId", ""+type); | ||
audio.putString("facing", ""); | ||
audio.putString("kind", "audioinput"); | ||
array.pushMap(audio); | ||
for (int i = 0; i < devices.length; i++) { | ||
AudioDeviceInfo device = devices[i]; | ||
if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_MIC || device.getType() == AudioDeviceInfo.TYPE_BLUETOOTH_SCO || | ||
device.getType() == AudioDeviceInfo.TYPE_WIRED_HEADSET) { | ||
int type = (device.getType() & 0xFF); | ||
String label = Build.VERSION.SDK_INT < Build.VERSION_CODES.P ? String.valueOf(i) : device.getAddress(); | ||
ConstraintsMap audio = new ConstraintsMap(); | ||
audio.putString("label", label); | ||
audio.putString("deviceId", String.valueOf(i)); | ||
audio.putString("groupId", "" + type); | ||
audio.putString("facing", ""); | ||
audio.putString("kind", "audioinput"); | ||
array.pushMap(audio); | ||
} | ||
} | ||
} | ||
|
||
List<? extends AudioDevice> audioOutputs = audioSwitchManager.availableAudioDevices(); | ||
|
||
for (AudioDevice audioOutput : audioOutputs) { | ||
ConstraintsMap audioOutputMap = new ConstraintsMap(); | ||
audioOutputMap.putString("label", audioOutput.getName()); | ||
audioOutputMap.putString("deviceId", AudioDeviceKind.fromAudioDevice(audioOutput).typeName); | ||
audioOutputMap.putString("facing", ""); | ||
audioOutputMap.putString("kind", "audiooutput"); | ||
array.pushMap(audioOutputMap); | ||
} | ||
|
||
ConstraintsMap map = new ConstraintsMap(); | ||
map.putArray("sources", array.toArrayList()); | ||
|
@@ -1545,7 +1567,7 @@ public void peerConnectionDispose(final String id) { | |
mPeerConnectionObservers.remove(id); | ||
} | ||
if (mPeerConnectionObservers.size() == 0) { | ||
audioManager.onAudioManagerRequested(false); | ||
//audioSwitchManager.stop(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as my previous comments @cloudwebrtc |
||
} | ||
} | ||
|
||
|
1 change: 0 additions & 1 deletion
C632
1
android/src/main/java/com/cloudwebrtc/webrtc/PeerConnectionObserver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
android/src/main/java/com/cloudwebrtc/webrtc/SimulcastVideoEncoderFactoryWrapper.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look strange that this if execute nothing. I didn't know if we need to start the manager or not. But having a if that does nothing seems useless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rechecked the code, this piece should be able to be removed,
audioSwitchManager has already called start when it is created, and start is only used to monitor device changes, so it will not take over the audio route
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this Bluetooth permission necessary?
I'm getting requested access for nearby devices but from my understanding, this shouldn't be required. My app does not require bluetooth.
Can it be removed? If not, is there a way to prevent this line from being called?
Thanks in advance!