blob: d5cb6c16c0d1ff50c6f45c341e18ca0e73d81659 [file] [log] [blame]
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -07001/*
Mingming Yin0ae14ea2014-07-09 17:55:56 -07002 * Copyright (c) 2013, 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
21#include <stdint.h>
22#include <sys/types.h>
23#include <utils/Timers.h>
24#include <utils/Errors.h>
25#include <utils/KeyedVector.h>
Mingming Yin0ae14ea2014-07-09 17:55:56 -070026#include <hardware_legacy/AudioPolicyManagerBase.h>
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070027
28
Mingming Yin0ae14ea2014-07-09 17:55:56 -070029namespace android_audio_legacy {
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070030
31// ----------------------------------------------------------------------------
32
Mingming Yin0ae14ea2014-07-09 17:55:56 -070033class AudioPolicyManager: public AudioPolicyManagerBase
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070034{
35
36public:
Mingming Yin0ae14ea2014-07-09 17:55:56 -070037 AudioPolicyManager(AudioPolicyClientInterface *clientInterface)
38 : AudioPolicyManagerBase(clientInterface) {
39 mHdmiAudioDisabled = false;
40 mHdmiAudioEvent = false; }
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070041
Mingming Yin0ae14ea2014-07-09 17:55:56 -070042 virtual ~AudioPolicyManager() {}
43
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070044 virtual status_t setDeviceConnectionState(audio_devices_t device,
Mingming Yin0ae14ea2014-07-09 17:55:56 -070045 AudioSystem::device_connection_state state,
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070046 const char *device_address);
Mingming Yin0ae14ea2014-07-09 17:55:56 -070047 virtual void setForceUse(AudioSystem::force_use usage, AudioSystem::forced_config config);
48 virtual audio_io_handle_t getInput(int inputSource,
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070049 uint32_t samplingRate,
Mingming Yin0ae14ea2014-07-09 17:55:56 -070050 uint32_t format,
51 uint32_t channels,
52 AudioSystem::audio_in_acoustics acoustics);
53 virtual audio_io_handle_t getOutput(AudioSystem::stream_type stream,
54 uint32_t samplingRate = 0,
55 uint32_t format = AudioSystem::FORMAT_DEFAULT,
56 uint32_t channels = 0,
57 AudioSystem::output_flags flags =
58 AudioSystem::OUTPUT_FLAG_INDIRECT,
59 const audio_offload_info_t *offloadInfo = NULL);
Naresh Tanniru36c08932014-01-27 18:40:53 +053060
Zhou Songc0d78c22014-06-16 10:48:22 +080061 virtual status_t stopOutput(audio_io_handle_t output,
62 AudioSystem::stream_type stream,
63 int session = 0);
64
Naresh Tanniru36c08932014-01-27 18:40:53 +053065 virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo);
66
Mingming Yin0ae14ea2014-07-09 17:55:56 -070067 virtual void setPhoneState(int state);
Karthik Reddy Katta060a6c42014-05-20 15:21:28 +053068
Mingming Yin0ae14ea2014-07-09 17:55:56 -070069 // true if given state represents a device in a telephony or VoIP call
70 virtual bool isStateInCall(int state);
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070071protected:
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070072 // return the strategy corresponding to a given stream type
Mingming Yin0ae14ea2014-07-09 17:55:56 -070073 static routing_strategy getStrategy(AudioSystem::stream_type stream);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070074
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070075 // return appropriate device for streams handled by the specified strategy according to current
76 // phone state, connected devices...
77 // if fromCache is true, the device is returned from mDeviceForStrategy[],
78 // otherwise it is determine by current state
79 // (device connected,phone state, force use, a2dp output...)
80 // This allows to:
81 // 1 speed up process when the state is stable (when starting or stopping an output)
82 // 2 access to either current device selection (fromCache == true) or
83 // "future" device selection (fromCache == false) when called from a context
84 // where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND
85 // before updateDevicesAndOutputs() is called.
86 virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy,
Mingming Yin0ae14ea2014-07-09 17:55:56 -070087 bool fromCache = true);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070088 // select input device corresponding to requested audio source
Mingming Yin0ae14ea2014-07-09 17:55:56 -070089 virtual audio_devices_t getDeviceForInputSource(int inputSource);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070090
91 // compute the actual volume for a given stream according to the requested index and a particular
92 // device
Mingming Yin0ae14ea2014-07-09 17:55:56 -070093 virtual float computeVolume(int stream, int index, audio_io_handle_t output, audio_devices_t device);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070094
95 // check that volume change is permitted, compute and send new volume to audio hardware
Mingming Yin0ae14ea2014-07-09 17:55:56 -070096 status_t checkAndSetVolume(int stream, int index, audio_io_handle_t output, audio_devices_t device, int delayMs = 0, bool force = false);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070097
98 // returns the category the device belongs to with regard to volume curve management
99 static device_category getDeviceCategory(audio_devices_t device);
100
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700101 static const char* HDMI_SPKR_STR;
Tanya Finkelde496d82014-03-05 23:59:45 +0200102
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700103 //parameter indicates of HDMI speakers disabled from the Qualcomm settings
104 bool mHdmiAudioDisabled;
Tanya Finkelde496d82014-03-05 23:59:45 +0200105
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700106 //parameter indicates if HDMI plug in/out detected
107 bool mHdmiAudioEvent;
Tanya Finkelde496d82014-03-05 23:59:45 +0200108
Pavan Chikkala785b6932014-03-24 18:58:11 +0530109private:
Zhou Songc0d78c22014-06-16 10:48:22 +0800110 void handleNotificationRoutingForStream(AudioSystem::stream_type stream);
111
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700112 // Used for voip + voice concurrency usecase
113 int mPrevPhoneState;
114 static int mvoice_call_state;
Mingming Yin0670f162014-06-12 16:05:49 -0700115
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700116};
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700117};