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.
This commit is contained in:
Thomas Zimmermann 2014-09-05 10:00:40 +02:00
parent 288ce086d5
commit 598620d0a3
3 changed files with 57 additions and 21 deletions

View File

@ -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<BluetoothAvrcpMediaAttribute>(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()

View File

@ -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,

View File

@ -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);