AudioPort.h revision f129b03fa583d4cc26fd9c9171b8fb3b0ed8d4f4
1/* 2 * Copyright (C) 2015 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 <utils/String8.h> 20#include <utils/Vector.h> 21#include <utils/RefBase.h> 22#include <utils/Errors.h> 23#include <system/audio.h> 24#include <cutils/config_utils.h> 25 26namespace android { 27 28class HwModule; 29class AudioGain; 30 31class AudioPort : public virtual RefBase 32{ 33public: 34 AudioPort(const String8& name, audio_port_type_t type, 35 audio_port_role_t role); 36 virtual ~AudioPort() {} 37 38 virtual void attach(const sp<HwModule>& module); 39 bool isAttached() { return mModule != 0; } 40 41 static audio_port_handle_t getNextUniqueId(); 42 43 virtual void toAudioPort(struct audio_port *port) const; 44 45 void importAudioPort(const sp<AudioPort> port); 46 void clearCapabilities(); 47 48 void loadSamplingRates(char *name); 49 void loadFormats(char *name); 50 void loadOutChannels(char *name); 51 void loadInChannels(char *name); 52 53 audio_gain_mode_t loadGainMode(char *name); 54 void loadGain(cnode *root, int index); 55 virtual void loadGains(cnode *root); 56 57 // searches for an exact match 58 status_t checkExactSamplingRate(uint32_t samplingRate) const; 59 // searches for a compatible match, and returns the best match via updatedSamplingRate 60 status_t checkCompatibleSamplingRate(uint32_t samplingRate, 61 uint32_t *updatedSamplingRate) const; 62 // searches for an exact match 63 status_t checkExactChannelMask(audio_channel_mask_t channelMask) const; 64 // searches for a compatible match, currently implemented for input channel masks only 65 status_t checkCompatibleChannelMask(audio_channel_mask_t channelMask, 66 audio_channel_mask_t *updatedChannelMask) const; 67 68 status_t checkExactFormat(audio_format_t format) const; 69 // searches for a compatible match, currently implemented for input formats only 70 status_t checkCompatibleFormat(audio_format_t format, audio_format_t *updatedFormat) const; 71 status_t checkGain(const struct audio_gain_config *gainConfig, int index) const; 72 73 uint32_t pickSamplingRate() const; 74 audio_channel_mask_t pickChannelMask() const; 75 audio_format_t pickFormat() const; 76 77 static const audio_format_t sPcmFormatCompareTable[]; 78 static int compareFormatsGoodToBad( 79 const audio_format_t *format1, const audio_format_t *format2) { 80 // compareFormats sorts from bad to good, we reverse it here 81 return compareFormats(*format2, *format1); 82 } 83 static int compareFormats(audio_format_t format1, audio_format_t format2); 84 85 audio_module_handle_t getModuleHandle() const; 86 uint32_t getModuleVersion() const; 87 const char *getModuleName() const; 88 89 void dump(int fd, int spaces) const; 90 void log(const char* indent) const; 91 92 String8 mName; 93 audio_port_type_t mType; 94 audio_port_role_t mRole; 95 bool mUseInChannelMask; 96 // by convention, "0' in the first entry in mSamplingRates, mChannelMasks or mFormats 97 // indicates the supported parameters should be read from the output stream 98 // after it is opened for the first time 99 Vector <uint32_t> mSamplingRates; // supported sampling rates 100 Vector <audio_channel_mask_t> mChannelMasks; // supported channel masks 101 Vector <audio_format_t> mFormats; // supported audio formats 102 Vector < sp<AudioGain> > mGains; // gain controllers 103 sp<HwModule> mModule; // audio HW module exposing this I/O stream 104 uint32_t mFlags; // attribute flags (e.g primary output, 105 // direct output...). 106 107private: 108 static volatile int32_t mNextUniqueId; 109}; 110 111class AudioPortConfig : public virtual RefBase 112{ 113public: 114 AudioPortConfig(); 115 virtual ~AudioPortConfig() {} 116 117 status_t applyAudioPortConfig(const struct audio_port_config *config, 118 struct audio_port_config *backupConfig = NULL); 119 virtual void toAudioPortConfig(struct audio_port_config *dstConfig, 120 const struct audio_port_config *srcConfig = NULL) const = 0; 121 virtual sp<AudioPort> getAudioPort() const = 0; 122 uint32_t mSamplingRate; 123 audio_format_t mFormat; 124 audio_channel_mask_t mChannelMask; 125 struct audio_gain_config mGain; 126}; 127 128}; // namespace android 129