Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 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 | #ifndef OBOE_OBOEDEFINITIONS_H |
| 18 | #define OBOE_OBOEDEFINITIONS_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | |
Glenn Kasten | 08ba52f | 2016-12-07 13:58:40 -0800 | [diff] [blame] | 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
| 26 | typedef int32_t oboe_handle_t; // negative handles are error codes |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 27 | typedef int32_t oboe_result_t; |
| 28 | typedef int32_t oboe_sample_rate_t; |
| 29 | /** This is used for small quantities such as the number of frames in a buffer. */ |
| 30 | typedef int32_t oboe_size_frames_t; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 31 | /** This is used for small quantities such as the number of bytes in a frame. */ |
| 32 | typedef int32_t oboe_size_bytes_t; |
| 33 | /** |
| 34 | * This is used for large quantities, such as the number of frames that have |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 35 | * been played since a stream was started. |
| 36 | * At 48000 Hz, a 32-bit integer would wrap around in just over 12 hours. |
| 37 | */ |
| 38 | typedef int64_t oboe_position_frames_t; |
| 39 | |
| 40 | typedef int64_t oboe_nanoseconds_t; |
| 41 | typedef uint32_t oboe_audio_format_t; |
| 42 | |
| 43 | /** |
| 44 | * This is used to represent a value that has not been specified. |
| 45 | * For example, an application could use OBOE_UNSPECIFIED to indicate |
| 46 | * that is did not not care what the specific value of a parameter was |
| 47 | * and would accept whatever it was given. |
| 48 | */ |
| 49 | #define OBOE_UNSPECIFIED 0 |
| 50 | #define OBOE_NANOS_PER_MICROSECOND ((int64_t)1000) |
| 51 | #define OBOE_NANOS_PER_MILLISECOND (OBOE_NANOS_PER_MICROSECOND * 1000) |
| 52 | #define OBOE_MILLIS_PER_SECOND 1000 |
| 53 | #define OBOE_NANOS_PER_SECOND (OBOE_NANOS_PER_MILLISECOND * OBOE_MILLIS_PER_SECOND) |
| 54 | |
| 55 | #define OBOE_HANDLE_INVALID ((oboe_handle_t)-1) |
| 56 | |
| 57 | enum oboe_direction_t { |
| 58 | OBOE_DIRECTION_OUTPUT, |
| 59 | OBOE_DIRECTION_INPUT, |
| 60 | OBOE_DIRECTION_COUNT // This should always be last. |
| 61 | }; |
| 62 | |
Phil Burk | 5a7bdb2 | 2016-11-22 15:52:04 -0800 | [diff] [blame] | 63 | enum oboe_datatype_t { |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 64 | OBOE_AUDIO_DATATYPE_INT16, |
| 65 | OBOE_AUDIO_DATATYPE_INT32, |
| 66 | OBOE_AUDIO_DATATYPE_INT824, |
| 67 | OBOE_AUDIO_DATATYPE_UINT8, |
| 68 | OBOE_AUDIO_DATATYPE_FLOAT32, // Add new values below. |
| 69 | OBOE_AUDIO_DATATYPE_COUNT // This should always be last. |
| 70 | }; |
| 71 | |
Phil Burk | 5a7bdb2 | 2016-11-22 15:52:04 -0800 | [diff] [blame] | 72 | enum oboe_content_t { |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 73 | OBOE_AUDIO_CONTENT_PCM, |
| 74 | OBOE_AUDIO_CONTENT_MP3, |
| 75 | OBOE_AUDIO_CONTENT_AAC, |
| 76 | OBOE_AUDIO_CONTENT_AC3, |
| 77 | OBOE_AUDIO_CONTENT_EAC3, |
| 78 | OBOE_AUDIO_CONTENT_DTS, |
| 79 | OBOE_AUDIO_CONTENT_DTSHD, // Add new values below. |
| 80 | OBOE_AUDIO_CONTENT_COUNT // This should always be last. |
| 81 | }; |
| 82 | |
Phil Burk | 5a7bdb2 | 2016-11-22 15:52:04 -0800 | [diff] [blame] | 83 | enum oboe_wrapper_t { |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 84 | OBOE_AUDIO_WRAPPER_NONE, |
| 85 | OBOE_AUDIO_WRAPPER_IEC61937, // Add new values below. |
| 86 | OBOE_AUDIO_WRAPPER_COUNT // This should always be last. |
| 87 | }; |
| 88 | |
| 89 | /** |
| 90 | * Fields packed into oboe_audio_format_t, from most to least significant bits. |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 91 | * Invalid:1 |
| 92 | * Reserved:7 |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 93 | * Wrapper:8 |
| 94 | * Content:8 |
| 95 | * Data Type:8 |
| 96 | */ |
| 97 | #define OBOE_AUDIO_FORMAT(dataType, content, wrapper) \ |
| 98 | ((oboe_audio_format_t)((wrapper << 16) | (content << 8) | dataType)) |
| 99 | |
| 100 | #define OBOE_AUDIO_FORMAT_RAW(dataType, content) \ |
| 101 | OBOE_AUDIO_FORMAT(dataType, content, OBOE_AUDIO_WRAPPER_NONE) |
| 102 | |
| 103 | #define OBOE_AUDIO_FORMAT_DATA_TYPE(format) \ |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 104 | ((oboe_datatype_t)(format & 0x0FF)) |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 105 | |
| 106 | // Define some common formats. |
| 107 | #define OBOE_AUDIO_FORMAT_PCM16 \ |
| 108 | OBOE_AUDIO_FORMAT_RAW(OBOE_AUDIO_DATATYPE_INT16, OBOE_AUDIO_CONTENT_PCM) |
| 109 | #define OBOE_AUDIO_FORMAT_PCM_FLOAT \ |
| 110 | OBOE_AUDIO_FORMAT_RAW(OBOE_AUDIO_DATATYPE_FLOAT32, OBOE_AUDIO_CONTENT_PCM) |
| 111 | #define OBOE_AUDIO_FORMAT_PCM824 \ |
| 112 | OBOE_AUDIO_FORMAT_RAW(OBOE_AUDIO_DATATYPE_INT824, OBOE_AUDIO_CONTENT_PCM) |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 113 | #define OBOE_AUDIO_FORMAT_PCM32 \ |
| 114 | OBOE_AUDIO_FORMAT_RAW(OBOE_AUDIO_DATATYPE_INT32, OBOE_AUDIO_CONTENT_PCM) |
| 115 | #define OBOE_AUDIO_FORMAT_INVALID ((oboe_audio_format_t)-1) |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 116 | |
| 117 | enum { |
| 118 | OBOE_OK, |
| 119 | OBOE_ERROR_BASE = -900, // TODO review |
| 120 | OBOE_ERROR_DISCONNECTED, |
| 121 | OBOE_ERROR_ILLEGAL_ARGUMENT, |
| 122 | OBOE_ERROR_INCOMPATIBLE, |
| 123 | OBOE_ERROR_INTERNAL, // an underlying API returned an error code |
| 124 | OBOE_ERROR_INVALID_STATE, |
| 125 | OBOE_ERROR_UNEXPECTED_STATE, |
| 126 | OBOE_ERROR_UNEXPECTED_VALUE, |
| 127 | OBOE_ERROR_INVALID_HANDLE, |
| 128 | OBOE_ERROR_INVALID_QUERY, |
| 129 | OBOE_ERROR_UNIMPLEMENTED, |
| 130 | OBOE_ERROR_UNAVAILABLE, |
| 131 | OBOE_ERROR_NO_FREE_HANDLES, |
| 132 | OBOE_ERROR_NO_MEMORY, |
| 133 | OBOE_ERROR_NULL, |
| 134 | OBOE_ERROR_TIMEOUT, |
| 135 | OBOE_ERROR_WOULD_BLOCK, |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 136 | OBOE_ERROR_INVALID_ORDER, |
| 137 | OBOE_ERROR_OUT_OF_RANGE |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | typedef enum { |
| 141 | OBOE_CLOCK_MONOTONIC, // Clock since booted, pauses when CPU is sleeping. |
| 142 | OBOE_CLOCK_BOOTTIME, // Clock since booted, runs all the time. |
| 143 | OBOE_CLOCK_COUNT // This should always be last. |
| 144 | } oboe_clockid_t; |
| 145 | |
| 146 | typedef enum |
| 147 | { |
Phil Burk | 5a7bdb2 | 2016-11-22 15:52:04 -0800 | [diff] [blame] | 148 | OBOE_STREAM_STATE_UNINITIALIZED = 0, |
| 149 | OBOE_STREAM_STATE_OPEN, |
| 150 | OBOE_STREAM_STATE_STARTING, |
| 151 | OBOE_STREAM_STATE_STARTED, |
| 152 | OBOE_STREAM_STATE_PAUSING, |
| 153 | OBOE_STREAM_STATE_PAUSED, |
| 154 | OBOE_STREAM_STATE_FLUSHING, |
| 155 | OBOE_STREAM_STATE_FLUSHED, |
| 156 | OBOE_STREAM_STATE_STOPPING, |
| 157 | OBOE_STREAM_STATE_STOPPED, |
| 158 | OBOE_STREAM_STATE_CLOSING, |
| 159 | OBOE_STREAM_STATE_CLOSED, |
| 160 | } oboe_stream_state_t; |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 161 | |
| 162 | // TODO review API |
| 163 | typedef enum { |
| 164 | /** |
| 165 | * This will use an AudioTrack object for playing audio |
| 166 | * and an AudioRecord for recording data. |
| 167 | */ |
| 168 | OBOE_SHARING_MODE_LEGACY, |
| 169 | /** |
| 170 | * This will be the only stream using a particular source or sink. |
| 171 | * This mode will provide the lowest possible latency. |
| 172 | * You should close EXCLUSIVE streams immediately when you are not using them. |
| 173 | */ |
| 174 | OBOE_SHARING_MODE_EXCLUSIVE, |
| 175 | /** |
| 176 | * Multiple applications will be mixed by the Oboe Server. |
| 177 | * This will have higher latency than the EXCLUSIVE mode. |
| 178 | */ |
| 179 | OBOE_SHARING_MODE_SHARED, |
| 180 | /** |
| 181 | * Multiple applications will do their own mixing into a memory mapped buffer. |
| 182 | * It may be possible for malicious applications to read the data produced by |
| 183 | * other apps. So do not use this for private data such as telephony or messaging. |
| 184 | */ |
| 185 | OBOE_SHARING_MODE_PUBLIC_MIX, |
| 186 | OBOE_SHARING_MODE_COUNT // This should always be last. |
| 187 | } oboe_sharing_mode_t; |
| 188 | |
Glenn Kasten | 08ba52f | 2016-12-07 13:58:40 -0800 | [diff] [blame] | 189 | #ifdef __cplusplus |
| 190 | } |
| 191 | #endif |
| 192 | |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 193 | #endif // OBOE_OBOEDEFINITIONS_H |