1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <vector> 20 21 #include <binder/Parcel.h> 22 #include <binder/Parcelable.h> 23 #include <media/AudioContainers.h> 24 #include <media/AudioPort.h> 25 #include <media/AudioDeviceTypeAddr.h> 26 #include <utils/Errors.h> 27 #include <cutils/config_utils.h> 28 #include <system/audio.h> 29 #include <system/audio_policy.h> 30 31 namespace android { 32 33 class DeviceDescriptorBase : public AudioPort, public AudioPortConfig 34 { 35 public: 36 // Note that empty name refers by convention to a generic device. 37 explicit DeviceDescriptorBase(audio_devices_t type); 38 DeviceDescriptorBase(audio_devices_t type, const std::string& address); 39 explicit DeviceDescriptorBase(const AudioDeviceTypeAddr& deviceTypeAddr); 40 ~DeviceDescriptorBase()41 virtual ~DeviceDescriptorBase() {} 42 type()43 audio_devices_t type() const { return mDeviceTypeAddr.mType; } address()44 std::string address() const { return mDeviceTypeAddr.mAddress; } setAddress(const std::string & address)45 void setAddress(const std::string &address) { mDeviceTypeAddr.mAddress = address; } getDeviceTypeAddr()46 const AudioDeviceTypeAddr& getDeviceTypeAddr() const { return mDeviceTypeAddr; } 47 48 // AudioPortConfig getAudioPort()49 virtual sp<AudioPort> getAudioPort() const { 50 return static_cast<AudioPort*>(const_cast<DeviceDescriptorBase*>(this)); 51 } 52 virtual void toAudioPortConfig(struct audio_port_config *dstConfig, 53 const struct audio_port_config *srcConfig = NULL) const; 54 55 // AudioPort 56 virtual void toAudioPort(struct audio_port *port) const; 57 58 status_t setEncapsulationModes(uint32_t encapsulationModes); 59 status_t setEncapsulationMetadataTypes(uint32_t encapsulationMetadataTypes); 60 61 void dump(std::string *dst, int spaces, int index, 62 const char* extraInfo = nullptr, bool verbose = true) const; 63 void log() const; 64 std::string toString() const; 65 66 bool equals(const sp<DeviceDescriptorBase>& other) const; 67 68 status_t writeToParcel(Parcel* parcel) const override; 69 status_t readFromParcel(const Parcel* parcel) override; 70 71 protected: 72 AudioDeviceTypeAddr mDeviceTypeAddr; 73 uint32_t mEncapsulationModes = 0; 74 uint32_t mEncapsulationMetadataTypes = 0; 75 }; 76 77 using DeviceDescriptorBaseVector = std::vector<sp<DeviceDescriptorBase>>; 78 79 /** 80 * Return human readable string for collection of DeviceDescriptorBase. 81 * For a DeviceDescriptorBase, it contains port id, audio device type and address. 82 */ 83 std::string toString(const DeviceDescriptorBaseVector& devices); 84 85 /** 86 * Return a set of device types and addresses from collection of DeviceDescriptorBase. 87 */ 88 AudioDeviceTypeAddrVector deviceTypeAddrsFromDescriptors(const DeviceDescriptorBaseVector& devices); 89 90 } // namespace android 91