blob: 2ec080d02945fab1c99ccef7e4c2c11b3ff5dbdf [file] [log] [blame]
Mikhail Naganov96b30be2016-10-05 11:21:12 -07001/*
2 * Copyright (C) 2016 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@2.0;
18
19import android.hardware.audio.common@2.0;
20import IStream;
21import IStreamOutCallback;
22
23interface IStreamOut extends IStream {
24 typedef android.hardware.audio@2.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.
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 */
44 setVolume(float left, float right) generates (Result retval);
45
46 /*
Mikhail Naganova468fa82017-01-31 13:56:02 -080047 * Commands that can be executed on the driver writer thread.
48 */
49 enum WriteCommand : int32_t {
50 WRITE,
51 GET_PRESENTATION_POSITION,
52 GET_LATENCY
53 };
54
55 /*
Mikhail Naganovb29438e2016-12-22 09:21:34 -080056 * Data structure passed back to the client via status message queue
57 * of 'write' operation.
Mikhail Naganov96b30be2016-10-05 11:21:12 -070058 *
Mikhail Naganova468fa82017-01-31 13:56:02 -080059 * Possible values of 'retval' field:
Mikhail Naganovb29438e2016-12-22 09:21:34 -080060 * - OK, write operation was successful;
61 * - INVALID_ARGUMENTS, stream was not configured properly;
Mikhail Naganova468fa82017-01-31 13:56:02 -080062 * - INVALID_STATE, stream is in a state that doesn't allow writes;
63 * - INVALID_OPERATION, retrieving presentation position isn't supported.
Mikhail Naganov96b30be2016-10-05 11:21:12 -070064 */
Mikhail Naganovb29438e2016-12-22 09:21:34 -080065 struct WriteStatus {
Mikhail Naganova468fa82017-01-31 13:56:02 -080066 Result retval;
67 WriteCommand replyTo; // discriminator
68 union Reply {
69 uint64_t written; // WRITE command, amount of bytes written, >= 0.
70 struct PresentationPosition { // same as generated by
71 uint64_t frames; // getPresentationPosition.
72 TimeSpec timeStamp;
73 } presentationPosition;
74 uint32_t latencyMs; // Same as generated by getLatency.
75 } reply;
Mikhail Naganovb29438e2016-12-22 09:21:34 -080076 };
77
78 /*
79 * Set up required transports for passing audio buffers to the driver.
80 *
Mikhail Naganova468fa82017-01-31 13:56:02 -080081 * The transport consists of three message queues:
82 * -- command queue is used to instruct the writer thread what operation
83 * to perform;
84 * -- data queue is used for passing audio data from the client
85 * to the driver;
86 * -- status queue is used for reporting operation status
87 * (e.g. amount of bytes actually written or error code).
88 * The driver operates on a dedicated thread.
Mikhail Naganovb29438e2016-12-22 09:21:34 -080089 *
90 * @param frameSize the size of a single frame, in bytes.
91 * @param framesCount the number of frames in a buffer.
Mikhail Naganova468fa82017-01-31 13:56:02 -080092 * @param threadPriority priority of the driver thread.
Mikhail Naganovb29438e2016-12-22 09:21:34 -080093 * @return retval OK if both message queues were created successfully.
94 * INVALID_STATE if the method was already called.
95 * INVALID_ARGUMENTS if there was a problem setting up
96 * the queues.
Mikhail Naganova468fa82017-01-31 13:56:02 -080097 * @return commandMQ a message queue used for passing commands.
Mikhail Naganovb29438e2016-12-22 09:21:34 -080098 * @return dataMQ a message queue used for passing audio data in the format
99 * specified at the stream opening.
100 * @return statusMQ a message queue used for passing status from the driver
101 * using WriteStatus structures.
102 */
103 prepareForWriting(
104 uint32_t frameSize, uint32_t framesCount,
105 ThreadPriority threadPriority)
106 generates (
107 Result retval,
Mikhail Naganova468fa82017-01-31 13:56:02 -0800108 fmq_sync<WriteCommand> commandMQ,
109 fmq_sync<uint8_t> dataMQ,
110 fmq_sync<WriteStatus> statusMQ);
Mikhail Naganov96b30be2016-10-05 11:21:12 -0700111
112 /*
113 * Return the number of audio frames written by the audio DSP to DAC since
114 * the output has exited standby.
115 *
116 * @return retval operation completion status.
117 * @return dspFrames number of audio frames written.
118 */
119 getRenderPosition() generates (Result retval, uint32_t dspFrames);
120
121 /*
122 * Get the local time at which the next write to the audio driver will be
123 * presented. The units are microseconds, where the epoch is decided by the
124 * local audio HAL.
125 *
126 * @return retval operation completion status.
127 * @return timestampUs time of the next write.
128 */
129 getNextWriteTimestamp() generates (Result retval, int64_t timestampUs);
130
131 /*
132 * Set the callback interface for notifying completion of non-blocking
133 * write and drain.
134 *
135 * Calling this function implies that all future 'write' and 'drain'
136 * must be non-blocking and use the callback to signal completion.
137 *
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -0800138 * 'clearCallback' method needs to be called in order to release the local
139 * callback proxy on the server side and thus dereference the callback
140 * implementation on the client side.
141 *
Mikhail Naganov96b30be2016-10-05 11:21:12 -0700142 * @return retval operation completion status.
143 */
144 setCallback(IStreamOutCallback callback) generates (Result retval);
145
146 /*
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -0800147 * Clears the callback previously set via 'setCallback' method.
148 *
149 * Warning: failure to call this method results in callback implementation
150 * on the client side being held until the HAL server termination.
151 *
152 * @return retval operation completion status: OK or NOT_SUPPORTED.
153 */
154 clearCallback() generates (Result retval);
155
156 /*
Mikhail Naganov96b30be2016-10-05 11:21:12 -0700157 * Returns whether HAL supports pausing and resuming of streams.
158 *
159 * @return supportsPause true if pausing is supported.
160 * @return supportsResume true if resume is supported.
161 */
162 supportsPauseAndResume()
163 generates (bool supportsPause, bool supportsResume);
164
165 /**
166 * Notifies to the audio driver to stop playback however the queued buffers
167 * are retained by the hardware. Useful for implementing pause/resume. Empty
168 * implementation if not supported however must be implemented for hardware
169 * with non-trivial latency. In the pause state, some audio hardware may
170 * still be using power. Client code may consider calling 'suspend' after a
171 * timeout to prevent that excess power usage.
172 *
173 * Implementation of this function is mandatory for offloaded playback.
174 *
175 * @return retval operation completion status.
176 */
177 pause() generates (Result retval);
178
179 /*
180 * Notifies to the audio driver to resume playback following a pause.
181 * Returns error INVALID_STATE if called without matching pause.
182 *
183 * Implementation of this function is mandatory for offloaded playback.
184 *
185 * @return retval operation completion status.
186 */
187 resume() generates (Result retval);
188
189 /*
190 * Returns whether HAL supports draining of streams.
191 *
192 * @return supports true if draining is supported.
193 */
194 supportsDrain() generates (bool supports);
195
196 /**
197 * Requests notification when data buffered by the driver/hardware has been
198 * played. If 'setCallback' has previously been called to enable
199 * non-blocking mode, then 'drain' must not block, instead it must return
200 * quickly and completion of the drain is notified through the callback. If
201 * 'setCallback' has not been called, then 'drain' must block until
202 * completion.
203 *
Mikhail Naganov10548292016-10-31 10:39:47 -0700204 * If 'type' is 'ALL', the drain completes when all previously written data
205 * has been played.
Mikhail Naganov96b30be2016-10-05 11:21:12 -0700206 *
Mikhail Naganov10548292016-10-31 10:39:47 -0700207 * If 'type' is 'EARLY_NOTIFY', the drain completes shortly before all data
208 * for the current track has played to allow time for the framework to
209 * perform a gapless track switch.
Mikhail Naganov96b30be2016-10-05 11:21:12 -0700210 *
211 * Drain must return immediately on 'stop' and 'flush' calls.
212 *
213 * Implementation of this function is mandatory for offloaded playback.
214 *
215 * @param type type of drain.
216 * @return retval operation completion status.
217 */
218 drain(AudioDrain type) generates (Result retval);
219
220 /*
221 * Notifies to the audio driver to flush the queued data. Stream must
222 * already be paused before calling 'flush'.
223 *
224 * Implementation of this function is mandatory for offloaded playback.
225 *
226 * @return retval operation completion status.
227 */
228 flush() generates (Result retval);
229
230 /*
231 * Return a recent count of the number of audio frames presented to an
232 * external observer. This excludes frames which have been written but are
233 * still in the pipeline. The count is not reset to zero when output enters
234 * standby. Also returns the value of CLOCK_MONOTONIC as of this
235 * presentation count. The returned count is expected to be 'recent', but
236 * does not need to be the most recent possible value. However, the
237 * associated time must correspond to whatever count is returned.
238 *
239 * Example: assume that N+M frames have been presented, where M is a 'small'
240 * number. Then it is permissible to return N instead of N+M, and the
241 * timestamp must correspond to N rather than N+M. The terms 'recent' and
242 * 'small' are not defined. They reflect the quality of the implementation.
243 *
244 * @return retval operation completion status.
245 * @return frames count of presented audio frames.
246 * @return timeStamp associated clock time.
247 */
248 getPresentationPosition()
249 generates (Result retval, uint64_t frames, TimeSpec timeStamp);
250};