blob: 336684ff66594068b56cbfed5d16ce88f741383e [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 Naganovb29438e2016-12-22 09:21:34 -080047 * Data structure passed back to the client via status message queue
48 * of 'write' operation.
Mikhail Naganov96b30be2016-10-05 11:21:12 -070049 *
Mikhail Naganovee901e32017-01-12 09:28:52 -080050 * Possible values of 'writeRetval' field:
Mikhail Naganovb29438e2016-12-22 09:21:34 -080051 * - OK, write operation was successful;
52 * - INVALID_ARGUMENTS, stream was not configured properly;
53 * - INVALID_STATE, stream is in a state that doesn't allow writes.
Mikhail Naganovee901e32017-01-12 09:28:52 -080054 *
55 * Possible values of 'presentationPositionRetval' field (must only
56 * be considered if 'writeRetval' field is set to 'OK'):
57 * - OK, presentation position retrieved successfully;
58 * - INVALID_ARGUMENTS, indicates that the position can't be retrieved;
59 * - INVALID_OPERATION, retrieving presentation position isn't supported;
Mikhail Naganov96b30be2016-10-05 11:21:12 -070060 */
Mikhail Naganovb29438e2016-12-22 09:21:34 -080061 struct WriteStatus {
Mikhail Naganovee901e32017-01-12 09:28:52 -080062 Result writeRetval;
Mikhail Naganovb29438e2016-12-22 09:21:34 -080063 uint64_t written;
Mikhail Naganovee901e32017-01-12 09:28:52 -080064 Result presentationPositionRetval;
Mikhail Naganovb29438e2016-12-22 09:21:34 -080065 uint64_t frames; // presentation position
66 TimeSpec timeStamp; // presentation position
67 };
68
69 /*
70 * Set up required transports for passing audio buffers to the driver.
71 *
72 * The transport consists of two message queues: one is used for passing
73 * audio data from the client to the driver, another is used for reporting
74 * write operation status (amount of bytes actually written or error code),
75 * and the presentation position immediately after the write, see
76 * WriteStatus structure definition.
77 *
78 * @param frameSize the size of a single frame, in bytes.
79 * @param framesCount the number of frames in a buffer.
80 * @param threadPriority priority of the thread that performs writes.
81 * @return retval OK if both message queues were created successfully.
82 * INVALID_STATE if the method was already called.
83 * INVALID_ARGUMENTS if there was a problem setting up
84 * the queues.
85 * @return dataMQ a message queue used for passing audio data in the format
86 * specified at the stream opening.
87 * @return statusMQ a message queue used for passing status from the driver
88 * using WriteStatus structures.
89 */
90 prepareForWriting(
91 uint32_t frameSize, uint32_t framesCount,
92 ThreadPriority threadPriority)
93 generates (
94 Result retval,
95 fmq_sync<uint8_t> dataMQ, fmq_sync<WriteStatus> statusMQ);
Mikhail Naganov96b30be2016-10-05 11:21:12 -070096
97 /*
98 * Return the number of audio frames written by the audio DSP to DAC since
99 * the output has exited standby.
100 *
101 * @return retval operation completion status.
102 * @return dspFrames number of audio frames written.
103 */
104 getRenderPosition() generates (Result retval, uint32_t dspFrames);
105
106 /*
107 * Get the local time at which the next write to the audio driver will be
108 * presented. The units are microseconds, where the epoch is decided by the
109 * local audio HAL.
110 *
111 * @return retval operation completion status.
112 * @return timestampUs time of the next write.
113 */
114 getNextWriteTimestamp() generates (Result retval, int64_t timestampUs);
115
116 /*
117 * Set the callback interface for notifying completion of non-blocking
118 * write and drain.
119 *
120 * Calling this function implies that all future 'write' and 'drain'
121 * must be non-blocking and use the callback to signal completion.
122 *
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -0800123 * 'clearCallback' method needs to be called in order to release the local
124 * callback proxy on the server side and thus dereference the callback
125 * implementation on the client side.
126 *
Mikhail Naganov96b30be2016-10-05 11:21:12 -0700127 * @return retval operation completion status.
128 */
129 setCallback(IStreamOutCallback callback) generates (Result retval);
130
131 /*
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -0800132 * Clears the callback previously set via 'setCallback' method.
133 *
134 * Warning: failure to call this method results in callback implementation
135 * on the client side being held until the HAL server termination.
136 *
137 * @return retval operation completion status: OK or NOT_SUPPORTED.
138 */
139 clearCallback() generates (Result retval);
140
141 /*
Mikhail Naganov96b30be2016-10-05 11:21:12 -0700142 * Returns whether HAL supports pausing and resuming of streams.
143 *
144 * @return supportsPause true if pausing is supported.
145 * @return supportsResume true if resume is supported.
146 */
147 supportsPauseAndResume()
148 generates (bool supportsPause, bool supportsResume);
149
150 /**
151 * Notifies to the audio driver to stop playback however the queued buffers
152 * are retained by the hardware. Useful for implementing pause/resume. Empty
153 * implementation if not supported however must be implemented for hardware
154 * with non-trivial latency. In the pause state, some audio hardware may
155 * still be using power. Client code may consider calling 'suspend' after a
156 * timeout to prevent that excess power usage.
157 *
158 * Implementation of this function is mandatory for offloaded playback.
159 *
160 * @return retval operation completion status.
161 */
162 pause() generates (Result retval);
163
164 /*
165 * Notifies to the audio driver to resume playback following a pause.
166 * Returns error INVALID_STATE if called without matching pause.
167 *
168 * Implementation of this function is mandatory for offloaded playback.
169 *
170 * @return retval operation completion status.
171 */
172 resume() generates (Result retval);
173
174 /*
175 * Returns whether HAL supports draining of streams.
176 *
177 * @return supports true if draining is supported.
178 */
179 supportsDrain() generates (bool supports);
180
181 /**
182 * Requests notification when data buffered by the driver/hardware has been
183 * played. If 'setCallback' has previously been called to enable
184 * non-blocking mode, then 'drain' must not block, instead it must return
185 * quickly and completion of the drain is notified through the callback. If
186 * 'setCallback' has not been called, then 'drain' must block until
187 * completion.
188 *
Mikhail Naganov10548292016-10-31 10:39:47 -0700189 * If 'type' is 'ALL', the drain completes when all previously written data
190 * has been played.
Mikhail Naganov96b30be2016-10-05 11:21:12 -0700191 *
Mikhail Naganov10548292016-10-31 10:39:47 -0700192 * If 'type' is 'EARLY_NOTIFY', the drain completes shortly before all data
193 * for the current track has played to allow time for the framework to
194 * perform a gapless track switch.
Mikhail Naganov96b30be2016-10-05 11:21:12 -0700195 *
196 * Drain must return immediately on 'stop' and 'flush' calls.
197 *
198 * Implementation of this function is mandatory for offloaded playback.
199 *
200 * @param type type of drain.
201 * @return retval operation completion status.
202 */
203 drain(AudioDrain type) generates (Result retval);
204
205 /*
206 * Notifies to the audio driver to flush the queued data. Stream must
207 * already be paused before calling 'flush'.
208 *
209 * Implementation of this function is mandatory for offloaded playback.
210 *
211 * @return retval operation completion status.
212 */
213 flush() generates (Result retval);
214
215 /*
216 * Return a recent count of the number of audio frames presented to an
217 * external observer. This excludes frames which have been written but are
218 * still in the pipeline. The count is not reset to zero when output enters
219 * standby. Also returns the value of CLOCK_MONOTONIC as of this
220 * presentation count. The returned count is expected to be 'recent', but
221 * does not need to be the most recent possible value. However, the
222 * associated time must correspond to whatever count is returned.
223 *
224 * Example: assume that N+M frames have been presented, where M is a 'small'
225 * number. Then it is permissible to return N instead of N+M, and the
226 * timestamp must correspond to N rather than N+M. The terms 'recent' and
227 * 'small' are not defined. They reflect the quality of the implementation.
228 *
229 * @return retval operation completion status.
230 * @return frames count of presented audio frames.
231 * @return timeStamp associated clock time.
232 */
233 getPresentationPosition()
234 generates (Result retval, uint64_t frames, TimeSpec timeStamp);
235};