From 6c070ca4e89c4d5d044153d05bc53f9339b36f3c Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Wed, 11 Dec 2019 12:36:26 -0800 Subject: [PATCH] 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 --- audio/6.0/IDevice.hal | 19 ++++++++++++ audio/core/all-versions/default/Device.cpp | 29 ++++++++++++++++--- .../all-versions/default/PrimaryDevice.cpp | 7 +++++ .../default/include/core/default/Device.h | 6 ++++ .../include/core/default/PrimaryDevice.h | 3 ++ .../6.0/AudioPrimaryHidlHalTest.cpp | 9 ++++++ current.txt | 2 +- 7 files changed, 70 insertions(+), 5 deletions(-) diff --git a/audio/6.0/IDevice.hal b/audio/6.0/IDevice.hal index 2347696035..c2e310ce69 100644 --- a/audio/6.0/IDevice.hal +++ b/audio/6.0/IDevice.hal @@ -167,6 +167,25 @@ interface IDevice { createAudioPatch(vec sources, vec 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 sources, + vec sinks) generates ( + Result retval, AudioPatchHandle patch); + /** * Release an audio patch. * diff --git a/audio/core/all-versions/default/Device.cpp b/audio/core/all-versions/default/Device.cpp index ad841caf2e..47e31c1801 100644 --- a/audio/core/all-versions/default/Device.cpp +++ b/audio/core/all-versions/default/Device.cpp @@ -269,12 +269,21 @@ Return Device::supportsAudioPatches() { Return Device::createAudioPatch(const hidl_vec& sources, const hidl_vec& sinks, createAudioPatch_cb _hidl_cb) { + auto [retval, patch] = createOrUpdateAudioPatch( + static_cast(AudioHandleConsts::AUDIO_PATCH_HANDLE_NONE), sources, + sinks); + _hidl_cb(retval, patch); + return Void(); +} + +std::tuple Device::createOrUpdateAudioPatch( + AudioPatchHandle patch, const hidl_vec& sources, + const hidl_vec& sinks) { Result retval(Result::NOT_SUPPORTED); - AudioPatchHandle patch = 0; if (version() >= AUDIO_DEVICE_API_VERSION_3_0) { std::unique_ptr halSources(HidlUtils::audioPortConfigsToHal(sources)); std::unique_ptr halSinks(HidlUtils::audioPortConfigsToHal(sinks)); - audio_patch_handle_t halPatch = AUDIO_PATCH_HANDLE_NONE; + audio_patch_handle_t halPatch = static_cast(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 Device::createAudioPatch(const hidl_vec& sources, patch = static_cast(halPatch); } } - _hidl_cb(retval, patch); - return Void(); + return {retval, patch}; } Return Device::releaseAudioPatch(int32_t patch) { @@ -438,6 +446,19 @@ Return Device::removeDeviceEffect(AudioPortHandle device, uint64_t effec } } +Return Device::updateAudioPatch(int32_t previousPatch, + const hidl_vec& sources, + const hidl_vec& sinks, + createAudioPatch_cb _hidl_cb) { + if (previousPatch != static_cast(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 diff --git a/audio/core/all-versions/default/PrimaryDevice.cpp b/audio/core/all-versions/default/PrimaryDevice.cpp index 0f1aba0f2f..679f85dad3 100644 --- a/audio/core/all-versions/default/PrimaryDevice.cpp +++ b/audio/core/all-versions/default/PrimaryDevice.cpp @@ -176,6 +176,13 @@ Return PrimaryDevice::addDeviceEffect(AudioPortHandle device, uint64_t e Return PrimaryDevice::removeDeviceEffect(AudioPortHandle device, uint64_t effectId) { return mDevice->removeDeviceEffect(device, effectId); } + +Return PrimaryDevice::updateAudioPatch(int32_t previousPatch, + const hidl_vec& sources, + const hidl_vec& sinks, + updateAudioPatch_cb _hidl_cb) { + return mDevice->updateAudioPatch(previousPatch, sources, sinks, _hidl_cb); +} #endif // Methods from ::android::hardware::audio::CPP_VERSION::IPrimaryDevice follow. diff --git a/audio/core/all-versions/default/include/core/default/Device.h b/audio/core/all-versions/default/include/core/default/Device.h index 80a9638004..b0e72d9600 100644 --- a/audio/core/all-versions/default/include/core/default/Device.h +++ b/audio/core/all-versions/default/include/core/default/Device.h @@ -118,6 +118,9 @@ struct Device : public IDevice, public ParametersUtil { Return close() override; Return addDeviceEffect(AudioPortHandle device, uint64_t effectId) override; Return removeDeviceEffect(AudioPortHandle device, uint64_t effectId) override; + Return updateAudioPatch(int32_t previousPatch, const hidl_vec& sources, + const hidl_vec& sinks, + createAudioPatch_cb _hidl_cb) override; #endif Return debug(const hidl_handle& fd, const hidl_vec& options) override; @@ -136,6 +139,9 @@ struct Device : public IDevice, public ParametersUtil { virtual ~Device(); Result doClose(); + std::tuple createOrUpdateAudioPatch( + AudioPatchHandle patch, const hidl_vec& sources, + const hidl_vec& sinks); // Methods from ParametersUtil. char* halGetParameters(const char* keys) override; diff --git a/audio/core/all-versions/default/include/core/default/PrimaryDevice.h b/audio/core/all-versions/default/include/core/default/PrimaryDevice.h index 9fc90c39fe..ccdb7b26c1 100644 --- a/audio/core/all-versions/default/include/core/default/PrimaryDevice.h +++ b/audio/core/all-versions/default/include/core/default/PrimaryDevice.h @@ -100,6 +100,9 @@ struct PrimaryDevice : public IPrimaryDevice { Return close() override; Return addDeviceEffect(AudioPortHandle device, uint64_t effectId) override; Return removeDeviceEffect(AudioPortHandle device, uint64_t effectId) override; + Return updateAudioPatch(int32_t previousPatch, const hidl_vec& sources, + const hidl_vec& sinks, + updateAudioPatch_cb _hidl_cb) override; #endif Return debug(const hidl_handle& fd, const hidl_vec& options) override; diff --git a/audio/core/all-versions/vts/functional/6.0/AudioPrimaryHidlHalTest.cpp b/audio/core/all-versions/vts/functional/6.0/AudioPrimaryHidlHalTest.cpp index 2afbbb8fc4..09ef330be6 100644 --- a/audio/core/all-versions/vts/functional/6.0/AudioPrimaryHidlHalTest.cpp +++ b/audio/core/all-versions/vts/functional/6.0/AudioPrimaryHidlHalTest.cpp @@ -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(AudioHandleConsts::AUDIO_PATCH_HANDLE_NONE), + hidl_vec(), hidl_vec(), returnIn(res, ignored))); + ASSERT_RESULT(Result::INVALID_ARGUMENTS, res); +} diff --git a/current.txt b/current.txt index 999b207899..1fe17d5ca4 100644 --- a/current.txt +++ b/current.txt @@ -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