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
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user