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

Commit a6f2f169 authored by Vlad Popa's avatar Vlad Popa
Browse files

SoundPool: Assign the java piid to the AudioTrack

This allows to send native playback notifications for SoundPool players.

Test: dumpsys audio
Bug: 235521198
Change-Id: I7e743df4a16e0d8dae9f15f21fb4e8fa01aa4465
parent f1d9af06
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -311,7 +311,7 @@ public class SoundPool extends PlayerBase {
            int priority, int loop, float rate) {
        // FIXME: b/174876164 implement device id for soundpool
        baseStart(0);
        return _play(soundID, leftVolume, rightVolume, priority, loop, rate);
        return _play(soundID, leftVolume, rightVolume, priority, loop, rate, getPlayerIId());
    }

    /**
@@ -512,7 +512,7 @@ public class SoundPool extends PlayerBase {
            @NonNull Object/*AudioAttributes*/ attributes, @NonNull String opPackageName);

    private native final int _play(int soundID, float leftVolume, float rightVolume,
            int priority, int loop, float rate);
            int priority, int loop, float rate, int playerIId);

    private native final void _setVolume(int streamID, float leftVolume, float rightVolume);

+3 −2
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ bool SoundPool::unload(int32_t soundID)
}

int32_t SoundPool::play(int32_t soundID, float leftVolume, float rightVolume,
        int32_t priority, int32_t loop, float rate)
        int32_t priority, int32_t loop, float rate, int32_t playerIId)
{
    ALOGV("%s(soundID=%d, leftVolume=%f, rightVolume=%f, priority=%d, loop=%d, rate=%f)",
            __func__, soundID, leftVolume, rightVolume, priority, loop, rate);
@@ -136,8 +136,9 @@ int32_t SoundPool::play(int32_t soundID, float leftVolume, float rightVolume,
    }

    const int32_t streamID = mStreamManager.queueForPlay(
            sound, soundID, leftVolume, rightVolume, priority, loop, rate);
            sound, soundID, leftVolume, rightVolume, priority, loop, rate, playerIId);
    ALOGV("%s returned %d", __func__, streamID);

    return streamID;
}

+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ public:
    int32_t load(int fd, int64_t offset, int64_t length, int32_t priority);
    bool unload(int32_t soundID);
    int32_t play(int32_t soundID, float leftVolume, float rightVolume, int32_t priority,
            int32_t loop, float rate);
            int32_t loop, float rate, int32_t playerIId = PLAYER_PIID_INVALID);
    void pause(int32_t streamID);
    void autoPause();
    void resume(int32_t streamID);
+10 −5
Original line number Diff line number Diff line
@@ -229,7 +229,7 @@ Stream* Stream::getPairStream() const
   return mStreamManager->getPairStream(this);
}

Stream* Stream::playPairStream(std::vector<std::any>& garbage) {
Stream* Stream::playPairStream(std::vector<std::any>& garbage, int32_t playerIId) {
    Stream* pairStream = getPairStream();
    LOG_ALWAYS_FATAL_IF(pairStream == nullptr, "No pair stream!");
    {
@@ -260,7 +260,7 @@ Stream* Stream::playPairStream(std::vector<std::any>& garbage) {
        const int pairState = pairStream->mState;
        pairStream->play_l(pairStream->mSound, pairStream->mStreamID,
                pairStream->mLeftVolume, pairStream->mRightVolume, pairStream->mPriority,
                pairStream->mLoop, pairStream->mRate, garbage);
                pairStream->mLoop, pairStream->mRate, garbage, playerIId);
        if (pairStream->mState == IDLE) {
            return nullptr; // AudioTrack error
        }
@@ -274,12 +274,12 @@ Stream* Stream::playPairStream(std::vector<std::any>& garbage) {

void Stream::play_l(const std::shared_ptr<Sound>& sound, int32_t nextStreamID,
        float leftVolume, float rightVolume, int32_t priority, int32_t loop, float rate,
        std::vector<std::any>& garbage)
        std::vector<std::any>& garbage, int32_t playerIId)
{
    ALOGV("%s(%p)(soundID=%d, streamID=%d, leftVolume=%f, rightVolume=%f,"
            " priority=%d, loop=%d, rate=%f)",
            " priority=%d, loop=%d, rate=%f, playerIId=%d)",
            __func__, this, sound->getSoundID(), nextStreamID, leftVolume, rightVolume,
            priority, loop, rate);
            priority, loop, rate, playerIId);

    // initialize track
    const audio_stream_type_t streamType =
@@ -340,6 +340,10 @@ void Stream::play_l(const std::shared_ptr<Sound>& sound, int32_t nextStreamID,
        // MediaMetricsConstants.h: AMEDIAMETRICS_PROP_CALLERNAME_VALUE_SOUNDPOOL
        mAudioTrack->setCallerName("soundpool");

        if (playerIId != PLAYER_PIID_INVALID) {
            mAudioTrack->setPlayerIId(playerIId);
        }

        if (status_t status = mAudioTrack->initCheck();
            status != NO_ERROR) {
            ALOGE("%s: error %d creating AudioTrack", __func__, status);
@@ -379,6 +383,7 @@ int Stream::getCorrespondingStreamID() {
    std::lock_guard lock(mLock);
    return static_cast<int>(mAudioTrack ? mStreamID : getPairStream()->mStreamID);
}

size_t Stream::StreamCallback::onMoreData(const AudioTrack::Buffer&) {
    ALOGW("%s streamID %d Unexpected EVENT_MORE_DATA for static track",
            __func__, mStream->getCorrespondingStreamID());
+3 −2
Original line number Diff line number Diff line
@@ -93,7 +93,8 @@ public:

    // returns the pair stream if successful, nullptr otherwise.
    // garbage is used to release tracks and data outside of any lock.
    Stream* playPairStream(std::vector<std::any>& garbage);
    Stream* playPairStream(std::vector<std::any>& garbage,
                           int32_t playerIId = PLAYER_PIID_INVALID);

    // These parameters are explicitly checked in the SoundPool class
    // so never deviate from the Java API specified values.
@@ -157,7 +158,7 @@ private:
    // garbage is used to release tracks and data outside of any lock.
    void play_l(const std::shared_ptr<Sound>& sound, int streamID,
            float leftVolume, float rightVolume, int priority, int loop, float rate,
            std::vector<std::any>& garbage) REQUIRES(mLock);
            std::vector<std::any>& garbage, int playerIId) REQUIRES(mLock);
    void stop_l() REQUIRES(mLock);
    void setVolume_l(float leftVolume, float rightVolume) REQUIRES(mLock);

Loading