Skip to content

Commit 2ac2afe

Browse files
committed
Add support for controlling remote submix audio routing
Add method in AudioManager to control remote submix through AudioService. AudioService controls remote submxi: enabling/disabling remote submix will: - make the sink audio device available/unavailable - make the audio source available/unavailable - force/unforce media streams to be routed to WFD Change-Id: I05d9cc7c3e8a720318ec1385737cbd46a21a3207
1 parent 7201829 commit 2ac2afe

File tree

5 files changed

+65
-3
lines changed

5 files changed

+65
-3
lines changed

media/java/android/media/AudioManager.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ public boolean isSpeakerphoneOn() {
11641164
/**
11651165
* Indicates if current platform supports use of SCO for off call use cases.
11661166
* Application wanted to use bluetooth SCO audio when the phone is not in call
1167-
* must first call thsi method to make sure that the platform supports this
1167+
* must first call this method to make sure that the platform supports this
11681168
* feature.
11691169
* @return true if bluetooth SCO can be used for audio when not in call
11701170
* false otherwise
@@ -1299,6 +1299,19 @@ public boolean isBluetoothA2dpOn() {
12991299
}
13001300
}
13011301

1302+
/**
1303+
* @hide
1304+
* Signals whether remote submix audio rerouting is enabled.
1305+
*/
1306+
public void setRemoteSubmixOn(boolean on, int address) {
1307+
IAudioService service = getService();
1308+
try {
1309+
service.setRemoteSubmixOn(on, address);
1310+
} catch (RemoteException e) {
1311+
Log.e(TAG, "Dead object in setRemoteSubmixOn", e);
1312+
}
1313+
}
1314+
13021315
/**
13031316
* Sets audio routing to the wired headset on or off.
13041317
*

media/java/android/media/AudioService.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
151151
private static final int MSG_SET_WIRED_DEVICE_CONNECTION_STATE = 21;
152152
private static final int MSG_SET_A2DP_CONNECTION_STATE = 22;
153153
// end of messages handled under wakelock
154+
private static final int MSG_SET_RSX_CONNECTION_STATE = 23; // change remote submix connection
155+
private static final int MSG_SET_FORCE_RSX_USE = 24; // force remote submix audio routing
154156

155157
// flags for MSG_PERSIST_VOLUME indicating if current and/or last audible volume should be
156158
// persisted
@@ -2109,6 +2111,33 @@ public void onServiceDisconnected(int profile) {
21092111
}
21102112
};
21112113

2114+
/** see AudioManager.setRemoteSubmixOn(boolean on) */
2115+
public void setRemoteSubmixOn(boolean on, int address) {
2116+
sendMsg(mAudioHandler, MSG_SET_RSX_CONNECTION_STATE,
2117+
SENDMSG_REPLACE /* replace with QUEUE when multiple addresses are supported */,
2118+
on ? 1 : 0 /*arg1*/,
2119+
address /*arg2*/,
2120+
null/*obj*/, 0/*delay*/);
2121+
2122+
// Note that we are currently forcing use of remote submix as soon as corresponding device
2123+
// is made available
2124+
sendMsg(mAudioHandler, MSG_SET_FORCE_RSX_USE, SENDMSG_REPLACE,
2125+
AudioSystem.FOR_MEDIA,
2126+
on ? AudioSystem.FORCE_REMOTE_SUBMIX : AudioSystem.FORCE_NONE,
2127+
null/*obj*/, 0/*delay*/);
2128+
}
2129+
2130+
private void onSetRsxConnectionState(int available, int address) {
2131+
AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_IN_REMOTE_SUBMIX,
2132+
available == 1 ?
2133+
AudioSystem.DEVICE_STATE_AVAILABLE : AudioSystem.DEVICE_STATE_UNAVAILABLE,
2134+
String.valueOf(address) /*device_address*/);
2135+
AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_REMOTE_SUBMIX,
2136+
available == 1 ?
2137+
AudioSystem.DEVICE_STATE_AVAILABLE : AudioSystem.DEVICE_STATE_UNAVAILABLE,
2138+
String.valueOf(address) /*device_address*/);
2139+
}
2140+
21122141
///////////////////////////////////////////////////////////////////////////
21132142
// Internal methods
21142143
///////////////////////////////////////////////////////////////////////////
@@ -3072,6 +3101,7 @@ public void handleMessage(Message msg) {
30723101

30733102
case MSG_SET_FORCE_USE:
30743103
case MSG_SET_FORCE_BT_A2DP_USE:
3104+
case MSG_SET_FORCE_RSX_USE:
30753105
setForceUse(msg.arg1, msg.arg2);
30763106
break;
30773107

@@ -3134,6 +3164,10 @@ public void handleMessage(Message msg) {
31343164
onRegisterVolumeObserverForRcc(msg.arg1 /* rccId */,
31353165
(IRemoteVolumeObserver)msg.obj /* rvo */);
31363166
break;
3167+
3168+
case MSG_SET_RSX_CONNECTION_STATE:
3169+
onSetRsxConnectionState(msg.arg1/*available*/, msg.arg2/*address*/);
3170+
break;
31373171
}
31383172
}
31393173
}

media/java/android/media/AudioSystem.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ private static void errorCallbackFromNative(int error)
214214
public static final int DEVICE_OUT_REMOTE_SUBMIX = 0x8000;
215215

216216
public static final int DEVICE_OUT_DEFAULT = DEVICE_BIT_DEFAULT;
217+
217218
public static final int DEVICE_OUT_ALL = (DEVICE_OUT_EARPIECE |
218219
DEVICE_OUT_SPEAKER |
219220
DEVICE_OUT_WIRED_HEADSET |
@@ -352,7 +353,8 @@ public static String getDeviceName(int device)
352353
public static final int FORCE_ANALOG_DOCK = 8;
353354
public static final int FORCE_DIGITAL_DOCK = 9;
354355
public static final int FORCE_NO_BT_A2DP = 10;
355-
private static final int NUM_FORCE_CONFIG = 11;
356+
public static final int FORCE_REMOTE_SUBMIX = 11;
357+
private static final int NUM_FORCE_CONFIG = 12;
356358
public static final int FORCE_DEFAULT = FORCE_NONE;
357359

358360
// usage for setForceUse, must match AudioSystem::force_use

media/java/android/media/IAudioService.aidl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ interface IAudioService {
108108

109109
boolean isBluetoothA2dpOn();
110110

111+
oneway void setRemoteSubmixOn(boolean on, int address);
112+
111113
int requestAudioFocus(int mainStreamType, int durationHint, IBinder cb, IAudioFocusDispatcher l,
112114
String clientId, String callingPackageName);
113115

media/java/android/media/MediaRecorder.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ private AudioSource() {}
177177
* is applied.
178178
*/
179179
public static final int VOICE_COMMUNICATION = 7;
180+
181+
/**
182+
* @hide
183+
* Audio source for remote submix.
184+
*/
185+
public static final int REMOTE_SUBMIX_SOURCE = 8;
180186
}
181187

182188
/**
@@ -291,7 +297,12 @@ public native void setAudioSource(int audio_source)
291297
* Gets the maximum value for audio sources.
292298
* @see android.media.MediaRecorder.AudioSource
293299
*/
294-
public static final int getAudioSourceMax() { return AudioSource.VOICE_COMMUNICATION; }
300+
public static final int getAudioSourceMax() {
301+
// FIXME disable selection of the remote submxi source selection once test code
302+
// doesn't rely on it
303+
return AudioSource.REMOTE_SUBMIX_SOURCE;
304+
//return AudioSource.VOICE_COMMUNICATION;
305+
}
295306

296307
/**
297308
* Sets the video source to be used for recording. If this method is not

0 commit comments

Comments
 (0)