summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-02-19 10:57:31 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-02-19 10:57:31 -0800
commit3001a035439d8134a7d70d796376d1dfbff3cdcd (patch)
tree343ccdba15a594ff6e50c874a145232753315a30 /media
parentda996f390e17e16f2dfa60e972e7ebc4f868f37e (diff)
downloadframeworks_base-3001a035439d8134a7d70d796376d1dfbff3cdcd.zip
frameworks_base-3001a035439d8134a7d70d796376d1dfbff3cdcd.tar.gz
frameworks_base-3001a035439d8134a7d70d796376d1dfbff3cdcd.tar.bz2
auto import from //branches/cupcake/...@132276
Diffstat (limited to 'media')
-rw-r--r--media/java/android/media/AsyncPlayer.java9
-rw-r--r--media/java/android/media/AudioManager.java72
-rw-r--r--media/java/android/media/AudioService.java37
-rw-r--r--media/java/android/media/AudioTrack.java33
-rw-r--r--media/java/android/media/IAudioService.aidl2
-rw-r--r--media/libmedia/AudioTrack.cpp2
-rw-r--r--media/libmedia/JetPlayer.cpp11
-rwxr-xr-xmedia/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java2
8 files changed, 132 insertions, 36 deletions
diff --git a/media/java/android/media/AsyncPlayer.java b/media/java/android/media/AsyncPlayer.java
index 0620f32..35f0409 100644
--- a/media/java/android/media/AsyncPlayer.java
+++ b/media/java/android/media/AsyncPlayer.java
@@ -22,6 +22,7 @@ import android.os.PowerManager;
import android.util.Log;
import java.io.IOException;
+import java.lang.IllegalStateException;
/**
* Plays a series of audio URIs, but does all the hard work on another thread
@@ -71,20 +72,20 @@ public class AsyncPlayer {
// is playing, let it continue until we're done, so there
// is less of a glitch.
MediaPlayer player = new MediaPlayer();
- player.setDataSource(cmd.context, cmd.uri);
player.setAudioStreamType(cmd.stream);
+ player.setDataSource(cmd.context, cmd.uri);
player.setLooping(cmd.looping);
player.prepare();
+ player.start();
if (mPlayer != null) {
- // stop the previous one.
- mPlayer.stop();
mPlayer.release();
}
- player.start();
mPlayer = player;
}
catch (IOException e) {
Log.w(mTag, "error loading sound for " + cmd.uri, e);
+ } catch (IllegalStateException e) {
+ Log.w(mTag, "IllegalStateException (content provider died?) " + cmd.uri, e);
}
break;
case STOP:
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index 4d2e725..077d016 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -932,29 +932,53 @@ public class AudioManager {
*/
public static final int FX_KEY_CLICK = 0;
/**
- * Focuse has moved up
+ * Focus has moved up
* @see #playSoundEffect(int)
*/
public static final int FX_FOCUS_NAVIGATION_UP = 1;
/**
- * Focuse has moved down
+ * Focus has moved down
* @see #playSoundEffect(int)
*/
public static final int FX_FOCUS_NAVIGATION_DOWN = 2;
/**
- * Focuse has moved left
+ * Focus has moved left
* @see #playSoundEffect(int)
*/
public static final int FX_FOCUS_NAVIGATION_LEFT = 3;
/**
- * Focuse has moved right
+ * Focus has moved right
* @see #playSoundEffect(int)
*/
public static final int FX_FOCUS_NAVIGATION_RIGHT = 4;
/**
+ * IME standard keypress sound
+ * @see #playSoundEffect(int)
+ * @hide FIXME: Unhide before release
+ */
+ public static final int FX_KEYPRESS_STANDARD = 5;
+ /**
+ * IME spacebar keypress sound
+ * @see #playSoundEffect(int)
+ * @hide FIXME: Unhide before release
+ */
+ public static final int FX_KEYPRESS_SPACEBAR = 6;
+ /**
+ * IME delete keypress sound
+ * @see #playSoundEffect(int)
+ * @hide FIXME: Unhide before release
+ */
+ public static final int FX_KEYPRESS_DELETE = 7;
+ /**
+ * IME return_keypress sound
+ * @see #playSoundEffect(int)
+ * @hide FIXME: Unhide before release
+ */
+ public static final int FX_KEYPRESS_RETURN = 8;
+ /**
* @hide Number of sound effects
*/
- public static final int NUM_SOUND_EFFECTS = 5;
+ public static final int NUM_SOUND_EFFECTS = 9;
/**
* Plays a sound effect (Key clicks, lid open/close...)
@@ -964,6 +988,13 @@ public class AudioManager {
* {@link #FX_FOCUS_NAVIGATION_DOWN},
* {@link #FX_FOCUS_NAVIGATION_LEFT},
* {@link #FX_FOCUS_NAVIGATION_RIGHT},
+ * FIXME: include links before release
+ * {link #FX_KEYPRESS_STANDARD},
+ * {link #FX_KEYPRESS_SPACEBAR},
+ * {link #FX_KEYPRESS_DELETE},
+ * {link #FX_KEYPRESS_RETURN},
+ * NOTE: This version uses the UI settings to determine
+ * whether sounds are heard or not.
*/
public void playSoundEffect(int effectType) {
if (effectType < 0 || effectType >= NUM_SOUND_EFFECTS) {
@@ -983,6 +1014,37 @@ public class AudioManager {
}
/**
+ * Plays a sound effect (Key clicks, lid open/close...)
+ * @param effectType The type of sound effect. One of
+ * {@link #FX_KEY_CLICK},
+ * {@link #FX_FOCUS_NAVIGATION_UP},
+ * {@link #FX_FOCUS_NAVIGATION_DOWN},
+ * {@link #FX_FOCUS_NAVIGATION_LEFT},
+ * {@link #FX_FOCUS_NAVIGATION_RIGHT},
+ * FIXME: include links before release
+ * {link #FX_KEYPRESS_STANDARD},
+ * {link #FX_KEYPRESS_SPACEBAR},
+ * {link #FX_KEYPRESS_DELETE},
+ * {link #FX_KEYPRESS_RETURN},
+ * @param volume Sound effect volume
+ * NOTE: This version is for applications that have their own
+ * settings panel for enabling and controlling volume.
+ * @hide FIXME: Unhide before release
+ */
+ public void playSoundEffect(int effectType, float volume) {
+ if (effectType < 0 || effectType >= NUM_SOUND_EFFECTS) {
+ return;
+ }
+
+ IAudioService service = getService();
+ try {
+ service.playSoundEffectVolume(effectType, volume);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Dead object in playSoundEffect"+e);
+ }
+ }
+
+ /**
* Settings has an in memory cache, so this is fast.
*/
private boolean querySoundEffectsEnabled() {
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index bdabda7..83ede0d 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -102,12 +102,16 @@ public class AudioService extends IAudioService.Stub {
private SoundPool mSoundPool;
private Object mSoundEffectsLock = new Object();
private static final int NUM_SOUNDPOOL_CHANNELS = 4;
- private static final float SOUND_EFFECT_VOLUME = 1.0f;
+ private static final int SOUND_EFFECT_VOLUME = 1000;
/* Sound effect file names */
private static final String SOUND_EFFECTS_PATH = "/media/audio/ui/";
private static final String[] SOUND_EFFECT_FILES = new String[] {
- "Effect_Tick.ogg"
+ "Effect_Tick.ogg",
+ "KeypressStandard.ogg",
+ "KeypressSpacebar.ogg",
+ "KeypressDelete.ogg",
+ "KeypressReturn.ogg"
};
/* Sound effect file name mapping sound effect id (AudioManager.FX_xxx) to
@@ -118,7 +122,11 @@ public class AudioService extends IAudioService.Stub {
{0, -1}, // FX_FOCUS_NAVIGATION_UP
{0, -1}, // FX_FOCUS_NAVIGATION_DOWN
{0, -1}, // FX_FOCUS_NAVIGATION_LEFT
- {0, -1} // FX_FOCUS_NAVIGATION_RIGHT
+ {0, -1}, // FX_FOCUS_NAVIGATION_RIGHT
+ {1, -1}, // FX_KEYPRESS_STANDARD
+ {2, -1}, // FX_KEYPRESS_SPACEBAR
+ {3, -1}, // FX_FOCUS_DELETE
+ {4, -1} // FX_FOCUS_RETURN
};
private AudioSystem.ErrorCallback mAudioSystemCallback = new AudioSystem.ErrorCallback() {
@@ -180,9 +188,7 @@ public class AudioService extends IAudioService.Stub {
readAudioSettings();
mMediaServerOk = true;
AudioSystem.setErrorCallback(mAudioSystemCallback);
- if (Settings.System.getInt(mContentResolver, Settings.System.SOUND_EFFECTS_ENABLED, 0) == 1) {
- loadSoundEffects();
- }
+ loadSoundEffects();
}
private void createAudioSystemThread() {
@@ -648,8 +654,15 @@ public class AudioService extends IAudioService.Stub {
/** @see AudioManager#playSoundEffect(int) */
public void playSoundEffect(int effectType) {
- sendMsg(mAudioHandler, MSG_PLAY_SOUND_EFFECT, SHARED_MSG, SENDMSG_NOOP, effectType, 0,
- null, 0);
+ sendMsg(mAudioHandler, MSG_PLAY_SOUND_EFFECT, SHARED_MSG, SENDMSG_NOOP,
+ effectType, SOUND_EFFECT_VOLUME, null, 0);
+ }
+
+ /** @see AudioManager#playSoundEffect(int, float) */
+ /* @hide FIXME: unhide before release */
+ public void playSoundEffectVolume(int effectType, float volume) {
+ sendMsg(mAudioHandler, MSG_PLAY_SOUND_EFFECT, SHARED_MSG, SENDMSG_NOOP,
+ effectType, (int) (volume * 1000), null, 0);
}
/**
@@ -1113,15 +1126,15 @@ public class AudioService extends IAudioService.Stub {
System.putInt(mContentResolver, System.VIBRATE_ON, mVibrateSetting);
}
- private void playSoundEffect(int effectType) {
+ private void playSoundEffect(int effectType, int volume) {
synchronized (mSoundEffectsLock) {
if (mSoundPool == null) {
return;
}
if (SOUND_EFFECT_FILES_MAP[effectType][1] > 0) {
- mSoundPool.play(SOUND_EFFECT_FILES_MAP[effectType][1], SOUND_EFFECT_VOLUME, SOUND_EFFECT_VOLUME,
- 0, 0, 1.0f);
+ float v = (float) volume / 1000.0f;
+ mSoundPool.play(SOUND_EFFECT_FILES_MAP[effectType][1], v, v, 0, 0, 1.0f);
} else {
MediaPlayer mediaPlayer = new MediaPlayer();
if (mediaPlayer != null) {
@@ -1214,7 +1227,7 @@ public class AudioService extends IAudioService.Stub {
break;
case MSG_PLAY_SOUND_EFFECT:
- playSoundEffect(msg.arg1);
+ playSoundEffect(msg.arg1, msg.arg2);
break;
}
}
diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java
index 74ffc1a..e32835c 100644
--- a/media/java/android/media/AudioTrack.java
+++ b/media/java/android/media/AudioTrack.java
@@ -538,9 +538,10 @@ public class AudioTrack
* @param audioFormat the format in which the audio data is represented.
* See {@link AudioFormat#ENCODING_PCM_16BIT} and
* {@link AudioFormat#ENCODING_PCM_8BIT}
- * @return -1 if an invalid parameter was passed or if the implementation was unable to
- * query the hardware for its output properties, or the minimum buffer size expressed
- * in number of bytes.
+ * @return {@link #ERROR_BAD_VALUE} if an invalid parameter was passed,
+ * or {@link #ERROR} if the implementation was unable to query the hardware for its output
+ * properties,
+ * or the minimum buffer size expressed in number of bytes.
*/
static public int getMinBufferSize(int sampleRateInHz, int channelConfig, int audioFormat) {
int channelCount = 0;
@@ -553,16 +554,28 @@ public class AudioTrack
break;
default:
loge("getMinBufferSize(): Invalid channel configuration.");
- return -1;
+ return AudioTrack.ERROR_BAD_VALUE;
}
if ((audioFormat != AudioFormat.ENCODING_PCM_16BIT)
&& (audioFormat != AudioFormat.ENCODING_PCM_8BIT)) {
loge("getMinBufferSize(): Invalid audio format.");
- return -1;
+ return AudioTrack.ERROR_BAD_VALUE;
}
- return native_get_min_buff_size(sampleRateInHz, channelCount, audioFormat);
+ if ( (sampleRateInHz < 4000) || (sampleRateInHz > 48000) ) {
+ loge("getMinBufferSize(): " + sampleRateInHz +"Hz is not a supported sample rate.");
+ return AudioTrack.ERROR_BAD_VALUE;
+ }
+
+ int size = native_get_min_buff_size(sampleRateInHz, channelCount, audioFormat);
+ if ((size == -1) || (size == 0)) {
+ loge("getMinBufferSize(): error querying hardware");
+ return AudioTrack.ERROR;
+ }
+ else {
+ return size;
+ }
}
@@ -810,7 +823,7 @@ public class AudioTrack
return -1;
}
- return native_write_byte(audioData, offsetInBytes, sizeInBytes);
+ return native_write_byte(audioData, offsetInBytes, sizeInBytes, mAudioFormat);
}
@@ -836,7 +849,7 @@ public class AudioTrack
return -1;
}
- return native_write_short(audioData, offsetInShorts, sizeInShorts);
+ return native_write_short(audioData, offsetInShorts, sizeInShorts, mAudioFormat);
}
@@ -969,10 +982,10 @@ public class AudioTrack
private native final void native_flush();
private native final int native_write_byte(byte[] audioData,
- int offsetInBytes, int sizeInBytes);
+ int offsetInBytes, int sizeInBytes, int format);
private native final int native_write_short(short[] audioData,
- int offsetInShorts, int sizeInShorts);
+ int offsetInShorts, int sizeInShorts, int format);
private native final int native_reload_static();
diff --git a/media/java/android/media/IAudioService.aidl b/media/java/android/media/IAudioService.aidl
index 3e33d98..f5e242d 100644
--- a/media/java/android/media/IAudioService.aidl
+++ b/media/java/android/media/IAudioService.aidl
@@ -65,6 +65,8 @@ interface IAudioService {
oneway void playSoundEffect(int effectType);
+ oneway void playSoundEffectVolume(int effectType, float volume);
+
boolean loadSoundEffects();
oneway void unloadSoundEffects();
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 1ffad46..f8520a7 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -156,7 +156,7 @@ status_t AudioTrack::set(
}
// validate parameters
- if (((format != AudioSystem::PCM_8_BIT) || mSharedBuffer != 0) &&
+ if (((format != AudioSystem::PCM_8_BIT) || sharedBuffer != 0) &&
(format != AudioSystem::PCM_16_BIT)) {
LOGE("Invalid format");
return BAD_VALUE;
diff --git a/media/libmedia/JetPlayer.cpp b/media/libmedia/JetPlayer.cpp
index 9bd75c2..2c62104 100644
--- a/media/libmedia/JetPlayer.cpp
+++ b/media/libmedia/JetPlayer.cpp
@@ -86,8 +86,8 @@ int JetPlayer::init()
mState = EAS_STATE_ERROR;
return result;
}
- // init the JET library
- result = JET_Init(mEasData, NULL, 0);
+ // init the JET library with the default app event controller range
+ result = JET_Init(mEasData, NULL, sizeof(S_JET_CONFIG));
if( result != EAS_SUCCESS) {
LOGE("JetPlayer::init(): Error initializing JET library, aborting.");
mState = EAS_STATE_ERROR;
@@ -200,6 +200,11 @@ int JetPlayer::render() {
while (!mRender)
{
LOGV("JetPlayer::render(): signal wait");
+ if (audioStarted) {
+ mAudioTrack->pause();
+ // we have to restart the playback once we start rendering again
+ audioStarted = false;
+ }
mCondition.wait(mMutex);
LOGV("JetPlayer::render(): signal rx'd");
}
@@ -315,7 +320,7 @@ void JetPlayer::fireEventsFromJetQueue()
while (JET_GetEvent(mEasData, NULL, NULL)) { }
return;
}
-
+
EAS_U32 rawEvent;
while (JET_GetEvent(mEasData, &rawEvent, NULL)) {
mEventCallback(
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java
index 1731940..453a165 100755
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java
@@ -47,7 +47,7 @@ public class MediaFrameworkTestRunner extends InstrumentationTestRunner {
suite.addTestSuite(MediaPlayerApiTest.class);
suite.addTestSuite(SimTonesTest.class);
suite.addTestSuite(MediaMetadataTest.class);
- suite.addTestSuite(CameraTest.class);
+ // suite.addTestSuite(CameraTest.class);
suite.addTestSuite(MediaRecorderTest.class);
suite.addTestSuite(MediaAudioTrackTest.class);
return suite;