Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Phil Burk | 965650e | 2017-09-07 21:00:09 -0700 | [diff] [blame] | 17 | #define LOG_TAG "AudioStreamTrack" |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 18 | //#define LOG_NDEBUG 0 |
| 19 | #include <utils/Log.h> |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <media/AudioTrack.h> |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 23 | |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 24 | #include <aaudio/AAudio.h> |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 25 | #include "utility/AudioClock.h" |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 26 | #include "legacy/AudioStreamLegacy.h" |
| 27 | #include "legacy/AudioStreamTrack.h" |
| 28 | #include "utility/FixedBlockReader.h" |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 29 | |
| 30 | using namespace android; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 31 | using namespace aaudio; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 32 | |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 33 | // Arbitrary and somewhat generous number of bursts. |
| 34 | #define DEFAULT_BURSTS_PER_BUFFER_CAPACITY 8 |
| 35 | |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 36 | /* |
| 37 | * Create a stream that uses the AudioTrack. |
| 38 | */ |
| 39 | AudioStreamTrack::AudioStreamTrack() |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 40 | : AudioStreamLegacy() |
| 41 | , mFixedBlockReader(*this) |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 42 | { |
| 43 | } |
| 44 | |
| 45 | AudioStreamTrack::~AudioStreamTrack() |
| 46 | { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 47 | const aaudio_stream_state_t state = getState(); |
| 48 | bool bad = !(state == AAUDIO_STREAM_STATE_UNINITIALIZED || state == AAUDIO_STREAM_STATE_CLOSED); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 49 | ALOGE_IF(bad, "stream not closed, in state %d", state); |
| 50 | } |
| 51 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 52 | aaudio_result_t AudioStreamTrack::open(const AudioStreamBuilder& builder) |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 53 | { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 54 | aaudio_result_t result = AAUDIO_OK; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 55 | |
| 56 | result = AudioStream::open(builder); |
| 57 | if (result != OK) { |
| 58 | return result; |
| 59 | } |
| 60 | |
| 61 | // Try to create an AudioTrack |
Phil Burk | 5204d31 | 2017-05-04 17:16:13 -0700 | [diff] [blame] | 62 | // Use stereo if unspecified. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 63 | int32_t samplesPerFrame = (getSamplesPerFrame() == AAUDIO_UNSPECIFIED) |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 64 | ? 2 : getSamplesPerFrame(); |
| 65 | audio_channel_mask_t channelMask = audio_channel_out_mask_from_count(samplesPerFrame); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 66 | |
Phil Burk | e2fbb59 | 2017-05-01 15:05:52 -0700 | [diff] [blame] | 67 | audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE; |
Phil Burk | 30a7077 | 2017-05-16 11:20:36 -0700 | [diff] [blame] | 68 | aaudio_performance_mode_t perfMode = getPerformanceMode(); |
| 69 | switch(perfMode) { |
Phil Burk | e2fbb59 | 2017-05-01 15:05:52 -0700 | [diff] [blame] | 70 | case AAUDIO_PERFORMANCE_MODE_LOW_LATENCY: |
| 71 | // Bypass the normal mixer and go straight to the FAST mixer. |
| 72 | flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_FAST | AUDIO_OUTPUT_FLAG_RAW); |
| 73 | break; |
| 74 | |
| 75 | case AAUDIO_PERFORMANCE_MODE_POWER_SAVING: |
| 76 | // This uses a mixer that wakes up less often than the FAST mixer. |
| 77 | flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER; |
| 78 | break; |
| 79 | |
| 80 | case AAUDIO_PERFORMANCE_MODE_NONE: |
| 81 | default: |
| 82 | // No flags. Use a normal mixer in front of the FAST mixer. |
| 83 | break; |
| 84 | } |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 85 | |
Phil Burk | cf5f6d2 | 2017-05-26 12:35:07 -0700 | [diff] [blame] | 86 | size_t frameCount = (size_t)builder.getBufferCapacity(); |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 87 | |
| 88 | int32_t notificationFrames = 0; |
| 89 | |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 90 | audio_format_t format = (getFormat() == AAUDIO_FORMAT_UNSPECIFIED) |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 91 | ? AUDIO_FORMAT_PCM_FLOAT |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 92 | : AAudioConvert_aaudioToAndroidDataFormat(getFormat()); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 93 | |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 94 | // Setup the callback if there is one. |
| 95 | AudioTrack::callback_t callback = nullptr; |
| 96 | void *callbackData = nullptr; |
| 97 | // Note that TRANSFER_SYNC does not allow FAST track |
| 98 | AudioTrack::transfer_type streamTransferType = AudioTrack::transfer_type::TRANSFER_SYNC; |
| 99 | if (builder.getDataCallbackProc() != nullptr) { |
| 100 | streamTransferType = AudioTrack::transfer_type::TRANSFER_CALLBACK; |
| 101 | callback = getLegacyCallback(); |
| 102 | callbackData = this; |
| 103 | |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 104 | // If the total buffer size is unspecified then base the size on the burst size. |
Phil Burk | 4485d41 | 2017-05-09 15:55:02 -0700 | [diff] [blame] | 105 | if (frameCount == 0 |
| 106 | && ((flags & AUDIO_OUTPUT_FLAG_FAST) != 0)) { |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 107 | // Take advantage of a special trick that allows us to create a buffer |
| 108 | // that is some multiple of the burst size. |
| 109 | notificationFrames = 0 - DEFAULT_BURSTS_PER_BUFFER_CAPACITY; |
Phil Burk | 4485d41 | 2017-05-09 15:55:02 -0700 | [diff] [blame] | 110 | } else { |
| 111 | notificationFrames = builder.getFramesPerDataCallback(); |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | mCallbackBufferSize = builder.getFramesPerDataCallback(); |
| 115 | |
Phil Burk | fbf031e | 2017-10-12 15:58:31 -0700 | [diff] [blame] | 116 | ALOGD("open(), request notificationFrames = %d, frameCount = %u", |
Phil Burk | cf5f6d2 | 2017-05-26 12:35:07 -0700 | [diff] [blame] | 117 | notificationFrames, (uint)frameCount); |
Phil Burk | ee99539 | 2017-12-11 11:44:36 -0800 | [diff] [blame] | 118 | |
| 119 | // Don't call mAudioTrack->setDeviceId() because it will be overwritten by set()! |
| 120 | audio_port_handle_t selectedDeviceId = (getDeviceId() == AAUDIO_UNSPECIFIED) |
| 121 | ? AUDIO_PORT_HANDLE_NONE |
| 122 | : getDeviceId(); |
| 123 | |
Phil Burk | d4ccc62 | 2017-12-20 15:32:44 -0800 | [diff] [blame] | 124 | const audio_content_type_t contentType = |
| 125 | AAudioConvert_contentTypeToInternal(builder.getContentType()); |
| 126 | const audio_usage_t usage = |
| 127 | AAudioConvert_usageToInternal(builder.getUsage()); |
| 128 | |
| 129 | const audio_attributes_t attributes = { |
| 130 | .content_type = contentType, |
| 131 | .usage = usage, |
| 132 | .source = AUDIO_SOURCE_DEFAULT, // only used for recording |
| 133 | .flags = flags, // If attributes are set then the other flags parameter is ignored. |
| 134 | .tags = "" |
| 135 | }; |
| 136 | |
Phil Burk | 4e1af9f | 2018-01-03 15:54:35 -0800 | [diff] [blame] | 137 | static_assert(AAUDIO_UNSPECIFIED == AUDIO_SESSION_ALLOCATE, "Session IDs should match"); |
| 138 | |
| 139 | aaudio_session_id_t requestedSessionId = builder.getSessionId(); |
| 140 | audio_session_t sessionId = AAudioConvert_aaudioToAndroidSessionId(requestedSessionId); |
| 141 | |
Phil Burk | ee99539 | 2017-12-11 11:44:36 -0800 | [diff] [blame] | 142 | mAudioTrack = new AudioTrack(); |
Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 143 | mAudioTrack->set( |
Phil Burk | d4ccc62 | 2017-12-20 15:32:44 -0800 | [diff] [blame] | 144 | AUDIO_STREAM_DEFAULT, // ignored because we pass attributes below |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 145 | getSampleRate(), |
| 146 | format, |
| 147 | channelMask, |
| 148 | frameCount, |
| 149 | flags, |
| 150 | callback, |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 151 | callbackData, |
| 152 | notificationFrames, |
Phil Burk | ee99539 | 2017-12-11 11:44:36 -0800 | [diff] [blame] | 153 | 0, // DEFAULT sharedBuffer*/, |
| 154 | false, // DEFAULT threadCanCallJava |
Phil Burk | 4e1af9f | 2018-01-03 15:54:35 -0800 | [diff] [blame] | 155 | sessionId, |
Phil Burk | ee99539 | 2017-12-11 11:44:36 -0800 | [diff] [blame] | 156 | streamTransferType, |
| 157 | NULL, // DEFAULT audio_offload_info_t |
| 158 | AUDIO_UID_INVALID, // DEFAULT uid |
| 159 | -1, // DEFAULT pid |
Phil Burk | d4ccc62 | 2017-12-20 15:32:44 -0800 | [diff] [blame] | 160 | &attributes, |
Phil Burk | ee99539 | 2017-12-11 11:44:36 -0800 | [diff] [blame] | 161 | // WARNING - If doNotReconnect set true then audio stops after plugging and unplugging |
| 162 | // headphones a few times. |
| 163 | false, // DEFAULT doNotReconnect, |
| 164 | 1.0f, // DEFAULT maxRequiredSpeed |
| 165 | selectedDeviceId |
| 166 | ); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 167 | |
| 168 | // Did we get a valid track? |
| 169 | status_t status = mAudioTrack->initCheck(); |
Phil Burk | dec33ab | 2017-01-17 14:48:16 -0800 | [diff] [blame] | 170 | if (status != NO_ERROR) { |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 171 | close(); |
Phil Burk | fbf031e | 2017-10-12 15:58:31 -0700 | [diff] [blame] | 172 | ALOGE("open(), initCheck() returned %d", status); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 173 | return AAudioConvert_androidToAAudioResult(status); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 174 | } |
| 175 | |
Phil Burk | 965650e | 2017-09-07 21:00:09 -0700 | [diff] [blame] | 176 | doSetVolume(); |
Eric Laurent | 1d32e9f | 2017-06-02 14:01:32 -0700 | [diff] [blame] | 177 | |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 178 | // Get the actual values from the AudioTrack. |
| 179 | setSamplesPerFrame(mAudioTrack->channelCount()); |
Phil Burk | 9dca982 | 2017-05-26 14:27:43 -0700 | [diff] [blame] | 180 | aaudio_format_t aaudioFormat = |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 181 | AAudioConvert_androidToAAudioDataFormat(mAudioTrack->format()); |
| 182 | setFormat(aaudioFormat); |
| 183 | |
Phil Burk | cf5f6d2 | 2017-05-26 12:35:07 -0700 | [diff] [blame] | 184 | int32_t actualSampleRate = mAudioTrack->getSampleRate(); |
| 185 | ALOGW_IF(actualSampleRate != getSampleRate(), |
Phil Burk | fbf031e | 2017-10-12 15:58:31 -0700 | [diff] [blame] | 186 | "open() sampleRate changed from %d to %d", |
Phil Burk | cf5f6d2 | 2017-05-26 12:35:07 -0700 | [diff] [blame] | 187 | getSampleRate(), actualSampleRate); |
| 188 | setSampleRate(actualSampleRate); |
| 189 | |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 190 | // We may need to pass the data through a block size adapter to guarantee constant size. |
| 191 | if (mCallbackBufferSize != AAUDIO_UNSPECIFIED) { |
| 192 | int callbackSizeBytes = getBytesPerFrame() * mCallbackBufferSize; |
| 193 | mFixedBlockReader.open(callbackSizeBytes); |
| 194 | mBlockAdapter = &mFixedBlockReader; |
| 195 | } else { |
| 196 | mBlockAdapter = nullptr; |
| 197 | } |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 198 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 199 | setState(AAUDIO_STREAM_STATE_OPEN); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 200 | setDeviceId(mAudioTrack->getRoutedDeviceId()); |
Phil Burk | 4e1af9f | 2018-01-03 15:54:35 -0800 | [diff] [blame] | 201 | |
| 202 | aaudio_session_id_t actualSessionId = |
| 203 | (requestedSessionId == AAUDIO_SESSION_ID_NONE) |
| 204 | ? AAUDIO_SESSION_ID_NONE |
| 205 | : (aaudio_session_id_t) mAudioTrack->getSessionId(); |
| 206 | setSessionId(actualSessionId); |
| 207 | |
Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 208 | mAudioTrack->addAudioDeviceCallback(mDeviceCallback); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 209 | |
Phil Burk | 09c27ca | 2017-08-24 22:12:56 -0700 | [diff] [blame] | 210 | // Update performance mode based on the actual stream flags. |
Phil Burk | 30a7077 | 2017-05-16 11:20:36 -0700 | [diff] [blame] | 211 | // For example, if the sample rate is not allowed then you won't get a FAST track. |
| 212 | audio_output_flags_t actualFlags = mAudioTrack->getFlags(); |
| 213 | aaudio_performance_mode_t actualPerformanceMode = AAUDIO_PERFORMANCE_MODE_NONE; |
Phil Burk | 09c27ca | 2017-08-24 22:12:56 -0700 | [diff] [blame] | 214 | // We may not get the RAW flag. But as long as we get the FAST flag we can call it LOW_LATENCY. |
| 215 | if ((actualFlags & AUDIO_OUTPUT_FLAG_FAST) != 0) { |
Phil Burk | 30a7077 | 2017-05-16 11:20:36 -0700 | [diff] [blame] | 216 | actualPerformanceMode = AAUDIO_PERFORMANCE_MODE_LOW_LATENCY; |
Phil Burk | 30a7077 | 2017-05-16 11:20:36 -0700 | [diff] [blame] | 217 | } else if ((actualFlags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) != 0) { |
| 218 | actualPerformanceMode = AAUDIO_PERFORMANCE_MODE_POWER_SAVING; |
| 219 | } |
| 220 | setPerformanceMode(actualPerformanceMode); |
Phil Burk | efa5600 | 2017-08-02 15:07:21 -0700 | [diff] [blame] | 221 | |
| 222 | setSharingMode(AAUDIO_SHARING_MODE_SHARED); // EXCLUSIVE mode not supported in legacy |
| 223 | |
Phil Burk | 30a7077 | 2017-05-16 11:20:36 -0700 | [diff] [blame] | 224 | // Log warning if we did not get what we asked for. |
| 225 | ALOGW_IF(actualFlags != flags, |
Phil Burk | fbf031e | 2017-10-12 15:58:31 -0700 | [diff] [blame] | 226 | "open() flags changed from 0x%08X to 0x%08X", |
Phil Burk | 30a7077 | 2017-05-16 11:20:36 -0700 | [diff] [blame] | 227 | flags, actualFlags); |
| 228 | ALOGW_IF(actualPerformanceMode != perfMode, |
Phil Burk | fbf031e | 2017-10-12 15:58:31 -0700 | [diff] [blame] | 229 | "open() perfMode changed from %d to %d", |
Phil Burk | 30a7077 | 2017-05-16 11:20:36 -0700 | [diff] [blame] | 230 | perfMode, actualPerformanceMode); |
| 231 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 232 | return AAUDIO_OK; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 233 | } |
| 234 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 235 | aaudio_result_t AudioStreamTrack::close() |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 236 | { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 237 | if (getState() != AAUDIO_STREAM_STATE_CLOSED) { |
Phil Burk | 965650e | 2017-09-07 21:00:09 -0700 | [diff] [blame] | 238 | mAudioTrack->removeAudioDeviceCallback(mDeviceCallback); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 239 | setState(AAUDIO_STREAM_STATE_CLOSED); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 240 | } |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 241 | mFixedBlockReader.close(); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 242 | return AAUDIO_OK; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 245 | void AudioStreamTrack::processCallback(int event, void *info) { |
| 246 | |
| 247 | switch (event) { |
| 248 | case AudioTrack::EVENT_MORE_DATA: |
| 249 | processCallbackCommon(AAUDIO_CALLBACK_OPERATION_PROCESS_DATA, info); |
| 250 | break; |
| 251 | |
| 252 | // Stream got rerouted so we disconnect. |
| 253 | case AudioTrack::EVENT_NEW_IAUDIOTRACK: |
| 254 | processCallbackCommon(AAUDIO_CALLBACK_OPERATION_DISCONNECTED, info); |
| 255 | break; |
| 256 | |
| 257 | default: |
| 258 | break; |
| 259 | } |
| 260 | return; |
| 261 | } |
| 262 | |
Phil Burk | 965650e | 2017-09-07 21:00:09 -0700 | [diff] [blame] | 263 | aaudio_result_t AudioStreamTrack::requestStart() { |
Phil Burk | d8bdcab | 2017-01-03 17:20:30 -0800 | [diff] [blame] | 264 | if (mAudioTrack.get() == nullptr) { |
Phil Burk | fbf031e | 2017-10-12 15:58:31 -0700 | [diff] [blame] | 265 | ALOGE("requestStart() no AudioTrack"); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 266 | return AAUDIO_ERROR_INVALID_STATE; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 267 | } |
| 268 | // Get current position so we can detect when the track is playing. |
| 269 | status_t err = mAudioTrack->getPosition(&mPositionWhenStarting); |
| 270 | if (err != OK) { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 271 | return AAudioConvert_androidToAAudioResult(err); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 272 | } |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 273 | |
Phil Burk | 9e9a95b | 2018-01-18 12:14:15 -0800 | [diff] [blame] | 274 | // Enable callback before starting AudioTrack to avoid shutting |
| 275 | // down because of a race condition. |
| 276 | mCallbackEnabled.store(true); |
Phil Burk | 965650e | 2017-09-07 21:00:09 -0700 | [diff] [blame] | 277 | err = mAudioTrack->start(); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 278 | if (err != OK) { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 279 | return AAudioConvert_androidToAAudioResult(err); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 280 | } else { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 281 | setState(AAUDIO_STREAM_STATE_STARTING); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 282 | } |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 283 | return AAUDIO_OK; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Phil Burk | 965650e | 2017-09-07 21:00:09 -0700 | [diff] [blame] | 286 | aaudio_result_t AudioStreamTrack::requestPause() { |
Phil Burk | d8bdcab | 2017-01-03 17:20:30 -0800 | [diff] [blame] | 287 | if (mAudioTrack.get() == nullptr) { |
Phil Burk | 965650e | 2017-09-07 21:00:09 -0700 | [diff] [blame] | 288 | ALOGE("requestPause() no AudioTrack"); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 289 | return AAUDIO_ERROR_INVALID_STATE; |
| 290 | } else if (getState() != AAUDIO_STREAM_STATE_STARTING |
| 291 | && getState() != AAUDIO_STREAM_STATE_STARTED) { |
Phil Burk | 134f197 | 2017-12-08 13:06:11 -0800 | [diff] [blame] | 292 | // TODO What about DISCONNECTED? |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 293 | ALOGE("requestPause(), called when state is %s", |
| 294 | AAudio_convertStreamStateToText(getState())); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 295 | return AAUDIO_ERROR_INVALID_STATE; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 296 | } |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 297 | setState(AAUDIO_STREAM_STATE_PAUSING); |
Phil Burk | 965650e | 2017-09-07 21:00:09 -0700 | [diff] [blame] | 298 | mAudioTrack->pause(); |
Phil Burk | 9e9a95b | 2018-01-18 12:14:15 -0800 | [diff] [blame] | 299 | mCallbackEnabled.store(false); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 300 | status_t err = mAudioTrack->getPosition(&mPositionWhenPausing); |
| 301 | if (err != OK) { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 302 | return AAudioConvert_androidToAAudioResult(err); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 303 | } |
Phil Burk | 134f197 | 2017-12-08 13:06:11 -0800 | [diff] [blame] | 304 | return checkForDisconnectRequest(false); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 305 | } |
| 306 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 307 | aaudio_result_t AudioStreamTrack::requestFlush() { |
Phil Burk | d8bdcab | 2017-01-03 17:20:30 -0800 | [diff] [blame] | 308 | if (mAudioTrack.get() == nullptr) { |
Phil Burk | fbf031e | 2017-10-12 15:58:31 -0700 | [diff] [blame] | 309 | ALOGE("requestFlush() no AudioTrack"); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 310 | return AAUDIO_ERROR_INVALID_STATE; |
| 311 | } else if (getState() != AAUDIO_STREAM_STATE_PAUSED) { |
Phil Burk | fbf031e | 2017-10-12 15:58:31 -0700 | [diff] [blame] | 312 | ALOGE("requestFlush() not paused"); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 313 | return AAUDIO_ERROR_INVALID_STATE; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 314 | } |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 315 | setState(AAUDIO_STREAM_STATE_FLUSHING); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 316 | incrementFramesRead(getFramesWritten() - getFramesRead()); |
| 317 | mAudioTrack->flush(); |
| 318 | mFramesWritten.reset32(); |
Phil Burk | 7328a80 | 2017-08-30 09:29:48 -0700 | [diff] [blame] | 319 | mTimestampPosition.reset32(); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 320 | return AAUDIO_OK; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 321 | } |
| 322 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 323 | aaudio_result_t AudioStreamTrack::requestStop() { |
Phil Burk | d8bdcab | 2017-01-03 17:20:30 -0800 | [diff] [blame] | 324 | if (mAudioTrack.get() == nullptr) { |
Phil Burk | fbf031e | 2017-10-12 15:58:31 -0700 | [diff] [blame] | 325 | ALOGE("requestStop() no AudioTrack"); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 326 | return AAUDIO_ERROR_INVALID_STATE; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 327 | } |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 328 | setState(AAUDIO_STREAM_STATE_STOPPING); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 329 | incrementFramesRead(getFramesWritten() - getFramesRead()); // TODO review |
Phil Burk | 7328a80 | 2017-08-30 09:29:48 -0700 | [diff] [blame] | 330 | mTimestampPosition.set(getFramesWritten()); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 331 | mFramesWritten.reset32(); |
Phil Burk | 7328a80 | 2017-08-30 09:29:48 -0700 | [diff] [blame] | 332 | mTimestampPosition.reset32(); |
Phil Burk | 965650e | 2017-09-07 21:00:09 -0700 | [diff] [blame] | 333 | mAudioTrack->stop(); |
Phil Burk | 9e9a95b | 2018-01-18 12:14:15 -0800 | [diff] [blame] | 334 | mCallbackEnabled.store(false); |
Phil Burk | 134f197 | 2017-12-08 13:06:11 -0800 | [diff] [blame] | 335 | return checkForDisconnectRequest(false);; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 336 | } |
| 337 | |
Phil Burk | 0befec6 | 2017-07-28 15:12:13 -0700 | [diff] [blame] | 338 | aaudio_result_t AudioStreamTrack::updateStateMachine() |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 339 | { |
| 340 | status_t err; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 341 | aaudio_wrapping_frames_t position; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 342 | switch (getState()) { |
| 343 | // TODO add better state visibility to AudioTrack |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 344 | case AAUDIO_STREAM_STATE_STARTING: |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 345 | if (mAudioTrack->hasStarted()) { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 346 | setState(AAUDIO_STREAM_STATE_STARTED); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 347 | } |
| 348 | break; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 349 | case AAUDIO_STREAM_STATE_PAUSING: |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 350 | if (mAudioTrack->stopped()) { |
| 351 | err = mAudioTrack->getPosition(&position); |
| 352 | if (err != OK) { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 353 | return AAudioConvert_androidToAAudioResult(err); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 354 | } else if (position == mPositionWhenPausing) { |
| 355 | // Has stream really stopped advancing? |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 356 | setState(AAUDIO_STREAM_STATE_PAUSED); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 357 | } |
| 358 | mPositionWhenPausing = position; |
| 359 | } |
| 360 | break; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 361 | case AAUDIO_STREAM_STATE_FLUSHING: |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 362 | { |
| 363 | err = mAudioTrack->getPosition(&position); |
| 364 | if (err != OK) { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 365 | return AAudioConvert_androidToAAudioResult(err); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 366 | } else if (position == 0) { |
Phil Burk | 5204d31 | 2017-05-04 17:16:13 -0700 | [diff] [blame] | 367 | // TODO Advance frames read to match written. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 368 | setState(AAUDIO_STREAM_STATE_FLUSHED); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | break; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 372 | case AAUDIO_STREAM_STATE_STOPPING: |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 373 | if (mAudioTrack->stopped()) { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 374 | setState(AAUDIO_STREAM_STATE_STOPPED); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 375 | } |
| 376 | break; |
| 377 | default: |
| 378 | break; |
| 379 | } |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 380 | return AAUDIO_OK; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 381 | } |
| 382 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 383 | aaudio_result_t AudioStreamTrack::write(const void *buffer, |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 384 | int32_t numFrames, |
| 385 | int64_t timeoutNanoseconds) |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 386 | { |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 387 | int32_t bytesPerFrame = getBytesPerFrame(); |
| 388 | int32_t numBytes; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 389 | aaudio_result_t result = AAudioConvert_framesToBytes(numFrames, bytesPerFrame, &numBytes); |
| 390 | if (result != AAUDIO_OK) { |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 391 | return result; |
| 392 | } |
| 393 | |
Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 394 | if (getState() == AAUDIO_STREAM_STATE_DISCONNECTED) { |
| 395 | return AAUDIO_ERROR_DISCONNECTED; |
| 396 | } |
| 397 | |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 398 | // TODO add timeout to AudioTrack |
| 399 | bool blocking = timeoutNanoseconds > 0; |
| 400 | ssize_t bytesWritten = mAudioTrack->write(buffer, numBytes, blocking); |
| 401 | if (bytesWritten == WOULD_BLOCK) { |
| 402 | return 0; |
| 403 | } else if (bytesWritten < 0) { |
| 404 | ALOGE("invalid write, returned %d", (int)bytesWritten); |
Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 405 | // in this context, a DEAD_OBJECT is more likely to be a disconnect notification due to |
| 406 | // AudioTrack invalidation |
| 407 | if (bytesWritten == DEAD_OBJECT) { |
| 408 | setState(AAUDIO_STREAM_STATE_DISCONNECTED); |
| 409 | return AAUDIO_ERROR_DISCONNECTED; |
| 410 | } |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 411 | return AAudioConvert_androidToAAudioResult(bytesWritten); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 412 | } |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 413 | int32_t framesWritten = (int32_t)(bytesWritten / bytesPerFrame); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 414 | incrementFramesWritten(framesWritten); |
Phil Burk | 0befec6 | 2017-07-28 15:12:13 -0700 | [diff] [blame] | 415 | |
| 416 | result = updateStateMachine(); |
| 417 | if (result != AAUDIO_OK) { |
| 418 | return result; |
| 419 | } |
| 420 | |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 421 | return framesWritten; |
| 422 | } |
| 423 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 424 | aaudio_result_t AudioStreamTrack::setBufferSize(int32_t requestedFrames) |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 425 | { |
| 426 | ssize_t result = mAudioTrack->setBufferSizeInFrames(requestedFrames); |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 427 | if (result < 0) { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 428 | return AAudioConvert_androidToAAudioResult(result); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 429 | } else { |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 430 | return result; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 434 | int32_t AudioStreamTrack::getBufferSize() const |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 435 | { |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 436 | return static_cast<int32_t>(mAudioTrack->getBufferSizeInFrames()); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 437 | } |
| 438 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 439 | int32_t AudioStreamTrack::getBufferCapacity() const |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 440 | { |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 441 | return static_cast<int32_t>(mAudioTrack->frameCount()); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | int32_t AudioStreamTrack::getXRunCount() const |
| 445 | { |
| 446 | return static_cast<int32_t>(mAudioTrack->getUnderrunCount()); |
| 447 | } |
| 448 | |
| 449 | int32_t AudioStreamTrack::getFramesPerBurst() const |
| 450 | { |
Phil Burk | b588402 | 2017-03-27 15:26:14 -0700 | [diff] [blame] | 451 | return static_cast<int32_t>(mAudioTrack->getNotificationPeriodInFrames()); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 452 | } |
| 453 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 454 | int64_t AudioStreamTrack::getFramesRead() { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 455 | aaudio_wrapping_frames_t position; |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 456 | status_t result; |
| 457 | switch (getState()) { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 458 | case AAUDIO_STREAM_STATE_STARTING: |
| 459 | case AAUDIO_STREAM_STATE_STARTED: |
| 460 | case AAUDIO_STREAM_STATE_STOPPING: |
Phil Burk | 4c5129b | 2017-04-28 15:17:32 -0700 | [diff] [blame] | 461 | case AAUDIO_STREAM_STATE_PAUSING: |
| 462 | case AAUDIO_STREAM_STATE_PAUSED: |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 463 | result = mAudioTrack->getPosition(&position); |
| 464 | if (result == OK) { |
| 465 | mFramesRead.update32(position); |
| 466 | } |
| 467 | break; |
| 468 | default: |
| 469 | break; |
| 470 | } |
Phil Burk | ec89b2e | 2017-06-20 15:05:06 -0700 | [diff] [blame] | 471 | return AudioStreamLegacy::getFramesRead(); |
Phil Burk | e1ce491 | 2016-11-21 10:40:25 -0800 | [diff] [blame] | 472 | } |
Phil Burk | 35e80f3 | 2017-03-28 10:25:21 -0700 | [diff] [blame] | 473 | |
| 474 | aaudio_result_t AudioStreamTrack::getTimestamp(clockid_t clockId, |
| 475 | int64_t *framePosition, |
| 476 | int64_t *timeNanoseconds) { |
| 477 | ExtendedTimestamp extendedTimestamp; |
| 478 | status_t status = mAudioTrack->getTimestamp(&extendedTimestamp); |
Phil Burk | c75d97f | 2017-09-08 15:48:36 -0700 | [diff] [blame] | 479 | if (status == WOULD_BLOCK) { |
| 480 | return AAUDIO_ERROR_INVALID_STATE; |
| 481 | } if (status != NO_ERROR) { |
Phil Burk | 35e80f3 | 2017-03-28 10:25:21 -0700 | [diff] [blame] | 482 | return AAudioConvert_androidToAAudioResult(status); |
| 483 | } |
Phil Burk | 7328a80 | 2017-08-30 09:29:48 -0700 | [diff] [blame] | 484 | int64_t position = 0; |
| 485 | int64_t nanoseconds = 0; |
| 486 | aaudio_result_t result = getBestTimestamp(clockId, &position, |
| 487 | &nanoseconds, &extendedTimestamp); |
| 488 | if (result == AAUDIO_OK) { |
| 489 | if (position < getFramesWritten()) { |
| 490 | *framePosition = position; |
| 491 | *timeNanoseconds = nanoseconds; |
| 492 | return result; |
| 493 | } else { |
| 494 | return AAUDIO_ERROR_INVALID_STATE; // TODO review, documented but not consistent |
| 495 | } |
| 496 | } |
| 497 | return result; |
Phil Burk | 35e80f3 | 2017-03-28 10:25:21 -0700 | [diff] [blame] | 498 | } |
Phil Burk | 965650e | 2017-09-07 21:00:09 -0700 | [diff] [blame] | 499 | |
| 500 | status_t AudioStreamTrack::doSetVolume() { |
| 501 | status_t status = NO_INIT; |
| 502 | if (mAudioTrack.get() != nullptr) { |
| 503 | float volume = getDuckAndMuteVolume(); |
| 504 | mAudioTrack->setVolume(volume, volume); |
| 505 | status = NO_ERROR; |
| 506 | } |
| 507 | return status; |
| 508 | } |
| 509 | |
| 510 | #if AAUDIO_USE_VOLUME_SHAPER |
Phil Burk | 8a8a9e5 | 2017-09-12 16:25:15 -0700 | [diff] [blame] | 511 | |
| 512 | using namespace android::media::VolumeShaper; |
| 513 | |
Phil Burk | 965650e | 2017-09-07 21:00:09 -0700 | [diff] [blame] | 514 | binder::Status AudioStreamTrack::applyVolumeShaper( |
| 515 | const VolumeShaper::Configuration& configuration, |
| 516 | const VolumeShaper::Operation& operation) { |
| 517 | |
| 518 | sp<VolumeShaper::Configuration> spConfiguration = new VolumeShaper::Configuration(configuration); |
| 519 | sp<VolumeShaper::Operation> spOperation = new VolumeShaper::Operation(operation); |
| 520 | |
| 521 | if (mAudioTrack.get() != nullptr) { |
| 522 | ALOGD("applyVolumeShaper() from IPlayer"); |
Phil Burk | 8a8a9e5 | 2017-09-12 16:25:15 -0700 | [diff] [blame] | 523 | binder::Status status = mAudioTrack->applyVolumeShaper(spConfiguration, spOperation); |
Phil Burk | 965650e | 2017-09-07 21:00:09 -0700 | [diff] [blame] | 524 | if (status < 0) { // a non-negative value is the volume shaper id. |
| 525 | ALOGE("applyVolumeShaper() failed with status %d", status); |
| 526 | } |
| 527 | return binder::Status::fromStatusT(status); |
| 528 | } else { |
| 529 | ALOGD("applyVolumeShaper()" |
| 530 | " no AudioTrack for volume control from IPlayer"); |
| 531 | return binder::Status::ok(); |
| 532 | } |
| 533 | } |
| 534 | #endif |