Bug 946240 - [Bluetooth][gonk-kk] Add flags to support different AVRCP profile version. r=echou
authorShawn Huang <shuang@mozilla.com>
Wed, 08 Jan 2014 09:32:19 -0500
changeset 162536 065cf8a7264576f28c0d949bc6e58ebb251f50b4
parent 162535 e435bb71e27a17c8c1a0ed3b424df8690516848b
child 162537 7d434e24be3b990be881554e992710e1ceead673
push id25958
push userryanvm@gmail.com
push dateWed, 08 Jan 2014 20:22:21 +0000
treeherdermozilla-central@8988416e489d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechou
bugs946240
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 946240 - [Bluetooth][gonk-kk] Add flags to support different AVRCP profile version. r=echou
dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp
--- a/dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp
@@ -5,17 +5,19 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "base/basictypes.h"
 
 #include "BluetoothA2dpManager.h"
 
 #include <hardware/bluetooth.h>
 #include <hardware/bt_av.h>
+#if ANDROID_VERSION > 17
 #include <hardware/bt_rc.h>
+#endif
 
 #include "BluetoothCommon.h"
 #include "BluetoothService.h"
 #include "BluetoothSocket.h"
 #include "BluetoothUtils.h"
 
 #include "mozilla/dom/bluetooth/BluetoothTypes.h"
 #include "mozilla/Services.h"
@@ -26,17 +28,19 @@
 
 using namespace mozilla;
 USING_BLUETOOTH_NAMESPACE
 
 namespace {
   StaticRefPtr<BluetoothA2dpManager> sBluetoothA2dpManager;
   bool sInShutdown = false;
   static const btav_interface_t* sBtA2dpInterface;
+#if ANDROID_VERSION > 17
   static const btrc_interface_t* sBtAvrcpInterface;
+#endif
 } // anonymous namespace
 
 class SinkPropertyChangedHandler : public nsRunnable
 {
 public:
   SinkPropertyChangedHandler(const BluetoothSignal& aSignal)
     : mSignal(aSignal)
   {
@@ -77,16 +81,17 @@ public:
     BluetoothService* bs = BluetoothService::Get();
     NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
     bs->DistributeSignal(signal);
 
     return NS_OK;
   }
 };
 
+#if ANDROID_VERSION > 17
 class UpdateRegisterNotificationTask : public nsRunnable
 {
 public:
   UpdateRegisterNotificationTask(btrc_event_id_t aEventId, uint32_t aParam)
     : mEventId(aEventId)
     , mParam(aParam)
   {
     MOZ_ASSERT(!NS_IsMainThread());
@@ -168,16 +173,17 @@ public:
     sBtAvrcpInterface->get_element_attr_rsp(mNumAttr, attrs);
 
     return NS_OK;
   }
 private:
   uint8_t mNumAttr;
   btrc_media_attr_t* mPlayerAttrs;
 };
+#endif
 
 NS_IMETHODIMP
 BluetoothA2dpManager::Observe(nsISupports* aSubject,
                               const char* aTopic,
                               const char16_t* aData)
 {
   MOZ_ASSERT(sBluetoothA2dpManager);
 
@@ -259,16 +265,17 @@ A2dpAudioStateCallback(btav_audio_state_
   props.AppendElement(
     BluetoothNamedValue(NS_LITERAL_STRING("State"), a2dpState));
 
   BluetoothSignal signal(NS_LITERAL_STRING("AudioSink"),
                          remoteDeviceBdAddress, props);
   NS_DispatchToMainThread(new SinkPropertyChangedHandler(signal));
 }
 
+#if ANDROID_VERSION > 17
 /*
  * Avrcp 1.3 callbacks
  */
 
 /*
  * This function is to request Gaia player application to update
  * current play status.
  * Callback for play status request
@@ -364,35 +371,80 @@ AvrcpGetPlayerAppValuesTextCallback(uint
 
 static void
 AvrcpSetPlayerAppValueCallback(btrc_player_settings_t* aPlayerVals)
 {
   MOZ_ASSERT(!NS_IsMainThread());
 
 // TODO: Support avrcp application setting related functions
 }
+#endif
+
+#if ANDROID_VERSION > 18
+/*
+ * This callback function is to get CT features from Feature Bit Mask.
+ * If Advanced Control Player bit is set, CT supports
+ * volume sync (absolute volume feature). If Browsing bit is set, Avrcp 1.4
+ * Browse feature will be supported
+ */
+static void
+AvrcpRemoteFeaturesCallback(bt_bdaddr_t* aBdAddress,
+                            btrc_remote_features_t aFeatures)
+{
+// TODO: Support avrcp 1.4 absolute volume/browse
+}
+
+/*
+ * This callback function is to get notification that volume changed on the
+ * remote car kit (if it supports Avrcp 1.4), not notification from phone.
+ */
+static void
+AvrcpRemoteVolumeChangedCallback(uint8_t aVolume, uint8_t aCType)
+{
+// TODO: Support avrcp 1.4 absolute volume/browse
+}
+
+/*
+ * This callback function is to get notification that volume changed on the
+ * remote car kit (if it supports Avrcp 1.4), not notification from phone.
+ */
+static void
+AvrcpPassThroughCallback(int id, int key_state)
+{
+// TODO: Support avrcp 1.4 absolute volume/browse
+}
+#endif
 
 static btav_callbacks_t sBtA2dpCallbacks = {
   sizeof(sBtA2dpCallbacks),
   A2dpConnectionStateCallback,
   A2dpAudioStateCallback
 };
 
+#if ANDROID_VERSION > 17
 static btrc_callbacks_t sBtAvrcpCallbacks = {
   sizeof(sBtAvrcpCallbacks),
+#if ANDROID_VERSION > 18
+  AvrcpRemoteFeaturesCallback,
+#endif
   AvrcpGetPlayStatusCallback,
   AvrcpListPlayerAppAttributeCallback,
   AvrcpListPlayerAppValuesCallback,
   AvrcpGetPlayerAppValueCallback,
   AvrcpGetPlayerAppAttrsTextCallback,
   AvrcpGetPlayerAppValuesTextCallback,
   AvrcpSetPlayerAppValueCallback,
   AvrcpGetElementAttrCallback,
-  AvrcpRegisterNotificationCallback
+  AvrcpRegisterNotificationCallback,
+#if ANDROID_VERSION > 18
+  AvrcpRemoteVolumeChangedCallback,
+  AvrcpPassThroughCallback
+#endif
 };
+#endif
 
 /*
  * This function will be only called when Bluetooth is turning on.
  * It is important to register a2dp callbacks before enable() gets called.
  * It is required to register a2dp callbacks before a2dp media task
  * starts up.
  */
 bool
@@ -406,25 +458,27 @@ BluetoothA2dpManager::Init()
   NS_ENSURE_TRUE(sBtA2dpInterface, false);
 
   int ret = sBtA2dpInterface->init(&sBtA2dpCallbacks);
   if (ret != BT_STATUS_SUCCESS) {
     BT_LOGR("Warning: failed to init a2dp module");
     return false;
   }
 
+#if ANDROID_VERSION > 17
   sBtAvrcpInterface = (btrc_interface_t *)btInf->
     get_profile_interface(BT_PROFILE_AV_RC_ID);
   NS_ENSURE_TRUE(sBtAvrcpInterface, false);
 
   ret = sBtAvrcpInterface->init(&sBtAvrcpCallbacks);
   if (ret != BT_STATUS_SUCCESS) {
     BT_LOGR("Warning: failed to init avrcp module");
     return false;
   }
+#endif
 
   return true;
 }
 
 BluetoothA2dpManager::~BluetoothA2dpManager()
 {
   nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
   NS_ENSURE_TRUE_VOID(obs);
@@ -763,16 +817,17 @@ BluetoothA2dpManager::UpdateMetaData(con
                                      const nsAString& aArtist,
                                      const nsAString& aAlbum,
                                      uint32_t aMediaNumber,
                                      uint32_t aTotalMediaCount,
                                      uint32_t aDuration)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
+#if ANDROID_VERSION > 17
   NS_ENSURE_TRUE_VOID(sBtAvrcpInterface);
 
   // Send track changed and position changed if track num is not the same.
   // See also AVRCP 1.3 Spec 5.4.2
   if (mMediaNumber != aMediaNumber &&
       mTrackChangedNotifyType == BTRC_NOTIFICATION_TYPE_INTERIM) {
     btrc_register_notification_t param;
     // convert to network big endian format
@@ -797,29 +852,31 @@ BluetoothA2dpManager::UpdateMetaData(con
   }
 
   mTitle.Assign(aTitle);
   mArtist.Assign(aArtist);
   mAlbum.Assign(aAlbum);
   mMediaNumber = aMediaNumber;
   mTotalMediaCount = aTotalMediaCount;
   mDuration = aDuration;
+#endif
 }
 
 /*
  * This function is to reply AvrcpGetPlayStatusCallback (play-status-request)
  * from media player application (Gaia side)
  */
 void
 BluetoothA2dpManager::UpdatePlayStatus(uint32_t aDuration,
                                        uint32_t aPosition,
                                        ControlPlayStatus aPlayStatus)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
+#if ANDROID_VERSION > 17
   NS_ENSURE_TRUE_VOID(sBtAvrcpInterface);
   // when play status changed, send both play status and position
   if (mPlayStatus != aPlayStatus &&
       mPlayStatusChangedNotifyType == BTRC_NOTIFICATION_TYPE_INTERIM) {
     btrc_register_notification_t param;
     param.play_status = (btrc_play_status_t)aPlayStatus;
     mPlayStatusChangedNotifyType = BTRC_NOTIFICATION_TYPE_CHANGED;
     sBtAvrcpInterface->register_notification_rsp(BTRC_EVT_PLAY_STATUS_CHANGED,
@@ -837,30 +894,32 @@ BluetoothA2dpManager::UpdatePlayStatus(u
                                                  &param);
   }
 
   sBtAvrcpInterface->get_play_status_rsp((btrc_play_status_t)aPlayStatus,
                                          aDuration, aPosition);
   mDuration = aDuration;
   mPosition = aPosition;
   mPlayStatus = aPlayStatus;
+#endif
 }
 
 /*
  * This function handles RegisterNotification request from
  * AvrcpRegisterNotificationCallback, which updates current
  * track/status/position status.
  *
  * aParam is only valid when position changed
  */
 void
 BluetoothA2dpManager::UpdateRegisterNotification(int aEventId, int aParam)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
+#if ANDROID_VERSION > 17
   NS_ENSURE_TRUE_VOID(sBtAvrcpInterface);
 
   btrc_register_notification_t param;
 
   switch (aEventId) {
     case BTRC_EVT_PLAY_STATUS_CHANGED:
       mPlayPosChangedNotifyType = BTRC_NOTIFICATION_TYPE_INTERIM;
       param.play_status = (btrc_play_status_t)mPlayStatus;
@@ -880,16 +939,17 @@ BluetoothA2dpManager::UpdateRegisterNoti
       break;
     default:
       break;
   }
 
   sBtAvrcpInterface->register_notification_rsp((btrc_event_id_t)aEventId,
                                                BTRC_NOTIFICATION_TYPE_INTERIM,
                                                &param);
+#endif
 }
 
 void
 BluetoothA2dpManager::GetAlbum(nsAString& aAlbum)
 {
   aAlbum.Assign(mAlbum);
 }