Loading include/media/SoundPool.h +2 −2 Original line number Diff line number Diff line Loading @@ -188,6 +188,7 @@ public: // called from SoundPoolThread void sampleLoaded(int sampleID); sp<Sample> findSample(int sampleID); // called from AudioTrack thread void done_l(SoundChannel* channel); Loading @@ -199,8 +200,7 @@ public: private: SoundPool() {} // no default constructor bool startThreads(); void doLoad(sp<Sample>& sample); sp<Sample> findSample(int sampleID) { return mSamples.valueFor(sampleID); } sp<Sample> findSample_l(int sampleID); SoundChannel* findChannel (int channelID); SoundChannel* findNextChannel (int channelID); SoundChannel* allocateChannel_l(int priority); Loading media/libmedia/SoundPool.cpp +42 −19 Original line number Diff line number Diff line Loading @@ -179,6 +179,17 @@ bool SoundPool::startThreads() return mDecodeThread != NULL; } sp<Sample> SoundPool::findSample(int sampleID) { Mutex::Autolock lock(&mLock); return findSample_l(sampleID); } sp<Sample> SoundPool::findSample_l(int sampleID) { return mSamples.valueFor(sampleID); } SoundChannel* SoundPool::findChannel(int channelID) { for (int i = 0; i < mMaxChannels; ++i) { Loading @@ -202,29 +213,42 @@ SoundChannel* SoundPool::findNextChannel(int channelID) int SoundPool::load(const char* path, int priority) { ALOGV("load: path=%s, priority=%d", path, priority); int sampleID; { Mutex::Autolock lock(&mLock); sp<Sample> sample = new Sample(++mNextSampleID, path); mSamples.add(sample->sampleID(), sample); doLoad(sample); return sample->sampleID(); sampleID = ++mNextSampleID; sp<Sample> sample = new Sample(sampleID, path); mSamples.add(sampleID, sample); sample->startLoad(); } // mDecodeThread->loadSample() must be called outside of mLock. // mDecodeThread->loadSample() may block on mDecodeThread message queue space; // the message queue emptying may block on SoundPool::findSample(). // // It theoretically possible that sample loads might decode out-of-order. mDecodeThread->loadSample(sampleID); return sampleID; } int SoundPool::load(int fd, int64_t offset, int64_t length, int priority) { ALOGV("load: fd=%d, offset=%lld, length=%lld, priority=%d", fd, offset, length, priority); Mutex::Autolock lock(&mLock); sp<Sample> sample = new Sample(++mNextSampleID, fd, offset, length); mSamples.add(sample->sampleID(), sample); doLoad(sample); return sample->sampleID(); } void SoundPool::doLoad(sp<Sample>& sample) int sampleID; { ALOGV("doLoad: loading sample sampleID=%d", sample->sampleID()); Mutex::Autolock lock(&mLock); sampleID = ++mNextSampleID; sp<Sample> sample = new Sample(sampleID, fd, offset, length); mSamples.add(sampleID, sample); sample->startLoad(); mDecodeThread->loadSample(sample->sampleID()); } // mDecodeThread->loadSample() must be called outside of mLock. // mDecodeThread->loadSample() may block on mDecodeThread message queue space; // the message queue emptying may block on SoundPool::findSample(). // // It theoretically possible that sample loads might decode out-of-order. mDecodeThread->loadSample(sampleID); return sampleID; } bool SoundPool::unload(int sampleID) Loading @@ -239,7 +263,6 @@ int SoundPool::play(int sampleID, float leftVolume, float rightVolume, { ALOGV("play sampleID=%d, leftVolume=%f, rightVolume=%f, priority=%d, loop=%d, rate=%f", sampleID, leftVolume, rightVolume, priority, loop, rate); sp<Sample> sample; SoundChannel* channel; int channelID; Loading @@ -249,7 +272,7 @@ int SoundPool::play(int sampleID, float leftVolume, float rightVolume, return 0; } // is sample ready? sample = findSample(sampleID); sp<Sample> sample(findSample_l(sampleID)); if ((sample == 0) || (sample->state() != Sample::READY)) { ALOGW(" sample %d not READY", sampleID); return 0; Loading Loading
include/media/SoundPool.h +2 −2 Original line number Diff line number Diff line Loading @@ -188,6 +188,7 @@ public: // called from SoundPoolThread void sampleLoaded(int sampleID); sp<Sample> findSample(int sampleID); // called from AudioTrack thread void done_l(SoundChannel* channel); Loading @@ -199,8 +200,7 @@ public: private: SoundPool() {} // no default constructor bool startThreads(); void doLoad(sp<Sample>& sample); sp<Sample> findSample(int sampleID) { return mSamples.valueFor(sampleID); } sp<Sample> findSample_l(int sampleID); SoundChannel* findChannel (int channelID); SoundChannel* findNextChannel (int channelID); SoundChannel* allocateChannel_l(int priority); Loading
media/libmedia/SoundPool.cpp +42 −19 Original line number Diff line number Diff line Loading @@ -179,6 +179,17 @@ bool SoundPool::startThreads() return mDecodeThread != NULL; } sp<Sample> SoundPool::findSample(int sampleID) { Mutex::Autolock lock(&mLock); return findSample_l(sampleID); } sp<Sample> SoundPool::findSample_l(int sampleID) { return mSamples.valueFor(sampleID); } SoundChannel* SoundPool::findChannel(int channelID) { for (int i = 0; i < mMaxChannels; ++i) { Loading @@ -202,29 +213,42 @@ SoundChannel* SoundPool::findNextChannel(int channelID) int SoundPool::load(const char* path, int priority) { ALOGV("load: path=%s, priority=%d", path, priority); int sampleID; { Mutex::Autolock lock(&mLock); sp<Sample> sample = new Sample(++mNextSampleID, path); mSamples.add(sample->sampleID(), sample); doLoad(sample); return sample->sampleID(); sampleID = ++mNextSampleID; sp<Sample> sample = new Sample(sampleID, path); mSamples.add(sampleID, sample); sample->startLoad(); } // mDecodeThread->loadSample() must be called outside of mLock. // mDecodeThread->loadSample() may block on mDecodeThread message queue space; // the message queue emptying may block on SoundPool::findSample(). // // It theoretically possible that sample loads might decode out-of-order. mDecodeThread->loadSample(sampleID); return sampleID; } int SoundPool::load(int fd, int64_t offset, int64_t length, int priority) { ALOGV("load: fd=%d, offset=%lld, length=%lld, priority=%d", fd, offset, length, priority); Mutex::Autolock lock(&mLock); sp<Sample> sample = new Sample(++mNextSampleID, fd, offset, length); mSamples.add(sample->sampleID(), sample); doLoad(sample); return sample->sampleID(); } void SoundPool::doLoad(sp<Sample>& sample) int sampleID; { ALOGV("doLoad: loading sample sampleID=%d", sample->sampleID()); Mutex::Autolock lock(&mLock); sampleID = ++mNextSampleID; sp<Sample> sample = new Sample(sampleID, fd, offset, length); mSamples.add(sampleID, sample); sample->startLoad(); mDecodeThread->loadSample(sample->sampleID()); } // mDecodeThread->loadSample() must be called outside of mLock. // mDecodeThread->loadSample() may block on mDecodeThread message queue space; // the message queue emptying may block on SoundPool::findSample(). // // It theoretically possible that sample loads might decode out-of-order. mDecodeThread->loadSample(sampleID); return sampleID; } bool SoundPool::unload(int sampleID) Loading @@ -239,7 +263,6 @@ int SoundPool::play(int sampleID, float leftVolume, float rightVolume, { ALOGV("play sampleID=%d, leftVolume=%f, rightVolume=%f, priority=%d, loop=%d, rate=%f", sampleID, leftVolume, rightVolume, priority, loop, rate); sp<Sample> sample; SoundChannel* channel; int channelID; Loading @@ -249,7 +272,7 @@ int SoundPool::play(int sampleID, float leftVolume, float rightVolume, return 0; } // is sample ready? sample = findSample(sampleID); sp<Sample> sample(findSample_l(sampleID)); if ((sample == 0) || (sample->state() != Sample::READY)) { ALOGW(" sample %d not READY", sampleID); return 0; Loading