Loading services/audioflinger/AudioFlinger.cpp +2 −24 Original line number Diff line number Diff line Loading @@ -2886,28 +2886,6 @@ sp<IAfThreadBase> AudioFlinger::openOutput_l(audio_module_handle_t module, } mHardwareStatus = AUDIO_HW_OUTPUT_OPEN; // FOR TESTING ONLY: // This if statement allows overriding the audio policy settings // and forcing a specific format or channel mask to the HAL/Sink device for testing. if (!(flags & (AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | AUDIO_OUTPUT_FLAG_DIRECT))) { // Check only for Normal Mixing mode if (kEnableExtendedPrecision) { // Specify format (uncomment one below to choose) //halConfig->format = AUDIO_FORMAT_PCM_FLOAT; //halConfig->format = AUDIO_FORMAT_PCM_24_BIT_PACKED; //halConfig->format = AUDIO_FORMAT_PCM_32_BIT; //halConfig->format = AUDIO_FORMAT_PCM_8_24_BIT; // ALOGV("openOutput_l() upgrading format to %#08x", halConfig->format); } if (kEnableExtendedChannels) { // Specify channel mask (uncomment one below to choose) //halConfig->channel_mask = audio_channel_out_mask_from_count(4); // for USB 4ch //halConfig->channel_mask = audio_channel_mask_from_representation_and_bits( // AUDIO_CHANNEL_REPRESENTATION_INDEX, (1 << 4) - 1); // another 4ch example } } AudioStreamOut *outputStream = NULL; status_t status = outHwDev->openOutputStream( &outputStream, Loading Loading @@ -2945,8 +2923,8 @@ sp<IAfThreadBase> AudioFlinger::openOutput_l(audio_module_handle_t module, ALOGV("openOutput_l() created offload output: ID %d thread %p", *output, thread.get()); } else if ((flags & AUDIO_OUTPUT_FLAG_DIRECT) || !isValidPcmSinkFormat(halConfig->format) || !isValidPcmSinkChannelMask(halConfig->channel_mask)) { || !IAfThreadBase::isValidPcmSinkFormat(halConfig->format) || !IAfThreadBase::isValidPcmSinkChannelMask(halConfig->channel_mask)) { thread = IAfPlaybackThread::createDirectOutputThread(this, outputStream, *output, mSystemReady, halConfig->offload_info); ALOGV("openOutput_l() created direct output: ID %d thread %p", Loading services/audioflinger/AudioFlinger.h +0 −53 Original line number Diff line number Diff line Loading @@ -501,63 +501,10 @@ private: AudioHwDevice* findSuitableHwDev_l(audio_module_handle_t module, audio_devices_t deviceType); // Set kEnableExtendedChannels to true to enable greater than stereo output // for the MixerThread and device sink. Number of channels allowed is // FCC_2 <= channels <= AudioMixer::MAX_NUM_CHANNELS. static const bool kEnableExtendedChannels = true; public: // Remove this when Oboeservice is updated to obtain handle directly. static inline std::atomic<AudioFlinger*> gAudioFlinger = nullptr; // Returns true if channel mask is permitted for the PCM sink in the MixerThread static inline bool isValidPcmSinkChannelMask(audio_channel_mask_t channelMask) { switch (audio_channel_mask_get_representation(channelMask)) { case AUDIO_CHANNEL_REPRESENTATION_POSITION: { // Haptic channel mask is only applicable for channel position mask. const uint32_t channelCount = audio_channel_count_from_out_mask( static_cast<audio_channel_mask_t>(channelMask & ~AUDIO_CHANNEL_HAPTIC_ALL)); const uint32_t maxChannelCount = kEnableExtendedChannels ? AudioMixer::MAX_NUM_CHANNELS : FCC_2; if (channelCount < FCC_2 // mono is not supported at this time || channelCount > maxChannelCount) { return false; } // check that channelMask is the "canonical" one we expect for the channelCount. return audio_channel_position_mask_is_out_canonical(channelMask); } case AUDIO_CHANNEL_REPRESENTATION_INDEX: if (kEnableExtendedChannels) { const uint32_t channelCount = audio_channel_count_from_out_mask(channelMask); if (channelCount >= FCC_2 // mono is not supported at this time && channelCount <= AudioMixer::MAX_NUM_CHANNELS) { return true; } } return false; default: return false; } } // Set kEnableExtendedPrecision to true to use extended precision in MixerThread static const bool kEnableExtendedPrecision = true; // Returns true if format is permitted for the PCM sink in the MixerThread static inline bool isValidPcmSinkFormat(audio_format_t format) { switch (format) { case AUDIO_FORMAT_PCM_16_BIT: return true; case AUDIO_FORMAT_PCM_FLOAT: case AUDIO_FORMAT_PCM_24_BIT_PACKED: case AUDIO_FORMAT_PCM_32_BIT: case AUDIO_FORMAT_PCM_8_24_BIT: return kEnableExtendedPrecision; default: return false; } } private: // incremented by 2 when screen state changes, bit 0 == 1 means "off" Loading services/audioflinger/IAfThread.h +3 −0 Original line number Diff line number Diff line Loading @@ -117,6 +117,9 @@ public: }; static const char* threadTypeToString(type_t type); static bool isValidPcmSinkChannelMask(audio_channel_mask_t channelMask); static bool isValidPcmSinkFormat(audio_format_t format); virtual status_t readyToRun() = 0; virtual void clearPowerManager() = 0; virtual status_t initCheck() const = 0; Loading services/audioflinger/Threads.cpp +61 −6 Original line number Diff line number Diff line Loading @@ -257,6 +257,61 @@ static nsecs_t getStandbyTimeInNanos() { return standbyTimeInNanos; } // Set kEnableExtendedChannels to true to enable greater than stereo output // for the MixerThread and device sink. Number of channels allowed is // FCC_2 <= channels <= FCC_LIMIT. constexpr bool kEnableExtendedChannels = true; // Returns true if channel mask is permitted for the PCM sink in the MixerThread /* static */ bool IAfThreadBase::isValidPcmSinkChannelMask(audio_channel_mask_t channelMask) { switch (audio_channel_mask_get_representation(channelMask)) { case AUDIO_CHANNEL_REPRESENTATION_POSITION: { // Haptic channel mask is only applicable for channel position mask. const uint32_t channelCount = audio_channel_count_from_out_mask( static_cast<audio_channel_mask_t>(channelMask & ~AUDIO_CHANNEL_HAPTIC_ALL)); const uint32_t maxChannelCount = kEnableExtendedChannels ? FCC_LIMIT : FCC_2; if (channelCount < FCC_2 // mono is not supported at this time || channelCount > maxChannelCount) { return false; } // check that channelMask is the "canonical" one we expect for the channelCount. return audio_channel_position_mask_is_out_canonical(channelMask); } case AUDIO_CHANNEL_REPRESENTATION_INDEX: if (kEnableExtendedChannels) { const uint32_t channelCount = audio_channel_count_from_out_mask(channelMask); if (channelCount >= FCC_2 // mono is not supported at this time && channelCount <= FCC_LIMIT) { return true; } } return false; default: return false; } } // Set kEnableExtendedPrecision to true to use extended precision in MixerThread constexpr bool kEnableExtendedPrecision = true; // Returns true if format is permitted for the PCM sink in the MixerThread /* static */ bool IAfThreadBase::isValidPcmSinkFormat(audio_format_t format) { switch (format) { case AUDIO_FORMAT_PCM_16_BIT: return true; case AUDIO_FORMAT_PCM_FLOAT: case AUDIO_FORMAT_PCM_24_BIT_PACKED: case AUDIO_FORMAT_PCM_32_BIT: case AUDIO_FORMAT_PCM_8_24_BIT: return kEnableExtendedPrecision; default: return false; } } // ---------------------------------------------------------------------------- // TODO: move all toString helpers to audio.h Loading Loading @@ -2055,12 +2110,12 @@ PlaybackThread::PlaybackThread(const sp<IAfThreadCallback>& afThreadCallback, audio_config_base_t *mixerConfig) : ThreadBase(afThreadCallback, id, type, systemReady, true /* isOut */), mNormalFrameCount(0), mSinkBuffer(NULL), mMixerBufferEnabled(AudioFlinger::kEnableExtendedPrecision || type == SPATIALIZER), mMixerBufferEnabled(kEnableExtendedPrecision || type == SPATIALIZER), mMixerBuffer(NULL), mMixerBufferSize(0), mMixerBufferFormat(AUDIO_FORMAT_INVALID), mMixerBufferValid(false), mEffectBufferEnabled(AudioFlinger::kEnableExtendedPrecision || type == SPATIALIZER), mEffectBufferEnabled(kEnableExtendedPrecision || type == SPATIALIZER), mEffectBuffer(NULL), mEffectBufferSize(0), mEffectBufferFormat(AUDIO_FORMAT_INVALID), Loading Loading @@ -3043,7 +3098,7 @@ void PlaybackThread::readOutputParameters_l() if (!audio_is_output_channel(mChannelMask)) { LOG_ALWAYS_FATAL("HAL channel mask %#x not valid for output", mChannelMask); } if (hasMixer() && !AudioFlinger::isValidPcmSinkChannelMask(mChannelMask)) { if (hasMixer() && !isValidPcmSinkChannelMask(mChannelMask)) { LOG_ALWAYS_FATAL("HAL channel mask %#x not supported for mixed output", mChannelMask); } Loading @@ -3066,7 +3121,7 @@ void PlaybackThread::readOutputParameters_l() if (!audio_is_valid_format(mFormat)) { LOG_ALWAYS_FATAL("HAL format %#x not valid for output", mFormat); } if (hasMixer() && !AudioFlinger::isValidPcmSinkFormat(mFormat)) { if (hasMixer() && !isValidPcmSinkFormat(mFormat)) { LOG_FATAL("HAL format %#x not supported for mixed output", mFormat); } Loading Loading @@ -6195,7 +6250,7 @@ bool MixerThread::checkForNewParameter_l(const String8& keyValuePair, reconfig = true; } if (param.getInt(String8(AudioParameter::keyFormat), value) == NO_ERROR) { if (!AudioFlinger::isValidPcmSinkFormat(static_cast<audio_format_t>(value))) { if (!isValidPcmSinkFormat(static_cast<audio_format_t>(value))) { status = BAD_VALUE; } else { // no need to save value, since it's constant Loading @@ -6203,7 +6258,7 @@ bool MixerThread::checkForNewParameter_l(const String8& keyValuePair, } } if (param.getInt(String8(AudioParameter::keyChannels), value) == NO_ERROR) { if (!AudioFlinger::isValidPcmSinkChannelMask(static_cast<audio_channel_mask_t>(value))) { if (!isValidPcmSinkChannelMask(static_cast<audio_channel_mask_t>(value))) { status = BAD_VALUE; } else { // no need to save value, since it's constant Loading Loading
services/audioflinger/AudioFlinger.cpp +2 −24 Original line number Diff line number Diff line Loading @@ -2886,28 +2886,6 @@ sp<IAfThreadBase> AudioFlinger::openOutput_l(audio_module_handle_t module, } mHardwareStatus = AUDIO_HW_OUTPUT_OPEN; // FOR TESTING ONLY: // This if statement allows overriding the audio policy settings // and forcing a specific format or channel mask to the HAL/Sink device for testing. if (!(flags & (AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | AUDIO_OUTPUT_FLAG_DIRECT))) { // Check only for Normal Mixing mode if (kEnableExtendedPrecision) { // Specify format (uncomment one below to choose) //halConfig->format = AUDIO_FORMAT_PCM_FLOAT; //halConfig->format = AUDIO_FORMAT_PCM_24_BIT_PACKED; //halConfig->format = AUDIO_FORMAT_PCM_32_BIT; //halConfig->format = AUDIO_FORMAT_PCM_8_24_BIT; // ALOGV("openOutput_l() upgrading format to %#08x", halConfig->format); } if (kEnableExtendedChannels) { // Specify channel mask (uncomment one below to choose) //halConfig->channel_mask = audio_channel_out_mask_from_count(4); // for USB 4ch //halConfig->channel_mask = audio_channel_mask_from_representation_and_bits( // AUDIO_CHANNEL_REPRESENTATION_INDEX, (1 << 4) - 1); // another 4ch example } } AudioStreamOut *outputStream = NULL; status_t status = outHwDev->openOutputStream( &outputStream, Loading Loading @@ -2945,8 +2923,8 @@ sp<IAfThreadBase> AudioFlinger::openOutput_l(audio_module_handle_t module, ALOGV("openOutput_l() created offload output: ID %d thread %p", *output, thread.get()); } else if ((flags & AUDIO_OUTPUT_FLAG_DIRECT) || !isValidPcmSinkFormat(halConfig->format) || !isValidPcmSinkChannelMask(halConfig->channel_mask)) { || !IAfThreadBase::isValidPcmSinkFormat(halConfig->format) || !IAfThreadBase::isValidPcmSinkChannelMask(halConfig->channel_mask)) { thread = IAfPlaybackThread::createDirectOutputThread(this, outputStream, *output, mSystemReady, halConfig->offload_info); ALOGV("openOutput_l() created direct output: ID %d thread %p", Loading
services/audioflinger/AudioFlinger.h +0 −53 Original line number Diff line number Diff line Loading @@ -501,63 +501,10 @@ private: AudioHwDevice* findSuitableHwDev_l(audio_module_handle_t module, audio_devices_t deviceType); // Set kEnableExtendedChannels to true to enable greater than stereo output // for the MixerThread and device sink. Number of channels allowed is // FCC_2 <= channels <= AudioMixer::MAX_NUM_CHANNELS. static const bool kEnableExtendedChannels = true; public: // Remove this when Oboeservice is updated to obtain handle directly. static inline std::atomic<AudioFlinger*> gAudioFlinger = nullptr; // Returns true if channel mask is permitted for the PCM sink in the MixerThread static inline bool isValidPcmSinkChannelMask(audio_channel_mask_t channelMask) { switch (audio_channel_mask_get_representation(channelMask)) { case AUDIO_CHANNEL_REPRESENTATION_POSITION: { // Haptic channel mask is only applicable for channel position mask. const uint32_t channelCount = audio_channel_count_from_out_mask( static_cast<audio_channel_mask_t>(channelMask & ~AUDIO_CHANNEL_HAPTIC_ALL)); const uint32_t maxChannelCount = kEnableExtendedChannels ? AudioMixer::MAX_NUM_CHANNELS : FCC_2; if (channelCount < FCC_2 // mono is not supported at this time || channelCount > maxChannelCount) { return false; } // check that channelMask is the "canonical" one we expect for the channelCount. return audio_channel_position_mask_is_out_canonical(channelMask); } case AUDIO_CHANNEL_REPRESENTATION_INDEX: if (kEnableExtendedChannels) { const uint32_t channelCount = audio_channel_count_from_out_mask(channelMask); if (channelCount >= FCC_2 // mono is not supported at this time && channelCount <= AudioMixer::MAX_NUM_CHANNELS) { return true; } } return false; default: return false; } } // Set kEnableExtendedPrecision to true to use extended precision in MixerThread static const bool kEnableExtendedPrecision = true; // Returns true if format is permitted for the PCM sink in the MixerThread static inline bool isValidPcmSinkFormat(audio_format_t format) { switch (format) { case AUDIO_FORMAT_PCM_16_BIT: return true; case AUDIO_FORMAT_PCM_FLOAT: case AUDIO_FORMAT_PCM_24_BIT_PACKED: case AUDIO_FORMAT_PCM_32_BIT: case AUDIO_FORMAT_PCM_8_24_BIT: return kEnableExtendedPrecision; default: return false; } } private: // incremented by 2 when screen state changes, bit 0 == 1 means "off" Loading
services/audioflinger/IAfThread.h +3 −0 Original line number Diff line number Diff line Loading @@ -117,6 +117,9 @@ public: }; static const char* threadTypeToString(type_t type); static bool isValidPcmSinkChannelMask(audio_channel_mask_t channelMask); static bool isValidPcmSinkFormat(audio_format_t format); virtual status_t readyToRun() = 0; virtual void clearPowerManager() = 0; virtual status_t initCheck() const = 0; Loading
services/audioflinger/Threads.cpp +61 −6 Original line number Diff line number Diff line Loading @@ -257,6 +257,61 @@ static nsecs_t getStandbyTimeInNanos() { return standbyTimeInNanos; } // Set kEnableExtendedChannels to true to enable greater than stereo output // for the MixerThread and device sink. Number of channels allowed is // FCC_2 <= channels <= FCC_LIMIT. constexpr bool kEnableExtendedChannels = true; // Returns true if channel mask is permitted for the PCM sink in the MixerThread /* static */ bool IAfThreadBase::isValidPcmSinkChannelMask(audio_channel_mask_t channelMask) { switch (audio_channel_mask_get_representation(channelMask)) { case AUDIO_CHANNEL_REPRESENTATION_POSITION: { // Haptic channel mask is only applicable for channel position mask. const uint32_t channelCount = audio_channel_count_from_out_mask( static_cast<audio_channel_mask_t>(channelMask & ~AUDIO_CHANNEL_HAPTIC_ALL)); const uint32_t maxChannelCount = kEnableExtendedChannels ? FCC_LIMIT : FCC_2; if (channelCount < FCC_2 // mono is not supported at this time || channelCount > maxChannelCount) { return false; } // check that channelMask is the "canonical" one we expect for the channelCount. return audio_channel_position_mask_is_out_canonical(channelMask); } case AUDIO_CHANNEL_REPRESENTATION_INDEX: if (kEnableExtendedChannels) { const uint32_t channelCount = audio_channel_count_from_out_mask(channelMask); if (channelCount >= FCC_2 // mono is not supported at this time && channelCount <= FCC_LIMIT) { return true; } } return false; default: return false; } } // Set kEnableExtendedPrecision to true to use extended precision in MixerThread constexpr bool kEnableExtendedPrecision = true; // Returns true if format is permitted for the PCM sink in the MixerThread /* static */ bool IAfThreadBase::isValidPcmSinkFormat(audio_format_t format) { switch (format) { case AUDIO_FORMAT_PCM_16_BIT: return true; case AUDIO_FORMAT_PCM_FLOAT: case AUDIO_FORMAT_PCM_24_BIT_PACKED: case AUDIO_FORMAT_PCM_32_BIT: case AUDIO_FORMAT_PCM_8_24_BIT: return kEnableExtendedPrecision; default: return false; } } // ---------------------------------------------------------------------------- // TODO: move all toString helpers to audio.h Loading Loading @@ -2055,12 +2110,12 @@ PlaybackThread::PlaybackThread(const sp<IAfThreadCallback>& afThreadCallback, audio_config_base_t *mixerConfig) : ThreadBase(afThreadCallback, id, type, systemReady, true /* isOut */), mNormalFrameCount(0), mSinkBuffer(NULL), mMixerBufferEnabled(AudioFlinger::kEnableExtendedPrecision || type == SPATIALIZER), mMixerBufferEnabled(kEnableExtendedPrecision || type == SPATIALIZER), mMixerBuffer(NULL), mMixerBufferSize(0), mMixerBufferFormat(AUDIO_FORMAT_INVALID), mMixerBufferValid(false), mEffectBufferEnabled(AudioFlinger::kEnableExtendedPrecision || type == SPATIALIZER), mEffectBufferEnabled(kEnableExtendedPrecision || type == SPATIALIZER), mEffectBuffer(NULL), mEffectBufferSize(0), mEffectBufferFormat(AUDIO_FORMAT_INVALID), Loading Loading @@ -3043,7 +3098,7 @@ void PlaybackThread::readOutputParameters_l() if (!audio_is_output_channel(mChannelMask)) { LOG_ALWAYS_FATAL("HAL channel mask %#x not valid for output", mChannelMask); } if (hasMixer() && !AudioFlinger::isValidPcmSinkChannelMask(mChannelMask)) { if (hasMixer() && !isValidPcmSinkChannelMask(mChannelMask)) { LOG_ALWAYS_FATAL("HAL channel mask %#x not supported for mixed output", mChannelMask); } Loading @@ -3066,7 +3121,7 @@ void PlaybackThread::readOutputParameters_l() if (!audio_is_valid_format(mFormat)) { LOG_ALWAYS_FATAL("HAL format %#x not valid for output", mFormat); } if (hasMixer() && !AudioFlinger::isValidPcmSinkFormat(mFormat)) { if (hasMixer() && !isValidPcmSinkFormat(mFormat)) { LOG_FATAL("HAL format %#x not supported for mixed output", mFormat); } Loading Loading @@ -6195,7 +6250,7 @@ bool MixerThread::checkForNewParameter_l(const String8& keyValuePair, reconfig = true; } if (param.getInt(String8(AudioParameter::keyFormat), value) == NO_ERROR) { if (!AudioFlinger::isValidPcmSinkFormat(static_cast<audio_format_t>(value))) { if (!isValidPcmSinkFormat(static_cast<audio_format_t>(value))) { status = BAD_VALUE; } else { // no need to save value, since it's constant Loading @@ -6203,7 +6258,7 @@ bool MixerThread::checkForNewParameter_l(const String8& keyValuePair, } } if (param.getInt(String8(AudioParameter::keyChannels), value) == NO_ERROR) { if (!AudioFlinger::isValidPcmSinkChannelMask(static_cast<audio_channel_mask_t>(value))) { if (!isValidPcmSinkChannelMask(static_cast<audio_channel_mask_t>(value))) { status = BAD_VALUE; } else { // no need to save value, since it's constant Loading