Bug 953034 - Part 1: Reply RegisterNotification event EVENT_TRACK_CHANGED with correct parameter whether a track is selected or not. r=gyeh, a=1.3+
authorShawn Huang <shuang@mozilla.com>
Thu, 16 Jan 2014 16:29:34 -0500
changeset 174851 b3401fde9ff00ae5ed57c07ea1d6a331584c61ce
parent 174850 ac12618cf462b8ed36fc354c72e0742c2a6488e0
child 174852 e87a716cef373ca8e83ea6011443225a79c9123f
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgyeh, 1
bugs953034
milestone28.0a2
Bug 953034 - Part 1: Reply RegisterNotification event EVENT_TRACK_CHANGED with correct parameter whether a track is selected or not. r=gyeh, a=1.3+
dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp
dom/bluetooth/bluedroid/BluetoothA2dpManager.h
--- a/dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp
@@ -758,18 +758,18 @@ BluetoothA2dpManager::IsAvrcpConnected()
 /*
  * This function only updates meta data in BluetoothA2dpManager
  * Send "Get Element Attributes response" in AvrcpGetElementAttrCallback
  */
 void
 BluetoothA2dpManager::UpdateMetaData(const nsAString& aTitle,
                                      const nsAString& aArtist,
                                      const nsAString& aAlbum,
-                                     uint32_t aMediaNumber,
-                                     uint32_t aTotalMediaCount,
+                                     uint64_t aMediaNumber,
+                                     uint64_t aTotalMediaCount,
                                      uint32_t aDuration)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   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
@@ -843,17 +843,17 @@ BluetoothA2dpManager::UpdatePlayStatus(u
   mDuration = aDuration;
   mPosition = aPosition;
   mPlayStatus = aPlayStatus;
 }
 
 /*
  * This function handles RegisterNotification request from
  * AvrcpRegisterNotificationCallback, which updates current
- * track/status/position status.
+ * track/status/position status in the INTERRIM response.
  *
  * aParam is only valid when position changed
  */
 void
 BluetoothA2dpManager::UpdateRegisterNotification(int aEventId, int aParam)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
@@ -862,26 +862,44 @@ BluetoothA2dpManager::UpdateRegisterNoti
   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;
       break;
     case BTRC_EVT_TRACK_CHANGE:
+      // In AVRCP 1.3 and 1.4, the identifier parameter of EVENT_TRACK_CHANGED
+      // is different.
+      // AVRCP 1.4: If no track is selected, we shall return 0xFFFFFFFFFFFFFFFF,
+      // otherwise return 0x0 in the INTERRIM response. The expanded text in
+      // version 1.4 is to allow for new UID feature. As for AVRCP 1.3, we shall
+      // return 0xFFFFFFFF. Since PTS enforces to check this part to comply with
+      // the most updated spec.
       mTrackChangedNotifyType = BTRC_NOTIFICATION_TYPE_INTERIM;
       // needs to convert to network big endian format since track stores
-      // as uint8[8]. 56 = 8 * (BTRC_UID_SIZE -1)
-      for (int i = 0; i < BTRC_UID_SIZE; ++i) {
-        param.track[i] = (mMediaNumber >> (56 - 8 * i));
+      // as uint8[8]. 56 = 8 * (BTRC_UID_SIZE -1).
+      for (int index = 0; index < BTRC_UID_SIZE; ++index) {
+        // We cannot easily check if a track is selected, so whenever A2DP is
+        // streaming, we assume a track is selected.
+        if (mSinkState == BluetoothA2dpManager::SinkState::SINK_PLAYING) {
+          param.track[index] = 0x0;
+        } else {
+          param.track[index] = 0xFF;
+        }
       }
       break;
     case BTRC_EVT_PLAY_POS_CHANGED:
+      // If no track is selected, return 0xFFFFFFFF in the INTERIM response
       mPlayPosChangedNotifyType = BTRC_NOTIFICATION_TYPE_INTERIM;
-      param.song_pos = mPosition;
+      if (mSinkState == BluetoothA2dpManager::SinkState::SINK_PLAYING) {
+        param.song_pos = mPosition;
+      } else {
+        param.song_pos = 0xFFFFFFFF;
+      }
       mPlaybackInterval = aParam;
       break;
     default:
       break;
   }
 
   sBtAvrcpInterface->register_notification_rsp((btrc_event_id_t)aEventId,
                                                BTRC_NOTIFICATION_TYPE_INTERIM,
@@ -907,23 +925,23 @@ BluetoothA2dpManager::GetPlayStatus()
 }
 
 uint32_t
 BluetoothA2dpManager::GetPosition()
 {
   return mPosition;
 }
 
-uint32_t
+uint64_t
 BluetoothA2dpManager::GetMediaNumber()
 {
   return mMediaNumber;
 }
 
-uint32_t
+uint64_t
 BluetoothA2dpManager::GetTotalMediaNumber()
 {
   return mTotalMediaCount;
 }
 
 void
 BluetoothA2dpManager::GetTitle(nsAString& aTitle)
 {
--- a/dom/bluetooth/bluedroid/BluetoothA2dpManager.h
+++ b/dom/bluetooth/bluedroid/BluetoothA2dpManager.h
@@ -40,29 +40,29 @@ public:
   void HandleSinkPropertyChanged(const BluetoothSignal& aSignal);
 
   // AVRCP-specific functions
   void SetAvrcpConnected(bool aConnected);
   bool IsAvrcpConnected();
   void UpdateMetaData(const nsAString& aTitle,
                       const nsAString& aArtist,
                       const nsAString& aAlbum,
-                      uint32_t aMediaNumber,
-                      uint32_t aTotalMediaCount,
+                      uint64_t aMediaNumber,
+                      uint64_t aTotalMediaCount,
                       uint32_t aDuration);
   void UpdatePlayStatus(uint32_t aDuration,
                         uint32_t aPosition,
                         ControlPlayStatus aPlayStatus);
   void UpdateRegisterNotification(int aEventId, int aParam);
   void GetAlbum(nsAString& aAlbum);
   uint32_t GetDuration();
   ControlPlayStatus GetPlayStatus();
   uint32_t GetPosition();
-  uint32_t GetMediaNumber();
-  uint32_t GetTotalMediaNumber();
+  uint64_t GetMediaNumber();
+  uint64_t GetTotalMediaNumber();
   void GetTitle(nsAString& aTitle);
   void GetArtist(nsAString& aArtist);
 private:
   class SinkPropertyChangedHandler;
   BluetoothA2dpManager();
   bool Init();
   void HandleShutdown();
   void NotifyConnectionStatusChanged();
@@ -75,18 +75,18 @@ private:
   SinkState mSinkState;
 
   // AVRCP data member
   bool mAvrcpConnected;
   nsString mAlbum;
   nsString mArtist;
   nsString mTitle;
   uint32_t mDuration;
-  uint32_t mMediaNumber;
-  uint32_t mTotalMediaCount;
+  uint64_t mMediaNumber;
+  uint64_t mTotalMediaCount;
   uint32_t mPosition;
   /*
    * mPlaybackInterval specifies the time interval (in seconds) at which
    * the change in playback position will be notified. If the song is being
    * forwarded / rewound, a notification will be received whenever the playback
    * position will change by this value.
    */
   uint32_t mPlaybackInterval;