# Oboe: include/oboe/Definitions.h Source File

Definitions.h
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OBOE_DEFINITIONS_H
#define OBOE_DEFINITIONS_H
#include <cstdint>
#include <type_traits>
// Oboe needs to be able to build on old NDKs so we use hard coded constants.
// The correctness of these constants is verified in "aaudio/AAudioLoader.cpp".
namespace oboe {
constexpr int32_t kUnspecified = 0;
// TODO: Investigate using std::chrono
constexpr int64_t kNanosPerMicrosecond = 1000;
constexpr int64_t kNanosPerMillisecond = kNanosPerMicrosecond * 1000;
constexpr int64_t kMillisPerSecond = 1000;
constexpr int64_t kNanosPerSecond = kNanosPerMillisecond * kMillisPerSecond;
enum class StreamState : int32_t { // aaudio_stream_state_t
Uninitialized = 0, // AAUDIO_STREAM_STATE_UNINITIALIZED,
Unknown = 1, // AAUDIO_STREAM_STATE_UNKNOWN,
Open = 2, // AAUDIO_STREAM_STATE_OPEN,
Starting = 3, // AAUDIO_STREAM_STATE_STARTING,
Started = 4, // AAUDIO_STREAM_STATE_STARTED,
Pausing = 5, // AAUDIO_STREAM_STATE_PAUSING,
Paused = 6, // AAUDIO_STREAM_STATE_PAUSED,
Flushing = 7, // AAUDIO_STREAM_STATE_FLUSHING,
Flushed = 8, // AAUDIO_STREAM_STATE_FLUSHED,
Stopping = 9, // AAUDIO_STREAM_STATE_STOPPING,
Stopped = 10, // AAUDIO_STREAM_STATE_STOPPED,
Closing = 11, // AAUDIO_STREAM_STATE_CLOSING,
Closed = 12, // AAUDIO_STREAM_STATE_CLOSED,
Disconnected = 13, // AAUDIO_STREAM_STATE_DISCONNECTED,
};
enum class Direction : int32_t { // aaudio_direction_t
Output = 0, // AAUDIO_DIRECTION_OUTPUT,
Input = 1, // AAUDIO_DIRECTION_INPUT,
};
enum class AudioFormat : int32_t { // aaudio_format_t
Invalid = -1, // AAUDIO_FORMAT_INVALID,
Unspecified = 0, // AAUDIO_FORMAT_UNSPECIFIED,
I16 = 1, // AAUDIO_FORMAT_PCM_I16,
Float = 2, // AAUDIO_FORMAT_PCM_FLOAT,
};
enum class DataCallbackResult : int32_t { // aaudio_data_callback_result_t
// Indicates to the caller that the callbacks should continue.
Continue = 0, // AAUDIO_CALLBACK_RESULT_CONTINUE,
// Indicates to the caller that the callbacks should stop immediately.
Stop = 1, // AAUDIO_CALLBACK_RESULT_STOP,
};
enum class Result : int32_t { // aaudio_result_t
OK = 0, // AAUDIO_OK
ErrorBase = -900, // AAUDIO_ERROR_BASE,
ErrorDisconnected = -899, // AAUDIO_ERROR_DISCONNECTED,
ErrorIllegalArgument = -898, // AAUDIO_ERROR_ILLEGAL_ARGUMENT,
ErrorInternal = -896, // AAUDIO_ERROR_INTERNAL,
ErrorInvalidState = -895, // AAUDIO_ERROR_INVALID_STATE,
ErrorInvalidHandle = -892, // AAUDIO_ERROR_INVALID_HANDLE,
ErrorUnimplemented = -890, // AAUDIO_ERROR_UNIMPLEMENTED,
ErrorUnavailable = -889, // AAUDIO_ERROR_UNAVAILABLE,
ErrorNoFreeHandles = -888, // AAUDIO_ERROR_NO_FREE_HANDLES,
ErrorNoMemory = -887, // AAUDIO_ERROR_NO_MEMORY,
ErrorNull = -886, // AAUDIO_ERROR_NULL,
ErrorTimeout = -885, // AAUDIO_ERROR_TIMEOUT,
ErrorWouldBlock = -884, // AAUDIO_ERROR_WOULD_BLOCK,
ErrorInvalidFormat = -883, // AAUDIO_ERROR_INVALID_FORMAT,
ErrorOutOfRange = -882, // AAUDIO_ERROR_OUT_OF_RANGE,
ErrorNoService = -881, // AAUDIO_ERROR_NO_SERVICE,
ErrorInvalidRate = -880, // AAUDIO_ERROR_INVALID_RATE,
// Reserved for future AAudio result types
Reserved1,
Reserved2,
Reserved3,
Reserved4,
Reserved5,
Reserved6,
Reserved7,
Reserved8,
Reserved9,
Reserved10,
ErrorClosed,
};
enum class SharingMode : int32_t { // aaudio_sharing_mode_t
Exclusive = 0, // AAUDIO_SHARING_MODE_EXCLUSIVE,
Shared = 1, // AAUDIO_SHARING_MODE_SHARED,
};
enum class PerformanceMode : int32_t { // aaudio_performance_mode_t
None = 10, // AAUDIO_PERFORMANCE_MODE_NONE,
PowerSaving = 11, // AAUDIO_PERFORMANCE_MODE_POWER_SAVING,
LowLatency = 12, // AAUDIO_PERFORMANCE_MODE_LOW_LATENCY
};
enum class AudioApi : int32_t {
Unspecified = kUnspecified,
OpenSLES,
AAudio
};
enum class SampleRateConversionQuality : int32_t {
None,
Fastest,
Low,
Medium,
High,
Best,
};
enum class Usage : int32_t { // aaudio_usage_t
Media = 1, // AAUDIO_USAGE_MEDIA
VoiceCommunication = 2, // AAUDIO_USAGE_VOICE_COMMUNICATION
VoiceCommunicationSignalling = 3, // AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING
Alarm = 4, // AAUDIO_USAGE_ALARM
Notification = 5, // AAUDIO_USAGE_NOTIFICATION
NotificationRingtone = 6, // AAUDIO_USAGE_NOTIFICATION_RINGTONE
NotificationEvent = 10, // AAUDIO_USAGE_NOTIFICATION_EVENT
AssistanceAccessibility = 11, // AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY
AssistanceNavigationGuidance = 12, // AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE
AssistanceSonification = 13, // AAUDIO_USAGE_ASSISTANCE_SONIFICATION
Game = 14, // AAUDIO_USAGE_GAME
Assistant = 16, // AAUDIO_USAGE_ASSISTANT
};
enum ContentType : int32_t { // aaudio_content_type_t
Speech = 1, // AAUDIO_CONTENT_TYPE_SPEECH
Music = 2, // AAUDIO_CONTENT_TYPE_MUSIC
Movie = 3, // AAUDIO_CONTENT_TYPE_MOVIE
Sonification = 4, // AAUDIO_CONTENT_TYPE_SONIFICATION
};
enum InputPreset : int32_t { // aaudio_input_preset_t
Generic = 1, // AAUDIO_INPUT_PRESET_GENERIC
Camcorder = 5, // AAUDIO_INPUT_PRESET_CAMCORDER
VoiceRecognition = 6, // AAUDIO_INPUT_PRESET_VOICE_RECOGNITION
VoiceCommunication = 7, // AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION
Unprocessed = 9, // AAUDIO_INPUT_PRESET_UNPROCESSED
VoicePerformance = 10, // AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE
};
enum SessionId {
None = -1, // AAUDIO_SESSION_ID_NONE
Allocate = 0, // AAUDIO_SESSION_ID_ALLOCATE
};
enum ChannelCount : int32_t {
Unspecified = kUnspecified,
Mono = 1,
Stereo = 2,
};
class DefaultStreamValues {
public:
static int32_t SampleRate;
static int32_t FramesPerBurst;
static int32_t ChannelCount;
};
struct FrameTimestamp {
int64_t position; // in frames
int64_t timestamp; // in nanoseconds
};
class OboeGlobals {
public:
static bool areWorkaroundsEnabled() {
return mWorkaroundsEnabled;
}
static void setWorkaroundsEnabled(bool enabled) {
mWorkaroundsEnabled = enabled;
}
private:
static bool mWorkaroundsEnabled;
};
} // namespace oboe
#endif // OBOE_DEFINITIONS_H
oboe::kNanosPerMicrosecond
constexpr int64_t kNanosPerMicrosecond
Definition: Definitions.h:38
oboe::AudioApi::AAudio
oboe::Direction::Output
oboe::OboeGlobals
Definition: Definitions.h:498
oboe::Allocate
Definition: Definitions.h:429
oboe::VoiceRecognition
Definition: Definitions.h:386
oboe::None
Definition: Definitions.h:420
oboe::kNanosPerSecond
constexpr int64_t kNanosPerSecond
Definition: Definitions.h:53
oboe::Usage::Assistant
oboe::Usage::AssistanceAccessibility
oboe::PerformanceMode::PowerSaving
oboe::SharingMode::Exclusive
oboe::PerformanceMode
PerformanceMode
Definition: Definitions.h:192
oboe::SessionId
SessionId
Definition: Definitions.h:414
oboe::SharingMode::Shared
oboe::Usage::AssistanceSonification
oboe::Movie
Definition: Definitions.h:354
oboe::Generic
Definition: Definitions.h:376
oboe::PerformanceMode::LowLatency
oboe::DataCallbackResult
DataCallbackResult
Definition: Definitions.h:119
oboe::OboeGlobals::setWorkaroundsEnabled
static void setWorkaroundsEnabled(bool enabled)
Definition: Definitions.h:510
oboe::AudioApi
AudioApi
Definition: Definitions.h:213
oboe::ContentType
ContentType
Definition: Definitions.h:339
oboe::DefaultStreamValues
Definition: Definitions.h:477
oboe::AudioApi::OpenSLES
oboe::FrameTimestamp
Definition: Definitions.h:493
oboe::SampleRateConversionQuality::Best
oboe::Usage::NotificationRingtone
oboe::Usage
Usage
Definition: Definitions.h:263
oboe::Stereo
Definition: Definitions.h:456
oboe::VoiceCommunication
Definition: Definitions.h:391
oboe::Usage::Media
oboe::AudioFormat::I16
oboe::DefaultStreamValues::FramesPerBurst
static int32_t FramesPerBurst
Definition: Definitions.h:484
oboe::Camcorder
Definition: Definitions.h:381
oboe::kNanosPerMillisecond
constexpr int64_t kNanosPerMillisecond
Definition: Definitions.h:43
oboe::Usage::Game
oboe::AudioFormat::Float
oboe::Unprocessed
Definition: Definitions.h:398
oboe::Mono
Definition: Definitions.h:451
oboe::AudioFormat
AudioFormat
Definition: Definitions.h:94
oboe::Direction::Input
oboe::Sonification
Definition: Definitions.h:360
oboe::ChannelCount
ChannelCount
Definition: Definitions.h:442
oboe::AudioFormat::Invalid
oboe::Result
Result
Definition: Definitions.h:131
oboe::Usage::AssistanceNavigationGuidance
oboe::kUnspecified
constexpr int32_t kUnspecified
Definition: Definitions.h:32
oboe
Definition: AudioStream.h:31
oboe::kMillisPerSecond
constexpr int64_t kMillisPerSecond
Definition: Definitions.h:48
oboe::SampleRateConversionQuality
SampleRateConversionQuality
Definition: Definitions.h:235
oboe::Unspecified
Definition: Definitions.h:446
oboe::Direction
Direction
Definition: Definitions.h:78
oboe::SharingMode
SharingMode
Definition: Definitions.h:167
oboe::InputPreset
InputPreset
Definition: Definitions.h:372
oboe::StreamState
StreamState
Definition: Definitions.h:58
oboe::Usage::VoiceCommunicationSignalling
oboe::DefaultStreamValues::SampleRate
static int32_t SampleRate
Definition: Definitions.h:482
oboe::DefaultStreamValues::ChannelCount
static int32_t ChannelCount
Definition: Definitions.h:486
oboe::VoicePerformance
Definition: Definitions.h:405
oboe::Music
Definition: Definitions.h:349
oboe::SampleRateConversionQuality::Fastest
oboe::Speech
Definition: Definitions.h:344
oboe::Usage::NotificationEvent
oboe::Usage::Notification
oboe::Usage::Alarm