summaryrefslogtreecommitdiffstats
path: root/media/java
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-02-13 12:57:50 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-02-13 12:57:50 -0800
commitda996f390e17e16f2dfa60e972e7ebc4f868f37e (patch)
tree00a0f15270d4c7b619fd34d8383257e1761082f4 /media/java
parentd24b8183b93e781080b2c16c487e60d51c12da31 (diff)
downloadframeworks_base-da996f390e17e16f2dfa60e972e7ebc4f868f37e.zip
frameworks_base-da996f390e17e16f2dfa60e972e7ebc4f868f37e.tar.gz
frameworks_base-da996f390e17e16f2dfa60e972e7ebc4f868f37e.tar.bz2
auto import from //branches/cupcake/...@131421
Diffstat (limited to 'media/java')
-rw-r--r--media/java/android/media/AudioManager.java15
-rw-r--r--media/java/android/media/AudioRecord.java59
-rw-r--r--media/java/android/media/AudioService.java4
-rw-r--r--media/java/android/media/AudioTrack.java8
-rw-r--r--media/java/android/media/MediaRecorder.java62
5 files changed, 123 insertions, 25 deletions
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index 2978774..4d2e725 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -135,7 +135,7 @@ public class AudioManager {
public static final int STREAM_VOICE_CALL = AudioSystem.STREAM_VOICE_CALL;
/** The audio stream for system sounds */
public static final int STREAM_SYSTEM = AudioSystem.STREAM_SYSTEM;
- /** The audio stream for the phone ring and message alerts */
+ /** The audio stream for the phone ring */
public static final int STREAM_RING = AudioSystem.STREAM_RING;
/** The audio stream for music playback */
public static final int STREAM_MUSIC = AudioSystem.STREAM_MUSIC;
@@ -214,14 +214,13 @@ public class AudioManager {
/**
* Whether to include ringer modes as possible options when changing volume.
* For example, if true and volume level is 0 and the volume is adjusted
- * with {@link #ADJUST_LOWER}, then the ringer mode may switch the silent
- * or vibrate mode.
+ * with {@link #ADJUST_LOWER}, then the ringer mode may switch the silent or
+ * vibrate mode.
* <p>
- * By default this is on for stream types that are affected by the ringer
- * mode (for example, the ring stream type). If this flag is included, this
- * behavior will be present regardless of the stream type being affected by
- * the ringer mode.
- *
+ * By default this is on for the ring stream. If this flag is included,
+ * this behavior will be present regardless of the stream type being
+ * affected by the ringer mode.
+ *
* @see #adjustVolume(int, int)
* @see #adjustStreamVolume(int, int, int)
*/
diff --git a/media/java/android/media/AudioRecord.java b/media/java/android/media/AudioRecord.java
index 1314ba1..fd990fe 100644
--- a/media/java/android/media/AudioRecord.java
+++ b/media/java/android/media/AudioRecord.java
@@ -339,7 +339,11 @@ public class AudioRecord
* Releases the native AudioRecord resources.
*/
public void release() {
- stop();
+ try {
+ stop();
+ } catch(IllegalStateException ise) {
+ // don't raise an exception, we're releasing the resources.
+ }
native_release();
mState = STATE_UNINITIALIZED;
}
@@ -427,6 +431,56 @@ public class AudioRecord
public int getPositionNotificationPeriod() {
return native_get_pos_update_period();
}
+
+ /**
+ * {@hide}
+ * Returns the minimum buffer size required for the successful creation of an AudioRecord
+ * object.
+ * @param sampleRateInHz the sample rate expressed in Hertz.
+ * @param channelConfig describes the configuration of the audio channels.
+ * See {@link AudioFormat#CHANNEL_CONFIGURATION_MONO} and
+ * {@link AudioFormat#CHANNEL_CONFIGURATION_STEREO}
+ * @param audioFormat the format in which the audio data is represented.
+ * See {@link AudioFormat#ENCODING_PCM_16BIT}.
+ * @return {@link #ERROR_BAD_VALUE} if the recording parameters are not supported by the
+ * hardware, or 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 of bytes.
+ */
+ static public int getMinBufferSize(int sampleRateInHz, int channelConfig, int audioFormat) {
+ int channelCount = 0;
+ switch(channelConfig) {
+ case AudioFormat.CHANNEL_CONFIGURATION_DEFAULT:
+ case AudioFormat.CHANNEL_CONFIGURATION_MONO:
+ channelCount = 1;
+ break;
+ case AudioFormat.CHANNEL_CONFIGURATION_STEREO:
+ channelCount = 2;
+ break;
+ case AudioFormat.CHANNEL_CONFIGURATION_INVALID:
+ default:
+ loge("getMinBufferSize(): Invalid channel configuration.");
+ return AudioRecord.ERROR_BAD_VALUE;
+ }
+
+ // PCM_8BIT is not supported at the moment
+ if (audioFormat != AudioFormat.ENCODING_PCM_16BIT) {
+ loge("getMinBufferSize(): Invalid audio format.");
+ return AudioRecord.ERROR_BAD_VALUE;
+ }
+
+ int size = native_get_min_buff_size(sampleRateInHz, channelCount, audioFormat);
+ if (size == 0) {
+ return AudioRecord.ERROR_BAD_VALUE;
+ }
+ else if (size == -1) {
+ return AudioRecord.ERROR;
+ }
+ else {
+ return size;
+ }
+ }
//---------------------------------------------------------
@@ -699,6 +753,9 @@ public class AudioRecord
private native final int native_set_pos_update_period(int updatePeriod);
private native final int native_get_pos_update_period();
+
+ static private native final int native_get_min_buff_size(
+ int sampleRateInHz, int channelCount, int audioFormat);
//---------------------------------------------------------
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index f3d8957..bdabda7 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -349,9 +349,9 @@ public class AudioService extends IAudioService.Stub {
// If either the client forces allowing ringer modes for this adjustment,
// or the stream type is one that is affected by ringer modes
if ((flags & AudioManager.FLAG_ALLOW_RINGER_MODES) != 0
- || isStreamAffectedByRingerMode(streamType)) {
+ || streamType == AudioManager.STREAM_RING) {
// Check if the ringer mode changes with this volume adjustment. If
- // it does, it will handle adjusting the volome, so we won't below
+ // it does, it will handle adjusting the volume, so we won't below
adjustVolume = checkForRingerModeChange(oldIndex, direction);
}
diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java
index 9bb1df9..74ffc1a 100644
--- a/media/java/android/media/AudioTrack.java
+++ b/media/java/android/media/AudioTrack.java
@@ -395,7 +395,11 @@ public class AudioTrack
public void release() {
// even though native_release() stops the native AudioTrack, we need to stop
// AudioTrack subclasses too.
- stop();
+ try {
+ stop();
+ } catch(IllegalStateException ise) {
+ // don't raise an exception, we're releasing the resources.
+ }
native_release();
mState = STATE_UNINITIALIZED;
}
@@ -1007,4 +1011,4 @@ public class AudioTrack
Log.e(TAG, "[ android.media.AudioTrack ] " + msg);
}
-} \ No newline at end of file
+}
diff --git a/media/java/android/media/MediaRecorder.java b/media/java/android/media/MediaRecorder.java
index 4a30114..3609826 100644
--- a/media/java/android/media/MediaRecorder.java
+++ b/media/java/android/media/MediaRecorder.java
@@ -19,6 +19,10 @@ package android.media;
import android.view.Surface;
import android.hardware.Camera;
import java.io.IOException;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileDescriptor;
+import android.util.Log;
/**
* Used to record audio and video. The recording control is based on a
@@ -50,6 +54,7 @@ public class MediaRecorder
static {
System.loadLibrary("media_jni");
}
+ private final static String TAG = "MediaRecorder";
// The two fields below are accessed by native methods
@SuppressWarnings("unused")
@@ -57,7 +62,10 @@ public class MediaRecorder
@SuppressWarnings("unused")
private Surface mSurface;
-
+
+ private String mPath;
+ private FileDescriptor mFd;
+
/**
* Default constructor.
*/
@@ -71,8 +79,6 @@ public class MediaRecorder
* the camera object. Must call before prepare().
*
* @param c the Camera to use for recording
- * FIXME: Temporarily hidden until API approval
- * @hide
*/
public native void setCamera(Camera c);
@@ -104,7 +110,6 @@ public class MediaRecorder
/**
* Defines the video source. These constants are used with
* {@link MediaRecorder#setVideoSource(int)}.
- * @hide
*/
public final class VideoSource {
/* Do not change these values without updating their counterparts
@@ -152,7 +157,6 @@ public class MediaRecorder
/**
* Defines the video encoding. These constants are used with
* {@link MediaRecorder#setVideoEncoder(int)}.
- * @hide
*/
public final class VideoEncoder {
/* Do not change these values without updating their counterparts
@@ -187,7 +191,6 @@ public class MediaRecorder
* @param video_source the video source to use
* @throws IllegalStateException if it is called after setOutputFormat()
* @see android.media.MediaRecorder.VideoSource
- * @hide
*/
public native void setVideoSource(int video_source)
throws IllegalStateException;
@@ -214,7 +217,6 @@ public class MediaRecorder
* @param height the height of the video to be captured
* @throws IllegalStateException if it is called after
* prepare() or before setOutputFormat()
- * @hide
*/
public native void setVideoSize(int width, int height)
throws IllegalStateException;
@@ -227,7 +229,10 @@ public class MediaRecorder
* @param rate the number of frames per second of video to capture
* @throws IllegalStateException if it is called after
* prepare() or before setOutputFormat().
- * @hide
+ *
+ * NOTE: On some devices that have auto-frame rate, this sets the
+ * maximum frame rate, not a constant frame rate. Actual frame rate
+ * will vary according to lighting conditions.
*/
public native void setVideoFrameRate(int rate) throws IllegalStateException;
@@ -253,21 +258,43 @@ public class MediaRecorder
* @throws IllegalStateException if it is called before
* setOutputFormat() or after prepare()
* @see android.media.MediaRecorder.VideoEncoder
- * @hide
*/
public native void setVideoEncoder(int video_encoder)
throws IllegalStateException;
/**
+ * Pass in the file descriptor of the file to be written. Call this after
+ * setOutputFormat() but before prepare().
+ *
+ * @param fd an open file descriptor to be written into.
+ * @throws IllegalStateException if it is called before
+ * setOutputFormat() or after prepare()
+ */
+ public void setOutputFile(FileDescriptor fd) throws IllegalStateException
+ {
+ mPath = null;
+ mFd = fd;
+ }
+
+ /**
* Sets the path of the output file to be produced. Call this after
* setOutputFormat() but before prepare().
*
- * @param path The pathname to use()
+ * @param path The pathname to use.
* @throws IllegalStateException if it is called before
* setOutputFormat() or after prepare()
*/
- public native void setOutputFile(String path) throws IllegalStateException;
+ public void setOutputFile(String path) throws IllegalStateException
+ {
+ mFd = null;
+ mPath = path;
+ }
+ // native implementation
+ private native void _setOutputFile(FileDescriptor fd, long offset, long length)
+ throws IllegalStateException, IOException;
+ private native void _prepare() throws IllegalStateException, IOException;
+
/**
* Prepares the recorder to begin capturing and encoding data. This method
* must be called after setting up the desired audio and video sources,
@@ -277,7 +304,18 @@ public class MediaRecorder
* start() or before setOutputFormat().
* @throws IOException if prepare fails otherwise.
*/
- public native void prepare() throws IllegalStateException, IOException;
+ public void prepare() throws IllegalStateException, IOException
+ {
+ if (mPath != null) {
+ FileOutputStream f = new FileOutputStream(mPath);
+ _setOutputFile(f.getFD(), 0, 0);
+ } else if (mFd != null) {
+ _setOutputFile(mFd, 0, 0);
+ } else {
+ throw new IOException("No valid output file");
+ }
+ _prepare();
+ }
/**
* Begins capturing and encoding data to the file specified with