blob: ea2826ea3242a071566e949fedb7b4d65d1f698b [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 /**
87 * Set up required transports for receiving audio buffers from the driver.
88 *
89 * The transport consists of three message queues:
90 * -- command queue is used to instruct the reader thread what operation
91 * to perform;
92 * -- data queue is used for passing audio data from the driver
93 * to the client;
94 * -- status queue is used for reporting operation status
95 * (e.g. amount of bytes actually read or error code).
96 *
97 * The driver operates on a dedicated thread. The client must ensure that
98 * the thread is given an appropriate priority and assigned to correct
99 * scheduler and cgroup. For this purpose, the method returns identifiers
100 * of the driver thread.
101 *
102 * @param frameSize the size of a single frame, in bytes.
103 * @param framesCount the number of frames in a buffer.
104 * @param threadPriority priority of the driver thread.
105 * @return retval OK if both message queues were created successfully.
106 * INVALID_STATE if the method was already called.
107 * INVALID_ARGUMENTS if there was a problem setting up
108 * the queues.
109 * @return commandMQ a message queue used for passing commands.
110 * @return dataMQ a message queue used for passing audio data in the format
111 * specified at the stream opening.
112 * @return statusMQ a message queue used for passing status from the driver
113 * using ReadStatus structures.
114 * @return threadInfo identifiers of the driver's dedicated thread.
115 */
116 prepareForReading(uint32_t frameSize, uint32_t framesCount)
117 generates (
118 Result retval,
119 fmq_sync<ReadParameters> commandMQ,
120 fmq_sync<uint8_t> dataMQ,
121 fmq_sync<ReadStatus> statusMQ,
122 ThreadInfo threadInfo);
123
124 /**
125 * Return the amount of input frames lost in the audio driver since the last
126 * call of this function.
127 *
128 * Audio driver is expected to reset the value to 0 and restart counting
129 * upon returning the current value by this function call. Such loss
130 * typically occurs when the user space process is blocked longer than the
131 * capacity of audio driver buffers.
132 *
133 * @return framesLost the number of input audio frames lost.
134 */
135 getInputFramesLost() generates (uint32_t framesLost);
136
137 /**
138 * Return a recent count of the number of audio frames received and the
139 * clock time associated with that frame count.
140 *
141 * @return retval INVALID_STATE if the device is not ready/available,
142 * NOT_SUPPORTED if the command is not supported,
143 * OK otherwise.
144 * @return frames the total frame count received. This must be as early in
145 * the capture pipeline as possible. In general, frames
146 * must be non-negative and must not go "backwards".
147 * @return time is the clock monotonic time when frames was measured. In
148 * general, time must be a positive quantity and must not
149 * go "backwards".
150 */
151 getCapturePosition()
152 generates (Result retval, uint64_t frames, uint64_t time);
153};