1 /*
2  * Copyright (C) 2011 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 "AudioPolicyCompatClient"
18 //#define LOG_NDEBUG 0
19 
20 #include <stdint.h>
21 
22 #include <hardware/hardware.h>
23 #include <system/audio.h>
24 #include <system/audio_policy.h>
25 #include <hardware/audio_policy.h>
26 
27 #include <hardware_legacy/AudioSystemLegacy.h>
28 
29 #include "AudioPolicyCompatClient.h"
30 
31 namespace android_audio_legacy {
32 
loadHwModule(const char * moduleName)33 audio_module_handle_t AudioPolicyCompatClient::loadHwModule(const char *moduleName)
34 {
35     return mServiceOps->load_hw_module(mService, moduleName);
36 }
37 
openOutput(audio_module_handle_t module,audio_devices_t * pDevices,uint32_t * pSamplingRate,audio_format_t * pFormat,audio_channel_mask_t * pChannelMask,uint32_t * pLatencyMs,audio_output_flags_t flags,const audio_offload_info_t * offloadInfo)38 audio_io_handle_t AudioPolicyCompatClient::openOutput(audio_module_handle_t module,
39                                                       audio_devices_t *pDevices,
40                                                       uint32_t *pSamplingRate,
41                                                       audio_format_t *pFormat,
42                                                       audio_channel_mask_t *pChannelMask,
43                                                       uint32_t *pLatencyMs,
44                                                       audio_output_flags_t flags,
45                                                       const audio_offload_info_t *offloadInfo)
46 {
47     return mServiceOps->open_output_on_module(mService, module, pDevices, pSamplingRate,
48                                               pFormat, pChannelMask, pLatencyMs,
49                                               flags, offloadInfo);
50 }
51 
openDuplicateOutput(audio_io_handle_t output1,audio_io_handle_t output2)52 audio_io_handle_t AudioPolicyCompatClient::openDuplicateOutput(audio_io_handle_t output1,
53                                                           audio_io_handle_t output2)
54 {
55     return mServiceOps->open_duplicate_output(mService, output1, output2);
56 }
57 
closeOutput(audio_io_handle_t output)58 status_t AudioPolicyCompatClient::closeOutput(audio_io_handle_t output)
59 {
60     return mServiceOps->close_output(mService, output);
61 }
62 
suspendOutput(audio_io_handle_t output)63 status_t AudioPolicyCompatClient::suspendOutput(audio_io_handle_t output)
64 {
65     return mServiceOps->suspend_output(mService, output);
66 }
67 
restoreOutput(audio_io_handle_t output)68 status_t AudioPolicyCompatClient::restoreOutput(audio_io_handle_t output)
69 {
70     return mServiceOps->restore_output(mService, output);
71 }
72 
openInput(audio_module_handle_t module,audio_devices_t * pDevices,uint32_t * pSamplingRate,audio_format_t * pFormat,audio_channel_mask_t * pChannelMask)73 audio_io_handle_t AudioPolicyCompatClient::openInput(audio_module_handle_t module,
74                                                      audio_devices_t *pDevices,
75                                                      uint32_t *pSamplingRate,
76                                                      audio_format_t *pFormat,
77                                                      audio_channel_mask_t *pChannelMask)
78 {
79     return mServiceOps->open_input_on_module(mService, module, pDevices,
80                                              pSamplingRate, pFormat, pChannelMask);
81 }
82 
closeInput(audio_io_handle_t input)83 status_t AudioPolicyCompatClient::closeInput(audio_io_handle_t input)
84 {
85     return mServiceOps->close_input(mService, input);
86 }
87 
invalidateStream(AudioSystem::stream_type stream)88 status_t AudioPolicyCompatClient::invalidateStream(AudioSystem::stream_type stream)
89 {
90     return mServiceOps->invalidate_stream(mService, (audio_stream_type_t)stream);
91 }
92 
moveEffects(audio_session_t session,audio_io_handle_t srcOutput,audio_io_handle_t dstOutput)93 status_t AudioPolicyCompatClient::moveEffects(audio_session_t session, audio_io_handle_t srcOutput,
94                                                audio_io_handle_t dstOutput)
95 {
96     return mServiceOps->move_effects(mService, session, srcOutput, dstOutput);
97 }
98 
getParameters(audio_io_handle_t ioHandle,const String8 & keys)99 String8 AudioPolicyCompatClient::getParameters(audio_io_handle_t ioHandle, const String8& keys)
100 {
101     char *str;
102     String8 out_str8;
103 
104     str = mServiceOps->get_parameters(mService, ioHandle, keys.string());
105     out_str8 = String8(str);
106     free(str);
107 
108     return out_str8;
109 }
110 
setParameters(audio_io_handle_t ioHandle,const String8 & keyValuePairs,int delayMs)111 void AudioPolicyCompatClient::setParameters(audio_io_handle_t ioHandle,
112                                             const String8& keyValuePairs,
113                                             int delayMs)
114 {
115     mServiceOps->set_parameters(mService, ioHandle, keyValuePairs.string(),
116                            delayMs);
117 }
118 
setStreamVolume(AudioSystem::stream_type stream,float volume,audio_io_handle_t output,int delayMs)119 status_t AudioPolicyCompatClient::setStreamVolume(
120                                              AudioSystem::stream_type stream,
121                                              float volume,
122                                              audio_io_handle_t output,
123                                              int delayMs)
124 {
125     return mServiceOps->set_stream_volume(mService, (audio_stream_type_t)stream,
126                                           volume, output, delayMs);
127 }
128 
startTone(ToneGenerator::tone_type tone,AudioSystem::stream_type stream)129 status_t AudioPolicyCompatClient::startTone(ToneGenerator::tone_type tone,
130                                        AudioSystem::stream_type stream)
131 {
132     return mServiceOps->start_tone(mService,
133                                    AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION,
134                                    (audio_stream_type_t)stream);
135 }
136 
stopTone()137 status_t AudioPolicyCompatClient::stopTone()
138 {
139     return mServiceOps->stop_tone(mService);
140 }
141 
setVoiceVolume(float volume,int delayMs)142 status_t AudioPolicyCompatClient::setVoiceVolume(float volume, int delayMs)
143 {
144     return mServiceOps->set_voice_volume(mService, volume, delayMs);
145 }
146 
147 }; // namespace android_audio_legacy
148