summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2014-01-13 10:37:17 -0800
committerGlenn Kasten <gkasten@google.com>2014-01-14 14:20:18 -0800
commit23a7545c4de71e989c2d8ebf1d5b9dcf463c36a9 (patch)
tree13f9b25c2dcc70506e3c743c817fce0998021be9
parent84fba38b60c2ddb02b9a787f56be88fc084b4a16 (diff)
downloadframeworks_av-23a7545c4de71e989c2d8ebf1d5b9dcf463c36a9.zip
frameworks_av-23a7545c4de71e989c2d8ebf1d5b9dcf463c36a9.tar.gz
frameworks_av-23a7545c4de71e989c2d8ebf1d5b9dcf463c36a9.tar.bz2
Document locking rules for mFlags, and fix discrepancies
Change-Id: Id45ba544cc84133ed5e578fb4fd8a11b62211dc1
-rw-r--r--include/media/AudioTrack.h9
-rw-r--r--media/libmedia/AudioTrack.cpp25
2 files changed, 23 insertions, 11 deletions
diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h
index 9fc589d..4fe537f 100644
--- a/include/media/AudioTrack.h
+++ b/include/media/AudioTrack.h
@@ -568,7 +568,7 @@ public:
uint32_t getUnderrunFrames() const;
/* Get the flags */
- audio_output_flags_t getFlags() const { return mFlags; }
+ audio_output_flags_t getFlags() const { AutoMutex _l(mLock); return mFlags; }
/* Set parameters - only possible when using direct output */
status_t setParameters(const String8& keyValuePairs);
@@ -630,6 +630,8 @@ protected:
static const nsecs_t NS_WHENEVER = -1, NS_INACTIVE = -2, NS_NEVER = -3;
nsecs_t processAudioBuffer();
+ bool isOffloaded() const;
+
// caller must hold lock on mLock for all _l methods
status_t createTrack_l(audio_stream_type_t streamType,
@@ -650,7 +652,7 @@ protected:
// FIXME enum is faster than strcmp() for parameter 'from'
status_t restoreTrack_l(const char *from);
- bool isOffloaded() const
+ bool isOffloaded_l() const
{ return (mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0; }
// Next 3 fields may be changed if IAudioTrack is re-created, but always != 0
@@ -720,6 +722,9 @@ protected:
uint32_t mUpdatePeriod; // in frames, zero means no EVENT_NEW_POS
audio_output_flags_t mFlags;
+ // const after set(), except for bits AUDIO_OUTPUT_FLAG_FAST and AUDIO_OUTPUT_FLAG_OFFLOAD.
+ // mLock must be held to read or write those bits reliably.
+
int mSessionId;
int mAuxEffectId;
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 50e394b..8954d9f 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -457,7 +457,7 @@ void AudioTrack::stop()
return;
}
- if (isOffloaded()) {
+ if (isOffloaded_l()) {
mState = STATE_STOPPING;
} else {
mState = STATE_STOPPED;
@@ -479,7 +479,7 @@ void AudioTrack::stop()
sp<AudioTrackThread> t = mAudioTrackThread;
if (t != 0) {
- if (!isOffloaded()) {
+ if (!isOffloaded_l()) {
t->pause();
}
} else {
@@ -517,7 +517,7 @@ void AudioTrack::flush_l()
mRefreshRemaining = true;
mState = STATE_FLUSHED;
- if (isOffloaded()) {
+ if (isOffloaded_l()) {
mProxy->interrupt();
}
mProxy->flush();
@@ -550,7 +550,7 @@ status_t AudioTrack::setVolume(float left, float right)
mProxy->setVolumeLR((uint32_t(uint16_t(right * 0x1000)) << 16) | uint16_t(left * 0x1000));
- if (isOffloaded()) {
+ if (isOffloaded_l()) {
mAudioTrack->signal();
}
return NO_ERROR;
@@ -614,7 +614,7 @@ uint32_t AudioTrack::getSampleRate() const
// sample rate can be updated during playback by the offloaded decoder so we need to
// query the HAL and update if needed.
// FIXME use Proxy return channel to update the rate from server and avoid polling here
- if (isOffloaded()) {
+ if (isOffloaded_l()) {
if (mOutput != 0) {
uint32_t sampleRate = 0;
status_t status = AudioSystem::getSamplingRate(mOutput, mStreamType, &sampleRate);
@@ -751,7 +751,7 @@ status_t AudioTrack::getPosition(uint32_t *position) const
}
AutoMutex lock(mLock);
- if (isOffloaded()) {
+ if (isOffloaded_l()) {
uint32_t dspFrames = 0;
if (mOutput != 0) {
@@ -1389,7 +1389,7 @@ nsecs_t AudioTrack::processAudioBuffer()
// for offloaded tracks restoreTrack_l() will just update the sequence and clear
// AudioSystem cache. We should not exit here but after calling the callback so
// that the upper layers can recreate the track
- if (!isOffloaded() || (mSequence == mObservedSequence)) {
+ if (!isOffloaded_l() || (mSequence == mObservedSequence)) {
status_t status = restoreTrack_l("processAudioBuffer");
mLock.unlock();
// Run again immediately, but with a new IAudioTrack
@@ -1676,7 +1676,7 @@ nsecs_t AudioTrack::processAudioBuffer()
status_t AudioTrack::restoreTrack_l(const char *from)
{
ALOGW("dead IAudioTrack, %s, creating a new one from %s()",
- isOffloaded() ? "Offloaded" : "PCM", from);
+ isOffloaded_l() ? "Offloaded" : "PCM", from);
++mSequence;
status_t result;
@@ -1684,7 +1684,8 @@ status_t AudioTrack::restoreTrack_l(const char *from)
// output parameters in getOutput_l() and createTrack_l()
AudioSystem::clearAudioConfigCache();
- if (isOffloaded()) {
+ if (isOffloaded_l()) {
+ // FIXME re-creation of offloaded tracks is not yet implemented
return DEAD_OBJECT;
}
@@ -1778,6 +1779,12 @@ String8 AudioTrack::getParameters(const String8& keys)
}
}
+bool AudioTrack::isOffloaded() const
+{
+ AutoMutex lock(mLock);
+ return isOffloaded_l();
+}
+
status_t AudioTrack::dump(int fd, const Vector<String16>& args __unused) const
{