mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 16:50:18 +00:00
Merge "Audio HAL V7.1: Add latency mode APIs"
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
28
audio/7.1/IStreamOutLatencyModeCallback.hal
Normal file
28
audio/7.1/IStreamOutLatencyModeCallback.hal
Normal 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);
|
||||
};
|
||||
30
audio/7.1/types.hal
Normal file
30
audio/7.1/types.hal
Normal 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,
|
||||
};
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user