• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 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 #include <dlfcn.h>
18 #include <oboe/Utilities.h>
19 #include "common/OboeDebug.h"
20 #include "AAudioLoader.h"
21 
22 #define LIB_AAUDIO_NAME "libaaudio.so"
23 
24 namespace oboe {
25 
~AAudioLoader()26 AAudioLoader::~AAudioLoader() {
27     // Issue 360: thread_local variables with non-trivial destructors
28     // will cause segfaults if the containing library is dlclose()ed on
29     // devices running M or newer, or devices before M when using a static STL.
30     // The simple workaround is to not call dlclose.
31     // https://github.com/android/ndk/wiki/Changelog-r22#known-issues
32     //
33     // The libaaudio and libaaudioclient do not use thread_local.
34     // But, to be safe, we should avoid dlclose() if possible.
35     // Because AAudioLoader is a static Singleton, we can safely skip
36     // calling dlclose() without causing a resource leak.
37     LOGI("%s() dlclose(%s) not called, OK", __func__, LIB_AAUDIO_NAME);
38 }
39 
getInstance()40 AAudioLoader* AAudioLoader::getInstance() {
41     static AAudioLoader instance;
42     return &instance;
43 }
44 
open()45 int AAudioLoader::open() {
46     if (mLibHandle != nullptr) {
47         return 0;
48     }
49 
50     // Use RTLD_NOW to avoid the unpredictable behavior that RTLD_LAZY can cause.
51     // Also resolving all the links now will prevent a run-time penalty later.
52     mLibHandle = dlopen(LIB_AAUDIO_NAME, RTLD_NOW);
53     if (mLibHandle == nullptr) {
54         LOGI("AAudioLoader::open() could not find " LIB_AAUDIO_NAME);
55         return -1; // TODO review return code
56     } else {
57         LOGD("AAudioLoader():  dlopen(%s) returned %p", LIB_AAUDIO_NAME, mLibHandle);
58     }
59 
60     // Load all the function pointers.
61     createStreamBuilder        = load_I_PPB("AAudio_createStreamBuilder");
62     builder_openStream         = load_I_PBPPS("AAudioStreamBuilder_openStream");
63 
64     builder_setChannelCount    = load_V_PBI("AAudioStreamBuilder_setChannelCount");
65     if (builder_setChannelCount == nullptr) {
66         // Use old deprecated alias if needed.
67         builder_setChannelCount = load_V_PBI("AAudioStreamBuilder_setSamplesPerFrame");
68     }
69 
70     builder_setBufferCapacityInFrames = load_V_PBI("AAudioStreamBuilder_setBufferCapacityInFrames");
71     builder_setDeviceId        = load_V_PBI("AAudioStreamBuilder_setDeviceId");
72     builder_setDirection       = load_V_PBI("AAudioStreamBuilder_setDirection");
73     builder_setFormat          = load_V_PBI("AAudioStreamBuilder_setFormat");
74     builder_setFramesPerDataCallback = load_V_PBI("AAudioStreamBuilder_setFramesPerDataCallback");
75     builder_setSharingMode     = load_V_PBI("AAudioStreamBuilder_setSharingMode");
76     builder_setPerformanceMode = load_V_PBI("AAudioStreamBuilder_setPerformanceMode");
77     builder_setSampleRate      = load_V_PBI("AAudioStreamBuilder_setSampleRate");
78 
79     if (getSdkVersion() >= __ANDROID_API_P__){
80         builder_setUsage       = load_V_PBI("AAudioStreamBuilder_setUsage");
81         builder_setContentType = load_V_PBI("AAudioStreamBuilder_setContentType");
82         builder_setInputPreset = load_V_PBI("AAudioStreamBuilder_setInputPreset");
83         builder_setSessionId   = load_V_PBI("AAudioStreamBuilder_setSessionId");
84     }
85 
86     if (getSdkVersion() >= __ANDROID_API_S__){
87         builder_setPackageName       = load_V_PBCPH("AAudioStreamBuilder_setPackageName");
88         builder_setAttributionTag    = load_V_PBCPH("AAudioStreamBuilder_setAttributionTag");
89     }
90 
91     if (getSdkVersion() >= __ANDROID_API_S_V2__) {
92         builder_setChannelMask = load_V_PBU("AAudioStreamBuilder_setChannelMask");
93     }
94 
95     builder_delete             = load_I_PB("AAudioStreamBuilder_delete");
96 
97 
98     builder_setDataCallback    = load_V_PBPDPV("AAudioStreamBuilder_setDataCallback");
99     builder_setErrorCallback   = load_V_PBPEPV("AAudioStreamBuilder_setErrorCallback");
100 
101     stream_read                = load_I_PSPVIL("AAudioStream_read");
102 
103     stream_write               = load_I_PSCPVIL("AAudioStream_write");
104 
105     stream_waitForStateChange  = load_I_PSTPTL("AAudioStream_waitForStateChange");
106 
107     stream_getTimestamp        = load_I_PSKPLPL("AAudioStream_getTimestamp");
108 
109     stream_getChannelCount     = load_I_PS("AAudioStream_getChannelCount");
110     if (stream_getChannelCount == nullptr) {
111         // Use old alias if needed.
112         stream_getChannelCount    = load_I_PS("AAudioStream_getSamplesPerFrame");
113     }
114 
115     stream_close               = load_I_PS("AAudioStream_close");
116 
117     stream_getBufferSize       = load_I_PS("AAudioStream_getBufferSizeInFrames");
118     stream_getDeviceId         = load_I_PS("AAudioStream_getDeviceId");
119     stream_getBufferCapacity   = load_I_PS("AAudioStream_getBufferCapacityInFrames");
120     stream_getFormat           = load_F_PS("AAudioStream_getFormat");
121     stream_getFramesPerBurst   = load_I_PS("AAudioStream_getFramesPerBurst");
122     stream_getFramesRead       = load_L_PS("AAudioStream_getFramesRead");
123     stream_getFramesWritten    = load_L_PS("AAudioStream_getFramesWritten");
124     stream_getPerformanceMode  = load_I_PS("AAudioStream_getPerformanceMode");
125     stream_getSampleRate       = load_I_PS("AAudioStream_getSampleRate");
126     stream_getSharingMode      = load_I_PS("AAudioStream_getSharingMode");
127     stream_getState            = load_I_PS("AAudioStream_getState");
128     stream_getXRunCount        = load_I_PS("AAudioStream_getXRunCount");
129 
130     stream_requestStart        = load_I_PS("AAudioStream_requestStart");
131     stream_requestPause        = load_I_PS("AAudioStream_requestPause");
132     stream_requestFlush        = load_I_PS("AAudioStream_requestFlush");
133     stream_requestStop         = load_I_PS("AAudioStream_requestStop");
134 
135     stream_setBufferSize       = load_I_PSI("AAudioStream_setBufferSizeInFrames");
136 
137     convertResultToText        = load_CPH_I("AAudio_convertResultToText");
138 
139     if (getSdkVersion() >= __ANDROID_API_P__){
140         stream_getUsage        = load_I_PS("AAudioStream_getUsage");
141         stream_getContentType  = load_I_PS("AAudioStream_getContentType");
142         stream_getInputPreset  = load_I_PS("AAudioStream_getInputPreset");
143         stream_getSessionId    = load_I_PS("AAudioStream_getSessionId");
144     }
145 
146     if (getSdkVersion() >= __ANDROID_API_S_V2__) {
147         stream_getChannelMask = load_U_PS("AAudioStream_getChannelMask");
148     }
149     return 0;
150 }
151 
AAudioLoader_check(void * proc,const char * functionName)152 static void AAudioLoader_check(void *proc, const char *functionName) {
153     if (proc == nullptr) {
154         LOGW("AAudioLoader could not find %s", functionName);
155     }
156 }
157 
load_I_PPB(const char * functionName)158 AAudioLoader::signature_I_PPB AAudioLoader::load_I_PPB(const char *functionName) {
159     void *proc = dlsym(mLibHandle, functionName);
160     AAudioLoader_check(proc, functionName);
161     return reinterpret_cast<signature_I_PPB>(proc);
162 }
163 
load_CPH_I(const char * functionName)164 AAudioLoader::signature_CPH_I AAudioLoader::load_CPH_I(const char *functionName) {
165     void *proc = dlsym(mLibHandle, functionName);
166     AAudioLoader_check(proc, functionName);
167     return reinterpret_cast<signature_CPH_I>(proc);
168 }
169 
load_V_PBI(const char * functionName)170 AAudioLoader::signature_V_PBI AAudioLoader::load_V_PBI(const char *functionName) {
171     void *proc = dlsym(mLibHandle, functionName);
172     AAudioLoader_check(proc, functionName);
173     return reinterpret_cast<signature_V_PBI>(proc);
174 }
175 
load_V_PBCPH(const char * functionName)176 AAudioLoader::signature_V_PBCPH AAudioLoader::load_V_PBCPH(const char *functionName) {
177     void *proc = dlsym(mLibHandle, functionName);
178     AAudioLoader_check(proc, functionName);
179     return reinterpret_cast<signature_V_PBCPH>(proc);
180 }
181 
load_V_PBPDPV(const char * functionName)182 AAudioLoader::signature_V_PBPDPV AAudioLoader::load_V_PBPDPV(const char *functionName) {
183     void *proc = dlsym(mLibHandle, functionName);
184     AAudioLoader_check(proc, functionName);
185     return reinterpret_cast<signature_V_PBPDPV>(proc);
186 }
187 
load_V_PBPEPV(const char * functionName)188 AAudioLoader::signature_V_PBPEPV AAudioLoader::load_V_PBPEPV(const char *functionName) {
189     void *proc = dlsym(mLibHandle, functionName);
190     AAudioLoader_check(proc, functionName);
191     return reinterpret_cast<signature_V_PBPEPV>(proc);
192 }
193 
load_I_PSI(const char * functionName)194 AAudioLoader::signature_I_PSI AAudioLoader::load_I_PSI(const char *functionName) {
195     void *proc = dlsym(mLibHandle, functionName);
196     AAudioLoader_check(proc, functionName);
197     return reinterpret_cast<signature_I_PSI>(proc);
198 }
199 
load_I_PS(const char * functionName)200 AAudioLoader::signature_I_PS AAudioLoader::load_I_PS(const char *functionName) {
201     void *proc = dlsym(mLibHandle, functionName);
202     AAudioLoader_check(proc, functionName);
203     return reinterpret_cast<signature_I_PS>(proc);
204 }
205 
load_L_PS(const char * functionName)206 AAudioLoader::signature_L_PS AAudioLoader::load_L_PS(const char *functionName) {
207     void *proc = dlsym(mLibHandle, functionName);
208     AAudioLoader_check(proc, functionName);
209     return reinterpret_cast<signature_L_PS>(proc);
210 }
211 
load_F_PS(const char * functionName)212 AAudioLoader::signature_F_PS AAudioLoader::load_F_PS(const char *functionName) {
213     void *proc = dlsym(mLibHandle, functionName);
214     AAudioLoader_check(proc, functionName);
215     return reinterpret_cast<signature_F_PS>(proc);
216 }
217 
load_B_PS(const char * functionName)218 AAudioLoader::signature_B_PS AAudioLoader::load_B_PS(const char *functionName) {
219     void *proc = dlsym(mLibHandle, functionName);
220     AAudioLoader_check(proc, functionName);
221     return reinterpret_cast<signature_B_PS>(proc);
222 }
223 
load_I_PB(const char * functionName)224 AAudioLoader::signature_I_PB AAudioLoader::load_I_PB(const char *functionName) {
225     void *proc = dlsym(mLibHandle, functionName);
226     AAudioLoader_check(proc, functionName);
227     return reinterpret_cast<signature_I_PB>(proc);
228 }
229 
load_I_PBPPS(const char * functionName)230 AAudioLoader::signature_I_PBPPS AAudioLoader::load_I_PBPPS(const char *functionName) {
231     void *proc = dlsym(mLibHandle, functionName);
232     AAudioLoader_check(proc, functionName);
233     return reinterpret_cast<signature_I_PBPPS>(proc);
234 }
235 
load_I_PSCPVIL(const char * functionName)236 AAudioLoader::signature_I_PSCPVIL AAudioLoader::load_I_PSCPVIL(const char *functionName) {
237     void *proc = dlsym(mLibHandle, functionName);
238     AAudioLoader_check(proc, functionName);
239     return reinterpret_cast<signature_I_PSCPVIL>(proc);
240 }
241 
load_I_PSPVIL(const char * functionName)242 AAudioLoader::signature_I_PSPVIL AAudioLoader::load_I_PSPVIL(const char *functionName) {
243     void *proc = dlsym(mLibHandle, functionName);
244     AAudioLoader_check(proc, functionName);
245     return reinterpret_cast<signature_I_PSPVIL>(proc);
246 }
247 
load_I_PSTPTL(const char * functionName)248 AAudioLoader::signature_I_PSTPTL AAudioLoader::load_I_PSTPTL(const char *functionName) {
249     void *proc = dlsym(mLibHandle, functionName);
250     AAudioLoader_check(proc, functionName);
251     return reinterpret_cast<signature_I_PSTPTL>(proc);
252 }
253 
load_I_PSKPLPL(const char * functionName)254 AAudioLoader::signature_I_PSKPLPL AAudioLoader::load_I_PSKPLPL(const char *functionName) {
255     void *proc = dlsym(mLibHandle, functionName);
256     AAudioLoader_check(proc, functionName);
257     return reinterpret_cast<signature_I_PSKPLPL>(proc);
258 }
259 
load_V_PBU(const char * functionName)260 AAudioLoader::signature_V_PBU AAudioLoader::load_V_PBU(const char *functionName) {
261     void *proc = dlsym(mLibHandle, functionName);
262     AAudioLoader_check(proc, functionName);
263     return reinterpret_cast<signature_V_PBU>(proc);
264 }
265 
load_U_PS(const char * functionName)266 AAudioLoader::signature_U_PS AAudioLoader::load_U_PS(const char *functionName) {
267     void *proc = dlsym(mLibHandle, functionName);
268     AAudioLoader_check(proc, functionName);
269     return reinterpret_cast<signature_U_PS>(proc);
270 }
271 
272 // Ensure that all AAudio primitive data types are int32_t
273 #define ASSERT_INT32(type) static_assert(std::is_same<int32_t, type>::value, \
274 #type" must be int32_t")
275 
276 // Ensure that all AAudio primitive data types are uint32_t
277 #define ASSERT_UINT32(type) static_assert(std::is_same<uint32_t, type>::value, \
278 #type" must be uint32_t")
279 
280 #define ERRMSG "Oboe constants must match AAudio constants."
281 
282 // These asserts help verify that the Oboe definitions match the equivalent AAudio definitions.
283 // This code is in this .cpp file so it only gets tested once.
284 #ifdef AAUDIO_AAUDIO_H
285 
286     ASSERT_INT32(aaudio_stream_state_t);
287     ASSERT_INT32(aaudio_direction_t);
288     ASSERT_INT32(aaudio_format_t);
289     ASSERT_INT32(aaudio_data_callback_result_t);
290     ASSERT_INT32(aaudio_result_t);
291     ASSERT_INT32(aaudio_sharing_mode_t);
292     ASSERT_INT32(aaudio_performance_mode_t);
293 
294     static_assert((int32_t)StreamState::Uninitialized == AAUDIO_STREAM_STATE_UNINITIALIZED, ERRMSG);
295     static_assert((int32_t)StreamState::Unknown == AAUDIO_STREAM_STATE_UNKNOWN, ERRMSG);
296     static_assert((int32_t)StreamState::Open == AAUDIO_STREAM_STATE_OPEN, ERRMSG);
297     static_assert((int32_t)StreamState::Starting == AAUDIO_STREAM_STATE_STARTING, ERRMSG);
298     static_assert((int32_t)StreamState::Started == AAUDIO_STREAM_STATE_STARTED, ERRMSG);
299     static_assert((int32_t)StreamState::Pausing == AAUDIO_STREAM_STATE_PAUSING, ERRMSG);
300     static_assert((int32_t)StreamState::Paused == AAUDIO_STREAM_STATE_PAUSED, ERRMSG);
301     static_assert((int32_t)StreamState::Flushing == AAUDIO_STREAM_STATE_FLUSHING, ERRMSG);
302     static_assert((int32_t)StreamState::Flushed == AAUDIO_STREAM_STATE_FLUSHED, ERRMSG);
303     static_assert((int32_t)StreamState::Stopping == AAUDIO_STREAM_STATE_STOPPING, ERRMSG);
304     static_assert((int32_t)StreamState::Stopped == AAUDIO_STREAM_STATE_STOPPED, ERRMSG);
305     static_assert((int32_t)StreamState::Closing == AAUDIO_STREAM_STATE_CLOSING, ERRMSG);
306     static_assert((int32_t)StreamState::Closed == AAUDIO_STREAM_STATE_CLOSED, ERRMSG);
307     static_assert((int32_t)StreamState::Disconnected == AAUDIO_STREAM_STATE_DISCONNECTED, ERRMSG);
308 
309     static_assert((int32_t)Direction::Output == AAUDIO_DIRECTION_OUTPUT, ERRMSG);
310     static_assert((int32_t)Direction::Input == AAUDIO_DIRECTION_INPUT, ERRMSG);
311 
312     static_assert((int32_t)AudioFormat::Invalid == AAUDIO_FORMAT_INVALID, ERRMSG);
313     static_assert((int32_t)AudioFormat::Unspecified == AAUDIO_FORMAT_UNSPECIFIED, ERRMSG);
314     static_assert((int32_t)AudioFormat::I16 == AAUDIO_FORMAT_PCM_I16, ERRMSG);
315     static_assert((int32_t)AudioFormat::Float == AAUDIO_FORMAT_PCM_FLOAT, ERRMSG);
316 
317     static_assert((int32_t)DataCallbackResult::Continue == AAUDIO_CALLBACK_RESULT_CONTINUE, ERRMSG);
318     static_assert((int32_t)DataCallbackResult::Stop == AAUDIO_CALLBACK_RESULT_STOP, ERRMSG);
319 
320     static_assert((int32_t)Result::OK == AAUDIO_OK, ERRMSG);
321     static_assert((int32_t)Result::ErrorBase == AAUDIO_ERROR_BASE, ERRMSG);
322     static_assert((int32_t)Result::ErrorDisconnected == AAUDIO_ERROR_DISCONNECTED, ERRMSG);
323     static_assert((int32_t)Result::ErrorIllegalArgument == AAUDIO_ERROR_ILLEGAL_ARGUMENT, ERRMSG);
324     static_assert((int32_t)Result::ErrorInternal == AAUDIO_ERROR_INTERNAL, ERRMSG);
325     static_assert((int32_t)Result::ErrorInvalidState == AAUDIO_ERROR_INVALID_STATE, ERRMSG);
326     static_assert((int32_t)Result::ErrorInvalidHandle == AAUDIO_ERROR_INVALID_HANDLE, ERRMSG);
327     static_assert((int32_t)Result::ErrorUnimplemented == AAUDIO_ERROR_UNIMPLEMENTED, ERRMSG);
328     static_assert((int32_t)Result::ErrorUnavailable == AAUDIO_ERROR_UNAVAILABLE, ERRMSG);
329     static_assert((int32_t)Result::ErrorNoFreeHandles == AAUDIO_ERROR_NO_FREE_HANDLES, ERRMSG);
330     static_assert((int32_t)Result::ErrorNoMemory == AAUDIO_ERROR_NO_MEMORY, ERRMSG);
331     static_assert((int32_t)Result::ErrorNull == AAUDIO_ERROR_NULL, ERRMSG);
332     static_assert((int32_t)Result::ErrorTimeout == AAUDIO_ERROR_TIMEOUT, ERRMSG);
333     static_assert((int32_t)Result::ErrorWouldBlock == AAUDIO_ERROR_WOULD_BLOCK, ERRMSG);
334     static_assert((int32_t)Result::ErrorInvalidFormat == AAUDIO_ERROR_INVALID_FORMAT, ERRMSG);
335     static_assert((int32_t)Result::ErrorOutOfRange == AAUDIO_ERROR_OUT_OF_RANGE, ERRMSG);
336     static_assert((int32_t)Result::ErrorNoService == AAUDIO_ERROR_NO_SERVICE, ERRMSG);
337     static_assert((int32_t)Result::ErrorInvalidRate == AAUDIO_ERROR_INVALID_RATE, ERRMSG);
338 
339     static_assert((int32_t)SharingMode::Exclusive == AAUDIO_SHARING_MODE_EXCLUSIVE, ERRMSG);
340     static_assert((int32_t)SharingMode::Shared == AAUDIO_SHARING_MODE_SHARED, ERRMSG);
341 
342     static_assert((int32_t)PerformanceMode::None == AAUDIO_PERFORMANCE_MODE_NONE, ERRMSG);
343     static_assert((int32_t)PerformanceMode::PowerSaving
344             == AAUDIO_PERFORMANCE_MODE_POWER_SAVING, ERRMSG);
345     static_assert((int32_t)PerformanceMode::LowLatency
346             == AAUDIO_PERFORMANCE_MODE_LOW_LATENCY, ERRMSG);
347 
348 // The aaudio_ usage, content and input_preset types were added in NDK 17,
349 // which is the first version to support Android Pie (API 28).
350 #if __NDK_MAJOR__ >= 17
351 
352     ASSERT_INT32(aaudio_usage_t);
353     ASSERT_INT32(aaudio_content_type_t);
354     ASSERT_INT32(aaudio_input_preset_t);
355 
356     static_assert((int32_t)Usage::Media == AAUDIO_USAGE_MEDIA, ERRMSG);
357     static_assert((int32_t)Usage::VoiceCommunication == AAUDIO_USAGE_VOICE_COMMUNICATION, ERRMSG);
358     static_assert((int32_t)Usage::VoiceCommunicationSignalling
359             == AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING, ERRMSG);
360     static_assert((int32_t)Usage::Alarm == AAUDIO_USAGE_ALARM, ERRMSG);
361     static_assert((int32_t)Usage::Notification == AAUDIO_USAGE_NOTIFICATION, ERRMSG);
362     static_assert((int32_t)Usage::NotificationRingtone == AAUDIO_USAGE_NOTIFICATION_RINGTONE, ERRMSG);
363     static_assert((int32_t)Usage::NotificationEvent == AAUDIO_USAGE_NOTIFICATION_EVENT, ERRMSG);
364     static_assert((int32_t)Usage::AssistanceAccessibility == AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY, ERRMSG);
365     static_assert((int32_t)Usage::AssistanceNavigationGuidance
366             == AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, ERRMSG);
367     static_assert((int32_t)Usage::AssistanceSonification == AAUDIO_USAGE_ASSISTANCE_SONIFICATION, ERRMSG);
368     static_assert((int32_t)Usage::Game == AAUDIO_USAGE_GAME, ERRMSG);
369     static_assert((int32_t)Usage::Assistant == AAUDIO_USAGE_ASSISTANT, ERRMSG);
370 
371     static_assert((int32_t)ContentType::Speech == AAUDIO_CONTENT_TYPE_SPEECH, ERRMSG);
372     static_assert((int32_t)ContentType::Music == AAUDIO_CONTENT_TYPE_MUSIC, ERRMSG);
373     static_assert((int32_t)ContentType::Movie == AAUDIO_CONTENT_TYPE_MOVIE, ERRMSG);
374     static_assert((int32_t)ContentType::Sonification == AAUDIO_CONTENT_TYPE_SONIFICATION, ERRMSG);
375 
376     static_assert((int32_t)InputPreset::Generic == AAUDIO_INPUT_PRESET_GENERIC, ERRMSG);
377     static_assert((int32_t)InputPreset::Camcorder == AAUDIO_INPUT_PRESET_CAMCORDER, ERRMSG);
378     static_assert((int32_t)InputPreset::VoiceRecognition == AAUDIO_INPUT_PRESET_VOICE_RECOGNITION, ERRMSG);
379     static_assert((int32_t)InputPreset::VoiceCommunication
380             == AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION, ERRMSG);
381     static_assert((int32_t)InputPreset::Unprocessed == AAUDIO_INPUT_PRESET_UNPROCESSED, ERRMSG);
382 
383     static_assert((int32_t)SessionId::None == AAUDIO_SESSION_ID_NONE, ERRMSG);
384     static_assert((int32_t)SessionId::Allocate == AAUDIO_SESSION_ID_ALLOCATE, ERRMSG);
385 
386 #endif // __NDK_MAJOR__ >= 17
387 
388 // The aaudio channel masks were added in NDK 24,
389 // which is the first version to support Android SC_V2 (API 32).
390 #if __NDK_MAJOR__ >= 24
391 
392     ASSERT_UINT32(aaudio_channel_mask_t);
393 
394     static_assert((uint32_t)ChannelMask::FrontLeft == AAUDIO_CHANNEL_FRONT_LEFT, ERRMSG);
395     static_assert((uint32_t)ChannelMask::FrontRight == AAUDIO_CHANNEL_FRONT_RIGHT, ERRMSG);
396     static_assert((uint32_t)ChannelMask::FrontCenter == AAUDIO_CHANNEL_FRONT_CENTER, ERRMSG);
397     static_assert((uint32_t)ChannelMask::LowFrequency == AAUDIO_CHANNEL_LOW_FREQUENCY, ERRMSG);
398     static_assert((uint32_t)ChannelMask::BackLeft == AAUDIO_CHANNEL_BACK_LEFT, ERRMSG);
399     static_assert((uint32_t)ChannelMask::BackRight == AAUDIO_CHANNEL_BACK_RIGHT, ERRMSG);
400     static_assert((uint32_t)ChannelMask::FrontLeftOfCenter == AAUDIO_CHANNEL_FRONT_LEFT_OF_CENTER, ERRMSG);
401     static_assert((uint32_t)ChannelMask::FrontRightOfCenter == AAUDIO_CHANNEL_FRONT_RIGHT_OF_CENTER, ERRMSG);
402     static_assert((uint32_t)ChannelMask::BackCenter == AAUDIO_CHANNEL_BACK_CENTER, ERRMSG);
403     static_assert((uint32_t)ChannelMask::SideLeft == AAUDIO_CHANNEL_SIDE_LEFT, ERRMSG);
404     static_assert((uint32_t)ChannelMask::SideRight == AAUDIO_CHANNEL_SIDE_RIGHT, ERRMSG);
405     static_assert((uint32_t)ChannelMask::TopCenter == AAUDIO_CHANNEL_TOP_CENTER, ERRMSG);
406     static_assert((uint32_t)ChannelMask::TopFrontLeft == AAUDIO_CHANNEL_TOP_FRONT_LEFT, ERRMSG);
407     static_assert((uint32_t)ChannelMask::TopFrontCenter == AAUDIO_CHANNEL_TOP_FRONT_CENTER, ERRMSG);
408     static_assert((uint32_t)ChannelMask::TopFrontRight == AAUDIO_CHANNEL_TOP_FRONT_RIGHT, ERRMSG);
409     static_assert((uint32_t)ChannelMask::TopBackLeft == AAUDIO_CHANNEL_TOP_BACK_LEFT, ERRMSG);
410     static_assert((uint32_t)ChannelMask::TopBackCenter == AAUDIO_CHANNEL_TOP_BACK_CENTER, ERRMSG);
411     static_assert((uint32_t)ChannelMask::TopBackRight == AAUDIO_CHANNEL_TOP_BACK_RIGHT, ERRMSG);
412     static_assert((uint32_t)ChannelMask::TopSideLeft == AAUDIO_CHANNEL_TOP_SIDE_LEFT, ERRMSG);
413     static_assert((uint32_t)ChannelMask::TopSideRight == AAUDIO_CHANNEL_TOP_SIDE_RIGHT, ERRMSG);
414     static_assert((uint32_t)ChannelMask::BottomFrontLeft == AAUDIO_CHANNEL_BOTTOM_FRONT_LEFT, ERRMSG);
415     static_assert((uint32_t)ChannelMask::BottomFrontCenter == AAUDIO_CHANNEL_BOTTOM_FRONT_CENTER, ERRMSG);
416     static_assert((uint32_t)ChannelMask::BottomFrontRight == AAUDIO_CHANNEL_BOTTOM_FRONT_RIGHT, ERRMSG);
417     static_assert((uint32_t)ChannelMask::LowFrequency2 == AAUDIO_CHANNEL_LOW_FREQUENCY_2, ERRMSG);
418     static_assert((uint32_t)ChannelMask::FrontWideLeft == AAUDIO_CHANNEL_FRONT_WIDE_LEFT, ERRMSG);
419     static_assert((uint32_t)ChannelMask::FrontWideRight == AAUDIO_CHANNEL_FRONT_WIDE_RIGHT, ERRMSG);
420     static_assert((uint32_t)ChannelMask::Mono == AAUDIO_CHANNEL_MONO, ERRMSG);
421     static_assert((uint32_t)ChannelMask::Stereo == AAUDIO_CHANNEL_STEREO, ERRMSG);
422     static_assert((uint32_t)ChannelMask::CM2Point1 == AAUDIO_CHANNEL_2POINT1, ERRMSG);
423     static_assert((uint32_t)ChannelMask::Tri == AAUDIO_CHANNEL_TRI, ERRMSG);
424     static_assert((uint32_t)ChannelMask::TriBack == AAUDIO_CHANNEL_TRI_BACK, ERRMSG);
425     static_assert((uint32_t)ChannelMask::CM3Point1 == AAUDIO_CHANNEL_3POINT1, ERRMSG);
426     static_assert((uint32_t)ChannelMask::CM2Point0Point2 == AAUDIO_CHANNEL_2POINT0POINT2, ERRMSG);
427     static_assert((uint32_t)ChannelMask::CM2Point1Point2 == AAUDIO_CHANNEL_2POINT1POINT2, ERRMSG);
428     static_assert((uint32_t)ChannelMask::CM3Point0Point2 == AAUDIO_CHANNEL_3POINT0POINT2, ERRMSG);
429     static_assert((uint32_t)ChannelMask::CM3Point1Point2 == AAUDIO_CHANNEL_3POINT1POINT2, ERRMSG);
430     static_assert((uint32_t)ChannelMask::Quad == AAUDIO_CHANNEL_QUAD, ERRMSG);
431     static_assert((uint32_t)ChannelMask::QuadSide == AAUDIO_CHANNEL_QUAD_SIDE, ERRMSG);
432     static_assert((uint32_t)ChannelMask::Surround == AAUDIO_CHANNEL_SURROUND, ERRMSG);
433     static_assert((uint32_t)ChannelMask::Penta == AAUDIO_CHANNEL_PENTA, ERRMSG);
434     static_assert((uint32_t)ChannelMask::CM5Point1 == AAUDIO_CHANNEL_5POINT1, ERRMSG);
435     static_assert((uint32_t)ChannelMask::CM5Point1Side == AAUDIO_CHANNEL_5POINT1_SIDE, ERRMSG);
436     static_assert((uint32_t)ChannelMask::CM6Point1 == AAUDIO_CHANNEL_6POINT1, ERRMSG);
437     static_assert((uint32_t)ChannelMask::CM7Point1 == AAUDIO_CHANNEL_7POINT1, ERRMSG);
438     static_assert((uint32_t)ChannelMask::CM5Point1Point2 == AAUDIO_CHANNEL_5POINT1POINT2, ERRMSG);
439     static_assert((uint32_t)ChannelMask::CM5Point1Point4 == AAUDIO_CHANNEL_5POINT1POINT4, ERRMSG);
440     static_assert((uint32_t)ChannelMask::CM7Point1Point2 == AAUDIO_CHANNEL_7POINT1POINT2, ERRMSG);
441     static_assert((uint32_t)ChannelMask::CM7Point1Point4 == AAUDIO_CHANNEL_7POINT1POINT4, ERRMSG);
442     static_assert((uint32_t)ChannelMask::CM9Point1Point4 == AAUDIO_CHANNEL_9POINT1POINT4, ERRMSG);
443     static_assert((uint32_t)ChannelMask::CM9Point1Point6 == AAUDIO_CHANNEL_9POINT1POINT6, ERRMSG);
444     static_assert((uint32_t)ChannelMask::FrontBack == AAUDIO_CHANNEL_FRONT_BACK, ERRMSG);
445 
446 #endif
447 
448 #endif // AAUDIO_AAUDIO_H
449 
450 } // namespace oboe
451