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

Commit 6fada95a authored by Chen Chen's avatar Chen Chen Committed by Gerrit Code Review
Browse files

Merge "SpatialAudio: Pass buffer size switching signal from audio HAL to native Bluetooth"

parents 0ad31ce7 f41721c0
Loading
Loading
Loading
Loading
+3 −19
Original line number Diff line number Diff line
@@ -599,31 +599,15 @@ static void link_quality_report_callback(
      (jint)negative_acknowledgement_count);
}

static void switch_buffer_size_callback(RawAddress* bd_addr,
                                        bool is_low_latency_buffer_size) {

  if (!bd_addr) {
    ALOGE("Address is null in %s", __func__);
    return;
  }
static void switch_buffer_size_callback(bool is_low_latency_buffer_size) {
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;

  ScopedLocalRef<jbyteArray> addr(
      sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
  if (!addr.get()) {
    ALOGE("Error while allocating in: %s", __func__);
    return;
  }

  sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
                                 (jbyte*)bd_addr);

  ALOGV("%s: SwitchBufferSizeCallback: %s", __func__,
        is_low_latency_buffer_size ? "true" : "false");

  sCallbackEnv->CallVoidMethod(
      sJniCallbacksObj, method_switchBufferSizeCallback, addr.get(),
      sJniCallbacksObj, method_switchBufferSizeCallback,
      (jboolean)is_low_latency_buffer_size);
}

@@ -924,7 +908,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
      jniCallbackClass, "linkQualityReportCallback", "(JIIIIII)V");

  method_switchBufferSizeCallback =
      env->GetMethodID(jniCallbackClass, "switchBufferSizeCallback", "([BZ)V");
      env->GetMethodID(jniCallbackClass, "switchBufferSizeCallback", "(Z)V");

  method_setWakeAlarm = env->GetMethodID(clazz, "setWakeAlarm", "(JZ)Z");
  method_acquireWakeLock =
+9 −3
Original line number Diff line number Diff line
@@ -831,15 +831,21 @@ public class AdapterService extends Service {
        }
    }

    void switchBufferSizeCallback(byte[] address, boolean isLowLatencyBufferSize) {
        BluetoothDevice device = getDeviceFromByte(address);
    void switchBufferSizeCallback(boolean isLowLatencyBufferSize) {
        List<BluetoothDevice> activeDevices = getActiveDevices(BluetoothProfile.A2DP);
        if (activeDevices.size() != 1) {
            errorLog(
                    "Cannot switch buffer size. The number of A2DP active devices is "
                            + activeDevices.size());
        }

        // Send intent to fastpair
        Intent switchBufferSizeIntent = new Intent(BluetoothDevice.ACTION_SWITCH_BUFFER_SIZE);
        switchBufferSizeIntent.setClassName(
                getString(com.android.bluetooth.R.string.peripheral_link_package),
                getString(com.android.bluetooth.R.string.peripheral_link_package)
                        + getString(com.android.bluetooth.R.string.peripheral_link_service));
        switchBufferSizeIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        switchBufferSizeIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, activeDevices.get(0));
        switchBufferSizeIntent.putExtra(
                BluetoothDevice.EXTRA_LOW_LATENCY_BUFFER_SIZE, isLowLatencyBufferSize);
        sendBroadcast(switchBufferSizeIntent);
+2 −2
Original line number Diff line number Diff line
@@ -106,8 +106,8 @@ final class JniCallbacks {
                packets_not_receive_count, negative_acknowledgement_count);
    }

    void switchBufferSizeCallback(byte[] mac_address, boolean is_low_latency_buffer_size) {
        mAdapterService.switchBufferSizeCallback(mac_address, is_low_latency_buffer_size);
    void switchBufferSizeCallback(boolean is_low_latency_buffer_size) {
        mAdapterService.switchBufferSizeCallback(is_low_latency_buffer_size);
    }

}
+3 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#include "bluetooth_audio_port_impl.h"

#include "btif/include/btif_common.h"
#include "common/stop_watch_legacy.h"

namespace bluetooth {
@@ -134,6 +135,8 @@ ndk::ScopedAStatus BluetoothAudioPortImpl::updateSinkMetadata(

ndk::ScopedAStatus BluetoothAudioPortImpl::setLatencyMode(
    LatencyMode latency_mode) {
  bool is_low_latency = latency_mode == LatencyMode::LOW_LATENCY ? true : false;
  invoke_switch_buffer_size_cb(is_low_latency);
  return ndk::ScopedAStatus::ok();
}

+1 −2
Original line number Diff line number Diff line
@@ -232,7 +232,6 @@ void invoke_link_quality_report_cb(
    int retransmission_count, int packets_not_receive_count,
    int negative_acknowledgement_count);

void invoke_switch_buffer_size_cb(RawAddress remote_addr,
                                     bool is_low_latency_buffer_size);
void invoke_switch_buffer_size_cb(bool is_low_latency_buffer_size);

#endif /* BTIF_COMMON_H */
Loading