Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 182ee543 authored by Kevin Rocard's avatar Kevin Rocard Committed by android-build-merger
Browse files

Avoid querying the audio service twice

am: a8f13932

Change-Id: I978296c9f488802f7eef92fe5e3acbaddc5c42a7
parents d47413ce a8f13932
Loading
Loading
Loading
Loading
+6 −14
Original line number Original line Diff line number Diff line
@@ -14,26 +14,18 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


#include <android/hardware/audio/2.0/IDevicesFactory.h>
#include <android/hardware/audio/4.0/IDevicesFactory.h>
#include <android/hardware/audio/5.0/IDevicesFactory.h>

#include <libaudiohal/FactoryHalHidl.h>
#include <libaudiohal/FactoryHalHidl.h>


#include <media/audiohal/DevicesFactoryHalInterface.h>

namespace android {
namespace android {


// static
// static
sp<DevicesFactoryHalInterface> DevicesFactoryHalInterface::create() {
sp<DevicesFactoryHalInterface> DevicesFactoryHalInterface::create() {
    if (hardware::audio::V5_0::IDevicesFactory::getService() != nullptr) {
    return V5_0::createDevicesFactoryHal() ?:
        return V5_0::createDevicesFactoryHal();
           V4_0::createDevicesFactoryHal() ?:
    }
           V2_0::createDevicesFactoryHal() ?:
    if (hardware::audio::V4_0::IDevicesFactory::getService() != nullptr) {
           nullptr;
        return V4_0::createDevicesFactoryHal();
    }
    if (hardware::audio::V2_0::IDevicesFactory::getService() != nullptr) {
        return V2_0::createDevicesFactoryHal();
    }
    return nullptr;
}
}


} // namespace android
} // namespace android
+4 −10
Original line number Original line Diff line number Diff line
@@ -24,16 +24,10 @@ namespace android {


// static
// static
sp<EffectsFactoryHalInterface> EffectsFactoryHalInterface::create() {
sp<EffectsFactoryHalInterface> EffectsFactoryHalInterface::create() {
    if (hardware::audio::effect::V5_0::IEffectsFactory::getService() != nullptr) {
    return effect::V5_0::createEffectsFactoryHal() ?:
        return effect::V5_0::createEffectsFactoryHal();
           effect::V4_0::createEffectsFactoryHal() ?:
    }
           effect::V2_0::createEffectsFactoryHal() ?:
    if (hardware::audio::effect::V4_0::IEffectsFactory::getService() != nullptr) {
           nullptr;
        return effect::V4_0::createEffectsFactoryHal();
    }
    if (hardware::audio::effect::V2_0::IEffectsFactory::getService() != nullptr) {
        return effect::V2_0::createEffectsFactoryHal();
    }
    return nullptr;
}
}


// static
// static
+4 −7
Original line number Original line Diff line number Diff line
@@ -35,13 +35,10 @@ using ::android::hardware::Return;
namespace android {
namespace android {
namespace CPP_VERSION {
namespace CPP_VERSION {


DevicesFactoryHalHidl::DevicesFactoryHalHidl() {
DevicesFactoryHalHidl::DevicesFactoryHalHidl(sp<IDevicesFactory> devicesFactory) {
    sp<IDevicesFactory> defaultFactory{IDevicesFactory::getService()};
    ALOG_ASSERT(devicesFactory != nullptr, "Provided IDevicesFactory service is NULL");
    if (!defaultFactory) {

        ALOGE("Failed to obtain IDevicesFactory/default service, terminating process.");
    mDeviceFactories.push_back(devicesFactory);
        exit(1);
    }
    mDeviceFactories.push_back(defaultFactory);
    if (MAJOR_VERSION >= 4) {
    if (MAJOR_VERSION >= 4) {
        // The MSD factory is optional and only available starting at HAL 4.0
        // The MSD factory is optional and only available starting at HAL 4.0
        sp<IDevicesFactory> msdFactory{IDevicesFactory::getService(AUDIO_HAL_SERVICE_NAME_MSD)};
        sp<IDevicesFactory> msdFactory{IDevicesFactory::getService(AUDIO_HAL_SERVICE_NAME_MSD)};
+2 −6
Original line number Original line Diff line number Diff line
@@ -32,18 +32,14 @@ namespace CPP_VERSION {
class DevicesFactoryHalHidl : public DevicesFactoryHalInterface
class DevicesFactoryHalHidl : public DevicesFactoryHalInterface
{
{
  public:
  public:
    DevicesFactoryHalHidl(sp<IDevicesFactory> devicesFactory);

    // Opens a device with the specified name. To close the device, it is
    // Opens a device with the specified name. To close the device, it is
    // necessary to release references to the returned object.
    // necessary to release references to the returned object.
    virtual status_t openDevice(const char *name, sp<DeviceHalInterface> *device);
    virtual status_t openDevice(const char *name, sp<DeviceHalInterface> *device);

  private:
  private:
    friend class DevicesFactoryHalHybrid;

    std::vector<sp<IDevicesFactory>> mDeviceFactories;
    std::vector<sp<IDevicesFactory>> mDeviceFactories;


    // Can not be constructed directly by clients.
    DevicesFactoryHalHidl();

    virtual ~DevicesFactoryHalHidl() = default;
    virtual ~DevicesFactoryHalHidl() = default;
};
};


+2 −2
Original line number Original line Diff line number Diff line
@@ -24,9 +24,9 @@
namespace android {
namespace android {
namespace CPP_VERSION {
namespace CPP_VERSION {


DevicesFactoryHalHybrid::DevicesFactoryHalHybrid()
DevicesFactoryHalHybrid::DevicesFactoryHalHybrid(sp<IDevicesFactory> hidlFactory)
        : mLocalFactory(new DevicesFactoryHalLocal()),
        : mLocalFactory(new DevicesFactoryHalLocal()),
          mHidlFactory(new DevicesFactoryHalHidl()) {
          mHidlFactory(new DevicesFactoryHalHidl(hidlFactory)) {
}
}


status_t DevicesFactoryHalHybrid::openDevice(const char *name, sp<DeviceHalInterface> *device) {
status_t DevicesFactoryHalHybrid::openDevice(const char *name, sp<DeviceHalInterface> *device) {
Loading