diff options
| author | 2022-08-19 15:08:22 +0200 | |
|---|---|---|
| committer | 2022-08-25 13:52:08 +0200 | |
| commit | a6f2f169ca9e6803f9ebf06d87fbbcb36cbae01f (patch) | |
| tree | 71c6e0e5ce8f6baada50f6a60f1ab6963b390cd7 | |
| parent | f1d9af06a534278ffdb419ad19111875575b7d6f (diff) | |
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
| -rw-r--r-- | media/java/android/media/SoundPool.java | 4 | ||||
| -rw-r--r-- | media/jni/soundpool/SoundPool.cpp | 5 | ||||
| -rw-r--r-- | media/jni/soundpool/SoundPool.h | 2 | ||||
| -rw-r--r-- | media/jni/soundpool/Stream.cpp | 15 | ||||
| -rw-r--r-- | media/jni/soundpool/Stream.h | 5 | ||||
| -rw-r--r-- | media/jni/soundpool/StreamManager.cpp | 11 | ||||
| -rw-r--r-- | media/jni/soundpool/StreamManager.h | 2 | ||||
| -rw-r--r-- | media/jni/soundpool/android_media_SoundPool.cpp | 13 |
8 files changed, 37 insertions, 20 deletions
diff --git a/media/java/android/media/SoundPool.java b/media/java/android/media/SoundPool.java index bb086d6839eb..dc093595b6a4 100644 --- a/media/java/android/media/SoundPool.java +++ b/media/java/android/media/SoundPool.java @@ -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); diff --git a/media/jni/soundpool/SoundPool.cpp b/media/jni/soundpool/SoundPool.cpp index a2826cb58ccf..9f32a83ad5be 100644 --- a/media/jni/soundpool/SoundPool.cpp +++ b/media/jni/soundpool/SoundPool.cpp @@ -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; } diff --git a/media/jni/soundpool/SoundPool.h b/media/jni/soundpool/SoundPool.h index 6bb971b07e43..efc358ddf3b2 100644 --- a/media/jni/soundpool/SoundPool.h +++ b/media/jni/soundpool/SoundPool.h @@ -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); diff --git a/media/jni/soundpool/Stream.cpp b/media/jni/soundpool/Stream.cpp index 9ed8770a455c..4194a22bfb67 100644 --- a/media/jni/soundpool/Stream.cpp +++ b/media/jni/soundpool/Stream.cpp @@ -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()); diff --git a/media/jni/soundpool/Stream.h b/media/jni/soundpool/Stream.h index 0054eeca529a..6c9ef2e087f8 100644 --- a/media/jni/soundpool/Stream.h +++ b/media/jni/soundpool/Stream.h @@ -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); diff --git a/media/jni/soundpool/StreamManager.cpp b/media/jni/soundpool/StreamManager.cpp index 487a696d8765..acd4badad9b0 100644 --- a/media/jni/soundpool/StreamManager.cpp +++ b/media/jni/soundpool/StreamManager.cpp @@ -151,10 +151,13 @@ StreamManager::~StreamManager() int32_t StreamManager::queueForPlay(const std::shared_ptr<Sound> &sound, 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(sound=%p, soundID=%d, leftVolume=%f, rightVolume=%f, priority=%d, loop=%d, rate=%f)", - __func__, sound.get(), soundID, leftVolume, rightVolume, priority, loop, rate); + ALOGV( + "%s(sound=%p, soundID=%d, leftVolume=%f, rightVolume=%f, priority=%d, loop=%d, rate=%f," + " playerIId=%d)", __func__, sound.get(), soundID, leftVolume, rightVolume, priority, + loop, rate, playerIId); + bool launchThread = false; int32_t streamID = 0; std::vector<std::any> garbage; @@ -244,7 +247,7 @@ int32_t StreamManager::queueForPlay(const std::shared_ptr<Sound> &sound, removeFromQueues_l(newStream); mProcessingStreams.emplace(newStream); lock.unlock(); - if (Stream* nextStream = newStream->playPairStream(garbage)) { + if (Stream* nextStream = newStream->playPairStream(garbage, playerIId)) { lock.lock(); ALOGV("%s: starting streamID:%d", __func__, nextStream->getStreamID()); addToActiveQueue_l(nextStream); diff --git a/media/jni/soundpool/StreamManager.h b/media/jni/soundpool/StreamManager.h index ec65b0c49dc4..adbab4b0f9d9 100644 --- a/media/jni/soundpool/StreamManager.h +++ b/media/jni/soundpool/StreamManager.h @@ -394,7 +394,7 @@ public: // Returns positive streamID on success, 0 on failure. This is locked. int32_t queueForPlay(const std::shared_ptr<Sound> &sound, 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) NO_THREAD_SAFETY_ANALYSIS; // uses unique_lock /////////////////////////////////////////////////////////////////////// diff --git a/media/jni/soundpool/android_media_SoundPool.cpp b/media/jni/soundpool/android_media_SoundPool.cpp index 5264772be7c3..25040a942061 100644 --- a/media/jni/soundpool/android_media_SoundPool.cpp +++ b/media/jni/soundpool/android_media_SoundPool.cpp @@ -364,12 +364,19 @@ android_media_SoundPool_unload(JNIEnv *env, jobject thiz, jint sampleID) { static jint android_media_SoundPool_play(JNIEnv *env, jobject thiz, jint sampleID, jfloat leftVolume, jfloat rightVolume, jint priority, jint loop, - jfloat rate) + jfloat rate, jint playerIId) { ALOGV("android_media_SoundPool_play\n"); auto soundPool = getSoundPool(env, thiz); if (soundPool == nullptr) return 0; - return (jint) soundPool->play(sampleID, leftVolume, rightVolume, priority, loop, rate); + + return (jint) soundPool->play(sampleID, + leftVolume, + rightVolume, + priority, + loop, + rate, + playerIId); } static void @@ -563,7 +570,7 @@ static JNINativeMethod gMethods[] = { (void *)android_media_SoundPool_unload }, { "_play", - "(IFFIIF)I", + "(IFFIIFI)I", (void *)android_media_SoundPool_play }, { "pause", |