blob: 55a852d1ca06d29c1cb213694f9f166524657ba5 [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 *
93 * @return retval operation completion status.
94 */
95 setCallback(IStreamOutCallback callback) generates (Result retval);
96
97 /*
98 * Returns whether HAL supports pausing and resuming of streams.
99 *
100 * @return supportsPause true if pausing is supported.
101 * @return supportsResume true if resume is supported.
102 */
103 supportsPauseAndResume()
104 generates (bool supportsPause, bool supportsResume);
105
106 /**
107 * Notifies to the audio driver to stop playback however the queued buffers
108 * are retained by the hardware. Useful for implementing pause/resume. Empty
109 * implementation if not supported however must be implemented for hardware
110 * with non-trivial latency. In the pause state, some audio hardware may
111 * still be using power. Client code may consider calling 'suspend' after a
112 * timeout to prevent that excess power usage.
113 *
114 * Implementation of this function is mandatory for offloaded playback.
115 *
116 * @return retval operation completion status.
117 */
118 pause() generates (Result retval);
119
120 /*
121 * Notifies to the audio driver to resume playback following a pause.
122 * Returns error INVALID_STATE if called without matching pause.
123 *
124 * Implementation of this function is mandatory for offloaded playback.
125 *
126 * @return retval operation completion status.
127 */
128 resume() generates (Result retval);
129
130 /*
131 * Returns whether HAL supports draining of streams.
132 *
133 * @return supports true if draining is supported.
134 */
135 supportsDrain() generates (bool supports);
136
137 /**
138 * Requests notification when data buffered by the driver/hardware has been
139 * played. If 'setCallback' has previously been called to enable
140 * non-blocking mode, then 'drain' must not block, instead it must return
141 * quickly and completion of the drain is notified through the callback. If
142 * 'setCallback' has not been called, then 'drain' must block until
143 * completion.
144 *
Mikhail Naganov10548292016-10-31 10:39:47 -0700145 * If 'type' is 'ALL', the drain completes when all previously written data
146 * has been played.
Mikhail Naganov96b30be2016-10-05 11:21:12 -0700147 *
Mikhail Naganov10548292016-10-31 10:39:47 -0700148 * If 'type' is 'EARLY_NOTIFY', the drain completes shortly before all data
149 * for the current track has played to allow time for the framework to
150 * perform a gapless track switch.
Mikhail Naganov96b30be2016-10-05 11:21:12 -0700151 *
152 * Drain must return immediately on 'stop' and 'flush' calls.
153 *
154 * Implementation of this function is mandatory for offloaded playback.
155 *
156 * @param type type of drain.
157 * @return retval operation completion status.
158 */
159 drain(AudioDrain type) generates (Result retval);
160
161 /*
162 * Notifies to the audio driver to flush the queued data. Stream must
163 * already be paused before calling 'flush'.
164 *
165 * Implementation of this function is mandatory for offloaded playback.
166 *
167 * @return retval operation completion status.
168 */
169 flush() generates (Result retval);
170
171 /*
172 * Return a recent count of the number of audio frames presented to an
173 * external observer. This excludes frames which have been written but are
174 * still in the pipeline. The count is not reset to zero when output enters
175 * standby. Also returns the value of CLOCK_MONOTONIC as of this
176 * presentation count. The returned count is expected to be 'recent', but
177 * does not need to be the most recent possible value. However, the
178 * associated time must correspond to whatever count is returned.
179 *
180 * Example: assume that N+M frames have been presented, where M is a 'small'
181 * number. Then it is permissible to return N instead of N+M, and the
182 * timestamp must correspond to N rather than N+M. The terms 'recent' and
183 * 'small' are not defined. They reflect the quality of the implementation.
184 *
185 * @return retval operation completion status.
186 * @return frames count of presented audio frames.
187 * @return timeStamp associated clock time.
188 */
189 getPresentationPosition()
190 generates (Result retval, uint64_t frames, TimeSpec timeStamp);
191};