Merge changes from topic "upstream-hal-v7_1-p2"

* changes:
  audio: add new enums for 7.1 HAL
  Audio HAL V7.1: Add latency mode APIs
This commit is contained in:
Treehugger Robot
2022-02-08 19:35:58 +00:00
committed by Gerrit Code Review
9 changed files with 197 additions and 0 deletions

View File

@@ -13,11 +13,13 @@ hidl_interface {
name: "android.hardware.audio@7.1",
root: "android.hardware",
srcs: [
"types.hal",
"IDevice.hal",
"IDevicesFactory.hal",
"IPrimaryDevice.hal",
"IStreamIn.hal",
"IStreamOut.hal",
"IStreamOutLatencyModeCallback.hal",
],
interfaces: [
"android.hardware.audio@7.0",

View File

@@ -16,7 +16,54 @@
package android.hardware.audio@7.1;
import @7.0::Result;
import @7.0::IStreamOut;
import IStreamOutLatencyModeCallback;
interface IStreamOut extends @7.0::IStreamOut {
/**
* Indicates the requested latency mode for this output stream.
*
* The requested mode can be one of the modes returned by
* getRecommendedLatencyModes() API.
*
* Optional method.
* Mandated only on specific spatial audio streams indicated by
* AUDIO_OUTPUT_FLAG_SPATIALIZER flag if they can be routed to a BT classic sink.
*
* @return retval operation completion status.
*/
setLatencyMode(LatencyMode mode) generates (Result retval);
/**
* Indicates which latency modes are currently supported on this output stream.
* If the transport protocol (e.g Bluetooth A2DP) used by this output stream to reach
* the output device supports variable latency modes, the HAL indicates which
* modes are currently supported.
* The framework can then call setLatencyMode() with one of the supported modes to select
* the desired operation mode.
*
* Optional method.
* Mandated only on specific spatial audio streams indicated by
* AUDIO_OUTPUT_FLAG_SPATIALIZER flag if they can be routed to a BT classic sink.
*
* @return retval operation completion status.
* @return modes currrently supported latency modes.
*/
getRecommendedLatencyModes() generates (Result retval, vec<LatencyMode> modes);
/**
* Set the callback interface for notifying changes in supported latency modes.
*
* Calling this method with a null pointer will result in releasing
* the callback.
*
* Optional method.
* Mandated only on specific spatial audio streams indicated by
* AUDIO_OUTPUT_FLAG_SPATIALIZER flag if they can be routed to a BT classic sink.
*
* @return retval operation completion status.
*/
setLatencyModeCallback(IStreamOutLatencyModeCallback callback) generates (Result retval);
};

View File

@@ -0,0 +1,28 @@
/*
* Copyright (C) 2022 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@7.1;
/**
* Callback interface for output stream variable latency mode feature.
*/
interface IStreamOutLatencyModeCallback {
/**
* Called with the new list of supported latency modes when a change occurs.
*/
oneway onRecommendedLatencyModeChanged(vec<LatencyMode> modes);
};

View File

@@ -62,6 +62,8 @@ package android.audio.policy.configuration.V7_1 {
enum_constant public static final android.audio.policy.configuration.V7_1.AudioChannelMask AUDIO_CHANNEL_OUT_7POINT1;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioChannelMask AUDIO_CHANNEL_OUT_7POINT1POINT2;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioChannelMask AUDIO_CHANNEL_OUT_7POINT1POINT4;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioChannelMask AUDIO_CHANNEL_OUT_9POINT1POINT4;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioChannelMask AUDIO_CHANNEL_OUT_9POINT1POINT6;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioChannelMask AUDIO_CHANNEL_OUT_HAPTIC_AB;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioChannelMask AUDIO_CHANNEL_OUT_MONO;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioChannelMask AUDIO_CHANNEL_OUT_MONO_HAPTIC_A;
@@ -125,6 +127,7 @@ package android.audio.policy.configuration.V7_1 {
enum_constant public static final android.audio.policy.configuration.V7_1.AudioDevice AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioDevice AUDIO_DEVICE_OUT_AUX_DIGITAL;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioDevice AUDIO_DEVICE_OUT_AUX_LINE;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioDevice AUDIO_DEVICE_OUT_BLE_BROADCAST;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioDevice AUDIO_DEVICE_OUT_BLE_HEADSET;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioDevice AUDIO_DEVICE_OUT_BLE_SPEAKER;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioDevice AUDIO_DEVICE_OUT_BLUETOOTH_A2DP;
@@ -284,6 +287,7 @@ package android.audio.policy.configuration.V7_1 {
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_OUTPUT_FLAG_NON_BLOCKING;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_OUTPUT_FLAG_PRIMARY;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_OUTPUT_FLAG_RAW;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_OUTPUT_FLAG_SPATIALIZER;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_OUTPUT_FLAG_SYNC;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_OUTPUT_FLAG_TTS;
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_OUTPUT_FLAG_VOIP_RX;

View File

@@ -179,6 +179,7 @@
<xs:enumeration value="AUDIO_OUTPUT_FLAG_VOIP_RX" />
<xs:enumeration value="AUDIO_OUTPUT_FLAG_INCALL_MUSIC" />
<xs:enumeration value="AUDIO_OUTPUT_FLAG_GAPLESS_OFFLOAD" />
<xs:enumeration value="AUDIO_OUTPUT_FLAG_SPATIALIZER" />
<xs:enumeration value="AUDIO_INPUT_FLAG_FAST" />
<xs:enumeration value="AUDIO_INPUT_FLAG_HW_HOTWORD" />
<xs:enumeration value="AUDIO_INPUT_FLAG_RAW" />
@@ -276,6 +277,7 @@
<xs:enumeration value="AUDIO_DEVICE_OUT_ECHO_CANCELLER"/>
<xs:enumeration value="AUDIO_DEVICE_OUT_BLE_HEADSET"/>
<xs:enumeration value="AUDIO_DEVICE_OUT_BLE_SPEAKER"/>
<xs:enumeration value="AUDIO_DEVICE_OUT_BLE_BROADCAST"/>
<xs:enumeration value="AUDIO_DEVICE_OUT_DEFAULT"/>
<xs:enumeration value="AUDIO_DEVICE_OUT_STUB"/>
@@ -510,6 +512,8 @@
<xs:enumeration value="AUDIO_CHANNEL_OUT_7POINT1"/>
<xs:enumeration value="AUDIO_CHANNEL_OUT_7POINT1POINT2"/>
<xs:enumeration value="AUDIO_CHANNEL_OUT_7POINT1POINT4"/>
<xs:enumeration value="AUDIO_CHANNEL_OUT_9POINT1POINT4"/>
<xs:enumeration value="AUDIO_CHANNEL_OUT_9POINT1POINT6"/>
<xs:enumeration value="AUDIO_CHANNEL_OUT_13POINT_360RA"/>
<xs:enumeration value="AUDIO_CHANNEL_OUT_22POINT2"/>
<xs:enumeration value="AUDIO_CHANNEL_OUT_MONO_HAPTIC_A"/>

30
audio/7.1/types.hal Normal file
View File

@@ -0,0 +1,30 @@
/*
* Copyright (C) 2022 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@7.1;
/**
* Latency modes used for the variable latency feature on output streams.
* Used by setLatencyMode() and getRecommendedLatencyModes() methods.
*/
@export(name="audio_latency_mode_t", value_prefix="AUDIO_LATENCY_MODE_")
enum LatencyMode : int32_t {
/** No specific constraint on the latency */
FREE = 0,
/** A relatively low latency compatible with head tracking operation (e.g less than 100ms) */
LOW = 1,
};

View File

@@ -97,10 +97,12 @@ static inline size_t getChannelCount(AudioChannelMask mask) {
case AudioChannelMask::AUDIO_CHANNEL_OUT_13POINT_360RA:
case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_13:
return 13;
case AudioChannelMask::AUDIO_CHANNEL_OUT_9POINT1POINT4:
case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_14:
return 14;
case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_15:
return 15;
case AudioChannelMask::AUDIO_CHANNEL_OUT_9POINT1POINT6:
case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_16:
return 16;
case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_17:
@@ -170,6 +172,7 @@ static inline bool isOutputDevice(AudioDevice device) {
case AudioDevice::AUDIO_DEVICE_OUT_ECHO_CANCELLER:
case AudioDevice::AUDIO_DEVICE_OUT_BLE_HEADSET:
case AudioDevice::AUDIO_DEVICE_OUT_BLE_SPEAKER:
case AudioDevice::AUDIO_DEVICE_OUT_BLE_BROADCAST:
case AudioDevice::AUDIO_DEVICE_OUT_DEFAULT:
case AudioDevice::AUDIO_DEVICE_OUT_STUB:
return true;

View File

@@ -761,6 +761,73 @@ int StreamOut::asyncEventCallback(stream_event_callback_type_t event, void* para
ALOGW_IF(!result.isOk(), "Client callback failed: %s", result.description().c_str());
return 0;
}
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
Return<Result> StreamOut::setLatencyMode(LatencyMode mode) {
return mStream->set_latency_mode != nullptr
? Stream::analyzeStatus(
"set_latency_mode",
mStream->set_latency_mode(mStream,
static_cast<audio_latency_mode_t>(mode)))
: Result::NOT_SUPPORTED;
};
Return<void> StreamOut::getRecommendedLatencyModes(getRecommendedLatencyModes_cb _hidl_cb) {
Result retval = Result::NOT_SUPPORTED;
hidl_vec<LatencyMode> hidlModes;
size_t num_modes = AUDIO_LATENCY_MODE_CNT;
audio_latency_mode_t modes[AUDIO_LATENCY_MODE_CNT];
if (mStream->get_recommended_latency_modes != nullptr &&
mStream->get_recommended_latency_modes(mStream, &modes[0], &num_modes) == 0) {
if (num_modes == 0 || num_modes > AUDIO_LATENCY_MODE_CNT) {
ALOGW("%s invalid number of modes returned: %zu", __func__, num_modes);
retval = Result::INVALID_STATE;
} else {
hidlModes.resize(num_modes);
for (size_t i = 0; i < num_modes; ++i) {
hidlModes[i] = static_cast<LatencyMode>(modes[i]);
}
retval = Result::OK;
}
}
_hidl_cb(retval, hidlModes);
return Void();
};
// static
void StreamOut::latencyModeCallback(audio_latency_mode_t* modes, size_t num_modes, void* cookie) {
StreamOut* self = reinterpret_cast<StreamOut*>(cookie);
sp<IStreamOutLatencyModeCallback> callback = self->mLatencyModeCallback.load();
if (callback.get() == nullptr) return;
ALOGV("%s", __func__);
if (num_modes == 0 || num_modes > AUDIO_LATENCY_MODE_CNT) {
ALOGW("%s invalid number of modes returned: %zu", __func__, num_modes);
return;
}
hidl_vec<LatencyMode> hidlModes(num_modes);
for (size_t i = 0; i < num_modes; ++i) {
hidlModes[i] = static_cast<LatencyMode>(modes[i]);
}
Return<void> result = callback->onRecommendedLatencyModeChanged(hidlModes);
ALOGW_IF(!result.isOk(), "Client callback failed: %s", result.description().c_str());
}
Return<Result> StreamOut::setLatencyModeCallback(
const sp<IStreamOutLatencyModeCallback>& callback) {
if (mStream->set_latency_mode_callback == nullptr) return Result::NOT_SUPPORTED;
int result = mStream->set_latency_mode_callback(mStream, StreamOut::latencyModeCallback, this);
if (result == 0) {
mLatencyModeCallback = callback;
}
return Stream::analyzeStatus("set_latency_mode_callback", result, {ENOSYS} /*ignore*/);
};
#endif
#endif
} // namespace implementation

View File

@@ -153,6 +153,12 @@ struct StreamOut : public IStreamOut {
Result doUpdateSourceMetadata(const SourceMetadata& sourceMetadata);
#if MAJOR_VERSION >= 7
Result doUpdateSourceMetadataV7(const SourceMetadata& sourceMetadata);
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
Return<Result> setLatencyMode(LatencyMode mode) override;
Return<void> getRecommendedLatencyModes(getRecommendedLatencyModes_cb _hidl_cb) override;
Return<Result> setLatencyModeCallback(
const sp<IStreamOutLatencyModeCallback>& callback) override;
#endif
#endif
#endif // MAJOR_VERSION >= 4
@@ -163,6 +169,9 @@ struct StreamOut : public IStreamOut {
mediautils::atomic_sp<IStreamOutCallback> mCallback; // for non-blocking write and drain
#if MAJOR_VERSION >= 6
mediautils::atomic_sp<IStreamOutEventCallback> mEventCallback;
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
mediautils::atomic_sp<IStreamOutLatencyModeCallback> mLatencyModeCallback;
#endif
#endif
std::unique_ptr<CommandMQ> mCommandMQ;
std::unique_ptr<DataMQ> mDataMQ;
@@ -177,6 +186,9 @@ struct StreamOut : public IStreamOut {
#if MAJOR_VERSION >= 6
static int asyncEventCallback(stream_event_callback_type_t event, void* param, void* cookie);
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
static void latencyModeCallback(audio_latency_mode_t* modes, size_t num_modes, void* cookie);
#endif
#endif
};