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

Commit 158a2ce5 authored by Glenn Kasten's avatar Glenn Kasten Committed by Android (Google) Code Review
Browse files

Merge "Initial version of LifeVibes integration. Also changed tabs to spaces...

Merge "Initial version of LifeVibes integration. Also changed tabs to spaces in other audioflinger files."
parents aa3780b6 871c16ce
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -10,5 +10,10 @@ include $(CLEAR_VARS)
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_SRC_FILES := service_manager.c binder.c
LOCAL_SRC_FILES := service_manager.c binder.c
LOCAL_MODULE := servicemanager
LOCAL_MODULE := servicemanager
ifeq ($(LVMX),true)
  ifeq ($(TARGET_ARCH),arm)
    LOCAL_CFLAGS += -DLVMX
  endif
endif
include $(BUILD_EXECUTABLE)
include $(BUILD_EXECUTABLE)
endif
endif
+3 −0
Original line number Original line Diff line number Diff line
@@ -27,6 +27,9 @@ static struct {
    unsigned uid;
    unsigned uid;
    const char *name;
    const char *name;
} allowed[] = {
} allowed[] = {
#ifdef LVMX
    { AID_MEDIA, "com.lifevibes.mx.ipc" },
#endif
    { AID_MEDIA, "media.audio_flinger" },
    { AID_MEDIA, "media.audio_flinger" },
    { AID_MEDIA, "media.player" },
    { AID_MEDIA, "media.player" },
    { AID_MEDIA, "media.camera" },
    { AID_MEDIA, "media.camera" },
+15 −5
Original line number Original line Diff line number Diff line
@@ -119,4 +119,14 @@ ifeq ($(TARGET_SIMULATOR),true)
    endif
    endif
endif
endif


ifeq ($(LVMX),true)
  ifeq ($(TARGET_ARCH),arm)
    LOCAL_CFLAGS += -DLVMX
    LOCAL_C_INCLUDES += vendor/nxp
    LOCAL_STATIC_LIBRARIES += liblifevibes
    LOCAL_SHARED_LIBRARIES += liblvmxservice
#    LOCAL_SHARED_LIBRARIES += liblvmxipc
  endif
endif

include $(BUILD_SHARED_LIBRARY)
include $(BUILD_SHARED_LIBRARY)
+131 −4
Original line number Original line Diff line number Diff line
@@ -47,6 +47,10 @@
#include "A2dpAudioInterface.h"
#include "A2dpAudioInterface.h"
#endif
#endif


#ifdef LVMX
#include "lifevibes.h"
#endif

// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// the sim build doesn't have gettid
// the sim build doesn't have gettid


@@ -132,6 +136,9 @@ AudioFlinger::AudioFlinger()
    } else {
    } else {
        LOGE("Couldn't even initialize the stubbed audio hardware!");
        LOGE("Couldn't even initialize the stubbed audio hardware!");
    }
    }
#ifdef LVMX
    LifeVibes::init();
#endif
}
}


AudioFlinger::~AudioFlinger()
AudioFlinger::~AudioFlinger()
@@ -411,6 +418,11 @@ status_t AudioFlinger::setMode(int mode)
    AutoMutex lock(mHardwareLock);
    AutoMutex lock(mHardwareLock);
    mHardwareStatus = AUDIO_HW_SET_MODE;
    mHardwareStatus = AUDIO_HW_SET_MODE;
    status_t ret = mAudioHardware->setMode(mode);
    status_t ret = mAudioHardware->setMode(mode);
#ifdef LVMX
    if (NO_ERROR == ret) {
        LifeVibes::setMode(mode);
    }
#endif
    mHardwareStatus = AUDIO_HW_IDLE;
    mHardwareStatus = AUDIO_HW_IDLE;
    return ret;
    return ret;
}
}
@@ -566,11 +578,37 @@ status_t AudioFlinger::setParameters(int ioHandle, const String8& keyValuePairs)
        return PERMISSION_DENIED;
        return PERMISSION_DENIED;
    }
    }


#ifdef LVMX
    AudioParameter param = AudioParameter(keyValuePairs);
    LifeVibes::setParameters(ioHandle,keyValuePairs);
    String8 key = String8(AudioParameter::keyRouting);
    int device;
    if (NO_ERROR != param.getInt(key, device)) {
        device = -1;
    }

    key = String8(LifevibesTag);
    String8 value;
    int musicEnabled = -1;
    if (NO_ERROR == param.get(key, value)) {
        if (value == LifevibesEnable) {
            musicEnabled = 1;
        } else if (value == LifevibesDisable) {
            musicEnabled = 0;
        }
    }
#endif

    // ioHandle == 0 means the parameters are global to the audio hardware interface
    // ioHandle == 0 means the parameters are global to the audio hardware interface
    if (ioHandle == 0) {
    if (ioHandle == 0) {
        AutoMutex lock(mHardwareLock);
        AutoMutex lock(mHardwareLock);
        mHardwareStatus = AUDIO_SET_PARAMETER;
        mHardwareStatus = AUDIO_SET_PARAMETER;
        result = mAudioHardware->setParameters(keyValuePairs);
        result = mAudioHardware->setParameters(keyValuePairs);
#ifdef LVMX
        if ((NO_ERROR == result) && (musicEnabled != -1)) {
            LifeVibes::enableMusic((bool) musicEnabled);
        }
#endif
        mHardwareStatus = AUDIO_HW_IDLE;
        mHardwareStatus = AUDIO_HW_IDLE;
        return result;
        return result;
    }
    }
@@ -586,7 +624,13 @@ status_t AudioFlinger::setParameters(int ioHandle, const String8& keyValuePairs)
        }
        }
    }
    }
    if (thread != NULL) {
    if (thread != NULL) {
        return thread->setParameters(keyValuePairs);
        result = thread->setParameters(keyValuePairs);
#ifdef LVMX
        if ((NO_ERROR == result) && (device != -1)) {
            LifeVibes::setDevice(LifeVibes::threadIdToAudioOutputType(thread->id()), device);
        }
#endif
        return result;
    }
    }
    return BAD_VALUE;
    return BAD_VALUE;
}
}
@@ -1058,12 +1102,24 @@ uint32_t AudioFlinger::PlaybackThread::latency() const


status_t AudioFlinger::PlaybackThread::setMasterVolume(float value)
status_t AudioFlinger::PlaybackThread::setMasterVolume(float value)
{
{
#ifdef LVMX
    int audioOutputType = LifeVibes::getMixerType(mId, mType);
    if (LifeVibes::audioOutputTypeIsLifeVibes(audioOutputType)) {
        LifeVibes::setMasterVolume(audioOutputType, value);
    }
#endif
    mMasterVolume = value;
    mMasterVolume = value;
    return NO_ERROR;
    return NO_ERROR;
}
}


status_t AudioFlinger::PlaybackThread::setMasterMute(bool muted)
status_t AudioFlinger::PlaybackThread::setMasterMute(bool muted)
{
{
#ifdef LVMX
    int audioOutputType = LifeVibes::getMixerType(mId, mType);
    if (LifeVibes::audioOutputTypeIsLifeVibes(audioOutputType)) {
        LifeVibes::setMasterMute(audioOutputType, muted);
    }
#endif
    mMasterMute = muted;
    mMasterMute = muted;
    return NO_ERROR;
    return NO_ERROR;
}
}
@@ -1080,12 +1136,24 @@ bool AudioFlinger::PlaybackThread::masterMute() const


status_t AudioFlinger::PlaybackThread::setStreamVolume(int stream, float value)
status_t AudioFlinger::PlaybackThread::setStreamVolume(int stream, float value)
{
{
#ifdef LVMX
    int audioOutputType = LifeVibes::getMixerType(mId, mType);
    if (LifeVibes::audioOutputTypeIsLifeVibes(audioOutputType)) {
        LifeVibes::setStreamVolume(audioOutputType, stream, value);
    }
#endif
    mStreamTypes[stream].volume = value;
    mStreamTypes[stream].volume = value;
    return NO_ERROR;
    return NO_ERROR;
}
}


status_t AudioFlinger::PlaybackThread::setStreamMute(int stream, bool muted)
status_t AudioFlinger::PlaybackThread::setStreamMute(int stream, bool muted)
{
{
#ifdef LVMX
    int audioOutputType = LifeVibes::getMixerType(mId, mType);
    if (LifeVibes::audioOutputTypeIsLifeVibes(audioOutputType)) {
        LifeVibes::setStreamMute(audioOutputType, stream, muted);
    }
#endif
    mStreamTypes[stream].mute = muted;
    mStreamTypes[stream].mute = muted;
    return NO_ERROR;
    return NO_ERROR;
}
}
@@ -1333,6 +1401,12 @@ bool AudioFlinger::MixerThread::threadLoop()
            mLastWriteTime = systemTime();
            mLastWriteTime = systemTime();
            mInWrite = true;
            mInWrite = true;
            mBytesWritten += mixBufferSize;
            mBytesWritten += mixBufferSize;
#ifdef LVMX
            int audioOutputType = LifeVibes::getMixerType(mId, mType);
            if (LifeVibes::audioOutputTypeIsLifeVibes(audioOutputType)) {
               LifeVibes::process(audioOutputType, curBuf, mixBufferSize);
            }
#endif
            int bytesWritten = (int)mOutput->write(curBuf, mixBufferSize);
            int bytesWritten = (int)mOutput->write(curBuf, mixBufferSize);
            if (bytesWritten < 0) mBytesWritten -= mixBufferSize;
            if (bytesWritten < 0) mBytesWritten -= mixBufferSize;
            mNumWrites++;
            mNumWrites++;
@@ -1376,6 +1450,29 @@ uint32_t AudioFlinger::MixerThread::prepareTracks_l(const SortedVector< wp<Track
    uint32_t mixerStatus = MIXER_IDLE;
    uint32_t mixerStatus = MIXER_IDLE;
    // find out which tracks need to be processed
    // find out which tracks need to be processed
    size_t count = activeTracks.size();
    size_t count = activeTracks.size();

    float masterVolume = mMasterVolume;
    bool  masterMute = mMasterMute;

#ifdef LVMX
    bool tracksConnectedChanged = false;
    bool stateChanged = false;

    int audioOutputType = LifeVibes::getMixerType(mId, mType);
    if (LifeVibes::audioOutputTypeIsLifeVibes(audioOutputType))
    {
        int activeTypes = 0;
        for (size_t i=0 ; i<count ; i++) {
            sp<Track> t = activeTracks[i].promote();
            if (t == 0) continue;
            Track* const track = t.get();
            int iTracktype=track->type();
            activeTypes |= 1<<track->type();
        }
        LifeVibes::computeVolumes(audioOutputType, activeTypes, tracksConnectedChanged, stateChanged, masterVolume, masterMute);
    }
#endif

    for (size_t i=0 ; i<count ; i++) {
    for (size_t i=0 ; i<count ; i++) {
        sp<Track> t = activeTracks[i].promote();
        sp<Track> t = activeTracks[i].promote();
        if (t == 0) continue;
        if (t == 0) continue;
@@ -1393,15 +1490,27 @@ uint32_t AudioFlinger::MixerThread::prepareTracks_l(const SortedVector< wp<Track


            // compute volume for this track
            // compute volume for this track
            int16_t left, right;
            int16_t left, right;
            if (track->isMuted() || mMasterMute || track->isPausing() ||
            if (track->isMuted() || masterMute || track->isPausing() ||
                mStreamTypes[track->type()].mute) {
                mStreamTypes[track->type()].mute) {
                left = right = 0;
                left = right = 0;
                if (track->isPausing()) {
                if (track->isPausing()) {
                    track->setPaused();
                    track->setPaused();
                }
                }
            } else {
            } else {
                // read original volumes with volume control
                float typeVolume = mStreamTypes[track->type()].volume;
                float typeVolume = mStreamTypes[track->type()].volume;
                float v = mMasterVolume * typeVolume;
#ifdef LVMX
                bool streamMute=false;
                // read the volume from the LivesVibes audio engine.
                if (LifeVibes::audioOutputTypeIsLifeVibes(audioOutputType))
                {
                    LifeVibes::getStreamVolumes(audioOutputType, track->type(), &typeVolume, &streamMute);
                    if (streamMute) {
                        typeVolume = 0;
                    }
                }
#endif
                float v = masterVolume * typeVolume;
                float v_clamped = v * cblk->volume[0];
                float v_clamped = v * cblk->volume[0];
                if (v_clamped > MAX_GAIN) v_clamped = MAX_GAIN;
                if (v_clamped > MAX_GAIN) v_clamped = MAX_GAIN;
                left = int16_t(v_clamped);
                left = int16_t(v_clamped);
@@ -1427,7 +1536,13 @@ uint32_t AudioFlinger::MixerThread::prepareTracks_l(const SortedVector< wp<Track
                // do not apply ramp
                // do not apply ramp
                param = AudioMixer::RAMP_VOLUME;
                param = AudioMixer::RAMP_VOLUME;
            }
            }

#ifdef LVMX
            if ( tracksConnectedChanged || stateChanged )
            {
                 // only do the ramp when the volume is changed by the user / application
                 param = AudioMixer::VOLUME;
            }
#endif
            mAudioMixer->setParameter(param, AudioMixer::VOLUME0, left);
            mAudioMixer->setParameter(param, AudioMixer::VOLUME0, left);
            mAudioMixer->setParameter(param, AudioMixer::VOLUME1, right);
            mAudioMixer->setParameter(param, AudioMixer::VOLUME1, right);
            mAudioMixer->setParameter(
            mAudioMixer->setParameter(
@@ -3652,6 +3767,18 @@ int AudioFlinger::openOutput(uint32_t *pDevices,
        } else {
        } else {
            thread = new MixerThread(this, output, ++mNextThreadId);
            thread = new MixerThread(this, output, ++mNextThreadId);
            LOGV("openOutput() created mixer output: ID %d thread %p", mNextThreadId, thread);
            LOGV("openOutput() created mixer output: ID %d thread %p", mNextThreadId, thread);

#ifdef LVMX
            unsigned bitsPerSample =
                (format == AudioSystem::PCM_16_BIT) ? 16 :
                    ((format == AudioSystem::PCM_8_BIT) ? 8 : 0);
            unsigned channelCount = (channels == AudioSystem::CHANNEL_OUT_STEREO) ? 2 : 1;
            int audioOutputType = LifeVibes::threadIdToAudioOutputType(thread->id());

            LifeVibes::init_aot(audioOutputType, samplingRate, bitsPerSample, channelCount);
            LifeVibes::setDevice(audioOutputType, *pDevices);
#endif

        }
        }
        mPlaybackThreads.add(mNextThreadId, thread);
        mPlaybackThreads.add(mNextThreadId, thread);


+1 −1

File changed.

Contains only whitespace changes.

+2 −2

File changed.

Contains only whitespace changes.

Loading