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

Commit b96f0793 authored by Divya Narayanan Poojary's avatar Divya Narayanan Poojary Committed by Steve Kondik
Browse files

audio:Avoid AudioTrackThread if Track creation fails

-mAudioTrackThread is starting before the track creation.
 This thread is used to process the audio buffer, which
 is no longer valid if the track creation itself is
 failing.

-Fix is to check for the result of track creation and
 based on the result need to start the mAudioTrackThread.

Change-Id: Ic69e45f4269408ff60fe83390e9f8d0c895582e3
CRs-Fixed: 611668
parent 2ce9191f
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -476,11 +476,6 @@ status_t AudioTrack::set(
    }
    else {
#endif
    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,
@@ -491,6 +486,11 @@ status_t AudioTrack::set(
                                  output,
                                  0 /*epoch*/);

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

    if (status != NO_ERROR) {
        if (mAudioTrackThread != 0) {
            mAudioTrackThread->requestExit();   // see comment in AudioTrack.h
@@ -1623,7 +1623,10 @@ nsecs_t AudioTrack::processAudioBuffer(const sp<AudioTrackThread>& thread)
    // Currently the AudioTrack thread is not created if there are no callbacks.
    // Would it ever make sense to run the thread, even without callbacks?
    // If so, then replace this by checks at each use for mCbf != NULL.
    LOG_ALWAYS_FATAL_IF(mCblk == NULL);
    if (mCblk == NULL) {
        ALOGE("mCblk is NULL");
        return NS_NEVER;
    }

    mLock.lock();
    if (mAwaitBoost) {