blob: 585bffed66973fba8956b34ad279473f4ab14748 [file] [log] [blame]
Kevin Rocarda4e6d8b2018-01-20 21:52:01 -08001/*
2 * Copyright (C) 2018 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@4.0;
18
19import android.hardware.audio.common@4.0;
20import IStream;
21import IStreamOutCallback;
22
23interface IStreamOut extends IStream {
24 typedef android.hardware.audio@4.0::Result Result;
25
26 /**
27 * Return the audio hardware driver estimated latency in milliseconds.
28 *
29 * @return latencyMs latency in milliseconds.
30 */
31 getLatency() generates (uint32_t latencyMs);
32
33 /**
34 * This method is used in situations where audio mixing is done in the
35 * hardware. This method serves as a direct interface with hardware,
36 * allowing to directly set the volume as apposed to via the framework.
37 * This method might produce multiple PCM outputs or hardware accelerated
38 * codecs, such as MP3 or AAC.
Kevin Rocard74980b52018-01-20 22:12:57 -080039 * Optional method
Kevin Rocarda4e6d8b2018-01-20 21:52:01 -080040 *
41 * @param left left channel attenuation, 1.0f is unity, 0.0f is zero.
42 * @param right right channel attenuation, 1.0f is unity, 0.0f is zero.
43 * @return retval operation completion status.
Kevin Rocard74980b52018-01-20 22:12:57 -080044 * If a volume is outside [0,1], return INVALID_ARGUMENTS
Kevin Rocarda4e6d8b2018-01-20 21:52:01 -080045 */
46 setVolume(float left, float right) generates (Result retval);
47
48 /**
49 * Commands that can be executed on the driver writer thread.
50 */
51 enum WriteCommand : int32_t {
52 WRITE,
53 GET_PRESENTATION_POSITION,
54 GET_LATENCY
55 };
56
57 /**
58 * Data structure passed back to the client via status message queue
59 * of 'write' operation.
60 *
61 * Possible values of 'retval' field:
62 * - OK, write operation was successful;
63 * - INVALID_ARGUMENTS, stream was not configured properly;
64 * - INVALID_STATE, stream is in a state that doesn't allow writes;
65 * - INVALID_OPERATION, retrieving presentation position isn't supported.
66 */
67 struct WriteStatus {
68 Result retval;
69 WriteCommand replyTo; // discriminator
70 union Reply {
71 uint64_t written; // WRITE command, amount of bytes written, >= 0.
72 struct PresentationPosition { // same as generated by
73 uint64_t frames; // getPresentationPosition.
74 TimeSpec timeStamp;
75 } presentationPosition;
76 uint32_t latencyMs; // Same as generated by getLatency.
77 } reply;
78 };
79
80 /**
Kevin Rocard14dbb1e2018-01-24 19:12:06 -080081 * Called when the metadata of the stream's source has been changed.
82 * @param sourceMetadata Description of the audio that is played by the clients.
83 */
84 updateSourceMetadata(SourceMetadata sourceMetadata);
85
86 /**
Kevin Rocarda4e6d8b2018-01-20 21:52:01 -080087 * Set up required transports for passing audio buffers to the driver.
88 *
89 * The transport consists of three message queues:
90 * -- command queue is used to instruct the writer thread what operation
91 * to perform;
92 * -- data queue is used for passing audio data from the client
93 * to the driver;
94 * -- status queue is used for reporting operation status
95 * (e.g. amount of bytes actually written or error code).
96 *
97 * The driver operates on a dedicated thread. The client must ensure that
98 * the thread is given an appropriate priority and assigned to correct
99 * scheduler and cgroup. For this purpose, the method returns identifiers
100 * of the driver thread.
101 *
102 * @param frameSize the size of a single frame, in bytes.
103 * @param framesCount the number of frames in a buffer.
104 * @return retval OK if both message queues were created successfully.
105 * INVALID_STATE if the method was already called.
106 * INVALID_ARGUMENTS if there was a problem setting up
107 * the queues.
108 * @return commandMQ a message queue used for passing commands.
109 * @return dataMQ a message queue used for passing audio data in the format
110 * specified at the stream opening.
111 * @return statusMQ a message queue used for passing status from the driver
112 * using WriteStatus structures.
113 * @return threadInfo identifiers of the driver's dedicated thread.
114 */
115 prepareForWriting(uint32_t frameSize, uint32_t framesCount)
116 generates (
117 Result retval,
118 fmq_sync<WriteCommand> commandMQ,
119 fmq_sync<uint8_t> dataMQ,
120 fmq_sync<WriteStatus> statusMQ,
121 ThreadInfo threadInfo);
122
123 /**
124 * Return the number of audio frames written by the audio DSP to DAC since
125 * the output has exited standby.
Kevin Rocard74980b52018-01-20 22:12:57 -0800126 * Optional method
Kevin Rocarda4e6d8b2018-01-20 21:52:01 -0800127 *
128 * @return retval operation completion status.
129 * @return dspFrames number of audio frames written.
130 */
131 getRenderPosition() generates (Result retval, uint32_t dspFrames);
132
133 /**
134 * Get the local time at which the next write to the audio driver will be
135 * presented. The units are microseconds, where the epoch is decided by the
136 * local audio HAL.
Kevin Rocard74980b52018-01-20 22:12:57 -0800137 * Optional method
Kevin Rocarda4e6d8b2018-01-20 21:52:01 -0800138 *
139 * @return retval operation completion status.
140 * @return timestampUs time of the next write.
141 */
142 getNextWriteTimestamp() generates (Result retval, int64_t timestampUs);
143
144 /**
145 * Set the callback interface for notifying completion of non-blocking
146 * write and drain.
147 *
148 * Calling this function implies that all future 'write' and 'drain'
149 * must be non-blocking and use the callback to signal completion.
150 *
151 * 'clearCallback' method needs to be called in order to release the local
152 * callback proxy on the server side and thus dereference the callback
153 * implementation on the client side.
154 *
155 * @return retval operation completion status.
156 */
157 setCallback(IStreamOutCallback callback) generates (Result retval);
158
159 /**
160 * Clears the callback previously set via 'setCallback' method.
161 *
162 * Warning: failure to call this method results in callback implementation
163 * on the client side being held until the HAL server termination.
164 *
Kevin Rocard74980b52018-01-20 22:12:57 -0800165 * If no callback was previously set, the method should be a no-op
166 * and return OK.
167 *
Kevin Rocarda4e6d8b2018-01-20 21:52:01 -0800168 * @return retval operation completion status: OK or NOT_SUPPORTED.
169 */
170 clearCallback() generates (Result retval);
171
172 /**
173 * Returns whether HAL supports pausing and resuming of streams.
174 *
175 * @return supportsPause true if pausing is supported.
176 * @return supportsResume true if resume is supported.
177 */
178 supportsPauseAndResume()
179 generates (bool supportsPause, bool supportsResume);
180
181 /**
182 * Notifies to the audio driver to stop playback however the queued buffers
183 * are retained by the hardware. Useful for implementing pause/resume. Empty
184 * implementation if not supported however must be implemented for hardware
185 * with non-trivial latency. In the pause state, some audio hardware may
186 * still be using power. Client code may consider calling 'suspend' after a
187 * timeout to prevent that excess power usage.
188 *
189 * Implementation of this function is mandatory for offloaded playback.
190 *
191 * @return retval operation completion status.
192 */
193 pause() generates (Result retval);
194
195 /**
196 * Notifies to the audio driver to resume playback following a pause.
197 * Returns error INVALID_STATE if called without matching pause.
198 *
199 * Implementation of this function is mandatory for offloaded playback.
200 *
201 * @return retval operation completion status.
202 */
203 resume() generates (Result retval);
204
205 /**
206 * Returns whether HAL supports draining of streams.
207 *
208 * @return supports true if draining is supported.
209 */
210 supportsDrain() generates (bool supports);
211
212 /**
213 * Requests notification when data buffered by the driver/hardware has been
214 * played. If 'setCallback' has previously been called to enable
215 * non-blocking mode, then 'drain' must not block, instead it must return
216 * quickly and completion of the drain is notified through the callback. If
217 * 'setCallback' has not been called, then 'drain' must block until
218 * completion.
219 *
220 * If 'type' is 'ALL', the drain completes when all previously written data
221 * has been played.
222 *
223 * If 'type' is 'EARLY_NOTIFY', the drain completes shortly before all data
224 * for the current track has played to allow time for the framework to
225 * perform a gapless track switch.
226 *
227 * Drain must return immediately on 'stop' and 'flush' calls.
228 *
229 * Implementation of this function is mandatory for offloaded playback.
230 *
231 * @param type type of drain.
232 * @return retval operation completion status.
233 */
234 drain(AudioDrain type) generates (Result retval);
235
236 /**
237 * Notifies to the audio driver to flush the queued data. Stream must
238 * already be paused before calling 'flush'.
Kevin Rocard74980b52018-01-20 22:12:57 -0800239 * Optional method
Kevin Rocarda4e6d8b2018-01-20 21:52:01 -0800240 *
241 * Implementation of this function is mandatory for offloaded playback.
242 *
243 * @return retval operation completion status.
244 */
245 flush() generates (Result retval);
246
247 /**
248 * Return a recent count of the number of audio frames presented to an
249 * external observer. This excludes frames which have been written but are
250 * still in the pipeline. The count is not reset to zero when output enters
251 * standby. Also returns the value of CLOCK_MONOTONIC as of this
252 * presentation count. The returned count is expected to be 'recent', but
253 * does not need to be the most recent possible value. However, the
254 * associated time must correspond to whatever count is returned.
255 *
256 * Example: assume that N+M frames have been presented, where M is a 'small'
257 * number. Then it is permissible to return N instead of N+M, and the
258 * timestamp must correspond to N rather than N+M. The terms 'recent' and
259 * 'small' are not defined. They reflect the quality of the implementation.
260 *
Kevin Rocard74980b52018-01-20 22:12:57 -0800261 * Optional method
262 *
Kevin Rocarda4e6d8b2018-01-20 21:52:01 -0800263 * @return retval operation completion status.
264 * @return frames count of presented audio frames.
265 * @return timeStamp associated clock time.
266 */
267 getPresentationPosition()
268 generates (Result retval, uint64_t frames, TimeSpec timeStamp);
269};