summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Phil Burk <philburk@google.com> 2016-03-18 17:09:22 -0700
committer Phil Burk <philburk@google.com> 2016-03-21 11:15:02 -0700
commit621dbc874047b7f8c227f12fe15f977618f1f2f8 (patch)
tree736189a796ea3018f57ec241faea42d05b618da9
parentf8de70c7b7855cad84fd3565eb29bd9c49bb0bc3 (diff)
Audio ENCODING_IEC61937: enforce use of CHANNEL_OUT_STEREO
Prevent developers from using a channelMask that will fail. Bug: 27721209 Change-Id: I87ad67caedaedf6ed2230165cb1687a2a0b74703 Signed-off-by: Phil Burk <philburk@google.com>
-rw-r--r--media/java/android/media/AudioFormat.java5
-rw-r--r--media/java/android/media/AudioTrack.java9
2 files changed, 14 insertions, 0 deletions
diff --git a/media/java/android/media/AudioFormat.java b/media/java/android/media/AudioFormat.java
index abb6f4e9964c..a4484e757ac5 100644
--- a/media/java/android/media/AudioFormat.java
+++ b/media/java/android/media/AudioFormat.java
@@ -256,6 +256,11 @@ public final class AudioFormat implements Parcelable {
public static final int ENCODING_AAC_HE_V2 = 12;
/** Audio data format: compressed audio wrapped in PCM for HDMI
* or S/PDIF passthrough.
+ * IEC61937 uses a stereo stream of 16-bit samples as the wrapper.
+ * So the channel mask for the track must be {@link #CHANNEL_OUT_STEREO}.
+ * Data should be written to the stream in a short[] array.
+ * If the data is written in a byte[] array then there may be endian problems
+ * on some platforms when converting to short internally.
*/
public static final int ENCODING_IEC61937 = 13;
diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java
index 2aac2b32bc62..c8c4e027d5ef 100644
--- a/media/java/android/media/AudioTrack.java
+++ b/media/java/android/media/AudioTrack.java
@@ -786,6 +786,15 @@ public class AudioTrack implements AudioRouting
}
mSampleRate = sampleRateInHz;
+ // IEC61937 is based on stereo. We could coerce it to stereo.
+ // But the application needs to know the stream is stereo so that
+ // it is encoded and played correctly. So better to just reject it.
+ if (audioFormat == AudioFormat.ENCODING_IEC61937
+ && channelConfig != AudioFormat.CHANNEL_OUT_STEREO) {
+ throw new IllegalArgumentException(
+ "ENCODING_IEC61937 must be configured as CHANNEL_OUT_STEREO");
+ }
+
//--------------
// channel config
mChannelConfiguration = channelConfig;