1660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon/*
2660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon * Copyright 2018 The Android Open Source Project
3660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon *
4660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon * Licensed under the Apache License, Version 2.0 (the "License");
5660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon * you may not use this file except in compliance with the License.
6660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon * You may obtain a copy of the License at
7660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon *
8660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon *      http://www.apache.org/licenses/LICENSE-2.0
9660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon *
10660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon * Unless required by applicable law or agreed to in writing, software
11660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon * distributed under the License is distributed on an "AS IS" BASIS,
12660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon * See the License for the specific language governing permissions and
14660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon * limitations under the License.
15660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon */
16660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon
17660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon#ifndef ANDROID_JAUDIOTRACK_H
18660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon#define ANDROID_JAUDIOTRACK_H
19660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon
20660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon#include <jni.h>
21fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon#include <media/AudioResamplerPublic.h>
2242a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon#include <media/AudioSystem.h>
23fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon#include <media/VolumeShaper.h>
24660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon#include <system/audio.h>
25fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon#include <utils/Errors.h>
26fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon
27fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon#include <media/AudioTimestamp.h>   // It has dependency on audio.h/Errors.h, but doesn't
28fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon                                    // include them in it. Therefore it is included here at last.
29660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon
30660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moonnamespace android {
31660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon
32660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moonclass JAudioTrack {
33660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moonpublic:
34660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon
3542a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    /* Events used by AudioTrack callback function (callback_t).
3642a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * Keep in sync with frameworks/base/media/java/android/media/AudioTrack.java NATIVE_EVENT_*.
3742a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     */
3842a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    enum event_type {
3942a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon        EVENT_MORE_DATA = 0,        // Request to write more data to buffer.
4042a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon        EVENT_NEW_IAUDIOTRACK = 6,  // IAudioTrack was re-created, either due to re-routing and
4142a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon                                    // voluntary invalidation by mediaserver, or mediaserver crash.
4242a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon        EVENT_STREAM_END = 7,       // Sent after all the buffers queued in AF and HW are played
4342a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon                                    // back (after stop is called) for an offloaded track.
4442a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    };
4542a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon
4642a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    class Buffer
4742a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    {
4842a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    public:
4942a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon        size_t      mSize;        // input/output in bytes.
5042a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon        void*       mData;        // pointer to the audio data.
5142a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    };
5242a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon
5342a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    /* As a convenience, if a callback is supplied, a handler thread
5442a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * is automatically created with the appropriate priority. This thread
5542a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * invokes the callback when a new buffer becomes available or various conditions occur.
5642a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *
5742a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * Parameters:
5842a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *
5942a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * event:   type of event notified (see enum AudioTrack::event_type).
6042a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * user:    Pointer to context for use by the callback receiver.
6142a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * info:    Pointer to optional parameter according to event type:
6242a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *          - EVENT_MORE_DATA: pointer to JAudioTrack::Buffer struct. The callback must not
6342a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *            write more bytes than indicated by 'size' field and update 'size' if fewer bytes
6442a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *            are written.
6542a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *          - EVENT_NEW_IAUDIOTRACK: unused.
6642a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *          - EVENT_STREAM_END: unused.
6742a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     */
6842a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon
6942a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    typedef void (*callback_t)(int event, void* user, void *info);
7042a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon
71660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon    /* Creates an JAudioTrack object for non-offload mode.
72660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     * Once created, the track needs to be started before it can be used.
73660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     * Unspecified values are set to appropriate default values.
74660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *
75660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     * Parameters:
76660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *
77660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     * streamType:         Select the type of audio stream this track is attached to
78660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *                     (e.g. AUDIO_STREAM_MUSIC).
79660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     * sampleRate:         Data source sampling rate in Hz.  Zero means to use the sink sample rate.
80660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *                     A non-zero value must be specified if AUDIO_OUTPUT_FLAG_DIRECT is set.
81660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *                     0 will not work with current policy implementation for direct output
82660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *                     selection where an exact match is needed for sampling rate.
83660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *                     (TODO: Check direct output after flags can be used in Java AudioTrack.)
84660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     * format:             Audio format. For mixed tracks, any PCM format supported by server is OK.
85660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *                     For direct and offloaded tracks, the possible format(s) depends on the
86660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *                     output sink.
87660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *                     (TODO: How can we check whether a format is supported?)
88660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     * channelMask:        Channel mask, such that audio_is_output_channel(channelMask) is true.
8942a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * cbf:                Callback function. If not null, this function is called periodically
9042a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *                     to provide new data and inform of marker, position updates, etc.
9142a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * user:               Context for use by the callback receiver.
92660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     * frameCount:         Minimum size of track PCM buffer in frames. This defines the
93660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *                     application's contribution to the latency of the track.
94660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *                     The actual size selected by the JAudioTrack could be larger if the
95660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *                     requested size is not compatible with current audio HAL configuration.
96660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *                     Zero means to use a default value.
97660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     * sessionId:          Specific session ID, or zero to use default.
98660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     * pAttributes:        If not NULL, supersedes streamType for use case selection.
99660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     * maxRequiredSpeed:   For PCM tracks, this creates an appropriate buffer size that will allow
100660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *                     maxRequiredSpeed playback. Values less than 1.0f and greater than
101660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *                     AUDIO_TIMESTRETCH_SPEED_MAX will be clamped.  For non-PCM tracks
102660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *                     and direct or offloaded tracks, this parameter is ignored.
103660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *                     (TODO: Handle this after offload / direct track is supported.)
104660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     *
105660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     * TODO: Revive removed arguments after offload mode is supported.
106660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon     */
107660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon    JAudioTrack(audio_stream_type_t streamType,
108660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon                uint32_t sampleRate,
109660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon                audio_format_t format,
110660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon                audio_channel_mask_t channelMask,
11142a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon                callback_t cbf,
11242a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon                void* user,
113660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon                size_t frameCount = 0,
114660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon                audio_session_t sessionId  = AUDIO_SESSION_ALLOCATE,
115660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon                const audio_attributes_t* pAttributes = NULL,
116660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon                float maxRequiredSpeed = 1.0f);
117660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon
118660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon    /*
119660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon       // Q. May be used in AudioTrack.setPreferredDevice(AudioDeviceInfo)?
120660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon       audio_port_handle_t selectedDeviceId,
121660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon
12242a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon       // TODO: No place to use these values.
123660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon       int32_t notificationFrames,
124660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon       const audio_offload_info_t *offloadInfo,
125660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon    */
126660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon
1279b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    virtual ~JAudioTrack();
1289b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon
1299b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    size_t frameCount();
1309b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    size_t channelCount();
1319b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon
132904183eeeeb8e9f7345c3e5f517719d6b5c93128Hyundo Moon    /* Returns this track's estimated latency in milliseconds.
133904183eeeeb8e9f7345c3e5f517719d6b5c93128Hyundo Moon     * This includes the latency due to AudioTrack buffer size, AudioMixer (if any)
134904183eeeeb8e9f7345c3e5f517719d6b5c93128Hyundo Moon     * and audio hardware driver.
135904183eeeeb8e9f7345c3e5f517719d6b5c93128Hyundo Moon     */
136904183eeeeb8e9f7345c3e5f517719d6b5c93128Hyundo Moon    uint32_t latency();
137904183eeeeb8e9f7345c3e5f517719d6b5c93128Hyundo Moon
1389b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    /* Return the total number of frames played since playback start.
1399b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * The counter will wrap (overflow) periodically, e.g. every ~27 hours at 44.1 kHz.
1409b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * It is reset to zero by flush(), reload(), and stop().
1419b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     *
1429b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * Parameters:
1439b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     *
1449b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * position: Address where to return play head position.
1459b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     *
1469b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * Returned status (from utils/Errors.h) can be:
1479b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     *  - NO_ERROR: successful operation
1489b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     *  - BAD_VALUE: position is NULL
1499b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     */
1509b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    status_t getPosition(uint32_t *position);
1519b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon
152fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    // TODO: Does this comment apply same to Java AudioTrack::getTimestamp?
153fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    // Changed the return type from status_t to bool, since Java AudioTrack::getTimestamp returns
154fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    // boolean. Will Java getTimestampWithStatus() be public?
155fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    /* Poll for a timestamp on demand.
156fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * Use if EVENT_NEW_TIMESTAMP is not delivered often enough for your needs,
157fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * or if you need to get the most recent timestamp outside of the event callback handler.
158fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * Caution: calling this method too often may be inefficient;
159fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * if you need a high resolution mapping between frame position and presentation time,
160fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * consider implementing that at application level, based on the low resolution timestamps.
161fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * Returns true if timestamp is valid.
162fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * The timestamp parameter is undefined on return, if false is returned.
163fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     */
164904183eeeeb8e9f7345c3e5f517719d6b5c93128Hyundo Moon    bool getTimestamp(AudioTimestamp& timestamp);
165fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon
16642a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    // TODO: This doc is just copied from AudioTrack.h. Revise it after implemenation.
16742a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    /* Return the extended timestamp, with additional timebase info and improved drain behavior.
16842a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *
16942a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * This is similar to the AudioTrack.java API:
17042a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * getTimestamp(@NonNull AudioTimestamp timestamp, @AudioTimestamp.Timebase int timebase)
17142a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *
17242a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * Some differences between this method and the getTimestamp(AudioTimestamp& timestamp) method
17342a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *
17442a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *   1. stop() by itself does not reset the frame position.
17542a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *      A following start() resets the frame position to 0.
17642a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *   2. flush() by itself does not reset the frame position.
17742a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *      The frame position advances by the number of frames flushed,
17842a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *      when the first frame after flush reaches the audio sink.
17942a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *   3. BOOTTIME clock offsets are provided to help synchronize with
18042a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *      non-audio streams, e.g. sensor data.
18142a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *   4. Position is returned with 64 bits of resolution.
18242a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *
18342a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * Parameters:
18442a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *  timestamp: A pointer to the caller allocated ExtendedTimestamp.
18542a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *
18642a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * Returns NO_ERROR    on success; timestamp is filled with valid data.
18742a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *         BAD_VALUE   if timestamp is NULL.
18842a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *         WOULD_BLOCK if called immediately after start() when the number
18942a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *                     of frames consumed is less than the
19042a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *                     overall hardware latency to physical output. In WOULD_BLOCK cases,
19142a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *                     one might poll again, or use getPosition(), or use 0 position and
19242a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *                     current time for the timestamp.
19342a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *                     If WOULD_BLOCK is returned, the timestamp is still
19442a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *                     modified with the LOCATION_CLIENT portion filled.
19542a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *         DEAD_OBJECT if AudioFlinger dies or the output device changes and
19642a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *                     the track cannot be automatically restored.
19742a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *                     The application needs to recreate the AudioTrack
19842a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *                     because the audio device changed or AudioFlinger died.
19942a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *                     This typically occurs for direct or offloaded tracks
20042a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *                     or if mDoNotReconnect is true.
20142a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *         INVALID_OPERATION  if called on a offloaded or direct track.
20242a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *                     Use getTimestamp(AudioTimestamp& timestamp) instead.
20342a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     */
20442a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    status_t getTimestamp(ExtendedTimestamp *timestamp);
20542a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon
206fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    /* Set source playback rate for timestretch
207fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * 1.0 is normal speed: < 1.0 is slower, > 1.0 is faster
208fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * 1.0 is normal pitch: < 1.0 is lower pitch, > 1.0 is higher pitch
209fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     *
210fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * AUDIO_TIMESTRETCH_SPEED_MIN <= speed <= AUDIO_TIMESTRETCH_SPEED_MAX
211fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * AUDIO_TIMESTRETCH_PITCH_MIN <= pitch <= AUDIO_TIMESTRETCH_PITCH_MAX
212fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     *
213fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * Speed increases the playback rate of media, but does not alter pitch.
214fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * Pitch increases the "tonal frequency" of media, but does not affect the playback rate.
215fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     */
216fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    status_t setPlaybackRate(const AudioPlaybackRate &playbackRate);
217fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon
218fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    /* Return current playback rate */
219fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    const AudioPlaybackRate getPlaybackRate();
220fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon
221fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    /* Sets the volume shaper object */
222fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    media::VolumeShaper::Status applyVolumeShaper(
223fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon            const sp<media::VolumeShaper::Configuration>& configuration,
224fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon            const sp<media::VolumeShaper::Operation>& operation);
225fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon
2269b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    /* Set the send level for this track. An auxiliary effect should be attached
227fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * to the track with attachEffect(). Level must be >= 0.0 and <= 1.0.
2289b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     */
2299b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    status_t setAuxEffectSendLevel(float level);
2309b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon
2319b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    /* Attach track auxiliary output to specified effect. Use effectId = 0
2329b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * to detach track from effect.
2339b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     *
2349b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * Parameters:
2359b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     *
2369b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * effectId: effectId obtained from AudioEffect::id().
2379b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     *
2389b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * Returned status (from utils/Errors.h) can be:
2399b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     *  - NO_ERROR: successful operation
240fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     *  - INVALID_OPERATION: The effect is not an auxiliary effect.
241fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     *  - BAD_VALUE: The specified effect ID is invalid.
2429b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     */
2439b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    status_t attachAuxEffect(int effectId);
2449b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon
2459b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    /* Set volume for this track, mostly used for games' sound effects
2469b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * left and right volumes. Levels must be >= 0.0 and <= 1.0.
2479b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * This is the older API.  New applications should use setVolume(float) when possible.
2489b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     */
2499b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    status_t setVolume(float left, float right);
2509b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon
2519b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    /* Set volume for all channels. This is the preferred API for new applications,
2529b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * especially for multi-channel content.
2539b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     */
2549b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    status_t setVolume(float volume);
2559b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon
2569b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    // TODO: Does this comment equally apply to the Java AudioTrack::play()?
2579b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    /* After it's created the track is not active. Call start() to
2589b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * make it active. If set, the callback will start being called.
2599b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * If the track was previously paused, volume is ramped up over the first mix buffer.
2609b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     */
2619b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    status_t start();
2629b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon
263fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    // TODO: Does this comment still applies? It seems not. (obtainBuffer, AudioFlinger, ...)
264fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    /* As a convenience we provide a write() interface to the audio buffer.
265fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * Input parameter 'size' is in byte units.
266fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * This is implemented on top of obtainBuffer/releaseBuffer. For best
267fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * performance use callbacks. Returns actual number of bytes written >= 0,
268fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * or one of the following negative status codes:
269fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     *      INVALID_OPERATION   AudioTrack is configured for static buffer or streaming mode
270fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     *      BAD_VALUE           size is invalid
271fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     *      WOULD_BLOCK         when obtainBuffer() returns same, or
272fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     *                          AudioTrack was stopped during the write
273fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     *      DEAD_OBJECT         when AudioFlinger dies or the output device changes and
274fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     *                          the track cannot be automatically restored.
275fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     *                          The application needs to recreate the AudioTrack
276fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     *                          because the audio device changed or AudioFlinger died.
277fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     *                          This typically occurs for direct or offload tracks
278fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     *                          or if mDoNotReconnect is true.
279fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     *      or any other error code returned by IAudioTrack::start() or restoreTrack_l().
280fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * Default behavior is to only return when all data has been transferred. Set 'blocking' to
281fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * false for the method to return immediately without waiting to try multiple times to write
282fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     * the full content of the buffer.
283fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon     */
284fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    ssize_t write(const void* buffer, size_t size, bool blocking = true);
285fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon
2869b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    // TODO: Does this comment equally apply to the Java AudioTrack::stop()?
2879b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    /* Stop a track.
2889b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * In static buffer mode, the track is stopped immediately.
2899b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * In streaming mode, the callback will cease being called.  Note that obtainBuffer() still
2909b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * works and will fill up buffers until the pool is exhausted, and then will return WOULD_BLOCK.
2919b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * In streaming mode the stop does not occur immediately: any data remaining in the buffer
2929b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * is first drained, mixed, and output, and only then is the track marked as stopped.
2939b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     */
294660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon    void stop();
2959b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    bool stopped() const;
2969b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon
2979b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    // TODO: Does this comment equally apply to the Java AudioTrack::flush()?
2989b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    /* Flush a stopped or paused track. All previously buffered data is discarded immediately.
2999b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * This has the effect of draining the buffers without mixing or output.
3009b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * Flush is intended for streaming mode, for example before switching to non-contiguous content.
3019b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * This function is a no-op if the track is not stopped or paused, or uses a static buffer.
3029b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     */
3039b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    void flush();
3049b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon
3059b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    // TODO: Does this comment equally apply to the Java AudioTrack::pause()?
3069b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    // At least we are not using obtainBuffer.
3079b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    /* Pause a track. After pause, the callback will cease being called and
3089b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * obtainBuffer returns WOULD_BLOCK. Note that obtainBuffer() still works
3099b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * and will fill up buffers until the pool is exhausted.
3109b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * Volume is ramped down over the next mix buffer following the pause request,
3119b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * and then the track is marked as paused. It can be resumed with ramp up by start().
3129b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     */
3139b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    void pause();
3149b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon
3159b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    bool isPlaying() const;
3169b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon
3179b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    /* Return current source sample rate in Hz.
3189b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     * If specified as zero in constructor, this will be the sink sample rate.
3199b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon     */
3209b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    uint32_t getSampleRate();
3219b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon
322fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    /* Returns the buffer duration in microseconds at current playback rate. */
323fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    status_t getBufferDurationInUs(int64_t *duration);
324fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon
3259b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    audio_format_t format();
326660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon
327904183eeeeb8e9f7345c3e5f517719d6b5c93128Hyundo Moon    /*
328904183eeeeb8e9f7345c3e5f517719d6b5c93128Hyundo Moon     * Dumps the state of an audio track.
329904183eeeeb8e9f7345c3e5f517719d6b5c93128Hyundo Moon     * Not a general-purpose API; intended only for use by media player service to dump its tracks.
330904183eeeeb8e9f7345c3e5f517719d6b5c93128Hyundo Moon     */
331904183eeeeb8e9f7345c3e5f517719d6b5c93128Hyundo Moon    status_t dump(int fd, const Vector<String16>& args) const;
332904183eeeeb8e9f7345c3e5f517719d6b5c93128Hyundo Moon
333904183eeeeb8e9f7345c3e5f517719d6b5c93128Hyundo Moon    /* Returns the ID of the audio device actually used by the output to which this AudioTrack is
334904183eeeeb8e9f7345c3e5f517719d6b5c93128Hyundo Moon     * attached. When the AudioTrack is inactive, it will return AUDIO_PORT_HANDLE_NONE.
335904183eeeeb8e9f7345c3e5f517719d6b5c93128Hyundo Moon     */
336904183eeeeb8e9f7345c3e5f517719d6b5c93128Hyundo Moon    audio_port_handle_t getRoutedDeviceId();
337904183eeeeb8e9f7345c3e5f517719d6b5c93128Hyundo Moon
33842a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    /* Returns the ID of the audio session this AudioTrack belongs to. */
33942a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    audio_session_t getAudioSessionId();
34042a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon
34142a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    /* Selects the audio device to use for output of this AudioTrack. A value of
34242a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * AUDIO_PORT_HANDLE_NONE indicates default routing.
34342a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *
34442a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * Parameters:
34542a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *  The device ID of the selected device (as returned by the AudioDevicesManager API).
34642a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *
34742a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * Returned value:
34842a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *  - NO_ERROR: successful operation
34942a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *  - BAD_VALUE: failed to find the valid output device with given device Id.
35042a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     */
35142a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    status_t setOutputDevice(audio_port_handle_t deviceId);
35242a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon
35342a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    // TODO: Add AUDIO_OUTPUT_FLAG_DIRECT when it is possible to check.
35442a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    // TODO: Add AUDIO_FLAG_HW_AV_SYNC when it is possible to check.
35542a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    /* Returns the flags */
35642a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    audio_output_flags_t getFlags() const { return mFlags; }
35742a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon
35842a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    /* Obtain the pending duration in milliseconds for playback of pure PCM data remaining in
35942a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * AudioTrack.
36042a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *
36142a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * Returns NO_ERROR if successful.
36242a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *         INVALID_OPERATION if the AudioTrack does not contain pure PCM data.
36342a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *         BAD_VALUE if msec is nullptr.
36442a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     */
36542a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    status_t pendingDuration(int32_t *msec);
36642a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon
36742a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    /* Adds an AudioDeviceCallback. The caller will be notified when the audio device to which this
36842a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * AudioTrack is routed is updated.
36942a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * Replaces any previously installed callback.
37042a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *
37142a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * Parameters:
37242a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *
37342a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * callback: The callback interface
37442a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *
37542a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * Returns NO_ERROR if successful.
37642a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *         INVALID_OPERATION if the same callback is already installed.
37742a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *         NO_INIT or PREMISSION_DENIED if AudioFlinger service is not reachable
37842a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *         BAD_VALUE if the callback is NULL
37942a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     */
38042a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    status_t addAudioDeviceCallback(const sp<AudioSystem::AudioDeviceCallback>& callback);
38142a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon
38242a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    /* Removes an AudioDeviceCallback.
38342a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *
38442a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * Parameters:
38542a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *
38642a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * callback: The callback interface
38742a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *
38842a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     * Returns NO_ERROR if successful.
38942a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *         INVALID_OPERATION if the callback is not installed
39042a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     *         BAD_VALUE if the callback is NULL
39142a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon     */
39242a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    status_t removeAudioDeviceCallback(const sp<AudioSystem::AudioDeviceCallback>& callback);
39342a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon
3949b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moonprivate:
39542a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    audio_output_flags_t mFlags;
39642a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon
3979b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    jclass mAudioTrackCls;
3989b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    jobject mAudioTrackObj;
399660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon
400fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    /* Creates a Java VolumeShaper.Configuration object from VolumeShaper::Configuration */
401fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    jobject createVolumeShaperConfigurationObj(
402fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon            const sp<media::VolumeShaper::Configuration>& config);
403fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon
404fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    /* Creates a Java VolumeShaper.Operation object from VolumeShaper::Operation */
405fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon    jobject createVolumeShaperOperationObj(
406fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon            const sp<media::VolumeShaper::Operation>& operation);
407fd328170d288e337cb779b2ef14f9e4c5e860c6aHyundo Moon
40842a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    /* Creates a Java StreamEventCallback object */
40942a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    jobject createStreamEventCallback(callback_t cbf, void* user);
41042a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon
41142a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    /* Creates a Java Executor object for running a callback */
41242a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon    jobject createCallbackExecutor();
41342a6decdd6c173a36e51c19d44849e6654eb60f9Hyundo Moon
4149b26e9467a77e2ee03f1d19e1dbf9671c3770286Hyundo Moon    status_t javaToNativeStatus(int javaStatus);
415660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon};
416660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon
417660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon}; // namespace android
418660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon
419660a74ebf0a8b5b6c79f9a016b202ccfaf815d3bHyundo Moon#endif // ANDROID_JAUDIOTRACK_H
420