policy_hal: Add support to identify direct pcm client.

-Update Direct pcm implementation to identify direct pcm client
as mediaplayer or app based audio track.
-This gives flexibility to disable direct pcm either of these clients.

Change-Id: Ief418a864a6f776c4dea7b2e953df9497cbcb5d0
diff --git a/policy_hal/AudioPolicyManager.cpp b/policy_hal/AudioPolicyManager.cpp
index 8bfea9a..089efc5 100644
--- a/policy_hal/AudioPolicyManager.cpp
+++ b/policy_hal/AudioPolicyManager.cpp
@@ -1405,17 +1405,34 @@
     return false;
 }
 
-bool static isDirectPCMEnabled(int bitWidth)
+bool static tryForDirectPCM(int bitWidth, audio_output_flags_t *flags)
 {
-    bool directPCMEnabled = false;
-    if (bitWidth == 24 || bitWidth == 32)
-        directPCMEnabled =
-             property_get_bool("audio.offload.pcm.24bit.enable", false);
-    else
-        directPCMEnabled =
-             property_get_bool("audio.offload.pcm.16bit.enable", false);
+    bool playerDirectPCM = false; // Output request for Track created by mediaplayer
+    bool trackDirectPCM = false;  // Output request for track created by other apps
 
-    return directPCMEnabled;
+    // Direct PCM is allowed only if
+    // In case of mediaPlayer playback
+    // 16 bit direct pcm or 24bit direct PCM property is set and
+    // the FLAG requested is DIRECT_PCM ( NuPlayer case) or
+    // In case of AudioTracks created by apps
+    // track offload is enabled and FLAG requested is FLAG_NONE.
+
+    if (*flags == AUDIO_OUTPUT_FLAG_DIRECT_PCM) {
+       if (bitWidth == 24 || bitWidth == 32)
+           playerDirectPCM =
+                property_get_bool("audio.offload.pcm.24bit.enable", false);
+       else
+           playerDirectPCM =
+                property_get_bool("audio.offload.pcm.16bit.enable", false);
+       // Reset flag to NONE so that we can still reuse direct pcm criteria check
+       // in getOutputforDevice
+       *flags = AUDIO_OUTPUT_FLAG_NONE;
+    } else if ( *flags == AUDIO_OUTPUT_FLAG_NONE) {
+        trackDirectPCM = property_get_bool("audio.offload.track.enable", true);
+    }
+
+    ALOGI("%s for Direct PCM",trackDirectPCM || playerDirectPCM?"Check":"Dont check");
+    return trackDirectPCM || playerDirectPCM;
 }
 
 status_t AudioPolicyManagerCustom::getOutputForAttr(const audio_attributes_t *attr,
@@ -1440,8 +1457,7 @@
     }
 
     if (!offloadDisabled && (offloadInfo == NULL) &&
-        isDirectPCMEnabled(bitWidth) &&
-        (flags == AUDIO_OUTPUT_FLAG_NONE)) {
+        tryForDirectPCM(bitWidth, &flags)) {
 
         tOffloadInfo.sample_rate  = samplingRate;
         tOffloadInfo.channel_mask = channelMask;