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