summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2022-01-06 13:54:56 +0100
committerEric Laurent <elaurent@google.com>2022-01-06 16:58:42 +0100
commitd7f33c5ba46b01e3e580597260cd0ffffdf773b6 (patch)
tree1544063f71efff05f94bdd9200fc61c2942b271f
parent6bb7dbea95f6ac0d37170a0469c69655fccd78a9 (diff)
downloadav-android12L-dev.tar.gz
AudioTrack: fix output flags updateandroid-vts-12.1_r2android-cts-12.1_r2android12L-dev
Fix regression introduced by commit c2b0c7a18c6c97a4086956ac95f06addd0f3558f that caused output flags modifications made in AudioTrack::set() to be dropped wihtout being saved for further use by createTrack_l(). Bug: 213437414 Test: Play Youtube Music and verify use of deep buffer Change-Id: I3c6c407fa4408c528a68a3d9736690d563bbafc3
-rw-r--r--media/libaudioclient/AudioTrack.cpp81
1 files changed, 41 insertions, 40 deletions
diff --git a/media/libaudioclient/AudioTrack.cpp b/media/libaudioclient/AudioTrack.cpp
index 536101a0e6..c2bea66309 100644
--- a/media/libaudioclient/AudioTrack.cpp
+++ b/media/libaudioclient/AudioTrack.cpp
@@ -413,14 +413,50 @@ status_t AudioTrack::set(
mSelectedDeviceId = selectedDeviceId;
mSessionId = sessionId;
mChannelMask = channelMask;
- mFormat = format;
- mOrigFlags = mFlags = flags;
mReqFrameCount = mFrameCount = frameCount;
mSampleRate = sampleRate;
mOriginalSampleRate = sampleRate;
mAttributes = pAttributes != nullptr ? *pAttributes : AUDIO_ATTRIBUTES_INITIALIZER;
mPlaybackRate = AUDIO_PLAYBACK_RATE_DEFAULT;
+ // update format and flags before storing them in mFormat, mOrigFlags and mFlags
+ if (pAttributes != NULL) {
+ // stream type shouldn't be looked at, this track has audio attributes
+ ALOGV("%s(): Building AudioTrack with attributes:"
+ " usage=%d content=%d flags=0x%x tags=[%s]",
+ __func__,
+ mAttributes.usage, mAttributes.content_type, mAttributes.flags, mAttributes.tags);
+ audio_flags_to_audio_output_flags(mAttributes.flags, &flags);
+ }
+
+ // these below should probably come from the audioFlinger too...
+ if (format == AUDIO_FORMAT_DEFAULT) {
+ format = AUDIO_FORMAT_PCM_16_BIT;
+ } else if (format == AUDIO_FORMAT_IEC61937) { // HDMI pass-through?
+ flags = static_cast<audio_output_flags_t>(flags | AUDIO_OUTPUT_FLAG_IEC958_NONAUDIO);
+ }
+
+ // force direct flag if format is not linear PCM
+ // or offload was requested
+ if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)
+ || !audio_is_linear_pcm(format)) {
+ ALOGV( (flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)
+ ? "%s(): Offload request, forcing to Direct Output"
+ : "%s(): Not linear PCM, forcing to Direct Output",
+ __func__);
+ flags = (audio_output_flags_t)
+ // FIXME why can't we allow direct AND fast?
+ ((flags | AUDIO_OUTPUT_FLAG_DIRECT) & ~AUDIO_OUTPUT_FLAG_FAST);
+ }
+
+ // force direct flag if HW A/V sync requested
+ if ((flags & AUDIO_OUTPUT_FLAG_HW_AV_SYNC) != 0) {
+ flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT);
+ }
+
+ mFormat = format;
+ mOrigFlags = mFlags = flags;
+
switch (transferType) {
case TRANSFER_DEFAULT:
if (sharedBuffer != 0) {
@@ -470,9 +506,6 @@ status_t AudioTrack::set(
ALOGV_IF(sharedBuffer != 0, "%s(): sharedBuffer: %p, size: %zu",
__func__, sharedBuffer->unsecurePointer(), sharedBuffer->size());
- ALOGV("%s(): streamType %d frameCount %zu flags %04x",
- __func__, streamType, frameCount, flags);
-
// invariant that mAudioTrack != 0 is true only after set() returns successfully
if (mAudioTrack != 0) {
errorMessage = StringPrintf("%s: Track already in use", __func__);
@@ -491,22 +524,8 @@ status_t AudioTrack::set(
goto error;
}
mOriginalStreamType = streamType;
-
} else {
- // stream type shouldn't be looked at, this track has audio attributes
- ALOGV("%s(): Building AudioTrack with attributes:"
- " usage=%d content=%d flags=0x%x tags=[%s]",
- __func__,
- mAttributes.usage, mAttributes.content_type, mAttributes.flags, mAttributes.tags);
mOriginalStreamType = AUDIO_STREAM_DEFAULT;
- audio_flags_to_audio_output_flags(mAttributes.flags, &flags);
- }
-
- // these below should probably come from the audioFlinger too...
- if (format == AUDIO_FORMAT_DEFAULT) {
- format = AUDIO_FORMAT_PCM_16_BIT;
- } else if (format == AUDIO_FORMAT_IEC61937) { // HDMI pass-through?
- flags = static_cast<audio_output_flags_t>(flags | AUDIO_OUTPUT_FLAG_IEC958_NONAUDIO);
}
// validate parameters
@@ -524,25 +543,7 @@ status_t AudioTrack::set(
channelCount = audio_channel_count_from_out_mask(channelMask);
mChannelCount = channelCount;
- // force direct flag if format is not linear PCM
- // or offload was requested
- if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)
- || !audio_is_linear_pcm(format)) {
- ALOGV( (flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)
- ? "%s(): Offload request, forcing to Direct Output"
- : "%s(): Not linear PCM, forcing to Direct Output",
- __func__);
- flags = (audio_output_flags_t)
- // FIXME why can't we allow direct AND fast?
- ((flags | AUDIO_OUTPUT_FLAG_DIRECT) & ~AUDIO_OUTPUT_FLAG_FAST);
- }
-
- // force direct flag if HW A/V sync requested
- if ((flags & AUDIO_OUTPUT_FLAG_HW_AV_SYNC) != 0) {
- flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT);
- }
-
- if (flags & AUDIO_OUTPUT_FLAG_DIRECT) {
+ if (mFlags & AUDIO_OUTPUT_FLAG_DIRECT) {
if (audio_has_proportional_frames(format)) {
mFrameSize = channelCount * audio_bytes_per_sample(format);
} else {
@@ -556,7 +557,7 @@ status_t AudioTrack::set(
}
// sampling rate must be specified for direct outputs
- if (sampleRate == 0 && (flags & AUDIO_OUTPUT_FLAG_DIRECT) != 0) {
+ if (sampleRate == 0 && (mFlags & AUDIO_OUTPUT_FLAG_DIRECT) != 0) {
errorMessage = StringPrintf(
"%s: sample rate must be specified for direct outputs", __func__);
status = BAD_VALUE;
@@ -585,7 +586,7 @@ status_t AudioTrack::set(
mNotificationFramesReq = notificationFrames;
mNotificationsPerBufferReq = 0;
} else {
- if (!(flags & AUDIO_OUTPUT_FLAG_FAST)) {
+ if (!(mFlags & AUDIO_OUTPUT_FLAG_FAST)) {
errorMessage = StringPrintf(
"%s: notificationFrames=%d not permitted for non-fast track",
__func__, notificationFrames);