OSDN Git Service

AudioFormat: more compressed formats
authorEric Laurent <elaurent@google.com>
Tue, 19 May 2015 23:46:52 +0000 (16:46 -0700)
committerEric Laurent <elaurent@google.com>
Tue, 19 May 2015 23:46:52 +0000 (16:46 -0700)
Add MP3 and AAC as valid AudioFormat encodings.
Only @hide for now to allow system components to manage
audio patches with those formats.

Bug: 18649264.
Change-Id: I5ef5f151783308e31d8ac5b29454589077ef62ea

core/jni/android_media_AudioFormat.h
media/java/android/media/AudioDeviceInfo.java
media/java/android/media/AudioFormat.java
media/java/android/media/AudioTrack.java
services/core/java/com/android/server/audio/AudioService.java

index 32b5b02..5144457 100644 (file)
 #define ENCODING_E_AC3      6
 #define ENCODING_DTS        7
 #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_DEFAULT    1
 
@@ -52,6 +56,14 @@ static inline audio_format_t audioFormatToNative(int audioFormat)
         return AUDIO_FORMAT_DTS;
     case ENCODING_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:
         return AUDIO_FORMAT_DEFAULT;
     default:
@@ -76,6 +88,14 @@ static inline int audioFormatFromNative(audio_format_t nativeFormat)
         return ENCODING_DTS;
     case AUDIO_FORMAT_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:
         return ENCODING_DEFAULT;
     default:
index 2099bd0..431d37e 100644 (file)
@@ -204,7 +204,7 @@ public final class AudioDeviceInfo {
      * @see AudioFormat
      */
     public @NonNull int[] getEncodings() {
-        return mPort.formats();
+        return AudioFormat.filterPublicFormats(mPort.formats());
     }
 
    /**
index a7e092f..c35f10f 100644 (file)
@@ -20,6 +20,7 @@ import android.annotation.IntDef;
 import android.annotation.NonNull;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
+import java.util.Arrays;
 
 /**
  * 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;
     /** Audio data format: DTS HD compressed */
     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 */
     /** @deprecated Use {@link #CHANNEL_INVALID} instead.  */
@@ -241,6 +258,27 @@ public class AudioFormat {
         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) {
+        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:
             return true;
         default:
             return false;
@@ -260,6 +298,10 @@ public class AudioFormat {
         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 false;
         case ENCODING_INVALID:
         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 */
     public AudioFormat()
     {
index f893fdd..82212f4 100644 (file)
@@ -764,7 +764,7 @@ public class AudioTrack
             audioFormat = AudioFormat.ENCODING_PCM_16BIT;
         }
 
-        if (!AudioFormat.isValidEncoding(audioFormat)) {
+        if (!AudioFormat.isPublicEncoding(audioFormat)) {
             throw new IllegalArgumentException("Unsupported audio encoding.");
         }
         mAudioFormat = audioFormat;
@@ -1109,7 +1109,7 @@ public class AudioTrack
             }
         }
 
-        if (!AudioFormat.isValidEncoding(audioFormat)) {
+        if (!AudioFormat.isPublicEncoding(audioFormat)) {
             loge("getMinBufferSize(): Invalid audio format.");
             return ERROR_BAD_VALUE;
         }
index 9f35843..352c499 100644 (file)
@@ -4787,7 +4787,7 @@ public class AudioService extends IAudioService.Stub {
                         if (devicePort.type() == AudioManager.DEVICE_OUT_HDMI ||
                                 devicePort.type() == AudioManager.DEVICE_OUT_HDMI_ARC) {
                             // format the list of supported encodings
-                            int[] formats = devicePort.formats();
+                            int[] formats = AudioFormat.filterPublicFormats(devicePort.formats());
                             if (formats.length > 0) {
                                 ArrayList<Integer> encodingList = new ArrayList(1);
                                 for (int format : formats) {