AudioPolicyService.cpp revision f269b8e0e9ab950fc6652b9594b7a3431c81630c
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 "AudioPolicyService"
18//#define LOG_NDEBUG 0
19
20#include "Configuration.h"
21#undef __STRICT_ANSI__
22#define __STDINT_LIMITS
23#define __STDC_LIMIT_MACROS
24#include <stdint.h>
25
26#include <sys/time.h>
27#include <binder/IServiceManager.h>
28#include <utils/Log.h>
29#include <cutils/properties.h>
30#include <binder/IPCThreadState.h>
31#include <utils/String16.h>
32#include <utils/threads.h>
33#include "AudioPolicyService.h"
34#include "ServiceUtilities.h"
35#include <hardware_legacy/power.h>
36#include <media/AudioEffect.h>
37#include <media/EffectsFactoryApi.h>
38
39#include <hardware/hardware.h>
40#include <system/audio.h>
41#include <system/audio_policy.h>
42#include <hardware/audio_policy.h>
43#include <audio_effects/audio_effects_conf.h>
44#include <media/AudioParameter.h>
45
46namespace android {
47
48static const char kDeadlockedString[] = "AudioPolicyService may be deadlocked\n";
49static const char kCmdDeadlockedString[] = "AudioPolicyService command thread may be deadlocked\n";
50
51static const int kDumpLockRetries = 50;
52static const int kDumpLockSleepUs = 20000;
53
54static const nsecs_t kAudioCommandTimeoutNs = seconds(3); // 3 seconds
55
56namespace {
57    extern struct audio_policy_service_ops aps_ops;
58};
59
60// ----------------------------------------------------------------------------
61
62AudioPolicyService::AudioPolicyService()
63    : BnAudioPolicyService(), mpAudioPolicyDev(NULL), mpAudioPolicy(NULL),
64      mAudioPolicyManager(NULL), mAudioPolicyClient(NULL)
65{
66    char value[PROPERTY_VALUE_MAX];
67    const struct hw_module_t *module;
68    int forced_val;
69    int rc;
70
71    Mutex::Autolock _l(mLock);
72
73    // start tone playback thread
74    mTonePlaybackThread = new AudioCommandThread(String8("ApmTone"), this);
75    // start audio commands thread
76    mAudioCommandThread = new AudioCommandThread(String8("ApmAudio"), this);
77    // start output activity command thread
78    mOutputCommandThread = new AudioCommandThread(String8("ApmOutput"), this);
79
80#ifdef USE_LEGACY_AUDIO_POLICY
81    ALOGI("AudioPolicyService CSTOR in legacy mode");
82
83    /* instantiate the audio policy manager */
84    rc = hw_get_module(AUDIO_POLICY_HARDWARE_MODULE_ID, &module);
85    if (rc) {
86        return;
87    }
88    rc = audio_policy_dev_open(module, &mpAudioPolicyDev);
89    ALOGE_IF(rc, "couldn't open audio policy device (%s)", strerror(-rc));
90    if (rc) {
91        return;
92    }
93
94    rc = mpAudioPolicyDev->create_audio_policy(mpAudioPolicyDev, &aps_ops, this,
95                                               &mpAudioPolicy);
96    ALOGE_IF(rc, "couldn't create audio policy (%s)", strerror(-rc));
97    if (rc) {
98        return;
99    }
100
101    rc = mpAudioPolicy->init_check(mpAudioPolicy);
102    ALOGE_IF(rc, "couldn't init_check the audio policy (%s)", strerror(-rc));
103    if (rc) {
104        return;
105    }
106    ALOGI("Loaded audio policy from %s (%s)", module->name, module->id);
107#else
108    ALOGI("AudioPolicyService CSTOR in new mode");
109
110    mAudioPolicyClient = new AudioPolicyClient(this);
111    mAudioPolicyManager = createAudioPolicyManager(mAudioPolicyClient);
112#endif
113
114    // load audio pre processing modules
115    if (access(AUDIO_EFFECT_VENDOR_CONFIG_FILE, R_OK) == 0) {
116        loadPreProcessorConfig(AUDIO_EFFECT_VENDOR_CONFIG_FILE);
117    } else if (access(AUDIO_EFFECT_DEFAULT_CONFIG_FILE, R_OK) == 0) {
118        loadPreProcessorConfig(AUDIO_EFFECT_DEFAULT_CONFIG_FILE);
119    }
120}
121
122AudioPolicyService::~AudioPolicyService()
123{
124    mTonePlaybackThread->exit();
125    mAudioCommandThread->exit();
126    mOutputCommandThread->exit();
127
128    // release audio pre processing resources
129    for (size_t i = 0; i < mInputSources.size(); i++) {
130        delete mInputSources.valueAt(i);
131    }
132    mInputSources.clear();
133
134    for (size_t i = 0; i < mInputs.size(); i++) {
135        mInputs.valueAt(i)->mEffects.clear();
136        delete mInputs.valueAt(i);
137    }
138    mInputs.clear();
139
140#ifdef USE_LEGACY_AUDIO_POLICY
141    if (mpAudioPolicy != NULL && mpAudioPolicyDev != NULL) {
142        mpAudioPolicyDev->destroy_audio_policy(mpAudioPolicyDev, mpAudioPolicy);
143    }
144    if (mpAudioPolicyDev != NULL) {
145        audio_policy_dev_close(mpAudioPolicyDev);
146    }
147#else
148    destroyAudioPolicyManager(mAudioPolicyManager);
149    delete mAudioPolicyClient;
150#endif
151
152    mNotificationClients.clear();
153}
154
155// A notification client is always registered by AudioSystem when the client process
156// connects to AudioPolicyService.
157void AudioPolicyService::registerClient(const sp<IAudioPolicyServiceClient>& client)
158{
159
160    Mutex::Autolock _l(mLock);
161
162    uid_t uid = IPCThreadState::self()->getCallingUid();
163    if (mNotificationClients.indexOfKey(uid) < 0) {
164        sp<NotificationClient> notificationClient = new NotificationClient(this,
165                                                                           client,
166                                                                           uid);
167        ALOGV("registerClient() client %p, uid %d", client.get(), uid);
168
169        mNotificationClients.add(uid, notificationClient);
170
171        sp<IBinder> binder = client->asBinder();
172        binder->linkToDeath(notificationClient);
173    }
174}
175
176// removeNotificationClient() is called when the client process dies.
177void AudioPolicyService::removeNotificationClient(uid_t uid)
178{
179    Mutex::Autolock _l(mLock);
180
181    mNotificationClients.removeItem(uid);
182
183#ifndef USE_LEGACY_AUDIO_POLICY
184        if (mAudioPolicyManager) {
185            mAudioPolicyManager->clearAudioPatches(uid);
186        }
187#endif
188}
189
190void AudioPolicyService::onAudioPortListUpdate()
191{
192    mOutputCommandThread->updateAudioPortListCommand();
193}
194
195void AudioPolicyService::doOnAudioPortListUpdate()
196{
197    Mutex::Autolock _l(mLock);
198    for (size_t i = 0; i < mNotificationClients.size(); i++) {
199        mNotificationClients.valueAt(i)->onAudioPortListUpdate();
200    }
201}
202
203void AudioPolicyService::onAudioPatchListUpdate()
204{
205    mOutputCommandThread->updateAudioPatchListCommand();
206}
207
208status_t AudioPolicyService::clientCreateAudioPatch(const struct audio_patch *patch,
209                                                audio_patch_handle_t *handle,
210                                                int delayMs)
211{
212    return mAudioCommandThread->createAudioPatchCommand(patch, handle, delayMs);
213}
214
215status_t AudioPolicyService::clientReleaseAudioPatch(audio_patch_handle_t handle,
216                                                 int delayMs)
217{
218    return mAudioCommandThread->releaseAudioPatchCommand(handle, delayMs);
219}
220
221void AudioPolicyService::doOnAudioPatchListUpdate()
222{
223    Mutex::Autolock _l(mLock);
224    for (size_t i = 0; i < mNotificationClients.size(); i++) {
225        mNotificationClients.valueAt(i)->onAudioPatchListUpdate();
226    }
227}
228
229status_t AudioPolicyService::clientSetAudioPortConfig(const struct audio_port_config *config,
230                                                      int delayMs)
231{
232    return mAudioCommandThread->setAudioPortConfigCommand(config, delayMs);
233}
234
235AudioPolicyService::NotificationClient::NotificationClient(const sp<AudioPolicyService>& service,
236                                                     const sp<IAudioPolicyServiceClient>& client,
237                                                     uid_t uid)
238    : mService(service), mUid(uid), mAudioPolicyServiceClient(client)
239{
240}
241
242AudioPolicyService::NotificationClient::~NotificationClient()
243{
244}
245
246void AudioPolicyService::NotificationClient::binderDied(const wp<IBinder>& who __unused)
247{
248    sp<NotificationClient> keep(this);
249    sp<AudioPolicyService> service = mService.promote();
250    if (service != 0) {
251        service->removeNotificationClient(mUid);
252    }
253}
254
255void AudioPolicyService::NotificationClient::onAudioPortListUpdate()
256{
257    if (mAudioPolicyServiceClient != 0) {
258        mAudioPolicyServiceClient->onAudioPortListUpdate();
259    }
260}
261
262void AudioPolicyService::NotificationClient::onAudioPatchListUpdate()
263{
264    if (mAudioPolicyServiceClient != 0) {
265        mAudioPolicyServiceClient->onAudioPatchListUpdate();
266    }
267}
268
269void AudioPolicyService::binderDied(const wp<IBinder>& who) {
270    ALOGW("binderDied() %p, calling pid %d", who.unsafe_get(),
271            IPCThreadState::self()->getCallingPid());
272}
273
274static bool tryLock(Mutex& mutex)
275{
276    bool locked = false;
277    for (int i = 0; i < kDumpLockRetries; ++i) {
278        if (mutex.tryLock() == NO_ERROR) {
279            locked = true;
280            break;
281        }
282        usleep(kDumpLockSleepUs);
283    }
284    return locked;
285}
286
287status_t AudioPolicyService::dumpInternals(int fd)
288{
289    const size_t SIZE = 256;
290    char buffer[SIZE];
291    String8 result;
292
293#ifdef USE_LEGACY_AUDIO_POLICY
294    snprintf(buffer, SIZE, "PolicyManager Interface: %p\n", mpAudioPolicy);
295#else
296    snprintf(buffer, SIZE, "AudioPolicyManager: %p\n", mAudioPolicyManager);
297#endif
298    result.append(buffer);
299    snprintf(buffer, SIZE, "Command Thread: %p\n", mAudioCommandThread.get());
300    result.append(buffer);
301    snprintf(buffer, SIZE, "Tones Thread: %p\n", mTonePlaybackThread.get());
302    result.append(buffer);
303
304    write(fd, result.string(), result.size());
305    return NO_ERROR;
306}
307
308status_t AudioPolicyService::dump(int fd, const Vector<String16>& args __unused)
309{
310    if (!dumpAllowed()) {
311        dumpPermissionDenial(fd);
312    } else {
313        bool locked = tryLock(mLock);
314        if (!locked) {
315            String8 result(kDeadlockedString);
316            write(fd, result.string(), result.size());
317        }
318
319        dumpInternals(fd);
320        if (mAudioCommandThread != 0) {
321            mAudioCommandThread->dump(fd);
322        }
323        if (mTonePlaybackThread != 0) {
324            mTonePlaybackThread->dump(fd);
325        }
326
327#ifdef USE_LEGACY_AUDIO_POLICY
328        if (mpAudioPolicy) {
329            mpAudioPolicy->dump(mpAudioPolicy, fd);
330        }
331#else
332        if (mAudioPolicyManager) {
333            mAudioPolicyManager->dump(fd);
334        }
335#endif
336
337        if (locked) mLock.unlock();
338    }
339    return NO_ERROR;
340}
341
342status_t AudioPolicyService::dumpPermissionDenial(int fd)
343{
344    const size_t SIZE = 256;
345    char buffer[SIZE];
346    String8 result;
347    snprintf(buffer, SIZE, "Permission Denial: "
348            "can't dump AudioPolicyService from pid=%d, uid=%d\n",
349            IPCThreadState::self()->getCallingPid(),
350            IPCThreadState::self()->getCallingUid());
351    result.append(buffer);
352    write(fd, result.string(), result.size());
353    return NO_ERROR;
354}
355
356void AudioPolicyService::setPreProcessorEnabled(const InputDesc *inputDesc, bool enabled)
357{
358    const Vector<sp<AudioEffect> > &fxVector = inputDesc->mEffects;
359    for (size_t i = 0; i < fxVector.size(); i++) {
360        fxVector.itemAt(i)->setEnabled(enabled);
361    }
362}
363
364status_t AudioPolicyService::onTransact(
365        uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
366{
367    return BnAudioPolicyService::onTransact(code, data, reply, flags);
368}
369
370
371// -----------  AudioPolicyService::AudioCommandThread implementation ----------
372
373AudioPolicyService::AudioCommandThread::AudioCommandThread(String8 name,
374                                                           const wp<AudioPolicyService>& service)
375    : Thread(false), mName(name), mService(service)
376{
377    mpToneGenerator = NULL;
378}
379
380
381AudioPolicyService::AudioCommandThread::~AudioCommandThread()
382{
383    if (!mAudioCommands.isEmpty()) {
384        release_wake_lock(mName.string());
385    }
386    mAudioCommands.clear();
387    delete mpToneGenerator;
388}
389
390void AudioPolicyService::AudioCommandThread::onFirstRef()
391{
392    run(mName.string(), ANDROID_PRIORITY_AUDIO);
393}
394
395bool AudioPolicyService::AudioCommandThread::threadLoop()
396{
397    nsecs_t waitTime = INT64_MAX;
398
399    mLock.lock();
400    while (!exitPending())
401    {
402        while (!mAudioCommands.isEmpty()) {
403            nsecs_t curTime = systemTime();
404            // commands are sorted by increasing time stamp: execute them from index 0 and up
405            if (mAudioCommands[0]->mTime <= curTime) {
406                sp<AudioCommand> command = mAudioCommands[0];
407                mAudioCommands.removeAt(0);
408                mLastCommand = command;
409
410                switch (command->mCommand) {
411                case START_TONE: {
412                    mLock.unlock();
413                    ToneData *data = (ToneData *)command->mParam.get();
414                    ALOGV("AudioCommandThread() processing start tone %d on stream %d",
415                            data->mType, data->mStream);
416                    delete mpToneGenerator;
417                    mpToneGenerator = new ToneGenerator(data->mStream, 1.0);
418                    mpToneGenerator->startTone(data->mType);
419                    mLock.lock();
420                    }break;
421                case STOP_TONE: {
422                    mLock.unlock();
423                    ALOGV("AudioCommandThread() processing stop tone");
424                    if (mpToneGenerator != NULL) {
425                        mpToneGenerator->stopTone();
426                        delete mpToneGenerator;
427                        mpToneGenerator = NULL;
428                    }
429                    mLock.lock();
430                    }break;
431                case SET_VOLUME: {
432                    VolumeData *data = (VolumeData *)command->mParam.get();
433                    ALOGV("AudioCommandThread() processing set volume stream %d, \
434                            volume %f, output %d", data->mStream, data->mVolume, data->mIO);
435                    command->mStatus = AudioSystem::setStreamVolume(data->mStream,
436                                                                    data->mVolume,
437                                                                    data->mIO);
438                    }break;
439                case SET_PARAMETERS: {
440                    ParametersData *data = (ParametersData *)command->mParam.get();
441                    ALOGV("AudioCommandThread() processing set parameters string %s, io %d",
442                            data->mKeyValuePairs.string(), data->mIO);
443                    command->mStatus = AudioSystem::setParameters(data->mIO, data->mKeyValuePairs);
444                    }break;
445                case SET_VOICE_VOLUME: {
446                    VoiceVolumeData *data = (VoiceVolumeData *)command->mParam.get();
447                    ALOGV("AudioCommandThread() processing set voice volume volume %f",
448                            data->mVolume);
449                    command->mStatus = AudioSystem::setVoiceVolume(data->mVolume);
450                    }break;
451                case STOP_OUTPUT: {
452                    StopOutputData *data = (StopOutputData *)command->mParam.get();
453                    ALOGV("AudioCommandThread() processing stop output %d",
454                            data->mIO);
455                    sp<AudioPolicyService> svc = mService.promote();
456                    if (svc == 0) {
457                        break;
458                    }
459                    mLock.unlock();
460                    svc->doStopOutput(data->mIO, data->mStream, data->mSession);
461                    mLock.lock();
462                    }break;
463                case RELEASE_OUTPUT: {
464                    ReleaseOutputData *data = (ReleaseOutputData *)command->mParam.get();
465                    ALOGV("AudioCommandThread() processing release output %d",
466                            data->mIO);
467                    sp<AudioPolicyService> svc = mService.promote();
468                    if (svc == 0) {
469                        break;
470                    }
471                    mLock.unlock();
472                    svc->doReleaseOutput(data->mIO);
473                    mLock.lock();
474                    }break;
475                case CREATE_AUDIO_PATCH: {
476                    CreateAudioPatchData *data = (CreateAudioPatchData *)command->mParam.get();
477                    ALOGV("AudioCommandThread() processing create audio patch");
478                    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
479                    if (af == 0) {
480                        command->mStatus = PERMISSION_DENIED;
481                    } else {
482                        command->mStatus = af->createAudioPatch(&data->mPatch, &data->mHandle);
483                    }
484                    } break;
485                case RELEASE_AUDIO_PATCH: {
486                    ReleaseAudioPatchData *data = (ReleaseAudioPatchData *)command->mParam.get();
487                    ALOGV("AudioCommandThread() processing release audio patch");
488                    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
489                    if (af == 0) {
490                        command->mStatus = PERMISSION_DENIED;
491                    } else {
492                        command->mStatus = af->releaseAudioPatch(data->mHandle);
493                    }
494                    } break;
495                case UPDATE_AUDIOPORT_LIST: {
496                    ALOGV("AudioCommandThread() processing update audio port list");
497                    sp<AudioPolicyService> svc = mService.promote();
498                    if (svc == 0) {
499                        break;
500                    }
501                    mLock.unlock();
502                    svc->doOnAudioPortListUpdate();
503                    mLock.lock();
504                    }break;
505                case UPDATE_AUDIOPATCH_LIST: {
506                    ALOGV("AudioCommandThread() processing update audio patch list");
507                    sp<AudioPolicyService> svc = mService.promote();
508                    if (svc == 0) {
509                        break;
510                    }
511                    mLock.unlock();
512                    svc->doOnAudioPatchListUpdate();
513                    mLock.lock();
514                    }break;
515                case SET_AUDIOPORT_CONFIG: {
516                    SetAudioPortConfigData *data = (SetAudioPortConfigData *)command->mParam.get();
517                    ALOGV("AudioCommandThread() processing set port config");
518                    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
519                    if (af == 0) {
520                        command->mStatus = PERMISSION_DENIED;
521                    } else {
522                        command->mStatus = af->setAudioPortConfig(&data->mConfig);
523                    }
524                    } break;
525                default:
526                    ALOGW("AudioCommandThread() unknown command %d", command->mCommand);
527                }
528                {
529                    Mutex::Autolock _l(command->mLock);
530                    if (command->mWaitStatus) {
531                        command->mWaitStatus = false;
532                        command->mCond.signal();
533                    }
534                }
535                waitTime = INT64_MAX;
536            } else {
537                waitTime = mAudioCommands[0]->mTime - curTime;
538                break;
539            }
540        }
541        // release delayed commands wake lock
542        if (mAudioCommands.isEmpty()) {
543            release_wake_lock(mName.string());
544        }
545        ALOGV("AudioCommandThread() going to sleep");
546        mWaitWorkCV.waitRelative(mLock, waitTime);
547        ALOGV("AudioCommandThread() waking up");
548    }
549    mLock.unlock();
550    return false;
551}
552
553status_t AudioPolicyService::AudioCommandThread::dump(int fd)
554{
555    const size_t SIZE = 256;
556    char buffer[SIZE];
557    String8 result;
558
559    snprintf(buffer, SIZE, "AudioCommandThread %p Dump\n", this);
560    result.append(buffer);
561    write(fd, result.string(), result.size());
562
563    bool locked = tryLock(mLock);
564    if (!locked) {
565        String8 result2(kCmdDeadlockedString);
566        write(fd, result2.string(), result2.size());
567    }
568
569    snprintf(buffer, SIZE, "- Commands:\n");
570    result = String8(buffer);
571    result.append("   Command Time        Wait pParam\n");
572    for (size_t i = 0; i < mAudioCommands.size(); i++) {
573        mAudioCommands[i]->dump(buffer, SIZE);
574        result.append(buffer);
575    }
576    result.append("  Last Command\n");
577    if (mLastCommand != 0) {
578        mLastCommand->dump(buffer, SIZE);
579        result.append(buffer);
580    } else {
581        result.append("     none\n");
582    }
583
584    write(fd, result.string(), result.size());
585
586    if (locked) mLock.unlock();
587
588    return NO_ERROR;
589}
590
591void AudioPolicyService::AudioCommandThread::startToneCommand(ToneGenerator::tone_type type,
592        audio_stream_type_t stream)
593{
594    sp<AudioCommand> command = new AudioCommand();
595    command->mCommand = START_TONE;
596    sp<ToneData> data = new ToneData();
597    data->mType = type;
598    data->mStream = stream;
599    command->mParam = data;
600    ALOGV("AudioCommandThread() adding tone start type %d, stream %d", type, stream);
601    sendCommand(command);
602}
603
604void AudioPolicyService::AudioCommandThread::stopToneCommand()
605{
606    sp<AudioCommand> command = new AudioCommand();
607    command->mCommand = STOP_TONE;
608    ALOGV("AudioCommandThread() adding tone stop");
609    sendCommand(command);
610}
611
612status_t AudioPolicyService::AudioCommandThread::volumeCommand(audio_stream_type_t stream,
613                                                               float volume,
614                                                               audio_io_handle_t output,
615                                                               int delayMs)
616{
617    sp<AudioCommand> command = new AudioCommand();
618    command->mCommand = SET_VOLUME;
619    sp<VolumeData> data = new VolumeData();
620    data->mStream = stream;
621    data->mVolume = volume;
622    data->mIO = output;
623    command->mParam = data;
624    command->mWaitStatus = true;
625    ALOGV("AudioCommandThread() adding set volume stream %d, volume %f, output %d",
626            stream, volume, output);
627    return sendCommand(command, delayMs);
628}
629
630status_t AudioPolicyService::AudioCommandThread::parametersCommand(audio_io_handle_t ioHandle,
631                                                                   const char *keyValuePairs,
632                                                                   int delayMs)
633{
634    sp<AudioCommand> command = new AudioCommand();
635    command->mCommand = SET_PARAMETERS;
636    sp<ParametersData> data = new ParametersData();
637    data->mIO = ioHandle;
638    data->mKeyValuePairs = String8(keyValuePairs);
639    command->mParam = data;
640    command->mWaitStatus = true;
641    ALOGV("AudioCommandThread() adding set parameter string %s, io %d ,delay %d",
642            keyValuePairs, ioHandle, delayMs);
643    return sendCommand(command, delayMs);
644}
645
646status_t AudioPolicyService::AudioCommandThread::voiceVolumeCommand(float volume, int delayMs)
647{
648    sp<AudioCommand> command = new AudioCommand();
649    command->mCommand = SET_VOICE_VOLUME;
650    sp<VoiceVolumeData> data = new VoiceVolumeData();
651    data->mVolume = volume;
652    command->mParam = data;
653    command->mWaitStatus = true;
654    ALOGV("AudioCommandThread() adding set voice volume volume %f", volume);
655    return sendCommand(command, delayMs);
656}
657
658void AudioPolicyService::AudioCommandThread::stopOutputCommand(audio_io_handle_t output,
659                                                               audio_stream_type_t stream,
660                                                               int session)
661{
662    sp<AudioCommand> command = new AudioCommand();
663    command->mCommand = STOP_OUTPUT;
664    sp<StopOutputData> data = new StopOutputData();
665    data->mIO = output;
666    data->mStream = stream;
667    data->mSession = session;
668    command->mParam = data;
669    ALOGV("AudioCommandThread() adding stop output %d", output);
670    sendCommand(command);
671}
672
673void AudioPolicyService::AudioCommandThread::releaseOutputCommand(audio_io_handle_t output)
674{
675    sp<AudioCommand> command = new AudioCommand();
676    command->mCommand = RELEASE_OUTPUT;
677    sp<ReleaseOutputData> data = new ReleaseOutputData();
678    data->mIO = output;
679    command->mParam = data;
680    ALOGV("AudioCommandThread() adding release output %d", output);
681    sendCommand(command);
682}
683
684status_t AudioPolicyService::AudioCommandThread::createAudioPatchCommand(
685                                                const struct audio_patch *patch,
686                                                audio_patch_handle_t *handle,
687                                                int delayMs)
688{
689    status_t status = NO_ERROR;
690
691    sp<AudioCommand> command = new AudioCommand();
692    command->mCommand = CREATE_AUDIO_PATCH;
693    CreateAudioPatchData *data = new CreateAudioPatchData();
694    data->mPatch = *patch;
695    data->mHandle = *handle;
696    command->mParam = data;
697    command->mWaitStatus = true;
698    ALOGV("AudioCommandThread() adding create patch delay %d", delayMs);
699    status = sendCommand(command, delayMs);
700    if (status == NO_ERROR) {
701        *handle = data->mHandle;
702    }
703    return status;
704}
705
706status_t AudioPolicyService::AudioCommandThread::releaseAudioPatchCommand(audio_patch_handle_t handle,
707                                                 int delayMs)
708{
709    sp<AudioCommand> command = new AudioCommand();
710    command->mCommand = RELEASE_AUDIO_PATCH;
711    ReleaseAudioPatchData *data = new ReleaseAudioPatchData();
712    data->mHandle = handle;
713    command->mParam = data;
714    command->mWaitStatus = true;
715    ALOGV("AudioCommandThread() adding release patch delay %d", delayMs);
716    return sendCommand(command, delayMs);
717}
718
719void AudioPolicyService::AudioCommandThread::updateAudioPortListCommand()
720{
721    sp<AudioCommand> command = new AudioCommand();
722    command->mCommand = UPDATE_AUDIOPORT_LIST;
723    ALOGV("AudioCommandThread() adding update audio port list");
724    sendCommand(command);
725}
726
727void AudioPolicyService::AudioCommandThread::updateAudioPatchListCommand()
728{
729    sp<AudioCommand>command = new AudioCommand();
730    command->mCommand = UPDATE_AUDIOPATCH_LIST;
731    ALOGV("AudioCommandThread() adding update audio patch list");
732    sendCommand(command);
733}
734
735status_t AudioPolicyService::AudioCommandThread::setAudioPortConfigCommand(
736                                            const struct audio_port_config *config, int delayMs)
737{
738    sp<AudioCommand> command = new AudioCommand();
739    command->mCommand = SET_AUDIOPORT_CONFIG;
740    SetAudioPortConfigData *data = new SetAudioPortConfigData();
741    data->mConfig = *config;
742    command->mParam = data;
743    command->mWaitStatus = true;
744    ALOGV("AudioCommandThread() adding set port config delay %d", delayMs);
745    return sendCommand(command, delayMs);
746}
747
748status_t AudioPolicyService::AudioCommandThread::sendCommand(sp<AudioCommand>& command, int delayMs)
749{
750    {
751        Mutex::Autolock _l(mLock);
752        insertCommand_l(command, delayMs);
753        mWaitWorkCV.signal();
754    }
755    Mutex::Autolock _l(command->mLock);
756    while (command->mWaitStatus) {
757        nsecs_t timeOutNs = kAudioCommandTimeoutNs + milliseconds(delayMs);
758        if (command->mCond.waitRelative(command->mLock, timeOutNs) != NO_ERROR) {
759            command->mStatus = TIMED_OUT;
760            command->mWaitStatus = false;
761        }
762    }
763    return command->mStatus;
764}
765
766// insertCommand_l() must be called with mLock held
767void AudioPolicyService::AudioCommandThread::insertCommand_l(sp<AudioCommand>& command, int delayMs)
768{
769    ssize_t i;  // not size_t because i will count down to -1
770    Vector < sp<AudioCommand> > removedCommands;
771    command->mTime = systemTime() + milliseconds(delayMs);
772
773    // acquire wake lock to make sure delayed commands are processed
774    if (mAudioCommands.isEmpty()) {
775        acquire_wake_lock(PARTIAL_WAKE_LOCK, mName.string());
776    }
777
778    // check same pending commands with later time stamps and eliminate them
779    for (i = mAudioCommands.size()-1; i >= 0; i--) {
780        sp<AudioCommand> command2 = mAudioCommands[i];
781        // commands are sorted by increasing time stamp: no need to scan the rest of mAudioCommands
782        if (command2->mTime <= command->mTime) break;
783        if (command2->mCommand != command->mCommand) continue;
784
785        switch (command->mCommand) {
786        case SET_PARAMETERS: {
787            ParametersData *data = (ParametersData *)command->mParam.get();
788            ParametersData *data2 = (ParametersData *)command2->mParam.get();
789            if (data->mIO != data2->mIO) break;
790            ALOGV("Comparing parameter command %s to new command %s",
791                    data2->mKeyValuePairs.string(), data->mKeyValuePairs.string());
792            AudioParameter param = AudioParameter(data->mKeyValuePairs);
793            AudioParameter param2 = AudioParameter(data2->mKeyValuePairs);
794            for (size_t j = 0; j < param.size(); j++) {
795                String8 key;
796                String8 value;
797                param.getAt(j, key, value);
798                for (size_t k = 0; k < param2.size(); k++) {
799                    String8 key2;
800                    String8 value2;
801                    param2.getAt(k, key2, value2);
802                    if (key2 == key) {
803                        param2.remove(key2);
804                        ALOGV("Filtering out parameter %s", key2.string());
805                        break;
806                    }
807                }
808            }
809            // if all keys have been filtered out, remove the command.
810            // otherwise, update the key value pairs
811            if (param2.size() == 0) {
812                removedCommands.add(command2);
813            } else {
814                data2->mKeyValuePairs = param2.toString();
815            }
816            command->mTime = command2->mTime;
817            // force delayMs to non 0 so that code below does not request to wait for
818            // command status as the command is now delayed
819            delayMs = 1;
820        } break;
821
822        case SET_VOLUME: {
823            VolumeData *data = (VolumeData *)command->mParam.get();
824            VolumeData *data2 = (VolumeData *)command2->mParam.get();
825            if (data->mIO != data2->mIO) break;
826            if (data->mStream != data2->mStream) break;
827            ALOGV("Filtering out volume command on output %d for stream %d",
828                    data->mIO, data->mStream);
829            removedCommands.add(command2);
830            command->mTime = command2->mTime;
831            // force delayMs to non 0 so that code below does not request to wait for
832            // command status as the command is now delayed
833            delayMs = 1;
834        } break;
835        case START_TONE:
836        case STOP_TONE:
837        default:
838            break;
839        }
840    }
841
842    // remove filtered commands
843    for (size_t j = 0; j < removedCommands.size(); j++) {
844        // removed commands always have time stamps greater than current command
845        for (size_t k = i + 1; k < mAudioCommands.size(); k++) {
846            if (mAudioCommands[k].get() == removedCommands[j].get()) {
847                ALOGV("suppressing command: %d", mAudioCommands[k]->mCommand);
848                mAudioCommands.removeAt(k);
849                break;
850            }
851        }
852    }
853    removedCommands.clear();
854
855    // Disable wait for status if delay is not 0
856    if (delayMs != 0) {
857        command->mWaitStatus = false;
858    }
859
860    // insert command at the right place according to its time stamp
861    ALOGV("inserting command: %d at index %d, num commands %d",
862            command->mCommand, (int)i+1, mAudioCommands.size());
863    mAudioCommands.insertAt(command, i + 1);
864}
865
866void AudioPolicyService::AudioCommandThread::exit()
867{
868    ALOGV("AudioCommandThread::exit");
869    {
870        AutoMutex _l(mLock);
871        requestExit();
872        mWaitWorkCV.signal();
873    }
874    requestExitAndWait();
875}
876
877void AudioPolicyService::AudioCommandThread::AudioCommand::dump(char* buffer, size_t size)
878{
879    snprintf(buffer, size, "   %02d      %06d.%03d  %01u    %p\n",
880            mCommand,
881            (int)ns2s(mTime),
882            (int)ns2ms(mTime)%1000,
883            mWaitStatus,
884            mParam.get());
885}
886
887/******* helpers for the service_ops callbacks defined below *********/
888void AudioPolicyService::setParameters(audio_io_handle_t ioHandle,
889                                       const char *keyValuePairs,
890                                       int delayMs)
891{
892    mAudioCommandThread->parametersCommand(ioHandle, keyValuePairs,
893                                           delayMs);
894}
895
896int AudioPolicyService::setStreamVolume(audio_stream_type_t stream,
897                                        float volume,
898                                        audio_io_handle_t output,
899                                        int delayMs)
900{
901    return (int)mAudioCommandThread->volumeCommand(stream, volume,
902                                                   output, delayMs);
903}
904
905int AudioPolicyService::startTone(audio_policy_tone_t tone,
906                                  audio_stream_type_t stream)
907{
908    if (tone != AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION) {
909        ALOGE("startTone: illegal tone requested (%d)", tone);
910    }
911    if (stream != AUDIO_STREAM_VOICE_CALL) {
912        ALOGE("startTone: illegal stream (%d) requested for tone %d", stream,
913            tone);
914    }
915    mTonePlaybackThread->startToneCommand(ToneGenerator::TONE_SUP_CALL_WAITING,
916                                          AUDIO_STREAM_VOICE_CALL);
917    return 0;
918}
919
920int AudioPolicyService::stopTone()
921{
922    mTonePlaybackThread->stopToneCommand();
923    return 0;
924}
925
926int AudioPolicyService::setVoiceVolume(float volume, int delayMs)
927{
928    return (int)mAudioCommandThread->voiceVolumeCommand(volume, delayMs);
929}
930
931// ----------------------------------------------------------------------------
932// Audio pre-processing configuration
933// ----------------------------------------------------------------------------
934
935/*static*/ const char * const AudioPolicyService::kInputSourceNames[AUDIO_SOURCE_CNT -1] = {
936    MIC_SRC_TAG,
937    VOICE_UL_SRC_TAG,
938    VOICE_DL_SRC_TAG,
939    VOICE_CALL_SRC_TAG,
940    CAMCORDER_SRC_TAG,
941    VOICE_REC_SRC_TAG,
942    VOICE_COMM_SRC_TAG
943};
944
945// returns the audio_source_t enum corresponding to the input source name or
946// AUDIO_SOURCE_CNT is no match found
947audio_source_t AudioPolicyService::inputSourceNameToEnum(const char *name)
948{
949    int i;
950    for (i = AUDIO_SOURCE_MIC; i < AUDIO_SOURCE_CNT; i++) {
951        if (strcmp(name, kInputSourceNames[i - AUDIO_SOURCE_MIC]) == 0) {
952            ALOGV("inputSourceNameToEnum found source %s %d", name, i);
953            break;
954        }
955    }
956    return (audio_source_t)i;
957}
958
959size_t AudioPolicyService::growParamSize(char *param,
960                                         size_t size,
961                                         size_t *curSize,
962                                         size_t *totSize)
963{
964    // *curSize is at least sizeof(effect_param_t) + 2 * sizeof(int)
965    size_t pos = ((*curSize - 1 ) / size + 1) * size;
966
967    if (pos + size > *totSize) {
968        while (pos + size > *totSize) {
969            *totSize += ((*totSize + 7) / 8) * 4;
970        }
971        param = (char *)realloc(param, *totSize);
972    }
973    *curSize = pos + size;
974    return pos;
975}
976
977size_t AudioPolicyService::readParamValue(cnode *node,
978                                          char *param,
979                                          size_t *curSize,
980                                          size_t *totSize)
981{
982    if (strncmp(node->name, SHORT_TAG, sizeof(SHORT_TAG) + 1) == 0) {
983        size_t pos = growParamSize(param, sizeof(short), curSize, totSize);
984        *(short *)((char *)param + pos) = (short)atoi(node->value);
985        ALOGV("readParamValue() reading short %d", *(short *)((char *)param + pos));
986        return sizeof(short);
987    } else if (strncmp(node->name, INT_TAG, sizeof(INT_TAG) + 1) == 0) {
988        size_t pos = growParamSize(param, sizeof(int), curSize, totSize);
989        *(int *)((char *)param + pos) = atoi(node->value);
990        ALOGV("readParamValue() reading int %d", *(int *)((char *)param + pos));
991        return sizeof(int);
992    } else if (strncmp(node->name, FLOAT_TAG, sizeof(FLOAT_TAG) + 1) == 0) {
993        size_t pos = growParamSize(param, sizeof(float), curSize, totSize);
994        *(float *)((char *)param + pos) = (float)atof(node->value);
995        ALOGV("readParamValue() reading float %f",*(float *)((char *)param + pos));
996        return sizeof(float);
997    } else if (strncmp(node->name, BOOL_TAG, sizeof(BOOL_TAG) + 1) == 0) {
998        size_t pos = growParamSize(param, sizeof(bool), curSize, totSize);
999        if (strncmp(node->value, "false", strlen("false") + 1) == 0) {
1000            *(bool *)((char *)param + pos) = false;
1001        } else {
1002            *(bool *)((char *)param + pos) = true;
1003        }
1004        ALOGV("readParamValue() reading bool %s",*(bool *)((char *)param + pos) ? "true" : "false");
1005        return sizeof(bool);
1006    } else if (strncmp(node->name, STRING_TAG, sizeof(STRING_TAG) + 1) == 0) {
1007        size_t len = strnlen(node->value, EFFECT_STRING_LEN_MAX);
1008        if (*curSize + len + 1 > *totSize) {
1009            *totSize = *curSize + len + 1;
1010            param = (char *)realloc(param, *totSize);
1011        }
1012        strncpy(param + *curSize, node->value, len);
1013        *curSize += len;
1014        param[*curSize] = '\0';
1015        ALOGV("readParamValue() reading string %s", param + *curSize - len);
1016        return len;
1017    }
1018    ALOGW("readParamValue() unknown param type %s", node->name);
1019    return 0;
1020}
1021
1022effect_param_t *AudioPolicyService::loadEffectParameter(cnode *root)
1023{
1024    cnode *param;
1025    cnode *value;
1026    size_t curSize = sizeof(effect_param_t);
1027    size_t totSize = sizeof(effect_param_t) + 2 * sizeof(int);
1028    effect_param_t *fx_param = (effect_param_t *)malloc(totSize);
1029
1030    param = config_find(root, PARAM_TAG);
1031    value = config_find(root, VALUE_TAG);
1032    if (param == NULL && value == NULL) {
1033        // try to parse simple parameter form {int int}
1034        param = root->first_child;
1035        if (param != NULL) {
1036            // Note: that a pair of random strings is read as 0 0
1037            int *ptr = (int *)fx_param->data;
1038            int *ptr2 = (int *)((char *)param + sizeof(effect_param_t));
1039            ALOGW("loadEffectParameter() ptr %p ptr2 %p", ptr, ptr2);
1040            *ptr++ = atoi(param->name);
1041            *ptr = atoi(param->value);
1042            fx_param->psize = sizeof(int);
1043            fx_param->vsize = sizeof(int);
1044            return fx_param;
1045        }
1046    }
1047    if (param == NULL || value == NULL) {
1048        ALOGW("loadEffectParameter() invalid parameter description %s", root->name);
1049        goto error;
1050    }
1051
1052    fx_param->psize = 0;
1053    param = param->first_child;
1054    while (param) {
1055        ALOGV("loadEffectParameter() reading param of type %s", param->name);
1056        size_t size = readParamValue(param, (char *)fx_param, &curSize, &totSize);
1057        if (size == 0) {
1058            goto error;
1059        }
1060        fx_param->psize += size;
1061        param = param->next;
1062    }
1063
1064    // align start of value field on 32 bit boundary
1065    curSize = ((curSize - 1 ) / sizeof(int) + 1) * sizeof(int);
1066
1067    fx_param->vsize = 0;
1068    value = value->first_child;
1069    while (value) {
1070        ALOGV("loadEffectParameter() reading value of type %s", value->name);
1071        size_t size = readParamValue(value, (char *)fx_param, &curSize, &totSize);
1072        if (size == 0) {
1073            goto error;
1074        }
1075        fx_param->vsize += size;
1076        value = value->next;
1077    }
1078
1079    return fx_param;
1080
1081error:
1082    free(fx_param);
1083    return NULL;
1084}
1085
1086void AudioPolicyService::loadEffectParameters(cnode *root, Vector <effect_param_t *>& params)
1087{
1088    cnode *node = root->first_child;
1089    while (node) {
1090        ALOGV("loadEffectParameters() loading param %s", node->name);
1091        effect_param_t *param = loadEffectParameter(node);
1092        if (param == NULL) {
1093            node = node->next;
1094            continue;
1095        }
1096        params.add(param);
1097        node = node->next;
1098    }
1099}
1100
1101AudioPolicyService::InputSourceDesc *AudioPolicyService::loadInputSource(
1102                                                            cnode *root,
1103                                                            const Vector <EffectDesc *>& effects)
1104{
1105    cnode *node = root->first_child;
1106    if (node == NULL) {
1107        ALOGW("loadInputSource() empty element %s", root->name);
1108        return NULL;
1109    }
1110    InputSourceDesc *source = new InputSourceDesc();
1111    while (node) {
1112        size_t i;
1113        for (i = 0; i < effects.size(); i++) {
1114            if (strncmp(effects[i]->mName, node->name, EFFECT_STRING_LEN_MAX) == 0) {
1115                ALOGV("loadInputSource() found effect %s in list", node->name);
1116                break;
1117            }
1118        }
1119        if (i == effects.size()) {
1120            ALOGV("loadInputSource() effect %s not in list", node->name);
1121            node = node->next;
1122            continue;
1123        }
1124        EffectDesc *effect = new EffectDesc(*effects[i]);   // deep copy
1125        loadEffectParameters(node, effect->mParams);
1126        ALOGV("loadInputSource() adding effect %s uuid %08x", effect->mName, effect->mUuid.timeLow);
1127        source->mEffects.add(effect);
1128        node = node->next;
1129    }
1130    if (source->mEffects.size() == 0) {
1131        ALOGW("loadInputSource() no valid effects found in source %s", root->name);
1132        delete source;
1133        return NULL;
1134    }
1135    return source;
1136}
1137
1138status_t AudioPolicyService::loadInputSources(cnode *root, const Vector <EffectDesc *>& effects)
1139{
1140    cnode *node = config_find(root, PREPROCESSING_TAG);
1141    if (node == NULL) {
1142        return -ENOENT;
1143    }
1144    node = node->first_child;
1145    while (node) {
1146        audio_source_t source = inputSourceNameToEnum(node->name);
1147        if (source == AUDIO_SOURCE_CNT) {
1148            ALOGW("loadInputSources() invalid input source %s", node->name);
1149            node = node->next;
1150            continue;
1151        }
1152        ALOGV("loadInputSources() loading input source %s", node->name);
1153        InputSourceDesc *desc = loadInputSource(node, effects);
1154        if (desc == NULL) {
1155            node = node->next;
1156            continue;
1157        }
1158        mInputSources.add(source, desc);
1159        node = node->next;
1160    }
1161    return NO_ERROR;
1162}
1163
1164AudioPolicyService::EffectDesc *AudioPolicyService::loadEffect(cnode *root)
1165{
1166    cnode *node = config_find(root, UUID_TAG);
1167    if (node == NULL) {
1168        return NULL;
1169    }
1170    effect_uuid_t uuid;
1171    if (AudioEffect::stringToGuid(node->value, &uuid) != NO_ERROR) {
1172        ALOGW("loadEffect() invalid uuid %s", node->value);
1173        return NULL;
1174    }
1175    return new EffectDesc(root->name, uuid);
1176}
1177
1178status_t AudioPolicyService::loadEffects(cnode *root, Vector <EffectDesc *>& effects)
1179{
1180    cnode *node = config_find(root, EFFECTS_TAG);
1181    if (node == NULL) {
1182        return -ENOENT;
1183    }
1184    node = node->first_child;
1185    while (node) {
1186        ALOGV("loadEffects() loading effect %s", node->name);
1187        EffectDesc *effect = loadEffect(node);
1188        if (effect == NULL) {
1189            node = node->next;
1190            continue;
1191        }
1192        effects.add(effect);
1193        node = node->next;
1194    }
1195    return NO_ERROR;
1196}
1197
1198status_t AudioPolicyService::loadPreProcessorConfig(const char *path)
1199{
1200    cnode *root;
1201    char *data;
1202
1203    data = (char *)load_file(path, NULL);
1204    if (data == NULL) {
1205        return -ENODEV;
1206    }
1207    root = config_node("", "");
1208    config_load(root, data);
1209
1210    Vector <EffectDesc *> effects;
1211    loadEffects(root, effects);
1212    loadInputSources(root, effects);
1213
1214    // delete effects to fix memory leak.
1215    // as effects is local var and valgrind would treat this as memory leak
1216    // and although it only did in mediaserver init, but free it in case mediaserver reboot
1217    size_t i;
1218    for (i = 0; i < effects.size(); i++) {
1219      delete effects[i];
1220    }
1221
1222    config_free(root);
1223    free(root);
1224    free(data);
1225
1226    return NO_ERROR;
1227}
1228
1229extern "C" {
1230audio_module_handle_t aps_load_hw_module(void *service __unused,
1231                                             const char *name);
1232audio_io_handle_t aps_open_output(void *service __unused,
1233                                         audio_devices_t *pDevices,
1234                                         uint32_t *pSamplingRate,
1235                                         audio_format_t *pFormat,
1236                                         audio_channel_mask_t *pChannelMask,
1237                                         uint32_t *pLatencyMs,
1238                                         audio_output_flags_t flags);
1239
1240audio_io_handle_t aps_open_output_on_module(void *service __unused,
1241                                                   audio_module_handle_t module,
1242                                                   audio_devices_t *pDevices,
1243                                                   uint32_t *pSamplingRate,
1244                                                   audio_format_t *pFormat,
1245                                                   audio_channel_mask_t *pChannelMask,
1246                                                   uint32_t *pLatencyMs,
1247                                                   audio_output_flags_t flags,
1248                                                   const audio_offload_info_t *offloadInfo);
1249audio_io_handle_t aps_open_dup_output(void *service __unused,
1250                                                 audio_io_handle_t output1,
1251                                                 audio_io_handle_t output2);
1252int aps_close_output(void *service __unused, audio_io_handle_t output);
1253int aps_suspend_output(void *service __unused, audio_io_handle_t output);
1254int aps_restore_output(void *service __unused, audio_io_handle_t output);
1255audio_io_handle_t aps_open_input(void *service __unused,
1256                                        audio_devices_t *pDevices,
1257                                        uint32_t *pSamplingRate,
1258                                        audio_format_t *pFormat,
1259                                        audio_channel_mask_t *pChannelMask,
1260                                        audio_in_acoustics_t acoustics __unused);
1261audio_io_handle_t aps_open_input_on_module(void *service __unused,
1262                                                  audio_module_handle_t module,
1263                                                  audio_devices_t *pDevices,
1264                                                  uint32_t *pSamplingRate,
1265                                                  audio_format_t *pFormat,
1266                                                  audio_channel_mask_t *pChannelMask);
1267int aps_close_input(void *service __unused, audio_io_handle_t input);
1268int aps_invalidate_stream(void *service __unused, audio_stream_type_t stream);
1269int aps_move_effects(void *service __unused, int session,
1270                                audio_io_handle_t src_output,
1271                                audio_io_handle_t dst_output);
1272char * aps_get_parameters(void *service __unused, audio_io_handle_t io_handle,
1273                                     const char *keys);
1274void aps_set_parameters(void *service, audio_io_handle_t io_handle,
1275                                   const char *kv_pairs, int delay_ms);
1276int aps_set_stream_volume(void *service, audio_stream_type_t stream,
1277                                     float volume, audio_io_handle_t output,
1278                                     int delay_ms);
1279int aps_start_tone(void *service, audio_policy_tone_t tone,
1280                              audio_stream_type_t stream);
1281int aps_stop_tone(void *service);
1282int aps_set_voice_volume(void *service, float volume, int delay_ms);
1283};
1284
1285namespace {
1286    struct audio_policy_service_ops aps_ops = {
1287        .open_output           = aps_open_output,
1288        .open_duplicate_output = aps_open_dup_output,
1289        .close_output          = aps_close_output,
1290        .suspend_output        = aps_suspend_output,
1291        .restore_output        = aps_restore_output,
1292        .open_input            = aps_open_input,
1293        .close_input           = aps_close_input,
1294        .set_stream_volume     = aps_set_stream_volume,
1295        .invalidate_stream     = aps_invalidate_stream,
1296        .set_parameters        = aps_set_parameters,
1297        .get_parameters        = aps_get_parameters,
1298        .start_tone            = aps_start_tone,
1299        .stop_tone             = aps_stop_tone,
1300        .set_voice_volume      = aps_set_voice_volume,
1301        .move_effects          = aps_move_effects,
1302        .load_hw_module        = aps_load_hw_module,
1303        .open_output_on_module = aps_open_output_on_module,
1304        .open_input_on_module  = aps_open_input_on_module,
1305    };
1306}; // namespace <unnamed>
1307
1308}; // namespace android
1309