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

Commit ce243a72 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "libaudiohal: Update stubs for the core HAL"

parents 470cdbdb 31d46652
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -70,6 +70,9 @@ public:
    }

    virtual status_t writeToParcelable(MicrophoneInfoData* parcelable) const {
#if defined(BACKEND_NDK)
        using ::aidl::android::convertReinterpret;
#endif
        parcelable->deviceId = mDeviceId;
        parcelable->portId = mPortId;
        parcelable->type = VALUE_OR_RETURN_STATUS(convertReinterpret<int32_t>(mType));
@@ -98,6 +101,9 @@ public:
    }

    virtual status_t readFromParcelable(const MicrophoneInfoData& parcelable) {
#if defined(BACKEND_NDK)
        using ::aidl::android::convertReinterpret;
#endif
        mDeviceId = parcelable.deviceId;
        mPortId = parcelable.portId;
        mType = VALUE_OR_RETURN_STATUS(convertReinterpret<uint32_t>(parcelable.type));
@@ -208,6 +214,10 @@ private:
    int32_t mDirectionality;
};

#if defined(BACKEND_NDK)
using ::aidl::ConversionResult;
#endif

// Conversion routines, according to AidlConversion.h conventions.
inline ConversionResult<MicrophoneInfo>
aidl2legacy_MicrophoneInfo(const media::MicrophoneInfoData& aidl) {
+3 −1
Original line number Diff line number Diff line
@@ -245,12 +245,14 @@ cc_library_shared {
        "latest_android_media_audio_common_types_ndk_shared",
    ],
    srcs: [
        "DeviceHalAidl.cpp",
        "DevicesFactoryHalEntry.cpp",
        "DevicesFactoryHalAidl.cpp",
        "EffectBufferHalAidl.cpp",
        "EffectHalAidl.cpp",
        "EffectsFactoryHalAidl.cpp",
        "EffectsFactoryHalEntry.cpp",
        "StreamHalAidl.cpp",
    ],
    static_libs: [
        "android.hardware.common-V2-ndk",
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.
 */

#pragma once

#include <string>
#include <string_view>

namespace android {

class ConversionHelperAidl {
  protected:
    ConversionHelperAidl(std::string_view className) : mClassName(className) {}

    const std::string& getClassName() const {
        return mClassName;
    }

    const std::string mClassName;
};

}  // namespace android
+130 −44
Original line number Diff line number Diff line
@@ -16,94 +16,149 @@

#define LOG_TAG "DeviceHalAidl"

#include <mediautils/TimeCheck.h>
#include <utils/Log.h>

#include <aidl/android/hardware/audio/core/StreamDescriptor.h>

#include "DeviceHalAidl.h"
#include "StreamHalAidl.h"

status_t DeviceHalAidl::getSupportedDevices(uint32_t* devices) {
    ALOGE("%s not implemented yet devices %p", __func__, devices);
    return OK;
using ::aidl::android::hardware::audio::core::StreamDescriptor;

namespace android {

status_t DeviceHalAidl::getSupportedDevices(uint32_t*) {
    // Obsolete.
    return INVALID_OPERATION;
}

status_t DeviceHalAidl::initCheck() {
    ALOGE("%s not implemented yet", __func__);
    if (mModule == nullptr) return NO_INIT;
    // HAL modules are already initialized by the time they are published to the SM.
    return OK;
}

status_t DeviceHalAidl::setVoiceVolume(float volume) {
    TIME_CHECK();
    mVoiceVolume = volume;
    ALOGE("%s not implemented yet %f", __func__, volume);
    return OK;
}

status_t DeviceHalAidl::setMasterVolume(float volume) {
    TIME_CHECK();
    mMasterVolume = volume;
    ALOGE("%s not implemented yet %f", __func__, volume);
    return OK;
}

status_t DeviceHalAidl::getMasterVolume(float *volume) {
    TIME_CHECK();
    *volume = mMasterVolume;
    ALOGE("%s not implemented yet %f", __func__, *volume);
    return OK;
}

status_t DeviceHalAidl::setMode(audio_mode_t mode) {
    ALOGE("%s not implemented yet %u", __func__, mode);
status_t DeviceHalAidl::setMode(audio_mode_t mode __unused) {
    TIME_CHECK();
    if (!mModule) return NO_INIT;
    ALOGE("%s not implemented yet", __func__);
    return OK;
}

status_t DeviceHalAidl::setMicMute(bool state) {
    TIME_CHECK();
    mMicMute = state;
    ALOGE("%s not implemented yet %d", __func__, state);
    return OK;
}

status_t DeviceHalAidl::getMicMute(bool *state) {
    TIME_CHECK();
    *state = mMicMute;
    ALOGE("%s not implemented yet %d", __func__, *state);
    return OK;
}

status_t DeviceHalAidl::setMasterMute(bool state) {
    TIME_CHECK();
    mMasterMute = state;
    ALOGE("%s not implemented yet %d", __func__, state);
    return OK;
}

status_t DeviceHalAidl::getMasterMute(bool *state) {
    TIME_CHECK();
    *state = mMasterMute;
    ALOGE("%s not implemented yet %d", __func__, *state);
    return OK;
}

status_t DeviceHalAidl::setParameters(const String8& kvPairs) {
    ALOGE("%s not implemented yet %s", __func__, kvPairs.c_str());
status_t DeviceHalAidl::setParameters(const String8& kvPairs __unused) {
    TIME_CHECK();
    if (!mModule) return NO_INIT;
    ALOGE("%s not implemented yet", __func__);
    return OK;
}

status_t DeviceHalAidl::getParameters(const String8& keys, String8 *values) {
    ALOGE("%s not implemented yet %s %s", __func__, keys.c_str(), values->c_str());
status_t DeviceHalAidl::getParameters(const String8& keys __unused, String8 *values) {
    TIME_CHECK();
    values->clear();
    if (!mModule) return NO_INIT;
    ALOGE("%s not implemented yet", __func__);
    return OK;
}

status_t DeviceHalAidl::getInputBufferSize(const struct audio_config* config, size_t* size) {
    ALOGE("%s not implemented yet %p %zu", __func__, config, *size);
status_t DeviceHalAidl::getInputBufferSize(
        const struct audio_config* config __unused, size_t* size __unused) {
    TIME_CHECK();
    if (!mModule) return NO_INIT;
    ALOGE("%s not implemented yet", __func__);
    return OK;
}

status_t DeviceHalAidl::openOutputStream(audio_io_handle_t handle, audio_devices_t devices,
                                         audio_output_flags_t flags, struct audio_config* config,
                                         const char* address,
status_t DeviceHalAidl::openOutputStream(
        audio_io_handle_t handle __unused, audio_devices_t devices __unused,
        audio_output_flags_t flags __unused, struct audio_config* config,
        const char* address __unused,
        sp<StreamOutHalInterface>* outStream) {
    ALOGE("%s not implemented yet %d %u %u %p %s %p", __func__, handle, devices, flags, config,
          address, outStream);
    if (!outStream || !config) {
        return BAD_VALUE;
    }
    TIME_CHECK();
    if (!mModule) return NO_INIT;
    config->sample_rate = 48000;
    config->format = AUDIO_FORMAT_PCM_24_BIT_PACKED;
    config->channel_mask = AUDIO_CHANNEL_OUT_STEREO;
    StreamDescriptor descriptor;
    descriptor.frameSizeBytes = audio_bytes_per_sample(config->format) *
            audio_channel_count_from_out_mask(config->channel_mask);
    descriptor.bufferSizeFrames = 600;
    *outStream = sp<StreamOutHalAidl>::make(descriptor, nullptr);
    return OK;
}

status_t DeviceHalAidl::openInputStream(audio_io_handle_t handle, audio_devices_t devices,
                                        struct audio_config* config, audio_input_flags_t flags,
                                        const char* address, audio_source_t source,
                                        audio_devices_t outputDevice,
                                        const char* outputDeviceAddress,
status_t DeviceHalAidl::openInputStream(
        audio_io_handle_t handle __unused, audio_devices_t devices __unused,
        struct audio_config* config, audio_input_flags_t flags __unused,
        const char* address __unused, audio_source_t source __unused,
        audio_devices_t outputDevice __unused,
        const char* outputDeviceAddress __unused,
        sp<StreamInHalInterface>* inStream) {
    ALOGE("%s not implemented yet %d %u %u %u %p %s %s %p %d", __func__, handle, devices,
          outputDevice, flags, config, address, outputDeviceAddress, inStream, source);
    if (!inStream || !config) {
        return BAD_VALUE;
    }
    TIME_CHECK();
    if (!mModule) return NO_INIT;
    config->sample_rate = 48000;
    config->format = AUDIO_FORMAT_PCM_24_BIT_PACKED;
    config->channel_mask = AUDIO_CHANNEL_IN_STEREO;
    StreamDescriptor descriptor;
    descriptor.frameSizeBytes = audio_bytes_per_sample(config->format) *
            audio_channel_count_from_out_mask(config->channel_mask);
    descriptor.bufferSizeFrames = 600;
    *inStream = sp<StreamInHalAidl>::make(descriptor, nullptr);
    return OK;
}

@@ -112,66 +167,94 @@ status_t DeviceHalAidl::supportsAudioPatches(bool* supportsPatches) {
    return OK;
}

status_t DeviceHalAidl::createAudioPatch(unsigned int num_sources,
                                         const struct audio_port_config* sources,
                                         unsigned int num_sinks,
                                         const struct audio_port_config* sinks,
                                         audio_patch_handle_t* patch) {
    ALOGE("%s not implemented yet %d %p %d %p %p", __func__, num_sources, sources, num_sinks,
            sinks, patch);
status_t DeviceHalAidl::createAudioPatch(unsigned int num_sources __unused,
                                         const struct audio_port_config* sources __unused,
                                         unsigned int num_sinks __unused,
                                         const struct audio_port_config* sinks __unused,
                                         audio_patch_handle_t* patch __unused) {
    TIME_CHECK();
    if (!mModule) return NO_INIT;
    ALOGE("%s not implemented yet", __func__);
    return OK;
}

status_t DeviceHalAidl::releaseAudioPatch(audio_patch_handle_t patch) {
    ALOGE("%s not implemented yet patch %d", __func__, patch);
status_t DeviceHalAidl::releaseAudioPatch(audio_patch_handle_t patch __unused) {
    TIME_CHECK();
    if (!mModule) return NO_INIT;
    ALOGE("%s not implemented yet", __func__);
    return OK;
}

status_t DeviceHalAidl::setAudioPortConfig(const struct audio_port_config* config) {
    ALOGE("%s not implemented yet config %p", __func__, config);
status_t DeviceHalAidl::getAudioPort(struct audio_port* port __unused) {
    TIME_CHECK();
    ALOGE("%s not implemented yet", __func__);
    return INVALID_OPERATION;
}

status_t DeviceHalAidl::getAudioPort(struct audio_port_v7 *port __unused) {
    TIME_CHECK();
    ALOGE("%s not implemented yet", __func__);
    return INVALID_OPERATION;
}

status_t DeviceHalAidl::setAudioPortConfig(const struct audio_port_config* config __unused) {
    TIME_CHECK();
    if (!mModule) return NO_INIT;
    ALOGE("%s not implemented yet", __func__);
    return OK;
}

status_t DeviceHalAidl::getMicrophones(
        std::vector<audio_microphone_characteristic_t>* microphones) {
    ALOGE("%s not implemented yet microphones %p", __func__, microphones);
        std::vector<audio_microphone_characteristic_t>* microphones __unused) {
    TIME_CHECK();
    if (!mModule) return NO_INIT;
    ALOGE("%s not implemented yet", __func__);
    return OK;
}

status_t DeviceHalAidl::addDeviceEffect(audio_port_handle_t device, sp<EffectHalInterface> effect) {
status_t DeviceHalAidl::addDeviceEffect(audio_port_handle_t device __unused,
        sp<EffectHalInterface> effect) {
    if (!effect) {
        return BAD_VALUE;
    }
    ALOGE("%s not implemented yet device %d", __func__, device);
    TIME_CHECK();
    if (!mModule) return NO_INIT;
    ALOGE("%s not implemented yet", __func__);
    return OK;
}
status_t DeviceHalAidl::removeDeviceEffect(audio_port_handle_t device,
status_t DeviceHalAidl::removeDeviceEffect(audio_port_handle_t device __unused,
                            sp<EffectHalInterface> effect) {
    if (!effect) {
        return BAD_VALUE;
    }
    ALOGE("%s not implemented yet device %d", __func__, device);
    TIME_CHECK();
    if (!mModule) return NO_INIT;
    ALOGE("%s not implemented yet", __func__);
    return OK;
}

status_t DeviceHalAidl::getMmapPolicyInfos(
        media::audio::common::AudioMMapPolicyType policyType __unused,
        std::vector<media::audio::common::AudioMMapPolicyInfo>* policyInfos __unused) {
    TIME_CHECK();
    ALOGE("%s not implemented yet", __func__);
    return OK;
}

int32_t DeviceHalAidl::getAAudioMixerBurstCount() {
    TIME_CHECK();
    ALOGE("%s not implemented yet", __func__);
    return OK;
}

int32_t DeviceHalAidl::getAAudioHardwareBurstMinUsec() {
    TIME_CHECK();
    ALOGE("%s not implemented yet", __func__);
    return OK;
}

error::Result<audio_hw_sync_t> DeviceHalAidl::getHwAvSync() {
    TIME_CHECK();
    ALOGE("%s not implemented yet", __func__);
    return base::unexpected(INVALID_OPERATION);
}
@@ -181,7 +264,10 @@ status_t DeviceHalAidl::dump(int __unused, const Vector<String16>& __unused) {
    return OK;
};

int32_t DeviceHalAidl::supportsBluetoothVariableLatency(bool* supports __unused) override {
int32_t DeviceHalAidl::supportsBluetoothVariableLatency(bool* supports __unused) {
    TIME_CHECK();
    ALOGE("%s not implemented yet", __func__);
    return INVALID_OPERATION;
}

} // namespace android
+16 −8
Original line number Diff line number Diff line
@@ -16,14 +16,15 @@

#pragma once

#include <aidl/android/hardware/audio/core/BpModule.h>
#include <media/audiohal/DeviceHalInterface.h>
#include <media/audiohal/EffectHalInterface.h>

#include <aidl/android/hardware/audio/core/BpModule.h>
#include "ConversionHelperAidl.h"

namespace android {

class DeviceHalAidl : public DeviceHalInterface {
class DeviceHalAidl : public DeviceHalInterface, public ConversionHelperAidl {
  public:
    // Sets the value of 'devices' to a bitmask of 1 or more values of audio_devices_t.
    status_t getSupportedDevices(uint32_t *devices) override;
@@ -86,6 +87,12 @@ class DeviceHalAidl : public DeviceHalInterface {
    // Releases an audio patch.
    status_t releaseAudioPatch(audio_patch_handle_t patch) override;

    // Fills the list of supported attributes for a given audio port.
    status_t getAudioPort(struct audio_port* port) override;

    // Fills the list of supported attributes for a given audio port.
    status_t getAudioPort(struct audio_port_v7 *port) override;

    // Set audio port configuration.
    status_t setAudioPortConfig(const struct audio_port_config* config) override;

@@ -111,8 +118,10 @@ class DeviceHalAidl : public DeviceHalInterface {
    int32_t supportsBluetoothVariableLatency(bool* supports __unused) override;

  private:
    friend class DevicesFactoryHalAidl;
    const std::shared_ptr<::aidl::android::hardware::audio::core::IModule> mCore;
    friend class sp<DeviceHalAidl>;

    const std::shared_ptr<::aidl::android::hardware::audio::core::IModule> mModule;
    // FIXME: Remove these after implementing calls into the HAL.
    float mMasterVolume = 0.0f;
    float mVoiceVolume = 0.0f;
    bool mMasterMute = false;
@@ -120,11 +129,10 @@ class DeviceHalAidl : public DeviceHalInterface {

    // Can not be constructed directly by clients.
    explicit DeviceHalAidl(
            const std::shared_ptr<::aidl::android::hardware::audio::core::IModule>& core)
        : mCore(core) {}
            const std::shared_ptr<::aidl::android::hardware::audio::core::IModule>& module)
            : ConversionHelperAidl("DeviceHalAidl"), mModule(module) {}

    // The destructor automatically closes the device.
    ~DeviceHalAidl();
    ~DeviceHalAidl() override = default;
};

} // namespace android
Loading