summaryrefslogtreecommitdiffstats
path: root/include/private/media/AudioTrackShared.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/private/media/AudioTrackShared.h')
-rw-r--r--include/private/media/AudioTrackShared.h47
1 files changed, 39 insertions, 8 deletions
diff --git a/include/private/media/AudioTrackShared.h b/include/private/media/AudioTrackShared.h
index 20abd51..dd97ce4 100644
--- a/include/private/media/AudioTrackShared.h
+++ b/include/private/media/AudioTrackShared.h
@@ -59,8 +59,8 @@ struct audio_track_cblk_t
// The data members are grouped so that members accessed frequently and in the same context
// are in the same line of data cache.
- Mutex lock;
- Condition cv;
+ Mutex lock; // sizeof(int)
+ Condition cv; // sizeof(int)
volatile uint32_t user;
volatile uint32_t server;
uint32_t userBase;
@@ -71,21 +71,28 @@ struct audio_track_cblk_t
uint32_t loopStart;
uint32_t loopEnd;
int loopCount;
- volatile union {
- uint16_t volume[2];
- uint32_t volumeLR;
- };
+
+ // Channel volumes are fixed point U4.12, so 0x1000 means 1.0.
+ // Left channel is in [0:15], right channel is in [16:31].
+ // Always read and write the combined pair atomically.
+ // For AudioTrack only, not used by AudioRecord.
+private:
+ uint32_t mVolumeLR;
+public:
+
uint32_t sampleRate;
// NOTE: audio_track_cblk_t::frameSize is not equal to AudioTrack::frameSize() for
// 8 bit PCM data: in this case, mCblk->frameSize is based on a sample size of
// 16 bit because data is converted to 16 bit before being stored in buffer
- uint8_t frameSize;
+ uint8_t frameSize; // would normally be size_t, but 8 bits is plenty
uint8_t pad1;
uint16_t bufferTimeoutMs; // Maximum cumulated timeout before restarting audioflinger
uint16_t waitTimeMs; // Cumulated wait time
- uint16_t sendLevel;
+private:
+ uint16_t mSendLevel; // Fixed point U4.12 so 0x1000 means 1.0
+public:
volatile int32_t flags;
// Cache line boundary (32 bytes)
@@ -98,6 +105,30 @@ struct audio_track_cblk_t
uint32_t framesAvailable_l();
uint32_t framesReady();
bool tryLock();
+
+ // No barriers on the following operations, so the ordering of loads/stores
+ // with respect to other parameters is UNPREDICTABLE. That's considered safe.
+
+ // for AudioTrack client only, caller must limit to 0.0 <= sendLevel <= 1.0
+ void setSendLevel(float sendLevel) {
+ mSendLevel = uint16_t(sendLevel * 0x1000);
+ }
+
+ // for AudioFlinger only; the return value must be validated by the caller
+ uint16_t getSendLevel_U4_12() const {
+ return mSendLevel;
+ }
+
+ // for AudioTrack client only, caller must limit to 0 <= volumeLR <= 0x10001000
+ void setVolumeLR(uint32_t volumeLR) {
+ mVolumeLR = volumeLR;
+ }
+
+ // for AudioFlinger only; the return value must be validated by the caller
+ uint32_t getVolumeLR() const {
+ return mVolumeLR;
+ }
+
};