diff options
author | Andy Hung <hunga@google.com> | 2015-04-15 01:54:18 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-04-15 01:54:20 +0000 |
commit | 8f08d04b4ea6f9cd9c57159635ea20afe7e01312 (patch) | |
tree | b11be959ad52c93497a82df269eb2c6e41672aa6 /media | |
parent | 0e08a225dab277d367b6665b933869dc7587090e (diff) | |
parent | 864ae678521cc26801a1611b3d4eabe90c0a17f7 (diff) | |
download | frameworks_base-8f08d04b4ea6f9cd9c57159635ea20afe7e01312.zip frameworks_base-8f08d04b4ea6f9cd9c57159635ea20afe7e01312.tar.gz frameworks_base-8f08d04b4ea6f9cd9c57159635ea20afe7e01312.tar.bz2 |
Merge "Default to minimum buffer size for AudioRecord.Builder"
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/AudioRecord.java | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/media/java/android/media/AudioRecord.java b/media/java/android/media/AudioRecord.java index fc0189c..9e1e055 100644 --- a/media/java/android/media/AudioRecord.java +++ b/media/java/android/media/AudioRecord.java @@ -398,8 +398,8 @@ public class AudioRecord * default output sample rate of the device (see * {@link AudioManager#PROPERTY_OUTPUT_SAMPLE_RATE}), its channel configuration will be * {@link AudioFormat#CHANNEL_IN_DEFAULT}. - * <br>Failing to set an adequate buffer size with {@link #setBufferSizeInBytes(int)} will - * prevent the successful creation of an <code>AudioRecord</code> instance. + * <br>If the buffer size is not specified with {@link #setBufferSizeInBytes(int)}, + * the minimum buffer size for the source is used. */ public static class Builder { private AudioAttributes mAttributes; @@ -473,7 +473,9 @@ public class AudioRecord * during the recording. New audio data can be read from this buffer in smaller chunks * than this size. See {@link #getMinBufferSize(int, int, int)} to determine the minimum * required buffer size for the successful creation of an AudioRecord instance. - * Using values smaller than getMinBufferSize() will result in an initialization failure. + * Since bufferSizeInBytes may be internally increased to accommodate the source + * requirements, use {@link #getNativeFrameCount()} to determine the actual buffer size + * in frames. * @param bufferSizeInBytes a value strictly greater than 0 * @return the same Builder instance. * @throws IllegalArgumentException @@ -520,6 +522,13 @@ public class AudioRecord .build(); } try { + // If the buffer size is not specified, + // use a single frame for the buffer size and let the + // native code figure out the minimum buffer size. + if (mBufferSizeInBytes == 0) { + mBufferSizeInBytes = mFormat.getChannelCount() + * mFormat.getBytesPerSample(mFormat.getEncoding()); + } return new AudioRecord(mAttributes, mFormat, mBufferSizeInBytes, mSessionId); } catch (IllegalArgumentException e) { throw new UnsupportedOperationException(e.getMessage()); @@ -711,6 +720,20 @@ public class AudioRecord } /** + * Returns the "native frame count" of the <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 + * source on creation or if the <code>AudioRecord</code> + * is subsequently rerouted. + * @return current size in frames of the <code>AudioRecord</code> buffer. + * @throws IllegalStateException + */ + public int getNativeFrameCount() throws IllegalStateException { + return native_get_native_frame_count(); + } + + /** * Returns the notification marker position expressed in frames. */ public int getNotificationMarkerPosition() { @@ -1173,6 +1196,8 @@ public class AudioRecord private native final int native_read_in_direct_buffer(Object jBuffer, int sizeInBytes); + private native final int native_get_native_frame_count(); + private native final int native_set_marker_pos(int marker); private native final int native_get_marker_pos(); |