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

Commit aafa0782 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "APM: Reject attempts to use DEEP_BUFFER in openDirectOutput" into main

parents ccba2cca 806170e2
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -16,10 +16,10 @@

#pragma once

#include <optional>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <DeviceDescriptor.h>
#include <HwModule.h>
@@ -141,6 +141,12 @@ public:

    void setDefault();

    void setUseDeepBufferForMediaOverrideForTests(bool useDeepBufferForMedia)
    {
        mUseDeepBufferForMediaOverride = useDeepBufferForMedia;
    }
    bool useDeepBufferForMedia() const;

private:
    friend class sp<AudioPolicyConfig>;

@@ -158,6 +164,7 @@ private:
    sp<DeviceDescriptor> mDefaultOutputDevice;
    bool mIsCallScreenModeSupported = false;
    SurroundFormats mSurroundFormats;
    std::optional<bool> mUseDeepBufferForMediaOverride;
};

} // namespace android
+6 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#define LOG_TAG "APM_Config"

#include <android-base/properties.h>
#include <AudioPolicyConfig.h>
#include <IOProfile.h>
#include <Serializer.h>
@@ -344,4 +345,9 @@ void AudioPolicyConfig::setDefaultSurroundFormats() {
        {AUDIO_FORMAT_AC4, {}}};
}

bool AudioPolicyConfig::useDeepBufferForMedia() const {
    if (mUseDeepBufferForMediaOverride.has_value()) return *mUseDeepBufferForMediaOverride;
    return property_get_bool("audio.deep_buffer.media", false /* default_value */);
}

} // namespace android
+9 −4
Original line number Diff line number Diff line
@@ -1194,8 +1194,7 @@ audio_io_handle_t AudioPolicyManager::getOutput(audio_stream_type_t stream)

    SortedVector<audio_io_handle_t> outputs = getOutputsForDevices(devices, mOutputs);
    audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE;
    if (stream == AUDIO_STREAM_MUSIC &&
        property_get_bool("audio.deep_buffer.media", false /* default_value */)) {
    if (stream == AUDIO_STREAM_MUSIC && mConfig->useDeepBufferForMedia()) {
        flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
    }
    const audio_io_handle_t output = selectOutput(outputs, flags);
@@ -1572,6 +1571,13 @@ status_t AudioPolicyManager::openDirectOutput(audio_stream_type_t stream,
        return NAME_NOT_FOUND;
    }

    // Reject flag combinations that do not make sense. Note that the requested flags might not
    // have the 'DIRECT' flag set, however once a direct-capable profile is found, it will
    // combine the requested flags with its own flags, yielding an unsupported combination.
    if ((flags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) != 0) {
        return NAME_NOT_FOUND;
    }

    // Do not allow offloading if one non offloadable effect is enabled or MasterMono is enabled.
    // This prevents creating an offloaded track and tearing it down immediately after start
    // when audioflinger detects there is an active non offloadable effect.
@@ -1720,8 +1726,7 @@ audio_io_handle_t AudioPolicyManager::getOutputForDevices(
    if (stream != AUDIO_STREAM_MUSIC) {
        *flags = (audio_output_flags_t)(*flags &~AUDIO_OUTPUT_FLAG_DEEP_BUFFER);
    } else if (/* stream == AUDIO_STREAM_MUSIC && */
            *flags == AUDIO_OUTPUT_FLAG_NONE &&
            property_get_bool("audio.deep_buffer.media", false /* default_value */)) {
            *flags == AUDIO_OUTPUT_FLAG_NONE && mConfig->useDeepBufferForMedia()) {
        // use DEEP_BUFFER as default output for music stream type
        *flags = (audio_output_flags_t)AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
    }
+29 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include <map>
#include <set>

#include <media/TypeConverter.h>
#include <system/audio.h>
#include <utils/Log.h>
#include <utils/String8.h>
@@ -37,11 +38,11 @@ public:

    status_t openOutput(audio_module_handle_t module,
                        audio_io_handle_t *output,
                        audio_config_t * /*halConfig*/,
                        audio_config_base_t * /*mixerConfig*/,
                        audio_config_t *halConfig,
                        audio_config_base_t *mixerConfig,
                        const sp<DeviceDescriptorBase>& /*device*/,
                        uint32_t * /*latencyMs*/,
                        audio_output_flags_t /*flags*/,
                        audio_output_flags_t flags,
                        audio_attributes_t /*attributes*/) override {
        if (module >= mNextModuleHandle) {
            ALOGE("%s: Module handle %d has not been allocated yet (next is %d)",
@@ -49,6 +50,13 @@ public:
            return BAD_VALUE;
        }
        *output = mNextIoHandle++;
        mOpenedOutputs[*output] = flags;
        ALOGD("%s: opened output %d: HAL(%s %s %d) Mixer(%s %s %d) %s", __func__, *output,
              audio_channel_out_mask_to_string(halConfig->channel_mask),
              audio_format_to_string(halConfig->format), halConfig->sample_rate,
              audio_channel_out_mask_to_string(mixerConfig->channel_mask),
              audio_format_to_string(mixerConfig->format), mixerConfig->sample_rate,
              android::toString(flags).c_str());
        return NO_ERROR;
    }

@@ -58,6 +66,16 @@ public:
        return id;
    }

    status_t closeOutput(audio_io_handle_t output) override {
        if (auto iter = mOpenedOutputs.find(output); iter != mOpenedOutputs.end()) {
            mOpenedOutputs.erase(iter);
            return NO_ERROR;
        } else {
            ALOGE("%s: Unknown output %d", __func__, output);
            return BAD_VALUE;
        }
    }

    status_t openInput(audio_module_handle_t module,
                       audio_io_handle_t *input,
                       audio_config_t * /*config*/,
@@ -276,6 +294,13 @@ public:
        return mOpenInputCallsCount;
    }

    std::optional<audio_output_flags_t> getOpenOutputFlags(audio_io_handle_t output) const {
        if (auto iter = mOpenedOutputs.find(output); iter != mOpenedOutputs.end()) {
            return iter->second;
        }
        return std::nullopt;
    }

private:
    audio_module_handle_t mNextModuleHandle = AUDIO_MODULE_HANDLE_NONE + 1;
    audio_io_handle_t mNextIoHandle = AUDIO_IO_HANDLE_NONE + 1;
@@ -292,6 +317,7 @@ private:
    std::set<audio_io_handle_t> mOpenedInputs;
    size_t mOpenInputCallsCount = 0;
    size_t mCloseInputCallsCount = 0;
    std::map<audio_io_handle_t, audio_output_flags_t> mOpenedOutputs;
};

} // namespace android
+288 −31

File changed.

Preview size limit exceeded, changes collapsed.

Loading