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