Loading include/media/audiohal/hidl/HalDeathHandler.h 0 → 100644 +62 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ANDROID_HARDWARE_HIDL_HAL_DEATH_HANDLER_H #define ANDROID_HARDWARE_HIDL_HAL_DEATH_HANDLER_H #include <functional> #include <mutex> #include <unordered_map> #include <hidl/HidlSupport.h> #include <utils/Singleton.h> using android::hardware::hidl_death_recipient; using android::hidl::base::V1_0::IBase; namespace android { class HalDeathHandler : public hidl_death_recipient, private Singleton<HalDeathHandler> { public: typedef std::function<void()> AtExitHandler; // Note that the exit handler gets called using a thread from // RPC threadpool, thus it needs to be thread-safe. void registerAtExitHandler(void* cookie, AtExitHandler handler); void unregisterAtExitHandler(void* cookie); // hidl_death_recipient virtual void serviceDied(uint64_t cookie, const wp<IBase>& who); // Used both for (un)registering handlers, and for passing to // '(un)linkToDeath'. static sp<HalDeathHandler> getInstance(); private: friend class Singleton<HalDeathHandler>; typedef std::unordered_map<void*, AtExitHandler> Handlers; HalDeathHandler(); virtual ~HalDeathHandler(); sp<HalDeathHandler> mSelf; // Allows the singleton instance to live forever. std::mutex mHandlersLock; Handlers mHandlers; }; } // namespace android #endif // ANDROID_HARDWARE_HIDL_HAL_DEATH_HANDLER_H media/libaudiohal/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ else # if !USE_LEGACY_LOCAL_AUDIO_HAL LOCAL_SRC_FILES := \ ConversionHelperHidl.cpp \ HalDeathHandlerHidl.cpp \ DeviceHalHidl.cpp \ DevicesFactoryHalHidl.cpp \ EffectBufferHalHidl.cpp \ Loading media/libaudiohal/ConversionHelperHidl.h +2 −2 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ class ConversionHelperHidl { if (!ret.isOk()) { emitError(funcName, ret.description().c_str()); } return ret.isOk() ? OK : UNKNOWN_ERROR; return ret.isOk() ? OK : FAILED_TRANSACTION; } status_t processReturn(const char* funcName, const Return<hardware::audio::V2_0::Result>& ret) { Loading @@ -62,7 +62,7 @@ class ConversionHelperHidl { template<typename T> status_t processReturn( const char* funcName, const Return<T>& ret, hardware::audio::V2_0::Result retval) { const status_t st = ret.isOk() ? analyzeResult(retval) : UNKNOWN_ERROR; const status_t st = ret.isOk() ? analyzeResult(retval) : FAILED_TRANSACTION; if (!ret.isOk()) { emitError(funcName, ret.description().c_str()); } Loading media/libaudiohal/DevicesFactoryHalHidl.cpp +7 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ //#define LOG_NDEBUG 0 #include <android/hardware/audio/2.0/IDevice.h> #include <media/audiohal/hidl/HalDeathHandler.h> #include <utils/Log.h> #include "ConversionHelperHidl.h" Loading @@ -40,6 +41,11 @@ sp<DevicesFactoryHalInterface> DevicesFactoryHalInterface::create() { DevicesFactoryHalHidl::DevicesFactoryHalHidl() { mDevicesFactory = IDevicesFactory::getService("audio_devices_factory"); if (mDevicesFactory != 0) { // It is assumet that DevicesFactory is owned by AudioFlinger // and thus have the same lifespan. mDevicesFactory->linkToDeath(HalDeathHandler::getInstance(), 0 /*cookie*/); } } DevicesFactoryHalHidl::~DevicesFactoryHalHidl() { Loading Loading @@ -83,7 +89,7 @@ status_t DevicesFactoryHalHidl::openDevice(const char *name, sp<DeviceHalInterfa else if (retval == Result::INVALID_ARGUMENTS) return BAD_VALUE; else return NO_INIT; } return UNKNOWN_ERROR; return FAILED_TRANSACTION; } } // namespace android media/libaudiohal/EffectHalHidl.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -160,7 +160,7 @@ status_t EffectHalHidl::setProcessBuffers() { mBuffersChanged = false; return OK; } return ret.isOk() ? analyzeResult(ret) : UNKNOWN_ERROR; return ret.isOk() ? analyzeResult(ret) : FAILED_TRANSACTION; } status_t EffectHalHidl::command(uint32_t cmdCode, uint32_t cmdSize, void *pCmdData, Loading @@ -183,7 +183,7 @@ status_t EffectHalHidl::command(uint32_t cmdCode, uint32_t cmdSize, void *pCmdDa } } }); return status; return ret.isOk() ? status : FAILED_TRANSACTION; } status_t EffectHalHidl::getDescriptor(effect_descriptor_t *pDescriptor) { Loading @@ -196,13 +196,13 @@ status_t EffectHalHidl::getDescriptor(effect_descriptor_t *pDescriptor) { effectDescriptorToHal(result, pDescriptor); } }); return ret.isOk() ? analyzeResult(retval) : UNKNOWN_ERROR; return ret.isOk() ? analyzeResult(retval) : FAILED_TRANSACTION; } status_t EffectHalHidl::close() { if (mEffect == 0) return NO_INIT; Return<Result> ret = mEffect->close(); return ret.isOk() ? analyzeResult(ret) : UNKNOWN_ERROR; return ret.isOk() ? analyzeResult(ret) : FAILED_TRANSACTION; } } // namespace android Loading
include/media/audiohal/hidl/HalDeathHandler.h 0 → 100644 +62 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ANDROID_HARDWARE_HIDL_HAL_DEATH_HANDLER_H #define ANDROID_HARDWARE_HIDL_HAL_DEATH_HANDLER_H #include <functional> #include <mutex> #include <unordered_map> #include <hidl/HidlSupport.h> #include <utils/Singleton.h> using android::hardware::hidl_death_recipient; using android::hidl::base::V1_0::IBase; namespace android { class HalDeathHandler : public hidl_death_recipient, private Singleton<HalDeathHandler> { public: typedef std::function<void()> AtExitHandler; // Note that the exit handler gets called using a thread from // RPC threadpool, thus it needs to be thread-safe. void registerAtExitHandler(void* cookie, AtExitHandler handler); void unregisterAtExitHandler(void* cookie); // hidl_death_recipient virtual void serviceDied(uint64_t cookie, const wp<IBase>& who); // Used both for (un)registering handlers, and for passing to // '(un)linkToDeath'. static sp<HalDeathHandler> getInstance(); private: friend class Singleton<HalDeathHandler>; typedef std::unordered_map<void*, AtExitHandler> Handlers; HalDeathHandler(); virtual ~HalDeathHandler(); sp<HalDeathHandler> mSelf; // Allows the singleton instance to live forever. std::mutex mHandlersLock; Handlers mHandlers; }; } // namespace android #endif // ANDROID_HARDWARE_HIDL_HAL_DEATH_HANDLER_H
media/libaudiohal/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ else # if !USE_LEGACY_LOCAL_AUDIO_HAL LOCAL_SRC_FILES := \ ConversionHelperHidl.cpp \ HalDeathHandlerHidl.cpp \ DeviceHalHidl.cpp \ DevicesFactoryHalHidl.cpp \ EffectBufferHalHidl.cpp \ Loading
media/libaudiohal/ConversionHelperHidl.h +2 −2 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ class ConversionHelperHidl { if (!ret.isOk()) { emitError(funcName, ret.description().c_str()); } return ret.isOk() ? OK : UNKNOWN_ERROR; return ret.isOk() ? OK : FAILED_TRANSACTION; } status_t processReturn(const char* funcName, const Return<hardware::audio::V2_0::Result>& ret) { Loading @@ -62,7 +62,7 @@ class ConversionHelperHidl { template<typename T> status_t processReturn( const char* funcName, const Return<T>& ret, hardware::audio::V2_0::Result retval) { const status_t st = ret.isOk() ? analyzeResult(retval) : UNKNOWN_ERROR; const status_t st = ret.isOk() ? analyzeResult(retval) : FAILED_TRANSACTION; if (!ret.isOk()) { emitError(funcName, ret.description().c_str()); } Loading
media/libaudiohal/DevicesFactoryHalHidl.cpp +7 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ //#define LOG_NDEBUG 0 #include <android/hardware/audio/2.0/IDevice.h> #include <media/audiohal/hidl/HalDeathHandler.h> #include <utils/Log.h> #include "ConversionHelperHidl.h" Loading @@ -40,6 +41,11 @@ sp<DevicesFactoryHalInterface> DevicesFactoryHalInterface::create() { DevicesFactoryHalHidl::DevicesFactoryHalHidl() { mDevicesFactory = IDevicesFactory::getService("audio_devices_factory"); if (mDevicesFactory != 0) { // It is assumet that DevicesFactory is owned by AudioFlinger // and thus have the same lifespan. mDevicesFactory->linkToDeath(HalDeathHandler::getInstance(), 0 /*cookie*/); } } DevicesFactoryHalHidl::~DevicesFactoryHalHidl() { Loading Loading @@ -83,7 +89,7 @@ status_t DevicesFactoryHalHidl::openDevice(const char *name, sp<DeviceHalInterfa else if (retval == Result::INVALID_ARGUMENTS) return BAD_VALUE; else return NO_INIT; } return UNKNOWN_ERROR; return FAILED_TRANSACTION; } } // namespace android
media/libaudiohal/EffectHalHidl.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -160,7 +160,7 @@ status_t EffectHalHidl::setProcessBuffers() { mBuffersChanged = false; return OK; } return ret.isOk() ? analyzeResult(ret) : UNKNOWN_ERROR; return ret.isOk() ? analyzeResult(ret) : FAILED_TRANSACTION; } status_t EffectHalHidl::command(uint32_t cmdCode, uint32_t cmdSize, void *pCmdData, Loading @@ -183,7 +183,7 @@ status_t EffectHalHidl::command(uint32_t cmdCode, uint32_t cmdSize, void *pCmdDa } } }); return status; return ret.isOk() ? status : FAILED_TRANSACTION; } status_t EffectHalHidl::getDescriptor(effect_descriptor_t *pDescriptor) { Loading @@ -196,13 +196,13 @@ status_t EffectHalHidl::getDescriptor(effect_descriptor_t *pDescriptor) { effectDescriptorToHal(result, pDescriptor); } }); return ret.isOk() ? analyzeResult(retval) : UNKNOWN_ERROR; return ret.isOk() ? analyzeResult(retval) : FAILED_TRANSACTION; } status_t EffectHalHidl::close() { if (mEffect == 0) return NO_INIT; Return<Result> ret = mEffect->close(); return ret.isOk() ? analyzeResult(ret) : UNKNOWN_ERROR; return ret.isOk() ? analyzeResult(ret) : FAILED_TRANSACTION; } } // namespace android