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

Commit d0ba9ed0 authored by François Gaffie's avatar François Gaffie Committed by Eric Laurent
Browse files

audio policy service: Add introspection API to retrieve AudioProductStrategies



This CL adds required introspection APIs to deal with product strategies:

-getter of the collection of product strategies
-helper function to return the strategy associated to a given attributes.
This API is mandatory to avoid duplicating the logic that compiles the strategy
for a given Audio Attributes structure.

Test: make

Change-Id: I0e107570a44227bb52a4f359954c93215d4f8bae
Signed-off-by: default avatarFrançois Gaffie <francois.gaffie@renault.com>
parent 7188f1ad
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
../../media/libaudioclient/include/media/AudioAttributes.h
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
../../media/libaudioclient/include/media/AudioProductStrategy.h
 No newline at end of file
+23 −1
Original line number Diff line number Diff line
@@ -4,6 +4,28 @@ cc_library_headers {
    export_include_dirs: ["include"],
}

cc_library_shared {
    name: "libaudiopolicy",
    srcs: [
        "AudioAttributes.cpp",
        "AudioPolicy.cpp",
        "AudioProductStrategy.cpp",
    ],
    shared_libs: [
        "libaudioutils",
        "libbinder",
        "libcutils",
        "liblog",
        "libutils",
    ],
    cflags: [
        "-Werror",
        "-Wall",
    ],
    include_dirs: ["system/media/audio_utils/include"],
    export_include_dirs: ["include"],
}

cc_library_shared {
    name: "libaudioclient",

@@ -23,7 +45,6 @@ cc_library_shared {
        ":libaudioclient_aidl",

        "AudioEffect.cpp",
        "AudioPolicy.cpp",
        "AudioRecord.cpp",
        "AudioSystem.cpp",
        "AudioTrack.cpp",
@@ -41,6 +62,7 @@ cc_library_shared {
    ],
    shared_libs: [
        "libaudioutils",
        "libaudiopolicy",
        "libaudiomanager",
        "libbinder",
        "libcutils",
+67 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.
 */

#define LOG_TAG "AudioAttributes"
//#define LOG_NDEBUG 0
#include <utils/Log.h>

#include <binder/Parcel.h>

#include <media/AudioAttributes.h>

namespace android {

status_t AudioAttributes::readFromParcel(const Parcel *parcel)
{
    status_t ret = NO_ERROR;
    mAttributes.content_type = static_cast<audio_content_type_t>(parcel->readInt32());
    mAttributes.usage = static_cast<audio_usage_t>(parcel->readInt32());
    mAttributes.source = static_cast<audio_source_t>(parcel->readInt32());
    mAttributes.flags = static_cast<audio_flags_mask_t>(parcel->readInt32());
    const bool hasFlattenedTag = (parcel->readInt32() == 1);
    if (hasFlattenedTag) {
        std::string tags;
        ret = parcel->readUtf8FromUtf16(&tags);
        if (ret != NO_ERROR) {
            return ret;
        }
        std::strncpy(mAttributes.tags, tags.c_str(), AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - 1);
    } else {
        strcpy(mAttributes.tags, "");
    }
    mStreamType = static_cast<audio_stream_type_t>(parcel->readInt32());
    mGroupId = parcel->readUint32();
    return NO_ERROR;
}

status_t AudioAttributes::writeToParcel(Parcel *parcel) const
{
    parcel->writeInt32(static_cast<int32_t>(mAttributes.content_type));
    parcel->writeInt32(static_cast<int32_t>(mAttributes.usage));
    parcel->writeInt32(static_cast<int32_t>(mAttributes.source));
    parcel->writeInt32(static_cast<int32_t>(mAttributes.flags));
    if (strlen(mAttributes.tags) == 0) {
        parcel->writeInt32(0);
    } else {
        parcel->writeInt32(1);
        parcel->writeUtf8AsUtf16(mAttributes.tags);
    }
    parcel->writeInt32(static_cast<int32_t>(mStreamType));
    parcel->writeUint32(mGroupId);
    return NO_ERROR;
}

} // namespace android
+94 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.
 */

#define LOG_TAG "AudioProductStrategy"
//#define LOG_NDEBUG 0
#include <utils/Log.h>
#include <media/AudioProductStrategy.h>
#include <media/AudioAttributes.h>
#include <media/AudioSystem.h>

namespace android {

status_t AudioProductStrategy::readFromParcel(const Parcel *parcel)
{
    mId = static_cast<product_strategy_t>(parcel->readInt32());
    status_t ret = parcel->readUtf8FromUtf16(&mName);
    if (ret != NO_ERROR) {
        return ret;
    }
    size_t size = static_cast<size_t>(parcel->readInt32());
    for (size_t i = 0; i < size; i++) {
        AudioAttributes attribute;
        ret = attribute.readFromParcel(parcel);
        if (ret != NO_ERROR) {
            mAudioAttributes.clear();
            return ret;
        }
        mAudioAttributes.push_back(attribute);
    }
    return NO_ERROR;
}

status_t AudioProductStrategy::writeToParcel(Parcel *parcel) const
{
    parcel->writeInt32(static_cast<int32_t>(mId));
    parcel->writeUtf8AsUtf16(mName);
    size_t size = mAudioAttributes.size();
    size_t sizePosition = parcel->dataPosition();
    parcel->writeInt32(size);
    size_t finalSize = size;

    for (size_t i = 0; i < size; i++) {
        size_t position = parcel->dataPosition();
        AudioAttributes attribute(mAudioAttributes[i]);
        status_t ret = attribute.writeToParcel(parcel);
        if (ret != NO_ERROR) {
            parcel->setDataPosition(position);
            finalSize--;
        }
    }
    if (size != finalSize) {
        size_t position = parcel->dataPosition();
        parcel->setDataPosition(sizePosition);
        parcel->writeInt32(finalSize);
        parcel->setDataPosition(position);
    }
    return NO_ERROR;
}

bool AudioProductStrategy::attributesMatches(const audio_attributes_t refAttributes,
                                        const audio_attributes_t clientAttritubes)
{
    if (refAttributes == AUDIO_ATTRIBUTES_INITIALIZER) {
        // The default product strategy is the strategy that holds default attributes by convention.
        // All attributes that fail to match will follow the default strategy for routing.
        // Choosing the default must be done as a fallback, the attributes match shall not
        // select the default.
        return false;
    }
    return ((refAttributes.usage == AUDIO_USAGE_UNKNOWN) ||
            (clientAttritubes.usage == refAttributes.usage)) &&
            ((refAttributes.content_type == AUDIO_CONTENT_TYPE_UNKNOWN) ||
             (clientAttritubes.content_type == refAttributes.content_type)) &&
            ((refAttributes.flags == AUDIO_FLAG_NONE) ||
             (clientAttritubes.flags != AUDIO_FLAG_NONE &&
            (clientAttritubes.flags & refAttributes.flags) == clientAttritubes.flags)) &&
            ((strlen(refAttributes.tags) == 0) ||
             (std::strcmp(clientAttritubes.tags, refAttributes.tags) == 0));
}

} // namespace android
Loading