Closed Bug 935578 Opened 13 years ago Closed 12 years ago

[bluedroid][A2dp] BluetoothA2dpManager prototype

Categories

(Firefox OS Graveyard :: Bluetooth, defect)

ARM
Gonk (Firefox OS)
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
1.3 Sprint 5 - 11/22

People

(Reporter: shawnjohnjr, Assigned: shawnjohnjr)

References

Details

Attachments

(3 files, 11 obsolete files)

45.60 KB, patch
Details | Diff | Splinter Review
1.43 KB, patch
Details | Diff | Splinter Review
12.25 KB, patch
Details | Diff | Splinter Review
No description provided.
I'm stuck when doing a2dp init with registering callbacks. After digging into bluedroid, I found that problem is related to a2dp media task started while bluetooth turned on. * When turning on bluetooth 11-12 00:41:00.706 I/bt-btif ( 178): ## A2DP START MEDIA TASK ## 11-12 00:41:00.706 I/bt-btif ( 178): HC lpm_result_cb 1 11-12 00:41:00.706 I/GKI_LINUX( 178): gki_task_entry: gki_task_entry task_id=2 [A2DP-MEDIA] starting 11-12 00:41:00.706 I/bt-btif ( 178): ## A2DP MEDIA TASK STARTED ## It looks like btif_av_init needs to be called before media task started. Otherwise, btif_a2dp_start_media_task() return GKI_FAILURE when doing btif_av_init.
OS: Mac OS X → Gonk (Firefox OS)
Hardware: x86 → ARM
It looks like we need to get a2dp interface and register callback before AdapterStateChangeCallback with state changing to "Turn On". Otherwise, bluedroid will reject register callback due to a2dp media task has already started.
After moving registration of callbacks to the place before we call sBtInterface->enable(), it seems that A2DP now is working. So this is correct things to do.
Summary: [bluedroid] BluetoothA2dpManager prototype → [bluedroid][A2dp] BluetoothA2dpManager prototype
Note: BluetoothA2dpManager.cpp under bluedroid folder is bluez version, Patch 2 will have bluedroid diff. Patch 1 make build pass, Patch 2 shows the diff for bluedroid version.
Attachment #832777 - Flags: review?(echou)
This just for test a2dp if BluetoothHfpManager not yet finished.
This patch set is based on Bug 938529 - [bluedroid] Set BT_SCAN_MODE to Connectable after Bluetooth turned on Bug 938521 - [Bluetooth] Make GetBluetoothInterface() and StringToBdAddressType() available for profile managers Bug 936732 - [Bluetooth] Refactor dom/bluetooth for both BlueZ and Bluedroid compatibility
(In reply to Shawn Huang [:shuang] [:shawnjohnjr] from comment #6) > Created attachment 832779 [details] [diff] [review] > Bug 935578 - Patch 2: BluetoothA2dpManager bluedroid version The reason NOT put A2dp connect into BluetoothServiceBluedroid.cpp is to reduce size of BluetoothServiceBluedroid. Let BluetoothServiceBluedroid become GAP adaptation only. Although this leaves a lot of empty implementation.
Comment on attachment 832777 [details] [diff] [review] Bug 935578 - Patch 1: Separate BluetoothA2dpManager implementation for bluez/bluedroid stack Review of attachment 832777 [details] [diff] [review]: ----------------------------------------------------------------- r=me since it's just relocation.
Attachment #832777 - Flags: review?(echou) → review+
See also Bug 937434, we need Bug 937434 to verify a2dp function. Without patch Bug 937434, we can not hear anything from a2dp.
Comment on attachment 832779 [details] [diff] [review] Bug 935578 - Patch 2: BluetoothA2dpManager bluedroid version Review of attachment 832779 [details] [diff] [review]: ----------------------------------------------------------------- Hi Shawn, please see my comments below. Thanks. ::: dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp @@ +25,5 @@ > > using namespace mozilla; > USING_BLUETOOTH_NAMESPACE > > +static const btav_interface_t* sBtA2dpInterface; Please declare this inside the anonymous namespace below. @@ +31,5 @@ > StaticRefPtr<BluetoothA2dpManager> sBluetoothA2dpManager; > bool sInShutdown = false; > } // anonymous namespace > > +const bt_interface_t* sBtInterface; Ditto, also please make it static. @@ +67,5 @@ > + aState = NS_LITERAL_STRING("connecting"); > + } else if (aStatus == BTAV_CONNECTION_STATE_CONNECTED) { > + aState = NS_LITERAL_STRING("connected"); > + } else { > + BT_WARNING("Unknown sink state"); There is still a state BTAV_CONNECTION_STATE_DISCONNECTING which we should deal with, otherwise the warning would be printed once BTAV_CONNECTION_STATE_DISCONNECTING was fired. In addition, please move this function to the "Static functions" section below. @@ +141,5 @@ > + * Static functions > + */ > +static void > +A2dpConnectionStateCallback(btav_connection_state_t aState, > + bt_bdaddr_t* aBdAddress) nit: please line up. @@ +158,5 @@ > + BluetoothValue value = props; > + > + BluetoothSignal signal(NS_LITERAL_STRING("AudioSink"), remoteDeviceBdAddress, value); > + NS_DispatchToMainThread(new SinkPropertyChangedHandler(signal)); > + nit: extra line. @@ +163,5 @@ > +} > + > +static void > +A2dpAudioStateCallback(btav_audio_state_t aState, > + bt_bdaddr_t* aBdAddress) nit: please line up. @@ +174,5 @@ > + nsString a2dpState; > + // only handle start streaming state > + if (aState == BTAV_AUDIO_STATE_STARTED) { > + a2dpState = NS_LITERAL_STRING("playing"); > + } Shouldn't we handle BTAV_AUDIO_STATE_REMOTE_SUSPEND and BTAV_AUDIO_STATE_STOPPED? From the name of these two states, I think we have to notify A2dpManager as well as BTAV_AUDIO_STATE_STARTED. On the other hand, what will happen once the other states comes? The "AudioSink" event will still be fired with an empty "State" (because a2dpState won't be assgined to any string). Make sense? @@ +207,5 @@ > + > + sBtInterface = aBtInterface; > + if (sBtInterface) { > + if (sBtA2dpInterface != nullptr) { > + return true; We can re-write this part to something like NS_ENSURE_TRUE(!sBtA2dpInterface || !sBtInterface, true); @@ +301,5 @@ > > + bt_bdaddr_t remoteAddress; > + StringToBdAddressType(aDeviceAddress, &remoteAddress); > + if (sBtA2dpInterface) { > + sBtA2dpInterface->connect(&remoteAddress); This may fail. Please check the return value and do error handling (e.g., call aController->OnConnect() just like what we do now). @@ +331,5 @@ > > + bt_bdaddr_t remoteAddress; > + StringToBdAddressType(mDeviceAddress, &remoteAddress); > + if (sBtA2dpInterface) { > + sBtA2dpInterface->disconnect(&remoteAddress); Ditto. ::: dom/bluetooth/bluedroid/BluetoothA2dpManager.h @@ +9,5 @@ > > #include "BluetoothCommon.h" > #include "BluetoothProfileController.h" > #include "BluetoothProfileManagerBase.h" > +#include "BluetoothServiceBluedroid.h" #include <hardware/bluetooth.h> should be enough. ::: dom/bluetooth/bluedroid/gonk/BluetoothServiceBluedroid.cpp @@ +650,5 @@ > return NS_ERROR_FAILURE; > } > sIsBtInterfaceInitialized = true; > } > + BluetoothA2dpManager::RegisterA2dpCallbacks(sBtInterface); ok, so it seems like that we should register callbacks before bluetooth is enabled from this modification. If so, then the patch of bug 938524 has to be revised. Will figure out which one is more reasonable.
Attachment #832779 - Flags: review?(echou) → review-
> > + BluetoothA2dpManager::RegisterA2dpCallbacks(sBtInterface); > ok, so it seems like that we should register callbacks before bluetooth is > enabled from this modification. If so, then the patch of bug 938524 has to > be revised. Will figure out which one is more reasonable. I can change to init callbacks in static gettter BluetoothA2dpManager::Get(). such as BluetoothHfpManager as Bug 938524. But we need to remove assertion in Get(), Init(), InitA2dpInterface. They might handle in both main thread and non-main thread.
Find something interesting here, it looks like "AddObserver" with NS_XPCOM_SHUTDOWN_OBSERVER_ID, always fail in non-mainthread. I even don't understand adding shutdown observer is necessary here. Anyway, this is why we can see BluetoothA2dpManager::Init(). if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) { BT_WARNING("Failed to add shutdown observer!"); return false; }
Comment on attachment 8334319 [details] [diff] [review] Bug 935578 - Patch 2: BluetoothA2dpManager bluedroid version Review of attachment 8334319 [details] [diff] [review]: ----------------------------------------------------------------- Hi Shawn, please see my comments below. ::: dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp @@ +80,5 @@ > > bool > BluetoothA2dpManager::Init() > { > + NS_ENSURE_TRUE(InitA2dpInterface(), false); Please see my comments at the signature of InitA2dpInterface(). @@ +197,5 @@ > + * It is required to register a2dp callbacks before a2dp media task > + * starts up. > + */ > +bool > +BluetoothA2dpManager::InitA2dpInterface() InitA2dpInterface() is only called once in Init(). We should merge these two. Init() seems to be better to me. @@ +201,5 @@ > +BluetoothA2dpManager::InitA2dpInterface() > +{ > + const bt_interface_t* btInf = GetBluetoothInterface(); > + NS_ENSURE_TRUE(btInf, false); > + if (btInf) { This is redundant. btInf must have value to be here. @@ +204,5 @@ > + NS_ENSURE_TRUE(btInf, false); > + if (btInf) { > + if ((sBtA2dpInterface = (btav_interface_t *) > + btInf->get_profile_interface( > + BT_PROFILE_ADVANCED_AUDIO_ID)) == nullptr) { This statement is too hard to read. Please re-write this to something like sBtA2dpInterface = (btav_interface_t *)btInf-> get_profile_interface(BT_PROFILE_ADVANCED_AUDIO_ID); NS_ENSURE_TRUE(sBtA2dpInterface, false); @@ +240,5 @@ > > //static > BluetoothA2dpManager* > BluetoothA2dpManager::Get() > { We should keep this assertion since BluetoothA2dpManager object is not thread-safe. @@ +290,5 @@ > mController = aController; > > + bt_bdaddr_t remoteAddress; > + StringToBdAddressType(aDeviceAddress, &remoteAddress); > + if (sBtA2dpInterface) { Please use NS_ENSURE_TRUE_VOID(sBtA2dpInterface) to print out logs when sBtA2dpInterface has no value. @@ +320,5 @@ > mController = aController; > > + bt_bdaddr_t remoteAddress; > + StringToBdAddressType(mDeviceAddress, &remoteAddress); > + if (sBtA2dpInterface) { Ditto. ::: dom/bluetooth/bluedroid/BluetoothA2dpManager.h @@ +9,5 @@ > > #include "BluetoothCommon.h" > #include "BluetoothProfileController.h" > #include "BluetoothProfileManagerBase.h" > +#include "BluetoothServiceBluedroid.h" It's not necessary. ::: dom/bluetooth/bluedroid/gonk/BluetoothServiceBluedroid.cpp @@ +20,5 @@ > > #include <hardware/hardware.h> > > +#include "bluedroid/BluetoothHfpManager.h" > +#include "bluedroid/BluetoothA2dpManager.h" super-nit: alphabetical order, please. @@ +650,5 @@ > return NS_ERROR_FAILURE; > } > sIsBtInterfaceInitialized = true; > } > + BluetoothA2dpManager::Get(); We should keep Bluetooth*Manager::Get() only able to be called on main thread. Maybe dispatching a runnable which is in charge of callback registration to main thread would be a choice.
Attachment #8334319 - Flags: review?(echou) → review-
Comment on attachment 8334432 [details] [diff] [review] Bug 935578 - Patch 2: BluetoothA2dpManager bluedroid version Review of attachment 8334432 [details] [diff] [review]: ----------------------------------------------------------------- Almost there. :) ::: dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp @@ +130,5 @@ > + > + if (aState == BTAV_AUDIO_STATE_STARTED) { > + a2dpState = NS_LITERAL_STRING("playing"); > + } else if (aState == BTAV_AUDIO_STATE_STOPPED) { > + a2dpState = NS_LITERAL_STRING("stopped"); This is not what I meant in previous comment. In BluetoothA2dpManager::StatusStringToSinkState(), only "disconnected", "connecting", "connected" and "playing" would be handled. So we should think about "what should I send to SinkPropertyChangedHandler if BTAV_AUDIO_STATE_STOPPED/BTAV_AUDIO_STATE_REMOTE_SUSPEND comes". @@ +161,5 @@ > bool > BluetoothA2dpManager::Init() > { > + const bt_interface_t* btInf = GetBluetoothInterface(); > + if (btInf) { nit: NS_ENSURE_TRUE(btInf, true). However I suggest that maybe we should return false if btInf has no value. @@ +282,5 @@ > mController = aController; > > + bt_bdaddr_t remoteAddress; > + StringToBdAddressType(aDeviceAddress, &remoteAddress); > + if (sBtA2dpInterface) { nit: NS_ENSURE_TRUE_VOID(sBtA2dpInterface) @@ +314,5 @@ > mController = aController; > > + bt_bdaddr_t remoteAddress; > + StringToBdAddressType(mDeviceAddress, &remoteAddress); > + if (sBtA2dpInterface) { nit: NS_ENSURE_TRUE_VOID(sBtA2dpInterface) @@ +317,5 @@ > + StringToBdAddressType(mDeviceAddress, &remoteAddress); > + if (sBtA2dpInterface) { > + NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS == > + sBtA2dpInterface->disconnect(&remoteAddress)); > + nit: extra line. ::: dom/bluetooth/bluedroid/gonk/BluetoothServiceBluedroid.cpp @@ +644,2 @@ > sIsBtInterfaceInitialized = true; > } Please refine this function since variables like sIsBtInterfaceInitialized may be able to removed. In addition, please ensure sBtInterface is valid before using it. @@ +683,5 @@ > + > +BluetoothServiceBluedroid::BluetoothServiceBluedroid() > +{ > + if (!EnsureBluetoothHalLoad()) { > + BT_LOGR("Failed to load bluedroid library.\n"); I think we should return early here because it's useless to call Bluetooth*Manager::Get() without valid sBtInterface. @@ +686,5 @@ > + if (!EnsureBluetoothHalLoad()) { > + BT_LOGR("Failed to load bluedroid library.\n"); > + } > + > + BluetoothHfpManager::Get(); Please add comments here to explain why we have to do this.
Attachment #8334432 - Flags: review?(echou) → review-
(In reply to Eric Chou [:ericchou] [:echou] from comment #20) > Comment on attachment 8334432 [details] [diff] [review] > Bug 935578 - Patch 2: BluetoothA2dpManager bluedroid version > > Review of attachment 8334432 [details] [diff] [review]: > ----------------------------------------------------------------- > > > "disconnected", "connecting", "connected" and "playing" > > would be handled. So we should think about "what should I send to > SinkPropertyChangedHandler if > BTAV_AUDIO_STATE_STOPPED/BTAV_AUDIO_STATE_REMOTE_SUSPEND comes". > We currently don't handle AVDTP Stop stream and AVDTP Suspend stream from remote. I don't see requirement unless we want to handle special some cases for remote a2dp headset different behaviors.
Attachment #8334461 - Attachment is obsolete: true
Attachment #8334461 - Flags: review?(echou)
Comment on attachment 8334592 [details] [diff] [review] Bug 935578 - Patch 2: BluetoothA2dpManager bluedroid version Review of attachment 8334592 [details] [diff] [review]: ----------------------------------------------------------------- r=me with nits addressed. Thanks. :) ::: dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp @@ +284,5 @@ > + bt_bdaddr_t remoteAddress; > + StringToBdAddressType(aDeviceAddress, &remoteAddress); > + NS_ENSURE_TRUE_VOID(sBtA2dpInterface); > + NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS == > + sBtA2dpInterface->connect(&remoteAddress)); nit: please line up. @@ +314,5 @@ > + bt_bdaddr_t remoteAddress; > + StringToBdAddressType(mDeviceAddress, &remoteAddress); > + if (sBtA2dpInterface) { > + NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS == > + sBtA2dpInterface->disconnect(&remoteAddress)); nit: please line up. @@ +315,5 @@ > + StringToBdAddressType(mDeviceAddress, &remoteAddress); > + if (sBtA2dpInterface) { > + NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS == > + sBtA2dpInterface->disconnect(&remoteAddress)); > + nit: please remove extra line.
Attachment #8334592 - Flags: review?(echou) → review+
Attachment #8335054 - Attachment description: Bug 935578 - Patch 2: BluetoothA2dpManager bluedroid version, r=echouBug935578-a2dp-patch2.patch → Bug 935578 - Patch 2: BluetoothA2dpManager bluedroid version, r=echou
Attachment #832781 - Flags: review?(echou) → review+
Attachment #832777 - Attachment is obsolete: true
Attached patch patch 2: final, r=echou (obsolete) — — Splinter Review
Attachment #8335054 - Attachment is obsolete: true
Attachment #832781 - Attachment is obsolete: true
Attachment #8335152 - Attachment is obsolete: true
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → 1.3 Sprint 5 - 11/22
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: