From e541269be94f3a1072932d51537905b120ef4733 Mon Sep 17 00:00:00 2001 From: Andy Hung Date: Fri, 16 May 2014 11:25:07 -0700 Subject: Use new channel count functions for audio masks Change-Id: Ia658ab4b6320d19fdb50f123c930918724ff0ef3 Signed-off-by: Andy Hung --- media/libeffects/downmix/EffectDownmix.c | 7 ++++--- media/libeffects/preprocessing/PreProcessing.cpp | 6 +++--- media/libeffects/visualizer/EffectVisualizer.cpp | 3 ++- media/libmedia/AudioRecord.cpp | 5 +++-- media/libmedia/AudioTrack.cpp | 2 +- media/libnbaio/AudioStreamInSource.cpp | 3 ++- media/libnbaio/AudioStreamOutSink.cpp | 3 ++- services/audioflinger/AudioFlinger.cpp | 6 ++++-- services/audioflinger/AudioMixer.cpp | 4 ++-- services/audioflinger/Threads.cpp | 8 ++++---- services/audioflinger/Tracks.cpp | 6 ++++-- 11 files changed, 31 insertions(+), 22 deletions(-) diff --git a/media/libeffects/downmix/EffectDownmix.c b/media/libeffects/downmix/EffectDownmix.c index 661fde9..6686f27 100644 --- a/media/libeffects/downmix/EffectDownmix.c +++ b/media/libeffects/downmix/EffectDownmix.c @@ -118,7 +118,7 @@ void Downmix_testIndexComputation(uint32_t mask) { hasBacks = true; } - const int numChan = popcount(mask); + const int numChan = audio_channel_count_from_out_mask(mask); const bool hasFC = ((mask & AUDIO_CHANNEL_OUT_FRONT_CENTER) == AUDIO_CHANNEL_OUT_FRONT_CENTER); const bool hasLFE = ((mask & AUDIO_CHANNEL_OUT_LOW_FREQUENCY) == AUDIO_CHANNEL_OUT_LOW_FREQUENCY); @@ -629,7 +629,8 @@ int Downmix_Configure(downmix_module_t *pDwmModule, effect_config_t *pConfig, bo ALOGE("Downmix_Configure error: input channel mask can't be 0"); return -EINVAL; } - pDownmixer->input_channel_count = popcount(pConfig->inputCfg.channels); + pDownmixer->input_channel_count = + audio_channel_count_from_out_mask(pConfig->inputCfg.channels); } Downmix_Reset(pDownmixer, init); @@ -997,7 +998,7 @@ bool Downmix_foldGeneric( hasBacks = true; } - const int numChan = popcount(mask); + const int numChan = audio_channel_count_from_out_mask(mask); const bool hasFC = ((mask & AUDIO_CHANNEL_OUT_FRONT_CENTER) == AUDIO_CHANNEL_OUT_FRONT_CENTER); const bool hasLFE = ((mask & AUDIO_CHANNEL_OUT_LOW_FREQUENCY) == AUDIO_CHANNEL_OUT_LOW_FREQUENCY); diff --git a/media/libeffects/preprocessing/PreProcessing.cpp b/media/libeffects/preprocessing/PreProcessing.cpp index a96a703..cf98f56 100644 --- a/media/libeffects/preprocessing/PreProcessing.cpp +++ b/media/libeffects/preprocessing/PreProcessing.cpp @@ -879,8 +879,8 @@ int Session_ReleaseEffect(preproc_session_t *session, int Session_SetConfig(preproc_session_t *session, effect_config_t *config) { uint32_t sr; - uint32_t inCnl = popcount(config->inputCfg.channels); - uint32_t outCnl = popcount(config->outputCfg.channels); + uint32_t inCnl = audio_channel_count_from_out_mask(config->inputCfg.channels); + uint32_t outCnl = audio_channel_count_from_out_mask(config->outputCfg.channels); if (config->inputCfg.samplingRate != config->outputCfg.samplingRate || config->inputCfg.format != config->outputCfg.format || @@ -1035,7 +1035,7 @@ int Session_SetReverseConfig(preproc_session_t *session, effect_config_t *config config->inputCfg.format != AUDIO_FORMAT_PCM_16_BIT) { return -EINVAL; } - uint32_t inCnl = popcount(config->inputCfg.channels); + uint32_t inCnl = audio_channel_count_from_out_mask(config->inputCfg.channels); int status = session->apm->set_num_reverse_channels(inCnl); if (status < 0) { return -EINVAL; diff --git a/media/libeffects/visualizer/EffectVisualizer.cpp b/media/libeffects/visualizer/EffectVisualizer.cpp index 47cab62..e5089da 100644 --- a/media/libeffects/visualizer/EffectVisualizer.cpp +++ b/media/libeffects/visualizer/EffectVisualizer.cpp @@ -207,7 +207,8 @@ int Visualizer_init(VisualizerContext *pContext) pContext->mScalingMode = VISUALIZER_SCALING_MODE_NORMALIZED; // measurement initialization - pContext->mChannelCount = popcount(pContext->mConfig.inputCfg.channels); + pContext->mChannelCount = + audio_channel_count_from_out_mask(pContext->mConfig.inputCfg.channels); pContext->mMeasurementMode = MEASUREMENT_MODE_NONE; pContext->mMeasurementWindowSizeInBuffers = MEASUREMENT_WINDOW_MAX_SIZE_IN_BUFFERS; pContext->mMeasurementBufferIdx = 0; diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp index 97ab8f8..1c808d0 100644 --- a/media/libmedia/AudioRecord.cpp +++ b/media/libmedia/AudioRecord.cpp @@ -51,7 +51,8 @@ status_t AudioRecord::getMinFrameCount( // We double the size of input buffer for ping pong use of record buffer. // Assumes audio_is_linear_pcm(format) - if ((*frameCount = (size * 2) / (popcount(channelMask) * audio_bytes_per_sample(format))) == 0) { + if ((*frameCount = (size * 2) / (audio_channel_count_from_in_mask(channelMask) * + audio_bytes_per_sample(format))) == 0) { ALOGE("Unsupported configuration: sampleRate %u, format %#x, channelMask %#x", sampleRate, format, channelMask); return BAD_VALUE; @@ -193,7 +194,7 @@ status_t AudioRecord::set( return BAD_VALUE; } mChannelMask = channelMask; - uint32_t channelCount = popcount(channelMask); + uint32_t channelCount = audio_channel_count_from_in_mask(channelMask); mChannelCount = channelCount; if (audio_is_linear_pcm(format)) { diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp index aaaa3f1..b4d6d76 100644 --- a/media/libmedia/AudioTrack.cpp +++ b/media/libmedia/AudioTrack.cpp @@ -290,7 +290,7 @@ status_t AudioTrack::set( return BAD_VALUE; } mChannelMask = channelMask; - uint32_t channelCount = popcount(channelMask); + uint32_t channelCount = audio_channel_count_from_out_mask(channelMask); mChannelCount = channelCount; // AudioFlinger does not currently support 8-bit data in shared memory diff --git a/media/libnbaio/AudioStreamInSource.cpp b/media/libnbaio/AudioStreamInSource.cpp index af8f365..6aab48a 100644 --- a/media/libnbaio/AudioStreamInSource.cpp +++ b/media/libnbaio/AudioStreamInSource.cpp @@ -46,7 +46,8 @@ ssize_t AudioStreamInSource::negotiate(const NBAIO_Format offers[], size_t numOf uint32_t sampleRate = mStream->common.get_sample_rate(&mStream->common); audio_channel_mask_t channelMask = (audio_channel_mask_t) mStream->common.get_channels(&mStream->common); - mFormat = Format_from_SR_C(sampleRate, popcount(channelMask), streamFormat); + mFormat = Format_from_SR_C(sampleRate, + audio_channel_count_from_in_mask(channelMask), streamFormat); mFrameSize = Format_frameSize(mFormat); } return NBAIO_Source::negotiate(offers, numOffers, counterOffers, numCounterOffers); diff --git a/media/libnbaio/AudioStreamOutSink.cpp b/media/libnbaio/AudioStreamOutSink.cpp index c28d34d..0d5f935 100644 --- a/media/libnbaio/AudioStreamOutSink.cpp +++ b/media/libnbaio/AudioStreamOutSink.cpp @@ -43,7 +43,8 @@ ssize_t AudioStreamOutSink::negotiate(const NBAIO_Format offers[], size_t numOff uint32_t sampleRate = mStream->common.get_sample_rate(&mStream->common); audio_channel_mask_t channelMask = (audio_channel_mask_t) mStream->common.get_channels(&mStream->common); - mFormat = Format_from_SR_C(sampleRate, popcount(channelMask), streamFormat); + mFormat = Format_from_SR_C(sampleRate, + audio_channel_count_from_out_mask(channelMask), streamFormat); mFrameSize = Format_frameSize(mFormat); } return NBAIO_Sink::negotiate(offers, numOffers, counterOffers, numCounterOffers); diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index 11170c2..45e17f8 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -1837,7 +1837,8 @@ audio_io_handle_t AudioFlinger::openInput(audio_module_handle_t module, if (status == BAD_VALUE && reqFormat == config.format && config.format == AUDIO_FORMAT_PCM_16_BIT && (config.sample_rate <= 2 * reqSamplingRate) && - (popcount(config.channel_mask) <= FCC_2) && (popcount(reqChannelMask) <= FCC_2)) { + (audio_channel_count_from_in_mask(config.channel_mask) <= FCC_2) && + (audio_channel_count_from_in_mask(reqChannelMask) <= FCC_2)) { // FIXME describe the change proposed by HAL (save old values so we can log them here) ALOGV("openInput() reopening with proposed sampling rate and channel mask"); inStream = NULL; @@ -1857,7 +1858,8 @@ audio_io_handle_t AudioFlinger::openInput(audio_module_handle_t module, TEE_SINK_OLD, // copy input using an existing pipe } kind; NBAIO_Format format = Format_from_SR_C(inStream->common.get_sample_rate(&inStream->common), - popcount(inStream->common.get_channels(&inStream->common))); + audio_channel_count_from_in_mask( + inStream->common.get_channels(&inStream->common))); if (!mTeeSinkInputEnabled) { kind = TEE_SINK_NO; } else if (!Format_isValid(format)) { diff --git a/services/audioflinger/AudioMixer.cpp b/services/audioflinger/AudioMixer.cpp index 2d67efb..d32f4d1 100644 --- a/services/audioflinger/AudioMixer.cpp +++ b/services/audioflinger/AudioMixer.cpp @@ -215,7 +215,7 @@ void AudioMixer::invalidateState(uint32_t mask) status_t AudioMixer::initTrackDownmix(track_t* pTrack, int trackNum, audio_channel_mask_t mask) { - uint32_t channelCount = popcount(mask); + uint32_t channelCount = audio_channel_count_from_out_mask(mask); ALOG_ASSERT((channelCount <= MAX_NUM_CHANNELS_TO_DOWNMIX) && channelCount); status_t status = OK; if (channelCount > MAX_NUM_CHANNELS) { @@ -410,7 +410,7 @@ void AudioMixer::setParameter(int name, int target, int param, void *value) audio_channel_mask_t mask = static_cast(reinterpret_cast(value)); if (track.channelMask != mask) { - uint32_t channelCount = popcount(mask); + uint32_t channelCount = audio_channel_count_from_out_mask(mask); ALOG_ASSERT((channelCount <= MAX_NUM_CHANNELS_TO_DOWNMIX) && channelCount); track.channelMask = mask; track.channelCount = channelCount; diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp index 2d4e025..8d9ccd0 100644 --- a/services/audioflinger/Threads.cpp +++ b/services/audioflinger/Threads.cpp @@ -1730,7 +1730,7 @@ void AudioFlinger::PlaybackThread::readOutputParameters_l() LOG_ALWAYS_FATAL("HAL channel mask %#x not supported for mixed output; " "must be AUDIO_CHANNEL_OUT_STEREO", mChannelMask); } - mChannelCount = popcount(mChannelMask); + mChannelCount = audio_channel_count_from_out_mask(mChannelMask); mFormat = mOutput->stream->common.get_format(&mOutput->stream->common); if (!audio_is_valid_format(mFormat)) { LOG_ALWAYS_FATAL("HAL format %#x not valid for output", mFormat); @@ -5564,8 +5564,8 @@ bool AudioFlinger::RecordThread::checkForNewParameter_l(const String8& keyValueP reqFormat == AUDIO_FORMAT_PCM_16_BIT && (mInput->stream->common.get_sample_rate(&mInput->stream->common) <= (2 * samplingRate)) && - popcount(mInput->stream->common.get_channels(&mInput->stream->common)) - <= FCC_2 && + audio_channel_count_from_in_mask( + mInput->stream->common.get_channels(&mInput->stream->common)) <= FCC_2 && (channelMask == AUDIO_CHANNEL_IN_MONO || channelMask == AUDIO_CHANNEL_IN_STEREO)) { status = NO_ERROR; @@ -5619,7 +5619,7 @@ void AudioFlinger::RecordThread::readInputParameters_l() { mSampleRate = mInput->stream->common.get_sample_rate(&mInput->stream->common); mChannelMask = mInput->stream->common.get_channels(&mInput->stream->common); - mChannelCount = popcount(mChannelMask); + mChannelCount = audio_channel_count_from_in_mask(mChannelMask); mFormat = mInput->stream->common.get_format(&mInput->stream->common); if (mFormat != AUDIO_FORMAT_PCM_16_BIT) { ALOGE("HAL format %#x not supported; must be AUDIO_FORMAT_PCM_16_BIT", mFormat); diff --git a/services/audioflinger/Tracks.cpp b/services/audioflinger/Tracks.cpp index 6dc7f30..1d46f87 100644 --- a/services/audioflinger/Tracks.cpp +++ b/services/audioflinger/Tracks.cpp @@ -81,7 +81,9 @@ AudioFlinger::ThreadBase::TrackBase::TrackBase( mSampleRate(sampleRate), mFormat(format), mChannelMask(channelMask), - mChannelCount(popcount(channelMask)), + mChannelCount(isOut ? + audio_channel_count_from_out_mask(channelMask) : + audio_channel_count_from_in_mask(channelMask)), mFrameSize(audio_is_linear_pcm(format) ? mChannelCount * audio_bytes_per_sample(format) : sizeof(int8_t)), mFrameCount(frameCount), @@ -1849,7 +1851,7 @@ AudioFlinger::RecordThread::RecordTrack::RecordTrack( mServerProxy = new AudioRecordServerProxy(mCblk, mBuffer, frameCount, mFrameSize); - uint32_t channelCount = popcount(channelMask); + uint32_t channelCount = audio_channel_count_from_in_mask(channelMask); // FIXME I don't understand either of the channel count checks if (thread->mSampleRate != sampleRate && thread->mChannelCount <= FCC_2 && channelCount <= FCC_2) { -- cgit v1.1