blob: 02f169730ad3482d1ecc562d6788f9a4cb0a7226 [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 /**
81 * Set up required transports for passing audio buffers to the driver.
82 *
83 * The transport consists of three message queues:
84 * -- command queue is used to instruct the writer thread what operation
85 * to perform;
86 * -- data queue is used for passing audio data from the client
87 * to the driver;
88 * -- status queue is used for reporting operation status
89 * (e.g. amount of bytes actually written or error code).
90 *
91 * The driver operates on a dedicated thread. The client must ensure that
92 * the thread is given an appropriate priority and assigned to correct
93 * scheduler and cgroup. For this purpose, the method returns identifiers
94 * of the driver thread.
95 *
96 * @param frameSize the size of a single frame, in bytes.
97 * @param framesCount the number of frames in a buffer.
98 * @return retval OK if both message queues were created successfully.
99 * INVALID_STATE if the method was already called.
100 * INVALID_ARGUMENTS if there was a problem setting up
101 * the queues.
102 * @return commandMQ a message queue used for passing commands.
103 * @return dataMQ a message queue used for passing audio data in the format
104 * specified at the stream opening.
105 * @return statusMQ a message queue used for passing status from the driver
106 * using WriteStatus structures.
107 * @return threadInfo identifiers of the driver's dedicated thread.
108 */
109 prepareForWriting(uint32_t frameSize, uint32_t framesCount)
110 generates (
111 Result retval,
112 fmq_sync<WriteCommand> commandMQ,
113 fmq_sync<uint8_t> dataMQ,
114 fmq_sync<WriteStatus> statusMQ,
115 ThreadInfo threadInfo);
116
117 /**
118 * Return the number of audio frames written by the audio DSP to DAC since
119 * the output has exited standby.
Kevin Rocard74980b52018-01-20 22:12:57 -0800120 * Optional method
Kevin Rocarda4e6d8b2018-01-20 21:52:01 -0800121 *
122 * @return retval operation completion status.
123 * @return dspFrames number of audio frames written.
124 */
125 getRenderPosition() generates (Result retval, uint32_t dspFrames);
126
127 /**
128 * Get the local time at which the next write to the audio driver will be
129 * presented. The units are microseconds, where the epoch is decided by the
130 * local audio HAL.
Kevin Rocard74980b52018-01-20 22:12:57 -0800131 * Optional method
Kevin Rocarda4e6d8b2018-01-20 21:52:01 -0800132 *
133 * @return retval operation completion status.
134 * @return timestampUs time of the next write.
135 */
136 getNextWriteTimestamp() generates (Result retval, int64_t timestampUs);
137
138 /**
139 * Set the callback interface for notifying completion of non-blocking
140 * write and drain.
141 *
142 * Calling this function implies that all future 'write' and 'drain'
143 * must be non-blocking and use the callback to signal completion.
144 *
145 * 'clearCallback' method needs to be called in order to release the local
146 * callback proxy on the server side and thus dereference the callback
147 * implementation on the client side.
148 *
149 * @return retval operation completion status.
150 */
151 setCallback(IStreamOutCallback callback) generates (Result retval);
152
153 /**
154 * Clears the callback previously set via 'setCallback' method.
155 *
156 * Warning: failure to call this method results in callback implementation
157 * on the client side being held until the HAL server termination.
158 *
Kevin Rocard74980b52018-01-20 22:12:57 -0800159 * If no callback was previously set, the method should be a no-op
160 * and return OK.
161 *
Kevin Rocarda4e6d8b2018-01-20 21:52:01 -0800162 * @return retval operation completion status: OK or NOT_SUPPORTED.
163 */
164 clearCallback() generates (Result retval);
165
166 /**
167 * Returns whether HAL supports pausing and resuming of streams.
168 *
169 * @return supportsPause true if pausing is supported.
170 * @return supportsResume true if resume is supported.
171 */
172 supportsPauseAndResume()
173 generates (bool supportsPause, bool supportsResume);
174
175 /**
176 * Notifies to the audio driver to stop playback however the queued buffers
177 * are retained by the hardware. Useful for implementing pause/resume. Empty
178 * implementation if not supported however must be implemented for hardware
179 * with non-trivial latency. In the pause state, some audio hardware may
180 * still be using power. Client code may consider calling 'suspend' after a
181 * timeout to prevent that excess power usage.
182 *
183 * Implementation of this function is mandatory for offloaded playback.
184 *
185 * @return retval operation completion status.
186 */
187 pause() generates (Result retval);
188
189 /**
190 * Notifies to the audio driver to resume playback following a pause.
191 * Returns error INVALID_STATE if called without matching pause.
192 *
193 * Implementation of this function is mandatory for offloaded playback.
194 *
195 * @return retval operation completion status.
196 */
197 resume() generates (Result retval);
198
199 /**
200 * Returns whether HAL supports draining of streams.
201 *
202 * @return supports true if draining is supported.
203 */
204 supportsDrain() generates (bool supports);
205
206 /**
207 * Requests notification when data buffered by the driver/hardware has been
208 * played. If 'setCallback' has previously been called to enable
209 * non-blocking mode, then 'drain' must not block, instead it must return
210 * quickly and completion of the drain is notified through the callback. If
211 * 'setCallback' has not been called, then 'drain' must block until
212 * completion.
213 *
214 * If 'type' is 'ALL', the drain completes when all previously written data
215 * has been played.
216 *
217 * If 'type' is 'EARLY_NOTIFY', the drain completes shortly before all data
218 * for the current track has played to allow time for the framework to
219 * perform a gapless track switch.
220 *
221 * Drain must return immediately on 'stop' and 'flush' calls.
222 *
223 * Implementation of this function is mandatory for offloaded playback.
224 *
225 * @param type type of drain.
226 * @return retval operation completion status.
227 */
228 drain(AudioDrain type) generates (Result retval);
229
230 /**
231 * Notifies to the audio driver to flush the queued data. Stream must
232 * already be paused before calling 'flush'.
Kevin Rocard74980b52018-01-20 22:12:57 -0800233 * Optional method
Kevin Rocarda4e6d8b2018-01-20 21:52:01 -0800234 *
235 * Implementation of this function is mandatory for offloaded playback.
236 *
237 * @return retval operation completion status.
238 */
239 flush() generates (Result retval);
240
241 /**
242 * Return a recent count of the number of audio frames presented to an
243 * external observer. This excludes frames which have been written but are
244 * still in the pipeline. The count is not reset to zero when output enters
245 * standby. Also returns the value of CLOCK_MONOTONIC as of this
246 * presentation count. The returned count is expected to be 'recent', but
247 * does not need to be the most recent possible value. However, the
248 * associated time must correspond to whatever count is returned.
249 *
250 * Example: assume that N+M frames have been presented, where M is a 'small'
251 * number. Then it is permissible to return N instead of N+M, and the
252 * timestamp must correspond to N rather than N+M. The terms 'recent' and
253 * 'small' are not defined. They reflect the quality of the implementation.
254 *
Kevin Rocard74980b52018-01-20 22:12:57 -0800255 * Optional method
256 *
Kevin Rocarda4e6d8b2018-01-20 21:52:01 -0800257 * @return retval operation completion status.
258 * @return frames count of presented audio frames.
259 * @return timeStamp associated clock time.
260 */
261 getPresentationPosition()
262 generates (Result retval, uint64_t frames, TimeSpec timeStamp);
263};