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

Commit 5d51ca95 authored by jiabin's avatar jiabin
Browse files

Use AudioDeviceTypeAddr in DeviceDescriptorBase.

AudioDeviceTypeAddr is moved to libaudiofoundation. In that case, it can
be used in DeviceDescriptorBase.

Bug: 135621476
Test: make, atest audiofoundation_parcelable_test
Test: play music, record audio
Change-Id: Ia66dce29c8fb9d25c40598d9bada6eb295313884
parent 05b5edd0
Loading
Loading
Loading
Loading
+20 −22
Original line number Diff line number Diff line
@@ -27,11 +27,11 @@ namespace android {
DeviceDescriptorBase::DeviceDescriptorBase(audio_devices_t type) :
    AudioPort("", AUDIO_PORT_TYPE_DEVICE,
              audio_is_output_device(type) ? AUDIO_PORT_ROLE_SINK :
                                             AUDIO_PORT_ROLE_SOURCE),
    mDeviceType(type)
                                             AUDIO_PORT_ROLE_SOURCE)
{
    mDeviceTypeAddr.mType = type;
    if (audio_is_remote_submix_device(type)) {
        mAddress = "0";
        mDeviceTypeAddr.mAddress = "0";
    }
}

@@ -55,22 +55,22 @@ void DeviceDescriptorBase::toAudioPortConfig(struct audio_port_config *dstConfig

    AudioPortConfig::toAudioPortConfig(dstConfig, srcConfig);

    dstConfig->role = audio_is_output_device(mDeviceType) ?
    dstConfig->role = audio_is_output_device(mDeviceTypeAddr.mType) ?
                        AUDIO_PORT_ROLE_SINK : AUDIO_PORT_ROLE_SOURCE;
    dstConfig->type = AUDIO_PORT_TYPE_DEVICE;
    dstConfig->ext.device.type = mDeviceType;
    dstConfig->ext.device.type = mDeviceTypeAddr.mType;

    (void)audio_utils_strlcpy_zerofill(dstConfig->ext.device.address, mAddress.c_str());
    (void)audio_utils_strlcpy_zerofill(dstConfig->ext.device.address, mDeviceTypeAddr.getAddress());
}

void DeviceDescriptorBase::toAudioPort(struct audio_port *port) const
{
    ALOGV("DeviceDescriptorBase::toAudioPort() handle %d type %08x", mId, mDeviceType);
    ALOGV("DeviceDescriptorBase::toAudioPort() handle %d type %08x", mId, mDeviceTypeAddr.mType);
    AudioPort::toAudioPort(port);
    toAudioPortConfig(&port->active_config);
    port->id = mId;
    port->ext.device.type = mDeviceType;
    (void)audio_utils_strlcpy_zerofill(port->ext.device.address, mAddress.c_str());
    port->ext.device.type = mDeviceTypeAddr.mType;
    (void)audio_utils_strlcpy_zerofill(port->ext.device.address, mDeviceTypeAddr.getAddress());
}

void DeviceDescriptorBase::dump(std::string *dst, int spaces, int index,
@@ -86,10 +86,11 @@ void DeviceDescriptorBase::dump(std::string *dst, int spaces, int index,
    }

    dst->append(base::StringPrintf("%*s- type: %-48s\n",
            spaces, "", ::android::toString(mDeviceType).c_str()));
            spaces, "", ::android::toString(mDeviceTypeAddr.mType).c_str()));

    if (mAddress.size() != 0) {
        dst->append(base::StringPrintf("%*s- address: %-32s\n", spaces, "", mAddress.c_str()));
    if (mDeviceTypeAddr.mAddress.size() != 0) {
        dst->append(base::StringPrintf(
                "%*s- address: %-32s\n", spaces, "", mDeviceTypeAddr.getAddress()));
    }
    AudioPort::dump(dst, spaces, verbose);
}
@@ -97,15 +98,15 @@ void DeviceDescriptorBase::dump(std::string *dst, int spaces, int index,
std::string DeviceDescriptorBase::toString() const
{
    std::stringstream sstream;
    sstream << "type:0x" << std::hex << type() << ",@:" << mAddress;
    sstream << "type:0x" << std::hex << type() << ",@:" << mDeviceTypeAddr.mAddress;
    return sstream.str();
}

void DeviceDescriptorBase::log() const
{
    ALOGI("Device id:%d type:0x%08X:%s, addr:%s", mId,  mDeviceType,
          ::android::toString(mDeviceType).c_str(),
          mAddress.c_str());
    ALOGI("Device id:%d type:0x%08X:%s, addr:%s", mId,  mDeviceTypeAddr.mType,
          ::android::toString(mDeviceTypeAddr.mType).c_str(),
          mDeviceTypeAddr.getAddress());

    AudioPort::log("  ");
}
@@ -115,8 +116,7 @@ bool DeviceDescriptorBase::equals(const sp<DeviceDescriptorBase> &other) const
    return other != nullptr &&
           static_cast<const AudioPort*>(this)->equals(other) &&
           static_cast<const AudioPortConfig*>(this)->equals(other) &&
           mAddress.compare(other->address()) == 0 &&
           mDeviceType == other->type();
           mDeviceTypeAddr.equals(other->mDeviceTypeAddr);
}

status_t DeviceDescriptorBase::writeToParcel(Parcel *parcel) const
@@ -124,8 +124,7 @@ status_t DeviceDescriptorBase::writeToParcel(Parcel *parcel) const
    status_t status = NO_ERROR;
    if ((status = AudioPort::writeToParcel(parcel)) != NO_ERROR) return status;
    if ((status = AudioPortConfig::writeToParcel(parcel)) != NO_ERROR) return status;
    if ((status = parcel->writeUtf8AsUtf16(mAddress)) != NO_ERROR) return status;
    if ((status = parcel->writeUint32(mDeviceType)) != NO_ERROR) return status;
    if ((status = parcel->writeParcelable(mDeviceTypeAddr)) != NO_ERROR) return status;
    return status;
}

@@ -134,8 +133,7 @@ status_t DeviceDescriptorBase::readFromParcel(const Parcel *parcel)
    status_t status = NO_ERROR;
    if ((status = AudioPort::readFromParcel(parcel)) != NO_ERROR) return status;
    if ((status = AudioPortConfig::readFromParcel(parcel)) != NO_ERROR) return status;
    if ((status = parcel->readUtf8FromUtf16(&mAddress)) != NO_ERROR) return status;
    if ((status = parcel->readUint32(&mDeviceType)) != NO_ERROR) return status;
    if ((status = parcel->readParcelable(&mDeviceTypeAddr)) != NO_ERROR) return status;
    return status;
}

+6 −5
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <binder/Parcel.h>
#include <binder/Parcelable.h>
#include <media/AudioPort.h>
#include <media/AudioDeviceTypeAddr.h>
#include <utils/Errors.h>
#include <cutils/config_utils.h>
#include <system/audio.h>
@@ -34,9 +35,10 @@ public:

    virtual ~DeviceDescriptorBase() {}

    audio_devices_t type() const { return mDeviceType; }
    std::string address() const { return mAddress; }
    void setAddress(const std::string &address) { mAddress = address; }
    audio_devices_t type() const { return mDeviceTypeAddr.mType; }
    std::string address() const { return mDeviceTypeAddr.mAddress; }
    void setAddress(const std::string &address) { mDeviceTypeAddr.mAddress = address; }
    const AudioDeviceTypeAddr& getDeviceTypeAddr() const { return mDeviceTypeAddr; }

    // AudioPortConfig
    virtual sp<AudioPort> getAudioPort() const {
@@ -59,8 +61,7 @@ public:
    status_t readFromParcel(const Parcel* parcel) override;

protected:
    std::string mAddress{""};
    audio_devices_t     mDeviceType;
    AudioDeviceTypeAddr mDeviceTypeAddr;
};

} // namespace android
+2 −2
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ bool DeviceDescriptor::equals(const sp<DeviceDescriptor>& other) const
        return false;
    }

    return (mDeviceType == other->mDeviceType) && (mAddress == other->mAddress) &&
    return mDeviceTypeAddr.equals(other->mDeviceTypeAddr) &&
           checkEqual(mEncodedFormats, other->mEncodedFormats);
}

@@ -135,7 +135,7 @@ void DeviceDescriptor::toAudioPortConfig(struct audio_port_config *dstConfig,

void DeviceDescriptor::toAudioPort(struct audio_port *port) const
{
    ALOGV("DeviceDescriptor::toAudioPort() handle %d type %08x", mId, mDeviceType);
    ALOGV("DeviceDescriptor::toAudioPort() handle %d type %08x", mId, mDeviceTypeAddr.mType);
    DeviceDescriptorBase::toAudioPort(port);
    port->ext.device.hw_module = getModuleHandle();
}