From 240d32c20140c95916450d0ee370ab3b8c0e96ed Mon Sep 17 00:00:00 2001 From: Andy Hung Date: Fri, 18 Mar 2022 19:49:09 -0700 Subject: [PATCH] SoundPool: Clean up attribute pointer Test: atest SoundPoolAacTest Test: atest SoundPoolHapticTest Test: atest SoundPoolMidiTest Test: atest SoundPoolOggTest Test: atest AudioManagerTest#testSoundEffects Test: soundpool_stress Bug: 223815163 Change-Id: Idb2dafb9ad53dc7ffa0005425ea630fa7b7e5102 --- media/jni/soundpool/SoundPool.cpp | 5 +++-- media/jni/soundpool/SoundPool.h | 2 +- media/jni/soundpool/StreamManager.cpp | 4 ++-- media/jni/soundpool/StreamManager.h | 2 +- media/jni/soundpool/android_media_SoundPool.cpp | 2 +- media/jni/soundpool/tests/soundpool_stress.cpp | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/media/jni/soundpool/SoundPool.cpp b/media/jni/soundpool/SoundPool.cpp index 00c4a9782f33c..a2826cb58ccf5 100644 --- a/media/jni/soundpool/SoundPool.cpp +++ b/media/jni/soundpool/SoundPool.cpp @@ -85,12 +85,13 @@ bool checkLoop(int32_t *loop) } // namespace SoundPool::SoundPool( - int32_t maxStreams, const audio_attributes_t* attributes, const std::string& opPackageName) + int32_t maxStreams, const audio_attributes_t& attributes, + const std::string& opPackageName) : mStreamManager(maxStreams, kStreamManagerThreads, attributes, opPackageName) { ALOGV("%s(maxStreams=%d, attr={ content_type=%d, usage=%d, flags=0x%x, tags=%s })", __func__, maxStreams, - attributes->content_type, attributes->usage, attributes->flags, attributes->tags); + attributes.content_type, attributes.usage, attributes.flags, attributes.tags); } SoundPool::~SoundPool() diff --git a/media/jni/soundpool/SoundPool.h b/media/jni/soundpool/SoundPool.h index ffb1c997393a3..6bb971b07e437 100644 --- a/media/jni/soundpool/SoundPool.h +++ b/media/jni/soundpool/SoundPool.h @@ -31,7 +31,7 @@ namespace android { */ class SoundPool { public: - SoundPool(int32_t maxStreams, const audio_attributes_t* attributes, + SoundPool(int32_t maxStreams, const audio_attributes_t& attributes, const std::string& opPackageName = {}); ~SoundPool(); diff --git a/media/jni/soundpool/StreamManager.cpp b/media/jni/soundpool/StreamManager.cpp index 7f987e31d1d88..487a696d87659 100644 --- a/media/jni/soundpool/StreamManager.cpp +++ b/media/jni/soundpool/StreamManager.cpp @@ -106,10 +106,10 @@ int32_t StreamMap::getNextIdForStream(Stream* stream) const { #pragma clang diagnostic ignored "-Wthread-safety-analysis" StreamManager::StreamManager( - int32_t streams, size_t threads, const audio_attributes_t* attributes, + int32_t streams, size_t threads, const audio_attributes_t& attributes, std::string opPackageName) : StreamMap(streams) - , mAttributes(*attributes) + , mAttributes(attributes) , mOpPackageName(std::move(opPackageName)) , mLockStreamManagerStop(streams == 1 || kForceLockStreamManagerStop) { diff --git a/media/jni/soundpool/StreamManager.h b/media/jni/soundpool/StreamManager.h index 85b468cd2cbcb..ec65b0c49dc4c 100644 --- a/media/jni/soundpool/StreamManager.h +++ b/media/jni/soundpool/StreamManager.h @@ -387,7 +387,7 @@ class StreamManager : public StreamMap { public: // Note: the SoundPool pointer is only used for stream initialization. // It is not stored in StreamManager. - StreamManager(int32_t streams, size_t threads, const audio_attributes_t* attributes, + StreamManager(int32_t streams, size_t threads, const audio_attributes_t& attributes, std::string opPackageName); ~StreamManager(); diff --git a/media/jni/soundpool/android_media_SoundPool.cpp b/media/jni/soundpool/android_media_SoundPool.cpp index 14b0c11c986ad..5264772be7c3a 100644 --- a/media/jni/soundpool/android_media_SoundPool.cpp +++ b/media/jni/soundpool/android_media_SoundPool.cpp @@ -520,7 +520,7 @@ android_media_SoundPool_native_setup(JNIEnv *env, jobject thiz, (audio_flags_mask_t) env->GetIntField(jaa, javaAudioAttrFields.fieldFlags); ScopedUtfChars opPackageNameStr(env, opPackageName); auto soundPool = std::make_shared( - maxChannels, &audioAttributes, opPackageNameStr.c_str()); + maxChannels, audioAttributes, opPackageNameStr.c_str()); soundPool->setCallback(android_media_callback, nullptr /* user */); // register with SoundPoolManager. diff --git a/media/jni/soundpool/tests/soundpool_stress.cpp b/media/jni/soundpool/tests/soundpool_stress.cpp index 7d9b6a21b5c4b..0116a99b2ba9d 100644 --- a/media/jni/soundpool/tests/soundpool_stress.cpp +++ b/media/jni/soundpool/tests/soundpool_stress.cpp @@ -274,7 +274,7 @@ int main(int argc, char *argv[]) .content_type = AUDIO_CONTENT_TYPE_MUSIC, .usage = AUDIO_USAGE_MEDIA, }; - auto soundPool = std::make_unique(maxStreams, &aa); + auto soundPool = std::make_unique(maxStreams, aa); gCallbackManager.setSoundPool(soundPool.get()); soundPool->setCallback(StaticCallbackManager, &gCallbackManager);