1 /* 2 * Copyright 2017 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 #ifndef AAUDIO_STREAM_PARAMETERS_H 18 #define AAUDIO_STREAM_PARAMETERS_H 19 20 #include <stdint.h> 21 22 #include <aaudio/AAudio.h> 23 #include <media/AudioContainers.h> 24 #include <utility/AAudioUtilities.h> 25 26 namespace aaudio { 27 28 class AAudioStreamParameters { 29 public: 30 AAudioStreamParameters() = default; 31 virtual ~AAudioStreamParameters() = default; 32 getDeviceIds()33 android::DeviceIdVector getDeviceIds() const { 34 return mDeviceIds; 35 } 36 setDeviceIds(const android::DeviceIdVector & deviceIds)37 void setDeviceIds(const android::DeviceIdVector& deviceIds) { 38 mDeviceIds = deviceIds; 39 } 40 getSampleRate()41 int32_t getSampleRate() const { 42 return mSampleRate; 43 } 44 setSampleRate(int32_t sampleRate)45 void setSampleRate(int32_t sampleRate) { 46 mSampleRate = sampleRate; 47 } 48 getSamplesPerFrame()49 int32_t getSamplesPerFrame() const { 50 return mSamplesPerFrame; 51 } 52 getFormat()53 audio_format_t getFormat() const { 54 return mAudioFormat; 55 } 56 setFormat(audio_format_t audioFormat)57 void setFormat(audio_format_t audioFormat) { 58 mAudioFormat = audioFormat; 59 } 60 getSharingMode()61 aaudio_sharing_mode_t getSharingMode() const { 62 return mSharingMode; 63 } 64 setSharingMode(aaudio_sharing_mode_t sharingMode)65 void setSharingMode(aaudio_sharing_mode_t sharingMode) { 66 mSharingMode = sharingMode; 67 } 68 getBufferCapacity()69 int32_t getBufferCapacity() const { 70 return mBufferCapacity; 71 } 72 setBufferCapacity(int32_t frames)73 void setBufferCapacity(int32_t frames) { 74 mBufferCapacity = frames; 75 } 76 getDirection()77 aaudio_direction_t getDirection() const { 78 return mDirection; 79 } 80 setDirection(aaudio_direction_t direction)81 void setDirection(aaudio_direction_t direction) { 82 mDirection = direction; 83 } 84 getUsage()85 aaudio_usage_t getUsage() const { 86 return mUsage; 87 } 88 setUsage(aaudio_usage_t usage)89 void setUsage(aaudio_usage_t usage) { 90 mUsage = usage; 91 } 92 getContentType()93 aaudio_content_type_t getContentType() const { 94 return mContentType; 95 } 96 setContentType(aaudio_content_type_t contentType)97 void setContentType(aaudio_content_type_t contentType) { 98 mContentType = contentType; 99 } 100 setTags(const std::set<std::string> & tags)101 void setTags(const std::set<std::string>& tags) { 102 mTags = tags; 103 } 104 getTags()105 const std::set<std::string>& getTags() const { 106 return mTags; 107 } 108 109 std::string getTagsAsString() const; 110 getSpatializationBehavior()111 aaudio_spatialization_behavior_t getSpatializationBehavior() const { 112 return mSpatializationBehavior; 113 } 114 setSpatializationBehavior(aaudio_spatialization_behavior_t spatializationBehavior)115 void setSpatializationBehavior(aaudio_spatialization_behavior_t spatializationBehavior) { 116 mSpatializationBehavior = spatializationBehavior; 117 } 118 isContentSpatialized()119 bool isContentSpatialized() const { 120 return mIsContentSpatialized; 121 } 122 setIsContentSpatialized(bool isSpatialized)123 void setIsContentSpatialized(bool isSpatialized) { 124 mIsContentSpatialized = isSpatialized; 125 } 126 getInputPreset()127 aaudio_input_preset_t getInputPreset() const { 128 return mInputPreset; 129 } 130 setInputPreset(aaudio_input_preset_t inputPreset)131 void setInputPreset(aaudio_input_preset_t inputPreset) { 132 mInputPreset = inputPreset; 133 } 134 getAllowedCapturePolicy()135 aaudio_allowed_capture_policy_t getAllowedCapturePolicy() const { 136 return mAllowedCapturePolicy; 137 } 138 setAllowedCapturePolicy(aaudio_allowed_capture_policy_t policy)139 void setAllowedCapturePolicy(aaudio_allowed_capture_policy_t policy) { 140 mAllowedCapturePolicy = policy; 141 } 142 getSessionId()143 aaudio_session_id_t getSessionId() const { 144 return mSessionId; 145 } 146 setSessionId(aaudio_session_id_t sessionId)147 void setSessionId(aaudio_session_id_t sessionId) { 148 mSessionId = sessionId; 149 } 150 isPrivacySensitive()151 bool isPrivacySensitive() const { 152 return mIsPrivacySensitive; 153 } 154 setPrivacySensitive(bool privacySensitive)155 void setPrivacySensitive(bool privacySensitive) { 156 mIsPrivacySensitive = privacySensitive; 157 } 158 getOpPackageName()159 const std::optional<std::string> getOpPackageName() const { 160 return mOpPackageName; 161 } 162 163 // TODO b/182392769: reexamine if Identity can be used setOpPackageName(const std::optional<std::string> & opPackageName)164 void setOpPackageName(const std::optional<std::string>& opPackageName) { 165 mOpPackageName = opPackageName; 166 } 167 getAttributionTag()168 const std::optional<std::string> getAttributionTag() const { 169 return mAttributionTag; 170 } 171 setAttributionTag(const std::optional<std::string> & attributionTag)172 void setAttributionTag(const std::optional<std::string>& attributionTag) { 173 mAttributionTag = attributionTag; 174 } 175 getChannelMask()176 aaudio_channel_mask_t getChannelMask() const { 177 return mChannelMask; 178 } 179 setChannelMask(aaudio_channel_mask_t channelMask)180 void setChannelMask(aaudio_channel_mask_t channelMask) { 181 mChannelMask = channelMask; 182 mSamplesPerFrame = AAudioConvert_channelMaskToCount(channelMask); 183 } 184 getHardwareSamplesPerFrame()185 int32_t getHardwareSamplesPerFrame() const { 186 return mHardwareSamplesPerFrame; 187 } 188 setHardwareSamplesPerFrame(int32_t hardwareSamplesPerFrame)189 void setHardwareSamplesPerFrame(int32_t hardwareSamplesPerFrame) { 190 mHardwareSamplesPerFrame = hardwareSamplesPerFrame; 191 } 192 getHardwareSampleRate()193 int32_t getHardwareSampleRate() const { 194 return mHardwareSampleRate; 195 } 196 setHardwareSampleRate(int32_t hardwareSampleRate)197 void setHardwareSampleRate(int32_t hardwareSampleRate) { 198 mHardwareSampleRate = hardwareSampleRate; 199 } 200 getHardwareFormat()201 audio_format_t getHardwareFormat() const { 202 return mHardwareAudioFormat; 203 } 204 setHardwareFormat(audio_format_t hardwareAudioFormat)205 void setHardwareFormat(audio_format_t hardwareAudioFormat) { 206 mHardwareAudioFormat = hardwareAudioFormat; 207 } 208 209 /** 210 * @return bytes per frame of getFormat() 211 */ calculateBytesPerFrame()212 int32_t calculateBytesPerFrame() const { 213 return getSamplesPerFrame() * audio_bytes_per_sample(getFormat()); 214 } 215 216 /** 217 * Copy variables defined in other AAudioStreamParameters instance to this one. 218 * @param other 219 */ 220 void copyFrom(const AAudioStreamParameters &other); 221 222 virtual aaudio_result_t validate() const; 223 224 void dump() const; 225 226 protected: 227 std::set<std::string> mTags; 228 229 private: 230 aaudio_result_t validateChannelMask() const; 231 232 int32_t mSamplesPerFrame = AAUDIO_UNSPECIFIED; 233 int32_t mSampleRate = AAUDIO_UNSPECIFIED; 234 android::DeviceIdVector mDeviceIds; 235 aaudio_sharing_mode_t mSharingMode = AAUDIO_SHARING_MODE_SHARED; 236 audio_format_t mAudioFormat = AUDIO_FORMAT_DEFAULT; 237 aaudio_direction_t mDirection = AAUDIO_DIRECTION_OUTPUT; 238 aaudio_usage_t mUsage = AAUDIO_UNSPECIFIED; 239 aaudio_content_type_t mContentType = AAUDIO_UNSPECIFIED; 240 aaudio_spatialization_behavior_t mSpatializationBehavior 241 = AAUDIO_UNSPECIFIED; 242 bool mIsContentSpatialized = false; 243 aaudio_input_preset_t mInputPreset = AAUDIO_UNSPECIFIED; 244 int32_t mBufferCapacity = AAUDIO_UNSPECIFIED; 245 aaudio_allowed_capture_policy_t mAllowedCapturePolicy = AAUDIO_UNSPECIFIED; 246 aaudio_session_id_t mSessionId = AAUDIO_SESSION_ID_NONE; 247 bool mIsPrivacySensitive = false; 248 std::optional<std::string> mOpPackageName = {}; 249 std::optional<std::string> mAttributionTag = {}; 250 aaudio_channel_mask_t mChannelMask = AAUDIO_UNSPECIFIED; 251 int mHardwareSamplesPerFrame 252 = AAUDIO_UNSPECIFIED; 253 int mHardwareSampleRate = AAUDIO_UNSPECIFIED; 254 audio_format_t mHardwareAudioFormat = AUDIO_FORMAT_DEFAULT; 255 }; 256 257 } /* namespace aaudio */ 258 259 #endif //AAUDIO_STREAM_PARAMETERS_H 260