Fix issue 2001517: AudioTrack compatibility issue.
Modified enum values in AudioFormat.java and AudioSystem.h.
Added code for backward compatibility in AudioTrack.java and AudioRecord.java.
diff --git a/api/current.xml b/api/current.xml
index 4dee3d2..c819972 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -73496,7 +73496,7 @@
type="int"
transient="false"
volatile="false"
- value="-1"
+ value="0"
static="true"
final="true"
deprecated="not deprecated"
@@ -73507,7 +73507,7 @@
type="int"
transient="false"
volatile="false"
- value="524288"
+ value="32"
static="true"
final="true"
deprecated="not deprecated"
@@ -73518,7 +73518,7 @@
type="int"
transient="false"
volatile="false"
- value="8388608"
+ value="512"
static="true"
final="true"
deprecated="not deprecated"
@@ -73529,7 +73529,7 @@
type="int"
transient="false"
volatile="false"
- value="0"
+ value="1"
static="true"
final="true"
deprecated="not deprecated"
@@ -73540,7 +73540,7 @@
type="int"
transient="false"
volatile="false"
- value="262144"
+ value="16"
static="true"
final="true"
deprecated="not deprecated"
@@ -73551,7 +73551,7 @@
type="int"
transient="false"
volatile="false"
- value="4194304"
+ value="256"
static="true"
final="true"
deprecated="not deprecated"
@@ -73562,7 +73562,7 @@
type="int"
transient="false"
volatile="false"
- value="65536"
+ value="4"
static="true"
final="true"
deprecated="not deprecated"
@@ -73573,7 +73573,7 @@
type="int"
transient="false"
volatile="false"
- value="1048576"
+ value="64"
static="true"
final="true"
deprecated="not deprecated"
@@ -73584,7 +73584,7 @@
type="int"
transient="false"
volatile="false"
- value="262144"
+ value="16"
static="true"
final="true"
deprecated="not deprecated"
@@ -73595,7 +73595,7 @@
type="int"
transient="false"
volatile="false"
- value="16777216"
+ value="1024"
static="true"
final="true"
deprecated="not deprecated"
@@ -73606,7 +73606,7 @@
type="int"
transient="false"
volatile="false"
- value="131072"
+ value="8"
static="true"
final="true"
deprecated="not deprecated"
@@ -73617,7 +73617,7 @@
type="int"
transient="false"
volatile="false"
- value="2097152"
+ value="128"
static="true"
final="true"
deprecated="not deprecated"
@@ -73628,7 +73628,29 @@
type="int"
transient="false"
volatile="false"
- value="196608"
+ value="12"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="CHANNEL_IN_VOICE_DNLINK"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="32768"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="CHANNEL_IN_VOICE_UPLINK"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16384"
static="true"
final="true"
deprecated="not deprecated"
@@ -73639,7 +73661,7 @@
type="int"
transient="false"
volatile="false"
- value="33554432"
+ value="2048"
static="true"
final="true"
deprecated="not deprecated"
@@ -73650,7 +73672,7 @@
type="int"
transient="false"
volatile="false"
- value="67108864"
+ value="4096"
static="true"
final="true"
deprecated="not deprecated"
@@ -73661,7 +73683,7 @@
type="int"
transient="false"
volatile="false"
- value="134217728"
+ value="8192"
static="true"
final="true"
deprecated="not deprecated"
@@ -73672,7 +73694,7 @@
type="int"
transient="false"
volatile="false"
- value="63"
+ value="252"
static="true"
final="true"
deprecated="not deprecated"
@@ -73683,7 +73705,7 @@
type="int"
transient="false"
volatile="false"
- value="255"
+ value="1020"
static="true"
final="true"
deprecated="not deprecated"
@@ -73694,7 +73716,7 @@
type="int"
transient="false"
volatile="false"
- value="256"
+ value="1024"
static="true"
final="true"
deprecated="not deprecated"
@@ -73705,7 +73727,7 @@
type="int"
transient="false"
volatile="false"
- value="16"
+ value="64"
static="true"
final="true"
deprecated="not deprecated"
@@ -73716,7 +73738,7 @@
type="int"
transient="false"
volatile="false"
- value="32"
+ value="128"
static="true"
final="true"
deprecated="not deprecated"
@@ -73727,7 +73749,7 @@
type="int"
transient="false"
volatile="false"
- value="0"
+ value="1"
static="true"
final="true"
deprecated="not deprecated"
@@ -73738,7 +73760,7 @@
type="int"
transient="false"
volatile="false"
- value="4"
+ value="16"
static="true"
final="true"
deprecated="not deprecated"
@@ -73749,7 +73771,7 @@
type="int"
transient="false"
volatile="false"
- value="1"
+ value="4"
static="true"
final="true"
deprecated="not deprecated"
@@ -73760,7 +73782,7 @@
type="int"
transient="false"
volatile="false"
- value="64"
+ value="256"
static="true"
final="true"
deprecated="not deprecated"
@@ -73771,7 +73793,7 @@
type="int"
transient="false"
volatile="false"
- value="2"
+ value="8"
static="true"
final="true"
deprecated="not deprecated"
@@ -73782,7 +73804,7 @@
type="int"
transient="false"
volatile="false"
- value="128"
+ value="512"
static="true"
final="true"
deprecated="not deprecated"
@@ -73793,7 +73815,7 @@
type="int"
transient="false"
volatile="false"
- value="8"
+ value="32"
static="true"
final="true"
deprecated="not deprecated"
@@ -73804,7 +73826,7 @@
type="int"
transient="false"
volatile="false"
- value="1"
+ value="4"
static="true"
final="true"
deprecated="not deprecated"
@@ -73815,7 +73837,7 @@
type="int"
transient="false"
volatile="false"
- value="51"
+ value="204"
static="true"
final="true"
deprecated="not deprecated"
@@ -73826,7 +73848,7 @@
type="int"
transient="false"
volatile="false"
- value="3"
+ value="12"
static="true"
final="true"
deprecated="not deprecated"
@@ -73837,7 +73859,7 @@
type="int"
transient="false"
volatile="false"
- value="263"
+ value="1052"
static="true"
final="true"
deprecated="not deprecated"
diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h
index 0ea04a4..1243502 100644
--- a/include/media/AudioSystem.h
+++ b/include/media/AudioSystem.h
@@ -103,15 +103,15 @@
// Channel mask definitions must be kept in sync with JAVA values in /media/java/android/media/AudioFormat.java
enum audio_channels {
// output channels
- CHANNEL_OUT_FRONT_LEFT = 0x1,
- CHANNEL_OUT_FRONT_RIGHT = 0x2,
- CHANNEL_OUT_FRONT_CENTER = 0x4,
- CHANNEL_OUT_LOW_FREQUENCY = 0x8,
- CHANNEL_OUT_BACK_LEFT = 0x10,
- CHANNEL_OUT_BACK_RIGHT = 0x20,
- CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x40,
- CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x80,
- CHANNEL_OUT_BACK_CENTER = 0x100,
+ CHANNEL_OUT_FRONT_LEFT = 0x4,
+ CHANNEL_OUT_FRONT_RIGHT = 0x8,
+ CHANNEL_OUT_FRONT_CENTER = 0x10,
+ CHANNEL_OUT_LOW_FREQUENCY = 0x20,
+ CHANNEL_OUT_BACK_LEFT = 0x40,
+ CHANNEL_OUT_BACK_RIGHT = 0x80,
+ CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x100,
+ CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x200,
+ CHANNEL_OUT_BACK_CENTER = 0x400,
CHANNEL_OUT_MONO = CHANNEL_OUT_FRONT_LEFT,
CHANNEL_OUT_STEREO = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT),
CHANNEL_OUT_QUAD = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
@@ -128,20 +128,20 @@
CHANNEL_OUT_FRONT_LEFT_OF_CENTER | CHANNEL_OUT_FRONT_RIGHT_OF_CENTER | CHANNEL_OUT_BACK_CENTER),
// input channels
- CHANNEL_IN_LEFT = 0x10000,
- CHANNEL_IN_RIGHT = 0x20000,
- CHANNEL_IN_FRONT = 0x40000,
- CHANNEL_IN_BACK = 0x80000,
- CHANNEL_IN_LEFT_PROCESSED = 0x100000,
- CHANNEL_IN_RIGHT_PROCESSED = 0x200000,
- CHANNEL_IN_FRONT_PROCESSED = 0x400000,
- CHANNEL_IN_BACK_PROCESSED = 0x800000,
- CHANNEL_IN_PRESSURE = 0x1000000,
- CHANNEL_IN_X_AXIS = 0x2000000,
- CHANNEL_IN_Y_AXIS = 0x4000000,
- CHANNEL_IN_Z_AXIS = 0x8000000,
- CHANNEL_IN_VOICE_UPLINK = 0x10000000,
- CHANNEL_IN_VOICE_DNLINK = 0x20000000,
+ CHANNEL_IN_LEFT = 0x4,
+ CHANNEL_IN_RIGHT = 0x8,
+ CHANNEL_IN_FRONT = 0x10,
+ CHANNEL_IN_BACK = 0x20,
+ CHANNEL_IN_LEFT_PROCESSED = 0x40,
+ CHANNEL_IN_RIGHT_PROCESSED = 0x80,
+ CHANNEL_IN_FRONT_PROCESSED = 0x100,
+ CHANNEL_IN_BACK_PROCESSED = 0x200,
+ CHANNEL_IN_PRESSURE = 0x400,
+ CHANNEL_IN_X_AXIS = 0x800,
+ CHANNEL_IN_Y_AXIS = 0x1000,
+ CHANNEL_IN_Z_AXIS = 0x2000,
+ CHANNEL_IN_VOICE_UPLINK = 0x4000,
+ CHANNEL_IN_VOICE_DNLINK = 0x8000,
CHANNEL_IN_MONO = CHANNEL_IN_FRONT,
CHANNEL_IN_STEREO = (CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT),
CHANNEL_IN_ALL = (CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT | CHANNEL_IN_FRONT | CHANNEL_IN_BACK|
diff --git a/media/java/android/media/AudioFormat.java b/media/java/android/media/AudioFormat.java
index 500f6a4..b3aae72 100644
--- a/media/java/android/media/AudioFormat.java
+++ b/media/java/android/media/AudioFormat.java
@@ -50,19 +50,20 @@
@Deprecated public static final int CHANNEL_CONFIGURATION_STEREO = 3;
/** Invalid audio channel mask */
- public static final int CHANNEL_INVALID = -1;
+ public static final int CHANNEL_INVALID = 0;
/** Default audio channel mask */
+ public static final int CHANNEL_OUT_DEFAULT = 1;
+
// Channel mask definitions must be kept in sync with native values in include/media/AudioSystem.h
- public static final int CHANNEL_OUT_DEFAULT = 0;
- public static final int CHANNEL_OUT_FRONT_LEFT = 0x1;
- public static final int CHANNEL_OUT_FRONT_RIGHT = 0x2;
- public static final int CHANNEL_OUT_FRONT_CENTER = 0x4;
- public static final int CHANNEL_OUT_LOW_FREQUENCY = 0x8;
- public static final int CHANNEL_OUT_BACK_LEFT = 0x10;
- public static final int CHANNEL_OUT_BACK_RIGHT = 0x20;
- public static final int CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x40;
- public static final int CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x80;
- public static final int CHANNEL_OUT_BACK_CENTER = 0x100;
+ public static final int CHANNEL_OUT_FRONT_LEFT = 0x4;
+ public static final int CHANNEL_OUT_FRONT_RIGHT = 0x8;
+ public static final int CHANNEL_OUT_FRONT_CENTER = 0x10;
+ public static final int CHANNEL_OUT_LOW_FREQUENCY = 0x20;
+ public static final int CHANNEL_OUT_BACK_LEFT = 0x40;
+ public static final int CHANNEL_OUT_BACK_RIGHT = 0x80;
+ public static final int CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x100;
+ public static final int CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x200;
+ public static final int CHANNEL_OUT_BACK_CENTER = 0x400;
public static final int CHANNEL_OUT_MONO = CHANNEL_OUT_FRONT_LEFT;
public static final int CHANNEL_OUT_STEREO = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT);
public static final int CHANNEL_OUT_QUAD = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
@@ -75,19 +76,21 @@
CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT |
CHANNEL_OUT_FRONT_LEFT_OF_CENTER | CHANNEL_OUT_FRONT_RIGHT_OF_CENTER);
- public static final int CHANNEL_IN_DEFAULT = 0;
- public static final int CHANNEL_IN_LEFT = 0x10000;
- public static final int CHANNEL_IN_RIGHT = 0x20000;
- public static final int CHANNEL_IN_FRONT = 0x40000;
- public static final int CHANNEL_IN_BACK = 0x80000;
- public static final int CHANNEL_IN_LEFT_PROCESSED = 0x100000;
- public static final int CHANNEL_IN_RIGHT_PROCESSED = 0x200000;
- public static final int CHANNEL_IN_FRONT_PROCESSED = 0x400000;
- public static final int CHANNEL_IN_BACK_PROCESSED = 0x800000;
- public static final int CHANNEL_IN_PRESSURE = 0x1000000;
- public static final int CHANNEL_IN_X_AXIS = 0x2000000;
- public static final int CHANNEL_IN_Y_AXIS = 0x4000000;
- public static final int CHANNEL_IN_Z_AXIS = 0x8000000;
+ public static final int CHANNEL_IN_DEFAULT = 1;
+ public static final int CHANNEL_IN_LEFT = 0x4;
+ public static final int CHANNEL_IN_RIGHT = 0x8;
+ public static final int CHANNEL_IN_FRONT = 0x10;
+ public static final int CHANNEL_IN_BACK = 0x20;
+ public static final int CHANNEL_IN_LEFT_PROCESSED = 0x40;
+ public static final int CHANNEL_IN_RIGHT_PROCESSED = 0x80;
+ public static final int CHANNEL_IN_FRONT_PROCESSED = 0x100;
+ public static final int CHANNEL_IN_BACK_PROCESSED = 0x200;
+ public static final int CHANNEL_IN_PRESSURE = 0x400;
+ public static final int CHANNEL_IN_X_AXIS = 0x800;
+ public static final int CHANNEL_IN_Y_AXIS = 0x1000;
+ public static final int CHANNEL_IN_Z_AXIS = 0x2000;
+ public static final int CHANNEL_IN_VOICE_UPLINK = 0x4000;
+ public static final int CHANNEL_IN_VOICE_DNLINK = 0x8000;
public static final int CHANNEL_IN_MONO = CHANNEL_IN_FRONT;
public static final int CHANNEL_IN_STEREO = (CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT);
diff --git a/media/java/android/media/AudioRecord.java b/media/java/android/media/AudioRecord.java
index d96331f..7a47157 100644
--- a/media/java/android/media/AudioRecord.java
+++ b/media/java/android/media/AudioRecord.java
@@ -133,6 +133,10 @@
*/
private int mChannelCount = 1;
/**
+ * The audio channel mask
+ */
+ private int mChannels = AudioFormat.CHANNEL_IN_MONO;
+ /**
* The current audio channel configuration
*/
private int mChannelConfiguration = AudioFormat.CHANNEL_IN_MONO;
@@ -224,7 +228,7 @@
//TODO: update native initialization when information about hardware init failure
// due to capture device already open is available.
int initResult = native_setup( new WeakReference<AudioRecord>(this),
- mRecordSource, mSampleRate, mChannelCount, mAudioFormat, mNativeBufferSizeInBytes);
+ mRecordSource, mSampleRate, mChannels, mAudioFormat, mNativeBufferSizeInBytes);
if (initResult != SUCCESS) {
loge("Error code "+initResult+" when initializing native AudioRecord object.");
return; // with mState == STATE_UNINITIALIZED
@@ -239,6 +243,7 @@
// postconditions:
// mRecordSource is valid
// mChannelCount is valid
+ // mChannels is valid
// mAudioFormat is valid
// mSampleRate is valid
private void audioParamCheck(int audioSource, int sampleRateInHz,
@@ -264,20 +269,25 @@
//--------------
// channel config
+ mChannelConfiguration = channelConfig;
+
switch (channelConfig) {
- case AudioFormat.CHANNEL_IN_DEFAULT:
+ case AudioFormat.CHANNEL_IN_DEFAULT: // AudioFormat.CHANNEL_CONFIGURATION_DEFAULT
case AudioFormat.CHANNEL_IN_MONO:
+ case AudioFormat.CHANNEL_CONFIGURATION_MONO:
mChannelCount = 1;
- mChannelConfiguration = AudioFormat.CHANNEL_IN_MONO;
+ mChannels = AudioFormat.CHANNEL_IN_MONO;
break;
case AudioFormat.CHANNEL_IN_STEREO:
+ case AudioFormat.CHANNEL_CONFIGURATION_STEREO:
mChannelCount = 2;
- mChannelConfiguration = AudioFormat.CHANNEL_IN_STEREO;
+ mChannels = AudioFormat.CHANNEL_IN_STEREO;
break;
default:
mChannelCount = 0;
- mChannelConfiguration = AudioFormat.CHANNEL_INVALID;
- throw (new IllegalArgumentException("Unsupported channel configuration."));
+ mChannels = AudioFormat.CHANNEL_INVALID;
+ mChannelConfiguration = AudioFormat.CHANNEL_INVALID;
+ throw (new IllegalArgumentException("Unsupported channel configuration."));
}
//--------------
@@ -438,11 +448,13 @@
static public int getMinBufferSize(int sampleRateInHz, int channelConfig, int audioFormat) {
int channelCount = 0;
switch(channelConfig) {
- case AudioFormat.CHANNEL_IN_DEFAULT:
+ case AudioFormat.CHANNEL_IN_DEFAULT: // AudioFormat.CHANNEL_CONFIGURATION_DEFAULT
case AudioFormat.CHANNEL_IN_MONO:
+ case AudioFormat.CHANNEL_CONFIGURATION_MONO:
channelCount = 1;
break;
case AudioFormat.CHANNEL_IN_STEREO:
+ case AudioFormat.CHANNEL_CONFIGURATION_STEREO:
channelCount = 2;
break;
case AudioFormat.CHANNEL_INVALID:
diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java
index 7fbe965..1e8d72f 100644
--- a/media/java/android/media/AudioTrack.java
+++ b/media/java/android/media/AudioTrack.java
@@ -181,10 +181,15 @@
*/
private int mSampleRate = 22050;
/**
- * The number of input audio channels (1 is mono, 2 is stereo).
+ * The number of audio output channels (1 is mono, 2 is stereo).
*/
private int mChannelCount = 1;
/**
+ * The audio channel mask.
+ */
+ private int mChannels = AudioFormat.CHANNEL_OUT_MONO;
+
+ /**
* The type of the audio stream to play. See
* {@link AudioManager#STREAM_VOICE_CALL}, {@link AudioManager#STREAM_SYSTEM},
* {@link AudioManager#STREAM_RING}, {@link AudioManager#STREAM_MUSIC} and
@@ -266,7 +271,7 @@
// native initialization
int initResult = native_setup(new WeakReference<AudioTrack>(this),
- mStreamType, mSampleRate, mChannelCount, mAudioFormat,
+ mStreamType, mSampleRate, mChannels, mAudioFormat,
mNativeBufferSizeInBytes, mDataLoadMode);
if (initResult != SUCCESS) {
loge("Error code "+initResult+" when initializing AudioTrack.");
@@ -286,6 +291,7 @@
// postconditions:
// mStreamType is valid
// mChannelCount is valid
+ // mChannels is valid
// mAudioFormat is valid
// mSampleRate is valid
// mDataLoadMode is valid
@@ -316,19 +322,24 @@
//--------------
// channel config
+ mChannelConfiguration = channelConfig;
+
switch (channelConfig) {
- case AudioFormat.CHANNEL_OUT_DEFAULT:
+ case AudioFormat.CHANNEL_OUT_DEFAULT: //AudioFormat.CHANNEL_CONFIGURATION_DEFAULT
case AudioFormat.CHANNEL_OUT_MONO:
+ case AudioFormat.CHANNEL_CONFIGURATION_MONO:
mChannelCount = 1;
- mChannelConfiguration = AudioFormat.CHANNEL_OUT_MONO;
+ mChannels = AudioFormat.CHANNEL_OUT_MONO;
break;
case AudioFormat.CHANNEL_OUT_STEREO:
+ case AudioFormat.CHANNEL_CONFIGURATION_STEREO:
mChannelCount = 2;
- mChannelConfiguration = AudioFormat.CHANNEL_OUT_STEREO;
+ mChannels = AudioFormat.CHANNEL_OUT_STEREO;
break;
default:
mChannelCount = 0;
- mChannelConfiguration = AudioFormat.CHANNEL_INVALID;
+ mChannels = AudioFormat.CHANNEL_INVALID;
+ mChannelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_INVALID;
throw(new IllegalArgumentException("Unsupported channel configuration."));
}
@@ -546,9 +557,11 @@
int channelCount = 0;
switch(channelConfig) {
case AudioFormat.CHANNEL_OUT_MONO:
+ case AudioFormat.CHANNEL_CONFIGURATION_MONO:
channelCount = 1;
break;
case AudioFormat.CHANNEL_OUT_STEREO:
+ case AudioFormat.CHANNEL_CONFIGURATION_STEREO:
channelCount = 2;
break;
default: