audiopolicy: use deep buffer output by default for music streams

Default disabled. This is enabled by

adb shell setprop audio.deep_buffer.media 1

Applications that use AudioTrack java interface for audio rendering
defaults to primary output as flags indicated as FLAG_NONE. If the
primary output is low latency output, it results higher power
consumption than deep-buffer path if used.
Make the deep buffer output as default option for music streams if
flags are not specified.

It may also be used for testing audio glitches from heavy CPU
or DRM which may cause issues with the FastMixer.

Bug: 21198655
Bug: 21785618
Change-Id: I909c296ddcf4484b9a877ef1c0230ea58537e06a
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 0adaac9..6befb8d 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -789,6 +789,11 @@
     // only allow deep buffering for music stream type
     if (stream != AUDIO_STREAM_MUSIC) {
         flags = (audio_output_flags_t)(flags &~AUDIO_OUTPUT_FLAG_DEEP_BUFFER);
+    } else if (/* stream == AUDIO_STREAM_MUSIC && */
+            flags == AUDIO_OUTPUT_FLAG_NONE &&
+            property_get_bool("audio.deep_buffer.media", false /* default_value */)) {
+        // use DEEP_BUFFER as default output for music stream type
+        flags = (audio_output_flags_t)AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
     }
     if (stream == AUDIO_STREAM_TTS) {
         flags = AUDIO_OUTPUT_FLAG_TTS;