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
diff --git a/media/jni/soundpool/SoundPool.cpp b/media/jni/soundpool/SoundPool.cpp
index 00c4a97..a2826cb 100644
--- a/media/jni/soundpool/SoundPool.cpp
+++ b/media/jni/soundpool/SoundPool.cpp
@@ -85,12 +85,13 @@
} // 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 ffb1c99..6bb971b 100644
--- a/media/jni/soundpool/SoundPool.h
+++ b/media/jni/soundpool/SoundPool.h
@@ -31,7 +31,7 @@
*/
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 7f987e3..487a696 100644
--- a/media/jni/soundpool/StreamManager.cpp
+++ b/media/jni/soundpool/StreamManager.cpp
@@ -106,10 +106,10 @@
#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 85b468c..ec65b0c 100644
--- a/media/jni/soundpool/StreamManager.h
+++ b/media/jni/soundpool/StreamManager.h
@@ -387,7 +387,7 @@
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 14b0c11..5264772 100644
--- a/media/jni/soundpool/android_media_SoundPool.cpp
+++ b/media/jni/soundpool/android_media_SoundPool.cpp
@@ -520,7 +520,7 @@
(audio_flags_mask_t) env->GetIntField(jaa, javaAudioAttrFields.fieldFlags);
ScopedUtfChars opPackageNameStr(env, opPackageName);
auto soundPool = std::make_shared<SoundPool>(
- 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 7d9b6a2..0116a99 100644
--- a/media/jni/soundpool/tests/soundpool_stress.cpp
+++ b/media/jni/soundpool/tests/soundpool_stress.cpp
@@ -274,7 +274,7 @@
.content_type = AUDIO_CONTENT_TYPE_MUSIC,
.usage = AUDIO_USAGE_MEDIA,
};
- auto soundPool = std::make_unique<SoundPool>(maxStreams, &aa);
+ auto soundPool = std::make_unique<SoundPool>(maxStreams, aa);
gCallbackManager.setSoundPool(soundPool.get());
soundPool->setCallback(StaticCallbackManager, &gCallbackManager);