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