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

Commit 06e69ef1 authored by Mikhail Naganov's avatar Mikhail Naganov Committed by Automerger Merge Worker
Browse files

audio: Add example HAL implementation am: baf57fb1 am: 5b0e2ae0

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1507219

Change-Id: Iacce33d57ca6cd7d985dc90341a6c7dfdab74728
parents ffcbe24f 5b0e2ae0
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -18,6 +18,10 @@ based on an existing one.
   - `2.0` -- version 2.0 of the common types HIDL API.
   - `4.0` -- version 4.0.
   - ...
   - `7.0` -- version 7.0.
      - `example` -- example implementation of the core and effect
        V7.0 API. It represents a "fake" audio HAL that doesn't
        actually communicate with hardware.
   - `all-versions` -- code common to all version of both core and effect API.
      - `default` -- shared code of the default implementation.
         - `service` -- vendor HAL service for hosting the default
+45 −0
Original line number Diff line number Diff line
//
// Copyright (C) 2020 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.

cc_binary {
    name: "android.hardware.audio@7.0-service.example",
    vendor: true,
    relative_install_path: "hw",
    init_rc: ["android.hardware.audio@7.0-service.example.rc"],
    vintf_fragments: ["android.hardware.audio@7.0-service.example.xml"],
    srcs: [
        "DevicesFactory.cpp",
        "Effect.cpp",
        "EffectsFactory.cpp",
        "EqualizerEffect.cpp",
        "LoudnessEnhancerEffect.cpp",
        "service.cpp",
    ],
    cflags: [
        "-Wall",
        "-Werror",
    ],
    shared_libs: [
        "libcutils",
        "libhidlbase",
        "liblog",
        "libxml2",
        "libutils",
        "android.hardware.audio@7.0",
        "android.hardware.audio.common@7.0",
        "android.hardware.audio.common@7.0-enums",
        "android.hardware.audio.effect@7.0",
    ],
}
+39 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.
 */

#define LOG_TAG "DevicesFactory7.0"
#include <log/log.h>

#include "DevicesFactory.h"

using ::android::hardware::hidl_string;
using ::android::hardware::Return;
using ::android::hardware::Void;

namespace android::hardware::audio::V7_0::implementation {

Return<void> DevicesFactory::openDevice(const hidl_string& device, openDevice_cb _hidl_cb) {
    (void)device;
    _hidl_cb(Result::INVALID_ARGUMENTS, nullptr);
    return Void();
}

Return<void> DevicesFactory::openPrimaryDevice(openPrimaryDevice_cb _hidl_cb) {
    _hidl_cb(Result::INVALID_ARGUMENTS, nullptr);
    return Void();
}

}  // namespace android::hardware::audio::V7_0::implementation
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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 <android/hardware/audio/7.0/IDevicesFactory.h>

namespace android::hardware::audio::V7_0::implementation {

class DevicesFactory : public IDevicesFactory {
  public:
    DevicesFactory() = default;

    ::android::hardware::Return<void> openDevice(const ::android::hardware::hidl_string& device,
                                                 openDevice_cb _hidl_cb) override;

    ::android::hardware::Return<void> openPrimaryDevice(openPrimaryDevice_cb _hidl_cb) override;
};

}  // namespace android::hardware::audio::V7_0::implementation
+224 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.
 */

#define LOG_TAG "EffectsFactory7.0"
#include <log/log.h>

#include <audio_policy_configuration_V7_0.h>

#include "Effect.h"

using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using namespace ::android::hardware::audio::common::V7_0;
// Make an alias for enumerations generated from the APM config XSD.
namespace xsd {
using namespace ::audio::policy::configuration::V7_0;
}

namespace android::hardware::audio::effect::V7_0::implementation {

Return<Result> Effect::init() {
    return Result::OK;
}

Return<Result> Effect::setConfig(
        const EffectConfig& config,
        const ::android::sp<IEffectBufferProviderCallback>& inputBufferProvider,
        const ::android::sp<IEffectBufferProviderCallback>& outputBufferProvider) {
    (void)config;
    (void)inputBufferProvider;
    (void)outputBufferProvider;
    return Result::OK;
}

Return<Result> Effect::reset() {
    return Result::OK;
}

Return<Result> Effect::enable() {
    if (!mEnabled) {
        mEnabled = true;
        return Result::OK;
    } else {
        return Result::NOT_SUPPORTED;
    }
}

Return<Result> Effect::disable() {
    if (mEnabled) {
        mEnabled = false;
        return Result::OK;
    } else {
        return Result::NOT_SUPPORTED;
    }
}

Return<Result> Effect::setDevice(const DeviceAddress& device) {
    (void)device;
    return Result::OK;
}

Return<void> Effect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
                                     setAndGetVolume_cb _hidl_cb) {
    (void)volumes;
    _hidl_cb(Result::OK, hidl_vec<uint32_t>{});
    return Void();
}

Return<Result> Effect::volumeChangeNotification(const hidl_vec<uint32_t>& volumes) {
    (void)volumes;
    return Result::OK;
}

Return<Result> Effect::setAudioMode(AudioMode mode) {
    (void)mode;
    return Result::OK;
}

Return<Result> Effect::setConfigReverse(
        const EffectConfig& config,
        const ::android::sp<IEffectBufferProviderCallback>& inputBufferProvider,
        const ::android::sp<IEffectBufferProviderCallback>& outputBufferProvider) {
    (void)config;
    (void)inputBufferProvider;
    (void)outputBufferProvider;
    return Result::OK;
}

Return<Result> Effect::setInputDevice(const DeviceAddress& device) {
    (void)device;
    return Result::OK;
}

Return<void> Effect::getConfig(getConfig_cb _hidl_cb) {
    const EffectConfig config = {{} /* inputCfg */,
                                 // outputCfg
                                 {{} /* buffer */,
                                  48000 /* samplingRateHz */,
                                  toString(xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_STEREO),
                                  toString(xsd::AudioFormat::AUDIO_FORMAT_PCM_16_BIT),
                                  EffectBufferAccess::ACCESS_ACCUMULATE,
                                  0 /* mask */}};
    _hidl_cb(Result::OK, config);
    return Void();
}

Return<void> Effect::getConfigReverse(getConfigReverse_cb _hidl_cb) {
    _hidl_cb(Result::OK, EffectConfig{});
    return Void();
}

Return<void> Effect::getSupportedAuxChannelsConfigs(uint32_t maxConfigs,
                                                    getSupportedAuxChannelsConfigs_cb _hidl_cb) {
    (void)maxConfigs;
    _hidl_cb(Result::OK, hidl_vec<EffectAuxChannelsConfig>{});
    return Void();
}

Return<void> Effect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) {
    _hidl_cb(Result::OK, EffectAuxChannelsConfig{});
    return Void();
}

Return<Result> Effect::setAuxChannelsConfig(const EffectAuxChannelsConfig& config) {
    (void)config;
    return Result::OK;
}

Return<Result> Effect::setAudioSource(const hidl_string& source) {
    (void)source;
    return Result::OK;
}

Return<Result> Effect::offload(const EffectOffloadParameter& param) {
    (void)param;
    return Result::OK;
}

Return<void> Effect::getDescriptor(getDescriptor_cb _hidl_cb) {
    _hidl_cb(Result::OK, mDescriptor);
    return Void();
}

Return<void> Effect::prepareForProcessing(prepareForProcessing_cb _hidl_cb) {
    _hidl_cb(Result::OK, MQDescriptor<Result, kSynchronizedReadWrite>{});
    return Void();
}

Return<Result> Effect::setProcessBuffers(const AudioBuffer& inBuffer,
                                         const AudioBuffer& outBuffer) {
    (void)inBuffer;
    (void)outBuffer;
    return Result::OK;
}

Return<void> Effect::command(uint32_t commandId, const hidl_vec<uint8_t>& data,
                             uint32_t resultMaxSize, command_cb _hidl_cb) {
    (void)commandId;
    (void)data;
    (void)resultMaxSize;
    _hidl_cb(-EINVAL, hidl_vec<uint8_t>{});
    return Void();
}

Return<Result> Effect::setParameter(const hidl_vec<uint8_t>& parameter,
                                    const hidl_vec<uint8_t>& value) {
    (void)parameter;
    (void)value;
    return Result::OK;
}

Return<void> Effect::getParameter(const hidl_vec<uint8_t>& parameter, uint32_t valueMaxSize,
                                  getParameter_cb _hidl_cb) {
    (void)parameter;
    (void)valueMaxSize;
    _hidl_cb(Result::OK, hidl_vec<uint8_t>{});
    return Void();
}

Return<void> Effect::getSupportedConfigsForFeature(uint32_t featureId, uint32_t maxConfigs,
                                                   uint32_t configSize,
                                                   getSupportedConfigsForFeature_cb _hidl_cb) {
    (void)featureId;
    (void)maxConfigs;
    (void)configSize;
    _hidl_cb(Result::OK, 0, hidl_vec<uint8_t>{});
    return Void();
}

Return<void> Effect::getCurrentConfigForFeature(uint32_t featureId, uint32_t configSize,
                                                getCurrentConfigForFeature_cb _hidl_cb) {
    (void)featureId;
    (void)configSize;
    _hidl_cb(Result::OK, hidl_vec<uint8_t>{});
    return Void();
}

Return<Result> Effect::setCurrentConfigForFeature(uint32_t featureId,
                                                  const hidl_vec<uint8_t>& configData) {
    (void)featureId;
    (void)configData;
    return Result::OK;
}

Return<Result> Effect::close() {
    return Result::OK;
}

}  // namespace android::hardware::audio::effect::V7_0::implementation
Loading