blob: 4ba3b2f1941c80f2963eb40c80c0a4ca0e97666a [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 /*
47 * Write audio buffer to driver. On success, sets 'retval' to 'OK', and
48 * returns number of bytes written. If at least one frame was written
49 * successfully prior to the error, it is suggested that the driver return
50 * that successful (short) byte count and then return an error in the
51 * subsequent call.
52 *
53 * If 'setCallback' has previously been called to enable non-blocking mode
54 * then 'write' is not allowed to block. It must write only the number of
55 * bytes that currently fit in the driver/hardware buffer and then return
56 * this byte count. If this is less than the requested write size the
57 * callback function must be called when more space is available in the
58 * driver/hardware buffer.
59 *
60 * @param data audio data.
61 * @return retval operation completion status.
62 * @return written number of bytes written.
63 */
64 // TODO(mnaganov): Replace with FMQ version.
65 write(vec<uint8_t> data) generates (Result retval, uint64_t written);
66
67 /*
68 * Return the number of audio frames written by the audio DSP to DAC since
69 * the output has exited standby.
70 *
71 * @return retval operation completion status.
72 * @return dspFrames number of audio frames written.
73 */
74 getRenderPosition() generates (Result retval, uint32_t dspFrames);
75
76 /*
77 * Get the local time at which the next write to the audio driver will be
78 * presented. The units are microseconds, where the epoch is decided by the
79 * local audio HAL.
80 *
81 * @return retval operation completion status.
82 * @return timestampUs time of the next write.
83 */
84 getNextWriteTimestamp() generates (Result retval, int64_t timestampUs);
85
86 /*
87 * Set the callback interface for notifying completion of non-blocking
88 * write and drain.
89 *
90 * Calling this function implies that all future 'write' and 'drain'
91 * must be non-blocking and use the callback to signal completion.
92 *
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -080093 * 'clearCallback' method needs to be called in order to release the local
94 * callback proxy on the server side and thus dereference the callback
95 * implementation on the client side.
96 *
Mikhail Naganov96b30be2016-10-05 11:21:12 -070097 * @return retval operation completion status.
98 */
99 setCallback(IStreamOutCallback callback) generates (Result retval);
100
101 /*
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -0800102 * Clears the callback previously set via 'setCallback' method.
103 *
104 * Warning: failure to call this method results in callback implementation
105 * on the client side being held until the HAL server termination.
106 *
107 * @return retval operation completion status: OK or NOT_SUPPORTED.
108 */
109 clearCallback() generates (Result retval);
110
111 /*
Mikhail Naganov96b30be2016-10-05 11:21:12 -0700112 * Returns whether HAL supports pausing and resuming of streams.
113 *
114 * @return supportsPause true if pausing is supported.
115 * @return supportsResume true if resume is supported.
116 */
117 supportsPauseAndResume()
118 generates (bool supportsPause, bool supportsResume);
119
120 /**
121 * Notifies to the audio driver to stop playback however the queued buffers
122 * are retained by the hardware. Useful for implementing pause/resume. Empty
123 * implementation if not supported however must be implemented for hardware
124 * with non-trivial latency. In the pause state, some audio hardware may
125 * still be using power. Client code may consider calling 'suspend' after a
126 * timeout to prevent that excess power usage.
127 *
128 * Implementation of this function is mandatory for offloaded playback.
129 *
130 * @return retval operation completion status.
131 */
132 pause() generates (Result retval);
133
134 /*
135 * Notifies to the audio driver to resume playback following a pause.
136 * Returns error INVALID_STATE if called without matching pause.
137 *
138 * Implementation of this function is mandatory for offloaded playback.
139 *
140 * @return retval operation completion status.
141 */
142 resume() generates (Result retval);
143
144 /*
145 * Returns whether HAL supports draining of streams.
146 *
147 * @return supports true if draining is supported.
148 */
149 supportsDrain() generates (bool supports);
150
151 /**
152 * Requests notification when data buffered by the driver/hardware has been
153 * played. If 'setCallback' has previously been called to enable
154 * non-blocking mode, then 'drain' must not block, instead it must return
155 * quickly and completion of the drain is notified through the callback. If
156 * 'setCallback' has not been called, then 'drain' must block until
157 * completion.
158 *
Mikhail Naganov10548292016-10-31 10:39:47 -0700159 * If 'type' is 'ALL', the drain completes when all previously written data
160 * has been played.
Mikhail Naganov96b30be2016-10-05 11:21:12 -0700161 *
Mikhail Naganov10548292016-10-31 10:39:47 -0700162 * If 'type' is 'EARLY_NOTIFY', the drain completes shortly before all data
163 * for the current track has played to allow time for the framework to
164 * perform a gapless track switch.
Mikhail Naganov96b30be2016-10-05 11:21:12 -0700165 *
166 * Drain must return immediately on 'stop' and 'flush' calls.
167 *
168 * Implementation of this function is mandatory for offloaded playback.
169 *
170 * @param type type of drain.
171 * @return retval operation completion status.
172 */
173 drain(AudioDrain type) generates (Result retval);
174
175 /*
176 * Notifies to the audio driver to flush the queued data. Stream must
177 * already be paused before calling 'flush'.
178 *
179 * Implementation of this function is mandatory for offloaded playback.
180 *
181 * @return retval operation completion status.
182 */
183 flush() generates (Result retval);
184
185 /*
186 * Return a recent count of the number of audio frames presented to an
187 * external observer. This excludes frames which have been written but are
188 * still in the pipeline. The count is not reset to zero when output enters
189 * standby. Also returns the value of CLOCK_MONOTONIC as of this
190 * presentation count. The returned count is expected to be 'recent', but
191 * does not need to be the most recent possible value. However, the
192 * associated time must correspond to whatever count is returned.
193 *
194 * Example: assume that N+M frames have been presented, where M is a 'small'
195 * number. Then it is permissible to return N instead of N+M, and the
196 * timestamp must correspond to N rather than N+M. The terms 'recent' and
197 * 'small' are not defined. They reflect the quality of the implementation.
198 *
199 * @return retval operation completion status.
200 * @return frames count of presented audio frames.
201 * @return timeStamp associated clock time.
202 */
203 getPresentationPosition()
204 generates (Result retval, uint64_t frames, TimeSpec timeStamp);
205};