blob: 8e47d1908d471c66248537b2573b061821bd6c9e [file] [log] [blame]
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -07001/*
Sharad Sanglef2e11662015-05-28 16:15:16 +05302 * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -07003 * Not a contribution.
4 *
5 * Copyright (C) 2009 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20
Sharad Sanglef2e11662015-05-28 16:15:16 +053021#include <audiopolicy/managerdefault/AudioPolicyManager.h>
22#include <audio_policy_conf.h>
23#include <Volume.h>
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070024
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -070025
26namespace android {
Satya Krishna Pindiproli4cda5352015-08-12 18:21:25 +053027#ifndef AUDIO_EXTN_FORMATS_ENABLED
28#define AUDIO_FORMAT_WMA 0x12000000UL
29#define AUDIO_FORMAT_WMA_PRO 0x13000000UL
30#define AUDIO_FORMAT_FLAC 0x1B000000UL
31#define AUDIO_FORMAT_ALAC 0x1C000000UL
32#define AUDIO_FORMAT_APE 0x1D000000UL
Sharad Sanglef2e11662015-05-28 16:15:16 +053033#endif
34
Manish Dewangan93672f12015-08-24 20:30:31 +053035#ifndef AAC_ADTS_OFFLOAD_ENABLED
36#define AUDIO_FORMAT_AAC_ADTS 0x1E000000UL
37#endif
38
Sharad Sangleb53795f2015-08-19 20:47:12 +053039#ifndef AUDIO_EXTN_AFE_PROXY_ENABLED
Yamit Mehtaa46815c2015-07-14 17:32:52 +053040#define AUDIO_DEVICE_OUT_PROXY 0x1000000
Sharad Sanglef2e11662015-05-28 16:15:16 +053041#endif
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070042// ----------------------------------------------------------------------------
43
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -070044class AudioPolicyManagerCustom: public AudioPolicyManager
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070045{
46
47public:
Sharad Sangle78d53242015-06-04 20:24:10 +053048 AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface);
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070049
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -070050 virtual ~AudioPolicyManagerCustom() {}
Mingming Yin0ae14ea2014-07-09 17:55:56 -070051
Sharad Sanglef2e11662015-05-28 16:15:16 +053052 status_t setDeviceConnectionStateInt(audio_devices_t device,
53 audio_policy_dev_state_t state,
54 const char *device_address,
55 const char *device_name);
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -070056 virtual void setPhoneState(audio_mode_t state);
Zhou Songc0d78c22014-06-16 10:48:22 +080057
Naresh Tanniru36c08932014-01-27 18:40:53 +053058 virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo);
59
Sharad Sangle78d53242015-06-04 20:24:10 +053060 virtual status_t getInputForAttr(const audio_attributes_t *attr,
61 audio_io_handle_t *input,
62 audio_session_t session,
63 uid_t uid,
64 uint32_t samplingRate,
65 audio_format_t format,
66 audio_channel_mask_t channelMask,
67 audio_input_flags_t flags,
68 audio_port_handle_t selectedDeviceId,
69 input_type_t *inputType);
70 // indicates to the audio policy manager that the input starts being used.
71 virtual status_t startInput(audio_io_handle_t input,
72 audio_session_t session);
73 // indicates to the audio policy manager that the input stops being used.
74 virtual status_t stopInput(audio_io_handle_t input,
75 audio_session_t session);
Chaithanya Krishna Bacharaju54177c42015-09-14 15:05:09 +053076 virtual void closeAllInputs();
Sharad Sangledd1e1842015-07-27 15:14:23 +053077
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070078protected:
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070079
Sharad Sanglef2e11662015-05-28 16:15:16 +053080 status_t checkAndSetVolume(audio_stream_type_t stream,
81 int index,
82 const sp<SwAudioOutputDescriptor>& outputDesc,
83 audio_devices_t device,
84 int delayMs = 0, bool force = false);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070085
Sharad Sanglef2e11662015-05-28 16:15:16 +053086 // selects the most appropriate device on output for current state
87 // must be called every time a condition that affects the device choice for a given output is
88 // changed: connected device, phone state, force use, output start, output stop..
89 // see getDeviceForStrategy() for the use of fromCache parameter
90 audio_devices_t getNewOutputDevice(const sp<AudioOutputDescriptor>& outputDesc,
91 bool fromCache);
92 // returns true if given output is direct output
93 bool isDirectOutput(audio_io_handle_t output);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070094
Sharad Sanglef2e11662015-05-28 16:15:16 +053095 // if argument "device" is different from AUDIO_DEVICE_NONE, startSource() will force
96 // the re-evaluation of the output device.
97 status_t startSource(sp<SwAudioOutputDescriptor> outputDesc,
98 audio_stream_type_t stream,
99 audio_devices_t device,
100 uint32_t *delayMs);
101 status_t stopSource(sp<SwAudioOutputDescriptor> outputDesc,
102 audio_stream_type_t stream,
103 bool forceDeviceUpdate);
Sharad Sangleb53795f2015-08-19 20:47:12 +0530104 // event is one of STARTING_OUTPUT, STARTING_BEACON, STOPPING_OUTPUT, STOPPING_BEACON
105 // returns 0 if no mute/unmute event happened, the largest latency of the device where
106 // the mute/unmute happened
Sharad Sanglef2e11662015-05-28 16:15:16 +0530107 uint32_t handleEventForBeacon(int){return 0;}
108 uint32_t setBeaconMute(bool){return 0;}
Sharad Sangle78d53242015-06-04 20:24:10 +0530109#ifdef VOICE_CONCURRENCY
110 static audio_output_flags_t getFallBackPath();
111 int mFallBackflag;
112#endif /*VOICE_CONCURRENCY*/
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700113
Sharad Sanglef2e11662015-05-28 16:15:16 +0530114 // handle special cases for sonification strategy while in call: mute streams or replace by
115 // a special tone in the device used for communication
116 void handleIncallSonification(audio_stream_type_t stream, bool starting, bool stateChange, audio_io_handle_t output);
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -0700117 //parameter indicates of HDMI speakers disabled
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700118 bool mHdmiAudioDisabled;
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700119 //parameter indicates if HDMI plug in/out detected
120 bool mHdmiAudioEvent;
Pavan Chikkala785b6932014-03-24 18:58:11 +0530121private:
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -0700122 // updates device caching and output for streams that can influence the
123 // routing of notifications
124 void handleNotificationRoutingForStream(audio_stream_type_t stream);
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -0700125 // internal method to return the output handle for the given device and format
126 audio_io_handle_t getOutputForDevice(
127 audio_devices_t device,
Sharad Sanglef2e11662015-05-28 16:15:16 +0530128 audio_session_t session,
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -0700129 audio_stream_type_t stream,
130 uint32_t samplingRate,
131 audio_format_t format,
132 audio_channel_mask_t channelMask,
133 audio_output_flags_t flags,
134 const audio_offload_info_t *offloadInfo);
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700135 // Used for voip + voice concurrency usecase
136 int mPrevPhoneState;
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -0700137 int mvoice_call_state;
Sharad Sangle78d53242015-06-04 20:24:10 +0530138#ifdef RECORD_PLAY_CONCURRENCY
139 // Used for record + playback concurrency
140 bool mIsInputRequestOnProgress;
141#endif
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700142};
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -0700143
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700144};