audioflinger: implement Bluetooth latency mode control
Generalize latency mode control previously
only implemented on spatializer thread to mixer threads.
For mixer threads, latency mode control is used when a
Bluetooth A2DP or LE audio device is selected and the
audio HAL stream supports sevreal latency modes.
The following methods and class members are moved from
SpatializerThread class to MixerThread class:
- onHalLatencyModesChanged_l()
- getSupportedLatencyModes()
- mSetLatencyMode
- mSupportedLatencyModes
setHalLatencyMode_l() has a different implementation in
SpatializerThread and MixerThread.
Test: make
Bug: 257922898
Change-Id: I25106fcb7c3dd9fdeabfbbe29941c7cd3be22196
diff --git a/services/audioflinger/Threads.h b/services/audioflinger/Threads.h
index 1f0f13a..4ab4557 100644
--- a/services/audioflinger/Threads.h
+++ b/services/audioflinger/Threads.h
@@ -376,8 +376,6 @@
virtual void toAudioPortConfig(struct audio_port_config *config) = 0;
virtual void resizeInputBuffer_l(int32_t maxSharedAudioHistoryMs);
- virtual void onHalLatencyModesChanged_l() {}
-
// see note at declaration of mStandby, mOutDevice and mInDevice
bool standby() const { return mStandby; }
@@ -625,6 +623,8 @@
product_strategy_t getStrategyForStream(audio_stream_type_t stream) const;
+ virtual void onHalLatencyModesChanged_l() {}
+
virtual void dumpInternals_l(int fd __unused, const Vector<String16>& args __unused)
{ }
virtual void dumpTracks_l(int fd __unused, const Vector<String16>& args __unused) { }
@@ -1102,7 +1102,9 @@
return INVALID_OPERATION;
}
- virtual status_t setBluetoothVariableLatencyEnabled(bool enabled);
+ virtual status_t setBluetoothVariableLatencyEnabled(bool enabled __unused) {
+ return INVALID_OPERATION;
+ }
void startMelComputation(const sp<audio_utils::MelProcessor>& processor);
void stopMelComputation();
@@ -1462,12 +1464,10 @@
virtual void flushHw_l() {
mIsTimestampAdvancing.clear();
}
-
- // Bluetooth Variable latency control logic is enabled or disabled for this thread
- std::atomic_bool mBluetoothLatencyModesEnabled;
};
-class MixerThread : public PlaybackThread {
+class MixerThread : public PlaybackThread,
+ public StreamOutHalInterfaceLatencyModeCallback {
public:
MixerThread(const sp<AudioFlinger>& audioFlinger,
AudioStreamOut* output,
@@ -1477,6 +1477,13 @@
audio_config_base_t *mixerConfig = nullptr);
virtual ~MixerThread();
+ // RefBase
+ virtual void onFirstRef();
+
+ // StreamOutHalInterfaceLatencyModeCallback
+ void onRecommendedLatencyModeChanged(
+ std::vector<audio_latency_mode_t> modes) override;
+
// Thread virtuals
virtual bool checkForNewParameter_l(const String8& keyValuePair,
@@ -1513,6 +1520,17 @@
virtual status_t releaseAudioPatch_l(const audio_patch_handle_t handle);
AudioMixer* mAudioMixer; // normal mixer
+
+ // Support low latency mode by default as unless explicitly indicated by the audio HAL
+ // we assume the audio path is compatible with the head tracking latency requirements
+ std::vector<audio_latency_mode_t> mSupportedLatencyModes = {AUDIO_LATENCY_MODE_LOW};
+ // default to invalid value to force first update to the audio HAL
+ audio_latency_mode_t mSetLatencyMode =
+ (audio_latency_mode_t)AUDIO_LATENCY_MODE_INVALID;
+
+ // Bluetooth Variable latency control logic is enabled or disabled for this thread
+ std::atomic_bool mBluetoothLatencyModesEnabled;
+
private:
// one-time initialization, no locks required
sp<FastMixer> mFastMixer; // non-0 if there is also a fast mixer
@@ -1546,6 +1564,11 @@
return INVALID_OPERATION;
}
+ status_t getSupportedLatencyModes(
+ std::vector<audio_latency_mode_t>* modes) override;
+
+ status_t setBluetoothVariableLatencyEnabled(bool enabled) override;
+
protected:
virtual void setMasterMono_l(bool mono) {
mMasterMono.store(mono);
@@ -1564,6 +1587,10 @@
mFastMixer->setMasterBalance(balance);
}
}
+
+ void updateHalSupportedLatencyModes_l();
+ void onHalLatencyModesChanged_l() override;
+ void setHalLatencyMode_l() override;
};
class DirectOutputThread : public PlaybackThread {
@@ -1767,8 +1794,7 @@
}
};
-class SpatializerThread : public MixerThread,
- public StreamOutHalInterfaceLatencyModeCallback {
+class SpatializerThread : public MixerThread {
public:
SpatializerThread(const sp<AudioFlinger>& audioFlinger,
AudioStreamOut* output,
@@ -1779,32 +1805,16 @@
bool hasFastMixer() const override { return false; }
- status_t createAudioPatch_l(const struct audio_patch *patch,
- audio_patch_handle_t *handle) override;
-
// RefBase
virtual void onFirstRef();
- // StreamOutHalInterfaceLatencyModeCallback
- void onRecommendedLatencyModeChanged(std::vector<audio_latency_mode_t> modes) override;
-
status_t setRequestedLatencyMode(audio_latency_mode_t mode) override;
- status_t getSupportedLatencyModes(std::vector<audio_latency_mode_t>* modes) override;
protected:
void checkOutputStageEffects() override;
- void onHalLatencyModesChanged_l() override;
void setHalLatencyMode_l() override;
private:
- void updateHalSupportedLatencyModes_l();
-
- // Support low latency mode by default as unless explicitly indicated by the audio HAL
- // we assume the audio path is compatible with the head tracking latency requirements
- std::vector<audio_latency_mode_t> mSupportedLatencyModes = {AUDIO_LATENCY_MODE_LOW};
- // default to invalid value to force first update to the audio HAL
- audio_latency_mode_t mSetLatencyMode =
- (audio_latency_mode_t)AUDIO_LATENCY_MODE_INVALID;
// Do not request a specific mode by default
audio_latency_mode_t mRequestedLatencyMode = AUDIO_LATENCY_MODE_FREE;