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

Commit 17bb9c2c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Revert "Revert "Added device info playback config for native pla...""

parents 3380cc65 e0414ecf
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -171,7 +171,7 @@ aaudio_result_t AudioStream::systemStart() {
    aaudio_result_t result = requestStart_l();
    if (result == AAUDIO_OK) {
        // We only call this for logging in "dumpsys audio". So ignore return code.
        (void) mPlayerBase->start();
        (void) mPlayerBase->startWithStatus(getDeviceId());
    }
    return result;
}
@@ -221,7 +221,7 @@ aaudio_result_t AudioStream::systemPause() {
    aaudio_result_t result = requestPause_l();
    if (result == AAUDIO_OK) {
        // We only call this for logging in "dumpsys audio". So ignore return code.
        (void) mPlayerBase->pause();
        (void) mPlayerBase->pauseWithStatus();
    }
    return result;
}
@@ -251,7 +251,7 @@ aaudio_result_t AudioStream::systemStopFromCallback() {
    aaudio_result_t result = safeStop_l();
    if (result == AAUDIO_OK) {
        // We only call this for logging in "dumpsys audio". So ignore return code.
        (void) mPlayerBase->stop();
        (void) mPlayerBase->stopWithStatus();
    }
    return result;
}
@@ -265,7 +265,7 @@ aaudio_result_t AudioStream::systemStopFromApp() {
    aaudio_result_t result = safeStop_l();
    if (result == AAUDIO_OK) {
        // We only call this for logging in "dumpsys audio". So ignore return code.
        (void) mPlayerBase->stop();
        (void) mPlayerBase->stopWithStatus();
    }
    return result;
}
+38 −16
Original line number Diff line number Diff line
@@ -30,7 +30,8 @@ using media::VolumeShaperOperation;
PlayerBase::PlayerBase() : BnPlayer(),
        mPanMultiplierL(1.0f), mPanMultiplierR(1.0f),
        mVolumeMultiplierL(1.0f), mVolumeMultiplierR(1.0f),
        mPIId(PLAYER_PIID_INVALID), mLastReportedEvent(PLAYER_STATE_UNKNOWN)
        mPIId(PLAYER_PIID_INVALID), mLastReportedEvent(PLAYER_STATE_UNKNOWN),
        mLastReportedDeviceId(AUDIO_PORT_HANDLE_NONE)
{
    ALOGD("PlayerBase::PlayerBase()");
    // use checkService() to avoid blocking if audio service is not up yet
@@ -64,14 +65,26 @@ void PlayerBase::baseDestroy() {
}

//------------------------------------------------------------------------------
void PlayerBase::servicePlayerEvent(player_state_t event) {
void PlayerBase::servicePlayerEvent(player_state_t event, audio_port_handle_t deviceId) {
    if (mAudioManager != 0) {
        // only report state change
        bool changed = false;
        {
            Mutex::Autolock _l(mDeviceIdLock);
            changed = mLastReportedDeviceId != deviceId;
            mLastReportedDeviceId = deviceId;
        }

        {
            Mutex::Autolock _l(mPlayerStateLock);
        if (event != mLastReportedEvent
                && mPIId != PLAYER_PIID_INVALID) {
            // PLAYER_UPDATE_DEVICE_ID is not saved as an actual state, instead it is used to update
            // device ID only.
            if ((event != PLAYER_UPDATE_DEVICE_ID) && (event != mLastReportedEvent)) {
                mLastReportedEvent = event;
            mAudioManager->playerEvent(mPIId, event);
                changed = true;
            }
        }
        if (changed && (mPIId != PLAYER_PIID_INVALID)) {
            mAudioManager->playerEvent(mPIId, event, deviceId);
        }
    }
}
@@ -84,14 +97,18 @@ void PlayerBase::serviceReleasePlayer() {
}

//FIXME temporary method while some player state is outside of this class
void PlayerBase::reportEvent(player_state_t event) {
    servicePlayerEvent(event);
void PlayerBase::reportEvent(player_state_t event, audio_port_handle_t deviceId) {
    servicePlayerEvent(event, deviceId);
}

status_t PlayerBase::startWithStatus() {
void PlayerBase::baseUpdateDeviceId(audio_port_handle_t deviceId) {
    servicePlayerEvent(PLAYER_UPDATE_DEVICE_ID, deviceId);
}

status_t PlayerBase::startWithStatus(audio_port_handle_t deviceId) {
    status_t status = playerStart();
    if (status == NO_ERROR) {
        servicePlayerEvent(PLAYER_STATE_STARTED);
        servicePlayerEvent(PLAYER_STATE_STARTED, deviceId);
    } else {
        ALOGW("PlayerBase::start() error %d", status);
    }
@@ -101,18 +118,18 @@ status_t PlayerBase::startWithStatus() {
status_t PlayerBase::pauseWithStatus() {
    status_t status = playerPause();
    if (status == NO_ERROR) {
        servicePlayerEvent(PLAYER_STATE_PAUSED);
        servicePlayerEvent(PLAYER_STATE_PAUSED, AUDIO_PORT_HANDLE_NONE);
    } else {
        ALOGW("PlayerBase::pause() error %d", status);
    }
    return status;
}


status_t PlayerBase::stopWithStatus() {
    status_t status = playerStop();

    if (status == NO_ERROR) {
        servicePlayerEvent(PLAYER_STATE_STOPPED);
        servicePlayerEvent(PLAYER_STATE_STOPPED, AUDIO_PORT_HANDLE_NONE);
    } else {
        ALOGW("PlayerBase::stop() error %d", status);
    }
@@ -123,7 +140,12 @@ status_t PlayerBase::stopWithStatus() {
// Implementation of IPlayer
binder::Status PlayerBase::start() {
    ALOGD("PlayerBase::start() from IPlayer");
    (void)startWithStatus();
    audio_port_handle_t deviceId;
    {
        Mutex::Autolock _l(mDeviceIdLock);
        deviceId = mLastReportedDeviceId;
    }
    (void)startWithStatus(deviceId);
    return binder::Status::ok();
}

+18 −0
Original line number Diff line number Diff line
@@ -36,6 +36,10 @@ TrackPlayerBase::~TrackPlayerBase() {
void TrackPlayerBase::init(AudioTrack* pat, player_type_t playerType, audio_usage_t usage) {
    PlayerBase::init(playerType, usage);
    mAudioTrack = pat;
    if (mAudioTrack != 0) {
        mSelfAudioDeviceCallback = new SelfAudioDeviceCallback(*this);
        mAudioTrack->addAudioDeviceCallback(mSelfAudioDeviceCallback);
    }
}

void TrackPlayerBase::destroy() {
@@ -43,9 +47,23 @@ void TrackPlayerBase::destroy() {
    baseDestroy();
}

TrackPlayerBase::SelfAudioDeviceCallback::SelfAudioDeviceCallback(PlayerBase& self) :
    AudioSystem::AudioDeviceCallback(), mSelf(self) {
}

TrackPlayerBase::SelfAudioDeviceCallback::~SelfAudioDeviceCallback() {
}

void TrackPlayerBase::SelfAudioDeviceCallback::onAudioDeviceUpdate(audio_io_handle_t __unused,
                                                                   audio_port_handle_t deviceId) {
    mSelf.baseUpdateDeviceId(deviceId);
}

void TrackPlayerBase::doDestroy() {
    if (mAudioTrack != 0) {
        mAudioTrack->stop();
        mAudioTrack->removeAudioDeviceCallback(mSelfAudioDeviceCallback);
        mSelfAudioDeviceCallback.clear();
        // Note that there may still be another reference in post-unlock phase of SetPlayState
        mAudioTrack.clear();
    }
+8 −3
Original line number Diff line number Diff line
@@ -44,12 +44,14 @@ public:
            const media::VolumeShaperConfiguration& configuration,
            const media::VolumeShaperOperation& operation) override;

            status_t startWithStatus();
            status_t startWithStatus(audio_port_handle_t deviceId);
            status_t pauseWithStatus();
            status_t stopWithStatus();

            //FIXME temporary method while some player state is outside of this class
            void reportEvent(player_state_t event);
            void reportEvent(player_state_t event, audio_port_handle_t deviceId);

            void baseUpdateDeviceId(audio_port_handle_t deviceId);

protected:

@@ -71,7 +73,7 @@ protected:

private:
            // report events to AudioService
            void servicePlayerEvent(player_state_t event);
            void servicePlayerEvent(player_state_t event, audio_port_handle_t deviceId);
            void serviceReleasePlayer();

    // native interface to AudioService
@@ -83,6 +85,9 @@ private:
    // Mutex for state reporting
    Mutex mPlayerStateLock;
    player_state_t mLastReportedEvent;

    Mutex mDeviceIdLock;
    audio_port_handle_t mLastReportedDeviceId;
};

} // namespace android
+12 −0
Original line number Diff line number Diff line
@@ -53,8 +53,20 @@ private:
            void doDestroy();
            status_t doSetVolume();

            class SelfAudioDeviceCallback : public AudioSystem::AudioDeviceCallback {
            public:
                SelfAudioDeviceCallback(PlayerBase& self);
                virtual void onAudioDeviceUpdate(audio_io_handle_t audioIo,
                                                         audio_port_handle_t deviceId);
            private:
                virtual ~SelfAudioDeviceCallback();
                PlayerBase& mSelf;
            };

    // volume coming from the player volume API
    float mPlayerVolumeL, mPlayerVolumeR;

   sp<SelfAudioDeviceCallback> mSelfAudioDeviceCallback;
};

} // namespace android