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

Commit a9ac889b authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

audio: Create libraries for data types in core and effect

Add 'CoreUtils' library similar to 'HidlUtils' for the types
specific to the core HAL. Add 'EffectUtils' library similar to
'HidlUtils' for the types specific to the effects HAL.  Move into
them and de-duplicate code previously scattered across the
default HAL implementation and libaudiohal. Add unit tests.

Removed 'AUDIO_{INPUT|OUTPUT}_FLAG_NONE' from the list of
values in the XSD file to avoid additional complexity due to
equivalence of this value to an empty list of flags.

Bug: 142480271
Test: m android.hardware.audio@X.0-impl
Test: m android.hardware.audio.effect@X.0-impl
Test: atest android.hardware.audio@7.0-util_tests
Test: atest android.hardware.audio.common@7.0-util_tests
Test: atest android.hardware.audio.effect@7.0-util_tests
Change-Id: I71a95cbe07fcc162dc6d74ff9665747a17ce5a80
Merged-In: I71a95cbe07fcc162dc6d74ff9665747a17ce5a80
parent 39059ed1
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -251,7 +251,6 @@ package android.audio.policy.configuration.V7_0 {
    enum_constant public static final android.audio.policy.configuration.V7_0.AudioInOutFlag AUDIO_INPUT_FLAG_HW_AV_SYNC;
    enum_constant public static final android.audio.policy.configuration.V7_0.AudioInOutFlag AUDIO_INPUT_FLAG_HW_HOTWORD;
    enum_constant public static final android.audio.policy.configuration.V7_0.AudioInOutFlag AUDIO_INPUT_FLAG_MMAP_NOIRQ;
    enum_constant public static final android.audio.policy.configuration.V7_0.AudioInOutFlag AUDIO_INPUT_FLAG_NONE;
    enum_constant public static final android.audio.policy.configuration.V7_0.AudioInOutFlag AUDIO_INPUT_FLAG_RAW;
    enum_constant public static final android.audio.policy.configuration.V7_0.AudioInOutFlag AUDIO_INPUT_FLAG_SYNC;
    enum_constant public static final android.audio.policy.configuration.V7_0.AudioInOutFlag AUDIO_INPUT_FLAG_VOIP_TX;
@@ -264,7 +263,6 @@ package android.audio.policy.configuration.V7_0 {
    enum_constant public static final android.audio.policy.configuration.V7_0.AudioInOutFlag AUDIO_OUTPUT_FLAG_IEC958_NONAUDIO;
    enum_constant public static final android.audio.policy.configuration.V7_0.AudioInOutFlag AUDIO_OUTPUT_FLAG_INCALL_MUSIC;
    enum_constant public static final android.audio.policy.configuration.V7_0.AudioInOutFlag AUDIO_OUTPUT_FLAG_MMAP_NOIRQ;
    enum_constant public static final android.audio.policy.configuration.V7_0.AudioInOutFlag AUDIO_OUTPUT_FLAG_NONE;
    enum_constant public static final android.audio.policy.configuration.V7_0.AudioInOutFlag AUDIO_OUTPUT_FLAG_NON_BLOCKING;
    enum_constant public static final android.audio.policy.configuration.V7_0.AudioInOutFlag AUDIO_OUTPUT_FLAG_PRIMARY;
    enum_constant public static final android.audio.policy.configuration.V7_0.AudioInOutFlag AUDIO_OUTPUT_FLAG_RAW;
+0 −5
Original line number Diff line number Diff line
@@ -159,13 +159,9 @@
        <xs:annotation>
            <xs:documentation xml:lang="en">
              The flags indicate suggested stream attributes supported by the profile.
              Use of AUDIO_{INPUT|OUTPUT}_FLAG_NONE in the XML file isn't required
              as empty flag lists are allowed. However these constants are useful for
              representing an empty enum value.
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:enumeration value="AUDIO_OUTPUT_FLAG_NONE" />
            <xs:enumeration value="AUDIO_OUTPUT_FLAG_DIRECT" />
            <xs:enumeration value="AUDIO_OUTPUT_FLAG_PRIMARY" />
            <xs:enumeration value="AUDIO_OUTPUT_FLAG_FAST" />
@@ -181,7 +177,6 @@
            <xs:enumeration value="AUDIO_OUTPUT_FLAG_MMAP_NOIRQ" />
            <xs:enumeration value="AUDIO_OUTPUT_FLAG_VOIP_RX" />
            <xs:enumeration value="AUDIO_OUTPUT_FLAG_INCALL_MUSIC" />
            <xs:enumeration value="AUDIO_INPUT_FLAG_NONE" />
            <xs:enumeration value="AUDIO_INPUT_FLAG_FAST" />
            <xs:enumeration value="AUDIO_INPUT_FLAG_HW_HOTWORD" />
            <xs:enumeration value="AUDIO_INPUT_FLAG_RAW" />
+28 −26
Original line number Diff line number Diff line
@@ -7,47 +7,49 @@ based on an existing one.

## Directory Structure

* `2.0` -- version 2.0 of the core HIDL API. Note that `.hal` files
* `2.0`  version 2.0 of the core HIDL API. Note that `.hal` files
  can not be moved into the `core` directory because that would change
  its namespace and include path.
   - `config` -- the XSD schema for the Audio Policy Manager
   - `config`  the XSD schema for the Audio Policy Manager
     configuration file.
* `4.0` -- version 4.0 of the core HIDL API.
* `4.0`  version 4.0 of the core HIDL API.
* ...
* `common` -- common types for audio core and effect HIDL API.
   - `2.0` -- version 2.0 of the common types HIDL API.
   - `4.0` -- version 4.0.
* `common`  common types for audio core and effect HIDL API.
   - `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
   - `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
   - `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
           implementation.
      - `test` -- utilities used by tests.
      - `util` -- utilities used by both implementation and tests.
* `core` -- VTS tests and the default implementation of the core API
      - `test`  utilities used by tests.
      - `util`  utilities used by both implementation and tests.
* `core`  VTS tests and the default implementation of the core API
  (not HIDL API, it's in `audio/N.M`).
   - `7.0` -- code specific to version V7.0 of the core HIDL API
   - `all-versions` -- the code is common between all versions,
   - `7.0`  code specific to version V7.0 of the core HIDL API
   - `all-versions`  the code is common between all versions,
     version-specific parts are enclosed into conditional directives
     of preprocessor or reside in dedicated files.
       - `default` -- code that wraps the legacy API (from
       - `default`  code that wraps the legacy API (from
         `hardware/libhardware`).
         - `util` — utilities for the default implementation.
       - `vts` VTS tests for the core HIDL API.
* `effect` -- same for the effect HIDL API.
* `effect`  same for the effect HIDL API.
   - `2.0`
      - `config` -- the XSD schema for the Audio Effects configuration
        file.
      - `config` — the XSD schema for the Audio Effects configuration file.
   - `4.0`
   - ...
   - `all-versions`
      - `default`
      - `vts`
* `policy` -- Configurable Audio Policy schemes.
   - `1.0` -- note that versions of CAP are not linked to the versions
       - `default` — code that wraps the legacy API (from
         `hardware/libhardware`).
         - `util` — utilities for the default implementation.
       - `vts` VTS tests for the effect HIDL API.
* `policy` — Configurable Audio Policy schemes.
   - `1.0` — note that versions of CAP are not linked to the versions
     of audio HAL.
      - `vts` -- VTS tests for validating actual configuration files.
      - `xml` -- XSD schemas for CAP configuration files.
      - `vts`  VTS tests for validating actual configuration files.
      - `xml`  XSD schemas for CAP configuration files.
+7 −1
Original line number Diff line number Diff line
@@ -212,10 +212,16 @@ static inline bool isOutputDevice(const std::string& device) {
    return isOutputDevice(stringToAudioDevice(device));
}

static inline bool maybeVendorExtension(const std::string& s) {
    // Only checks whether the string starts with the "vendor prefix".
    static const std::string vendorPrefix = "VX_";
    return s.size() > vendorPrefix.size() && s.substr(0, vendorPrefix.size()) == vendorPrefix;
}

static inline bool isVendorExtension(const std::string& s) {
    // Must match the "vendorExtension" rule from the XSD file.
    static const std::string vendorPrefix = "VX_";
    return s.size() > vendorPrefix.size() && s.substr(0, vendorPrefix.size()) == vendorPrefix &&
    return maybeVendorExtension(s) &&
           std::all_of(s.begin() + vendorPrefix.size(), s.end(),
                       [](unsigned char c) { return c == '_' || std::isalnum(c); });
}
+6 −6
Original line number Diff line number Diff line
@@ -309,15 +309,15 @@ typedef string AudioTag;
struct PlaybackTrackMetadata {
    AudioUsage usage;
    AudioContentType contentType;
    /** Tags from AudioTrack audio atttributes */
    vec<AudioTag> tags;
    AudioChannelMask channelMask;
    /**
     * Positive linear gain applied to the track samples. 0 being muted and 1 is no attenuation,
     * 2 means double amplification...
     * Must not be negative.
     */
    float gain;
    AudioChannelMask channelMask;
    /** Tags from AudioTrack audio atttributes */
    vec<AudioTag> tags;
};

/** Metadatas of the source of a StreamOut. */
@@ -328,9 +328,6 @@ struct SourceMetadata {
/** Metadata of a record track for a StreamIn. */
struct RecordTrackMetadata {
    AudioSource source;
    /** Tags from AudioTrack audio atttributes */
    vec<AudioTag> tags;
    AudioChannelMask channelMask;
    /**
     * Positive linear gain applied to the track samples. 0 being muted and 1 is no attenuation,
     * 2 means double amplification...
@@ -344,6 +341,9 @@ struct RecordTrackMetadata {
        Monostate unspecified;
        DeviceAddress device;
    } destination;
    AudioChannelMask channelMask;
    /** Tags from AudioTrack audio atttributes */
    vec<AudioTag> tags;
};

/** Metadatas of the sink of a StreamIn. */
Loading