Mikhail Naganov | 60ced76 | 2020-07-23 18:08:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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 | |
| 17 | package android.hardware.audio@7.0; |
| 18 | |
| 19 | import android.hardware.audio.common@7.0; |
| 20 | import IStream; |
| 21 | import IStreamOutCallback; |
| 22 | import IStreamOutEventCallback; |
| 23 | |
| 24 | interface IStreamOut extends IStream { |
| 25 | /** |
| 26 | * Return the audio hardware driver estimated latency in milliseconds. |
| 27 | * |
| 28 | * @return latencyMs latency in milliseconds. |
| 29 | */ |
| 30 | getLatency() generates (uint32_t latencyMs); |
| 31 | |
| 32 | /** |
| 33 | * This method is used in situations where audio mixing is done in the |
| 34 | * hardware. This method serves as a direct interface with hardware, |
| 35 | * allowing to directly set the volume as apposed to via the framework. |
| 36 | * This method might produce multiple PCM outputs or hardware accelerated |
| 37 | * codecs, such as MP3 or AAC. |
| 38 | * Optional method |
| 39 | * |
| 40 | * @param left left channel attenuation, 1.0f is unity, 0.0f is zero. |
| 41 | * @param right right channel attenuation, 1.0f is unity, 0.0f is zero. |
| 42 | * @return retval operation completion status. |
| 43 | * If a volume is outside [0,1], return INVALID_ARGUMENTS |
| 44 | */ |
| 45 | setVolume(float left, float right) generates (Result retval); |
| 46 | |
| 47 | /** |
| 48 | * Commands that can be executed on the driver writer thread. |
| 49 | */ |
| 50 | enum WriteCommand : int32_t { |
| 51 | WRITE, |
| 52 | GET_PRESENTATION_POSITION, |
| 53 | GET_LATENCY |
| 54 | }; |
| 55 | |
| 56 | /** |
| 57 | * Data structure passed back to the client via status message queue |
| 58 | * of 'write' operation. |
| 59 | * |
| 60 | * Possible values of 'retval' field: |
| 61 | * - OK, write operation was successful; |
| 62 | * - INVALID_ARGUMENTS, stream was not configured properly; |
| 63 | * - INVALID_STATE, stream is in a state that doesn't allow writes; |
| 64 | * - INVALID_OPERATION, retrieving presentation position isn't supported. |
| 65 | */ |
| 66 | struct WriteStatus { |
| 67 | Result retval; |
| 68 | WriteCommand replyTo; // discriminator |
| 69 | union Reply { |
| 70 | uint64_t written; // WRITE command, amount of bytes written, >= 0. |
| 71 | struct PresentationPosition { // same as generated by |
| 72 | uint64_t frames; // getPresentationPosition. |
| 73 | TimeSpec timeStamp; |
| 74 | } presentationPosition; |
| 75 | uint32_t latencyMs; // Same as generated by getLatency. |
| 76 | } reply; |
| 77 | }; |
| 78 | |
| 79 | /** |
| 80 | * Called when the metadata of the stream's source has been changed. |
| 81 | * @param sourceMetadata Description of the audio that is played by the clients. |
| 82 | */ |
| 83 | updateSourceMetadata(SourceMetadata sourceMetadata); |
| 84 | |
| 85 | /** |
| 86 | * Set up required transports for passing audio buffers to the driver. |
| 87 | * |
| 88 | * The transport consists of three message queues: |
| 89 | * -- command queue is used to instruct the writer thread what operation |
| 90 | * to perform; |
| 91 | * -- data queue is used for passing audio data from the client |
| 92 | * to the driver; |
| 93 | * -- status queue is used for reporting operation status |
| 94 | * (e.g. amount of bytes actually written or error code). |
| 95 | * |
| 96 | * The driver operates on a dedicated thread. The client must ensure that |
| 97 | * the thread is given an appropriate priority and assigned to correct |
Mikhail Naganov | fda2042 | 2020-08-04 23:37:05 +0000 | [diff] [blame] | 98 | * scheduler and cgroup. For this purpose, the method returns the identifier |
Mikhail Naganov | 60ced76 | 2020-07-23 18:08:26 +0000 | [diff] [blame] | 99 | * of the driver thread. |
| 100 | * |
| 101 | * @param frameSize the size of a single frame, in bytes. |
| 102 | * @param framesCount the number of frames in a buffer. |
| 103 | * @return retval OK if both message queues were created successfully. |
| 104 | * INVALID_STATE if the method was already called. |
| 105 | * INVALID_ARGUMENTS if there was a problem setting up |
| 106 | * the queues. |
| 107 | * @return commandMQ a message queue used for passing commands. |
| 108 | * @return dataMQ a message queue used for passing audio data in the format |
| 109 | * specified at the stream opening. |
| 110 | * @return statusMQ a message queue used for passing status from the driver |
| 111 | * using WriteStatus structures. |
Mikhail Naganov | fda2042 | 2020-08-04 23:37:05 +0000 | [diff] [blame] | 112 | * @return threadId identifier of the driver's dedicated thread; the caller |
| 113 | * may adjust the thread priority to match the priority |
| 114 | * of the thread that provides audio data. |
Mikhail Naganov | 60ced76 | 2020-07-23 18:08:26 +0000 | [diff] [blame] | 115 | */ |
| 116 | prepareForWriting(uint32_t frameSize, uint32_t framesCount) |
| 117 | generates ( |
| 118 | Result retval, |
| 119 | fmq_sync<WriteCommand> commandMQ, |
| 120 | fmq_sync<uint8_t> dataMQ, |
| 121 | fmq_sync<WriteStatus> statusMQ, |
Mikhail Naganov | fda2042 | 2020-08-04 23:37:05 +0000 | [diff] [blame] | 122 | int32_t threadId); |
Mikhail Naganov | 60ced76 | 2020-07-23 18:08:26 +0000 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * Return the number of audio frames written by the audio DSP to DAC since |
| 126 | * the output has exited standby. |
| 127 | * Optional method |
| 128 | * |
| 129 | * @return retval operation completion status. |
| 130 | * @return dspFrames number of audio frames written. |
| 131 | */ |
| 132 | getRenderPosition() generates (Result retval, uint32_t dspFrames); |
| 133 | |
| 134 | /** |
| 135 | * Get the local time at which the next write to the audio driver will be |
| 136 | * presented. The units are microseconds, where the epoch is decided by the |
| 137 | * local audio HAL. |
| 138 | * Optional method |
| 139 | * |
| 140 | * @return retval operation completion status. |
| 141 | * @return timestampUs time of the next write. |
| 142 | */ |
| 143 | getNextWriteTimestamp() generates (Result retval, int64_t timestampUs); |
| 144 | |
| 145 | /** |
| 146 | * Set the callback interface for notifying completion of non-blocking |
| 147 | * write and drain. |
| 148 | * |
| 149 | * Calling this function implies that all future 'write' and 'drain' |
| 150 | * must be non-blocking and use the callback to signal completion. |
| 151 | * |
| 152 | * 'clearCallback' method needs to be called in order to release the local |
| 153 | * callback proxy on the server side and thus dereference the callback |
| 154 | * implementation on the client side. |
| 155 | * |
| 156 | * @return retval operation completion status. |
| 157 | */ |
| 158 | setCallback(IStreamOutCallback callback) generates (Result retval); |
| 159 | |
| 160 | /** |
| 161 | * Clears the callback previously set via 'setCallback' method. |
| 162 | * |
| 163 | * Warning: failure to call this method results in callback implementation |
| 164 | * on the client side being held until the HAL server termination. |
| 165 | * |
| 166 | * If no callback was previously set, the method should be a no-op |
| 167 | * and return OK. |
| 168 | * |
| 169 | * @return retval operation completion status: OK or NOT_SUPPORTED. |
| 170 | */ |
| 171 | clearCallback() generates (Result retval); |
| 172 | |
| 173 | /** |
| 174 | * Set the callback interface for notifying about an output stream event. |
| 175 | * |
| 176 | * Calling this method with a null pointer will result in releasing |
| 177 | * the local callback proxy on the server side and thus dereference |
| 178 | * the callback implementation on the client side. |
| 179 | * |
| 180 | * @return retval operation completion status. |
| 181 | */ |
| 182 | setEventCallback(IStreamOutEventCallback callback) |
| 183 | generates (Result retval); |
| 184 | |
| 185 | /** |
| 186 | * Returns whether HAL supports pausing and resuming of streams. |
| 187 | * |
| 188 | * @return supportsPause true if pausing is supported. |
| 189 | * @return supportsResume true if resume is supported. |
| 190 | */ |
| 191 | supportsPauseAndResume() |
| 192 | generates (bool supportsPause, bool supportsResume); |
| 193 | |
| 194 | /** |
| 195 | * Notifies to the audio driver to stop playback however the queued buffers |
| 196 | * are retained by the hardware. Useful for implementing pause/resume. Empty |
| 197 | * implementation if not supported however must be implemented for hardware |
| 198 | * with non-trivial latency. In the pause state, some audio hardware may |
| 199 | * still be using power. Client code may consider calling 'suspend' after a |
| 200 | * timeout to prevent that excess power usage. |
| 201 | * |
| 202 | * Implementation of this function is mandatory for offloaded playback. |
| 203 | * |
| 204 | * @return retval operation completion status. |
| 205 | */ |
| 206 | pause() generates (Result retval); |
| 207 | |
| 208 | /** |
| 209 | * Notifies to the audio driver to resume playback following a pause. |
| 210 | * Returns error INVALID_STATE if called without matching pause. |
| 211 | * |
| 212 | * Implementation of this function is mandatory for offloaded playback. |
| 213 | * |
| 214 | * @return retval operation completion status. |
| 215 | */ |
| 216 | resume() generates (Result retval); |
| 217 | |
| 218 | /** |
| 219 | * Returns whether HAL supports draining of streams. |
| 220 | * |
| 221 | * @return supports true if draining is supported. |
| 222 | */ |
| 223 | supportsDrain() generates (bool supports); |
| 224 | |
| 225 | /** |
| 226 | * Requests notification when data buffered by the driver/hardware has been |
| 227 | * played. If 'setCallback' has previously been called to enable |
| 228 | * non-blocking mode, then 'drain' must not block, instead it must return |
| 229 | * quickly and completion of the drain is notified through the callback. If |
| 230 | * 'setCallback' has not been called, then 'drain' must block until |
| 231 | * completion. |
| 232 | * |
| 233 | * If 'type' is 'ALL', the drain completes when all previously written data |
| 234 | * has been played. |
| 235 | * |
| 236 | * If 'type' is 'EARLY_NOTIFY', the drain completes shortly before all data |
| 237 | * for the current track has played to allow time for the framework to |
| 238 | * perform a gapless track switch. |
| 239 | * |
| 240 | * Drain must return immediately on 'stop' and 'flush' calls. |
| 241 | * |
| 242 | * Implementation of this function is mandatory for offloaded playback. |
| 243 | * |
| 244 | * @param type type of drain. |
| 245 | * @return retval operation completion status. |
| 246 | */ |
| 247 | drain(AudioDrain type) generates (Result retval); |
| 248 | |
| 249 | /** |
| 250 | * Notifies to the audio driver to flush the queued data. Stream must |
| 251 | * already be paused before calling 'flush'. |
| 252 | * Optional method |
| 253 | * |
| 254 | * Implementation of this function is mandatory for offloaded playback. |
| 255 | * |
| 256 | * @return retval operation completion status. |
| 257 | */ |
| 258 | flush() generates (Result retval); |
| 259 | |
| 260 | /** |
| 261 | * Return a recent count of the number of audio frames presented to an |
| 262 | * external observer. This excludes frames which have been written but are |
| 263 | * still in the pipeline. The count is not reset to zero when output enters |
| 264 | * standby. Also returns the value of CLOCK_MONOTONIC as of this |
| 265 | * presentation count. The returned count is expected to be 'recent', but |
| 266 | * does not need to be the most recent possible value. However, the |
| 267 | * associated time must correspond to whatever count is returned. |
| 268 | * |
| 269 | * Example: assume that N+M frames have been presented, where M is a 'small' |
| 270 | * number. Then it is permissible to return N instead of N+M, and the |
| 271 | * timestamp must correspond to N rather than N+M. The terms 'recent' and |
| 272 | * 'small' are not defined. They reflect the quality of the implementation. |
| 273 | * |
| 274 | * Optional method |
| 275 | * |
| 276 | * @return retval operation completion status. |
| 277 | * @return frames count of presented audio frames. |
| 278 | * @return timeStamp associated clock time. |
| 279 | */ |
| 280 | getPresentationPosition() |
| 281 | generates (Result retval, uint64_t frames, TimeSpec timeStamp); |
| 282 | |
| 283 | /** |
| 284 | * Selects a presentation for decoding from a next generation media stream |
| 285 | * (as defined per ETSI TS 103 190-2) and a program within the presentation. |
| 286 | * Optional method |
| 287 | * |
| 288 | * @param presentationId selected audio presentation. |
| 289 | * @param programId refinement for the presentation. |
| 290 | * @return retval operation completion status. |
| 291 | */ |
| 292 | selectPresentation(int32_t presentationId, int32_t programId) |
| 293 | generates (Result retval); |
| 294 | |
| 295 | /** |
| 296 | * Returns the Dual Mono mode presentation setting. |
| 297 | * |
| 298 | * Optional method |
| 299 | * |
| 300 | * @return retval operation completion status. |
| 301 | * @return mode current setting of Dual Mono mode. |
| 302 | */ |
| 303 | getDualMonoMode() generates (Result retval, DualMonoMode mode); |
| 304 | |
| 305 | /** |
| 306 | * Sets the Dual Mono mode presentation on the output device. |
| 307 | * |
| 308 | * The Dual Mono mode is generally applied to stereo audio streams |
| 309 | * where the left and right channels come from separate sources. |
| 310 | * |
| 311 | * Optional method |
| 312 | * |
| 313 | * @param mode selected Dual Mono mode. |
| 314 | * @return retval operation completion status. |
| 315 | */ |
| 316 | setDualMonoMode(DualMonoMode mode) generates (Result retval); |
| 317 | |
| 318 | /** |
| 319 | * Returns the Audio Description Mix level in dB. |
| 320 | * |
| 321 | * The level is applied to streams incorporating a secondary Audio |
| 322 | * Description stream. It specifies the relative level of mixing for |
| 323 | * the Audio Description with a reference to the Main Audio. |
| 324 | * |
| 325 | * Optional method |
| 326 | * |
| 327 | * The value of the relative level is in the range from negative infinity |
| 328 | * to +48. |
| 329 | * |
| 330 | * @return retval operation completion status. |
| 331 | * @return leveldB the current Audio Description Mix Level in dB. |
| 332 | */ |
| 333 | getAudioDescriptionMixLevel() generates (Result retval, float leveldB); |
| 334 | |
| 335 | /** |
| 336 | * Sets the Audio Description Mix level in dB. |
| 337 | * |
| 338 | * For streams incorporating a secondary Audio Description stream |
| 339 | * the relative level of mixing of the Audio Description to the Main Audio |
| 340 | * is controlled by this method. |
| 341 | * |
| 342 | * Optional method |
| 343 | * |
| 344 | * The value of the relative level must be in the range from negative |
| 345 | * infinity to +48. |
| 346 | * |
| 347 | * @param leveldB Audio Description Mix Level in dB |
| 348 | * @return retval operation completion status. |
| 349 | */ |
| 350 | setAudioDescriptionMixLevel(float leveldB) generates (Result retval); |
| 351 | |
| 352 | /** |
| 353 | * Retrieves current playback rate parameters. |
| 354 | * |
| 355 | * Optional method |
| 356 | * |
| 357 | * @return retval operation completion status. |
| 358 | * @return playbackRate current playback parameters |
| 359 | */ |
| 360 | getPlaybackRateParameters() |
| 361 | generates (Result retval, PlaybackRate playbackRate); |
| 362 | |
| 363 | /** |
| 364 | * Sets the playback rate parameters that control playback behavior. |
| 365 | * This is normally used when playing encoded content and decoding |
| 366 | * is performed in hardware. Otherwise, the framework can apply |
| 367 | * necessary transformations. |
| 368 | * |
| 369 | * Optional method |
| 370 | * |
| 371 | * If the HAL supports setting the playback rate, it is recommended |
| 372 | * to support speed and pitch values at least in the range |
| 373 | * from 0.5f to 2.0f, inclusive (see the definition of PlaybackRate struct). |
| 374 | * |
| 375 | * @param playbackRate playback parameters |
| 376 | * @return retval operation completion status. |
| 377 | */ |
| 378 | setPlaybackRateParameters(PlaybackRate playbackRate) |
| 379 | generates (Result retval); |
| 380 | }; |