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

Commit bc292d74 authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge "Update Opus over A2DP to use BluetoothCodecConfig api"

parents e6e483ff aa37865c
Loading
Loading
Loading
Loading
+6 −10
Original line number Diff line number Diff line
@@ -38,9 +38,6 @@ class A2dpCodecConfig {
    private static final boolean DBG = true;
    private static final String TAG = "A2dpCodecConfig";

    // TODO(b/240635097): remove in U
    private static final int SOURCE_CODEC_TYPE_OPUS = 6;

    private Context mContext;
    private A2dpNativeInterface mA2dpNativeInterface;

@@ -300,8 +297,7 @@ class A2dpCodecConfig {
                .build();
        codecConfigArray[4] = codecConfig;
        codecConfig = new BluetoothCodecConfig.Builder()
                // TODO(b/240635097): update in U
                .setCodecType(SOURCE_CODEC_TYPE_OPUS)
                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS)
                .setCodecPriority(mA2dpSourceCodecPriorityOpus)
                .build();
        codecConfigArray[5] = codecConfig;
@@ -311,16 +307,16 @@ class A2dpCodecConfig {

    public void switchCodecByBufferSize(
            BluetoothDevice device, boolean isLowLatency, int currentCodecType) {
        // TODO(b/240635097): update in U
        if ((isLowLatency && currentCodecType == SOURCE_CODEC_TYPE_OPUS)
                || (!isLowLatency && currentCodecType != SOURCE_CODEC_TYPE_OPUS)) {
        if ((isLowLatency
                && currentCodecType == BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS)
                || (!isLowLatency
                    && currentCodecType != BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS)) {
            return;
        }
        BluetoothCodecConfig[] codecConfigArray = assignCodecConfigPriorities();
        for (int i = 0; i < codecConfigArray.length; i++){
            BluetoothCodecConfig codecConfig = codecConfigArray[i];
            // TODO(b/240635097): update in U
            if (codecConfig.getCodecType() == SOURCE_CODEC_TYPE_OPUS) {
            if (codecConfig.getCodecType() == BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS) {
                if (isLowLatency) {
                    codecConfig.setCodecPriority(BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST);
                } else {
+1 −4
Original line number Diff line number Diff line
@@ -76,9 +76,6 @@ final class A2dpStateMachine extends StateMachine {
    private static final boolean DBG = true;
    private static final String TAG = "A2dpStateMachine";

    // TODO(b/240635097): remove in U
    private static final int SOURCE_CODEC_TYPE_OPUS = 6;

    static final int CONNECT = 1;
    static final int DISCONNECT = 2;
    @VisibleForTesting
@@ -672,7 +669,7 @@ final class A2dpStateMachine extends StateMachine {
                        != newCodecConfig.getCodecSpecific1())) {
                update = true;
            } else if ((newCodecConfig.getCodecType()
                        == SOURCE_CODEC_TYPE_OPUS) // TODO(b/240635097): update in U
                        == BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS)
                    && (prevCodecConfig != null)
                    // check framesize field
                    && (prevCodecConfig.getCodecSpecific1()
+15 −27
Original line number Diff line number Diff line
@@ -45,9 +45,6 @@ import java.util.Arrays;
@RunWith(AndroidJUnit4.class)
public class A2dpCodecConfigTest {

    // TODO(b/240635097): remove in U
    private static final int SOURCE_CODEC_TYPE_OPUS = 6;

    private Context mTargetContext;
    private BluetoothDevice mTestDevice;
    private A2dpCodecConfig mA2dpCodecConfig;
@@ -61,7 +58,7 @@ public class A2dpCodecConfigTest {
            BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX,
            BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD,
            BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC,
            SOURCE_CODEC_TYPE_OPUS // TODO(b/240635097): update in U
            BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS
    };

    // Not use the default value to make sure it reads from config
@@ -113,7 +110,7 @@ public class A2dpCodecConfigTest {
                                     | BluetoothCodecConfig.BITS_PER_SAMPLE_32,
                                     BluetoothCodecConfig.CHANNEL_MODE_STEREO,
                                     0, 0, 0, 0),       // Codec-specific fields
            buildBluetoothCodecConfig(SOURCE_CODEC_TYPE_OPUS, // TODO(b/240635097): update in U
            buildBluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS,
                                     OPUS_PRIORITY_DEFAULT,
                                     BluetoothCodecConfig.SAMPLE_RATE_48000,
                                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
@@ -152,7 +149,7 @@ public class A2dpCodecConfigTest {
                                     BluetoothCodecConfig.BITS_PER_SAMPLE_32,
                                     BluetoothCodecConfig.CHANNEL_MODE_STEREO,
                                     0, 0, 0, 0),       // Codec-specific fields
            buildBluetoothCodecConfig(SOURCE_CODEC_TYPE_OPUS, // TODO(b/240635097): update in U
            buildBluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS,
                                     OPUS_PRIORITY_DEFAULT,
                                     BluetoothCodecConfig.SAMPLE_RATE_48000,
                                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
@@ -212,7 +209,7 @@ public class A2dpCodecConfigTest {
                case BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC:
                    Assert.assertEquals(config.getCodecPriority(), LDAC_PRIORITY_DEFAULT);
                    break;
                case SOURCE_CODEC_TYPE_OPUS: // TODO(b/240635097): update in U
                case BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS:
                    Assert.assertEquals(config.getCodecPriority(), OPUS_PRIORITY_DEFAULT);
                    break;
            }
@@ -245,9 +242,8 @@ public class A2dpCodecConfigTest {
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC, PRIORITY_HIGH,
                true);
        testCodecPriorityChangeHelper(
                // TODO(b/240635097): update in U
                SOURCE_CODEC_TYPE_OPUS, OPUS_PRIORITY_DEFAULT,
                SOURCE_CODEC_TYPE_OPUS, PRIORITY_HIGH,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS, OPUS_PRIORITY_DEFAULT,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS, PRIORITY_HIGH,
                false);
    }

@@ -259,33 +255,27 @@ public class A2dpCodecConfigTest {
    public void testSetCodecPreference_priorityDefaultToRaiseHigh() {
        testCodecPriorityChangeHelper(
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, PRIORITY_HIGH,
                // TODO(b/240635097): update in U
                SOURCE_CODEC_TYPE_OPUS, OPUS_PRIORITY_DEFAULT,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS, OPUS_PRIORITY_DEFAULT,
                true);
        testCodecPriorityChangeHelper(
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC, PRIORITY_HIGH,
                // TODO(b/240635097): update in U
                SOURCE_CODEC_TYPE_OPUS, OPUS_PRIORITY_DEFAULT,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS, OPUS_PRIORITY_DEFAULT,
                true);
        testCodecPriorityChangeHelper(
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX, PRIORITY_HIGH,
                // TODO(b/240635097): update in U
                SOURCE_CODEC_TYPE_OPUS, OPUS_PRIORITY_DEFAULT,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS, OPUS_PRIORITY_DEFAULT,
                true);
        testCodecPriorityChangeHelper(
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD, PRIORITY_HIGH,
                // TODO(b/240635097): update in U
                SOURCE_CODEC_TYPE_OPUS, OPUS_PRIORITY_DEFAULT,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS, OPUS_PRIORITY_DEFAULT,
                true);
        testCodecPriorityChangeHelper(
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC, PRIORITY_HIGH,
                // TODO(b/240635097): update in U
                SOURCE_CODEC_TYPE_OPUS, OPUS_PRIORITY_DEFAULT,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS, OPUS_PRIORITY_DEFAULT,
                true);
        testCodecPriorityChangeHelper(
                // TODO(b/240635097): update in U
                SOURCE_CODEC_TYPE_OPUS, PRIORITY_HIGH,
                SOURCE_CODEC_TYPE_OPUS, OPUS_PRIORITY_DEFAULT,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS, PRIORITY_HIGH,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS, OPUS_PRIORITY_DEFAULT,
                false);
    }

@@ -312,8 +302,7 @@ public class A2dpCodecConfigTest {
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, PRIORITY_HIGH,
                true);
        testCodecPriorityChangeHelper(
                // TODO(b/240635097): update in U
                SOURCE_CODEC_TYPE_OPUS, PRIORITY_HIGH,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS, PRIORITY_HIGH,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, PRIORITY_HIGH,
                true);
    }
@@ -341,8 +330,7 @@ public class A2dpCodecConfigTest {
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC, PRIORITY_HIGH,
                true);
        testCodecPriorityChangeHelper(
                // TODO(b/240635097): update in U
                SOURCE_CODEC_TYPE_OPUS, PRIORITY_HIGH,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS, PRIORITY_HIGH,
                BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC, PRIORITY_HIGH,
                true);
    }
+1 −4
Original line number Diff line number Diff line
@@ -53,9 +53,6 @@ import java.util.Arrays;
@MediumTest
@RunWith(AndroidJUnit4.class)
public class A2dpStateMachineTest {
    // TODO(b/240635097): remove in U
    private static final int SOURCE_CODEC_TYPE_OPUS = 6;

    private BluetoothAdapter mAdapter;
    private Context mTargetContext;
    private HandlerThread mHandlerThread;
@@ -108,7 +105,7 @@ public class A2dpStateMachineTest {
                    .build();

        mCodecConfigOpus = new BluetoothCodecConfig.Builder()
                    .setCodecType(SOURCE_CODEC_TYPE_OPUS) // TODO(b/240635097): update in U
                    .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS)
                    .setCodecPriority(BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT)
                    .setSampleRate(BluetoothCodecConfig.SAMPLE_RATE_48000)
                    .setBitsPerSample(BluetoothCodecConfig.BITS_PER_SAMPLE_16)
+1 −0
Original line number Diff line number Diff line
@@ -457,6 +457,7 @@ package android.bluetooth {
    field public static final int SOURCE_CODEC_TYPE_INVALID = 1000000; // 0xf4240
    field public static final int SOURCE_CODEC_TYPE_LC3 = 5; // 0x5
    field public static final int SOURCE_CODEC_TYPE_LDAC = 4; // 0x4
    field public static final int SOURCE_CODEC_TYPE_OPUS = 6; // 0x6
    field public static final int SOURCE_CODEC_TYPE_SBC = 0; // 0x0
  }

Loading