• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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()28 aaudio_policy_t AudioGlobal_getMMapPolicy() {
29   return g_MMapPolicy;
30 }
31 
AudioGlobal_setMMapPolicy(aaudio_policy_t policy)32 aaudio_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)50 const 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";
75 }
76 
AudioGlobal_convertFormatToText(aaudio_format_t format)77 const char* AudioGlobal_convertFormatToText(aaudio_format_t format) {
78       switch (format) {
79         AAUDIO_CASE_ENUM(AAUDIO_FORMAT_UNSPECIFIED);
80         AAUDIO_CASE_ENUM(AAUDIO_FORMAT_INVALID);
81         AAUDIO_CASE_ENUM(AAUDIO_FORMAT_PCM_I16);
82         AAUDIO_CASE_ENUM(AAUDIO_FORMAT_PCM_FLOAT);
83         AAUDIO_CASE_ENUM(AAUDIO_FORMAT_PCM_I24_PACKED);
84         AAUDIO_CASE_ENUM(AAUDIO_FORMAT_PCM_I32);
85     }
86     return "Unrecognized";
87 }
88 
AudioGlobal_convertDirectionToText(aaudio_direction_t direction)89 const char* AudioGlobal_convertDirectionToText(aaudio_direction_t direction) {
90       switch (direction) {
91         AAUDIO_CASE_ENUM(AAUDIO_DIRECTION_INPUT);
92         AAUDIO_CASE_ENUM(AAUDIO_DIRECTION_OUTPUT);
93     }
94     return "Unrecognized";
95 }
96 
AudioGlobal_convertPerformanceModeToText(aaudio_performance_mode_t mode)97 const char* AudioGlobal_convertPerformanceModeToText(aaudio_performance_mode_t mode) {
98       switch (mode) {
99         AAUDIO_CASE_ENUM(AAUDIO_PERFORMANCE_MODE_POWER_SAVING);
100         AAUDIO_CASE_ENUM(AAUDIO_PERFORMANCE_MODE_NONE);
101         AAUDIO_CASE_ENUM(AAUDIO_PERFORMANCE_MODE_LOW_LATENCY);
102     }
103     return "Unrecognized";
104 }
105 
AudioGlobal_convertSharingModeToText(aaudio_sharing_mode_t mode)106 const char* AudioGlobal_convertSharingModeToText(aaudio_sharing_mode_t mode) {
107       switch (mode) {
108         AAUDIO_CASE_ENUM(AAUDIO_SHARING_MODE_SHARED);
109         AAUDIO_CASE_ENUM(AAUDIO_SHARING_MODE_EXCLUSIVE);
110     }
111     return "Unrecognized";
112 }
113 
AudioGlobal_convertStreamStateToText(aaudio_stream_state_t state)114 const char* AudioGlobal_convertStreamStateToText(aaudio_stream_state_t state) {
115       switch (state) {
116         AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_UNINITIALIZED);
117         AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_UNKNOWN);
118         AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_OPEN);
119         AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_STARTING);
120         AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_STARTED);
121         AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_PAUSING);
122         AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_PAUSED);
123         AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_FLUSHING);
124         AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_FLUSHED);
125         AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_STOPPING);
126         AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_STOPPED);
127         AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_CLOSING);
128         AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_CLOSED);
129         AAUDIO_CASE_ENUM(AAUDIO_STREAM_STATE_DISCONNECTED);
130     }
131     return "Unrecognized";
132 }
133 
134 #undef AAUDIO_CASE_ENUM
135 
136 }  // namespace aaudio
137