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

Commit 742dc966 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski Committed by Grzegorz Kołodziejczyk
Browse files

leaudio: Rework selecting Broadcast Audio stream parameters

This change adds support for broadcast audio stream
parameter slection through the stream context type
in the metadata stream parameter. The passed context
is being mapped to a specific set of lc3 codec
paremeters and QOS settings.

Proper QOS settings were the missing piece for a while
now in the broadcast audio source implementation, and
this change fixes these outstanding todos. This change
is also needed to pass some of qualification tests for
BAP Broadcast Source.

Bug: 230340466
Tag: #feature
Sponsor: jpawlowski@
Test: atest LeAudioBroadcastServiceTest bluetooth_test_broadcaster_sm bluetooth_test_broadcaster
Change-Id: I5f6c2ceca4120f65bdfd51fcde6c9c3802bf02e9
Merged-In: I5f6c2ceca4120f65bdfd51fcde6c9c3802bf02e9
(cherry picked from commit af290f42)
parent 65a0542a
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@
#include "com_android_bluetooth.h"
#include "hardware/bt_le_audio.h"

using bluetooth::le_audio::BroadcastAudioProfile;
using bluetooth::le_audio::BroadcastId;
using bluetooth::le_audio::BroadcastState;
using bluetooth::le_audio::btle_audio_codec_config_t;
@@ -1125,7 +1124,7 @@ static void BroadcasterCleanupNative(JNIEnv* env, jobject object) {
}

static void CreateBroadcastNative(JNIEnv* env, jobject object,
                                  jbyteArray metadata, jint audio_profile,
                                  jbyteArray metadata,
                                  jbyteArray broadcast_code) {
  LOG(INFO) << __func__;
  std::shared_lock<std::shared_timed_mutex> lock(sBroadcasterInterfaceMutex);
@@ -1138,7 +1137,6 @@ static void CreateBroadcastNative(JNIEnv* env, jobject object,
  jbyte* meta = env->GetByteArrayElements(metadata, nullptr);
  sLeAudioBroadcasterInterface->CreateBroadcast(
      std::vector<uint8_t>(meta, meta + env->GetArrayLength(metadata)),
      static_cast<BroadcastAudioProfile>(audio_profile),
      broadcast_code ? std::optional<std::array<uint8_t, 16>>(code_array)
                     : std::nullopt);
  env->ReleaseByteArrayElements(metadata, meta, 0);
@@ -1198,7 +1196,7 @@ static JNINativeMethod sBroadcasterMethods[] = {
    {"initNative", "()V", (void*)BroadcasterInitNative},
    {"stopNative", "()V", (void*)BroadcasterStopNative},
    {"cleanupNative", "()V", (void*)BroadcasterCleanupNative},
    {"createBroadcastNative", "([BI[B)V", (void*)CreateBroadcastNative},
    {"createBroadcastNative", "([B[B)V", (void*)CreateBroadcastNative},
    {"updateMetadataNative", "(I[B)V", (void*)UpdateMetadataNative},
    {"startBroadcastNative", "(I)V", (void*)StartBroadcastNative},
    {"stopBroadcastNative", "(I)V", (void*)StopBroadcastNative},
+3 −4
Original line number Diff line number Diff line
@@ -169,12 +169,11 @@ public class LeAudioBroadcasterNativeInterface {
     * Creates LeAudio Broadcast instance.
     *
     * @param metadata metadata buffer with TLVs
     * @param audioProfile broadcast audio profile
     * @param broadcastCode optional code if broadcast should be encrypted
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    public void createBroadcast(byte[] metadata, int audioProfile, byte[] broadcastCode) {
        createBroadcastNative(metadata, audioProfile, broadcastCode);
    public void createBroadcast(byte[] metadata, byte[] broadcastCode) {
        createBroadcastNative(metadata, broadcastCode);
    }

    /**
@@ -241,7 +240,7 @@ public class LeAudioBroadcasterNativeInterface {
    private native void initNative();
    private native void stopNative();
    private native void cleanupNative();
    private native void createBroadcastNative(byte[] metadata, int profile, byte[] broadcastCode);
    private native void createBroadcastNative(byte[] metadata, byte[] broadcastCode);
    private native void updateMetadataNative(int broadcastId, byte[] metadata);
    private native void startBroadcastNative(int broadcastId);
    private native void stopBroadcastNative(int broadcastId);
+1 −9
Original line number Diff line number Diff line
@@ -105,12 +105,6 @@ public class LeAudioService extends ProfileService {
     */
    private static final int ACTIVE_CONTEXTS_NONE = 0;

    /*
     * Brodcast profile used by the lower layers
     */
    private static final int BROADCAST_PROFILE_SONIFICATION = 0;
    private static final int BROADCAST_PROFILE_MEDIA = 1;

    private AdapterService mAdapterService;
    private DatabaseManager mDatabaseManager;
    private HandlerThread mStateMachinesThread;
@@ -662,8 +656,6 @@ public class LeAudioService extends ProfileService {
    /**
     * Creates LeAudio Broadcast instance.
     * @param metadata metadata buffer with TLVs
     * @param audioProfile broadcast audio profile
     * @param broadcastCode optional code if broadcast should be encrypted
     */
    public void createBroadcast(BluetoothLeAudioContentMetadata metadata, byte[] broadcastCode) {
        if (mLeAudioBroadcasterNativeInterface == null) {
@@ -671,7 +663,7 @@ public class LeAudioService extends ProfileService {
            return;
        }
        mLeAudioBroadcasterNativeInterface.createBroadcast(metadata.getRawMetadata(),
                BROADCAST_PROFILE_MEDIA, broadcastCode);
                broadcastCode);
    }

    /**
+2 −3
Original line number Diff line number Diff line
@@ -239,7 +239,7 @@ public class LeAudioBroadcastServiceTest {
            BluetoothLeAudioContentMetadata meta) {
        mService.createBroadcast(meta, code);

        verify(mNativeInterface, times(1)).createBroadcast(eq(meta.getRawMetadata()), eq(1),
        verify(mNativeInterface, times(1)).createBroadcast(eq(meta.getRawMetadata()),
                eq(code));

        // Check if broadcast is started automatically when created
@@ -321,8 +321,7 @@ public class LeAudioBroadcastServiceTest {
        BluetoothLeAudioContentMetadata meta = meta_builder.build();
        mService.createBroadcast(meta, code);

        verify(mNativeInterface, times(1)).createBroadcast(eq(meta.getRawMetadata()), eq(1),
                eq(code));
        verify(mNativeInterface, times(1)).createBroadcast(eq(meta.getRawMetadata()), eq(code));

        LeAudioStackEvent create_event =
                new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_BROADCAST_CREATED);
+4 −4
Original line number Diff line number Diff line
@@ -1222,7 +1222,7 @@ public class BluetoothProxy {

            switchToPreviousPresetMethod.invoke(bluetoothHapClient, device);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            // Do nothing
            return false;
        }
        return true;
    }
@@ -1239,7 +1239,7 @@ public class BluetoothProxy {

            switchToNextPresetMethod.invoke(bluetoothHapClient, device);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            // Do nothing
            return false;
        }
        return true;
    }
@@ -1256,7 +1256,7 @@ public class BluetoothProxy {

            switchToPreviousPresetForGroupMethod.invoke(bluetoothHapClient, group_id);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            // Do nothing
            return false;
        }
        return true;
    }
@@ -1273,7 +1273,7 @@ public class BluetoothProxy {

            switchToNextPresetForGroupMethod.invoke(bluetoothHapClient, group_id);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            // Do nothing
            return false;
        }
        return true;
    }
Loading