blob: 3b1fd40c597b9f29cee0160a914d5f381cecd8bb [file] [log] [blame]
Kevin Rocarda4e6d8b2018-01-20 21:52:01 -08001/*
2 * Copyright (C) 2018 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@4.0;
18
19import android.hardware.audio.common@4.0;
20import IStream;
21
22interface IStreamIn extends IStream {
23 typedef android.hardware.audio@4.0::Result Result;
24
25 /**
26 * Returns the source descriptor of the input stream. Calling this method is
27 * equivalent to getting AUDIO_PARAMETER_STREAM_INPUT_SOURCE on the legacy
28 * HAL.
Kevin Rocard74980b52018-01-20 22:12:57 -080029 * Optional method
Kevin Rocarda4e6d8b2018-01-20 21:52:01 -080030 *
31 * @return retval operation completion status.
32 * @return source audio source.
33 */
34 getAudioSource() generates (Result retval, AudioSource source);
35
36 /**
37 * Set the input gain for the audio driver.
Kevin Rocard74980b52018-01-20 22:12:57 -080038 * Optional method
Kevin Rocarda4e6d8b2018-01-20 21:52:01 -080039 *
40 * @param gain 1.0f is unity, 0.0f is zero.
41 * @result retval operation completion status.
42 */
43 setGain(float gain) generates (Result retval);
44
45 /**
46 * Commands that can be executed on the driver reader thread.
47 */
48 enum ReadCommand : int32_t {
49 READ,
50 GET_CAPTURE_POSITION
51 };
52
53 /**
54 * Data structure passed to the driver for executing commands
55 * on the driver reader thread.
56 */
57 struct ReadParameters {
58 ReadCommand command; // discriminator
59 union Params {
60 uint64_t read; // READ command, amount of bytes to read, >= 0.
61 // No parameters for GET_CAPTURE_POSITION.
62 } params;
63 };
64
65 /**
66 * Data structure passed back to the client via status message queue
67 * of 'read' operation.
68 *
69 * Possible values of 'retval' field:
70 * - OK, read operation was successful;
71 * - INVALID_ARGUMENTS, stream was not configured properly;
72 * - INVALID_STATE, stream is in a state that doesn't allow reads.
73 */
74 struct ReadStatus {
75 Result retval;
76 ReadCommand replyTo; // discriminator
77 union Reply {
78 uint64_t read; // READ command, amount of bytes read, >= 0.
79 struct CapturePosition { // same as generated by getCapturePosition.
80 uint64_t frames;
81 uint64_t time;
82 } capturePosition;
83 } reply;
84 };
85
86 /**
Kevin Rocard14dbb1e2018-01-24 19:12:06 -080087 * Called when the metadata of the stream's sink has been changed.
88 * @param sinkMetadata Description of the audio that is suggested by the clients.
89 */
90 updateSinkMetadata(SinkMetadata sinkMetadata);
91
92 /**
Kevin Rocarda4e6d8b2018-01-20 21:52:01 -080093 * Set up required transports for receiving audio buffers from the driver.
94 *
95 * The transport consists of three message queues:
96 * -- command queue is used to instruct the reader thread what operation
97 * to perform;
98 * -- data queue is used for passing audio data from the driver
99 * to the client;
100 * -- status queue is used for reporting operation status
101 * (e.g. amount of bytes actually read or error code).
102 *
103 * The driver operates on a dedicated thread. The client must ensure that
104 * the thread is given an appropriate priority and assigned to correct
105 * scheduler and cgroup. For this purpose, the method returns identifiers
106 * of the driver thread.
107 *
108 * @param frameSize the size of a single frame, in bytes.
109 * @param framesCount the number of frames in a buffer.
110 * @param threadPriority priority of the driver thread.
111 * @return retval OK if both message queues were created successfully.
112 * INVALID_STATE if the method was already called.
113 * INVALID_ARGUMENTS if there was a problem setting up
114 * the queues.
115 * @return commandMQ a message queue used for passing commands.
116 * @return dataMQ a message queue used for passing audio data in the format
117 * specified at the stream opening.
118 * @return statusMQ a message queue used for passing status from the driver
119 * using ReadStatus structures.
120 * @return threadInfo identifiers of the driver's dedicated thread.
121 */
122 prepareForReading(uint32_t frameSize, uint32_t framesCount)
123 generates (
124 Result retval,
125 fmq_sync<ReadParameters> commandMQ,
126 fmq_sync<uint8_t> dataMQ,
127 fmq_sync<ReadStatus> statusMQ,
128 ThreadInfo threadInfo);
129
130 /**
131 * Return the amount of input frames lost in the audio driver since the last
132 * call of this function.
133 *
134 * Audio driver is expected to reset the value to 0 and restart counting
135 * upon returning the current value by this function call. Such loss
136 * typically occurs when the user space process is blocked longer than the
137 * capacity of audio driver buffers.
138 *
139 * @return framesLost the number of input audio frames lost.
140 */
141 getInputFramesLost() generates (uint32_t framesLost);
142
143 /**
144 * Return a recent count of the number of audio frames received and the
145 * clock time associated with that frame count.
146 *
147 * @return retval INVALID_STATE if the device is not ready/available,
148 * NOT_SUPPORTED if the command is not supported,
149 * OK otherwise.
150 * @return frames the total frame count received. This must be as early in
151 * the capture pipeline as possible. In general, frames
152 * must be non-negative and must not go "backwards".
153 * @return time is the clock monotonic time when frames was measured. In
154 * general, time must be a positive quantity and must not
155 * go "backwards".
156 */
157 getCapturePosition()
158 generates (Result retval, uint64_t frames, uint64_t time);
159};