diff options
| author | 2019-11-19 16:44:13 -0800 | |
|---|---|---|
| committer | 2019-12-03 22:28:40 +0000 | |
| commit | 457ed3ae48113037fc6fb1e5b3875f542a6243e9 (patch) | |
| tree | b33ce2d53de7b19078913e61083f16e22a47ce6b | |
| parent | aefb7bcea93ec8f9611cd729a657f0c88ed4bc2a (diff) | |
SoundPool: Improve tests
Add repeated sound IDs.
Add more Stream logging.
Test: soundpool_stress
Test: android.media.cts.SoundPool*Test
Bug: 140807581
Change-Id: Icc249791c43a943d3cdb237d476eee58c669216e
| -rw-r--r-- | media/jni/soundpool/Stream.cpp | 3 | ||||
| -rw-r--r-- | media/jni/soundpool/StreamManager.cpp | 14 | ||||
| -rwxr-xr-x | media/jni/soundpool/tests/build_and_run.sh | 5 | ||||
| -rw-r--r-- | media/jni/soundpool/tests/soundpool_stress.cpp | 58 |
4 files changed, 52 insertions, 28 deletions
diff --git a/media/jni/soundpool/Stream.cpp b/media/jni/soundpool/Stream.cpp index e7d4d9093bb8..809e81b13a45 100644 --- a/media/jni/soundpool/Stream.cpp +++ b/media/jni/soundpool/Stream.cpp @@ -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); @@ -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(); } @@ -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? diff --git a/media/jni/soundpool/StreamManager.cpp b/media/jni/soundpool/StreamManager.cpp index 64f81d5c34fb..79e4d8ae6e26 100644 --- a/media/jni/soundpool/StreamManager.cpp +++ b/media/jni/soundpool/StreamManager.cpp @@ -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; } @@ -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; } } @@ -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__); } } } @@ -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; } @@ -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) { diff --git a/media/jni/soundpool/tests/build_and_run.sh b/media/jni/soundpool/tests/build_and_run.sh index 741f2efbfddb..72fd52814202 100755 --- a/media/jni/soundpool/tests/build_and_run.sh +++ b/media/jni/soundpool/tests/build_and_run.sh @@ -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. diff --git a/media/jni/soundpool/tests/soundpool_stress.cpp b/media/jni/soundpool/tests/soundpool_stress.cpp index 212662fb6b96..7d9b6a21b5c4 100644 --- a/media/jni/soundpool/tests/soundpool_stress.cpp +++ b/media/jni/soundpool/tests/soundpool_stress.cpp @@ -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"); @@ -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; @@ -153,23 +154,25 @@ void testStreams(SoundPool *soundPool, const std::vector<const char *> &filename // TODO: Use SoundPool::setCallback() for wait for (int32_t soundID : soundIDs) { - while (true) { - const int32_t streamID = + for (int i = 0; i <= repeat; ++i) { + while (true) { + const int32_t streamID = soundPool->play(soundID, silentVol, silentVol, priority, 0 /*loop*/, rate); - if (streamID != 0) { - const int32_t events = gCallbackManager.getNumberEvents(soundID); - if (events != 1) { - printf("WARNING: successful play for streamID:%d soundID:%d" - " but callback events(%d) != 1\n", streamID, soundID, events); - ++gWarnings; + if (streamID != 0) { + const int32_t events = gCallbackManager.getNumberEvents(soundID); + if (events != 1) { + printf("WARNING: successful play for streamID:%d soundID:%d" + " but callback events(%d) != 1\n", streamID, soundID, events); + ++gWarnings; + } + soundPool->stop(streamID); + break; } - soundPool->stop(streamID); - break; + usleep(1000); } - usleep(1000); + printf("[%d]", soundID); + fflush(stdout); } - printf("[%d]", soundID); - fflush(stdout); } const int64_t loadTimeNs = systemTime(); @@ -178,14 +181,17 @@ 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) { - printf("\nplaying soundID=%d", soundID); - const int32_t streamID = soundPool->play(soundID, maxVol, maxVol, priority, loop, rate); - if (streamID == 0) { - printf(" failed! ERROR"); - ++gErrors; - } else { - printf(" streamID=%d", streamID); - streamIDs.emplace_back(streamID); + for (int i = 0; i <= repeat; ++i) { + printf("\nplaying soundID=%d", soundID); + const int32_t streamID = + soundPool->play(soundID, maxVol, maxVol, priority, loop, rate); + if (streamID == 0) { + printf(" failed! ERROR"); + ++gErrors; + } else { + printf(" streamID=%d", streamID); + streamIDs.emplace_back(streamID); + } } } const int64_t playTimeNs = systemTime(); @@ -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); @@ -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; @@ -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. } |