blob: bd6db556693a070a2cb37a027164195ede765e30 [file] [log] [blame]
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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 ANDROID_AUDIO_TRACK_SHARED_H
18#define ANDROID_AUDIO_TRACK_SHARED_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
Glenn Kastenc56f3422014-03-21 17:53:17 -070023#include <audio_utils/minifloat.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080024#include <utils/threads.h>
Glenn Kastene3aa6592012-12-04 12:22:46 -080025#include <utils/Log.h>
Glenn Kasten9f80dd22012-12-18 15:57:32 -080026#include <utils/RefBase.h>
Glenn Kasten53dbe772015-01-06 10:46:38 -080027#include <audio_utils/roundup.h>
Andy Hung8edb8dc2015-03-26 19:13:55 -070028#include <media/AudioResamplerPublic.h>
Andy Hung3f0c9022016-01-15 17:49:46 -080029#include <media/AudioTimestamp.h>
Andy Hung90e8a972015-11-09 16:42:40 -080030#include <media/Modulo.h>
Mikhail Naganov9f3c02d2019-08-12 11:36:05 -070031#include <media/nbaio/SingleStateQueue.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080032
33namespace android {
34
35// ----------------------------------------------------------------------------
36
Glenn Kasten96f60d82013-07-12 10:21:18 -070037// for audio_track_cblk_t::mFlags
Glenn Kasten9f80dd22012-12-18 15:57:32 -080038#define CBLK_UNDERRUN 0x01 // set by server immediately on output underrun, cleared by client
Glenn Kasten864585d2012-11-06 16:15:41 -080039#define CBLK_FORCEREADY 0x02 // set: track is considered ready immediately by AudioFlinger,
Glenn Kasten9c5fdd82012-11-05 13:38:15 -080040 // clear: track is ready when buffer full
Glenn Kasten864585d2012-11-06 16:15:41 -080041#define CBLK_INVALID 0x04 // track buffer invalidated by AudioFlinger, need to re-create
Glenn Kasten9f80dd22012-12-18 15:57:32 -080042#define CBLK_DISABLED 0x08 // output track disabled by AudioFlinger due to underrun,
43 // need to re-start. Unlike CBLK_UNDERRUN, this is not set
44 // immediately, but only after a long string of underruns.
45// 0x10 unused
46#define CBLK_LOOP_CYCLE 0x20 // set by server each time a loop cycle other than final one completes
47#define CBLK_LOOP_FINAL 0x40 // set by server when the final loop cycle completes
48#define CBLK_BUFFER_END 0x80 // set by server when the position reaches end of buffer if not looping
49#define CBLK_OVERRUN 0x100 // set by server immediately on input overrun, cleared by client
50#define CBLK_INTERRUPT 0x200 // set by client on interrupt(), cleared by client in obtainBuffer()
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000051#define CBLK_STREAM_END_DONE 0x400 // set by server on render completion, cleared by client
52
53//EL_FIXME 20 seconds may not be enough and must be reconciled with new obtainBuffer implementation
Glenn Kastene198c362013-08-13 09:13:36 -070054#define MAX_RUN_OFFLOADED_TIMEOUT_MS 20000 // assuming up to a maximum of 20 seconds of offloaded
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080055
Andy Hung959b5b82021-09-24 10:46:20 -070056// for audio_track_cblk_t::mState, to match TrackBase.h
57static inline constexpr int CBLK_STATE_IDLE = 0;
58static inline constexpr int CBLK_STATE_PAUSING = 7;
59
60/**
61 * MirroredVariable is a local variable which simultaneously updates
62 * a mirrored storage location. This is useful for server side variables
63 * where a local copy is kept, but a client visible copy is offered through shared memory.
64 *
65 * We use std::atomic as the default container class to access this memory.
66 */
67template <typename T, template <typename> class Container = std::atomic>
68class MirroredVariable {
69 template <typename C>
70 struct Constraints {
71 // If setMirror is used with a different type U != T passed in,
72 // as a general rule, the Container must issue a memcpy to read or write
73 // (or its equivalent) to avoid possible strict aliasing issues.
74 // The memcpy also avoids gaps in structs and alignment issues with different types.
75 static constexpr bool ok_ = false; // Containers must specify constraints.
76 };
77 template <typename X>
78 struct Constraints<std::atomic<X>> {
79 // Atomics force read and write to memory.
80 static constexpr bool ok = std::is_same_v<X, T> ||
81 (std::atomic<X>::is_always_lock_free // no additional locking
82 && sizeof(std::atomic<X>) == sizeof(X) // layout identical to X.
83 && (std::is_arithmetic_v<X> || std::is_enum_v<X>)); // No gaps in the layout.
84 };
85
86static_assert(Constraints<Container<T>>::ok);
87public:
88 explicit MirroredVariable(const T& t) : t_{t} {}
89
90 // implicit conversion operator
91 operator T() const {
92 return t_;
93 }
94
95 MirroredVariable& operator=(const T& t) {
96 t_ = t;
97 if (mirror_ != nullptr) {
98 *mirror_ = t;
99 }
100 return *this;
101 }
102
103 template <typename U>
104 void setMirror(Container<U> *other_mirror) {
105 // Much of the concern is with T != U, however there are additional concerns
106 // when storage uses shared memory between processes. For atomics, it must be
107 // lock free.
108 static_assert(sizeof(U) == sizeof(T));
109 static_assert(alignof(U) == alignof(T));
110 static_assert(Constraints<Container<U>>::ok);
111 static_assert(sizeof(Container<U>) == sizeof(Container<T>));
112 static_assert(alignof(Container<U>) == alignof(Container<T>));
113 auto mirror = reinterpret_cast<Container<T>*>(other_mirror);
114 if (mirror_ != mirror) {
115 mirror_ = mirror;
116 if (mirror != nullptr) {
117 *mirror = t_;
118 }
119 }
120 }
121
122 void clear() {
123 mirror_ = nullptr;
124 }
125
126 MirroredVariable& operator&() const = delete;
127
128protected:
129 T t_{};
130 Container<T>* mirror_ = nullptr;
131};
132
Glenn Kastene3aa6592012-12-04 12:22:46 -0800133struct AudioTrackSharedStreaming {
134 // similar to NBAIO MonoPipe
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800135 // in continuously incrementing frame units, take modulo buffer size, which must be a power of 2
Glenn Kastenf59497b2015-01-26 16:35:47 -0800136 volatile int32_t mFront; // read by consumer (output: server, input: client)
137 volatile int32_t mRear; // written by producer (output: client, input: server)
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800138 volatile int32_t mFlush; // incremented by client to indicate a request to flush;
139 // server notices and discards all data between mFront and mRear
Andy Hung1d3556d2018-03-29 16:30:14 -0700140 volatile int32_t mStop; // set by client to indicate a stop frame position; server
141 // will not read beyond this position until start is called.
Phil Burk2812d9e2016-01-04 10:34:30 -0800142 volatile uint32_t mUnderrunFrames; // server increments for each unavailable but desired frame
143 volatile uint32_t mUnderrunCount; // server increments for each underrun occurrence
Glenn Kastene3aa6592012-12-04 12:22:46 -0800144};
145
Andy Hung9b461582014-12-01 17:56:29 -0800146// Represents a single state of an AudioTrack that was created in static mode (shared memory buffer
147// supplied by the client). This state needs to be communicated from the client to server. As this
148// state is too large to be updated atomically without a mutex, and mutexes aren't allowed here, the
149// state is wrapped by a SingleStateQueue.
150struct StaticAudioTrackState {
151 // Do not define constructors, destructors, or virtual methods as this is part of a
152 // union in shared memory and they will not get called properly.
153
154 // These fields should both be size_t, but since they are located in shared memory we
155 // force to 32-bit. The client and server may have different typedefs for size_t.
156
157 // The state has a sequence counter to indicate whether changes are made to loop or position.
158 // The sequence counter also currently indicates whether loop or position is first depending
159 // on which is greater; it jumps by max(mLoopSequence, mPositionSequence) + 1.
160
161 uint32_t mLoopStart;
162 uint32_t mLoopEnd;
163 int32_t mLoopCount;
164 uint32_t mLoopSequence; // a sequence counter to indicate changes to loop
165 uint32_t mPosition;
166 uint32_t mPositionSequence; // a sequence counter to indicate changes to position
167};
168
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800169typedef SingleStateQueue<StaticAudioTrackState> StaticAudioTrackSingleStateQueue;
170
Andy Hung4ede21d2014-12-12 15:37:34 -0800171struct StaticAudioTrackPosLoop {
172 // Do not define constructors, destructors, or virtual methods as this is part of a
173 // union in shared memory and will not get called properly.
174
175 // These fields should both be size_t, but since they are located in shared memory we
176 // force to 32-bit. The client and server may have different typedefs for size_t.
177
178 // This struct information is stored in a single state queue to communicate the
179 // static AudioTrack server state to the client while data is consumed.
180 // It is smaller than StaticAudioTrackState to prevent unnecessary information from
181 // being sent.
182
183 uint32_t mBufferPosition;
184 int32_t mLoopCount;
185};
186
187typedef SingleStateQueue<StaticAudioTrackPosLoop> StaticAudioTrackPosLoopQueue;
188
Glenn Kastene3aa6592012-12-04 12:22:46 -0800189struct AudioTrackSharedStatic {
Andy Hung4ede21d2014-12-12 15:37:34 -0800190 // client requests to the server for loop or position changes.
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800191 StaticAudioTrackSingleStateQueue::Shared
192 mSingleStateQueue;
Andy Hung4ede21d2014-12-12 15:37:34 -0800193 // position info updated asynchronously by server and read by client,
194 // "for entertainment purposes only"
195 StaticAudioTrackPosLoopQueue::Shared
196 mPosLoopQueue;
Glenn Kastene3aa6592012-12-04 12:22:46 -0800197};
198
Ricardo Garcia5a8a95d2015-04-18 14:47:04 -0700199typedef SingleStateQueue<AudioPlaybackRate> PlaybackRateQueue;
Andy Hung8edb8dc2015-03-26 19:13:55 -0700200
Andy Hung3f0c9022016-01-15 17:49:46 -0800201typedef SingleStateQueue<ExtendedTimestamp> ExtendedTimestampQueue;
202
Glenn Kastene3aa6592012-12-04 12:22:46 -0800203// ----------------------------------------------------------------------------
204
Glenn Kasten1a0ae5b2012-02-03 10:24:48 -0800205// Important: do not add any virtual methods, including ~
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800206struct audio_track_cblk_t
207{
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800208 // Since the control block is always located in shared memory, this constructor
209 // is only used for placement new(). It is never used for regular new() or stack.
210 audio_track_cblk_t();
211 /*virtual*/ ~audio_track_cblk_t() { }
212
Glenn Kastene3aa6592012-12-04 12:22:46 -0800213 friend class Proxy;
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800214 friend class ClientProxy;
Glenn Kastene3aa6592012-12-04 12:22:46 -0800215 friend class AudioTrackClientProxy;
216 friend class AudioRecordClientProxy;
217 friend class ServerProxy;
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800218 friend class AudioTrackServerProxy;
219 friend class AudioRecordServerProxy;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800220
221 // The data members are grouped so that members accessed frequently and in the same context
222 // are in the same line of data cache.
Glenn Kasten99e53b82012-01-19 08:59:58 -0800223
Glenn Kastenf20e1d82013-07-12 09:45:18 -0700224 uint32_t mServer; // Number of filled frames consumed by server (mIsOut),
225 // or filled frames provided by server (!mIsOut).
226 // It is updated asynchronously by server without a barrier.
Glenn Kastenb187de12014-12-30 08:18:15 -0800227 // The value should be used
228 // "for entertainment purposes only",
Glenn Kastenf20e1d82013-07-12 09:45:18 -0700229 // which means don't make important decisions based on it.
Glenn Kasten22eb4e22012-11-07 14:03:00 -0800230
Glenn Kasten74935e42013-12-19 08:56:45 -0800231 uint32_t mPad1; // unused
Glenn Kasten99e53b82012-01-19 08:59:58 -0800232
Glenn Kasten0d09a9b2013-06-24 12:06:46 -0700233 volatile int32_t mFutex; // event flag: down (P) by client,
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800234 // up (V) by server or binderDied() or interrupt()
Glenn Kasten0d09a9b2013-06-24 12:06:46 -0700235#define CBLK_FUTEX_WAKE 1 // if event flag bit is set, then a deferred wake is pending
Glenn Kasten99e53b82012-01-19 08:59:58 -0800236
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800237private:
238
Glenn Kastenfdac7c02014-01-28 11:03:28 -0800239 // This field should be a size_t, but since it is located in shared memory we
240 // force to 32-bit. The client and server may have different typedefs for size_t.
241 uint32_t mMinimum; // server wakes up client if available >= mMinimum
Glenn Kastenb1cf75c2012-01-17 12:20:54 -0800242
Glenn Kastenc56f3422014-03-21 17:53:17 -0700243 // Stereo gains for AudioTrack only, not used by AudioRecord.
244 gain_minifloat_packed_t mVolumeLR;
Glenn Kastenb1cf75c2012-01-17 12:20:54 -0800245
Glenn Kastene3aa6592012-12-04 12:22:46 -0800246 uint32_t mSampleRate; // AudioTrack only: client's requested sample rate in Hz
247 // or 0 == default. Write-only client, read-only server.
Glenn Kasten99e53b82012-01-19 08:59:58 -0800248
Ricardo Garcia5a8a95d2015-04-18 14:47:04 -0700249 PlaybackRateQueue::Shared mPlaybackRateQueue;
Andy Hung8edb8dc2015-03-26 19:13:55 -0700250
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800251 // client write-only, server read-only
252 uint16_t mSendLevel; // Fixed point U4.12 so 0x1000 means 1.0
253
Colin Crossb8c35f92017-04-27 16:15:51 -0700254 uint16_t mPad2 __attribute__((__unused__)); // unused
Eric Laurentd1b449a2010-05-14 03:26:45 -0700255
Andy Hung3f0c9022016-01-15 17:49:46 -0800256 // server write-only, client read
Eric Laurent8ce8e262016-02-16 11:59:23 -0800257 ExtendedTimestampQueue::Shared mExtendedTimestampQueue;
Andy Hung818e7a32016-02-16 18:08:07 -0800258
Phil Burke8972b02016-03-04 11:29:57 -0800259 // This is set by AudioTrack.setBufferSizeInFrames().
260 // A write will not fill the buffer above this limit.
261 volatile uint32_t mBufferSizeInFrames; // effective size of the buffer
Andy Hung3c7f47a2021-03-16 17:30:09 -0700262 volatile uint32_t mStartThresholdInFrames; // min frames in buffer to start streaming
Phil Burke8972b02016-03-04 11:29:57 -0800263
Glenn Kastene3aa6592012-12-04 12:22:46 -0800264public:
Glenn Kasten99e53b82012-01-19 08:59:58 -0800265
Glenn Kasten96f60d82013-07-12 10:21:18 -0700266 volatile int32_t mFlags; // combinations of CBLK_*
Eric Laurent38ccae22011-03-28 18:37:07 -0700267
Andy Hung959b5b82021-09-24 10:46:20 -0700268 std::atomic<int32_t> mState; // current TrackBase state.
269
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800270public:
Glenn Kastene3aa6592012-12-04 12:22:46 -0800271 union {
272 AudioTrackSharedStreaming mStreaming;
273 AudioTrackSharedStatic mStatic;
274 int mAlign[8];
275 } u;
276
277 // Cache line boundary (32 bytes)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800278};
279
Andy Hung959b5b82021-09-24 10:46:20 -0700280// TODO: ensure standard layout.
281// static_assert(std::is_standard_layout_v<audio_track_cblk_t>);
282
Glenn Kastene3aa6592012-12-04 12:22:46 -0800283// ----------------------------------------------------------------------------
284
285// Proxy for shared memory control block, to isolate callers from needing to know the details.
286// There is exactly one ClientProxy and one ServerProxy per shared memory control block.
287// The proxies are located in normal memory, and are not multi-thread safe within a given side.
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800288class Proxy : public RefBase {
Glenn Kastene3aa6592012-12-04 12:22:46 -0800289protected:
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800290 Proxy(audio_track_cblk_t* cblk, void *buffers, size_t frameCount, size_t frameSize, bool isOut,
291 bool clientInServer);
Glenn Kastene3aa6592012-12-04 12:22:46 -0800292 virtual ~Proxy() { }
293
294public:
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800295 struct Buffer {
296 size_t mFrameCount; // number of frames available in this buffer
297 void* mRaw; // pointer to first frame
298 size_t mNonContig; // number of additional non-contiguous frames available
299 };
Glenn Kastene3aa6592012-12-04 12:22:46 -0800300
Phil Burkc0adecb2016-01-08 12:44:11 -0800301 size_t frameCount() const { return mFrameCount; }
Andy Hung3c7f47a2021-03-16 17:30:09 -0700302 uint32_t getStartThresholdInFrames() const;
303 uint32_t setStartThresholdInFrames(uint32_t startThresholdInFrames);
Phil Burkc0adecb2016-01-08 12:44:11 -0800304
Glenn Kastene3aa6592012-12-04 12:22:46 -0800305protected:
306 // These refer to shared memory, and are virtual addresses with respect to the current process.
307 // They may have different virtual addresses within the other process.
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800308 audio_track_cblk_t* const mCblk; // the control block
309 void* const mBuffers; // starting address of buffers
Glenn Kastene3aa6592012-12-04 12:22:46 -0800310
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800311 const size_t mFrameCount; // not necessarily a power of 2
312 const size_t mFrameSize; // in bytes
313 const size_t mFrameCountP2; // mFrameCount rounded to power of 2, streaming mode
314 const bool mIsOut; // true for AudioTrack, false for AudioRecord
315 const bool mClientInServer; // true for OutputTrack, false for AudioTrack & AudioRecord
316 bool mIsShutdown; // latch set to true when shared memory corruption detected
Glenn Kasten7db7df02013-06-25 16:13:23 -0700317 size_t mUnreleased; // unreleased frames remaining from most recent obtainBuffer
Glenn Kastene3aa6592012-12-04 12:22:46 -0800318};
319
320// ----------------------------------------------------------------------------
321
322// Proxy seen by AudioTrack client and AudioRecord client
323class ClientProxy : public Proxy {
Eric Laurent83b88082014-06-20 18:31:16 -0700324public:
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800325 ClientProxy(audio_track_cblk_t* cblk, void *buffers, size_t frameCount, size_t frameSize,
326 bool isOut, bool clientInServer);
Glenn Kastene3aa6592012-12-04 12:22:46 -0800327 virtual ~ClientProxy() { }
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800328
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800329 static const struct timespec kForever;
330 static const struct timespec kNonBlocking;
331
332 // Obtain a buffer with filled frames (reading) or empty frames (writing).
333 // It is permitted to call obtainBuffer() multiple times in succession, without any intervening
334 // calls to releaseBuffer(). In that case, the final obtainBuffer() is the one that effectively
335 // sets or extends the unreleased frame count.
336 // On entry:
337 // buffer->mFrameCount should be initialized to maximum number of desired frames,
338 // which must be > 0.
339 // buffer->mNonContig is unused.
340 // buffer->mRaw is unused.
341 // requested is the requested timeout in local monotonic delta time units:
342 // NULL or &kNonBlocking means non-blocking (zero timeout).
343 // &kForever means block forever (infinite timeout).
344 // Other values mean a specific timeout in local monotonic delta time units.
345 // elapsed is a pointer to a location that will hold the total local monotonic time that
346 // elapsed while blocked, or NULL if not needed.
347 // On exit:
348 // buffer->mFrameCount has the actual number of contiguous available frames,
349 // which is always 0 when the return status != NO_ERROR.
350 // buffer->mNonContig is the number of additional non-contiguous available frames.
351 // buffer->mRaw is a pointer to the first available frame,
352 // or NULL when buffer->mFrameCount == 0.
353 // The return status is one of:
354 // NO_ERROR Success, buffer->mFrameCount > 0.
355 // WOULD_BLOCK Non-blocking mode and no frames are available.
356 // TIMED_OUT Timeout occurred before any frames became available.
357 // This can happen even for infinite timeout, due to a spurious wakeup.
358 // In this case, the caller should investigate and then re-try as appropriate.
359 // DEAD_OBJECT Server has died or invalidated, caller should destroy this proxy and re-create.
360 // -EINTR Call has been interrupted. Look around to see why, and then perhaps try again.
361 // NO_INIT Shared memory is corrupt.
Eric Laurent4d231dc2016-03-11 18:38:23 -0800362 // NOT_ENOUGH_DATA Server has disabled the track because of underrun: restart the track
363 // if still in active state.
Glenn Kasten7db7df02013-06-25 16:13:23 -0700364 // Assertion failure on entry, if buffer == NULL or buffer->mFrameCount == 0.
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800365 status_t obtainBuffer(Buffer* buffer, const struct timespec *requested = NULL,
366 struct timespec *elapsed = NULL);
367
368 // Release (some of) the frames last obtained.
369 // On entry, buffer->mFrameCount should have the number of frames to release,
370 // which must (cumulatively) be <= the number of frames last obtained but not yet released.
371 // buffer->mRaw is ignored, but is normally same pointer returned by last obtainBuffer().
372 // It is permitted to call releaseBuffer() multiple times to release the frames in chunks.
373 // On exit:
374 // buffer->mFrameCount is zero.
375 // buffer->mRaw is NULL.
376 void releaseBuffer(Buffer* buffer);
377
378 // Call after detecting server's death
379 void binderDied();
380
381 // Call to force an obtainBuffer() to return quickly with -EINTR
382 void interrupt();
383
Andy Hung90e8a972015-11-09 16:42:40 -0800384 Modulo<uint32_t> getPosition() {
Glenn Kastenf20e1d82013-07-12 09:45:18 -0700385 return mEpoch + mCblk->mServer;
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800386 }
387
Phil Burkc0adecb2016-01-08 12:44:11 -0800388 void setEpoch(const Modulo<uint32_t> &epoch) {
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800389 mEpoch = epoch;
390 }
391
392 void setMinimum(size_t minimum) {
Glenn Kastenfdac7c02014-01-28 11:03:28 -0800393 // This can only happen on a 64-bit client
394 if (minimum > UINT32_MAX) {
395 minimum = UINT32_MAX;
396 }
397 mCblk->mMinimum = (uint32_t) minimum;
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800398 }
399
400 // Return the number of frames that would need to be obtained and released
401 // in order for the client to be aligned at start of buffer
402 virtual size_t getMisalignment();
403
Andy Hung90e8a972015-11-09 16:42:40 -0800404 Modulo<uint32_t> getEpoch() const {
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800405 return mEpoch;
406 }
407
Andy Hung959b5b82021-09-24 10:46:20 -0700408 int32_t getState() const { return mCblk->mState; }
Phil Burke8972b02016-03-04 11:29:57 -0800409 uint32_t getBufferSizeInFrames() const { return mBufferSizeInFrames; }
410 // See documentation for AudioTrack::setBufferSizeInFrames()
411 uint32_t setBufferSizeInFrames(uint32_t requestedSize);
Phil Burkc0adecb2016-01-08 12:44:11 -0800412
Andy Hung6ae58432016-02-16 18:32:24 -0800413 status_t getTimestamp(ExtendedTimestamp *timestamp) {
414 if (timestamp == nullptr) {
415 return BAD_VALUE;
416 }
417 (void) mTimestampObserver.poll(mTimestamp);
418 *timestamp = mTimestamp;
419 return OK;
420 }
421
422 void clearTimestamp() {
423 mTimestamp.clear();
424 }
425
Andy Hung1d3556d2018-03-29 16:30:14 -0700426 virtual void stop() { }; // called by client in AudioTrack::stop()
427
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800428private:
Phil Burke8972b02016-03-04 11:29:57 -0800429 // This is a copy of mCblk->mBufferSizeInFrames
430 uint32_t mBufferSizeInFrames; // effective size of the buffer
431
Andy Hung90e8a972015-11-09 16:42:40 -0800432 Modulo<uint32_t> mEpoch;
Andy Hung6ae58432016-02-16 18:32:24 -0800433
434 // The shared buffer contents referred to by the timestamp observer
435 // is initialized when the server proxy created. A local zero timestamp
436 // is initialized by the client constructor.
437 ExtendedTimestampQueue::Observer mTimestampObserver;
438 ExtendedTimestamp mTimestamp; // initialized by constructor
Glenn Kastene3aa6592012-12-04 12:22:46 -0800439};
440
441// ----------------------------------------------------------------------------
442
443// Proxy used by AudioTrack client, which also includes AudioFlinger::PlaybackThread::OutputTrack
444class AudioTrackClientProxy : public ClientProxy {
445public:
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800446 AudioTrackClientProxy(audio_track_cblk_t* cblk, void *buffers, size_t frameCount,
447 size_t frameSize, bool clientInServer = false)
448 : ClientProxy(cblk, buffers, frameCount, frameSize, true /*isOut*/,
Andy Hung8edb8dc2015-03-26 19:13:55 -0700449 clientInServer),
Andy Hung6ae58432016-02-16 18:32:24 -0800450 mPlaybackRateMutator(&cblk->mPlaybackRateQueue) {
451 }
452
Glenn Kastene3aa6592012-12-04 12:22:46 -0800453 virtual ~AudioTrackClientProxy() { }
454
455 // No barriers on the following operations, so the ordering of loads/stores
456 // with respect to other parameters is UNPREDICTABLE. That's considered safe.
457
458 // caller must limit to 0.0 <= sendLevel <= 1.0
459 void setSendLevel(float sendLevel) {
460 mCblk->mSendLevel = uint16_t(sendLevel * 0x1000);
461 }
462
Glenn Kastenc56f3422014-03-21 17:53:17 -0700463 // set stereo gains
464 void setVolumeLR(gain_minifloat_packed_t volumeLR) {
Glenn Kastene3aa6592012-12-04 12:22:46 -0800465 mCblk->mVolumeLR = volumeLR;
466 }
467
468 void setSampleRate(uint32_t sampleRate) {
469 mCblk->mSampleRate = sampleRate;
470 }
471
Ricardo Garcia5a8a95d2015-04-18 14:47:04 -0700472 void setPlaybackRate(const AudioPlaybackRate& playbackRate) {
Andy Hung8edb8dc2015-03-26 19:13:55 -0700473 mPlaybackRateMutator.push(playbackRate);
474 }
475
Andy Hung1d3556d2018-03-29 16:30:14 -0700476 // Sends flush and stop position information from the client to the server,
477 // used by streaming AudioTrack flush() or stop().
478 void sendStreamingFlushStop(bool flush);
479
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800480 virtual void flush();
481
Andy Hung1d3556d2018-03-29 16:30:14 -0700482 void stop() override;
483
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800484 virtual uint32_t getUnderrunFrames() const {
485 return mCblk->u.mStreaming.mUnderrunFrames;
486 }
Phil Burk2812d9e2016-01-04 10:34:30 -0800487 virtual uint32_t getUnderrunCount() const {
488 return mCblk->u.mStreaming.mUnderrunCount;
489 }
Eric Laurentbfb1b832013-01-07 09:53:42 -0800490
491 bool clearStreamEndDone(); // and return previous value
492
493 bool getStreamEndDone() const;
494
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100495 status_t waitStreamEndDone(const struct timespec *requested);
Andy Hung8edb8dc2015-03-26 19:13:55 -0700496
497private:
Ricardo Garcia5a8a95d2015-04-18 14:47:04 -0700498 PlaybackRateQueue::Mutator mPlaybackRateMutator;
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800499};
500
501class StaticAudioTrackClientProxy : public AudioTrackClientProxy {
502public:
503 StaticAudioTrackClientProxy(audio_track_cblk_t* cblk, void *buffers, size_t frameCount,
504 size_t frameSize);
505 virtual ~StaticAudioTrackClientProxy() { }
506
507 virtual void flush();
508
Andy Hung1d3556d2018-03-29 16:30:14 -0700509 void stop() override;
510
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800511#define MIN_LOOP 16 // minimum length of each loop iteration in frames
Andy Hung9b461582014-12-01 17:56:29 -0800512
513 // setLoop(), setBufferPosition(), and setBufferPositionAndLoop() set the
514 // static buffer position and looping parameters. These commands are not
515 // synchronous (they do not wait or block); instead they take effect at the
516 // next buffer data read from the server side. However, the client side
517 // getters will read a cached version of the position and loop variables
518 // until the setting takes effect.
519 //
520 // setBufferPositionAndLoop() is equivalent to calling, in order, setLoop() and
521 // setBufferPosition().
522 //
523 // The functions should not be relied upon to do parameter or state checking.
524 // That is done at the AudioTrack level.
525
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800526 void setLoop(size_t loopStart, size_t loopEnd, int loopCount);
Andy Hung9b461582014-12-01 17:56:29 -0800527 void setBufferPosition(size_t position);
528 void setBufferPositionAndLoop(size_t position, size_t loopStart, size_t loopEnd,
529 int loopCount);
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800530 size_t getBufferPosition();
Andy Hung4ede21d2014-12-12 15:37:34 -0800531 // getBufferPositionAndLoopCount() provides the proper snapshot of
532 // position and loopCount together.
533 void getBufferPositionAndLoopCount(size_t *position, int *loopCount);
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800534
535 virtual size_t getMisalignment() {
536 return 0;
Glenn Kastene3aa6592012-12-04 12:22:46 -0800537 }
538
Andy Hung03e1e2c2018-02-20 12:49:08 -0800539 virtual uint32_t getUnderrunFrames() const override {
540 return 0;
541 }
542
543 virtual uint32_t getUnderrunCount() const override {
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800544 return 0;
Glenn Kastene3aa6592012-12-04 12:22:46 -0800545 }
546
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800547private:
548 StaticAudioTrackSingleStateQueue::Mutator mMutator;
Andy Hung4ede21d2014-12-12 15:37:34 -0800549 StaticAudioTrackPosLoopQueue::Observer mPosLoopObserver;
Andy Hung9b461582014-12-01 17:56:29 -0800550 StaticAudioTrackState mState; // last communicated state to server
Andy Hung4ede21d2014-12-12 15:37:34 -0800551 StaticAudioTrackPosLoop mPosLoop; // snapshot of position and loop.
Glenn Kastene3aa6592012-12-04 12:22:46 -0800552};
553
554// ----------------------------------------------------------------------------
555
556// Proxy used by AudioRecord client
557class AudioRecordClientProxy : public ClientProxy {
558public:
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800559 AudioRecordClientProxy(audio_track_cblk_t* cblk, void *buffers, size_t frameCount,
560 size_t frameSize)
561 : ClientProxy(cblk, buffers, frameCount, frameSize,
Andy Hung6ae58432016-02-16 18:32:24 -0800562 false /*isOut*/, false /*clientInServer*/) { }
Glenn Kastene3aa6592012-12-04 12:22:46 -0800563 ~AudioRecordClientProxy() { }
Andy Hung3f0c9022016-01-15 17:49:46 -0800564
Andy Hung3f0c9022016-01-15 17:49:46 -0800565 // Advances the client read pointer to the server write head pointer
566 // effectively flushing the client read buffer. The effect is
567 // instantaneous. Returns the number of frames flushed.
568 uint32_t flush() {
569 int32_t rear = android_atomic_acquire_load(&mCblk->u.mStreaming.mRear);
570 int32_t front = mCblk->u.mStreaming.mFront;
571 android_atomic_release_store(rear, &mCblk->u.mStreaming.mFront);
572 return (Modulo<int32_t>(rear) - front).unsignedValue();
573 }
Glenn Kastene3aa6592012-12-04 12:22:46 -0800574};
575
576// ----------------------------------------------------------------------------
577
578// Proxy used by AudioFlinger server
579class ServerProxy : public Proxy {
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800580protected:
581 ServerProxy(audio_track_cblk_t* cblk, void *buffers, size_t frameCount, size_t frameSize,
582 bool isOut, bool clientInServer);
Glenn Kastene3aa6592012-12-04 12:22:46 -0800583public:
Glenn Kastene3aa6592012-12-04 12:22:46 -0800584 virtual ~ServerProxy() { }
585
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800586 // Obtain a buffer with filled frames (writing) or empty frames (reading).
587 // It is permitted to call obtainBuffer() multiple times in succession, without any intervening
588 // calls to releaseBuffer(). In that case, the final obtainBuffer() is the one that effectively
589 // sets or extends the unreleased frame count.
590 // Always non-blocking.
591 // On entry:
592 // buffer->mFrameCount should be initialized to maximum number of desired frames,
593 // which must be > 0.
594 // buffer->mNonContig is unused.
595 // buffer->mRaw is unused.
Glenn Kasten2e422c42013-10-18 13:00:29 -0700596 // ackFlush is true iff being called from Track::start to acknowledge a pending flush.
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800597 // On exit:
598 // buffer->mFrameCount has the actual number of contiguous available frames,
599 // which is always 0 when the return status != NO_ERROR.
600 // buffer->mNonContig is the number of additional non-contiguous available frames.
601 // buffer->mRaw is a pointer to the first available frame,
602 // or NULL when buffer->mFrameCount == 0.
603 // The return status is one of:
604 // NO_ERROR Success, buffer->mFrameCount > 0.
605 // WOULD_BLOCK No frames are available.
606 // NO_INIT Shared memory is corrupt.
Glenn Kasten2e422c42013-10-18 13:00:29 -0700607 virtual status_t obtainBuffer(Buffer* buffer, bool ackFlush = false);
Glenn Kastene3aa6592012-12-04 12:22:46 -0800608
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800609 // Release (some of) the frames last obtained.
610 // On entry, buffer->mFrameCount should have the number of frames to release,
611 // which must (cumulatively) be <= the number of frames last obtained but not yet released.
612 // It is permitted to call releaseBuffer() multiple times to release the frames in chunks.
613 // buffer->mRaw is ignored, but is normally same pointer returned by last obtainBuffer().
614 // On exit:
615 // buffer->mFrameCount is zero.
616 // buffer->mRaw is NULL.
617 virtual void releaseBuffer(Buffer* buffer);
618
Andy Hung6ae58432016-02-16 18:32:24 -0800619 // Return the total number of frames that AudioFlinger has obtained and released
620 virtual int64_t framesReleased() const { return mReleased; }
621
622 // Expose timestamp to client proxy. Should only be called by a single thread.
623 virtual void setTimestamp(const ExtendedTimestamp &timestamp) {
624 mTimestampMutator.push(timestamp);
625 }
626
Andy Hungf6ab58d2018-05-25 12:50:39 -0700627 virtual ExtendedTimestamp getTimestamp() const {
628 return mTimestampMutator.last();
629 }
630
Phil Burk4bb650b2016-09-09 12:11:17 -0700631 // Flushes the shared ring buffer if the client had requested it using mStreaming.mFlush.
632 // If flush occurs then:
633 // cblk->u.mStreaming.mFront, ServerProxy::mFlush and ServerProxy::mFlushed will be modified
634 // client will be notified via Futex
635 virtual void flushBufferIfNeeded();
636
Andy Hung1d3556d2018-03-29 16:30:14 -0700637 // Returns the rear position of the AudioTrack shared ring buffer, limited by
638 // the stop frame position level.
639 virtual int32_t getRear() const = 0;
640
Andy Hungea2b9c02016-02-12 17:06:53 -0800641 // Total count of the number of flushed frames since creation (never reset).
642 virtual int64_t framesFlushed() const { return mFlushed; }
643
Andy Hung2a4e1612018-06-01 15:06:09 -0700644 // Safe frames ready query with no side effects.
645 virtual size_t framesReadySafe() const = 0;
646
Phil Burke8972b02016-03-04 11:29:57 -0800647 // Get dynamic buffer size from the shared control block.
648 uint32_t getBufferSizeInFrames() const {
649 return android_atomic_acquire_load((int32_t *)&mCblk->mBufferSizeInFrames);
650 }
651
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800652protected:
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800653 size_t mAvailToClient; // estimated frames available to client prior to releaseBuffer()
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800654 int32_t mFlush; // our copy of cblk->u.mStreaming.mFlush, for streaming output only
Andy Hung3f0c9022016-01-15 17:49:46 -0800655 int64_t mReleased; // our copy of cblk->mServer, at 64 bit resolution
Andy Hungea2b9c02016-02-12 17:06:53 -0800656 int64_t mFlushed; // flushed frames to account for client-server discrepancy
Andy Hung6ae58432016-02-16 18:32:24 -0800657 ExtendedTimestampQueue::Mutator mTimestampMutator;
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800658};
659
660// Proxy used by AudioFlinger for servicing AudioTrack
661class AudioTrackServerProxy : public ServerProxy {
662public:
663 AudioTrackServerProxy(audio_track_cblk_t* cblk, void *buffers, size_t frameCount,
Kevin Rocard36862032019-10-10 10:52:19 +0100664 size_t frameSize, bool clientInServer, uint32_t sampleRate)
Andy Hung8edb8dc2015-03-26 19:13:55 -0700665 : ServerProxy(cblk, buffers, frameCount, frameSize, true /*isOut*/, clientInServer),
Phil Burk2812d9e2016-01-04 10:34:30 -0800666 mPlaybackRateObserver(&cblk->mPlaybackRateQueue),
Andy Hung818e7a32016-02-16 18:08:07 -0800667 mUnderrunCount(0), mUnderrunning(false), mDrained(true) {
Eric Laurent83b88082014-06-20 18:31:16 -0700668 mCblk->mSampleRate = sampleRate;
Ricardo Garcia5a8a95d2015-04-18 14:47:04 -0700669 mPlaybackRate = AUDIO_PLAYBACK_RATE_DEFAULT;
Eric Laurent83b88082014-06-20 18:31:16 -0700670 }
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800671protected:
672 virtual ~AudioTrackServerProxy() { }
673
674public:
Glenn Kastene3aa6592012-12-04 12:22:46 -0800675 // return value of these methods must be validated by the caller
676 uint32_t getSampleRate() const { return mCblk->mSampleRate; }
677 uint16_t getSendLevel_U4_12() const { return mCblk->mSendLevel; }
Glenn Kastenc56f3422014-03-21 17:53:17 -0700678 gain_minifloat_packed_t getVolumeLR() const { return mCblk->mVolumeLR; }
Glenn Kastene3aa6592012-12-04 12:22:46 -0800679
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800680 // estimated total number of filled frames available to server to read,
681 // which may include non-contiguous frames
682 virtual size_t framesReady();
Glenn Kastene3aa6592012-12-04 12:22:46 -0800683
Andy Hung2a4e1612018-06-01 15:06:09 -0700684 size_t framesReadySafe() const override; // frames available to read by server.
Andy Hung2c6c3bb2017-06-16 14:01:45 -0700685
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800686 // Currently AudioFlinger will call framesReady() for a fast track from two threads:
687 // FastMixer thread, and normal mixer thread. This is dangerous, as the proxy is intended
688 // to be called from at most one thread of server, and one thread of client.
689 // As a temporary workaround, this method informs the proxy implementation that it
690 // should avoid doing a state queue poll from within framesReady().
691 // FIXME Change AudioFlinger to not call framesReady() from normal mixer thread.
692 virtual void framesReadyIsCalledByMultipleThreads() { }
Eric Laurentbfb1b832013-01-07 09:53:42 -0800693
694 bool setStreamEndDone(); // and return previous value
Glenn Kasten82aaf942013-07-17 16:05:07 -0700695
696 // Add to the tally of underrun frames, and inform client of underrun
697 virtual void tallyUnderrunFrames(uint32_t frameCount);
698
699 // Return the total number of frames which AudioFlinger desired but were unavailable,
700 // and thus which resulted in an underrun.
701 virtual uint32_t getUnderrunFrames() const { return mCblk->u.mStreaming.mUnderrunFrames; }
Glenn Kastenbd096fd2013-08-23 13:53:56 -0700702
Andy Hungc2b11cb2020-04-22 09:04:01 -0700703 virtual uint32_t getUnderrunCount() const { return mCblk->u.mStreaming.mUnderrunCount; }
704
Andy Hung8edb8dc2015-03-26 19:13:55 -0700705 // Return the playback speed and pitch read atomically. Not multi-thread safe on server side.
Ricardo Garcia5a8a95d2015-04-18 14:47:04 -0700706 AudioPlaybackRate getPlaybackRate();
Andy Hung8edb8dc2015-03-26 19:13:55 -0700707
Andy Hung818e7a32016-02-16 18:08:07 -0800708 // Set the internal drain state of the track buffer from the timestamp received.
709 virtual void setDrained(bool drained) {
710 mDrained.store(drained);
711 }
712
713 // Check if the internal drain state of the track buffer.
714 // This is not a guarantee, but advisory for determining whether the track is
715 // fully played out.
716 virtual bool isDrained() const {
717 return mDrained.load();
718 }
719
Andy Hung1d3556d2018-03-29 16:30:14 -0700720 int32_t getRear() const override;
721
722 // Called on server side track start().
723 virtual void start();
724
Andy Hung8edb8dc2015-03-26 19:13:55 -0700725private:
Ricardo Garcia5a8a95d2015-04-18 14:47:04 -0700726 AudioPlaybackRate mPlaybackRate; // last observed playback rate
727 PlaybackRateQueue::Observer mPlaybackRateObserver;
Phil Burk2812d9e2016-01-04 10:34:30 -0800728
Andy Hung1d3556d2018-03-29 16:30:14 -0700729 // Last client stop-at position when start() was called. Used for streaming AudioTracks.
730 std::atomic<int32_t> mStopLast{0};
731
Phil Burk2812d9e2016-01-04 10:34:30 -0800732 // The server keeps a copy here where it is safe from the client.
733 uint32_t mUnderrunCount; // echoed to mCblk
734 bool mUnderrunning; // used to detect edge of underrun
Andy Hung818e7a32016-02-16 18:08:07 -0800735
736 std::atomic<bool> mDrained; // is the track buffer drained
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800737};
738
739class StaticAudioTrackServerProxy : public AudioTrackServerProxy {
740public:
741 StaticAudioTrackServerProxy(audio_track_cblk_t* cblk, void *buffers, size_t frameCount,
Kevin Rocard36862032019-10-10 10:52:19 +0100742 size_t frameSize, uint32_t sampleRate);
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800743protected:
744 virtual ~StaticAudioTrackServerProxy() { }
745
746public:
747 virtual size_t framesReady();
Andy Hung2c6c3bb2017-06-16 14:01:45 -0700748 virtual size_t framesReadySafe() const override;
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800749 virtual void framesReadyIsCalledByMultipleThreads();
Glenn Kasten2e422c42013-10-18 13:00:29 -0700750 virtual status_t obtainBuffer(Buffer* buffer, bool ackFlush);
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800751 virtual void releaseBuffer(Buffer* buffer);
Glenn Kasten82aaf942013-07-17 16:05:07 -0700752 virtual void tallyUnderrunFrames(uint32_t frameCount);
753 virtual uint32_t getUnderrunFrames() const { return 0; }
Glenn Kastene3aa6592012-12-04 12:22:46 -0800754
Andy Hung1d3556d2018-03-29 16:30:14 -0700755 int32_t getRear() const override;
756
757 void start() override { } // ignore for static tracks
758
Glenn Kastene3aa6592012-12-04 12:22:46 -0800759private:
Andy Hung9b461582014-12-01 17:56:29 -0800760 status_t updateStateWithLoop(StaticAudioTrackState *localState,
761 const StaticAudioTrackState &update) const;
762 status_t updateStateWithPosition(StaticAudioTrackState *localState,
763 const StaticAudioTrackState &update) const;
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800764 ssize_t pollPosition(); // poll for state queue update, and return current position
765 StaticAudioTrackSingleStateQueue::Observer mObserver;
Andy Hung4ede21d2014-12-12 15:37:34 -0800766 StaticAudioTrackPosLoopQueue::Mutator mPosLoopMutator;
Andy Hungcb2129b2014-11-11 12:17:22 -0800767 size_t mFramesReadySafe; // Assuming size_t read/writes are atomic on 32 / 64 bit
768 // processors, this is a thread-safe version of
769 // mFramesReady.
770 int64_t mFramesReady; // The number of frames ready in the static buffer
771 // including loops. This is 64 bits since loop mode
772 // can cause a track to appear to have a large number
773 // of frames. INT64_MAX means an infinite loop.
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800774 bool mFramesReadyIsCalledByMultipleThreads;
Andy Hung9b461582014-12-01 17:56:29 -0800775 StaticAudioTrackState mState; // Server side state. Any updates from client must be
776 // passed by the mObserver SingleStateQueue.
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800777};
Glenn Kastene3aa6592012-12-04 12:22:46 -0800778
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800779// Proxy used by AudioFlinger for servicing AudioRecord
780class AudioRecordServerProxy : public ServerProxy {
781public:
782 AudioRecordServerProxy(audio_track_cblk_t* cblk, void *buffers, size_t frameCount,
Eric Laurent83b88082014-06-20 18:31:16 -0700783 size_t frameSize, bool clientInServer)
Andy Hung6ae58432016-02-16 18:32:24 -0800784 : ServerProxy(cblk, buffers, frameCount, frameSize, false /*isOut*/, clientInServer) { }
Andy Hung3f0c9022016-01-15 17:49:46 -0800785
Andy Hung1d3556d2018-03-29 16:30:14 -0700786 int32_t getRear() const override {
787 return mCblk->u.mStreaming.mRear; // For completeness only; mRear written by server.
788 }
789
Andy Hung2a4e1612018-06-01 15:06:09 -0700790 size_t framesReadySafe() const override; // frames available to read by client.
791
Glenn Kasten9f80dd22012-12-18 15:57:32 -0800792protected:
793 virtual ~AudioRecordServerProxy() { }
Glenn Kastene3aa6592012-12-04 12:22:46 -0800794};
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800795
796// ----------------------------------------------------------------------------
797
798}; // namespace android
799
800#endif // ANDROID_AUDIO_TRACK_SHARED_H