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