| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 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_EXAMPLE_ARGS_PARSER_H | 
 | 18 | #define AAUDIO_EXAMPLE_ARGS_PARSER_H | 
 | 19 |  | 
| Phil Burk | 67ed9da | 2017-09-06 16:26:52 -0700 | [diff] [blame] | 20 | #define MAX_CHANNELS                     8 | 
 | 21 |  | 
| Phil Burk | 4e98efa | 2018-02-05 18:41:55 -0800 | [diff] [blame] | 22 | //#include <cctype> | 
 | 23 | #include <dlfcn.h> | 
| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 24 | #include <unistd.h> | 
 | 25 | #include <stdio.h> | 
 | 26 | #include <stdlib.h> | 
 | 27 |  | 
 | 28 | #include <aaudio/AAudio.h> | 
 | 29 | #include <aaudio/AAudioTesting.h> | 
| Phil Burk | a5222e2 | 2017-07-28 13:31:14 -0700 | [diff] [blame] | 30 |  | 
 | 31 | #include "AAudioExampleUtils.h" | 
| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 32 |  | 
| Phil Burk | 4e98efa | 2018-02-05 18:41:55 -0800 | [diff] [blame] | 33 |  | 
 | 34 | static void (*s_setUsage)(AAudioStreamBuilder* builder, aaudio_usage_t usage) = nullptr; | 
 | 35 | static void (*s_setContentType)(AAudioStreamBuilder* builder, | 
 | 36 |                                 aaudio_content_type_t contentType) = nullptr; | 
 | 37 | static void (*s_setInputPreset)(AAudioStreamBuilder* builder, | 
 | 38 |                                 aaudio_input_preset_t inputPreset) = nullptr; | 
 | 39 |  | 
 | 40 | static bool s_loadAttempted = false; | 
 | 41 | static aaudio_usage_t (*s_getUsage)(AAudioStream *stream) = nullptr; | 
 | 42 | static aaudio_content_type_t (*s_getContentType)(AAudioStream *stream) = nullptr; | 
 | 43 | static aaudio_input_preset_t (*s_getInputPreset)(AAudioStream *stream) = nullptr; | 
 | 44 |  | 
 | 45 | // Link to test functions in shared library. | 
 | 46 | static void loadFutureFunctions() { | 
 | 47 |     if (s_loadAttempted)  return; // only try once | 
 | 48 |     s_loadAttempted = true; | 
 | 49 |  | 
 | 50 |     void *handle = dlopen("libaaudio.so", RTLD_NOW); | 
 | 51 |     if (handle != nullptr) { | 
 | 52 |         s_setUsage = (void (*)(AAudioStreamBuilder *, aaudio_usage_t)) | 
 | 53 |                 dlsym(handle, "AAudioStreamBuilder_setUsage"); | 
 | 54 |         if (s_setUsage == nullptr) goto error; | 
 | 55 |  | 
 | 56 |         s_setContentType = (void (*)(AAudioStreamBuilder *, aaudio_content_type_t)) | 
 | 57 |                 dlsym(handle, "AAudioStreamBuilder_setContentType"); | 
 | 58 |         if (s_setContentType == nullptr) goto error; | 
 | 59 |  | 
 | 60 |         s_setInputPreset = (void (*)(AAudioStreamBuilder *, aaudio_input_preset_t)) | 
 | 61 |                 dlsym(handle, "AAudioStreamBuilder_setInputPreset"); | 
 | 62 |         if (s_setInputPreset == nullptr) goto error; | 
 | 63 |  | 
 | 64 |         s_getUsage = (aaudio_usage_t (*)(AAudioStream *)) | 
 | 65 |                 dlsym(handle, "AAudioStream_getUsage"); | 
 | 66 |         if (s_getUsage == nullptr) goto error; | 
 | 67 |  | 
 | 68 |         s_getContentType = (aaudio_content_type_t (*)(AAudioStream *)) | 
 | 69 |                 dlsym(handle, "AAudioStream_getContentType"); | 
 | 70 |         if (s_getContentType == nullptr) goto error; | 
 | 71 |  | 
 | 72 |         s_getInputPreset = (aaudio_input_preset_t (*)(AAudioStream *)) | 
 | 73 |                 dlsym(handle, "AAudioStream_getInputPreset"); | 
 | 74 |         if (s_getInputPreset == nullptr) goto error; | 
 | 75 |     } | 
 | 76 |     return; | 
 | 77 |  | 
 | 78 | error: | 
 | 79 |     // prevent any calls to these functions | 
 | 80 |     s_setUsage = nullptr; | 
 | 81 |     s_setContentType = nullptr; | 
 | 82 |     s_setInputPreset = nullptr; | 
 | 83 |     s_getUsage = nullptr; | 
 | 84 |     s_getContentType = nullptr; | 
 | 85 |     s_getInputPreset = nullptr; | 
 | 86 |     dlclose(handle); | 
 | 87 |     return; | 
 | 88 | } | 
 | 89 |  | 
| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 90 | class AAudioParameters { | 
 | 91 | public: | 
 | 92 |  | 
 | 93 |     /** | 
 | 94 |      * This is also known as samplesPerFrame. | 
 | 95 |      */ | 
 | 96 |     int32_t getChannelCount() const { | 
 | 97 |         return mChannelCount; | 
 | 98 |     } | 
 | 99 |  | 
 | 100 |     void setChannelCount(int32_t channelCount) { | 
| Phil Burk | 67ed9da | 2017-09-06 16:26:52 -0700 | [diff] [blame] | 101 |         if (channelCount > MAX_CHANNELS) { | 
 | 102 |             printf("Sorry, MAX of %d channels!\n", MAX_CHANNELS); | 
 | 103 |             channelCount = MAX_CHANNELS; | 
 | 104 |         } | 
| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 105 |         mChannelCount = channelCount; | 
 | 106 |     } | 
 | 107 |  | 
 | 108 |     int32_t getSampleRate() const { | 
 | 109 |         return mSampleRate; | 
 | 110 |     } | 
 | 111 |  | 
 | 112 |     void setSampleRate(int32_t sampleRate) { | 
 | 113 |         mSampleRate = sampleRate; | 
 | 114 |     } | 
 | 115 |  | 
 | 116 |     aaudio_format_t getFormat() const { | 
 | 117 |         return mFormat; | 
 | 118 |     } | 
 | 119 |  | 
 | 120 |     void setFormat(aaudio_format_t format) { | 
 | 121 |         mFormat = format; | 
 | 122 |     } | 
 | 123 |  | 
 | 124 |     aaudio_sharing_mode_t getSharingMode() const { | 
 | 125 |         return mSharingMode; | 
 | 126 |     } | 
 | 127 |  | 
 | 128 |     void setSharingMode(aaudio_sharing_mode_t sharingMode) { | 
 | 129 |         mSharingMode = sharingMode; | 
 | 130 |     } | 
 | 131 |  | 
 | 132 |     int32_t getBufferCapacity() const { | 
 | 133 |         return mBufferCapacity; | 
 | 134 |     } | 
 | 135 |  | 
 | 136 |     void setBufferCapacity(int32_t frames) { | 
 | 137 |         mBufferCapacity = frames; | 
 | 138 |     } | 
 | 139 |  | 
 | 140 |     int32_t getPerformanceMode() const { | 
 | 141 |         return mPerformanceMode; | 
 | 142 |     } | 
 | 143 |  | 
 | 144 |     void setPerformanceMode(aaudio_performance_mode_t performanceMode) { | 
 | 145 |         mPerformanceMode = performanceMode; | 
 | 146 |     } | 
 | 147 |  | 
| Phil Burk | 6d6f3f6 | 2018-01-12 17:27:54 -0800 | [diff] [blame] | 148 |     aaudio_usage_t getUsage() const { | 
 | 149 |         return mUsage; | 
 | 150 |     } | 
 | 151 |  | 
 | 152 |     void setUsage(aaudio_usage_t usage) { | 
 | 153 |         mUsage = usage; | 
 | 154 |     } | 
 | 155 |  | 
 | 156 |     aaudio_content_type_t getContentType() const { | 
 | 157 |         return mContentType; | 
 | 158 |     } | 
 | 159 |  | 
 | 160 |     void setContentType(aaudio_content_type_t contentType) { | 
 | 161 |         mContentType = contentType; | 
 | 162 |     } | 
 | 163 |  | 
 | 164 |     aaudio_input_preset_t getInputPreset() const { | 
 | 165 |         return mInputPreset; | 
 | 166 |     } | 
 | 167 |  | 
 | 168 |     void setInputPreset(aaudio_input_preset_t inputPreset) { | 
 | 169 |         mInputPreset = inputPreset; | 
 | 170 |     } | 
 | 171 |  | 
| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 172 |     int32_t getDeviceId() const { | 
 | 173 |         return mDeviceId; | 
 | 174 |     } | 
 | 175 |  | 
 | 176 |     void setDeviceId(int32_t deviceId) { | 
 | 177 |         mDeviceId = deviceId; | 
 | 178 |     } | 
 | 179 |  | 
 | 180 |     int32_t getNumberOfBursts() const { | 
 | 181 |         return mNumberOfBursts; | 
 | 182 |     } | 
 | 183 |  | 
 | 184 |     void setNumberOfBursts(int32_t numBursts) { | 
 | 185 |         mNumberOfBursts = numBursts; | 
 | 186 |     } | 
 | 187 |  | 
 | 188 |     /** | 
 | 189 |      * Apply these parameters to a stream builder. | 
 | 190 |      * @param builder | 
 | 191 |      */ | 
 | 192 |     void applyParameters(AAudioStreamBuilder *builder) const { | 
 | 193 |         AAudioStreamBuilder_setChannelCount(builder, mChannelCount); | 
 | 194 |         AAudioStreamBuilder_setFormat(builder, mFormat); | 
 | 195 |         AAudioStreamBuilder_setSampleRate(builder, mSampleRate); | 
 | 196 |         AAudioStreamBuilder_setBufferCapacityInFrames(builder, mBufferCapacity); | 
 | 197 |         AAudioStreamBuilder_setDeviceId(builder, mDeviceId); | 
 | 198 |         AAudioStreamBuilder_setSharingMode(builder, mSharingMode); | 
 | 199 |         AAudioStreamBuilder_setPerformanceMode(builder, mPerformanceMode); | 
| Phil Burk | 4e98efa | 2018-02-05 18:41:55 -0800 | [diff] [blame] | 200 |  | 
 | 201 |         // Call P functions if supported. | 
 | 202 |         loadFutureFunctions(); | 
 | 203 |         if (s_setUsage != nullptr) { | 
 | 204 |             s_setUsage(builder, mUsage); | 
 | 205 |         } else if (mUsage != AAUDIO_UNSPECIFIED){ | 
 | 206 |             printf("WARNING: setUsage not supported"); | 
 | 207 |         } | 
 | 208 |         if (s_setContentType != nullptr) { | 
 | 209 |             s_setContentType(builder, mContentType); | 
 | 210 |         } else if (mUsage != AAUDIO_UNSPECIFIED){ | 
 | 211 |             printf("WARNING: setContentType not supported"); | 
 | 212 |         } | 
 | 213 |         if (s_setInputPreset != nullptr) { | 
 | 214 |             s_setInputPreset(builder, mInputPreset); | 
 | 215 |         } else if (mUsage != AAUDIO_UNSPECIFIED){ | 
 | 216 |             printf("WARNING: setInputPreset not supported"); | 
 | 217 |         } | 
| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 218 |     } | 
 | 219 |  | 
 | 220 | private: | 
 | 221 |     int32_t                    mChannelCount    = AAUDIO_UNSPECIFIED; | 
 | 222 |     aaudio_format_t            mFormat          = AAUDIO_FORMAT_UNSPECIFIED; | 
 | 223 |     int32_t                    mSampleRate      = AAUDIO_UNSPECIFIED; | 
 | 224 |  | 
 | 225 |     int32_t                    mBufferCapacity  = AAUDIO_UNSPECIFIED; | 
 | 226 |     int32_t                    mDeviceId        = AAUDIO_UNSPECIFIED; | 
 | 227 |     aaudio_sharing_mode_t      mSharingMode     = AAUDIO_SHARING_MODE_SHARED; | 
 | 228 |     aaudio_performance_mode_t  mPerformanceMode = AAUDIO_PERFORMANCE_MODE_NONE; | 
 | 229 |  | 
| Phil Burk | 6d6f3f6 | 2018-01-12 17:27:54 -0800 | [diff] [blame] | 230 |     aaudio_usage_t             mUsage           = AAUDIO_UNSPECIFIED; | 
 | 231 |     aaudio_content_type_t      mContentType     = AAUDIO_UNSPECIFIED; | 
 | 232 |     aaudio_input_preset_t      mInputPreset     = AAUDIO_UNSPECIFIED; | 
 | 233 |  | 
| Phil Burk | fcf9efd | 2017-07-14 08:25:08 -0700 | [diff] [blame] | 234 |     int32_t                    mNumberOfBursts  = AAUDIO_UNSPECIFIED; | 
| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 235 | }; | 
 | 236 |  | 
 | 237 | class AAudioArgsParser : public AAudioParameters { | 
 | 238 | public: | 
 | 239 |     AAudioArgsParser() = default; | 
 | 240 |     ~AAudioArgsParser() = default; | 
 | 241 |  | 
 | 242 |     enum { | 
 | 243 |         DEFAULT_DURATION_SECONDS = 5 | 
 | 244 |     }; | 
 | 245 |  | 
 | 246 |     /** | 
 | 247 |      * @param arg | 
 | 248 |      * @return true if the argument was not handled | 
 | 249 |      */ | 
 | 250 |     bool parseArg(const char *arg) { | 
 | 251 |         bool unrecognized = false; | 
 | 252 |         if (arg[0] == '-') { | 
 | 253 |             char option = arg[1]; | 
 | 254 |             switch (option) { | 
 | 255 |                 case 'b': | 
 | 256 |                     setBufferCapacity(atoi(&arg[2])); | 
 | 257 |                     break; | 
 | 258 |                 case 'c': | 
 | 259 |                     setChannelCount(atoi(&arg[2])); | 
 | 260 |                     break; | 
 | 261 |                 case 'd': | 
| Phil Burk | e008d02 | 2017-08-23 12:56:15 -0700 | [diff] [blame] | 262 |                     setDeviceId(atoi(&arg[2])); | 
 | 263 |                     break; | 
| Phil Burk | dd574ca | 2018-04-04 14:41:28 -0700 | [diff] [blame] | 264 |                 case 'f': | 
 | 265 |                     setFormat(atoi(&arg[2])); | 
 | 266 |                     break; | 
| Phil Burk | 6d6f3f6 | 2018-01-12 17:27:54 -0800 | [diff] [blame] | 267 |                 case 'i': | 
 | 268 |                     setInputPreset(atoi(&arg[2])); | 
| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 269 |                     break; | 
| Phil Burk | fcf9efd | 2017-07-14 08:25:08 -0700 | [diff] [blame] | 270 |                 case 'm': { | 
 | 271 |                     aaudio_policy_t policy = AAUDIO_POLICY_AUTO; | 
 | 272 |                     if (strlen(arg) > 2) { | 
 | 273 |                         policy = atoi(&arg[2]); | 
 | 274 |                     } | 
| Kevin Rocard | 9dcd34f | 2018-06-13 16:19:36 -0700 | [diff] [blame^] | 275 |                     if (!AAudio_setMMapPolicy(policy)) { | 
 | 276 |                         printf("ERROR: invalid MMAP policy mode %i\n", policy); | 
 | 277 |                     } | 
| Phil Burk | fcf9efd | 2017-07-14 08:25:08 -0700 | [diff] [blame] | 278 |                 } break; | 
| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 279 |                 case 'n': | 
 | 280 |                     setNumberOfBursts(atoi(&arg[2])); | 
 | 281 |                     break; | 
 | 282 |                 case 'p': | 
 | 283 |                     setPerformanceMode(parsePerformanceMode(arg[2])); | 
 | 284 |                     break; | 
 | 285 |                 case 'r': | 
 | 286 |                     setSampleRate(atoi(&arg[2])); | 
 | 287 |                     break; | 
| Phil Burk | 6d6f3f6 | 2018-01-12 17:27:54 -0800 | [diff] [blame] | 288 |                 case 's': | 
 | 289 |                     mDurationSeconds = atoi(&arg[2]); | 
 | 290 |                     break; | 
 | 291 |                 case 'u': | 
 | 292 |                     setUsage(atoi(&arg[2])); | 
 | 293 |                     break; | 
| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 294 |                 case 'x': | 
 | 295 |                     setSharingMode(AAUDIO_SHARING_MODE_EXCLUSIVE); | 
 | 296 |                     break; | 
| Phil Burk | 6d6f3f6 | 2018-01-12 17:27:54 -0800 | [diff] [blame] | 297 |                 case 'y': | 
 | 298 |                     setContentType(atoi(&arg[2])); | 
 | 299 |                     break; | 
| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 300 |                 default: | 
 | 301 |                     unrecognized = true; | 
 | 302 |                     break; | 
 | 303 |             } | 
 | 304 |         } | 
 | 305 |         return unrecognized; | 
 | 306 |     } | 
 | 307 |  | 
 | 308 |     /** | 
 | 309 |      * | 
 | 310 |      * @param argc | 
 | 311 |      * @param argv | 
 | 312 |      * @return true if an unrecognized argument was passed | 
 | 313 |      */ | 
 | 314 |     bool parseArgs(int argc, const char **argv) { | 
 | 315 |         for (int i = 1; i < argc; i++) { | 
 | 316 |             const char *arg = argv[i]; | 
 | 317 |             if (parseArg(arg)) { | 
 | 318 |                 usage(); | 
 | 319 |                 return true; | 
 | 320 |             } | 
 | 321 |  | 
 | 322 |         } | 
 | 323 |         return false; | 
 | 324 |     } | 
 | 325 |  | 
 | 326 |     static void usage() { | 
| Phil Burk | 6d6f3f6 | 2018-01-12 17:27:54 -0800 | [diff] [blame] | 327 |         printf("-c{channels} -d{deviceId} -m{mmapPolicy} -n{burstsPerBuffer} -p{perfMode}"); | 
 | 328 |         printf(" -r{rate} -s{seconds} -x\n"); | 
| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 329 |         printf("      Default values are UNSPECIFIED unless otherwise stated.\n"); | 
 | 330 |         printf("      -b{bufferCapacity} frames\n"); | 
 | 331 |         printf("      -c{channels} for example 2 for stereo\n"); | 
| Phil Burk | e008d02 | 2017-08-23 12:56:15 -0700 | [diff] [blame] | 332 |         printf("      -d{deviceId} default is %d\n", AAUDIO_UNSPECIFIED); | 
| Phil Burk | dd574ca | 2018-04-04 14:41:28 -0700 | [diff] [blame] | 333 |         printf("      -f{0|1|2} set format\n"); | 
 | 334 |         printf("          0 = UNSPECIFIED\n"); | 
 | 335 |         printf("          1 = PCM_I16\n"); | 
 | 336 |         printf("          2 = FLOAT\n"); | 
| Phil Burk | 6d6f3f6 | 2018-01-12 17:27:54 -0800 | [diff] [blame] | 337 |         printf("      -i{inputPreset} eg. 5 for AAUDIO_INPUT_PRESET_CAMCORDER\n"); | 
| Phil Burk | fcf9efd | 2017-07-14 08:25:08 -0700 | [diff] [blame] | 338 |         printf("      -m{0|1|2|3} set MMAP policy\n"); | 
| Phil Burk | 6d6f3f6 | 2018-01-12 17:27:54 -0800 | [diff] [blame] | 339 |         printf("          0 = _UNSPECIFIED, use aaudio.mmap_policy system property, default\n"); | 
 | 340 |         printf("          1 = _NEVER, never use MMAP\n"); | 
 | 341 |         printf("          2 = _AUTO, use MMAP if available, default for -m with no number\n"); | 
 | 342 |         printf("          3 = _ALWAYS, use MMAP or fail\n"); | 
| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 343 |         printf("      -n{numberOfBursts} for setBufferSize\n"); | 
 | 344 |         printf("      -p{performanceMode} set output AAUDIO_PERFORMANCE_MODE*, default NONE\n"); | 
 | 345 |         printf("          n for _NONE\n"); | 
 | 346 |         printf("          l for _LATENCY\n"); | 
 | 347 |         printf("          p for _POWER_SAVING;\n"); | 
 | 348 |         printf("      -r{sampleRate} for example 44100\n"); | 
| Phil Burk | 6d6f3f6 | 2018-01-12 17:27:54 -0800 | [diff] [blame] | 349 |         printf("      -s{duration} in seconds, default is %d\n", DEFAULT_DURATION_SECONDS); | 
 | 350 |         printf("      -u{usage} eg. 14 for AAUDIO_USAGE_GAME\n"); | 
| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 351 |         printf("      -x to use EXCLUSIVE mode\n"); | 
| Phil Burk | 6d6f3f6 | 2018-01-12 17:27:54 -0800 | [diff] [blame] | 352 |         printf("      -y{contentType} eg. 1 for AAUDIO_CONTENT_TYPE_SPEECH\n"); | 
| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 353 |     } | 
 | 354 |  | 
 | 355 |     static aaudio_performance_mode_t parsePerformanceMode(char c) { | 
 | 356 |         aaudio_performance_mode_t mode = AAUDIO_PERFORMANCE_MODE_NONE; | 
 | 357 |         switch (c) { | 
 | 358 |             case 'n': | 
 | 359 |                 mode = AAUDIO_PERFORMANCE_MODE_NONE; | 
 | 360 |                 break; | 
 | 361 |             case 'l': | 
 | 362 |                 mode = AAUDIO_PERFORMANCE_MODE_LOW_LATENCY; | 
 | 363 |                 break; | 
 | 364 |             case 'p': | 
 | 365 |                 mode = AAUDIO_PERFORMANCE_MODE_POWER_SAVING; | 
 | 366 |                 break; | 
 | 367 |             default: | 
| Kevin Rocard | 9dcd34f | 2018-06-13 16:19:36 -0700 | [diff] [blame^] | 368 |                 printf("ERROR: invalid performance mode %c\n", c); | 
| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 369 |                 break; | 
 | 370 |         } | 
 | 371 |         return mode; | 
 | 372 |     } | 
 | 373 |  | 
 | 374 |     /** | 
 | 375 |      * Print stream parameters in comparison with requested values. | 
 | 376 |      * @param stream | 
 | 377 |      */ | 
| Phil Burk | a5222e2 | 2017-07-28 13:31:14 -0700 | [diff] [blame] | 378 |     void compareWithStream(AAudioStream *stream) const { | 
| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 379 |  | 
 | 380 |         printf("  DeviceId:     requested = %d, actual = %d\n", | 
 | 381 |                getDeviceId(), AAudioStream_getDeviceId(stream)); | 
 | 382 |  | 
 | 383 |         aaudio_stream_state_t state = AAudioStream_getState(stream); | 
 | 384 |         printf("  State:        %s\n", AAudio_convertStreamStateToText(state)); | 
 | 385 |  | 
 | 386 |         // Check to see what kind of stream we actually got. | 
 | 387 |         printf("  SampleRate:   requested = %d, actual = %d\n", | 
 | 388 |                getSampleRate(), AAudioStream_getSampleRate(stream)); | 
 | 389 |  | 
 | 390 |         printf("  ChannelCount: requested = %d, actual = %d\n", | 
 | 391 |                getChannelCount(), AAudioStream_getChannelCount(stream)); | 
 | 392 |  | 
 | 393 |         printf("  DataFormat:   requested = %d, actual = %d\n", | 
 | 394 |                getFormat(), AAudioStream_getFormat(stream)); | 
 | 395 |  | 
 | 396 |         int32_t framesPerBurst = AAudioStream_getFramesPerBurst(stream); | 
 | 397 |         int32_t sizeFrames = AAudioStream_getBufferSizeInFrames(stream); | 
 | 398 |         printf("  Buffer:       burst     = %d\n", framesPerBurst); | 
 | 399 |         if (framesPerBurst > 0) { | 
 | 400 |             printf("  Buffer:       size      = %d = (%d * %d) + %d\n", | 
 | 401 |                    sizeFrames, | 
 | 402 |                    (sizeFrames / framesPerBurst), | 
 | 403 |                    framesPerBurst, | 
 | 404 |                    (sizeFrames % framesPerBurst)); | 
 | 405 |         } | 
 | 406 |         printf("  Capacity:     requested = %d, actual = %d\n", getBufferCapacity(), | 
 | 407 |                AAudioStream_getBufferCapacityInFrames(stream)); | 
 | 408 |  | 
 | 409 |         printf("  SharingMode:  requested = %s, actual = %s\n", | 
 | 410 |                getSharingModeText(getSharingMode()), | 
 | 411 |                getSharingModeText(AAudioStream_getSharingMode(stream))); | 
 | 412 |  | 
 | 413 |         printf("  PerformanceMode: requested = %d, actual = %d\n", | 
 | 414 |                getPerformanceMode(), AAudioStream_getPerformanceMode(stream)); | 
| Phil Burk | 6d6f3f6 | 2018-01-12 17:27:54 -0800 | [diff] [blame] | 415 |  | 
| Phil Burk | 4e98efa | 2018-02-05 18:41:55 -0800 | [diff] [blame] | 416 |         loadFutureFunctions(); | 
| Phil Burk | 6d6f3f6 | 2018-01-12 17:27:54 -0800 | [diff] [blame] | 417 |  | 
| Phil Burk | 4e98efa | 2018-02-05 18:41:55 -0800 | [diff] [blame] | 418 |         if (s_setUsage != nullptr) { | 
 | 419 |             printf("  Usage:        requested = %d, actual = %d\n", | 
 | 420 |                    getUsage(), s_getUsage(stream)); | 
 | 421 |         } | 
 | 422 |         if (s_getContentType != nullptr) { | 
 | 423 |             printf("  ContentType:  requested = %d, actual = %d\n", | 
 | 424 |                    getContentType(), s_getContentType(stream)); | 
 | 425 |         } | 
 | 426 |  | 
 | 427 |         if (AAudioStream_getDirection(stream) == AAUDIO_DIRECTION_INPUT | 
 | 428 |             && s_getInputPreset != nullptr) { | 
 | 429 |                 printf("  InputPreset:  requested = %d, actual = %d\n", | 
 | 430 |                        getInputPreset(), s_getInputPreset(stream)); | 
| Phil Burk | 6d6f3f6 | 2018-01-12 17:27:54 -0800 | [diff] [blame] | 431 |         } | 
 | 432 |  | 
| Phil Burk | 4479523 | 2017-06-30 16:27:38 -0700 | [diff] [blame] | 433 |         printf("  Is MMAP used? %s\n", AAudioStream_isMMapUsed(stream) | 
 | 434 |                ? "yes" : "no"); | 
 | 435 |  | 
 | 436 |     } | 
 | 437 |  | 
 | 438 |     int32_t getDurationSeconds() const { | 
 | 439 |         return mDurationSeconds; | 
 | 440 |     } | 
 | 441 |  | 
 | 442 |     void setDurationSeconds(int32_t seconds) { | 
 | 443 |         mDurationSeconds = seconds; | 
 | 444 |     } | 
 | 445 |  | 
 | 446 | private: | 
 | 447 |     int32_t      mDurationSeconds = DEFAULT_DURATION_SECONDS; | 
 | 448 | }; | 
 | 449 |  | 
 | 450 | #endif // AAUDIO_EXAMPLE_ARGS_PARSER_H |