blob: bf9ae52923572fe0e20924645044d8bd838836f9 [file] [log] [blame]
Mikhail Naganov60ced762020-07-23 18:08:26 +00001/*
2 * Copyright (C) 2020 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@7.0;
18
19import android.hardware.audio.common@7.0;
20import IStream;
21
22interface IStreamIn extends IStream {
23 /**
24 * Returns the source descriptor of the input stream. Calling this method is
25 * equivalent to getting AUDIO_PARAMETER_STREAM_INPUT_SOURCE on the legacy
26 * HAL.
27 * Optional method
28 *
29 * @return retval operation completion status.
30 * @return source audio source.
31 */
32 getAudioSource() generates (Result retval, AudioSource source);
33
34 /**
35 * Set the input gain for the audio driver.
36 * Optional method
37 *
38 * @param gain 1.0f is unity, 0.0f is zero.
39 * @result retval operation completion status.
40 */
41 setGain(float gain) generates (Result retval);
42
43 /**
Mikhail Naganov3f1457b2020-12-17 15:01:54 -080044 * Called when the metadata of the stream's sink has been changed.
45 * Optional method
46 *
47 * @param sinkMetadata Description of the audio that is suggested by the clients.
48 * @return retval operation completion status.
49 * If any of the metadata fields contains an invalid value,
50 * returns INVALID_ARGUMENTS.
51 * If method isn't supported by the HAL returns NOT_SUPPORTED.
52 */
53 updateSinkMetadata(SinkMetadata sinkMetadata) generates (Result retval);
54
55 /**
Mikhail Naganov60ced762020-07-23 18:08:26 +000056 * Commands that can be executed on the driver reader thread.
57 */
58 enum ReadCommand : int32_t {
59 READ,
60 GET_CAPTURE_POSITION
61 };
62
63 /**
64 * Data structure passed to the driver for executing commands
65 * on the driver reader thread.
66 */
67 struct ReadParameters {
68 ReadCommand command; // discriminator
69 union Params {
70 uint64_t read; // READ command, amount of bytes to read, >= 0.
71 // No parameters for GET_CAPTURE_POSITION.
72 } params;
73 };
74
75 /**
76 * Data structure passed back to the client via status message queue
77 * of 'read' operation.
78 *
79 * Possible values of 'retval' field:
80 * - OK, read operation was successful;
81 * - INVALID_ARGUMENTS, stream was not configured properly;
82 * - INVALID_STATE, stream is in a state that doesn't allow reads.
83 */
84 struct ReadStatus {
85 Result retval;
86 ReadCommand replyTo; // discriminator
87 union Reply {
88 uint64_t read; // READ command, amount of bytes read, >= 0.
89 struct CapturePosition { // same as generated by getCapturePosition.
90 uint64_t frames;
91 uint64_t time;
92 } capturePosition;
93 } reply;
94 };
95
96 /**
Mikhail Naganov60ced762020-07-23 18:08:26 +000097 * Set up required transports for receiving audio buffers from the driver.
98 *
99 * The transport consists of three message queues:
100 * -- command queue is used to instruct the reader thread what operation
101 * to perform;
102 * -- data queue is used for passing audio data from the driver
103 * to the client;
104 * -- status queue is used for reporting operation status
105 * (e.g. amount of bytes actually read or error code).
106 *
107 * The driver operates on a dedicated thread. The client must ensure that
108 * the thread is given an appropriate priority and assigned to correct
Mikhail Naganovfda20422020-08-04 23:37:05 +0000109 * scheduler and cgroup. For this purpose, the method returns the identifier
Mikhail Naganov60ced762020-07-23 18:08:26 +0000110 * of the driver thread.
111 *
112 * @param frameSize the size of a single frame, in bytes.
113 * @param framesCount the number of frames in a buffer.
114 * @param threadPriority priority of the driver thread.
115 * @return retval OK if both message queues were created successfully.
116 * INVALID_STATE if the method was already called.
117 * INVALID_ARGUMENTS if there was a problem setting up
118 * the queues.
119 * @return commandMQ a message queue used for passing commands.
120 * @return dataMQ a message queue used for passing audio data in the format
121 * specified at the stream opening.
122 * @return statusMQ a message queue used for passing status from the driver
123 * using ReadStatus structures.
Mikhail Naganovfda20422020-08-04 23:37:05 +0000124 * @return threadId identifier of the driver's dedicated thread; the caller
125 * may adjust the thread priority to match the priority
126 * of the thread that provides audio data.
Mikhail Naganov60ced762020-07-23 18:08:26 +0000127 */
128 prepareForReading(uint32_t frameSize, uint32_t framesCount)
129 generates (
130 Result retval,
131 fmq_sync<ReadParameters> commandMQ,
132 fmq_sync<uint8_t> dataMQ,
133 fmq_sync<ReadStatus> statusMQ,
Mikhail Naganovfda20422020-08-04 23:37:05 +0000134 int32_t threadId);
Mikhail Naganov60ced762020-07-23 18:08:26 +0000135
136 /**
137 * Return the amount of input frames lost in the audio driver since the last
138 * call of this function.
139 *
140 * Audio driver is expected to reset the value to 0 and restart counting
141 * upon returning the current value by this function call. Such loss
142 * typically occurs when the user space process is blocked longer than the
143 * capacity of audio driver buffers.
144 *
145 * @return framesLost the number of input audio frames lost.
146 */
147 getInputFramesLost() generates (uint32_t framesLost);
148
149 /**
150 * Return a recent count of the number of audio frames received and the
151 * clock time associated with that frame count.
152 *
153 * @return retval INVALID_STATE if the device is not ready/available,
154 * NOT_SUPPORTED if the command is not supported,
155 * OK otherwise.
156 * @return frames the total frame count received. This must be as early in
157 * the capture pipeline as possible. In general, frames
158 * must be non-negative and must not go "backwards".
159 * @return time is the clock monotonic time when frames was measured. In
160 * general, time must be a positive quantity and must not
161 * go "backwards".
162 */
163 getCapturePosition()
164 generates (Result retval, uint64_t frames, uint64_t time);
165
166 /**
167 * Returns an array with active microphones in the stream.
168 *
169 * @return retval INVALID_STATE if the call is not successful,
170 * OK otherwise.
171 *
172 * @return microphones array with microphones info
173 */
174 getActiveMicrophones()
175 generates(Result retval, vec<MicrophoneInfo> microphones);
176
177 /**
178 * Specifies the logical microphone (for processing).
179 *
180 * If the feature is not supported an error should be returned
181 * If multiple microphones are present, this should be treated as a preference
182 * for their combined direction.
183 *
184 * Optional method
185 *
186 * @param Direction constant
187 * @return retval OK if the call is successful, an error code otherwise.
188 */
189 setMicrophoneDirection(MicrophoneDirection direction)
190 generates(Result retval);
191
192 /**
193 * Specifies the zoom factor for the selected microphone (for processing).
194 *
195 * If the feature is not supported an error should be returned
196 * If multiple microphones are present, this should be treated as a preference
197 * for their combined field dimension.
198 *
199 * Optional method
200 *
201 * @param the desired field dimension of microphone capture. Range is from -1 (wide angle),
202 * though 0 (no zoom) to 1 (maximum zoom).
203 *
204 * @return retval OK if the call is not successful, an error code otherwise.
205 */
206 setMicrophoneFieldDimension(float zoom) generates(Result retval);
207};