Merge "AudioFormat: more compressed formats" into mnc-dev

This commit is contained in:
Eric Laurent
2015-05-20 16:22:00 +00:00
committed by Android (Google) Code Review
5 changed files with 88 additions and 4 deletions

View File

@@ -27,6 +27,10 @@
#define ENCODING_E_AC3 6 #define ENCODING_E_AC3 6
#define ENCODING_DTS 7 #define ENCODING_DTS 7
#define ENCODING_DTS_HD 8 #define ENCODING_DTS_HD 8
#define ENCODING_MP3 9
#define ENCODING_AAC_LC 10
#define ENCODING_AAC_HE_V1 11
#define ENCODING_AAC_HE_V2 12
#define ENCODING_INVALID 0 #define ENCODING_INVALID 0
#define ENCODING_DEFAULT 1 #define ENCODING_DEFAULT 1
@@ -52,6 +56,14 @@ static inline audio_format_t audioFormatToNative(int audioFormat)
return AUDIO_FORMAT_DTS; return AUDIO_FORMAT_DTS;
case ENCODING_DTS_HD: case ENCODING_DTS_HD:
return AUDIO_FORMAT_DTS_HD; return AUDIO_FORMAT_DTS_HD;
case ENCODING_MP3:
return AUDIO_FORMAT_MP3;
case ENCODING_AAC_LC:
return AUDIO_FORMAT_AAC_LC;
case ENCODING_AAC_HE_V1:
return AUDIO_FORMAT_AAC_HE_V1;
case ENCODING_AAC_HE_V2:
return AUDIO_FORMAT_AAC_HE_V2;
case ENCODING_DEFAULT: case ENCODING_DEFAULT:
return AUDIO_FORMAT_DEFAULT; return AUDIO_FORMAT_DEFAULT;
default: default:
@@ -76,6 +88,14 @@ static inline int audioFormatFromNative(audio_format_t nativeFormat)
return ENCODING_DTS; return ENCODING_DTS;
case AUDIO_FORMAT_DTS_HD: case AUDIO_FORMAT_DTS_HD:
return ENCODING_DTS_HD; return ENCODING_DTS_HD;
case AUDIO_FORMAT_MP3:
return ENCODING_MP3;
case AUDIO_FORMAT_AAC_LC:
return ENCODING_AAC_LC;
case AUDIO_FORMAT_AAC_HE_V1:
return ENCODING_AAC_HE_V1;
case AUDIO_FORMAT_AAC_HE_V2:
return ENCODING_AAC_HE_V2;
case AUDIO_FORMAT_DEFAULT: case AUDIO_FORMAT_DEFAULT:
return ENCODING_DEFAULT; return ENCODING_DEFAULT;
default: default:

View File

@@ -204,7 +204,7 @@ public final class AudioDeviceInfo {
* @see AudioFormat * @see AudioFormat
*/ */
public @NonNull int[] getEncodings() { public @NonNull int[] getEncodings() {
return mPort.formats(); return AudioFormat.filterPublicFormats(mPort.formats());
} }
/** /**

View File

@@ -20,6 +20,7 @@ import android.annotation.IntDef;
import android.annotation.NonNull; import android.annotation.NonNull;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
/** /**
* The AudioFormat class is used to access a number of audio format and * The AudioFormat class is used to access a number of audio format and
@@ -53,6 +54,22 @@ public class AudioFormat {
public static final int ENCODING_DTS = 7; public static final int ENCODING_DTS = 7;
/** Audio data format: DTS HD compressed */ /** Audio data format: DTS HD compressed */
public static final int ENCODING_DTS_HD = 8; public static final int ENCODING_DTS_HD = 8;
/** Audio data format: MP3 compressed
* @hide
* */
public static final int ENCODING_MP3 = 9;
/** Audio data format: AAC LC compressed
* @hide
* */
public static final int ENCODING_AAC_LC = 10;
/** Audio data format: AAC HE V1 compressed
* @hide
* */
public static final int ENCODING_AAC_HE_V1 = 11;
/** Audio data format: AAC HE V2 compressed
* @hide
* */
public static final int ENCODING_AAC_HE_V2 = 12;
/** Invalid audio channel configuration */ /** Invalid audio channel configuration */
/** @deprecated Use {@link #CHANNEL_INVALID} instead. */ /** @deprecated Use {@link #CHANNEL_INVALID} instead. */
@@ -232,6 +249,27 @@ public class AudioFormat {
/** @hide */ /** @hide */
public static boolean isValidEncoding(int audioFormat) public static boolean isValidEncoding(int audioFormat)
{
switch (audioFormat) {
case ENCODING_PCM_8BIT:
case ENCODING_PCM_16BIT:
case ENCODING_PCM_FLOAT:
case ENCODING_AC3:
case ENCODING_E_AC3:
case ENCODING_DTS:
case ENCODING_DTS_HD:
case ENCODING_MP3:
case ENCODING_AAC_LC:
case ENCODING_AAC_HE_V1:
case ENCODING_AAC_HE_V2:
return true;
default:
return false;
}
}
/** @hide */
public static boolean isPublicEncoding(int audioFormat)
{ {
switch (audioFormat) { switch (audioFormat) {
case ENCODING_PCM_8BIT: case ENCODING_PCM_8BIT:
@@ -260,6 +298,10 @@ public class AudioFormat {
case ENCODING_E_AC3: case ENCODING_E_AC3:
case ENCODING_DTS: case ENCODING_DTS:
case ENCODING_DTS_HD: case ENCODING_DTS_HD:
case ENCODING_MP3:
case ENCODING_AAC_LC:
case ENCODING_AAC_HE_V1:
case ENCODING_AAC_HE_V2:
return false; return false;
case ENCODING_INVALID: case ENCODING_INVALID:
default: default:
@@ -267,6 +309,28 @@ public class AudioFormat {
} }
} }
/**
* Returns an array of public encoding values extracted from an array of
* encoding values.
* @hide
*/
public static int[] filterPublicFormats(int[] formats) {
if (formats == null) {
return null;
}
int[] myCopy = Arrays.copyOf(formats, formats.length);
int size = 0;
for (int i = 0; i < myCopy.length; i++) {
if (isPublicEncoding(myCopy[i])) {
if (size != i) {
myCopy[size] = myCopy[i];
}
size++;
}
}
return Arrays.copyOf(myCopy, size);
}
/** @removed */ /** @removed */
public AudioFormat() public AudioFormat()
{ {

View File

@@ -775,7 +775,7 @@ public class AudioTrack
audioFormat = AudioFormat.ENCODING_PCM_16BIT; audioFormat = AudioFormat.ENCODING_PCM_16BIT;
} }
if (!AudioFormat.isValidEncoding(audioFormat)) { if (!AudioFormat.isPublicEncoding(audioFormat)) {
throw new IllegalArgumentException("Unsupported audio encoding."); throw new IllegalArgumentException("Unsupported audio encoding.");
} }
mAudioFormat = audioFormat; mAudioFormat = audioFormat;
@@ -1119,7 +1119,7 @@ public class AudioTrack
} }
} }
if (!AudioFormat.isValidEncoding(audioFormat)) { if (!AudioFormat.isPublicEncoding(audioFormat)) {
loge("getMinBufferSize(): Invalid audio format."); loge("getMinBufferSize(): Invalid audio format.");
return ERROR_BAD_VALUE; return ERROR_BAD_VALUE;
} }

View File

@@ -4787,7 +4787,7 @@ public class AudioService extends IAudioService.Stub {
if (devicePort.type() == AudioManager.DEVICE_OUT_HDMI || if (devicePort.type() == AudioManager.DEVICE_OUT_HDMI ||
devicePort.type() == AudioManager.DEVICE_OUT_HDMI_ARC) { devicePort.type() == AudioManager.DEVICE_OUT_HDMI_ARC) {
// format the list of supported encodings // format the list of supported encodings
int[] formats = devicePort.formats(); int[] formats = AudioFormat.filterPublicFormats(devicePort.formats());
if (formats.length > 0) { if (formats.length > 0) {
ArrayList<Integer> encodingList = new ArrayList(1); ArrayList<Integer> encodingList = new ArrayList(1);
for (int format : formats) { for (int format : formats) {