Bug 739090: Dynamically call the right *ForceUse interface. r=mwu (npotb)
authorChris Jones <jones.chris.g@gmail.com>
Mon, 26 Mar 2012 17:39:33 -0700
changeset 93620 c3cb87871829896d2a57d5bc7377521e2898399f
parent 93619 5adbca606d517b3759bb024fbab7a07c0bdd9850
child 93621 8ff0525ff798c14220bc9b22ffcece75a0324a17
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmwu
bugs739090
milestone14.0a1
first release with
nightly linux32
c3cb87871829 / 14.0a1 / 20120327031149 / files
nightly linux64
c3cb87871829 / 14.0a1 / 20120327031149 / files
nightly mac
c3cb87871829 / 14.0a1 / 20120327031149 / files
nightly win32
c3cb87871829 / 14.0a1 / 20120327031149 / files
nightly win64
c3cb87871829 / 14.0a1 / 20120327031149 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 739090: Dynamically call the right *ForceUse interface. r=mwu (npotb)
dom/system/gonk/AudioManager.cpp
media/libsydneyaudio/src/gonk/AudioSystem.h
--- a/dom/system/gonk/AudioManager.cpp
+++ b/dom/system/gonk/AudioManager.cpp
@@ -112,29 +112,52 @@ NS_IMETHODIMP
 AudioManager::SetPhoneState(PRInt32 aState)
 {
   if (AudioSystem::setPhoneState(aState)) {
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }
 
+//
+// Kids, don't try this at home.  We want this to link and work on
+// both GB and ICS.  Problem is, the symbol exported by audioflinger
+// is different on the two gonks.
+//
+// So what we do here is weakly link to both of them, and then call
+// whichever symbol resolves at dynamic link time (if any).
+//
 NS_IMETHODIMP
 AudioManager::SetForceForUse(PRInt32 aUsage, PRInt32 aForce)
 {
-  /*
-   * FIXME/bug XXXXXX: why do we need to disable forceUse in ICS?
-  if (AudioSystem::setForceUse((AudioSystem::force_use)aUsage,
-                               (AudioSystem::forced_config)aForce)) {
-    return NS_ERROR_FAILURE;
+  status_t status = 0;
+  if (static_cast<
+      status_t (*)(AudioSystem::force_use, AudioSystem::forced_config)
+      >(AudioSystem::setForceUse)) {
+    // Dynamically resolved the GB signature.
+    status = AudioSystem::setForceUse((AudioSystem::force_use)aUsage,
+                                      (AudioSystem::forced_config)aForce);
+  } else if (static_cast<
+             status_t (*)(audio_policy_force_use_t, audio_policy_forced_cfg_t)
+             >(AudioSystem::setForceUse)) {
+    // Dynamically resolved the ICS signature.
+    status = AudioSystem::setForceUse((audio_policy_force_use_t)aUsage,
+                                      (audio_policy_forced_cfg_t)aForce);
   }
-  */
-  return NS_OK;
+
+  return status ? NS_ERROR_FAILURE : NS_OK;
 }
 
 NS_IMETHODIMP
 AudioManager::GetForceForUse(PRInt32 aUsage, PRInt32* aForce) {
-  /*
-   * FIXME/bug XXXXXX: why do we need to disable forceUse in ICS?
-  *aForce = AudioSystem::getForceUse((AudioSystem::force_use)aUsage);
-  */
+  if (static_cast<
+      AudioSystem::forced_config (*)(AudioSystem::force_use)
+      >(AudioSystem::getForceUse)) {
+    // Dynamically resolved the GB signature.
+    *aForce = AudioSystem::getForceUse((AudioSystem::force_use)aUsage);
+  } else if (static_cast<
+             audio_policy_forced_cfg_t (*)(audio_policy_force_use_t)
+             >(AudioSystem::getForceUse)) {
+    // Dynamically resolved the ICS signature.
+    *aForce = AudioSystem::getForceUse((audio_policy_force_use_t)aUsage);
+  }
   return NS_OK;
 }
--- a/media/libsydneyaudio/src/gonk/AudioSystem.h
+++ b/media/libsydneyaudio/src/gonk/AudioSystem.h
@@ -16,16 +16,51 @@
 
 #ifndef ANDROID_AUDIOSYSTEM_H_
 #define ANDROID_AUDIOSYSTEM_H_
 
 #include <utils/RefBase.h>
 #include <utils/threads.h>
 #include "IAudioFlinger.h"
 
+#ifndef VANILLA_ANDROID
+/* device categories used for audio_policy->set_force_use() */
+typedef enum {
+    AUDIO_POLICY_FORCE_NONE,
+    AUDIO_POLICY_FORCE_SPEAKER,
+    AUDIO_POLICY_FORCE_HEADPHONES,
+    AUDIO_POLICY_FORCE_BT_SCO,
+    AUDIO_POLICY_FORCE_BT_A2DP,
+    AUDIO_POLICY_FORCE_WIRED_ACCESSORY,
+    AUDIO_POLICY_FORCE_BT_CAR_DOCK,
+    AUDIO_POLICY_FORCE_BT_DESK_DOCK,
+
+#ifdef VANILLA_ANDROID
+    AUDIO_POLICY_FORCE_ANALOG_DOCK,
+    AUDIO_POLICY_FORCE_DIGITAL_DOCK,
+#endif
+
+    AUDIO_POLICY_FORCE_CFG_CNT,
+    AUDIO_POLICY_FORCE_CFG_MAX = AUDIO_POLICY_FORCE_CFG_CNT - 1,
+
+    AUDIO_POLICY_FORCE_DEFAULT = AUDIO_POLICY_FORCE_NONE,
+} audio_policy_forced_cfg_t;
+
+/* usages used for audio_policy->set_force_use() */
+typedef enum {
+    AUDIO_POLICY_FORCE_FOR_COMMUNICATION,
+    AUDIO_POLICY_FORCE_FOR_MEDIA,
+    AUDIO_POLICY_FORCE_FOR_RECORD,
+    AUDIO_POLICY_FORCE_FOR_DOCK,
+
+    AUDIO_POLICY_FORCE_USE_CNT,
+    AUDIO_POLICY_FORCE_USE_MAX = AUDIO_POLICY_FORCE_USE_CNT - 1,
+} audio_policy_force_use_t;
+#endif
+
 namespace android {
 
 typedef void (*audio_error_callback)(status_t err);
 typedef int audio_io_handle_t;
 
 class IAudioPolicyService;
 class String8;
 
@@ -354,18 +389,26 @@ public:
 
     //
     // IAudioPolicyService interface (see AudioPolicyInterface for method descriptions)
     //
     static status_t setDeviceConnectionState(audio_devices device, device_connection_state state, const char *device_address);
     static device_connection_state getDeviceConnectionState(audio_devices device, const char *device_address);
     static status_t setPhoneState(int state);
     static status_t setRingerMode(uint32_t mode, uint32_t mask);
+#ifdef VANILLA_ANDROID
     static status_t setForceUse(force_use usage, forced_config config);
     static forced_config getForceUse(force_use usage);
+#else
+    static status_t setForceUse(force_use usage, forced_config config) __attribute__((weak));
+    static forced_config getForceUse(force_use usage) __attribute__((weak));
+
+    static status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) __attribute__((weak));
+    static audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) __attribute__((weak));
+#endif
     static audio_io_handle_t getOutput(stream_type stream,
                                         uint32_t samplingRate = 0,
                                         uint32_t format = FORMAT_DEFAULT,
                                         uint32_t channels = CHANNEL_OUT_STEREO,
                                         output_flags flags = OUTPUT_FLAG_INDIRECT);
     static status_t startOutput(audio_io_handle_t output,
                                 AudioSystem::stream_type stream,
                                 int session = 0);