blob: e34c95f4efed35c030db42569f43aefa4e7dabb2 [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;
21
22interface IStreamIn extends IStream {
23 typedef android.hardware.audio@2.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.
29 *
30 * @return retval operation completion status.
31 * @return source audio source.
32 */
33 getAudioSource() generates (Result retval, AudioSource source);
34
35 /*
36 * Set the input gain for the audio driver.
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 Naganova468fa82017-01-31 13:56:02 -080044 * Commands that can be executed on the driver reader thread.
45 */
46 enum ReadCommand : int32_t {
47 READ,
48 GET_CAPTURE_POSITION
49 };
50
51 /*
52 * Data structure passed to the driver for executing commands
53 * on the driver reader thread.
54 */
55 struct ReadParameters {
56 ReadCommand command; // discriminator
57 union Params {
58 uint64_t read; // READ command, amount of bytes to read, >= 0.
59 // No parameters for GET_CAPTURE_POSITION.
60 } params;
61 };
62
63 /*
Mikhail Naganovb29438e2016-12-22 09:21:34 -080064 * Data structure passed back to the client via status message queue
65 * of 'read' operation.
Mikhail Naganov96b30be2016-10-05 11:21:12 -070066 *
Mikhail Naganovb29438e2016-12-22 09:21:34 -080067 * Possible values of 'retval' field:
68 * - OK, read operation was successful;
69 * - INVALID_ARGUMENTS, stream was not configured properly;
70 * - INVALID_STATE, stream is in a state that doesn't allow reads.
Mikhail Naganov96b30be2016-10-05 11:21:12 -070071 */
Mikhail Naganovb29438e2016-12-22 09:21:34 -080072 struct ReadStatus {
73 Result retval;
Mikhail Naganova468fa82017-01-31 13:56:02 -080074 ReadCommand replyTo; // discriminator
75 union Reply {
76 uint64_t read; // READ command, amount of bytes read, >= 0.
77 struct CapturePosition { // same as generated by getCapturePosition.
78 uint64_t frames;
79 uint64_t time;
80 } capturePosition;
81 } reply;
Mikhail Naganovb29438e2016-12-22 09:21:34 -080082 };
83
84 /*
85 * Set up required transports for receiving audio buffers from the driver.
86 *
Mikhail Naganova468fa82017-01-31 13:56:02 -080087 * The transport consists of three message queues:
88 * -- command queue is used to instruct the reader thread what operation
89 * to perform;
90 * -- data queue is used for passing audio data from the driver
91 * to the client;
92 * -- status queue is used for reporting operation status
93 * (e.g. amount of bytes actually read or error code).
94 * The driver operates on a dedicated thread.
Mikhail Naganovb29438e2016-12-22 09:21:34 -080095 *
96 * @param frameSize the size of a single frame, in bytes.
97 * @param framesCount the number of frames in a buffer.
Mikhail Naganova468fa82017-01-31 13:56:02 -080098 * @param threadPriority priority of the driver thread.
Mikhail Naganovb29438e2016-12-22 09:21:34 -080099 * @return retval OK if both message queues were created successfully.
100 * INVALID_STATE if the method was already called.
101 * INVALID_ARGUMENTS if there was a problem setting up
102 * the queues.
Mikhail Naganova468fa82017-01-31 13:56:02 -0800103 * @return commandMQ a message queue used for passing commands.
Mikhail Naganovb29438e2016-12-22 09:21:34 -0800104 * @return dataMQ a message queue used for passing audio data in the format
105 * specified at the stream opening.
106 * @return statusMQ a message queue used for passing status from the driver
107 * using ReadStatus structures.
108 */
109 prepareForReading(
110 uint32_t frameSize, uint32_t framesCount,
111 ThreadPriority threadPriority)
112 generates (
113 Result retval,
Mikhail Naganova468fa82017-01-31 13:56:02 -0800114 fmq_sync<ReadParameters> commandMQ,
115 fmq_sync<uint8_t> dataMQ,
116 fmq_sync<ReadStatus> statusMQ);
Mikhail Naganov96b30be2016-10-05 11:21:12 -0700117
118 /*
119 * Return the amount of input frames lost in the audio driver since the last
120 * call of this function.
121 *
122 * Audio driver is expected to reset the value to 0 and restart counting
123 * upon returning the current value by this function call. Such loss
124 * typically occurs when the user space process is blocked longer than the
125 * capacity of audio driver buffers.
126 *
Mikhail Naganov96b30be2016-10-05 11:21:12 -0700127 * @return framesLost the number of input audio frames lost.
128 */
Mikhail Naganov10548292016-10-31 10:39:47 -0700129 getInputFramesLost() generates (uint32_t framesLost);
Mikhail Naganov96b30be2016-10-05 11:21:12 -0700130
131 /**
132 * Return a recent count of the number of audio frames received and the
133 * clock time associated with that frame count.
134 *
135 * @return retval INVALID_STATE if the device is not ready/available,
136 * NOT_SUPPORTED if the command is not supported,
137 * OK otherwise.
138 * @return frames the total frame count received. This must be as early in
139 * the capture pipeline as possible. In general, frames
140 * must be non-negative and must not go "backwards".
141 * @return time is the clock monotonic time when frames was measured. In
142 * general, time must be a positive quantity and must not
143 * go "backwards".
144 */
145 getCapturePosition()
146 generates (Result retval, uint64_t frames, uint64_t time);
147};