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; |
Phil Burk | d8bdcab | 2017-01-03 17:20:30 -0800 | [diff] [blame^] | 28 | /** |
| 29 | * A platform specific identifier for a device. |
| 30 | */ |
| 31 | typedef int32_t oboe_device_id_t; |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 32 | typedef int32_t oboe_sample_rate_t; |
| 33 | /** This is used for small quantities such as the number of frames in a buffer. */ |
| 34 | typedef int32_t oboe_size_frames_t; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 35 | /** This is used for small quantities such as the number of bytes in a frame. */ |
| 36 | typedef int32_t oboe_size_bytes_t; |
| 37 | /** |
| 38 | * 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] | 39 | * been played since a stream was started. |
| 40 | * At 48000 Hz, a 32-bit integer would wrap around in just over 12 hours. |
| 41 | */ |
| 42 | typedef int64_t oboe_position_frames_t; |
| 43 | |
| 44 | typedef int64_t oboe_nanoseconds_t; |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * This is used to represent a value that has not been specified. |
| 48 | * For example, an application could use OBOE_UNSPECIFIED to indicate |
| 49 | * that is did not not care what the specific value of a parameter was |
| 50 | * and would accept whatever it was given. |
| 51 | */ |
| 52 | #define OBOE_UNSPECIFIED 0 |
Phil Burk | d8bdcab | 2017-01-03 17:20:30 -0800 | [diff] [blame^] | 53 | #define OBOE_DEVICE_UNSPECIFIED ((oboe_device_id_t) -1) |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 54 | #define OBOE_NANOS_PER_MICROSECOND ((int64_t)1000) |
| 55 | #define OBOE_NANOS_PER_MILLISECOND (OBOE_NANOS_PER_MICROSECOND * 1000) |
| 56 | #define OBOE_MILLIS_PER_SECOND 1000 |
| 57 | #define OBOE_NANOS_PER_SECOND (OBOE_NANOS_PER_MILLISECOND * OBOE_MILLIS_PER_SECOND) |
| 58 | |
| 59 | #define OBOE_HANDLE_INVALID ((oboe_handle_t)-1) |
| 60 | |
| 61 | enum oboe_direction_t { |
| 62 | OBOE_DIRECTION_OUTPUT, |
| 63 | OBOE_DIRECTION_INPUT, |
| 64 | OBOE_DIRECTION_COUNT // This should always be last. |
| 65 | }; |
| 66 | |
Phil Burk | d8bdcab | 2017-01-03 17:20:30 -0800 | [diff] [blame^] | 67 | enum oboe_audio_format_t { |
| 68 | OBOE_AUDIO_FORMAT_INVALID = -1, |
| 69 | OBOE_AUDIO_FORMAT_UNSPECIFIED = 0, |
| 70 | OBOE_AUDIO_FORMAT_PCM16, // TODO rename to _PCM_I16 |
| 71 | OBOE_AUDIO_FORMAT_PCM_FLOAT, |
| 72 | OBOE_AUDIO_FORMAT_PCM824, // TODO rename to _PCM_I8_24 |
| 73 | OBOE_AUDIO_FORMAT_PCM32 // TODO rename to _PCM_I32 |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 74 | }; |
| 75 | |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 76 | enum { |
| 77 | OBOE_OK, |
| 78 | OBOE_ERROR_BASE = -900, // TODO review |
| 79 | OBOE_ERROR_DISCONNECTED, |
| 80 | OBOE_ERROR_ILLEGAL_ARGUMENT, |
| 81 | OBOE_ERROR_INCOMPATIBLE, |
| 82 | OBOE_ERROR_INTERNAL, // an underlying API returned an error code |
| 83 | OBOE_ERROR_INVALID_STATE, |
| 84 | OBOE_ERROR_UNEXPECTED_STATE, |
| 85 | OBOE_ERROR_UNEXPECTED_VALUE, |
| 86 | OBOE_ERROR_INVALID_HANDLE, |
| 87 | OBOE_ERROR_INVALID_QUERY, |
| 88 | OBOE_ERROR_UNIMPLEMENTED, |
| 89 | OBOE_ERROR_UNAVAILABLE, |
| 90 | OBOE_ERROR_NO_FREE_HANDLES, |
| 91 | OBOE_ERROR_NO_MEMORY, |
| 92 | OBOE_ERROR_NULL, |
| 93 | OBOE_ERROR_TIMEOUT, |
| 94 | OBOE_ERROR_WOULD_BLOCK, |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 95 | OBOE_ERROR_INVALID_ORDER, |
| 96 | OBOE_ERROR_OUT_OF_RANGE |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | typedef enum { |
| 100 | OBOE_CLOCK_MONOTONIC, // Clock since booted, pauses when CPU is sleeping. |
| 101 | OBOE_CLOCK_BOOTTIME, // Clock since booted, runs all the time. |
| 102 | OBOE_CLOCK_COUNT // This should always be last. |
| 103 | } oboe_clockid_t; |
| 104 | |
| 105 | typedef enum |
| 106 | { |
Phil Burk | 5a7bdb2 | 2016-11-22 15:52:04 -0800 | [diff] [blame] | 107 | OBOE_STREAM_STATE_UNINITIALIZED = 0, |
| 108 | OBOE_STREAM_STATE_OPEN, |
| 109 | OBOE_STREAM_STATE_STARTING, |
| 110 | OBOE_STREAM_STATE_STARTED, |
| 111 | OBOE_STREAM_STATE_PAUSING, |
| 112 | OBOE_STREAM_STATE_PAUSED, |
| 113 | OBOE_STREAM_STATE_FLUSHING, |
| 114 | OBOE_STREAM_STATE_FLUSHED, |
| 115 | OBOE_STREAM_STATE_STOPPING, |
| 116 | OBOE_STREAM_STATE_STOPPED, |
| 117 | OBOE_STREAM_STATE_CLOSING, |
| 118 | OBOE_STREAM_STATE_CLOSED, |
| 119 | } oboe_stream_state_t; |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 120 | |
| 121 | // TODO review API |
| 122 | typedef enum { |
| 123 | /** |
| 124 | * This will use an AudioTrack object for playing audio |
| 125 | * and an AudioRecord for recording data. |
| 126 | */ |
| 127 | OBOE_SHARING_MODE_LEGACY, |
| 128 | /** |
| 129 | * This will be the only stream using a particular source or sink. |
| 130 | * This mode will provide the lowest possible latency. |
| 131 | * You should close EXCLUSIVE streams immediately when you are not using them. |
| 132 | */ |
| 133 | OBOE_SHARING_MODE_EXCLUSIVE, |
| 134 | /** |
| 135 | * Multiple applications will be mixed by the Oboe Server. |
| 136 | * This will have higher latency than the EXCLUSIVE mode. |
| 137 | */ |
| 138 | OBOE_SHARING_MODE_SHARED, |
| 139 | /** |
| 140 | * Multiple applications will do their own mixing into a memory mapped buffer. |
| 141 | * It may be possible for malicious applications to read the data produced by |
| 142 | * other apps. So do not use this for private data such as telephony or messaging. |
| 143 | */ |
| 144 | OBOE_SHARING_MODE_PUBLIC_MIX, |
| 145 | OBOE_SHARING_MODE_COUNT // This should always be last. |
| 146 | } oboe_sharing_mode_t; |
| 147 | |
Glenn Kasten | 08ba52f | 2016-12-07 13:58:40 -0800 | [diff] [blame] | 148 | #ifdef __cplusplus |
| 149 | } |
| 150 | #endif |
| 151 | |
Phil Burk | ab17796 | 2016-11-18 17:11:59 -0800 | [diff] [blame] | 152 | #endif // OBOE_OBOEDEFINITIONS_H |