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

Commit ce182940 authored by Ytai Ben-Tsvi's avatar Ytai Ben-Tsvi
Browse files

AIDLize createEffect params

As part of the effort to convert IAudioFlinger to AIDL, converting
some of the method arguments to pure AIDL and making their
signatures more AIDL-friendly, by avoiding multiple primitive
return value.

Test: Audio-related CTS tests from CtsMediaTestCases
Change-Id: I720ff197ae5ffd50afa8d23f8fd6f19a2246e974
parent 16d87618
Loading
Loading
Loading
Loading
+63 −0
Original line number Diff line number Diff line
@@ -284,6 +284,14 @@ ConversionResult<std::string> legacy2aidl_String16_string(const String16& legacy
    return std::string(String8(legacy).c_str());
}

ConversionResult<String8> aidl2legacy_string_view_String8(std::string_view aidl) {
    return String8(aidl.data(), aidl.size());
}

ConversionResult<std::string> legacy2aidl_String8_string(const String8& legacy) {
    return std::string(legacy.c_str());
}

// The legacy enum is unnamed. Thus, we use int.
ConversionResult<int> aidl2legacy_AudioPortConfigType(media::AudioPortConfigType aidl) {
    switch (aidl) {
@@ -1695,4 +1703,59 @@ legacy2aidl_AudioTimestamp(const AudioTimestamp& legacy) {
    return aidl;
}

ConversionResult<audio_uuid_t>
aidl2legacy_AudioUuid_audio_uuid_t(const media::AudioUuid& aidl) {
    audio_uuid_t legacy;
    legacy.timeLow = VALUE_OR_RETURN(convertReinterpret<uint32_t>(aidl.timeLow));
    legacy.timeMid = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.timeMid));
    legacy.timeHiAndVersion = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.timeHiAndVersion));
    legacy.clockSeq = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.clockSeq));
    if (aidl.node.size() != std::size(legacy.node)) {
        return unexpected(BAD_VALUE);
    }
    std::copy(aidl.node.begin(), aidl.node.end(), legacy.node);
    return legacy;
}

ConversionResult<media::AudioUuid>
legacy2aidl_audio_uuid_t_AudioUuid(const audio_uuid_t& legacy) {
    media::AudioUuid aidl;
    aidl.timeLow = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy.timeLow));
    aidl.timeMid = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.timeMid));
    aidl.timeHiAndVersion = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.timeHiAndVersion));
    aidl.clockSeq = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.clockSeq));
    std::copy(legacy.node, legacy.node + std::size(legacy.node), std::back_inserter(aidl.node));
    return aidl;
}

ConversionResult<effect_descriptor_t>
aidl2legacy_EffectDescriptor_effect_descriptor_t(const media::EffectDescriptor& aidl) {
    effect_descriptor_t legacy;
    legacy.type = VALUE_OR_RETURN(aidl2legacy_AudioUuid_audio_uuid_t(aidl.type));
    legacy.uuid = VALUE_OR_RETURN(aidl2legacy_AudioUuid_audio_uuid_t(aidl.uuid));
    legacy.apiVersion = VALUE_OR_RETURN(convertReinterpret<uint32_t>(aidl.apiVersion));
    legacy.flags = VALUE_OR_RETURN(convertReinterpret<uint32_t>(aidl.flags));
    legacy.cpuLoad = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.cpuLoad));
    legacy.memoryUsage = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.memoryUsage));
    RETURN_IF_ERROR(aidl2legacy_string(aidl.name, legacy.name, sizeof(legacy.name)));
    RETURN_IF_ERROR(
            aidl2legacy_string(aidl.implementor, legacy.implementor, sizeof(legacy.implementor)));
    return legacy;
}

ConversionResult<media::EffectDescriptor>
legacy2aidl_effect_descriptor_t_EffectDescriptor(const effect_descriptor_t& legacy) {
    media::EffectDescriptor aidl;
    aidl.type = VALUE_OR_RETURN(legacy2aidl_audio_uuid_t_AudioUuid(legacy.type));
    aidl.uuid = VALUE_OR_RETURN(legacy2aidl_audio_uuid_t_AudioUuid(legacy.uuid));
    aidl.apiVersion = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy.apiVersion));
    aidl.flags = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy.flags));
    aidl.cpuLoad = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.cpuLoad));
    aidl.memoryUsage = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.memoryUsage));
    aidl.name = VALUE_OR_RETURN(legacy2aidl_string(legacy.name, sizeof(legacy.name)));
    aidl.implementor = VALUE_OR_RETURN(
            legacy2aidl_string(legacy.implementor, sizeof(legacy.implementor)));
    return aidl;
}

}  // namespace android
+14 −2
Original line number Diff line number Diff line
@@ -130,12 +130,12 @@ cc_library_shared {
    ],
    export_header_lib_headers: ["libaudioclient_headers"],
    export_static_lib_headers: [
        "effect-aidl-cpp",
        "effect-aidl-unstable-cpp",
        "shared-file-region-aidl-unstable-cpp",
    ],

    static_libs: [
        "effect-aidl-cpp",
        "effect-aidl-unstable-cpp",
        // for memory heap analysis
        "libc_malloc_debug_backtrace",
        "shared-file-region-aidl-unstable-cpp",
@@ -216,6 +216,9 @@ aidl_interface {
    name: "effect-aidl",
    unstable: true,
    local_include_dir: "aidl",
    host_supported: true,
    double_loadable: true,
    vendor_available: true,
    srcs: [
        "aidl/android/media/IEffect.aidl",
        "aidl/android/media/IEffectClient.aidl",
@@ -238,6 +241,7 @@ aidl_interface {
        "aidl/android/media/AudioConfig.aidl",
        "aidl/android/media/AudioConfigBase.aidl",
        "aidl/android/media/AudioContentType.aidl",
        "aidl/android/media/AudioDevice.aidl",
        "aidl/android/media/AudioEncapsulationMode.aidl",
        "aidl/android/media/AudioFlag.aidl",
        "aidl/android/media/AudioGainConfig.aidl",
@@ -246,6 +250,7 @@ aidl_interface {
        "aidl/android/media/AudioIoConfigEvent.aidl",
        "aidl/android/media/AudioIoDescriptor.aidl",
        "aidl/android/media/AudioIoFlags.aidl",
        "aidl/android/media/AudioMode.aidl",
        "aidl/android/media/AudioOffloadInfo.aidl",
        "aidl/android/media/AudioOutputFlags.aidl",
        "aidl/android/media/AudioPatch.aidl",
@@ -261,7 +266,10 @@ aidl_interface {
        "aidl/android/media/AudioSourceType.aidl",
        "aidl/android/media/AudioStreamType.aidl",
        "aidl/android/media/AudioTimestampInternal.aidl",
        "aidl/android/media/AudioUniqueIdUse.aidl",
        "aidl/android/media/AudioUsage.aidl",
        "aidl/android/media/AudioUuid.aidl",
        "aidl/android/media/EffectDescriptor.aidl",
    ],
    imports: [
        "audio_common-aidl",
@@ -284,6 +292,8 @@ aidl_interface {
    host_supported: true,
    vendor_available: true,
    srcs: [
        "aidl/android/media/CreateEffectRequest.aidl",
        "aidl/android/media/CreateEffectResponse.aidl",
        "aidl/android/media/CreateRecordRequest.aidl",
        "aidl/android/media/CreateRecordResponse.aidl",
        "aidl/android/media/CreateTrackRequest.aidl",
@@ -295,8 +305,10 @@ aidl_interface {
        "aidl/android/media/IAudioTrackCallback.aidl",
    ],
    imports: [
        "audio_common-aidl",
        "audioclient-types-aidl",
        "av-types-aidl",
        "effect-aidl",
        "shared-file-region-aidl",
    ],
    double_loadable: true,
+30 −3
Original line number Diff line number Diff line
@@ -29,6 +29,13 @@
#include <private/media/AudioEffectShared.h>
#include <utils/Log.h>

#define VALUE_OR_RETURN_STATUS(exp)          \
    ({                                       \
        auto _tmp = (exp);                   \
        if (!_tmp.ok()) return _tmp.error(); \
        std::move(_tmp.value());             \
    })

namespace android {

using binder::Status;
@@ -101,9 +108,29 @@ status_t AudioEffect::set(const effect_uuid_t *type,
    mClientPid = IPCThreadState::self()->getCallingPid();
    mClientUid = IPCThreadState::self()->getCallingUid();

    iEffect = audioFlinger->createEffect((effect_descriptor_t *)&mDescriptor,
            mIEffectClient, priority, io, mSessionId, device, mOpPackageName, mClientPid,
            probe, &mStatus, &mId, &enabled);
    media::CreateEffectRequest request;
    request.desc = VALUE_OR_RETURN_STATUS(
            legacy2aidl_effect_descriptor_t_EffectDescriptor(mDescriptor));
    request.client = mIEffectClient;
    request.priority = priority;
    request.output = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(io));
    request.sessionId = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_session_t_int32_t(mSessionId));
    request.device = VALUE_OR_RETURN_STATUS(legacy2aidl_AudioDeviceTypeAddress(device));
    request.opPackageName = VALUE_OR_RETURN_STATUS(legacy2aidl_String16_string(mOpPackageName));
    request.pid = VALUE_OR_RETURN_STATUS(legacy2aidl_pid_t_int32_t(mClientPid));
    request.probe = probe;

    media::CreateEffectResponse response;

    mStatus = audioFlinger->createEffect(request, &response);

    if (mStatus == OK) {
        mId = response.id;
        enabled = response.enabled;
        iEffect = response.effect;
        mDescriptor = VALUE_OR_RETURN_STATUS(
                aidl2legacy_EffectDescriptor_effect_descriptor_t(response.desc));
    }

    // In probe mode, we stop here and return the status: the IEffect interface to
    // audio flinger will not be retained. initCheck() will return the creation status
+17 −80
Original line number Diff line number Diff line
@@ -792,66 +792,25 @@ public:
        return NO_ERROR;
    }

    virtual sp<media::IEffect> createEffect(
                                    effect_descriptor_t *pDesc,
                                    const sp<media::IEffectClient>& client,
                                    int32_t priority,
                                    audio_io_handle_t output,
                                    audio_session_t sessionId,
                                    const AudioDeviceTypeAddr& device,
                                    const String16& opPackageName,
                                    pid_t pid,
                                    bool probe,
                                    status_t *status,
                                    int *id,
                                    int *enabled)
    virtual status_t createEffect(const media::CreateEffectRequest& request,
                                  media::CreateEffectResponse* response)
    {
        Parcel data, reply;
        sp<media::IEffect> effect;
        if (pDesc == NULL) {
            if (status != NULL) {
                *status = BAD_VALUE;
            }
            return nullptr;
        }

        data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
        data.write(pDesc, sizeof(effect_descriptor_t));
        data.writeStrongBinder(IInterface::asBinder(client));
        data.writeInt32(priority);
        data.writeInt32((int32_t) output);
        data.writeInt32(sessionId);
        if (data.writeParcelable(device) != NO_ERROR) {
            if (status != NULL) {
                *status = NO_INIT;
            }
            return nullptr;
        if (response == nullptr) {
            return BAD_VALUE;
        }
        data.writeString16(opPackageName);
        data.writeInt32((int32_t) pid);
        data.writeInt32(probe ? 1 : 0);

        status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
        status_t status;
        status_t lStatus = data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor())
                           ?: data.writeParcelable(request)
                           ?: remote()->transact(CREATE_EFFECT, data, &reply)
                           ?: reply.readInt32(&status)
                           ?: reply.readParcelable(response)
                           ?: status;
        if (lStatus != NO_ERROR) {
            ALOGE("createEffect error: %s", strerror(-lStatus));
        } else {
            lStatus = reply.readInt32();
            int tmp = reply.readInt32();
            if (id != NULL) {
                *id = tmp;
            }
            tmp = reply.readInt32();
            if (enabled != NULL) {
                *enabled = tmp;
        }
            effect = interface_cast<media::IEffect>(reply.readStrongBinder());
            reply.read(pDesc, sizeof(effect_descriptor_t));
        }
        if (status != NULL) {
            *status = lStatus;
        }

        return effect;
        return lStatus;
    }

    virtual status_t moveEffects(audio_session_t session, audio_io_handle_t srcOutput,
@@ -1525,35 +1484,13 @@ status_t BnAudioFlinger::onTransact(
        }
        case CREATE_EFFECT: {
            CHECK_INTERFACE(IAudioFlinger, data, reply);
            effect_descriptor_t desc = {};
            if (data.read(&desc, sizeof(effect_descriptor_t)) != NO_ERROR) {
                ALOGE("b/23905951");
            }
            sp<media::IEffectClient> client =
                    interface_cast<media::IEffectClient>(data.readStrongBinder());
            int32_t priority = data.readInt32();
            audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
            audio_session_t sessionId = (audio_session_t) data.readInt32();
            AudioDeviceTypeAddr device;
            status_t status = NO_ERROR;
            if ((status = data.readParcelable(&device)) != NO_ERROR) {
                return status;
            }
            const String16 opPackageName = data.readString16();
            pid_t pid = (pid_t)data.readInt32();
            bool probe = data.readInt32() == 1;

            int id = 0;
            int enabled = 0;
            media::CreateEffectRequest request;
            media::CreateEffectResponse response;

            sp<media::IEffect> effect = createEffect(&desc, client, priority, output, sessionId,
                    device, opPackageName, pid, probe, &status, &id, &enabled);
            reply->writeInt32(status);
            reply->writeInt32(id);
            reply->writeInt32(enabled);
            reply->writeStrongBinder(IInterface::asBinder(effect));
            reply->write(&desc, sizeof(effect_descriptor_t));
            return NO_ERROR;
            return data.readParcelable(&request)
                ?: reply->writeInt32(createEffect(request, &response))
                ?: reply->writeParcelable(response);
        } break;
        case MOVE_EFFECTS: {
            CHECK_INTERFACE(IAudioFlinger, data, reply);
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.media;

/**
 * {@hide}
 */
parcelable AudioDevice {
    /** Interpreted as audio_devices_t. */
    int type;
    @utf8InCpp String address;
}
Loading