/* * Copyright (C) 2015 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. */ #pragma once #include #include #include #include #include #include namespace android { class HwModule; class AudioGain; class AudioPort : public virtual RefBase { public: AudioPort(const String8& name, audio_port_type_t type, audio_port_role_t role, const sp& module); virtual ~AudioPort() {} audio_port_handle_t getHandle() { return mId; } void attach(const sp& module); bool isAttached() { return mId != 0; } static audio_port_handle_t getNextUniqueId(); virtual void toAudioPort(struct audio_port *port) const; void importAudioPort(const sp port); void clearCapabilities(); void loadSamplingRates(char *name); void loadFormats(char *name); void loadOutChannels(char *name); void loadInChannels(char *name); audio_gain_mode_t loadGainMode(char *name); void loadGain(cnode *root, int index); virtual void loadGains(cnode *root); // searches for an exact match status_t checkExactSamplingRate(uint32_t samplingRate) const; // searches for a compatible match, and returns the best match via updatedSamplingRate status_t checkCompatibleSamplingRate(uint32_t samplingRate, uint32_t *updatedSamplingRate) const; // searches for an exact match status_t checkExactChannelMask(audio_channel_mask_t channelMask) const; // searches for a compatible match, currently implemented for input channel masks only status_t checkCompatibleChannelMask(audio_channel_mask_t channelMask) const; status_t checkFormat(audio_format_t format) const; status_t checkGain(const struct audio_gain_config *gainConfig, int index) const; uint32_t pickSamplingRate() const; audio_channel_mask_t pickChannelMask() const; audio_format_t pickFormat() const; static const audio_format_t sPcmFormatCompareTable[]; static int compareFormats(audio_format_t format1, audio_format_t format2); audio_module_handle_t getModuleHandle() const; void dump(int fd, int spaces) const; void log(const char* indent) const; String8 mName; audio_port_type_t mType; audio_port_role_t mRole; bool mUseInChannelMask; // by convention, "0' in the first entry in mSamplingRates, mChannelMasks or mFormats // indicates the supported parameters should be read from the output stream // after it is opened for the first time Vector mSamplingRates; // supported sampling rates Vector mChannelMasks; // supported channel masks Vector mFormats; // supported audio formats Vector < sp > mGains; // gain controllers sp mModule; // audio HW module exposing this I/O stream uint32_t mFlags; // attribute flags (e.g primary output, // direct output...). protected: //TODO - clarify the role of mId in this case, both an "attached" indicator // and a unique ID for identifying a port to the (upcoming) selection API, // and its relationship to the mId in AudioOutputDescriptor and AudioInputDescriptor. audio_port_handle_t mId; private: static volatile int32_t mNextUniqueId; }; class AudioPortConfig : public virtual RefBase { public: AudioPortConfig(); virtual ~AudioPortConfig() {} status_t applyAudioPortConfig(const struct audio_port_config *config, struct audio_port_config *backupConfig = NULL); virtual void toAudioPortConfig(struct audio_port_config *dstConfig, const struct audio_port_config *srcConfig = NULL) const = 0; virtual sp getAudioPort() const = 0; uint32_t mSamplingRate; audio_format_t mFormat; audio_channel_mask_t mChannelMask; struct audio_gain_config mGain; }; }; // namespace android