Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6c070ca4 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

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
parent c13049c6
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -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.
     *
+25 −4
Original line number Diff line number Diff line
@@ -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
+7 −0
Original line number Diff line number Diff line
@@ -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.
+6 −0
Original line number Diff line number Diff line
@@ -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;
+3 −0
Original line number Diff line number Diff line
@@ -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;
Loading