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

Commit 96b30be9 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

Define audio HAL

Created after hardware/audio.h with the following changes:

 - names changed to satisfy HAL style guide;

 - defined getter / setter methods for properties, and interfaces
   for devices where needed;

 - stream out callback changed to be used over RPC;

 - 'dump' method is already defined by BBinder, so in HAL
   interfaces it is replaced by 'debugDump'.

Note that audio data is currently transferred using byte buffer,
which is not effective due to memory copy and HwBinder transaction
involved. The transfer method will be changed to FastMessageQueue.

Bug: 30222631
Test: make

Change-Id: Ibb3bd940a91820e81d1a2b53b38d63b9e3de148a
parent 12adb906
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
// This is an autogenerated file, do not edit.
subdirs = [
    "audio/2.0",
    "audio/common/2.0",
    "audio/effect/2.0",
    "benchmarks/msgq/1.0",
@@ -7,14 +8,14 @@ subdirs = [
    "graphics/allocator/2.0/default",
    "graphics/mapper/2.0",
    "graphics/mapper/2.0/default",
    "light/2.0",
    "memtrack/1.0",
    "memtrack/1.0/default",
    "light/2.0",
    "nfc/1.0",
    "nfc/1.0/default",
    "radio/1.0",
    "power/1.0",
    "power/1.0/default",
    "radio/1.0",
    "soundtrigger/2.0",
    "tests/bar/1.0",
    "tests/baz/1.0",
@@ -23,8 +24,8 @@ subdirs = [
    "tests/libhwbinder/1.0",
    "tests/msgq/1.0",
    "tests/pointer/1.0",
    "vibrator/1.0",
    "vehicle/2.0",
    "vibrator/1.0",
    "wifi/1.0",
    "wifi/supplicant/1.0",
]

audio/2.0/Android.bp

0 → 100644
+96 −0
Original line number Diff line number Diff line
// This file is autogenerated by hidl-gen. Do not edit manually.

genrule {
    name: "android.hardware.audio@2.0_genc++",
    tool: "hidl-gen",
    cmd: "$tool -o $genDir -Lc++ -randroid.hardware:hardware/interfaces android.hardware.audio@2.0",
    srcs: [
        "types.hal",
        "IDevice.hal",
        "IDevicesFactory.hal",
        "IPrimaryDevice.hal",
        "IStream.hal",
        "IStreamIn.hal",
        "IStreamOut.hal",
        "IStreamOutCallback.hal",
    ],
    out: [
        "android/hardware/audio/2.0/types.cpp",
        "android/hardware/audio/2.0/DeviceAll.cpp",
        "android/hardware/audio/2.0/DevicesFactoryAll.cpp",
        "android/hardware/audio/2.0/PrimaryDeviceAll.cpp",
        "android/hardware/audio/2.0/StreamAll.cpp",
        "android/hardware/audio/2.0/StreamInAll.cpp",
        "android/hardware/audio/2.0/StreamOutAll.cpp",
        "android/hardware/audio/2.0/StreamOutCallbackAll.cpp",
    ],
}

genrule {
    name: "android.hardware.audio@2.0_genc++_headers",
    tool: "hidl-gen",
    cmd: "$tool -o $genDir -Lc++ -randroid.hardware:hardware/interfaces android.hardware.audio@2.0",
    srcs: [
        "types.hal",
        "IDevice.hal",
        "IDevicesFactory.hal",
        "IPrimaryDevice.hal",
        "IStream.hal",
        "IStreamIn.hal",
        "IStreamOut.hal",
        "IStreamOutCallback.hal",
    ],
    out: [
        "android/hardware/audio/2.0/types.h",
        "android/hardware/audio/2.0/IDevice.h",
        "android/hardware/audio/2.0/IHwDevice.h",
        "android/hardware/audio/2.0/BnDevice.h",
        "android/hardware/audio/2.0/BpDevice.h",
        "android/hardware/audio/2.0/BsDevice.h",
        "android/hardware/audio/2.0/IDevicesFactory.h",
        "android/hardware/audio/2.0/IHwDevicesFactory.h",
        "android/hardware/audio/2.0/BnDevicesFactory.h",
        "android/hardware/audio/2.0/BpDevicesFactory.h",
        "android/hardware/audio/2.0/BsDevicesFactory.h",
        "android/hardware/audio/2.0/IPrimaryDevice.h",
        "android/hardware/audio/2.0/IHwPrimaryDevice.h",
        "android/hardware/audio/2.0/BnPrimaryDevice.h",
        "android/hardware/audio/2.0/BpPrimaryDevice.h",
        "android/hardware/audio/2.0/BsPrimaryDevice.h",
        "android/hardware/audio/2.0/IStream.h",
        "android/hardware/audio/2.0/IHwStream.h",
        "android/hardware/audio/2.0/BnStream.h",
        "android/hardware/audio/2.0/BpStream.h",
        "android/hardware/audio/2.0/BsStream.h",
        "android/hardware/audio/2.0/IStreamIn.h",
        "android/hardware/audio/2.0/IHwStreamIn.h",
        "android/hardware/audio/2.0/BnStreamIn.h",
        "android/hardware/audio/2.0/BpStreamIn.h",
        "android/hardware/audio/2.0/BsStreamIn.h",
        "android/hardware/audio/2.0/IStreamOut.h",
        "android/hardware/audio/2.0/IHwStreamOut.h",
        "android/hardware/audio/2.0/BnStreamOut.h",
        "android/hardware/audio/2.0/BpStreamOut.h",
        "android/hardware/audio/2.0/BsStreamOut.h",
        "android/hardware/audio/2.0/IStreamOutCallback.h",
        "android/hardware/audio/2.0/IHwStreamOutCallback.h",
        "android/hardware/audio/2.0/BnStreamOutCallback.h",
        "android/hardware/audio/2.0/BpStreamOutCallback.h",
        "android/hardware/audio/2.0/BsStreamOutCallback.h",
    ],
}

cc_library_shared {
    name: "android.hardware.audio@2.0",
    generated_sources: ["android.hardware.audio@2.0_genc++"],
    generated_headers: ["android.hardware.audio@2.0_genc++_headers"],
    export_generated_headers: ["android.hardware.audio@2.0_genc++_headers"],
    shared_libs: [
        "libhidl",
        "libhwbinder",
        "libutils",
        "libcutils",
        "android.hardware.audio.common@2.0",
        "android.hardware.audio.effect@2.0",
    ],
}

audio/2.0/IDevice.hal

0 → 100644
+226 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 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.
 */

package android.hardware.audio@2.0;

import android.hardware.audio.common@2.0;
import IStreamIn;
import IStreamOut;

interface IDevice {
    typedef android.hardware.audio@2.0::Result Result;

    /*
     * Returns whether the audio hardware interface has been initialized.
     *
     * @return retval OK on success, NOT_INITIALIZED on failure.
     */
    initCheck() generates (Result retval);

    /*
     * Sets the audio volume for all audio activities other than voice call. If
     * NOT_SUPPORTED is returned, the software mixer will emulate this
     * capability.
     *
     * @param volume 1.0f means unity, 0.0f is zero.
     * @return retval operation completion status.
     */
    setMasterVolume(float volume) generates (Result retval);

    /*
     * Get the current master volume value for the HAL, if the HAL supports
     * master volume control. For example, AudioFlinger will query this value
     * from the primary audio HAL when the service starts and use the value for
     * setting the initial master volume across all HALs. HALs which do not
     * support this method must return NOT_SUPPORTED in 'retval'.
     *
     * @return retval operation completion status.
     * @return volume 1.0f means unity, 0.0f is zero.
     */
    getMasterVolume() generates (Result retval, float volume);

    /*
     * Sets microphone muting state.
     *
     * @param mute whether microphone is muted.
     * @return retval operation completion status.
     */
    setMicMute(bool mute) generates (Result retval);

    /*
     * Gets whether microphone is muted.
     *
     * @return retval operation completion status.
     * @return mute whether microphone is muted.
     */
    getMicMute() generates (Result retval, bool mute);

    /*
     * Set the audio mute status for all audio activities. If the return value
     * is NOT_SUPPORTED, the software mixer will emulate this capability.
     *
     * @param mute whether audio is muted.
     * @return retval operation completion status.
     */
    setMasterMute(bool mute) generates (Result retval);

    /**
     * Get the current master mute status for the HAL, if the HAL supports
     * master mute control. AudioFlinger will query this value from the primary
     * audio HAL when the service starts and use the value for setting the
     * initial master mute across all HALs. HAL must indicate that the feature
     * is not supported by returning NOT_SUPPORTED status.
     *
     * @return retval operation completion status.
     * @return mute whether audio is muted.
     */
    getMasterMute() generates (Result retval, bool mute);

    /*
     * Returns audio input buffer size according to parameters passed or
     * INVALID_ARGUMENTS if one of the parameters is not supported.
     *
     * @param config audio configuration.
     * @return retval operation completion status.
     * @return bufferSize input buffer size in bytes.
     */
    getInputBufferSize(AudioConfig config)
            generates (Result retval, uint64_t bufferSize);

    /*
     * This method creates and opens the audio hardware output stream.
     *
     * @param ioHandle handle assigned by AudioFlinger.
     * @param device device type and (if needed) address.
     * @param config stream configuration.
     * @param flags additional flags.
     * @return retval operation completion status.
     * @return outStream created output stream.
     */
    openOutputStream(
            AudioIoHandle ioHandle,
            DeviceAddress device,
            AudioConfig config,
            AudioOutputFlag flags) generates (Result retval, IStreamOut outStream);

    /*
     * This method creates and opens the audio hardware input stream.
     *
     * @param ioHandle handle assigned by AudioFlinger.
     * @param device device type and (if needed) address.
     * @param config stream configuration.
     * @param flags additional flags.
     * @param source source specification.
     * @return retval operation completion status.
     * @return inStream created input stream.
     */
    openInputStream(
            AudioIoHandle ioHandle,
            DeviceAddress device,
            AudioConfig config,
            AudioInputFlag flags,
            AudioSource source) generates (Result retval, IStreamIn inStream);

    /*
     * Creates an audio patch between several source and sink ports.  The handle
     * is allocated by the HAL and must be unique for this audio HAL module.
     *
     * @param sources patch sources.
     * @param sinks patch sinks.
     * @return retval operation completion status.
     * @return patch created patch handle.
     */
    createAudioPatch(vec<AudioPortConfig> sources, vec<AudioPortConfig> sinks)
            generates (Result retval, AudioPatchHandle patch);

    /*
     * Release an audio patch.
     *
     * @param patch patch handle.
     * @return retval operation completion status.
     */
    releaseAudioPatch(AudioPatchHandle patch) generates (Result retval);

    /*
     * Returns the list of supported attributes for a given audio port.
     *
     * As input, 'port' contains the information (type, role, address etc...)
     * needed by the HAL to identify the port.
     *
     * As output, 'port' contains possible attributes (sampling rates, formats,
     * channel masks, gain controllers...) for this port.
     *
     * @param port port identifier.
     * @return retval operation completion status.
     * @return port port descriptor with all parameters filled up.
     */
    getAudioPort(AudioPort port)
            generates (Result retval, AudioPort port);

    /*
     * Set audio port configuration.
     *
     * @param config audio port configuration.
     * @return retval operation completion status.
     */
    setAudioPortConfig(AudioPortConfig config) generates (Result retval);

    /*
     * Gets the HW synchronization source of the device. Calling this method is
     * equivalent to getting AUDIO_PARAMETER_STREAM_HW_AV_SYNC on the legacy
     * HAL.
     *
     * @return retval operation completion status.
     * @return hwAvSync HW synchronization source
     */
    getHwAvSync() generates (Result retval, AudioHwSync hwAvSync);

    /*
     * Sets whether the screen is on. Calling this method is equivalent to
     * setting AUDIO_PARAMETER_KEY_SCREEN_STATE on the legacy HAL.
     */
    setScreenState(bool turnedOn);

    /*
     * Generic method for retrieving vendor-specific parameter values.
     * The framework does not interpret the parameters, they are passed
     * in an opaque manner between a vendor application and HAL.
     *
     * @param keys parameter keys.
     * @return retval operation completion status.
     * @return parameters parameter key value pairs.
     */
    getParameters(vec<string> keys)
            generates (Result retval, vec<ParameterValue> parameters);

    /*
     * Generic method for setting vendor-specific parameter values.
     * The framework does not interpret the parameters, they are passed
     * in an opaque manner between a vendor application and HAL.
     *
     * @param parameters parameter key value pairs.
     * @return retval operation completion status.
     */
    setParameters(vec<ParameterValue> parameters) generates (Result retval);

    /*
     * Dumps information about the stream into the provided file descriptor.
     * This is used for the dumpsys facility.
     *
     * @param fd dump file descriptor.
     */
    debugDump(handle fd);
};
+44 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 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.
 */

package android.hardware.audio@2.0;

import android.hardware.audio.common@2.0;
import IDevice;

interface IDevicesFactory {
    typedef android.hardware.audio@2.0::Result Result;

    enum Device {
        PRIMARY,
        A2DP,
        USB,
        R_SUBMIX
    };

    /*
     * Opens an audio device. To close the device, it is necessary to release
     * references to the returned device object.
     *
     * @param device device type.
     * @return retval operation completion status. Returns INVALID_ARGUMENTS
     *         if there is no corresponding hardware module found,
     *         NOT_INITIALIZED if an error occured while opening the hardware
     *         module.
     * @return result the interface for the created device.
     */
    openDevice(Device device) generates (Result retval, IDevice result);
};
+123 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 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.
 */

package android.hardware.audio@2.0;

import android.hardware.audio.common@2.0;
import IDevice;

interface IPrimaryDevice extends IDevice {
    typedef android.hardware.audio@2.0::Result Result;

    /*
     * Sets the audio volume of a voice call.
     *
     * @param volume 1.0f means unity, 0.0f is zero.
     * @return retval operation completion status.
     */
    setVoiceVolume(float volume) generates (Result retval);

    /*
     * This method is used to notify the HAL about audio mode changes.
     *
     * @param mode new mode.
     * @return retval operation completion status.
     */
    setMode(AudioMode mode) generates (Result retval);

    /*
     * Gets whether BT SCO Noise Reduction and Echo Cancellation are enabled.
     * Calling this method is equivalent to getting AUDIO_PARAMETER_KEY_BT_NREC
     * on the legacy HAL.
     *
     * @return retval operation completion status.
     * @return enabled whether BT SCO NR + EC are enabled.
     */
    getBtScoNrecEnabled() generates (Result retval, bool enabled);

    /*
     * Sets whether BT SCO Noise Reduction and Echo Cancellation are enabled.
     * Calling this method is equivalent to setting AUDIO_PARAMETER_KEY_BT_NREC
     * on the legacy HAL.
     *
     * @param enabled whether BT SCO NR + EC are enabled.
     * @return retval operation completion status.
     */
    setBtScoNrecEnabled(bool enabled) generates (Result retval);

    /*
     * Gets whether BT SCO Wideband mode is enabled. Calling this method is
     * equivalent to getting AUDIO_PARAMETER_KEY_BT_SCO_WB on the legacy HAL.
     *
     * @return retval operation completion status.
     * @return enabled whether BT Wideband is enabled.
     */
    getBtScoWidebandEnabled() generates (Result retval, bool enabled);

    /*
     * Sets whether BT SCO Wideband mode is enabled. Calling this method is
     * equivalent to setting AUDIO_PARAMETER_KEY_BT_SCO_WB on the legacy HAL.
     *
     * @param enabled whether BT Wideband is enabled.
     * @return retval operation completion status.
     */
    setBtScoWidebandEnabled(bool enabled) generates (Result retval);

    enum TtyMode {
        OFF,
        VCO,
        HCO,
        FULL
    };

    /*
     * Gets current TTY mode selection. Calling this method is equivalent to
     * getting AUDIO_PARAMETER_KEY_TTY_MODE on the legacy HAL.
     *
     * @return retval operation completion status.
     * @return mode TTY mode.
     */
    getTtyMode() generates (Result retval, TtyMode mode);

    /*
     * Sets current TTY mode. Calling this method is equivalent to setting
     * AUDIO_PARAMETER_KEY_TTY_MODE on the legacy HAL.
     *
     * @param mode TTY mode.
     * @return retval operation completion status.
     */
    setTtyMode(TtyMode mode) generates (Result retval);

    /*
     * Gets whether Hearing Aid Compatibility - Telecoil (HAC-T) mode is
     * enabled. Calling this method is equivalent to getting
     * AUDIO_PARAMETER_KEY_HAC on the legacy HAL.
     *
     * @return retval operation completion status.
     * @return enabled whether HAC mode is enabled.
     */
    getHacEnabled() generates (Result retval, bool enabled);

    /*
     * Sets whether Hearing Aid Compatibility - Telecoil (HAC-T) mode is
     * enabled. Calling this method is equivalent to setting
     * AUDIO_PARAMETER_KEY_HAC on the legacy HAL.
     *
     * @param enabled whether HAC mode is enabled.
     * @return retval operation completion status.
     */
    setHacEnabled(bool enabled) generates (Result retval);
};
Loading