blob: 9d56a243d73a3d42ec4a246ea9bb23a6ce7e2cd5 [file] [log] [blame]
Phil Burkab177962016-11-18 17:11:59 -08001/*
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 Kasten08ba52f2016-12-07 13:58:40 -080022#ifdef __cplusplus
23extern "C" {
24#endif
25
26typedef int32_t oboe_handle_t; // negative handles are error codes
Phil Burkab177962016-11-18 17:11:59 -080027typedef int32_t oboe_result_t;
Phil Burkd8bdcab2017-01-03 17:20:30 -080028/**
29 * A platform specific identifier for a device.
30 */
31typedef int32_t oboe_device_id_t;
Phil Burkab177962016-11-18 17:11:59 -080032typedef int32_t oboe_sample_rate_t;
33/** This is used for small quantities such as the number of frames in a buffer. */
34typedef int32_t oboe_size_frames_t;
Phil Burke1ce4912016-11-21 10:40:25 -080035/** This is used for small quantities such as the number of bytes in a frame. */
36typedef int32_t oboe_size_bytes_t;
37/**
38 * This is used for large quantities, such as the number of frames that have
Phil Burkab177962016-11-18 17:11:59 -080039 * been played since a stream was started.
40 * At 48000 Hz, a 32-bit integer would wrap around in just over 12 hours.
41 */
42typedef int64_t oboe_position_frames_t;
43
44typedef int64_t oboe_nanoseconds_t;
Phil Burkab177962016-11-18 17:11:59 -080045
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 Burkd8bdcab2017-01-03 17:20:30 -080053#define OBOE_DEVICE_UNSPECIFIED ((oboe_device_id_t) -1)
Phil Burkab177962016-11-18 17:11:59 -080054#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
61enum oboe_direction_t {
62 OBOE_DIRECTION_OUTPUT,
63 OBOE_DIRECTION_INPUT,
64 OBOE_DIRECTION_COUNT // This should always be last.
65};
66
Phil Burkd8bdcab2017-01-03 17:20:30 -080067enum 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 Burkab177962016-11-18 17:11:59 -080074};
75
Phil Burkab177962016-11-18 17:11:59 -080076enum {
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 Burke1ce4912016-11-21 10:40:25 -080095 OBOE_ERROR_INVALID_ORDER,
96 OBOE_ERROR_OUT_OF_RANGE
Phil Burkab177962016-11-18 17:11:59 -080097};
98
99typedef 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
105typedef enum
106{
Phil Burk5a7bdb22016-11-22 15:52:04 -0800107 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 Burkab177962016-11-18 17:11:59 -0800120
121// TODO review API
122typedef 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 Kasten08ba52f2016-12-07 13:58:40 -0800148#ifdef __cplusplus
149}
150#endif
151
Phil Burkab177962016-11-18 17:11:59 -0800152#endif // OBOE_OBOEDEFINITIONS_H