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

Commit 1dd70b9f authored by Eric Laurent's avatar Eric Laurent
Browse files

Fix issue 1745312: Various cleanups in media framework

AudioTrack, AudioRecord:
  - remove useless mAudioFlinger member of AudioTrack and AudioRecord.
  - signal cblk.cv condition in stop() method to speed up stop completion.
  - extend wait condition timeout in obtainBuffer() when waitCount is -1 to avoid waking up callback thread unnecessarily

AudioFlinger:
  - remove some warnings in AudioFlinger.cpp.
  - remove function AudioFlinger::MixerThread::removetrack_l()  as its content is never executed.
  - remove useless call to setMasterVolume in AudioFlinger::handleForcedSpeakerRoute().
  - Offset VOICE_CALL stream volume to reflect actual volume that is never 0 in hardware (this fix has been made in the open source): 0.01 + v * 0.99.

AudioSystem.java:
  - correct typo in comment

IAudioflinger, IAudioFlingerClient:
  - make AudioFlinger binder interfaces used for callbacks ONEWAY.

AudioHardwareInterface:
  - correct routeStrings[] table in AudioHardwareInteface.cpp
parent ce80c82f
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -312,7 +312,6 @@ private:

            bool processAudioBuffer(const sp<ClientRecordThread>& thread);

    sp<IAudioFlinger>       mAudioFlinger;
    sp<IAudioRecord>        mAudioRecord;
    sp<IMemory>             mCblkMemory;
    sp<ClientRecordThread>  mClientRecordThread;
+0 −1
Original line number Diff line number Diff line
@@ -383,7 +383,6 @@ private:

            bool processAudioBuffer(const sp<AudioTrackThread>& thread);

    sp<IAudioFlinger>       mAudioFlinger;
    sp<IAudioTrack>         mAudioTrack;
    sp<IMemory>             mCblkMemory;
    sp<AudioTrackThread>    mAudioTrackThread;
+6 −6
Original line number Diff line number Diff line
@@ -73,7 +73,6 @@ AudioRecord::~AudioRecord()
        // Otherwise the callback thread will never exit.
        stop();
        if (mClientRecordThread != 0) {
            mCblk->cv.signal();
            mClientRecordThread->requestExitAndWait();
            mClientRecordThread.clear();
        }
@@ -96,7 +95,7 @@ status_t AudioRecord::set(
{

    LOGV("set(): sampleRate %d, channelCount %d, frameCount %d",sampleRate, channelCount, frameCount);
    if (mAudioFlinger != 0) {
    if (mAudioRecord != 0) {
        return INVALID_OPERATION;
    }

@@ -181,7 +180,6 @@ status_t AudioRecord::set(

    mStatus = NO_ERROR;

    mAudioFlinger = audioFlinger;
    mAudioRecord = record;
    mCblkMemory = cblk;
    mCblk = static_cast<audio_track_cblk_t*>(cblk->pointer());
@@ -293,6 +291,7 @@ status_t AudioRecord::stop()
     }

    if (android_atomic_and(~1, &mActive) == 1) {
        mCblk->cv.signal();
        mAudioRecord->stop();
        // the record head position will reset to 0, so if a marker is set, we need
        // to activate it again
@@ -375,6 +374,7 @@ status_t AudioRecord::obtainBuffer(Buffer* audioBuffer, int32_t waitCount)
    status_t result;
    audio_track_cblk_t* cblk = mCblk;
    uint32_t framesReq = audioBuffer->frameCount;
    uint32_t waitTimeMs = (waitCount < 0) ? cblk->bufferTimeoutMs : WAIT_PERIOD_MS;

    audioBuffer->frameCount  = 0;
    audioBuffer->size        = 0;
@@ -391,9 +391,9 @@ status_t AudioRecord::obtainBuffer(Buffer* audioBuffer, int32_t waitCount)
            if (UNLIKELY(!waitCount))
                return WOULD_BLOCK;
            timeout = 0;
            result = cblk->cv.waitRelative(cblk->lock, milliseconds(WAIT_PERIOD_MS));
            result = cblk->cv.waitRelative(cblk->lock, milliseconds(waitTimeMs));
            if (__builtin_expect(result!=NO_ERROR, false)) {
                cblk->waitTimeMs += WAIT_PERIOD_MS;
                cblk->waitTimeMs += waitTimeMs;
                if (cblk->waitTimeMs >= cblk->bufferTimeoutMs) {
                    LOGW(   "obtainBuffer timed out (is the CPU pegged?) "
                            "user=%08x, server=%08x", cblk->user, cblk->server);
@@ -520,7 +520,7 @@ bool AudioRecord::processAudioBuffer(const sp<ClientRecordThread>& thread)
        status_t err = obtainBuffer(&audioBuffer, 1);
        if (err < NO_ERROR) {
            if (err != TIMED_OUT) {
                LOGE("Error obtaining an audio buffer, giving up.");
                LOGE_IF(err != status_t(NO_MORE_BUFFERS), "Error obtaining an audio buffer, giving up.");
                return false;
            }
            break;
+6 −6
Original line number Diff line number Diff line
@@ -92,7 +92,6 @@ AudioTrack::~AudioTrack()
        // Otherwise the callback thread will never exit.
        stop();
        if (mAudioTrackThread != 0) {
            mCblk->cv.signal();
            mAudioTrackThread->requestExitAndWait();
            mAudioTrackThread.clear();
        }
@@ -117,7 +116,7 @@ status_t AudioTrack::set(

    LOGV_IF(sharedBuffer != 0, "sharedBuffer: %p, size: %d", sharedBuffer->pointer(), sharedBuffer->size());

    if (mAudioFlinger != 0) {
    if (mAudioTrack != 0) {
        LOGE("Track already in use");
        return INVALID_OPERATION;
    }
@@ -228,7 +227,6 @@ status_t AudioTrack::set(

    mStatus = NO_ERROR;

    mAudioFlinger = audioFlinger;
    mAudioTrack = track;
    mCblkMemory = cblk;
    mCblk = static_cast<audio_track_cblk_t*>(cblk->pointer());
@@ -357,6 +355,7 @@ void AudioTrack::stop()
    }

    if (android_atomic_and(~1, &mActive) == 1) {
        mCblk->cv.signal();
        mAudioTrack->stop();
        // Cancel loops (If we are in the middle of a loop, playback
        // would not stop until loopCount reaches 0).
@@ -596,6 +595,7 @@ status_t AudioTrack::obtainBuffer(Buffer* audioBuffer, int32_t waitCount)
    status_t result;
    audio_track_cblk_t* cblk = mCblk;
    uint32_t framesReq = audioBuffer->frameCount;
    uint32_t waitTimeMs = (waitCount < 0) ? cblk->bufferTimeoutMs : WAIT_PERIOD_MS;

    audioBuffer->frameCount  = 0;
    audioBuffer->size = 0;
@@ -614,9 +614,9 @@ status_t AudioTrack::obtainBuffer(Buffer* audioBuffer, int32_t waitCount)
            if (UNLIKELY(!waitCount))
                return WOULD_BLOCK;
            timeout = 0;
            result = cblk->cv.waitRelative(cblk->lock, milliseconds(WAIT_PERIOD_MS));
            result = cblk->cv.waitRelative(cblk->lock, milliseconds(waitTimeMs));
            if (__builtin_expect(result!=NO_ERROR, false)) { 
                cblk->waitTimeMs += WAIT_PERIOD_MS;
                cblk->waitTimeMs += waitTimeMs;
                if (cblk->waitTimeMs >= cblk->bufferTimeoutMs) {
                    // timing out when a loop has been set and we have already written upto loop end
                    // is a normal condition: no need to wake AudioFlinger up.
@@ -798,7 +798,7 @@ bool AudioTrack::processAudioBuffer(const sp<AudioTrackThread>& thread)
        status_t err = obtainBuffer(&audioBuffer, 1);
        if (err < NO_ERROR) {
            if (err != TIMED_OUT) {
                LOGE("Error obtaining an audio buffer, giving up.");
                LOGE_IF(err != status_t(NO_MORE_BUFFERS), "Error obtaining an audio buffer, giving up.");
                return false;
            }
            break;
+1 −1
Original line number Diff line number Diff line
@@ -336,7 +336,7 @@ public:
    {
        Parcel data, reply;
        data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
        remote()->transact(WAKE_UP, data, &reply);
        remote()->transact(WAKE_UP, data, &reply, IBinder::FLAG_ONEWAY);
        return;
    }

Loading