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

Commit 5d464eb0 authored by Glenn Kasten's avatar Glenn Kasten
Browse files

Swap the order of creating IAudioTrack and thread

Simplifies the error recovery in case IAudioTrack fails.

Change-Id: I6aee41a2ac747a5689fb4836b04174e6107bf32f
parent 0ec23ce0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -473,7 +473,7 @@ protected:
        friend class AudioTrack;
        virtual bool        threadLoop();
        AudioTrack& mReceiver;
        ~AudioTrackThread();
        virtual ~AudioTrackThread();
        Mutex               mMyLock;    // Thread::mLock is private
        Condition           mMyCond;    // Thread::mThreadExitedCondition is private
        bool                mPaused;    // whether thread is currently paused
+5 −10
Original line number Diff line number Diff line
@@ -278,11 +278,6 @@ status_t AudioTrack::set(
    mFlags = flags;
    mCbf = cbf;

    if (cbf != NULL) {
        mAudioTrackThread = new AudioTrackThread(*this, threadCanCallJava);
        mAudioTrackThread->run("AudioTrack", ANDROID_PRIORITY_AUDIO, 0 /*stack*/);
    }

    // create the IAudioTrack
    status_t status = createTrack_l(streamType,
                                  sampleRate,
@@ -292,15 +287,15 @@ status_t AudioTrack::set(
                                  flags,
                                  sharedBuffer,
                                  output);

    if (status != NO_ERROR) {
        if (mAudioTrackThread != 0) {
            mAudioTrackThread->requestExit();
            mAudioTrackThread.clear();
        }
        return status;
    }

    if (cbf != NULL) {
        mAudioTrackThread = new AudioTrackThread(*this, threadCanCallJava);
        mAudioTrackThread->run("AudioTrack", ANDROID_PRIORITY_AUDIO);
    }

    mStatus = NO_ERROR;

    mStreamType = streamType;