blob: 9da48fe02fef68e2a5d27302de4e0fef97ac8e59 [file] [log] [blame]
Kevin Rocard0349c2f2019-09-30 19:53:00 +01001/*
2 * Copyright (C) 2019 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@6.0;
18
19import android.hardware.audio.common@6.0;
20import IStream;
21import IStreamOutCallback;
jiabin5d116122020-02-12 13:05:44 -080022import IStreamOutEventCallback;
Kevin Rocard0349c2f2019-09-30 19:53:00 +010023
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 /**
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
98 * scheduler and cgroup. For this purpose, the method returns identifiers
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.
112 * @return threadInfo identifiers of the driver's dedicated thread.
113 */
114 prepareForWriting(uint32_t frameSize, uint32_t framesCount)
115 generates (
116 Result retval,
117 fmq_sync<WriteCommand> commandMQ,
118 fmq_sync<uint8_t> dataMQ,
119 fmq_sync<WriteStatus> statusMQ,
120 ThreadInfo threadInfo);
121
122 /**
123 * Return the number of audio frames written by the audio DSP to DAC since
124 * the output has exited standby.
125 * Optional method
126 *
127 * @return retval operation completion status.
128 * @return dspFrames number of audio frames written.
129 */
130 getRenderPosition() generates (Result retval, uint32_t dspFrames);
131
132 /**
133 * Get the local time at which the next write to the audio driver will be
134 * presented. The units are microseconds, where the epoch is decided by the
135 * local audio HAL.
136 * Optional method
137 *
138 * @return retval operation completion status.
139 * @return timestampUs time of the next write.
140 */
141 getNextWriteTimestamp() generates (Result retval, int64_t timestampUs);
142
143 /**
144 * Set the callback interface for notifying completion of non-blocking
145 * write and drain.
146 *
147 * Calling this function implies that all future 'write' and 'drain'
148 * must be non-blocking and use the callback to signal completion.
149 *
150 * 'clearCallback' method needs to be called in order to release the local
151 * callback proxy on the server side and thus dereference the callback
152 * implementation on the client side.
153 *
154 * @return retval operation completion status.
155 */
156 setCallback(IStreamOutCallback callback) generates (Result retval);
157
158 /**
159 * Clears the callback previously set via 'setCallback' method.
160 *
161 * Warning: failure to call this method results in callback implementation
162 * on the client side being held until the HAL server termination.
163 *
164 * If no callback was previously set, the method should be a no-op
165 * and return OK.
166 *
167 * @return retval operation completion status: OK or NOT_SUPPORTED.
168 */
169 clearCallback() generates (Result retval);
170
171 /**
jiabin5d116122020-02-12 13:05:44 -0800172 * Set the callback interface for notifying about an output stream event.
173 *
174 * Calling this method with a null pointer will result in releasing
175 * the local callback proxy on the server side and thus dereference
176 * the callback implementation on the client side.
177 *
178 * @return retval operation completion status.
179 */
180 setEventCallback(IStreamOutEventCallback callback)
181 generates (Result retval);
182
183 /**
Kevin Rocard0349c2f2019-09-30 19:53:00 +0100184 * Returns whether HAL supports pausing and resuming of streams.
185 *
186 * @return supportsPause true if pausing is supported.
187 * @return supportsResume true if resume is supported.
188 */
189 supportsPauseAndResume()
190 generates (bool supportsPause, bool supportsResume);
191
192 /**
193 * Notifies to the audio driver to stop playback however the queued buffers
194 * are retained by the hardware. Useful for implementing pause/resume. Empty
195 * implementation if not supported however must be implemented for hardware
196 * with non-trivial latency. In the pause state, some audio hardware may
197 * still be using power. Client code may consider calling 'suspend' after a
198 * timeout to prevent that excess power usage.
199 *
200 * Implementation of this function is mandatory for offloaded playback.
201 *
202 * @return retval operation completion status.
203 */
204 pause() generates (Result retval);
205
206 /**
207 * Notifies to the audio driver to resume playback following a pause.
208 * Returns error INVALID_STATE if called without matching pause.
209 *
210 * Implementation of this function is mandatory for offloaded playback.
211 *
212 * @return retval operation completion status.
213 */
214 resume() generates (Result retval);
215
216 /**
217 * Returns whether HAL supports draining of streams.
218 *
219 * @return supports true if draining is supported.
220 */
221 supportsDrain() generates (bool supports);
222
223 /**
224 * Requests notification when data buffered by the driver/hardware has been
225 * played. If 'setCallback' has previously been called to enable
226 * non-blocking mode, then 'drain' must not block, instead it must return
227 * quickly and completion of the drain is notified through the callback. If
228 * 'setCallback' has not been called, then 'drain' must block until
229 * completion.
230 *
231 * If 'type' is 'ALL', the drain completes when all previously written data
232 * has been played.
233 *
234 * If 'type' is 'EARLY_NOTIFY', the drain completes shortly before all data
235 * for the current track has played to allow time for the framework to
236 * perform a gapless track switch.
237 *
238 * Drain must return immediately on 'stop' and 'flush' calls.
239 *
240 * Implementation of this function is mandatory for offloaded playback.
241 *
242 * @param type type of drain.
243 * @return retval operation completion status.
244 */
245 drain(AudioDrain type) generates (Result retval);
246
247 /**
248 * Notifies to the audio driver to flush the queued data. Stream must
249 * already be paused before calling 'flush'.
250 * Optional method
251 *
252 * Implementation of this function is mandatory for offloaded playback.
253 *
254 * @return retval operation completion status.
255 */
256 flush() generates (Result retval);
257
258 /**
259 * Return a recent count of the number of audio frames presented to an
260 * external observer. This excludes frames which have been written but are
261 * still in the pipeline. The count is not reset to zero when output enters
262 * standby. Also returns the value of CLOCK_MONOTONIC as of this
263 * presentation count. The returned count is expected to be 'recent', but
264 * does not need to be the most recent possible value. However, the
265 * associated time must correspond to whatever count is returned.
266 *
267 * Example: assume that N+M frames have been presented, where M is a 'small'
268 * number. Then it is permissible to return N instead of N+M, and the
269 * timestamp must correspond to N rather than N+M. The terms 'recent' and
270 * 'small' are not defined. They reflect the quality of the implementation.
271 *
272 * Optional method
273 *
274 * @return retval operation completion status.
275 * @return frames count of presented audio frames.
276 * @return timeStamp associated clock time.
277 */
278 getPresentationPosition()
279 generates (Result retval, uint64_t frames, TimeSpec timeStamp);
280
281 /**
282 * Selects a presentation for decoding from a next generation media stream
283 * (as defined per ETSI TS 103 190-2) and a program within the presentation.
284 * Optional method
285 *
286 * @param presentationId selected audio presentation.
287 * @param programId refinement for the presentation.
288 * @return retval operation completion status.
289 */
290 selectPresentation(int32_t presentationId, int32_t programId)
291 generates (Result retval);
Mikhail Naganov0a675fc2020-02-14 17:13:52 -0800292
293 /**
294 * Returns the Dual Mono mode presentation setting.
295 *
296 * Optional method
297 *
298 * @return retval operation completion status.
299 * @return mode current setting of Dual Mono mode.
300 */
301 getDualMonoMode() generates (Result retval, DualMonoMode mode);
302
303 /**
304 * Sets the Dual Mono mode presentation on the output device.
305 *
306 * The Dual Mono mode is generally applied to stereo audio streams
307 * where the left and right channels come from separate sources.
308 *
309 * Optional method
310 *
311 * @param mode selected Dual Mono mode.
312 * @return retval operation completion status.
313 */
314 setDualMonoMode(DualMonoMode mode) generates (Result retval);
315
316 /**
317 * Returns the Audio Description Mix level in dB.
318 *
319 * The level is applied to streams incorporating a secondary Audio
320 * Description stream. It specifies the relative level of mixing for
321 * the Audio Description with a reference to the Main Audio.
322 *
323 * Optional method
324 *
325 * The value of the relative level is in the range from negative infinity
326 * to +48.
327 *
328 * @return retval operation completion status.
329 * @return leveldB the current Audio Description Mix Level in dB.
330 */
331 getAudioDescriptionMixLevel() generates (Result retval, float leveldB);
332
333 /**
334 * Sets the Audio Description Mix level in dB.
335 *
336 * For streams incorporating a secondary Audio Description stream
337 * the relative level of mixing of the Audio Description to the Main Audio
338 * is controlled by this method.
339 *
340 * Optional method
341 *
342 * The value of the relative level must be in the range from negative
343 * infinity to +48.
344 *
345 * @param leveldB Audio Description Mix Level in dB
346 * @return retval operation completion status.
347 */
348 setAudioDescriptionMixLevel(float leveldB) generates (Result retval);
Mikhail Naganov973e4d32020-02-19 10:50:50 -0800349
350 /**
351 * Retrieves current playback rate parameters.
352 *
353 * Optional method
354 *
355 * @return retval operation completion status.
356 * @return playbackRate current playback parameters
357 */
358 getPlaybackRateParameters()
359 generates (Result retval, PlaybackRate playbackRate);
360
361 /**
362 * Sets the playback rate parameters that control playback behavior.
363 * This is normally used when playing encoded content and decoding
364 * is performed in hardware. Otherwise, the framework can apply
365 * necessary transformations.
366 *
367 * Optional method
368 *
369 * If the HAL supports setting the playback rate, it is recommended
370 * to support speed and pitch values at least in the range
371 * from 0.5f to 2.0f, inclusive (see the definition of PlaybackRate struct).
372 *
373 * @param playbackRate playback parameters
374 * @return retval operation completion status.
375 */
376 setPlaybackRateParameters(PlaybackRate playbackRate)
377 generates (Result retval);
Kevin Rocard0349c2f2019-09-30 19:53:00 +0100378};