From 200092b7f21d2b98f30b800e79d152636f9ba225 Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Fri, 15 Aug 2014 15:13:30 -0700 Subject: Clean up AudioTrack position and timestamp handling Replace epoch concept by observing and accumulating server delta positions. The advantage of using server deltas instead of absolute values is that they (1) are not sensitive to 32-bit wraparound, (2) are not sensitive to server behavior for stop(), and (3) prepare for future 64-bit client positions without requiring 64-bit positions on server. Add comments to AudioTrack::getTimestamp() and friends that the timestamp output parameter is undefined on error. Don't allow getTimestamp to return a negative frame position after stop(). Accumulate the client released frames, which may be useful for a future API. Bug: 11815245 Change-Id: I652940fa2db2f34a78c012a3ead0d9204fa29c6e --- include/media/AudioTrack.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'include/media/AudioTrack.h') diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h index a3cc396..72e51f9 100644 --- a/include/media/AudioTrack.h +++ b/include/media/AudioTrack.h @@ -430,7 +430,7 @@ public: * - NO_ERROR: successful operation * - BAD_VALUE: position is NULL */ - status_t getPosition(uint32_t *position) const; + status_t getPosition(uint32_t *position); /* For static buffer mode only, this returns the current playback position in frames * relative to start of buffer. It is analogous to the position units used by @@ -581,6 +581,7 @@ public: * if you need a high resolution mapping between frame position and presentation time, * consider implementing that at application level, based on the low resolution timestamps. * Returns NO_ERROR if timestamp is valid. + * The timestamp parameter is undefined on return, if status is not NO_ERROR. */ status_t getTimestamp(AudioTimestamp& timestamp); @@ -639,7 +640,7 @@ protected: // caller must hold lock on mLock for all _l methods - status_t createTrack_l(size_t epoch); + status_t createTrack_l(); // can only be called when mState != STATE_ACTIVE void flush_l(); @@ -659,6 +660,9 @@ protected: bool isDirect_l() const { return (mFlags & AUDIO_OUTPUT_FLAG_DIRECT) != 0; } + // increment mPosition by the delta of mServer, and return new value of mPosition + uint32_t updateAndGetPosition_l(); + // Next 4 fields may be changed if IAudioTrack is re-created, but always != 0 sp mAudioTrack; sp mCblkMemory; @@ -731,6 +735,18 @@ protected: bool mMarkerReached; uint32_t mNewPosition; // in frames uint32_t mUpdatePeriod; // in frames, zero means no EVENT_NEW_POS + uint32_t mServer; // in frames, last known mProxy->getPosition() + // which is count of frames consumed by server, + // reset by new IAudioTrack, + // whether it is reset by stop() is TBD + uint32_t mPosition; // in frames, like mServer except continues + // monotonically after new IAudioTrack, + // and could be easily widened to uint64_t + uint32_t mReleased; // in frames, count of frames released to server + // but not necessarily consumed by server, + // reset by stop() but continues monotonically + // after new IAudioTrack to restore mPosition, + // and could be easily widened to uint64_t audio_output_flags_t mFlags; // const after set(), except for bits AUDIO_OUTPUT_FLAG_FAST and AUDIO_OUTPUT_FLAG_OFFLOAD. -- cgit v1.1