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

Commit 36c4b0b6 authored by Preetam Singh Ranawat's avatar Preetam Singh Ranawat Committed by Ethan Chen
Browse files

frameworks/av: port fixes in LPA and Tunnel mode playback Draft -2

-LPAPlayer: Update condition to ignore seek CRs-Fixed: 453067
-libstagefright: TunnelPlayer: update condition to send SEEK_COMPLETE
  CRs-Fixed: 441411
-libstagefright: Fix ANR with rigorous rewind of 3gp LPA clips
  CRs-Fixed: 491077 490992
-frameworks/av: Add  metadata mode changes to LPAPlayer
  CRs-Fixed: 458904 491077 490992

Change-Id: Ia89d7d6ac63b1267422a9138df9f98ef59b0ccb7
parent 7d789191
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -103,12 +103,12 @@ private:

    //Declare the condition Variables and Mutex

    pthread_mutex_t mDecoderMutex;
    Mutex mDecoderMutex;

    pthread_cond_t mDecoderCv;
    Condition mDecoderCv;

    // make sure Decoder thread has exited
    void requestAndWaitForDecoderThreadExit();
    void requestAndWaitForDecoderThreadExit_l();

    static void *decoderThreadWrapper(void *me);
    void decoderThreadEntry();
@@ -162,6 +162,7 @@ private:
        void *buffer, size_t size, void *cookie);
    size_t AudioCallback(void *cookie, void *data, size_t size);
    int64_t getMediaTimeUs_l();
    bool seekTooClose(int64_t);

    void convertMonoToStereo(int16_t *data, size_t size);

+44 −35
Original line number Diff line number Diff line
@@ -40,7 +40,8 @@

static const char   mName[] = "LPAPlayer";

#define MEM_BUFFER_SIZE (256*1024)
#define MEM_METADATA_SIZE 64
#define MEM_BUFFER_SIZE ((256*1024) - MEM_METADATA_SIZE)
#define MEM_BUFFER_COUNT 4
#define LPA_BUFFER_TIME 1500000

@@ -202,7 +203,9 @@ status_t LPAPlayer::start(bool sourceAlreadyStarted) {
    mStarted = true;
    mAudioSink->start();
    ALOGV("Waking up decoder thread");
    pthread_cond_signal(&mDecoderCv);
    mLock.lock();
    mDecoderCv.signal();
    mLock.unlock();

    return OK;
}
@@ -211,19 +214,12 @@ status_t LPAPlayer::seekTo(int64_t time_us) {
    Mutex::Autolock autoLock(mLock);
    ALOGV("seekTo: time_us %lld", time_us);

    int64_t mediaTimeUs = getMediaTimeUs_l();

    if (mediaTimeUs != 0) {
      //check for return conditions only if seektime
      // is set
      int64_t diffUs = time_us - mediaTimeUs;

      if (labs(diffUs) < LPA_BUFFER_TIME) {
          ALOGV("In seekTo(), ignoring time_us %lld mSeekTimeUs %lld", time_us, mSeekTimeUs);
    if (seekTooClose(time_us)) {
        mLock.unlock();
        mObserver->postAudioSeekComplete();
        mLock.lock();
        return OK;
    }
    }

    mSeeking = true;
    mSeekTimeUs = time_us;
@@ -239,7 +235,7 @@ status_t LPAPlayer::seekTo(int64_t time_us) {
        mReachedOutputEOS = false;
        if(mPaused == false) {
            ALOGV("Going to signal decoder thread since playback is already going on ");
            pthread_cond_signal(&mDecoderCv);
            mDecoderCv.signal();
            ALOGV("Signalled extractor thread.");
        }
    }
@@ -296,7 +292,8 @@ status_t LPAPlayer::resume() {
        }
        mPaused = false;
        mAudioSink->start();
        pthread_cond_signal(&mDecoderCv);
        mDecoderCv.signal();

    }
    return err;
}
@@ -335,7 +332,7 @@ void LPAPlayer::reset() {

    // make sure Decoder thread has exited
    ALOGD("Closing all the threads");
    requestAndWaitForDecoderThreadExit();
    requestAndWaitForDecoderThreadExit_l();

    ALOGD("Close the Sink");
    if (mIsAudioRouted) {
@@ -399,18 +396,17 @@ void *LPAPlayer::decoderThreadWrapper(void *me) {

void LPAPlayer::decoderThreadEntry() {

    pthread_mutex_lock(&mDecoderMutex);

    mLock.lock();
    pid_t tid  = gettid();
    androidSetThreadPriority(tid, ANDROID_PRIORITY_AUDIO);
    prctl(PR_SET_NAME, (unsigned long)"LPA DecodeThread", 0, 0, 0);

    ALOGV("mDecoderThreadEntry wait for signal \n");
    if (!mStarted) {
        pthread_cond_wait(&mDecoderCv, &mDecoderMutex);
        mDecoderCv.wait(mLock);
    }
    ALOGV("mDecoderThreadEntry ready to work \n");
    pthread_mutex_unlock(&mDecoderMutex);
    ALOGV("decoderThreadEntry ready to work \n");
    mLock.unlock();
    if (mKillDecoderThread) {
        return;
    }
@@ -437,9 +433,9 @@ void LPAPlayer::decoderThreadEntry() {
            ALOGV("Going to sleep before write since "
                  "mReachedEOS %d, mPaused %d, mIsAudioRouted %d",
                  mReachedEOS, mPaused, mIsAudioRouted);
            pthread_mutex_lock(&mDecoderMutex);
            pthread_cond_wait(&mDecoderCv, &mDecoderMutex);
            pthread_mutex_unlock(&mDecoderMutex);
            mDecoderMutex.lock();
            mDecoderCv.wait(mDecoderMutex);
            mDecoderMutex.unlock();
            ALOGV("Woke up from sleep before write since "
                  "mReachedEOS %d, mPaused %d, mIsAudioRouted %d",
                  mReachedEOS, mPaused, mIsAudioRouted);
@@ -469,12 +465,12 @@ void LPAPlayer::decoderThreadEntry() {
                //write only if player is not in paused state. Sleep on lock
                // resume is called
                ALOGV("Going to sleep in decodethreadiwrite since sink is paused");
                pthread_mutex_lock(&mDecoderMutex);
                pthread_cond_wait(&mDecoderCv, &mDecoderMutex);
                mDecoderMutex.lock();
                mDecoderCv.wait(mDecoderMutex);
                ALOGV("Going to unlock n decodethreadwrite since sink "
                      "resumed mPaused %d, mIsAudioRouted %d, mReachedEOS %d",
                      mPaused, mIsAudioRouted, mReachedEOS);
                pthread_mutex_unlock(&mDecoderMutex);
                mDecoderMutex.unlock();
            }
            mLock.lock();
            lSeeking = mSeeking||mInternalSeeking;
@@ -498,10 +494,7 @@ void LPAPlayer::decoderThreadEntry() {

void LPAPlayer::createThreads() {

    //Initialize all the Mutexes and Condition Variables
    pthread_mutex_init(&mDecoderMutex, NULL);
    pthread_cond_init (&mDecoderCv, NULL);

    // Create 4 threads Effect, decoder, event and A2dp
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
@@ -676,8 +669,24 @@ bool LPAPlayer::getMediaTimeMapping(
    return false;
}

bool LPAPlayer::seekTooClose(int64_t time_us) {
    int64_t t1 = getMediaTimeUs_l();
    /*
     * empirical
     * -----------
     * This constant signifies how much data (in Us) has been rendered by the
     * DSP in the interval between the moment flush is issued on AudioSink to
     * after ioctl(PAUSE) returns in Audio HAL. (flush triggers an implicit
     * pause in audio HAL)
     *
     */
     const int64_t kDeltaUs = 60000LL; /* 60-70ms on msm8974, must be measured for other targets */
     t1 += kDeltaUs;
     return (time_us > t1) && ((time_us - t1) <= LPA_BUFFER_TIME);
}

//lock taken in reset()
void LPAPlayer::requestAndWaitForDecoderThreadExit() {
void LPAPlayer::requestAndWaitForDecoderThreadExit_l() {

    if (!mDecoderThreadAlive)
        return;
@@ -688,7 +697,7 @@ void LPAPlayer::requestAndWaitForDecoderThreadExit() {
    if (!mReachedOutputEOS && mIsAudioRouted)
        mAudioSink->flush();

    pthread_cond_signal(&mDecoderCv);
    mDecoderCv.signal();
    mLock.unlock();
    pthread_join(mDecoderThread,NULL);
    mLock.lock();
+3 −1
Original line number Diff line number Diff line
@@ -777,7 +777,9 @@ void TunnelPlayer::onPauseTimeOut() {
bool TunnelPlayer::seekTooClose(int64_t time_us) {
    int64_t t1 = -1;
    /* The time as per DSP just before flush is issued */
    if (mPositionTimeRealUs == -1) {
        getOffsetRealTime_l(&mPositionTimeRealUs);
    }

    t1 = mPositionTimeRealUs;
    /*