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