mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 16:50:18 +00:00
audio: Add IDevice::updateAudioPatch method
Add method 'updateAudioPatch' which should be used when an existing patch needs to be updated with new routing. Use of this method allows audio HAL to avoid disrupting audio stream while changing routing. Bug: 79248321 Test: atest VtsHalAudioV6_0TargetTest Change-Id: I6c87f67fa4f2463ba9e8f0272a3232f5c9c55714
This commit is contained in:
@@ -167,6 +167,25 @@ interface IDevice {
|
||||
createAudioPatch(vec<AudioPortConfig> sources, vec<AudioPortConfig> sinks)
|
||||
generates (Result retval, AudioPatchHandle patch);
|
||||
|
||||
/**
|
||||
* Updates an audio patch.
|
||||
*
|
||||
* Use of this function is preferred to releasing and re-creating a patch
|
||||
* as the HAL module can figure out a way of switching the route without
|
||||
* causing audio disruption.
|
||||
*
|
||||
* @param previousPatch handle of the previous patch to update.
|
||||
* @param sources new patch sources.
|
||||
* @param sinks new patch sinks.
|
||||
* @return retval operation completion status.
|
||||
* @return patch updated patch handle.
|
||||
*/
|
||||
updateAudioPatch(
|
||||
AudioPatchHandle previousPatch,
|
||||
vec<AudioPortConfig> sources,
|
||||
vec<AudioPortConfig> sinks) generates (
|
||||
Result retval, AudioPatchHandle patch);
|
||||
|
||||
/**
|
||||
* Release an audio patch.
|
||||
*
|
||||
|
||||
@@ -269,12 +269,21 @@ Return<bool> Device::supportsAudioPatches() {
|
||||
Return<void> Device::createAudioPatch(const hidl_vec<AudioPortConfig>& sources,
|
||||
const hidl_vec<AudioPortConfig>& sinks,
|
||||
createAudioPatch_cb _hidl_cb) {
|
||||
auto [retval, patch] = createOrUpdateAudioPatch(
|
||||
static_cast<AudioPatchHandle>(AudioHandleConsts::AUDIO_PATCH_HANDLE_NONE), sources,
|
||||
sinks);
|
||||
_hidl_cb(retval, patch);
|
||||
return Void();
|
||||
}
|
||||
|
||||
std::tuple<Result, AudioPatchHandle> Device::createOrUpdateAudioPatch(
|
||||
AudioPatchHandle patch, const hidl_vec<AudioPortConfig>& sources,
|
||||
const hidl_vec<AudioPortConfig>& sinks) {
|
||||
Result retval(Result::NOT_SUPPORTED);
|
||||
AudioPatchHandle patch = 0;
|
||||
if (version() >= AUDIO_DEVICE_API_VERSION_3_0) {
|
||||
std::unique_ptr<audio_port_config[]> halSources(HidlUtils::audioPortConfigsToHal(sources));
|
||||
std::unique_ptr<audio_port_config[]> halSinks(HidlUtils::audioPortConfigsToHal(sinks));
|
||||
audio_patch_handle_t halPatch = AUDIO_PATCH_HANDLE_NONE;
|
||||
audio_patch_handle_t halPatch = static_cast<audio_patch_handle_t>(patch);
|
||||
retval = analyzeStatus("create_audio_patch",
|
||||
mDevice->create_audio_patch(mDevice, sources.size(), &halSources[0],
|
||||
sinks.size(), &halSinks[0], &halPatch));
|
||||
@@ -282,8 +291,7 @@ Return<void> Device::createAudioPatch(const hidl_vec<AudioPortConfig>& sources,
|
||||
patch = static_cast<AudioPatchHandle>(halPatch);
|
||||
}
|
||||
}
|
||||
_hidl_cb(retval, patch);
|
||||
return Void();
|
||||
return {retval, patch};
|
||||
}
|
||||
|
||||
Return<Result> Device::releaseAudioPatch(int32_t patch) {
|
||||
@@ -438,6 +446,19 @@ Return<Result> Device::removeDeviceEffect(AudioPortHandle device, uint64_t effec
|
||||
}
|
||||
}
|
||||
|
||||
Return<void> Device::updateAudioPatch(int32_t previousPatch,
|
||||
const hidl_vec<AudioPortConfig>& sources,
|
||||
const hidl_vec<AudioPortConfig>& sinks,
|
||||
createAudioPatch_cb _hidl_cb) {
|
||||
if (previousPatch != static_cast<int32_t>(AudioHandleConsts::AUDIO_PATCH_HANDLE_NONE)) {
|
||||
auto [retval, patch] = createOrUpdateAudioPatch(previousPatch, sources, sinks);
|
||||
_hidl_cb(retval, patch);
|
||||
} else {
|
||||
_hidl_cb(Result::INVALID_ARGUMENTS, previousPatch);
|
||||
}
|
||||
return Void();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
@@ -176,6 +176,13 @@ Return<Result> PrimaryDevice::addDeviceEffect(AudioPortHandle device, uint64_t e
|
||||
Return<Result> PrimaryDevice::removeDeviceEffect(AudioPortHandle device, uint64_t effectId) {
|
||||
return mDevice->removeDeviceEffect(device, effectId);
|
||||
}
|
||||
|
||||
Return<void> PrimaryDevice::updateAudioPatch(int32_t previousPatch,
|
||||
const hidl_vec<AudioPortConfig>& sources,
|
||||
const hidl_vec<AudioPortConfig>& sinks,
|
||||
updateAudioPatch_cb _hidl_cb) {
|
||||
return mDevice->updateAudioPatch(previousPatch, sources, sinks, _hidl_cb);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Methods from ::android::hardware::audio::CPP_VERSION::IPrimaryDevice follow.
|
||||
|
||||
@@ -118,6 +118,9 @@ struct Device : public IDevice, public ParametersUtil {
|
||||
Return<Result> close() override;
|
||||
Return<Result> addDeviceEffect(AudioPortHandle device, uint64_t effectId) override;
|
||||
Return<Result> removeDeviceEffect(AudioPortHandle device, uint64_t effectId) override;
|
||||
Return<void> updateAudioPatch(int32_t previousPatch, const hidl_vec<AudioPortConfig>& sources,
|
||||
const hidl_vec<AudioPortConfig>& sinks,
|
||||
createAudioPatch_cb _hidl_cb) override;
|
||||
#endif
|
||||
Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override;
|
||||
|
||||
@@ -136,6 +139,9 @@ struct Device : public IDevice, public ParametersUtil {
|
||||
virtual ~Device();
|
||||
|
||||
Result doClose();
|
||||
std::tuple<Result, AudioPatchHandle> createOrUpdateAudioPatch(
|
||||
AudioPatchHandle patch, const hidl_vec<AudioPortConfig>& sources,
|
||||
const hidl_vec<AudioPortConfig>& sinks);
|
||||
|
||||
// Methods from ParametersUtil.
|
||||
char* halGetParameters(const char* keys) override;
|
||||
|
||||
@@ -100,6 +100,9 @@ struct PrimaryDevice : public IPrimaryDevice {
|
||||
Return<Result> close() override;
|
||||
Return<Result> addDeviceEffect(AudioPortHandle device, uint64_t effectId) override;
|
||||
Return<Result> removeDeviceEffect(AudioPortHandle device, uint64_t effectId) override;
|
||||
Return<void> updateAudioPatch(int32_t previousPatch, const hidl_vec<AudioPortConfig>& sources,
|
||||
const hidl_vec<AudioPortConfig>& sinks,
|
||||
updateAudioPatch_cb _hidl_cb) override;
|
||||
#endif
|
||||
|
||||
Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override;
|
||||
|
||||
@@ -181,3 +181,12 @@ TEST_P(AudioHidlDeviceTest, CloseDeviceWithOpenedInputStreams) {
|
||||
ASSERT_OK(getDevice()->close());
|
||||
ASSERT_TRUE(resetDevice());
|
||||
}
|
||||
|
||||
TEST_P(AudioPatchHidlTest, UpdatePatchInvalidHandle) {
|
||||
doc::test("Verify that passing an invalid handle to updateAudioPatch is checked");
|
||||
AudioPatchHandle ignored;
|
||||
ASSERT_OK(getDevice()->updateAudioPatch(
|
||||
static_cast<int32_t>(AudioHandleConsts::AUDIO_PATCH_HANDLE_NONE),
|
||||
hidl_vec<AudioPortConfig>(), hidl_vec<AudioPortConfig>(), returnIn(res, ignored)));
|
||||
ASSERT_RESULT(Result::INVALID_ARGUMENTS, res);
|
||||
}
|
||||
|
||||
@@ -598,7 +598,7 @@ fd65298e1e09e0e3c781ab18305920d757dbe55a3b459ce17814ec5cf6dfee99 android.hardwar
|
||||
|
||||
# HALs released in Android R
|
||||
e966a3437d6a98d9d9e14e9d672088771716031900c0deb55a0946c751a03a44 android.hardware.audio@6.0::types
|
||||
4540d12fe1cea996f21bd1712d4ae0906dcbd58177dac494efc605b004902d43 android.hardware.audio@6.0::IDevice
|
||||
dd3e9280be60a5e042331c1046d13938e2cc323dc4b267cc74d544bf62fc0314 android.hardware.audio@6.0::IDevice
|
||||
2402876cbc23c0de3690a665eca84fd3857d1808dba5cad25ce272f81ecef8c9 android.hardware.audio@6.0::IDevicesFactory
|
||||
bca5379d5065e2e08b6ad7308ffc8a71a972fc0698bec678ea32eea786d01cb5 android.hardware.audio@6.0::IPrimaryDevice
|
||||
fd1f1b29f26b42e886220f04a08086c00e5ade9d7b53f095438e578ab9d42a93 android.hardware.audio@6.0::IStream
|
||||
|
||||
Reference in New Issue
Block a user