AudioPolicyClientImpl.cpp revision 951f455566775e5f01e67c5ee26863d7d19209d7
1/*
2 * Copyright (C) 2009 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 "AudioPolicyClientImpl"
18//#define LOG_NDEBUG 0
19
20#include <utils/Log.h>
21#include "AudioPolicyService.h"
22
23namespace android {
24
25/* implementation of the client interface from the policy manager */
26
27audio_module_handle_t AudioPolicyService::AudioPolicyClient::loadHwModule(const char *name)
28{
29    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
30    if (af == 0) {
31        ALOGW("%s: could not get AudioFlinger", __func__);
32        return 0;
33    }
34
35    return af->loadHwModule(name);
36}
37
38audio_io_handle_t AudioPolicyService::AudioPolicyClient::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    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
48    if (af == 0) {
49        ALOGW("%s: could not get AudioFlinger", __func__);
50        return 0;
51    }
52    return af->openOutput(module, pDevices, pSamplingRate, pFormat, pChannelMask,
53                          pLatencyMs, flags, offloadInfo);
54}
55
56audio_io_handle_t AudioPolicyService::AudioPolicyClient::openDuplicateOutput(
57                                                                audio_io_handle_t output1,
58                                                                audio_io_handle_t output2)
59{
60    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
61    if (af == 0) {
62        ALOGW("%s: could not get AudioFlinger", __func__);
63        return 0;
64    }
65    return af->openDuplicateOutput(output1, output2);
66}
67
68status_t AudioPolicyService::AudioPolicyClient::closeOutput(audio_io_handle_t output)
69{
70    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
71    if (af == 0) {
72        return PERMISSION_DENIED;
73    }
74
75    return af->closeOutput(output);
76}
77
78status_t AudioPolicyService::AudioPolicyClient::suspendOutput(audio_io_handle_t output)
79{
80    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
81    if (af == 0) {
82        ALOGW("%s: could not get AudioFlinger", __func__);
83        return PERMISSION_DENIED;
84    }
85
86    return af->suspendOutput(output);
87}
88
89status_t AudioPolicyService::AudioPolicyClient::restoreOutput(audio_io_handle_t output)
90{
91    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
92    if (af == 0) {
93        ALOGW("%s: could not get AudioFlinger", __func__);
94        return PERMISSION_DENIED;
95    }
96
97    return af->restoreOutput(output);
98}
99
100audio_io_handle_t AudioPolicyService::AudioPolicyClient::openInput(audio_module_handle_t module,
101                              audio_devices_t *pDevices,
102                              uint32_t *pSamplingRate,
103                              audio_format_t *pFormat,
104                              audio_channel_mask_t *pChannelMask)
105{
106    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
107    if (af == 0) {
108        ALOGW("%s: could not get AudioFlinger", __func__);
109        return 0;
110    }
111
112    return af->openInput(module, pDevices, pSamplingRate, pFormat, pChannelMask);
113}
114
115status_t AudioPolicyService::AudioPolicyClient::closeInput(audio_io_handle_t input)
116{
117    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
118    if (af == 0) {
119        return PERMISSION_DENIED;
120    }
121
122    return af->closeInput(input);
123}
124
125status_t AudioPolicyService::AudioPolicyClient::setStreamVolume(audio_stream_type_t stream,
126                     float volume, audio_io_handle_t output,
127                     int delay_ms)
128{
129    return mAudioPolicyService->setStreamVolume(stream, volume, output,
130                                               delay_ms);
131}
132
133status_t AudioPolicyService::AudioPolicyClient::invalidateStream(audio_stream_type_t stream)
134{
135    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
136    if (af == 0) {
137        return PERMISSION_DENIED;
138    }
139
140    return af->invalidateStream(stream);
141}
142
143void AudioPolicyService::AudioPolicyClient::setParameters(audio_io_handle_t io_handle,
144                   const String8& keyValuePairs,
145                   int delay_ms)
146{
147    mAudioPolicyService->setParameters(io_handle, keyValuePairs.string(), delay_ms);
148}
149
150String8 AudioPolicyService::AudioPolicyClient::getParameters(audio_io_handle_t io_handle,
151                      const String8& keys)
152{
153    String8 result = AudioSystem::getParameters(io_handle, keys);
154    return result;
155}
156
157status_t AudioPolicyService::AudioPolicyClient::startTone(audio_policy_tone_t tone,
158              audio_stream_type_t stream)
159{
160    return mAudioPolicyService->startTone(tone, stream);
161}
162
163status_t AudioPolicyService::AudioPolicyClient::stopTone()
164{
165    return mAudioPolicyService->stopTone();
166}
167
168status_t AudioPolicyService::AudioPolicyClient::setVoiceVolume(float volume, int delay_ms)
169{
170    return mAudioPolicyService->setVoiceVolume(volume, delay_ms);
171}
172
173status_t AudioPolicyService::AudioPolicyClient::moveEffects(int session,
174                        audio_io_handle_t src_output,
175                        audio_io_handle_t dst_output)
176{
177    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
178    if (af == 0) {
179        return PERMISSION_DENIED;
180    }
181
182    return af->moveEffects(session, src_output, dst_output);
183}
184
185status_t AudioPolicyService::AudioPolicyClient::createAudioPatch(const struct audio_patch *patch,
186                                                                  audio_patch_handle_t *handle,
187                                                                  int delayMs)
188{
189    return mAudioPolicyService->clientCreateAudioPatch(patch, handle, delayMs);
190}
191
192status_t AudioPolicyService::AudioPolicyClient::releaseAudioPatch(audio_patch_handle_t handle,
193                                                                  int delayMs)
194{
195    return mAudioPolicyService->clientReleaseAudioPatch(handle, delayMs);
196}
197
198}; // namespace android
199