Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3dc6ae1f authored by Steve Kondik's avatar Steve Kondik
Browse files

DTS Postpro integration (for frameworks/av)

Adds DTS Postpro support in <root>/frameworks/av

Change-Id: I46edfb41571574ffa52c3a3f301cc003f914b00a
parent 521cf3ed
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -25,9 +25,6 @@
#include <system/audio_policy.h>
#include <utils/Errors.h>
#include <utils/Mutex.h>
#ifdef QCOM_HARDWARE
#include <media/AudioParameter.h>
#endif

namespace android {

+27 −11
Original line number Diff line number Diff line
#
# This file was modified by DTS, Inc. The portions of the
# code that are surrounded by "DTS..." are copyrighted and
# licensed separately, as follows:
#
#  (C) 2013 DTS, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License
#

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)
@@ -46,14 +66,6 @@ LOCAL_SHARED_LIBRARIES := \
    libdl \
    libpowermanager

# SRS Processing
ifeq ($(strip $(BOARD_USES_SRS_TRUEMEDIA)),true)
LOCAL_SHARED_LIBRARIES += libsrsprocessing
LOCAL_CFLAGS += -DSRS_PROCESSING
LOCAL_C_INCLUDES += $(TARGET_OUT_HEADERS)/mm-audio/audio-effects
endif
# SRS Processing

LOCAL_STATIC_LIBRARIES := \
    libscheduling_policy \
    libcpustats \
@@ -77,7 +89,11 @@ ifeq ($(BOARD_HAVE_PRE_KITKAT_AUDIO_BLOB),true)
endif

LOCAL_CFLAGS += -fvisibility=hidden

ifeq ($(strip $(BOARD_USES_SRS_TRUEMEDIA)),true)
LOCAL_SHARED_LIBRARIES += libsrsprocessing
LOCAL_CFLAGS += -DSRS_PROCESSING
LOCAL_C_INCLUDES += $(TARGET_OUT_HEADERS)/mm-audio/audio-effects
endif
include $(BUILD_SHARED_LIBRARY)

#
+28 −18
Original line number Diff line number Diff line
@@ -14,6 +14,24 @@
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
**
** This file was modified by DTS, Inc. The portions of the
** code that are surrounded by "DTS..." are copyrighted and
** licensed separately, as follows:
**
**  (C) 2013 DTS, Inc.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**    http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License
*/


@@ -63,10 +81,8 @@
#include <media/nbaio/PipeReader.h>
#include <media/AudioParameter.h>
#include <private/android_filesystem_config.h>

#ifdef SRS_PROCESSING
#include "srs_processing.h"
#include "postpro_patch_ics.h"
#include "postpro_patch.h"
#endif

// ----------------------------------------------------------------------------
@@ -1067,12 +1083,15 @@ status_t AudioFlinger::setParameters(audio_io_handle_t ioHandle, const String8&
    // ioHandle == 0 means the parameters are global to the audio hardware interface
    if (ioHandle == 0) {
        Mutex::Autolock _l(mLock);
        status_t final_result = NO_ERROR;

#ifdef SRS_PROCESSING
        POSTPRO_PATCH_ICS_PARAMS_SET(keyValuePairs);
        if (!mDirectAudioTracks.isEmpty())
            audioConfigChanged_l(AudioSystem::EFFECT_CONFIG_CHANGED, 0, NULL);
        POSTPRO_PATCH_PARAMS_SET(keyValuePairs);
        for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
            PlaybackThread *thread = mPlaybackThreads.valueAt(i).get();
            thread->setPostPro();
        }
#endif
        status_t final_result = NO_ERROR;
        {
            AutoMutex lock(mHardwareLock);
            mHardwareStatus = AUDIO_HW_SET_PARAMETER;
@@ -1150,12 +1169,6 @@ status_t AudioFlinger::setParameters(audio_io_handle_t ioHandle, const String8&
            int device;
            if (param.getInt(key, device) == NO_ERROR) {
                mDirectDevice = device;
#ifdef SRS_PROCESSING
                ALOGV("setParameters:: routing change to device %d", device);
                POSTPRO_PATCH_ICS_OUTPROC_MIX_ROUTE(desc->trackRefPtr, param, device);
                if(desc->flag & AUDIO_OUTPUT_FLAG_TUNNEL)
                    audioConfigChanged_l(AudioSystem::EFFECT_CONFIG_CHANGED, 0, NULL);
#endif
                if(mLPAEffectChain != NULL){
                    mLPAEffectChain->setDevice_l(device);
                    audioConfigChanged_l(AudioSystem::EFFECT_CONFIG_CHANGED, 0, NULL);
@@ -1202,8 +1215,9 @@ String8 AudioFlinger::getParameters(audio_io_handle_t ioHandle, const String8& k
        String8 out_s8;

#ifdef SRS_PROCESSING
        POSTPRO_PATCH_ICS_PARAMS_GET(keys, out_s8);
        POSTPRO_PATCH_PARAMS_GET(keys, out_s8);
#endif

        for (size_t i = 0; i < mAudioHwDevs.size(); i++) {
            char *s;
            {
@@ -1923,10 +1937,6 @@ audio_io_handle_t AudioFlinger::openOutput(audio_module_handle_t module,
        if ((mPrimaryHardwareDev == NULL) && (flags & AUDIO_OUTPUT_FLAG_PRIMARY)) {
            ALOGI("Using module %d has the primary audio interface", module);
            mPrimaryHardwareDev = outHwDev;
#ifdef SRS_PROCESSING
            SRS_Processing::RawDataSet(NULL, "qdsp hook", &mPrimaryHardwareDev,
                sizeof(&mPrimaryHardwareDev));
#endif
            AutoMutex lock(mHardwareLock);
            mHardwareStatus = AUDIO_HW_SET_MODE;
            hwDevHal->set_mode(hwDevHal, mMode);
+0 −19
Original line number Diff line number Diff line
@@ -30,11 +30,6 @@
#include "AudioFlinger.h"
#include "ServiceUtilities.h"

#ifdef SRS_PROCESSING
#include "srs_processing.h"
#include "postpro_patch_ics.h"
#endif

// ----------------------------------------------------------------------------

// Note: the following macro is used for extremely verbose logging message.  In
@@ -1908,9 +1903,6 @@ bool AudioFlinger::applyEffectsOn(void *token, int16_t *inBuffer,
    mIsEffectConfigChanged = false;

    volatile size_t numEffects = 0;
#ifdef SRS_PROCESSING
    POSTPRO_PATCH_ICS_OUTPROC_DIRECT_SAMPLES(token, AUDIO_FORMAT_PCM_16_BIT, outBuffer, size, mLPASampleRate, mLPANumChannels);
#endif

    if(mLPAEffectChain != NULL) {
        numEffects = mLPAEffectChain->getNumEffects();
@@ -2035,17 +2027,6 @@ void AudioFlinger::DirectAudioTrack::EffectsThreadEntry() {
                        break;
                    }
            }
#ifdef SRS_PROCESSING
            } else if (mFlag & AUDIO_OUTPUT_FLAG_TUNNEL) {
                ALOGV("applying effects for TUNNEL");
                char buffer[2];
                    //dummy buffer to ensure the SRS processing takes place
                    // The API mandates Sample rate and channel mode. Hence
                    // defaulted the sample rate channel mode to 48000 and 2 respectively
                POSTPRO_PATCH_ICS_OUTPROC_DIRECT_SAMPLES(static_cast<void *>(this),
                                                         AUDIO_FORMAT_PCM_16_BIT,
                                                        (int16_t*)buffer, 2, 48000, 2);
#endif
            }
        }
        mEffectLock.unlock();
+84 −41
Original line number Diff line number Diff line
@@ -14,6 +14,24 @@
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
**
** This file was modified by DTS, Inc. The portions of the
** code that are surrounded by "DTS..." are copyrighted and
** licensed separately, as follows:
**
**  (C) 2013 DTS, Inc.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**    http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License
*/


@@ -66,8 +84,7 @@
#endif

#ifdef SRS_PROCESSING
#include "srs_processing.h"
#include "postpro_patch_ics.h"
#include "postpro_patch.h"
#endif

// ----------------------------------------------------------------------------
@@ -1487,6 +1504,13 @@ float AudioFlinger::PlaybackThread::streamVolume(audio_stream_type_t stream) con
    return mStreamTypes[stream].volume;
}

void AudioFlinger::PlaybackThread::setPostPro()
{
    Mutex::Autolock _l(mLock);
    if (mType == OFFLOAD)
        broadcast_l();
}

// addTrack_l() must be called with ThreadBase::mLock held
status_t AudioFlinger::PlaybackThread::addTrack_l(const sp<Track>& track)
{
@@ -2217,13 +2241,6 @@ bool AudioFlinger::PlaybackThread::threadLoop()

    standbyTime = systemTime();

#ifdef SRS_PROCESSING
if (mType == MIXER) {
        POSTPRO_PATCH_ICS_OUTPROC_MIX_INIT(this, gettid());
    } else if (mType == DUPLICATING) {
        POSTPRO_PATCH_ICS_OUTPROC_DUPE_INIT(this, gettid());
    }
#endif
    // MIXER
    nsecs_t lastWarning = 0;

@@ -2245,6 +2262,18 @@ if (mType == MIXER) {

    acquireWakeLock();

#ifdef SRS_PROCESSING
    if (mType == MIXER) {
        POSTPRO_PATCH_OUTPROC_PLAY_INIT(this, myName);
    } else if (mType == DUPLICATING) {
        POSTPRO_PATCH_OUTPROC_DUPE_INIT(this, myName);
    } else if (mType == OFFLOAD) {
        POSTPRO_PATCH_OUTPROC_DIRECT_INIT(this, myName);
    } else if (mType == DIRECT) {
        POSTPRO_PATCH_OUTPROC_DIRECT_INIT(this, myName);
    }
#endif

    // mNBLogWriter->log can only be called while thread mutex mLock is held.
    // So if you need to log when mutex is unlocked, set logString to a non-NULL string,
    // and then that string will be logged at the next convenient opportunity.
@@ -2403,6 +2432,13 @@ if (mType == MIXER) {
            for (size_t i = 0; i < effectChains.size(); i ++) {
                effectChains[i]->process_l();
            }
#ifdef SRS_PROCESSING
            // Offload thread
            if (mType == OFFLOAD) {
                char buffer[2];
                POSTPRO_PATCH_OUTPROC_DIRECT_SAMPLES(this, AUDIO_FORMAT_PCM_16_BIT, (int16_t *) buffer, 2, 48000, 2);
            }
#endif
        }

        // enable changes in effect chain
@@ -2413,12 +2449,14 @@ if (mType == MIXER) {
            if (sleepTime == 0) {
#ifdef SRS_PROCESSING
                if (mType == MIXER) {
                    POSTPRO_PATCH_ICS_OUTPROC_MIX_SAMPLES(this, mFormat, mMixBuffer,
                        mixBufferSize, mSampleRate, mChannelCount);
                    POSTPRO_PATCH_OUTPROC_PLAY_SAMPLES(this, mFormat, mMixBuffer, mixBufferSize, mSampleRate, mChannelCount);
                } else if (mType == DUPLICATING) {
                    POSTPRO_PATCH_ICS_OUTPROC_DUPE_SAMPLES(this, mFormat, mMixBuffer,
                        mixBufferSize, mSampleRate, mChannelCount);
                }
                    POSTPRO_PATCH_OUTPROC_DUPE_SAMPLES(this, mFormat, mMixBuffer, mixBufferSize, mSampleRate, mChannelCount);
                } /* else if (mType == OFFLOAD) {
                    POSTPRO_PATCH_OUTPROC_DIRECT_SAMPLES(this, mFormat, mMixBuffer, mixBufferSize, mSampleRate, mChannelCount);
                } else if (mType == DIRECT) {
                    POSTPRO_PATCH_OUTPROC_DIRECT_SAMPLES(this, mFormat, mMixBuffer, mixBufferSize, mSampleRate, mChannelCount);
                } */
#endif
                if (mBytesRemaining) {
                    ssize_t ret = threadLoop_write();
@@ -2480,12 +2518,15 @@ if (mType == MIXER) {
            mOutput->stream->common.standby(&mOutput->stream->common);
        }
    }

#ifdef SRS_PROCESSING
    if (mType == MIXER) {
            POSTPRO_PATCH_ICS_OUTPROC_MIX_EXIT(this, gettid());
        POSTPRO_PATCH_OUTPROC_PLAY_EXIT(this, myName);
    } else if (mType == DUPLICATING) {
            POSTPRO_PATCH_ICS_OUTPROC_DUPE_EXIT(this, gettid());
        POSTPRO_PATCH_OUTPROC_DUPE_EXIT(this, myName);
    } else if (mType == OFFLOAD) {
        POSTPRO_PATCH_OUTPROC_DIRECT_EXIT(this, myName);
    } else if (mType == DIRECT) {
        POSTPRO_PATCH_OUTPROC_DIRECT_EXIT(this, myName);
    }
#endif
    releaseWakeLock();
@@ -3459,9 +3500,8 @@ bool AudioFlinger::MixerThread::checkForNewParameters_l()
        String8 keyValuePair = mNewParameters[0];
        AudioParameter param = AudioParameter(keyValuePair);
        int value;

#ifdef SRS_PROCESSING
        POSTPRO_PATCH_ICS_OUTPROC_MIX_ROUTE(this, param, value);
        POSTPRO_PATCH_OUTPROC_PLAY_ROUTE(this, param, value);
#endif
        if (param.getInt(String8(AudioParameter::keySamplingRate), value) == NO_ERROR) {
            reconfig = true;
@@ -3859,6 +3899,10 @@ bool AudioFlinger::DirectOutputThread::checkForNewParameters_l()
        AudioParameter param = AudioParameter(keyValuePair);
        int value;

#ifdef SRS_PROCESSING
        POSTPRO_PATCH_OUTPROC_PLAY_ROUTE(this, param, value);
#endif

        if (param.getInt(String8(AudioParameter::keyFrameCount), value) == NO_ERROR) {
            // do not accept frame count changes if tracks are open as the track buffer
            // size depends on frame count and correct behavior would not be garantied
@@ -4546,6 +4590,10 @@ bool AudioFlinger::RecordThread::threadLoop()
        acquireWakeLock_l(activeTrack != 0 ? activeTrack->uid() : -1);
    }

#ifdef SRS_PROCESSING
    POSTPRO_PATCH_INPROC_INIT(this, gettid(), mFormat);
#endif

    // used to verify we've read at least once before evaluating how many bytes were read
    bool readOnce = false;

@@ -4683,6 +4731,9 @@ bool AudioFlinger::RecordThread::threadLoop()
                                    InputBytes);
#else
                                    mBufferSize);
#endif
#ifdef SRS_PROCESSING
                            POSTPRO_PATCH_INPROC_SAMPLES(this, mFormat, readInto, mBytesRead, mSampleRate, mChannelCount);
#endif
                            if (mBytesRead <= 0) {
                                if ((mBytesRead < 0) && (mActiveTrack->mState == TrackBase::ACTIVE))
@@ -4785,6 +4836,10 @@ bool AudioFlinger::RecordThread::threadLoop()
        mStartStopCond.broadcast();
    }

#ifdef SRS_PROCESSING
    POSTPRO_PATCH_INPROC_EXIT(this, gettid(), mFormat);
#endif

    releaseWakeLock();

    ALOGV("RecordThread %p exiting", this);
@@ -5166,6 +5221,10 @@ status_t AudioFlinger::RecordThread::getNextBuffer(AudioBufferProvider::Buffer*

    if (framesReady == 0) {
        mBytesRead = mInput->stream->read(mInput->stream, mRsmpInBuffer, mBufferSize);

#ifdef SRS_PROCESSING
        POSTPRO_PATCH_INPROC_SAMPLES(this, mFormat, mRsmpInBuffer, mBytesRead, mSampleRate, mChannelCount);
#endif
        if (mBytesRead <= 0) {
            if ((mBytesRead < 0) && (mActiveTrack->mState == TrackBase::ACTIVE)) {
                ALOGE("RecordThread::getNextBuffer() Error reading audio input");
@@ -5216,6 +5275,9 @@ bool AudioFlinger::RecordThread::checkForNewParameters_l()
        uint32_t reqSamplingRate = mReqSampleRate;
        uint32_t reqChannelCount = mReqChannelCount;

#ifdef SRS_PROCESSING
        POSTPRO_PATCH_INPROC_ROUTE(this, param, value);
#endif
        if (param.getInt(String8(AudioParameter::keySamplingRate), value) == NO_ERROR) {
            reqSamplingRate = value;
            reconfig = true;
@@ -5498,20 +5560,13 @@ AudioFlinger::DirectAudioTrack::DirectAudioTrack(const sp<AudioFlinger>& audioFl
      mClient(client), mEffectConfigChanged(false), mKillEffectsThread(false), mFlag(outflag),
      mEffectsThreadScratchBuffer(NULL)
{
#ifdef SRS_PROCESSING
    ALOGD("SRS_Processing - DirectAudioTrack - OutNotify_Init: %p TID %d\n", this, gettid());
    POSTPRO_PATCH_ICS_OUTPROC_DIRECT_INIT(this, gettid());
    SRS_Processing::ProcessOutRoute(SRS_Processing::AUTO, this, outputDesc->device);
#endif
    if (mFlag & AUDIO_OUTPUT_FLAG_LPA) {
        ALOGV("create effects thread for LPA");
        createEffectThread();
        allocateBufPool();
#ifdef SRS_PROCESSING
    } else if (mFlag & AUDIO_OUTPUT_FLAG_TUNNEL) {
        ALOGV("create effects thread for TUNNEL");
        createEffectThread();
#endif
    }
    outputDesc->mVolumeScale = 1.0;
    mDeathRecipient = new PMDeathRecipient(this);
@@ -5523,28 +5578,16 @@ void AudioFlinger::DirectAudioTrack::signalEffect() {
        mEffectConfigChanged = true;
        mEffectCv.signal();
    }
#ifdef SRS_PROCESSING
    if (mFlag & AUDIO_OUTPUT_FLAG_TUNNEL){
        mEffectConfigChanged = true;
        mEffectCv.signal();
    }
#endif
}

AudioFlinger::DirectAudioTrack::~DirectAudioTrack() {
#ifdef SRS_PROCESSING
    ALOGD("SRS_Processing - DirectAudioTrack - OutNotify_Init: %p TID %d\n", this, gettid());
    POSTPRO_PATCH_ICS_OUTPROC_DIRECT_EXIT(this, gettid());
#endif
    if (mFlag & AUDIO_OUTPUT_FLAG_LPA) {
        requestAndWaitForEffectsThreadExit();
        mAudioFlinger->deleteEffectSession();
        deallocateBufPool();
#ifdef SRS_PROCESSING
    } else if (mFlag & AUDIO_OUTPUT_FLAG_TUNNEL) {
        requestAndWaitForEffectsThreadExit();
        mAudioFlinger->deleteEffectSession();
#endif
    }
    AudioSystem::releaseOutput(mOutput);
    releaseWakeLock();
Loading