From 598620d0a3120e26df5fdc3b8e44d14c73a202f4 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Fri, 5 Sep 2014 10:00:40 +0200 Subject: [PATCH] Bug 1061124: Use Bluetooth A2DP and AVRCP notifications (under bluetooth2/), r=btian This patch converts Bluetooth's A2DP manager and Bluedroid interface to use notifications instead of callbacks. --- .../bluedroid/BluetoothA2dpManager.cpp | 29 ++++++------ .../bluedroid/BluetoothInterface.cpp | 45 ++++++++++++++++--- dom/bluetooth2/bluedroid/BluetoothInterface.h | 4 +- 3 files changed, 57 insertions(+), 21 deletions(-) diff --git a/dom/bluetooth2/bluedroid/BluetoothA2dpManager.cpp b/dom/bluetooth2/bluedroid/BluetoothA2dpManager.cpp index 8bc0ac8c2cb..5c832632640 100644 --- a/dom/bluetooth2/bluedroid/BluetoothA2dpManager.cpp +++ b/dom/bluetooth2/bluedroid/BluetoothA2dpManager.cpp @@ -111,35 +111,35 @@ private: /* * This function maps attribute id and returns corresponding values - * Attribute id refers to btrc_media_attr_t in bt_rc.h */ static void -ConvertAttributeString(int aAttrId, nsAString& aAttrStr) +ConvertAttributeString(BluetoothAvrcpMediaAttribute aAttrId, + nsAString& aAttrStr) { BluetoothA2dpManager* a2dp = BluetoothA2dpManager::Get(); NS_ENSURE_TRUE_VOID(a2dp); switch (aAttrId) { - case BTRC_MEDIA_ATTR_TITLE: + case AVRCP_MEDIA_ATTRIBUTE_TITLE: a2dp->GetTitle(aAttrStr); break; - case BTRC_MEDIA_ATTR_ARTIST: + case AVRCP_MEDIA_ATTRIBUTE_ARTIST: a2dp->GetArtist(aAttrStr); break; - case BTRC_MEDIA_ATTR_ALBUM: + case AVRCP_MEDIA_ATTRIBUTE_ALBUM: a2dp->GetAlbum(aAttrStr); break; - case BTRC_MEDIA_ATTR_TRACK_NUM: + case AVRCP_MEDIA_ATTRIBUTE_TRACK_NUM: aAttrStr.AppendInt(a2dp->GetMediaNumber()); break; - case BTRC_MEDIA_ATTR_NUM_TRACKS: + case AVRCP_MEDIA_ATTRIBUTE_NUM_TRACKS: aAttrStr.AppendInt(a2dp->GetTotalMediaNumber()); break; - case BTRC_MEDIA_ATTR_GENRE: + case AVRCP_MEDIA_ATTRIBUTE_GENRE: // TODO: we currently don't support genre from music player aAttrStr.Truncate(); break; - case BTRC_MEDIA_ATTR_PLAYING_TIME: + case AVRCP_MEDIA_ATTRIBUTE_PLAYING_TIME: aAttrStr.AppendInt(a2dp->GetDuration()); break; } @@ -178,7 +178,9 @@ public: MOZ_ASSERT(NS_IsMainThread()); for (uint8_t i = 0; i < mNumAttr; ++i) { - ConvertAttributeString(mAttrs[i].mId, mAttrs[i].mValue); + ConvertAttributeString( + static_cast(mAttrs[i].mId), + mAttrs[i].mValue); } NS_ENSURE_TRUE(sBtAvrcpInterface, NS_OK); @@ -614,8 +616,8 @@ public: return; } - sBtAvrcpInterface->Init(&sBtAvrcpCallbacks, - new InitAvrcpResultHandler(mRes)); + BluetoothA2dpManager* a2dpManager = BluetoothA2dpManager::Get(); + sBtAvrcpInterface->Init(a2dpManager, new InitAvrcpResultHandler(mRes)); #else /* ...or signal success otherwise. */ if (mRes) { @@ -656,7 +658,8 @@ BluetoothA2dpManager::InitA2dpInterface(BluetoothProfileResultHandler* aRes) return; } - sBtA2dpInterface->Init(&sBtA2dpCallbacks, new InitA2dpResultHandler(aRes)); + BluetoothA2dpManager* a2dpManager = BluetoothA2dpManager::Get(); + sBtA2dpInterface->Init(a2dpManager, new InitA2dpResultHandler(aRes)); } BluetoothA2dpManager::~BluetoothA2dpManager() diff --git a/dom/bluetooth2/bluedroid/BluetoothInterface.cpp b/dom/bluetooth2/bluedroid/BluetoothInterface.cpp index 9b4a1cf3d89..cd19ff66c72 100644 --- a/dom/bluetooth2/bluedroid/BluetoothInterface.cpp +++ b/dom/bluetooth2/bluedroid/BluetoothInterface.cpp @@ -2902,10 +2902,19 @@ BluetoothA2dpInterface::~BluetoothA2dpInterface() { } void -BluetoothA2dpInterface::Init(btav_callbacks_t* aCallbacks, - BluetoothA2dpResultHandler* aRes) +BluetoothA2dpInterface::Init( + BluetoothA2dpNotificationHandler* aNotificationHandler, + BluetoothA2dpResultHandler* aRes) { - bt_status_t status = mInterface->init(aCallbacks); + static btav_callbacks_t sCallbacks = { + sizeof(sCallbacks), + BluetoothA2dpCallback::ConnectionState, + BluetoothA2dpCallback::AudioState + }; + + sA2dpNotificationHandler = aNotificationHandler; + + bt_status_t status = mInterface->init(&sCallbacks); if (aRes) { DispatchBluetoothA2dpResult(aRes, &BluetoothA2dpResultHandler::Init, @@ -3214,10 +3223,34 @@ BluetoothAvrcpInterface::~BluetoothAvrcpInterface() { } void -BluetoothAvrcpInterface::Init(btrc_callbacks_t* aCallbacks, - BluetoothAvrcpResultHandler* aRes) +BluetoothAvrcpInterface::Init( + BluetoothAvrcpNotificationHandler* aNotificationHandler, + BluetoothAvrcpResultHandler* aRes) { - bt_status_t status = mInterface->init(aCallbacks); + static btrc_callbacks_t sCallbacks = { + sizeof(sCallbacks), +#if ANDROID_VERSION >= 19 + BluetoothAvrcpCallback::RemoteFeature, +#endif + BluetoothAvrcpCallback::GetPlayStatus, + BluetoothAvrcpCallback::ListPlayerAppAttr, + BluetoothAvrcpCallback::ListPlayerAppValues, + BluetoothAvrcpCallback::GetPlayerAppValue, + BluetoothAvrcpCallback::GetPlayerAppAttrsText, + BluetoothAvrcpCallback::GetPlayerAppValuesText, + BluetoothAvrcpCallback::SetPlayerAppValue, + BluetoothAvrcpCallback::GetElementAttr, + BluetoothAvrcpCallback::RegisterNotification +#if ANDROID_VERSION >= 19 + , + BluetoothAvrcpCallback::VolumeChange, + BluetoothAvrcpCallback::PassthroughCmd +#endif + }; + + sAvrcpNotificationHandler = aNotificationHandler; + + bt_status_t status = mInterface->init(&sCallbacks); if (aRes) { DispatchBluetoothAvrcpResult(aRes, &BluetoothAvrcpResultHandler::Init, diff --git a/dom/bluetooth2/bluedroid/BluetoothInterface.h b/dom/bluetooth2/bluedroid/BluetoothInterface.h index 794adfc6761..83ff5158da2 100644 --- a/dom/bluetooth2/bluedroid/BluetoothInterface.h +++ b/dom/bluetooth2/bluedroid/BluetoothInterface.h @@ -308,7 +308,7 @@ class BluetoothA2dpInterface public: friend class BluetoothInterface; - void Init(btav_callbacks_t *aCallbacks, + void Init(BluetoothA2dpNotificationHandler* aNotificationHandler, BluetoothA2dpResultHandler* aRes); void Cleanup(BluetoothA2dpResultHandler* aRes); @@ -431,7 +431,7 @@ class BluetoothAvrcpInterface public: friend class BluetoothInterface; - void Init(btrc_callbacks_t* aCallbacks, + void Init(BluetoothAvrcpNotificationHandler* aNotificationHandler, BluetoothAvrcpResultHandler* aRes); void Cleanup(BluetoothAvrcpResultHandler* aRes);