audio: make direct output independent of DIRECT_PCM flag
- Make direct output independent of flag AUDIO_OUTPUT_FLAG_DIRECT_PCM.
- Remove multi-channel profile as it is redundant with respect to
direct output profiles.
Change-Id: I7f5fef656f1d8796872e4d297da3220c3e69951d
diff --git a/policy_hal/AudioPolicyManager.cpp b/policy_hal/AudioPolicyManager.cpp
index 8a572fa..c258a39 100644
--- a/policy_hal/AudioPolicyManager.cpp
+++ b/policy_hal/AudioPolicyManager.cpp
@@ -1374,41 +1374,14 @@
return false;
}
-bool static tryForDirectPCM(int bitWidth, audio_output_flags_t *flags, uint32_t samplingRate)
+bool static tryForDirectPCM(audio_output_flags_t flags)
{
- bool playerDirectPCM = false; // Output request for Track created by mediaplayer
bool trackDirectPCM = false; // Output request for track created by other apps
- bool offloadDisabled = property_get_bool("audio.offload.disable", false);
- // Direct PCM is allowed only if
- // In case of mediaPlayer playback
- // 16 bit direct pcm or 24bit direct PCM property is set and
- // the FLAG requested is DIRECT_PCM ( NuPlayer case) or
- // In case of AudioTracks created by apps
- // track offload is enabled and FLAG requested is FLAG_NONE.
-
- if (offloadDisabled) {
- ALOGI("offload disabled by audio.offload.disable=%d", offloadDisabled);
- }
-
- if (*flags == AUDIO_OUTPUT_FLAG_DIRECT_PCM) {
- if (bitWidth == 24 || bitWidth == 32)
- playerDirectPCM =
- property_get_bool("audio.offload.pcm.24bit.enable", false);
- else
- playerDirectPCM =
- property_get_bool("audio.offload.pcm.16bit.enable", false);
- // Reset flag to NONE so that we can still reuse direct pcm criteria check
- // in getOutputforDevice
- *flags = AUDIO_OUTPUT_FLAG_NONE;
- } else if ((*flags == AUDIO_OUTPUT_FLAG_NONE) && (samplingRate % SAMPLE_RATE_8000 == 0)) {
+ if (flags == AUDIO_OUTPUT_FLAG_NONE) {
trackDirectPCM = property_get_bool("audio.offload.track.enable", true);
}
-
- ALOGI("Direct PCM %s for this request",
- (!offloadDisabled && (trackDirectPCM || playerDirectPCM))?"can be enabled":"is disabled");
-
- return (!offloadDisabled && (trackDirectPCM || playerDirectPCM));
+ return trackDirectPCM;
}
status_t AudioPolicyManagerCustom::getOutputForAttr(const audio_attributes_t *attr,
@@ -1421,14 +1394,13 @@
audio_port_handle_t selectedDeviceId,
audio_port_handle_t *portId)
{
-
audio_offload_info_t tOffloadInfo = AUDIO_INFO_INITIALIZER;
audio_config_t tConfig;
uint32_t bitWidth = (audio_bytes_per_sample(config->format) * 8);
memcpy(&tConfig, config, sizeof(audio_config_t));
- if (tryForDirectPCM(bitWidth, &flags, config->sample_rate) &&
+ if ((flags == AUDIO_OUTPUT_FLAG_DIRECT || tryForDirectPCM(flags)) &&
(!memcmp(&config->offload_info, &tOffloadInfo, sizeof(audio_offload_info_t)))) {
tConfig.offload_info.sample_rate = config->sample_rate;
tConfig.offload_info.channel_mask = config->channel_mask;
@@ -1705,6 +1677,20 @@
flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT);
}
+ // Do internal direct magic here
+ bool offload_disabled = property_get_bool("audio.offload.disable", false);
+ if ((flags == AUDIO_OUTPUT_FLAG_NONE) &&
+ (stream == AUDIO_STREAM_MUSIC) &&
+ (offloadInfo != NULL) && !offload_disabled &&
+ ((offloadInfo->usage == AUDIO_USAGE_MEDIA) || (offloadInfo->usage == AUDIO_USAGE_GAME))) {
+ audio_output_flags_t old_flags = flags;
+ flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_DIRECT);
+ ALOGD("AudioCustomHAL --> Force Direct Flag .. old flags(0x%x)", old_flags);
+ } else if (flags == AUDIO_OUTPUT_FLAG_DIRECT && offload_disabled) {
+ ALOGD("AudioCustomHAL --> offloading is disabled: Force Remove Direct Flag");
+ flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_NONE);
+ }
+
bool forced_deep = false;
// only allow deep buffering for music stream type
if (stream != AUDIO_STREAM_MUSIC) {
@@ -1719,31 +1705,11 @@
flags = AUDIO_OUTPUT_FLAG_TTS;
}
- // check if direct output for track offload already exits
- bool is_track_offload_active = false;
- for (size_t i = 0; i < mOutputs.size(); i++) {
- sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
- if (desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) {
- is_track_offload_active = true;
- ALOGD("Track offload already active");
- break;
- }
- }
-
- // Do offload magic here
- if ((flags == AUDIO_OUTPUT_FLAG_NONE) &&
- (stream == AUDIO_STREAM_MUSIC) &&
- (offloadInfo != NULL) && !is_track_offload_active &&
- ((offloadInfo->usage == AUDIO_USAGE_MEDIA) || (offloadInfo->usage == AUDIO_USAGE_GAME))) {
- flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_DIRECT_PCM);
- ALOGD("AudioCustomHAL --> Force Direct Flag .. flag (0x%x)", flags);
- }
-
sp<IOProfile> profile;
// skip direct output selection if the request can obviously be attached to a mixed output
// and not explicitly requested
- if (((flags & (AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM)) == 0) &&
+ if (((flags & AUDIO_OUTPUT_FLAG_DIRECT) == 0) &&
audio_is_linear_pcm(format) && samplingRate <= SAMPLE_RATE_HZ_MAX &&
audio_channel_count_from_out_mask(channelMask) <= 2) {
goto non_direct_output;
@@ -1759,7 +1725,7 @@
// Supplementary annotation:
// For sake of track offload introduced, we need a rollback for both compress offload
// and track offload use cases.
- if ((flags & (AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD|AUDIO_OUTPUT_FLAG_DIRECT_PCM)) &&
+ if ((flags & (AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD|AUDIO_OUTPUT_FLAG_DIRECT)) &&
(mEffects.isNonOffloadableEffectEnabled() || mMasterMono)) {
ALOGD("non offloadable effect is enabled, try with non direct output");
goto non_direct_output;
@@ -1773,9 +1739,9 @@
if (profile != 0) {
- if (!(flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) &&
- (profile->getFlags() & AUDIO_OUTPUT_FLAG_DIRECT_PCM)) {
- ALOGI("got Direct_PCM without requesting ... reject ");
+ if (!(flags & AUDIO_OUTPUT_FLAG_DIRECT) &&
+ (profile->getFlags() & AUDIO_OUTPUT_FLAG_DIRECT)) {
+ ALOGI("got Direct without requesting ... reject ");
profile = NULL;
goto non_direct_output;
}
@@ -1786,7 +1752,7 @@
// do no check for reuse and also don't close previous output if its offload
// previous output will be closed during track destruction
if (!(property_get_bool("audio.offload.multiple.enabled", false) &&
- ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0))) {
+ ((flags & AUDIO_OUTPUT_FLAG_DIRECT) != 0))) {
for (size_t i = 0; i < mOutputs.size(); i++) {
sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
if (!desc->isDuplicated() && (profile == desc->mProfile)) {