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

Commit 68ed2541 authored by Haynes Mathew George's avatar Haynes Mathew George Committed by Brint E. Kriebel
Browse files

audiooutput: Serialize access to AudioOutput

AudioOutput can be accessed by NuPlayer and MediaPlayer::Client.
This can cause race conditions if say one of them deletes the AudioOutput
(e.g. on a offload tear down) while other accesses it. Add synchronization
for safe access.

CRs-Fixed: 837500
Change-Id: Ic09f706a3c3f73a93d4dc8477bd4caee208c292d
Ticket: CYNGNOS-325
parent 6ccd878f
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -1850,6 +1850,7 @@ status_t MediaPlayerService::AudioOutput::open(
        if (reuse) {
            ALOGV("chaining to next output and recycling track");
            close();
            Mutex::Autolock _l(mLock);
            mTrack = mRecycledTrack;
            mRecycledTrack.clear();
            if (mCallbackData != NULL) {
@@ -1886,6 +1887,7 @@ status_t MediaPlayerService::AudioOutput::open(
    if (t->getPosition(&pos) == OK) {
        mBytesWritten = uint64_t(pos) * t->frameSize();
    }
    Mutex::Autolock _l(mLock);
    mTrack = t;

    status_t res = NO_ERROR;
@@ -1920,6 +1922,7 @@ void MediaPlayerService::AudioOutput::setNextOutput(const sp<AudioOutput>& nextO


void MediaPlayerService::AudioOutput::switchToNextOutput() {
    Mutex::Autolock _l(mLock);
    ALOGV("switchToNextOutput");
    if (mNextOutput != NULL) {
        if (mCallbackData != NULL) {
@@ -1972,12 +1975,14 @@ void MediaPlayerService::AudioOutput::pause()
void MediaPlayerService::AudioOutput::close()
{
    ALOGV("close");
    Mutex::Autolock _l(mLock);
    mTrack.clear();
}

void MediaPlayerService::AudioOutput::setVolume(float left, float right)
{
    ALOGV("setVolume(%f, %f)", left, right);
    Mutex::Autolock _l(mLock);
    mLeftVolume = left;
    mRightVolume = right;
    if (mTrack != 0) {
@@ -2004,6 +2009,7 @@ status_t MediaPlayerService::AudioOutput::setPlaybackRatePermille(int32_t ratePe
status_t MediaPlayerService::AudioOutput::setAuxEffectSendLevel(float level)
{
    ALOGV("setAuxEffectSendLevel(%f)", level);
    Mutex::Autolock _l(mLock);
    mSendLevel = level;
    if (mTrack != 0) {
        return mTrack->setAuxEffectSendLevel(level);
@@ -2014,6 +2020,7 @@ status_t MediaPlayerService::AudioOutput::setAuxEffectSendLevel(float level)
status_t MediaPlayerService::AudioOutput::attachAuxEffect(int effectId)
{
    ALOGV("attachAuxEffect(%d)", effectId);
    Mutex::Autolock _l(mLock);
    mAuxEffectId = effectId;
    if (mTrack != 0) {
        return mTrack->attachAuxEffect(effectId);
+1 −0
Original line number Diff line number Diff line
@@ -194,6 +194,7 @@ class MediaPlayerService : public BnMediaPlayerService
            DISALLOW_EVIL_CONSTRUCTORS(CallbackData);
        };

        mutable Mutex mLock;
    }; // AudioOutput