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