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

Commit cfc28661 authored by jiabin's avatar jiabin Committed by Automerger Merge Worker
Browse files

Add interfaces to query aaudio hardware information. am: b76981e2

parents 6ecb2d66 b76981e2
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -70,6 +70,10 @@ interface IModule {
  void removeDeviceEffect(int portConfigId, in android.hardware.audio.effect.IEffect effect);
  android.media.audio.common.AudioMMapPolicyInfo[] getMmapPolicyInfos(android.media.audio.common.AudioMMapPolicyType mmapPolicyType);
  boolean supportsVariableLatency();
  int getAAudioMixerBurstCount();
  int getAAudioHardwareBurstMinUsec();
  const int DEFAULT_AAUDIO_MIXER_BURST_COUNT = 2;
  const int DEFAULT_AAUDIO_HARDWARE_BURST_MIN_DURATION_US = 1000;
  @VintfStability
  parcelable OpenInputStreamArguments {
    int portConfigId;
+27 −0
Original line number Diff line number Diff line
@@ -833,4 +833,31 @@ interface IModule {
     * @return Whether the module supports variable latency control.
     */
    boolean supportsVariableLatency();

    /**
     * Default value for number of bursts per aaudio mixer cycle. This is a suggested value
     * to return for the HAL module, unless it is known that a better option exists.
     */
    const int DEFAULT_AAUDIO_MIXER_BURST_COUNT = 2;
    /**
     * Get the number of bursts per aaudio mixer cycle.
     *
     * @return The number of burst per aaudio mixer cycle.
     * @throw EX_UNSUPPORTED_OPERATION If the module does not support aaudio MMAP.
     */
    int getAAudioMixerBurstCount();

    /**
     * Default value for minimum duration in microseconds for a MMAP hardware burst. This
     * is a suggested value to return for the HAL module, unless it is known that a better
     * option exists.
     */
    const int DEFAULT_AAUDIO_HARDWARE_BURST_MIN_DURATION_US = 1000;
    /**
     * Get the minimum duration in microseconds for a MMAP hardware burst.
     *
     * @return The minimum number of microseconds for a MMAP hardware burst.
     * @throw EX_UNSUPPORTED_OPERATION If the module does not support aaudio MMAP.
     */
    int getAAudioHardwareBurstMinUsec();
}
+37 −0
Original line number Diff line number Diff line
@@ -1151,4 +1151,41 @@ ndk::ScopedAStatus Module::supportsVariableLatency(bool* _aidl_return) {
    return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus Module::getAAudioMixerBurstCount(int32_t* _aidl_return) {
    if (!isMmapSupported()) {
        LOG(DEBUG) << __func__ << ": mmap is not supported ";
        return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
    }
    *_aidl_return = DEFAULT_AAUDIO_MIXER_BURST_COUNT;
    LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
    return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus Module::getAAudioHardwareBurstMinUsec(int32_t* _aidl_return) {
    if (!isMmapSupported()) {
        LOG(DEBUG) << __func__ << ": mmap is not supported ";
        return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
    }
    *_aidl_return = DEFAULT_AAUDIO_HARDWARE_BURST_MIN_DURATION_US;
    LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
    return ndk::ScopedAStatus::ok();
}

bool Module::isMmapSupported() {
    if (mIsMmapSupported.has_value()) {
        return mIsMmapSupported.value();
    }
    std::vector<AudioMMapPolicyInfo> mmapPolicyInfos;
    if (!getMmapPolicyInfos(AudioMMapPolicyType::DEFAULT, &mmapPolicyInfos).isOk()) {
        mIsMmapSupported = false;
    } else {
        mIsMmapSupported =
                std::find_if(mmapPolicyInfos.begin(), mmapPolicyInfos.end(), [](const auto& info) {
                    return info.mmapPolicy == AudioMMapPolicy::AUTO ||
                           info.mmapPolicy == AudioMMapPolicy::ALWAYS;
                }) != mmapPolicyInfos.end();
    }
    return mIsMmapSupported.value();
}

}  // namespace aidl::android::hardware::audio::core
+4 −0
Original line number Diff line number Diff line
@@ -115,6 +115,8 @@ class Module : public BnModule {
            std::vector<::aidl::android::media::audio::common::AudioMMapPolicyInfo>* _aidl_return)
            override;
    ndk::ScopedAStatus supportsVariableLatency(bool* _aidl_return) override;
    ndk::ScopedAStatus getAAudioMixerBurstCount(int32_t* _aidl_return) override;
    ndk::ScopedAStatus getAAudioHardwareBurstMinUsec(int32_t* _aidl_return) override;

    void cleanUpPatch(int32_t patchId);
    ndk::ScopedAStatus createStreamContext(
@@ -132,6 +134,7 @@ class Module : public BnModule {
    std::set<int32_t> portIdsFromPortConfigIds(C portConfigIds);
    void registerPatch(const AudioPatch& patch);
    void updateStreamsConnectedState(const AudioPatch& oldPatch, const AudioPatch& newPatch);
    bool isMmapSupported();

    // This value is used for all AudioPatches.
    static constexpr int32_t kMinimumStreamBufferSizeFrames = 16;
@@ -159,6 +162,7 @@ class Module : public BnModule {
    bool mMicMute = false;
    std::shared_ptr<sounddose::ISoundDose> mSoundDose;
    ndk::SpAIBinder mSoundDoseBinder;
    std::optional<bool> mIsMmapSupported;
};

}  // namespace aidl::android::hardware::audio::core
+8 −0
Original line number Diff line number Diff line
@@ -438,3 +438,11 @@ std::vector<AudioPortConfig> ModuleConfig::generateAudioDevicePortConfigs(
    }
    return result;
}

bool ModuleConfig::isMmapSupported() const {
    const std::vector<AudioPort> mmapOutMixPorts =
            getMmapOutMixPorts(false /*attachedOnly*/, false /*singlePort*/);
    const std::vector<AudioPort> mmapInMixPorts =
            getMmapInMixPorts(false /*attachedOnly*/, false /*singlePort*/);
    return !mmapOutMixPorts.empty() || !mmapInMixPorts.empty();
}
Loading