audio policy: refactor preferred route implementation
Remove SessionRoute class and replace by use of
preferredDevice and active state in ClientDescriptor
Also fix the behavior for other clients using same strategy as
client with preferred route: the preferred route is only used if
no other clients using the same strategy are active without a preferred
route.
If all clients have a preferred route, the route of the last active
client is used.
Also fixed getOutputForAttr() to return correct selected device ID when
dynamic policies are used.
Test: CTS RoutingTest, AudioPlayRoutingNative, AudioRecordRoutingNative
Test: Manual: AudioExplicitRouting, UplinkMusicSampleApp
Change-Id: Id342c2241ace3e1a359ea74f4a539a395f793b86
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.h b/services/audiopolicy/managerdefault/AudioPolicyManager.h
index 9436767..cc5739b 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.h
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.h
@@ -49,7 +49,6 @@
#include <AudioPolicyMix.h>
#include <EffectDescriptor.h>
#include <SoundTriggerSession.h>
-#include <SessionRoute.h>
#include <VolumeCurve.h>
namespace android {
@@ -156,7 +155,7 @@
// return the strategy corresponding to a given stream type
virtual uint32_t getStrategyForStream(audio_stream_type_t stream);
// return the strategy corresponding to the given audio attributes
- virtual uint32_t getStrategyForAttr(const audio_attributes_t *attr);
+ virtual routing_strategy getStrategyForAttr(const audio_attributes_t *attr);
// return the enabled output devices for the given stream type
virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream);
@@ -366,7 +365,7 @@
bool on,
const sp<AudioOutputDescriptor>& outputDesc,
int delayMs = 0,
- audio_devices_t device = (audio_devices_t)0);
+ audio_devices_t device = AUDIO_DEVICE_NONE);
// Mute or unmute the stream on the specified output
void setStreamMute(audio_stream_type_t stream,
@@ -422,6 +421,14 @@
// manages A2DP output suspend/restore according to phone state and BT SCO usage
void checkA2dpSuspend();
+ template <class IoDescriptor, class Filter>
+ sp<DeviceDescriptor> findPreferredDevice(IoDescriptor& desc, Filter filter,
+ bool& active, const DeviceVector& devices);
+
+ template <class IoCollection, class Filter>
+ sp<DeviceDescriptor> findPreferredDevice(IoCollection& ioCollection, Filter filter,
+ const DeviceVector& devices);
+
// selects the most appropriate device on output for current state
// must be called every time a condition that affects the device choice for a given output is
// changed: connected device, phone state, force use, output start, output stop..
@@ -508,16 +515,11 @@
sp<DeviceDescriptor> findDevice(
const DeviceVector& devices, audio_devices_t device) const;
- // if argument "device" is different from AUDIO_DEVICE_NONE, startSource() will force
- // the re-evaluation of the output device.
- status_t startSource(const sp<AudioOutputDescriptor>& outputDesc,
- audio_stream_type_t stream,
- audio_devices_t device,
- const char *address,
+ status_t startSource(const sp<SwAudioOutputDescriptor>& outputDesc,
+ const sp<TrackClientDescriptor>& client,
uint32_t *delayMs);
- status_t stopSource(const sp<AudioOutputDescriptor>& outputDesc,
- audio_stream_type_t stream,
- bool forceDeviceUpdate);
+ status_t stopSource(const sp<SwAudioOutputDescriptor>& outputDesc,
+ const sp<TrackClientDescriptor>& client);
void clearAudioPatches(uid_t uid);
void clearSessionRoutes(uid_t uid);
@@ -561,9 +563,6 @@
DeviceVector mAvailableOutputDevices; // all available output devices
DeviceVector mAvailableInputDevices; // all available input devices
- SessionRouteMap mOutputRoutes = SessionRouteMap(SessionRouteMap::MAPTYPE_OUTPUT);
- SessionRouteMap mInputRoutes = SessionRouteMap(SessionRouteMap::MAPTYPE_INPUT);
-
bool mLimitRingtoneVolume; // limit ringtone volume to music volume if headset connected
audio_devices_t mDeviceForStrategy[NUM_STRATEGIES];
float mLastVoiceVolume; // last voice volume value sent to audio HAL