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

Commit 53150399 authored by Rongxuan Liu's avatar Rongxuan Liu Committed by Gerrit Code Review
Browse files

Merge changes from topic "pbp-more-apis"

* changes:
  [le audio] Reuse existing constants for broadcast metadata codec config
  [le audio] Update 2nd LE broadcast APIs change to support Public Broadcast
parents bcf51872 03e9ca4c
Loading
Loading
Loading
Loading
+50 −7
Original line number Diff line number Diff line
@@ -576,6 +576,8 @@ static std::shared_timed_mutex sBroadcasterCallbacksMutex;
  ((vec.data()[3] << 24) + (vec.data()[2] << 16) + (vec.data()[1] << 8) + \
   vec.data()[0])

#define VEC_UINT8_TO_UINT16(vec) (((vec).data()[1] << 8) + ((vec).data()[0]))

size_t RawPacketSize(const std::map<uint8_t, std::vector<uint8_t>>& values) {
  size_t bytes = 0;
  for (auto const& value : values) {
@@ -625,9 +627,48 @@ static jlong getAudioLocationOrDefault(
  return VEC_UINT8_TO_UINT32(vec);
}

static jint getSamplingFrequencyOrDefault(
    const std::map<uint8_t, std::vector<uint8_t>>& metadata,
    jint default_sampling_frequency) {
  if (metadata.count(bluetooth::le_audio::kLeAudioCodecLC3TypeSamplingFreq) ==
      0)
    return default_sampling_frequency;

  auto& vec =
      metadata.at(bluetooth::le_audio::kLeAudioCodecLC3TypeSamplingFreq);
  return (jint)(vec.data()[0]);
}

static jint getFrameDurationOrDefault(
    const std::map<uint8_t, std::vector<uint8_t>>& metadata,
    jint default_frame_duration) {
  if (metadata.count(bluetooth::le_audio::kLeAudioCodecLC3TypeFrameDuration) ==
      0)
    return default_frame_duration;

  auto& vec =
      metadata.at(bluetooth::le_audio::kLeAudioCodecLC3TypeFrameDuration);
  return (jint)(vec.data()[0]);
}

static jint getOctetsPerFrameOrDefault(
    const std::map<uint8_t, std::vector<uint8_t>>& metadata,
    jint default_octets_per_frame) {
  if (metadata.count(bluetooth::le_audio::kLeAudioCodecLC3TypeOctetPerFrame) ==
      0)
    return default_octets_per_frame;

  auto& vec =
      metadata.at(bluetooth::le_audio::kLeAudioCodecLC3TypeOctetPerFrame);
  return VEC_UINT8_TO_UINT16(vec);
}

jobject prepareLeAudioCodecConfigMetadataObject(
    JNIEnv* env, const std::map<uint8_t, std::vector<uint8_t>>& metadata) {
  jlong audio_location = getAudioLocationOrDefault(metadata, -1);
  jint sampling_frequency = getSamplingFrequencyOrDefault(metadata, 0);
  jint frame_duration = getFrameDurationOrDefault(metadata, -1);
  jint octets_per_frame = getOctetsPerFrameOrDefault(metadata, 0);
  ScopedLocalRef<jbyteArray> raw_metadata(env,
                                          prepareRawLtvArray(env, metadata));
  if (!raw_metadata.get()) {
@@ -638,7 +679,8 @@ jobject prepareLeAudioCodecConfigMetadataObject(
  jobject obj = env->NewObject(
      android_bluetooth_BluetoothLeAudioCodecConfigMetadata.clazz,
      android_bluetooth_BluetoothLeAudioCodecConfigMetadata.constructor,
      audio_location, raw_metadata.get());
      audio_location, sampling_frequency, frame_duration, octets_per_frame,
      raw_metadata.get());

  return obj;
}
@@ -875,7 +917,7 @@ jobject prepareBluetoothLeBroadcastMetadataObject(
      false, nullptr,
      broadcast_metadata.broadcast_code ? code.get() : nullptr,
      (jint)broadcast_metadata.basic_audio_announcement.presentation_delay,
      subgroup_list_obj.get());
      (jint)0, nullptr, subgroup_list_obj.get());
}

class LeAudioBroadcasterCallbacksImpl : public LeAudioBroadcasterCallbacks {
@@ -962,7 +1004,7 @@ static void BroadcasterClassInitNative(JNIEnv* env, jclass clazz) {
      env->FindClass("android/bluetooth/BluetoothLeAudioCodecConfigMetadata");
  android_bluetooth_BluetoothLeAudioCodecConfigMetadata.constructor =
      env->GetMethodID(jniBluetoothLeAudioCodecConfigMetadataClass, "<init>",
                       "(J[B)V");
                       "(JIII[B)V");

  jclass jniBluetoothLeAudioContentMetadataClass =
      env->FindClass("android/bluetooth/BluetoothLeAudioContentMetadata");
@@ -991,10 +1033,11 @@ static void BroadcasterClassInitNative(JNIEnv* env, jclass clazz) {

  jclass jniBluetoothLeBroadcastMetadataClass =
      env->FindClass("android/bluetooth/BluetoothLeBroadcastMetadata");
  android_bluetooth_BluetoothLeBroadcastMetadata.constructor =
      env->GetMethodID(jniBluetoothLeBroadcastMetadataClass, "<init>",
                       "(ILandroid/bluetooth/BluetoothDevice;IIIZZLjava/lang/"
                       "String;[BILjava/util/List;)V");
  android_bluetooth_BluetoothLeBroadcastMetadata.constructor = env->GetMethodID(
      jniBluetoothLeBroadcastMetadataClass, "<init>",
      "(ILandroid/bluetooth/BluetoothDevice;IIIZZLjava/lang/String;"
      "[BIILandroid/bluetooth/BluetoothLeAudioContentMetadata;"
      "Ljava/util/List;)V");
}

static void BroadcasterInitNative(JNIEnv* env, jobject object) {
+5 −1
Original line number Diff line number Diff line
@@ -407,6 +407,9 @@ public class LeAudioBinderTest {
        BluetoothLeAudioContentMetadata metadata =
                new BluetoothLeAudioContentMetadata.Builder().build();

        BluetoothLeAudioContentMetadata publicBroadcastMetadata =
                new BluetoothLeAudioContentMetadata.Builder().build();

        BluetoothLeBroadcastSubgroupSettings.Builder subgroupBuilder =
                new BluetoothLeBroadcastSubgroupSettings.Builder()
                .setPreferredQuality(TEST_QUALITY)
@@ -415,7 +418,8 @@ public class LeAudioBinderTest {
        BluetoothLeBroadcastSettings.Builder builder = new BluetoothLeBroadcastSettings.Builder()
                        .setPublicBroadcast(false)
                        .setBroadcastName(TEST_BROADCAST_NAME)
                        .setBroadcastCode(null);
                        .setBroadcastCode(null)
                        .setPublicBroadcastMetadata(publicBroadcastMetadata);
        // builder expect at least one subgroup setting
        builder.addSubgroupSettings(subgroupBuilder.build());
        return builder.build();
+5 −1
Original line number Diff line number Diff line
@@ -461,13 +461,17 @@ public class LeAudioBroadcastServiceTest {
    private BluetoothLeBroadcastSettings buildBroadcastSettingsFromMetadata(
            BluetoothLeAudioContentMetadata contentMetadata,
            @Nullable byte[] broadcastCode) {
        BluetoothLeAudioContentMetadata publicBroadcastMetadata =
                new BluetoothLeAudioContentMetadata.Builder().build();

        BluetoothLeBroadcastSubgroupSettings.Builder subgroupBuilder =
                new BluetoothLeBroadcastSubgroupSettings.Builder()
                .setContentMetadata(contentMetadata);

        BluetoothLeBroadcastSettings.Builder builder = new BluetoothLeBroadcastSettings.Builder()
                        .setPublicBroadcast(false)
                        .setBroadcastCode(broadcastCode);
                        .setBroadcastCode(broadcastCode)
                        .setPublicBroadcastMetadata(publicBroadcastMetadata);
        // builder expect at least one subgroup setting
        builder.addSubgroupSettings(subgroupBuilder.build());
        return builder.build();
+15 −0
Original line number Diff line number Diff line
@@ -456,7 +456,10 @@ package android.bluetooth {
  public final class BluetoothLeAudioCodecConfigMetadata implements android.os.Parcelable {
    method @NonNull public static android.bluetooth.BluetoothLeAudioCodecConfigMetadata fromRawBytes(@NonNull byte[]);
    method public long getAudioLocation();
    method public int getFrameDuration();
    method public int getOctetsPerFrame();
    method @NonNull public byte[] getRawMetadata();
    method public int getSampleRate();
    field @NonNull public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothLeAudioCodecConfigMetadata> CREATOR;
  }

@@ -465,6 +468,9 @@ package android.bluetooth {
    ctor public BluetoothLeAudioCodecConfigMetadata.Builder(@NonNull android.bluetooth.BluetoothLeAudioCodecConfigMetadata);
    method @NonNull public android.bluetooth.BluetoothLeAudioCodecConfigMetadata build();
    method @NonNull public android.bluetooth.BluetoothLeAudioCodecConfigMetadata.Builder setAudioLocation(long);
    method @NonNull public android.bluetooth.BluetoothLeAudioCodecConfigMetadata.Builder setFrameDuration(int);
    method @NonNull public android.bluetooth.BluetoothLeAudioCodecConfigMetadata.Builder setOctetsPerFrame(int);
    method @NonNull public android.bluetooth.BluetoothLeAudioCodecConfigMetadata.Builder setSampleRate(int);
  }

  public final class BluetoothLeAudioContentMetadata implements android.os.Parcelable {
@@ -561,17 +567,22 @@ package android.bluetooth {
  }

  public final class BluetoothLeBroadcastMetadata implements android.os.Parcelable {
    method public int getAudioConfigQuality();
    method @Nullable public byte[] getBroadcastCode();
    method public int getBroadcastId();
    method @Nullable public String getBroadcastName();
    method public int getPaSyncInterval();
    method @IntRange(from=0, to=16777215) public int getPresentationDelayMicros();
    method @Nullable public android.bluetooth.BluetoothLeAudioContentMetadata getPublicBroadcastMetadata();
    method public int getSourceAddressType();
    method public int getSourceAdvertisingSid();
    method @NonNull public android.bluetooth.BluetoothDevice getSourceDevice();
    method @NonNull public java.util.List<android.bluetooth.BluetoothLeBroadcastSubgroup> getSubgroups();
    method public boolean isEncrypted();
    method public boolean isPublicBroadcast();
    field public static final int AUDIO_CONFIG_QUALITY_HIGH = 2; // 0x2
    field public static final int AUDIO_CONFIG_QUALITY_NONE = 0; // 0x0
    field public static final int AUDIO_CONFIG_QUALITY_STANDARD = 1; // 0x1
    field @NonNull public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothLeBroadcastMetadata> CREATOR;
    field public static final int PA_SYNC_INTERVAL_UNKNOWN = 65535; // 0xffff
  }
@@ -582,6 +593,7 @@ package android.bluetooth {
    method @NonNull public android.bluetooth.BluetoothLeBroadcastMetadata.Builder addSubgroup(@NonNull android.bluetooth.BluetoothLeBroadcastSubgroup);
    method @NonNull public android.bluetooth.BluetoothLeBroadcastMetadata build();
    method @NonNull public android.bluetooth.BluetoothLeBroadcastMetadata.Builder clearSubgroup();
    method @NonNull public android.bluetooth.BluetoothLeBroadcastMetadata.Builder setAudioConfigQuality(int);
    method @NonNull public android.bluetooth.BluetoothLeBroadcastMetadata.Builder setBroadcastCode(@Nullable byte[]);
    method @NonNull public android.bluetooth.BluetoothLeBroadcastMetadata.Builder setBroadcastId(int);
    method @NonNull public android.bluetooth.BluetoothLeBroadcastMetadata.Builder setBroadcastName(@Nullable String);
@@ -589,6 +601,7 @@ package android.bluetooth {
    method @NonNull public android.bluetooth.BluetoothLeBroadcastMetadata.Builder setPaSyncInterval(int);
    method @NonNull public android.bluetooth.BluetoothLeBroadcastMetadata.Builder setPresentationDelayMicros(@IntRange(from=0, to=16777215) int);
    method @NonNull public android.bluetooth.BluetoothLeBroadcastMetadata.Builder setPublicBroadcast(boolean);
    method @NonNull public android.bluetooth.BluetoothLeBroadcastMetadata.Builder setPublicBroadcastMetadata(@Nullable android.bluetooth.BluetoothLeAudioContentMetadata);
    method @NonNull public android.bluetooth.BluetoothLeBroadcastMetadata.Builder setSourceAdvertisingSid(int);
    method @NonNull public android.bluetooth.BluetoothLeBroadcastMetadata.Builder setSourceDevice(@NonNull android.bluetooth.BluetoothDevice, int);
  }
@@ -620,6 +633,7 @@ package android.bluetooth {
  public final class BluetoothLeBroadcastSettings implements android.os.Parcelable {
    method @Nullable public byte[] getBroadcastCode();
    method @Nullable public String getBroadcastName();
    method @Nullable public android.bluetooth.BluetoothLeAudioContentMetadata getPublicBroadcastMetadata();
    method @NonNull public java.util.List<android.bluetooth.BluetoothLeBroadcastSubgroupSettings> getSubgroupSettings();
    method public boolean isPublicBroadcast();
    field @NonNull public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothLeBroadcastSettings> CREATOR;
@@ -634,6 +648,7 @@ package android.bluetooth {
    method @NonNull public android.bluetooth.BluetoothLeBroadcastSettings.Builder setBroadcastCode(@Nullable byte[]);
    method @NonNull public android.bluetooth.BluetoothLeBroadcastSettings.Builder setBroadcastName(@Nullable String);
    method @NonNull public android.bluetooth.BluetoothLeBroadcastSettings.Builder setPublicBroadcast(boolean);
    method @NonNull public android.bluetooth.BluetoothLeBroadcastSettings.Builder setPublicBroadcastMetadata(@Nullable android.bluetooth.BluetoothLeAudioContentMetadata);
  }

  public final class BluetoothLeBroadcastSubgroup implements android.os.Parcelable {
+289 −9

File changed.

Preview size limit exceeded, changes collapsed.

Loading