1e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent/*
2e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent * Copyright (C) 2009 The Android Open Source Project
3e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent *
4e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent * Licensed under the Apache License, Version 2.0 (the "License");
5e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent * you may not use this file except in compliance with the License.
6e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent * You may obtain a copy of the License at
7e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent *
8e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent *      http://www.apache.org/licenses/LICENSE-2.0
9e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent *
10e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent * Unless required by applicable law or agreed to in writing, software
11e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent * distributed under the License is distributed on an "AS IS" BASIS,
12e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent * See the License for the specific language governing permissions and
14e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent * limitations under the License.
15e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent */
16e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
17dce54a1492c410ad0d93253b341fb33305337505Eric Laurent#ifndef ANDROID_AUDIOPOLICY_INTERFACE_H
18dce54a1492c410ad0d93253b341fb33305337505Eric Laurent#define ANDROID_AUDIOPOLICY_INTERFACE_H
19e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
20e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent#include <media/AudioSystem.h>
21baac183f3808d7b68f184647a97bd381620415feEric Laurent#include <media/AudioPolicy.h>
22e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent#include <utils/String8.h>
23e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
243b73df74357b33869b39a1d69427673c780bd805Eric Laurentnamespace android {
25e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
26e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent// ----------------------------------------------------------------------------
27e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
28e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent// The AudioPolicyInterface and AudioPolicyClientInterface classes define the communication interfaces
29e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent// between the platform specific audio policy manager and Android generic audio policy manager.
30e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent// The platform specific audio policy manager must implement methods of the AudioPolicyInterface class.
31e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent// This implementation makes use of the AudioPolicyClientInterface to control the activity and
32e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent// configuration of audio input and output streams.
33e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent//
34e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent// The platform specific audio policy manager is in charge of the audio routing and volume control
35e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent// policies for a given platform.
36e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent// The main roles of this module are:
37e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent//   - keep track of current system state (removable device connections, phone state, user requests...).
38e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent//   System state changes and user actions are notified to audio policy manager with methods of the AudioPolicyInterface.
39e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent//   - process getOutput() queries received when AudioTrack objects are created: Those queries
40e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent//   return a handler on an output that has been selected, configured and opened by the audio policy manager and that
41e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent//   must be used by the AudioTrack when registering to the AudioFlinger with the createTrack() method.
42e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent//   When the AudioTrack object is released, a putOutput() query is received and the audio policy manager can decide
43e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent//   to close or reconfigure the output depending on other streams using this output and current system state.
44e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent//   - similarly process getInput() and putInput() queries received from AudioRecord objects and configure audio inputs.
45e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent//   - process volume control requests: the stream volume is converted from an index value (received from UI) to a float value
46e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent//   applicable to each output as a function of platform specific settings and current output route (destination device). It
47e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent//   also make sure that streams are not muted if not allowed (e.g. camera shutter sound in some countries).
48e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent//
49e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent// The platform specific audio policy manager is provided as a shared library by platform vendors (as for libaudio.so)
50e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent// and is linked with libaudioflinger.so
51e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
52e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
53e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent//    Audio Policy Manager Interface
54e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurentclass AudioPolicyInterface
55e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent{
56e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
57e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurentpublic:
5897bb33f58d742539f3382583d7978fca71ffa2d5Jean-Michel Trivi    typedef enum {
5997bb33f58d742539f3382583d7978fca71ffa2d5Jean-Michel Trivi        API_INPUT_INVALID = -1,
6097bb33f58d742539f3382583d7978fca71ffa2d5Jean-Michel Trivi        API_INPUT_LEGACY  = 0,// e.g. audio recording from a microphone
6197bb33f58d742539f3382583d7978fca71ffa2d5Jean-Michel Trivi        API_INPUT_MIX_CAPTURE,// used for "remote submix", capture of the media to play it remotely
6297bb33f58d742539f3382583d7978fca71ffa2d5Jean-Michel Trivi        API_INPUT_MIX_EXT_POLICY_REROUTE,// used for platform audio rerouting, where mixes are
6397bb33f58d742539f3382583d7978fca71ffa2d5Jean-Michel Trivi                                         // handled by external and dynamically installed
6497bb33f58d742539f3382583d7978fca71ffa2d5Jean-Michel Trivi                                         // policies which reroute audio mixes
6582db269d4797cb9909988b723d91fa2094a74b38Eric Laurent        API_INPUT_TELEPHONY_RX, // used for capture from telephony RX path
6697bb33f58d742539f3382583d7978fca71ffa2d5Jean-Michel Trivi    } input_type_t;
6797bb33f58d742539f3382583d7978fca71ffa2d5Jean-Michel Trivi
68fb66dd9f95a1168698f072c4e5c2a2cf8c49a80fEric Laurent   enum {
69fb66dd9f95a1168698f072c4e5c2a2cf8c49a80fEric Laurent        API_INPUT_CONCURRENCY_NONE = 0,
70fb66dd9f95a1168698f072c4e5c2a2cf8c49a80fEric Laurent        API_INPUT_CONCURRENCY_CALL = (1 << 0),      // Concurrency with a call
71fb66dd9f95a1168698f072c4e5c2a2cf8c49a80fEric Laurent        API_INPUT_CONCURRENCY_CAPTURE = (1 << 1),   // Concurrency with another capture
724342335fb84bfa4ec5b99e3ef82f186820c2275fEric Laurent
734342335fb84bfa4ec5b99e3ef82f186820c2275fEric Laurent        API_INPUT_CONCURRENCY_ALL = (API_INPUT_CONCURRENCY_CALL | API_INPUT_CONCURRENCY_CAPTURE),
74fb66dd9f95a1168698f072c4e5c2a2cf8c49a80fEric Laurent   };
75fb66dd9f95a1168698f072c4e5c2a2cf8c49a80fEric Laurent
76fb66dd9f95a1168698f072c4e5c2a2cf8c49a80fEric Laurent   typedef uint32_t concurrency_type__mask_t;
77fb66dd9f95a1168698f072c4e5c2a2cf8c49a80fEric Laurent
7897bb33f58d742539f3382583d7978fca71ffa2d5Jean-Michel Trivipublic:
79e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual ~AudioPolicyInterface() {}
80e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    //
81e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // configuration functions
82e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    //
83e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
84e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // indicate a change in device connection status
85e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual status_t setDeviceConnectionState(audio_devices_t device,
863b73df74357b33869b39a1d69427673c780bd805Eric Laurent                                              audio_policy_dev_state_t state,
87e743a47f445f02a0612018fa5640301304844fbfPaul McLean                                              const char *device_address,
88e743a47f445f02a0612018fa5640301304844fbfPaul McLean                                              const char *device_name) = 0;
89e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // retrieve a device connection status
903b73df74357b33869b39a1d69427673c780bd805Eric Laurent    virtual audio_policy_dev_state_t getDeviceConnectionState(audio_devices_t device,
91e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent                                                                          const char *device_address) = 0;
92f862bc6a7a35054e38cb50fa16ae7a07f683ee01Pavlin Radoslavov    // indicate a change in device configuration
93f862bc6a7a35054e38cb50fa16ae7a07f683ee01Pavlin Radoslavov    virtual status_t handleDeviceConfigChange(audio_devices_t device,
94f862bc6a7a35054e38cb50fa16ae7a07f683ee01Pavlin Radoslavov                                              const char *device_address,
95f862bc6a7a35054e38cb50fa16ae7a07f683ee01Pavlin Radoslavov                                              const char *device_name) = 0;
963b73df74357b33869b39a1d69427673c780bd805Eric Laurent    // indicate a change in phone state. Valid phones states are defined by audio_mode_t
973b73df74357b33869b39a1d69427673c780bd805Eric Laurent    virtual void setPhoneState(audio_mode_t state) = 0;
98e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // force using a specific device category for the specified usage
993b73df74357b33869b39a1d69427673c780bd805Eric Laurent    virtual void setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) = 0;
100e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // retrieve current device category forced for a given usage
1013b73df74357b33869b39a1d69427673c780bd805Eric Laurent    virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) = 0;
102e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // set a system property (e.g. camera sound always audible)
103e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual void setSystemProperty(const char* property, const char* value) = 0;
104e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // check proper initialization
105e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual status_t initCheck() = 0;
106e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
107e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    //
108e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // Audio routing query functions
109e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    //
110e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
111e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // request an output appropriate for playback of the supplied stream type and parameters
1123b73df74357b33869b39a1d69427673c780bd805Eric Laurent    virtual audio_io_handle_t getOutput(audio_stream_type_t stream,
113e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent                                        uint32_t samplingRate,
114e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent                                        audio_format_t format,
115e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent                                        audio_channel_mask_t channelMask,
1163b73df74357b33869b39a1d69427673c780bd805Eric Laurent                                        audio_output_flags_t flags,
117e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent                                        const audio_offload_info_t *offloadInfo) = 0;
118e83b55dc29ca16092ba02f36f55fa6e0e37fd78cEric Laurent    virtual status_t getOutputForAttr(const audio_attributes_t *attr,
119e83b55dc29ca16092ba02f36f55fa6e0e37fd78cEric Laurent                                        audio_io_handle_t *output,
120e83b55dc29ca16092ba02f36f55fa6e0e37fd78cEric Laurent                                        audio_session_t session,
121e83b55dc29ca16092ba02f36f55fa6e0e37fd78cEric Laurent                                        audio_stream_type_t *stream,
1228c7e6dac6f5eb38cef627dab92eac8b38513450cEric Laurent                                        uid_t uid,
12320b9ef0b55c9150ae11057ab997ae61be2d496efEric Laurent                                        const audio_config_t *config,
124e83b55dc29ca16092ba02f36f55fa6e0e37fd78cEric Laurent                                        audio_output_flags_t flags,
125aa9811945f575614b3482d09e4d969792701cebbPaul McLean                                        int selectedDeviceId,
12620b9ef0b55c9150ae11057ab997ae61be2d496efEric Laurent                                        audio_port_handle_t *portId) = 0;
127e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // indicates to the audio policy manager that the output starts being used by corresponding stream.
128e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual status_t startOutput(audio_io_handle_t output,
1293b73df74357b33869b39a1d69427673c780bd805Eric Laurent                                 audio_stream_type_t stream,
130e83b55dc29ca16092ba02f36f55fa6e0e37fd78cEric Laurent                                 audio_session_t session) = 0;
131e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // indicates to the audio policy manager that the output stops being used by corresponding stream.
132e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual status_t stopOutput(audio_io_handle_t output,
1333b73df74357b33869b39a1d69427673c780bd805Eric Laurent                                audio_stream_type_t stream,
134e83b55dc29ca16092ba02f36f55fa6e0e37fd78cEric Laurent                                audio_session_t session) = 0;
135e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // releases the output.
136e83b55dc29ca16092ba02f36f55fa6e0e37fd78cEric Laurent    virtual void releaseOutput(audio_io_handle_t output,
137e83b55dc29ca16092ba02f36f55fa6e0e37fd78cEric Laurent                               audio_stream_type_t stream,
138e83b55dc29ca16092ba02f36f55fa6e0e37fd78cEric Laurent                               audio_session_t session) = 0;
139e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
140e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // request an input appropriate for record from the supplied device with supplied parameters.
141caf7f48a0ef558689d39aafd187c1571ff4128b4Eric Laurent    virtual status_t getInputForAttr(const audio_attributes_t *attr,
142caf7f48a0ef558689d39aafd187c1571ff4128b4Eric Laurent                                     audio_io_handle_t *input,
143caf7f48a0ef558689d39aafd187c1571ff4128b4Eric Laurent                                     audio_session_t session,
1448c7e6dac6f5eb38cef627dab92eac8b38513450cEric Laurent                                     uid_t uid,
14520b9ef0b55c9150ae11057ab997ae61be2d496efEric Laurent                                     const audio_config_base_t *config,
14697bb33f58d742539f3382583d7978fca71ffa2d5Jean-Michel Trivi                                     audio_input_flags_t flags,
147466dc8ed6ca6b7f585104806c48613dd34e608c9Paul McLean                                     audio_port_handle_t selectedDeviceId,
14820b9ef0b55c9150ae11057ab997ae61be2d496efEric Laurent                                     input_type_t *inputType,
14920b9ef0b55c9150ae11057ab997ae61be2d496efEric Laurent                                     audio_port_handle_t *portId) = 0;
150e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // indicates to the audio policy manager that the input starts being used.
1514dc680607181e6a76f4e91a39366c4f5dfb7b03eEric Laurent    virtual status_t startInput(audio_io_handle_t input,
152fb66dd9f95a1168698f072c4e5c2a2cf8c49a80fEric Laurent                                audio_session_t session,
153fb66dd9f95a1168698f072c4e5c2a2cf8c49a80fEric Laurent                                concurrency_type__mask_t *concurrency) = 0;
154e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // indicates to the audio policy manager that the input stops being used.
1554dc680607181e6a76f4e91a39366c4f5dfb7b03eEric Laurent    virtual status_t stopInput(audio_io_handle_t input,
1564dc680607181e6a76f4e91a39366c4f5dfb7b03eEric Laurent                               audio_session_t session) = 0;
157e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // releases the input.
1584dc680607181e6a76f4e91a39366c4f5dfb7b03eEric Laurent    virtual void releaseInput(audio_io_handle_t input,
1594dc680607181e6a76f4e91a39366c4f5dfb7b03eEric Laurent                              audio_session_t session) = 0;
160e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
161e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    //
162e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // volume control functions
163e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    //
164e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
165e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // initialises stream volume conversion parameters by specifying volume index range.
1663b73df74357b33869b39a1d69427673c780bd805Eric Laurent    virtual void initStreamVolume(audio_stream_type_t stream,
167e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent                                      int indexMin,
168e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent                                      int indexMax) = 0;
169e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
170e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // sets the new stream volume at a level corresponding to the supplied index for the
1715a2b62984c7cecd1761fe272c078dd814c167942Eric Laurent    // supplied device. By convention, specifying AUDIO_DEVICE_OUT_DEFAULT_FOR_VOLUME means
172e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // setting volume for all devices
1733b73df74357b33869b39a1d69427673c780bd805Eric Laurent    virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
174e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent                                          int index,
175e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent                                          audio_devices_t device) = 0;
176e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
177e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // retrieve current volume index for the specified stream and the
1785a2b62984c7cecd1761fe272c078dd814c167942Eric Laurent    // specified device. By convention, specifying AUDIO_DEVICE_OUT_DEFAULT_FOR_VOLUME means
179e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // querying the volume of the active device.
1803b73df74357b33869b39a1d69427673c780bd805Eric Laurent    virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
181e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent                                          int *index,
182e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent                                          audio_devices_t device) = 0;
183e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
184e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // return the strategy corresponding to a given stream type
1853b73df74357b33869b39a1d69427673c780bd805Eric Laurent    virtual uint32_t getStrategyForStream(audio_stream_type_t stream) = 0;
186e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
187e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // return the enabled output devices for the given stream type
1883b73df74357b33869b39a1d69427673c780bd805Eric Laurent    virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream) = 0;
189e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
190e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // Audio effect management
191e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc) = 0;
192e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual status_t registerEffect(const effect_descriptor_t *desc,
193e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent                                    audio_io_handle_t io,
194e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent                                    uint32_t strategy,
195e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent                                    int session,
196e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent                                    int id) = 0;
197e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual status_t unregisterEffect(int id) = 0;
198e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual status_t setEffectEnabled(int id, bool enabled) = 0;
199e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
2003b73df74357b33869b39a1d69427673c780bd805Eric Laurent    virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs = 0) const = 0;
2013b73df74357b33869b39a1d69427673c780bd805Eric Laurent    virtual bool isStreamActiveRemotely(audio_stream_type_t stream,
2023b73df74357b33869b39a1d69427673c780bd805Eric Laurent                                        uint32_t inPastMs = 0) const = 0;
203e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual bool isSourceActive(audio_source_t source) const = 0;
204e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
205e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    //dump state
206e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual status_t    dump(int fd) = 0;
207e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
208e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo) = 0;
2096a94d69dc4f32abb53c466a96f905bb199be6417Eric Laurent
2106a94d69dc4f32abb53c466a96f905bb199be6417Eric Laurent    virtual status_t listAudioPorts(audio_port_role_t role,
2116a94d69dc4f32abb53c466a96f905bb199be6417Eric Laurent                                    audio_port_type_t type,
2126a94d69dc4f32abb53c466a96f905bb199be6417Eric Laurent                                    unsigned int *num_ports,
2136a94d69dc4f32abb53c466a96f905bb199be6417Eric Laurent                                    struct audio_port *ports,
2146a94d69dc4f32abb53c466a96f905bb199be6417Eric Laurent                                    unsigned int *generation) = 0;
2156a94d69dc4f32abb53c466a96f905bb199be6417Eric Laurent    virtual status_t getAudioPort(struct audio_port *port) = 0;
2166a94d69dc4f32abb53c466a96f905bb199be6417Eric Laurent    virtual status_t createAudioPatch(const struct audio_patch *patch,
2176a94d69dc4f32abb53c466a96f905bb199be6417Eric Laurent                                       audio_patch_handle_t *handle,
2186a94d69dc4f32abb53c466a96f905bb199be6417Eric Laurent                                       uid_t uid) = 0;
2196a94d69dc4f32abb53c466a96f905bb199be6417Eric Laurent    virtual status_t releaseAudioPatch(audio_patch_handle_t handle,
2206a94d69dc4f32abb53c466a96f905bb199be6417Eric Laurent                                          uid_t uid) = 0;
2216a94d69dc4f32abb53c466a96f905bb199be6417Eric Laurent    virtual status_t listAudioPatches(unsigned int *num_patches,
2226a94d69dc4f32abb53c466a96f905bb199be6417Eric Laurent                                      struct audio_patch *patches,
2236a94d69dc4f32abb53c466a96f905bb199be6417Eric Laurent                                      unsigned int *generation) = 0;
2246a94d69dc4f32abb53c466a96f905bb199be6417Eric Laurent    virtual status_t setAudioPortConfig(const struct audio_port_config *config) = 0;
2258c7e6dac6f5eb38cef627dab92eac8b38513450cEric Laurent    virtual void releaseResourcesForUid(uid_t uid) = 0;
2266a94d69dc4f32abb53c466a96f905bb199be6417Eric Laurent
227df3dc7e2fe6c639529b70e3f3a7d2bf0f4c6e871Eric Laurent    virtual status_t acquireSoundTriggerSession(audio_session_t *session,
228df3dc7e2fe6c639529b70e3f3a7d2bf0f4c6e871Eric Laurent                                           audio_io_handle_t *ioHandle,
229df3dc7e2fe6c639529b70e3f3a7d2bf0f4c6e871Eric Laurent                                           audio_devices_t *device) = 0;
230df3dc7e2fe6c639529b70e3f3a7d2bf0f4c6e871Eric Laurent
231df3dc7e2fe6c639529b70e3f3a7d2bf0f4c6e871Eric Laurent    virtual status_t releaseSoundTriggerSession(audio_session_t session) = 0;
232baac183f3808d7b68f184647a97bd381620415feEric Laurent
233e964d4e421e2d1ca937227a580c0c837091a11e3Chih-Hung Hsieh    virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes) = 0;
234baac183f3808d7b68f184647a97bd381620415feEric Laurent    virtual status_t unregisterPolicyMixes(Vector<AudioMix> mixes) = 0;
235554a277d4e42a3d3df3d90ba0e7dfa2d31690e32Eric Laurent
236554a277d4e42a3d3df3d90ba0e7dfa2d31690e32Eric Laurent    virtual status_t startAudioSource(const struct audio_port_config *source,
237554a277d4e42a3d3df3d90ba0e7dfa2d31690e32Eric Laurent                                      const audio_attributes_t *attributes,
238559d439c6fe8679e3c52f1cf265d46d7d2e65b68Glenn Kasten                                      audio_patch_handle_t *handle,
239d60560af7cb559762593161c8202459cc01fb0f5Eric Laurent                                      uid_t uid) = 0;
240559d439c6fe8679e3c52f1cf265d46d7d2e65b68Glenn Kasten    virtual status_t stopAudioSource(audio_patch_handle_t handle) = 0;
2412ddee19245641e86bca436dda23a0f5089bf2ab5Andy Hung
2422ddee19245641e86bca436dda23a0f5089bf2ab5Andy Hung    virtual status_t setMasterMono(bool mono) = 0;
2432ddee19245641e86bca436dda23a0f5089bf2ab5Andy Hung    virtual status_t getMasterMono(bool *mono) = 0;
244e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent};
245e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
246e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
247e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent// Audio Policy client Interface
248e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurentclass AudioPolicyClientInterface
249e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent{
250e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurentpublic:
251e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual ~AudioPolicyClientInterface() {}
252e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
253e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    //
254e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // Audio HW module functions
255e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    //
256e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
257e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // loads a HW module.
258e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual audio_module_handle_t loadHwModule(const char *name) = 0;
259e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
260e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    //
261e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // Audio output Control functions
262e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    //
263e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
264e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // opens an audio output with the requested parameters. The parameter values can indicate to use the default values
265e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // in case the audio policy manager has no specific requirements for the output being opened.
266e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // When the function returns, the parameter values reflect the actual values used by the audio hardware output stream.
267e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // The audio policy manager can check if the proposed parameters are suitable or not and act accordingly.
268cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent    virtual status_t openOutput(audio_module_handle_t module,
269cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent                                audio_io_handle_t *output,
270cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent                                audio_config_t *config,
271cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent                                audio_devices_t *devices,
272cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent                                const String8& address,
273cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent                                uint32_t *latencyMs,
274cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent                                audio_output_flags_t flags) = 0;
275e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // creates a special output that is duplicated to the two outputs passed as arguments. The duplication is performed by
276e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // a special mixer thread in the AudioFlinger.
277e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, audio_io_handle_t output2) = 0;
278e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // closes the output stream
279e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual status_t closeOutput(audio_io_handle_t output) = 0;
280e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // suspends the output. When an output is suspended, the corresponding audio hardware output stream is placed in
281e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // standby and the AudioTracks attached to the mixer thread are still processed but the output mix is discarded.
282e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual status_t suspendOutput(audio_io_handle_t output) = 0;
283e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // restores a suspended output.
284e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual status_t restoreOutput(audio_io_handle_t output) = 0;
285e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
286e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    //
287e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // Audio input Control functions
288e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    //
289e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
290e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // opens an audio input
291cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent    virtual status_t openInput(audio_module_handle_t module,
292cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent                               audio_io_handle_t *input,
293cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent                               audio_config_t *config,
294cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent                               audio_devices_t *device,
295cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent                               const String8& address,
296cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent                               audio_source_t source,
297cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent                               audio_input_flags_t flags) = 0;
298e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // closes an audio input
299e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual status_t closeInput(audio_io_handle_t input) = 0;
300e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    //
301e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // misc control functions
302e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    //
303e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
304e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // set a stream volume for a particular output. For the same user setting, a given stream type can have different volumes
305e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // for each output (destination device) it is attached to.
3063b73df74357b33869b39a1d69427673c780bd805Eric Laurent    virtual status_t setStreamVolume(audio_stream_type_t stream, float volume, audio_io_handle_t output, int delayMs = 0) = 0;
307e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
308e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // invalidate a stream type, causing a reroute to an unspecified new output
3093b73df74357b33869b39a1d69427673c780bd805Eric Laurent    virtual status_t invalidateStream(audio_stream_type_t stream) = 0;
310e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
311e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // function enabling to send proprietary informations directly from audio policy manager to audio hardware interface.
312e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual void setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs, int delayMs = 0) = 0;
313e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // function enabling to receive proprietary informations directly from audio hardware interface to audio policy manager.
314e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) = 0;
315e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
316e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // request the playback of a tone on the specified stream: used for instance to replace notification sounds when playing
317e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // over a telephony device during a phone call.
3183b73df74357b33869b39a1d69427673c780bd805Eric Laurent    virtual status_t startTone(audio_policy_tone_t tone, audio_stream_type_t stream) = 0;
319e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual status_t stopTone() = 0;
320e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
321e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // set down link audio volume.
322e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    virtual status_t setVoiceVolume(float volume, int delayMs = 0) = 0;
323e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
324e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent    // move effect to the specified output
325d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten    virtual status_t moveEffects(audio_session_t session,
326e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent                                     audio_io_handle_t srcOutput,
327e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent                                     audio_io_handle_t dstOutput) = 0;
328e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
329951f455566775e5f01e67c5ee26863d7d19209d7Eric Laurent    /* Create a patch between several source and sink ports */
330951f455566775e5f01e67c5ee26863d7d19209d7Eric Laurent    virtual status_t createAudioPatch(const struct audio_patch *patch,
331951f455566775e5f01e67c5ee26863d7d19209d7Eric Laurent                                       audio_patch_handle_t *handle,
332951f455566775e5f01e67c5ee26863d7d19209d7Eric Laurent                                       int delayMs) = 0;
333951f455566775e5f01e67c5ee26863d7d19209d7Eric Laurent
334951f455566775e5f01e67c5ee26863d7d19209d7Eric Laurent    /* Release a patch */
335951f455566775e5f01e67c5ee26863d7d19209d7Eric Laurent    virtual status_t releaseAudioPatch(audio_patch_handle_t handle,
336951f455566775e5f01e67c5ee26863d7d19209d7Eric Laurent                                       int delayMs) = 0;
337951f455566775e5f01e67c5ee26863d7d19209d7Eric Laurent
338e1715a465a29db625da9d0ea365edf371e39e201Eric Laurent    /* Set audio port configuration */
339e1715a465a29db625da9d0ea365edf371e39e201Eric Laurent    virtual status_t setAudioPortConfig(const struct audio_port_config *config, int delayMs) = 0;
340e1715a465a29db625da9d0ea365edf371e39e201Eric Laurent
341b52c152d553556b2d227ffc943489de0c60b4b02Eric Laurent    virtual void onAudioPortListUpdate() = 0;
342b52c152d553556b2d227ffc943489de0c60b4b02Eric Laurent
343b52c152d553556b2d227ffc943489de0c60b4b02Eric Laurent    virtual void onAudioPatchListUpdate() = 0;
344de3f8392fbf380ba6f09d009b00d7172477389a2Eric Laurent
345f0c6d7d940314dbec47c9b53cb99da79eb022787Glenn Kasten    virtual audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t use) = 0;
346de80105c3f2db0eabd47640c49387ea3b44d4782Jean-Michel Trivi
347de80105c3f2db0eabd47640c49387ea3b44d4782Jean-Michel Trivi    virtual void onDynamicPolicyMixStateUpdate(String8 regId, int32_t state) = 0;
3482f4fe9f7df8f22c6bc8745407d19df73128810ecJean-Michel Trivi
3492f4fe9f7df8f22c6bc8745407d19df73128810ecJean-Michel Trivi    virtual void onRecordingConfigurationUpdate(int event, audio_session_t session,
3507281aa9810b33eff47b00104db26c97c77931611Jean-Michel Trivi                    audio_source_t source,
3517281aa9810b33eff47b00104db26c97c77931611Jean-Michel Trivi                    const struct audio_config_base *clientConfig,
3528c7cf3b7d0d7bccb9affbc34ae2ab2d6b332f972Jean-Michel Trivi                    const struct audio_config_base *deviceConfig,
3538c7cf3b7d0d7bccb9affbc34ae2ab2d6b332f972Jean-Michel Trivi                    audio_patch_handle_t patchHandle) = 0;
354e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent};
355e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
356e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurentextern "C" AudioPolicyInterface* createAudioPolicyManager(AudioPolicyClientInterface *clientInterface);
357e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurentextern "C" void destroyAudioPolicyManager(AudioPolicyInterface *interface);
358e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
359e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
360e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent}; // namespace android
361e552edb33fb5873179ae0a46d9579d1103eb13c6Eric Laurent
362dce54a1492c410ad0d93253b341fb33305337505Eric Laurent#endif // ANDROID_AUDIOPOLICY_INTERFACE_H
363