summaryrefslogtreecommitdiffstats
path: root/media/jni
diff options
context:
space:
mode:
authorDave Sparks <davidsparks@android.com>2010-02-09 13:00:09 -0800
committerDave Sparks <davidsparks@android.com>2010-02-16 16:19:32 -0800
commitf992cbb9aae593c7787ac9c5f6b475e7bb0a92c5 (patch)
tree198ccb03a7257622d3f68b6e693c3e140346e0d6 /media/jni
parent146c4a53b5e4d09e712147b031a9db9088a1769c (diff)
downloadframeworks_base-f992cbb9aae593c7787ac9c5f6b475e7bb0a92c5.zip
frameworks_base-f992cbb9aae593c7787ac9c5f6b475e7bb0a92c5.tar.gz
frameworks_base-f992cbb9aae593c7787ac9c5f6b475e7bb0a92c5.tar.bz2
Add SoundPool API to pause and resume all active streams. Bug 2426531.
Diffstat (limited to 'media/jni')
-rw-r--r--media/jni/soundpool/SoundPool.cpp43
-rw-r--r--media/jni/soundpool/SoundPool.h8
-rw-r--r--media/jni/soundpool/android_media_SoundPool.cpp26
3 files changed, 76 insertions, 1 deletions
diff --git a/media/jni/soundpool/SoundPool.cpp b/media/jni/soundpool/SoundPool.cpp
index e57f4a4..2a65b0d 100644
--- a/media/jni/soundpool/SoundPool.cpp
+++ b/media/jni/soundpool/SoundPool.cpp
@@ -294,6 +294,16 @@ void SoundPool::pause(int channelID)
}
}
+void SoundPool::autoPause()
+{
+ LOGV("pauseAll()");
+ Mutex::Autolock lock(&mLock);
+ for (int i = 0; i < mMaxChannels; ++i) {
+ SoundChannel* channel = &mChannelPool[i];
+ channel->autoPause();
+ }
+}
+
void SoundPool::resume(int channelID)
{
LOGV("resume(%d)", channelID);
@@ -304,6 +314,16 @@ void SoundPool::resume(int channelID)
}
}
+void SoundPool::autoResume()
+{
+ LOGV("pauseAll()");
+ Mutex::Autolock lock(&mLock);
+ for (int i = 0; i < mMaxChannels; ++i) {
+ SoundChannel* channel = &mChannelPool[i];
+ channel->autoResume();
+ }
+}
+
void SoundPool::stop(int channelID)
{
LOGV("stop(%d)", channelID);
@@ -710,12 +730,35 @@ void SoundChannel::pause()
}
}
+void SoundChannel::autoPause()
+{
+ Mutex::Autolock lock(&mLock);
+ if (mState == PLAYING) {
+ LOGV("pause track");
+ mState = PAUSED;
+ mAutoPaused = true;
+ mAudioTrack->pause();
+ }
+}
+
void SoundChannel::resume()
{
Mutex::Autolock lock(&mLock);
if (mState == PAUSED) {
LOGV("resume track");
mState = PLAYING;
+ mAutoPaused = false;
+ mAudioTrack->start();
+ }
+}
+
+void SoundChannel::autoResume()
+{
+ Mutex::Autolock lock(&mLock);
+ if (mAutoPaused && (mState == PAUSED)) {
+ LOGV("resume track");
+ mState = PLAYING;
+ mAutoPaused = false;
mAudioTrack->start();
}
}
diff --git a/media/jni/soundpool/SoundPool.h b/media/jni/soundpool/SoundPool.h
index 7a2d631..42037af 100644
--- a/media/jni/soundpool/SoundPool.h
+++ b/media/jni/soundpool/SoundPool.h
@@ -117,7 +117,8 @@ protected:
class SoundChannel : public SoundEvent {
public:
enum state { IDLE, RESUMING, STOPPING, PAUSED, PLAYING };
- SoundChannel() : mAudioTrack(0), mState(IDLE), mNumChannels(1), mPos(0), mToggle(0) {}
+ SoundChannel() : mAudioTrack(0), mState(IDLE), mNumChannels(1),
+ mPos(0), mToggle(0), mAutoPaused(false) {}
~SoundChannel();
void init(SoundPool* soundPool);
void play(const sp<Sample>& sample, int channelID, float leftVolume, float rightVolume,
@@ -127,7 +128,9 @@ public:
void stop_l();
void stop();
void pause();
+ void autoPause();
void resume();
+ void autoResume();
void setRate(float rate);
int state() { return mState; }
void setPriority(int priority) { mPriority = priority; }
@@ -151,6 +154,7 @@ private:
int mPos;
int mAudioBufferSize;
unsigned long mToggle;
+ bool mAutoPaused;
};
// application object for managing a pool of sounds
@@ -166,7 +170,9 @@ public:
int play(int sampleID, float leftVolume, float rightVolume, int priority,
int loop, float rate);
void pause(int channelID);
+ void autoPause();
void resume(int channelID);
+ void autoResume();
void stop(int channelID);
void setVolume(int channelID, float leftVolume, float rightVolume);
void setPriority(int channelID, int priority);
diff --git a/media/jni/soundpool/android_media_SoundPool.cpp b/media/jni/soundpool/android_media_SoundPool.cpp
index f0677a6..447f931 100644
--- a/media/jni/soundpool/android_media_SoundPool.cpp
+++ b/media/jni/soundpool/android_media_SoundPool.cpp
@@ -102,6 +102,24 @@ android_media_SoundPool_resume(JNIEnv *env, jobject thiz, jint channelID)
}
static void
+android_media_SoundPool_autoPause(JNIEnv *env, jobject thiz)
+{
+ LOGV("android_media_SoundPool_autoPause");
+ SoundPool *ap = MusterSoundPool(env, thiz);
+ if (ap == NULL) return;
+ ap->autoPause();
+}
+
+static void
+android_media_SoundPool_autoResume(JNIEnv *env, jobject thiz)
+{
+ LOGV("android_media_SoundPool_autoResume");
+ SoundPool *ap = MusterSoundPool(env, thiz);
+ if (ap == NULL) return;
+ ap->autoResume();
+}
+
+static void
android_media_SoundPool_stop(JNIEnv *env, jobject thiz, jint channelID)
{
LOGV("android_media_SoundPool_stop");
@@ -223,6 +241,14 @@ static JNINativeMethod gMethods[] = {
"(I)V",
(void *)android_media_SoundPool_resume
},
+ { "autoPause",
+ "()V",
+ (void *)android_media_SoundPool_autoPause
+ },
+ { "autoResume",
+ "()V",
+ (void *)android_media_SoundPool_autoResume
+ },
{ "stop",
"(I)V",
(void *)android_media_SoundPool_stop