Loading media/jni/soundpool/Stream.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -179,6 +179,7 @@ bool Stream::requestStop(int32_t streamID) { std::lock_guard lock(mLock); if (streamID == mStreamID) { ALOGV("%s: track streamID: %d", __func__, streamID); if (mAudioTrack != nullptr) { if (mState == PLAYING && !mMuted && (mLeftVolume != 0.f || mRightVolume != 0.f)) { setVolume_l(0.f, 0.f); Loading @@ -202,6 +203,7 @@ void Stream::stop() void Stream::stop_l() { if (mState != IDLE) { ALOGV("%s: track streamID: %d", __func__, (int)mStreamID); if (mAudioTrack != nullptr) { mAudioTrack->stop(); } Loading @@ -227,6 +229,7 @@ Stream* Stream::playPairStream() { LOG_ALWAYS_FATAL_IF(pairStream == nullptr, "No pair stream!"); sp<AudioTrack> releaseTracks[2]; { ALOGV("%s: track streamID: %d", __func__, (int)mStreamID); // TODO: Do we really want to force a simultaneous synchronization between // the stream and its pair? Loading media/jni/soundpool/StreamManager.cpp +11 −3 Original line number Diff line number Diff line Loading @@ -148,16 +148,18 @@ int32_t StreamManager::queueForPlay(const std::shared_ptr<Sound> &sound, sanityCheckQueue_l(); // find an available stream, prefer one that has matching sound id. if (mAvailableStreams.size() > 0) { newStream = *mAvailableStreams.begin(); for (auto stream : mAvailableStreams) { if (stream->getSoundID() == soundID) { newStream = stream; ALOGV("%s: found soundID %d in available queue", __func__, soundID); break; } } if (newStream != nullptr) { newStream->setStopTimeNs(systemTime()); if (newStream == nullptr) { ALOGV("%s: found stream in available queue", __func__); newStream = *mAvailableStreams.begin(); } newStream->setStopTimeNs(systemTime()); fromAvailableQueue = true; } Loading @@ -166,10 +168,12 @@ int32_t StreamManager::queueForPlay(const std::shared_ptr<Sound> &sound, for (auto [unused , stream] : mRestartStreams) { if (!stream->getPairStream()->hasSound()) { if (stream->getSoundID() == soundID) { ALOGV("%s: found soundID %d in restart queue", __func__, soundID); newStream = stream; fromAvailableQueue = false; break; } else if (newStream == nullptr) { ALOGV("%s: found stream in restart queue", __func__); newStream = stream; } } Loading @@ -183,6 +187,7 @@ int32_t StreamManager::queueForPlay(const std::shared_ptr<Sound> &sound, if (newStream == nullptr || newStream->getPriority() > stream->getPriority()) { newStream = stream; ALOGV("%s: found stream in active queue", __func__); } } } Loading @@ -195,6 +200,7 @@ int32_t StreamManager::queueForPlay(const std::shared_ptr<Sound> &sound, if (newStream == nullptr) { for (auto [unused, stream] : mRestartStreams) { if (stream->getPairPriority() <= priority) { ALOGV("%s: evict stream from restart queue", __func__); newStream = stream; break; } Loading @@ -210,6 +216,8 @@ int32_t StreamManager::queueForPlay(const std::shared_ptr<Sound> &sound, Stream *pairStream = newStream->getPairStream(); streamID = getNextIdForStream(pairStream); ALOGV("%s: newStream:%p pairStream:%p, streamID:%d", __func__, newStream, pairStream, streamID); pairStream->setPlay( streamID, sound, soundID, leftVolume, rightVolume, priority, loop, rate); if (fromAvailableQueue && kPlayOnCallingThread) { Loading media/jni/soundpool/tests/build_and_run.sh +4 −1 Original line number Diff line number Diff line Loading @@ -23,7 +23,10 @@ uidir="/product/media/audio/notifications" adb push $OUT/system/bin/soundpool_stress /system/bin # test SoundPool playback of all the UI sound samples (loaded twice) looping 10s 1 thread. #adb shell /system/bin/soundpool_stress -l -1 $uidir/*.ogg $uidir/*.ogg adb shell /system/bin/soundpool_stress -l -1 $uidir/*.ogg $uidir/*.ogg # test SoundPool playback of all the UI sound samples (repeating 3 times) looping 10s 1 thread. adb shell /system/bin/soundpool_stress -l 1 -r 3 $uidir/*.ogg # performance test SoundPool playback of all the UI sound samples (x2) # 1 iterations, looping, 1 second playback, 4 threads. Loading media/jni/soundpool/tests/soundpool_stress.cpp +34 −24 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ void usage(const char *name) printf(" -i #iterations, default 1\n"); printf(" -l #loop looping mode, -1 forever\n"); printf(" -p #playback_seconds, default 10\n"); printf(" -r #repeat soundIDs (0 or more times), default 0\n"); printf(" -s #streams for concurrent sound playback, default 20\n"); printf(" -t #threads, default 1\n"); printf(" -z #snoozeSec after stopping, -1 forever, default 0\n"); Loading Loading @@ -112,7 +113,7 @@ void StaticCallbackManager(SoundPoolEvent event, SoundPool* soundPool, void* use } void testStreams(SoundPool *soundPool, const std::vector<const char *> &filenames, int loop, int playSec) int loop, int repeat, int playSec) { const int64_t startTimeNs = systemTime(); std::vector<int32_t> soundIDs; Loading Loading @@ -153,6 +154,7 @@ void testStreams(SoundPool *soundPool, const std::vector<const char *> &filename // TODO: Use SoundPool::setCallback() for wait for (int32_t soundID : soundIDs) { for (int i = 0; i <= repeat; ++i) { while (true) { const int32_t streamID = soundPool->play(soundID, silentVol, silentVol, priority, 0 /*loop*/, rate); Loading @@ -171,6 +173,7 @@ void testStreams(SoundPool *soundPool, const std::vector<const char *> &filename printf("[%d]", soundID); fflush(stdout); } } const int64_t loadTimeNs = systemTime(); printf("\nloadTimeMs: %d\n", (int)((loadTimeNs - startTimeNs) / NANOS_PER_MILLISECOND)); Loading @@ -178,8 +181,10 @@ void testStreams(SoundPool *soundPool, const std::vector<const char *> &filename // check and play (overlap with above). std::vector<int32_t> streamIDs; for (int32_t soundID : soundIDs) { for (int i = 0; i <= repeat; ++i) { printf("\nplaying soundID=%d", soundID); const int32_t streamID = soundPool->play(soundID, maxVol, maxVol, priority, loop, rate); const int32_t streamID = soundPool->play(soundID, maxVol, maxVol, priority, loop, rate); if (streamID == 0) { printf(" failed! ERROR"); ++gErrors; Loading @@ -188,6 +193,7 @@ void testStreams(SoundPool *soundPool, const std::vector<const char *> &filename streamIDs.emplace_back(streamID); } } } const int64_t playTimeNs = systemTime(); printf("\nplayTimeMs: %d\n", (int)((playTimeNs - loadTimeNs) / NANOS_PER_MILLISECOND)); Loading Loading @@ -217,9 +223,10 @@ int main(int argc, char *argv[]) int loop = 0; // disable looping int maxStreams = 40; // change to have more concurrent playback streams int playSec = 10; int repeat = 0; int snoozeSec = 0; int threadCount = 1; for (int ch; (ch = getopt(argc, argv, "i:l:p:s:t:z:")) != -1; ) { for (int ch; (ch = getopt(argc, argv, "i:l:p:r:s:t:z:")) != -1; ) { switch (ch) { case 'i': iterations = atoi(optarg); Loading @@ -230,6 +237,9 @@ int main(int argc, char *argv[]) case 'p': playSec = atoi(optarg); break; case 'r': repeat = atoi(optarg); break; case 's': maxStreams = atoi(optarg); break; Loading Loading @@ -280,7 +290,7 @@ int main(int argc, char *argv[]) printf("testing %zu threads\n", threads.size()); for (auto &thread : threads) { thread = std::async(std::launch::async, [&]{ testStreams(soundPool.get(), filenames, loop, playSec);}); [&]{ testStreams(soundPool.get(), filenames, loop, repeat, playSec);}); } // automatically joins. } Loading Loading
media/jni/soundpool/Stream.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -179,6 +179,7 @@ bool Stream::requestStop(int32_t streamID) { std::lock_guard lock(mLock); if (streamID == mStreamID) { ALOGV("%s: track streamID: %d", __func__, streamID); if (mAudioTrack != nullptr) { if (mState == PLAYING && !mMuted && (mLeftVolume != 0.f || mRightVolume != 0.f)) { setVolume_l(0.f, 0.f); Loading @@ -202,6 +203,7 @@ void Stream::stop() void Stream::stop_l() { if (mState != IDLE) { ALOGV("%s: track streamID: %d", __func__, (int)mStreamID); if (mAudioTrack != nullptr) { mAudioTrack->stop(); } Loading @@ -227,6 +229,7 @@ Stream* Stream::playPairStream() { LOG_ALWAYS_FATAL_IF(pairStream == nullptr, "No pair stream!"); sp<AudioTrack> releaseTracks[2]; { ALOGV("%s: track streamID: %d", __func__, (int)mStreamID); // TODO: Do we really want to force a simultaneous synchronization between // the stream and its pair? Loading
media/jni/soundpool/StreamManager.cpp +11 −3 Original line number Diff line number Diff line Loading @@ -148,16 +148,18 @@ int32_t StreamManager::queueForPlay(const std::shared_ptr<Sound> &sound, sanityCheckQueue_l(); // find an available stream, prefer one that has matching sound id. if (mAvailableStreams.size() > 0) { newStream = *mAvailableStreams.begin(); for (auto stream : mAvailableStreams) { if (stream->getSoundID() == soundID) { newStream = stream; ALOGV("%s: found soundID %d in available queue", __func__, soundID); break; } } if (newStream != nullptr) { newStream->setStopTimeNs(systemTime()); if (newStream == nullptr) { ALOGV("%s: found stream in available queue", __func__); newStream = *mAvailableStreams.begin(); } newStream->setStopTimeNs(systemTime()); fromAvailableQueue = true; } Loading @@ -166,10 +168,12 @@ int32_t StreamManager::queueForPlay(const std::shared_ptr<Sound> &sound, for (auto [unused , stream] : mRestartStreams) { if (!stream->getPairStream()->hasSound()) { if (stream->getSoundID() == soundID) { ALOGV("%s: found soundID %d in restart queue", __func__, soundID); newStream = stream; fromAvailableQueue = false; break; } else if (newStream == nullptr) { ALOGV("%s: found stream in restart queue", __func__); newStream = stream; } } Loading @@ -183,6 +187,7 @@ int32_t StreamManager::queueForPlay(const std::shared_ptr<Sound> &sound, if (newStream == nullptr || newStream->getPriority() > stream->getPriority()) { newStream = stream; ALOGV("%s: found stream in active queue", __func__); } } } Loading @@ -195,6 +200,7 @@ int32_t StreamManager::queueForPlay(const std::shared_ptr<Sound> &sound, if (newStream == nullptr) { for (auto [unused, stream] : mRestartStreams) { if (stream->getPairPriority() <= priority) { ALOGV("%s: evict stream from restart queue", __func__); newStream = stream; break; } Loading @@ -210,6 +216,8 @@ int32_t StreamManager::queueForPlay(const std::shared_ptr<Sound> &sound, Stream *pairStream = newStream->getPairStream(); streamID = getNextIdForStream(pairStream); ALOGV("%s: newStream:%p pairStream:%p, streamID:%d", __func__, newStream, pairStream, streamID); pairStream->setPlay( streamID, sound, soundID, leftVolume, rightVolume, priority, loop, rate); if (fromAvailableQueue && kPlayOnCallingThread) { Loading
media/jni/soundpool/tests/build_and_run.sh +4 −1 Original line number Diff line number Diff line Loading @@ -23,7 +23,10 @@ uidir="/product/media/audio/notifications" adb push $OUT/system/bin/soundpool_stress /system/bin # test SoundPool playback of all the UI sound samples (loaded twice) looping 10s 1 thread. #adb shell /system/bin/soundpool_stress -l -1 $uidir/*.ogg $uidir/*.ogg adb shell /system/bin/soundpool_stress -l -1 $uidir/*.ogg $uidir/*.ogg # test SoundPool playback of all the UI sound samples (repeating 3 times) looping 10s 1 thread. adb shell /system/bin/soundpool_stress -l 1 -r 3 $uidir/*.ogg # performance test SoundPool playback of all the UI sound samples (x2) # 1 iterations, looping, 1 second playback, 4 threads. Loading
media/jni/soundpool/tests/soundpool_stress.cpp +34 −24 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ void usage(const char *name) printf(" -i #iterations, default 1\n"); printf(" -l #loop looping mode, -1 forever\n"); printf(" -p #playback_seconds, default 10\n"); printf(" -r #repeat soundIDs (0 or more times), default 0\n"); printf(" -s #streams for concurrent sound playback, default 20\n"); printf(" -t #threads, default 1\n"); printf(" -z #snoozeSec after stopping, -1 forever, default 0\n"); Loading Loading @@ -112,7 +113,7 @@ void StaticCallbackManager(SoundPoolEvent event, SoundPool* soundPool, void* use } void testStreams(SoundPool *soundPool, const std::vector<const char *> &filenames, int loop, int playSec) int loop, int repeat, int playSec) { const int64_t startTimeNs = systemTime(); std::vector<int32_t> soundIDs; Loading Loading @@ -153,6 +154,7 @@ void testStreams(SoundPool *soundPool, const std::vector<const char *> &filename // TODO: Use SoundPool::setCallback() for wait for (int32_t soundID : soundIDs) { for (int i = 0; i <= repeat; ++i) { while (true) { const int32_t streamID = soundPool->play(soundID, silentVol, silentVol, priority, 0 /*loop*/, rate); Loading @@ -171,6 +173,7 @@ void testStreams(SoundPool *soundPool, const std::vector<const char *> &filename printf("[%d]", soundID); fflush(stdout); } } const int64_t loadTimeNs = systemTime(); printf("\nloadTimeMs: %d\n", (int)((loadTimeNs - startTimeNs) / NANOS_PER_MILLISECOND)); Loading @@ -178,8 +181,10 @@ void testStreams(SoundPool *soundPool, const std::vector<const char *> &filename // check and play (overlap with above). std::vector<int32_t> streamIDs; for (int32_t soundID : soundIDs) { for (int i = 0; i <= repeat; ++i) { printf("\nplaying soundID=%d", soundID); const int32_t streamID = soundPool->play(soundID, maxVol, maxVol, priority, loop, rate); const int32_t streamID = soundPool->play(soundID, maxVol, maxVol, priority, loop, rate); if (streamID == 0) { printf(" failed! ERROR"); ++gErrors; Loading @@ -188,6 +193,7 @@ void testStreams(SoundPool *soundPool, const std::vector<const char *> &filename streamIDs.emplace_back(streamID); } } } const int64_t playTimeNs = systemTime(); printf("\nplayTimeMs: %d\n", (int)((playTimeNs - loadTimeNs) / NANOS_PER_MILLISECOND)); Loading Loading @@ -217,9 +223,10 @@ int main(int argc, char *argv[]) int loop = 0; // disable looping int maxStreams = 40; // change to have more concurrent playback streams int playSec = 10; int repeat = 0; int snoozeSec = 0; int threadCount = 1; for (int ch; (ch = getopt(argc, argv, "i:l:p:s:t:z:")) != -1; ) { for (int ch; (ch = getopt(argc, argv, "i:l:p:r:s:t:z:")) != -1; ) { switch (ch) { case 'i': iterations = atoi(optarg); Loading @@ -230,6 +237,9 @@ int main(int argc, char *argv[]) case 'p': playSec = atoi(optarg); break; case 'r': repeat = atoi(optarg); break; case 's': maxStreams = atoi(optarg); break; Loading Loading @@ -280,7 +290,7 @@ int main(int argc, char *argv[]) printf("testing %zu threads\n", threads.size()); for (auto &thread : threads) { thread = std::async(std::launch::async, [&]{ testStreams(soundPool.get(), filenames, loop, playSec);}); [&]{ testStreams(soundPool.get(), filenames, loop, repeat, playSec);}); } // automatically joins. } Loading