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

Commit d395b0ea authored by Chen Chen's avatar Chen Chen Committed by Automerger Merge Worker
Browse files

Merge "SpatialAudio: Swtich codecs using setCodecPriority Sponsored by...

Merge "SpatialAudio: Swtich codecs using setCodecPriority Sponsored by @cheneyni Test: Build Bug: 214615268" am: ec34017d am: a0d36b54 am: 2dacd679 am: 0b5a636c

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2000135

Change-Id: I72c904327be0bb711ac3164e7c2bb5c2dd4dafbf
parents a4cf396b 0b5a636c
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -279,5 +279,27 @@ class A2dpCodecConfig {

        return codecConfigArray;
    }

    public void switchCodecByBufferSize(
            BluetoothDevice device, boolean isLowLatency, int currentCodecType) {
        if ((isLowLatency && currentCodecType == BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3)
        || (!isLowLatency && currentCodecType != BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3)) {
            return;
        }
        BluetoothCodecConfig[] codecConfigArray = assignCodecConfigPriorities();
        for (int i = 0; i < codecConfigArray.length; i++){
            BluetoothCodecConfig codecConfig = codecConfigArray[i];
            if (codecConfig.getCodecType() == BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3) {
                if (isLowLatency) {
                    codecConfig.setCodecPriority(BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST);
                } else {
                    codecConfig.setCodecPriority(BluetoothCodecConfig.CODEC_PRIORITY_DISABLED);
                }
            } else {
                codecConfigArray[i] = null;
            }
        }
        mA2dpNativeInterface.setCodecConfigPreference(device, codecConfigArray);
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -1601,4 +1601,9 @@ public class A2dpService extends ProfileService {
            sm.dump(sb);
        }
    }

    public void switchCodecByBufferSize(BluetoothDevice device, boolean isLowLatency) {
        mA2dpCodecConfig.switchCodecByBufferSize(
                device, isLowLatency, getCodecStatus(device).getCodecConfig().getCodecType());
    }
}
+1 −35
Original line number Diff line number Diff line
@@ -851,41 +851,7 @@ public class AdapterService extends Service {
                    "Cannot switch buffer size. The number of A2DP active devices is "
                            + activeDevices.size());
        }
        BluetoothCodecConfig codecConfig = null;
        BluetoothCodecStatus currentCodecStatus = mA2dpService.getCodecStatus(activeDevices.get(0));
        int currentCodec = currentCodecStatus.getCodecConfig().getCodecType();
        if (isLowLatencyBufferSize) {
            if (currentCodec == BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3) {
                Log.w(TAG, "Current codec is already LC3. No need to change it.");
                return;
            }
            codecConfig = new BluetoothCodecConfig(
                    BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3,
                    BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST,
                    BluetoothCodecConfig.SAMPLE_RATE_48000,
                    BluetoothCodecConfig.BITS_PER_SAMPLE_16,
                    BluetoothCodecConfig.CHANNEL_MODE_STEREO,
                    0, 0x1 << 2, 0, 0);
        } else {
            if (currentCodec != BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3) {
                Log.w(TAG, "Current codec is not LC3. No need to change it.");
                return;
            }
            List<BluetoothCodecConfig> selectableCodecs =
                    currentCodecStatus.getCodecsSelectableCapabilities();
            for (BluetoothCodecConfig config : selectableCodecs) {
                // Find a non LC3 codec
                if (config.getCodecType() != BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3) {
                    codecConfig = config;
                    break;
                }
            }
            if (codecConfig == null) {
                Log.e(TAG, "Cannot find a non LC3 codec compatible with the remote device");
                return;
            }
        }
        mA2dpService.setCodecConfigPreference(activeDevices.get(0), codecConfig);
        mA2dpService.switchCodecByBufferSize(activeDevices.get(0), isLowLatencyBufferSize);
    }

    /**