blob: 31dd74d5a43515c17545106414aacb9376f6dbb6
1 | /* |
2 | * Copyright (C) 2014 The Android Open Source Project |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | |
17 | #define LOG_TAG "DLGAudioPolicyManager" |
18 | //#define LOG_NDEBUG 0 |
19 | #include <media/AudioParameter.h> |
20 | #include <media/mediarecorder.h> |
21 | #include <utils/Log.h> |
22 | #include <utils/String16.h> |
23 | #include <utils/String8.h> |
24 | #include <utils/StrongPointer.h> |
25 | |
26 | #include "DLGAudioPolicyManager.h" |
27 | |
28 | |
29 | namespace android { |
30 | // ---------------------------------------------------------------------------- |
31 | // Common audio policy manager code is implemented in AudioPolicyManager class |
32 | // ---------------------------------------------------------------------------- |
33 | |
34 | // --- class factory |
35 | |
36 | |
37 | extern "C" AudioPolicyInterface* createAudioPolicyManager( |
38 | AudioPolicyClientInterface *clientInterface) |
39 | { |
40 | return new DLGAudioPolicyManager(clientInterface); |
41 | } |
42 | |
43 | extern "C" void destroyAudioPolicyManager(AudioPolicyInterface *interface) |
44 | { |
45 | delete interface; |
46 | } |
47 | |
48 | DLGAudioPolicyManager::DLGAudioPolicyManager( |
49 | AudioPolicyClientInterface *clientInterface) |
50 | : AudioPolicyManager(clientInterface), mForceSubmixInputSelection(false) |
51 | { |
52 | } |
53 | |
54 | float DLGAudioPolicyManager::computeVolume(audio_stream_type_t stream, |
55 | int index, |
56 | audio_devices_t device) |
57 | { |
58 | // We only use master volume, so all audio flinger streams |
59 | // should be set to maximum |
60 | (void)stream; |
61 | (void)index; |
62 | (void)device; |
63 | return AudioPolicyManager::computeVolume(stream,index,device); |
64 | } |
65 | |
66 | status_t DLGAudioPolicyManager::setDeviceConnectionState(audio_devices_t device, |
67 | audio_policy_dev_state_t state, |
68 | const char *device_address, |
69 | const char *device_name) |
70 | { |
71 | audio_devices_t tmp = AUDIO_DEVICE_NONE;; |
72 | ALOGV("setDeviceConnectionState %08x %x %s", device, state, |
73 | device_address ? device_address : "(null)"); |
74 | |
75 | // If the input device is the remote submix and an address starting with "force=" was |
76 | // specified, enable "force=1" / disable "force=0" the forced selection of the remote submix |
77 | // input device over hardware input devices (e.g RemoteControl). |
78 | if (device == AUDIO_DEVICE_IN_REMOTE_SUBMIX && device_address) { |
79 | AudioParameter parameters = AudioParameter(String8(device_address)); |
80 | int forceValue; |
81 | if (parameters.getInt(String8("force"), forceValue) == OK) { |
82 | mForceSubmixInputSelection = forceValue != 0; |
83 | } |
84 | } |
85 | |
86 | status_t ret = 0; |
87 | if (device != AUDIO_DEVICE_IN_REMOTE_SUBMIX) { |
88 | ret = AudioPolicyManager::setDeviceConnectionState( |
89 | device, state, device_address,device_name); |
90 | } |
91 | |
92 | return ret; |
93 | } |
94 | |
95 | audio_devices_t DLGAudioPolicyManager::getDeviceForInputSource(audio_source_t inputSource) |
96 | { |
97 | uint32_t device = AUDIO_DEVICE_NONE; |
98 | bool usePhysRemote = true; |
99 | |
100 | if (inputSource == AUDIO_SOURCE_VOICE_RECOGNITION) { |
101 | ALOGV("getDeviceForInputSource %s", mForceSubmixInputSelection ? "use virtual" : ""); |
102 | audio_devices_t availableDeviceTypes = mAvailableInputDevices.types() & |
103 | ~AUDIO_DEVICE_BIT_IN; |
104 | if (availableDeviceTypes & AUDIO_DEVICE_IN_REMOTE_SUBMIX && |
105 | mForceSubmixInputSelection) { |
106 | // REMOTE_SUBMIX should always be avaible, let's make sure it's being forced at the moment |
107 | ALOGV("Virtual remote available"); |
108 | device = AUDIO_DEVICE_IN_REMOTE_SUBMIX; |
109 | } |
110 | else |
111 | device = AudioPolicyManager::getDeviceForInputSource(inputSource); |
112 | } |
113 | else |
114 | device = AudioPolicyManager::getDeviceForInputSource(inputSource); |
115 | |
116 | ALOGV("getDeviceForInputSource() input source %d, device %08x", inputSource, device); |
117 | return device; |
118 | } |
119 | |
120 | } // namespace android |
121 |