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(); 30 virtual ~AAudioStreamParameters(); 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 52 /** 53 * This is also known as channelCount. 54 */ setSamplesPerFrame(int32_t samplesPerFrame)55 void setSamplesPerFrame(int32_t samplesPerFrame) { 56 mSamplesPerFrame = samplesPerFrame; 57 } 58 getFormat()59 audio_format_t getFormat() const { 60 return mAudioFormat; 61 } 62 setFormat(audio_format_t audioFormat)63 void setFormat(audio_format_t audioFormat) { 64 mAudioFormat = audioFormat; 65 } 66 getSharingMode()67 aaudio_sharing_mode_t getSharingMode() const { 68 return mSharingMode; 69 } 70 setSharingMode(aaudio_sharing_mode_t sharingMode)71 void setSharingMode(aaudio_sharing_mode_t sharingMode) { 72 mSharingMode = sharingMode; 73 } 74 getBufferCapacity()75 int32_t getBufferCapacity() const { 76 return mBufferCapacity; 77 } 78 setBufferCapacity(int32_t frames)79 void setBufferCapacity(int32_t frames) { 80 mBufferCapacity = frames; 81 } 82 getDirection()83 aaudio_direction_t getDirection() const { 84 return mDirection; 85 } 86 setDirection(aaudio_direction_t direction)87 void setDirection(aaudio_direction_t direction) { 88 mDirection = direction; 89 } 90 getUsage()91 aaudio_usage_t getUsage() const { 92 return mUsage; 93 } 94 setUsage(aaudio_usage_t usage)95 void setUsage(aaudio_usage_t usage) { 96 mUsage = usage; 97 } 98 getContentType()99 aaudio_content_type_t getContentType() const { 100 return mContentType; 101 } 102 setContentType(aaudio_content_type_t contentType)103 void setContentType(aaudio_content_type_t contentType) { 104 mContentType = contentType; 105 } 106 getInputPreset()107 aaudio_input_preset_t getInputPreset() const { 108 return mInputPreset; 109 } 110 setInputPreset(aaudio_input_preset_t inputPreset)111 void setInputPreset(aaudio_input_preset_t inputPreset) { 112 mInputPreset = inputPreset; 113 } 114 getAllowedCapturePolicy()115 aaudio_allowed_capture_policy_t getAllowedCapturePolicy() const { 116 return mAllowedCapturePolicy; 117 } 118 setAllowedCapturePolicy(aaudio_allowed_capture_policy_t policy)119 void setAllowedCapturePolicy(aaudio_allowed_capture_policy_t policy) { 120 mAllowedCapturePolicy = policy; 121 } 122 getSessionId()123 aaudio_session_id_t getSessionId() const { 124 return mSessionId; 125 } 126 setSessionId(aaudio_session_id_t sessionId)127 void setSessionId(aaudio_session_id_t sessionId) { 128 mSessionId = sessionId; 129 } 130 isPrivacySensitive()131 bool isPrivacySensitive() const { 132 return mIsPrivacySensitive; 133 } 134 setPrivacySensitive(bool privacySensitive)135 void setPrivacySensitive(bool privacySensitive) { 136 mIsPrivacySensitive = privacySensitive; 137 } 138 getOpPackageName()139 const std::optional<std::string> getOpPackageName() const { 140 return mOpPackageName; 141 } 142 143 // TODO b/182392769: reexamine if Identity can be used setOpPackageName(const std::optional<std::string> opPackageName)144 void setOpPackageName(const std::optional<std::string> opPackageName) { 145 mOpPackageName = opPackageName; 146 } 147 getAttributionTag()148 const std::optional<std::string> getAttributionTag() const { 149 return mAttributionTag; 150 } 151 setAttributionTag(const std::optional<std::string> attributionTag)152 void setAttributionTag(const std::optional<std::string> attributionTag) { 153 mAttributionTag = attributionTag; 154 } 155 156 /** 157 * @return bytes per frame of getFormat() 158 */ calculateBytesPerFrame()159 int32_t calculateBytesPerFrame() const { 160 return getSamplesPerFrame() * audio_bytes_per_sample(getFormat()); 161 } 162 163 /** 164 * Copy variables defined in other AAudioStreamParameters instance to this one. 165 * @param other 166 */ 167 void copyFrom(const AAudioStreamParameters &other); 168 169 virtual aaudio_result_t validate() const; 170 171 void dump() const; 172 173 private: 174 int32_t mSamplesPerFrame = AAUDIO_UNSPECIFIED; 175 int32_t mSampleRate = AAUDIO_UNSPECIFIED; 176 int32_t mDeviceId = AAUDIO_UNSPECIFIED; 177 aaudio_sharing_mode_t mSharingMode = AAUDIO_SHARING_MODE_SHARED; 178 audio_format_t mAudioFormat = AUDIO_FORMAT_DEFAULT; 179 aaudio_direction_t mDirection = AAUDIO_DIRECTION_OUTPUT; 180 aaudio_usage_t mUsage = AAUDIO_UNSPECIFIED; 181 aaudio_content_type_t mContentType = AAUDIO_UNSPECIFIED; 182 aaudio_input_preset_t mInputPreset = AAUDIO_UNSPECIFIED; 183 int32_t mBufferCapacity = AAUDIO_UNSPECIFIED; 184 aaudio_allowed_capture_policy_t mAllowedCapturePolicy = AAUDIO_UNSPECIFIED; 185 aaudio_session_id_t mSessionId = AAUDIO_SESSION_ID_NONE; 186 bool mIsPrivacySensitive = false; 187 std::optional<std::string> mOpPackageName = {}; 188 std::optional<std::string> mAttributionTag = {}; 189 }; 190 191 } /* namespace aaudio */ 192 193 #endif //AAUDIO_STREAM_PARAMETERS_H 194