Skip to content

Commit

Permalink
Merge ZP1A.240615.001
Browse files Browse the repository at this point in the history
Change-Id: I72790d375ac33c0f9d1f2904def547dddc35dd78
  • Loading branch information
Scott Lobdell committed Jun 25, 2024
2 parents 4c76c47 + 75c0376 commit 23cca9e
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 18 deletions.
9 changes: 9 additions & 0 deletions media/codec2/sfplugin/CCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2637,6 +2637,15 @@ void CCodec::signalSetParameters(const sp<AMessage> &msg) {
if (config->mInputSurface == nullptr
&& (property_get_bool("debug.stagefright.ccodec_delayed_params", false)
|| comp->getName().find("c2.android.") == 0)) {
std::vector<std::unique_ptr<C2Param>> localConfigUpdate;
for (const std::unique_ptr<C2Param> &param : configUpdate) {
if (param && param->coreIndex().coreIndex() == C2StreamSurfaceScalingInfo::CORE_INDEX) {
localConfigUpdate.push_back(C2Param::Copy(*param));
}
}
if (!localConfigUpdate.empty()) {
(void)config->setParameters(comp, localConfigUpdate, C2_MAY_BLOCK);
}
mChannel->setParameters(configUpdate);
} else {
sp<AMessage> outputFormat = config->mOutputFormat;
Expand Down
16 changes: 14 additions & 2 deletions media/libaudiohal/impl/effectsAidlConversion/AidlConversionEq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <cstdint>
#include <cstring>
#include <optional>
#include <unordered_set>
#define LOG_TAG "AidlConversionEQ"
//#define LOG_NDEBUG 0

Expand Down Expand Up @@ -262,10 +263,21 @@ status_t AidlConversionEq::getParameter(EffectParamWriter& param) {
}
case EQ_PARAM_GET_NUM_OF_PRESETS: {
Parameter aidlParam = VALUE_OR_RETURN_STATUS(getAidlParameter(Equalizer::presets));
const auto& presets = VALUE_OR_RETURN_STATUS(GET_PARAMETER_SPECIFIC_FIELD(
auto presets = VALUE_OR_RETURN_STATUS(GET_PARAMETER_SPECIFIC_FIELD(
aidlParam, Equalizer, equalizer, Equalizer::presets,
std::vector<Equalizer::Preset>));
uint16_t num = presets.size();
// it was assumed the presets index in the range of [0, NUM_OF_PRESETS - 1], so
// filter out presets out of this range (one example is preset {-1, "custom"})
std::erase_if(presets, [](const auto& preset) { return preset.index < 0; });
// validate remaining indexes are unique [0, num - 1]
std::unordered_set<uint16_t> uniqueIndices;
const uint16_t num = presets.size();
for (const auto& preset : presets) {
if (preset.index >= num || 0 != uniqueIndices.count(preset.index)) {
return BAD_VALUE;
}
uniqueIndices.insert(preset.index);
}
return param.writeToValue(&num);
}
case EQ_PARAM_GET_PRESET_NAME: {
Expand Down
4 changes: 2 additions & 2 deletions media/module/foundation/tests/AData_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ TEST_F(ADataTest, AData_CopyMoveTest) {
EXPECT_EQ(2L, _shared.use_count()); // still both u and _shared contains the object

EXPECT_TRUE(u.clear());
EXPECT_TRUE(_shared.unique()); // now only _shared contains the object
EXPECT_EQ(1L, _shared.use_count()); // now only _shared contains the object

EXPECT_TRUE(u.set(_constShared));
EXPECT_EQ(2L, _constShared.use_count()); // even though it is const, we can add a use count
Expand Down Expand Up @@ -591,7 +591,7 @@ TEST_F(ADataTest, AData_RelaxedCopyMoveTest) {
EXPECT_EQ(2L, _shared.use_count()); // still both u and _shared contains the object

EXPECT_TRUE(u.clear());
EXPECT_TRUE(_shared.unique()); // now only _shared contains the object
EXPECT_EQ(1L, _shared.use_count()); // now only _shared contains the object

EXPECT_TRUE(u.set(_constShared));
EXPECT_EQ(2L, _constShared.use_count()); // even though it is const, we can add a use count
Expand Down
2 changes: 0 additions & 2 deletions media/utils/tests/static_string_view_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ TEST(StaticStringViewTests, CreateTicket) {
// const std::array<char,2> nonstatic = {'a', 'b'};
// static_assert(can_assign<nonstatic>::value == false);
static std::array<char, 2> nonconst = {'a', 'b'};
static const std::array<char, 2> nonconstexpr = {'a', 'b'};
static constexpr std::array<int, 2> nonchar = {1, 2};
static constexpr size_t nonarray = 2;

static_assert(CanCreate<nonconst>::value == false);
static_assert(CanCreate<nonarray>::value == false);
static_assert(CanCreate<nonchar>::value == false);
static_assert(CanCreate<nonconstexpr>::value == false);

static constexpr std::array<char, 2> scoped = {'a', 'b'};
constexpr StaticStringView Ticket1 = StaticStringView::create<global>();
Expand Down
4 changes: 4 additions & 0 deletions services/audioflinger/AudioFlinger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4570,6 +4570,10 @@ NO_THREAD_SAFETY_ANALYSIS
if ((pt->type() == IAfThreadBase::MIXER || pt->type() == IAfThreadBase::OFFLOAD) &&
((sessionType & IAfThreadBase::EFFECT_SESSION) != 0)) {
srcThread = pt.get();
if (srcThread == dstThread) {
ALOGD("%s() same dst and src threads, ignoring move", __func__);
return NO_ERROR;
}
ALOGW("%s() found srcOutput %d hosting AUDIO_SESSION_OUTPUT_MIX", __func__,
pt->id());
break;
Expand Down
1 change: 1 addition & 0 deletions services/audiopolicy/enginedefault/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ cc_library_shared {
"libaudiopolicyengine_config",
],
shared_libs: [
"com.android.media.audioserver-aconfig-cc",
"libaudio_aidl_conversion_common_cpp",
"libaudiofoundation",
"libaudiopolicy",
Expand Down
67 changes: 58 additions & 9 deletions services/audiopolicy/enginedefault/src/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <PolicyAudioPort.h>
#include <IOProfile.h>
#include <AudioIODescriptorInterface.h>
#include <com_android_media_audioserver.h>
#include <policy.h>
#include <media/AudioContainers.h>
#include <utils/String8.h>
Expand Down Expand Up @@ -155,12 +156,58 @@ status_t Engine::setForceUse(audio_policy_force_use_t usage, audio_policy_forced
return EngineBase::setForceUse(usage, config);
}

bool Engine::isBtScoActive(DeviceVector& availableOutputDevices,
const SwAudioOutputCollection &outputs) const {
if (availableOutputDevices.getDevicesFromTypes(getAudioDeviceOutAllScoSet()).isEmpty()) {
return false;
}
// SCO is active if:
// 1) we are in a call and SCO is the preferred device for PHONE strategy
if (isInCall() && audio_is_bluetooth_out_sco_device(
getPreferredDeviceTypeForLegacyStrategy(availableOutputDevices, STRATEGY_PHONE))) {
return true;
}

// 2) A strategy for which the preferred device is SCO is active
for (const auto &ps : getOrderedProductStrategies()) {
if (outputs.isStrategyActive(ps) &&
!getPreferredAvailableDevicesForProductStrategy(availableOutputDevices, ps)
.getDevicesFromTypes(getAudioDeviceOutAllScoSet()).isEmpty()) {
return true;
}
}
// 3) a ringtone is active and SCO is used for ringing
if (outputs.isActiveLocally(toVolumeSource(AUDIO_STREAM_RING))
&& (getForceUse(AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING)
== AUDIO_POLICY_FORCE_BT_SCO)) {
return true;
}
// 4) an active input is routed from SCO
DeviceVector availableInputDevices = getApmObserver()->getAvailableInputDevices();
const auto &inputs = getApmObserver()->getInputs();
if (inputs.activeInputsCountOnDevices(availableInputDevices.getDevicesFromType(
AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET)) > 0) {
return true;
}
return false;
}

void Engine::filterOutputDevicesForStrategy(legacy_strategy strategy,
DeviceVector& availableOutputDevices,
const SwAudioOutputCollection &outputs) const
{
DeviceVector availableInputDevices = getApmObserver()->getAvailableInputDevices();

if (com::android::media::audioserver::use_bt_sco_for_media()) {
// remove A2DP and LE Audio devices whenever BT SCO is in use
if (isBtScoActive(availableOutputDevices, outputs)) {
availableOutputDevices.remove(
availableOutputDevices.getDevicesFromTypes(getAudioDeviceOutAllA2dpSet()));
availableOutputDevices.remove(
availableOutputDevices.getDevicesFromTypes(getAudioDeviceOutAllBleSet()));
}
}

switch (strategy) {
case STRATEGY_SONIFICATION_RESPECTFUL: {
if (!(isInCall() || outputs.isActiveLocally(toVolumeSource(AUDIO_STREAM_VOICE_CALL)))) {
Expand Down Expand Up @@ -440,25 +487,27 @@ DeviceVector Engine::getDevicesForStrategyInt(legacy_strategy strategy,
getLastRemovableMediaDevices(GROUP_WIRED, excludedDevices));
}
}
if (devices2.isEmpty()) {
devices2 = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_USB_DEVICE);
}
if (devices2.isEmpty()) {
devices2 = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET);

if (com::android::media::audioserver::use_bt_sco_for_media()) {
if (devices2.isEmpty() && isBtScoActive(availableOutputDevices, outputs)) {
devices2 = availableOutputDevices.getFirstDevicesFromTypes(
{ AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT,
AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET,
AUDIO_DEVICE_OUT_BLUETOOTH_SCO});
}
}

if ((devices2.isEmpty()) &&
(getForceUse(AUDIO_POLICY_FORCE_FOR_DOCK) == AUDIO_POLICY_FORCE_ANALOG_DOCK)) {
devices2 = availableOutputDevices.getDevicesFromType(
AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET);
}
if ((devices2.isEmpty()) && (strategy != STRATEGY_SONIFICATION) && (devices.isEmpty())) {
// no sonification on WFD sink
devices2 = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_PROXY);
}

if (devices2.isEmpty()) {
devices2 = availableOutputDevices.getFirstDevicesFromTypes({
AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET, AUDIO_DEVICE_OUT_SPEAKER});
}

DeviceVector devices3;
if (strategy == STRATEGY_MEDIA) {
// ARC, SPDIF and AUX_LINE can co-exist with others.
Expand Down
3 changes: 3 additions & 0 deletions services/audiopolicy/enginedefault/src/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class Engine : public EngineBase
DeviceVector getDisabledDevicesForInputSource(
const DeviceVector& availableInputDevices, audio_source_t inputSource) const;

bool isBtScoActive(DeviceVector& availableOutputDevices,
const SwAudioOutputCollection &outputs) const;

std::map<product_strategy_t, legacy_strategy> mLegacyStrategyMap;
};
} // namespace audio_policy
Expand Down
7 changes: 4 additions & 3 deletions services/audiopolicy/managerdefault/AudioPolicyManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8514,9 +8514,10 @@ float AudioPolicyManager::computeVolume(IVolumeCurves &curves,
}
if (Volume::getDeviceForVolume(deviceTypes) != AUDIO_DEVICE_OUT_SPEAKER
&& !Intersection(deviceTypes, {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP,
AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES}).empty()) {
// on A2DP, also ensure notification volume is not too low compared to media when
// intended to be played
AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES,
AUDIO_DEVICE_OUT_BLE_HEADSET}).empty()) {
// on A2DP/BLE, also ensure notification volume is not too low compared to media
// when intended to be played.
if ((volumeDb > -96.0f) &&
(musicVolDb - SONIFICATION_A2DP_MAX_MEDIA_DIFF_DB > volumeDb)) {
ALOGV("%s increasing volume for volume source=%d device=%s from %f to %f",
Expand Down

0 comments on commit 23cca9e

Please sign in to comment.