Android audio player: use audio attributes instead of legacy stream type am: 53ac8c773c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/wilhelm/+/23285183

Change-Id: Ia924304a5239e1e70fee6d8fb8ba711ee3007e61
Signed-off-by: Automerger Merge Worker <[email protected]>
diff --git a/src/android/AudioPlayer_to_android.cpp b/src/android/AudioPlayer_to_android.cpp
index 8acc499..5df053d 100644
--- a/src/android/AudioPlayer_to_android.cpp
+++ b/src/android/AudioPlayer_to_android.cpp
@@ -1609,19 +1609,23 @@
         checkAndSetPerformanceModePre(pAudioPlayer);
 
         audio_output_flags_t policy;
+        audio_flags_mask_t attrFlags = AUDIO_FLAG_NONE;
         switch (pAudioPlayer->mPerformanceMode) {
         case ANDROID_PERFORMANCE_MODE_POWER_SAVING:
             policy = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
+            attrFlags = static_cast<audio_flags_mask_t>(attrFlags | AUDIO_FLAG_DEEP_BUFFER);
             break;
         case ANDROID_PERFORMANCE_MODE_NONE:
             policy = AUDIO_OUTPUT_FLAG_NONE;
             break;
         case ANDROID_PERFORMANCE_MODE_LATENCY_EFFECTS:
             policy = AUDIO_OUTPUT_FLAG_FAST;
+            attrFlags = static_cast<audio_flags_mask_t>(attrFlags | AUDIO_FLAG_LOW_LATENCY);
             break;
         case ANDROID_PERFORMANCE_MODE_LATENCY:
         default:
             policy = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_FAST | AUDIO_OUTPUT_FLAG_RAW);
+            attrFlags = static_cast<audio_flags_mask_t>(attrFlags | AUDIO_FLAG_LOW_LATENCY);
             break;
         }
 
@@ -1633,9 +1637,13 @@
         } else {
             notificationFrames = 0;
         }
+        audio_attributes_t attributes = AUDIO_ATTRIBUTES_INITIALIZER;
+        attributes.usage = usageForStreamType(pAudioPlayer->mStreamType);
+        attributes.flags = attrFlags;
+
         const auto callbackHandle = android::sp<android::AudioTrackCallback>::make(pAudioPlayer);
         const auto pat = android::sp<android::AudioTrack>::make(
-                pAudioPlayer->mStreamType,                           // streamType
+                AUDIO_STREAM_DEFAULT,                                // streamType
                 sampleRate,                                          // sampleRate
                 sles_to_android_sampleFormat(df_pcm),                // format
                 channelMask,                                         // channel mask
@@ -1643,7 +1651,12 @@
                 policy,                                              // flags
                 callbackHandle,                                      // callback
                 notificationFrames,                                  // see comment above
-                pAudioPlayer->mSessionId);
+                pAudioPlayer->mSessionId,
+                android::AudioTrack::TRANSFER_DEFAULT,               // transferType
+                nullptr,                                             // offloadInfo
+                AttributionSourceState(),                            // attributionSource
+                &attributes                                          // pAttributes
+                );
 
         // Set it here so it can be logged by the destructor if the open failed.
         pat->setCallerName(ANDROID_OPENSLES_CALLER_NAME);