Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f9ad8bde authored by Ted Wang's avatar Ted Wang
Browse files

Add framework support of LC3 codec

Bug: 203621600
Test: atest BluetoothCodecConfigTest
Change-Id: Ibacc8b39c4d916f69befca139604ed94c627c103
parent 91315641
Loading
Loading
Loading
Loading
+16 −12
Original line number Diff line number Diff line
@@ -38,14 +38,10 @@ import java.util.Objects;
 */
public final class BluetoothCodecConfig implements Parcelable {
    /** @hide */
    @IntDef(prefix = "SOURCE_CODEC_TYPE_", value = {
            SOURCE_CODEC_TYPE_SBC,
            SOURCE_CODEC_TYPE_AAC,
            SOURCE_CODEC_TYPE_APTX,
            SOURCE_CODEC_TYPE_APTX_HD,
            SOURCE_CODEC_TYPE_LDAC,
            SOURCE_CODEC_TYPE_INVALID
    })
    @IntDef(prefix = "SOURCE_CODEC_TYPE_",
        value = {SOURCE_CODEC_TYPE_SBC, SOURCE_CODEC_TYPE_AAC, SOURCE_CODEC_TYPE_APTX,
            SOURCE_CODEC_TYPE_APTX_HD, SOURCE_CODEC_TYPE_LDAC, SOURCE_CODEC_TYPE_LC3,
            SOURCE_CODEC_TYPE_INVALID})
    @Retention(RetentionPolicy.SOURCE)
    public @interface SourceCodecType {}

@@ -75,6 +71,11 @@ public final class BluetoothCodecConfig implements Parcelable {
     */
    public static final int SOURCE_CODEC_TYPE_LDAC = 4;

    /**
     * Source codec type LC3.
     */
    public static final int SOURCE_CODEC_TYPE_LC3 = 5;

    /**
     * Source codec type invalid. This is the default value used for codec
     * type.
@@ -85,7 +86,7 @@ public final class BluetoothCodecConfig implements Parcelable {
     * Represents the count of valid source codec types. Can be accessed via
     * {@link #getMaxCodecType}.
     */
    private static final int SOURCE_CODEC_TYPE_MAX = 5;
    private static final int SOURCE_CODEC_TYPE_MAX = 6;

    /** @hide */
    @IntDef(prefix = "CODEC_PRIORITY_", value = {
@@ -460,6 +461,8 @@ public final class BluetoothCodecConfig implements Parcelable {
                return "aptX HD";
            case SOURCE_CODEC_TYPE_LDAC:
                return "LDAC";
            case SOURCE_CODEC_TYPE_LC3:
              return "LC3";
            case SOURCE_CODEC_TYPE_INVALID:
                return "INVALID CODEC";
            default:
@@ -664,6 +667,7 @@ public final class BluetoothCodecConfig implements Parcelable {
        switch (mCodecType) {
            case SOURCE_CODEC_TYPE_AAC:
            case SOURCE_CODEC_TYPE_LDAC:
            case SOURCE_CODEC_TYPE_LC3:
              if (mCodecSpecific1 != other.mCodecSpecific1) {
                return false;
              }
+74 −50
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ public class BluetoothCodecConfigTest extends TestCase {
      BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX,
      BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD,
      BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC,
      BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3,
      BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID,
  };
  private static final int[] kCodecPriorityArray = new int[] {
@@ -60,15 +61,35 @@ public class BluetoothCodecConfigTest extends TestCase {
      BluetoothCodecConfig.CHANNEL_MODE_MONO,
      BluetoothCodecConfig.CHANNEL_MODE_STEREO,
  };
    private static final long[] kCodecSpecific1Array = new long[] { 1000, 1001, 1002, 1003, };
    private static final long[] kCodecSpecific2Array = new long[] { 2000, 2001, 2002, 2003, };
    private static final long[] kCodecSpecific3Array = new long[] { 3000, 3001, 3002, 3003, };
    private static final long[] kCodecSpecific4Array = new long[] { 4000, 4001, 4002, 4003, };

    private static final int kTotalConfigs = kCodecTypeArray.length * kCodecPriorityArray.length *
        kSampleRateArray.length * kBitsPerSampleArray.length * kChannelModeArray.length *
        kCodecSpecific1Array.length * kCodecSpecific2Array.length * kCodecSpecific3Array.length *
        kCodecSpecific4Array.length;
  private static final long[] kCodecSpecific1Array = new long[] {
      1000,
      1001,
      1002,
      1003,
  };
  private static final long[] kCodecSpecific2Array = new long[] {
      2000,
      2001,
      2002,
      2003,
  };
  private static final long[] kCodecSpecific3Array = new long[] {
      3000,
      3001,
      3002,
      3003,
  };
  private static final long[] kCodecSpecific4Array = new long[] {
      4000,
      4001,
      4002,
      4003,
  };

  private static final int kTotalConfigs = kCodecTypeArray.length * kCodecPriorityArray.length
      * kSampleRateArray.length * kBitsPerSampleArray.length * kChannelModeArray.length
      * kCodecSpecific1Array.length * kCodecSpecific2Array.length * kCodecSpecific3Array.length
      * kCodecSpecific4Array.length;

  private int selectCodecType(int configId) {
    int left = kCodecTypeArray.length;
@@ -193,6 +214,9 @@ public class BluetoothCodecConfigTest extends TestCase {
            if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC) {
                assertEquals("LDAC", bcc.getCodecName());
            }
            if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3) {
              assertEquals("LC3", bcc.getCodecName());
            }
            if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID) {
                assertEquals("INVALID CODEC", bcc.getCodecName());
            }