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

Commit 327f089f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Call getAudioPort to get supported attributes for audio devices."

parents cd7ba517 b4fed19d
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -946,14 +946,14 @@ public:
        reply.read(ports, *num_ports * sizeof(struct audio_port));
        return status;
    }
    virtual status_t getAudioPort(struct audio_port *port)
    virtual status_t getAudioPort(struct audio_port_v7 *port)
    {
        if (port == NULL) {
        if (port == nullptr) {
            return BAD_VALUE;
        }
        Parcel data, reply;
        data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
        data.write(port, sizeof(struct audio_port));
        data.write(port, sizeof(struct audio_port_v7));
        status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
        if (status != NO_ERROR ||
                (status = (status_t)reply.readInt32()) != NO_ERROR) {
@@ -1645,7 +1645,7 @@ status_t BnAudioFlinger::onTransact(
        } break;
        case GET_AUDIO_PORT: {
            CHECK_INTERFACE(IAudioFlinger, data, reply);
            struct audio_port port = {};
            struct audio_port_v7 port = {};
            status_t status = data.read(&port, sizeof(struct audio_port));
            if (status != NO_ERROR) {
                ALOGE("b/23905951");
@@ -1657,7 +1657,7 @@ status_t BnAudioFlinger::onTransact(
            }
            reply->writeInt32(status);
            if (status == NO_ERROR) {
                reply->write(&port, sizeof(struct audio_port));
                reply->write(&port, sizeof(struct audio_port_v7));
            }
            return NO_ERROR;
        } break;
+1 −1
Original line number Diff line number Diff line
@@ -317,7 +317,7 @@ public:
                                    struct audio_port *ports) = 0;

    /* Get attributes for a given audio port */
    virtual status_t getAudioPort(struct audio_port *port) = 0;
    virtual status_t getAudioPort(struct audio_port_v7 *port) = 0;

    /* Create an audio patch between several source and sink ports */
    virtual status_t createAudioPatch(const struct audio_patch *patch,
+40 −7
Original line number Diff line number Diff line
@@ -38,6 +38,21 @@ void AudioPort::importAudioPort(const sp<AudioPort>& port, bool force __unused)
    }
}

void AudioPort::importAudioPort(const audio_port_v7 &port) {
    for (size_t i = 0; i < port.num_audio_profiles; ++i) {
        sp<AudioProfile> profile = new AudioProfile(port.audio_profiles[i].format,
                ChannelMaskSet(port.audio_profiles[i].channel_masks,
                        port.audio_profiles[i].channel_masks +
                        port.audio_profiles->num_channel_masks),
                SampleRateSet(port.audio_profiles[i].sample_rates,
                        port.audio_profiles[i].sample_rates +
                        port.audio_profiles[i].num_sample_rates));
        if (!mProfiles.contains(profile)) {
            addAudioProfile(profile);
        }
    }
}

void AudioPort::toAudioPort(struct audio_port *port) const {
    // TODO: update this function once audio_port structure reflects the new profile definition.
    // For compatibility reason: flatening the AudioProfile into audio_port structure.
@@ -62,21 +77,39 @@ void AudioPort::toAudioPort(struct audio_port *port) const {
            }
        }
    }
    port->role = mRole;
    port->type = mType;
    strlcpy(port->name, mName.c_str(), AUDIO_PORT_MAX_NAME_LEN);
    toAudioPortBase(port);
    port->num_sample_rates = flatenedRates.size();
    port->num_channel_masks = flatenedChannels.size();
    port->num_formats = flatenedFormats.size();
    std::copy(flatenedRates.begin(), flatenedRates.end(), port->sample_rates);
    std::copy(flatenedChannels.begin(), flatenedChannels.end(), port->channel_masks);
    std::copy(flatenedFormats.begin(), flatenedFormats.end(), port->formats);
}

void AudioPort::toAudioPort(struct audio_port_v7 *port) const {
    toAudioPortBase(port);
    port->num_audio_profiles = 0;
    for (const auto& profile : mProfiles) {
        if (profile->isValid()) {
            const SampleRateSet &sampleRates = profile->getSampleRates();
            const ChannelMaskSet &channelMasks = profile->getChannels();

    ALOGV("AudioPort::toAudioPort() num gains %zu", mGains.size());
            if (sampleRates.size() > AUDIO_PORT_MAX_SAMPLING_RATES ||
                    channelMasks.size() > AUDIO_PORT_MAX_CHANNEL_MASKS ||
                    port->num_audio_profiles >= AUDIO_PORT_MAX_AUDIO_PROFILES) {
                ALOGE("%s: bailing out: cannot export profiles to port config", __func__);
                return;
            }

    port->num_gains = std::min(mGains.size(), (size_t) AUDIO_PORT_MAX_GAINS);
    for (size_t i = 0; i < port->num_gains; i++) {
        port->gains[i] = mGains[i]->getGain();
            auto& dstProfile = port->audio_profiles[port->num_audio_profiles++];
            dstProfile.format = profile->getFormat();
            dstProfile.num_sample_rates = sampleRates.size();
            std::copy(sampleRates.begin(), sampleRates.end(),
                    std::begin(dstProfile.sample_rates));
            dstProfile.num_channel_masks = channelMasks.size();
            std::copy(channelMasks.begin(), channelMasks.end(),
                    std::begin(dstProfile.channel_masks));
        }
    }
}

+10 −0
Original line number Diff line number Diff line
@@ -260,6 +260,16 @@ bool AudioProfileVector::hasDynamicRateFor(audio_format_t format) const
    return false;
}

bool AudioProfileVector::contains(const sp<AudioProfile>& profile) const
{
    for (const auto& audioProfile : *this) {
        if (audioProfile->equals(profile)) {
            return true;
        }
    }
    return false;
}

void AudioProfileVector::dump(std::string *dst, int spaces) const
{
    dst->append(base::StringPrintf("%*s- Profiles:\n", spaces, ""));
+6 −7
Original line number Diff line number Diff line
@@ -80,13 +80,12 @@ void DeviceDescriptorBase::toAudioPortConfig(struct audio_port_config *dstConfig
void DeviceDescriptorBase::toAudioPort(struct audio_port *port) const
{
    ALOGV("DeviceDescriptorBase::toAudioPort() handle %d type %08x", mId, mDeviceTypeAddr.mType);
    AudioPort::toAudioPort(port);
    toAudioPortConfig(&port->active_config);
    port->id = mId;
    port->ext.device.type = mDeviceTypeAddr.mType;
    port->ext.device.encapsulation_modes = mEncapsulationModes;
    port->ext.device.encapsulation_metadata_types = mEncapsulationMetadataTypes;
    (void)audio_utils_strlcpy_zerofill(port->ext.device.address, mDeviceTypeAddr.getAddress());
    toAudioPortInternal(port);
}

void DeviceDescriptorBase::toAudioPort(struct audio_port_v7 *port) const {
    ALOGV("DeviceDescriptorBase::toAudioPort() v7 handle %d type %08x", mId, mDeviceTypeAddr.mType);
    toAudioPortInternal(port);
}

status_t DeviceDescriptorBase::setEncapsulationModes(uint32_t encapsulationModes) {
Loading