OSDN Git Service

Fix AudioTrack, AudioRecord, AudioFormat API
authorAndy Hung <hunga@google.com>
Tue, 19 May 2015 22:44:31 +0000 (15:44 -0700)
committerJean-Michel Trivi <jmtrivi@google.com>
Wed, 20 May 2015 22:58:31 +0000 (22:58 +0000)
Rename getNativeFrameCount to getBufferSizeInFrames
Remove throw declaration on IllegalArgumentException and
IllegalStateException

Bug: 20887665
Bug: 21304902
Change-Id: Ia85d8010be46524b9a8b93105b16b7b9480f6bd9

api/current.txt
api/system-current.txt
core/jni/android_media_AudioRecord.cpp
media/java/android/media/AudioFormat.java
media/java/android/media/AudioRecord.java
media/java/android/media/AudioTrack.java

index 80c4dc8..f8a3bea 100644 (file)
@@ -14798,8 +14798,8 @@ package android.media {
     ctor public AudioFormat.Builder();
     ctor public AudioFormat.Builder(android.media.AudioFormat);
     method public android.media.AudioFormat build();
-    method public android.media.AudioFormat.Builder setChannelIndexMask(int) throws java.lang.IllegalArgumentException;
-    method public android.media.AudioFormat.Builder setChannelMask(int) throws java.lang.IllegalArgumentException;
+    method public android.media.AudioFormat.Builder setChannelIndexMask(int);
+    method public android.media.AudioFormat.Builder setChannelMask(int);
     method public android.media.AudioFormat.Builder setEncoding(int) throws java.lang.IllegalArgumentException;
     method public android.media.AudioFormat.Builder setSampleRate(int) throws java.lang.IllegalArgumentException;
   }
@@ -14961,11 +14961,11 @@ package android.media {
     method public int getAudioFormat();
     method public int getAudioSessionId();
     method public int getAudioSource();
+    method public int getBufferSizeInFrames();
     method public int getChannelConfiguration();
     method public int getChannelCount();
     method public android.media.AudioFormat getFormat();
     method public static int getMinBufferSize(int, int, int);
-    method public int getNativeFrameCount() throws java.lang.IllegalStateException;
     method public int getNotificationMarkerPosition();
     method public int getPositionNotificationPeriod();
     method public android.media.AudioDeviceInfo getPreferredDevice();
@@ -15034,13 +15034,14 @@ package android.media {
     method public void flush();
     method public int getAudioFormat();
     method public int getAudioSessionId();
+    method public int getBufferSizeInFrames();
     method public int getChannelConfiguration();
     method public int getChannelCount();
     method public android.media.AudioFormat getFormat();
     method public static float getMaxVolume();
     method public static int getMinBufferSize(int, int, int);
     method public static float getMinVolume();
-    method public int getNativeFrameCount() throws java.lang.IllegalStateException;
+    method protected deprecated int getNativeFrameCount();
     method public static int getNativeOutputSampleRate(int);
     method public int getNotificationMarkerPosition();
     method public int getPlayState();
index 6c4f278..eb6fc46 100644 (file)
@@ -16024,8 +16024,8 @@ package android.media {
     ctor public AudioFormat.Builder();
     ctor public AudioFormat.Builder(android.media.AudioFormat);
     method public android.media.AudioFormat build();
-    method public android.media.AudioFormat.Builder setChannelIndexMask(int) throws java.lang.IllegalArgumentException;
-    method public android.media.AudioFormat.Builder setChannelMask(int) throws java.lang.IllegalArgumentException;
+    method public android.media.AudioFormat.Builder setChannelIndexMask(int);
+    method public android.media.AudioFormat.Builder setChannelMask(int);
     method public android.media.AudioFormat.Builder setEncoding(int) throws java.lang.IllegalArgumentException;
     method public android.media.AudioFormat.Builder setSampleRate(int) throws java.lang.IllegalArgumentException;
   }
@@ -16197,11 +16197,11 @@ package android.media {
     method public int getAudioFormat();
     method public int getAudioSessionId();
     method public int getAudioSource();
+    method public int getBufferSizeInFrames();
     method public int getChannelConfiguration();
     method public int getChannelCount();
     method public android.media.AudioFormat getFormat();
     method public static int getMinBufferSize(int, int, int);
-    method public int getNativeFrameCount() throws java.lang.IllegalStateException;
     method public int getNotificationMarkerPosition();
     method public int getPositionNotificationPeriod();
     method public android.media.AudioDeviceInfo getPreferredDevice();
@@ -16272,13 +16272,14 @@ package android.media {
     method public void flush();
     method public int getAudioFormat();
     method public int getAudioSessionId();
+    method public int getBufferSizeInFrames();
     method public int getChannelConfiguration();
     method public int getChannelCount();
     method public android.media.AudioFormat getFormat();
     method public static float getMaxVolume();
     method public static int getMinBufferSize(int, int, int);
     method public static float getMinVolume();
-    method public int getNativeFrameCount() throws java.lang.IllegalStateException;
+    method protected deprecated int getNativeFrameCount();
     method public static int getNativeOutputSampleRate(int);
     method public int getNotificationMarkerPosition();
     method public int getPlayState();
index 87b81d5..e5c4ba9 100644 (file)
@@ -521,11 +521,11 @@ static jint android_media_AudioRecord_readInDirectBuffer(JNIEnv *env,  jobject t
 }
 
 // ----------------------------------------------------------------------------
-static jint android_media_AudioRecord_get_native_frame_count(JNIEnv *env,  jobject thiz) {
+static jint android_media_AudioRecord_get_buffer_size_in_frames(JNIEnv *env,  jobject thiz) {
     sp<AudioRecord> lpRecorder = getAudioRecord(env, thiz);
     if (lpRecorder == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
-            "Unable to retrieve AudioRecord pointer for getNativeFrameCount()");
+            "Unable to retrieve AudioRecord pointer for frameCount()");
         return (jint)AUDIO_JAVA_ERROR;
     }
     return lpRecorder->frameCount();
@@ -700,8 +700,8 @@ static JNINativeMethod gMethods[] = {
                                      (void *)android_media_AudioRecord_readInArray<jfloatArray>},
     {"native_read_in_direct_buffer","(Ljava/lang/Object;IZ)I",
                                        (void *)android_media_AudioRecord_readInDirectBuffer},
-    {"native_get_native_frame_count",
-                             "()I",    (void *)android_media_AudioRecord_get_native_frame_count},
+    {"native_get_buffer_size_in_frames",
+                             "()I", (void *)android_media_AudioRecord_get_buffer_size_in_frames},
     {"native_set_marker_pos","(I)I",   (void *)android_media_AudioRecord_set_marker_pos},
     {"native_get_marker_pos","()I",    (void *)android_media_AudioRecord_get_marker_pos},
     {"native_set_pos_update_period",
index a7e092f..0f33c62 100644 (file)
@@ -503,7 +503,7 @@ public class AudioFormat {
          *    if both channel index mask and channel position mask
          *    are specified but do not have the same channel count.
          */
-        public @NonNull Builder setChannelMask(int channelMask) throws IllegalArgumentException {
+        public @NonNull Builder setChannelMask(int channelMask) {
             if (channelMask == 0) {
                 throw new IllegalArgumentException("Invalid zero channel mask");
             } else if (/* channelMask != 0 && */ mChannelIndexMask != 0 &&
@@ -555,8 +555,7 @@ public class AudioFormat {
          *    if both channel index mask and channel position mask
          *    are specified but do not have the same channel count.
          */
-        public @NonNull Builder setChannelIndexMask(int channelIndexMask)
-                throws IllegalArgumentException {
+        public @NonNull Builder setChannelIndexMask(int channelIndexMask) {
             if (channelIndexMask == 0) {
                 throw new IllegalArgumentException("Invalid zero channel index mask");
             } else if (/* channelIndexMask != 0 && */ mChannelMask != 0 &&
index c0bc6d6..accd117 100644 (file)
@@ -494,7 +494,7 @@ public class AudioRecord
          * than this size. See {@link #getMinBufferSize(int, int, int)} to determine the minimum
          * required buffer size for the successful creation of an AudioRecord instance.
          * Since bufferSizeInBytes may be internally increased to accommodate the source
-         * requirements, use {@link #getNativeFrameCount()} to determine the actual buffer size
+         * requirements, use {@link #getBufferSizeInFrames()} to determine the actual buffer size
          * in frames.
          * @param bufferSizeInBytes a value strictly greater than 0
          * @return the same Builder instance.
@@ -777,7 +777,7 @@ public class AudioRecord
     }
 
     /**
-     *  Returns the "native frame count" of the <code>AudioRecord</code> buffer.
+     *  Returns the frame count of the native <code>AudioRecord</code> buffer.
      *  This is greater than or equal to the bufferSizeInBytes converted to frame units
      *  specified in the <code>AudioRecord</code> constructor or Builder.
      *  The native frame count may be enlarged to accommodate the requirements of the
@@ -786,8 +786,8 @@ public class AudioRecord
      *  @return current size in frames of the <code>AudioRecord</code> buffer.
      *  @throws IllegalStateException
      */
-    public int getNativeFrameCount() throws IllegalStateException {
-        return native_get_native_frame_count();
+    public int getBufferSizeInFrames() {
+        return native_get_buffer_size_in_frames();
     }
 
     /**
@@ -1528,7 +1528,7 @@ public class AudioRecord
     private native final int native_read_in_direct_buffer(Object jBuffer,
             int sizeInBytes, boolean isBlocking);
 
-    private native final int native_get_native_frame_count();
+    private native final int native_get_buffer_size_in_frames();
 
     private native final int native_set_marker_pos(int marker);
     private native final int native_get_marker_pos();
index d21762b..7a184fc 100644 (file)
@@ -229,7 +229,7 @@ public class AudioTrack
     /**
      * Sizes of the native audio buffer.
      * These values are set during construction and can be stale.
-     * To obtain the current native audio buffer frame count use {@link #getNativeFrameCount()}.
+     * To obtain the current native audio buffer frame count use {@link #getBufferSizeInFrames()}.
      */
     private int mNativeBufferSizeInBytes = 0;
     private int mNativeBufferSizeInFrames = 0;
@@ -346,7 +346,7 @@ public class AudioTrack
      *   If <code>bufferSizeInBytes</code> is less than the
      *   minimum buffer size for the output sink, it is automatically increased to the minimum
      *   buffer size.
-     *   The method {@link #getNativeFrameCount()} returns the
+     *   The method {@link #getBufferSizeInFrames()} returns the
      *   actual size in frames of the native buffer created, which
      *   determines the frequency to write
      *   to the streaming <code>AudioTrack</code> to avoid underrun.
@@ -1009,7 +1009,7 @@ public class AudioTrack
     }
 
     /**
-     *  Returns the "native frame count" of the <code>AudioTrack</code> buffer.
+     *  Returns the frame count of the native <code>AudioTrack</code> buffer.
      *  <p> If the track's creation mode is {@link #MODE_STATIC},
      *  it is equal to the specified bufferSizeInBytes on construction, converted to frame units.
      *  A static track's native frame count will not change.
@@ -1019,12 +1019,26 @@ public class AudioTrack
      *  the target output sink, and
      *  if the track is subsequently routed to a different output sink, the native
      *  frame count may enlarge to accommodate.
-     *  See also {@link AudioManager#getProperty(String)} for key
+     *  <p> If the <code>AudioTrack</code> encoding indicates compressed data,
+     *  e.g. {@link AudioFormat#ENCODING_AC3}, then the frame count returned is
+     *  the size of the native <code>AudioTrack</code> buffer in bytes.
+     *  <p> See also {@link AudioManager#getProperty(String)} for key
      *  {@link AudioManager#PROPERTY_OUTPUT_FRAMES_PER_BUFFER}.
-     *  @return current size in frames of the audio track buffer.
+     *  @return current size in frames of the <code>AudioTrack</code> buffer.
      *  @throws IllegalStateException
      */
-    public int getNativeFrameCount() throws IllegalStateException {
+    public int getBufferSizeInFrames() {
+        return native_get_native_frame_count();
+    }
+
+    /**
+     *  Returns the frame count of the native <code>AudioTrack</code> buffer.
+     *  @return current size in frames of the <code>AudioTrack</code> buffer.
+     *  @throws IllegalStateException
+     *  @deprecated Use the identical public method {@link #getBufferSizeInFrames()} instead.
+     */
+    @Deprecated
+    protected int getNativeFrameCount() {
         return native_get_native_frame_count();
     }
 
@@ -1305,6 +1319,9 @@ public class AudioTrack
      * The valid sample rate range is from 1 Hz to twice the value returned by
      * {@link #getNativeOutputSampleRate(int)}.
      * Use {@link #setPlaybackParams(PlaybackParams)} for speed control.
+     * <p> This method may also be used to repurpose an existing <code>AudioTrack</code>
+     * for playback of content of differing sample rate,
+     * but with identical encoding and channel mask.
      * @param sampleRateInHz the sample rate expressed in Hz
      * @return error code or success, see {@link #SUCCESS}, {@link #ERROR_BAD_VALUE},
      *    {@link #ERROR_INVALID_OPERATION}
@@ -1474,7 +1491,7 @@ public class AudioTrack
      * <p>
      * If the mode is {@link #MODE_STREAM}, you can optionally prime the data path prior to
      * calling play(), by writing up to <code>bufferSizeInBytes</code> (from constructor).
-     * If you dont call write() first, or if you call write() but with an insufficient amount of
+     * If you don't call write() first, or if you call write() but with an insufficient amount of
      * data, then the track will be in underrun state at play().  In this case,
      * playback will not actually start playing until the data path is filled to a
      * device-specific minimum level.  This requirement for the path to be filled