1 /* 2 * Copyright (C) 2019 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 #include <aaudio/AAudio.h> 17 #include <aaudio/AAudioTesting.h> 18 19 #include "AudioGlobal.h" 20 21 /****************************************** 22 * Static globals. 23 */ 24 namespace aaudio { 25 26 static aaudio_policy_t g_MMapPolicy = AAUDIO_UNSPECIFIED; 27 AudioGlobal_getMMapPolicy()28aaudio_policy_t AudioGlobal_getMMapPolicy() { 29 return g_MMapPolicy; 30 } 31 AudioGlobal_setMMapPolicy(aaudio_policy_t policy)32aaudio_result_t AudioGlobal_setMMapPolicy(aaudio_policy_t policy) { 33 aaudio_result_t result = AAUDIO_OK; 34 switch(policy) { 35 case AAUDIO_UNSPECIFIED: 36 case AAUDIO_POLICY_NEVER: 37 case AAUDIO_POLICY_AUTO: 38 case AAUDIO_POLICY_ALWAYS: 39 g_MMapPolicy = policy; 40 break; 41 default: 42 result = AAUDIO_ERROR_ILLEGAL_ARGUMENT; 43 break; 44 } 45 return result; 46 } 47 48 #define AAUDIO_CASE_ENUM(name) case name: return #name 49 AudioGlobal_convertResultToText(aaudio_result_t returnCode)50const char* AudioGlobal_convertResultToText(aaudio_result_t returnCode) { 51 switch (returnCode) { 52 AAUDIO_CASE_ENUM(AAUDIO_OK); 53 AAUDIO_CASE_ENUM(AAUDIO_ERROR_DISCONNECTED); 54 AAUDIO_CASE_ENUM(AAUDIO_ERROR_ILLEGAL_ARGUMENT); 55 // reserved 56 AAUDIO_CASE_ENUM(AAUDIO_ERROR_INTERNAL); 57 AAUDIO_CASE_ENUM(AAUDIO_ERROR_INVALID_STATE); 58 // reserved 59 // reserved 60 AAUDIO_CASE_ENUM(AAUDIO_ERROR_INVALID_HANDLE); 61 // reserved 62 AAUDIO_CASE_ENUM(AAUDIO_ERROR_UNIMPLEMENTED); 63 AAUDIO_CASE_ENUM(AAUDIO_ERROR_UNAVAILABLE); 64 AAUDIO_CASE_ENUM(AAUDIO_ERROR_NO_FREE_HANDLES); 65 AAUDIO_CASE_ENUM(AAUDIO_ERROR_NO_MEMORY); 66 AAUDIO_CASE_ENUM(AAUDIO_ERROR_NULL); 67 AAUDIO_CASE_ENUM(AAUDIO_ERROR_TIMEOUT); 68 AAUDIO_CASE_ENUM(AAUDIO_ERROR_WOULD_BLOCK); 69 AAUDIO_CASE_ENUM(AAUDIO_ERROR_INVALID_FORMAT); 70 AAUDIO_CASE_ENUM(AAUDIO_ERROR_OUT_OF_RANGE); 71 AAUDIO_CASE_ENUM(AAUDIO_ERROR_NO_SERVICE); 72 AAUDIO_CASE_ENUM(AAUDIO_ERROR_INVALID_RATE); 73 } 74 return "Unrecognized AAudio error."; 75 } 76 AudioGlobal_convertStreamStateToText(aaudio_stream_state_t state)77const char* AudioGlobal_convertStreamStateToText(aaudio_stream_state_t state) { 78 switch (state) { 79 AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_UNINITIALIZED); 80 AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_UNKNOWN); 81 AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_OPEN); 82 AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_STARTING); 83 AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_STARTED); 84 AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_PAUSING); 85 AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_PAUSED); 86 AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_FLUSHING); 87 AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_FLUSHED); 88 AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_STOPPING); 89 AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_STOPPED); 90 AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_DISCONNECTED); 91 AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_CLOSING); 92 AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_CLOSED); 93 } 94 return "Unrecognized AAudio state."; 95 } 96 97 #undef AAUDIO_CASE_ENUM 98 99 } // namespace aaudio 100