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

Commit 403be8e3 authored by Chaithanya Krishna Bacharaju's avatar Chaithanya Krishna Bacharaju Committed by Giulio Cervera
Browse files

libstagefright: Add support for TCXO shutdown

-Add support for onPauseTimeout to close the Audio path after
3sec of pause. This allows TCXO shudown to happen.

Change-Id: I747edf146475df8c828294f01ffe38aba5a3eccf
parent a0723cdd
Loading
Loading
Loading
Loading
+11 −74
Original line number Diff line number Diff line
@@ -104,60 +104,6 @@ mTrackType(TRACK_NONE){

    initCheck = true;

    //mDeathRecipient = new PMDeathRecipient(this);
}

void LPAPlayer::acquireWakeLock()
{
    /*Mutex::Autolock _l(pmLock);

    if (mPowerManager == 0) {
        // use checkService() to avoid blocking if power service is not up yet
        sp<IBinder> binder =
            defaultServiceManager()->checkService(String16("power"));
        if (binder == 0) {
            ALOGW("Thread %s cannot connect to the power manager service", mName);
        } else {
            mPowerManager = interface_cast<IPowerManager>(binder);
            binder->linkToDeath(mDeathRecipient);
        }
    }
    if (mPowerManager != 0 && mWakeLockToken == 0) {
        sp<IBinder> binder = new BBinder();
        status_t status = mPowerManager->acquireWakeLock(POWERMANAGER_PARTIAL_WAKE_LOCK,
                                                         binder,
                                                         String16(mName));
        if (status == NO_ERROR) {
            mWakeLockToken = binder;
        }
        ALOGV("acquireWakeLock() %s status %d", mName, status);
    }*/
}

void LPAPlayer::releaseWakeLock()
{
   /*Mutex::Autolock _l(pmLock);

    if (mWakeLockToken != 0) {
        ALOGV("releaseWakeLock() %s", mName);
        if (mPowerManager != 0) {
            mPowerManager->releaseWakeLock(mWakeLockToken, 0);
        }
        mWakeLockToken.clear();
    }*/
}

void LPAPlayer::clearPowerManager()
{
    /*Mutex::Autolock _l(pmLock);
    releaseWakeLock();
    mPowerManager.clear();*/
}

void LPAPlayer::PMDeathRecipient::binderDied(const wp<IBinder>& who)
{
    parentClass->clearPowerManager();
    ALOGW("power manager service died !!!");
}

LPAPlayer::~LPAPlayer() {
@@ -172,11 +118,6 @@ LPAPlayer::~LPAPlayer() {
    }
    objectsAlive--;

    releaseWakeLock();
    if (mPowerManager != 0) {
        sp<IBinder> binder = mPowerManager->asBinder();
        binder->unlinkToDeath(mDeathRecipient);
    }
}

void LPAPlayer::getAudioFlinger() {
@@ -341,10 +282,6 @@ status_t LPAPlayer::start(bool sourceAlreadyStarted) {
        return err;
    }

    if (!mIsA2DPEnabled) {
        acquireWakeLock();
    }

    mIsAudioRouted = true;
    mStarted = true;
    mAudioSink->start();
@@ -382,11 +319,11 @@ void LPAPlayer::pause(bool playPendingSamples) {
    mPaused = true;
    if (playPendingSamples) {
        if (!mIsA2DPEnabled) {
           /* if (!mPauseEventPending) {
            if (!mPauseEventPending) {
                ALOGV("Posting an event for Pause timeout");
                mQueue.postEventWithDelay(mPauseEvent, LPA_PAUSE_TIMEOUT_USEC);
                mPauseEventPending = true;
            }*/
            }
            if (mAudioSink.get() != NULL)
                mAudioSink->pause();
        }
@@ -397,11 +334,11 @@ void LPAPlayer::pause(bool playPendingSamples) {
        }
    } else {
        if (!mIsA2DPEnabled) {
            /*if(!mPauseEventPending) {
            if(!mPauseEventPending) {
                ALOGV("Posting an event for Pause timeout");
                mQueue.postEventWithDelay(mPauseEvent, LPA_PAUSE_TIMEOUT_USEC);
                mPauseEventPending = true;
            }*/
            }
            if (mAudioSink.get() != NULL)
                mAudioSink->pause();
            } else {
@@ -429,6 +366,7 @@ void LPAPlayer::resume() {
        setupAudioSink();

        mPaused = false;
        mIsAudioRouted = true;
        mAudioSink->start();
        mTimeStarted = nanoseconds_to_microseconds(systemTime(SYSTEM_TIME_MONOTONIC));
        pthread_cond_signal(&decoder_cv);
@@ -459,9 +397,10 @@ void LPAPlayer::reset() {
    // make sure Decoder thread has exited
    requestAndWaitForDecoderThreadExit();
    requestAndWaitForA2DPNotificationThreadExit();

    if (mIsAudioRouted) {
        mAudioSink->stop();
        mAudioSink->close();
    }
    mAudioSink.clear();
    // Make sure to release any buffer we hold onto so that the
    // source is able to stop().
@@ -767,12 +706,10 @@ void LPAPlayer::onPauseTimeOut() {
        // 2.) Close routing Session
        mAudioSink->close();
        mIsAudioRouted = false;

        // 3.) Release Wake Lock
        releaseWakeLock();
        mTrackType = TRACK_NONE;
    }

}

status_t  LPAPlayer::setupAudioSink()
{
    status_t err = NO_ERROR;