196b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov/*
296b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov * Copyright (C) 2016 The Android Open Source Project
396b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov *
496b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov * Licensed under the Apache License, Version 2.0 (the "License");
596b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov * you may not use this file except in compliance with the License.
696b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov * You may obtain a copy of the License at
796b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov *
896b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov *      http://www.apache.org/licenses/LICENSE-2.0
996b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov *
1096b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov * Unless required by applicable law or agreed to in writing, software
1196b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov * distributed under the License is distributed on an "AS IS" BASIS,
1296b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1396b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov * See the License for the specific language governing permissions and
1496b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov * limitations under the License.
1596b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov */
1696b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov
1796b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganovpackage android.hardware.audio@2.0;
1896b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov
1996b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganovimport android.hardware.audio.common@2.0;
2096b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganovimport IStream;
2196b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganovimport IStreamOutCallback;
2296b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov
2396b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganovinterface IStreamOut extends IStream {
2496b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov    typedef android.hardware.audio@2.0::Result Result;
2596b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov
2640d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
2796b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Return the audio hardware driver estimated latency in milliseconds.
2896b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
2996b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @return latencyMs latency in milliseconds.
3096b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     */
3196b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov    getLatency() generates (uint32_t latencyMs);
3296b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov
3340d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
3496b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * This method is used in situations where audio mixing is done in the
3596b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * hardware. This method serves as a direct interface with hardware,
3696b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * allowing to directly set the volume as apposed to via the framework.
3796b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * This method might produce multiple PCM outputs or hardware accelerated
3896b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * codecs, such as MP3 or AAC.
3996b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
4096b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @param left left channel attenuation, 1.0f is unity, 0.0f is zero.
4196b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @param right right channel attenuation, 1.0f is unity, 0.0f is zero.
4296b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @return retval operation completion status.
4396b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     */
4496b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov    setVolume(float left, float right) generates (Result retval);
4596b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov
4640d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
47a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov     * Commands that can be executed on the driver writer thread.
48a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov     */
49a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov    enum WriteCommand : int32_t {
50a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov        WRITE,
51a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov        GET_PRESENTATION_POSITION,
52a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov        GET_LATENCY
53a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov    };
54a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov
5540d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
56b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov     * Data structure passed back to the client via status message queue
57b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov     * of 'write' operation.
5896b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
59a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov     * Possible values of 'retval' field:
60b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov     *  - OK, write operation was successful;
61b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov     *  - INVALID_ARGUMENTS, stream was not configured properly;
62a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov     *  - INVALID_STATE, stream is in a state that doesn't allow writes;
63a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov     *  - INVALID_OPERATION, retrieving presentation position isn't supported.
64b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov     */
65b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov    struct WriteStatus {
66a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov        Result retval;
67a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov        WriteCommand replyTo;  // discriminator
68a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov        union Reply {
69a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov            uint64_t written;  // WRITE command, amount of bytes written, >= 0.
70a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov            struct PresentationPosition {  // same as generated by
71a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov                uint64_t frames;           // getPresentationPosition.
72a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov                TimeSpec timeStamp;
73a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov            } presentationPosition;
74a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov            uint32_t latencyMs; // Same as generated by getLatency.
75a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov        } reply;
76b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov    };
77b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov
7840d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
79b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov     * Set up required transports for passing audio buffers to the driver.
8096b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
81a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov     * The transport consists of three message queues:
82a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov     *  -- command queue is used to instruct the writer thread what operation
83a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov     *     to perform;
84a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov     *  -- data queue is used for passing audio data from the client
85a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov     *     to the driver;
86a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov     *  -- status queue is used for reporting operation status
87a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov     *     (e.g. amount of bytes actually written or error code).
88a1db22a3e5b45b3bd3c2edf84c605ce211c89220Mikhail Naganov     *
89a1db22a3e5b45b3bd3c2edf84c605ce211c89220Mikhail Naganov     * The driver operates on a dedicated thread. The client must ensure that
90a1db22a3e5b45b3bd3c2edf84c605ce211c89220Mikhail Naganov     * the thread is given an appropriate priority and assigned to correct
91a1db22a3e5b45b3bd3c2edf84c605ce211c89220Mikhail Naganov     * scheduler and cgroup. For this purpose, the method returns identifiers
92a1db22a3e5b45b3bd3c2edf84c605ce211c89220Mikhail Naganov     * of the driver thread.
93b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov     *
94b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov     * @param frameSize the size of a single frame, in bytes.
95b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov     * @param framesCount the number of frames in a buffer.
96b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov     * @return retval OK if both message queues were created successfully.
97b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov     *                INVALID_STATE if the method was already called.
98b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov     *                INVALID_ARGUMENTS if there was a problem setting up
99b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov     *                                  the queues.
100a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov     * @return commandMQ a message queue used for passing commands.
101b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov     * @return dataMQ a message queue used for passing audio data in the format
102b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov     *                specified at the stream opening.
103b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov     * @return statusMQ a message queue used for passing status from the driver
104b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov     *                  using WriteStatus structures.
105a1db22a3e5b45b3bd3c2edf84c605ce211c89220Mikhail Naganov     * @return threadInfo identifiers of the driver's dedicated thread.
10696b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     */
107a1db22a3e5b45b3bd3c2edf84c605ce211c89220Mikhail Naganov    prepareForWriting(uint32_t frameSize, uint32_t framesCount)
108b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov    generates (
109b29438ef70549a331d11c0384c53cf1dc6e7f0beMikhail Naganov            Result retval,
110a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov            fmq_sync<WriteCommand> commandMQ,
111a468fa84d13b085b1808f20f70d22ed9dbe3f3ebMikhail Naganov            fmq_sync<uint8_t> dataMQ,
112a1db22a3e5b45b3bd3c2edf84c605ce211c89220Mikhail Naganov            fmq_sync<WriteStatus> statusMQ,
113a1db22a3e5b45b3bd3c2edf84c605ce211c89220Mikhail Naganov            ThreadInfo threadInfo);
11496b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov
11540d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
11696b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Return the number of audio frames written by the audio DSP to DAC since
11796b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * the output has exited standby.
11896b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
11996b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @return retval operation completion status.
12096b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @return dspFrames number of audio frames written.
12196b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     */
12296b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov    getRenderPosition() generates (Result retval, uint32_t dspFrames);
12396b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov
12440d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
12596b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Get the local time at which the next write to the audio driver will be
12696b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * presented. The units are microseconds, where the epoch is decided by the
12796b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * local audio HAL.
12896b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
12996b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @return retval operation completion status.
13096b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @return timestampUs time of the next write.
13196b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     */
13296b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov    getNextWriteTimestamp() generates (Result retval, int64_t timestampUs);
13396b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov
13440d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
13596b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Set the callback interface for notifying completion of non-blocking
13696b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * write and drain.
13796b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
13896b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Calling this function implies that all future 'write' and 'drain'
13996b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * must be non-blocking and use the callback to signal completion.
14096b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
1416e81e9bb3c13d8c51fde503cf8be2bfb56e1ca1dMikhail Naganov     * 'clearCallback' method needs to be called in order to release the local
1426e81e9bb3c13d8c51fde503cf8be2bfb56e1ca1dMikhail Naganov     * callback proxy on the server side and thus dereference the callback
1436e81e9bb3c13d8c51fde503cf8be2bfb56e1ca1dMikhail Naganov     * implementation on the client side.
1446e81e9bb3c13d8c51fde503cf8be2bfb56e1ca1dMikhail Naganov     *
14596b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @return retval operation completion status.
14696b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     */
14796b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov    setCallback(IStreamOutCallback callback) generates (Result retval);
14896b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov
14940d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
1506e81e9bb3c13d8c51fde503cf8be2bfb56e1ca1dMikhail Naganov     * Clears the callback previously set via 'setCallback' method.
1516e81e9bb3c13d8c51fde503cf8be2bfb56e1ca1dMikhail Naganov     *
1526e81e9bb3c13d8c51fde503cf8be2bfb56e1ca1dMikhail Naganov     * Warning: failure to call this method results in callback implementation
1536e81e9bb3c13d8c51fde503cf8be2bfb56e1ca1dMikhail Naganov     * on the client side being held until the HAL server termination.
1546e81e9bb3c13d8c51fde503cf8be2bfb56e1ca1dMikhail Naganov     *
1556e81e9bb3c13d8c51fde503cf8be2bfb56e1ca1dMikhail Naganov     * @return retval operation completion status: OK or NOT_SUPPORTED.
1566e81e9bb3c13d8c51fde503cf8be2bfb56e1ca1dMikhail Naganov     */
1576e81e9bb3c13d8c51fde503cf8be2bfb56e1ca1dMikhail Naganov    clearCallback() generates (Result retval);
1586e81e9bb3c13d8c51fde503cf8be2bfb56e1ca1dMikhail Naganov
15940d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
16096b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Returns whether HAL supports pausing and resuming of streams.
16196b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
16296b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @return supportsPause true if pausing is supported.
16396b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @return supportsResume true if resume is supported.
16496b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     */
16596b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov    supportsPauseAndResume()
16696b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov            generates (bool supportsPause, bool supportsResume);
16796b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov
16896b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov    /**
16996b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Notifies to the audio driver to stop playback however the queued buffers
17096b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * are retained by the hardware. Useful for implementing pause/resume. Empty
17196b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * implementation if not supported however must be implemented for hardware
17296b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * with non-trivial latency. In the pause state, some audio hardware may
17396b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * still be using power. Client code may consider calling 'suspend' after a
17496b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * timeout to prevent that excess power usage.
17596b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
17696b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Implementation of this function is mandatory for offloaded playback.
17796b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
17896b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @return retval operation completion status.
17996b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     */
18096b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov    pause() generates (Result retval);
18196b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov
18240d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
18396b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Notifies to the audio driver to resume playback following a pause.
18496b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Returns error INVALID_STATE if called without matching pause.
18596b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
18696b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Implementation of this function is mandatory for offloaded playback.
18796b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
18896b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @return retval operation completion status.
18996b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     */
19096b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov    resume() generates (Result retval);
19196b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov
19240d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
19396b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Returns whether HAL supports draining of streams.
19496b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
19596b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @return supports true if draining is supported.
19696b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     */
19796b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov    supportsDrain() generates (bool supports);
19896b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov
19996b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov    /**
20096b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Requests notification when data buffered by the driver/hardware has been
20196b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * played. If 'setCallback' has previously been called to enable
20296b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * non-blocking mode, then 'drain' must not block, instead it must return
20396b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * quickly and completion of the drain is notified through the callback. If
20496b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * 'setCallback' has not been called, then 'drain' must block until
20596b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * completion.
20696b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
20710548295023bee99108e418499aff09fe578211eMikhail Naganov     * If 'type' is 'ALL', the drain completes when all previously written data
20810548295023bee99108e418499aff09fe578211eMikhail Naganov     * has been played.
20996b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
21010548295023bee99108e418499aff09fe578211eMikhail Naganov     * If 'type' is 'EARLY_NOTIFY', the drain completes shortly before all data
21110548295023bee99108e418499aff09fe578211eMikhail Naganov     * for the current track has played to allow time for the framework to
21210548295023bee99108e418499aff09fe578211eMikhail Naganov     * perform a gapless track switch.
21396b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
21496b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Drain must return immediately on 'stop' and 'flush' calls.
21596b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
21696b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Implementation of this function is mandatory for offloaded playback.
21796b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
21896b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @param type type of drain.
21996b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @return retval operation completion status.
22096b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     */
22196b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov    drain(AudioDrain type) generates (Result retval);
22296b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov
22340d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
22496b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Notifies to the audio driver to flush the queued data. Stream must
22596b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * already be paused before calling 'flush'.
22696b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
22796b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Implementation of this function is mandatory for offloaded playback.
22896b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
22996b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @return retval operation completion status.
23096b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     */
23196b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov    flush() generates (Result retval);
23296b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov
23340d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
23496b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Return a recent count of the number of audio frames presented to an
23596b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * external observer. This excludes frames which have been written but are
23696b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * still in the pipeline. The count is not reset to zero when output enters
23796b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * standby. Also returns the value of CLOCK_MONOTONIC as of this
23896b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * presentation count. The returned count is expected to be 'recent', but
23996b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * does not need to be the most recent possible value. However, the
24096b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * associated time must correspond to whatever count is returned.
24196b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
24296b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * Example: assume that N+M frames have been presented, where M is a 'small'
24396b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * number. Then it is permissible to return N instead of N+M, and the
24496b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * timestamp must correspond to N rather than N+M. The terms 'recent' and
24596b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * 'small' are not defined. They reflect the quality of the implementation.
24696b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     *
24796b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @return retval operation completion status.
24896b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @return frames count of presented audio frames.
24996b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     * @return timeStamp associated clock time.
25096b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov     */
25196b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov    getPresentationPosition()
25296b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov            generates (Result retval, uint64_t frames, TimeSpec timeStamp);
25396b30be9d0bd14e4ae31533a9fc6844058352fccMikhail Naganov};
254