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

Commit 6bf2e507 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes from topic "a2dp_lc3_framework"

* changes:
  Add framework support of LC3 codec
  Add priority for LC3 codec
parents 502eee98 f9ad8bde
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@
    <integer name="a2dp_source_codec_priority_aptx">3001</integer>
    <integer name="a2dp_source_codec_priority_aptx_hd">4001</integer>
    <integer name="a2dp_source_codec_priority_ldac">5001</integer>
    <integer name="a2dp_source_codec_priority_lc3">6001</integer>

    <!-- For enabling the AVRCP Target Cover Artowrk feature-->
    <bool name="avrcp_target_enable_cover_art">true</bool>
+17 −0
Original line number Diff line number Diff line
@@ -51,6 +51,8 @@ class A2dpCodecConfig {
            BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;
    private @CodecPriority int mA2dpSourceCodecPriorityLdac =
            BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;
    private @CodecPriority int mA2dpSourceCodecPriorityLc3 =
            BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;

    private BluetoothCodecConfig[] mCodecConfigOffloading = new BluetoothCodecConfig[0];

@@ -231,6 +233,16 @@ class A2dpCodecConfig {
            mA2dpSourceCodecPriorityLdac = value;
        }

        try {
            value = resources.getInteger(R.integer.a2dp_source_codec_priority_lc3);
        } catch (NotFoundException e) {
            value = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;
        }
        if ((value >= BluetoothCodecConfig.CODEC_PRIORITY_DISABLED) && (value
                < BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST)) {
            mA2dpSourceCodecPriorityLc3 = value;
        }

        BluetoothCodecConfig codecConfig;
        BluetoothCodecConfig[] codecConfigArray =
                new BluetoothCodecConfig[BluetoothCodecConfig.getMaxCodecType()];
@@ -259,6 +271,11 @@ class A2dpCodecConfig {
                .setCodecPriority(mA2dpSourceCodecPriorityLdac)
                .build();
        codecConfigArray[4] = codecConfig;
        codecConfig = new BluetoothCodecConfig.Builder()
                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3)
                .setCodecPriority(mA2dpSourceCodecPriorityLc3)
                .build();
        codecConfigArray[5] = codecConfig;

        return codecConfigArray;
    }
+43 −6
Original line number Diff line number Diff line
@@ -56,7 +56,8 @@ public class A2dpCodecConfigTest {
            BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC,
            BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX,
            BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD,
            BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC
            BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC,
            BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3
    };

    // Not use the default value to make sure it reads from config
@@ -65,6 +66,7 @@ public class A2dpCodecConfigTest {
    private static final int APTX_PRIORITY_DEFAULT = 5001;
    private static final int APTX_HD_PRIORITY_DEFAULT = 7001;
    private static final int LDAC_PRIORITY_DEFAULT = 9001;
    private static final int LC3_PRIORITY_DEFAULT = 11001;
    private static final int PRIORITY_HIGH = 1000000;

    private static final BluetoothCodecConfig[] sCodecCapabilities = new BluetoothCodecConfig[] {
@@ -105,6 +107,14 @@ public class A2dpCodecConfigTest {
                                     | BluetoothCodecConfig.BITS_PER_SAMPLE_24
                                     | BluetoothCodecConfig.BITS_PER_SAMPLE_32,
                                     BluetoothCodecConfig.CHANNEL_MODE_STEREO,
                                     0, 0, 0, 0),       // Codec-specific fields
            buildBluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3,
                                     LC3_PRIORITY_DEFAULT,
                                     BluetoothCodecConfig.SAMPLE_RATE_44100
                                     | BluetoothCodecConfig.SAMPLE_RATE_48000,
                                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
                                     BluetoothCodecConfig.CHANNEL_MODE_MONO
                                     | BluetoothCodecConfig.CHANNEL_MODE_STEREO,
                                     0, 0, 0, 0)        // Codec-specific fields
    };

@@ -138,6 +148,12 @@ public class A2dpCodecConfigTest {
                                     BluetoothCodecConfig.SAMPLE_RATE_96000,
                                     BluetoothCodecConfig.BITS_PER_SAMPLE_32,
                                     BluetoothCodecConfig.CHANNEL_MODE_STEREO,
                                     0, 0, 0, 0),       // Codec-specific fields
            buildBluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3,
                                     LC3_PRIORITY_DEFAULT,
                                     BluetoothCodecConfig.SAMPLE_RATE_48000,
                                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
                                     BluetoothCodecConfig.CHANNEL_MODE_STEREO,
                                     0, 0, 0, 0)        // Codec-specific fields
    };

@@ -158,6 +174,8 @@ public class A2dpCodecConfigTest {
                .thenReturn(APTX_HD_PRIORITY_DEFAULT);
        when(mMockResources.getInteger(R.integer.a2dp_source_codec_priority_ldac))
                .thenReturn(LDAC_PRIORITY_DEFAULT);
        when(mMockResources.getInteger(R.integer.a2dp_source_codec_priority_lc3))
                .thenReturn(LC3_PRIORITY_DEFAULT);

        mA2dpCodecConfig = new A2dpCodecConfig(mMockContext, mA2dpNativeInterface);
        mTestDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice("00:01:02:03:04:05");
@@ -191,6 +209,9 @@ public class A2dpCodecConfigTest {
                case BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC:
                    Assert.assertEquals(config.getCodecPriority(), LDAC_PRIORITY_DEFAULT);
                    break;
                case BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3:
                    Assert.assertEquals(config.getCodecPriority(), LC3_PRIORITY_DEFAULT);
                    break;
            }
        }
    }
@@ -219,6 +240,10 @@ public class A2dpCodecConfigTest {
        testCodecPriorityChangeHelper(
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC, LDAC_PRIORITY_DEFAULT,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC, PRIORITY_HIGH,
                true);
        testCodecPriorityChangeHelper(
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3, LC3_PRIORITY_DEFAULT,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3, PRIORITY_HIGH,
                false);
    }

@@ -230,23 +255,27 @@ public class A2dpCodecConfigTest {
    public void testSetCodecPreference_priorityDefaultToRaiseHigh() {
        testCodecPriorityChangeHelper(
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, PRIORITY_HIGH,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC, LDAC_PRIORITY_DEFAULT,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3, LC3_PRIORITY_DEFAULT,
                true);
        testCodecPriorityChangeHelper(
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC, PRIORITY_HIGH,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC, LDAC_PRIORITY_DEFAULT,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3, LC3_PRIORITY_DEFAULT,
                true);
        testCodecPriorityChangeHelper(
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX, PRIORITY_HIGH,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC, LDAC_PRIORITY_DEFAULT,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3, LC3_PRIORITY_DEFAULT,
                true);
        testCodecPriorityChangeHelper(
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD, PRIORITY_HIGH,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC, LDAC_PRIORITY_DEFAULT,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3, LC3_PRIORITY_DEFAULT,
                true);
        testCodecPriorityChangeHelper(
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC, PRIORITY_HIGH,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC, LDAC_PRIORITY_DEFAULT,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3, LC3_PRIORITY_DEFAULT,
                true);
        testCodecPriorityChangeHelper(
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3, PRIORITY_HIGH,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3, LC3_PRIORITY_DEFAULT,
                false);
    }

@@ -272,6 +301,10 @@ public class A2dpCodecConfigTest {
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC, PRIORITY_HIGH,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, PRIORITY_HIGH,
                true);
        testCodecPriorityChangeHelper(
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3, PRIORITY_HIGH,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, PRIORITY_HIGH,
                true);
    }

    @Test
@@ -296,6 +329,10 @@ public class A2dpCodecConfigTest {
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC, PRIORITY_HIGH,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC, PRIORITY_HIGH,
                true);
        testCodecPriorityChangeHelper(
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3, PRIORITY_HIGH,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC, PRIORITY_HIGH,
                true);
    }

    @Test
+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());
            }