codec2 hal: use SharedRefBase::ref() instead of shared_from_this
Bug: 251850069
Test: adb shell dumpsys android.hardware.media.c2.IComponentStore/software
Change-Id: Ide7f5b8121b9f6536531b86733862bdcba795437
diff --git a/media/codec2/hal/aidl/Component.cpp b/media/codec2/hal/aidl/Component.cpp
index 2e0859b..392e3c6 100644
--- a/media/codec2/hal/aidl/Component.cpp
+++ b/media/codec2/hal/aidl/Component.cpp
@@ -411,7 +411,7 @@
mDeathRecipient = ::ndk::ScopedAIBinder_DeathRecipient(
AIBinder_DeathRecipient_new(OnBinderDied));
- mDeathContext = new DeathContext{weak_from_this()};
+ mDeathContext = new DeathContext{ref<Component>()};
AIBinder_DeathRecipient_setOnUnlinked(mDeathRecipient.get(), OnBinderUnlinked);
AIBinder_linkToDeath(mListener->asBinder().get(), mDeathRecipient.get(), mDeathContext);
} else {
diff --git a/media/codec2/hal/aidl/ComponentStore.cpp b/media/codec2/hal/aidl/ComponentStore.cpp
index 2489683..58407d1 100644
--- a/media/codec2/hal/aidl/ComponentStore.cpp
+++ b/media/codec2/hal/aidl/ComponentStore.cpp
@@ -216,7 +216,7 @@
#endif
onInterfaceLoaded(c2component->intf());
std::shared_ptr<Component> comp =
- SharedRefBase::make<Component>(c2component, listener, shared_from_this(), pool);
+ SharedRefBase::make<Component>(c2component, listener, ref<ComponentStore>(), pool);
*component = comp;
if (!component) {
status = C2_CORRUPTED;
diff --git a/media/codec2/hal/aidl/include/codec2/aidl/Component.h b/media/codec2/hal/aidl/include/codec2/aidl/Component.h
index d5ea92b..4a090e9 100644
--- a/media/codec2/hal/aidl/include/codec2/aidl/Component.h
+++ b/media/codec2/hal/aidl/include/codec2/aidl/Component.h
@@ -46,8 +46,7 @@
struct ComponentStore;
-struct Component : public BnComponent,
- public std::enable_shared_from_this<Component> {
+struct Component : public BnComponent {
Component(
const std::shared_ptr<C2Component>&,
const std::shared_ptr<IComponentListener>& listener,
diff --git a/media/codec2/hal/aidl/include/codec2/aidl/ComponentStore.h b/media/codec2/hal/aidl/include/codec2/aidl/ComponentStore.h
index 7fc5d2f..b3c97d5 100644
--- a/media/codec2/hal/aidl/include/codec2/aidl/ComponentStore.h
+++ b/media/codec2/hal/aidl/include/codec2/aidl/ComponentStore.h
@@ -50,8 +50,7 @@
using ::aidl::android::hardware::media::bufferpool2::IClientManager;
-struct ComponentStore : public BnComponentStore,
- public std::enable_shared_from_this<ComponentStore> {
+struct ComponentStore : public BnComponentStore {
ComponentStore(const std::shared_ptr<C2ComponentStore>& store);
virtual ~ComponentStore();