Bug 1110049: Add Bluetooth A2DP helpers (under bluetooth2/), r=btian
authorThomas Zimmermann <tdz@users.sourceforge.net>
Mon, 26 Jan 2015 18:39:08 +0100
changeset 225654 5b171228918d43dbf14e4b9b00178592fad97fe1
parent 225653 d914c177e2baa7aec5e43a49dc122c4692bca3c9
child 225655 7379867abc827d831c4b07efcec07848fe0abeef
push id28174
push userryanvm@gmail.com
push dateMon, 26 Jan 2015 21:23:42 +0000
treeherdermozilla-central@c3a90afa2dee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbtian
bugs1110049
milestone38.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 1110049: Add Bluetooth A2DP helpers (under bluetooth2/), r=btian
dom/bluetooth2/bluedroid/BluetoothDaemonHelpers.cpp
dom/bluetooth2/bluedroid/BluetoothDaemonHelpers.h
--- a/dom/bluetooth2/bluedroid/BluetoothDaemonHelpers.cpp
+++ b/dom/bluetooth2/bluedroid/BluetoothDaemonHelpers.cpp
@@ -93,16 +93,47 @@ Convert(uint8_t aIn, char& aOut)
 nsresult
 Convert(uint8_t aIn, int& aOut)
 {
   aOut = static_cast<int>(aIn);
   return NS_OK;
 }
 
 nsresult
+Convert(uint8_t aIn, BluetoothA2dpAudioState& aOut)
+{
+  static const BluetoothA2dpAudioState sAudioState[] = {
+    CONVERT(0x00, A2DP_AUDIO_STATE_REMOTE_SUSPEND),
+    CONVERT(0x01, A2DP_AUDIO_STATE_STOPPED),
+    CONVERT(0x02, A2DP_AUDIO_STATE_STARTED)
+  };
+  if (NS_WARN_IF(aIn >= MOZ_ARRAY_LENGTH(sAudioState))) {
+    return NS_ERROR_ILLEGAL_VALUE;
+  }
+  aOut = sAudioState[aIn];
+  return NS_OK;
+}
+
+nsresult
+Convert(uint8_t aIn, BluetoothA2dpConnectionState& aOut)
+{
+  static const BluetoothA2dpConnectionState sConnectionState[] = {
+    CONVERT(0x00, A2DP_CONNECTION_STATE_DISCONNECTED),
+    CONVERT(0x01, A2DP_CONNECTION_STATE_CONNECTING),
+    CONVERT(0x02, A2DP_CONNECTION_STATE_CONNECTED),
+    CONVERT(0x03, A2DP_CONNECTION_STATE_DISCONNECTING)
+  };
+  if (NS_WARN_IF(aIn >= MOZ_ARRAY_LENGTH(sConnectionState))) {
+    return NS_ERROR_ILLEGAL_VALUE;
+  }
+  aOut = sConnectionState[aIn];
+  return NS_OK;
+}
+
+nsresult
 Convert(uint8_t aIn, BluetoothAclState& aOut)
 {
   static const BluetoothAclState sAclState[] = {
     CONVERT(0x00, ACL_STATE_CONNECTED),
     CONVERT(0x01, ACL_STATE_DISCONNECTED),
   };
   if (NS_WARN_IF(aIn >= MOZ_ARRAY_LENGTH(sAclState))) {
     return NS_ERROR_ILLEGAL_VALUE;
@@ -914,16 +945,30 @@ UnpackPDU(BluetoothDaemonPDU& aPDU, bool
 
 nsresult
 UnpackPDU(BluetoothDaemonPDU& aPDU, char& aOut)
 {
   return UnpackPDU(aPDU, UnpackConversion<uint8_t, char>(aOut));
 }
 
 nsresult
+UnpackPDU(BluetoothDaemonPDU& aPDU, BluetoothA2dpAudioState& aOut)
+{
+  return UnpackPDU(
+    aPDU, UnpackConversion<uint8_t, BluetoothA2dpAudioState>(aOut));
+}
+
+nsresult
+UnpackPDU(BluetoothDaemonPDU& aPDU, BluetoothA2dpConnectionState& aOut)
+{
+  return UnpackPDU(
+    aPDU, UnpackConversion<uint8_t, BluetoothA2dpConnectionState>(aOut));
+}
+
+nsresult
 UnpackPDU(BluetoothDaemonPDU& aPDU, BluetoothAclState& aOut)
 {
   return UnpackPDU(aPDU, UnpackConversion<uint8_t, BluetoothAclState>(aOut));
 }
 
 nsresult
 UnpackPDU(BluetoothDaemonPDU& aPDU, BluetoothBondState& aOut)
 {
--- a/dom/bluetooth2/bluedroid/BluetoothDaemonHelpers.h
+++ b/dom/bluetooth2/bluedroid/BluetoothDaemonHelpers.h
@@ -94,16 +94,22 @@ Convert(uint8_t aIn, bool& aOut);
 
 nsresult
 Convert(uint8_t aIn, char& aOut);
 
 nsresult
 Convert(uint8_t aIn, int& aOut);
 
 nsresult
+Convert(uint8_t aIn, BluetoothA2dpAudioState& aOut);
+
+nsresult
+Convert(uint8_t aIn, BluetoothA2dpConnectionState& aOut);
+
+nsresult
 Convert(uint8_t aIn, BluetoothAclState& aOut);
 
 nsresult
 Convert(uint8_t aIn, BluetoothBondState& aOut);
 
 nsresult
 Convert(uint8_t aIn, BluetoothHandsfreeAudioState& aOut);
 
@@ -527,16 +533,22 @@ UnpackPDU(BluetoothDaemonPDU& aPDU, uint
 
 nsresult
 UnpackPDU(BluetoothDaemonPDU& aPDU, bool& aOut);
 
 nsresult
 UnpackPDU(BluetoothDaemonPDU& aPDU, char& aOut);
 
 nsresult
+UnpackPDU(BluetoothDaemonPDU& aPDU, BluetoothA2dpAudioState& aOut);
+
+nsresult
+UnpackPDU(BluetoothDaemonPDU& aPDU, BluetoothA2dpConnectionState& aOut);
+
+nsresult
 UnpackPDU(BluetoothDaemonPDU& aPDU, BluetoothAclState& aOut);
 
 inline nsresult
 UnpackPDU(BluetoothDaemonPDU& aPDU, BluetoothAddress& aOut)
 {
   return aPDU.Read(aOut.mAddr, sizeof(aOut.mAddr));
 }