AudioStream.h revision e2155ef0ec6742db7a3128c4ef4fb96e02828d1b
1e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk/* 2e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * Copyright 2016 The Android Open Source Project 3e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * 4e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * Licensed under the Apache License, Version 2.0 (the "License"); 5e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * you may not use this file except in compliance with the License. 6e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * You may obtain a copy of the License at 7e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * 8e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * http://www.apache.org/licenses/LICENSE-2.0 9e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * 10e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * Unless required by applicable law or agreed to in writing, software 11e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * distributed under the License is distributed on an "AS IS" BASIS, 12e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * See the License for the specific language governing permissions and 14e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * limitations under the License. 15e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk */ 16e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 175ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk#ifndef AAUDIO_AUDIOSTREAM_H 185ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk#define AAUDIO_AUDIOSTREAM_H 19e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 20d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk#include <atomic> 21d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk#include <stdint.h> 225ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk#include <aaudio/AAudioDefinitions.h> 235ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk#include <aaudio/AAudio.h> 24d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk 255ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk#include "AAudioUtilities.h" 26e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk#include "MonotonicCounter.h" 27e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 285ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burknamespace aaudio { 29e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 30e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burkclass AudioStreamBuilder; 31e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 32e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk/** 335ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk * AAudio audio stream. 34e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk */ 35e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burkclass AudioStream { 36e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burkpublic: 37e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 38e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk AudioStream(); 39e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 40e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk virtual ~AudioStream(); 41e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 42e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 43e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk // =========== Begin ABSTRACT methods =========================== 44e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 45e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk /* Asynchronous requests. 46e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * Use waitForStateChange() to wait for completion. 47e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk */ 485ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk virtual aaudio_result_t requestStart() = 0; 495ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk virtual aaudio_result_t requestPause() = 0; 505ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk virtual aaudio_result_t requestFlush() = 0; 515ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk virtual aaudio_result_t requestStop() = 0; 52e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 535ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk // TODO use aaudio_clockid_t all the way down to AudioClock 545ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk virtual aaudio_result_t getTimestamp(clockid_t clockId, 553316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk int64_t *framePosition, 563316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk int64_t *timeNanoseconds) = 0; 57e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 58e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 595ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk virtual aaudio_result_t updateState() = 0; 60e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 61e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 62e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk // =========== End ABSTRACT methods =========================== 63e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 645ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk virtual aaudio_result_t waitForStateChange(aaudio_stream_state_t currentState, 655ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk aaudio_stream_state_t *nextState, 663316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk int64_t timeoutNanoseconds); 67e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 68e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk /** 69e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * Open the stream using the parameters in the builder. 70e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * Allocate the necessary resources. 71e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk */ 725ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk virtual aaudio_result_t open(const AudioStreamBuilder& builder); 73e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 74e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk /** 75e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * Close the stream and deallocate any resources from the open() call. 76e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * It is safe to call close() multiple times. 77e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk */ 785ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk virtual aaudio_result_t close() { 795ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk return AAUDIO_OK; 80e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 81e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 823316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk virtual aaudio_result_t setBufferSize(int32_t requestedFrames) { 835ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk return AAUDIO_ERROR_UNIMPLEMENTED; 84e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 85e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 863316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk virtual aaudio_result_t createThread(int64_t periodNanoseconds, 87e2155ef0ec6742db7a3128c4ef4fb96e02828d1bPhil Burk aaudio_audio_thread_proc_t threadProc, 88d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk void *threadArg); 89e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 903316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk virtual aaudio_result_t joinThread(void **returnArg, int64_t timeoutNanoseconds); 91e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 925ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk virtual aaudio_result_t registerThread() { 935ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk return AAUDIO_OK; 94d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk } 95d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk 965ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk virtual aaudio_result_t unregisterThread() { 975ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk return AAUDIO_OK; 98d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk } 99d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk 100d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk /** 101d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk * Internal function used to call the audio thread passed by the user. 102d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk * It is unfortunately public because it needs to be called by a static 'C' function. 103d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk */ 104d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk void* wrapUserThread(); 105d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk 106e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk // ============== Queries =========================== 107e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 1083316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk aaudio_stream_state_t getState() const { 109e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk return mState; 110e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 111e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 1123316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk virtual int32_t getBufferSize() const { 1135ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk return AAUDIO_ERROR_UNIMPLEMENTED; 114e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 115e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 1163316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk virtual int32_t getBufferCapacity() const { 1175ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk return AAUDIO_ERROR_UNIMPLEMENTED; 118e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 119e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 1203316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk virtual int32_t getFramesPerBurst() const { 1215ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk return AAUDIO_ERROR_UNIMPLEMENTED; 122e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 123e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 124e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk virtual int32_t getXRunCount() const { 1255ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk return AAUDIO_ERROR_UNIMPLEMENTED; 126e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 127e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 128e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk bool isPlaying() const { 1295ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk return mState == AAUDIO_STREAM_STATE_STARTING || mState == AAUDIO_STREAM_STATE_STARTED; 130e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 131e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 1325ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk aaudio_result_t getSampleRate() const { 133e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk return mSampleRate; 134e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 135e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 1365ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk aaudio_audio_format_t getFormat() const { 137e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk return mFormat; 138e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 139e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 1405ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk aaudio_result_t getSamplesPerFrame() const { 141e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk return mSamplesPerFrame; 142e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 143e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 1443316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk int32_t getDeviceId() const { 145e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk return mDeviceId; 146e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 147e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 1485ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk aaudio_sharing_mode_t getSharingMode() const { 149e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk return mSharingMode; 150e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 151e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 1525ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk aaudio_direction_t getDirection() const { 153e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk return mDirection; 154e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 155e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 1563316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk int32_t getBytesPerFrame() const { 157e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk return mSamplesPerFrame * getBytesPerSample(); 158e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 159e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 1603316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk int32_t getBytesPerSample() const { 1615ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk return AAudioConvert_formatToSizeInBytes(mFormat); 162e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 163e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 1643316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk virtual int64_t getFramesWritten() { 165e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk return mFramesWritten.get(); 166e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 167e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 1683316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk virtual int64_t getFramesRead() { 169e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk return mFramesRead.get(); 170e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 171e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 172e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 173e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk // ============== I/O =========================== 174e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk // A Stream will only implement read() or write() depending on its direction. 1755ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk virtual aaudio_result_t write(const void *buffer, 1763316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk int32_t numFrames, 1773316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk int64_t timeoutNanoseconds) { 1785ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk return AAUDIO_ERROR_UNIMPLEMENTED; 179e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 180e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 1815ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk virtual aaudio_result_t read(void *buffer, 1823316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk int32_t numFrames, 1833316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk int64_t timeoutNanoseconds) { 1845ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk return AAUDIO_ERROR_UNIMPLEMENTED; 185e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 186e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 187e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burkprotected: 188e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 1893316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk virtual int64_t incrementFramesWritten(int32_t frames) { 1903316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk return static_cast<int64_t>(mFramesWritten.increment(frames)); 191e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 192e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 1933316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk virtual int64_t incrementFramesRead(int32_t frames) { 1943316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk return static_cast<int64_t>(mFramesRead.increment(frames)); 195e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 196e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 197e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk /** 198e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * Wait for a transition from one state to another. 1995ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk * @return AAUDIO_OK if the endingState was observed, or AAUDIO_ERROR_UNEXPECTED_STATE 200e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * if any state that was not the startingState or endingState was observed 2015ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk * or AAUDIO_ERROR_TIMEOUT 202e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk */ 2035ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk virtual aaudio_result_t waitForStateTransition(aaudio_stream_state_t startingState, 2043316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk aaudio_stream_state_t endingState, 2053316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk int64_t timeoutNanoseconds); 206e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 207e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk /** 208e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * This should not be called after the open() call. 209e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk */ 2103316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk void setSampleRate(int32_t sampleRate) { 211e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk mSampleRate = sampleRate; 212e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 213e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 214e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk /** 215e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * This should not be called after the open() call. 216e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk */ 217e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk void setSamplesPerFrame(int32_t samplesPerFrame) { 218e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk mSamplesPerFrame = samplesPerFrame; 219e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 220e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 221e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk /** 222e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * This should not be called after the open() call. 223e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk */ 2245ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk void setSharingMode(aaudio_sharing_mode_t sharingMode) { 225e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk mSharingMode = sharingMode; 226e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 227e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 228e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk /** 229e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk * This should not be called after the open() call. 230e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk */ 2315ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk void setFormat(aaudio_audio_format_t format) { 232e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk mFormat = format; 233e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 234e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 2355ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk void setState(aaudio_stream_state_t state) { 236e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk mState = state; 237e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk } 238e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 239d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk 240d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk 241d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burkprotected: 242e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk MonotonicCounter mFramesWritten; 243e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk MonotonicCounter mFramesRead; 244e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 2453316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk void setPeriodNanoseconds(int64_t periodNanoseconds) { 246d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk mPeriodNanoseconds.store(periodNanoseconds, std::memory_order_release); 247d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk } 248d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk 2493316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk int64_t getPeriodNanoseconds() { 250d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk return mPeriodNanoseconds.load(std::memory_order_acquire); 251d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk } 252d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk 253e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burkprivate: 254e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk // These do not change after open(). 2553316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk int32_t mSamplesPerFrame = AAUDIO_UNSPECIFIED; 2563316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk int32_t mSampleRate = AAUDIO_UNSPECIFIED; 2573316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk int32_t mDeviceId = AAUDIO_UNSPECIFIED; 258c35f3ae6f361a346b6d823601c69dd704afe644aPhil Burk aaudio_sharing_mode_t mSharingMode = AAUDIO_SHARING_MODE_SHARED; 2595ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk aaudio_audio_format_t mFormat = AAUDIO_FORMAT_UNSPECIFIED; 2605ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk aaudio_direction_t mDirection = AAUDIO_DIRECTION_OUTPUT; 2613316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk aaudio_stream_state_t mState = AAUDIO_STREAM_STATE_UNINITIALIZED; 262e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 263d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk // background thread ---------------------------------- 2643316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk bool mHasThread = false; 2653316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk pthread_t mThread; // initialized in constructor 266d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk 267d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk // These are set by the application thread and then read by the audio pthread. 2683316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk std::atomic<int64_t> mPeriodNanoseconds; // for tuning SCHED_FIFO threads 269d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk // TODO make atomic? 270e2155ef0ec6742db7a3128c4ef4fb96e02828d1bPhil Burk aaudio_audio_thread_proc_t mThreadProc = nullptr; 2713316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk void* mThreadArg = nullptr; 2725ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk aaudio_result_t mThreadRegistrationResult = AAUDIO_OK; 273d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk 274d8bdcabbac30d48ed17fa76c83cb9ee95c290a07Phil Burk 275e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk}; 276e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 2775ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk} /* namespace aaudio */ 278e1ce491a25faf06fdeab00dd938515f71f28b095Phil Burk 2795ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk#endif /* AAUDIO_AUDIOSTREAM_H */ 280