summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2013-05-30 14:33:29 -0700
committerGlenn Kasten <gkasten@google.com>2013-06-03 11:28:36 -0700
commit2799d743ee2ae5a25fe869a7f9c052acc029559f (patch)
tree5cab5ff06f7cae0025b93fdcd549cfb2ec72b755 /include
parent7c684c622110af460025eff85082030947278430 (diff)
downloadframeworks_av-2799d743ee2ae5a25fe869a7f9c052acc029559f.zip
frameworks_av-2799d743ee2ae5a25fe869a7f9c052acc029559f.tar.gz
frameworks_av-2799d743ee2ae5a25fe869a7f9c052acc029559f.tar.bz2
Use sp<AudioTrack> instead of raw AudioTrack *
This change prepares for the new implementation of AudioTrack client, which will require clients to use only sp<AudioTrack>, not raw AudioTrack *. A raw delete will cause a race condition during AudioTrack destruction. AudioTrack was made a RefBase by commit b68a91a70bc8d0d18e7404e14443d4e4020b3635 on 2011/11/15, when it was needed by OpenSL ES (for the callback protector). At that time, the only other client that was also converted from AudioTrack * to sp<AudioTrack> was android.media.AudioTrack JNI in project frameworks/base (file android_media_AudioTrack.cpp). Details: * Use .clear() instead of delete followed by = NULL. * ALOG %p need .get(). * sp<> don't need to be listed in constructor initializer, if initially 0. * Use == 0 for sp<> vs == NULL for raw pointers. * Use if (sp != 0) instead of if (raw). Change-Id: Ic7cad25795d6e862e112abdc227b6d33afdfce17
Diffstat (limited to 'include')
-rw-r--r--include/media/AudioTrack.h4
-rw-r--r--include/media/JetPlayer.h2
-rw-r--r--include/media/SoundPool.h4
-rw-r--r--include/media/ToneGenerator.h4
-rw-r--r--include/media/stagefright/AudioPlayer.h2
5 files changed, 9 insertions, 7 deletions
diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h
index 0b616e3..8dbc9ee 100644
--- a/include/media/AudioTrack.h
+++ b/include/media/AudioTrack.h
@@ -191,7 +191,9 @@ public:
/* Terminates the AudioTrack and unregisters it from AudioFlinger.
* Also destroys all resources associated with the AudioTrack.
*/
- ~AudioTrack();
+protected:
+ virtual ~AudioTrack();
+public:
/* Initialize an uninitialized AudioTrack.
* Returned status (from utils/Errors.h) can be:
diff --git a/include/media/JetPlayer.h b/include/media/JetPlayer.h
index 0616bf0..388f767 100644
--- a/include/media/JetPlayer.h
+++ b/include/media/JetPlayer.h
@@ -88,7 +88,7 @@ private:
EAS_DATA_HANDLE mEasData;
EAS_FILE_LOCATOR mEasJetFileLoc;
EAS_PCM* mAudioBuffer;// EAS renders the MIDI data into this buffer,
- AudioTrack* mAudioTrack; // and we play it in this audio track
+ sp<AudioTrack> mAudioTrack; // and we play it in this audio track
int mTrackBufferSize;
S_JET_STATUS mJetStatus;
S_JET_STATUS mPreviousJetStatus;
diff --git a/include/media/SoundPool.h b/include/media/SoundPool.h
index 7bf3069..9e5654f 100644
--- a/include/media/SoundPool.h
+++ b/include/media/SoundPool.h
@@ -118,7 +118,7 @@ protected:
class SoundChannel : public SoundEvent {
public:
enum state { IDLE, RESUMING, STOPPING, PAUSED, PLAYING };
- SoundChannel() : mAudioTrack(NULL), mState(IDLE), mNumChannels(1),
+ SoundChannel() : mState(IDLE), mNumChannels(1),
mPos(0), mToggle(0), mAutoPaused(false) {}
~SoundChannel();
void init(SoundPool* soundPool);
@@ -148,7 +148,7 @@ private:
bool doStop_l();
SoundPool* mSoundPool;
- AudioTrack* mAudioTrack;
+ sp<AudioTrack> mAudioTrack;
SoundEvent mNextEvent;
Mutex mLock;
int mState;
diff --git a/include/media/ToneGenerator.h b/include/media/ToneGenerator.h
index 2183fbe..98c4332 100644
--- a/include/media/ToneGenerator.h
+++ b/include/media/ToneGenerator.h
@@ -160,7 +160,7 @@ public:
bool isInited() { return (mState == TONE_IDLE)?false:true;}
// returns the audio session this ToneGenerator belongs to or 0 if an error occured.
- int getSessionId() { return (mpAudioTrack == NULL) ? 0 : mpAudioTrack->getSessionId(); }
+ int getSessionId() { return (mpAudioTrack == 0) ? 0 : mpAudioTrack->getSessionId(); }
private:
@@ -264,7 +264,7 @@ private:
unsigned short mLoopCounter; // Current tone loopback count
uint32_t mSamplingRate; // AudioFlinger Sampling rate
- AudioTrack *mpAudioTrack; // Pointer to audio track used for playback
+ sp<AudioTrack> mpAudioTrack; // Pointer to audio track used for playback
Mutex mLock; // Mutex to control concurent access to ToneGenerator object from audio callback and application API
Mutex mCbkCondLock; // Mutex associated to mWaitCbkCond
Condition mWaitCbkCond; // condition enabling interface to wait for audio callback completion after a change is requested
diff --git a/include/media/stagefright/AudioPlayer.h b/include/media/stagefright/AudioPlayer.h
index 1dc408f..3bf046d 100644
--- a/include/media/stagefright/AudioPlayer.h
+++ b/include/media/stagefright/AudioPlayer.h
@@ -70,7 +70,7 @@ public:
private:
friend class VideoEditorAudioPlayer;
sp<MediaSource> mSource;
- AudioTrack *mAudioTrack;
+ sp<AudioTrack> mAudioTrack;
MediaBuffer *mInputBuffer;