Loading policy_hal/AudioPolicyManager.cpp +37 −18 Original line number Original line Diff line number Diff line Loading @@ -52,7 +52,7 @@ // type alone is not enough: the address must match too // type alone is not enough: the address must match too #define APM_AUDIO_DEVICE_MATCH_ADDRESS_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX | \ #define APM_AUDIO_DEVICE_MATCH_ADDRESS_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX | \ AUDIO_DEVICE_OUT_REMOTE_SUBMIX) AUDIO_DEVICE_OUT_REMOTE_SUBMIX) #define SAMPLE_RATE_8000 8000 #include <inttypes.h> #include <inttypes.h> #include <math.h> #include <math.h> Loading Loading @@ -1293,17 +1293,41 @@ bool AudioPolicyManagerCustom::isDirectOutput(audio_io_handle_t output) { return false; return false; } } bool static isDirectPCMEnabled(int bitWidth) bool static tryForDirectPCM(int bitWidth, audio_output_flags_t *flags, uint32_t samplingRate) { { bool directPCMEnabled = false; 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) if (bitWidth == 24 || bitWidth == 32) directPCMEnabled = playerDirectPCM = property_get_bool("audio.offload.pcm.24bit.enable", false); property_get_bool("audio.offload.pcm.24bit.enable", false); else else directPCMEnabled = playerDirectPCM = property_get_bool("audio.offload.pcm.16bit.enable", false); 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)) { trackDirectPCM = property_get_bool("audio.offload.track.enable", true); } return directPCMEnabled; ALOGI("Direct PCM %s for this request", (!offloadDisabled && (trackDirectPCM || playerDirectPCM))?"can be enabled":"is disabled"); return (!offloadDisabled && (trackDirectPCM || playerDirectPCM)); } } status_t AudioPolicyManagerCustom::getOutputForAttr(const audio_attributes_t *attr, status_t AudioPolicyManagerCustom::getOutputForAttr(const audio_attributes_t *attr, Loading @@ -1320,16 +1344,11 @@ status_t AudioPolicyManagerCustom::getOutputForAttr(const audio_attributes_t *at { { audio_offload_info_t tOffloadInfo = AUDIO_INFO_INITIALIZER; audio_offload_info_t tOffloadInfo = AUDIO_INFO_INITIALIZER; bool offloadDisabled = property_get_bool("audio.offload.disable", false); uint32_t bitWidth = (audio_bytes_per_sample(format) * 8); uint32_t bitWidth = (audio_bytes_per_sample(format) * 8); if (offloadDisabled) { ALOGI("offload disabled by audio.offload.disable=%d", offloadDisabled); } if (!offloadDisabled && (offloadInfo == NULL) && if (tryForDirectPCM(bitWidth, &flags, samplingRate) && isDirectPCMEnabled(bitWidth) && (offloadInfo == NULL)) { (flags == AUDIO_OUTPUT_FLAG_NONE)) { tOffloadInfo.sample_rate = samplingRate; tOffloadInfo.sample_rate = samplingRate; tOffloadInfo.channel_mask = channelMask; tOffloadInfo.channel_mask = channelMask; Loading Loading
policy_hal/AudioPolicyManager.cpp +37 −18 Original line number Original line Diff line number Diff line Loading @@ -52,7 +52,7 @@ // type alone is not enough: the address must match too // type alone is not enough: the address must match too #define APM_AUDIO_DEVICE_MATCH_ADDRESS_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX | \ #define APM_AUDIO_DEVICE_MATCH_ADDRESS_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX | \ AUDIO_DEVICE_OUT_REMOTE_SUBMIX) AUDIO_DEVICE_OUT_REMOTE_SUBMIX) #define SAMPLE_RATE_8000 8000 #include <inttypes.h> #include <inttypes.h> #include <math.h> #include <math.h> Loading Loading @@ -1293,17 +1293,41 @@ bool AudioPolicyManagerCustom::isDirectOutput(audio_io_handle_t output) { return false; return false; } } bool static isDirectPCMEnabled(int bitWidth) bool static tryForDirectPCM(int bitWidth, audio_output_flags_t *flags, uint32_t samplingRate) { { bool directPCMEnabled = false; 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) if (bitWidth == 24 || bitWidth == 32) directPCMEnabled = playerDirectPCM = property_get_bool("audio.offload.pcm.24bit.enable", false); property_get_bool("audio.offload.pcm.24bit.enable", false); else else directPCMEnabled = playerDirectPCM = property_get_bool("audio.offload.pcm.16bit.enable", false); 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)) { trackDirectPCM = property_get_bool("audio.offload.track.enable", true); } return directPCMEnabled; ALOGI("Direct PCM %s for this request", (!offloadDisabled && (trackDirectPCM || playerDirectPCM))?"can be enabled":"is disabled"); return (!offloadDisabled && (trackDirectPCM || playerDirectPCM)); } } status_t AudioPolicyManagerCustom::getOutputForAttr(const audio_attributes_t *attr, status_t AudioPolicyManagerCustom::getOutputForAttr(const audio_attributes_t *attr, Loading @@ -1320,16 +1344,11 @@ status_t AudioPolicyManagerCustom::getOutputForAttr(const audio_attributes_t *at { { audio_offload_info_t tOffloadInfo = AUDIO_INFO_INITIALIZER; audio_offload_info_t tOffloadInfo = AUDIO_INFO_INITIALIZER; bool offloadDisabled = property_get_bool("audio.offload.disable", false); uint32_t bitWidth = (audio_bytes_per_sample(format) * 8); uint32_t bitWidth = (audio_bytes_per_sample(format) * 8); if (offloadDisabled) { ALOGI("offload disabled by audio.offload.disable=%d", offloadDisabled); } if (!offloadDisabled && (offloadInfo == NULL) && if (tryForDirectPCM(bitWidth, &flags, samplingRate) && isDirectPCMEnabled(bitWidth) && (offloadInfo == NULL)) { (flags == AUDIO_OUTPUT_FLAG_NONE)) { tOffloadInfo.sample_rate = samplingRate; tOffloadInfo.sample_rate = samplingRate; tOffloadInfo.channel_mask = channelMask; tOffloadInfo.channel_mask = channelMask; Loading